]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9-3.3.7-201205301837.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9-3.3.7-201205301837.patch
CommitLineData
5acc6d36
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index 0c083c5..bf13011 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@@ -92,19 +98,24 @@ bounds.h
46 bsetup
47 btfixupprep
48 build
49+builtin-policy.h
50 bvmlinux
51 bzImage*
52 capability_names.h
53 capflags.c
54 classlist.h*
55+clut_vga16.c
56+common-cmds.h
57 comp*.log
58 compile.h*
59 conf
60 config
61 config-*
62 config_data.h*
63+config.c
64 config.mak
65 config.mak.autogen
66+config.tmp
67 conmakehash
68 consolemap_deftbl.c*
69 cpustr.h
70@@ -115,9 +126,11 @@ devlist.h*
71 dnotify_test
72 docproc
73 dslm
74+dtc-lexer.lex.c
75 elf2ecoff
76 elfconfig.h*
77 evergreen_reg_safe.h
78+exception_policy.conf
79 fixdep
80 flask.h
81 fore200e_mkfirm
82@@ -125,12 +138,15 @@ fore200e_pca_fw.c*
83 gconf
84 gconf.glade.h
85 gen-devlist
86+gen-kdb_cmds.c
87 gen_crc32table
88 gen_init_cpio
89 generated
90 genheaders
91 genksyms
92 *_gray256.c
93+hash
94+hid-example
95 hpet_example
96 hugepage-mmap
97 hugepage-shm
98@@ -145,7 +161,7 @@ int32.c
99 int4.c
100 int8.c
101 kallsyms
102-kconfig
103+kern_constants.h
104 keywords.c
105 ksym.c*
106 ksym.h*
107@@ -153,7 +169,7 @@ kxgettext
108 lkc_defs.h
109 lex.c
110 lex.*.c
111-linux
112+lib1funcs.S
113 logo_*.c
114 logo_*_clut224.c
115 logo_*_mono.c
116@@ -165,14 +181,15 @@ machtypes.h
117 map
118 map_hugetlb
119 maui_boot.h
120-media
121 mconf
122+mdp
123 miboot*
124 mk_elfconfig
125 mkboot
126 mkbugboot
127 mkcpustr
128 mkdep
129+mkpiggy
130 mkprep
131 mkregtable
132 mktables
133@@ -208,6 +225,7 @@ r300_reg_safe.h
134 r420_reg_safe.h
135 r600_reg_safe.h
136 recordmcount
137+regdb.c
138 relocs
139 rlim_names.h
140 rn50_reg_safe.h
141@@ -218,6 +236,7 @@ setup
142 setup.bin
143 setup.elf
144 sImage
145+slabinfo
146 sm_tbl*
147 split-include
148 syscalltab.h
149@@ -228,6 +247,7 @@ tftpboot.img
150 timeconst.h
151 times.h*
152 trix_boot.h
153+user_constants.h
154 utsrelease.h*
155 vdso-syms.lds
156 vdso.lds
157@@ -245,7 +265,9 @@ vmlinux
158 vmlinux-*
159 vmlinux.aout
160 vmlinux.bin.all
161+vmlinux.bin.bz2
162 vmlinux.lds
163+vmlinux.relocs
164 vmlinuz
165 voffset.h
166 vsyscall.lds
167@@ -253,9 +275,11 @@ vsyscall_32.lds
168 wanxlfw.inc
169 uImage
170 unifdef
171+utsrelease.h
172 wakeup.bin
173 wakeup.elf
174 wakeup.lds
175 zImage*
176 zconf.hash.c
177+zconf.lex.c
178 zoffset.h
179diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
180index d99fd9c..8689fef 100644
181--- a/Documentation/kernel-parameters.txt
182+++ b/Documentation/kernel-parameters.txt
183@@ -1977,6 +1977,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
184 the specified number of seconds. This is to be used if
185 your oopses keep scrolling off the screen.
186
187+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
188+ virtualization environments that don't cope well with the
189+ expand down segment used by UDEREF on X86-32 or the frequent
190+ page table updates on X86-64.
191+
192+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
193+
194 pcbit= [HW,ISDN]
195
196 pcd. [PARIDE]
197diff --git a/Makefile b/Makefile
198index 073f74f..a689ddf 100644
199--- a/Makefile
200+++ b/Makefile
201@@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
202
203 HOSTCC = gcc
204 HOSTCXX = g++
205-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
206-HOSTCXXFLAGS = -O2
207+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
208+HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
209+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
210
211 # Decide whether to build built-in, modular, or both.
212 # Normally, just do built-in.
213@@ -357,9 +358,9 @@ CFLAGS_GCOV = -fprofile-arcs -ftest-coverage
214
215 # Use LINUXINCLUDE when you must reference the include/ directory.
216 # Needed to be compatible with the O= option
217-LINUXINCLUDE := -I$(srctree)/arch/$(hdr-arch)/include \
218- -Iarch/$(hdr-arch)/include/generated -Iinclude \
219- $(if $(KBUILD_SRC), -I$(srctree)/include) \
220+LINUXINCLUDE := -isystem arch/$(hdr-arch)/include \
221+ -isystem arch/$(hdr-arch)/include/generated -isystem include \
222+ -isystem include/generated \
223 -include $(srctree)/include/linux/kconfig.h
224
225 KBUILD_CPPFLAGS := -D__KERNEL__
226@@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
227 # Rules shared between *config targets and build targets
228
229 # Basic helpers built in scripts/
230-PHONY += scripts_basic
231-scripts_basic:
232+PHONY += scripts_basic gcc-plugins
233+scripts_basic: gcc-plugins
234 $(Q)$(MAKE) $(build)=scripts/basic
235 $(Q)rm -f .tmp_quiet_recordmcount
236
237@@ -442,7 +443,7 @@ asm-generic:
238
239 no-dot-config-targets := clean mrproper distclean \
240 cscope gtags TAGS tags help %docs check% coccicheck \
241- include/linux/version.h headers_% archheaders \
242+ include/generated/linux/version.h headers_% archheaders \
243 kernelversion %src-pkg
244
245 config-targets := 0
246@@ -485,11 +486,11 @@ include $(srctree)/arch/$(SRCARCH)/Makefile
247 export KBUILD_DEFCONFIG KBUILD_KCONFIG
248
249 config: scripts_basic outputmakefile FORCE
250- $(Q)mkdir -p include/linux include/config
251+ $(Q)mkdir -p include/generated/linux include/config
252 $(Q)$(MAKE) $(build)=scripts/kconfig $@
253
254 %config: scripts_basic outputmakefile FORCE
255- $(Q)mkdir -p include/linux include/config
256+ $(Q)mkdir -p include/generated/linux include/config
257 $(Q)$(MAKE) $(build)=scripts/kconfig $@
258
259 else
260@@ -564,6 +565,55 @@ else
261 KBUILD_CFLAGS += -O2
262 endif
263
264+ifndef DISABLE_PAX_PLUGINS
265+ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
266+ifndef DISABLE_PAX_CONSTIFY_PLUGIN
267+ifndef CONFIG_UML
268+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
269+endif
270+endif
271+ifdef CONFIG_PAX_MEMORY_STACKLEAK
272+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
273+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
274+endif
275+ifdef CONFIG_KALLOCSTAT_PLUGIN
276+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
277+endif
278+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
279+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
280+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
281+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
282+endif
283+ifdef CONFIG_CHECKER_PLUGIN
284+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
285+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
286+endif
287+endif
288+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
289+ifdef CONFIG_PAX_SIZE_OVERFLOW
290+SIZE_OVERFLOW_PLUGIN := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
291+endif
292+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
293+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS) $(SIZE_OVERFLOW_PLUGIN)
294+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
295+export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN SIZE_OVERFLOW_PLUGIN
296+ifeq ($(KBUILD_EXTMOD),)
297+gcc-plugins:
298+ $(Q)$(MAKE) $(build)=tools/gcc
299+else
300+gcc-plugins: ;
301+endif
302+else
303+gcc-plugins:
304+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
305+ $(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.))
306+else
307+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
308+endif
309+ $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
310+endif
311+endif
312+
313 include $(srctree)/arch/$(SRCARCH)/Makefile
314
315 ifneq ($(CONFIG_FRAME_WARN),0)
316@@ -708,7 +758,7 @@ export mod_strip_cmd
317
318
319 ifeq ($(KBUILD_EXTMOD),)
320-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
321+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
322
323 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
324 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
325@@ -932,6 +982,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
326
327 # The actual objects are generated when descending,
328 # make sure no implicit rule kicks in
329+$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
330+$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
331 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
332
333 # Handle descending into subdirectories listed in $(vmlinux-dirs)
334@@ -941,7 +993,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
335 # Error messages still appears in the original language
336
337 PHONY += $(vmlinux-dirs)
338-$(vmlinux-dirs): prepare scripts
339+$(vmlinux-dirs): gcc-plugins prepare scripts
340 $(Q)$(MAKE) $(build)=$@
341
342 # Store (new) KERNELRELASE string in include/config/kernel.release
343@@ -970,12 +1022,14 @@ ifneq ($(KBUILD_SRC),)
344 echo " in the '$(srctree)' directory.";\
345 /bin/false; \
346 fi;
347+ $(Q)for dir in $(srctree)/include/* ; do ln -fsn $$dir include/`basename $$dir` ; done
348+ $(Q)ln -fsn $(srctree)/arch/$(SRCARCH)/include/asm arch/$(SRCARCH)/include;
349 endif
350
351 # prepare2 creates a makefile if using a separate output directory
352 prepare2: prepare3 outputmakefile asm-generic
353
354-prepare1: prepare2 include/linux/version.h include/generated/utsrelease.h \
355+prepare1: prepare2 include/generated/linux/version.h include/generated/utsrelease.h \
356 include/config/auto.conf
357 $(cmd_crmodverdir)
358
359@@ -985,6 +1039,7 @@ prepare0: archprepare FORCE
360 $(Q)$(MAKE) $(build)=.
361
362 # All the preparing..
363+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
364 prepare: prepare0
365
366 # Generate some files
367@@ -1008,7 +1063,7 @@ define filechk_version.h
368 echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))';)
369 endef
370
371-include/linux/version.h: $(srctree)/Makefile FORCE
372+include/generated/linux/version.h: $(srctree)/Makefile FORCE
373 $(call filechk,version.h)
374
375 include/generated/utsrelease.h: include/config/kernel.release FORCE
376@@ -1050,7 +1105,7 @@ PHONY += archheaders
377 archheaders:
378
379 PHONY += __headers
380-__headers: include/linux/version.h scripts_basic asm-generic archheaders FORCE
381+__headers: include/generated/linux/version.h scripts_basic asm-generic archheaders FORCE
382 $(Q)$(MAKE) $(build)=scripts build_unifdef
383
384 PHONY += headers_install_all
385@@ -1089,6 +1144,8 @@ all: modules
386 # using awk while concatenating to the final file.
387
388 PHONY += modules
389+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
390+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
391 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
392 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
393 @$(kecho) ' Building modules, stage 2.';
394@@ -1104,7 +1161,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
395
396 # Target to prepare building external modules
397 PHONY += modules_prepare
398-modules_prepare: prepare scripts
399+modules_prepare: gcc-plugins prepare scripts
400
401 # Target to install modules
402 PHONY += modules_install
403@@ -1163,7 +1220,7 @@ CLEAN_FILES += vmlinux System.map \
404 MRPROPER_DIRS += include/config usr/include include/generated \
405 arch/*/include/generated
406 MRPROPER_FILES += .config .config.old .version .old_version \
407- include/linux/version.h \
408+ include/generated/linux/version.h \
409 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
410
411 # clean - Delete most, but leave enough to build external modules
412@@ -1201,6 +1258,7 @@ distclean: mrproper
413 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
414 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
415 -o -name '.*.rej' \
416+ -o -name '.*.rej' -o -name '*.so' \
417 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
418 -type f -print | xargs rm -f
419
420@@ -1361,6 +1419,8 @@ PHONY += $(module-dirs) modules
421 $(module-dirs): crmodverdir $(objtree)/Module.symvers
422 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
423
424+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
425+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
426 modules: $(module-dirs)
427 @$(kecho) ' Building modules, stage 2.';
428 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
429@@ -1487,17 +1547,21 @@ else
430 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
431 endif
432
433-%.s: %.c prepare scripts FORCE
434+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
435+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
436+%.s: %.c gcc-plugins prepare scripts FORCE
437 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
438 %.i: %.c prepare scripts FORCE
439 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
440-%.o: %.c prepare scripts FORCE
441+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
442+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
443+%.o: %.c gcc-plugins prepare scripts FORCE
444 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
445 %.lst: %.c prepare scripts FORCE
446 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
447-%.s: %.S prepare scripts FORCE
448+%.s: %.S gcc-plugins prepare scripts FORCE
449 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
450-%.o: %.S prepare scripts FORCE
451+%.o: %.S gcc-plugins prepare scripts FORCE
452 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
453 %.symtypes: %.c prepare scripts FORCE
454 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
455@@ -1507,11 +1571,15 @@ endif
456 $(cmd_crmodverdir)
457 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
458 $(build)=$(build-dir)
459-%/: prepare scripts FORCE
460+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
461+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
462+%/: gcc-plugins prepare scripts FORCE
463 $(cmd_crmodverdir)
464 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
465 $(build)=$(build-dir)
466-%.ko: prepare scripts FORCE
467+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
468+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
469+%.ko: gcc-plugins prepare scripts FORCE
470 $(cmd_crmodverdir)
471 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
472 $(build)=$(build-dir) $(@:.ko=.o)
473diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
474index 640f909..48b6597 100644
475--- a/arch/alpha/include/asm/atomic.h
476+++ b/arch/alpha/include/asm/atomic.h
477@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
478 #define atomic_dec(v) atomic_sub(1,(v))
479 #define atomic64_dec(v) atomic64_sub(1,(v))
480
481+#define atomic64_read_unchecked(v) atomic64_read(v)
482+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
483+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
484+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
485+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
486+#define atomic64_inc_unchecked(v) atomic64_inc(v)
487+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
488+#define atomic64_dec_unchecked(v) atomic64_dec(v)
489+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
490+
491 #define smp_mb__before_atomic_dec() smp_mb()
492 #define smp_mb__after_atomic_dec() smp_mb()
493 #define smp_mb__before_atomic_inc() smp_mb()
494diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
495index ad368a9..fbe0f25 100644
496--- a/arch/alpha/include/asm/cache.h
497+++ b/arch/alpha/include/asm/cache.h
498@@ -4,19 +4,19 @@
499 #ifndef __ARCH_ALPHA_CACHE_H
500 #define __ARCH_ALPHA_CACHE_H
501
502+#include <linux/const.h>
503
504 /* Bytes per L1 (data) cache line. */
505 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
506-# define L1_CACHE_BYTES 64
507 # define L1_CACHE_SHIFT 6
508 #else
509 /* Both EV4 and EV5 are write-through, read-allocate,
510 direct-mapped, physical.
511 */
512-# define L1_CACHE_BYTES 32
513 # define L1_CACHE_SHIFT 5
514 #endif
515
516+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
517 #define SMP_CACHE_BYTES L1_CACHE_BYTES
518
519 #endif
520diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
521index da5449e..7418343 100644
522--- a/arch/alpha/include/asm/elf.h
523+++ b/arch/alpha/include/asm/elf.h
524@@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
525
526 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
527
528+#ifdef CONFIG_PAX_ASLR
529+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
530+
531+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
532+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
533+#endif
534+
535 /* $0 is set by ld.so to a pointer to a function which might be
536 registered using atexit. This provides a mean for the dynamic
537 linker to call DT_FINI functions for shared libraries that have
538diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
539index bc2a0da..8ad11ee 100644
540--- a/arch/alpha/include/asm/pgalloc.h
541+++ b/arch/alpha/include/asm/pgalloc.h
542@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
543 pgd_set(pgd, pmd);
544 }
545
546+static inline void
547+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
548+{
549+ pgd_populate(mm, pgd, pmd);
550+}
551+
552 extern pgd_t *pgd_alloc(struct mm_struct *mm);
553
554 static inline void
555diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
556index de98a73..bd4f1f8 100644
557--- a/arch/alpha/include/asm/pgtable.h
558+++ b/arch/alpha/include/asm/pgtable.h
559@@ -101,6 +101,17 @@ struct vm_area_struct;
560 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
561 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
562 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
563+
564+#ifdef CONFIG_PAX_PAGEEXEC
565+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
566+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
567+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
568+#else
569+# define PAGE_SHARED_NOEXEC PAGE_SHARED
570+# define PAGE_COPY_NOEXEC PAGE_COPY
571+# define PAGE_READONLY_NOEXEC PAGE_READONLY
572+#endif
573+
574 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
575
576 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
577diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
578index 2fd00b7..cfd5069 100644
579--- a/arch/alpha/kernel/module.c
580+++ b/arch/alpha/kernel/module.c
581@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
582
583 /* The small sections were sorted to the end of the segment.
584 The following should definitely cover them. */
585- gp = (u64)me->module_core + me->core_size - 0x8000;
586+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
587 got = sechdrs[me->arch.gotsecindex].sh_addr;
588
589 for (i = 0; i < n; i++) {
590diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
591index 01e8715..be0e80f 100644
592--- a/arch/alpha/kernel/osf_sys.c
593+++ b/arch/alpha/kernel/osf_sys.c
594@@ -1147,7 +1147,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
595 /* At this point: (!vma || addr < vma->vm_end). */
596 if (limit - len < addr)
597 return -ENOMEM;
598- if (!vma || addr + len <= vma->vm_start)
599+ if (check_heap_stack_gap(vma, addr, len))
600 return addr;
601 addr = vma->vm_end;
602 vma = vma->vm_next;
603@@ -1183,6 +1183,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
604 merely specific addresses, but regions of memory -- perhaps
605 this feature should be incorporated into all ports? */
606
607+#ifdef CONFIG_PAX_RANDMMAP
608+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
609+#endif
610+
611 if (addr) {
612 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
613 if (addr != (unsigned long) -ENOMEM)
614@@ -1190,8 +1194,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
615 }
616
617 /* Next, try allocating at TASK_UNMAPPED_BASE. */
618- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
619- len, limit);
620+ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
621+
622 if (addr != (unsigned long) -ENOMEM)
623 return addr;
624
625diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
626index fadd5f8..904e73a 100644
627--- a/arch/alpha/mm/fault.c
628+++ b/arch/alpha/mm/fault.c
629@@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
630 __reload_thread(pcb);
631 }
632
633+#ifdef CONFIG_PAX_PAGEEXEC
634+/*
635+ * PaX: decide what to do with offenders (regs->pc = fault address)
636+ *
637+ * returns 1 when task should be killed
638+ * 2 when patched PLT trampoline was detected
639+ * 3 when unpatched PLT trampoline was detected
640+ */
641+static int pax_handle_fetch_fault(struct pt_regs *regs)
642+{
643+
644+#ifdef CONFIG_PAX_EMUPLT
645+ int err;
646+
647+ do { /* PaX: patched PLT emulation #1 */
648+ unsigned int ldah, ldq, jmp;
649+
650+ err = get_user(ldah, (unsigned int *)regs->pc);
651+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
652+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
653+
654+ if (err)
655+ break;
656+
657+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
658+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
659+ jmp == 0x6BFB0000U)
660+ {
661+ unsigned long r27, addr;
662+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
663+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
664+
665+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
666+ err = get_user(r27, (unsigned long *)addr);
667+ if (err)
668+ break;
669+
670+ regs->r27 = r27;
671+ regs->pc = r27;
672+ return 2;
673+ }
674+ } while (0);
675+
676+ do { /* PaX: patched PLT emulation #2 */
677+ unsigned int ldah, lda, br;
678+
679+ err = get_user(ldah, (unsigned int *)regs->pc);
680+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
681+ err |= get_user(br, (unsigned int *)(regs->pc+8));
682+
683+ if (err)
684+ break;
685+
686+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
687+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
688+ (br & 0xFFE00000U) == 0xC3E00000U)
689+ {
690+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
691+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
692+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
693+
694+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
695+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
696+ return 2;
697+ }
698+ } while (0);
699+
700+ do { /* PaX: unpatched PLT emulation */
701+ unsigned int br;
702+
703+ err = get_user(br, (unsigned int *)regs->pc);
704+
705+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
706+ unsigned int br2, ldq, nop, jmp;
707+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
708+
709+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
710+ err = get_user(br2, (unsigned int *)addr);
711+ err |= get_user(ldq, (unsigned int *)(addr+4));
712+ err |= get_user(nop, (unsigned int *)(addr+8));
713+ err |= get_user(jmp, (unsigned int *)(addr+12));
714+ err |= get_user(resolver, (unsigned long *)(addr+16));
715+
716+ if (err)
717+ break;
718+
719+ if (br2 == 0xC3600000U &&
720+ ldq == 0xA77B000CU &&
721+ nop == 0x47FF041FU &&
722+ jmp == 0x6B7B0000U)
723+ {
724+ regs->r28 = regs->pc+4;
725+ regs->r27 = addr+16;
726+ regs->pc = resolver;
727+ return 3;
728+ }
729+ }
730+ } while (0);
731+#endif
732+
733+ return 1;
734+}
735+
736+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
737+{
738+ unsigned long i;
739+
740+ printk(KERN_ERR "PAX: bytes at PC: ");
741+ for (i = 0; i < 5; i++) {
742+ unsigned int c;
743+ if (get_user(c, (unsigned int *)pc+i))
744+ printk(KERN_CONT "???????? ");
745+ else
746+ printk(KERN_CONT "%08x ", c);
747+ }
748+ printk("\n");
749+}
750+#endif
751
752 /*
753 * This routine handles page faults. It determines the address,
754@@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
755 good_area:
756 si_code = SEGV_ACCERR;
757 if (cause < 0) {
758- if (!(vma->vm_flags & VM_EXEC))
759+ if (!(vma->vm_flags & VM_EXEC)) {
760+
761+#ifdef CONFIG_PAX_PAGEEXEC
762+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
763+ goto bad_area;
764+
765+ up_read(&mm->mmap_sem);
766+ switch (pax_handle_fetch_fault(regs)) {
767+
768+#ifdef CONFIG_PAX_EMUPLT
769+ case 2:
770+ case 3:
771+ return;
772+#endif
773+
774+ }
775+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
776+ do_group_exit(SIGKILL);
777+#else
778 goto bad_area;
779+#endif
780+
781+ }
782 } else if (!cause) {
783 /* Allow reads even for write-only mappings */
784 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
785diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
786index 86976d0..c63ea6b 100644
787--- a/arch/arm/include/asm/atomic.h
788+++ b/arch/arm/include/asm/atomic.h
789@@ -15,6 +15,10 @@
790 #include <linux/types.h>
791 #include <asm/system.h>
792
793+#ifdef CONFIG_GENERIC_ATOMIC64
794+#include <asm-generic/atomic64.h>
795+#endif
796+
797 #define ATOMIC_INIT(i) { (i) }
798
799 #ifdef __KERNEL__
800@@ -25,7 +29,15 @@
801 * atomic_set() is the clrex or dummy strex done on every exception return.
802 */
803 #define atomic_read(v) (*(volatile int *)&(v)->counter)
804+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
805+{
806+ return v->counter;
807+}
808 #define atomic_set(v,i) (((v)->counter) = (i))
809+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
810+{
811+ v->counter = i;
812+}
813
814 #if __LINUX_ARM_ARCH__ >= 6
815
816@@ -40,6 +52,35 @@ static inline void atomic_add(int i, atomic_t *v)
817 int result;
818
819 __asm__ __volatile__("@ atomic_add\n"
820+"1: ldrex %1, [%3]\n"
821+" adds %0, %1, %4\n"
822+
823+#ifdef CONFIG_PAX_REFCOUNT
824+" bvc 3f\n"
825+"2: bkpt 0xf103\n"
826+"3:\n"
827+#endif
828+
829+" strex %1, %0, [%3]\n"
830+" teq %1, #0\n"
831+" bne 1b"
832+
833+#ifdef CONFIG_PAX_REFCOUNT
834+"\n4:\n"
835+ _ASM_EXTABLE(2b, 4b)
836+#endif
837+
838+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
839+ : "r" (&v->counter), "Ir" (i)
840+ : "cc");
841+}
842+
843+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
844+{
845+ unsigned long tmp;
846+ int result;
847+
848+ __asm__ __volatile__("@ atomic_add_unchecked\n"
849 "1: ldrex %0, [%3]\n"
850 " add %0, %0, %4\n"
851 " strex %1, %0, [%3]\n"
852@@ -58,6 +99,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
853 smp_mb();
854
855 __asm__ __volatile__("@ atomic_add_return\n"
856+"1: ldrex %1, [%3]\n"
857+" adds %0, %1, %4\n"
858+
859+#ifdef CONFIG_PAX_REFCOUNT
860+" bvc 3f\n"
861+" mov %0, %1\n"
862+"2: bkpt 0xf103\n"
863+"3:\n"
864+#endif
865+
866+" strex %1, %0, [%3]\n"
867+" teq %1, #0\n"
868+" bne 1b"
869+
870+#ifdef CONFIG_PAX_REFCOUNT
871+"\n4:\n"
872+ _ASM_EXTABLE(2b, 4b)
873+#endif
874+
875+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876+ : "r" (&v->counter), "Ir" (i)
877+ : "cc");
878+
879+ smp_mb();
880+
881+ return result;
882+}
883+
884+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
885+{
886+ unsigned long tmp;
887+ int result;
888+
889+ smp_mb();
890+
891+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
892 "1: ldrex %0, [%3]\n"
893 " add %0, %0, %4\n"
894 " strex %1, %0, [%3]\n"
895@@ -78,6 +155,35 @@ static inline void atomic_sub(int i, atomic_t *v)
896 int result;
897
898 __asm__ __volatile__("@ atomic_sub\n"
899+"1: ldrex %1, [%3]\n"
900+" subs %0, %1, %4\n"
901+
902+#ifdef CONFIG_PAX_REFCOUNT
903+" bvc 3f\n"
904+"2: bkpt 0xf103\n"
905+"3:\n"
906+#endif
907+
908+" strex %1, %0, [%3]\n"
909+" teq %1, #0\n"
910+" bne 1b"
911+
912+#ifdef CONFIG_PAX_REFCOUNT
913+"\n4:\n"
914+ _ASM_EXTABLE(2b, 4b)
915+#endif
916+
917+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
918+ : "r" (&v->counter), "Ir" (i)
919+ : "cc");
920+}
921+
922+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
923+{
924+ unsigned long tmp;
925+ int result;
926+
927+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
928 "1: ldrex %0, [%3]\n"
929 " sub %0, %0, %4\n"
930 " strex %1, %0, [%3]\n"
931@@ -96,11 +202,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
932 smp_mb();
933
934 __asm__ __volatile__("@ atomic_sub_return\n"
935-"1: ldrex %0, [%3]\n"
936-" sub %0, %0, %4\n"
937+"1: ldrex %1, [%3]\n"
938+" sub %0, %1, %4\n"
939+
940+#ifdef CONFIG_PAX_REFCOUNT
941+" bvc 3f\n"
942+" mov %0, %1\n"
943+"2: bkpt 0xf103\n"
944+"3:\n"
945+#endif
946+
947 " strex %1, %0, [%3]\n"
948 " teq %1, #0\n"
949 " bne 1b"
950+
951+#ifdef CONFIG_PAX_REFCOUNT
952+"\n4:\n"
953+ _ASM_EXTABLE(2b, 4b)
954+#endif
955+
956 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
957 : "r" (&v->counter), "Ir" (i)
958 : "cc");
959@@ -132,6 +252,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
960 return oldval;
961 }
962
963+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
964+{
965+ unsigned long oldval, res;
966+
967+ smp_mb();
968+
969+ do {
970+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
971+ "ldrex %1, [%3]\n"
972+ "mov %0, #0\n"
973+ "teq %1, %4\n"
974+ "strexeq %0, %5, [%3]\n"
975+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
976+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
977+ : "cc");
978+ } while (res);
979+
980+ smp_mb();
981+
982+ return oldval;
983+}
984+
985 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
986 {
987 unsigned long tmp, tmp2;
988@@ -165,7 +307,9 @@ static inline int atomic_add_return(int i, atomic_t *v)
989
990 return val;
991 }
992+#define atomic_add_return_unchecked(i, v) atomic_add_return(i, v)
993 #define atomic_add(i, v) (void) atomic_add_return(i, v)
994+#define atomic_add_unchecked(i, v) (void) atomic_add_return_unchecked(i, v)
995
996 static inline int atomic_sub_return(int i, atomic_t *v)
997 {
998@@ -179,7 +323,9 @@ static inline int atomic_sub_return(int i, atomic_t *v)
999
1000 return val;
1001 }
1002+#define atomic_sub_return_unchecked(i, v) atomic_sub_return(i, v)
1003 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1004+#define atomic_sub_unchecked(i, v) (void) atomic_sub_return_unchecked(i, v)
1005
1006 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1007 {
1008@@ -194,6 +340,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1009
1010 return ret;
1011 }
1012+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg(v, o, n)
1013
1014 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1015 {
1016@@ -207,6 +354,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1017 #endif /* __LINUX_ARM_ARCH__ */
1018
1019 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1020+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1021+{
1022+ return xchg(&v->counter, new);
1023+}
1024
1025 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1026 {
1027@@ -219,11 +370,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1028 }
1029
1030 #define atomic_inc(v) atomic_add(1, v)
1031+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1032+{
1033+ atomic_add_unchecked(1, v);
1034+}
1035 #define atomic_dec(v) atomic_sub(1, v)
1036+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1037+{
1038+ atomic_sub_unchecked(1, v);
1039+}
1040
1041 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1042+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1043+{
1044+ return atomic_add_return_unchecked(1, v) == 0;
1045+}
1046 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1047 #define atomic_inc_return(v) (atomic_add_return(1, v))
1048+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1049+{
1050+ return atomic_add_return_unchecked(1, v);
1051+}
1052 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1053 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1054
1055@@ -239,6 +406,14 @@ typedef struct {
1056 u64 __aligned(8) counter;
1057 } atomic64_t;
1058
1059+#ifdef CONFIG_PAX_REFCOUNT
1060+typedef struct {
1061+ u64 __aligned(8) counter;
1062+} atomic64_unchecked_t;
1063+#else
1064+typedef atomic64_t atomic64_unchecked_t;
1065+#endif
1066+
1067 #define ATOMIC64_INIT(i) { (i) }
1068
1069 static inline u64 atomic64_read(atomic64_t *v)
1070@@ -254,6 +429,19 @@ static inline u64 atomic64_read(atomic64_t *v)
1071 return result;
1072 }
1073
1074+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1075+{
1076+ u64 result;
1077+
1078+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1079+" ldrexd %0, %H0, [%1]"
1080+ : "=&r" (result)
1081+ : "r" (&v->counter), "Qo" (v->counter)
1082+ );
1083+
1084+ return result;
1085+}
1086+
1087 static inline void atomic64_set(atomic64_t *v, u64 i)
1088 {
1089 u64 tmp;
1090@@ -268,6 +456,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1091 : "cc");
1092 }
1093
1094+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1095+{
1096+ u64 tmp;
1097+
1098+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1099+"1: ldrexd %0, %H0, [%2]\n"
1100+" strexd %0, %3, %H3, [%2]\n"
1101+" teq %0, #0\n"
1102+" bne 1b"
1103+ : "=&r" (tmp), "=Qo" (v->counter)
1104+ : "r" (&v->counter), "r" (i)
1105+ : "cc");
1106+}
1107+
1108 static inline void atomic64_add(u64 i, atomic64_t *v)
1109 {
1110 u64 result;
1111@@ -276,6 +478,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1112 __asm__ __volatile__("@ atomic64_add\n"
1113 "1: ldrexd %0, %H0, [%3]\n"
1114 " adds %0, %0, %4\n"
1115+" adcs %H0, %H0, %H4\n"
1116+
1117+#ifdef CONFIG_PAX_REFCOUNT
1118+" bvc 3f\n"
1119+"2: bkpt 0xf103\n"
1120+"3:\n"
1121+#endif
1122+
1123+" strexd %1, %0, %H0, [%3]\n"
1124+" teq %1, #0\n"
1125+" bne 1b"
1126+
1127+#ifdef CONFIG_PAX_REFCOUNT
1128+"\n4:\n"
1129+ _ASM_EXTABLE(2b, 4b)
1130+#endif
1131+
1132+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1133+ : "r" (&v->counter), "r" (i)
1134+ : "cc");
1135+}
1136+
1137+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1138+{
1139+ u64 result;
1140+ unsigned long tmp;
1141+
1142+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1143+"1: ldrexd %0, %H0, [%3]\n"
1144+" adds %0, %0, %4\n"
1145 " adc %H0, %H0, %H4\n"
1146 " strexd %1, %0, %H0, [%3]\n"
1147 " teq %1, #0\n"
1148@@ -287,12 +519,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1149
1150 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1151 {
1152- u64 result;
1153- unsigned long tmp;
1154+ u64 result, tmp;
1155
1156 smp_mb();
1157
1158 __asm__ __volatile__("@ atomic64_add_return\n"
1159+"1: ldrexd %1, %H1, [%3]\n"
1160+" adds %0, %1, %4\n"
1161+" adcs %H0, %H1, %H4\n"
1162+
1163+#ifdef CONFIG_PAX_REFCOUNT
1164+" bvc 3f\n"
1165+" mov %0, %1\n"
1166+" mov %H0, %H1\n"
1167+"2: bkpt 0xf103\n"
1168+"3:\n"
1169+#endif
1170+
1171+" strexd %1, %0, %H0, [%3]\n"
1172+" teq %1, #0\n"
1173+" bne 1b"
1174+
1175+#ifdef CONFIG_PAX_REFCOUNT
1176+"\n4:\n"
1177+ _ASM_EXTABLE(2b, 4b)
1178+#endif
1179+
1180+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1181+ : "r" (&v->counter), "r" (i)
1182+ : "cc");
1183+
1184+ smp_mb();
1185+
1186+ return result;
1187+}
1188+
1189+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1190+{
1191+ u64 result;
1192+ unsigned long tmp;
1193+
1194+ smp_mb();
1195+
1196+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1197 "1: ldrexd %0, %H0, [%3]\n"
1198 " adds %0, %0, %4\n"
1199 " adc %H0, %H0, %H4\n"
1200@@ -316,6 +585,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1201 __asm__ __volatile__("@ atomic64_sub\n"
1202 "1: ldrexd %0, %H0, [%3]\n"
1203 " subs %0, %0, %4\n"
1204+" sbcs %H0, %H0, %H4\n"
1205+
1206+#ifdef CONFIG_PAX_REFCOUNT
1207+" bvc 3f\n"
1208+"2: bkpt 0xf103\n"
1209+"3:\n"
1210+#endif
1211+
1212+" strexd %1, %0, %H0, [%3]\n"
1213+" teq %1, #0\n"
1214+" bne 1b"
1215+
1216+#ifdef CONFIG_PAX_REFCOUNT
1217+"\n4:\n"
1218+ _ASM_EXTABLE(2b, 4b)
1219+#endif
1220+
1221+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1222+ : "r" (&v->counter), "r" (i)
1223+ : "cc");
1224+}
1225+
1226+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1227+{
1228+ u64 result;
1229+ unsigned long tmp;
1230+
1231+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1232+"1: ldrexd %0, %H0, [%3]\n"
1233+" subs %0, %0, %4\n"
1234 " sbc %H0, %H0, %H4\n"
1235 " strexd %1, %0, %H0, [%3]\n"
1236 " teq %1, #0\n"
1237@@ -327,18 +626,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1238
1239 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1240 {
1241- u64 result;
1242- unsigned long tmp;
1243+ u64 result, tmp;
1244
1245 smp_mb();
1246
1247 __asm__ __volatile__("@ atomic64_sub_return\n"
1248-"1: ldrexd %0, %H0, [%3]\n"
1249-" subs %0, %0, %4\n"
1250-" sbc %H0, %H0, %H4\n"
1251+"1: ldrexd %1, %H1, [%3]\n"
1252+" subs %0, %1, %4\n"
1253+" sbc %H0, %H1, %H4\n"
1254+
1255+#ifdef CONFIG_PAX_REFCOUNT
1256+" bvc 3f\n"
1257+" mov %0, %1\n"
1258+" mov %H0, %H1\n"
1259+"2: bkpt 0xf103\n"
1260+"3:\n"
1261+#endif
1262+
1263 " strexd %1, %0, %H0, [%3]\n"
1264 " teq %1, #0\n"
1265 " bne 1b"
1266+
1267+#ifdef CONFIG_PAX_REFCOUNT
1268+"\n4:\n"
1269+ _ASM_EXTABLE(2b, 4b)
1270+#endif
1271+
1272 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1273 : "r" (&v->counter), "r" (i)
1274 : "cc");
1275@@ -372,6 +685,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1276 return oldval;
1277 }
1278
1279+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1280+{
1281+ u64 oldval;
1282+ unsigned long res;
1283+
1284+ smp_mb();
1285+
1286+ do {
1287+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1288+ "ldrexd %1, %H1, [%3]\n"
1289+ "mov %0, #0\n"
1290+ "teq %1, %4\n"
1291+ "teqeq %H1, %H4\n"
1292+ "strexdeq %0, %5, %H5, [%3]"
1293+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1294+ : "r" (&ptr->counter), "r" (old), "r" (new)
1295+ : "cc");
1296+ } while (res);
1297+
1298+ smp_mb();
1299+
1300+ return oldval;
1301+}
1302+
1303 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1304 {
1305 u64 result;
1306@@ -395,21 +732,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1307
1308 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1309 {
1310- u64 result;
1311- unsigned long tmp;
1312+ u64 result, tmp;
1313
1314 smp_mb();
1315
1316 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1317-"1: ldrexd %0, %H0, [%3]\n"
1318-" subs %0, %0, #1\n"
1319-" sbc %H0, %H0, #0\n"
1320+"1: ldrexd %1, %H1, [%3]\n"
1321+" subs %0, %1, #1\n"
1322+" sbc %H0, %H1, #0\n"
1323+
1324+#ifdef CONFIG_PAX_REFCOUNT
1325+" bvc 3f\n"
1326+" mov %0, %1\n"
1327+" mov %H0, %H1\n"
1328+"2: bkpt 0xf103\n"
1329+"3:\n"
1330+#endif
1331+
1332 " teq %H0, #0\n"
1333-" bmi 2f\n"
1334+" bmi 4f\n"
1335 " strexd %1, %0, %H0, [%3]\n"
1336 " teq %1, #0\n"
1337 " bne 1b\n"
1338-"2:"
1339+"4:\n"
1340+
1341+#ifdef CONFIG_PAX_REFCOUNT
1342+ _ASM_EXTABLE(2b, 4b)
1343+#endif
1344+
1345 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1346 : "r" (&v->counter)
1347 : "cc");
1348@@ -432,13 +782,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1349 " teq %0, %5\n"
1350 " teqeq %H0, %H5\n"
1351 " moveq %1, #0\n"
1352-" beq 2f\n"
1353+" beq 4f\n"
1354 " adds %0, %0, %6\n"
1355 " adc %H0, %H0, %H6\n"
1356+
1357+#ifdef CONFIG_PAX_REFCOUNT
1358+" bvc 3f\n"
1359+"2: bkpt 0xf103\n"
1360+"3:\n"
1361+#endif
1362+
1363 " strexd %2, %0, %H0, [%4]\n"
1364 " teq %2, #0\n"
1365 " bne 1b\n"
1366-"2:"
1367+"4:\n"
1368+
1369+#ifdef CONFIG_PAX_REFCOUNT
1370+ _ASM_EXTABLE(2b, 4b)
1371+#endif
1372+
1373 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1374 : "r" (&v->counter), "r" (u), "r" (a)
1375 : "cc");
1376@@ -451,10 +813,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1377
1378 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1379 #define atomic64_inc(v) atomic64_add(1LL, (v))
1380+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1381 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1382+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1383 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1384 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1385 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1386+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1387 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1388 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1389 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1390diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1391index 75fe66b..2255c86 100644
1392--- a/arch/arm/include/asm/cache.h
1393+++ b/arch/arm/include/asm/cache.h
1394@@ -4,8 +4,10 @@
1395 #ifndef __ASMARM_CACHE_H
1396 #define __ASMARM_CACHE_H
1397
1398+#include <linux/const.h>
1399+
1400 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1401-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1402+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1403
1404 /*
1405 * Memory returned by kmalloc() may be used for DMA, so we must make
1406diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1407index d5d8d5c..ad92c96 100644
1408--- a/arch/arm/include/asm/cacheflush.h
1409+++ b/arch/arm/include/asm/cacheflush.h
1410@@ -108,7 +108,7 @@ struct cpu_cache_fns {
1411 void (*dma_unmap_area)(const void *, size_t, int);
1412
1413 void (*dma_flush_range)(const void *, const void *);
1414-};
1415+} __no_const;
1416
1417 /*
1418 * Select the calling method
1419diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1420index 0e9ce8d..6ef1e03 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,10 +133,6 @@ 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 extern int vectors_user_mapping(void);
1448 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
1449 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
1450diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1451index e51b1e8..32a3113 100644
1452--- a/arch/arm/include/asm/kmap_types.h
1453+++ b/arch/arm/include/asm/kmap_types.h
1454@@ -21,6 +21,7 @@ enum km_type {
1455 KM_L1_CACHE,
1456 KM_L2_CACHE,
1457 KM_KDB,
1458+ KM_CLEARPAGE,
1459 KM_TYPE_NR
1460 };
1461
1462diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1463index 53426c6..c7baff3 100644
1464--- a/arch/arm/include/asm/outercache.h
1465+++ b/arch/arm/include/asm/outercache.h
1466@@ -35,7 +35,7 @@ struct outer_cache_fns {
1467 #endif
1468 void (*set_debug)(unsigned long);
1469 void (*resume)(void);
1470-};
1471+} __no_const;
1472
1473 #ifdef CONFIG_OUTER_CACHE
1474
1475diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1476index 97b440c..b7ff179 100644
1477--- a/arch/arm/include/asm/page.h
1478+++ b/arch/arm/include/asm/page.h
1479@@ -123,7 +123,7 @@ struct cpu_user_fns {
1480 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1481 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1482 unsigned long vaddr, struct vm_area_struct *vma);
1483-};
1484+} __no_const;
1485
1486 #ifdef MULTI_USER
1487 extern struct cpu_user_fns cpu_user;
1488diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1489index 943504f..bf8d667 100644
1490--- a/arch/arm/include/asm/pgalloc.h
1491+++ b/arch/arm/include/asm/pgalloc.h
1492@@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1493 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1494 }
1495
1496+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1497+{
1498+ pud_populate(mm, pud, pmd);
1499+}
1500+
1501 #else /* !CONFIG_ARM_LPAE */
1502
1503 /*
1504@@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1505 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1506 #define pmd_free(mm, pmd) do { } while (0)
1507 #define pud_populate(mm,pmd,pte) BUG()
1508+#define pud_populate_kernel(mm,pmd,pte) BUG()
1509
1510 #endif /* CONFIG_ARM_LPAE */
1511
1512diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
1513index e4c96cc..1145653 100644
1514--- a/arch/arm/include/asm/system.h
1515+++ b/arch/arm/include/asm/system.h
1516@@ -98,6 +98,8 @@ void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
1517
1518 #define xchg(ptr,x) \
1519 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1520+#define xchg_unchecked(ptr,x) \
1521+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1522
1523 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
1524
1525@@ -534,6 +536,13 @@ static inline unsigned long long __cmpxchg64_mb(volatile void *ptr,
1526
1527 #endif /* __LINUX_ARM_ARCH__ >= 6 */
1528
1529+#define _ASM_EXTABLE(from, to) \
1530+" .pushsection __ex_table,\"a\"\n"\
1531+" .align 3\n" \
1532+" .long " #from ", " #to"\n" \
1533+" .popsection"
1534+
1535+
1536 #endif /* __ASSEMBLY__ */
1537
1538 #define arch_align_stack(x) (x)
1539diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1540index d4c24d4..4ac53e8 100644
1541--- a/arch/arm/include/asm/thread_info.h
1542+++ b/arch/arm/include/asm/thread_info.h
1543@@ -141,6 +141,12 @@ extern void vfp_flush_hwstate(struct thread_info *);
1544 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1545 #define TIF_SYSCALL_TRACE 8
1546 #define TIF_SYSCALL_AUDIT 9
1547+
1548+/* within 8 bits of TIF_SYSCALL_TRACE
1549+ to meet flexible second operand requirements
1550+*/
1551+#define TIF_GRSEC_SETXID 10
1552+
1553 #define TIF_POLLING_NRFLAG 16
1554 #define TIF_USING_IWMMXT 17
1555 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1556@@ -156,9 +162,11 @@ extern void vfp_flush_hwstate(struct thread_info *);
1557 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1558 #define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
1559 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1560+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1561
1562 /* Checks for any syscall work in entry-common.S */
1563-#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1564+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1565+ _TIF_GRSEC_SETXID)
1566
1567 /*
1568 * Change these and you break ASM code in entry-common.S
1569diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1570index 2958976..12ccac4 100644
1571--- a/arch/arm/include/asm/uaccess.h
1572+++ b/arch/arm/include/asm/uaccess.h
1573@@ -22,6 +22,8 @@
1574 #define VERIFY_READ 0
1575 #define VERIFY_WRITE 1
1576
1577+extern void check_object_size(const void *ptr, unsigned long n, bool to);
1578+
1579 /*
1580 * The exception table consists of pairs of addresses: the first is the
1581 * address of an instruction that is allowed to fault, and the second is
1582@@ -387,8 +389,23 @@ do { \
1583
1584
1585 #ifdef CONFIG_MMU
1586-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1587-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1588+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1589+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1590+
1591+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1592+{
1593+ if (!__builtin_constant_p(n))
1594+ check_object_size(to, n, false);
1595+ return ___copy_from_user(to, from, n);
1596+}
1597+
1598+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1599+{
1600+ if (!__builtin_constant_p(n))
1601+ check_object_size(from, n, true);
1602+ return ___copy_to_user(to, from, n);
1603+}
1604+
1605 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1606 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1607 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1608@@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1609
1610 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1611 {
1612+ if ((long)n < 0)
1613+ return n;
1614+
1615 if (access_ok(VERIFY_READ, from, n))
1616 n = __copy_from_user(to, from, n);
1617 else /* security hole - plug it */
1618@@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1619
1620 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1621 {
1622+ if ((long)n < 0)
1623+ return n;
1624+
1625 if (access_ok(VERIFY_WRITE, to, n))
1626 n = __copy_to_user(to, from, n);
1627 return n;
1628diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1629index 5b0bce6..becd81c 100644
1630--- a/arch/arm/kernel/armksyms.c
1631+++ b/arch/arm/kernel/armksyms.c
1632@@ -95,8 +95,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1633 #ifdef CONFIG_MMU
1634 EXPORT_SYMBOL(copy_page);
1635
1636-EXPORT_SYMBOL(__copy_from_user);
1637-EXPORT_SYMBOL(__copy_to_user);
1638+EXPORT_SYMBOL(___copy_from_user);
1639+EXPORT_SYMBOL(___copy_to_user);
1640 EXPORT_SYMBOL(__clear_user);
1641
1642 EXPORT_SYMBOL(__get_user_1);
1643diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1644index 971d65c..cc936fb 100644
1645--- a/arch/arm/kernel/process.c
1646+++ b/arch/arm/kernel/process.c
1647@@ -28,7 +28,6 @@
1648 #include <linux/tick.h>
1649 #include <linux/utsname.h>
1650 #include <linux/uaccess.h>
1651-#include <linux/random.h>
1652 #include <linux/hw_breakpoint.h>
1653 #include <linux/cpuidle.h>
1654
1655@@ -273,9 +272,10 @@ void machine_power_off(void)
1656 machine_shutdown();
1657 if (pm_power_off)
1658 pm_power_off();
1659+ BUG();
1660 }
1661
1662-void machine_restart(char *cmd)
1663+__noreturn void machine_restart(char *cmd)
1664 {
1665 machine_shutdown();
1666
1667@@ -517,12 +517,6 @@ unsigned long get_wchan(struct task_struct *p)
1668 return 0;
1669 }
1670
1671-unsigned long arch_randomize_brk(struct mm_struct *mm)
1672-{
1673- unsigned long range_end = mm->brk + 0x02000000;
1674- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1675-}
1676-
1677 #ifdef CONFIG_MMU
1678 /*
1679 * The vectors page is always readable from user space for the
1680diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1681index f5ce8ab..4b73893 100644
1682--- a/arch/arm/kernel/ptrace.c
1683+++ b/arch/arm/kernel/ptrace.c
1684@@ -905,10 +905,19 @@ long arch_ptrace(struct task_struct *child, long request,
1685 return ret;
1686 }
1687
1688+#ifdef CONFIG_GRKERNSEC_SETXID
1689+extern void gr_delayed_cred_worker(void);
1690+#endif
1691+
1692 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1693 {
1694 unsigned long ip;
1695
1696+#ifdef CONFIG_GRKERNSEC_SETXID
1697+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1698+ gr_delayed_cred_worker();
1699+#endif
1700+
1701 if (why)
1702 audit_syscall_exit(regs);
1703 else
1704diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1705index a255c39..4a19b25 100644
1706--- a/arch/arm/kernel/setup.c
1707+++ b/arch/arm/kernel/setup.c
1708@@ -109,13 +109,13 @@ struct processor processor __read_mostly;
1709 struct cpu_tlb_fns cpu_tlb __read_mostly;
1710 #endif
1711 #ifdef MULTI_USER
1712-struct cpu_user_fns cpu_user __read_mostly;
1713+struct cpu_user_fns cpu_user __read_only;
1714 #endif
1715 #ifdef MULTI_CACHE
1716-struct cpu_cache_fns cpu_cache __read_mostly;
1717+struct cpu_cache_fns cpu_cache __read_only;
1718 #endif
1719 #ifdef CONFIG_OUTER_CACHE
1720-struct outer_cache_fns outer_cache __read_mostly;
1721+struct outer_cache_fns outer_cache __read_only;
1722 EXPORT_SYMBOL(outer_cache);
1723 #endif
1724
1725diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1726index f84dfe6..13e94f7 100644
1727--- a/arch/arm/kernel/traps.c
1728+++ b/arch/arm/kernel/traps.c
1729@@ -259,6 +259,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1730
1731 static DEFINE_RAW_SPINLOCK(die_lock);
1732
1733+extern void gr_handle_kernel_exploit(void);
1734+
1735 /*
1736 * This function is protected against re-entrancy.
1737 */
1738@@ -291,6 +293,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1739 panic("Fatal exception in interrupt");
1740 if (panic_on_oops)
1741 panic("Fatal exception");
1742+
1743+ gr_handle_kernel_exploit();
1744+
1745 if (ret != NOTIFY_STOP)
1746 do_exit(SIGSEGV);
1747 }
1748diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1749index 66a477a..bee61d3 100644
1750--- a/arch/arm/lib/copy_from_user.S
1751+++ b/arch/arm/lib/copy_from_user.S
1752@@ -16,7 +16,7 @@
1753 /*
1754 * Prototype:
1755 *
1756- * size_t __copy_from_user(void *to, const void *from, size_t n)
1757+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
1758 *
1759 * Purpose:
1760 *
1761@@ -84,11 +84,11 @@
1762
1763 .text
1764
1765-ENTRY(__copy_from_user)
1766+ENTRY(___copy_from_user)
1767
1768 #include "copy_template.S"
1769
1770-ENDPROC(__copy_from_user)
1771+ENDPROC(___copy_from_user)
1772
1773 .pushsection .fixup,"ax"
1774 .align 0
1775diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1776index 6ee2f67..d1cce76 100644
1777--- a/arch/arm/lib/copy_page.S
1778+++ b/arch/arm/lib/copy_page.S
1779@@ -10,6 +10,7 @@
1780 * ASM optimised string functions
1781 */
1782 #include <linux/linkage.h>
1783+#include <linux/const.h>
1784 #include <asm/assembler.h>
1785 #include <asm/asm-offsets.h>
1786 #include <asm/cache.h>
1787diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1788index d066df6..df28194 100644
1789--- a/arch/arm/lib/copy_to_user.S
1790+++ b/arch/arm/lib/copy_to_user.S
1791@@ -16,7 +16,7 @@
1792 /*
1793 * Prototype:
1794 *
1795- * size_t __copy_to_user(void *to, const void *from, size_t n)
1796+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
1797 *
1798 * Purpose:
1799 *
1800@@ -88,11 +88,11 @@
1801 .text
1802
1803 ENTRY(__copy_to_user_std)
1804-WEAK(__copy_to_user)
1805+WEAK(___copy_to_user)
1806
1807 #include "copy_template.S"
1808
1809-ENDPROC(__copy_to_user)
1810+ENDPROC(___copy_to_user)
1811 ENDPROC(__copy_to_user_std)
1812
1813 .pushsection .fixup,"ax"
1814diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1815index 5c908b1..e712687 100644
1816--- a/arch/arm/lib/uaccess.S
1817+++ b/arch/arm/lib/uaccess.S
1818@@ -20,7 +20,7 @@
1819
1820 #define PAGE_SHIFT 12
1821
1822-/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1823+/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1824 * Purpose : copy a block to user memory from kernel memory
1825 * Params : to - user memory
1826 * : from - kernel memory
1827@@ -40,7 +40,7 @@ USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1828 sub r2, r2, ip
1829 b .Lc2u_dest_aligned
1830
1831-ENTRY(__copy_to_user)
1832+ENTRY(___copy_to_user)
1833 stmfd sp!, {r2, r4 - r7, lr}
1834 cmp r2, #4
1835 blt .Lc2u_not_enough
1836@@ -278,14 +278,14 @@ USER( TUSER( strgeb) r3, [r0], #1) @ May fault
1837 ldrgtb r3, [r1], #0
1838 USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1839 b .Lc2u_finished
1840-ENDPROC(__copy_to_user)
1841+ENDPROC(___copy_to_user)
1842
1843 .pushsection .fixup,"ax"
1844 .align 0
1845 9001: ldmfd sp!, {r0, r4 - r7, pc}
1846 .popsection
1847
1848-/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1849+/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1850 * Purpose : copy a block from user memory to kernel memory
1851 * Params : to - kernel memory
1852 * : from - user memory
1853@@ -304,7 +304,7 @@ USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1854 sub r2, r2, ip
1855 b .Lcfu_dest_aligned
1856
1857-ENTRY(__copy_from_user)
1858+ENTRY(___copy_from_user)
1859 stmfd sp!, {r0, r2, r4 - r7, lr}
1860 cmp r2, #4
1861 blt .Lcfu_not_enough
1862@@ -544,7 +544,7 @@ USER( TUSER( ldrgeb) r3, [r1], #1) @ May fault
1863 USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1864 strgtb r3, [r0], #1
1865 b .Lcfu_finished
1866-ENDPROC(__copy_from_user)
1867+ENDPROC(___copy_from_user)
1868
1869 .pushsection .fixup,"ax"
1870 .align 0
1871diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1872index 025f742..8432b08 100644
1873--- a/arch/arm/lib/uaccess_with_memcpy.c
1874+++ b/arch/arm/lib/uaccess_with_memcpy.c
1875@@ -104,7 +104,7 @@ out:
1876 }
1877
1878 unsigned long
1879-__copy_to_user(void __user *to, const void *from, unsigned long n)
1880+___copy_to_user(void __user *to, const void *from, unsigned long n)
1881 {
1882 /*
1883 * This test is stubbed out of the main function above to keep
1884diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1885index 6722627..8f97548c 100644
1886--- a/arch/arm/mach-omap2/board-n8x0.c
1887+++ b/arch/arm/mach-omap2/board-n8x0.c
1888@@ -597,7 +597,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1889 }
1890 #endif
1891
1892-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1893+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1894 .late_init = n8x0_menelaus_late_init,
1895 };
1896
1897diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
1898index 2b2d51c..0127490 100644
1899--- a/arch/arm/mach-ux500/mbox-db5500.c
1900+++ b/arch/arm/mach-ux500/mbox-db5500.c
1901@@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
1902 return sprintf(buf, "0x%X\n", mbox_value);
1903 }
1904
1905-static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1906+static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1907
1908 static int mbox_show(struct seq_file *s, void *data)
1909 {
1910diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1911index 90e366a..1b92505 100644
1912--- a/arch/arm/mm/fault.c
1913+++ b/arch/arm/mm/fault.c
1914@@ -172,6 +172,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1915 }
1916 #endif
1917
1918+#ifdef CONFIG_PAX_PAGEEXEC
1919+ if (fsr & FSR_LNX_PF) {
1920+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1921+ do_group_exit(SIGKILL);
1922+ }
1923+#endif
1924+
1925 tsk->thread.address = addr;
1926 tsk->thread.error_code = fsr;
1927 tsk->thread.trap_no = 14;
1928@@ -395,6 +402,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1929 }
1930 #endif /* CONFIG_MMU */
1931
1932+#ifdef CONFIG_PAX_PAGEEXEC
1933+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1934+{
1935+ long i;
1936+
1937+ printk(KERN_ERR "PAX: bytes at PC: ");
1938+ for (i = 0; i < 20; i++) {
1939+ unsigned char c;
1940+ if (get_user(c, (__force unsigned char __user *)pc+i))
1941+ printk(KERN_CONT "?? ");
1942+ else
1943+ printk(KERN_CONT "%02x ", c);
1944+ }
1945+ printk("\n");
1946+
1947+ printk(KERN_ERR "PAX: bytes at SP-4: ");
1948+ for (i = -1; i < 20; i++) {
1949+ unsigned long c;
1950+ if (get_user(c, (__force unsigned long __user *)sp+i))
1951+ printk(KERN_CONT "???????? ");
1952+ else
1953+ printk(KERN_CONT "%08lx ", c);
1954+ }
1955+ printk("\n");
1956+}
1957+#endif
1958+
1959 /*
1960 * First Level Translation Fault Handler
1961 *
1962@@ -575,6 +609,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1963 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1964 struct siginfo info;
1965
1966+#ifdef CONFIG_PAX_REFCOUNT
1967+ if (fsr_fs(ifsr) == 2) {
1968+ unsigned int bkpt;
1969+
1970+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1971+ current->thread.error_code = ifsr;
1972+ current->thread.trap_no = 0;
1973+ pax_report_refcount_overflow(regs);
1974+ fixup_exception(regs);
1975+ return;
1976+ }
1977+ }
1978+#endif
1979+
1980 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1981 return;
1982
1983diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1984index ce8cb19..3ec539d 100644
1985--- a/arch/arm/mm/mmap.c
1986+++ b/arch/arm/mm/mmap.c
1987@@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1988 if (len > TASK_SIZE)
1989 return -ENOMEM;
1990
1991+#ifdef CONFIG_PAX_RANDMMAP
1992+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1993+#endif
1994+
1995 if (addr) {
1996 if (do_align)
1997 addr = COLOUR_ALIGN(addr, pgoff);
1998@@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1999 addr = PAGE_ALIGN(addr);
2000
2001 vma = find_vma(mm, addr);
2002- if (TASK_SIZE - len >= addr &&
2003- (!vma || addr + len <= vma->vm_start))
2004+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2005 return addr;
2006 }
2007 if (len > mm->cached_hole_size) {
2008- start_addr = addr = mm->free_area_cache;
2009+ start_addr = addr = mm->free_area_cache;
2010 } else {
2011- start_addr = addr = mm->mmap_base;
2012- mm->cached_hole_size = 0;
2013+ start_addr = addr = mm->mmap_base;
2014+ mm->cached_hole_size = 0;
2015 }
2016
2017 full_search:
2018@@ -124,14 +127,14 @@ full_search:
2019 * Start a new search - just in case we missed
2020 * some holes.
2021 */
2022- if (start_addr != TASK_UNMAPPED_BASE) {
2023- start_addr = addr = TASK_UNMAPPED_BASE;
2024+ if (start_addr != mm->mmap_base) {
2025+ start_addr = addr = mm->mmap_base;
2026 mm->cached_hole_size = 0;
2027 goto full_search;
2028 }
2029 return -ENOMEM;
2030 }
2031- if (!vma || addr + len <= vma->vm_start) {
2032+ if (check_heap_stack_gap(vma, addr, len)) {
2033 /*
2034 * Remember the place where we stopped the search:
2035 */
2036@@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2037
2038 if (mmap_is_legacy()) {
2039 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2040+
2041+#ifdef CONFIG_PAX_RANDMMAP
2042+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2043+ mm->mmap_base += mm->delta_mmap;
2044+#endif
2045+
2046 mm->get_unmapped_area = arch_get_unmapped_area;
2047 mm->unmap_area = arch_unmap_area;
2048 } else {
2049 mm->mmap_base = mmap_base(random_factor);
2050+
2051+#ifdef CONFIG_PAX_RANDMMAP
2052+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2053+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2054+#endif
2055+
2056 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2057 mm->unmap_area = arch_unmap_area_topdown;
2058 }
2059diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2060index 71a6827..e7fbc23 100644
2061--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2062+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2063@@ -43,7 +43,7 @@ struct samsung_dma_ops {
2064 int (*started)(unsigned ch);
2065 int (*flush)(unsigned ch);
2066 int (*stop)(unsigned ch);
2067-};
2068+} __no_const;
2069
2070 extern void *samsung_dmadev_get_ops(void);
2071 extern void *s3c_dma_get_ops(void);
2072diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2073index 5f28cae..3d23723 100644
2074--- a/arch/arm/plat-samsung/include/plat/ehci.h
2075+++ b/arch/arm/plat-samsung/include/plat/ehci.h
2076@@ -14,7 +14,7 @@
2077 struct s5p_ehci_platdata {
2078 int (*phy_init)(struct platform_device *pdev, int type);
2079 int (*phy_exit)(struct platform_device *pdev, int type);
2080-};
2081+} __no_const;
2082
2083 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2084
2085diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2086index c3a58a1..78fbf54 100644
2087--- a/arch/avr32/include/asm/cache.h
2088+++ b/arch/avr32/include/asm/cache.h
2089@@ -1,8 +1,10 @@
2090 #ifndef __ASM_AVR32_CACHE_H
2091 #define __ASM_AVR32_CACHE_H
2092
2093+#include <linux/const.h>
2094+
2095 #define L1_CACHE_SHIFT 5
2096-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2097+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2098
2099 /*
2100 * Memory returned by kmalloc() may be used for DMA, so we must make
2101diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2102index 3b3159b..425ea94 100644
2103--- a/arch/avr32/include/asm/elf.h
2104+++ b/arch/avr32/include/asm/elf.h
2105@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2106 the loader. We need to make sure that it is out of the way of the program
2107 that it will "exec", and that there is sufficient room for the brk. */
2108
2109-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2110+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2111
2112+#ifdef CONFIG_PAX_ASLR
2113+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2114+
2115+#define PAX_DELTA_MMAP_LEN 15
2116+#define PAX_DELTA_STACK_LEN 15
2117+#endif
2118
2119 /* This yields a mask that user programs can use to figure out what
2120 instruction set this CPU supports. This could be done in user space,
2121diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2122index b7f5c68..556135c 100644
2123--- a/arch/avr32/include/asm/kmap_types.h
2124+++ b/arch/avr32/include/asm/kmap_types.h
2125@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2126 D(11) KM_IRQ1,
2127 D(12) KM_SOFTIRQ0,
2128 D(13) KM_SOFTIRQ1,
2129-D(14) KM_TYPE_NR
2130+D(14) KM_CLEARPAGE,
2131+D(15) KM_TYPE_NR
2132 };
2133
2134 #undef D
2135diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2136index f7040a1..db9f300 100644
2137--- a/arch/avr32/mm/fault.c
2138+++ b/arch/avr32/mm/fault.c
2139@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2140
2141 int exception_trace = 1;
2142
2143+#ifdef CONFIG_PAX_PAGEEXEC
2144+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2145+{
2146+ unsigned long i;
2147+
2148+ printk(KERN_ERR "PAX: bytes at PC: ");
2149+ for (i = 0; i < 20; i++) {
2150+ unsigned char c;
2151+ if (get_user(c, (unsigned char *)pc+i))
2152+ printk(KERN_CONT "???????? ");
2153+ else
2154+ printk(KERN_CONT "%02x ", c);
2155+ }
2156+ printk("\n");
2157+}
2158+#endif
2159+
2160 /*
2161 * This routine handles page faults. It determines the address and the
2162 * problem, and then passes it off to one of the appropriate routines.
2163@@ -156,6 +173,16 @@ bad_area:
2164 up_read(&mm->mmap_sem);
2165
2166 if (user_mode(regs)) {
2167+
2168+#ifdef CONFIG_PAX_PAGEEXEC
2169+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2170+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2171+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2172+ do_group_exit(SIGKILL);
2173+ }
2174+ }
2175+#endif
2176+
2177 if (exception_trace && printk_ratelimit())
2178 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2179 "sp %08lx ecr %lu\n",
2180diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2181index 568885a..f8008df 100644
2182--- a/arch/blackfin/include/asm/cache.h
2183+++ b/arch/blackfin/include/asm/cache.h
2184@@ -7,6 +7,7 @@
2185 #ifndef __ARCH_BLACKFIN_CACHE_H
2186 #define __ARCH_BLACKFIN_CACHE_H
2187
2188+#include <linux/const.h>
2189 #include <linux/linkage.h> /* for asmlinkage */
2190
2191 /*
2192@@ -14,7 +15,7 @@
2193 * Blackfin loads 32 bytes for cache
2194 */
2195 #define L1_CACHE_SHIFT 5
2196-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2197+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2198 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2199
2200 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2201diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2202index aea2718..3639a60 100644
2203--- a/arch/cris/include/arch-v10/arch/cache.h
2204+++ b/arch/cris/include/arch-v10/arch/cache.h
2205@@ -1,8 +1,9 @@
2206 #ifndef _ASM_ARCH_CACHE_H
2207 #define _ASM_ARCH_CACHE_H
2208
2209+#include <linux/const.h>
2210 /* Etrax 100LX have 32-byte cache-lines. */
2211-#define L1_CACHE_BYTES 32
2212 #define L1_CACHE_SHIFT 5
2213+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2214
2215 #endif /* _ASM_ARCH_CACHE_H */
2216diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2217index 1de779f..336fad3 100644
2218--- a/arch/cris/include/arch-v32/arch/cache.h
2219+++ b/arch/cris/include/arch-v32/arch/cache.h
2220@@ -1,11 +1,12 @@
2221 #ifndef _ASM_CRIS_ARCH_CACHE_H
2222 #define _ASM_CRIS_ARCH_CACHE_H
2223
2224+#include <linux/const.h>
2225 #include <arch/hwregs/dma.h>
2226
2227 /* A cache-line is 32 bytes. */
2228-#define L1_CACHE_BYTES 32
2229 #define L1_CACHE_SHIFT 5
2230+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2231
2232 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2233
2234diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2235index 0d8a7d6..d0c9ff5 100644
2236--- a/arch/frv/include/asm/atomic.h
2237+++ b/arch/frv/include/asm/atomic.h
2238@@ -241,6 +241,16 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
2239 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2240 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2241
2242+#define atomic64_read_unchecked(v) atomic64_read(v)
2243+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2244+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2245+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2246+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2247+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2248+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2249+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2250+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2251+
2252 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2253 {
2254 int c, old;
2255diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2256index 2797163..c2a401d 100644
2257--- a/arch/frv/include/asm/cache.h
2258+++ b/arch/frv/include/asm/cache.h
2259@@ -12,10 +12,11 @@
2260 #ifndef __ASM_CACHE_H
2261 #define __ASM_CACHE_H
2262
2263+#include <linux/const.h>
2264
2265 /* bytes per L1 cache line */
2266 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2267-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2268+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2269
2270 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2271 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2272diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2273index f8e16b2..c73ff79 100644
2274--- a/arch/frv/include/asm/kmap_types.h
2275+++ b/arch/frv/include/asm/kmap_types.h
2276@@ -23,6 +23,7 @@ enum km_type {
2277 KM_IRQ1,
2278 KM_SOFTIRQ0,
2279 KM_SOFTIRQ1,
2280+ KM_CLEARPAGE,
2281 KM_TYPE_NR
2282 };
2283
2284diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2285index 385fd30..6c3d97e 100644
2286--- a/arch/frv/mm/elf-fdpic.c
2287+++ b/arch/frv/mm/elf-fdpic.c
2288@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2289 if (addr) {
2290 addr = PAGE_ALIGN(addr);
2291 vma = find_vma(current->mm, addr);
2292- if (TASK_SIZE - len >= addr &&
2293- (!vma || addr + len <= vma->vm_start))
2294+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2295 goto success;
2296 }
2297
2298@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2299 for (; vma; vma = vma->vm_next) {
2300 if (addr > limit)
2301 break;
2302- if (addr + len <= vma->vm_start)
2303+ if (check_heap_stack_gap(vma, addr, len))
2304 goto success;
2305 addr = vma->vm_end;
2306 }
2307@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2308 for (; vma; vma = vma->vm_next) {
2309 if (addr > limit)
2310 break;
2311- if (addr + len <= vma->vm_start)
2312+ if (check_heap_stack_gap(vma, addr, len))
2313 goto success;
2314 addr = vma->vm_end;
2315 }
2316diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2317index c635028..6d9445a 100644
2318--- a/arch/h8300/include/asm/cache.h
2319+++ b/arch/h8300/include/asm/cache.h
2320@@ -1,8 +1,10 @@
2321 #ifndef __ARCH_H8300_CACHE_H
2322 #define __ARCH_H8300_CACHE_H
2323
2324+#include <linux/const.h>
2325+
2326 /* bytes per L1 cache line */
2327-#define L1_CACHE_BYTES 4
2328+#define L1_CACHE_BYTES _AC(4,UL)
2329
2330 /* m68k-elf-gcc 2.95.2 doesn't like these */
2331
2332diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2333index 0f01de2..d37d309 100644
2334--- a/arch/hexagon/include/asm/cache.h
2335+++ b/arch/hexagon/include/asm/cache.h
2336@@ -21,9 +21,11 @@
2337 #ifndef __ASM_CACHE_H
2338 #define __ASM_CACHE_H
2339
2340+#include <linux/const.h>
2341+
2342 /* Bytes per L1 cache line */
2343-#define L1_CACHE_SHIFT (5)
2344-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2345+#define L1_CACHE_SHIFT 5
2346+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2347
2348 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2349 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2350diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2351index 3fad89e..3047da5 100644
2352--- a/arch/ia64/include/asm/atomic.h
2353+++ b/arch/ia64/include/asm/atomic.h
2354@@ -209,6 +209,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2355 #define atomic64_inc(v) atomic64_add(1, (v))
2356 #define atomic64_dec(v) atomic64_sub(1, (v))
2357
2358+#define atomic64_read_unchecked(v) atomic64_read(v)
2359+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2360+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2361+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2362+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2363+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2364+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2365+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2366+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2367+
2368 /* Atomic operations are already serializing */
2369 #define smp_mb__before_atomic_dec() barrier()
2370 #define smp_mb__after_atomic_dec() barrier()
2371diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2372index 988254a..e1ee885 100644
2373--- a/arch/ia64/include/asm/cache.h
2374+++ b/arch/ia64/include/asm/cache.h
2375@@ -1,6 +1,7 @@
2376 #ifndef _ASM_IA64_CACHE_H
2377 #define _ASM_IA64_CACHE_H
2378
2379+#include <linux/const.h>
2380
2381 /*
2382 * Copyright (C) 1998-2000 Hewlett-Packard Co
2383@@ -9,7 +10,7 @@
2384
2385 /* Bytes per L1 (data) cache line. */
2386 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2387-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2388+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2389
2390 #ifdef CONFIG_SMP
2391 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2392diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2393index b5298eb..67c6e62 100644
2394--- a/arch/ia64/include/asm/elf.h
2395+++ b/arch/ia64/include/asm/elf.h
2396@@ -42,6 +42,13 @@
2397 */
2398 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2399
2400+#ifdef CONFIG_PAX_ASLR
2401+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2402+
2403+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2404+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2405+#endif
2406+
2407 #define PT_IA_64_UNWIND 0x70000001
2408
2409 /* IA-64 relocations: */
2410diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2411index 96a8d92..617a1cf 100644
2412--- a/arch/ia64/include/asm/pgalloc.h
2413+++ b/arch/ia64/include/asm/pgalloc.h
2414@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2415 pgd_val(*pgd_entry) = __pa(pud);
2416 }
2417
2418+static inline void
2419+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2420+{
2421+ pgd_populate(mm, pgd_entry, pud);
2422+}
2423+
2424 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2425 {
2426 return quicklist_alloc(0, GFP_KERNEL, NULL);
2427@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2428 pud_val(*pud_entry) = __pa(pmd);
2429 }
2430
2431+static inline void
2432+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2433+{
2434+ pud_populate(mm, pud_entry, pmd);
2435+}
2436+
2437 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2438 {
2439 return quicklist_alloc(0, GFP_KERNEL, NULL);
2440diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2441index 1a97af3..7529d31 100644
2442--- a/arch/ia64/include/asm/pgtable.h
2443+++ b/arch/ia64/include/asm/pgtable.h
2444@@ -12,7 +12,7 @@
2445 * David Mosberger-Tang <davidm@hpl.hp.com>
2446 */
2447
2448-
2449+#include <linux/const.h>
2450 #include <asm/mman.h>
2451 #include <asm/page.h>
2452 #include <asm/processor.h>
2453@@ -143,6 +143,17 @@
2454 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2455 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2456 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2457+
2458+#ifdef CONFIG_PAX_PAGEEXEC
2459+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2460+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2461+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2462+#else
2463+# define PAGE_SHARED_NOEXEC PAGE_SHARED
2464+# define PAGE_READONLY_NOEXEC PAGE_READONLY
2465+# define PAGE_COPY_NOEXEC PAGE_COPY
2466+#endif
2467+
2468 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2469 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2470 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2471diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2472index b77768d..e0795eb 100644
2473--- a/arch/ia64/include/asm/spinlock.h
2474+++ b/arch/ia64/include/asm/spinlock.h
2475@@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2476 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2477
2478 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2479- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2480+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2481 }
2482
2483 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2484diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2485index 449c8c0..432a3d2 100644
2486--- a/arch/ia64/include/asm/uaccess.h
2487+++ b/arch/ia64/include/asm/uaccess.h
2488@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2489 const void *__cu_from = (from); \
2490 long __cu_len = (n); \
2491 \
2492- if (__access_ok(__cu_to, __cu_len, get_fs())) \
2493+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2494 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2495 __cu_len; \
2496 })
2497@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2498 long __cu_len = (n); \
2499 \
2500 __chk_user_ptr(__cu_from); \
2501- if (__access_ok(__cu_from, __cu_len, get_fs())) \
2502+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2503 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2504 __cu_len; \
2505 })
2506diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2507index 24603be..948052d 100644
2508--- a/arch/ia64/kernel/module.c
2509+++ b/arch/ia64/kernel/module.c
2510@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2511 void
2512 module_free (struct module *mod, void *module_region)
2513 {
2514- if (mod && mod->arch.init_unw_table &&
2515- module_region == mod->module_init) {
2516+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2517 unw_remove_unwind_table(mod->arch.init_unw_table);
2518 mod->arch.init_unw_table = NULL;
2519 }
2520@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2521 }
2522
2523 static inline int
2524+in_init_rx (const struct module *mod, uint64_t addr)
2525+{
2526+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2527+}
2528+
2529+static inline int
2530+in_init_rw (const struct module *mod, uint64_t addr)
2531+{
2532+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2533+}
2534+
2535+static inline int
2536 in_init (const struct module *mod, uint64_t addr)
2537 {
2538- return addr - (uint64_t) mod->module_init < mod->init_size;
2539+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2540+}
2541+
2542+static inline int
2543+in_core_rx (const struct module *mod, uint64_t addr)
2544+{
2545+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2546+}
2547+
2548+static inline int
2549+in_core_rw (const struct module *mod, uint64_t addr)
2550+{
2551+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2552 }
2553
2554 static inline int
2555 in_core (const struct module *mod, uint64_t addr)
2556 {
2557- return addr - (uint64_t) mod->module_core < mod->core_size;
2558+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2559 }
2560
2561 static inline int
2562@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2563 break;
2564
2565 case RV_BDREL:
2566- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2567+ if (in_init_rx(mod, val))
2568+ val -= (uint64_t) mod->module_init_rx;
2569+ else if (in_init_rw(mod, val))
2570+ val -= (uint64_t) mod->module_init_rw;
2571+ else if (in_core_rx(mod, val))
2572+ val -= (uint64_t) mod->module_core_rx;
2573+ else if (in_core_rw(mod, val))
2574+ val -= (uint64_t) mod->module_core_rw;
2575 break;
2576
2577 case RV_LTV:
2578@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2579 * addresses have been selected...
2580 */
2581 uint64_t gp;
2582- if (mod->core_size > MAX_LTOFF)
2583+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2584 /*
2585 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2586 * at the end of the module.
2587 */
2588- gp = mod->core_size - MAX_LTOFF / 2;
2589+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2590 else
2591- gp = mod->core_size / 2;
2592- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2593+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2594+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2595 mod->arch.gp = gp;
2596 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2597 }
2598diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2599index 609d500..7dde2a8 100644
2600--- a/arch/ia64/kernel/sys_ia64.c
2601+++ b/arch/ia64/kernel/sys_ia64.c
2602@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2603 if (REGION_NUMBER(addr) == RGN_HPAGE)
2604 addr = 0;
2605 #endif
2606+
2607+#ifdef CONFIG_PAX_RANDMMAP
2608+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2609+ addr = mm->free_area_cache;
2610+ else
2611+#endif
2612+
2613 if (!addr)
2614 addr = mm->free_area_cache;
2615
2616@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2617 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2618 /* At this point: (!vma || addr < vma->vm_end). */
2619 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2620- if (start_addr != TASK_UNMAPPED_BASE) {
2621+ if (start_addr != mm->mmap_base) {
2622 /* Start a new search --- just in case we missed some holes. */
2623- addr = TASK_UNMAPPED_BASE;
2624+ addr = mm->mmap_base;
2625 goto full_search;
2626 }
2627 return -ENOMEM;
2628 }
2629- if (!vma || addr + len <= vma->vm_start) {
2630+ if (check_heap_stack_gap(vma, addr, len)) {
2631 /* Remember the address where we stopped this search: */
2632 mm->free_area_cache = addr + len;
2633 return addr;
2634diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2635index 53c0ba0..2accdde 100644
2636--- a/arch/ia64/kernel/vmlinux.lds.S
2637+++ b/arch/ia64/kernel/vmlinux.lds.S
2638@@ -199,7 +199,7 @@ SECTIONS {
2639 /* Per-cpu data: */
2640 . = ALIGN(PERCPU_PAGE_SIZE);
2641 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2642- __phys_per_cpu_start = __per_cpu_load;
2643+ __phys_per_cpu_start = per_cpu_load;
2644 /*
2645 * ensure percpu data fits
2646 * into percpu page size
2647diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2648index 20b3593..1ce77f0 100644
2649--- a/arch/ia64/mm/fault.c
2650+++ b/arch/ia64/mm/fault.c
2651@@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
2652 return pte_present(pte);
2653 }
2654
2655+#ifdef CONFIG_PAX_PAGEEXEC
2656+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2657+{
2658+ unsigned long i;
2659+
2660+ printk(KERN_ERR "PAX: bytes at PC: ");
2661+ for (i = 0; i < 8; i++) {
2662+ unsigned int c;
2663+ if (get_user(c, (unsigned int *)pc+i))
2664+ printk(KERN_CONT "???????? ");
2665+ else
2666+ printk(KERN_CONT "%08x ", c);
2667+ }
2668+ printk("\n");
2669+}
2670+#endif
2671+
2672 void __kprobes
2673 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2674 {
2675@@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2676 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2677 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2678
2679- if ((vma->vm_flags & mask) != mask)
2680+ if ((vma->vm_flags & mask) != mask) {
2681+
2682+#ifdef CONFIG_PAX_PAGEEXEC
2683+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2684+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2685+ goto bad_area;
2686+
2687+ up_read(&mm->mmap_sem);
2688+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2689+ do_group_exit(SIGKILL);
2690+ }
2691+#endif
2692+
2693 goto bad_area;
2694
2695+ }
2696+
2697 /*
2698 * If for any reason at all we couldn't handle the fault, make
2699 * sure we exit gracefully rather than endlessly redo the
2700diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2701index 5ca674b..e0e1b70 100644
2702--- a/arch/ia64/mm/hugetlbpage.c
2703+++ b/arch/ia64/mm/hugetlbpage.c
2704@@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2705 /* At this point: (!vmm || addr < vmm->vm_end). */
2706 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2707 return -ENOMEM;
2708- if (!vmm || (addr + len) <= vmm->vm_start)
2709+ if (check_heap_stack_gap(vmm, addr, len))
2710 return addr;
2711 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2712 }
2713diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2714index 13df239d..cb52116 100644
2715--- a/arch/ia64/mm/init.c
2716+++ b/arch/ia64/mm/init.c
2717@@ -121,6 +121,19 @@ ia64_init_addr_space (void)
2718 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2719 vma->vm_end = vma->vm_start + PAGE_SIZE;
2720 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2721+
2722+#ifdef CONFIG_PAX_PAGEEXEC
2723+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2724+ vma->vm_flags &= ~VM_EXEC;
2725+
2726+#ifdef CONFIG_PAX_MPROTECT
2727+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
2728+ vma->vm_flags &= ~VM_MAYEXEC;
2729+#endif
2730+
2731+ }
2732+#endif
2733+
2734 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2735 down_write(&current->mm->mmap_sem);
2736 if (insert_vm_struct(current->mm, vma)) {
2737diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2738index 40b3ee9..8c2c112 100644
2739--- a/arch/m32r/include/asm/cache.h
2740+++ b/arch/m32r/include/asm/cache.h
2741@@ -1,8 +1,10 @@
2742 #ifndef _ASM_M32R_CACHE_H
2743 #define _ASM_M32R_CACHE_H
2744
2745+#include <linux/const.h>
2746+
2747 /* L1 cache line size */
2748 #define L1_CACHE_SHIFT 4
2749-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2750+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2751
2752 #endif /* _ASM_M32R_CACHE_H */
2753diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2754index 82abd15..d95ae5d 100644
2755--- a/arch/m32r/lib/usercopy.c
2756+++ b/arch/m32r/lib/usercopy.c
2757@@ -14,6 +14,9 @@
2758 unsigned long
2759 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2760 {
2761+ if ((long)n < 0)
2762+ return n;
2763+
2764 prefetch(from);
2765 if (access_ok(VERIFY_WRITE, to, n))
2766 __copy_user(to,from,n);
2767@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2768 unsigned long
2769 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2770 {
2771+ if ((long)n < 0)
2772+ return n;
2773+
2774 prefetchw(to);
2775 if (access_ok(VERIFY_READ, from, n))
2776 __copy_user_zeroing(to,from,n);
2777diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2778index 0395c51..5f26031 100644
2779--- a/arch/m68k/include/asm/cache.h
2780+++ b/arch/m68k/include/asm/cache.h
2781@@ -4,9 +4,11 @@
2782 #ifndef __ARCH_M68K_CACHE_H
2783 #define __ARCH_M68K_CACHE_H
2784
2785+#include <linux/const.h>
2786+
2787 /* bytes per L1 cache line */
2788 #define L1_CACHE_SHIFT 4
2789-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2790+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2791
2792 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2793
2794diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2795index 4efe96a..60e8699 100644
2796--- a/arch/microblaze/include/asm/cache.h
2797+++ b/arch/microblaze/include/asm/cache.h
2798@@ -13,11 +13,12 @@
2799 #ifndef _ASM_MICROBLAZE_CACHE_H
2800 #define _ASM_MICROBLAZE_CACHE_H
2801
2802+#include <linux/const.h>
2803 #include <asm/registers.h>
2804
2805 #define L1_CACHE_SHIFT 5
2806 /* word-granular cache in microblaze */
2807-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2808+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2809
2810 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2811
2812diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2813index 1d93f81..67794d0 100644
2814--- a/arch/mips/include/asm/atomic.h
2815+++ b/arch/mips/include/asm/atomic.h
2816@@ -21,6 +21,10 @@
2817 #include <asm/war.h>
2818 #include <asm/system.h>
2819
2820+#ifdef CONFIG_GENERIC_ATOMIC64
2821+#include <asm-generic/atomic64.h>
2822+#endif
2823+
2824 #define ATOMIC_INIT(i) { (i) }
2825
2826 /*
2827@@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2828 */
2829 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2830
2831+#define atomic64_read_unchecked(v) atomic64_read(v)
2832+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2833+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2834+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2835+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2836+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2837+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2838+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2839+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2840+
2841 #endif /* CONFIG_64BIT */
2842
2843 /*
2844diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2845index b4db69f..8f3b093 100644
2846--- a/arch/mips/include/asm/cache.h
2847+++ b/arch/mips/include/asm/cache.h
2848@@ -9,10 +9,11 @@
2849 #ifndef _ASM_CACHE_H
2850 #define _ASM_CACHE_H
2851
2852+#include <linux/const.h>
2853 #include <kmalloc.h>
2854
2855 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2856-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2857+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2858
2859 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2860 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2861diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2862index 455c0ac..ad65fbe 100644
2863--- a/arch/mips/include/asm/elf.h
2864+++ b/arch/mips/include/asm/elf.h
2865@@ -372,13 +372,16 @@ extern const char *__elf_platform;
2866 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2867 #endif
2868
2869+#ifdef CONFIG_PAX_ASLR
2870+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2871+
2872+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2873+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2874+#endif
2875+
2876 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2877 struct linux_binprm;
2878 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2879 int uses_interp);
2880
2881-struct mm_struct;
2882-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2883-#define arch_randomize_brk arch_randomize_brk
2884-
2885 #endif /* _ASM_ELF_H */
2886diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2887index da9bd7d..91aa7ab 100644
2888--- a/arch/mips/include/asm/page.h
2889+++ b/arch/mips/include/asm/page.h
2890@@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2891 #ifdef CONFIG_CPU_MIPS32
2892 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2893 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2894- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2895+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2896 #else
2897 typedef struct { unsigned long long pte; } pte_t;
2898 #define pte_val(x) ((x).pte)
2899diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2900index 881d18b..cea38bc 100644
2901--- a/arch/mips/include/asm/pgalloc.h
2902+++ b/arch/mips/include/asm/pgalloc.h
2903@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2904 {
2905 set_pud(pud, __pud((unsigned long)pmd));
2906 }
2907+
2908+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2909+{
2910+ pud_populate(mm, pud, pmd);
2911+}
2912 #endif
2913
2914 /*
2915diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
2916index 6018c80..7c37203 100644
2917--- a/arch/mips/include/asm/system.h
2918+++ b/arch/mips/include/asm/system.h
2919@@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2920 */
2921 #define __ARCH_WANT_UNLOCKED_CTXSW
2922
2923-extern unsigned long arch_align_stack(unsigned long sp);
2924+#define arch_align_stack(x) ((x) & ~0xfUL)
2925
2926 #endif /* _ASM_SYSTEM_H */
2927diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2928index 0d85d8e..ec71487 100644
2929--- a/arch/mips/include/asm/thread_info.h
2930+++ b/arch/mips/include/asm/thread_info.h
2931@@ -123,6 +123,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2932 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2933 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2934 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2935+/* li takes a 32bit immediate */
2936+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2937 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2938
2939 #ifdef CONFIG_MIPS32_O32
2940@@ -146,15 +148,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2941 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2942 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2943 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2944+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2945+
2946+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2947
2948 /* work to do in syscall_trace_leave() */
2949-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2950+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2951
2952 /* work to do on interrupt/exception return */
2953 #define _TIF_WORK_MASK (0x0000ffef & \
2954 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2955 /* work to do on any return to u-space */
2956-#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2957+#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2958
2959 #endif /* __KERNEL__ */
2960
2961diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2962index 9fdd8bc..4bd7f1a 100644
2963--- a/arch/mips/kernel/binfmt_elfn32.c
2964+++ b/arch/mips/kernel/binfmt_elfn32.c
2965@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2966 #undef ELF_ET_DYN_BASE
2967 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2968
2969+#ifdef CONFIG_PAX_ASLR
2970+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2971+
2972+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2973+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2974+#endif
2975+
2976 #include <asm/processor.h>
2977 #include <linux/module.h>
2978 #include <linux/elfcore.h>
2979diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2980index ff44823..97f8906 100644
2981--- a/arch/mips/kernel/binfmt_elfo32.c
2982+++ b/arch/mips/kernel/binfmt_elfo32.c
2983@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2984 #undef ELF_ET_DYN_BASE
2985 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2986
2987+#ifdef CONFIG_PAX_ASLR
2988+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2989+
2990+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2991+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2992+#endif
2993+
2994 #include <asm/processor.h>
2995
2996 /*
2997diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2998index 7955409..ceaea7c 100644
2999--- a/arch/mips/kernel/process.c
3000+++ b/arch/mips/kernel/process.c
3001@@ -483,15 +483,3 @@ unsigned long get_wchan(struct task_struct *task)
3002 out:
3003 return pc;
3004 }
3005-
3006-/*
3007- * Don't forget that the stack pointer must be aligned on a 8 bytes
3008- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
3009- */
3010-unsigned long arch_align_stack(unsigned long sp)
3011-{
3012- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3013- sp -= get_random_int() & ~PAGE_MASK;
3014-
3015- return sp & ALMASK;
3016-}
3017diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
3018index 7786b60..3e38c72 100644
3019--- a/arch/mips/kernel/ptrace.c
3020+++ b/arch/mips/kernel/ptrace.c
3021@@ -529,6 +529,10 @@ static inline int audit_arch(void)
3022 return arch;
3023 }
3024
3025+#ifdef CONFIG_GRKERNSEC_SETXID
3026+extern void gr_delayed_cred_worker(void);
3027+#endif
3028+
3029 /*
3030 * Notification of system call entry/exit
3031 * - triggered by current->work.syscall_trace
3032@@ -538,6 +542,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3033 /* do the secure computing check first */
3034 secure_computing(regs->regs[2]);
3035
3036+#ifdef CONFIG_GRKERNSEC_SETXID
3037+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3038+ gr_delayed_cred_worker();
3039+#endif
3040+
3041 if (!(current->ptrace & PT_PTRACED))
3042 goto out;
3043
3044diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3045index a632bc1..0b77c7c 100644
3046--- a/arch/mips/kernel/scall32-o32.S
3047+++ b/arch/mips/kernel/scall32-o32.S
3048@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3049
3050 stack_done:
3051 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3052- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3053+ li t1, _TIF_SYSCALL_WORK
3054 and t0, t1
3055 bnez t0, syscall_trace_entry # -> yes
3056
3057diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3058index 3b5a5e9..e1ee86d 100644
3059--- a/arch/mips/kernel/scall64-64.S
3060+++ b/arch/mips/kernel/scall64-64.S
3061@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3062
3063 sd a3, PT_R26(sp) # save a3 for syscall restarting
3064
3065- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3066+ li t1, _TIF_SYSCALL_WORK
3067 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3068 and t0, t1, t0
3069 bnez t0, syscall_trace_entry
3070diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3071index 6be6f70..1859577 100644
3072--- a/arch/mips/kernel/scall64-n32.S
3073+++ b/arch/mips/kernel/scall64-n32.S
3074@@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3075
3076 sd a3, PT_R26(sp) # save a3 for syscall restarting
3077
3078- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3079+ li t1, _TIF_SYSCALL_WORK
3080 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3081 and t0, t1, t0
3082 bnez t0, n32_syscall_trace_entry
3083diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3084index 5422855..74e63a3 100644
3085--- a/arch/mips/kernel/scall64-o32.S
3086+++ b/arch/mips/kernel/scall64-o32.S
3087@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3088 PTR 4b, bad_stack
3089 .previous
3090
3091- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3092+ li t1, _TIF_SYSCALL_WORK
3093 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3094 and t0, t1, t0
3095 bnez t0, trace_a_syscall
3096diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3097index 69ebd58..e4bff83 100644
3098--- a/arch/mips/mm/fault.c
3099+++ b/arch/mips/mm/fault.c
3100@@ -28,6 +28,23 @@
3101 #include <asm/highmem.h> /* For VMALLOC_END */
3102 #include <linux/kdebug.h>
3103
3104+#ifdef CONFIG_PAX_PAGEEXEC
3105+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3106+{
3107+ unsigned long i;
3108+
3109+ printk(KERN_ERR "PAX: bytes at PC: ");
3110+ for (i = 0; i < 5; i++) {
3111+ unsigned int c;
3112+ if (get_user(c, (unsigned int *)pc+i))
3113+ printk(KERN_CONT "???????? ");
3114+ else
3115+ printk(KERN_CONT "%08x ", c);
3116+ }
3117+ printk("\n");
3118+}
3119+#endif
3120+
3121 /*
3122 * This routine handles page faults. It determines the address,
3123 * and the problem, and then passes it off to one of the appropriate
3124diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3125index 302d779..7d35bf8 100644
3126--- a/arch/mips/mm/mmap.c
3127+++ b/arch/mips/mm/mmap.c
3128@@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3129 do_color_align = 1;
3130
3131 /* requesting a specific address */
3132+
3133+#ifdef CONFIG_PAX_RANDMMAP
3134+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3135+#endif
3136+
3137 if (addr) {
3138 if (do_color_align)
3139 addr = COLOUR_ALIGN(addr, pgoff);
3140@@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3141 addr = PAGE_ALIGN(addr);
3142
3143 vma = find_vma(mm, addr);
3144- if (TASK_SIZE - len >= addr &&
3145- (!vma || addr + len <= vma->vm_start))
3146+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3147 return addr;
3148 }
3149
3150@@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3151 /* At this point: (!vma || addr < vma->vm_end). */
3152 if (TASK_SIZE - len < addr)
3153 return -ENOMEM;
3154- if (!vma || addr + len <= vma->vm_start)
3155+ if (check_heap_stack_gap(vmm, addr, len))
3156 return addr;
3157 addr = vma->vm_end;
3158 if (do_color_align)
3159@@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3160 /* make sure it can fit in the remaining address space */
3161 if (likely(addr > len)) {
3162 vma = find_vma(mm, addr - len);
3163- if (!vma || addr <= vma->vm_start) {
3164+ if (check_heap_stack_gap(vmm, addr - len, len))
3165 /* cache the address as a hint for next time */
3166 return mm->free_area_cache = addr - len;
3167 }
3168@@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3169 * return with success:
3170 */
3171 vma = find_vma(mm, addr);
3172- if (likely(!vma || addr + len <= vma->vm_start)) {
3173+ if (check_heap_stack_gap(vmm, addr, len)) {
3174 /* cache the address as a hint for next time */
3175 return mm->free_area_cache = addr;
3176 }
3177@@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3178 mm->unmap_area = arch_unmap_area_topdown;
3179 }
3180 }
3181-
3182-static inline unsigned long brk_rnd(void)
3183-{
3184- unsigned long rnd = get_random_int();
3185-
3186- rnd = rnd << PAGE_SHIFT;
3187- /* 8MB for 32bit, 256MB for 64bit */
3188- if (TASK_IS_32BIT_ADDR)
3189- rnd = rnd & 0x7ffffful;
3190- else
3191- rnd = rnd & 0xffffffful;
3192-
3193- return rnd;
3194-}
3195-
3196-unsigned long arch_randomize_brk(struct mm_struct *mm)
3197-{
3198- unsigned long base = mm->brk;
3199- unsigned long ret;
3200-
3201- ret = PAGE_ALIGN(base + brk_rnd());
3202-
3203- if (ret < mm->brk)
3204- return mm->brk;
3205-
3206- return ret;
3207-}
3208diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3209index 967d144..db12197 100644
3210--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3211+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3212@@ -11,12 +11,14 @@
3213 #ifndef _ASM_PROC_CACHE_H
3214 #define _ASM_PROC_CACHE_H
3215
3216+#include <linux/const.h>
3217+
3218 /* L1 cache */
3219
3220 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3221 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3222-#define L1_CACHE_BYTES 16 /* bytes per entry */
3223 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3224+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3225 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3226
3227 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3228diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3229index bcb5df2..84fabd2 100644
3230--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3231+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3232@@ -16,13 +16,15 @@
3233 #ifndef _ASM_PROC_CACHE_H
3234 #define _ASM_PROC_CACHE_H
3235
3236+#include <linux/const.h>
3237+
3238 /*
3239 * L1 cache
3240 */
3241 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3242 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3243-#define L1_CACHE_BYTES 32 /* bytes per entry */
3244 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3245+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3246 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3247
3248 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3249diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3250index 4ce7a01..449202a 100644
3251--- a/arch/openrisc/include/asm/cache.h
3252+++ b/arch/openrisc/include/asm/cache.h
3253@@ -19,11 +19,13 @@
3254 #ifndef __ASM_OPENRISC_CACHE_H
3255 #define __ASM_OPENRISC_CACHE_H
3256
3257+#include <linux/const.h>
3258+
3259 /* FIXME: How can we replace these with values from the CPU...
3260 * they shouldn't be hard-coded!
3261 */
3262
3263-#define L1_CACHE_BYTES 16
3264 #define L1_CACHE_SHIFT 4
3265+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3266
3267 #endif /* __ASM_OPENRISC_CACHE_H */
3268diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3269index 4054b31..a10c105 100644
3270--- a/arch/parisc/include/asm/atomic.h
3271+++ b/arch/parisc/include/asm/atomic.h
3272@@ -335,6 +335,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3273
3274 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3275
3276+#define atomic64_read_unchecked(v) atomic64_read(v)
3277+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3278+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3279+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3280+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3281+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3282+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3283+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3284+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3285+
3286 #endif /* !CONFIG_64BIT */
3287
3288
3289diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3290index 47f11c7..3420df2 100644
3291--- a/arch/parisc/include/asm/cache.h
3292+++ b/arch/parisc/include/asm/cache.h
3293@@ -5,6 +5,7 @@
3294 #ifndef __ARCH_PARISC_CACHE_H
3295 #define __ARCH_PARISC_CACHE_H
3296
3297+#include <linux/const.h>
3298
3299 /*
3300 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3301@@ -15,13 +16,13 @@
3302 * just ruin performance.
3303 */
3304 #ifdef CONFIG_PA20
3305-#define L1_CACHE_BYTES 64
3306 #define L1_CACHE_SHIFT 6
3307 #else
3308-#define L1_CACHE_BYTES 32
3309 #define L1_CACHE_SHIFT 5
3310 #endif
3311
3312+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3313+
3314 #ifndef __ASSEMBLY__
3315
3316 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3317diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3318index 19f6cb1..6c78cf2 100644
3319--- a/arch/parisc/include/asm/elf.h
3320+++ b/arch/parisc/include/asm/elf.h
3321@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3322
3323 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3324
3325+#ifdef CONFIG_PAX_ASLR
3326+#define PAX_ELF_ET_DYN_BASE 0x10000UL
3327+
3328+#define PAX_DELTA_MMAP_LEN 16
3329+#define PAX_DELTA_STACK_LEN 16
3330+#endif
3331+
3332 /* This yields a mask that user programs can use to figure out what
3333 instruction set this CPU supports. This could be done in user space,
3334 but it's not easy, and we've already done it here. */
3335diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3336index fc987a1..6e068ef 100644
3337--- a/arch/parisc/include/asm/pgalloc.h
3338+++ b/arch/parisc/include/asm/pgalloc.h
3339@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3340 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3341 }
3342
3343+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3344+{
3345+ pgd_populate(mm, pgd, pmd);
3346+}
3347+
3348 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3349 {
3350 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3351@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3352 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3353 #define pmd_free(mm, x) do { } while (0)
3354 #define pgd_populate(mm, pmd, pte) BUG()
3355+#define pgd_populate_kernel(mm, pmd, pte) BUG()
3356
3357 #endif
3358
3359diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3360index 22dadeb..f6c2be4 100644
3361--- a/arch/parisc/include/asm/pgtable.h
3362+++ b/arch/parisc/include/asm/pgtable.h
3363@@ -210,6 +210,17 @@ struct vm_area_struct;
3364 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3365 #define PAGE_COPY PAGE_EXECREAD
3366 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3367+
3368+#ifdef CONFIG_PAX_PAGEEXEC
3369+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3370+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3371+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3372+#else
3373+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3374+# define PAGE_COPY_NOEXEC PAGE_COPY
3375+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3376+#endif
3377+
3378 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3379 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3380 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3381diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3382index 5e34ccf..672bc9c 100644
3383--- a/arch/parisc/kernel/module.c
3384+++ b/arch/parisc/kernel/module.c
3385@@ -98,16 +98,38 @@
3386
3387 /* three functions to determine where in the module core
3388 * or init pieces the location is */
3389+static inline int in_init_rx(struct module *me, void *loc)
3390+{
3391+ return (loc >= me->module_init_rx &&
3392+ loc < (me->module_init_rx + me->init_size_rx));
3393+}
3394+
3395+static inline int in_init_rw(struct module *me, void *loc)
3396+{
3397+ return (loc >= me->module_init_rw &&
3398+ loc < (me->module_init_rw + me->init_size_rw));
3399+}
3400+
3401 static inline int in_init(struct module *me, void *loc)
3402 {
3403- return (loc >= me->module_init &&
3404- loc <= (me->module_init + me->init_size));
3405+ return in_init_rx(me, loc) || in_init_rw(me, loc);
3406+}
3407+
3408+static inline int in_core_rx(struct module *me, void *loc)
3409+{
3410+ return (loc >= me->module_core_rx &&
3411+ loc < (me->module_core_rx + me->core_size_rx));
3412+}
3413+
3414+static inline int in_core_rw(struct module *me, void *loc)
3415+{
3416+ return (loc >= me->module_core_rw &&
3417+ loc < (me->module_core_rw + me->core_size_rw));
3418 }
3419
3420 static inline int in_core(struct module *me, void *loc)
3421 {
3422- return (loc >= me->module_core &&
3423- loc <= (me->module_core + me->core_size));
3424+ return in_core_rx(me, loc) || in_core_rw(me, loc);
3425 }
3426
3427 static inline int in_local(struct module *me, void *loc)
3428@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3429 }
3430
3431 /* align things a bit */
3432- me->core_size = ALIGN(me->core_size, 16);
3433- me->arch.got_offset = me->core_size;
3434- me->core_size += gots * sizeof(struct got_entry);
3435+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3436+ me->arch.got_offset = me->core_size_rw;
3437+ me->core_size_rw += gots * sizeof(struct got_entry);
3438
3439- me->core_size = ALIGN(me->core_size, 16);
3440- me->arch.fdesc_offset = me->core_size;
3441- me->core_size += fdescs * sizeof(Elf_Fdesc);
3442+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3443+ me->arch.fdesc_offset = me->core_size_rw;
3444+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3445
3446 me->arch.got_max = gots;
3447 me->arch.fdesc_max = fdescs;
3448@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3449
3450 BUG_ON(value == 0);
3451
3452- got = me->module_core + me->arch.got_offset;
3453+ got = me->module_core_rw + me->arch.got_offset;
3454 for (i = 0; got[i].addr; i++)
3455 if (got[i].addr == value)
3456 goto out;
3457@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3458 #ifdef CONFIG_64BIT
3459 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3460 {
3461- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3462+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3463
3464 if (!value) {
3465 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3466@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3467
3468 /* Create new one */
3469 fdesc->addr = value;
3470- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3471+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3472 return (Elf_Addr)fdesc;
3473 }
3474 #endif /* CONFIG_64BIT */
3475@@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3476
3477 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3478 end = table + sechdrs[me->arch.unwind_section].sh_size;
3479- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3480+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3481
3482 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3483 me->arch.unwind_section, table, end, gp);
3484diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3485index c9b9322..02d8940 100644
3486--- a/arch/parisc/kernel/sys_parisc.c
3487+++ b/arch/parisc/kernel/sys_parisc.c
3488@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3489 /* At this point: (!vma || addr < vma->vm_end). */
3490 if (TASK_SIZE - len < addr)
3491 return -ENOMEM;
3492- if (!vma || addr + len <= vma->vm_start)
3493+ if (check_heap_stack_gap(vma, addr, len))
3494 return addr;
3495 addr = vma->vm_end;
3496 }
3497@@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3498 /* At this point: (!vma || addr < vma->vm_end). */
3499 if (TASK_SIZE - len < addr)
3500 return -ENOMEM;
3501- if (!vma || addr + len <= vma->vm_start)
3502+ if (check_heap_stack_gap(vma, addr, len))
3503 return addr;
3504 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3505 if (addr < vma->vm_end) /* handle wraparound */
3506@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3507 if (flags & MAP_FIXED)
3508 return addr;
3509 if (!addr)
3510- addr = TASK_UNMAPPED_BASE;
3511+ addr = current->mm->mmap_base;
3512
3513 if (filp) {
3514 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3515diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3516index f19e660..414fe24 100644
3517--- a/arch/parisc/kernel/traps.c
3518+++ b/arch/parisc/kernel/traps.c
3519@@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3520
3521 down_read(&current->mm->mmap_sem);
3522 vma = find_vma(current->mm,regs->iaoq[0]);
3523- if (vma && (regs->iaoq[0] >= vma->vm_start)
3524- && (vma->vm_flags & VM_EXEC)) {
3525-
3526+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3527 fault_address = regs->iaoq[0];
3528 fault_space = regs->iasq[0];
3529
3530diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3531index 18162ce..94de376 100644
3532--- a/arch/parisc/mm/fault.c
3533+++ b/arch/parisc/mm/fault.c
3534@@ -15,6 +15,7 @@
3535 #include <linux/sched.h>
3536 #include <linux/interrupt.h>
3537 #include <linux/module.h>
3538+#include <linux/unistd.h>
3539
3540 #include <asm/uaccess.h>
3541 #include <asm/traps.h>
3542@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3543 static unsigned long
3544 parisc_acctyp(unsigned long code, unsigned int inst)
3545 {
3546- if (code == 6 || code == 16)
3547+ if (code == 6 || code == 7 || code == 16)
3548 return VM_EXEC;
3549
3550 switch (inst & 0xf0000000) {
3551@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3552 }
3553 #endif
3554
3555+#ifdef CONFIG_PAX_PAGEEXEC
3556+/*
3557+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3558+ *
3559+ * returns 1 when task should be killed
3560+ * 2 when rt_sigreturn trampoline was detected
3561+ * 3 when unpatched PLT trampoline was detected
3562+ */
3563+static int pax_handle_fetch_fault(struct pt_regs *regs)
3564+{
3565+
3566+#ifdef CONFIG_PAX_EMUPLT
3567+ int err;
3568+
3569+ do { /* PaX: unpatched PLT emulation */
3570+ unsigned int bl, depwi;
3571+
3572+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3573+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3574+
3575+ if (err)
3576+ break;
3577+
3578+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3579+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3580+
3581+ err = get_user(ldw, (unsigned int *)addr);
3582+ err |= get_user(bv, (unsigned int *)(addr+4));
3583+ err |= get_user(ldw2, (unsigned int *)(addr+8));
3584+
3585+ if (err)
3586+ break;
3587+
3588+ if (ldw == 0x0E801096U &&
3589+ bv == 0xEAC0C000U &&
3590+ ldw2 == 0x0E881095U)
3591+ {
3592+ unsigned int resolver, map;
3593+
3594+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3595+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3596+ if (err)
3597+ break;
3598+
3599+ regs->gr[20] = instruction_pointer(regs)+8;
3600+ regs->gr[21] = map;
3601+ regs->gr[22] = resolver;
3602+ regs->iaoq[0] = resolver | 3UL;
3603+ regs->iaoq[1] = regs->iaoq[0] + 4;
3604+ return 3;
3605+ }
3606+ }
3607+ } while (0);
3608+#endif
3609+
3610+#ifdef CONFIG_PAX_EMUTRAMP
3611+
3612+#ifndef CONFIG_PAX_EMUSIGRT
3613+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3614+ return 1;
3615+#endif
3616+
3617+ do { /* PaX: rt_sigreturn emulation */
3618+ unsigned int ldi1, ldi2, bel, nop;
3619+
3620+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3621+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3622+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3623+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3624+
3625+ if (err)
3626+ break;
3627+
3628+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3629+ ldi2 == 0x3414015AU &&
3630+ bel == 0xE4008200U &&
3631+ nop == 0x08000240U)
3632+ {
3633+ regs->gr[25] = (ldi1 & 2) >> 1;
3634+ regs->gr[20] = __NR_rt_sigreturn;
3635+ regs->gr[31] = regs->iaoq[1] + 16;
3636+ regs->sr[0] = regs->iasq[1];
3637+ regs->iaoq[0] = 0x100UL;
3638+ regs->iaoq[1] = regs->iaoq[0] + 4;
3639+ regs->iasq[0] = regs->sr[2];
3640+ regs->iasq[1] = regs->sr[2];
3641+ return 2;
3642+ }
3643+ } while (0);
3644+#endif
3645+
3646+ return 1;
3647+}
3648+
3649+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3650+{
3651+ unsigned long i;
3652+
3653+ printk(KERN_ERR "PAX: bytes at PC: ");
3654+ for (i = 0; i < 5; i++) {
3655+ unsigned int c;
3656+ if (get_user(c, (unsigned int *)pc+i))
3657+ printk(KERN_CONT "???????? ");
3658+ else
3659+ printk(KERN_CONT "%08x ", c);
3660+ }
3661+ printk("\n");
3662+}
3663+#endif
3664+
3665 int fixup_exception(struct pt_regs *regs)
3666 {
3667 const struct exception_table_entry *fix;
3668@@ -192,8 +303,33 @@ good_area:
3669
3670 acc_type = parisc_acctyp(code,regs->iir);
3671
3672- if ((vma->vm_flags & acc_type) != acc_type)
3673+ if ((vma->vm_flags & acc_type) != acc_type) {
3674+
3675+#ifdef CONFIG_PAX_PAGEEXEC
3676+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3677+ (address & ~3UL) == instruction_pointer(regs))
3678+ {
3679+ up_read(&mm->mmap_sem);
3680+ switch (pax_handle_fetch_fault(regs)) {
3681+
3682+#ifdef CONFIG_PAX_EMUPLT
3683+ case 3:
3684+ return;
3685+#endif
3686+
3687+#ifdef CONFIG_PAX_EMUTRAMP
3688+ case 2:
3689+ return;
3690+#endif
3691+
3692+ }
3693+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3694+ do_group_exit(SIGKILL);
3695+ }
3696+#endif
3697+
3698 goto bad_area;
3699+ }
3700
3701 /*
3702 * If for any reason at all we couldn't handle the fault, make
3703diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3704index 02e41b5..ec6e26c 100644
3705--- a/arch/powerpc/include/asm/atomic.h
3706+++ b/arch/powerpc/include/asm/atomic.h
3707@@ -469,6 +469,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3708
3709 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3710
3711+#define atomic64_read_unchecked(v) atomic64_read(v)
3712+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3713+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3714+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3715+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3716+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3717+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3718+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3719+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3720+
3721 #endif /* __powerpc64__ */
3722
3723 #endif /* __KERNEL__ */
3724diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3725index 4b50941..5605819 100644
3726--- a/arch/powerpc/include/asm/cache.h
3727+++ b/arch/powerpc/include/asm/cache.h
3728@@ -3,6 +3,7 @@
3729
3730 #ifdef __KERNEL__
3731
3732+#include <linux/const.h>
3733
3734 /* bytes per L1 cache line */
3735 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3736@@ -22,7 +23,7 @@
3737 #define L1_CACHE_SHIFT 7
3738 #endif
3739
3740-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3741+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3742
3743 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3744
3745diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3746index 3bf9cca..e7457d0 100644
3747--- a/arch/powerpc/include/asm/elf.h
3748+++ b/arch/powerpc/include/asm/elf.h
3749@@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3750 the loader. We need to make sure that it is out of the way of the program
3751 that it will "exec", and that there is sufficient room for the brk. */
3752
3753-extern unsigned long randomize_et_dyn(unsigned long base);
3754-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3755+#define ELF_ET_DYN_BASE (0x20000000)
3756+
3757+#ifdef CONFIG_PAX_ASLR
3758+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3759+
3760+#ifdef __powerpc64__
3761+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3762+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3763+#else
3764+#define PAX_DELTA_MMAP_LEN 15
3765+#define PAX_DELTA_STACK_LEN 15
3766+#endif
3767+#endif
3768
3769 /*
3770 * Our registers are always unsigned longs, whether we're a 32 bit
3771@@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3772 (0x7ff >> (PAGE_SHIFT - 12)) : \
3773 (0x3ffff >> (PAGE_SHIFT - 12)))
3774
3775-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3776-#define arch_randomize_brk arch_randomize_brk
3777-
3778 #endif /* __KERNEL__ */
3779
3780 /*
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 7fdc2c0..e47a9b02d3 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/system.h b/arch/powerpc/include/asm/system.h
3926index c377457..3c69fbc 100644
3927--- a/arch/powerpc/include/asm/system.h
3928+++ b/arch/powerpc/include/asm/system.h
3929@@ -539,7 +539,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
3930 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3931 #endif
3932
3933-extern unsigned long arch_align_stack(unsigned long sp);
3934+#define arch_align_stack(x) ((x) & ~0xfUL)
3935
3936 /* Used in very early kernel initialization. */
3937 extern unsigned long reloc_offset(void);
3938diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3939index 96471494..60ed5a2 100644
3940--- a/arch/powerpc/include/asm/thread_info.h
3941+++ b/arch/powerpc/include/asm/thread_info.h
3942@@ -104,13 +104,15 @@ static inline struct thread_info *current_thread_info(void)
3943 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3944 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3945 #define TIF_SINGLESTEP 8 /* singlestepping active */
3946-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3947 #define TIF_SECCOMP 10 /* secure computing */
3948 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3949 #define TIF_NOERROR 12 /* Force successful syscall return */
3950 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3951 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3952 #define TIF_RUNLATCH 16 /* Is the runlatch enabled? */
3953+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
3954+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3955+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3956
3957 /* as above, but as bit values */
3958 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3959@@ -128,8 +130,11 @@ static inline struct thread_info *current_thread_info(void)
3960 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3961 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3962 #define _TIF_RUNLATCH (1<<TIF_RUNLATCH)
3963+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3964+
3965 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3966- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3967+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT \
3968+ _TIF_GRSEC_SETXID)
3969
3970 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3971 _TIF_NOTIFY_RESUME)
3972diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3973index bd0fb84..a42a14b 100644
3974--- a/arch/powerpc/include/asm/uaccess.h
3975+++ b/arch/powerpc/include/asm/uaccess.h
3976@@ -13,6 +13,8 @@
3977 #define VERIFY_READ 0
3978 #define VERIFY_WRITE 1
3979
3980+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3981+
3982 /*
3983 * The fs value determines whether argument validity checking should be
3984 * performed or not. If get_fs() == USER_DS, checking is performed, with
3985@@ -327,52 +329,6 @@ do { \
3986 extern unsigned long __copy_tofrom_user(void __user *to,
3987 const void __user *from, unsigned long size);
3988
3989-#ifndef __powerpc64__
3990-
3991-static inline unsigned long copy_from_user(void *to,
3992- const void __user *from, unsigned long n)
3993-{
3994- unsigned long over;
3995-
3996- if (access_ok(VERIFY_READ, from, n))
3997- return __copy_tofrom_user((__force void __user *)to, from, n);
3998- if ((unsigned long)from < TASK_SIZE) {
3999- over = (unsigned long)from + n - TASK_SIZE;
4000- return __copy_tofrom_user((__force void __user *)to, from,
4001- n - over) + over;
4002- }
4003- return n;
4004-}
4005-
4006-static inline unsigned long copy_to_user(void __user *to,
4007- const void *from, unsigned long n)
4008-{
4009- unsigned long over;
4010-
4011- if (access_ok(VERIFY_WRITE, to, n))
4012- return __copy_tofrom_user(to, (__force void __user *)from, n);
4013- if ((unsigned long)to < TASK_SIZE) {
4014- over = (unsigned long)to + n - TASK_SIZE;
4015- return __copy_tofrom_user(to, (__force void __user *)from,
4016- n - over) + over;
4017- }
4018- return n;
4019-}
4020-
4021-#else /* __powerpc64__ */
4022-
4023-#define __copy_in_user(to, from, size) \
4024- __copy_tofrom_user((to), (from), (size))
4025-
4026-extern unsigned long copy_from_user(void *to, const void __user *from,
4027- unsigned long n);
4028-extern unsigned long copy_to_user(void __user *to, const void *from,
4029- unsigned long n);
4030-extern unsigned long copy_in_user(void __user *to, const void __user *from,
4031- unsigned long n);
4032-
4033-#endif /* __powerpc64__ */
4034-
4035 static inline unsigned long __copy_from_user_inatomic(void *to,
4036 const void __user *from, unsigned long n)
4037 {
4038@@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4039 if (ret == 0)
4040 return 0;
4041 }
4042+
4043+ if (!__builtin_constant_p(n))
4044+ check_object_size(to, n, false);
4045+
4046 return __copy_tofrom_user((__force void __user *)to, from, n);
4047 }
4048
4049@@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4050 if (ret == 0)
4051 return 0;
4052 }
4053+
4054+ if (!__builtin_constant_p(n))
4055+ check_object_size(from, n, true);
4056+
4057 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4058 }
4059
4060@@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4061 return __copy_to_user_inatomic(to, from, size);
4062 }
4063
4064+#ifndef __powerpc64__
4065+
4066+static inline unsigned long __must_check copy_from_user(void *to,
4067+ const void __user *from, unsigned long n)
4068+{
4069+ unsigned long over;
4070+
4071+ if ((long)n < 0)
4072+ return n;
4073+
4074+ if (access_ok(VERIFY_READ, from, n)) {
4075+ if (!__builtin_constant_p(n))
4076+ check_object_size(to, n, false);
4077+ return __copy_tofrom_user((__force void __user *)to, from, n);
4078+ }
4079+ if ((unsigned long)from < TASK_SIZE) {
4080+ over = (unsigned long)from + n - TASK_SIZE;
4081+ if (!__builtin_constant_p(n - over))
4082+ check_object_size(to, n - over, false);
4083+ return __copy_tofrom_user((__force void __user *)to, from,
4084+ n - over) + over;
4085+ }
4086+ return n;
4087+}
4088+
4089+static inline unsigned long __must_check copy_to_user(void __user *to,
4090+ const void *from, unsigned long n)
4091+{
4092+ unsigned long over;
4093+
4094+ if ((long)n < 0)
4095+ return n;
4096+
4097+ if (access_ok(VERIFY_WRITE, to, n)) {
4098+ if (!__builtin_constant_p(n))
4099+ check_object_size(from, n, true);
4100+ return __copy_tofrom_user(to, (__force void __user *)from, n);
4101+ }
4102+ if ((unsigned long)to < TASK_SIZE) {
4103+ over = (unsigned long)to + n - TASK_SIZE;
4104+ if (!__builtin_constant_p(n))
4105+ check_object_size(from, n - over, true);
4106+ return __copy_tofrom_user(to, (__force void __user *)from,
4107+ n - over) + over;
4108+ }
4109+ return n;
4110+}
4111+
4112+#else /* __powerpc64__ */
4113+
4114+#define __copy_in_user(to, from, size) \
4115+ __copy_tofrom_user((to), (from), (size))
4116+
4117+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4118+{
4119+ if ((long)n < 0 || n > INT_MAX)
4120+ return n;
4121+
4122+ if (!__builtin_constant_p(n))
4123+ check_object_size(to, n, false);
4124+
4125+ if (likely(access_ok(VERIFY_READ, from, n)))
4126+ n = __copy_from_user(to, from, n);
4127+ else
4128+ memset(to, 0, n);
4129+ return n;
4130+}
4131+
4132+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4133+{
4134+ if ((long)n < 0 || n > INT_MAX)
4135+ return n;
4136+
4137+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
4138+ if (!__builtin_constant_p(n))
4139+ check_object_size(from, n, true);
4140+ n = __copy_to_user(to, from, n);
4141+ }
4142+ return n;
4143+}
4144+
4145+extern unsigned long copy_in_user(void __user *to, const void __user *from,
4146+ unsigned long n);
4147+
4148+#endif /* __powerpc64__ */
4149+
4150 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4151
4152 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4153diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4154index 429983c..7af363b 100644
4155--- a/arch/powerpc/kernel/exceptions-64e.S
4156+++ b/arch/powerpc/kernel/exceptions-64e.S
4157@@ -587,6 +587,7 @@ storage_fault_common:
4158 std r14,_DAR(r1)
4159 std r15,_DSISR(r1)
4160 addi r3,r1,STACK_FRAME_OVERHEAD
4161+ bl .save_nvgprs
4162 mr r4,r14
4163 mr r5,r15
4164 ld r14,PACA_EXGEN+EX_R14(r13)
4165@@ -596,8 +597,7 @@ storage_fault_common:
4166 cmpdi r3,0
4167 bne- 1f
4168 b .ret_from_except_lite
4169-1: bl .save_nvgprs
4170- mr r5,r3
4171+1: mr r5,r3
4172 addi r3,r1,STACK_FRAME_OVERHEAD
4173 ld r4,_DAR(r1)
4174 bl .bad_page_fault
4175diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4176index 15c5a4f..22a4000 100644
4177--- a/arch/powerpc/kernel/exceptions-64s.S
4178+++ b/arch/powerpc/kernel/exceptions-64s.S
4179@@ -1004,10 +1004,10 @@ handle_page_fault:
4180 11: ld r4,_DAR(r1)
4181 ld r5,_DSISR(r1)
4182 addi r3,r1,STACK_FRAME_OVERHEAD
4183+ bl .save_nvgprs
4184 bl .do_page_fault
4185 cmpdi r3,0
4186 beq+ 13f
4187- bl .save_nvgprs
4188 mr r5,r3
4189 addi r3,r1,STACK_FRAME_OVERHEAD
4190 lwz r4,_DAR(r1)
4191diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
4192index 01e2877..a1ba360 100644
4193--- a/arch/powerpc/kernel/irq.c
4194+++ b/arch/powerpc/kernel/irq.c
4195@@ -560,9 +560,6 @@ struct irq_host *irq_alloc_host(struct device_node *of_node,
4196 host->ops = ops;
4197 host->of_node = of_node_get(of_node);
4198
4199- if (host->ops->match == NULL)
4200- host->ops->match = default_irq_host_match;
4201-
4202 raw_spin_lock_irqsave(&irq_big_lock, flags);
4203
4204 /* If it's a legacy controller, check for duplicates and
4205@@ -635,7 +632,12 @@ struct irq_host *irq_find_host(struct device_node *node)
4206 */
4207 raw_spin_lock_irqsave(&irq_big_lock, flags);
4208 list_for_each_entry(h, &irq_hosts, link)
4209- if (h->ops->match(h, node)) {
4210+ if (h->ops->match) {
4211+ if (h->ops->match(h, node)) {
4212+ found = h;
4213+ break;
4214+ }
4215+ } else if (default_irq_host_match(h, node)) {
4216 found = h;
4217 break;
4218 }
4219diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4220index 0b6d796..d760ddb 100644
4221--- a/arch/powerpc/kernel/module_32.c
4222+++ b/arch/powerpc/kernel/module_32.c
4223@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4224 me->arch.core_plt_section = i;
4225 }
4226 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4227- printk("Module doesn't contain .plt or .init.plt sections.\n");
4228+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4229 return -ENOEXEC;
4230 }
4231
4232@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4233
4234 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4235 /* Init, or core PLT? */
4236- if (location >= mod->module_core
4237- && location < mod->module_core + mod->core_size)
4238+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4239+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4240 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4241- else
4242+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4243+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4244 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4245+ else {
4246+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4247+ return ~0UL;
4248+ }
4249
4250 /* Find this entry, or if that fails, the next avail. entry */
4251 while (entry->jump[0]) {
4252diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4253index d817ab0..b23b18e 100644
4254--- a/arch/powerpc/kernel/process.c
4255+++ b/arch/powerpc/kernel/process.c
4256@@ -676,8 +676,8 @@ void show_regs(struct pt_regs * regs)
4257 * Lookup NIP late so we have the best change of getting the
4258 * above info out without failing
4259 */
4260- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4261- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4262+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4263+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4264 #endif
4265 show_stack(current, (unsigned long *) regs->gpr[1]);
4266 if (!user_mode(regs))
4267@@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4268 newsp = stack[0];
4269 ip = stack[STACK_FRAME_LR_SAVE];
4270 if (!firstframe || ip != lr) {
4271- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4272+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4273 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4274 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4275- printk(" (%pS)",
4276+ printk(" (%pA)",
4277 (void *)current->ret_stack[curr_frame].ret);
4278 curr_frame--;
4279 }
4280@@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4281 struct pt_regs *regs = (struct pt_regs *)
4282 (sp + STACK_FRAME_OVERHEAD);
4283 lr = regs->link;
4284- printk("--- Exception: %lx at %pS\n LR = %pS\n",
4285+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
4286 regs->trap, (void *)regs->nip, (void *)lr);
4287 firstframe = 1;
4288 }
4289@@ -1279,58 +1279,3 @@ void thread_info_cache_init(void)
4290 }
4291
4292 #endif /* THREAD_SHIFT < PAGE_SHIFT */
4293-
4294-unsigned long arch_align_stack(unsigned long sp)
4295-{
4296- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4297- sp -= get_random_int() & ~PAGE_MASK;
4298- return sp & ~0xf;
4299-}
4300-
4301-static inline unsigned long brk_rnd(void)
4302-{
4303- unsigned long rnd = 0;
4304-
4305- /* 8MB for 32bit, 1GB for 64bit */
4306- if (is_32bit_task())
4307- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4308- else
4309- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4310-
4311- return rnd << PAGE_SHIFT;
4312-}
4313-
4314-unsigned long arch_randomize_brk(struct mm_struct *mm)
4315-{
4316- unsigned long base = mm->brk;
4317- unsigned long ret;
4318-
4319-#ifdef CONFIG_PPC_STD_MMU_64
4320- /*
4321- * If we are using 1TB segments and we are allowed to randomise
4322- * the heap, we can put it above 1TB so it is backed by a 1TB
4323- * segment. Otherwise the heap will be in the bottom 1TB
4324- * which always uses 256MB segments and this may result in a
4325- * performance penalty.
4326- */
4327- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4328- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4329-#endif
4330-
4331- ret = PAGE_ALIGN(base + brk_rnd());
4332-
4333- if (ret < mm->brk)
4334- return mm->brk;
4335-
4336- return ret;
4337-}
4338-
4339-unsigned long randomize_et_dyn(unsigned long base)
4340-{
4341- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4342-
4343- if (ret < base)
4344- return base;
4345-
4346- return ret;
4347-}
4348diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4349index 5b43325..94a5bb4 100644
4350--- a/arch/powerpc/kernel/ptrace.c
4351+++ b/arch/powerpc/kernel/ptrace.c
4352@@ -1702,6 +1702,10 @@ long arch_ptrace(struct task_struct *child, long request,
4353 return ret;
4354 }
4355
4356+#ifdef CONFIG_GRKERNSEC_SETXID
4357+extern void gr_delayed_cred_worker(void);
4358+#endif
4359+
4360 /*
4361 * We must return the syscall number to actually look up in the table.
4362 * This can be -1L to skip running any syscall at all.
4363@@ -1712,6 +1716,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4364
4365 secure_computing(regs->gpr[0]);
4366
4367+#ifdef CONFIG_GRKERNSEC_SETXID
4368+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4369+ gr_delayed_cred_worker();
4370+#endif
4371+
4372 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4373 tracehook_report_syscall_entry(regs))
4374 /*
4375@@ -1746,6 +1755,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4376 {
4377 int step;
4378
4379+#ifdef CONFIG_GRKERNSEC_SETXID
4380+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4381+ gr_delayed_cred_worker();
4382+#endif
4383+
4384 audit_syscall_exit(regs);
4385
4386 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4387diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4388index 836a5a1..27289a3 100644
4389--- a/arch/powerpc/kernel/signal_32.c
4390+++ b/arch/powerpc/kernel/signal_32.c
4391@@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4392 /* Save user registers on the stack */
4393 frame = &rt_sf->uc.uc_mcontext;
4394 addr = frame;
4395- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4396+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4397 if (save_user_regs(regs, frame, 0, 1))
4398 goto badframe;
4399 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4400diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4401index a50b5ec..547078a 100644
4402--- a/arch/powerpc/kernel/signal_64.c
4403+++ b/arch/powerpc/kernel/signal_64.c
4404@@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4405 current->thread.fpscr.val = 0;
4406
4407 /* Set up to return from userspace. */
4408- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4409+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4410 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4411 } else {
4412 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4413diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4414index c091527..5592625 100644
4415--- a/arch/powerpc/kernel/traps.c
4416+++ b/arch/powerpc/kernel/traps.c
4417@@ -131,6 +131,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4418 return flags;
4419 }
4420
4421+extern void gr_handle_kernel_exploit(void);
4422+
4423 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4424 int signr)
4425 {
4426@@ -178,6 +180,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4427 panic("Fatal exception in interrupt");
4428 if (panic_on_oops)
4429 panic("Fatal exception");
4430+
4431+ gr_handle_kernel_exploit();
4432+
4433 do_exit(signr);
4434 }
4435
4436diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4437index 7d14bb6..1305601 100644
4438--- a/arch/powerpc/kernel/vdso.c
4439+++ b/arch/powerpc/kernel/vdso.c
4440@@ -35,6 +35,7 @@
4441 #include <asm/firmware.h>
4442 #include <asm/vdso.h>
4443 #include <asm/vdso_datapage.h>
4444+#include <asm/mman.h>
4445
4446 #include "setup.h"
4447
4448@@ -219,7 +220,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4449 vdso_base = VDSO32_MBASE;
4450 #endif
4451
4452- current->mm->context.vdso_base = 0;
4453+ current->mm->context.vdso_base = ~0UL;
4454
4455 /* vDSO has a problem and was disabled, just don't "enable" it for the
4456 * process
4457@@ -239,7 +240,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4458 vdso_base = get_unmapped_area(NULL, vdso_base,
4459 (vdso_pages << PAGE_SHIFT) +
4460 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4461- 0, 0);
4462+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
4463 if (IS_ERR_VALUE(vdso_base)) {
4464 rc = vdso_base;
4465 goto fail_mmapsem;
4466diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4467index 5eea6f3..5d10396 100644
4468--- a/arch/powerpc/lib/usercopy_64.c
4469+++ b/arch/powerpc/lib/usercopy_64.c
4470@@ -9,22 +9,6 @@
4471 #include <linux/module.h>
4472 #include <asm/uaccess.h>
4473
4474-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4475-{
4476- if (likely(access_ok(VERIFY_READ, from, n)))
4477- n = __copy_from_user(to, from, n);
4478- else
4479- memset(to, 0, n);
4480- return n;
4481-}
4482-
4483-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4484-{
4485- if (likely(access_ok(VERIFY_WRITE, to, n)))
4486- n = __copy_to_user(to, from, n);
4487- return n;
4488-}
4489-
4490 unsigned long copy_in_user(void __user *to, const void __user *from,
4491 unsigned long n)
4492 {
4493@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4494 return n;
4495 }
4496
4497-EXPORT_SYMBOL(copy_from_user);
4498-EXPORT_SYMBOL(copy_to_user);
4499 EXPORT_SYMBOL(copy_in_user);
4500
4501diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4502index 2f0d1b0..36fb5cc 100644
4503--- a/arch/powerpc/mm/fault.c
4504+++ b/arch/powerpc/mm/fault.c
4505@@ -32,6 +32,10 @@
4506 #include <linux/perf_event.h>
4507 #include <linux/magic.h>
4508 #include <linux/ratelimit.h>
4509+#include <linux/slab.h>
4510+#include <linux/pagemap.h>
4511+#include <linux/compiler.h>
4512+#include <linux/unistd.h>
4513
4514 #include <asm/firmware.h>
4515 #include <asm/page.h>
4516@@ -43,6 +47,7 @@
4517 #include <asm/tlbflush.h>
4518 #include <asm/siginfo.h>
4519 #include <mm/mmu_decl.h>
4520+#include <asm/ptrace.h>
4521
4522 #include "icswx.h"
4523
4524@@ -68,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4525 }
4526 #endif
4527
4528+#ifdef CONFIG_PAX_PAGEEXEC
4529+/*
4530+ * PaX: decide what to do with offenders (regs->nip = fault address)
4531+ *
4532+ * returns 1 when task should be killed
4533+ */
4534+static int pax_handle_fetch_fault(struct pt_regs *regs)
4535+{
4536+ return 1;
4537+}
4538+
4539+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4540+{
4541+ unsigned long i;
4542+
4543+ printk(KERN_ERR "PAX: bytes at PC: ");
4544+ for (i = 0; i < 5; i++) {
4545+ unsigned int c;
4546+ if (get_user(c, (unsigned int __user *)pc+i))
4547+ printk(KERN_CONT "???????? ");
4548+ else
4549+ printk(KERN_CONT "%08x ", c);
4550+ }
4551+ printk("\n");
4552+}
4553+#endif
4554+
4555 /*
4556 * Check whether the instruction at regs->nip is a store using
4557 * an update addressing form which will update r1.
4558@@ -138,7 +170,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4559 * indicate errors in DSISR but can validly be set in SRR1.
4560 */
4561 if (trap == 0x400)
4562- error_code &= 0x48200000;
4563+ error_code &= 0x58200000;
4564 else
4565 is_write = error_code & DSISR_ISSTORE;
4566 #else
4567@@ -276,7 +308,7 @@ good_area:
4568 * "undefined". Of those that can be set, this is the only
4569 * one which seems bad.
4570 */
4571- if (error_code & 0x10000000)
4572+ if (error_code & DSISR_GUARDED)
4573 /* Guarded storage error. */
4574 goto bad_area;
4575 #endif /* CONFIG_8xx */
4576@@ -291,7 +323,7 @@ good_area:
4577 * processors use the same I/D cache coherency mechanism
4578 * as embedded.
4579 */
4580- if (error_code & DSISR_PROTFAULT)
4581+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4582 goto bad_area;
4583 #endif /* CONFIG_PPC_STD_MMU */
4584
4585@@ -360,6 +392,23 @@ bad_area:
4586 bad_area_nosemaphore:
4587 /* User mode accesses cause a SIGSEGV */
4588 if (user_mode(regs)) {
4589+
4590+#ifdef CONFIG_PAX_PAGEEXEC
4591+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4592+#ifdef CONFIG_PPC_STD_MMU
4593+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4594+#else
4595+ if (is_exec && regs->nip == address) {
4596+#endif
4597+ switch (pax_handle_fetch_fault(regs)) {
4598+ }
4599+
4600+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4601+ do_group_exit(SIGKILL);
4602+ }
4603+ }
4604+#endif
4605+
4606 _exception(SIGSEGV, regs, code, address);
4607 return 0;
4608 }
4609diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4610index 67a42ed..1c7210c 100644
4611--- a/arch/powerpc/mm/mmap_64.c
4612+++ b/arch/powerpc/mm/mmap_64.c
4613@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4614 */
4615 if (mmap_is_legacy()) {
4616 mm->mmap_base = TASK_UNMAPPED_BASE;
4617+
4618+#ifdef CONFIG_PAX_RANDMMAP
4619+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4620+ mm->mmap_base += mm->delta_mmap;
4621+#endif
4622+
4623 mm->get_unmapped_area = arch_get_unmapped_area;
4624 mm->unmap_area = arch_unmap_area;
4625 } else {
4626 mm->mmap_base = mmap_base();
4627+
4628+#ifdef CONFIG_PAX_RANDMMAP
4629+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4630+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4631+#endif
4632+
4633 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4634 mm->unmap_area = arch_unmap_area_topdown;
4635 }
4636diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4637index 73709f7..6b90313 100644
4638--- a/arch/powerpc/mm/slice.c
4639+++ b/arch/powerpc/mm/slice.c
4640@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4641 if ((mm->task_size - len) < addr)
4642 return 0;
4643 vma = find_vma(mm, addr);
4644- return (!vma || (addr + len) <= vma->vm_start);
4645+ return check_heap_stack_gap(vma, addr, len);
4646 }
4647
4648 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4649@@ -256,7 +256,7 @@ full_search:
4650 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4651 continue;
4652 }
4653- if (!vma || addr + len <= vma->vm_start) {
4654+ if (check_heap_stack_gap(vma, addr, len)) {
4655 /*
4656 * Remember the place where we stopped the search:
4657 */
4658@@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4659 }
4660 }
4661
4662- addr = mm->mmap_base;
4663- while (addr > len) {
4664+ if (mm->mmap_base < len)
4665+ addr = -ENOMEM;
4666+ else
4667+ addr = mm->mmap_base - len;
4668+
4669+ while (!IS_ERR_VALUE(addr)) {
4670 /* Go down by chunk size */
4671- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4672+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
4673
4674 /* Check for hit with different page size */
4675 mask = slice_range_to_mask(addr, len);
4676@@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4677 * return with success:
4678 */
4679 vma = find_vma(mm, addr);
4680- if (!vma || (addr + len) <= vma->vm_start) {
4681+ if (check_heap_stack_gap(vma, addr, len)) {
4682 /* remember the address as a hint for next time */
4683 if (use_cache)
4684 mm->free_area_cache = addr;
4685@@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4686 mm->cached_hole_size = vma->vm_start - addr;
4687
4688 /* try just below the current vma->vm_start */
4689- addr = vma->vm_start;
4690+ addr = skip_heap_stack_gap(vma, len);
4691 }
4692
4693 /*
4694@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4695 if (fixed && addr > (mm->task_size - len))
4696 return -EINVAL;
4697
4698+#ifdef CONFIG_PAX_RANDMMAP
4699+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4700+ addr = 0;
4701+#endif
4702+
4703 /* If hint, make sure it matches our alignment restrictions */
4704 if (!fixed && addr) {
4705 addr = _ALIGN_UP(addr, 1ul << pshift);
4706diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4707index 8517d2a..d2738d4 100644
4708--- a/arch/s390/include/asm/atomic.h
4709+++ b/arch/s390/include/asm/atomic.h
4710@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4711 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4712 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4713
4714+#define atomic64_read_unchecked(v) atomic64_read(v)
4715+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4716+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4717+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4718+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4719+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4720+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4721+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4722+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4723+
4724 #define smp_mb__before_atomic_dec() smp_mb()
4725 #define smp_mb__after_atomic_dec() smp_mb()
4726 #define smp_mb__before_atomic_inc() smp_mb()
4727diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4728index 2a30d5a..5e5586f 100644
4729--- a/arch/s390/include/asm/cache.h
4730+++ b/arch/s390/include/asm/cache.h
4731@@ -11,8 +11,10 @@
4732 #ifndef __ARCH_S390_CACHE_H
4733 #define __ARCH_S390_CACHE_H
4734
4735-#define L1_CACHE_BYTES 256
4736+#include <linux/const.h>
4737+
4738 #define L1_CACHE_SHIFT 8
4739+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4740 #define NET_SKB_PAD 32
4741
4742 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4743diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4744index 547f1a6..0b22b53 100644
4745--- a/arch/s390/include/asm/elf.h
4746+++ b/arch/s390/include/asm/elf.h
4747@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
4748 the loader. We need to make sure that it is out of the way of the program
4749 that it will "exec", and that there is sufficient room for the brk. */
4750
4751-extern unsigned long randomize_et_dyn(unsigned long base);
4752-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4753+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4754+
4755+#ifdef CONFIG_PAX_ASLR
4756+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4757+
4758+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4759+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4760+#endif
4761
4762 /* This yields a mask that user programs can use to figure out what
4763 instruction set this CPU supports. */
4764@@ -211,7 +217,4 @@ struct linux_binprm;
4765 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4766 int arch_setup_additional_pages(struct linux_binprm *, int);
4767
4768-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4769-#define arch_randomize_brk arch_randomize_brk
4770-
4771 #endif
4772diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
4773index d73cc6b..1a296ad 100644
4774--- a/arch/s390/include/asm/system.h
4775+++ b/arch/s390/include/asm/system.h
4776@@ -260,7 +260,7 @@ extern void (*_machine_restart)(char *command);
4777 extern void (*_machine_halt)(void);
4778 extern void (*_machine_power_off)(void);
4779
4780-extern unsigned long arch_align_stack(unsigned long sp);
4781+#define arch_align_stack(x) ((x) & ~0xfUL)
4782
4783 static inline int tprot(unsigned long addr)
4784 {
4785diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4786index 2b23885..e136e31 100644
4787--- a/arch/s390/include/asm/uaccess.h
4788+++ b/arch/s390/include/asm/uaccess.h
4789@@ -235,6 +235,10 @@ static inline unsigned long __must_check
4790 copy_to_user(void __user *to, const void *from, unsigned long n)
4791 {
4792 might_fault();
4793+
4794+ if ((long)n < 0)
4795+ return n;
4796+
4797 if (access_ok(VERIFY_WRITE, to, n))
4798 n = __copy_to_user(to, from, n);
4799 return n;
4800@@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4801 static inline unsigned long __must_check
4802 __copy_from_user(void *to, const void __user *from, unsigned long n)
4803 {
4804+ if ((long)n < 0)
4805+ return n;
4806+
4807 if (__builtin_constant_p(n) && (n <= 256))
4808 return uaccess.copy_from_user_small(n, from, to);
4809 else
4810@@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
4811 unsigned int sz = __compiletime_object_size(to);
4812
4813 might_fault();
4814+
4815+ if ((long)n < 0)
4816+ return n;
4817+
4818 if (unlikely(sz != -1 && sz < n)) {
4819 copy_from_user_overflow();
4820 return n;
4821diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4822index dfcb343..eda788a 100644
4823--- a/arch/s390/kernel/module.c
4824+++ b/arch/s390/kernel/module.c
4825@@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4826
4827 /* Increase core size by size of got & plt and set start
4828 offsets for got and plt. */
4829- me->core_size = ALIGN(me->core_size, 4);
4830- me->arch.got_offset = me->core_size;
4831- me->core_size += me->arch.got_size;
4832- me->arch.plt_offset = me->core_size;
4833- me->core_size += me->arch.plt_size;
4834+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
4835+ me->arch.got_offset = me->core_size_rw;
4836+ me->core_size_rw += me->arch.got_size;
4837+ me->arch.plt_offset = me->core_size_rx;
4838+ me->core_size_rx += me->arch.plt_size;
4839 return 0;
4840 }
4841
4842@@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4843 if (info->got_initialized == 0) {
4844 Elf_Addr *gotent;
4845
4846- gotent = me->module_core + me->arch.got_offset +
4847+ gotent = me->module_core_rw + me->arch.got_offset +
4848 info->got_offset;
4849 *gotent = val;
4850 info->got_initialized = 1;
4851@@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4852 else if (r_type == R_390_GOTENT ||
4853 r_type == R_390_GOTPLTENT)
4854 *(unsigned int *) loc =
4855- (val + (Elf_Addr) me->module_core - loc) >> 1;
4856+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4857 else if (r_type == R_390_GOT64 ||
4858 r_type == R_390_GOTPLT64)
4859 *(unsigned long *) loc = val;
4860@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4861 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4862 if (info->plt_initialized == 0) {
4863 unsigned int *ip;
4864- ip = me->module_core + me->arch.plt_offset +
4865+ ip = me->module_core_rx + me->arch.plt_offset +
4866 info->plt_offset;
4867 #ifndef CONFIG_64BIT
4868 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4869@@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4870 val - loc + 0xffffUL < 0x1ffffeUL) ||
4871 (r_type == R_390_PLT32DBL &&
4872 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4873- val = (Elf_Addr) me->module_core +
4874+ val = (Elf_Addr) me->module_core_rx +
4875 me->arch.plt_offset +
4876 info->plt_offset;
4877 val += rela->r_addend - loc;
4878@@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4879 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4880 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4881 val = val + rela->r_addend -
4882- ((Elf_Addr) me->module_core + me->arch.got_offset);
4883+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4884 if (r_type == R_390_GOTOFF16)
4885 *(unsigned short *) loc = val;
4886 else if (r_type == R_390_GOTOFF32)
4887@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4888 break;
4889 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4890 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4891- val = (Elf_Addr) me->module_core + me->arch.got_offset +
4892+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4893 rela->r_addend - loc;
4894 if (r_type == R_390_GOTPC)
4895 *(unsigned int *) loc = val;
4896diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4897index e795933..b32563c 100644
4898--- a/arch/s390/kernel/process.c
4899+++ b/arch/s390/kernel/process.c
4900@@ -323,39 +323,3 @@ unsigned long get_wchan(struct task_struct *p)
4901 }
4902 return 0;
4903 }
4904-
4905-unsigned long arch_align_stack(unsigned long sp)
4906-{
4907- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4908- sp -= get_random_int() & ~PAGE_MASK;
4909- return sp & ~0xf;
4910-}
4911-
4912-static inline unsigned long brk_rnd(void)
4913-{
4914- /* 8MB for 32bit, 1GB for 64bit */
4915- if (is_32bit_task())
4916- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4917- else
4918- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4919-}
4920-
4921-unsigned long arch_randomize_brk(struct mm_struct *mm)
4922-{
4923- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4924-
4925- if (ret < mm->brk)
4926- return mm->brk;
4927- return ret;
4928-}
4929-
4930-unsigned long randomize_et_dyn(unsigned long base)
4931-{
4932- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4933-
4934- if (!(current->flags & PF_RANDOMIZE))
4935- return base;
4936- if (ret < base)
4937- return base;
4938- return ret;
4939-}
4940diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4941index a0155c0..34cc491 100644
4942--- a/arch/s390/mm/mmap.c
4943+++ b/arch/s390/mm/mmap.c
4944@@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4945 */
4946 if (mmap_is_legacy()) {
4947 mm->mmap_base = TASK_UNMAPPED_BASE;
4948+
4949+#ifdef CONFIG_PAX_RANDMMAP
4950+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4951+ mm->mmap_base += mm->delta_mmap;
4952+#endif
4953+
4954 mm->get_unmapped_area = arch_get_unmapped_area;
4955 mm->unmap_area = arch_unmap_area;
4956 } else {
4957 mm->mmap_base = mmap_base();
4958+
4959+#ifdef CONFIG_PAX_RANDMMAP
4960+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4961+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4962+#endif
4963+
4964 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4965 mm->unmap_area = arch_unmap_area_topdown;
4966 }
4967@@ -167,10 +179,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4968 */
4969 if (mmap_is_legacy()) {
4970 mm->mmap_base = TASK_UNMAPPED_BASE;
4971+
4972+#ifdef CONFIG_PAX_RANDMMAP
4973+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4974+ mm->mmap_base += mm->delta_mmap;
4975+#endif
4976+
4977 mm->get_unmapped_area = s390_get_unmapped_area;
4978 mm->unmap_area = arch_unmap_area;
4979 } else {
4980 mm->mmap_base = mmap_base();
4981+
4982+#ifdef CONFIG_PAX_RANDMMAP
4983+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4984+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4985+#endif
4986+
4987 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4988 mm->unmap_area = arch_unmap_area_topdown;
4989 }
4990diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4991index ae3d59f..f65f075 100644
4992--- a/arch/score/include/asm/cache.h
4993+++ b/arch/score/include/asm/cache.h
4994@@ -1,7 +1,9 @@
4995 #ifndef _ASM_SCORE_CACHE_H
4996 #define _ASM_SCORE_CACHE_H
4997
4998+#include <linux/const.h>
4999+
5000 #define L1_CACHE_SHIFT 4
5001-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5002+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5003
5004 #endif /* _ASM_SCORE_CACHE_H */
5005diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
5006index 589d5c7..669e274 100644
5007--- a/arch/score/include/asm/system.h
5008+++ b/arch/score/include/asm/system.h
5009@@ -17,7 +17,7 @@ do { \
5010 #define finish_arch_switch(prev) do {} while (0)
5011
5012 typedef void (*vi_handler_t)(void);
5013-extern unsigned long arch_align_stack(unsigned long sp);
5014+#define arch_align_stack(x) (x)
5015
5016 #define mb() barrier()
5017 #define rmb() barrier()
5018diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
5019index 25d0803..d6c8e36 100644
5020--- a/arch/score/kernel/process.c
5021+++ b/arch/score/kernel/process.c
5022@@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
5023
5024 return task_pt_regs(task)->cp0_epc;
5025 }
5026-
5027-unsigned long arch_align_stack(unsigned long sp)
5028-{
5029- return sp;
5030-}
5031diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
5032index ef9e555..331bd29 100644
5033--- a/arch/sh/include/asm/cache.h
5034+++ b/arch/sh/include/asm/cache.h
5035@@ -9,10 +9,11 @@
5036 #define __ASM_SH_CACHE_H
5037 #ifdef __KERNEL__
5038
5039+#include <linux/const.h>
5040 #include <linux/init.h>
5041 #include <cpu/cache.h>
5042
5043-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5044+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5045
5046 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5047
5048diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5049index afeb710..d1d1289 100644
5050--- a/arch/sh/mm/mmap.c
5051+++ b/arch/sh/mm/mmap.c
5052@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5053 addr = PAGE_ALIGN(addr);
5054
5055 vma = find_vma(mm, addr);
5056- if (TASK_SIZE - len >= addr &&
5057- (!vma || addr + len <= vma->vm_start))
5058+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5059 return addr;
5060 }
5061
5062@@ -106,7 +105,7 @@ full_search:
5063 }
5064 return -ENOMEM;
5065 }
5066- if (likely(!vma || addr + len <= vma->vm_start)) {
5067+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5068 /*
5069 * Remember the place where we stopped the search:
5070 */
5071@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5072 addr = PAGE_ALIGN(addr);
5073
5074 vma = find_vma(mm, addr);
5075- if (TASK_SIZE - len >= addr &&
5076- (!vma || addr + len <= vma->vm_start))
5077+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5078 return addr;
5079 }
5080
5081@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5082 /* make sure it can fit in the remaining address space */
5083 if (likely(addr > len)) {
5084 vma = find_vma(mm, addr-len);
5085- if (!vma || addr <= vma->vm_start) {
5086+ if (check_heap_stack_gap(vma, addr - len, len)) {
5087 /* remember the address as a hint for next time */
5088 return (mm->free_area_cache = addr-len);
5089 }
5090@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5091 if (unlikely(mm->mmap_base < len))
5092 goto bottomup;
5093
5094- addr = mm->mmap_base-len;
5095- if (do_colour_align)
5096- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5097+ addr = mm->mmap_base - len;
5098
5099 do {
5100+ if (do_colour_align)
5101+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5102 /*
5103 * Lookup failure means no vma is above this address,
5104 * else if new region fits below vma->vm_start,
5105 * return with success:
5106 */
5107 vma = find_vma(mm, addr);
5108- if (likely(!vma || addr+len <= vma->vm_start)) {
5109+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5110 /* remember the address as a hint for next time */
5111 return (mm->free_area_cache = addr);
5112 }
5113@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5114 mm->cached_hole_size = vma->vm_start - addr;
5115
5116 /* try just below the current vma->vm_start */
5117- addr = vma->vm_start-len;
5118- if (do_colour_align)
5119- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5120- } while (likely(len < vma->vm_start));
5121+ addr = skip_heap_stack_gap(vma, len);
5122+ } while (!IS_ERR_VALUE(addr));
5123
5124 bottomup:
5125 /*
5126diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
5127index eddcfb3..b117d90 100644
5128--- a/arch/sparc/Makefile
5129+++ b/arch/sparc/Makefile
5130@@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
5131 # Export what is needed by arch/sparc/boot/Makefile
5132 export VMLINUX_INIT VMLINUX_MAIN
5133 VMLINUX_INIT := $(head-y) $(init-y)
5134-VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
5135+VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
5136 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
5137 VMLINUX_MAIN += $(drivers-y) $(net-y)
5138
5139diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5140index 9f421df..b81fc12 100644
5141--- a/arch/sparc/include/asm/atomic_64.h
5142+++ b/arch/sparc/include/asm/atomic_64.h
5143@@ -14,18 +14,40 @@
5144 #define ATOMIC64_INIT(i) { (i) }
5145
5146 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5147+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5148+{
5149+ return v->counter;
5150+}
5151 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5152+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5153+{
5154+ return v->counter;
5155+}
5156
5157 #define atomic_set(v, i) (((v)->counter) = i)
5158+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5159+{
5160+ v->counter = i;
5161+}
5162 #define atomic64_set(v, i) (((v)->counter) = i)
5163+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5164+{
5165+ v->counter = i;
5166+}
5167
5168 extern void atomic_add(int, atomic_t *);
5169+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5170 extern void atomic64_add(long, atomic64_t *);
5171+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5172 extern void atomic_sub(int, atomic_t *);
5173+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5174 extern void atomic64_sub(long, atomic64_t *);
5175+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5176
5177 extern int atomic_add_ret(int, atomic_t *);
5178+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5179 extern long atomic64_add_ret(long, atomic64_t *);
5180+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5181 extern int atomic_sub_ret(int, atomic_t *);
5182 extern long atomic64_sub_ret(long, atomic64_t *);
5183
5184@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5185 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5186
5187 #define atomic_inc_return(v) atomic_add_ret(1, v)
5188+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5189+{
5190+ return atomic_add_ret_unchecked(1, v);
5191+}
5192 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5193+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5194+{
5195+ return atomic64_add_ret_unchecked(1, v);
5196+}
5197
5198 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5199 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5200
5201 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5202+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5203+{
5204+ return atomic_add_ret_unchecked(i, v);
5205+}
5206 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5207+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5208+{
5209+ return atomic64_add_ret_unchecked(i, v);
5210+}
5211
5212 /*
5213 * atomic_inc_and_test - increment and test
5214@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5215 * other cases.
5216 */
5217 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5218+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5219+{
5220+ return atomic_inc_return_unchecked(v) == 0;
5221+}
5222 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5223
5224 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5225@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5226 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5227
5228 #define atomic_inc(v) atomic_add(1, v)
5229+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5230+{
5231+ atomic_add_unchecked(1, v);
5232+}
5233 #define atomic64_inc(v) atomic64_add(1, v)
5234+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5235+{
5236+ atomic64_add_unchecked(1, v);
5237+}
5238
5239 #define atomic_dec(v) atomic_sub(1, v)
5240+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5241+{
5242+ atomic_sub_unchecked(1, v);
5243+}
5244 #define atomic64_dec(v) atomic64_sub(1, v)
5245+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5246+{
5247+ atomic64_sub_unchecked(1, v);
5248+}
5249
5250 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5251 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5252
5253 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5254+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5255+{
5256+ return cmpxchg(&v->counter, old, new);
5257+}
5258 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5259+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5260+{
5261+ return xchg(&v->counter, new);
5262+}
5263
5264 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5265 {
5266- int c, old;
5267+ int c, old, new;
5268 c = atomic_read(v);
5269 for (;;) {
5270- if (unlikely(c == (u)))
5271+ if (unlikely(c == u))
5272 break;
5273- old = atomic_cmpxchg((v), c, c + (a));
5274+
5275+ asm volatile("addcc %2, %0, %0\n"
5276+
5277+#ifdef CONFIG_PAX_REFCOUNT
5278+ "tvs %%icc, 6\n"
5279+#endif
5280+
5281+ : "=r" (new)
5282+ : "0" (c), "ir" (a)
5283+ : "cc");
5284+
5285+ old = atomic_cmpxchg(v, c, new);
5286 if (likely(old == c))
5287 break;
5288 c = old;
5289@@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5290 #define atomic64_cmpxchg(v, o, n) \
5291 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5292 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5293+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5294+{
5295+ return xchg(&v->counter, new);
5296+}
5297
5298 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5299 {
5300- long c, old;
5301+ long c, old, new;
5302 c = atomic64_read(v);
5303 for (;;) {
5304- if (unlikely(c == (u)))
5305+ if (unlikely(c == u))
5306 break;
5307- old = atomic64_cmpxchg((v), c, c + (a));
5308+
5309+ asm volatile("addcc %2, %0, %0\n"
5310+
5311+#ifdef CONFIG_PAX_REFCOUNT
5312+ "tvs %%xcc, 6\n"
5313+#endif
5314+
5315+ : "=r" (new)
5316+ : "0" (c), "ir" (a)
5317+ : "cc");
5318+
5319+ old = atomic64_cmpxchg(v, c, new);
5320 if (likely(old == c))
5321 break;
5322 c = old;
5323 }
5324- return c != (u);
5325+ return c != u;
5326 }
5327
5328 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5329diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5330index 69358b5..9d0d492 100644
5331--- a/arch/sparc/include/asm/cache.h
5332+++ b/arch/sparc/include/asm/cache.h
5333@@ -7,10 +7,12 @@
5334 #ifndef _SPARC_CACHE_H
5335 #define _SPARC_CACHE_H
5336
5337+#include <linux/const.h>
5338+
5339 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5340
5341 #define L1_CACHE_SHIFT 5
5342-#define L1_CACHE_BYTES 32
5343+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5344
5345 #ifdef CONFIG_SPARC32
5346 #define SMP_CACHE_BYTES_SHIFT 5
5347diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5348index 4269ca6..e3da77f 100644
5349--- a/arch/sparc/include/asm/elf_32.h
5350+++ b/arch/sparc/include/asm/elf_32.h
5351@@ -114,6 +114,13 @@ typedef struct {
5352
5353 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5354
5355+#ifdef CONFIG_PAX_ASLR
5356+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5357+
5358+#define PAX_DELTA_MMAP_LEN 16
5359+#define PAX_DELTA_STACK_LEN 16
5360+#endif
5361+
5362 /* This yields a mask that user programs can use to figure out what
5363 instruction set this cpu supports. This can NOT be done in userspace
5364 on Sparc. */
5365diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5366index 7df8b7f..4946269 100644
5367--- a/arch/sparc/include/asm/elf_64.h
5368+++ b/arch/sparc/include/asm/elf_64.h
5369@@ -180,6 +180,13 @@ typedef struct {
5370 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5371 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5372
5373+#ifdef CONFIG_PAX_ASLR
5374+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5375+
5376+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5377+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5378+#endif
5379+
5380 extern unsigned long sparc64_elf_hwcap;
5381 #define ELF_HWCAP sparc64_elf_hwcap
5382
5383diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5384index ca2b344..c6084f89 100644
5385--- a/arch/sparc/include/asm/pgalloc_32.h
5386+++ b/arch/sparc/include/asm/pgalloc_32.h
5387@@ -37,6 +37,7 @@ BTFIXUPDEF_CALL(void, free_pgd_fast, pgd_t *)
5388 BTFIXUPDEF_CALL(void, pgd_set, pgd_t *, pmd_t *)
5389 #define pgd_set(pgdp,pmdp) BTFIXUP_CALL(pgd_set)(pgdp,pmdp)
5390 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5391+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5392
5393 BTFIXUPDEF_CALL(pmd_t *, pmd_alloc_one, struct mm_struct *, unsigned long)
5394 #define pmd_alloc_one(mm, address) BTFIXUP_CALL(pmd_alloc_one)(mm, address)
5395diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5396index 40b2d7a..22a665b 100644
5397--- a/arch/sparc/include/asm/pgalloc_64.h
5398+++ b/arch/sparc/include/asm/pgalloc_64.h
5399@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5400 }
5401
5402 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5403+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5404
5405 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5406 {
5407diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5408index a790cc6..091ed94 100644
5409--- a/arch/sparc/include/asm/pgtable_32.h
5410+++ b/arch/sparc/include/asm/pgtable_32.h
5411@@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
5412 BTFIXUPDEF_INT(page_none)
5413 BTFIXUPDEF_INT(page_copy)
5414 BTFIXUPDEF_INT(page_readonly)
5415+
5416+#ifdef CONFIG_PAX_PAGEEXEC
5417+BTFIXUPDEF_INT(page_shared_noexec)
5418+BTFIXUPDEF_INT(page_copy_noexec)
5419+BTFIXUPDEF_INT(page_readonly_noexec)
5420+#endif
5421+
5422 BTFIXUPDEF_INT(page_kernel)
5423
5424 #define PMD_SHIFT SUN4C_PMD_SHIFT
5425@@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
5426 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
5427 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
5428
5429+#ifdef CONFIG_PAX_PAGEEXEC
5430+extern pgprot_t PAGE_SHARED_NOEXEC;
5431+# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
5432+# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
5433+#else
5434+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5435+# define PAGE_COPY_NOEXEC PAGE_COPY
5436+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5437+#endif
5438+
5439 extern unsigned long page_kernel;
5440
5441 #ifdef MODULE
5442diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5443index f6ae2b2..b03ffc7 100644
5444--- a/arch/sparc/include/asm/pgtsrmmu.h
5445+++ b/arch/sparc/include/asm/pgtsrmmu.h
5446@@ -115,6 +115,13 @@
5447 SRMMU_EXEC | SRMMU_REF)
5448 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5449 SRMMU_EXEC | SRMMU_REF)
5450+
5451+#ifdef CONFIG_PAX_PAGEEXEC
5452+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5453+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5454+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5455+#endif
5456+
5457 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5458 SRMMU_DIRTY | SRMMU_REF)
5459
5460diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5461index 9689176..63c18ea 100644
5462--- a/arch/sparc/include/asm/spinlock_64.h
5463+++ b/arch/sparc/include/asm/spinlock_64.h
5464@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5465
5466 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5467
5468-static void inline arch_read_lock(arch_rwlock_t *lock)
5469+static inline void arch_read_lock(arch_rwlock_t *lock)
5470 {
5471 unsigned long tmp1, tmp2;
5472
5473 __asm__ __volatile__ (
5474 "1: ldsw [%2], %0\n"
5475 " brlz,pn %0, 2f\n"
5476-"4: add %0, 1, %1\n"
5477+"4: addcc %0, 1, %1\n"
5478+
5479+#ifdef CONFIG_PAX_REFCOUNT
5480+" tvs %%icc, 6\n"
5481+#endif
5482+
5483 " cas [%2], %0, %1\n"
5484 " cmp %0, %1\n"
5485 " bne,pn %%icc, 1b\n"
5486@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5487 " .previous"
5488 : "=&r" (tmp1), "=&r" (tmp2)
5489 : "r" (lock)
5490- : "memory");
5491+ : "memory", "cc");
5492 }
5493
5494-static int inline arch_read_trylock(arch_rwlock_t *lock)
5495+static inline int arch_read_trylock(arch_rwlock_t *lock)
5496 {
5497 int tmp1, tmp2;
5498
5499@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5500 "1: ldsw [%2], %0\n"
5501 " brlz,a,pn %0, 2f\n"
5502 " mov 0, %0\n"
5503-" add %0, 1, %1\n"
5504+" addcc %0, 1, %1\n"
5505+
5506+#ifdef CONFIG_PAX_REFCOUNT
5507+" tvs %%icc, 6\n"
5508+#endif
5509+
5510 " cas [%2], %0, %1\n"
5511 " cmp %0, %1\n"
5512 " bne,pn %%icc, 1b\n"
5513@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5514 return tmp1;
5515 }
5516
5517-static void inline arch_read_unlock(arch_rwlock_t *lock)
5518+static inline void arch_read_unlock(arch_rwlock_t *lock)
5519 {
5520 unsigned long tmp1, tmp2;
5521
5522 __asm__ __volatile__(
5523 "1: lduw [%2], %0\n"
5524-" sub %0, 1, %1\n"
5525+" subcc %0, 1, %1\n"
5526+
5527+#ifdef CONFIG_PAX_REFCOUNT
5528+" tvs %%icc, 6\n"
5529+#endif
5530+
5531 " cas [%2], %0, %1\n"
5532 " cmp %0, %1\n"
5533 " bne,pn %%xcc, 1b\n"
5534@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5535 : "memory");
5536 }
5537
5538-static void inline arch_write_lock(arch_rwlock_t *lock)
5539+static inline void arch_write_lock(arch_rwlock_t *lock)
5540 {
5541 unsigned long mask, tmp1, tmp2;
5542
5543@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5544 : "memory");
5545 }
5546
5547-static void inline arch_write_unlock(arch_rwlock_t *lock)
5548+static inline void arch_write_unlock(arch_rwlock_t *lock)
5549 {
5550 __asm__ __volatile__(
5551 " stw %%g0, [%0]"
5552@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5553 : "memory");
5554 }
5555
5556-static int inline arch_write_trylock(arch_rwlock_t *lock)
5557+static inline int arch_write_trylock(arch_rwlock_t *lock)
5558 {
5559 unsigned long mask, tmp1, tmp2, result;
5560
5561diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5562index c2a1080..21ed218 100644
5563--- a/arch/sparc/include/asm/thread_info_32.h
5564+++ b/arch/sparc/include/asm/thread_info_32.h
5565@@ -50,6 +50,8 @@ struct thread_info {
5566 unsigned long w_saved;
5567
5568 struct restart_block restart_block;
5569+
5570+ unsigned long lowest_stack;
5571 };
5572
5573 /*
5574diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5575index 01d057f..13a7d2f 100644
5576--- a/arch/sparc/include/asm/thread_info_64.h
5577+++ b/arch/sparc/include/asm/thread_info_64.h
5578@@ -63,6 +63,8 @@ struct thread_info {
5579 struct pt_regs *kern_una_regs;
5580 unsigned int kern_una_insn;
5581
5582+ unsigned long lowest_stack;
5583+
5584 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5585 };
5586
5587@@ -214,10 +216,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5588 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5589 /* flag bit 6 is available */
5590 #define TIF_32BIT 7 /* 32-bit binary */
5591-/* flag bit 8 is available */
5592+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5593 #define TIF_SECCOMP 9 /* secure computing */
5594 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5595 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5596+
5597 /* NOTE: Thread flags >= 12 should be ones we have no interest
5598 * in using in assembly, else we can't use the mask as
5599 * an immediate value in instructions such as andcc.
5600@@ -236,12 +239,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5601 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5602 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5603 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5604+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5605
5606 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5607 _TIF_DO_NOTIFY_RESUME_MASK | \
5608 _TIF_NEED_RESCHED)
5609 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5610
5611+#define _TIF_WORK_SYSCALL \
5612+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5613+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5614+
5615+
5616 /*
5617 * Thread-synchronous status.
5618 *
5619diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5620index e88fbe5..96b0ce5 100644
5621--- a/arch/sparc/include/asm/uaccess.h
5622+++ b/arch/sparc/include/asm/uaccess.h
5623@@ -1,5 +1,13 @@
5624 #ifndef ___ASM_SPARC_UACCESS_H
5625 #define ___ASM_SPARC_UACCESS_H
5626+
5627+#ifdef __KERNEL__
5628+#ifndef __ASSEMBLY__
5629+#include <linux/types.h>
5630+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5631+#endif
5632+#endif
5633+
5634 #if defined(__sparc__) && defined(__arch64__)
5635 #include <asm/uaccess_64.h>
5636 #else
5637diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5638index 8303ac4..07f333d 100644
5639--- a/arch/sparc/include/asm/uaccess_32.h
5640+++ b/arch/sparc/include/asm/uaccess_32.h
5641@@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5642
5643 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5644 {
5645- if (n && __access_ok((unsigned long) to, n))
5646+ if ((long)n < 0)
5647+ return n;
5648+
5649+ if (n && __access_ok((unsigned long) to, n)) {
5650+ if (!__builtin_constant_p(n))
5651+ check_object_size(from, n, true);
5652 return __copy_user(to, (__force void __user *) from, n);
5653- else
5654+ } else
5655 return n;
5656 }
5657
5658 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5659 {
5660+ if ((long)n < 0)
5661+ return n;
5662+
5663+ if (!__builtin_constant_p(n))
5664+ check_object_size(from, n, true);
5665+
5666 return __copy_user(to, (__force void __user *) from, n);
5667 }
5668
5669 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5670 {
5671- if (n && __access_ok((unsigned long) from, n))
5672+ if ((long)n < 0)
5673+ return n;
5674+
5675+ if (n && __access_ok((unsigned long) from, n)) {
5676+ if (!__builtin_constant_p(n))
5677+ check_object_size(to, n, false);
5678 return __copy_user((__force void __user *) to, from, n);
5679- else
5680+ } else
5681 return n;
5682 }
5683
5684 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5685 {
5686+ if ((long)n < 0)
5687+ return n;
5688+
5689 return __copy_user((__force void __user *) to, from, n);
5690 }
5691
5692diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5693index 3e1449f..5293a0e 100644
5694--- a/arch/sparc/include/asm/uaccess_64.h
5695+++ b/arch/sparc/include/asm/uaccess_64.h
5696@@ -10,6 +10,7 @@
5697 #include <linux/compiler.h>
5698 #include <linux/string.h>
5699 #include <linux/thread_info.h>
5700+#include <linux/kernel.h>
5701 #include <asm/asi.h>
5702 #include <asm/system.h>
5703 #include <asm/spitfire.h>
5704@@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5705 static inline unsigned long __must_check
5706 copy_from_user(void *to, const void __user *from, unsigned long size)
5707 {
5708- unsigned long ret = ___copy_from_user(to, from, size);
5709+ unsigned long ret;
5710
5711+ if ((long)size < 0 || size > INT_MAX)
5712+ return size;
5713+
5714+ if (!__builtin_constant_p(size))
5715+ check_object_size(to, size, false);
5716+
5717+ ret = ___copy_from_user(to, from, size);
5718 if (unlikely(ret))
5719 ret = copy_from_user_fixup(to, from, size);
5720
5721@@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5722 static inline unsigned long __must_check
5723 copy_to_user(void __user *to, const void *from, unsigned long size)
5724 {
5725- unsigned long ret = ___copy_to_user(to, from, size);
5726+ unsigned long ret;
5727
5728+ if ((long)size < 0 || size > INT_MAX)
5729+ return size;
5730+
5731+ if (!__builtin_constant_p(size))
5732+ check_object_size(from, size, true);
5733+
5734+ ret = ___copy_to_user(to, from, size);
5735 if (unlikely(ret))
5736 ret = copy_to_user_fixup(to, from, size);
5737 return ret;
5738diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5739index cb85458..e063f17 100644
5740--- a/arch/sparc/kernel/Makefile
5741+++ b/arch/sparc/kernel/Makefile
5742@@ -3,7 +3,7 @@
5743 #
5744
5745 asflags-y := -ansi
5746-ccflags-y := -Werror
5747+#ccflags-y := -Werror
5748
5749 extra-y := head_$(BITS).o
5750 extra-y += init_task.o
5751diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5752index f793742..4d880af 100644
5753--- a/arch/sparc/kernel/process_32.c
5754+++ b/arch/sparc/kernel/process_32.c
5755@@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
5756 rw->ins[4], rw->ins[5],
5757 rw->ins[6],
5758 rw->ins[7]);
5759- printk("%pS\n", (void *) rw->ins[7]);
5760+ printk("%pA\n", (void *) rw->ins[7]);
5761 rw = (struct reg_window32 *) rw->ins[6];
5762 }
5763 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5764@@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
5765
5766 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5767 r->psr, r->pc, r->npc, r->y, print_tainted());
5768- printk("PC: <%pS>\n", (void *) r->pc);
5769+ printk("PC: <%pA>\n", (void *) r->pc);
5770 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5771 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5772 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5773 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5774 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5775 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5776- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5777+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5778
5779 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5780 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5781@@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5782 rw = (struct reg_window32 *) fp;
5783 pc = rw->ins[7];
5784 printk("[%08lx : ", pc);
5785- printk("%pS ] ", (void *) pc);
5786+ printk("%pA ] ", (void *) pc);
5787 fp = rw->ins[6];
5788 } while (++count < 16);
5789 printk("\n");
5790diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5791index 39d8b05..d1a7d90 100644
5792--- a/arch/sparc/kernel/process_64.c
5793+++ b/arch/sparc/kernel/process_64.c
5794@@ -182,14 +182,14 @@ static void show_regwindow(struct pt_regs *regs)
5795 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5796 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5797 if (regs->tstate & TSTATE_PRIV)
5798- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5799+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5800 }
5801
5802 void show_regs(struct pt_regs *regs)
5803 {
5804 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5805 regs->tpc, regs->tnpc, regs->y, print_tainted());
5806- printk("TPC: <%pS>\n", (void *) regs->tpc);
5807+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5808 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5809 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5810 regs->u_regs[3]);
5811@@ -202,7 +202,7 @@ void show_regs(struct pt_regs *regs)
5812 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5813 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5814 regs->u_regs[15]);
5815- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5816+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5817 show_regwindow(regs);
5818 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5819 }
5820@@ -287,7 +287,7 @@ void arch_trigger_all_cpu_backtrace(void)
5821 ((tp && tp->task) ? tp->task->pid : -1));
5822
5823 if (gp->tstate & TSTATE_PRIV) {
5824- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5825+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5826 (void *) gp->tpc,
5827 (void *) gp->o7,
5828 (void *) gp->i7,
5829diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5830index 9388844..0075fd2 100644
5831--- a/arch/sparc/kernel/ptrace_64.c
5832+++ b/arch/sparc/kernel/ptrace_64.c
5833@@ -1058,6 +1058,10 @@ long arch_ptrace(struct task_struct *child, long request,
5834 return ret;
5835 }
5836
5837+#ifdef CONFIG_GRKERNSEC_SETXID
5838+extern void gr_delayed_cred_worker(void);
5839+#endif
5840+
5841 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5842 {
5843 int ret = 0;
5844@@ -1065,6 +1069,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5845 /* do the secure computing check first */
5846 secure_computing(regs->u_regs[UREG_G1]);
5847
5848+#ifdef CONFIG_GRKERNSEC_SETXID
5849+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5850+ gr_delayed_cred_worker();
5851+#endif
5852+
5853 if (test_thread_flag(TIF_SYSCALL_TRACE))
5854 ret = tracehook_report_syscall_entry(regs);
5855
5856@@ -1085,6 +1094,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5857
5858 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5859 {
5860+#ifdef CONFIG_GRKERNSEC_SETXID
5861+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5862+ gr_delayed_cred_worker();
5863+#endif
5864+
5865 audit_syscall_exit(regs);
5866
5867 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5868diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5869index 42b282f..28ce9f2 100644
5870--- a/arch/sparc/kernel/sys_sparc_32.c
5871+++ b/arch/sparc/kernel/sys_sparc_32.c
5872@@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5873 if (ARCH_SUN4C && len > 0x20000000)
5874 return -ENOMEM;
5875 if (!addr)
5876- addr = TASK_UNMAPPED_BASE;
5877+ addr = current->mm->mmap_base;
5878
5879 if (flags & MAP_SHARED)
5880 addr = COLOUR_ALIGN(addr);
5881@@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5882 }
5883 if (TASK_SIZE - PAGE_SIZE - len < addr)
5884 return -ENOMEM;
5885- if (!vmm || addr + len <= vmm->vm_start)
5886+ if (check_heap_stack_gap(vmm, addr, len))
5887 return addr;
5888 addr = vmm->vm_end;
5889 if (flags & MAP_SHARED)
5890diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5891index 232df99..cee1f9c 100644
5892--- a/arch/sparc/kernel/sys_sparc_64.c
5893+++ b/arch/sparc/kernel/sys_sparc_64.c
5894@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5895 /* We do not accept a shared mapping if it would violate
5896 * cache aliasing constraints.
5897 */
5898- if ((flags & MAP_SHARED) &&
5899+ if ((filp || (flags & MAP_SHARED)) &&
5900 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5901 return -EINVAL;
5902 return addr;
5903@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5904 if (filp || (flags & MAP_SHARED))
5905 do_color_align = 1;
5906
5907+#ifdef CONFIG_PAX_RANDMMAP
5908+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5909+#endif
5910+
5911 if (addr) {
5912 if (do_color_align)
5913 addr = COLOUR_ALIGN(addr, pgoff);
5914@@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
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 if (len > mm->cached_hole_size) {
5925- start_addr = addr = mm->free_area_cache;
5926+ start_addr = addr = mm->free_area_cache;
5927 } else {
5928- start_addr = addr = TASK_UNMAPPED_BASE;
5929+ start_addr = addr = mm->mmap_base;
5930 mm->cached_hole_size = 0;
5931 }
5932
5933@@ -174,14 +177,14 @@ full_search:
5934 vma = find_vma(mm, VA_EXCLUDE_END);
5935 }
5936 if (unlikely(task_size < addr)) {
5937- if (start_addr != TASK_UNMAPPED_BASE) {
5938- start_addr = addr = TASK_UNMAPPED_BASE;
5939+ if (start_addr != mm->mmap_base) {
5940+ start_addr = addr = mm->mmap_base;
5941 mm->cached_hole_size = 0;
5942 goto full_search;
5943 }
5944 return -ENOMEM;
5945 }
5946- if (likely(!vma || addr + len <= vma->vm_start)) {
5947+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5948 /*
5949 * Remember the place where we stopped the search:
5950 */
5951@@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5952 /* We do not accept a shared mapping if it would violate
5953 * cache aliasing constraints.
5954 */
5955- if ((flags & MAP_SHARED) &&
5956+ if ((filp || (flags & MAP_SHARED)) &&
5957 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5958 return -EINVAL;
5959 return addr;
5960@@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5961 addr = PAGE_ALIGN(addr);
5962
5963 vma = find_vma(mm, addr);
5964- if (task_size - len >= addr &&
5965- (!vma || addr + len <= vma->vm_start))
5966+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5967 return addr;
5968 }
5969
5970@@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5971 /* make sure it can fit in the remaining address space */
5972 if (likely(addr > len)) {
5973 vma = find_vma(mm, addr-len);
5974- if (!vma || addr <= vma->vm_start) {
5975+ if (check_heap_stack_gap(vma, addr - len, len)) {
5976 /* remember the address as a hint for next time */
5977 return (mm->free_area_cache = addr-len);
5978 }
5979@@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5980 if (unlikely(mm->mmap_base < len))
5981 goto bottomup;
5982
5983- addr = mm->mmap_base-len;
5984- if (do_color_align)
5985- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5986+ addr = mm->mmap_base - len;
5987
5988 do {
5989+ if (do_color_align)
5990+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5991 /*
5992 * Lookup failure means no vma is above this address,
5993 * else if new region fits below vma->vm_start,
5994 * return with success:
5995 */
5996 vma = find_vma(mm, addr);
5997- if (likely(!vma || addr+len <= vma->vm_start)) {
5998+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5999 /* remember the address as a hint for next time */
6000 return (mm->free_area_cache = addr);
6001 }
6002@@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6003 mm->cached_hole_size = vma->vm_start - addr;
6004
6005 /* try just below the current vma->vm_start */
6006- addr = vma->vm_start-len;
6007- if (do_color_align)
6008- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6009- } while (likely(len < vma->vm_start));
6010+ addr = skip_heap_stack_gap(vma, len);
6011+ } while (!IS_ERR_VALUE(addr));
6012
6013 bottomup:
6014 /*
6015@@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6016 gap == RLIM_INFINITY ||
6017 sysctl_legacy_va_layout) {
6018 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6019+
6020+#ifdef CONFIG_PAX_RANDMMAP
6021+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6022+ mm->mmap_base += mm->delta_mmap;
6023+#endif
6024+
6025 mm->get_unmapped_area = arch_get_unmapped_area;
6026 mm->unmap_area = arch_unmap_area;
6027 } else {
6028@@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6029 gap = (task_size / 6 * 5);
6030
6031 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
6032+
6033+#ifdef CONFIG_PAX_RANDMMAP
6034+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6035+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6036+#endif
6037+
6038 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6039 mm->unmap_area = arch_unmap_area_topdown;
6040 }
6041diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
6042index 1d7e274..b39c527 100644
6043--- a/arch/sparc/kernel/syscalls.S
6044+++ b/arch/sparc/kernel/syscalls.S
6045@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6046 #endif
6047 .align 32
6048 1: ldx [%g6 + TI_FLAGS], %l5
6049- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6050+ andcc %l5, _TIF_WORK_SYSCALL, %g0
6051 be,pt %icc, rtrap
6052 nop
6053 call syscall_trace_leave
6054@@ -179,7 +179,7 @@ linux_sparc_syscall32:
6055
6056 srl %i5, 0, %o5 ! IEU1
6057 srl %i2, 0, %o2 ! IEU0 Group
6058- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6059+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6060 bne,pn %icc, linux_syscall_trace32 ! CTI
6061 mov %i0, %l5 ! IEU1
6062 call %l7 ! CTI Group brk forced
6063@@ -202,7 +202,7 @@ linux_sparc_syscall:
6064
6065 mov %i3, %o3 ! IEU1
6066 mov %i4, %o4 ! IEU0 Group
6067- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6068+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6069 bne,pn %icc, linux_syscall_trace ! CTI Group
6070 mov %i0, %l5 ! IEU0
6071 2: call %l7 ! CTI Group brk forced
6072@@ -226,7 +226,7 @@ ret_sys_call:
6073
6074 cmp %o0, -ERESTART_RESTARTBLOCK
6075 bgeu,pn %xcc, 1f
6076- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6077+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6078 80:
6079 /* System call success, clear Carry condition code. */
6080 andn %g3, %g2, %g3
6081@@ -241,7 +241,7 @@ ret_sys_call:
6082 /* System call failure, set Carry condition code.
6083 * Also, get abs(errno) to return to the process.
6084 */
6085- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6086+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6087 sub %g0, %o0, %o0
6088 or %g3, %g2, %g3
6089 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6090diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6091index 591f20c..0f1b925 100644
6092--- a/arch/sparc/kernel/traps_32.c
6093+++ b/arch/sparc/kernel/traps_32.c
6094@@ -45,6 +45,8 @@ static void instruction_dump(unsigned long *pc)
6095 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6096 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6097
6098+extern void gr_handle_kernel_exploit(void);
6099+
6100 void die_if_kernel(char *str, struct pt_regs *regs)
6101 {
6102 static int die_counter;
6103@@ -77,15 +79,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6104 count++ < 30 &&
6105 (((unsigned long) rw) >= PAGE_OFFSET) &&
6106 !(((unsigned long) rw) & 0x7)) {
6107- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6108+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6109 (void *) rw->ins[7]);
6110 rw = (struct reg_window32 *)rw->ins[6];
6111 }
6112 }
6113 printk("Instruction DUMP:");
6114 instruction_dump ((unsigned long *) regs->pc);
6115- if(regs->psr & PSR_PS)
6116+ if(regs->psr & PSR_PS) {
6117+ gr_handle_kernel_exploit();
6118 do_exit(SIGKILL);
6119+ }
6120 do_exit(SIGSEGV);
6121 }
6122
6123diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6124index 0cbdaa4..438e4c9 100644
6125--- a/arch/sparc/kernel/traps_64.c
6126+++ b/arch/sparc/kernel/traps_64.c
6127@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6128 i + 1,
6129 p->trapstack[i].tstate, p->trapstack[i].tpc,
6130 p->trapstack[i].tnpc, p->trapstack[i].tt);
6131- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6132+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6133 }
6134 }
6135
6136@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6137
6138 lvl -= 0x100;
6139 if (regs->tstate & TSTATE_PRIV) {
6140+
6141+#ifdef CONFIG_PAX_REFCOUNT
6142+ if (lvl == 6)
6143+ pax_report_refcount_overflow(regs);
6144+#endif
6145+
6146 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6147 die_if_kernel(buffer, regs);
6148 }
6149@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6150 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6151 {
6152 char buffer[32];
6153-
6154+
6155 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6156 0, lvl, SIGTRAP) == NOTIFY_STOP)
6157 return;
6158
6159+#ifdef CONFIG_PAX_REFCOUNT
6160+ if (lvl == 6)
6161+ pax_report_refcount_overflow(regs);
6162+#endif
6163+
6164 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6165
6166 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6167@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6168 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6169 printk("%s" "ERROR(%d): ",
6170 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6171- printk("TPC<%pS>\n", (void *) regs->tpc);
6172+ printk("TPC<%pA>\n", (void *) regs->tpc);
6173 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6174 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6175 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6176@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6177 smp_processor_id(),
6178 (type & 0x1) ? 'I' : 'D',
6179 regs->tpc);
6180- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6181+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6182 panic("Irrecoverable Cheetah+ parity error.");
6183 }
6184
6185@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6186 smp_processor_id(),
6187 (type & 0x1) ? 'I' : 'D',
6188 regs->tpc);
6189- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6190+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6191 }
6192
6193 struct sun4v_error_entry {
6194@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6195
6196 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6197 regs->tpc, tl);
6198- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6199+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6200 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6201- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6202+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6203 (void *) regs->u_regs[UREG_I7]);
6204 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6205 "pte[%lx] error[%lx]\n",
6206@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6207
6208 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6209 regs->tpc, tl);
6210- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6211+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6212 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6213- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6214+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6215 (void *) regs->u_regs[UREG_I7]);
6216 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6217 "pte[%lx] error[%lx]\n",
6218@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6219 fp = (unsigned long)sf->fp + STACK_BIAS;
6220 }
6221
6222- printk(" [%016lx] %pS\n", pc, (void *) pc);
6223+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6224 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6225 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6226 int index = tsk->curr_ret_stack;
6227 if (tsk->ret_stack && index >= graph) {
6228 pc = tsk->ret_stack[index - graph].ret;
6229- printk(" [%016lx] %pS\n", pc, (void *) pc);
6230+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6231 graph++;
6232 }
6233 }
6234@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6235 return (struct reg_window *) (fp + STACK_BIAS);
6236 }
6237
6238+extern void gr_handle_kernel_exploit(void);
6239+
6240 void die_if_kernel(char *str, struct pt_regs *regs)
6241 {
6242 static int die_counter;
6243@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6244 while (rw &&
6245 count++ < 30 &&
6246 kstack_valid(tp, (unsigned long) rw)) {
6247- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6248+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6249 (void *) rw->ins[7]);
6250
6251 rw = kernel_stack_up(rw);
6252@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6253 }
6254 user_instruction_dump ((unsigned int __user *) regs->tpc);
6255 }
6256- if (regs->tstate & TSTATE_PRIV)
6257+ if (regs->tstate & TSTATE_PRIV) {
6258+ gr_handle_kernel_exploit();
6259 do_exit(SIGKILL);
6260+ }
6261 do_exit(SIGSEGV);
6262 }
6263 EXPORT_SYMBOL(die_if_kernel);
6264diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6265index 76e4ac1..78f8bb1 100644
6266--- a/arch/sparc/kernel/unaligned_64.c
6267+++ b/arch/sparc/kernel/unaligned_64.c
6268@@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
6269 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6270
6271 if (__ratelimit(&ratelimit)) {
6272- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6273+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6274 regs->tpc, (void *) regs->tpc);
6275 }
6276 }
6277diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6278index a3fc437..fea9957 100644
6279--- a/arch/sparc/lib/Makefile
6280+++ b/arch/sparc/lib/Makefile
6281@@ -2,7 +2,7 @@
6282 #
6283
6284 asflags-y := -ansi -DST_DIV0=0x02
6285-ccflags-y := -Werror
6286+#ccflags-y := -Werror
6287
6288 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
6289 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6290diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6291index 59186e0..f747d7a 100644
6292--- a/arch/sparc/lib/atomic_64.S
6293+++ b/arch/sparc/lib/atomic_64.S
6294@@ -18,7 +18,12 @@
6295 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6296 BACKOFF_SETUP(%o2)
6297 1: lduw [%o1], %g1
6298- add %g1, %o0, %g7
6299+ addcc %g1, %o0, %g7
6300+
6301+#ifdef CONFIG_PAX_REFCOUNT
6302+ tvs %icc, 6
6303+#endif
6304+
6305 cas [%o1], %g1, %g7
6306 cmp %g1, %g7
6307 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6308@@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6309 2: BACKOFF_SPIN(%o2, %o3, 1b)
6310 .size atomic_add, .-atomic_add
6311
6312+ .globl atomic_add_unchecked
6313+ .type atomic_add_unchecked,#function
6314+atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6315+ BACKOFF_SETUP(%o2)
6316+1: lduw [%o1], %g1
6317+ add %g1, %o0, %g7
6318+ cas [%o1], %g1, %g7
6319+ cmp %g1, %g7
6320+ bne,pn %icc, 2f
6321+ nop
6322+ retl
6323+ nop
6324+2: BACKOFF_SPIN(%o2, %o3, 1b)
6325+ .size atomic_add_unchecked, .-atomic_add_unchecked
6326+
6327 .globl atomic_sub
6328 .type atomic_sub,#function
6329 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6330 BACKOFF_SETUP(%o2)
6331 1: lduw [%o1], %g1
6332- sub %g1, %o0, %g7
6333+ subcc %g1, %o0, %g7
6334+
6335+#ifdef CONFIG_PAX_REFCOUNT
6336+ tvs %icc, 6
6337+#endif
6338+
6339 cas [%o1], %g1, %g7
6340 cmp %g1, %g7
6341 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6342@@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6343 2: BACKOFF_SPIN(%o2, %o3, 1b)
6344 .size atomic_sub, .-atomic_sub
6345
6346+ .globl atomic_sub_unchecked
6347+ .type atomic_sub_unchecked,#function
6348+atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6349+ BACKOFF_SETUP(%o2)
6350+1: lduw [%o1], %g1
6351+ sub %g1, %o0, %g7
6352+ cas [%o1], %g1, %g7
6353+ cmp %g1, %g7
6354+ bne,pn %icc, 2f
6355+ nop
6356+ retl
6357+ nop
6358+2: BACKOFF_SPIN(%o2, %o3, 1b)
6359+ .size atomic_sub_unchecked, .-atomic_sub_unchecked
6360+
6361 .globl atomic_add_ret
6362 .type atomic_add_ret,#function
6363 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6364 BACKOFF_SETUP(%o2)
6365 1: lduw [%o1], %g1
6366- add %g1, %o0, %g7
6367+ addcc %g1, %o0, %g7
6368+
6369+#ifdef CONFIG_PAX_REFCOUNT
6370+ tvs %icc, 6
6371+#endif
6372+
6373 cas [%o1], %g1, %g7
6374 cmp %g1, %g7
6375 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6376@@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6377 2: BACKOFF_SPIN(%o2, %o3, 1b)
6378 .size atomic_add_ret, .-atomic_add_ret
6379
6380+ .globl atomic_add_ret_unchecked
6381+ .type atomic_add_ret_unchecked,#function
6382+atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6383+ BACKOFF_SETUP(%o2)
6384+1: lduw [%o1], %g1
6385+ addcc %g1, %o0, %g7
6386+ cas [%o1], %g1, %g7
6387+ cmp %g1, %g7
6388+ bne,pn %icc, 2f
6389+ add %g7, %o0, %g7
6390+ sra %g7, 0, %o0
6391+ retl
6392+ nop
6393+2: BACKOFF_SPIN(%o2, %o3, 1b)
6394+ .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
6395+
6396 .globl atomic_sub_ret
6397 .type atomic_sub_ret,#function
6398 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6399 BACKOFF_SETUP(%o2)
6400 1: lduw [%o1], %g1
6401- sub %g1, %o0, %g7
6402+ subcc %g1, %o0, %g7
6403+
6404+#ifdef CONFIG_PAX_REFCOUNT
6405+ tvs %icc, 6
6406+#endif
6407+
6408 cas [%o1], %g1, %g7
6409 cmp %g1, %g7
6410 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6411@@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6412 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6413 BACKOFF_SETUP(%o2)
6414 1: ldx [%o1], %g1
6415- add %g1, %o0, %g7
6416+ addcc %g1, %o0, %g7
6417+
6418+#ifdef CONFIG_PAX_REFCOUNT
6419+ tvs %xcc, 6
6420+#endif
6421+
6422 casx [%o1], %g1, %g7
6423 cmp %g1, %g7
6424 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6425@@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6426 2: BACKOFF_SPIN(%o2, %o3, 1b)
6427 .size atomic64_add, .-atomic64_add
6428
6429+ .globl atomic64_add_unchecked
6430+ .type atomic64_add_unchecked,#function
6431+atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6432+ BACKOFF_SETUP(%o2)
6433+1: ldx [%o1], %g1
6434+ addcc %g1, %o0, %g7
6435+ casx [%o1], %g1, %g7
6436+ cmp %g1, %g7
6437+ bne,pn %xcc, 2f
6438+ nop
6439+ retl
6440+ nop
6441+2: BACKOFF_SPIN(%o2, %o3, 1b)
6442+ .size atomic64_add_unchecked, .-atomic64_add_unchecked
6443+
6444 .globl atomic64_sub
6445 .type atomic64_sub,#function
6446 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6447 BACKOFF_SETUP(%o2)
6448 1: ldx [%o1], %g1
6449- sub %g1, %o0, %g7
6450+ subcc %g1, %o0, %g7
6451+
6452+#ifdef CONFIG_PAX_REFCOUNT
6453+ tvs %xcc, 6
6454+#endif
6455+
6456 casx [%o1], %g1, %g7
6457 cmp %g1, %g7
6458 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6459@@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6460 2: BACKOFF_SPIN(%o2, %o3, 1b)
6461 .size atomic64_sub, .-atomic64_sub
6462
6463+ .globl atomic64_sub_unchecked
6464+ .type atomic64_sub_unchecked,#function
6465+atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6466+ BACKOFF_SETUP(%o2)
6467+1: ldx [%o1], %g1
6468+ subcc %g1, %o0, %g7
6469+ casx [%o1], %g1, %g7
6470+ cmp %g1, %g7
6471+ bne,pn %xcc, 2f
6472+ nop
6473+ retl
6474+ nop
6475+2: BACKOFF_SPIN(%o2, %o3, 1b)
6476+ .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
6477+
6478 .globl atomic64_add_ret
6479 .type atomic64_add_ret,#function
6480 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6481 BACKOFF_SETUP(%o2)
6482 1: ldx [%o1], %g1
6483- add %g1, %o0, %g7
6484+ addcc %g1, %o0, %g7
6485+
6486+#ifdef CONFIG_PAX_REFCOUNT
6487+ tvs %xcc, 6
6488+#endif
6489+
6490 casx [%o1], %g1, %g7
6491 cmp %g1, %g7
6492 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6493@@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6494 2: BACKOFF_SPIN(%o2, %o3, 1b)
6495 .size atomic64_add_ret, .-atomic64_add_ret
6496
6497+ .globl atomic64_add_ret_unchecked
6498+ .type atomic64_add_ret_unchecked,#function
6499+atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6500+ BACKOFF_SETUP(%o2)
6501+1: ldx [%o1], %g1
6502+ addcc %g1, %o0, %g7
6503+ casx [%o1], %g1, %g7
6504+ cmp %g1, %g7
6505+ bne,pn %xcc, 2f
6506+ add %g7, %o0, %g7
6507+ mov %g7, %o0
6508+ retl
6509+ nop
6510+2: BACKOFF_SPIN(%o2, %o3, 1b)
6511+ .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
6512+
6513 .globl atomic64_sub_ret
6514 .type atomic64_sub_ret,#function
6515 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6516 BACKOFF_SETUP(%o2)
6517 1: ldx [%o1], %g1
6518- sub %g1, %o0, %g7
6519+ subcc %g1, %o0, %g7
6520+
6521+#ifdef CONFIG_PAX_REFCOUNT
6522+ tvs %xcc, 6
6523+#endif
6524+
6525 casx [%o1], %g1, %g7
6526 cmp %g1, %g7
6527 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6528diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6529index f73c224..662af10 100644
6530--- a/arch/sparc/lib/ksyms.c
6531+++ b/arch/sparc/lib/ksyms.c
6532@@ -136,12 +136,18 @@ EXPORT_SYMBOL(__downgrade_write);
6533
6534 /* Atomic counter implementation. */
6535 EXPORT_SYMBOL(atomic_add);
6536+EXPORT_SYMBOL(atomic_add_unchecked);
6537 EXPORT_SYMBOL(atomic_add_ret);
6538+EXPORT_SYMBOL(atomic_add_ret_unchecked);
6539 EXPORT_SYMBOL(atomic_sub);
6540+EXPORT_SYMBOL(atomic_sub_unchecked);
6541 EXPORT_SYMBOL(atomic_sub_ret);
6542 EXPORT_SYMBOL(atomic64_add);
6543+EXPORT_SYMBOL(atomic64_add_unchecked);
6544 EXPORT_SYMBOL(atomic64_add_ret);
6545+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6546 EXPORT_SYMBOL(atomic64_sub);
6547+EXPORT_SYMBOL(atomic64_sub_unchecked);
6548 EXPORT_SYMBOL(atomic64_sub_ret);
6549
6550 /* Atomic bit operations. */
6551diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6552index 301421c..e2535d1 100644
6553--- a/arch/sparc/mm/Makefile
6554+++ b/arch/sparc/mm/Makefile
6555@@ -2,7 +2,7 @@
6556 #
6557
6558 asflags-y := -ansi
6559-ccflags-y := -Werror
6560+#ccflags-y := -Werror
6561
6562 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6563 obj-y += fault_$(BITS).o
6564diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6565index 8023fd7..c8e89e9 100644
6566--- a/arch/sparc/mm/fault_32.c
6567+++ b/arch/sparc/mm/fault_32.c
6568@@ -21,6 +21,9 @@
6569 #include <linux/perf_event.h>
6570 #include <linux/interrupt.h>
6571 #include <linux/kdebug.h>
6572+#include <linux/slab.h>
6573+#include <linux/pagemap.h>
6574+#include <linux/compiler.h>
6575
6576 #include <asm/system.h>
6577 #include <asm/page.h>
6578@@ -208,6 +211,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6579 return safe_compute_effective_address(regs, insn);
6580 }
6581
6582+#ifdef CONFIG_PAX_PAGEEXEC
6583+#ifdef CONFIG_PAX_DLRESOLVE
6584+static void pax_emuplt_close(struct vm_area_struct *vma)
6585+{
6586+ vma->vm_mm->call_dl_resolve = 0UL;
6587+}
6588+
6589+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6590+{
6591+ unsigned int *kaddr;
6592+
6593+ vmf->page = alloc_page(GFP_HIGHUSER);
6594+ if (!vmf->page)
6595+ return VM_FAULT_OOM;
6596+
6597+ kaddr = kmap(vmf->page);
6598+ memset(kaddr, 0, PAGE_SIZE);
6599+ kaddr[0] = 0x9DE3BFA8U; /* save */
6600+ flush_dcache_page(vmf->page);
6601+ kunmap(vmf->page);
6602+ return VM_FAULT_MAJOR;
6603+}
6604+
6605+static const struct vm_operations_struct pax_vm_ops = {
6606+ .close = pax_emuplt_close,
6607+ .fault = pax_emuplt_fault
6608+};
6609+
6610+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6611+{
6612+ int ret;
6613+
6614+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6615+ vma->vm_mm = current->mm;
6616+ vma->vm_start = addr;
6617+ vma->vm_end = addr + PAGE_SIZE;
6618+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6619+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6620+ vma->vm_ops = &pax_vm_ops;
6621+
6622+ ret = insert_vm_struct(current->mm, vma);
6623+ if (ret)
6624+ return ret;
6625+
6626+ ++current->mm->total_vm;
6627+ return 0;
6628+}
6629+#endif
6630+
6631+/*
6632+ * PaX: decide what to do with offenders (regs->pc = fault address)
6633+ *
6634+ * returns 1 when task should be killed
6635+ * 2 when patched PLT trampoline was detected
6636+ * 3 when unpatched PLT trampoline was detected
6637+ */
6638+static int pax_handle_fetch_fault(struct pt_regs *regs)
6639+{
6640+
6641+#ifdef CONFIG_PAX_EMUPLT
6642+ int err;
6643+
6644+ do { /* PaX: patched PLT emulation #1 */
6645+ unsigned int sethi1, sethi2, jmpl;
6646+
6647+ err = get_user(sethi1, (unsigned int *)regs->pc);
6648+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6649+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6650+
6651+ if (err)
6652+ break;
6653+
6654+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6655+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6656+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6657+ {
6658+ unsigned int addr;
6659+
6660+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6661+ addr = regs->u_regs[UREG_G1];
6662+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6663+ regs->pc = addr;
6664+ regs->npc = addr+4;
6665+ return 2;
6666+ }
6667+ } while (0);
6668+
6669+ { /* PaX: patched PLT emulation #2 */
6670+ unsigned int ba;
6671+
6672+ err = get_user(ba, (unsigned int *)regs->pc);
6673+
6674+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6675+ unsigned int addr;
6676+
6677+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6678+ regs->pc = addr;
6679+ regs->npc = addr+4;
6680+ return 2;
6681+ }
6682+ }
6683+
6684+ do { /* PaX: patched PLT emulation #3 */
6685+ unsigned int sethi, jmpl, nop;
6686+
6687+ err = get_user(sethi, (unsigned int *)regs->pc);
6688+ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6689+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6690+
6691+ if (err)
6692+ break;
6693+
6694+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6695+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6696+ nop == 0x01000000U)
6697+ {
6698+ unsigned int addr;
6699+
6700+ addr = (sethi & 0x003FFFFFU) << 10;
6701+ regs->u_regs[UREG_G1] = addr;
6702+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6703+ regs->pc = addr;
6704+ regs->npc = addr+4;
6705+ return 2;
6706+ }
6707+ } while (0);
6708+
6709+ do { /* PaX: unpatched PLT emulation step 1 */
6710+ unsigned int sethi, ba, nop;
6711+
6712+ err = get_user(sethi, (unsigned int *)regs->pc);
6713+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6714+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6715+
6716+ if (err)
6717+ break;
6718+
6719+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6720+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6721+ nop == 0x01000000U)
6722+ {
6723+ unsigned int addr, save, call;
6724+
6725+ if ((ba & 0xFFC00000U) == 0x30800000U)
6726+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6727+ else
6728+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6729+
6730+ err = get_user(save, (unsigned int *)addr);
6731+ err |= get_user(call, (unsigned int *)(addr+4));
6732+ err |= get_user(nop, (unsigned int *)(addr+8));
6733+ if (err)
6734+ break;
6735+
6736+#ifdef CONFIG_PAX_DLRESOLVE
6737+ if (save == 0x9DE3BFA8U &&
6738+ (call & 0xC0000000U) == 0x40000000U &&
6739+ nop == 0x01000000U)
6740+ {
6741+ struct vm_area_struct *vma;
6742+ unsigned long call_dl_resolve;
6743+
6744+ down_read(&current->mm->mmap_sem);
6745+ call_dl_resolve = current->mm->call_dl_resolve;
6746+ up_read(&current->mm->mmap_sem);
6747+ if (likely(call_dl_resolve))
6748+ goto emulate;
6749+
6750+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6751+
6752+ down_write(&current->mm->mmap_sem);
6753+ if (current->mm->call_dl_resolve) {
6754+ call_dl_resolve = current->mm->call_dl_resolve;
6755+ up_write(&current->mm->mmap_sem);
6756+ if (vma)
6757+ kmem_cache_free(vm_area_cachep, vma);
6758+ goto emulate;
6759+ }
6760+
6761+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6762+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6763+ up_write(&current->mm->mmap_sem);
6764+ if (vma)
6765+ kmem_cache_free(vm_area_cachep, vma);
6766+ return 1;
6767+ }
6768+
6769+ if (pax_insert_vma(vma, call_dl_resolve)) {
6770+ up_write(&current->mm->mmap_sem);
6771+ kmem_cache_free(vm_area_cachep, vma);
6772+ return 1;
6773+ }
6774+
6775+ current->mm->call_dl_resolve = call_dl_resolve;
6776+ up_write(&current->mm->mmap_sem);
6777+
6778+emulate:
6779+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6780+ regs->pc = call_dl_resolve;
6781+ regs->npc = addr+4;
6782+ return 3;
6783+ }
6784+#endif
6785+
6786+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6787+ if ((save & 0xFFC00000U) == 0x05000000U &&
6788+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6789+ nop == 0x01000000U)
6790+ {
6791+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6792+ regs->u_regs[UREG_G2] = addr + 4;
6793+ addr = (save & 0x003FFFFFU) << 10;
6794+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6795+ regs->pc = addr;
6796+ regs->npc = addr+4;
6797+ return 3;
6798+ }
6799+ }
6800+ } while (0);
6801+
6802+ do { /* PaX: unpatched PLT emulation step 2 */
6803+ unsigned int save, call, nop;
6804+
6805+ err = get_user(save, (unsigned int *)(regs->pc-4));
6806+ err |= get_user(call, (unsigned int *)regs->pc);
6807+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6808+ if (err)
6809+ break;
6810+
6811+ if (save == 0x9DE3BFA8U &&
6812+ (call & 0xC0000000U) == 0x40000000U &&
6813+ nop == 0x01000000U)
6814+ {
6815+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6816+
6817+ regs->u_regs[UREG_RETPC] = regs->pc;
6818+ regs->pc = dl_resolve;
6819+ regs->npc = dl_resolve+4;
6820+ return 3;
6821+ }
6822+ } while (0);
6823+#endif
6824+
6825+ return 1;
6826+}
6827+
6828+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6829+{
6830+ unsigned long i;
6831+
6832+ printk(KERN_ERR "PAX: bytes at PC: ");
6833+ for (i = 0; i < 8; i++) {
6834+ unsigned int c;
6835+ if (get_user(c, (unsigned int *)pc+i))
6836+ printk(KERN_CONT "???????? ");
6837+ else
6838+ printk(KERN_CONT "%08x ", c);
6839+ }
6840+ printk("\n");
6841+}
6842+#endif
6843+
6844 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6845 int text_fault)
6846 {
6847@@ -280,6 +545,24 @@ good_area:
6848 if(!(vma->vm_flags & VM_WRITE))
6849 goto bad_area;
6850 } else {
6851+
6852+#ifdef CONFIG_PAX_PAGEEXEC
6853+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6854+ up_read(&mm->mmap_sem);
6855+ switch (pax_handle_fetch_fault(regs)) {
6856+
6857+#ifdef CONFIG_PAX_EMUPLT
6858+ case 2:
6859+ case 3:
6860+ return;
6861+#endif
6862+
6863+ }
6864+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6865+ do_group_exit(SIGKILL);
6866+ }
6867+#endif
6868+
6869 /* Allow reads even for write-only mappings */
6870 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6871 goto bad_area;
6872diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6873index 504c062..6fcb9c6 100644
6874--- a/arch/sparc/mm/fault_64.c
6875+++ b/arch/sparc/mm/fault_64.c
6876@@ -21,6 +21,9 @@
6877 #include <linux/kprobes.h>
6878 #include <linux/kdebug.h>
6879 #include <linux/percpu.h>
6880+#include <linux/slab.h>
6881+#include <linux/pagemap.h>
6882+#include <linux/compiler.h>
6883
6884 #include <asm/page.h>
6885 #include <asm/pgtable.h>
6886@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6887 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6888 regs->tpc);
6889 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6890- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6891+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6892 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6893 dump_stack();
6894 unhandled_fault(regs->tpc, current, regs);
6895@@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6896 show_regs(regs);
6897 }
6898
6899+#ifdef CONFIG_PAX_PAGEEXEC
6900+#ifdef CONFIG_PAX_DLRESOLVE
6901+static void pax_emuplt_close(struct vm_area_struct *vma)
6902+{
6903+ vma->vm_mm->call_dl_resolve = 0UL;
6904+}
6905+
6906+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6907+{
6908+ unsigned int *kaddr;
6909+
6910+ vmf->page = alloc_page(GFP_HIGHUSER);
6911+ if (!vmf->page)
6912+ return VM_FAULT_OOM;
6913+
6914+ kaddr = kmap(vmf->page);
6915+ memset(kaddr, 0, PAGE_SIZE);
6916+ kaddr[0] = 0x9DE3BFA8U; /* save */
6917+ flush_dcache_page(vmf->page);
6918+ kunmap(vmf->page);
6919+ return VM_FAULT_MAJOR;
6920+}
6921+
6922+static const struct vm_operations_struct pax_vm_ops = {
6923+ .close = pax_emuplt_close,
6924+ .fault = pax_emuplt_fault
6925+};
6926+
6927+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6928+{
6929+ int ret;
6930+
6931+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6932+ vma->vm_mm = current->mm;
6933+ vma->vm_start = addr;
6934+ vma->vm_end = addr + PAGE_SIZE;
6935+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6936+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6937+ vma->vm_ops = &pax_vm_ops;
6938+
6939+ ret = insert_vm_struct(current->mm, vma);
6940+ if (ret)
6941+ return ret;
6942+
6943+ ++current->mm->total_vm;
6944+ return 0;
6945+}
6946+#endif
6947+
6948+/*
6949+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6950+ *
6951+ * returns 1 when task should be killed
6952+ * 2 when patched PLT trampoline was detected
6953+ * 3 when unpatched PLT trampoline was detected
6954+ */
6955+static int pax_handle_fetch_fault(struct pt_regs *regs)
6956+{
6957+
6958+#ifdef CONFIG_PAX_EMUPLT
6959+ int err;
6960+
6961+ do { /* PaX: patched PLT emulation #1 */
6962+ unsigned int sethi1, sethi2, jmpl;
6963+
6964+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6965+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6966+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6967+
6968+ if (err)
6969+ break;
6970+
6971+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6972+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6973+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6974+ {
6975+ unsigned long addr;
6976+
6977+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6978+ addr = regs->u_regs[UREG_G1];
6979+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6980+
6981+ if (test_thread_flag(TIF_32BIT))
6982+ addr &= 0xFFFFFFFFUL;
6983+
6984+ regs->tpc = addr;
6985+ regs->tnpc = addr+4;
6986+ return 2;
6987+ }
6988+ } while (0);
6989+
6990+ { /* PaX: patched PLT emulation #2 */
6991+ unsigned int ba;
6992+
6993+ err = get_user(ba, (unsigned int *)regs->tpc);
6994+
6995+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6996+ unsigned long addr;
6997+
6998+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6999+
7000+ if (test_thread_flag(TIF_32BIT))
7001+ addr &= 0xFFFFFFFFUL;
7002+
7003+ regs->tpc = addr;
7004+ regs->tnpc = addr+4;
7005+ return 2;
7006+ }
7007+ }
7008+
7009+ do { /* PaX: patched PLT emulation #3 */
7010+ unsigned int sethi, jmpl, nop;
7011+
7012+ err = get_user(sethi, (unsigned int *)regs->tpc);
7013+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
7014+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7015+
7016+ if (err)
7017+ break;
7018+
7019+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7020+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
7021+ nop == 0x01000000U)
7022+ {
7023+ unsigned long addr;
7024+
7025+ addr = (sethi & 0x003FFFFFU) << 10;
7026+ regs->u_regs[UREG_G1] = addr;
7027+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7028+
7029+ if (test_thread_flag(TIF_32BIT))
7030+ addr &= 0xFFFFFFFFUL;
7031+
7032+ regs->tpc = addr;
7033+ regs->tnpc = addr+4;
7034+ return 2;
7035+ }
7036+ } while (0);
7037+
7038+ do { /* PaX: patched PLT emulation #4 */
7039+ unsigned int sethi, mov1, call, mov2;
7040+
7041+ err = get_user(sethi, (unsigned int *)regs->tpc);
7042+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
7043+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
7044+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
7045+
7046+ if (err)
7047+ break;
7048+
7049+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7050+ mov1 == 0x8210000FU &&
7051+ (call & 0xC0000000U) == 0x40000000U &&
7052+ mov2 == 0x9E100001U)
7053+ {
7054+ unsigned long addr;
7055+
7056+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7057+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7058+
7059+ if (test_thread_flag(TIF_32BIT))
7060+ addr &= 0xFFFFFFFFUL;
7061+
7062+ regs->tpc = addr;
7063+ regs->tnpc = addr+4;
7064+ return 2;
7065+ }
7066+ } while (0);
7067+
7068+ do { /* PaX: patched PLT emulation #5 */
7069+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7070+
7071+ err = get_user(sethi, (unsigned int *)regs->tpc);
7072+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7073+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7074+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7075+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7076+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7077+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7078+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7079+
7080+ if (err)
7081+ break;
7082+
7083+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7084+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7085+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7086+ (or1 & 0xFFFFE000U) == 0x82106000U &&
7087+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7088+ sllx == 0x83287020U &&
7089+ jmpl == 0x81C04005U &&
7090+ nop == 0x01000000U)
7091+ {
7092+ unsigned long addr;
7093+
7094+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7095+ regs->u_regs[UREG_G1] <<= 32;
7096+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7097+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7098+ regs->tpc = addr;
7099+ regs->tnpc = addr+4;
7100+ return 2;
7101+ }
7102+ } while (0);
7103+
7104+ do { /* PaX: patched PLT emulation #6 */
7105+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7106+
7107+ err = get_user(sethi, (unsigned int *)regs->tpc);
7108+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7109+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7110+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7111+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
7112+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7113+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7114+
7115+ if (err)
7116+ break;
7117+
7118+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7119+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7120+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7121+ sllx == 0x83287020U &&
7122+ (or & 0xFFFFE000U) == 0x8A116000U &&
7123+ jmpl == 0x81C04005U &&
7124+ nop == 0x01000000U)
7125+ {
7126+ unsigned long addr;
7127+
7128+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7129+ regs->u_regs[UREG_G1] <<= 32;
7130+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7131+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7132+ regs->tpc = addr;
7133+ regs->tnpc = addr+4;
7134+ return 2;
7135+ }
7136+ } while (0);
7137+
7138+ do { /* PaX: unpatched PLT emulation step 1 */
7139+ unsigned int sethi, ba, nop;
7140+
7141+ err = get_user(sethi, (unsigned int *)regs->tpc);
7142+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7143+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7144+
7145+ if (err)
7146+ break;
7147+
7148+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7149+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7150+ nop == 0x01000000U)
7151+ {
7152+ unsigned long addr;
7153+ unsigned int save, call;
7154+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7155+
7156+ if ((ba & 0xFFC00000U) == 0x30800000U)
7157+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7158+ else
7159+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7160+
7161+ if (test_thread_flag(TIF_32BIT))
7162+ addr &= 0xFFFFFFFFUL;
7163+
7164+ err = get_user(save, (unsigned int *)addr);
7165+ err |= get_user(call, (unsigned int *)(addr+4));
7166+ err |= get_user(nop, (unsigned int *)(addr+8));
7167+ if (err)
7168+ break;
7169+
7170+#ifdef CONFIG_PAX_DLRESOLVE
7171+ if (save == 0x9DE3BFA8U &&
7172+ (call & 0xC0000000U) == 0x40000000U &&
7173+ nop == 0x01000000U)
7174+ {
7175+ struct vm_area_struct *vma;
7176+ unsigned long call_dl_resolve;
7177+
7178+ down_read(&current->mm->mmap_sem);
7179+ call_dl_resolve = current->mm->call_dl_resolve;
7180+ up_read(&current->mm->mmap_sem);
7181+ if (likely(call_dl_resolve))
7182+ goto emulate;
7183+
7184+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7185+
7186+ down_write(&current->mm->mmap_sem);
7187+ if (current->mm->call_dl_resolve) {
7188+ call_dl_resolve = current->mm->call_dl_resolve;
7189+ up_write(&current->mm->mmap_sem);
7190+ if (vma)
7191+ kmem_cache_free(vm_area_cachep, vma);
7192+ goto emulate;
7193+ }
7194+
7195+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7196+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7197+ up_write(&current->mm->mmap_sem);
7198+ if (vma)
7199+ kmem_cache_free(vm_area_cachep, vma);
7200+ return 1;
7201+ }
7202+
7203+ if (pax_insert_vma(vma, call_dl_resolve)) {
7204+ up_write(&current->mm->mmap_sem);
7205+ kmem_cache_free(vm_area_cachep, vma);
7206+ return 1;
7207+ }
7208+
7209+ current->mm->call_dl_resolve = call_dl_resolve;
7210+ up_write(&current->mm->mmap_sem);
7211+
7212+emulate:
7213+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7214+ regs->tpc = call_dl_resolve;
7215+ regs->tnpc = addr+4;
7216+ return 3;
7217+ }
7218+#endif
7219+
7220+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7221+ if ((save & 0xFFC00000U) == 0x05000000U &&
7222+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7223+ nop == 0x01000000U)
7224+ {
7225+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7226+ regs->u_regs[UREG_G2] = addr + 4;
7227+ addr = (save & 0x003FFFFFU) << 10;
7228+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7229+
7230+ if (test_thread_flag(TIF_32BIT))
7231+ addr &= 0xFFFFFFFFUL;
7232+
7233+ regs->tpc = addr;
7234+ regs->tnpc = addr+4;
7235+ return 3;
7236+ }
7237+
7238+ /* PaX: 64-bit PLT stub */
7239+ err = get_user(sethi1, (unsigned int *)addr);
7240+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7241+ err |= get_user(or1, (unsigned int *)(addr+8));
7242+ err |= get_user(or2, (unsigned int *)(addr+12));
7243+ err |= get_user(sllx, (unsigned int *)(addr+16));
7244+ err |= get_user(add, (unsigned int *)(addr+20));
7245+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7246+ err |= get_user(nop, (unsigned int *)(addr+28));
7247+ if (err)
7248+ break;
7249+
7250+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7251+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7252+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7253+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7254+ sllx == 0x89293020U &&
7255+ add == 0x8A010005U &&
7256+ jmpl == 0x89C14000U &&
7257+ nop == 0x01000000U)
7258+ {
7259+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7260+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7261+ regs->u_regs[UREG_G4] <<= 32;
7262+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7263+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7264+ regs->u_regs[UREG_G4] = addr + 24;
7265+ addr = regs->u_regs[UREG_G5];
7266+ regs->tpc = addr;
7267+ regs->tnpc = addr+4;
7268+ return 3;
7269+ }
7270+ }
7271+ } while (0);
7272+
7273+#ifdef CONFIG_PAX_DLRESOLVE
7274+ do { /* PaX: unpatched PLT emulation step 2 */
7275+ unsigned int save, call, nop;
7276+
7277+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7278+ err |= get_user(call, (unsigned int *)regs->tpc);
7279+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7280+ if (err)
7281+ break;
7282+
7283+ if (save == 0x9DE3BFA8U &&
7284+ (call & 0xC0000000U) == 0x40000000U &&
7285+ nop == 0x01000000U)
7286+ {
7287+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7288+
7289+ if (test_thread_flag(TIF_32BIT))
7290+ dl_resolve &= 0xFFFFFFFFUL;
7291+
7292+ regs->u_regs[UREG_RETPC] = regs->tpc;
7293+ regs->tpc = dl_resolve;
7294+ regs->tnpc = dl_resolve+4;
7295+ return 3;
7296+ }
7297+ } while (0);
7298+#endif
7299+
7300+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7301+ unsigned int sethi, ba, nop;
7302+
7303+ err = get_user(sethi, (unsigned int *)regs->tpc);
7304+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7305+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7306+
7307+ if (err)
7308+ break;
7309+
7310+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7311+ (ba & 0xFFF00000U) == 0x30600000U &&
7312+ nop == 0x01000000U)
7313+ {
7314+ unsigned long addr;
7315+
7316+ addr = (sethi & 0x003FFFFFU) << 10;
7317+ regs->u_regs[UREG_G1] = addr;
7318+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7319+
7320+ if (test_thread_flag(TIF_32BIT))
7321+ addr &= 0xFFFFFFFFUL;
7322+
7323+ regs->tpc = addr;
7324+ regs->tnpc = addr+4;
7325+ return 2;
7326+ }
7327+ } while (0);
7328+
7329+#endif
7330+
7331+ return 1;
7332+}
7333+
7334+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7335+{
7336+ unsigned long i;
7337+
7338+ printk(KERN_ERR "PAX: bytes at PC: ");
7339+ for (i = 0; i < 8; i++) {
7340+ unsigned int c;
7341+ if (get_user(c, (unsigned int *)pc+i))
7342+ printk(KERN_CONT "???????? ");
7343+ else
7344+ printk(KERN_CONT "%08x ", c);
7345+ }
7346+ printk("\n");
7347+}
7348+#endif
7349+
7350 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7351 {
7352 struct mm_struct *mm = current->mm;
7353@@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7354 if (!vma)
7355 goto bad_area;
7356
7357+#ifdef CONFIG_PAX_PAGEEXEC
7358+ /* PaX: detect ITLB misses on non-exec pages */
7359+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7360+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7361+ {
7362+ if (address != regs->tpc)
7363+ goto good_area;
7364+
7365+ up_read(&mm->mmap_sem);
7366+ switch (pax_handle_fetch_fault(regs)) {
7367+
7368+#ifdef CONFIG_PAX_EMUPLT
7369+ case 2:
7370+ case 3:
7371+ return;
7372+#endif
7373+
7374+ }
7375+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7376+ do_group_exit(SIGKILL);
7377+ }
7378+#endif
7379+
7380 /* Pure DTLB misses do not tell us whether the fault causing
7381 * load/store/atomic was a write or not, it only says that there
7382 * was no match. So in such a case we (carefully) read the
7383diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7384index 07e1453..0a7d9e9 100644
7385--- a/arch/sparc/mm/hugetlbpage.c
7386+++ b/arch/sparc/mm/hugetlbpage.c
7387@@ -67,7 +67,7 @@ full_search:
7388 }
7389 return -ENOMEM;
7390 }
7391- if (likely(!vma || addr + len <= vma->vm_start)) {
7392+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7393 /*
7394 * Remember the place where we stopped the search:
7395 */
7396@@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7397 /* make sure it can fit in the remaining address space */
7398 if (likely(addr > len)) {
7399 vma = find_vma(mm, addr-len);
7400- if (!vma || addr <= vma->vm_start) {
7401+ if (check_heap_stack_gap(vma, addr - len, len)) {
7402 /* remember the address as a hint for next time */
7403 return (mm->free_area_cache = addr-len);
7404 }
7405@@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7406 if (unlikely(mm->mmap_base < len))
7407 goto bottomup;
7408
7409- addr = (mm->mmap_base-len) & HPAGE_MASK;
7410+ addr = mm->mmap_base - len;
7411
7412 do {
7413+ addr &= HPAGE_MASK;
7414 /*
7415 * Lookup failure means no vma is above this address,
7416 * else if new region fits below vma->vm_start,
7417 * return with success:
7418 */
7419 vma = find_vma(mm, addr);
7420- if (likely(!vma || addr+len <= vma->vm_start)) {
7421+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7422 /* remember the address as a hint for next time */
7423 return (mm->free_area_cache = addr);
7424 }
7425@@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7426 mm->cached_hole_size = vma->vm_start - addr;
7427
7428 /* try just below the current vma->vm_start */
7429- addr = (vma->vm_start-len) & HPAGE_MASK;
7430- } while (likely(len < vma->vm_start));
7431+ addr = skip_heap_stack_gap(vma, len);
7432+ } while (!IS_ERR_VALUE(addr));
7433
7434 bottomup:
7435 /*
7436@@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7437 if (addr) {
7438 addr = ALIGN(addr, HPAGE_SIZE);
7439 vma = find_vma(mm, addr);
7440- if (task_size - len >= addr &&
7441- (!vma || addr + len <= vma->vm_start))
7442+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7443 return addr;
7444 }
7445 if (mm->get_unmapped_area == arch_get_unmapped_area)
7446diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
7447index 7b00de6..78239f4 100644
7448--- a/arch/sparc/mm/init_32.c
7449+++ b/arch/sparc/mm/init_32.c
7450@@ -316,6 +316,9 @@ extern void device_scan(void);
7451 pgprot_t PAGE_SHARED __read_mostly;
7452 EXPORT_SYMBOL(PAGE_SHARED);
7453
7454+pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
7455+EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
7456+
7457 void __init paging_init(void)
7458 {
7459 switch(sparc_cpu_model) {
7460@@ -344,17 +347,17 @@ void __init paging_init(void)
7461
7462 /* Initialize the protection map with non-constant, MMU dependent values. */
7463 protection_map[0] = PAGE_NONE;
7464- protection_map[1] = PAGE_READONLY;
7465- protection_map[2] = PAGE_COPY;
7466- protection_map[3] = PAGE_COPY;
7467+ protection_map[1] = PAGE_READONLY_NOEXEC;
7468+ protection_map[2] = PAGE_COPY_NOEXEC;
7469+ protection_map[3] = PAGE_COPY_NOEXEC;
7470 protection_map[4] = PAGE_READONLY;
7471 protection_map[5] = PAGE_READONLY;
7472 protection_map[6] = PAGE_COPY;
7473 protection_map[7] = PAGE_COPY;
7474 protection_map[8] = PAGE_NONE;
7475- protection_map[9] = PAGE_READONLY;
7476- protection_map[10] = PAGE_SHARED;
7477- protection_map[11] = PAGE_SHARED;
7478+ protection_map[9] = PAGE_READONLY_NOEXEC;
7479+ protection_map[10] = PAGE_SHARED_NOEXEC;
7480+ protection_map[11] = PAGE_SHARED_NOEXEC;
7481 protection_map[12] = PAGE_READONLY;
7482 protection_map[13] = PAGE_READONLY;
7483 protection_map[14] = PAGE_SHARED;
7484diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
7485index cbef74e..c38fead 100644
7486--- a/arch/sparc/mm/srmmu.c
7487+++ b/arch/sparc/mm/srmmu.c
7488@@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
7489 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
7490 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
7491 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
7492+
7493+#ifdef CONFIG_PAX_PAGEEXEC
7494+ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
7495+ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
7496+ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
7497+#endif
7498+
7499 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
7500 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
7501
7502diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7503index 27fe667..36d474c 100644
7504--- a/arch/tile/include/asm/atomic_64.h
7505+++ b/arch/tile/include/asm/atomic_64.h
7506@@ -142,6 +142,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7507
7508 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7509
7510+#define atomic64_read_unchecked(v) atomic64_read(v)
7511+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7512+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7513+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7514+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7515+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7516+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7517+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7518+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7519+
7520 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7521 #define smp_mb__before_atomic_dec() smp_mb()
7522 #define smp_mb__after_atomic_dec() smp_mb()
7523diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7524index 392e533..536b092 100644
7525--- a/arch/tile/include/asm/cache.h
7526+++ b/arch/tile/include/asm/cache.h
7527@@ -15,11 +15,12 @@
7528 #ifndef _ASM_TILE_CACHE_H
7529 #define _ASM_TILE_CACHE_H
7530
7531+#include <linux/const.h>
7532 #include <arch/chip.h>
7533
7534 /* bytes per L1 data cache line */
7535 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7536-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7537+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7538
7539 /* bytes per L2 cache line */
7540 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7541diff --git a/arch/um/Makefile b/arch/um/Makefile
7542index 28688e6..4c0aa1c 100644
7543--- a/arch/um/Makefile
7544+++ b/arch/um/Makefile
7545@@ -61,6 +61,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7546 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7547 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7548
7549+ifdef CONSTIFY_PLUGIN
7550+USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7551+endif
7552+
7553 #This will adjust *FLAGS accordingly to the platform.
7554 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7555
7556diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7557index 19e1bdd..3665b77 100644
7558--- a/arch/um/include/asm/cache.h
7559+++ b/arch/um/include/asm/cache.h
7560@@ -1,6 +1,7 @@
7561 #ifndef __UM_CACHE_H
7562 #define __UM_CACHE_H
7563
7564+#include <linux/const.h>
7565
7566 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7567 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7568@@ -12,6 +13,6 @@
7569 # define L1_CACHE_SHIFT 5
7570 #endif
7571
7572-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7573+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7574
7575 #endif
7576diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7577index 6c03acd..a5e0215 100644
7578--- a/arch/um/include/asm/kmap_types.h
7579+++ b/arch/um/include/asm/kmap_types.h
7580@@ -23,6 +23,7 @@ enum km_type {
7581 KM_IRQ1,
7582 KM_SOFTIRQ0,
7583 KM_SOFTIRQ1,
7584+ KM_CLEARPAGE,
7585 KM_TYPE_NR
7586 };
7587
7588diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7589index 7cfc3ce..cbd1a58 100644
7590--- a/arch/um/include/asm/page.h
7591+++ b/arch/um/include/asm/page.h
7592@@ -14,6 +14,9 @@
7593 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7594 #define PAGE_MASK (~(PAGE_SIZE-1))
7595
7596+#define ktla_ktva(addr) (addr)
7597+#define ktva_ktla(addr) (addr)
7598+
7599 #ifndef __ASSEMBLY__
7600
7601 struct page;
7602diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7603index 0032f92..cd151e0 100644
7604--- a/arch/um/include/asm/pgtable-3level.h
7605+++ b/arch/um/include/asm/pgtable-3level.h
7606@@ -58,6 +58,7 @@
7607 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7608 #define pud_populate(mm, pud, pmd) \
7609 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7610+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7611
7612 #ifdef CONFIG_64BIT
7613 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7614diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7615index 69f2490..2634831 100644
7616--- a/arch/um/kernel/process.c
7617+++ b/arch/um/kernel/process.c
7618@@ -408,22 +408,6 @@ int singlestepping(void * t)
7619 return 2;
7620 }
7621
7622-/*
7623- * Only x86 and x86_64 have an arch_align_stack().
7624- * All other arches have "#define arch_align_stack(x) (x)"
7625- * in their asm/system.h
7626- * As this is included in UML from asm-um/system-generic.h,
7627- * we can use it to behave as the subarch does.
7628- */
7629-#ifndef arch_align_stack
7630-unsigned long arch_align_stack(unsigned long sp)
7631-{
7632- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7633- sp -= get_random_int() % 8192;
7634- return sp & ~0xf;
7635-}
7636-#endif
7637-
7638 unsigned long get_wchan(struct task_struct *p)
7639 {
7640 unsigned long stack_page, sp, ip;
7641diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7642index ad8f795..2c7eec6 100644
7643--- a/arch/unicore32/include/asm/cache.h
7644+++ b/arch/unicore32/include/asm/cache.h
7645@@ -12,8 +12,10 @@
7646 #ifndef __UNICORE_CACHE_H__
7647 #define __UNICORE_CACHE_H__
7648
7649-#define L1_CACHE_SHIFT (5)
7650-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7651+#include <linux/const.h>
7652+
7653+#define L1_CACHE_SHIFT 5
7654+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7655
7656 /*
7657 * Memory returned by kmalloc() may be used for DMA, so we must make
7658diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7659index 5bed94e..fbcf200 100644
7660--- a/arch/x86/Kconfig
7661+++ b/arch/x86/Kconfig
7662@@ -226,7 +226,7 @@ config X86_HT
7663
7664 config X86_32_LAZY_GS
7665 def_bool y
7666- depends on X86_32 && !CC_STACKPROTECTOR
7667+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7668
7669 config ARCH_HWEIGHT_CFLAGS
7670 string
7671@@ -1058,7 +1058,7 @@ choice
7672
7673 config NOHIGHMEM
7674 bool "off"
7675- depends on !X86_NUMAQ
7676+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7677 ---help---
7678 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7679 However, the address space of 32-bit x86 processors is only 4
7680@@ -1095,7 +1095,7 @@ config NOHIGHMEM
7681
7682 config HIGHMEM4G
7683 bool "4GB"
7684- depends on !X86_NUMAQ
7685+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7686 ---help---
7687 Select this if you have a 32-bit processor and between 1 and 4
7688 gigabytes of physical RAM.
7689@@ -1149,7 +1149,7 @@ config PAGE_OFFSET
7690 hex
7691 default 0xB0000000 if VMSPLIT_3G_OPT
7692 default 0x80000000 if VMSPLIT_2G
7693- default 0x78000000 if VMSPLIT_2G_OPT
7694+ default 0x70000000 if VMSPLIT_2G_OPT
7695 default 0x40000000 if VMSPLIT_1G
7696 default 0xC0000000
7697 depends on X86_32
7698@@ -1539,6 +1539,7 @@ config SECCOMP
7699
7700 config CC_STACKPROTECTOR
7701 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7702+ depends on X86_64 || !PAX_MEMORY_UDEREF
7703 ---help---
7704 This option turns on the -fstack-protector GCC feature. This
7705 feature puts, at the beginning of functions, a canary value on
7706@@ -1596,6 +1597,7 @@ config KEXEC_JUMP
7707 config PHYSICAL_START
7708 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7709 default "0x1000000"
7710+ range 0x400000 0x40000000
7711 ---help---
7712 This gives the physical address where the kernel is loaded.
7713
7714@@ -1659,6 +1661,7 @@ config X86_NEED_RELOCS
7715 config PHYSICAL_ALIGN
7716 hex "Alignment value to which kernel should be aligned" if X86_32
7717 default "0x1000000"
7718+ range 0x400000 0x1000000 if PAX_KERNEXEC
7719 range 0x2000 0x1000000
7720 ---help---
7721 This value puts the alignment restrictions on physical address
7722@@ -1690,9 +1693,10 @@ config HOTPLUG_CPU
7723 Say N if you want to disable CPU hotplug.
7724
7725 config COMPAT_VDSO
7726- def_bool y
7727+ def_bool n
7728 prompt "Compat VDSO support"
7729 depends on X86_32 || IA32_EMULATION
7730+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7731 ---help---
7732 Map the 32-bit VDSO to the predictable old-style address too.
7733
7734diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7735index 3c57033..22d44aa 100644
7736--- a/arch/x86/Kconfig.cpu
7737+++ b/arch/x86/Kconfig.cpu
7738@@ -335,7 +335,7 @@ config X86_PPRO_FENCE
7739
7740 config X86_F00F_BUG
7741 def_bool y
7742- depends on M586MMX || M586TSC || M586 || M486 || M386
7743+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7744
7745 config X86_INVD_BUG
7746 def_bool y
7747@@ -359,7 +359,7 @@ config X86_POPAD_OK
7748
7749 config X86_ALIGNMENT_16
7750 def_bool y
7751- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7752+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7753
7754 config X86_INTEL_USERCOPY
7755 def_bool y
7756@@ -405,7 +405,7 @@ config X86_CMPXCHG64
7757 # generates cmov.
7758 config X86_CMOV
7759 def_bool y
7760- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7761+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7762
7763 config X86_MINIMUM_CPU_FAMILY
7764 int
7765diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7766index e46c214..7c72b55 100644
7767--- a/arch/x86/Kconfig.debug
7768+++ b/arch/x86/Kconfig.debug
7769@@ -84,7 +84,7 @@ config X86_PTDUMP
7770 config DEBUG_RODATA
7771 bool "Write protect kernel read-only data structures"
7772 default y
7773- depends on DEBUG_KERNEL
7774+ depends on DEBUG_KERNEL && BROKEN
7775 ---help---
7776 Mark the kernel read-only data as write-protected in the pagetables,
7777 in order to catch accidental (and incorrect) writes to such const
7778@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7779
7780 config DEBUG_SET_MODULE_RONX
7781 bool "Set loadable kernel module data as NX and text as RO"
7782- depends on MODULES
7783+ depends on MODULES && BROKEN
7784 ---help---
7785 This option helps catch unintended modifications to loadable
7786 kernel module's text and read-only data. It also prevents execution
7787diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7788index 209ba12..15140db 100644
7789--- a/arch/x86/Makefile
7790+++ b/arch/x86/Makefile
7791@@ -46,6 +46,7 @@ else
7792 UTS_MACHINE := x86_64
7793 CHECKFLAGS += -D__x86_64__ -m64
7794
7795+ biarch := $(call cc-option,-m64)
7796 KBUILD_AFLAGS += -m64
7797 KBUILD_CFLAGS += -m64
7798
7799@@ -201,3 +202,12 @@ define archhelp
7800 echo ' FDARGS="..." arguments for the booted kernel'
7801 echo ' FDINITRD=file initrd for the booted kernel'
7802 endef
7803+
7804+define OLD_LD
7805+
7806+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7807+*** Please upgrade your binutils to 2.18 or newer
7808+endef
7809+
7810+archprepare:
7811+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7812diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7813index 5a747dd..ff7b12c 100644
7814--- a/arch/x86/boot/Makefile
7815+++ b/arch/x86/boot/Makefile
7816@@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7817 $(call cc-option, -fno-stack-protector) \
7818 $(call cc-option, -mpreferred-stack-boundary=2)
7819 KBUILD_CFLAGS += $(call cc-option, -m32)
7820+ifdef CONSTIFY_PLUGIN
7821+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7822+endif
7823 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7824 GCOV_PROFILE := n
7825
7826diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7827index 878e4b9..20537ab 100644
7828--- a/arch/x86/boot/bitops.h
7829+++ b/arch/x86/boot/bitops.h
7830@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7831 u8 v;
7832 const u32 *p = (const u32 *)addr;
7833
7834- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7835+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7836 return v;
7837 }
7838
7839@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7840
7841 static inline void set_bit(int nr, void *addr)
7842 {
7843- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7844+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7845 }
7846
7847 #endif /* BOOT_BITOPS_H */
7848diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7849index c7093bd..d4247ffe0 100644
7850--- a/arch/x86/boot/boot.h
7851+++ b/arch/x86/boot/boot.h
7852@@ -85,7 +85,7 @@ static inline void io_delay(void)
7853 static inline u16 ds(void)
7854 {
7855 u16 seg;
7856- asm("movw %%ds,%0" : "=rm" (seg));
7857+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7858 return seg;
7859 }
7860
7861@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7862 static inline int memcmp(const void *s1, const void *s2, size_t len)
7863 {
7864 u8 diff;
7865- asm("repe; cmpsb; setnz %0"
7866+ asm volatile("repe; cmpsb; setnz %0"
7867 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7868 return diff;
7869 }
7870diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7871index fd55a2f..217b501 100644
7872--- a/arch/x86/boot/compressed/Makefile
7873+++ b/arch/x86/boot/compressed/Makefile
7874@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7875 KBUILD_CFLAGS += $(cflags-y)
7876 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7877 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7878+ifdef CONSTIFY_PLUGIN
7879+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7880+endif
7881
7882 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7883 GCOV_PROFILE := n
7884diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7885index 0cdfc0d..6e79437 100644
7886--- a/arch/x86/boot/compressed/eboot.c
7887+++ b/arch/x86/boot/compressed/eboot.c
7888@@ -122,7 +122,6 @@ again:
7889 *addr = max_addr;
7890 }
7891
7892-free_pool:
7893 efi_call_phys1(sys_table->boottime->free_pool, map);
7894
7895 fail:
7896@@ -186,7 +185,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7897 if (i == map_size / desc_size)
7898 status = EFI_NOT_FOUND;
7899
7900-free_pool:
7901 efi_call_phys1(sys_table->boottime->free_pool, map);
7902 fail:
7903 return status;
7904diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7905index c85e3ac..6f5aa80 100644
7906--- a/arch/x86/boot/compressed/head_32.S
7907+++ b/arch/x86/boot/compressed/head_32.S
7908@@ -106,7 +106,7 @@ preferred_addr:
7909 notl %eax
7910 andl %eax, %ebx
7911 #else
7912- movl $LOAD_PHYSICAL_ADDR, %ebx
7913+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7914 #endif
7915
7916 /* Target address to relocate to for decompression */
7917@@ -192,7 +192,7 @@ relocated:
7918 * and where it was actually loaded.
7919 */
7920 movl %ebp, %ebx
7921- subl $LOAD_PHYSICAL_ADDR, %ebx
7922+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7923 jz 2f /* Nothing to be done if loaded at compiled addr. */
7924 /*
7925 * Process relocations.
7926@@ -200,8 +200,7 @@ relocated:
7927
7928 1: subl $4, %edi
7929 movl (%edi), %ecx
7930- testl %ecx, %ecx
7931- jz 2f
7932+ jecxz 2f
7933 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7934 jmp 1b
7935 2:
7936diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7937index 87e03a1..0d94c76 100644
7938--- a/arch/x86/boot/compressed/head_64.S
7939+++ b/arch/x86/boot/compressed/head_64.S
7940@@ -91,7 +91,7 @@ ENTRY(startup_32)
7941 notl %eax
7942 andl %eax, %ebx
7943 #else
7944- movl $LOAD_PHYSICAL_ADDR, %ebx
7945+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7946 #endif
7947
7948 /* Target address to relocate to for decompression */
7949@@ -263,7 +263,7 @@ preferred_addr:
7950 notq %rax
7951 andq %rax, %rbp
7952 #else
7953- movq $LOAD_PHYSICAL_ADDR, %rbp
7954+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7955 #endif
7956
7957 /* Target address to relocate to for decompression */
7958diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7959index 7116dcb..d9ae1d7 100644
7960--- a/arch/x86/boot/compressed/misc.c
7961+++ b/arch/x86/boot/compressed/misc.c
7962@@ -310,7 +310,7 @@ static void parse_elf(void *output)
7963 case PT_LOAD:
7964 #ifdef CONFIG_RELOCATABLE
7965 dest = output;
7966- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7967+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7968 #else
7969 dest = (void *)(phdr->p_paddr);
7970 #endif
7971@@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7972 error("Destination address too large");
7973 #endif
7974 #ifndef CONFIG_RELOCATABLE
7975- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7976+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7977 error("Wrong destination address");
7978 #endif
7979
7980diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
7981index e77f4e4..17e511f 100644
7982--- a/arch/x86/boot/compressed/relocs.c
7983+++ b/arch/x86/boot/compressed/relocs.c
7984@@ -13,8 +13,11 @@
7985
7986 static void die(char *fmt, ...);
7987
7988+#include "../../../../include/generated/autoconf.h"
7989+
7990 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7991 static Elf32_Ehdr ehdr;
7992+static Elf32_Phdr *phdr;
7993 static unsigned long reloc_count, reloc_idx;
7994 static unsigned long *relocs;
7995
7996@@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7997 }
7998 }
7999
8000+static void read_phdrs(FILE *fp)
8001+{
8002+ unsigned int i;
8003+
8004+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
8005+ if (!phdr) {
8006+ die("Unable to allocate %d program headers\n",
8007+ ehdr.e_phnum);
8008+ }
8009+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
8010+ die("Seek to %d failed: %s\n",
8011+ ehdr.e_phoff, strerror(errno));
8012+ }
8013+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
8014+ die("Cannot read ELF program headers: %s\n",
8015+ strerror(errno));
8016+ }
8017+ for(i = 0; i < ehdr.e_phnum; i++) {
8018+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
8019+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
8020+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
8021+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
8022+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
8023+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
8024+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
8025+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
8026+ }
8027+
8028+}
8029+
8030 static void read_shdrs(FILE *fp)
8031 {
8032- int i;
8033+ unsigned int i;
8034 Elf32_Shdr shdr;
8035
8036 secs = calloc(ehdr.e_shnum, sizeof(struct section));
8037@@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
8038
8039 static void read_strtabs(FILE *fp)
8040 {
8041- int i;
8042+ unsigned int i;
8043 for (i = 0; i < ehdr.e_shnum; i++) {
8044 struct section *sec = &secs[i];
8045 if (sec->shdr.sh_type != SHT_STRTAB) {
8046@@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
8047
8048 static void read_symtabs(FILE *fp)
8049 {
8050- int i,j;
8051+ unsigned int i,j;
8052 for (i = 0; i < ehdr.e_shnum; i++) {
8053 struct section *sec = &secs[i];
8054 if (sec->shdr.sh_type != SHT_SYMTAB) {
8055@@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
8056
8057 static void read_relocs(FILE *fp)
8058 {
8059- int i,j;
8060+ unsigned int i,j;
8061+ uint32_t base;
8062+
8063 for (i = 0; i < ehdr.e_shnum; i++) {
8064 struct section *sec = &secs[i];
8065 if (sec->shdr.sh_type != SHT_REL) {
8066@@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
8067 die("Cannot read symbol table: %s\n",
8068 strerror(errno));
8069 }
8070+ base = 0;
8071+ for (j = 0; j < ehdr.e_phnum; j++) {
8072+ if (phdr[j].p_type != PT_LOAD )
8073+ continue;
8074+ 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)
8075+ continue;
8076+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
8077+ break;
8078+ }
8079 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
8080 Elf32_Rel *rel = &sec->reltab[j];
8081- rel->r_offset = elf32_to_cpu(rel->r_offset);
8082+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
8083 rel->r_info = elf32_to_cpu(rel->r_info);
8084 }
8085 }
8086@@ -396,13 +440,13 @@ static void read_relocs(FILE *fp)
8087
8088 static void print_absolute_symbols(void)
8089 {
8090- int i;
8091+ unsigned int i;
8092 printf("Absolute symbols\n");
8093 printf(" Num: Value Size Type Bind Visibility Name\n");
8094 for (i = 0; i < ehdr.e_shnum; i++) {
8095 struct section *sec = &secs[i];
8096 char *sym_strtab;
8097- int j;
8098+ unsigned int j;
8099
8100 if (sec->shdr.sh_type != SHT_SYMTAB) {
8101 continue;
8102@@ -429,14 +473,14 @@ static void print_absolute_symbols(void)
8103
8104 static void print_absolute_relocs(void)
8105 {
8106- int i, printed = 0;
8107+ unsigned int i, printed = 0;
8108
8109 for (i = 0; i < ehdr.e_shnum; i++) {
8110 struct section *sec = &secs[i];
8111 struct section *sec_applies, *sec_symtab;
8112 char *sym_strtab;
8113 Elf32_Sym *sh_symtab;
8114- int j;
8115+ unsigned int j;
8116 if (sec->shdr.sh_type != SHT_REL) {
8117 continue;
8118 }
8119@@ -497,13 +541,13 @@ static void print_absolute_relocs(void)
8120
8121 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
8122 {
8123- int i;
8124+ unsigned int i;
8125 /* Walk through the relocations */
8126 for (i = 0; i < ehdr.e_shnum; i++) {
8127 char *sym_strtab;
8128 Elf32_Sym *sh_symtab;
8129 struct section *sec_applies, *sec_symtab;
8130- int j;
8131+ unsigned int j;
8132 struct section *sec = &secs[i];
8133
8134 if (sec->shdr.sh_type != SHT_REL) {
8135@@ -528,6 +572,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
8136 !is_rel_reloc(sym_name(sym_strtab, sym))) {
8137 continue;
8138 }
8139+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
8140+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
8141+ continue;
8142+
8143+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
8144+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
8145+ if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
8146+ continue;
8147+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
8148+ continue;
8149+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
8150+ continue;
8151+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
8152+ continue;
8153+#endif
8154+
8155 switch (r_type) {
8156 case R_386_NONE:
8157 case R_386_PC32:
8158@@ -569,7 +629,7 @@ static int cmp_relocs(const void *va, const void *vb)
8159
8160 static void emit_relocs(int as_text)
8161 {
8162- int i;
8163+ unsigned int i;
8164 /* Count how many relocations I have and allocate space for them. */
8165 reloc_count = 0;
8166 walk_relocs(count_reloc);
8167@@ -663,6 +723,7 @@ int main(int argc, char **argv)
8168 fname, strerror(errno));
8169 }
8170 read_ehdr(fp);
8171+ read_phdrs(fp);
8172 read_shdrs(fp);
8173 read_strtabs(fp);
8174 read_symtabs(fp);
8175diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
8176index 4d3ff03..e4972ff 100644
8177--- a/arch/x86/boot/cpucheck.c
8178+++ b/arch/x86/boot/cpucheck.c
8179@@ -74,7 +74,7 @@ static int has_fpu(void)
8180 u16 fcw = -1, fsw = -1;
8181 u32 cr0;
8182
8183- asm("movl %%cr0,%0" : "=r" (cr0));
8184+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
8185 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
8186 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
8187 asm volatile("movl %0,%%cr0" : : "r" (cr0));
8188@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
8189 {
8190 u32 f0, f1;
8191
8192- asm("pushfl ; "
8193+ asm volatile("pushfl ; "
8194 "pushfl ; "
8195 "popl %0 ; "
8196 "movl %0,%1 ; "
8197@@ -115,7 +115,7 @@ static void get_flags(void)
8198 set_bit(X86_FEATURE_FPU, cpu.flags);
8199
8200 if (has_eflag(X86_EFLAGS_ID)) {
8201- asm("cpuid"
8202+ asm volatile("cpuid"
8203 : "=a" (max_intel_level),
8204 "=b" (cpu_vendor[0]),
8205 "=d" (cpu_vendor[1]),
8206@@ -124,7 +124,7 @@ static void get_flags(void)
8207
8208 if (max_intel_level >= 0x00000001 &&
8209 max_intel_level <= 0x0000ffff) {
8210- asm("cpuid"
8211+ asm volatile("cpuid"
8212 : "=a" (tfms),
8213 "=c" (cpu.flags[4]),
8214 "=d" (cpu.flags[0])
8215@@ -136,7 +136,7 @@ static void get_flags(void)
8216 cpu.model += ((tfms >> 16) & 0xf) << 4;
8217 }
8218
8219- asm("cpuid"
8220+ asm volatile("cpuid"
8221 : "=a" (max_amd_level)
8222 : "a" (0x80000000)
8223 : "ebx", "ecx", "edx");
8224@@ -144,7 +144,7 @@ static void get_flags(void)
8225 if (max_amd_level >= 0x80000001 &&
8226 max_amd_level <= 0x8000ffff) {
8227 u32 eax = 0x80000001;
8228- asm("cpuid"
8229+ asm volatile("cpuid"
8230 : "+a" (eax),
8231 "=c" (cpu.flags[6]),
8232 "=d" (cpu.flags[1])
8233@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8234 u32 ecx = MSR_K7_HWCR;
8235 u32 eax, edx;
8236
8237- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8238+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8239 eax &= ~(1 << 15);
8240- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8241+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8242
8243 get_flags(); /* Make sure it really did something */
8244 err = check_flags();
8245@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8246 u32 ecx = MSR_VIA_FCR;
8247 u32 eax, edx;
8248
8249- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8250+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8251 eax |= (1<<1)|(1<<7);
8252- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8253+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8254
8255 set_bit(X86_FEATURE_CX8, cpu.flags);
8256 err = check_flags();
8257@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8258 u32 eax, edx;
8259 u32 level = 1;
8260
8261- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8262- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8263- asm("cpuid"
8264+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8265+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8266+ asm volatile("cpuid"
8267 : "+a" (level), "=d" (cpu.flags[0])
8268 : : "ecx", "ebx");
8269- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8270+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8271
8272 err = check_flags();
8273 }
8274diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8275index f1bbeeb..aff09cb 100644
8276--- a/arch/x86/boot/header.S
8277+++ b/arch/x86/boot/header.S
8278@@ -372,7 +372,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
8279 # single linked list of
8280 # struct setup_data
8281
8282-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8283+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8284
8285 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8286 #define VO_INIT_SIZE (VO__end - VO__text)
8287diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8288index db75d07..8e6d0af 100644
8289--- a/arch/x86/boot/memory.c
8290+++ b/arch/x86/boot/memory.c
8291@@ -19,7 +19,7 @@
8292
8293 static int detect_memory_e820(void)
8294 {
8295- int count = 0;
8296+ unsigned int count = 0;
8297 struct biosregs ireg, oreg;
8298 struct e820entry *desc = boot_params.e820_map;
8299 static struct e820entry buf; /* static so it is zeroed */
8300diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8301index 11e8c6e..fdbb1ed 100644
8302--- a/arch/x86/boot/video-vesa.c
8303+++ b/arch/x86/boot/video-vesa.c
8304@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8305
8306 boot_params.screen_info.vesapm_seg = oreg.es;
8307 boot_params.screen_info.vesapm_off = oreg.di;
8308+ boot_params.screen_info.vesapm_size = oreg.cx;
8309 }
8310
8311 /*
8312diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8313index 43eda28..5ab5fdb 100644
8314--- a/arch/x86/boot/video.c
8315+++ b/arch/x86/boot/video.c
8316@@ -96,7 +96,7 @@ static void store_mode_params(void)
8317 static unsigned int get_entry(void)
8318 {
8319 char entry_buf[4];
8320- int i, len = 0;
8321+ unsigned int i, len = 0;
8322 int key;
8323 unsigned int v;
8324
8325diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8326index 5b577d5..3c1fed4 100644
8327--- a/arch/x86/crypto/aes-x86_64-asm_64.S
8328+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8329@@ -8,6 +8,8 @@
8330 * including this sentence is retained in full.
8331 */
8332
8333+#include <asm/alternative-asm.h>
8334+
8335 .extern crypto_ft_tab
8336 .extern crypto_it_tab
8337 .extern crypto_fl_tab
8338@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8339 je B192; \
8340 leaq 32(r9),r9;
8341
8342+#define ret pax_force_retaddr 0, 1; ret
8343+
8344 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8345 movq r1,r2; \
8346 movq r3,r4; \
8347diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8348index be6d9e3..21fbbca 100644
8349--- a/arch/x86/crypto/aesni-intel_asm.S
8350+++ b/arch/x86/crypto/aesni-intel_asm.S
8351@@ -31,6 +31,7 @@
8352
8353 #include <linux/linkage.h>
8354 #include <asm/inst.h>
8355+#include <asm/alternative-asm.h>
8356
8357 #ifdef __x86_64__
8358 .data
8359@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8360 pop %r14
8361 pop %r13
8362 pop %r12
8363+ pax_force_retaddr 0, 1
8364 ret
8365+ENDPROC(aesni_gcm_dec)
8366
8367
8368 /*****************************************************************************
8369@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8370 pop %r14
8371 pop %r13
8372 pop %r12
8373+ pax_force_retaddr 0, 1
8374 ret
8375+ENDPROC(aesni_gcm_enc)
8376
8377 #endif
8378
8379@@ -1714,6 +1719,7 @@ _key_expansion_256a:
8380 pxor %xmm1, %xmm0
8381 movaps %xmm0, (TKEYP)
8382 add $0x10, TKEYP
8383+ pax_force_retaddr_bts
8384 ret
8385
8386 .align 4
8387@@ -1738,6 +1744,7 @@ _key_expansion_192a:
8388 shufps $0b01001110, %xmm2, %xmm1
8389 movaps %xmm1, 0x10(TKEYP)
8390 add $0x20, TKEYP
8391+ pax_force_retaddr_bts
8392 ret
8393
8394 .align 4
8395@@ -1757,6 +1764,7 @@ _key_expansion_192b:
8396
8397 movaps %xmm0, (TKEYP)
8398 add $0x10, TKEYP
8399+ pax_force_retaddr_bts
8400 ret
8401
8402 .align 4
8403@@ -1769,6 +1777,7 @@ _key_expansion_256b:
8404 pxor %xmm1, %xmm2
8405 movaps %xmm2, (TKEYP)
8406 add $0x10, TKEYP
8407+ pax_force_retaddr_bts
8408 ret
8409
8410 /*
8411@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8412 #ifndef __x86_64__
8413 popl KEYP
8414 #endif
8415+ pax_force_retaddr 0, 1
8416 ret
8417+ENDPROC(aesni_set_key)
8418
8419 /*
8420 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8421@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8422 popl KLEN
8423 popl KEYP
8424 #endif
8425+ pax_force_retaddr 0, 1
8426 ret
8427+ENDPROC(aesni_enc)
8428
8429 /*
8430 * _aesni_enc1: internal ABI
8431@@ -1959,6 +1972,7 @@ _aesni_enc1:
8432 AESENC KEY STATE
8433 movaps 0x70(TKEYP), KEY
8434 AESENCLAST KEY STATE
8435+ pax_force_retaddr_bts
8436 ret
8437
8438 /*
8439@@ -2067,6 +2081,7 @@ _aesni_enc4:
8440 AESENCLAST KEY STATE2
8441 AESENCLAST KEY STATE3
8442 AESENCLAST KEY STATE4
8443+ pax_force_retaddr_bts
8444 ret
8445
8446 /*
8447@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8448 popl KLEN
8449 popl KEYP
8450 #endif
8451+ pax_force_retaddr 0, 1
8452 ret
8453+ENDPROC(aesni_dec)
8454
8455 /*
8456 * _aesni_dec1: internal ABI
8457@@ -2146,6 +2163,7 @@ _aesni_dec1:
8458 AESDEC KEY STATE
8459 movaps 0x70(TKEYP), KEY
8460 AESDECLAST KEY STATE
8461+ pax_force_retaddr_bts
8462 ret
8463
8464 /*
8465@@ -2254,6 +2272,7 @@ _aesni_dec4:
8466 AESDECLAST KEY STATE2
8467 AESDECLAST KEY STATE3
8468 AESDECLAST KEY STATE4
8469+ pax_force_retaddr_bts
8470 ret
8471
8472 /*
8473@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8474 popl KEYP
8475 popl LEN
8476 #endif
8477+ pax_force_retaddr 0, 1
8478 ret
8479+ENDPROC(aesni_ecb_enc)
8480
8481 /*
8482 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8483@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8484 popl KEYP
8485 popl LEN
8486 #endif
8487+ pax_force_retaddr 0, 1
8488 ret
8489+ENDPROC(aesni_ecb_dec)
8490
8491 /*
8492 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8493@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8494 popl LEN
8495 popl IVP
8496 #endif
8497+ pax_force_retaddr 0, 1
8498 ret
8499+ENDPROC(aesni_cbc_enc)
8500
8501 /*
8502 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8503@@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
8504 popl LEN
8505 popl IVP
8506 #endif
8507+ pax_force_retaddr 0, 1
8508 ret
8509+ENDPROC(aesni_cbc_dec)
8510
8511 #ifdef __x86_64__
8512 .align 16
8513@@ -2524,6 +2551,7 @@ _aesni_inc_init:
8514 mov $1, TCTR_LOW
8515 MOVQ_R64_XMM TCTR_LOW INC
8516 MOVQ_R64_XMM CTR TCTR_LOW
8517+ pax_force_retaddr_bts
8518 ret
8519
8520 /*
8521@@ -2552,6 +2580,7 @@ _aesni_inc:
8522 .Linc_low:
8523 movaps CTR, IV
8524 PSHUFB_XMM BSWAP_MASK IV
8525+ pax_force_retaddr_bts
8526 ret
8527
8528 /*
8529@@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
8530 .Lctr_enc_ret:
8531 movups IV, (IVP)
8532 .Lctr_enc_just_ret:
8533+ pax_force_retaddr 0, 1
8534 ret
8535+ENDPROC(aesni_ctr_enc)
8536 #endif
8537diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8538index 391d245..67f35c2 100644
8539--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8540+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8541@@ -20,6 +20,8 @@
8542 *
8543 */
8544
8545+#include <asm/alternative-asm.h>
8546+
8547 .file "blowfish-x86_64-asm.S"
8548 .text
8549
8550@@ -151,9 +153,11 @@ __blowfish_enc_blk:
8551 jnz __enc_xor;
8552
8553 write_block();
8554+ pax_force_retaddr 0, 1
8555 ret;
8556 __enc_xor:
8557 xor_block();
8558+ pax_force_retaddr 0, 1
8559 ret;
8560
8561 .align 8
8562@@ -188,6 +192,7 @@ blowfish_dec_blk:
8563
8564 movq %r11, %rbp;
8565
8566+ pax_force_retaddr 0, 1
8567 ret;
8568
8569 /**********************************************************************
8570@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8571
8572 popq %rbx;
8573 popq %rbp;
8574+ pax_force_retaddr 0, 1
8575 ret;
8576
8577 __enc_xor4:
8578@@ -349,6 +355,7 @@ __enc_xor4:
8579
8580 popq %rbx;
8581 popq %rbp;
8582+ pax_force_retaddr 0, 1
8583 ret;
8584
8585 .align 8
8586@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8587 popq %rbx;
8588 popq %rbp;
8589
8590+ pax_force_retaddr 0, 1
8591 ret;
8592
8593diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8594index 6214a9b..1f4fc9a 100644
8595--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8596+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8597@@ -1,3 +1,5 @@
8598+#include <asm/alternative-asm.h>
8599+
8600 # enter ECRYPT_encrypt_bytes
8601 .text
8602 .p2align 5
8603@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8604 add %r11,%rsp
8605 mov %rdi,%rax
8606 mov %rsi,%rdx
8607+ pax_force_retaddr 0, 1
8608 ret
8609 # bytesatleast65:
8610 ._bytesatleast65:
8611@@ -891,6 +894,7 @@ ECRYPT_keysetup:
8612 add %r11,%rsp
8613 mov %rdi,%rax
8614 mov %rsi,%rdx
8615+ pax_force_retaddr
8616 ret
8617 # enter ECRYPT_ivsetup
8618 .text
8619@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8620 add %r11,%rsp
8621 mov %rdi,%rax
8622 mov %rsi,%rdx
8623+ pax_force_retaddr
8624 ret
8625diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8626index 7f24a15..9cd3ffe 100644
8627--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8628+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8629@@ -24,6 +24,8 @@
8630 *
8631 */
8632
8633+#include <asm/alternative-asm.h>
8634+
8635 .file "serpent-sse2-x86_64-asm_64.S"
8636 .text
8637
8638@@ -695,12 +697,14 @@ __serpent_enc_blk_8way:
8639 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8640 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8641
8642+ pax_force_retaddr
8643 ret;
8644
8645 __enc_xor8:
8646 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8647 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8648
8649+ pax_force_retaddr
8650 ret;
8651
8652 .align 8
8653@@ -758,4 +762,5 @@ serpent_dec_blk_8way:
8654 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8655 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8656
8657+ pax_force_retaddr
8658 ret;
8659diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8660index b2c2f57..8470cab 100644
8661--- a/arch/x86/crypto/sha1_ssse3_asm.S
8662+++ b/arch/x86/crypto/sha1_ssse3_asm.S
8663@@ -28,6 +28,8 @@
8664 * (at your option) any later version.
8665 */
8666
8667+#include <asm/alternative-asm.h>
8668+
8669 #define CTX %rdi // arg1
8670 #define BUF %rsi // arg2
8671 #define CNT %rdx // arg3
8672@@ -104,6 +106,7 @@
8673 pop %r12
8674 pop %rbp
8675 pop %rbx
8676+ pax_force_retaddr 0, 1
8677 ret
8678
8679 .size \name, .-\name
8680diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8681index 5b012a2..36d5364 100644
8682--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8683+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8684@@ -20,6 +20,8 @@
8685 *
8686 */
8687
8688+#include <asm/alternative-asm.h>
8689+
8690 .file "twofish-x86_64-asm-3way.S"
8691 .text
8692
8693@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8694 popq %r13;
8695 popq %r14;
8696 popq %r15;
8697+ pax_force_retaddr 0, 1
8698 ret;
8699
8700 __enc_xor3:
8701@@ -271,6 +274,7 @@ __enc_xor3:
8702 popq %r13;
8703 popq %r14;
8704 popq %r15;
8705+ pax_force_retaddr 0, 1
8706 ret;
8707
8708 .global twofish_dec_blk_3way
8709@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8710 popq %r13;
8711 popq %r14;
8712 popq %r15;
8713+ pax_force_retaddr 0, 1
8714 ret;
8715
8716diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8717index 7bcf3fc..f53832f 100644
8718--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8719+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8720@@ -21,6 +21,7 @@
8721 .text
8722
8723 #include <asm/asm-offsets.h>
8724+#include <asm/alternative-asm.h>
8725
8726 #define a_offset 0
8727 #define b_offset 4
8728@@ -268,6 +269,7 @@ twofish_enc_blk:
8729
8730 popq R1
8731 movq $1,%rax
8732+ pax_force_retaddr 0, 1
8733 ret
8734
8735 twofish_dec_blk:
8736@@ -319,4 +321,5 @@ twofish_dec_blk:
8737
8738 popq R1
8739 movq $1,%rax
8740+ pax_force_retaddr 0, 1
8741 ret
8742diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8743index 39e4909..887aa7e 100644
8744--- a/arch/x86/ia32/ia32_aout.c
8745+++ b/arch/x86/ia32/ia32_aout.c
8746@@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8747 unsigned long dump_start, dump_size;
8748 struct user32 dump;
8749
8750+ memset(&dump, 0, sizeof(dump));
8751+
8752 fs = get_fs();
8753 set_fs(KERNEL_DS);
8754 has_dumped = 1;
8755diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8756index 6557769..ef6ae89 100644
8757--- a/arch/x86/ia32/ia32_signal.c
8758+++ b/arch/x86/ia32/ia32_signal.c
8759@@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8760 }
8761 seg = get_fs();
8762 set_fs(KERNEL_DS);
8763- ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8764+ ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8765 set_fs(seg);
8766 if (ret >= 0 && uoss_ptr) {
8767 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8768@@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8769 */
8770 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8771 size_t frame_size,
8772- void **fpstate)
8773+ void __user **fpstate)
8774 {
8775 unsigned long sp;
8776
8777@@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8778
8779 if (used_math()) {
8780 sp = sp - sig_xstate_ia32_size;
8781- *fpstate = (struct _fpstate_ia32 *) sp;
8782+ *fpstate = (struct _fpstate_ia32 __user *) sp;
8783 if (save_i387_xstate_ia32(*fpstate) < 0)
8784 return (void __user *) -1L;
8785 }
8786@@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8787 sp -= frame_size;
8788 /* Align the stack pointer according to the i386 ABI,
8789 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8790- sp = ((sp + 4) & -16ul) - 4;
8791+ sp = ((sp - 12) & -16ul) - 4;
8792 return (void __user *) sp;
8793 }
8794
8795@@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8796 * These are actually not used anymore, but left because some
8797 * gdb versions depend on them as a marker.
8798 */
8799- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8800+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8801 } put_user_catch(err);
8802
8803 if (err)
8804@@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8805 0xb8,
8806 __NR_ia32_rt_sigreturn,
8807 0x80cd,
8808- 0,
8809+ 0
8810 };
8811
8812 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8813@@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8814
8815 if (ka->sa.sa_flags & SA_RESTORER)
8816 restorer = ka->sa.sa_restorer;
8817+ else if (current->mm->context.vdso)
8818+ /* Return stub is in 32bit vsyscall page */
8819+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8820 else
8821- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8822- rt_sigreturn);
8823+ restorer = &frame->retcode;
8824 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8825
8826 /*
8827 * Not actually used anymore, but left because some gdb
8828 * versions need it.
8829 */
8830- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8831+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8832 } put_user_catch(err);
8833
8834 if (err)
8835diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8836index e3e7340..05ed805 100644
8837--- a/arch/x86/ia32/ia32entry.S
8838+++ b/arch/x86/ia32/ia32entry.S
8839@@ -13,8 +13,10 @@
8840 #include <asm/thread_info.h>
8841 #include <asm/segment.h>
8842 #include <asm/irqflags.h>
8843+#include <asm/pgtable.h>
8844 #include <linux/linkage.h>
8845 #include <linux/err.h>
8846+#include <asm/alternative-asm.h>
8847
8848 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8849 #include <linux/elf-em.h>
8850@@ -94,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8851 ENDPROC(native_irq_enable_sysexit)
8852 #endif
8853
8854+ .macro pax_enter_kernel_user
8855+ pax_set_fptr_mask
8856+#ifdef CONFIG_PAX_MEMORY_UDEREF
8857+ call pax_enter_kernel_user
8858+#endif
8859+ .endm
8860+
8861+ .macro pax_exit_kernel_user
8862+#ifdef CONFIG_PAX_MEMORY_UDEREF
8863+ call pax_exit_kernel_user
8864+#endif
8865+#ifdef CONFIG_PAX_RANDKSTACK
8866+ pushq %rax
8867+ pushq %r11
8868+ call pax_randomize_kstack
8869+ popq %r11
8870+ popq %rax
8871+#endif
8872+ .endm
8873+
8874+.macro pax_erase_kstack
8875+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8876+ call pax_erase_kstack
8877+#endif
8878+.endm
8879+
8880 /*
8881 * 32bit SYSENTER instruction entry.
8882 *
8883@@ -120,12 +148,6 @@ ENTRY(ia32_sysenter_target)
8884 CFI_REGISTER rsp,rbp
8885 SWAPGS_UNSAFE_STACK
8886 movq PER_CPU_VAR(kernel_stack), %rsp
8887- addq $(KERNEL_STACK_OFFSET),%rsp
8888- /*
8889- * No need to follow this irqs on/off section: the syscall
8890- * disabled irqs, here we enable it straight after entry:
8891- */
8892- ENABLE_INTERRUPTS(CLBR_NONE)
8893 movl %ebp,%ebp /* zero extension */
8894 pushq_cfi $__USER32_DS
8895 /*CFI_REL_OFFSET ss,0*/
8896@@ -133,24 +155,39 @@ ENTRY(ia32_sysenter_target)
8897 CFI_REL_OFFSET rsp,0
8898 pushfq_cfi
8899 /*CFI_REL_OFFSET rflags,0*/
8900- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8901- CFI_REGISTER rip,r10
8902+ orl $X86_EFLAGS_IF,(%rsp)
8903+ GET_THREAD_INFO(%r11)
8904+ movl TI_sysenter_return(%r11), %r11d
8905+ CFI_REGISTER rip,r11
8906 pushq_cfi $__USER32_CS
8907 /*CFI_REL_OFFSET cs,0*/
8908 movl %eax, %eax
8909- pushq_cfi %r10
8910+ pushq_cfi %r11
8911 CFI_REL_OFFSET rip,0
8912 pushq_cfi %rax
8913 cld
8914 SAVE_ARGS 0,1,0
8915+ pax_enter_kernel_user
8916+ /*
8917+ * No need to follow this irqs on/off section: the syscall
8918+ * disabled irqs, here we enable it straight after entry:
8919+ */
8920+ ENABLE_INTERRUPTS(CLBR_NONE)
8921 /* no need to do an access_ok check here because rbp has been
8922 32bit zero extended */
8923+
8924+#ifdef CONFIG_PAX_MEMORY_UDEREF
8925+ mov $PAX_USER_SHADOW_BASE,%r11
8926+ add %r11,%rbp
8927+#endif
8928+
8929 1: movl (%rbp),%ebp
8930 .section __ex_table,"a"
8931 .quad 1b,ia32_badarg
8932 .previous
8933- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8934- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8935+ GET_THREAD_INFO(%r11)
8936+ orl $TS_COMPAT,TI_status(%r11)
8937+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8938 CFI_REMEMBER_STATE
8939 jnz sysenter_tracesys
8940 cmpq $(IA32_NR_syscalls-1),%rax
8941@@ -160,12 +197,15 @@ sysenter_do_call:
8942 sysenter_dispatch:
8943 call *ia32_sys_call_table(,%rax,8)
8944 movq %rax,RAX-ARGOFFSET(%rsp)
8945+ GET_THREAD_INFO(%r11)
8946 DISABLE_INTERRUPTS(CLBR_NONE)
8947 TRACE_IRQS_OFF
8948- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8949+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8950 jnz sysexit_audit
8951 sysexit_from_sys_call:
8952- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8953+ pax_exit_kernel_user
8954+ pax_erase_kstack
8955+ andl $~TS_COMPAT,TI_status(%r11)
8956 /* clear IF, that popfq doesn't enable interrupts early */
8957 andl $~0x200,EFLAGS-R11(%rsp)
8958 movl RIP-R11(%rsp),%edx /* User %eip */
8959@@ -191,6 +231,9 @@ sysexit_from_sys_call:
8960 movl %eax,%esi /* 2nd arg: syscall number */
8961 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8962 call __audit_syscall_entry
8963+
8964+ pax_erase_kstack
8965+
8966 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8967 cmpq $(IA32_NR_syscalls-1),%rax
8968 ja ia32_badsys
8969@@ -202,7 +245,7 @@ sysexit_from_sys_call:
8970 .endm
8971
8972 .macro auditsys_exit exit
8973- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8974+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8975 jnz ia32_ret_from_sys_call
8976 TRACE_IRQS_ON
8977 sti
8978@@ -213,11 +256,12 @@ sysexit_from_sys_call:
8979 1: setbe %al /* 1 if error, 0 if not */
8980 movzbl %al,%edi /* zero-extend that into %edi */
8981 call __audit_syscall_exit
8982+ GET_THREAD_INFO(%r11)
8983 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8984 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8985 cli
8986 TRACE_IRQS_OFF
8987- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8988+ testl %edi,TI_flags(%r11)
8989 jz \exit
8990 CLEAR_RREGS -ARGOFFSET
8991 jmp int_with_check
8992@@ -235,7 +279,7 @@ sysexit_audit:
8993
8994 sysenter_tracesys:
8995 #ifdef CONFIG_AUDITSYSCALL
8996- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8997+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8998 jz sysenter_auditsys
8999 #endif
9000 SAVE_REST
9001@@ -243,6 +287,9 @@ sysenter_tracesys:
9002 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
9003 movq %rsp,%rdi /* &pt_regs -> arg1 */
9004 call syscall_trace_enter
9005+
9006+ pax_erase_kstack
9007+
9008 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
9009 RESTORE_REST
9010 cmpq $(IA32_NR_syscalls-1),%rax
9011@@ -274,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
9012 ENTRY(ia32_cstar_target)
9013 CFI_STARTPROC32 simple
9014 CFI_SIGNAL_FRAME
9015- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
9016+ CFI_DEF_CFA rsp,0
9017 CFI_REGISTER rip,rcx
9018 /*CFI_REGISTER rflags,r11*/
9019 SWAPGS_UNSAFE_STACK
9020 movl %esp,%r8d
9021 CFI_REGISTER rsp,r8
9022 movq PER_CPU_VAR(kernel_stack),%rsp
9023+ SAVE_ARGS 8*6,0,0
9024+ pax_enter_kernel_user
9025 /*
9026 * No need to follow this irqs on/off section: the syscall
9027 * disabled irqs and here we enable it straight after entry:
9028 */
9029 ENABLE_INTERRUPTS(CLBR_NONE)
9030- SAVE_ARGS 8,0,0
9031 movl %eax,%eax /* zero extension */
9032 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
9033 movq %rcx,RIP-ARGOFFSET(%rsp)
9034@@ -302,12 +350,19 @@ ENTRY(ia32_cstar_target)
9035 /* no need to do an access_ok check here because r8 has been
9036 32bit zero extended */
9037 /* hardware stack frame is complete now */
9038+
9039+#ifdef CONFIG_PAX_MEMORY_UDEREF
9040+ mov $PAX_USER_SHADOW_BASE,%r11
9041+ add %r11,%r8
9042+#endif
9043+
9044 1: movl (%r8),%r9d
9045 .section __ex_table,"a"
9046 .quad 1b,ia32_badarg
9047 .previous
9048- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9049- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9050+ GET_THREAD_INFO(%r11)
9051+ orl $TS_COMPAT,TI_status(%r11)
9052+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9053 CFI_REMEMBER_STATE
9054 jnz cstar_tracesys
9055 cmpq $IA32_NR_syscalls-1,%rax
9056@@ -317,12 +372,15 @@ cstar_do_call:
9057 cstar_dispatch:
9058 call *ia32_sys_call_table(,%rax,8)
9059 movq %rax,RAX-ARGOFFSET(%rsp)
9060+ GET_THREAD_INFO(%r11)
9061 DISABLE_INTERRUPTS(CLBR_NONE)
9062 TRACE_IRQS_OFF
9063- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9064+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
9065 jnz sysretl_audit
9066 sysretl_from_sys_call:
9067- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9068+ pax_exit_kernel_user
9069+ pax_erase_kstack
9070+ andl $~TS_COMPAT,TI_status(%r11)
9071 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
9072 movl RIP-ARGOFFSET(%rsp),%ecx
9073 CFI_REGISTER rip,rcx
9074@@ -350,7 +408,7 @@ sysretl_audit:
9075
9076 cstar_tracesys:
9077 #ifdef CONFIG_AUDITSYSCALL
9078- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9079+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
9080 jz cstar_auditsys
9081 #endif
9082 xchgl %r9d,%ebp
9083@@ -359,6 +417,9 @@ cstar_tracesys:
9084 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
9085 movq %rsp,%rdi /* &pt_regs -> arg1 */
9086 call syscall_trace_enter
9087+
9088+ pax_erase_kstack
9089+
9090 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
9091 RESTORE_REST
9092 xchgl %ebp,%r9d
9093@@ -404,19 +465,21 @@ ENTRY(ia32_syscall)
9094 CFI_REL_OFFSET rip,RIP-RIP
9095 PARAVIRT_ADJUST_EXCEPTION_FRAME
9096 SWAPGS
9097- /*
9098- * No need to follow this irqs on/off section: the syscall
9099- * disabled irqs and here we enable it straight after entry:
9100- */
9101- ENABLE_INTERRUPTS(CLBR_NONE)
9102 movl %eax,%eax
9103 pushq_cfi %rax
9104 cld
9105 /* note the registers are not zero extended to the sf.
9106 this could be a problem. */
9107 SAVE_ARGS 0,1,0
9108- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9109- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9110+ pax_enter_kernel_user
9111+ /*
9112+ * No need to follow this irqs on/off section: the syscall
9113+ * disabled irqs and here we enable it straight after entry:
9114+ */
9115+ ENABLE_INTERRUPTS(CLBR_NONE)
9116+ GET_THREAD_INFO(%r11)
9117+ orl $TS_COMPAT,TI_status(%r11)
9118+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9119 jnz ia32_tracesys
9120 cmpq $(IA32_NR_syscalls-1),%rax
9121 ja ia32_badsys
9122@@ -435,6 +498,9 @@ ia32_tracesys:
9123 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
9124 movq %rsp,%rdi /* &pt_regs -> arg1 */
9125 call syscall_trace_enter
9126+
9127+ pax_erase_kstack
9128+
9129 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
9130 RESTORE_REST
9131 cmpq $(IA32_NR_syscalls-1),%rax
9132diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
9133index f6f5c53..b358b28 100644
9134--- a/arch/x86/ia32/sys_ia32.c
9135+++ b/arch/x86/ia32/sys_ia32.c
9136@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
9137 */
9138 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
9139 {
9140- typeof(ubuf->st_uid) uid = 0;
9141- typeof(ubuf->st_gid) gid = 0;
9142+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
9143+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
9144 SET_UID(uid, stat->uid);
9145 SET_GID(gid, stat->gid);
9146 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
9147@@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
9148 }
9149 set_fs(KERNEL_DS);
9150 ret = sys_rt_sigprocmask(how,
9151- set ? (sigset_t __user *)&s : NULL,
9152- oset ? (sigset_t __user *)&s : NULL,
9153+ set ? (sigset_t __force_user *)&s : NULL,
9154+ oset ? (sigset_t __force_user *)&s : NULL,
9155 sigsetsize);
9156 set_fs(old_fs);
9157 if (ret)
9158@@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
9159 return alarm_setitimer(seconds);
9160 }
9161
9162-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
9163+asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
9164 int options)
9165 {
9166 return compat_sys_wait4(pid, stat_addr, options, NULL);
9167@@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
9168 mm_segment_t old_fs = get_fs();
9169
9170 set_fs(KERNEL_DS);
9171- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9172+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9173 set_fs(old_fs);
9174 if (put_compat_timespec(&t, interval))
9175 return -EFAULT;
9176@@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9177 mm_segment_t old_fs = get_fs();
9178
9179 set_fs(KERNEL_DS);
9180- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9181+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9182 set_fs(old_fs);
9183 if (!ret) {
9184 switch (_NSIG_WORDS) {
9185@@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9186 if (copy_siginfo_from_user32(&info, uinfo))
9187 return -EFAULT;
9188 set_fs(KERNEL_DS);
9189- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9190+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9191 set_fs(old_fs);
9192 return ret;
9193 }
9194@@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9195 return -EFAULT;
9196
9197 set_fs(KERNEL_DS);
9198- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9199+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9200 count);
9201 set_fs(old_fs);
9202
9203diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9204index 952bd01..7692c6f 100644
9205--- a/arch/x86/include/asm/alternative-asm.h
9206+++ b/arch/x86/include/asm/alternative-asm.h
9207@@ -15,6 +15,45 @@
9208 .endm
9209 #endif
9210
9211+#ifdef KERNEXEC_PLUGIN
9212+ .macro pax_force_retaddr_bts rip=0
9213+ btsq $63,\rip(%rsp)
9214+ .endm
9215+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9216+ .macro pax_force_retaddr rip=0, reload=0
9217+ btsq $63,\rip(%rsp)
9218+ .endm
9219+ .macro pax_force_fptr ptr
9220+ btsq $63,\ptr
9221+ .endm
9222+ .macro pax_set_fptr_mask
9223+ .endm
9224+#endif
9225+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9226+ .macro pax_force_retaddr rip=0, reload=0
9227+ .if \reload
9228+ pax_set_fptr_mask
9229+ .endif
9230+ orq %r10,\rip(%rsp)
9231+ .endm
9232+ .macro pax_force_fptr ptr
9233+ orq %r10,\ptr
9234+ .endm
9235+ .macro pax_set_fptr_mask
9236+ movabs $0x8000000000000000,%r10
9237+ .endm
9238+#endif
9239+#else
9240+ .macro pax_force_retaddr rip=0, reload=0
9241+ .endm
9242+ .macro pax_force_fptr ptr
9243+ .endm
9244+ .macro pax_force_retaddr_bts rip=0
9245+ .endm
9246+ .macro pax_set_fptr_mask
9247+ .endm
9248+#endif
9249+
9250 .macro altinstruction_entry orig alt feature orig_len alt_len
9251 .long \orig - .
9252 .long \alt - .
9253diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9254index 37ad100..7d47faa 100644
9255--- a/arch/x86/include/asm/alternative.h
9256+++ b/arch/x86/include/asm/alternative.h
9257@@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9258 ".section .discard,\"aw\",@progbits\n" \
9259 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9260 ".previous\n" \
9261- ".section .altinstr_replacement, \"ax\"\n" \
9262+ ".section .altinstr_replacement, \"a\"\n" \
9263 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9264 ".previous"
9265
9266diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9267index 3ab9bdd..238033e 100644
9268--- a/arch/x86/include/asm/apic.h
9269+++ b/arch/x86/include/asm/apic.h
9270@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
9271
9272 #ifdef CONFIG_X86_LOCAL_APIC
9273
9274-extern unsigned int apic_verbosity;
9275+extern int apic_verbosity;
9276 extern int local_apic_timer_c2_ok;
9277
9278 extern int disable_apic;
9279diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9280index 20370c6..a2eb9b0 100644
9281--- a/arch/x86/include/asm/apm.h
9282+++ b/arch/x86/include/asm/apm.h
9283@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9284 __asm__ __volatile__(APM_DO_ZERO_SEGS
9285 "pushl %%edi\n\t"
9286 "pushl %%ebp\n\t"
9287- "lcall *%%cs:apm_bios_entry\n\t"
9288+ "lcall *%%ss:apm_bios_entry\n\t"
9289 "setc %%al\n\t"
9290 "popl %%ebp\n\t"
9291 "popl %%edi\n\t"
9292@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9293 __asm__ __volatile__(APM_DO_ZERO_SEGS
9294 "pushl %%edi\n\t"
9295 "pushl %%ebp\n\t"
9296- "lcall *%%cs:apm_bios_entry\n\t"
9297+ "lcall *%%ss:apm_bios_entry\n\t"
9298 "setc %%bl\n\t"
9299 "popl %%ebp\n\t"
9300 "popl %%edi\n\t"
9301diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9302index 58cb6d4..ca9010d 100644
9303--- a/arch/x86/include/asm/atomic.h
9304+++ b/arch/x86/include/asm/atomic.h
9305@@ -22,7 +22,18 @@
9306 */
9307 static inline int atomic_read(const atomic_t *v)
9308 {
9309- return (*(volatile int *)&(v)->counter);
9310+ return (*(volatile const int *)&(v)->counter);
9311+}
9312+
9313+/**
9314+ * atomic_read_unchecked - read atomic variable
9315+ * @v: pointer of type atomic_unchecked_t
9316+ *
9317+ * Atomically reads the value of @v.
9318+ */
9319+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9320+{
9321+ return (*(volatile const int *)&(v)->counter);
9322 }
9323
9324 /**
9325@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9326 }
9327
9328 /**
9329+ * atomic_set_unchecked - set atomic variable
9330+ * @v: pointer of type atomic_unchecked_t
9331+ * @i: required value
9332+ *
9333+ * Atomically sets the value of @v to @i.
9334+ */
9335+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9336+{
9337+ v->counter = i;
9338+}
9339+
9340+/**
9341 * atomic_add - add integer to atomic variable
9342 * @i: integer value to add
9343 * @v: pointer of type atomic_t
9344@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9345 */
9346 static inline void atomic_add(int i, atomic_t *v)
9347 {
9348- asm volatile(LOCK_PREFIX "addl %1,%0"
9349+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9350+
9351+#ifdef CONFIG_PAX_REFCOUNT
9352+ "jno 0f\n"
9353+ LOCK_PREFIX "subl %1,%0\n"
9354+ "int $4\n0:\n"
9355+ _ASM_EXTABLE(0b, 0b)
9356+#endif
9357+
9358+ : "+m" (v->counter)
9359+ : "ir" (i));
9360+}
9361+
9362+/**
9363+ * atomic_add_unchecked - add integer to atomic variable
9364+ * @i: integer value to add
9365+ * @v: pointer of type atomic_unchecked_t
9366+ *
9367+ * Atomically adds @i to @v.
9368+ */
9369+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9370+{
9371+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9372 : "+m" (v->counter)
9373 : "ir" (i));
9374 }
9375@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9376 */
9377 static inline void atomic_sub(int i, atomic_t *v)
9378 {
9379- asm volatile(LOCK_PREFIX "subl %1,%0"
9380+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9381+
9382+#ifdef CONFIG_PAX_REFCOUNT
9383+ "jno 0f\n"
9384+ LOCK_PREFIX "addl %1,%0\n"
9385+ "int $4\n0:\n"
9386+ _ASM_EXTABLE(0b, 0b)
9387+#endif
9388+
9389+ : "+m" (v->counter)
9390+ : "ir" (i));
9391+}
9392+
9393+/**
9394+ * atomic_sub_unchecked - subtract integer from atomic variable
9395+ * @i: integer value to subtract
9396+ * @v: pointer of type atomic_unchecked_t
9397+ *
9398+ * Atomically subtracts @i from @v.
9399+ */
9400+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9401+{
9402+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9403 : "+m" (v->counter)
9404 : "ir" (i));
9405 }
9406@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9407 {
9408 unsigned char c;
9409
9410- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9411+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
9412+
9413+#ifdef CONFIG_PAX_REFCOUNT
9414+ "jno 0f\n"
9415+ LOCK_PREFIX "addl %2,%0\n"
9416+ "int $4\n0:\n"
9417+ _ASM_EXTABLE(0b, 0b)
9418+#endif
9419+
9420+ "sete %1\n"
9421 : "+m" (v->counter), "=qm" (c)
9422 : "ir" (i) : "memory");
9423 return c;
9424@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9425 */
9426 static inline void atomic_inc(atomic_t *v)
9427 {
9428- asm volatile(LOCK_PREFIX "incl %0"
9429+ asm volatile(LOCK_PREFIX "incl %0\n"
9430+
9431+#ifdef CONFIG_PAX_REFCOUNT
9432+ "jno 0f\n"
9433+ LOCK_PREFIX "decl %0\n"
9434+ "int $4\n0:\n"
9435+ _ASM_EXTABLE(0b, 0b)
9436+#endif
9437+
9438+ : "+m" (v->counter));
9439+}
9440+
9441+/**
9442+ * atomic_inc_unchecked - increment atomic variable
9443+ * @v: pointer of type atomic_unchecked_t
9444+ *
9445+ * Atomically increments @v by 1.
9446+ */
9447+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9448+{
9449+ asm volatile(LOCK_PREFIX "incl %0\n"
9450 : "+m" (v->counter));
9451 }
9452
9453@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9454 */
9455 static inline void atomic_dec(atomic_t *v)
9456 {
9457- asm volatile(LOCK_PREFIX "decl %0"
9458+ asm volatile(LOCK_PREFIX "decl %0\n"
9459+
9460+#ifdef CONFIG_PAX_REFCOUNT
9461+ "jno 0f\n"
9462+ LOCK_PREFIX "incl %0\n"
9463+ "int $4\n0:\n"
9464+ _ASM_EXTABLE(0b, 0b)
9465+#endif
9466+
9467+ : "+m" (v->counter));
9468+}
9469+
9470+/**
9471+ * atomic_dec_unchecked - decrement atomic variable
9472+ * @v: pointer of type atomic_unchecked_t
9473+ *
9474+ * Atomically decrements @v by 1.
9475+ */
9476+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9477+{
9478+ asm volatile(LOCK_PREFIX "decl %0\n"
9479 : "+m" (v->counter));
9480 }
9481
9482@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9483 {
9484 unsigned char c;
9485
9486- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9487+ asm volatile(LOCK_PREFIX "decl %0\n"
9488+
9489+#ifdef CONFIG_PAX_REFCOUNT
9490+ "jno 0f\n"
9491+ LOCK_PREFIX "incl %0\n"
9492+ "int $4\n0:\n"
9493+ _ASM_EXTABLE(0b, 0b)
9494+#endif
9495+
9496+ "sete %1\n"
9497 : "+m" (v->counter), "=qm" (c)
9498 : : "memory");
9499 return c != 0;
9500@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9501 {
9502 unsigned char c;
9503
9504- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9505+ asm volatile(LOCK_PREFIX "incl %0\n"
9506+
9507+#ifdef CONFIG_PAX_REFCOUNT
9508+ "jno 0f\n"
9509+ LOCK_PREFIX "decl %0\n"
9510+ "int $4\n0:\n"
9511+ _ASM_EXTABLE(0b, 0b)
9512+#endif
9513+
9514+ "sete %1\n"
9515+ : "+m" (v->counter), "=qm" (c)
9516+ : : "memory");
9517+ return c != 0;
9518+}
9519+
9520+/**
9521+ * atomic_inc_and_test_unchecked - increment and test
9522+ * @v: pointer of type atomic_unchecked_t
9523+ *
9524+ * Atomically increments @v by 1
9525+ * and returns true if the result is zero, or false for all
9526+ * other cases.
9527+ */
9528+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9529+{
9530+ unsigned char c;
9531+
9532+ asm volatile(LOCK_PREFIX "incl %0\n"
9533+ "sete %1\n"
9534 : "+m" (v->counter), "=qm" (c)
9535 : : "memory");
9536 return c != 0;
9537@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9538 {
9539 unsigned char c;
9540
9541- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9542+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9543+
9544+#ifdef CONFIG_PAX_REFCOUNT
9545+ "jno 0f\n"
9546+ LOCK_PREFIX "subl %2,%0\n"
9547+ "int $4\n0:\n"
9548+ _ASM_EXTABLE(0b, 0b)
9549+#endif
9550+
9551+ "sets %1\n"
9552 : "+m" (v->counter), "=qm" (c)
9553 : "ir" (i) : "memory");
9554 return c;
9555@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9556 goto no_xadd;
9557 #endif
9558 /* Modern 486+ processor */
9559- return i + xadd(&v->counter, i);
9560+ return i + xadd_check_overflow(&v->counter, i);
9561
9562 #ifdef CONFIG_M386
9563 no_xadd: /* Legacy 386 processor */
9564@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9565 }
9566
9567 /**
9568+ * atomic_add_return_unchecked - add integer and return
9569+ * @i: integer value to add
9570+ * @v: pointer of type atomic_unchecked_t
9571+ *
9572+ * Atomically adds @i to @v and returns @i + @v
9573+ */
9574+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9575+{
9576+#ifdef CONFIG_M386
9577+ int __i;
9578+ unsigned long flags;
9579+ if (unlikely(boot_cpu_data.x86 <= 3))
9580+ goto no_xadd;
9581+#endif
9582+ /* Modern 486+ processor */
9583+ return i + xadd(&v->counter, i);
9584+
9585+#ifdef CONFIG_M386
9586+no_xadd: /* Legacy 386 processor */
9587+ raw_local_irq_save(flags);
9588+ __i = atomic_read_unchecked(v);
9589+ atomic_set_unchecked(v, i + __i);
9590+ raw_local_irq_restore(flags);
9591+ return i + __i;
9592+#endif
9593+}
9594+
9595+/**
9596 * atomic_sub_return - subtract integer and return
9597 * @v: pointer of type atomic_t
9598 * @i: integer value to subtract
9599@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9600 }
9601
9602 #define atomic_inc_return(v) (atomic_add_return(1, v))
9603+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9604+{
9605+ return atomic_add_return_unchecked(1, v);
9606+}
9607 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9608
9609 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9610@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9611 return cmpxchg(&v->counter, old, new);
9612 }
9613
9614+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9615+{
9616+ return cmpxchg(&v->counter, old, new);
9617+}
9618+
9619 static inline int atomic_xchg(atomic_t *v, int new)
9620 {
9621 return xchg(&v->counter, new);
9622 }
9623
9624+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9625+{
9626+ return xchg(&v->counter, new);
9627+}
9628+
9629 /**
9630 * __atomic_add_unless - add unless the number is already a given value
9631 * @v: pointer of type atomic_t
9632@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9633 */
9634 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9635 {
9636- int c, old;
9637+ int c, old, new;
9638 c = atomic_read(v);
9639 for (;;) {
9640- if (unlikely(c == (u)))
9641+ if (unlikely(c == u))
9642 break;
9643- old = atomic_cmpxchg((v), c, c + (a));
9644+
9645+ asm volatile("addl %2,%0\n"
9646+
9647+#ifdef CONFIG_PAX_REFCOUNT
9648+ "jno 0f\n"
9649+ "subl %2,%0\n"
9650+ "int $4\n0:\n"
9651+ _ASM_EXTABLE(0b, 0b)
9652+#endif
9653+
9654+ : "=r" (new)
9655+ : "0" (c), "ir" (a));
9656+
9657+ old = atomic_cmpxchg(v, c, new);
9658 if (likely(old == c))
9659 break;
9660 c = old;
9661@@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9662 return c;
9663 }
9664
9665+/**
9666+ * atomic_inc_not_zero_hint - increment if not null
9667+ * @v: pointer of type atomic_t
9668+ * @hint: probable value of the atomic before the increment
9669+ *
9670+ * This version of atomic_inc_not_zero() gives a hint of probable
9671+ * value of the atomic. This helps processor to not read the memory
9672+ * before doing the atomic read/modify/write cycle, lowering
9673+ * number of bus transactions on some arches.
9674+ *
9675+ * Returns: 0 if increment was not done, 1 otherwise.
9676+ */
9677+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9678+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9679+{
9680+ int val, c = hint, new;
9681+
9682+ /* sanity test, should be removed by compiler if hint is a constant */
9683+ if (!hint)
9684+ return __atomic_add_unless(v, 1, 0);
9685+
9686+ do {
9687+ asm volatile("incl %0\n"
9688+
9689+#ifdef CONFIG_PAX_REFCOUNT
9690+ "jno 0f\n"
9691+ "decl %0\n"
9692+ "int $4\n0:\n"
9693+ _ASM_EXTABLE(0b, 0b)
9694+#endif
9695+
9696+ : "=r" (new)
9697+ : "0" (c));
9698+
9699+ val = atomic_cmpxchg(v, c, new);
9700+ if (val == c)
9701+ return 1;
9702+ c = val;
9703+ } while (c);
9704+
9705+ return 0;
9706+}
9707
9708 /*
9709 * atomic_dec_if_positive - decrement by 1 if old value positive
9710diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9711index fa13f0e..27c2e08 100644
9712--- a/arch/x86/include/asm/atomic64_32.h
9713+++ b/arch/x86/include/asm/atomic64_32.h
9714@@ -12,6 +12,14 @@ typedef struct {
9715 u64 __aligned(8) counter;
9716 } atomic64_t;
9717
9718+#ifdef CONFIG_PAX_REFCOUNT
9719+typedef struct {
9720+ u64 __aligned(8) counter;
9721+} atomic64_unchecked_t;
9722+#else
9723+typedef atomic64_t atomic64_unchecked_t;
9724+#endif
9725+
9726 #define ATOMIC64_INIT(val) { (val) }
9727
9728 #ifdef CONFIG_X86_CMPXCHG64
9729@@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9730 }
9731
9732 /**
9733+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9734+ * @p: pointer to type atomic64_unchecked_t
9735+ * @o: expected value
9736+ * @n: new value
9737+ *
9738+ * Atomically sets @v to @n if it was equal to @o and returns
9739+ * the old value.
9740+ */
9741+
9742+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9743+{
9744+ return cmpxchg64(&v->counter, o, n);
9745+}
9746+
9747+/**
9748 * atomic64_xchg - xchg atomic64 variable
9749 * @v: pointer to type atomic64_t
9750 * @n: value to assign
9751@@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9752 }
9753
9754 /**
9755+ * atomic64_set_unchecked - set atomic64 variable
9756+ * @v: pointer to type atomic64_unchecked_t
9757+ * @n: value to assign
9758+ *
9759+ * Atomically sets the value of @v to @n.
9760+ */
9761+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9762+{
9763+ unsigned high = (unsigned)(i >> 32);
9764+ unsigned low = (unsigned)i;
9765+ asm volatile(ATOMIC64_ALTERNATIVE(set)
9766+ : "+b" (low), "+c" (high)
9767+ : "S" (v)
9768+ : "eax", "edx", "memory"
9769+ );
9770+}
9771+
9772+/**
9773 * atomic64_read - read atomic64 variable
9774 * @v: pointer to type atomic64_t
9775 *
9776@@ -93,6 +134,22 @@ static inline long long atomic64_read(const atomic64_t *v)
9777 }
9778
9779 /**
9780+ * atomic64_read_unchecked - read atomic64 variable
9781+ * @v: pointer to type atomic64_unchecked_t
9782+ *
9783+ * Atomically reads the value of @v and returns it.
9784+ */
9785+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9786+{
9787+ long long r;
9788+ asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
9789+ : "=A" (r), "+c" (v)
9790+ : : "memory"
9791+ );
9792+ return r;
9793+ }
9794+
9795+/**
9796 * atomic64_add_return - add and return
9797 * @i: integer value to add
9798 * @v: pointer to type atomic64_t
9799@@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9800 return i;
9801 }
9802
9803+/**
9804+ * atomic64_add_return_unchecked - add and return
9805+ * @i: integer value to add
9806+ * @v: pointer to type atomic64_unchecked_t
9807+ *
9808+ * Atomically adds @i to @v and returns @i + *@v
9809+ */
9810+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9811+{
9812+ asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
9813+ : "+A" (i), "+c" (v)
9814+ : : "memory"
9815+ );
9816+ return i;
9817+}
9818+
9819 /*
9820 * Other variants with different arithmetic operators:
9821 */
9822@@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9823 return a;
9824 }
9825
9826+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9827+{
9828+ long long a;
9829+ asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
9830+ : "=A" (a)
9831+ : "S" (v)
9832+ : "memory", "ecx"
9833+ );
9834+ return a;
9835+}
9836+
9837 static inline long long atomic64_dec_return(atomic64_t *v)
9838 {
9839 long long a;
9840@@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9841 }
9842
9843 /**
9844+ * atomic64_add_unchecked - add integer to atomic64 variable
9845+ * @i: integer value to add
9846+ * @v: pointer to type atomic64_unchecked_t
9847+ *
9848+ * Atomically adds @i to @v.
9849+ */
9850+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9851+{
9852+ asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
9853+ : "+A" (i), "+c" (v)
9854+ : : "memory"
9855+ );
9856+ return i;
9857+}
9858+
9859+/**
9860 * atomic64_sub - subtract the atomic64 variable
9861 * @i: integer value to subtract
9862 * @v: pointer to type atomic64_t
9863diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9864index 0e1cbfc..5623683 100644
9865--- a/arch/x86/include/asm/atomic64_64.h
9866+++ b/arch/x86/include/asm/atomic64_64.h
9867@@ -18,7 +18,19 @@
9868 */
9869 static inline long atomic64_read(const atomic64_t *v)
9870 {
9871- return (*(volatile long *)&(v)->counter);
9872+ return (*(volatile const long *)&(v)->counter);
9873+}
9874+
9875+/**
9876+ * atomic64_read_unchecked - read atomic64 variable
9877+ * @v: pointer of type atomic64_unchecked_t
9878+ *
9879+ * Atomically reads the value of @v.
9880+ * Doesn't imply a read memory barrier.
9881+ */
9882+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9883+{
9884+ return (*(volatile const long *)&(v)->counter);
9885 }
9886
9887 /**
9888@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9889 }
9890
9891 /**
9892+ * atomic64_set_unchecked - set atomic64 variable
9893+ * @v: pointer to type atomic64_unchecked_t
9894+ * @i: required value
9895+ *
9896+ * Atomically sets the value of @v to @i.
9897+ */
9898+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9899+{
9900+ v->counter = i;
9901+}
9902+
9903+/**
9904 * atomic64_add - add integer to atomic64 variable
9905 * @i: integer value to add
9906 * @v: pointer to type atomic64_t
9907@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9908 */
9909 static inline void atomic64_add(long i, atomic64_t *v)
9910 {
9911+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9912+
9913+#ifdef CONFIG_PAX_REFCOUNT
9914+ "jno 0f\n"
9915+ LOCK_PREFIX "subq %1,%0\n"
9916+ "int $4\n0:\n"
9917+ _ASM_EXTABLE(0b, 0b)
9918+#endif
9919+
9920+ : "=m" (v->counter)
9921+ : "er" (i), "m" (v->counter));
9922+}
9923+
9924+/**
9925+ * atomic64_add_unchecked - add integer to atomic64 variable
9926+ * @i: integer value to add
9927+ * @v: pointer to type atomic64_unchecked_t
9928+ *
9929+ * Atomically adds @i to @v.
9930+ */
9931+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9932+{
9933 asm volatile(LOCK_PREFIX "addq %1,%0"
9934 : "=m" (v->counter)
9935 : "er" (i), "m" (v->counter));
9936@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9937 */
9938 static inline void atomic64_sub(long i, atomic64_t *v)
9939 {
9940- asm volatile(LOCK_PREFIX "subq %1,%0"
9941+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9942+
9943+#ifdef CONFIG_PAX_REFCOUNT
9944+ "jno 0f\n"
9945+ LOCK_PREFIX "addq %1,%0\n"
9946+ "int $4\n0:\n"
9947+ _ASM_EXTABLE(0b, 0b)
9948+#endif
9949+
9950+ : "=m" (v->counter)
9951+ : "er" (i), "m" (v->counter));
9952+}
9953+
9954+/**
9955+ * atomic64_sub_unchecked - subtract the atomic64 variable
9956+ * @i: integer value to subtract
9957+ * @v: pointer to type atomic64_unchecked_t
9958+ *
9959+ * Atomically subtracts @i from @v.
9960+ */
9961+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9962+{
9963+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9964 : "=m" (v->counter)
9965 : "er" (i), "m" (v->counter));
9966 }
9967@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9968 {
9969 unsigned char c;
9970
9971- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9972+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9973+
9974+#ifdef CONFIG_PAX_REFCOUNT
9975+ "jno 0f\n"
9976+ LOCK_PREFIX "addq %2,%0\n"
9977+ "int $4\n0:\n"
9978+ _ASM_EXTABLE(0b, 0b)
9979+#endif
9980+
9981+ "sete %1\n"
9982 : "=m" (v->counter), "=qm" (c)
9983 : "er" (i), "m" (v->counter) : "memory");
9984 return c;
9985@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9986 */
9987 static inline void atomic64_inc(atomic64_t *v)
9988 {
9989+ asm volatile(LOCK_PREFIX "incq %0\n"
9990+
9991+#ifdef CONFIG_PAX_REFCOUNT
9992+ "jno 0f\n"
9993+ LOCK_PREFIX "decq %0\n"
9994+ "int $4\n0:\n"
9995+ _ASM_EXTABLE(0b, 0b)
9996+#endif
9997+
9998+ : "=m" (v->counter)
9999+ : "m" (v->counter));
10000+}
10001+
10002+/**
10003+ * atomic64_inc_unchecked - increment atomic64 variable
10004+ * @v: pointer to type atomic64_unchecked_t
10005+ *
10006+ * Atomically increments @v by 1.
10007+ */
10008+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10009+{
10010 asm volatile(LOCK_PREFIX "incq %0"
10011 : "=m" (v->counter)
10012 : "m" (v->counter));
10013@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
10014 */
10015 static inline void atomic64_dec(atomic64_t *v)
10016 {
10017- asm volatile(LOCK_PREFIX "decq %0"
10018+ asm volatile(LOCK_PREFIX "decq %0\n"
10019+
10020+#ifdef CONFIG_PAX_REFCOUNT
10021+ "jno 0f\n"
10022+ LOCK_PREFIX "incq %0\n"
10023+ "int $4\n0:\n"
10024+ _ASM_EXTABLE(0b, 0b)
10025+#endif
10026+
10027+ : "=m" (v->counter)
10028+ : "m" (v->counter));
10029+}
10030+
10031+/**
10032+ * atomic64_dec_unchecked - decrement atomic64 variable
10033+ * @v: pointer to type atomic64_t
10034+ *
10035+ * Atomically decrements @v by 1.
10036+ */
10037+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10038+{
10039+ asm volatile(LOCK_PREFIX "decq %0\n"
10040 : "=m" (v->counter)
10041 : "m" (v->counter));
10042 }
10043@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
10044 {
10045 unsigned char c;
10046
10047- asm volatile(LOCK_PREFIX "decq %0; sete %1"
10048+ asm volatile(LOCK_PREFIX "decq %0\n"
10049+
10050+#ifdef CONFIG_PAX_REFCOUNT
10051+ "jno 0f\n"
10052+ LOCK_PREFIX "incq %0\n"
10053+ "int $4\n0:\n"
10054+ _ASM_EXTABLE(0b, 0b)
10055+#endif
10056+
10057+ "sete %1\n"
10058 : "=m" (v->counter), "=qm" (c)
10059 : "m" (v->counter) : "memory");
10060 return c != 0;
10061@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
10062 {
10063 unsigned char c;
10064
10065- asm volatile(LOCK_PREFIX "incq %0; sete %1"
10066+ asm volatile(LOCK_PREFIX "incq %0\n"
10067+
10068+#ifdef CONFIG_PAX_REFCOUNT
10069+ "jno 0f\n"
10070+ LOCK_PREFIX "decq %0\n"
10071+ "int $4\n0:\n"
10072+ _ASM_EXTABLE(0b, 0b)
10073+#endif
10074+
10075+ "sete %1\n"
10076 : "=m" (v->counter), "=qm" (c)
10077 : "m" (v->counter) : "memory");
10078 return c != 0;
10079@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10080 {
10081 unsigned char c;
10082
10083- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
10084+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
10085+
10086+#ifdef CONFIG_PAX_REFCOUNT
10087+ "jno 0f\n"
10088+ LOCK_PREFIX "subq %2,%0\n"
10089+ "int $4\n0:\n"
10090+ _ASM_EXTABLE(0b, 0b)
10091+#endif
10092+
10093+ "sets %1\n"
10094 : "=m" (v->counter), "=qm" (c)
10095 : "er" (i), "m" (v->counter) : "memory");
10096 return c;
10097@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10098 */
10099 static inline long atomic64_add_return(long i, atomic64_t *v)
10100 {
10101+ return i + xadd_check_overflow(&v->counter, i);
10102+}
10103+
10104+/**
10105+ * atomic64_add_return_unchecked - add and return
10106+ * @i: integer value to add
10107+ * @v: pointer to type atomic64_unchecked_t
10108+ *
10109+ * Atomically adds @i to @v and returns @i + @v
10110+ */
10111+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10112+{
10113 return i + xadd(&v->counter, i);
10114 }
10115
10116@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10117 }
10118
10119 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10120+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10121+{
10122+ return atomic64_add_return_unchecked(1, v);
10123+}
10124 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10125
10126 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10127@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10128 return cmpxchg(&v->counter, old, new);
10129 }
10130
10131+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10132+{
10133+ return cmpxchg(&v->counter, old, new);
10134+}
10135+
10136 static inline long atomic64_xchg(atomic64_t *v, long new)
10137 {
10138 return xchg(&v->counter, new);
10139@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10140 */
10141 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10142 {
10143- long c, old;
10144+ long c, old, new;
10145 c = atomic64_read(v);
10146 for (;;) {
10147- if (unlikely(c == (u)))
10148+ if (unlikely(c == u))
10149 break;
10150- old = atomic64_cmpxchg((v), c, c + (a));
10151+
10152+ asm volatile("add %2,%0\n"
10153+
10154+#ifdef CONFIG_PAX_REFCOUNT
10155+ "jno 0f\n"
10156+ "sub %2,%0\n"
10157+ "int $4\n0:\n"
10158+ _ASM_EXTABLE(0b, 0b)
10159+#endif
10160+
10161+ : "=r" (new)
10162+ : "0" (c), "ir" (a));
10163+
10164+ old = atomic64_cmpxchg(v, c, new);
10165 if (likely(old == c))
10166 break;
10167 c = old;
10168 }
10169- return c != (u);
10170+ return c != u;
10171 }
10172
10173 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10174diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10175index b97596e..9bd48b06 100644
10176--- a/arch/x86/include/asm/bitops.h
10177+++ b/arch/x86/include/asm/bitops.h
10178@@ -38,7 +38,7 @@
10179 * a mask operation on a byte.
10180 */
10181 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10182-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10183+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10184 #define CONST_MASK(nr) (1 << ((nr) & 7))
10185
10186 /**
10187diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10188index 5e1a2ee..c9f9533 100644
10189--- a/arch/x86/include/asm/boot.h
10190+++ b/arch/x86/include/asm/boot.h
10191@@ -11,10 +11,15 @@
10192 #include <asm/pgtable_types.h>
10193
10194 /* Physical address where kernel should be loaded. */
10195-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10196+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10197 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10198 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10199
10200+#ifndef __ASSEMBLY__
10201+extern unsigned char __LOAD_PHYSICAL_ADDR[];
10202+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10203+#endif
10204+
10205 /* Minimum kernel alignment, as a power of two */
10206 #ifdef CONFIG_X86_64
10207 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10208diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10209index 48f99f1..d78ebf9 100644
10210--- a/arch/x86/include/asm/cache.h
10211+++ b/arch/x86/include/asm/cache.h
10212@@ -5,12 +5,13 @@
10213
10214 /* L1 cache line size */
10215 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10216-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10217+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10218
10219 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10220+#define __read_only __attribute__((__section__(".data..read_only")))
10221
10222 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10223-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10224+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10225
10226 #ifdef CONFIG_X86_VSMP
10227 #ifdef CONFIG_SMP
10228diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10229index 4e12668..501d239 100644
10230--- a/arch/x86/include/asm/cacheflush.h
10231+++ b/arch/x86/include/asm/cacheflush.h
10232@@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10233 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10234
10235 if (pg_flags == _PGMT_DEFAULT)
10236- return -1;
10237+ return ~0UL;
10238 else if (pg_flags == _PGMT_WC)
10239 return _PAGE_CACHE_WC;
10240 else if (pg_flags == _PGMT_UC_MINUS)
10241diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10242index 46fc474..b02b0f9 100644
10243--- a/arch/x86/include/asm/checksum_32.h
10244+++ b/arch/x86/include/asm/checksum_32.h
10245@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10246 int len, __wsum sum,
10247 int *src_err_ptr, int *dst_err_ptr);
10248
10249+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10250+ int len, __wsum sum,
10251+ int *src_err_ptr, int *dst_err_ptr);
10252+
10253+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10254+ int len, __wsum sum,
10255+ int *src_err_ptr, int *dst_err_ptr);
10256+
10257 /*
10258 * Note: when you get a NULL pointer exception here this means someone
10259 * passed in an incorrect kernel address to one of these functions.
10260@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10261 int *err_ptr)
10262 {
10263 might_sleep();
10264- return csum_partial_copy_generic((__force void *)src, dst,
10265+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
10266 len, sum, err_ptr, NULL);
10267 }
10268
10269@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10270 {
10271 might_sleep();
10272 if (access_ok(VERIFY_WRITE, dst, len))
10273- return csum_partial_copy_generic(src, (__force void *)dst,
10274+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10275 len, sum, NULL, err_ptr);
10276
10277 if (len)
10278diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10279index 99480e5..d81165b 100644
10280--- a/arch/x86/include/asm/cmpxchg.h
10281+++ b/arch/x86/include/asm/cmpxchg.h
10282@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10283 __compiletime_error("Bad argument size for cmpxchg");
10284 extern void __xadd_wrong_size(void)
10285 __compiletime_error("Bad argument size for xadd");
10286+extern void __xadd_check_overflow_wrong_size(void)
10287+ __compiletime_error("Bad argument size for xadd_check_overflow");
10288 extern void __add_wrong_size(void)
10289 __compiletime_error("Bad argument size for add");
10290+extern void __add_check_overflow_wrong_size(void)
10291+ __compiletime_error("Bad argument size for add_check_overflow");
10292
10293 /*
10294 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10295@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10296 __ret; \
10297 })
10298
10299+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10300+ ({ \
10301+ __typeof__ (*(ptr)) __ret = (arg); \
10302+ switch (sizeof(*(ptr))) { \
10303+ case __X86_CASE_L: \
10304+ asm volatile (lock #op "l %0, %1\n" \
10305+ "jno 0f\n" \
10306+ "mov %0,%1\n" \
10307+ "int $4\n0:\n" \
10308+ _ASM_EXTABLE(0b, 0b) \
10309+ : "+r" (__ret), "+m" (*(ptr)) \
10310+ : : "memory", "cc"); \
10311+ break; \
10312+ case __X86_CASE_Q: \
10313+ asm volatile (lock #op "q %q0, %1\n" \
10314+ "jno 0f\n" \
10315+ "mov %0,%1\n" \
10316+ "int $4\n0:\n" \
10317+ _ASM_EXTABLE(0b, 0b) \
10318+ : "+r" (__ret), "+m" (*(ptr)) \
10319+ : : "memory", "cc"); \
10320+ break; \
10321+ default: \
10322+ __ ## op ## _check_overflow_wrong_size(); \
10323+ } \
10324+ __ret; \
10325+ })
10326+
10327 /*
10328 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10329 * Since this is generally used to protect other memory information, we
10330@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10331 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10332 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10333
10334+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10335+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10336+
10337 #define __add(ptr, inc, lock) \
10338 ({ \
10339 __typeof__ (*(ptr)) __ret = (inc); \
10340diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10341index 8d67d42..183d0eb 100644
10342--- a/arch/x86/include/asm/cpufeature.h
10343+++ b/arch/x86/include/asm/cpufeature.h
10344@@ -367,7 +367,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10345 ".section .discard,\"aw\",@progbits\n"
10346 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10347 ".previous\n"
10348- ".section .altinstr_replacement,\"ax\"\n"
10349+ ".section .altinstr_replacement,\"a\"\n"
10350 "3: movb $1,%0\n"
10351 "4:\n"
10352 ".previous\n"
10353diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10354index e95822d..a90010e 100644
10355--- a/arch/x86/include/asm/desc.h
10356+++ b/arch/x86/include/asm/desc.h
10357@@ -4,6 +4,7 @@
10358 #include <asm/desc_defs.h>
10359 #include <asm/ldt.h>
10360 #include <asm/mmu.h>
10361+#include <asm/pgtable.h>
10362
10363 #include <linux/smp.h>
10364
10365@@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10366
10367 desc->type = (info->read_exec_only ^ 1) << 1;
10368 desc->type |= info->contents << 2;
10369+ desc->type |= info->seg_not_present ^ 1;
10370
10371 desc->s = 1;
10372 desc->dpl = 0x3;
10373@@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10374 }
10375
10376 extern struct desc_ptr idt_descr;
10377-extern gate_desc idt_table[];
10378 extern struct desc_ptr nmi_idt_descr;
10379-extern gate_desc nmi_idt_table[];
10380-
10381-struct gdt_page {
10382- struct desc_struct gdt[GDT_ENTRIES];
10383-} __attribute__((aligned(PAGE_SIZE)));
10384-
10385-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10386+extern gate_desc idt_table[256];
10387+extern gate_desc nmi_idt_table[256];
10388
10389+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10390 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10391 {
10392- return per_cpu(gdt_page, cpu).gdt;
10393+ return cpu_gdt_table[cpu];
10394 }
10395
10396 #ifdef CONFIG_X86_64
10397@@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10398 unsigned long base, unsigned dpl, unsigned flags,
10399 unsigned short seg)
10400 {
10401- gate->a = (seg << 16) | (base & 0xffff);
10402- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10403+ gate->gate.offset_low = base;
10404+ gate->gate.seg = seg;
10405+ gate->gate.reserved = 0;
10406+ gate->gate.type = type;
10407+ gate->gate.s = 0;
10408+ gate->gate.dpl = dpl;
10409+ gate->gate.p = 1;
10410+ gate->gate.offset_high = base >> 16;
10411 }
10412
10413 #endif
10414@@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10415
10416 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10417 {
10418+ pax_open_kernel();
10419 memcpy(&idt[entry], gate, sizeof(*gate));
10420+ pax_close_kernel();
10421 }
10422
10423 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10424 {
10425+ pax_open_kernel();
10426 memcpy(&ldt[entry], desc, 8);
10427+ pax_close_kernel();
10428 }
10429
10430 static inline void
10431@@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10432 default: size = sizeof(*gdt); break;
10433 }
10434
10435+ pax_open_kernel();
10436 memcpy(&gdt[entry], desc, size);
10437+ pax_close_kernel();
10438 }
10439
10440 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10441@@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10442
10443 static inline void native_load_tr_desc(void)
10444 {
10445+ pax_open_kernel();
10446 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10447+ pax_close_kernel();
10448 }
10449
10450 static inline void native_load_gdt(const struct desc_ptr *dtr)
10451@@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10452 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10453 unsigned int i;
10454
10455+ pax_open_kernel();
10456 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10457 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10458+ pax_close_kernel();
10459 }
10460
10461 #define _LDT_empty(info) \
10462@@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10463 }
10464
10465 #ifdef CONFIG_X86_64
10466-static inline void set_nmi_gate(int gate, void *addr)
10467+static inline void set_nmi_gate(int gate, const void *addr)
10468 {
10469 gate_desc s;
10470
10471@@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10472 }
10473 #endif
10474
10475-static inline void _set_gate(int gate, unsigned type, void *addr,
10476+static inline void _set_gate(int gate, unsigned type, const void *addr,
10477 unsigned dpl, unsigned ist, unsigned seg)
10478 {
10479 gate_desc s;
10480@@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10481 * Pentium F0 0F bugfix can have resulted in the mapped
10482 * IDT being write-protected.
10483 */
10484-static inline void set_intr_gate(unsigned int n, void *addr)
10485+static inline void set_intr_gate(unsigned int n, const void *addr)
10486 {
10487 BUG_ON((unsigned)n > 0xFF);
10488 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10489@@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10490 /*
10491 * This routine sets up an interrupt gate at directory privilege level 3.
10492 */
10493-static inline void set_system_intr_gate(unsigned int n, void *addr)
10494+static inline void set_system_intr_gate(unsigned int n, const void *addr)
10495 {
10496 BUG_ON((unsigned)n > 0xFF);
10497 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10498 }
10499
10500-static inline void set_system_trap_gate(unsigned int n, void *addr)
10501+static inline void set_system_trap_gate(unsigned int n, const void *addr)
10502 {
10503 BUG_ON((unsigned)n > 0xFF);
10504 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10505 }
10506
10507-static inline void set_trap_gate(unsigned int n, void *addr)
10508+static inline void set_trap_gate(unsigned int n, const void *addr)
10509 {
10510 BUG_ON((unsigned)n > 0xFF);
10511 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10512@@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10513 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10514 {
10515 BUG_ON((unsigned)n > 0xFF);
10516- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10517+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10518 }
10519
10520-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10521+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10522 {
10523 BUG_ON((unsigned)n > 0xFF);
10524 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10525 }
10526
10527-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10528+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10529 {
10530 BUG_ON((unsigned)n > 0xFF);
10531 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10532 }
10533
10534+#ifdef CONFIG_X86_32
10535+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10536+{
10537+ struct desc_struct d;
10538+
10539+ if (likely(limit))
10540+ limit = (limit - 1UL) >> PAGE_SHIFT;
10541+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
10542+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10543+}
10544+#endif
10545+
10546 #endif /* _ASM_X86_DESC_H */
10547diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10548index 278441f..b95a174 100644
10549--- a/arch/x86/include/asm/desc_defs.h
10550+++ b/arch/x86/include/asm/desc_defs.h
10551@@ -31,6 +31,12 @@ struct desc_struct {
10552 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10553 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10554 };
10555+ struct {
10556+ u16 offset_low;
10557+ u16 seg;
10558+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10559+ unsigned offset_high: 16;
10560+ } gate;
10561 };
10562 } __attribute__((packed));
10563
10564diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10565index 3778256..c5d4fce 100644
10566--- a/arch/x86/include/asm/e820.h
10567+++ b/arch/x86/include/asm/e820.h
10568@@ -69,7 +69,7 @@ struct e820map {
10569 #define ISA_START_ADDRESS 0xa0000
10570 #define ISA_END_ADDRESS 0x100000
10571
10572-#define BIOS_BEGIN 0x000a0000
10573+#define BIOS_BEGIN 0x000c0000
10574 #define BIOS_END 0x00100000
10575
10576 #define BIOS_ROM_BASE 0xffe00000
10577diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10578index 5f962df..7289f09 100644
10579--- a/arch/x86/include/asm/elf.h
10580+++ b/arch/x86/include/asm/elf.h
10581@@ -238,7 +238,25 @@ extern int force_personality32;
10582 the loader. We need to make sure that it is out of the way of the program
10583 that it will "exec", and that there is sufficient room for the brk. */
10584
10585+#ifdef CONFIG_PAX_SEGMEXEC
10586+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10587+#else
10588 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10589+#endif
10590+
10591+#ifdef CONFIG_PAX_ASLR
10592+#ifdef CONFIG_X86_32
10593+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10594+
10595+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10596+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10597+#else
10598+#define PAX_ELF_ET_DYN_BASE 0x400000UL
10599+
10600+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10601+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10602+#endif
10603+#endif
10604
10605 /* This yields a mask that user programs can use to figure out what
10606 instruction set this CPU supports. This could be done in user space,
10607@@ -291,9 +309,7 @@ do { \
10608
10609 #define ARCH_DLINFO \
10610 do { \
10611- if (vdso_enabled) \
10612- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10613- (unsigned long)current->mm->context.vdso); \
10614+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10615 } while (0)
10616
10617 #define AT_SYSINFO 32
10618@@ -304,7 +320,7 @@ do { \
10619
10620 #endif /* !CONFIG_X86_32 */
10621
10622-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10623+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10624
10625 #define VDSO_ENTRY \
10626 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10627@@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
10628 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10629 #define compat_arch_setup_additional_pages syscall32_setup_pages
10630
10631-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10632-#define arch_randomize_brk arch_randomize_brk
10633-
10634 /*
10635 * True on X86_32 or when emulating IA32 on X86_64
10636 */
10637diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10638index cc70c1c..d96d011 100644
10639--- a/arch/x86/include/asm/emergency-restart.h
10640+++ b/arch/x86/include/asm/emergency-restart.h
10641@@ -15,6 +15,6 @@ enum reboot_type {
10642
10643 extern enum reboot_type reboot_type;
10644
10645-extern void machine_emergency_restart(void);
10646+extern void machine_emergency_restart(void) __noreturn;
10647
10648 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10649diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10650index d09bb03..4ea4194 100644
10651--- a/arch/x86/include/asm/futex.h
10652+++ b/arch/x86/include/asm/futex.h
10653@@ -12,16 +12,18 @@
10654 #include <asm/system.h>
10655
10656 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10657+ typecheck(u32 __user *, uaddr); \
10658 asm volatile("1:\t" insn "\n" \
10659 "2:\t.section .fixup,\"ax\"\n" \
10660 "3:\tmov\t%3, %1\n" \
10661 "\tjmp\t2b\n" \
10662 "\t.previous\n" \
10663 _ASM_EXTABLE(1b, 3b) \
10664- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10665+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10666 : "i" (-EFAULT), "0" (oparg), "1" (0))
10667
10668 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10669+ typecheck(u32 __user *, uaddr); \
10670 asm volatile("1:\tmovl %2, %0\n" \
10671 "\tmovl\t%0, %3\n" \
10672 "\t" insn "\n" \
10673@@ -34,7 +36,7 @@
10674 _ASM_EXTABLE(1b, 4b) \
10675 _ASM_EXTABLE(2b, 4b) \
10676 : "=&a" (oldval), "=&r" (ret), \
10677- "+m" (*uaddr), "=&r" (tem) \
10678+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10679 : "r" (oparg), "i" (-EFAULT), "1" (0))
10680
10681 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10682@@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10683
10684 switch (op) {
10685 case FUTEX_OP_SET:
10686- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10687+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10688 break;
10689 case FUTEX_OP_ADD:
10690- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10691+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10692 uaddr, oparg);
10693 break;
10694 case FUTEX_OP_OR:
10695@@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10696 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10697 return -EFAULT;
10698
10699- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10700+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10701 "2:\t.section .fixup, \"ax\"\n"
10702 "3:\tmov %3, %0\n"
10703 "\tjmp 2b\n"
10704 "\t.previous\n"
10705 _ASM_EXTABLE(1b, 3b)
10706- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10707+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10708 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10709 : "memory"
10710 );
10711diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10712index eb92a6e..b98b2f4 100644
10713--- a/arch/x86/include/asm/hw_irq.h
10714+++ b/arch/x86/include/asm/hw_irq.h
10715@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10716 extern void enable_IO_APIC(void);
10717
10718 /* Statistics */
10719-extern atomic_t irq_err_count;
10720-extern atomic_t irq_mis_count;
10721+extern atomic_unchecked_t irq_err_count;
10722+extern atomic_unchecked_t irq_mis_count;
10723
10724 /* EISA */
10725 extern void eisa_set_level_irq(unsigned int irq);
10726diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10727index 2479049..3fb9795 100644
10728--- a/arch/x86/include/asm/i387.h
10729+++ b/arch/x86/include/asm/i387.h
10730@@ -93,6 +93,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10731 {
10732 int err;
10733
10734+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10735+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10736+ fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10737+#endif
10738+
10739 /* See comment in fxsave() below. */
10740 #ifdef CONFIG_AS_FXSAVEQ
10741 asm volatile("1: fxrstorq %[fx]\n\t"
10742@@ -122,6 +127,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10743 {
10744 int err;
10745
10746+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10747+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10748+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10749+#endif
10750+
10751 /*
10752 * Clear the bytes not touched by the fxsave and reserved
10753 * for the SW usage.
10754@@ -278,7 +288,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10755 "emms\n\t" /* clear stack tags */
10756 "fildl %P[addr]", /* set F?P to defined value */
10757 X86_FEATURE_FXSAVE_LEAK,
10758- [addr] "m" (tsk->thread.fpu.has_fpu));
10759+ [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10760
10761 return fpu_restore_checking(&tsk->thread.fpu);
10762 }
10763@@ -445,7 +455,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
10764 static inline bool interrupted_user_mode(void)
10765 {
10766 struct pt_regs *regs = get_irq_regs();
10767- return regs && user_mode_vm(regs);
10768+ return regs && user_mode(regs);
10769 }
10770
10771 /*
10772diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10773index d8e8eef..99f81ae 100644
10774--- a/arch/x86/include/asm/io.h
10775+++ b/arch/x86/include/asm/io.h
10776@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10777
10778 #include <linux/vmalloc.h>
10779
10780+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10781+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10782+{
10783+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10784+}
10785+
10786+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10787+{
10788+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10789+}
10790+
10791 /*
10792 * Convert a virtual cached pointer to an uncached pointer
10793 */
10794diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10795index bba3cf8..06bc8da 100644
10796--- a/arch/x86/include/asm/irqflags.h
10797+++ b/arch/x86/include/asm/irqflags.h
10798@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10799 sti; \
10800 sysexit
10801
10802+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10803+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10804+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10805+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10806+
10807 #else
10808 #define INTERRUPT_RETURN iret
10809 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10810diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10811index 5478825..839e88c 100644
10812--- a/arch/x86/include/asm/kprobes.h
10813+++ b/arch/x86/include/asm/kprobes.h
10814@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10815 #define RELATIVEJUMP_SIZE 5
10816 #define RELATIVECALL_OPCODE 0xe8
10817 #define RELATIVE_ADDR_SIZE 4
10818-#define MAX_STACK_SIZE 64
10819-#define MIN_STACK_SIZE(ADDR) \
10820- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10821- THREAD_SIZE - (unsigned long)(ADDR))) \
10822- ? (MAX_STACK_SIZE) \
10823- : (((unsigned long)current_thread_info()) + \
10824- THREAD_SIZE - (unsigned long)(ADDR)))
10825+#define MAX_STACK_SIZE 64UL
10826+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10827
10828 #define flush_insn_slot(p) do { } while (0)
10829
10830diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10831index 52d6640..a013b87 100644
10832--- a/arch/x86/include/asm/kvm_host.h
10833+++ b/arch/x86/include/asm/kvm_host.h
10834@@ -663,7 +663,7 @@ struct kvm_x86_ops {
10835 int (*check_intercept)(struct kvm_vcpu *vcpu,
10836 struct x86_instruction_info *info,
10837 enum x86_intercept_stage stage);
10838-};
10839+} __do_const;
10840
10841 struct kvm_arch_async_pf {
10842 u32 token;
10843diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10844index 9cdae5d..300d20f 100644
10845--- a/arch/x86/include/asm/local.h
10846+++ b/arch/x86/include/asm/local.h
10847@@ -18,26 +18,58 @@ typedef struct {
10848
10849 static inline void local_inc(local_t *l)
10850 {
10851- asm volatile(_ASM_INC "%0"
10852+ asm volatile(_ASM_INC "%0\n"
10853+
10854+#ifdef CONFIG_PAX_REFCOUNT
10855+ "jno 0f\n"
10856+ _ASM_DEC "%0\n"
10857+ "int $4\n0:\n"
10858+ _ASM_EXTABLE(0b, 0b)
10859+#endif
10860+
10861 : "+m" (l->a.counter));
10862 }
10863
10864 static inline void local_dec(local_t *l)
10865 {
10866- asm volatile(_ASM_DEC "%0"
10867+ asm volatile(_ASM_DEC "%0\n"
10868+
10869+#ifdef CONFIG_PAX_REFCOUNT
10870+ "jno 0f\n"
10871+ _ASM_INC "%0\n"
10872+ "int $4\n0:\n"
10873+ _ASM_EXTABLE(0b, 0b)
10874+#endif
10875+
10876 : "+m" (l->a.counter));
10877 }
10878
10879 static inline void local_add(long i, local_t *l)
10880 {
10881- asm volatile(_ASM_ADD "%1,%0"
10882+ asm volatile(_ASM_ADD "%1,%0\n"
10883+
10884+#ifdef CONFIG_PAX_REFCOUNT
10885+ "jno 0f\n"
10886+ _ASM_SUB "%1,%0\n"
10887+ "int $4\n0:\n"
10888+ _ASM_EXTABLE(0b, 0b)
10889+#endif
10890+
10891 : "+m" (l->a.counter)
10892 : "ir" (i));
10893 }
10894
10895 static inline void local_sub(long i, local_t *l)
10896 {
10897- asm volatile(_ASM_SUB "%1,%0"
10898+ asm volatile(_ASM_SUB "%1,%0\n"
10899+
10900+#ifdef CONFIG_PAX_REFCOUNT
10901+ "jno 0f\n"
10902+ _ASM_ADD "%1,%0\n"
10903+ "int $4\n0:\n"
10904+ _ASM_EXTABLE(0b, 0b)
10905+#endif
10906+
10907 : "+m" (l->a.counter)
10908 : "ir" (i));
10909 }
10910@@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10911 {
10912 unsigned char c;
10913
10914- asm volatile(_ASM_SUB "%2,%0; sete %1"
10915+ asm volatile(_ASM_SUB "%2,%0\n"
10916+
10917+#ifdef CONFIG_PAX_REFCOUNT
10918+ "jno 0f\n"
10919+ _ASM_ADD "%2,%0\n"
10920+ "int $4\n0:\n"
10921+ _ASM_EXTABLE(0b, 0b)
10922+#endif
10923+
10924+ "sete %1\n"
10925 : "+m" (l->a.counter), "=qm" (c)
10926 : "ir" (i) : "memory");
10927 return c;
10928@@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10929 {
10930 unsigned char c;
10931
10932- asm volatile(_ASM_DEC "%0; sete %1"
10933+ asm volatile(_ASM_DEC "%0\n"
10934+
10935+#ifdef CONFIG_PAX_REFCOUNT
10936+ "jno 0f\n"
10937+ _ASM_INC "%0\n"
10938+ "int $4\n0:\n"
10939+ _ASM_EXTABLE(0b, 0b)
10940+#endif
10941+
10942+ "sete %1\n"
10943 : "+m" (l->a.counter), "=qm" (c)
10944 : : "memory");
10945 return c != 0;
10946@@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10947 {
10948 unsigned char c;
10949
10950- asm volatile(_ASM_INC "%0; sete %1"
10951+ asm volatile(_ASM_INC "%0\n"
10952+
10953+#ifdef CONFIG_PAX_REFCOUNT
10954+ "jno 0f\n"
10955+ _ASM_DEC "%0\n"
10956+ "int $4\n0:\n"
10957+ _ASM_EXTABLE(0b, 0b)
10958+#endif
10959+
10960+ "sete %1\n"
10961 : "+m" (l->a.counter), "=qm" (c)
10962 : : "memory");
10963 return c != 0;
10964@@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10965 {
10966 unsigned char c;
10967
10968- asm volatile(_ASM_ADD "%2,%0; sets %1"
10969+ asm volatile(_ASM_ADD "%2,%0\n"
10970+
10971+#ifdef CONFIG_PAX_REFCOUNT
10972+ "jno 0f\n"
10973+ _ASM_SUB "%2,%0\n"
10974+ "int $4\n0:\n"
10975+ _ASM_EXTABLE(0b, 0b)
10976+#endif
10977+
10978+ "sets %1\n"
10979 : "+m" (l->a.counter), "=qm" (c)
10980 : "ir" (i) : "memory");
10981 return c;
10982@@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10983 #endif
10984 /* Modern 486+ processor */
10985 __i = i;
10986- asm volatile(_ASM_XADD "%0, %1;"
10987+ asm volatile(_ASM_XADD "%0, %1\n"
10988+
10989+#ifdef CONFIG_PAX_REFCOUNT
10990+ "jno 0f\n"
10991+ _ASM_MOV "%0,%1\n"
10992+ "int $4\n0:\n"
10993+ _ASM_EXTABLE(0b, 0b)
10994+#endif
10995+
10996 : "+r" (i), "+m" (l->a.counter)
10997 : : "memory");
10998 return i + __i;
10999diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
11000index 593e51d..fa69c9a 100644
11001--- a/arch/x86/include/asm/mman.h
11002+++ b/arch/x86/include/asm/mman.h
11003@@ -5,4 +5,14 @@
11004
11005 #include <asm-generic/mman.h>
11006
11007+#ifdef __KERNEL__
11008+#ifndef __ASSEMBLY__
11009+#ifdef CONFIG_X86_32
11010+#define arch_mmap_check i386_mmap_check
11011+int i386_mmap_check(unsigned long addr, unsigned long len,
11012+ unsigned long flags);
11013+#endif
11014+#endif
11015+#endif
11016+
11017 #endif /* _ASM_X86_MMAN_H */
11018diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
11019index 5f55e69..e20bfb1 100644
11020--- a/arch/x86/include/asm/mmu.h
11021+++ b/arch/x86/include/asm/mmu.h
11022@@ -9,7 +9,7 @@
11023 * we put the segment information here.
11024 */
11025 typedef struct {
11026- void *ldt;
11027+ struct desc_struct *ldt;
11028 int size;
11029
11030 #ifdef CONFIG_X86_64
11031@@ -18,7 +18,19 @@ typedef struct {
11032 #endif
11033
11034 struct mutex lock;
11035- void *vdso;
11036+ unsigned long vdso;
11037+
11038+#ifdef CONFIG_X86_32
11039+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
11040+ unsigned long user_cs_base;
11041+ unsigned long user_cs_limit;
11042+
11043+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11044+ cpumask_t cpu_user_cs_mask;
11045+#endif
11046+
11047+#endif
11048+#endif
11049 } mm_context_t;
11050
11051 #ifdef CONFIG_SMP
11052diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
11053index 6902152..da4283a 100644
11054--- a/arch/x86/include/asm/mmu_context.h
11055+++ b/arch/x86/include/asm/mmu_context.h
11056@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
11057
11058 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
11059 {
11060+
11061+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11062+ unsigned int i;
11063+ pgd_t *pgd;
11064+
11065+ pax_open_kernel();
11066+ pgd = get_cpu_pgd(smp_processor_id());
11067+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
11068+ set_pgd_batched(pgd+i, native_make_pgd(0));
11069+ pax_close_kernel();
11070+#endif
11071+
11072 #ifdef CONFIG_SMP
11073 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
11074 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
11075@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11076 struct task_struct *tsk)
11077 {
11078 unsigned cpu = smp_processor_id();
11079+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11080+ int tlbstate = TLBSTATE_OK;
11081+#endif
11082
11083 if (likely(prev != next)) {
11084 #ifdef CONFIG_SMP
11085+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11086+ tlbstate = percpu_read(cpu_tlbstate.state);
11087+#endif
11088 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11089 percpu_write(cpu_tlbstate.active_mm, next);
11090 #endif
11091 cpumask_set_cpu(cpu, mm_cpumask(next));
11092
11093 /* Re-load page tables */
11094+#ifdef CONFIG_PAX_PER_CPU_PGD
11095+ pax_open_kernel();
11096+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11097+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11098+ pax_close_kernel();
11099+ load_cr3(get_cpu_pgd(cpu));
11100+#else
11101 load_cr3(next->pgd);
11102+#endif
11103
11104 /* stop flush ipis for the previous mm */
11105 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11106@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11107 */
11108 if (unlikely(prev->context.ldt != next->context.ldt))
11109 load_LDT_nolock(&next->context);
11110- }
11111+
11112+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11113+ if (!(__supported_pte_mask & _PAGE_NX)) {
11114+ smp_mb__before_clear_bit();
11115+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11116+ smp_mb__after_clear_bit();
11117+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11118+ }
11119+#endif
11120+
11121+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11122+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11123+ prev->context.user_cs_limit != next->context.user_cs_limit))
11124+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11125 #ifdef CONFIG_SMP
11126+ else if (unlikely(tlbstate != TLBSTATE_OK))
11127+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11128+#endif
11129+#endif
11130+
11131+ }
11132 else {
11133+
11134+#ifdef CONFIG_PAX_PER_CPU_PGD
11135+ pax_open_kernel();
11136+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11137+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11138+ pax_close_kernel();
11139+ load_cr3(get_cpu_pgd(cpu));
11140+#endif
11141+
11142+#ifdef CONFIG_SMP
11143 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11144 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
11145
11146@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11147 * tlb flush IPI delivery. We must reload CR3
11148 * to make sure to use no freed page tables.
11149 */
11150+
11151+#ifndef CONFIG_PAX_PER_CPU_PGD
11152 load_cr3(next->pgd);
11153+#endif
11154+
11155 load_LDT_nolock(&next->context);
11156+
11157+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11158+ if (!(__supported_pte_mask & _PAGE_NX))
11159+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11160+#endif
11161+
11162+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11163+#ifdef CONFIG_PAX_PAGEEXEC
11164+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11165+#endif
11166+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11167+#endif
11168+
11169 }
11170+#endif
11171 }
11172-#endif
11173 }
11174
11175 #define activate_mm(prev, next) \
11176diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11177index 9eae775..c914fea 100644
11178--- a/arch/x86/include/asm/module.h
11179+++ b/arch/x86/include/asm/module.h
11180@@ -5,6 +5,7 @@
11181
11182 #ifdef CONFIG_X86_64
11183 /* X86_64 does not define MODULE_PROC_FAMILY */
11184+#define MODULE_PROC_FAMILY ""
11185 #elif defined CONFIG_M386
11186 #define MODULE_PROC_FAMILY "386 "
11187 #elif defined CONFIG_M486
11188@@ -59,8 +60,20 @@
11189 #error unknown processor family
11190 #endif
11191
11192-#ifdef CONFIG_X86_32
11193-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11194+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11195+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11196+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11197+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11198+#else
11199+#define MODULE_PAX_KERNEXEC ""
11200 #endif
11201
11202+#ifdef CONFIG_PAX_MEMORY_UDEREF
11203+#define MODULE_PAX_UDEREF "UDEREF "
11204+#else
11205+#define MODULE_PAX_UDEREF ""
11206+#endif
11207+
11208+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11209+
11210 #endif /* _ASM_X86_MODULE_H */
11211diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11212index 7639dbf..e08a58c 100644
11213--- a/arch/x86/include/asm/page_64_types.h
11214+++ b/arch/x86/include/asm/page_64_types.h
11215@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11216
11217 /* duplicated to the one in bootmem.h */
11218 extern unsigned long max_pfn;
11219-extern unsigned long phys_base;
11220+extern const unsigned long phys_base;
11221
11222 extern unsigned long __phys_addr(unsigned long);
11223 #define __phys_reloc_hide(x) (x)
11224diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11225index a7d2db9..edb023e 100644
11226--- a/arch/x86/include/asm/paravirt.h
11227+++ b/arch/x86/include/asm/paravirt.h
11228@@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11229 val);
11230 }
11231
11232+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11233+{
11234+ pgdval_t val = native_pgd_val(pgd);
11235+
11236+ if (sizeof(pgdval_t) > sizeof(long))
11237+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11238+ val, (u64)val >> 32);
11239+ else
11240+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11241+ val);
11242+}
11243+
11244 static inline void pgd_clear(pgd_t *pgdp)
11245 {
11246 set_pgd(pgdp, __pgd(0));
11247@@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11248 pv_mmu_ops.set_fixmap(idx, phys, flags);
11249 }
11250
11251+#ifdef CONFIG_PAX_KERNEXEC
11252+static inline unsigned long pax_open_kernel(void)
11253+{
11254+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11255+}
11256+
11257+static inline unsigned long pax_close_kernel(void)
11258+{
11259+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11260+}
11261+#else
11262+static inline unsigned long pax_open_kernel(void) { return 0; }
11263+static inline unsigned long pax_close_kernel(void) { return 0; }
11264+#endif
11265+
11266 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11267
11268 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11269@@ -964,7 +991,7 @@ extern void default_banner(void);
11270
11271 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11272 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11273-#define PARA_INDIRECT(addr) *%cs:addr
11274+#define PARA_INDIRECT(addr) *%ss:addr
11275 #endif
11276
11277 #define INTERRUPT_RETURN \
11278@@ -1041,6 +1068,21 @@ extern void default_banner(void);
11279 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11280 CLBR_NONE, \
11281 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11282+
11283+#define GET_CR0_INTO_RDI \
11284+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11285+ mov %rax,%rdi
11286+
11287+#define SET_RDI_INTO_CR0 \
11288+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11289+
11290+#define GET_CR3_INTO_RDI \
11291+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11292+ mov %rax,%rdi
11293+
11294+#define SET_RDI_INTO_CR3 \
11295+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11296+
11297 #endif /* CONFIG_X86_32 */
11298
11299 #endif /* __ASSEMBLY__ */
11300diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11301index 8e8b9a4..f07d725 100644
11302--- a/arch/x86/include/asm/paravirt_types.h
11303+++ b/arch/x86/include/asm/paravirt_types.h
11304@@ -84,20 +84,20 @@ struct pv_init_ops {
11305 */
11306 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11307 unsigned long addr, unsigned len);
11308-};
11309+} __no_const;
11310
11311
11312 struct pv_lazy_ops {
11313 /* Set deferred update mode, used for batching operations. */
11314 void (*enter)(void);
11315 void (*leave)(void);
11316-};
11317+} __no_const;
11318
11319 struct pv_time_ops {
11320 unsigned long long (*sched_clock)(void);
11321 unsigned long long (*steal_clock)(int cpu);
11322 unsigned long (*get_tsc_khz)(void);
11323-};
11324+} __no_const;
11325
11326 struct pv_cpu_ops {
11327 /* hooks for various privileged instructions */
11328@@ -193,7 +193,7 @@ struct pv_cpu_ops {
11329
11330 void (*start_context_switch)(struct task_struct *prev);
11331 void (*end_context_switch)(struct task_struct *next);
11332-};
11333+} __no_const;
11334
11335 struct pv_irq_ops {
11336 /*
11337@@ -224,7 +224,7 @@ struct pv_apic_ops {
11338 unsigned long start_eip,
11339 unsigned long start_esp);
11340 #endif
11341-};
11342+} __no_const;
11343
11344 struct pv_mmu_ops {
11345 unsigned long (*read_cr2)(void);
11346@@ -313,6 +313,7 @@ struct pv_mmu_ops {
11347 struct paravirt_callee_save make_pud;
11348
11349 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11350+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11351 #endif /* PAGETABLE_LEVELS == 4 */
11352 #endif /* PAGETABLE_LEVELS >= 3 */
11353
11354@@ -324,6 +325,12 @@ struct pv_mmu_ops {
11355 an mfn. We can tell which is which from the index. */
11356 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11357 phys_addr_t phys, pgprot_t flags);
11358+
11359+#ifdef CONFIG_PAX_KERNEXEC
11360+ unsigned long (*pax_open_kernel)(void);
11361+ unsigned long (*pax_close_kernel)(void);
11362+#endif
11363+
11364 };
11365
11366 struct arch_spinlock;
11367@@ -334,7 +341,7 @@ struct pv_lock_ops {
11368 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11369 int (*spin_trylock)(struct arch_spinlock *lock);
11370 void (*spin_unlock)(struct arch_spinlock *lock);
11371-};
11372+} __no_const;
11373
11374 /* This contains all the paravirt structures: we get a convenient
11375 * number for each function using the offset which we use to indicate
11376diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11377index b4389a4..7024269 100644
11378--- a/arch/x86/include/asm/pgalloc.h
11379+++ b/arch/x86/include/asm/pgalloc.h
11380@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11381 pmd_t *pmd, pte_t *pte)
11382 {
11383 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11384+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11385+}
11386+
11387+static inline void pmd_populate_user(struct mm_struct *mm,
11388+ pmd_t *pmd, pte_t *pte)
11389+{
11390+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11391 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11392 }
11393
11394@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11395
11396 #ifdef CONFIG_X86_PAE
11397 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11398+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11399+{
11400+ pud_populate(mm, pudp, pmd);
11401+}
11402 #else /* !CONFIG_X86_PAE */
11403 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11404 {
11405 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11406 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11407 }
11408+
11409+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11410+{
11411+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11412+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11413+}
11414 #endif /* CONFIG_X86_PAE */
11415
11416 #if PAGETABLE_LEVELS > 3
11417@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11418 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11419 }
11420
11421+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11422+{
11423+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11424+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11425+}
11426+
11427 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11428 {
11429 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11430diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11431index 98391db..8f6984e 100644
11432--- a/arch/x86/include/asm/pgtable-2level.h
11433+++ b/arch/x86/include/asm/pgtable-2level.h
11434@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11435
11436 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11437 {
11438+ pax_open_kernel();
11439 *pmdp = pmd;
11440+ pax_close_kernel();
11441 }
11442
11443 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11444diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11445index effff47..bbb8295 100644
11446--- a/arch/x86/include/asm/pgtable-3level.h
11447+++ b/arch/x86/include/asm/pgtable-3level.h
11448@@ -31,6 +31,56 @@ static inline void native_set_pte(pte_t *ptep, pte_t pte)
11449 ptep->pte_low = pte.pte_low;
11450 }
11451
11452+#define __HAVE_ARCH_READ_PMD_ATOMIC
11453+/*
11454+ * pte_offset_map_lock on 32bit PAE kernels was reading the pmd_t with
11455+ * a "*pmdp" dereference done by gcc. Problem is, in certain places
11456+ * where pte_offset_map_lock is called, concurrent page faults are
11457+ * allowed, if the mmap_sem is hold for reading. An example is mincore
11458+ * vs page faults vs MADV_DONTNEED. On the page fault side
11459+ * pmd_populate rightfully does a set_64bit, but if we're reading the
11460+ * pmd_t with a "*pmdp" on the mincore side, a SMP race can happen
11461+ * because gcc will not read the 64bit of the pmd atomically. To fix
11462+ * this all places running pmd_offset_map_lock() while holding the
11463+ * mmap_sem in read mode, shall read the pmdp pointer using this
11464+ * function to know if the pmd is null nor not, and in turn to know if
11465+ * they can run pmd_offset_map_lock or pmd_trans_huge or other pmd
11466+ * operations.
11467+ *
11468+ * Without THP if the mmap_sem is hold for reading, the
11469+ * pmd can only transition from null to not null while read_pmd_atomic runs.
11470+ * So there's no need of literally reading it atomically.
11471+ *
11472+ * With THP if the mmap_sem is hold for reading, the pmd can become
11473+ * THP or null or point to a pte (and in turn become "stable") at any
11474+ * time under read_pmd_atomic, so it's mandatory to read it atomically
11475+ * with cmpxchg8b.
11476+ */
11477+#ifndef CONFIG_TRANSPARENT_HUGEPAGE
11478+static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
11479+{
11480+ pmdval_t ret;
11481+ u32 *tmp = (u32 *)pmdp;
11482+
11483+ ret = (pmdval_t) (*tmp);
11484+ if (ret) {
11485+ /*
11486+ * If the low part is null, we must not read the high part
11487+ * or we can end up with a partial pmd.
11488+ */
11489+ smp_rmb();
11490+ ret |= ((pmdval_t)*(tmp + 1)) << 32;
11491+ }
11492+
11493+ return __pmd(ret);
11494+}
11495+#else /* CONFIG_TRANSPARENT_HUGEPAGE */
11496+static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
11497+{
11498+ return __pmd(atomic64_read((atomic64_t *)pmdp));
11499+}
11500+#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
11501+
11502 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11503 {
11504 set_64bit((unsigned long long *)(ptep), native_pte_val(pte));
11505@@ -38,12 +88,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11506
11507 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11508 {
11509+ pax_open_kernel();
11510 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11511+ pax_close_kernel();
11512 }
11513
11514 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11515 {
11516+ pax_open_kernel();
11517 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11518+ pax_close_kernel();
11519 }
11520
11521 /*
11522diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11523index 49afb3f..91a8c63 100644
11524--- a/arch/x86/include/asm/pgtable.h
11525+++ b/arch/x86/include/asm/pgtable.h
11526@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11527
11528 #ifndef __PAGETABLE_PUD_FOLDED
11529 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11530+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11531 #define pgd_clear(pgd) native_pgd_clear(pgd)
11532 #endif
11533
11534@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11535
11536 #define arch_end_context_switch(prev) do {} while(0)
11537
11538+#define pax_open_kernel() native_pax_open_kernel()
11539+#define pax_close_kernel() native_pax_close_kernel()
11540 #endif /* CONFIG_PARAVIRT */
11541
11542+#define __HAVE_ARCH_PAX_OPEN_KERNEL
11543+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11544+
11545+#ifdef CONFIG_PAX_KERNEXEC
11546+static inline unsigned long native_pax_open_kernel(void)
11547+{
11548+ unsigned long cr0;
11549+
11550+ preempt_disable();
11551+ barrier();
11552+ cr0 = read_cr0() ^ X86_CR0_WP;
11553+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11554+ write_cr0(cr0);
11555+ return cr0 ^ X86_CR0_WP;
11556+}
11557+
11558+static inline unsigned long native_pax_close_kernel(void)
11559+{
11560+ unsigned long cr0;
11561+
11562+ cr0 = read_cr0() ^ X86_CR0_WP;
11563+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11564+ write_cr0(cr0);
11565+ barrier();
11566+ preempt_enable_no_resched();
11567+ return cr0 ^ X86_CR0_WP;
11568+}
11569+#else
11570+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11571+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11572+#endif
11573+
11574 /*
11575 * The following only work if pte_present() is true.
11576 * Undefined behaviour if not..
11577 */
11578+static inline int pte_user(pte_t pte)
11579+{
11580+ return pte_val(pte) & _PAGE_USER;
11581+}
11582+
11583 static inline int pte_dirty(pte_t pte)
11584 {
11585 return pte_flags(pte) & _PAGE_DIRTY;
11586@@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11587 return pte_clear_flags(pte, _PAGE_RW);
11588 }
11589
11590+static inline pte_t pte_mkread(pte_t pte)
11591+{
11592+ return __pte(pte_val(pte) | _PAGE_USER);
11593+}
11594+
11595 static inline pte_t pte_mkexec(pte_t pte)
11596 {
11597- return pte_clear_flags(pte, _PAGE_NX);
11598+#ifdef CONFIG_X86_PAE
11599+ if (__supported_pte_mask & _PAGE_NX)
11600+ return pte_clear_flags(pte, _PAGE_NX);
11601+ else
11602+#endif
11603+ return pte_set_flags(pte, _PAGE_USER);
11604+}
11605+
11606+static inline pte_t pte_exprotect(pte_t pte)
11607+{
11608+#ifdef CONFIG_X86_PAE
11609+ if (__supported_pte_mask & _PAGE_NX)
11610+ return pte_set_flags(pte, _PAGE_NX);
11611+ else
11612+#endif
11613+ return pte_clear_flags(pte, _PAGE_USER);
11614 }
11615
11616 static inline pte_t pte_mkdirty(pte_t pte)
11617@@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11618 #endif
11619
11620 #ifndef __ASSEMBLY__
11621+
11622+#ifdef CONFIG_PAX_PER_CPU_PGD
11623+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11624+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11625+{
11626+ return cpu_pgd[cpu];
11627+}
11628+#endif
11629+
11630 #include <linux/mm_types.h>
11631
11632 static inline int pte_none(pte_t pte)
11633@@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11634
11635 static inline int pgd_bad(pgd_t pgd)
11636 {
11637- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11638+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11639 }
11640
11641 static inline int pgd_none(pgd_t pgd)
11642@@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11643 * pgd_offset() returns a (pgd_t *)
11644 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11645 */
11646-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11647+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11648+
11649+#ifdef CONFIG_PAX_PER_CPU_PGD
11650+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11651+#endif
11652+
11653 /*
11654 * a shortcut which implies the use of the kernel's pgd, instead
11655 * of a process's
11656@@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11657 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11658 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11659
11660+#ifdef CONFIG_X86_32
11661+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11662+#else
11663+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11664+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11665+
11666+#ifdef CONFIG_PAX_MEMORY_UDEREF
11667+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11668+#else
11669+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11670+#endif
11671+
11672+#endif
11673+
11674 #ifndef __ASSEMBLY__
11675
11676 extern int direct_gbpages;
11677@@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11678 * dst and src can be on the same page, but the range must not overlap,
11679 * and must not cross a page boundary.
11680 */
11681-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11682+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11683 {
11684- memcpy(dst, src, count * sizeof(pgd_t));
11685+ pax_open_kernel();
11686+ while (count--)
11687+ *dst++ = *src++;
11688+ pax_close_kernel();
11689 }
11690
11691+#ifdef CONFIG_PAX_PER_CPU_PGD
11692+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11693+#endif
11694+
11695+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11696+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11697+#else
11698+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11699+#endif
11700
11701 #include <asm-generic/pgtable.h>
11702 #endif /* __ASSEMBLY__ */
11703diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11704index 0c92113..34a77c6 100644
11705--- a/arch/x86/include/asm/pgtable_32.h
11706+++ b/arch/x86/include/asm/pgtable_32.h
11707@@ -25,9 +25,6 @@
11708 struct mm_struct;
11709 struct vm_area_struct;
11710
11711-extern pgd_t swapper_pg_dir[1024];
11712-extern pgd_t initial_page_table[1024];
11713-
11714 static inline void pgtable_cache_init(void) { }
11715 static inline void check_pgt_cache(void) { }
11716 void paging_init(void);
11717@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11718 # include <asm/pgtable-2level.h>
11719 #endif
11720
11721+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11722+extern pgd_t initial_page_table[PTRS_PER_PGD];
11723+#ifdef CONFIG_X86_PAE
11724+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11725+#endif
11726+
11727 #if defined(CONFIG_HIGHPTE)
11728 #define pte_offset_map(dir, address) \
11729 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11730@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11731 /* Clear a kernel PTE and flush it from the TLB */
11732 #define kpte_clear_flush(ptep, vaddr) \
11733 do { \
11734+ pax_open_kernel(); \
11735 pte_clear(&init_mm, (vaddr), (ptep)); \
11736+ pax_close_kernel(); \
11737 __flush_tlb_one((vaddr)); \
11738 } while (0)
11739
11740@@ -74,6 +79,9 @@ do { \
11741
11742 #endif /* !__ASSEMBLY__ */
11743
11744+#define HAVE_ARCH_UNMAPPED_AREA
11745+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11746+
11747 /*
11748 * kern_addr_valid() is (1) for FLATMEM and (0) for
11749 * SPARSEMEM and DISCONTIGMEM
11750diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11751index ed5903b..c7fe163 100644
11752--- a/arch/x86/include/asm/pgtable_32_types.h
11753+++ b/arch/x86/include/asm/pgtable_32_types.h
11754@@ -8,7 +8,7 @@
11755 */
11756 #ifdef CONFIG_X86_PAE
11757 # include <asm/pgtable-3level_types.h>
11758-# define PMD_SIZE (1UL << PMD_SHIFT)
11759+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11760 # define PMD_MASK (~(PMD_SIZE - 1))
11761 #else
11762 # include <asm/pgtable-2level_types.h>
11763@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11764 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11765 #endif
11766
11767+#ifdef CONFIG_PAX_KERNEXEC
11768+#ifndef __ASSEMBLY__
11769+extern unsigned char MODULES_EXEC_VADDR[];
11770+extern unsigned char MODULES_EXEC_END[];
11771+#endif
11772+#include <asm/boot.h>
11773+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11774+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11775+#else
11776+#define ktla_ktva(addr) (addr)
11777+#define ktva_ktla(addr) (addr)
11778+#endif
11779+
11780 #define MODULES_VADDR VMALLOC_START
11781 #define MODULES_END VMALLOC_END
11782 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11783diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11784index 975f709..9f779c9 100644
11785--- a/arch/x86/include/asm/pgtable_64.h
11786+++ b/arch/x86/include/asm/pgtable_64.h
11787@@ -16,10 +16,14 @@
11788
11789 extern pud_t level3_kernel_pgt[512];
11790 extern pud_t level3_ident_pgt[512];
11791+extern pud_t level3_vmalloc_start_pgt[512];
11792+extern pud_t level3_vmalloc_end_pgt[512];
11793+extern pud_t level3_vmemmap_pgt[512];
11794+extern pud_t level2_vmemmap_pgt[512];
11795 extern pmd_t level2_kernel_pgt[512];
11796 extern pmd_t level2_fixmap_pgt[512];
11797-extern pmd_t level2_ident_pgt[512];
11798-extern pgd_t init_level4_pgt[];
11799+extern pmd_t level2_ident_pgt[512*2];
11800+extern pgd_t init_level4_pgt[512];
11801
11802 #define swapper_pg_dir init_level4_pgt
11803
11804@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11805
11806 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11807 {
11808+ pax_open_kernel();
11809 *pmdp = pmd;
11810+ pax_close_kernel();
11811 }
11812
11813 static inline void native_pmd_clear(pmd_t *pmd)
11814@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11815
11816 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11817 {
11818+ pax_open_kernel();
11819 *pudp = pud;
11820+ pax_close_kernel();
11821 }
11822
11823 static inline void native_pud_clear(pud_t *pud)
11824@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11825
11826 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11827 {
11828+ pax_open_kernel();
11829+ *pgdp = pgd;
11830+ pax_close_kernel();
11831+}
11832+
11833+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11834+{
11835 *pgdp = pgd;
11836 }
11837
11838diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11839index 766ea16..5b96cb3 100644
11840--- a/arch/x86/include/asm/pgtable_64_types.h
11841+++ b/arch/x86/include/asm/pgtable_64_types.h
11842@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11843 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11844 #define MODULES_END _AC(0xffffffffff000000, UL)
11845 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11846+#define MODULES_EXEC_VADDR MODULES_VADDR
11847+#define MODULES_EXEC_END MODULES_END
11848+
11849+#define ktla_ktva(addr) (addr)
11850+#define ktva_ktla(addr) (addr)
11851
11852 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11853diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11854index 013286a..8b42f4f 100644
11855--- a/arch/x86/include/asm/pgtable_types.h
11856+++ b/arch/x86/include/asm/pgtable_types.h
11857@@ -16,13 +16,12 @@
11858 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11859 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11860 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11861-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11862+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11863 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11864 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11865 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11866-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11867-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11868-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11869+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11870+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11871 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11872
11873 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11874@@ -40,7 +39,6 @@
11875 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11876 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11877 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11878-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11879 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11880 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11881 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11882@@ -57,8 +55,10 @@
11883
11884 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11885 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11886-#else
11887+#elif defined(CONFIG_KMEMCHECK)
11888 #define _PAGE_NX (_AT(pteval_t, 0))
11889+#else
11890+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11891 #endif
11892
11893 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11894@@ -96,6 +96,9 @@
11895 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11896 _PAGE_ACCESSED)
11897
11898+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11899+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11900+
11901 #define __PAGE_KERNEL_EXEC \
11902 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11903 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11904@@ -106,7 +109,7 @@
11905 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11906 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11907 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11908-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11909+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11910 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11911 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11912 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11913@@ -168,8 +171,8 @@
11914 * bits are combined, this will alow user to access the high address mapped
11915 * VDSO in the presence of CONFIG_COMPAT_VDSO
11916 */
11917-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11918-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11919+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11920+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11921 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11922 #endif
11923
11924@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11925 {
11926 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11927 }
11928+#endif
11929
11930+#if PAGETABLE_LEVELS == 3
11931+#include <asm-generic/pgtable-nopud.h>
11932+#endif
11933+
11934+#if PAGETABLE_LEVELS == 2
11935+#include <asm-generic/pgtable-nopmd.h>
11936+#endif
11937+
11938+#ifndef __ASSEMBLY__
11939 #if PAGETABLE_LEVELS > 3
11940 typedef struct { pudval_t pud; } pud_t;
11941
11942@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11943 return pud.pud;
11944 }
11945 #else
11946-#include <asm-generic/pgtable-nopud.h>
11947-
11948 static inline pudval_t native_pud_val(pud_t pud)
11949 {
11950 return native_pgd_val(pud.pgd);
11951@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11952 return pmd.pmd;
11953 }
11954 #else
11955-#include <asm-generic/pgtable-nopmd.h>
11956-
11957 static inline pmdval_t native_pmd_val(pmd_t pmd)
11958 {
11959 return native_pgd_val(pmd.pud.pgd);
11960@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11961
11962 extern pteval_t __supported_pte_mask;
11963 extern void set_nx(void);
11964-extern int nx_enabled;
11965
11966 #define pgprot_writecombine pgprot_writecombine
11967 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11968diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11969index 58545c9..fe6fc38e 100644
11970--- a/arch/x86/include/asm/processor.h
11971+++ b/arch/x86/include/asm/processor.h
11972@@ -266,7 +266,7 @@ struct tss_struct {
11973
11974 } ____cacheline_aligned;
11975
11976-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11977+extern struct tss_struct init_tss[NR_CPUS];
11978
11979 /*
11980 * Save the original ist values for checking stack pointers during debugging
11981@@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(const void *x)
11982 */
11983 #define TASK_SIZE PAGE_OFFSET
11984 #define TASK_SIZE_MAX TASK_SIZE
11985+
11986+#ifdef CONFIG_PAX_SEGMEXEC
11987+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11988+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11989+#else
11990 #define STACK_TOP TASK_SIZE
11991-#define STACK_TOP_MAX STACK_TOP
11992+#endif
11993+
11994+#define STACK_TOP_MAX TASK_SIZE
11995
11996 #define INIT_THREAD { \
11997- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11998+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11999 .vm86_info = NULL, \
12000 .sysenter_cs = __KERNEL_CS, \
12001 .io_bitmap_ptr = NULL, \
12002@@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(const void *x)
12003 */
12004 #define INIT_TSS { \
12005 .x86_tss = { \
12006- .sp0 = sizeof(init_stack) + (long)&init_stack, \
12007+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
12008 .ss0 = __KERNEL_DS, \
12009 .ss1 = __KERNEL_CS, \
12010 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
12011@@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(const void *x)
12012 extern unsigned long thread_saved_pc(struct task_struct *tsk);
12013
12014 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
12015-#define KSTK_TOP(info) \
12016-({ \
12017- unsigned long *__ptr = (unsigned long *)(info); \
12018- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
12019-})
12020+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
12021
12022 /*
12023 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
12024@@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
12025 #define task_pt_regs(task) \
12026 ({ \
12027 struct pt_regs *__regs__; \
12028- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
12029+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
12030 __regs__ - 1; \
12031 })
12032
12033@@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
12034 /*
12035 * User space process size. 47bits minus one guard page.
12036 */
12037-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
12038+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
12039
12040 /* This decides where the kernel will search for a free chunk of vm
12041 * space during mmap's.
12042 */
12043 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
12044- 0xc0000000 : 0xFFFFe000)
12045+ 0xc0000000 : 0xFFFFf000)
12046
12047 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
12048 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
12049@@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
12050 #define STACK_TOP_MAX TASK_SIZE_MAX
12051
12052 #define INIT_THREAD { \
12053- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12054+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12055 }
12056
12057 #define INIT_TSS { \
12058- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12059+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12060 }
12061
12062 /*
12063@@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
12064 */
12065 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
12066
12067+#ifdef CONFIG_PAX_SEGMEXEC
12068+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
12069+#endif
12070+
12071 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
12072
12073 /* Get/set a process' ability to use the timestamp counter instruction */
12074diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
12075index 3566454..4bdfb8c 100644
12076--- a/arch/x86/include/asm/ptrace.h
12077+++ b/arch/x86/include/asm/ptrace.h
12078@@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
12079 }
12080
12081 /*
12082- * user_mode_vm(regs) determines whether a register set came from user mode.
12083+ * user_mode(regs) determines whether a register set came from user mode.
12084 * This is true if V8086 mode was enabled OR if the register set was from
12085 * protected mode with RPL-3 CS value. This tricky test checks that with
12086 * one comparison. Many places in the kernel can bypass this full check
12087- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
12088+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
12089+ * be used.
12090 */
12091-static inline int user_mode(struct pt_regs *regs)
12092+static inline int user_mode_novm(struct pt_regs *regs)
12093 {
12094 #ifdef CONFIG_X86_32
12095 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
12096 #else
12097- return !!(regs->cs & 3);
12098+ return !!(regs->cs & SEGMENT_RPL_MASK);
12099 #endif
12100 }
12101
12102-static inline int user_mode_vm(struct pt_regs *regs)
12103+static inline int user_mode(struct pt_regs *regs)
12104 {
12105 #ifdef CONFIG_X86_32
12106 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
12107 USER_RPL;
12108 #else
12109- return user_mode(regs);
12110+ return user_mode_novm(regs);
12111 #endif
12112 }
12113
12114@@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12115 #ifdef CONFIG_X86_64
12116 static inline bool user_64bit_mode(struct pt_regs *regs)
12117 {
12118+ unsigned long cs = regs->cs & 0xffff;
12119 #ifndef CONFIG_PARAVIRT
12120 /*
12121 * On non-paravirt systems, this is the only long mode CPL 3
12122 * selector. We do not allow long mode selectors in the LDT.
12123 */
12124- return regs->cs == __USER_CS;
12125+ return cs == __USER_CS;
12126 #else
12127 /* Headers are too twisted for this to go in paravirt.h. */
12128- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12129+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12130 #endif
12131 }
12132 #endif
12133diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12134index 92f29706..a79cbbb 100644
12135--- a/arch/x86/include/asm/reboot.h
12136+++ b/arch/x86/include/asm/reboot.h
12137@@ -6,19 +6,19 @@
12138 struct pt_regs;
12139
12140 struct machine_ops {
12141- void (*restart)(char *cmd);
12142- void (*halt)(void);
12143- void (*power_off)(void);
12144+ void (* __noreturn restart)(char *cmd);
12145+ void (* __noreturn halt)(void);
12146+ void (* __noreturn power_off)(void);
12147 void (*shutdown)(void);
12148 void (*crash_shutdown)(struct pt_regs *);
12149- void (*emergency_restart)(void);
12150-};
12151+ void (* __noreturn emergency_restart)(void);
12152+} __no_const;
12153
12154 extern struct machine_ops machine_ops;
12155
12156 void native_machine_crash_shutdown(struct pt_regs *regs);
12157 void native_machine_shutdown(void);
12158-void machine_real_restart(unsigned int type);
12159+void machine_real_restart(unsigned int type) __noreturn;
12160 /* These must match dispatch_table in reboot_32.S */
12161 #define MRR_BIOS 0
12162 #define MRR_APM 1
12163diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12164index 2dbe4a7..ce1db00 100644
12165--- a/arch/x86/include/asm/rwsem.h
12166+++ b/arch/x86/include/asm/rwsem.h
12167@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12168 {
12169 asm volatile("# beginning down_read\n\t"
12170 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12171+
12172+#ifdef CONFIG_PAX_REFCOUNT
12173+ "jno 0f\n"
12174+ LOCK_PREFIX _ASM_DEC "(%1)\n"
12175+ "int $4\n0:\n"
12176+ _ASM_EXTABLE(0b, 0b)
12177+#endif
12178+
12179 /* adds 0x00000001 */
12180 " jns 1f\n"
12181 " call call_rwsem_down_read_failed\n"
12182@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12183 "1:\n\t"
12184 " mov %1,%2\n\t"
12185 " add %3,%2\n\t"
12186+
12187+#ifdef CONFIG_PAX_REFCOUNT
12188+ "jno 0f\n"
12189+ "sub %3,%2\n"
12190+ "int $4\n0:\n"
12191+ _ASM_EXTABLE(0b, 0b)
12192+#endif
12193+
12194 " jle 2f\n\t"
12195 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12196 " jnz 1b\n\t"
12197@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12198 long tmp;
12199 asm volatile("# beginning down_write\n\t"
12200 LOCK_PREFIX " xadd %1,(%2)\n\t"
12201+
12202+#ifdef CONFIG_PAX_REFCOUNT
12203+ "jno 0f\n"
12204+ "mov %1,(%2)\n"
12205+ "int $4\n0:\n"
12206+ _ASM_EXTABLE(0b, 0b)
12207+#endif
12208+
12209 /* adds 0xffff0001, returns the old value */
12210 " test %1,%1\n\t"
12211 /* was the count 0 before? */
12212@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12213 long tmp;
12214 asm volatile("# beginning __up_read\n\t"
12215 LOCK_PREFIX " xadd %1,(%2)\n\t"
12216+
12217+#ifdef CONFIG_PAX_REFCOUNT
12218+ "jno 0f\n"
12219+ "mov %1,(%2)\n"
12220+ "int $4\n0:\n"
12221+ _ASM_EXTABLE(0b, 0b)
12222+#endif
12223+
12224 /* subtracts 1, returns the old value */
12225 " jns 1f\n\t"
12226 " call call_rwsem_wake\n" /* expects old value in %edx */
12227@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12228 long tmp;
12229 asm volatile("# beginning __up_write\n\t"
12230 LOCK_PREFIX " xadd %1,(%2)\n\t"
12231+
12232+#ifdef CONFIG_PAX_REFCOUNT
12233+ "jno 0f\n"
12234+ "mov %1,(%2)\n"
12235+ "int $4\n0:\n"
12236+ _ASM_EXTABLE(0b, 0b)
12237+#endif
12238+
12239 /* subtracts 0xffff0001, returns the old value */
12240 " jns 1f\n\t"
12241 " call call_rwsem_wake\n" /* expects old value in %edx */
12242@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12243 {
12244 asm volatile("# beginning __downgrade_write\n\t"
12245 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12246+
12247+#ifdef CONFIG_PAX_REFCOUNT
12248+ "jno 0f\n"
12249+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12250+ "int $4\n0:\n"
12251+ _ASM_EXTABLE(0b, 0b)
12252+#endif
12253+
12254 /*
12255 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12256 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12257@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12258 */
12259 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12260 {
12261- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12262+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12263+
12264+#ifdef CONFIG_PAX_REFCOUNT
12265+ "jno 0f\n"
12266+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
12267+ "int $4\n0:\n"
12268+ _ASM_EXTABLE(0b, 0b)
12269+#endif
12270+
12271 : "+m" (sem->count)
12272 : "er" (delta));
12273 }
12274@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12275 */
12276 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12277 {
12278- return delta + xadd(&sem->count, delta);
12279+ return delta + xadd_check_overflow(&sem->count, delta);
12280 }
12281
12282 #endif /* __KERNEL__ */
12283diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12284index 5e64171..f58957e 100644
12285--- a/arch/x86/include/asm/segment.h
12286+++ b/arch/x86/include/asm/segment.h
12287@@ -64,10 +64,15 @@
12288 * 26 - ESPFIX small SS
12289 * 27 - per-cpu [ offset to per-cpu data area ]
12290 * 28 - stack_canary-20 [ for stack protector ]
12291- * 29 - unused
12292- * 30 - unused
12293+ * 29 - PCI BIOS CS
12294+ * 30 - PCI BIOS DS
12295 * 31 - TSS for double fault handler
12296 */
12297+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12298+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12299+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12300+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12301+
12302 #define GDT_ENTRY_TLS_MIN 6
12303 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12304
12305@@ -79,6 +84,8 @@
12306
12307 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12308
12309+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12310+
12311 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12312
12313 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12314@@ -104,6 +111,12 @@
12315 #define __KERNEL_STACK_CANARY 0
12316 #endif
12317
12318+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12319+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12320+
12321+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12322+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12323+
12324 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12325
12326 /*
12327@@ -141,7 +154,7 @@
12328 */
12329
12330 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12331-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12332+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12333
12334
12335 #else
12336@@ -165,6 +178,8 @@
12337 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12338 #define __USER32_DS __USER_DS
12339
12340+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12341+
12342 #define GDT_ENTRY_TSS 8 /* needs two entries */
12343 #define GDT_ENTRY_LDT 10 /* needs two entries */
12344 #define GDT_ENTRY_TLS_MIN 12
12345@@ -185,6 +200,7 @@
12346 #endif
12347
12348 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12349+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12350 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12351 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12352 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12353diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12354index 0434c40..1714bf0 100644
12355--- a/arch/x86/include/asm/smp.h
12356+++ b/arch/x86/include/asm/smp.h
12357@@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12358 /* cpus sharing the last level cache: */
12359 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12360 DECLARE_PER_CPU(u16, cpu_llc_id);
12361-DECLARE_PER_CPU(int, cpu_number);
12362+DECLARE_PER_CPU(unsigned int, cpu_number);
12363
12364 static inline struct cpumask *cpu_sibling_mask(int cpu)
12365 {
12366@@ -77,7 +77,7 @@ struct smp_ops {
12367
12368 void (*send_call_func_ipi)(const struct cpumask *mask);
12369 void (*send_call_func_single_ipi)(int cpu);
12370-};
12371+} __no_const;
12372
12373 /* Globals due to paravirt */
12374 extern void set_cpu_sibling_map(int cpu);
12375@@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12376 extern int safe_smp_processor_id(void);
12377
12378 #elif defined(CONFIG_X86_64_SMP)
12379-#define raw_smp_processor_id() (percpu_read(cpu_number))
12380-
12381-#define stack_smp_processor_id() \
12382-({ \
12383- struct thread_info *ti; \
12384- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12385- ti->cpu; \
12386-})
12387+#define raw_smp_processor_id() (percpu_read(cpu_number))
12388+#define stack_smp_processor_id() raw_smp_processor_id()
12389 #define safe_smp_processor_id() smp_processor_id()
12390
12391 #endif
12392diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12393index a82c2bf..2198f61 100644
12394--- a/arch/x86/include/asm/spinlock.h
12395+++ b/arch/x86/include/asm/spinlock.h
12396@@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12397 static inline void arch_read_lock(arch_rwlock_t *rw)
12398 {
12399 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12400+
12401+#ifdef CONFIG_PAX_REFCOUNT
12402+ "jno 0f\n"
12403+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12404+ "int $4\n0:\n"
12405+ _ASM_EXTABLE(0b, 0b)
12406+#endif
12407+
12408 "jns 1f\n"
12409 "call __read_lock_failed\n\t"
12410 "1:\n"
12411@@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12412 static inline void arch_write_lock(arch_rwlock_t *rw)
12413 {
12414 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12415+
12416+#ifdef CONFIG_PAX_REFCOUNT
12417+ "jno 0f\n"
12418+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12419+ "int $4\n0:\n"
12420+ _ASM_EXTABLE(0b, 0b)
12421+#endif
12422+
12423 "jz 1f\n"
12424 "call __write_lock_failed\n\t"
12425 "1:\n"
12426@@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12427
12428 static inline void arch_read_unlock(arch_rwlock_t *rw)
12429 {
12430- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12431+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12432+
12433+#ifdef CONFIG_PAX_REFCOUNT
12434+ "jno 0f\n"
12435+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12436+ "int $4\n0:\n"
12437+ _ASM_EXTABLE(0b, 0b)
12438+#endif
12439+
12440 :"+m" (rw->lock) : : "memory");
12441 }
12442
12443 static inline void arch_write_unlock(arch_rwlock_t *rw)
12444 {
12445- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12446+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12447+
12448+#ifdef CONFIG_PAX_REFCOUNT
12449+ "jno 0f\n"
12450+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12451+ "int $4\n0:\n"
12452+ _ASM_EXTABLE(0b, 0b)
12453+#endif
12454+
12455 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12456 }
12457
12458diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12459index 1575177..cb23f52 100644
12460--- a/arch/x86/include/asm/stackprotector.h
12461+++ b/arch/x86/include/asm/stackprotector.h
12462@@ -48,7 +48,7 @@
12463 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12464 */
12465 #define GDT_STACK_CANARY_INIT \
12466- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12467+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12468
12469 /*
12470 * Initialize the stackprotector canary value.
12471@@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
12472
12473 static inline void load_stack_canary_segment(void)
12474 {
12475-#ifdef CONFIG_X86_32
12476+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12477 asm volatile ("mov %0, %%gs" : : "r" (0));
12478 #endif
12479 }
12480diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12481index 70bbe39..4ae2bd4 100644
12482--- a/arch/x86/include/asm/stacktrace.h
12483+++ b/arch/x86/include/asm/stacktrace.h
12484@@ -11,28 +11,20 @@
12485
12486 extern int kstack_depth_to_print;
12487
12488-struct thread_info;
12489+struct task_struct;
12490 struct stacktrace_ops;
12491
12492-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12493- unsigned long *stack,
12494- unsigned long bp,
12495- const struct stacktrace_ops *ops,
12496- void *data,
12497- unsigned long *end,
12498- int *graph);
12499+typedef unsigned long walk_stack_t(struct task_struct *task,
12500+ void *stack_start,
12501+ unsigned long *stack,
12502+ unsigned long bp,
12503+ const struct stacktrace_ops *ops,
12504+ void *data,
12505+ unsigned long *end,
12506+ int *graph);
12507
12508-extern unsigned long
12509-print_context_stack(struct thread_info *tinfo,
12510- unsigned long *stack, unsigned long bp,
12511- const struct stacktrace_ops *ops, void *data,
12512- unsigned long *end, int *graph);
12513-
12514-extern unsigned long
12515-print_context_stack_bp(struct thread_info *tinfo,
12516- unsigned long *stack, unsigned long bp,
12517- const struct stacktrace_ops *ops, void *data,
12518- unsigned long *end, int *graph);
12519+extern walk_stack_t print_context_stack;
12520+extern walk_stack_t print_context_stack_bp;
12521
12522 /* Generic stack tracer with callbacks */
12523
12524@@ -40,7 +32,7 @@ struct stacktrace_ops {
12525 void (*address)(void *data, unsigned long address, int reliable);
12526 /* On negative return stop dumping */
12527 int (*stack)(void *data, char *name);
12528- walk_stack_t walk_stack;
12529+ walk_stack_t *walk_stack;
12530 };
12531
12532 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12533diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12534index cb23852..2dde194 100644
12535--- a/arch/x86/include/asm/sys_ia32.h
12536+++ b/arch/x86/include/asm/sys_ia32.h
12537@@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
12538 compat_sigset_t __user *, unsigned int);
12539 asmlinkage long sys32_alarm(unsigned int);
12540
12541-asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12542+asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12543 asmlinkage long sys32_sysfs(int, u32, u32);
12544
12545 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12546diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
12547index 2d2f01c..f985723 100644
12548--- a/arch/x86/include/asm/system.h
12549+++ b/arch/x86/include/asm/system.h
12550@@ -129,7 +129,7 @@ do { \
12551 "call __switch_to\n\t" \
12552 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12553 __switch_canary \
12554- "movq %P[thread_info](%%rsi),%%r8\n\t" \
12555+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12556 "movq %%rax,%%rdi\n\t" \
12557 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12558 "jnz ret_from_fork\n\t" \
12559@@ -140,7 +140,7 @@ do { \
12560 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12561 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12562 [_tif_fork] "i" (_TIF_FORK), \
12563- [thread_info] "i" (offsetof(struct task_struct, stack)), \
12564+ [thread_info] "m" (current_tinfo), \
12565 [current_task] "m" (current_task) \
12566 __switch_canary_iparam \
12567 : "memory", "cc" __EXTRA_CLOBBER)
12568@@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
12569 {
12570 unsigned long __limit;
12571 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12572- return __limit + 1;
12573+ return __limit;
12574 }
12575
12576 static inline void native_clts(void)
12577@@ -397,13 +397,13 @@ void enable_hlt(void);
12578
12579 void cpu_idle_wait(void);
12580
12581-extern unsigned long arch_align_stack(unsigned long sp);
12582+#define arch_align_stack(x) ((x) & ~0xfUL)
12583 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
12584
12585 void default_idle(void);
12586 bool set_pm_idle_to_default(void);
12587
12588-void stop_this_cpu(void *dummy);
12589+void stop_this_cpu(void *dummy) __noreturn;
12590
12591 /*
12592 * Force strict CPU ordering.
12593diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12594index cfd8144..664ac89 100644
12595--- a/arch/x86/include/asm/thread_info.h
12596+++ b/arch/x86/include/asm/thread_info.h
12597@@ -10,6 +10,7 @@
12598 #include <linux/compiler.h>
12599 #include <asm/page.h>
12600 #include <asm/types.h>
12601+#include <asm/percpu.h>
12602
12603 /*
12604 * low level task data that entry.S needs immediate access to
12605@@ -24,7 +25,6 @@ struct exec_domain;
12606 #include <linux/atomic.h>
12607
12608 struct thread_info {
12609- struct task_struct *task; /* main task structure */
12610 struct exec_domain *exec_domain; /* execution domain */
12611 __u32 flags; /* low level flags */
12612 __u32 status; /* thread synchronous flags */
12613@@ -34,19 +34,13 @@ struct thread_info {
12614 mm_segment_t addr_limit;
12615 struct restart_block restart_block;
12616 void __user *sysenter_return;
12617-#ifdef CONFIG_X86_32
12618- unsigned long previous_esp; /* ESP of the previous stack in
12619- case of nested (IRQ) stacks
12620- */
12621- __u8 supervisor_stack[0];
12622-#endif
12623+ unsigned long lowest_stack;
12624 unsigned int sig_on_uaccess_error:1;
12625 unsigned int uaccess_err:1; /* uaccess failed */
12626 };
12627
12628-#define INIT_THREAD_INFO(tsk) \
12629+#define INIT_THREAD_INFO \
12630 { \
12631- .task = &tsk, \
12632 .exec_domain = &default_exec_domain, \
12633 .flags = 0, \
12634 .cpu = 0, \
12635@@ -57,7 +51,7 @@ struct thread_info {
12636 }, \
12637 }
12638
12639-#define init_thread_info (init_thread_union.thread_info)
12640+#define init_thread_info (init_thread_union.stack)
12641 #define init_stack (init_thread_union.stack)
12642
12643 #else /* !__ASSEMBLY__ */
12644@@ -95,6 +89,7 @@ struct thread_info {
12645 #define TIF_BLOCKSTEP 25 /* set when we want DEBUGCTLMSR_BTF */
12646 #define TIF_LAZY_MMU_UPDATES 27 /* task is updating the mmu lazily */
12647 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12648+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
12649
12650 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12651 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12652@@ -116,16 +111,17 @@ struct thread_info {
12653 #define _TIF_BLOCKSTEP (1 << TIF_BLOCKSTEP)
12654 #define _TIF_LAZY_MMU_UPDATES (1 << TIF_LAZY_MMU_UPDATES)
12655 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12656+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12657
12658 /* work to do in syscall_trace_enter() */
12659 #define _TIF_WORK_SYSCALL_ENTRY \
12660 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12661- _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12662+ _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12663
12664 /* work to do in syscall_trace_leave() */
12665 #define _TIF_WORK_SYSCALL_EXIT \
12666 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12667- _TIF_SYSCALL_TRACEPOINT)
12668+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12669
12670 /* work to do on interrupt/exception return */
12671 #define _TIF_WORK_MASK \
12672@@ -135,7 +131,8 @@ struct thread_info {
12673
12674 /* work to do on any return to user space */
12675 #define _TIF_ALLWORK_MASK \
12676- ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12677+ ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12678+ _TIF_GRSEC_SETXID)
12679
12680 /* Only used for 64 bit */
12681 #define _TIF_DO_NOTIFY_MASK \
12682@@ -169,45 +166,40 @@ struct thread_info {
12683 ret; \
12684 })
12685
12686-#ifdef CONFIG_X86_32
12687-
12688-#define STACK_WARN (THREAD_SIZE/8)
12689-/*
12690- * macros/functions for gaining access to the thread information structure
12691- *
12692- * preempt_count needs to be 1 initially, until the scheduler is functional.
12693- */
12694-#ifndef __ASSEMBLY__
12695-
12696-
12697-/* how to get the current stack pointer from C */
12698-register unsigned long current_stack_pointer asm("esp") __used;
12699-
12700-/* how to get the thread information struct from C */
12701-static inline struct thread_info *current_thread_info(void)
12702-{
12703- return (struct thread_info *)
12704- (current_stack_pointer & ~(THREAD_SIZE - 1));
12705-}
12706-
12707-#else /* !__ASSEMBLY__ */
12708-
12709+#ifdef __ASSEMBLY__
12710 /* how to get the thread information struct from ASM */
12711 #define GET_THREAD_INFO(reg) \
12712- movl $-THREAD_SIZE, reg; \
12713- andl %esp, reg
12714+ mov PER_CPU_VAR(current_tinfo), reg
12715
12716 /* use this one if reg already contains %esp */
12717-#define GET_THREAD_INFO_WITH_ESP(reg) \
12718- andl $-THREAD_SIZE, reg
12719+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12720+#else
12721+/* how to get the thread information struct from C */
12722+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12723+
12724+static __always_inline struct thread_info *current_thread_info(void)
12725+{
12726+ return percpu_read_stable(current_tinfo);
12727+}
12728+#endif
12729+
12730+#ifdef CONFIG_X86_32
12731+
12732+#define STACK_WARN (THREAD_SIZE/8)
12733+/*
12734+ * macros/functions for gaining access to the thread information structure
12735+ *
12736+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12737+ */
12738+#ifndef __ASSEMBLY__
12739+
12740+/* how to get the current stack pointer from C */
12741+register unsigned long current_stack_pointer asm("esp") __used;
12742
12743 #endif
12744
12745 #else /* X86_32 */
12746
12747-#include <asm/percpu.h>
12748-#define KERNEL_STACK_OFFSET (5*8)
12749-
12750 /*
12751 * macros/functions for gaining access to the thread information structure
12752 * preempt_count needs to be 1 initially, until the scheduler is functional.
12753@@ -215,27 +207,8 @@ static inline struct thread_info *current_thread_info(void)
12754 #ifndef __ASSEMBLY__
12755 DECLARE_PER_CPU(unsigned long, kernel_stack);
12756
12757-static inline struct thread_info *current_thread_info(void)
12758-{
12759- struct thread_info *ti;
12760- ti = (void *)(percpu_read_stable(kernel_stack) +
12761- KERNEL_STACK_OFFSET - THREAD_SIZE);
12762- return ti;
12763-}
12764-
12765-#else /* !__ASSEMBLY__ */
12766-
12767-/* how to get the thread information struct from ASM */
12768-#define GET_THREAD_INFO(reg) \
12769- movq PER_CPU_VAR(kernel_stack),reg ; \
12770- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12771-
12772-/*
12773- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12774- * a certain register (to be used in assembler memory operands).
12775- */
12776-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12777-
12778+/* how to get the current stack pointer from C */
12779+register unsigned long current_stack_pointer asm("rsp") __used;
12780 #endif
12781
12782 #endif /* !X86_32 */
12783@@ -269,5 +242,16 @@ extern void arch_task_cache_init(void);
12784 extern void free_thread_info(struct thread_info *ti);
12785 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12786 #define arch_task_cache_init arch_task_cache_init
12787+
12788+#define __HAVE_THREAD_FUNCTIONS
12789+#define task_thread_info(task) (&(task)->tinfo)
12790+#define task_stack_page(task) ((task)->stack)
12791+#define setup_thread_stack(p, org) do {} while (0)
12792+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12793+
12794+#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12795+extern struct task_struct *alloc_task_struct_node(int node);
12796+extern void free_task_struct(struct task_struct *);
12797+
12798 #endif
12799 #endif /* _ASM_X86_THREAD_INFO_H */
12800diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12801index 8be5f54..7ae826d 100644
12802--- a/arch/x86/include/asm/uaccess.h
12803+++ b/arch/x86/include/asm/uaccess.h
12804@@ -7,12 +7,15 @@
12805 #include <linux/compiler.h>
12806 #include <linux/thread_info.h>
12807 #include <linux/string.h>
12808+#include <linux/sched.h>
12809 #include <asm/asm.h>
12810 #include <asm/page.h>
12811
12812 #define VERIFY_READ 0
12813 #define VERIFY_WRITE 1
12814
12815+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12816+
12817 /*
12818 * The fs value determines whether argument validity checking should be
12819 * performed or not. If get_fs() == USER_DS, checking is performed, with
12820@@ -28,7 +31,12 @@
12821
12822 #define get_ds() (KERNEL_DS)
12823 #define get_fs() (current_thread_info()->addr_limit)
12824+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12825+void __set_fs(mm_segment_t x);
12826+void set_fs(mm_segment_t x);
12827+#else
12828 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12829+#endif
12830
12831 #define segment_eq(a, b) ((a).seg == (b).seg)
12832
12833@@ -76,7 +84,33 @@
12834 * checks that the pointer is in the user space range - after calling
12835 * this function, memory access functions may still return -EFAULT.
12836 */
12837-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12838+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12839+#define access_ok(type, addr, size) \
12840+({ \
12841+ long __size = size; \
12842+ unsigned long __addr = (unsigned long)addr; \
12843+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12844+ unsigned long __end_ao = __addr + __size - 1; \
12845+ bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12846+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12847+ while(__addr_ao <= __end_ao) { \
12848+ char __c_ao; \
12849+ __addr_ao += PAGE_SIZE; \
12850+ if (__size > PAGE_SIZE) \
12851+ cond_resched(); \
12852+ if (__get_user(__c_ao, (char __user *)__addr)) \
12853+ break; \
12854+ if (type != VERIFY_WRITE) { \
12855+ __addr = __addr_ao; \
12856+ continue; \
12857+ } \
12858+ if (__put_user(__c_ao, (char __user *)__addr)) \
12859+ break; \
12860+ __addr = __addr_ao; \
12861+ } \
12862+ } \
12863+ __ret_ao; \
12864+})
12865
12866 /*
12867 * The exception table consists of pairs of addresses: the first is the
12868@@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12869 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12870 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12871
12872-
12873+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12874+#define __copyuser_seg "gs;"
12875+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12876+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12877+#else
12878+#define __copyuser_seg
12879+#define __COPYUSER_SET_ES
12880+#define __COPYUSER_RESTORE_ES
12881+#endif
12882
12883 #ifdef CONFIG_X86_32
12884 #define __put_user_asm_u64(x, addr, err, errret) \
12885- asm volatile("1: movl %%eax,0(%2)\n" \
12886- "2: movl %%edx,4(%2)\n" \
12887+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12888+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12889 "3:\n" \
12890 ".section .fixup,\"ax\"\n" \
12891 "4: movl %3,%0\n" \
12892@@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12893 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12894
12895 #define __put_user_asm_ex_u64(x, addr) \
12896- asm volatile("1: movl %%eax,0(%1)\n" \
12897- "2: movl %%edx,4(%1)\n" \
12898+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12899+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12900 "3:\n" \
12901 _ASM_EXTABLE(1b, 2b - 1b) \
12902 _ASM_EXTABLE(2b, 3b - 2b) \
12903@@ -252,7 +294,7 @@ extern void __put_user_8(void);
12904 __typeof__(*(ptr)) __pu_val; \
12905 __chk_user_ptr(ptr); \
12906 might_fault(); \
12907- __pu_val = x; \
12908+ __pu_val = (x); \
12909 switch (sizeof(*(ptr))) { \
12910 case 1: \
12911 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12912@@ -373,7 +415,7 @@ do { \
12913 } while (0)
12914
12915 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12916- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12917+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12918 "2:\n" \
12919 ".section .fixup,\"ax\"\n" \
12920 "3: mov %3,%0\n" \
12921@@ -381,7 +423,7 @@ do { \
12922 " jmp 2b\n" \
12923 ".previous\n" \
12924 _ASM_EXTABLE(1b, 3b) \
12925- : "=r" (err), ltype(x) \
12926+ : "=r" (err), ltype (x) \
12927 : "m" (__m(addr)), "i" (errret), "0" (err))
12928
12929 #define __get_user_size_ex(x, ptr, size) \
12930@@ -406,7 +448,7 @@ do { \
12931 } while (0)
12932
12933 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12934- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12935+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12936 "2:\n" \
12937 _ASM_EXTABLE(1b, 2b - 1b) \
12938 : ltype(x) : "m" (__m(addr)))
12939@@ -423,13 +465,24 @@ do { \
12940 int __gu_err; \
12941 unsigned long __gu_val; \
12942 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12943- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12944+ (x) = (__typeof__(*(ptr)))__gu_val; \
12945 __gu_err; \
12946 })
12947
12948 /* FIXME: this hack is definitely wrong -AK */
12949 struct __large_struct { unsigned long buf[100]; };
12950-#define __m(x) (*(struct __large_struct __user *)(x))
12951+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12952+#define ____m(x) \
12953+({ \
12954+ unsigned long ____x = (unsigned long)(x); \
12955+ if (____x < PAX_USER_SHADOW_BASE) \
12956+ ____x += PAX_USER_SHADOW_BASE; \
12957+ (void __user *)____x; \
12958+})
12959+#else
12960+#define ____m(x) (x)
12961+#endif
12962+#define __m(x) (*(struct __large_struct __user *)____m(x))
12963
12964 /*
12965 * Tell gcc we read from memory instead of writing: this is because
12966@@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12967 * aliasing issues.
12968 */
12969 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12970- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12971+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12972 "2:\n" \
12973 ".section .fixup,\"ax\"\n" \
12974 "3: mov %3,%0\n" \
12975@@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12976 ".previous\n" \
12977 _ASM_EXTABLE(1b, 3b) \
12978 : "=r"(err) \
12979- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12980+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12981
12982 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12983- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12984+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12985 "2:\n" \
12986 _ASM_EXTABLE(1b, 2b - 1b) \
12987 : : ltype(x), "m" (__m(addr)))
12988@@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12989 * On error, the variable @x is set to zero.
12990 */
12991
12992+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12993+#define __get_user(x, ptr) get_user((x), (ptr))
12994+#else
12995 #define __get_user(x, ptr) \
12996 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12997+#endif
12998
12999 /**
13000 * __put_user: - Write a simple value into user space, with less checking.
13001@@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
13002 * Returns zero on success, or -EFAULT on error.
13003 */
13004
13005+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13006+#define __put_user(x, ptr) put_user((x), (ptr))
13007+#else
13008 #define __put_user(x, ptr) \
13009 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
13010+#endif
13011
13012 #define __get_user_unaligned __get_user
13013 #define __put_user_unaligned __put_user
13014@@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
13015 #define get_user_ex(x, ptr) do { \
13016 unsigned long __gue_val; \
13017 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
13018- (x) = (__force __typeof__(*(ptr)))__gue_val; \
13019+ (x) = (__typeof__(*(ptr)))__gue_val; \
13020 } while (0)
13021
13022 #ifdef CONFIG_X86_WP_WORKS_OK
13023diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
13024index 566e803..1230707 100644
13025--- a/arch/x86/include/asm/uaccess_32.h
13026+++ b/arch/x86/include/asm/uaccess_32.h
13027@@ -11,15 +11,15 @@
13028 #include <asm/page.h>
13029
13030 unsigned long __must_check __copy_to_user_ll
13031- (void __user *to, const void *from, unsigned long n);
13032+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
13033 unsigned long __must_check __copy_from_user_ll
13034- (void *to, const void __user *from, unsigned long n);
13035+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13036 unsigned long __must_check __copy_from_user_ll_nozero
13037- (void *to, const void __user *from, unsigned long n);
13038+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13039 unsigned long __must_check __copy_from_user_ll_nocache
13040- (void *to, const void __user *from, unsigned long n);
13041+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13042 unsigned long __must_check __copy_from_user_ll_nocache_nozero
13043- (void *to, const void __user *from, unsigned long n);
13044+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13045
13046 /**
13047 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
13048@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
13049 static __always_inline unsigned long __must_check
13050 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13051 {
13052+ if ((long)n < 0)
13053+ return n;
13054+
13055 if (__builtin_constant_p(n)) {
13056 unsigned long ret;
13057
13058@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13059 return ret;
13060 }
13061 }
13062+ if (!__builtin_constant_p(n))
13063+ check_object_size(from, n, true);
13064 return __copy_to_user_ll(to, from, n);
13065 }
13066
13067@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
13068 __copy_to_user(void __user *to, const void *from, unsigned long n)
13069 {
13070 might_fault();
13071+
13072 return __copy_to_user_inatomic(to, from, n);
13073 }
13074
13075 static __always_inline unsigned long
13076 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
13077 {
13078+ if ((long)n < 0)
13079+ return n;
13080+
13081 /* Avoid zeroing the tail if the copy fails..
13082 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
13083 * but as the zeroing behaviour is only significant when n is not
13084@@ -137,6 +146,10 @@ static __always_inline unsigned long
13085 __copy_from_user(void *to, const void __user *from, unsigned long n)
13086 {
13087 might_fault();
13088+
13089+ if ((long)n < 0)
13090+ return n;
13091+
13092 if (__builtin_constant_p(n)) {
13093 unsigned long ret;
13094
13095@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
13096 return ret;
13097 }
13098 }
13099+ if (!__builtin_constant_p(n))
13100+ check_object_size(to, n, false);
13101 return __copy_from_user_ll(to, from, n);
13102 }
13103
13104@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
13105 const void __user *from, unsigned long n)
13106 {
13107 might_fault();
13108+
13109+ if ((long)n < 0)
13110+ return n;
13111+
13112 if (__builtin_constant_p(n)) {
13113 unsigned long ret;
13114
13115@@ -181,15 +200,19 @@ static __always_inline unsigned long
13116 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13117 unsigned long n)
13118 {
13119- return __copy_from_user_ll_nocache_nozero(to, from, n);
13120+ if ((long)n < 0)
13121+ return n;
13122+
13123+ return __copy_from_user_ll_nocache_nozero(to, from, n);
13124 }
13125
13126-unsigned long __must_check copy_to_user(void __user *to,
13127- const void *from, unsigned long n);
13128-unsigned long __must_check _copy_from_user(void *to,
13129- const void __user *from,
13130- unsigned long n);
13131-
13132+extern void copy_to_user_overflow(void)
13133+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13134+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13135+#else
13136+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13137+#endif
13138+;
13139
13140 extern void copy_from_user_overflow(void)
13141 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13142@@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
13143 #endif
13144 ;
13145
13146-static inline unsigned long __must_check copy_from_user(void *to,
13147- const void __user *from,
13148- unsigned long n)
13149+/**
13150+ * copy_to_user: - Copy a block of data into user space.
13151+ * @to: Destination address, in user space.
13152+ * @from: Source address, in kernel space.
13153+ * @n: Number of bytes to copy.
13154+ *
13155+ * Context: User context only. This function may sleep.
13156+ *
13157+ * Copy data from kernel space to user space.
13158+ *
13159+ * Returns number of bytes that could not be copied.
13160+ * On success, this will be zero.
13161+ */
13162+static inline unsigned long __must_check
13163+copy_to_user(void __user *to, const void *from, unsigned long n)
13164+{
13165+ int sz = __compiletime_object_size(from);
13166+
13167+ if (unlikely(sz != -1 && sz < n))
13168+ copy_to_user_overflow();
13169+ else if (access_ok(VERIFY_WRITE, to, n))
13170+ n = __copy_to_user(to, from, n);
13171+ return n;
13172+}
13173+
13174+/**
13175+ * copy_from_user: - Copy a block of data from user space.
13176+ * @to: Destination address, in kernel space.
13177+ * @from: Source address, in user space.
13178+ * @n: Number of bytes to copy.
13179+ *
13180+ * Context: User context only. This function may sleep.
13181+ *
13182+ * Copy data from user space to kernel space.
13183+ *
13184+ * Returns number of bytes that could not be copied.
13185+ * On success, this will be zero.
13186+ *
13187+ * If some data could not be copied, this function will pad the copied
13188+ * data to the requested size using zero bytes.
13189+ */
13190+static inline unsigned long __must_check
13191+copy_from_user(void *to, const void __user *from, unsigned long n)
13192 {
13193 int sz = __compiletime_object_size(to);
13194
13195- if (likely(sz == -1 || sz >= n))
13196- n = _copy_from_user(to, from, n);
13197- else
13198+ if (unlikely(sz != -1 && sz < n))
13199 copy_from_user_overflow();
13200-
13201+ else if (access_ok(VERIFY_READ, from, n))
13202+ n = __copy_from_user(to, from, n);
13203+ else if ((long)n > 0) {
13204+ if (!__builtin_constant_p(n))
13205+ check_object_size(to, n, false);
13206+ memset(to, 0, n);
13207+ }
13208 return n;
13209 }
13210
13211@@ -235,7 +302,7 @@ long __must_check __strncpy_from_user(char *dst,
13212 #define strlen_user(str) strnlen_user(str, LONG_MAX)
13213
13214 long strnlen_user(const char __user *str, long n);
13215-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13216-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13217+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13218+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13219
13220 #endif /* _ASM_X86_UACCESS_32_H */
13221diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13222index 1c66d30..bf1a2cc 100644
13223--- a/arch/x86/include/asm/uaccess_64.h
13224+++ b/arch/x86/include/asm/uaccess_64.h
13225@@ -10,6 +10,9 @@
13226 #include <asm/alternative.h>
13227 #include <asm/cpufeature.h>
13228 #include <asm/page.h>
13229+#include <asm/pgtable.h>
13230+
13231+#define set_fs(x) (current_thread_info()->addr_limit = (x))
13232
13233 /*
13234 * Copy To/From Userspace
13235@@ -17,12 +20,14 @@
13236
13237 /* Handles exceptions in both to and from, but doesn't do access_ok */
13238 __must_check unsigned long
13239-copy_user_generic_string(void *to, const void *from, unsigned len);
13240+copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13241 __must_check unsigned long
13242-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13243+copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13244
13245 static __always_inline __must_check unsigned long
13246-copy_user_generic(void *to, const void *from, unsigned len)
13247+copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13248+static __always_inline __must_check unsigned long
13249+copy_user_generic(void *to, const void *from, unsigned long len)
13250 {
13251 unsigned ret;
13252
13253@@ -32,142 +37,226 @@ copy_user_generic(void *to, const void *from, unsigned len)
13254 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13255 "=d" (len)),
13256 "1" (to), "2" (from), "3" (len)
13257- : "memory", "rcx", "r8", "r9", "r10", "r11");
13258+ : "memory", "rcx", "r8", "r9", "r11");
13259 return ret;
13260 }
13261
13262+static __always_inline __must_check unsigned long
13263+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13264+static __always_inline __must_check unsigned long
13265+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13266 __must_check unsigned long
13267-_copy_to_user(void __user *to, const void *from, unsigned len);
13268-__must_check unsigned long
13269-_copy_from_user(void *to, const void __user *from, unsigned len);
13270-__must_check unsigned long
13271-copy_in_user(void __user *to, const void __user *from, unsigned len);
13272+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13273
13274 static inline unsigned long __must_check copy_from_user(void *to,
13275 const void __user *from,
13276 unsigned long n)
13277 {
13278- int sz = __compiletime_object_size(to);
13279-
13280 might_fault();
13281- if (likely(sz == -1 || sz >= n))
13282- n = _copy_from_user(to, from, n);
13283-#ifdef CONFIG_DEBUG_VM
13284- else
13285- WARN(1, "Buffer overflow detected!\n");
13286-#endif
13287+
13288+ if (access_ok(VERIFY_READ, from, n))
13289+ n = __copy_from_user(to, from, n);
13290+ else if (n < INT_MAX) {
13291+ if (!__builtin_constant_p(n))
13292+ check_object_size(to, n, false);
13293+ memset(to, 0, n);
13294+ }
13295 return n;
13296 }
13297
13298 static __always_inline __must_check
13299-int copy_to_user(void __user *dst, const void *src, unsigned size)
13300+int copy_to_user(void __user *dst, const void *src, unsigned long size)
13301 {
13302 might_fault();
13303
13304- return _copy_to_user(dst, src, size);
13305+ if (access_ok(VERIFY_WRITE, dst, size))
13306+ size = __copy_to_user(dst, src, size);
13307+ return size;
13308 }
13309
13310 static __always_inline __must_check
13311-int __copy_from_user(void *dst, const void __user *src, unsigned size)
13312+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13313 {
13314- int ret = 0;
13315+ int sz = __compiletime_object_size(dst);
13316+ unsigned ret = 0;
13317
13318 might_fault();
13319- if (!__builtin_constant_p(size))
13320- return copy_user_generic(dst, (__force void *)src, size);
13321+
13322+ if (size > INT_MAX)
13323+ return size;
13324+
13325+#ifdef CONFIG_PAX_MEMORY_UDEREF
13326+ if (!__access_ok(VERIFY_READ, src, size))
13327+ return size;
13328+#endif
13329+
13330+ if (unlikely(sz != -1 && sz < size)) {
13331+#ifdef CONFIG_DEBUG_VM
13332+ WARN(1, "Buffer overflow detected!\n");
13333+#endif
13334+ return size;
13335+ }
13336+
13337+ if (!__builtin_constant_p(size)) {
13338+ check_object_size(dst, size, false);
13339+
13340+#ifdef CONFIG_PAX_MEMORY_UDEREF
13341+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13342+ src += PAX_USER_SHADOW_BASE;
13343+#endif
13344+
13345+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13346+ }
13347 switch (size) {
13348- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13349+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13350 ret, "b", "b", "=q", 1);
13351 return ret;
13352- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13353+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13354 ret, "w", "w", "=r", 2);
13355 return ret;
13356- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13357+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13358 ret, "l", "k", "=r", 4);
13359 return ret;
13360- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13361+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13362 ret, "q", "", "=r", 8);
13363 return ret;
13364 case 10:
13365- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13366+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13367 ret, "q", "", "=r", 10);
13368 if (unlikely(ret))
13369 return ret;
13370 __get_user_asm(*(u16 *)(8 + (char *)dst),
13371- (u16 __user *)(8 + (char __user *)src),
13372+ (const u16 __user *)(8 + (const char __user *)src),
13373 ret, "w", "w", "=r", 2);
13374 return ret;
13375 case 16:
13376- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13377+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13378 ret, "q", "", "=r", 16);
13379 if (unlikely(ret))
13380 return ret;
13381 __get_user_asm(*(u64 *)(8 + (char *)dst),
13382- (u64 __user *)(8 + (char __user *)src),
13383+ (const u64 __user *)(8 + (const char __user *)src),
13384 ret, "q", "", "=r", 8);
13385 return ret;
13386 default:
13387- return copy_user_generic(dst, (__force void *)src, size);
13388+
13389+#ifdef CONFIG_PAX_MEMORY_UDEREF
13390+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13391+ src += PAX_USER_SHADOW_BASE;
13392+#endif
13393+
13394+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13395 }
13396 }
13397
13398 static __always_inline __must_check
13399-int __copy_to_user(void __user *dst, const void *src, unsigned size)
13400+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13401 {
13402- int ret = 0;
13403+ int sz = __compiletime_object_size(src);
13404+ unsigned ret = 0;
13405
13406 might_fault();
13407- if (!__builtin_constant_p(size))
13408- return copy_user_generic((__force void *)dst, src, size);
13409+
13410+ if (size > INT_MAX)
13411+ return size;
13412+
13413+#ifdef CONFIG_PAX_MEMORY_UDEREF
13414+ if (!__access_ok(VERIFY_WRITE, dst, size))
13415+ return size;
13416+#endif
13417+
13418+ if (unlikely(sz != -1 && sz < size)) {
13419+#ifdef CONFIG_DEBUG_VM
13420+ WARN(1, "Buffer overflow detected!\n");
13421+#endif
13422+ return size;
13423+ }
13424+
13425+ if (!__builtin_constant_p(size)) {
13426+ check_object_size(src, size, true);
13427+
13428+#ifdef CONFIG_PAX_MEMORY_UDEREF
13429+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13430+ dst += PAX_USER_SHADOW_BASE;
13431+#endif
13432+
13433+ return copy_user_generic((__force_kernel void *)dst, src, size);
13434+ }
13435 switch (size) {
13436- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13437+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13438 ret, "b", "b", "iq", 1);
13439 return ret;
13440- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13441+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13442 ret, "w", "w", "ir", 2);
13443 return ret;
13444- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13445+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13446 ret, "l", "k", "ir", 4);
13447 return ret;
13448- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13449+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13450 ret, "q", "", "er", 8);
13451 return ret;
13452 case 10:
13453- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13454+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13455 ret, "q", "", "er", 10);
13456 if (unlikely(ret))
13457 return ret;
13458 asm("":::"memory");
13459- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13460+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13461 ret, "w", "w", "ir", 2);
13462 return ret;
13463 case 16:
13464- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13465+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13466 ret, "q", "", "er", 16);
13467 if (unlikely(ret))
13468 return ret;
13469 asm("":::"memory");
13470- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13471+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13472 ret, "q", "", "er", 8);
13473 return ret;
13474 default:
13475- return copy_user_generic((__force void *)dst, src, size);
13476+
13477+#ifdef CONFIG_PAX_MEMORY_UDEREF
13478+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13479+ dst += PAX_USER_SHADOW_BASE;
13480+#endif
13481+
13482+ return copy_user_generic((__force_kernel void *)dst, src, size);
13483 }
13484 }
13485
13486 static __always_inline __must_check
13487-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13488+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13489 {
13490- int ret = 0;
13491+ unsigned ret = 0;
13492
13493 might_fault();
13494- if (!__builtin_constant_p(size))
13495- return copy_user_generic((__force void *)dst,
13496- (__force void *)src, size);
13497+
13498+ if (size > INT_MAX)
13499+ return size;
13500+
13501+#ifdef CONFIG_PAX_MEMORY_UDEREF
13502+ if (!__access_ok(VERIFY_READ, src, size))
13503+ return size;
13504+ if (!__access_ok(VERIFY_WRITE, dst, size))
13505+ return size;
13506+#endif
13507+
13508+ if (!__builtin_constant_p(size)) {
13509+
13510+#ifdef CONFIG_PAX_MEMORY_UDEREF
13511+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13512+ src += PAX_USER_SHADOW_BASE;
13513+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13514+ dst += PAX_USER_SHADOW_BASE;
13515+#endif
13516+
13517+ return copy_user_generic((__force_kernel void *)dst,
13518+ (__force_kernel const void *)src, size);
13519+ }
13520 switch (size) {
13521 case 1: {
13522 u8 tmp;
13523- __get_user_asm(tmp, (u8 __user *)src,
13524+ __get_user_asm(tmp, (const u8 __user *)src,
13525 ret, "b", "b", "=q", 1);
13526 if (likely(!ret))
13527 __put_user_asm(tmp, (u8 __user *)dst,
13528@@ -176,7 +265,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13529 }
13530 case 2: {
13531 u16 tmp;
13532- __get_user_asm(tmp, (u16 __user *)src,
13533+ __get_user_asm(tmp, (const u16 __user *)src,
13534 ret, "w", "w", "=r", 2);
13535 if (likely(!ret))
13536 __put_user_asm(tmp, (u16 __user *)dst,
13537@@ -186,7 +275,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13538
13539 case 4: {
13540 u32 tmp;
13541- __get_user_asm(tmp, (u32 __user *)src,
13542+ __get_user_asm(tmp, (const u32 __user *)src,
13543 ret, "l", "k", "=r", 4);
13544 if (likely(!ret))
13545 __put_user_asm(tmp, (u32 __user *)dst,
13546@@ -195,7 +284,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13547 }
13548 case 8: {
13549 u64 tmp;
13550- __get_user_asm(tmp, (u64 __user *)src,
13551+ __get_user_asm(tmp, (const u64 __user *)src,
13552 ret, "q", "", "=r", 8);
13553 if (likely(!ret))
13554 __put_user_asm(tmp, (u64 __user *)dst,
13555@@ -203,8 +292,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13556 return ret;
13557 }
13558 default:
13559- return copy_user_generic((__force void *)dst,
13560- (__force void *)src, size);
13561+
13562+#ifdef CONFIG_PAX_MEMORY_UDEREF
13563+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13564+ src += PAX_USER_SHADOW_BASE;
13565+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13566+ dst += PAX_USER_SHADOW_BASE;
13567+#endif
13568+
13569+ return copy_user_generic((__force_kernel void *)dst,
13570+ (__force_kernel const void *)src, size);
13571 }
13572 }
13573
13574@@ -215,39 +312,76 @@ __strncpy_from_user(char *dst, const char __user *src, long count);
13575 __must_check long strnlen_user(const char __user *str, long n);
13576 __must_check long __strnlen_user(const char __user *str, long n);
13577 __must_check long strlen_user(const char __user *str);
13578-__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13579-__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13580+__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13581+__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13582
13583 static __must_check __always_inline int
13584-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13585+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13586 {
13587- return copy_user_generic(dst, (__force const void *)src, size);
13588+ if (size > INT_MAX)
13589+ return size;
13590+
13591+#ifdef CONFIG_PAX_MEMORY_UDEREF
13592+ if (!__access_ok(VERIFY_READ, src, size))
13593+ return size;
13594+
13595+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13596+ src += PAX_USER_SHADOW_BASE;
13597+#endif
13598+
13599+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13600 }
13601
13602-static __must_check __always_inline int
13603-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13604+static __must_check __always_inline unsigned long
13605+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13606 {
13607- return copy_user_generic((__force void *)dst, src, size);
13608+ if (size > INT_MAX)
13609+ return size;
13610+
13611+#ifdef CONFIG_PAX_MEMORY_UDEREF
13612+ if (!__access_ok(VERIFY_WRITE, dst, size))
13613+ return size;
13614+
13615+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13616+ dst += PAX_USER_SHADOW_BASE;
13617+#endif
13618+
13619+ return copy_user_generic((__force_kernel void *)dst, src, size);
13620 }
13621
13622-extern long __copy_user_nocache(void *dst, const void __user *src,
13623- unsigned size, int zerorest);
13624+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13625+ unsigned long size, int zerorest) __size_overflow(3);
13626
13627-static inline int
13628-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13629+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13630 {
13631 might_sleep();
13632+
13633+ if (size > INT_MAX)
13634+ return size;
13635+
13636+#ifdef CONFIG_PAX_MEMORY_UDEREF
13637+ if (!__access_ok(VERIFY_READ, src, size))
13638+ return size;
13639+#endif
13640+
13641 return __copy_user_nocache(dst, src, size, 1);
13642 }
13643
13644-static inline int
13645-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13646- unsigned size)
13647+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13648+ unsigned long size)
13649 {
13650+ if (size > INT_MAX)
13651+ return size;
13652+
13653+#ifdef CONFIG_PAX_MEMORY_UDEREF
13654+ if (!__access_ok(VERIFY_READ, src, size))
13655+ return size;
13656+#endif
13657+
13658 return __copy_user_nocache(dst, src, size, 0);
13659 }
13660
13661-unsigned long
13662-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13663+extern unsigned long
13664+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13665
13666 #endif /* _ASM_X86_UACCESS_64_H */
13667diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13668index bb05228..d763d5b 100644
13669--- a/arch/x86/include/asm/vdso.h
13670+++ b/arch/x86/include/asm/vdso.h
13671@@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13672 #define VDSO32_SYMBOL(base, name) \
13673 ({ \
13674 extern const char VDSO32_##name[]; \
13675- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13676+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13677 })
13678 #endif
13679
13680diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13681index a609c39..7a68dc7 100644
13682--- a/arch/x86/include/asm/x86_init.h
13683+++ b/arch/x86/include/asm/x86_init.h
13684@@ -29,7 +29,7 @@ struct x86_init_mpparse {
13685 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13686 void (*find_smp_config)(void);
13687 void (*get_smp_config)(unsigned int early);
13688-};
13689+} __no_const;
13690
13691 /**
13692 * struct x86_init_resources - platform specific resource related ops
13693@@ -43,7 +43,7 @@ struct x86_init_resources {
13694 void (*probe_roms)(void);
13695 void (*reserve_resources)(void);
13696 char *(*memory_setup)(void);
13697-};
13698+} __no_const;
13699
13700 /**
13701 * struct x86_init_irqs - platform specific interrupt setup
13702@@ -56,7 +56,7 @@ struct x86_init_irqs {
13703 void (*pre_vector_init)(void);
13704 void (*intr_init)(void);
13705 void (*trap_init)(void);
13706-};
13707+} __no_const;
13708
13709 /**
13710 * struct x86_init_oem - oem platform specific customizing functions
13711@@ -66,7 +66,7 @@ struct x86_init_irqs {
13712 struct x86_init_oem {
13713 void (*arch_setup)(void);
13714 void (*banner)(void);
13715-};
13716+} __no_const;
13717
13718 /**
13719 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13720@@ -77,7 +77,7 @@ struct x86_init_oem {
13721 */
13722 struct x86_init_mapping {
13723 void (*pagetable_reserve)(u64 start, u64 end);
13724-};
13725+} __no_const;
13726
13727 /**
13728 * struct x86_init_paging - platform specific paging functions
13729@@ -87,7 +87,7 @@ struct x86_init_mapping {
13730 struct x86_init_paging {
13731 void (*pagetable_setup_start)(pgd_t *base);
13732 void (*pagetable_setup_done)(pgd_t *base);
13733-};
13734+} __no_const;
13735
13736 /**
13737 * struct x86_init_timers - platform specific timer setup
13738@@ -102,7 +102,7 @@ struct x86_init_timers {
13739 void (*tsc_pre_init)(void);
13740 void (*timer_init)(void);
13741 void (*wallclock_init)(void);
13742-};
13743+} __no_const;
13744
13745 /**
13746 * struct x86_init_iommu - platform specific iommu setup
13747@@ -110,7 +110,7 @@ struct x86_init_timers {
13748 */
13749 struct x86_init_iommu {
13750 int (*iommu_init)(void);
13751-};
13752+} __no_const;
13753
13754 /**
13755 * struct x86_init_pci - platform specific pci init functions
13756@@ -124,7 +124,7 @@ struct x86_init_pci {
13757 int (*init)(void);
13758 void (*init_irq)(void);
13759 void (*fixup_irqs)(void);
13760-};
13761+} __no_const;
13762
13763 /**
13764 * struct x86_init_ops - functions for platform specific setup
13765@@ -140,7 +140,7 @@ struct x86_init_ops {
13766 struct x86_init_timers timers;
13767 struct x86_init_iommu iommu;
13768 struct x86_init_pci pci;
13769-};
13770+} __no_const;
13771
13772 /**
13773 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13774@@ -149,7 +149,7 @@ struct x86_init_ops {
13775 struct x86_cpuinit_ops {
13776 void (*setup_percpu_clockev)(void);
13777 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13778-};
13779+} __no_const;
13780
13781 /**
13782 * struct x86_platform_ops - platform specific runtime functions
13783@@ -171,7 +171,7 @@ struct x86_platform_ops {
13784 void (*nmi_init)(void);
13785 unsigned char (*get_nmi_reason)(void);
13786 int (*i8042_detect)(void);
13787-};
13788+} __no_const;
13789
13790 struct pci_dev;
13791
13792@@ -180,7 +180,7 @@ struct x86_msi_ops {
13793 void (*teardown_msi_irq)(unsigned int irq);
13794 void (*teardown_msi_irqs)(struct pci_dev *dev);
13795 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13796-};
13797+} __no_const;
13798
13799 extern struct x86_init_ops x86_init;
13800 extern struct x86_cpuinit_ops x86_cpuinit;
13801diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13802index c6ce245..ffbdab7 100644
13803--- a/arch/x86/include/asm/xsave.h
13804+++ b/arch/x86/include/asm/xsave.h
13805@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13806 {
13807 int err;
13808
13809+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13810+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13811+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13812+#endif
13813+
13814 /*
13815 * Clear the xsave header first, so that reserved fields are
13816 * initialized to zero.
13817@@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13818 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13819 {
13820 int err;
13821- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13822+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13823 u32 lmask = mask;
13824 u32 hmask = mask >> 32;
13825
13826+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13827+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13828+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13829+#endif
13830+
13831 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13832 "2:\n"
13833 ".section .fixup,\"ax\"\n"
13834diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13835index 6a564ac..9b1340c 100644
13836--- a/arch/x86/kernel/acpi/realmode/Makefile
13837+++ b/arch/x86/kernel/acpi/realmode/Makefile
13838@@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13839 $(call cc-option, -fno-stack-protector) \
13840 $(call cc-option, -mpreferred-stack-boundary=2)
13841 KBUILD_CFLAGS += $(call cc-option, -m32)
13842+ifdef CONSTIFY_PLUGIN
13843+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13844+endif
13845 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13846 GCOV_PROFILE := n
13847
13848diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13849index b4fd836..4358fe3 100644
13850--- a/arch/x86/kernel/acpi/realmode/wakeup.S
13851+++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13852@@ -108,6 +108,9 @@ wakeup_code:
13853 /* Do any other stuff... */
13854
13855 #ifndef CONFIG_64BIT
13856+ /* Recheck NX bit overrides (64bit path does this in trampoline */
13857+ call verify_cpu
13858+
13859 /* This could also be done in C code... */
13860 movl pmode_cr3, %eax
13861 movl %eax, %cr3
13862@@ -131,6 +134,7 @@ wakeup_code:
13863 movl pmode_cr0, %eax
13864 movl %eax, %cr0
13865 jmp pmode_return
13866+# include "../../verify_cpu.S"
13867 #else
13868 pushw $0
13869 pushw trampoline_segment
13870diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13871index 103b6ab..2004d0a 100644
13872--- a/arch/x86/kernel/acpi/sleep.c
13873+++ b/arch/x86/kernel/acpi/sleep.c
13874@@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
13875 header->trampoline_segment = trampoline_address() >> 4;
13876 #ifdef CONFIG_SMP
13877 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13878+
13879+ pax_open_kernel();
13880 early_gdt_descr.address =
13881 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13882+ pax_close_kernel();
13883+
13884 initial_gs = per_cpu_offset(smp_processor_id());
13885 #endif
13886 initial_code = (unsigned long)wakeup_long64;
13887diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13888index 13ab720..95d5442 100644
13889--- a/arch/x86/kernel/acpi/wakeup_32.S
13890+++ b/arch/x86/kernel/acpi/wakeup_32.S
13891@@ -30,13 +30,11 @@ wakeup_pmode_return:
13892 # and restore the stack ... but you need gdt for this to work
13893 movl saved_context_esp, %esp
13894
13895- movl %cs:saved_magic, %eax
13896- cmpl $0x12345678, %eax
13897+ cmpl $0x12345678, saved_magic
13898 jne bogus_magic
13899
13900 # jump to place where we left off
13901- movl saved_eip, %eax
13902- jmp *%eax
13903+ jmp *(saved_eip)
13904
13905 bogus_magic:
13906 jmp bogus_magic
13907diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13908index 1f84794..e23f862 100644
13909--- a/arch/x86/kernel/alternative.c
13910+++ b/arch/x86/kernel/alternative.c
13911@@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13912 */
13913 for (a = start; a < end; a++) {
13914 instr = (u8 *)&a->instr_offset + a->instr_offset;
13915+
13916+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13917+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13918+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13919+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13920+#endif
13921+
13922 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13923 BUG_ON(a->replacementlen > a->instrlen);
13924 BUG_ON(a->instrlen > sizeof(insnbuf));
13925@@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13926 for (poff = start; poff < end; poff++) {
13927 u8 *ptr = (u8 *)poff + *poff;
13928
13929+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13930+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13931+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13932+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13933+#endif
13934+
13935 if (!*poff || ptr < text || ptr >= text_end)
13936 continue;
13937 /* turn DS segment override prefix into lock prefix */
13938- if (*ptr == 0x3e)
13939+ if (*ktla_ktva(ptr) == 0x3e)
13940 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13941 };
13942 mutex_unlock(&text_mutex);
13943@@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13944 for (poff = start; poff < end; poff++) {
13945 u8 *ptr = (u8 *)poff + *poff;
13946
13947+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13948+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13949+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13950+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13951+#endif
13952+
13953 if (!*poff || ptr < text || ptr >= text_end)
13954 continue;
13955 /* turn lock prefix into DS segment override prefix */
13956- if (*ptr == 0xf0)
13957+ if (*ktla_ktva(ptr) == 0xf0)
13958 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13959 };
13960 mutex_unlock(&text_mutex);
13961@@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13962
13963 BUG_ON(p->len > MAX_PATCH_LEN);
13964 /* prep the buffer with the original instructions */
13965- memcpy(insnbuf, p->instr, p->len);
13966+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13967 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13968 (unsigned long)p->instr, p->len);
13969
13970@@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13971 if (smp_alt_once)
13972 free_init_pages("SMP alternatives",
13973 (unsigned long)__smp_locks,
13974- (unsigned long)__smp_locks_end);
13975+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13976
13977 restart_nmi();
13978 }
13979@@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13980 * instructions. And on the local CPU you need to be protected again NMI or MCE
13981 * handlers seeing an inconsistent instruction while you patch.
13982 */
13983-void *__init_or_module text_poke_early(void *addr, const void *opcode,
13984+void *__kprobes text_poke_early(void *addr, const void *opcode,
13985 size_t len)
13986 {
13987 unsigned long flags;
13988 local_irq_save(flags);
13989- memcpy(addr, opcode, len);
13990+
13991+ pax_open_kernel();
13992+ memcpy(ktla_ktva(addr), opcode, len);
13993 sync_core();
13994+ pax_close_kernel();
13995+
13996 local_irq_restore(flags);
13997 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13998 that causes hangs on some VIA CPUs. */
13999@@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
14000 */
14001 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
14002 {
14003- unsigned long flags;
14004- char *vaddr;
14005+ unsigned char *vaddr = ktla_ktva(addr);
14006 struct page *pages[2];
14007- int i;
14008+ size_t i;
14009
14010 if (!core_kernel_text((unsigned long)addr)) {
14011- pages[0] = vmalloc_to_page(addr);
14012- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
14013+ pages[0] = vmalloc_to_page(vaddr);
14014+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
14015 } else {
14016- pages[0] = virt_to_page(addr);
14017+ pages[0] = virt_to_page(vaddr);
14018 WARN_ON(!PageReserved(pages[0]));
14019- pages[1] = virt_to_page(addr + PAGE_SIZE);
14020+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
14021 }
14022 BUG_ON(!pages[0]);
14023- local_irq_save(flags);
14024- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
14025- if (pages[1])
14026- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
14027- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
14028- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
14029- clear_fixmap(FIX_TEXT_POKE0);
14030- if (pages[1])
14031- clear_fixmap(FIX_TEXT_POKE1);
14032- local_flush_tlb();
14033- sync_core();
14034- /* Could also do a CLFLUSH here to speed up CPU recovery; but
14035- that causes hangs on some VIA CPUs. */
14036+ text_poke_early(addr, opcode, len);
14037 for (i = 0; i < len; i++)
14038- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
14039- local_irq_restore(flags);
14040+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
14041 return addr;
14042 }
14043
14044diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
14045index 5b3f88e..61232b4 100644
14046--- a/arch/x86/kernel/apic/apic.c
14047+++ b/arch/x86/kernel/apic/apic.c
14048@@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
14049 /*
14050 * Debug level, exported for io_apic.c
14051 */
14052-unsigned int apic_verbosity;
14053+int apic_verbosity;
14054
14055 int pic_mode;
14056
14057@@ -1912,7 +1912,7 @@ void smp_error_interrupt(struct pt_regs *regs)
14058 apic_write(APIC_ESR, 0);
14059 v1 = apic_read(APIC_ESR);
14060 ack_APIC_irq();
14061- atomic_inc(&irq_err_count);
14062+ atomic_inc_unchecked(&irq_err_count);
14063
14064 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
14065 smp_processor_id(), v0 , v1);
14066diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
14067index fb07275..e06bb59 100644
14068--- a/arch/x86/kernel/apic/io_apic.c
14069+++ b/arch/x86/kernel/apic/io_apic.c
14070@@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
14071 }
14072 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
14073
14074-void lock_vector_lock(void)
14075+void lock_vector_lock(void) __acquires(vector_lock)
14076 {
14077 /* Used to the online set of cpus does not change
14078 * during assign_irq_vector.
14079@@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
14080 raw_spin_lock(&vector_lock);
14081 }
14082
14083-void unlock_vector_lock(void)
14084+void unlock_vector_lock(void) __releases(vector_lock)
14085 {
14086 raw_spin_unlock(&vector_lock);
14087 }
14088@@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
14089 ack_APIC_irq();
14090 }
14091
14092-atomic_t irq_mis_count;
14093+atomic_unchecked_t irq_mis_count;
14094
14095 static void ack_apic_level(struct irq_data *data)
14096 {
14097@@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
14098 * at the cpu.
14099 */
14100 if (!(v & (1 << (i & 0x1f)))) {
14101- atomic_inc(&irq_mis_count);
14102+ atomic_inc_unchecked(&irq_mis_count);
14103
14104 eoi_ioapic_irq(irq, cfg);
14105 }
14106diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14107index f76623c..aab694f 100644
14108--- a/arch/x86/kernel/apm_32.c
14109+++ b/arch/x86/kernel/apm_32.c
14110@@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
14111 * This is for buggy BIOS's that refer to (real mode) segment 0x40
14112 * even though they are called in protected mode.
14113 */
14114-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14115+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14116 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14117
14118 static const char driver_version[] = "1.16ac"; /* no spaces */
14119@@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
14120 BUG_ON(cpu != 0);
14121 gdt = get_cpu_gdt_table(cpu);
14122 save_desc_40 = gdt[0x40 / 8];
14123+
14124+ pax_open_kernel();
14125 gdt[0x40 / 8] = bad_bios_desc;
14126+ pax_close_kernel();
14127
14128 apm_irq_save(flags);
14129 APM_DO_SAVE_SEGS;
14130@@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
14131 &call->esi);
14132 APM_DO_RESTORE_SEGS;
14133 apm_irq_restore(flags);
14134+
14135+ pax_open_kernel();
14136 gdt[0x40 / 8] = save_desc_40;
14137+ pax_close_kernel();
14138+
14139 put_cpu();
14140
14141 return call->eax & 0xff;
14142@@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
14143 BUG_ON(cpu != 0);
14144 gdt = get_cpu_gdt_table(cpu);
14145 save_desc_40 = gdt[0x40 / 8];
14146+
14147+ pax_open_kernel();
14148 gdt[0x40 / 8] = bad_bios_desc;
14149+ pax_close_kernel();
14150
14151 apm_irq_save(flags);
14152 APM_DO_SAVE_SEGS;
14153@@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
14154 &call->eax);
14155 APM_DO_RESTORE_SEGS;
14156 apm_irq_restore(flags);
14157+
14158+ pax_open_kernel();
14159 gdt[0x40 / 8] = save_desc_40;
14160+ pax_close_kernel();
14161+
14162 put_cpu();
14163 return error;
14164 }
14165@@ -2347,12 +2361,15 @@ static int __init apm_init(void)
14166 * code to that CPU.
14167 */
14168 gdt = get_cpu_gdt_table(0);
14169+
14170+ pax_open_kernel();
14171 set_desc_base(&gdt[APM_CS >> 3],
14172 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14173 set_desc_base(&gdt[APM_CS_16 >> 3],
14174 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14175 set_desc_base(&gdt[APM_DS >> 3],
14176 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14177+ pax_close_kernel();
14178
14179 proc_create("apm", 0, NULL, &apm_file_ops);
14180
14181diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14182index 68de2dc..1f3c720 100644
14183--- a/arch/x86/kernel/asm-offsets.c
14184+++ b/arch/x86/kernel/asm-offsets.c
14185@@ -33,6 +33,8 @@ void common(void) {
14186 OFFSET(TI_status, thread_info, status);
14187 OFFSET(TI_addr_limit, thread_info, addr_limit);
14188 OFFSET(TI_preempt_count, thread_info, preempt_count);
14189+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14190+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14191
14192 BLANK();
14193 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14194@@ -53,8 +55,26 @@ void common(void) {
14195 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14196 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14197 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14198+
14199+#ifdef CONFIG_PAX_KERNEXEC
14200+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14201 #endif
14202
14203+#ifdef CONFIG_PAX_MEMORY_UDEREF
14204+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14205+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14206+#ifdef CONFIG_X86_64
14207+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14208+#endif
14209+#endif
14210+
14211+#endif
14212+
14213+ BLANK();
14214+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14215+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14216+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14217+
14218 #ifdef CONFIG_XEN
14219 BLANK();
14220 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14221diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14222index 834e897..dacddc8 100644
14223--- a/arch/x86/kernel/asm-offsets_64.c
14224+++ b/arch/x86/kernel/asm-offsets_64.c
14225@@ -70,6 +70,7 @@ int main(void)
14226 BLANK();
14227 #undef ENTRY
14228
14229+ DEFINE(TSS_size, sizeof(struct tss_struct));
14230 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14231 BLANK();
14232
14233diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14234index 25f24dc..4094a7f 100644
14235--- a/arch/x86/kernel/cpu/Makefile
14236+++ b/arch/x86/kernel/cpu/Makefile
14237@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14238 CFLAGS_REMOVE_perf_event.o = -pg
14239 endif
14240
14241-# Make sure load_percpu_segment has no stackprotector
14242-nostackp := $(call cc-option, -fno-stack-protector)
14243-CFLAGS_common.o := $(nostackp)
14244-
14245 obj-y := intel_cacheinfo.o scattered.o topology.o
14246 obj-y += proc.o capflags.o powerflags.o common.o
14247 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14248diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14249index 80ab83d..0a7b34e 100644
14250--- a/arch/x86/kernel/cpu/amd.c
14251+++ b/arch/x86/kernel/cpu/amd.c
14252@@ -670,7 +670,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14253 unsigned int size)
14254 {
14255 /* AMD errata T13 (order #21922) */
14256- if ((c->x86 == 6)) {
14257+ if (c->x86 == 6) {
14258 /* Duron Rev A0 */
14259 if (c->x86_model == 3 && c->x86_mask == 0)
14260 size = 64;
14261diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14262index 1a810e4..9fa8201 100644
14263--- a/arch/x86/kernel/cpu/common.c
14264+++ b/arch/x86/kernel/cpu/common.c
14265@@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14266
14267 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14268
14269-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14270-#ifdef CONFIG_X86_64
14271- /*
14272- * We need valid kernel segments for data and code in long mode too
14273- * IRET will check the segment types kkeil 2000/10/28
14274- * Also sysret mandates a special GDT layout
14275- *
14276- * TLS descriptors are currently at a different place compared to i386.
14277- * Hopefully nobody expects them at a fixed place (Wine?)
14278- */
14279- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14280- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14281- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14282- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14283- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14284- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14285-#else
14286- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14287- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14288- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14289- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14290- /*
14291- * Segments used for calling PnP BIOS have byte granularity.
14292- * They code segments and data segments have fixed 64k limits,
14293- * the transfer segment sizes are set at run time.
14294- */
14295- /* 32-bit code */
14296- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14297- /* 16-bit code */
14298- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14299- /* 16-bit data */
14300- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14301- /* 16-bit data */
14302- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14303- /* 16-bit data */
14304- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14305- /*
14306- * The APM segments have byte granularity and their bases
14307- * are set at run time. All have 64k limits.
14308- */
14309- /* 32-bit code */
14310- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14311- /* 16-bit code */
14312- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14313- /* data */
14314- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14315-
14316- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14317- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14318- GDT_STACK_CANARY_INIT
14319-#endif
14320-} };
14321-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14322-
14323 static int __init x86_xsave_setup(char *s)
14324 {
14325 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14326@@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
14327 {
14328 struct desc_ptr gdt_descr;
14329
14330- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14331+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14332 gdt_descr.size = GDT_SIZE - 1;
14333 load_gdt(&gdt_descr);
14334 /* Reload the per-cpu base */
14335@@ -839,6 +785,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14336 /* Filter out anything that depends on CPUID levels we don't have */
14337 filter_cpuid_features(c, true);
14338
14339+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14340+ setup_clear_cpu_cap(X86_FEATURE_SEP);
14341+#endif
14342+
14343 /* If the model name is still unset, do table lookup. */
14344 if (!c->x86_model_id[0]) {
14345 const char *p;
14346@@ -1019,10 +969,12 @@ static __init int setup_disablecpuid(char *arg)
14347 }
14348 __setup("clearcpuid=", setup_disablecpuid);
14349
14350+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14351+EXPORT_PER_CPU_SYMBOL(current_tinfo);
14352+
14353 #ifdef CONFIG_X86_64
14354 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14355-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14356- (unsigned long) nmi_idt_table };
14357+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14358
14359 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14360 irq_stack_union) __aligned(PAGE_SIZE);
14361@@ -1036,7 +988,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14362 EXPORT_PER_CPU_SYMBOL(current_task);
14363
14364 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14365- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14366+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14367 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14368
14369 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14370@@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14371 {
14372 memset(regs, 0, sizeof(struct pt_regs));
14373 regs->fs = __KERNEL_PERCPU;
14374- regs->gs = __KERNEL_STACK_CANARY;
14375+ savesegment(gs, regs->gs);
14376
14377 return regs;
14378 }
14379@@ -1181,7 +1133,7 @@ void __cpuinit cpu_init(void)
14380 int i;
14381
14382 cpu = stack_smp_processor_id();
14383- t = &per_cpu(init_tss, cpu);
14384+ t = init_tss + cpu;
14385 oist = &per_cpu(orig_ist, cpu);
14386
14387 #ifdef CONFIG_NUMA
14388@@ -1207,7 +1159,7 @@ void __cpuinit cpu_init(void)
14389 switch_to_new_gdt(cpu);
14390 loadsegment(fs, 0);
14391
14392- load_idt((const struct desc_ptr *)&idt_descr);
14393+ load_idt(&idt_descr);
14394
14395 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14396 syscall_init();
14397@@ -1216,7 +1168,6 @@ void __cpuinit cpu_init(void)
14398 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14399 barrier();
14400
14401- x86_configure_nx();
14402 if (cpu != 0)
14403 enable_x2apic();
14404
14405@@ -1272,7 +1223,7 @@ void __cpuinit cpu_init(void)
14406 {
14407 int cpu = smp_processor_id();
14408 struct task_struct *curr = current;
14409- struct tss_struct *t = &per_cpu(init_tss, cpu);
14410+ struct tss_struct *t = init_tss + cpu;
14411 struct thread_struct *thread = &curr->thread;
14412
14413 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14414diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14415index 3e6ff6c..54b4992 100644
14416--- a/arch/x86/kernel/cpu/intel.c
14417+++ b/arch/x86/kernel/cpu/intel.c
14418@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14419 * Update the IDT descriptor and reload the IDT so that
14420 * it uses the read-only mapped virtual address.
14421 */
14422- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14423+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14424 load_idt(&idt_descr);
14425 }
14426 #endif
14427diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14428index 5a11ae2..a1a1c8a 100644
14429--- a/arch/x86/kernel/cpu/mcheck/mce.c
14430+++ b/arch/x86/kernel/cpu/mcheck/mce.c
14431@@ -42,6 +42,7 @@
14432 #include <asm/processor.h>
14433 #include <asm/mce.h>
14434 #include <asm/msr.h>
14435+#include <asm/local.h>
14436
14437 #include "mce-internal.h"
14438
14439@@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14440 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14441 m->cs, m->ip);
14442
14443- if (m->cs == __KERNEL_CS)
14444+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14445 print_symbol("{%s}", m->ip);
14446 pr_cont("\n");
14447 }
14448@@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14449
14450 #define PANIC_TIMEOUT 5 /* 5 seconds */
14451
14452-static atomic_t mce_paniced;
14453+static atomic_unchecked_t mce_paniced;
14454
14455 static int fake_panic;
14456-static atomic_t mce_fake_paniced;
14457+static atomic_unchecked_t mce_fake_paniced;
14458
14459 /* Panic in progress. Enable interrupts and wait for final IPI */
14460 static void wait_for_panic(void)
14461@@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14462 /*
14463 * Make sure only one CPU runs in machine check panic
14464 */
14465- if (atomic_inc_return(&mce_paniced) > 1)
14466+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14467 wait_for_panic();
14468 barrier();
14469
14470@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14471 console_verbose();
14472 } else {
14473 /* Don't log too much for fake panic */
14474- if (atomic_inc_return(&mce_fake_paniced) > 1)
14475+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14476 return;
14477 }
14478 /* First print corrected ones that are still unlogged */
14479@@ -658,7 +659,7 @@ static int mce_timed_out(u64 *t)
14480 * might have been modified by someone else.
14481 */
14482 rmb();
14483- if (atomic_read(&mce_paniced))
14484+ if (atomic_read_unchecked(&mce_paniced))
14485 wait_for_panic();
14486 if (!monarch_timeout)
14487 goto out;
14488@@ -1446,7 +1447,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14489 }
14490
14491 /* Call the installed machine check handler for this CPU setup. */
14492-void (*machine_check_vector)(struct pt_regs *, long error_code) =
14493+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14494 unexpected_machine_check;
14495
14496 /*
14497@@ -1469,7 +1470,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14498 return;
14499 }
14500
14501+ pax_open_kernel();
14502 machine_check_vector = do_machine_check;
14503+ pax_close_kernel();
14504
14505 __mcheck_cpu_init_generic();
14506 __mcheck_cpu_init_vendor(c);
14507@@ -1483,7 +1486,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14508 */
14509
14510 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14511-static int mce_chrdev_open_count; /* #times opened */
14512+static local_t mce_chrdev_open_count; /* #times opened */
14513 static int mce_chrdev_open_exclu; /* already open exclusive? */
14514
14515 static int mce_chrdev_open(struct inode *inode, struct file *file)
14516@@ -1491,7 +1494,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14517 spin_lock(&mce_chrdev_state_lock);
14518
14519 if (mce_chrdev_open_exclu ||
14520- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14521+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14522 spin_unlock(&mce_chrdev_state_lock);
14523
14524 return -EBUSY;
14525@@ -1499,7 +1502,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14526
14527 if (file->f_flags & O_EXCL)
14528 mce_chrdev_open_exclu = 1;
14529- mce_chrdev_open_count++;
14530+ local_inc(&mce_chrdev_open_count);
14531
14532 spin_unlock(&mce_chrdev_state_lock);
14533
14534@@ -1510,7 +1513,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14535 {
14536 spin_lock(&mce_chrdev_state_lock);
14537
14538- mce_chrdev_open_count--;
14539+ local_dec(&mce_chrdev_open_count);
14540 mce_chrdev_open_exclu = 0;
14541
14542 spin_unlock(&mce_chrdev_state_lock);
14543@@ -2229,7 +2232,7 @@ struct dentry *mce_get_debugfs_dir(void)
14544 static void mce_reset(void)
14545 {
14546 cpu_missing = 0;
14547- atomic_set(&mce_fake_paniced, 0);
14548+ atomic_set_unchecked(&mce_fake_paniced, 0);
14549 atomic_set(&mce_executing, 0);
14550 atomic_set(&mce_callin, 0);
14551 atomic_set(&global_nwo, 0);
14552diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14553index 5c0e653..0882b0a 100644
14554--- a/arch/x86/kernel/cpu/mcheck/p5.c
14555+++ b/arch/x86/kernel/cpu/mcheck/p5.c
14556@@ -12,6 +12,7 @@
14557 #include <asm/system.h>
14558 #include <asm/mce.h>
14559 #include <asm/msr.h>
14560+#include <asm/pgtable.h>
14561
14562 /* By default disabled */
14563 int mce_p5_enabled __read_mostly;
14564@@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14565 if (!cpu_has(c, X86_FEATURE_MCE))
14566 return;
14567
14568+ pax_open_kernel();
14569 machine_check_vector = pentium_machine_check;
14570+ pax_close_kernel();
14571 /* Make sure the vector pointer is visible before we enable MCEs: */
14572 wmb();
14573
14574diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14575index 54060f5..c1a7577 100644
14576--- a/arch/x86/kernel/cpu/mcheck/winchip.c
14577+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14578@@ -11,6 +11,7 @@
14579 #include <asm/system.h>
14580 #include <asm/mce.h>
14581 #include <asm/msr.h>
14582+#include <asm/pgtable.h>
14583
14584 /* Machine check handler for WinChip C6: */
14585 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14586@@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14587 {
14588 u32 lo, hi;
14589
14590+ pax_open_kernel();
14591 machine_check_vector = winchip_machine_check;
14592+ pax_close_kernel();
14593 /* Make sure the vector pointer is visible before we enable MCEs: */
14594 wmb();
14595
14596diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14597index 6b96110..0da73eb 100644
14598--- a/arch/x86/kernel/cpu/mtrr/main.c
14599+++ b/arch/x86/kernel/cpu/mtrr/main.c
14600@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14601 u64 size_or_mask, size_and_mask;
14602 static bool mtrr_aps_delayed_init;
14603
14604-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14605+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14606
14607 const struct mtrr_ops *mtrr_if;
14608
14609diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14610index df5e41f..816c719 100644
14611--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14612+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14613@@ -25,7 +25,7 @@ struct mtrr_ops {
14614 int (*validate_add_page)(unsigned long base, unsigned long size,
14615 unsigned int type);
14616 int (*have_wrcomb)(void);
14617-};
14618+} __do_const;
14619
14620 extern int generic_get_free_region(unsigned long base, unsigned long size,
14621 int replace_reg);
14622diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14623index 5adce10..99284ec 100644
14624--- a/arch/x86/kernel/cpu/perf_event.c
14625+++ b/arch/x86/kernel/cpu/perf_event.c
14626@@ -1665,7 +1665,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14627 break;
14628
14629 perf_callchain_store(entry, frame.return_address);
14630- fp = frame.next_frame;
14631+ fp = (const void __force_user *)frame.next_frame;
14632 }
14633 }
14634
14635diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14636index 13ad899..f642b9a 100644
14637--- a/arch/x86/kernel/crash.c
14638+++ b/arch/x86/kernel/crash.c
14639@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14640 {
14641 #ifdef CONFIG_X86_32
14642 struct pt_regs fixed_regs;
14643-#endif
14644
14645-#ifdef CONFIG_X86_32
14646- if (!user_mode_vm(regs)) {
14647+ if (!user_mode(regs)) {
14648 crash_fixup_ss_esp(&fixed_regs, regs);
14649 regs = &fixed_regs;
14650 }
14651diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14652index 37250fe..bf2ec74 100644
14653--- a/arch/x86/kernel/doublefault_32.c
14654+++ b/arch/x86/kernel/doublefault_32.c
14655@@ -11,7 +11,7 @@
14656
14657 #define DOUBLEFAULT_STACKSIZE (1024)
14658 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14659-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14660+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14661
14662 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14663
14664@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14665 unsigned long gdt, tss;
14666
14667 store_gdt(&gdt_desc);
14668- gdt = gdt_desc.address;
14669+ gdt = (unsigned long)gdt_desc.address;
14670
14671 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14672
14673@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14674 /* 0x2 bit is always set */
14675 .flags = X86_EFLAGS_SF | 0x2,
14676 .sp = STACK_START,
14677- .es = __USER_DS,
14678+ .es = __KERNEL_DS,
14679 .cs = __KERNEL_CS,
14680 .ss = __KERNEL_DS,
14681- .ds = __USER_DS,
14682+ .ds = __KERNEL_DS,
14683 .fs = __KERNEL_PERCPU,
14684
14685 .__cr3 = __pa_nodebug(swapper_pg_dir),
14686diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14687index 4025fe4..d8451c6 100644
14688--- a/arch/x86/kernel/dumpstack.c
14689+++ b/arch/x86/kernel/dumpstack.c
14690@@ -2,6 +2,9 @@
14691 * Copyright (C) 1991, 1992 Linus Torvalds
14692 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14693 */
14694+#ifdef CONFIG_GRKERNSEC_HIDESYM
14695+#define __INCLUDED_BY_HIDESYM 1
14696+#endif
14697 #include <linux/kallsyms.h>
14698 #include <linux/kprobes.h>
14699 #include <linux/uaccess.h>
14700@@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
14701 static void
14702 print_ftrace_graph_addr(unsigned long addr, void *data,
14703 const struct stacktrace_ops *ops,
14704- struct thread_info *tinfo, int *graph)
14705+ struct task_struct *task, int *graph)
14706 {
14707- struct task_struct *task = tinfo->task;
14708 unsigned long ret_addr;
14709 int index = task->curr_ret_stack;
14710
14711@@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14712 static inline void
14713 print_ftrace_graph_addr(unsigned long addr, void *data,
14714 const struct stacktrace_ops *ops,
14715- struct thread_info *tinfo, int *graph)
14716+ struct task_struct *task, int *graph)
14717 { }
14718 #endif
14719
14720@@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14721 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14722 */
14723
14724-static inline int valid_stack_ptr(struct thread_info *tinfo,
14725- void *p, unsigned int size, void *end)
14726+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14727 {
14728- void *t = tinfo;
14729 if (end) {
14730 if (p < end && p >= (end-THREAD_SIZE))
14731 return 1;
14732@@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14733 }
14734
14735 unsigned long
14736-print_context_stack(struct thread_info *tinfo,
14737+print_context_stack(struct task_struct *task, void *stack_start,
14738 unsigned long *stack, unsigned long bp,
14739 const struct stacktrace_ops *ops, void *data,
14740 unsigned long *end, int *graph)
14741 {
14742 struct stack_frame *frame = (struct stack_frame *)bp;
14743
14744- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14745+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14746 unsigned long addr;
14747
14748 addr = *stack;
14749@@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
14750 } else {
14751 ops->address(data, addr, 0);
14752 }
14753- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14754+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14755 }
14756 stack++;
14757 }
14758@@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
14759 EXPORT_SYMBOL_GPL(print_context_stack);
14760
14761 unsigned long
14762-print_context_stack_bp(struct thread_info *tinfo,
14763+print_context_stack_bp(struct task_struct *task, void *stack_start,
14764 unsigned long *stack, unsigned long bp,
14765 const struct stacktrace_ops *ops, void *data,
14766 unsigned long *end, int *graph)
14767@@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14768 struct stack_frame *frame = (struct stack_frame *)bp;
14769 unsigned long *ret_addr = &frame->return_address;
14770
14771- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14772+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14773 unsigned long addr = *ret_addr;
14774
14775 if (!__kernel_text_address(addr))
14776@@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14777 ops->address(data, addr, 1);
14778 frame = frame->next_frame;
14779 ret_addr = &frame->return_address;
14780- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14781+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14782 }
14783
14784 return (unsigned long)frame;
14785@@ -186,7 +186,7 @@ void dump_stack(void)
14786
14787 bp = stack_frame(current, NULL);
14788 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14789- current->pid, current->comm, print_tainted(),
14790+ task_pid_nr(current), current->comm, print_tainted(),
14791 init_utsname()->release,
14792 (int)strcspn(init_utsname()->version, " "),
14793 init_utsname()->version);
14794@@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
14795 }
14796 EXPORT_SYMBOL_GPL(oops_begin);
14797
14798+extern void gr_handle_kernel_exploit(void);
14799+
14800 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14801 {
14802 if (regs && kexec_should_crash(current))
14803@@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14804 panic("Fatal exception in interrupt");
14805 if (panic_on_oops)
14806 panic("Fatal exception");
14807- do_exit(signr);
14808+
14809+ gr_handle_kernel_exploit();
14810+
14811+ do_group_exit(signr);
14812 }
14813
14814 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14815@@ -270,7 +275,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14816
14817 show_registers(regs);
14818 #ifdef CONFIG_X86_32
14819- if (user_mode_vm(regs)) {
14820+ if (user_mode(regs)) {
14821 sp = regs->sp;
14822 ss = regs->ss & 0xffff;
14823 } else {
14824@@ -298,7 +303,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14825 unsigned long flags = oops_begin();
14826 int sig = SIGSEGV;
14827
14828- if (!user_mode_vm(regs))
14829+ if (!user_mode(regs))
14830 report_bug(regs->ip, regs);
14831
14832 if (__die(str, regs, err))
14833diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14834index c99f9ed..2a15d80 100644
14835--- a/arch/x86/kernel/dumpstack_32.c
14836+++ b/arch/x86/kernel/dumpstack_32.c
14837@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14838 bp = stack_frame(task, regs);
14839
14840 for (;;) {
14841- struct thread_info *context;
14842+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14843
14844- context = (struct thread_info *)
14845- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14846- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14847+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14848
14849- stack = (unsigned long *)context->previous_esp;
14850- if (!stack)
14851+ if (stack_start == task_stack_page(task))
14852 break;
14853+ stack = *(unsigned long **)stack_start;
14854 if (ops->stack(data, "IRQ") < 0)
14855 break;
14856 touch_nmi_watchdog();
14857@@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14858 * When in-kernel, we also print out the stack and code at the
14859 * time of the fault..
14860 */
14861- if (!user_mode_vm(regs)) {
14862+ if (!user_mode(regs)) {
14863 unsigned int code_prologue = code_bytes * 43 / 64;
14864 unsigned int code_len = code_bytes;
14865 unsigned char c;
14866 u8 *ip;
14867+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14868
14869 printk(KERN_EMERG "Stack:\n");
14870 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14871
14872 printk(KERN_EMERG "Code: ");
14873
14874- ip = (u8 *)regs->ip - code_prologue;
14875+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14876 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14877 /* try starting at IP */
14878- ip = (u8 *)regs->ip;
14879+ ip = (u8 *)regs->ip + cs_base;
14880 code_len = code_len - code_prologue + 1;
14881 }
14882 for (i = 0; i < code_len; i++, ip++) {
14883@@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14884 printk(KERN_CONT " Bad EIP value.");
14885 break;
14886 }
14887- if (ip == (u8 *)regs->ip)
14888+ if (ip == (u8 *)regs->ip + cs_base)
14889 printk(KERN_CONT "<%02x> ", c);
14890 else
14891 printk(KERN_CONT "%02x ", c);
14892@@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14893 {
14894 unsigned short ud2;
14895
14896+ ip = ktla_ktva(ip);
14897 if (ip < PAGE_OFFSET)
14898 return 0;
14899 if (probe_kernel_address((unsigned short *)ip, ud2))
14900@@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14901
14902 return ud2 == 0x0b0f;
14903 }
14904+
14905+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14906+void pax_check_alloca(unsigned long size)
14907+{
14908+ unsigned long sp = (unsigned long)&sp, stack_left;
14909+
14910+ /* all kernel stacks are of the same size */
14911+ stack_left = sp & (THREAD_SIZE - 1);
14912+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14913+}
14914+EXPORT_SYMBOL(pax_check_alloca);
14915+#endif
14916diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14917index 17107bd..9623722 100644
14918--- a/arch/x86/kernel/dumpstack_64.c
14919+++ b/arch/x86/kernel/dumpstack_64.c
14920@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14921 unsigned long *irq_stack_end =
14922 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14923 unsigned used = 0;
14924- struct thread_info *tinfo;
14925 int graph = 0;
14926 unsigned long dummy;
14927+ void *stack_start;
14928
14929 if (!task)
14930 task = current;
14931@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14932 * current stack address. If the stacks consist of nested
14933 * exceptions
14934 */
14935- tinfo = task_thread_info(task);
14936 for (;;) {
14937 char *id;
14938 unsigned long *estack_end;
14939+
14940 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14941 &used, &id);
14942
14943@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14944 if (ops->stack(data, id) < 0)
14945 break;
14946
14947- bp = ops->walk_stack(tinfo, stack, bp, ops,
14948+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14949 data, estack_end, &graph);
14950 ops->stack(data, "<EOE>");
14951 /*
14952@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14953 * second-to-last pointer (index -2 to end) in the
14954 * exception stack:
14955 */
14956+ if ((u16)estack_end[-1] != __KERNEL_DS)
14957+ goto out;
14958 stack = (unsigned long *) estack_end[-2];
14959 continue;
14960 }
14961@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14962 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14963 if (ops->stack(data, "IRQ") < 0)
14964 break;
14965- bp = ops->walk_stack(tinfo, stack, bp,
14966+ bp = ops->walk_stack(task, irq_stack, stack, bp,
14967 ops, data, irq_stack_end, &graph);
14968 /*
14969 * We link to the next stack (which would be
14970@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14971 /*
14972 * This handles the process stack:
14973 */
14974- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14975+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14976+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14977+out:
14978 put_cpu();
14979 }
14980 EXPORT_SYMBOL(dump_trace);
14981@@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14982
14983 return ud2 == 0x0b0f;
14984 }
14985+
14986+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14987+void pax_check_alloca(unsigned long size)
14988+{
14989+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14990+ unsigned cpu, used;
14991+ char *id;
14992+
14993+ /* check the process stack first */
14994+ stack_start = (unsigned long)task_stack_page(current);
14995+ stack_end = stack_start + THREAD_SIZE;
14996+ if (likely(stack_start <= sp && sp < stack_end)) {
14997+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14998+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14999+ return;
15000+ }
15001+
15002+ cpu = get_cpu();
15003+
15004+ /* check the irq stacks */
15005+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
15006+ stack_start = stack_end - IRQ_STACK_SIZE;
15007+ if (stack_start <= sp && sp < stack_end) {
15008+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
15009+ put_cpu();
15010+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
15011+ return;
15012+ }
15013+
15014+ /* check the exception stacks */
15015+ used = 0;
15016+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
15017+ stack_start = stack_end - EXCEPTION_STKSZ;
15018+ if (stack_end && stack_start <= sp && sp < stack_end) {
15019+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
15020+ put_cpu();
15021+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
15022+ return;
15023+ }
15024+
15025+ put_cpu();
15026+
15027+ /* unknown stack */
15028+ BUG();
15029+}
15030+EXPORT_SYMBOL(pax_check_alloca);
15031+#endif
15032diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
15033index 9b9f18b..9fcaa04 100644
15034--- a/arch/x86/kernel/early_printk.c
15035+++ b/arch/x86/kernel/early_printk.c
15036@@ -7,6 +7,7 @@
15037 #include <linux/pci_regs.h>
15038 #include <linux/pci_ids.h>
15039 #include <linux/errno.h>
15040+#include <linux/sched.h>
15041 #include <asm/io.h>
15042 #include <asm/processor.h>
15043 #include <asm/fcntl.h>
15044diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
15045index 7b784f4..db6b628 100644
15046--- a/arch/x86/kernel/entry_32.S
15047+++ b/arch/x86/kernel/entry_32.S
15048@@ -179,13 +179,146 @@
15049 /*CFI_REL_OFFSET gs, PT_GS*/
15050 .endm
15051 .macro SET_KERNEL_GS reg
15052+
15053+#ifdef CONFIG_CC_STACKPROTECTOR
15054 movl $(__KERNEL_STACK_CANARY), \reg
15055+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15056+ movl $(__USER_DS), \reg
15057+#else
15058+ xorl \reg, \reg
15059+#endif
15060+
15061 movl \reg, %gs
15062 .endm
15063
15064 #endif /* CONFIG_X86_32_LAZY_GS */
15065
15066-.macro SAVE_ALL
15067+.macro pax_enter_kernel
15068+#ifdef CONFIG_PAX_KERNEXEC
15069+ call pax_enter_kernel
15070+#endif
15071+.endm
15072+
15073+.macro pax_exit_kernel
15074+#ifdef CONFIG_PAX_KERNEXEC
15075+ call pax_exit_kernel
15076+#endif
15077+.endm
15078+
15079+#ifdef CONFIG_PAX_KERNEXEC
15080+ENTRY(pax_enter_kernel)
15081+#ifdef CONFIG_PARAVIRT
15082+ pushl %eax
15083+ pushl %ecx
15084+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15085+ mov %eax, %esi
15086+#else
15087+ mov %cr0, %esi
15088+#endif
15089+ bts $16, %esi
15090+ jnc 1f
15091+ mov %cs, %esi
15092+ cmp $__KERNEL_CS, %esi
15093+ jz 3f
15094+ ljmp $__KERNEL_CS, $3f
15095+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15096+2:
15097+#ifdef CONFIG_PARAVIRT
15098+ mov %esi, %eax
15099+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15100+#else
15101+ mov %esi, %cr0
15102+#endif
15103+3:
15104+#ifdef CONFIG_PARAVIRT
15105+ popl %ecx
15106+ popl %eax
15107+#endif
15108+ ret
15109+ENDPROC(pax_enter_kernel)
15110+
15111+ENTRY(pax_exit_kernel)
15112+#ifdef CONFIG_PARAVIRT
15113+ pushl %eax
15114+ pushl %ecx
15115+#endif
15116+ mov %cs, %esi
15117+ cmp $__KERNEXEC_KERNEL_CS, %esi
15118+ jnz 2f
15119+#ifdef CONFIG_PARAVIRT
15120+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15121+ mov %eax, %esi
15122+#else
15123+ mov %cr0, %esi
15124+#endif
15125+ btr $16, %esi
15126+ ljmp $__KERNEL_CS, $1f
15127+1:
15128+#ifdef CONFIG_PARAVIRT
15129+ mov %esi, %eax
15130+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15131+#else
15132+ mov %esi, %cr0
15133+#endif
15134+2:
15135+#ifdef CONFIG_PARAVIRT
15136+ popl %ecx
15137+ popl %eax
15138+#endif
15139+ ret
15140+ENDPROC(pax_exit_kernel)
15141+#endif
15142+
15143+.macro pax_erase_kstack
15144+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15145+ call pax_erase_kstack
15146+#endif
15147+.endm
15148+
15149+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15150+/*
15151+ * ebp: thread_info
15152+ * ecx, edx: can be clobbered
15153+ */
15154+ENTRY(pax_erase_kstack)
15155+ pushl %edi
15156+ pushl %eax
15157+
15158+ mov TI_lowest_stack(%ebp), %edi
15159+ mov $-0xBEEF, %eax
15160+ std
15161+
15162+1: mov %edi, %ecx
15163+ and $THREAD_SIZE_asm - 1, %ecx
15164+ shr $2, %ecx
15165+ repne scasl
15166+ jecxz 2f
15167+
15168+ cmp $2*16, %ecx
15169+ jc 2f
15170+
15171+ mov $2*16, %ecx
15172+ repe scasl
15173+ jecxz 2f
15174+ jne 1b
15175+
15176+2: cld
15177+ mov %esp, %ecx
15178+ sub %edi, %ecx
15179+ shr $2, %ecx
15180+ rep stosl
15181+
15182+ mov TI_task_thread_sp0(%ebp), %edi
15183+ sub $128, %edi
15184+ mov %edi, TI_lowest_stack(%ebp)
15185+
15186+ popl %eax
15187+ popl %edi
15188+ ret
15189+ENDPROC(pax_erase_kstack)
15190+#endif
15191+
15192+.macro __SAVE_ALL _DS
15193 cld
15194 PUSH_GS
15195 pushl_cfi %fs
15196@@ -208,7 +341,7 @@
15197 CFI_REL_OFFSET ecx, 0
15198 pushl_cfi %ebx
15199 CFI_REL_OFFSET ebx, 0
15200- movl $(__USER_DS), %edx
15201+ movl $\_DS, %edx
15202 movl %edx, %ds
15203 movl %edx, %es
15204 movl $(__KERNEL_PERCPU), %edx
15205@@ -216,6 +349,15 @@
15206 SET_KERNEL_GS %edx
15207 .endm
15208
15209+.macro SAVE_ALL
15210+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15211+ __SAVE_ALL __KERNEL_DS
15212+ pax_enter_kernel
15213+#else
15214+ __SAVE_ALL __USER_DS
15215+#endif
15216+.endm
15217+
15218 .macro RESTORE_INT_REGS
15219 popl_cfi %ebx
15220 CFI_RESTORE ebx
15221@@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
15222 popfl_cfi
15223 jmp syscall_exit
15224 CFI_ENDPROC
15225-END(ret_from_fork)
15226+ENDPROC(ret_from_fork)
15227
15228 /*
15229 * Interrupt exit functions should be protected against kprobes
15230@@ -335,7 +477,15 @@ resume_userspace_sig:
15231 andl $SEGMENT_RPL_MASK, %eax
15232 #endif
15233 cmpl $USER_RPL, %eax
15234+
15235+#ifdef CONFIG_PAX_KERNEXEC
15236+ jae resume_userspace
15237+
15238+ pax_exit_kernel
15239+ jmp resume_kernel
15240+#else
15241 jb resume_kernel # not returning to v8086 or userspace
15242+#endif
15243
15244 ENTRY(resume_userspace)
15245 LOCKDEP_SYS_EXIT
15246@@ -347,8 +497,8 @@ ENTRY(resume_userspace)
15247 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15248 # int/exception return?
15249 jne work_pending
15250- jmp restore_all
15251-END(ret_from_exception)
15252+ jmp restore_all_pax
15253+ENDPROC(ret_from_exception)
15254
15255 #ifdef CONFIG_PREEMPT
15256 ENTRY(resume_kernel)
15257@@ -363,7 +513,7 @@ need_resched:
15258 jz restore_all
15259 call preempt_schedule_irq
15260 jmp need_resched
15261-END(resume_kernel)
15262+ENDPROC(resume_kernel)
15263 #endif
15264 CFI_ENDPROC
15265 /*
15266@@ -397,23 +547,34 @@ sysenter_past_esp:
15267 /*CFI_REL_OFFSET cs, 0*/
15268 /*
15269 * Push current_thread_info()->sysenter_return to the stack.
15270- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15271- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15272 */
15273- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15274+ pushl_cfi $0
15275 CFI_REL_OFFSET eip, 0
15276
15277 pushl_cfi %eax
15278 SAVE_ALL
15279+ GET_THREAD_INFO(%ebp)
15280+ movl TI_sysenter_return(%ebp),%ebp
15281+ movl %ebp,PT_EIP(%esp)
15282 ENABLE_INTERRUPTS(CLBR_NONE)
15283
15284 /*
15285 * Load the potential sixth argument from user stack.
15286 * Careful about security.
15287 */
15288+ movl PT_OLDESP(%esp),%ebp
15289+
15290+#ifdef CONFIG_PAX_MEMORY_UDEREF
15291+ mov PT_OLDSS(%esp),%ds
15292+1: movl %ds:(%ebp),%ebp
15293+ push %ss
15294+ pop %ds
15295+#else
15296 cmpl $__PAGE_OFFSET-3,%ebp
15297 jae syscall_fault
15298 1: movl (%ebp),%ebp
15299+#endif
15300+
15301 movl %ebp,PT_EBP(%esp)
15302 .section __ex_table,"a"
15303 .align 4
15304@@ -436,12 +597,24 @@ sysenter_do_call:
15305 testl $_TIF_ALLWORK_MASK, %ecx
15306 jne sysexit_audit
15307 sysenter_exit:
15308+
15309+#ifdef CONFIG_PAX_RANDKSTACK
15310+ pushl_cfi %eax
15311+ movl %esp, %eax
15312+ call pax_randomize_kstack
15313+ popl_cfi %eax
15314+#endif
15315+
15316+ pax_erase_kstack
15317+
15318 /* if something modifies registers it must also disable sysexit */
15319 movl PT_EIP(%esp), %edx
15320 movl PT_OLDESP(%esp), %ecx
15321 xorl %ebp,%ebp
15322 TRACE_IRQS_ON
15323 1: mov PT_FS(%esp), %fs
15324+2: mov PT_DS(%esp), %ds
15325+3: mov PT_ES(%esp), %es
15326 PTGS_TO_GS
15327 ENABLE_INTERRUPTS_SYSEXIT
15328
15329@@ -458,6 +631,9 @@ sysenter_audit:
15330 movl %eax,%edx /* 2nd arg: syscall number */
15331 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15332 call __audit_syscall_entry
15333+
15334+ pax_erase_kstack
15335+
15336 pushl_cfi %ebx
15337 movl PT_EAX(%esp),%eax /* reload syscall number */
15338 jmp sysenter_do_call
15339@@ -483,11 +659,17 @@ sysexit_audit:
15340
15341 CFI_ENDPROC
15342 .pushsection .fixup,"ax"
15343-2: movl $0,PT_FS(%esp)
15344+4: movl $0,PT_FS(%esp)
15345+ jmp 1b
15346+5: movl $0,PT_DS(%esp)
15347+ jmp 1b
15348+6: movl $0,PT_ES(%esp)
15349 jmp 1b
15350 .section __ex_table,"a"
15351 .align 4
15352- .long 1b,2b
15353+ .long 1b,4b
15354+ .long 2b,5b
15355+ .long 3b,6b
15356 .popsection
15357 PTGS_TO_GS_EX
15358 ENDPROC(ia32_sysenter_target)
15359@@ -520,6 +702,15 @@ syscall_exit:
15360 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15361 jne syscall_exit_work
15362
15363+restore_all_pax:
15364+
15365+#ifdef CONFIG_PAX_RANDKSTACK
15366+ movl %esp, %eax
15367+ call pax_randomize_kstack
15368+#endif
15369+
15370+ pax_erase_kstack
15371+
15372 restore_all:
15373 TRACE_IRQS_IRET
15374 restore_all_notrace:
15375@@ -579,14 +770,34 @@ ldt_ss:
15376 * compensating for the offset by changing to the ESPFIX segment with
15377 * a base address that matches for the difference.
15378 */
15379-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15380+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15381 mov %esp, %edx /* load kernel esp */
15382 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15383 mov %dx, %ax /* eax: new kernel esp */
15384 sub %eax, %edx /* offset (low word is 0) */
15385+#ifdef CONFIG_SMP
15386+ movl PER_CPU_VAR(cpu_number), %ebx
15387+ shll $PAGE_SHIFT_asm, %ebx
15388+ addl $cpu_gdt_table, %ebx
15389+#else
15390+ movl $cpu_gdt_table, %ebx
15391+#endif
15392 shr $16, %edx
15393- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15394- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15395+
15396+#ifdef CONFIG_PAX_KERNEXEC
15397+ mov %cr0, %esi
15398+ btr $16, %esi
15399+ mov %esi, %cr0
15400+#endif
15401+
15402+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15403+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15404+
15405+#ifdef CONFIG_PAX_KERNEXEC
15406+ bts $16, %esi
15407+ mov %esi, %cr0
15408+#endif
15409+
15410 pushl_cfi $__ESPFIX_SS
15411 pushl_cfi %eax /* new kernel esp */
15412 /* Disable interrupts, but do not irqtrace this section: we
15413@@ -615,38 +826,30 @@ work_resched:
15414 movl TI_flags(%ebp), %ecx
15415 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15416 # than syscall tracing?
15417- jz restore_all
15418+ jz restore_all_pax
15419 testb $_TIF_NEED_RESCHED, %cl
15420 jnz work_resched
15421
15422 work_notifysig: # deal with pending signals and
15423 # notify-resume requests
15424+ movl %esp, %eax
15425 #ifdef CONFIG_VM86
15426 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15427- movl %esp, %eax
15428- jne work_notifysig_v86 # returning to kernel-space or
15429+ jz 1f # returning to kernel-space or
15430 # vm86-space
15431- TRACE_IRQS_ON
15432- ENABLE_INTERRUPTS(CLBR_NONE)
15433- xorl %edx, %edx
15434- call do_notify_resume
15435- jmp resume_userspace_sig
15436
15437- ALIGN
15438-work_notifysig_v86:
15439 pushl_cfi %ecx # save ti_flags for do_notify_resume
15440 call save_v86_state # %eax contains pt_regs pointer
15441 popl_cfi %ecx
15442 movl %eax, %esp
15443-#else
15444- movl %esp, %eax
15445+1:
15446 #endif
15447 TRACE_IRQS_ON
15448 ENABLE_INTERRUPTS(CLBR_NONE)
15449 xorl %edx, %edx
15450 call do_notify_resume
15451 jmp resume_userspace_sig
15452-END(work_pending)
15453+ENDPROC(work_pending)
15454
15455 # perform syscall exit tracing
15456 ALIGN
15457@@ -654,11 +857,14 @@ syscall_trace_entry:
15458 movl $-ENOSYS,PT_EAX(%esp)
15459 movl %esp, %eax
15460 call syscall_trace_enter
15461+
15462+ pax_erase_kstack
15463+
15464 /* What it returned is what we'll actually use. */
15465 cmpl $(NR_syscalls), %eax
15466 jnae syscall_call
15467 jmp syscall_exit
15468-END(syscall_trace_entry)
15469+ENDPROC(syscall_trace_entry)
15470
15471 # perform syscall exit tracing
15472 ALIGN
15473@@ -671,20 +877,24 @@ syscall_exit_work:
15474 movl %esp, %eax
15475 call syscall_trace_leave
15476 jmp resume_userspace
15477-END(syscall_exit_work)
15478+ENDPROC(syscall_exit_work)
15479 CFI_ENDPROC
15480
15481 RING0_INT_FRAME # can't unwind into user space anyway
15482 syscall_fault:
15483+#ifdef CONFIG_PAX_MEMORY_UDEREF
15484+ push %ss
15485+ pop %ds
15486+#endif
15487 GET_THREAD_INFO(%ebp)
15488 movl $-EFAULT,PT_EAX(%esp)
15489 jmp resume_userspace
15490-END(syscall_fault)
15491+ENDPROC(syscall_fault)
15492
15493 syscall_badsys:
15494 movl $-ENOSYS,PT_EAX(%esp)
15495 jmp resume_userspace
15496-END(syscall_badsys)
15497+ENDPROC(syscall_badsys)
15498 CFI_ENDPROC
15499 /*
15500 * End of kprobes section
15501@@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
15502 CFI_ENDPROC
15503 ENDPROC(ptregs_clone)
15504
15505+ ALIGN;
15506+ENTRY(kernel_execve)
15507+ CFI_STARTPROC
15508+ pushl_cfi %ebp
15509+ sub $PT_OLDSS+4,%esp
15510+ pushl_cfi %edi
15511+ pushl_cfi %ecx
15512+ pushl_cfi %eax
15513+ lea 3*4(%esp),%edi
15514+ mov $PT_OLDSS/4+1,%ecx
15515+ xorl %eax,%eax
15516+ rep stosl
15517+ popl_cfi %eax
15518+ popl_cfi %ecx
15519+ popl_cfi %edi
15520+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15521+ pushl_cfi %esp
15522+ call sys_execve
15523+ add $4,%esp
15524+ CFI_ADJUST_CFA_OFFSET -4
15525+ GET_THREAD_INFO(%ebp)
15526+ test %eax,%eax
15527+ jz syscall_exit
15528+ add $PT_OLDSS+4,%esp
15529+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15530+ popl_cfi %ebp
15531+ ret
15532+ CFI_ENDPROC
15533+ENDPROC(kernel_execve)
15534+
15535 .macro FIXUP_ESPFIX_STACK
15536 /*
15537 * Switch back for ESPFIX stack to the normal zerobased stack
15538@@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
15539 * normal stack and adjusts ESP with the matching offset.
15540 */
15541 /* fixup the stack */
15542- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15543- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15544+#ifdef CONFIG_SMP
15545+ movl PER_CPU_VAR(cpu_number), %ebx
15546+ shll $PAGE_SHIFT_asm, %ebx
15547+ addl $cpu_gdt_table, %ebx
15548+#else
15549+ movl $cpu_gdt_table, %ebx
15550+#endif
15551+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15552+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15553 shl $16, %eax
15554 addl %esp, %eax /* the adjusted stack pointer */
15555 pushl_cfi $__KERNEL_DS
15556@@ -819,7 +1066,7 @@ vector=vector+1
15557 .endr
15558 2: jmp common_interrupt
15559 .endr
15560-END(irq_entries_start)
15561+ENDPROC(irq_entries_start)
15562
15563 .previous
15564 END(interrupt)
15565@@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
15566 pushl_cfi $do_coprocessor_error
15567 jmp error_code
15568 CFI_ENDPROC
15569-END(coprocessor_error)
15570+ENDPROC(coprocessor_error)
15571
15572 ENTRY(simd_coprocessor_error)
15573 RING0_INT_FRAME
15574@@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
15575 #endif
15576 jmp error_code
15577 CFI_ENDPROC
15578-END(simd_coprocessor_error)
15579+ENDPROC(simd_coprocessor_error)
15580
15581 ENTRY(device_not_available)
15582 RING0_INT_FRAME
15583@@ -896,7 +1143,7 @@ ENTRY(device_not_available)
15584 pushl_cfi $do_device_not_available
15585 jmp error_code
15586 CFI_ENDPROC
15587-END(device_not_available)
15588+ENDPROC(device_not_available)
15589
15590 #ifdef CONFIG_PARAVIRT
15591 ENTRY(native_iret)
15592@@ -905,12 +1152,12 @@ ENTRY(native_iret)
15593 .align 4
15594 .long native_iret, iret_exc
15595 .previous
15596-END(native_iret)
15597+ENDPROC(native_iret)
15598
15599 ENTRY(native_irq_enable_sysexit)
15600 sti
15601 sysexit
15602-END(native_irq_enable_sysexit)
15603+ENDPROC(native_irq_enable_sysexit)
15604 #endif
15605
15606 ENTRY(overflow)
15607@@ -919,7 +1166,7 @@ ENTRY(overflow)
15608 pushl_cfi $do_overflow
15609 jmp error_code
15610 CFI_ENDPROC
15611-END(overflow)
15612+ENDPROC(overflow)
15613
15614 ENTRY(bounds)
15615 RING0_INT_FRAME
15616@@ -927,7 +1174,7 @@ ENTRY(bounds)
15617 pushl_cfi $do_bounds
15618 jmp error_code
15619 CFI_ENDPROC
15620-END(bounds)
15621+ENDPROC(bounds)
15622
15623 ENTRY(invalid_op)
15624 RING0_INT_FRAME
15625@@ -935,7 +1182,7 @@ ENTRY(invalid_op)
15626 pushl_cfi $do_invalid_op
15627 jmp error_code
15628 CFI_ENDPROC
15629-END(invalid_op)
15630+ENDPROC(invalid_op)
15631
15632 ENTRY(coprocessor_segment_overrun)
15633 RING0_INT_FRAME
15634@@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
15635 pushl_cfi $do_coprocessor_segment_overrun
15636 jmp error_code
15637 CFI_ENDPROC
15638-END(coprocessor_segment_overrun)
15639+ENDPROC(coprocessor_segment_overrun)
15640
15641 ENTRY(invalid_TSS)
15642 RING0_EC_FRAME
15643 pushl_cfi $do_invalid_TSS
15644 jmp error_code
15645 CFI_ENDPROC
15646-END(invalid_TSS)
15647+ENDPROC(invalid_TSS)
15648
15649 ENTRY(segment_not_present)
15650 RING0_EC_FRAME
15651 pushl_cfi $do_segment_not_present
15652 jmp error_code
15653 CFI_ENDPROC
15654-END(segment_not_present)
15655+ENDPROC(segment_not_present)
15656
15657 ENTRY(stack_segment)
15658 RING0_EC_FRAME
15659 pushl_cfi $do_stack_segment
15660 jmp error_code
15661 CFI_ENDPROC
15662-END(stack_segment)
15663+ENDPROC(stack_segment)
15664
15665 ENTRY(alignment_check)
15666 RING0_EC_FRAME
15667 pushl_cfi $do_alignment_check
15668 jmp error_code
15669 CFI_ENDPROC
15670-END(alignment_check)
15671+ENDPROC(alignment_check)
15672
15673 ENTRY(divide_error)
15674 RING0_INT_FRAME
15675@@ -979,7 +1226,7 @@ ENTRY(divide_error)
15676 pushl_cfi $do_divide_error
15677 jmp error_code
15678 CFI_ENDPROC
15679-END(divide_error)
15680+ENDPROC(divide_error)
15681
15682 #ifdef CONFIG_X86_MCE
15683 ENTRY(machine_check)
15684@@ -988,7 +1235,7 @@ ENTRY(machine_check)
15685 pushl_cfi machine_check_vector
15686 jmp error_code
15687 CFI_ENDPROC
15688-END(machine_check)
15689+ENDPROC(machine_check)
15690 #endif
15691
15692 ENTRY(spurious_interrupt_bug)
15693@@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
15694 pushl_cfi $do_spurious_interrupt_bug
15695 jmp error_code
15696 CFI_ENDPROC
15697-END(spurious_interrupt_bug)
15698+ENDPROC(spurious_interrupt_bug)
15699 /*
15700 * End of kprobes section
15701 */
15702@@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15703
15704 ENTRY(mcount)
15705 ret
15706-END(mcount)
15707+ENDPROC(mcount)
15708
15709 ENTRY(ftrace_caller)
15710 cmpl $0, function_trace_stop
15711@@ -1141,7 +1388,7 @@ ftrace_graph_call:
15712 .globl ftrace_stub
15713 ftrace_stub:
15714 ret
15715-END(ftrace_caller)
15716+ENDPROC(ftrace_caller)
15717
15718 #else /* ! CONFIG_DYNAMIC_FTRACE */
15719
15720@@ -1177,7 +1424,7 @@ trace:
15721 popl %ecx
15722 popl %eax
15723 jmp ftrace_stub
15724-END(mcount)
15725+ENDPROC(mcount)
15726 #endif /* CONFIG_DYNAMIC_FTRACE */
15727 #endif /* CONFIG_FUNCTION_TRACER */
15728
15729@@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15730 popl %ecx
15731 popl %eax
15732 ret
15733-END(ftrace_graph_caller)
15734+ENDPROC(ftrace_graph_caller)
15735
15736 .globl return_to_handler
15737 return_to_handler:
15738@@ -1253,15 +1500,18 @@ error_code:
15739 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15740 REG_TO_PTGS %ecx
15741 SET_KERNEL_GS %ecx
15742- movl $(__USER_DS), %ecx
15743+ movl $(__KERNEL_DS), %ecx
15744 movl %ecx, %ds
15745 movl %ecx, %es
15746+
15747+ pax_enter_kernel
15748+
15749 TRACE_IRQS_OFF
15750 movl %esp,%eax # pt_regs pointer
15751 call *%edi
15752 jmp ret_from_exception
15753 CFI_ENDPROC
15754-END(page_fault)
15755+ENDPROC(page_fault)
15756
15757 /*
15758 * Debug traps and NMI can happen at the one SYSENTER instruction
15759@@ -1303,7 +1553,7 @@ debug_stack_correct:
15760 call do_debug
15761 jmp ret_from_exception
15762 CFI_ENDPROC
15763-END(debug)
15764+ENDPROC(debug)
15765
15766 /*
15767 * NMI is doubly nasty. It can happen _while_ we're handling
15768@@ -1340,6 +1590,9 @@ nmi_stack_correct:
15769 xorl %edx,%edx # zero error code
15770 movl %esp,%eax # pt_regs pointer
15771 call do_nmi
15772+
15773+ pax_exit_kernel
15774+
15775 jmp restore_all_notrace
15776 CFI_ENDPROC
15777
15778@@ -1376,12 +1629,15 @@ nmi_espfix_stack:
15779 FIXUP_ESPFIX_STACK # %eax == %esp
15780 xorl %edx,%edx # zero error code
15781 call do_nmi
15782+
15783+ pax_exit_kernel
15784+
15785 RESTORE_REGS
15786 lss 12+4(%esp), %esp # back to espfix stack
15787 CFI_ADJUST_CFA_OFFSET -24
15788 jmp irq_return
15789 CFI_ENDPROC
15790-END(nmi)
15791+ENDPROC(nmi)
15792
15793 ENTRY(int3)
15794 RING0_INT_FRAME
15795@@ -1393,14 +1649,14 @@ ENTRY(int3)
15796 call do_int3
15797 jmp ret_from_exception
15798 CFI_ENDPROC
15799-END(int3)
15800+ENDPROC(int3)
15801
15802 ENTRY(general_protection)
15803 RING0_EC_FRAME
15804 pushl_cfi $do_general_protection
15805 jmp error_code
15806 CFI_ENDPROC
15807-END(general_protection)
15808+ENDPROC(general_protection)
15809
15810 #ifdef CONFIG_KVM_GUEST
15811 ENTRY(async_page_fault)
15812@@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
15813 pushl_cfi $do_async_page_fault
15814 jmp error_code
15815 CFI_ENDPROC
15816-END(async_page_fault)
15817+ENDPROC(async_page_fault)
15818 #endif
15819
15820 /*
15821diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15822index 1333d98..b340ca2 100644
15823--- a/arch/x86/kernel/entry_64.S
15824+++ b/arch/x86/kernel/entry_64.S
15825@@ -56,6 +56,8 @@
15826 #include <asm/ftrace.h>
15827 #include <asm/percpu.h>
15828 #include <linux/err.h>
15829+#include <asm/pgtable.h>
15830+#include <asm/alternative-asm.h>
15831
15832 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15833 #include <linux/elf-em.h>
15834@@ -69,8 +71,9 @@
15835 #ifdef CONFIG_FUNCTION_TRACER
15836 #ifdef CONFIG_DYNAMIC_FTRACE
15837 ENTRY(mcount)
15838+ pax_force_retaddr
15839 retq
15840-END(mcount)
15841+ENDPROC(mcount)
15842
15843 ENTRY(ftrace_caller)
15844 cmpl $0, function_trace_stop
15845@@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15846 #endif
15847
15848 GLOBAL(ftrace_stub)
15849+ pax_force_retaddr
15850 retq
15851-END(ftrace_caller)
15852+ENDPROC(ftrace_caller)
15853
15854 #else /* ! CONFIG_DYNAMIC_FTRACE */
15855 ENTRY(mcount)
15856@@ -113,6 +117,7 @@ ENTRY(mcount)
15857 #endif
15858
15859 GLOBAL(ftrace_stub)
15860+ pax_force_retaddr
15861 retq
15862
15863 trace:
15864@@ -122,12 +127,13 @@ trace:
15865 movq 8(%rbp), %rsi
15866 subq $MCOUNT_INSN_SIZE, %rdi
15867
15868+ pax_force_fptr ftrace_trace_function
15869 call *ftrace_trace_function
15870
15871 MCOUNT_RESTORE_FRAME
15872
15873 jmp ftrace_stub
15874-END(mcount)
15875+ENDPROC(mcount)
15876 #endif /* CONFIG_DYNAMIC_FTRACE */
15877 #endif /* CONFIG_FUNCTION_TRACER */
15878
15879@@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15880
15881 MCOUNT_RESTORE_FRAME
15882
15883+ pax_force_retaddr
15884 retq
15885-END(ftrace_graph_caller)
15886+ENDPROC(ftrace_graph_caller)
15887
15888 GLOBAL(return_to_handler)
15889 subq $24, %rsp
15890@@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15891 movq 8(%rsp), %rdx
15892 movq (%rsp), %rax
15893 addq $24, %rsp
15894+ pax_force_fptr %rdi
15895 jmp *%rdi
15896 #endif
15897
15898@@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15899 ENDPROC(native_usergs_sysret64)
15900 #endif /* CONFIG_PARAVIRT */
15901
15902+ .macro ljmpq sel, off
15903+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15904+ .byte 0x48; ljmp *1234f(%rip)
15905+ .pushsection .rodata
15906+ .align 16
15907+ 1234: .quad \off; .word \sel
15908+ .popsection
15909+#else
15910+ pushq $\sel
15911+ pushq $\off
15912+ lretq
15913+#endif
15914+ .endm
15915+
15916+ .macro pax_enter_kernel
15917+ pax_set_fptr_mask
15918+#ifdef CONFIG_PAX_KERNEXEC
15919+ call pax_enter_kernel
15920+#endif
15921+ .endm
15922+
15923+ .macro pax_exit_kernel
15924+#ifdef CONFIG_PAX_KERNEXEC
15925+ call pax_exit_kernel
15926+#endif
15927+ .endm
15928+
15929+#ifdef CONFIG_PAX_KERNEXEC
15930+ENTRY(pax_enter_kernel)
15931+ pushq %rdi
15932+
15933+#ifdef CONFIG_PARAVIRT
15934+ PV_SAVE_REGS(CLBR_RDI)
15935+#endif
15936+
15937+ GET_CR0_INTO_RDI
15938+ bts $16,%rdi
15939+ jnc 3f
15940+ mov %cs,%edi
15941+ cmp $__KERNEL_CS,%edi
15942+ jnz 2f
15943+1:
15944+
15945+#ifdef CONFIG_PARAVIRT
15946+ PV_RESTORE_REGS(CLBR_RDI)
15947+#endif
15948+
15949+ popq %rdi
15950+ pax_force_retaddr
15951+ retq
15952+
15953+2: ljmpq __KERNEL_CS,1f
15954+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15955+4: SET_RDI_INTO_CR0
15956+ jmp 1b
15957+ENDPROC(pax_enter_kernel)
15958+
15959+ENTRY(pax_exit_kernel)
15960+ pushq %rdi
15961+
15962+#ifdef CONFIG_PARAVIRT
15963+ PV_SAVE_REGS(CLBR_RDI)
15964+#endif
15965+
15966+ mov %cs,%rdi
15967+ cmp $__KERNEXEC_KERNEL_CS,%edi
15968+ jz 2f
15969+1:
15970+
15971+#ifdef CONFIG_PARAVIRT
15972+ PV_RESTORE_REGS(CLBR_RDI);
15973+#endif
15974+
15975+ popq %rdi
15976+ pax_force_retaddr
15977+ retq
15978+
15979+2: GET_CR0_INTO_RDI
15980+ btr $16,%rdi
15981+ ljmpq __KERNEL_CS,3f
15982+3: SET_RDI_INTO_CR0
15983+ jmp 1b
15984+#ifdef CONFIG_PARAVIRT
15985+ PV_RESTORE_REGS(CLBR_RDI);
15986+#endif
15987+
15988+ popq %rdi
15989+ pax_force_retaddr
15990+ retq
15991+ENDPROC(pax_exit_kernel)
15992+#endif
15993+
15994+ .macro pax_enter_kernel_user
15995+ pax_set_fptr_mask
15996+#ifdef CONFIG_PAX_MEMORY_UDEREF
15997+ call pax_enter_kernel_user
15998+#endif
15999+ .endm
16000+
16001+ .macro pax_exit_kernel_user
16002+#ifdef CONFIG_PAX_MEMORY_UDEREF
16003+ call pax_exit_kernel_user
16004+#endif
16005+#ifdef CONFIG_PAX_RANDKSTACK
16006+ pushq %rax
16007+ call pax_randomize_kstack
16008+ popq %rax
16009+#endif
16010+ .endm
16011+
16012+#ifdef CONFIG_PAX_MEMORY_UDEREF
16013+ENTRY(pax_enter_kernel_user)
16014+ pushq %rdi
16015+ pushq %rbx
16016+
16017+#ifdef CONFIG_PARAVIRT
16018+ PV_SAVE_REGS(CLBR_RDI)
16019+#endif
16020+
16021+ GET_CR3_INTO_RDI
16022+ mov %rdi,%rbx
16023+ add $__START_KERNEL_map,%rbx
16024+ sub phys_base(%rip),%rbx
16025+
16026+#ifdef CONFIG_PARAVIRT
16027+ pushq %rdi
16028+ cmpl $0, pv_info+PARAVIRT_enabled
16029+ jz 1f
16030+ i = 0
16031+ .rept USER_PGD_PTRS
16032+ mov i*8(%rbx),%rsi
16033+ mov $0,%sil
16034+ lea i*8(%rbx),%rdi
16035+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16036+ i = i + 1
16037+ .endr
16038+ jmp 2f
16039+1:
16040+#endif
16041+
16042+ i = 0
16043+ .rept USER_PGD_PTRS
16044+ movb $0,i*8(%rbx)
16045+ i = i + 1
16046+ .endr
16047+
16048+#ifdef CONFIG_PARAVIRT
16049+2: popq %rdi
16050+#endif
16051+ SET_RDI_INTO_CR3
16052+
16053+#ifdef CONFIG_PAX_KERNEXEC
16054+ GET_CR0_INTO_RDI
16055+ bts $16,%rdi
16056+ SET_RDI_INTO_CR0
16057+#endif
16058+
16059+#ifdef CONFIG_PARAVIRT
16060+ PV_RESTORE_REGS(CLBR_RDI)
16061+#endif
16062+
16063+ popq %rbx
16064+ popq %rdi
16065+ pax_force_retaddr
16066+ retq
16067+ENDPROC(pax_enter_kernel_user)
16068+
16069+ENTRY(pax_exit_kernel_user)
16070+ push %rdi
16071+
16072+#ifdef CONFIG_PARAVIRT
16073+ pushq %rbx
16074+ PV_SAVE_REGS(CLBR_RDI)
16075+#endif
16076+
16077+#ifdef CONFIG_PAX_KERNEXEC
16078+ GET_CR0_INTO_RDI
16079+ btr $16,%rdi
16080+ SET_RDI_INTO_CR0
16081+#endif
16082+
16083+ GET_CR3_INTO_RDI
16084+ add $__START_KERNEL_map,%rdi
16085+ sub phys_base(%rip),%rdi
16086+
16087+#ifdef CONFIG_PARAVIRT
16088+ cmpl $0, pv_info+PARAVIRT_enabled
16089+ jz 1f
16090+ mov %rdi,%rbx
16091+ i = 0
16092+ .rept USER_PGD_PTRS
16093+ mov i*8(%rbx),%rsi
16094+ mov $0x67,%sil
16095+ lea i*8(%rbx),%rdi
16096+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16097+ i = i + 1
16098+ .endr
16099+ jmp 2f
16100+1:
16101+#endif
16102+
16103+ i = 0
16104+ .rept USER_PGD_PTRS
16105+ movb $0x67,i*8(%rdi)
16106+ i = i + 1
16107+ .endr
16108+
16109+#ifdef CONFIG_PARAVIRT
16110+2: PV_RESTORE_REGS(CLBR_RDI)
16111+ popq %rbx
16112+#endif
16113+
16114+ popq %rdi
16115+ pax_force_retaddr
16116+ retq
16117+ENDPROC(pax_exit_kernel_user)
16118+#endif
16119+
16120+.macro pax_erase_kstack
16121+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16122+ call pax_erase_kstack
16123+#endif
16124+.endm
16125+
16126+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16127+/*
16128+ * r11: thread_info
16129+ * rcx, rdx: can be clobbered
16130+ */
16131+ENTRY(pax_erase_kstack)
16132+ pushq %rdi
16133+ pushq %rax
16134+ pushq %r11
16135+
16136+ GET_THREAD_INFO(%r11)
16137+ mov TI_lowest_stack(%r11), %rdi
16138+ mov $-0xBEEF, %rax
16139+ std
16140+
16141+1: mov %edi, %ecx
16142+ and $THREAD_SIZE_asm - 1, %ecx
16143+ shr $3, %ecx
16144+ repne scasq
16145+ jecxz 2f
16146+
16147+ cmp $2*8, %ecx
16148+ jc 2f
16149+
16150+ mov $2*8, %ecx
16151+ repe scasq
16152+ jecxz 2f
16153+ jne 1b
16154+
16155+2: cld
16156+ mov %esp, %ecx
16157+ sub %edi, %ecx
16158+
16159+ cmp $THREAD_SIZE_asm, %rcx
16160+ jb 3f
16161+ ud2
16162+3:
16163+
16164+ shr $3, %ecx
16165+ rep stosq
16166+
16167+ mov TI_task_thread_sp0(%r11), %rdi
16168+ sub $256, %rdi
16169+ mov %rdi, TI_lowest_stack(%r11)
16170+
16171+ popq %r11
16172+ popq %rax
16173+ popq %rdi
16174+ pax_force_retaddr
16175+ ret
16176+ENDPROC(pax_erase_kstack)
16177+#endif
16178
16179 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16180 #ifdef CONFIG_TRACE_IRQFLAGS
16181@@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
16182 .endm
16183
16184 .macro UNFAKE_STACK_FRAME
16185- addq $8*6, %rsp
16186- CFI_ADJUST_CFA_OFFSET -(6*8)
16187+ addq $8*6 + ARG_SKIP, %rsp
16188+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16189 .endm
16190
16191 /*
16192@@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
16193 movq %rsp, %rsi
16194
16195 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16196- testl $3, CS(%rdi)
16197+ testb $3, CS(%rdi)
16198 je 1f
16199 SWAPGS
16200 /*
16201@@ -356,9 +640,10 @@ ENTRY(save_rest)
16202 movq_cfi r15, R15+16
16203 movq %r11, 8(%rsp) /* return address */
16204 FIXUP_TOP_OF_STACK %r11, 16
16205+ pax_force_retaddr
16206 ret
16207 CFI_ENDPROC
16208-END(save_rest)
16209+ENDPROC(save_rest)
16210
16211 /* save complete stack frame */
16212 .pushsection .kprobes.text, "ax"
16213@@ -387,9 +672,10 @@ ENTRY(save_paranoid)
16214 js 1f /* negative -> in kernel */
16215 SWAPGS
16216 xorl %ebx,%ebx
16217-1: ret
16218+1: pax_force_retaddr_bts
16219+ ret
16220 CFI_ENDPROC
16221-END(save_paranoid)
16222+ENDPROC(save_paranoid)
16223 .popsection
16224
16225 /*
16226@@ -411,7 +697,7 @@ ENTRY(ret_from_fork)
16227
16228 RESTORE_REST
16229
16230- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16231+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16232 jz retint_restore_args
16233
16234 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16235@@ -421,7 +707,7 @@ ENTRY(ret_from_fork)
16236 jmp ret_from_sys_call # go to the SYSRET fastpath
16237
16238 CFI_ENDPROC
16239-END(ret_from_fork)
16240+ENDPROC(ret_from_fork)
16241
16242 /*
16243 * System call entry. Up to 6 arguments in registers are supported.
16244@@ -457,7 +743,7 @@ END(ret_from_fork)
16245 ENTRY(system_call)
16246 CFI_STARTPROC simple
16247 CFI_SIGNAL_FRAME
16248- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16249+ CFI_DEF_CFA rsp,0
16250 CFI_REGISTER rip,rcx
16251 /*CFI_REGISTER rflags,r11*/
16252 SWAPGS_UNSAFE_STACK
16253@@ -470,21 +756,23 @@ GLOBAL(system_call_after_swapgs)
16254
16255 movq %rsp,PER_CPU_VAR(old_rsp)
16256 movq PER_CPU_VAR(kernel_stack),%rsp
16257+ SAVE_ARGS 8*6,0
16258+ pax_enter_kernel_user
16259 /*
16260 * No need to follow this irqs off/on section - it's straight
16261 * and short:
16262 */
16263 ENABLE_INTERRUPTS(CLBR_NONE)
16264- SAVE_ARGS 8,0
16265 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16266 movq %rcx,RIP-ARGOFFSET(%rsp)
16267 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16268- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16269+ GET_THREAD_INFO(%rcx)
16270+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16271 jnz tracesys
16272 system_call_fastpath:
16273 cmpq $__NR_syscall_max,%rax
16274 ja badsys
16275- movq %r10,%rcx
16276+ movq R10-ARGOFFSET(%rsp),%rcx
16277 call *sys_call_table(,%rax,8) # XXX: rip relative
16278 movq %rax,RAX-ARGOFFSET(%rsp)
16279 /*
16280@@ -498,10 +786,13 @@ sysret_check:
16281 LOCKDEP_SYS_EXIT
16282 DISABLE_INTERRUPTS(CLBR_NONE)
16283 TRACE_IRQS_OFF
16284- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16285+ GET_THREAD_INFO(%rcx)
16286+ movl TI_flags(%rcx),%edx
16287 andl %edi,%edx
16288 jnz sysret_careful
16289 CFI_REMEMBER_STATE
16290+ pax_exit_kernel_user
16291+ pax_erase_kstack
16292 /*
16293 * sysretq will re-enable interrupts:
16294 */
16295@@ -553,14 +844,18 @@ badsys:
16296 * jump back to the normal fast path.
16297 */
16298 auditsys:
16299- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16300+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16301 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16302 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16303 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16304 movq %rax,%rsi /* 2nd arg: syscall number */
16305 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16306 call __audit_syscall_entry
16307+
16308+ pax_erase_kstack
16309+
16310 LOAD_ARGS 0 /* reload call-clobbered registers */
16311+ pax_set_fptr_mask
16312 jmp system_call_fastpath
16313
16314 /*
16315@@ -581,7 +876,7 @@ sysret_audit:
16316 /* Do syscall tracing */
16317 tracesys:
16318 #ifdef CONFIG_AUDITSYSCALL
16319- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16320+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16321 jz auditsys
16322 #endif
16323 SAVE_REST
16324@@ -589,16 +884,20 @@ tracesys:
16325 FIXUP_TOP_OF_STACK %rdi
16326 movq %rsp,%rdi
16327 call syscall_trace_enter
16328+
16329+ pax_erase_kstack
16330+
16331 /*
16332 * Reload arg registers from stack in case ptrace changed them.
16333 * We don't reload %rax because syscall_trace_enter() returned
16334 * the value it wants us to use in the table lookup.
16335 */
16336 LOAD_ARGS ARGOFFSET, 1
16337+ pax_set_fptr_mask
16338 RESTORE_REST
16339 cmpq $__NR_syscall_max,%rax
16340 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16341- movq %r10,%rcx /* fixup for C */
16342+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16343 call *sys_call_table(,%rax,8)
16344 movq %rax,RAX-ARGOFFSET(%rsp)
16345 /* Use IRET because user could have changed frame */
16346@@ -619,6 +918,7 @@ GLOBAL(int_with_check)
16347 andl %edi,%edx
16348 jnz int_careful
16349 andl $~TS_COMPAT,TI_status(%rcx)
16350+ pax_erase_kstack
16351 jmp retint_swapgs
16352
16353 /* Either reschedule or signal or syscall exit tracking needed. */
16354@@ -665,7 +965,7 @@ int_restore_rest:
16355 TRACE_IRQS_OFF
16356 jmp int_with_check
16357 CFI_ENDPROC
16358-END(system_call)
16359+ENDPROC(system_call)
16360
16361 /*
16362 * Certain special system calls that need to save a complete full stack frame.
16363@@ -681,7 +981,7 @@ ENTRY(\label)
16364 call \func
16365 jmp ptregscall_common
16366 CFI_ENDPROC
16367-END(\label)
16368+ENDPROC(\label)
16369 .endm
16370
16371 PTREGSCALL stub_clone, sys_clone, %r8
16372@@ -699,9 +999,10 @@ ENTRY(ptregscall_common)
16373 movq_cfi_restore R12+8, r12
16374 movq_cfi_restore RBP+8, rbp
16375 movq_cfi_restore RBX+8, rbx
16376+ pax_force_retaddr
16377 ret $REST_SKIP /* pop extended registers */
16378 CFI_ENDPROC
16379-END(ptregscall_common)
16380+ENDPROC(ptregscall_common)
16381
16382 ENTRY(stub_execve)
16383 CFI_STARTPROC
16384@@ -716,7 +1017,7 @@ ENTRY(stub_execve)
16385 RESTORE_REST
16386 jmp int_ret_from_sys_call
16387 CFI_ENDPROC
16388-END(stub_execve)
16389+ENDPROC(stub_execve)
16390
16391 /*
16392 * sigreturn is special because it needs to restore all registers on return.
16393@@ -734,7 +1035,7 @@ ENTRY(stub_rt_sigreturn)
16394 RESTORE_REST
16395 jmp int_ret_from_sys_call
16396 CFI_ENDPROC
16397-END(stub_rt_sigreturn)
16398+ENDPROC(stub_rt_sigreturn)
16399
16400 /*
16401 * Build the entry stubs and pointer table with some assembler magic.
16402@@ -769,7 +1070,7 @@ vector=vector+1
16403 2: jmp common_interrupt
16404 .endr
16405 CFI_ENDPROC
16406-END(irq_entries_start)
16407+ENDPROC(irq_entries_start)
16408
16409 .previous
16410 END(interrupt)
16411@@ -789,6 +1090,16 @@ END(interrupt)
16412 subq $ORIG_RAX-RBP, %rsp
16413 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16414 SAVE_ARGS_IRQ
16415+#ifdef CONFIG_PAX_MEMORY_UDEREF
16416+ testb $3, CS(%rdi)
16417+ jnz 1f
16418+ pax_enter_kernel
16419+ jmp 2f
16420+1: pax_enter_kernel_user
16421+2:
16422+#else
16423+ pax_enter_kernel
16424+#endif
16425 call \func
16426 .endm
16427
16428@@ -820,7 +1131,7 @@ ret_from_intr:
16429
16430 exit_intr:
16431 GET_THREAD_INFO(%rcx)
16432- testl $3,CS-ARGOFFSET(%rsp)
16433+ testb $3,CS-ARGOFFSET(%rsp)
16434 je retint_kernel
16435
16436 /* Interrupt came from user space */
16437@@ -842,12 +1153,15 @@ retint_swapgs: /* return to user-space */
16438 * The iretq could re-enable interrupts:
16439 */
16440 DISABLE_INTERRUPTS(CLBR_ANY)
16441+ pax_exit_kernel_user
16442 TRACE_IRQS_IRETQ
16443 SWAPGS
16444 jmp restore_args
16445
16446 retint_restore_args: /* return to kernel space */
16447 DISABLE_INTERRUPTS(CLBR_ANY)
16448+ pax_exit_kernel
16449+ pax_force_retaddr RIP-ARGOFFSET
16450 /*
16451 * The iretq could re-enable interrupts:
16452 */
16453@@ -936,7 +1250,7 @@ ENTRY(retint_kernel)
16454 #endif
16455
16456 CFI_ENDPROC
16457-END(common_interrupt)
16458+ENDPROC(common_interrupt)
16459 /*
16460 * End of kprobes section
16461 */
16462@@ -953,7 +1267,7 @@ ENTRY(\sym)
16463 interrupt \do_sym
16464 jmp ret_from_intr
16465 CFI_ENDPROC
16466-END(\sym)
16467+ENDPROC(\sym)
16468 .endm
16469
16470 #ifdef CONFIG_SMP
16471@@ -1026,12 +1340,22 @@ ENTRY(\sym)
16472 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16473 call error_entry
16474 DEFAULT_FRAME 0
16475+#ifdef CONFIG_PAX_MEMORY_UDEREF
16476+ testb $3, CS(%rsp)
16477+ jnz 1f
16478+ pax_enter_kernel
16479+ jmp 2f
16480+1: pax_enter_kernel_user
16481+2:
16482+#else
16483+ pax_enter_kernel
16484+#endif
16485 movq %rsp,%rdi /* pt_regs pointer */
16486 xorl %esi,%esi /* no error code */
16487 call \do_sym
16488 jmp error_exit /* %ebx: no swapgs flag */
16489 CFI_ENDPROC
16490-END(\sym)
16491+ENDPROC(\sym)
16492 .endm
16493
16494 .macro paranoidzeroentry sym do_sym
16495@@ -1043,15 +1367,25 @@ ENTRY(\sym)
16496 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16497 call save_paranoid
16498 TRACE_IRQS_OFF
16499+#ifdef CONFIG_PAX_MEMORY_UDEREF
16500+ testb $3, CS(%rsp)
16501+ jnz 1f
16502+ pax_enter_kernel
16503+ jmp 2f
16504+1: pax_enter_kernel_user
16505+2:
16506+#else
16507+ pax_enter_kernel
16508+#endif
16509 movq %rsp,%rdi /* pt_regs pointer */
16510 xorl %esi,%esi /* no error code */
16511 call \do_sym
16512 jmp paranoid_exit /* %ebx: no swapgs flag */
16513 CFI_ENDPROC
16514-END(\sym)
16515+ENDPROC(\sym)
16516 .endm
16517
16518-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16519+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16520 .macro paranoidzeroentry_ist sym do_sym ist
16521 ENTRY(\sym)
16522 INTR_FRAME
16523@@ -1061,14 +1395,30 @@ ENTRY(\sym)
16524 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16525 call save_paranoid
16526 TRACE_IRQS_OFF
16527+#ifdef CONFIG_PAX_MEMORY_UDEREF
16528+ testb $3, CS(%rsp)
16529+ jnz 1f
16530+ pax_enter_kernel
16531+ jmp 2f
16532+1: pax_enter_kernel_user
16533+2:
16534+#else
16535+ pax_enter_kernel
16536+#endif
16537 movq %rsp,%rdi /* pt_regs pointer */
16538 xorl %esi,%esi /* no error code */
16539+#ifdef CONFIG_SMP
16540+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16541+ lea init_tss(%r12), %r12
16542+#else
16543+ lea init_tss(%rip), %r12
16544+#endif
16545 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16546 call \do_sym
16547 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16548 jmp paranoid_exit /* %ebx: no swapgs flag */
16549 CFI_ENDPROC
16550-END(\sym)
16551+ENDPROC(\sym)
16552 .endm
16553
16554 .macro errorentry sym do_sym
16555@@ -1079,13 +1429,23 @@ ENTRY(\sym)
16556 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16557 call error_entry
16558 DEFAULT_FRAME 0
16559+#ifdef CONFIG_PAX_MEMORY_UDEREF
16560+ testb $3, CS(%rsp)
16561+ jnz 1f
16562+ pax_enter_kernel
16563+ jmp 2f
16564+1: pax_enter_kernel_user
16565+2:
16566+#else
16567+ pax_enter_kernel
16568+#endif
16569 movq %rsp,%rdi /* pt_regs pointer */
16570 movq ORIG_RAX(%rsp),%rsi /* get error code */
16571 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16572 call \do_sym
16573 jmp error_exit /* %ebx: no swapgs flag */
16574 CFI_ENDPROC
16575-END(\sym)
16576+ENDPROC(\sym)
16577 .endm
16578
16579 /* error code is on the stack already */
16580@@ -1098,13 +1458,23 @@ ENTRY(\sym)
16581 call save_paranoid
16582 DEFAULT_FRAME 0
16583 TRACE_IRQS_OFF
16584+#ifdef CONFIG_PAX_MEMORY_UDEREF
16585+ testb $3, CS(%rsp)
16586+ jnz 1f
16587+ pax_enter_kernel
16588+ jmp 2f
16589+1: pax_enter_kernel_user
16590+2:
16591+#else
16592+ pax_enter_kernel
16593+#endif
16594 movq %rsp,%rdi /* pt_regs pointer */
16595 movq ORIG_RAX(%rsp),%rsi /* get error code */
16596 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16597 call \do_sym
16598 jmp paranoid_exit /* %ebx: no swapgs flag */
16599 CFI_ENDPROC
16600-END(\sym)
16601+ENDPROC(\sym)
16602 .endm
16603
16604 zeroentry divide_error do_divide_error
16605@@ -1134,9 +1504,10 @@ gs_change:
16606 2: mfence /* workaround */
16607 SWAPGS
16608 popfq_cfi
16609+ pax_force_retaddr
16610 ret
16611 CFI_ENDPROC
16612-END(native_load_gs_index)
16613+ENDPROC(native_load_gs_index)
16614
16615 .section __ex_table,"a"
16616 .align 8
16617@@ -1158,13 +1529,14 @@ ENTRY(kernel_thread_helper)
16618 * Here we are in the child and the registers are set as they were
16619 * at kernel_thread() invocation in the parent.
16620 */
16621+ pax_force_fptr %rsi
16622 call *%rsi
16623 # exit
16624 mov %eax, %edi
16625 call do_exit
16626 ud2 # padding for call trace
16627 CFI_ENDPROC
16628-END(kernel_thread_helper)
16629+ENDPROC(kernel_thread_helper)
16630
16631 /*
16632 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16633@@ -1191,11 +1563,11 @@ ENTRY(kernel_execve)
16634 RESTORE_REST
16635 testq %rax,%rax
16636 je int_ret_from_sys_call
16637- RESTORE_ARGS
16638 UNFAKE_STACK_FRAME
16639+ pax_force_retaddr
16640 ret
16641 CFI_ENDPROC
16642-END(kernel_execve)
16643+ENDPROC(kernel_execve)
16644
16645 /* Call softirq on interrupt stack. Interrupts are off. */
16646 ENTRY(call_softirq)
16647@@ -1213,9 +1585,10 @@ ENTRY(call_softirq)
16648 CFI_DEF_CFA_REGISTER rsp
16649 CFI_ADJUST_CFA_OFFSET -8
16650 decl PER_CPU_VAR(irq_count)
16651+ pax_force_retaddr
16652 ret
16653 CFI_ENDPROC
16654-END(call_softirq)
16655+ENDPROC(call_softirq)
16656
16657 #ifdef CONFIG_XEN
16658 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16659@@ -1253,7 +1626,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16660 decl PER_CPU_VAR(irq_count)
16661 jmp error_exit
16662 CFI_ENDPROC
16663-END(xen_do_hypervisor_callback)
16664+ENDPROC(xen_do_hypervisor_callback)
16665
16666 /*
16667 * Hypervisor uses this for application faults while it executes.
16668@@ -1312,7 +1685,7 @@ ENTRY(xen_failsafe_callback)
16669 SAVE_ALL
16670 jmp error_exit
16671 CFI_ENDPROC
16672-END(xen_failsafe_callback)
16673+ENDPROC(xen_failsafe_callback)
16674
16675 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16676 xen_hvm_callback_vector xen_evtchn_do_upcall
16677@@ -1361,16 +1734,31 @@ ENTRY(paranoid_exit)
16678 TRACE_IRQS_OFF
16679 testl %ebx,%ebx /* swapgs needed? */
16680 jnz paranoid_restore
16681- testl $3,CS(%rsp)
16682+ testb $3,CS(%rsp)
16683 jnz paranoid_userspace
16684+#ifdef CONFIG_PAX_MEMORY_UDEREF
16685+ pax_exit_kernel
16686+ TRACE_IRQS_IRETQ 0
16687+ SWAPGS_UNSAFE_STACK
16688+ RESTORE_ALL 8
16689+ pax_force_retaddr_bts
16690+ jmp irq_return
16691+#endif
16692 paranoid_swapgs:
16693+#ifdef CONFIG_PAX_MEMORY_UDEREF
16694+ pax_exit_kernel_user
16695+#else
16696+ pax_exit_kernel
16697+#endif
16698 TRACE_IRQS_IRETQ 0
16699 SWAPGS_UNSAFE_STACK
16700 RESTORE_ALL 8
16701 jmp irq_return
16702 paranoid_restore:
16703+ pax_exit_kernel
16704 TRACE_IRQS_IRETQ 0
16705 RESTORE_ALL 8
16706+ pax_force_retaddr_bts
16707 jmp irq_return
16708 paranoid_userspace:
16709 GET_THREAD_INFO(%rcx)
16710@@ -1399,7 +1787,7 @@ paranoid_schedule:
16711 TRACE_IRQS_OFF
16712 jmp paranoid_userspace
16713 CFI_ENDPROC
16714-END(paranoid_exit)
16715+ENDPROC(paranoid_exit)
16716
16717 /*
16718 * Exception entry point. This expects an error code/orig_rax on the stack.
16719@@ -1426,12 +1814,13 @@ ENTRY(error_entry)
16720 movq_cfi r14, R14+8
16721 movq_cfi r15, R15+8
16722 xorl %ebx,%ebx
16723- testl $3,CS+8(%rsp)
16724+ testb $3,CS+8(%rsp)
16725 je error_kernelspace
16726 error_swapgs:
16727 SWAPGS
16728 error_sti:
16729 TRACE_IRQS_OFF
16730+ pax_force_retaddr_bts
16731 ret
16732
16733 /*
16734@@ -1458,7 +1847,7 @@ bstep_iret:
16735 movq %rcx,RIP+8(%rsp)
16736 jmp error_swapgs
16737 CFI_ENDPROC
16738-END(error_entry)
16739+ENDPROC(error_entry)
16740
16741
16742 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16743@@ -1478,7 +1867,7 @@ ENTRY(error_exit)
16744 jnz retint_careful
16745 jmp retint_swapgs
16746 CFI_ENDPROC
16747-END(error_exit)
16748+ENDPROC(error_exit)
16749
16750 /*
16751 * Test if a given stack is an NMI stack or not.
16752@@ -1535,9 +1924,11 @@ ENTRY(nmi)
16753 * If %cs was not the kernel segment, then the NMI triggered in user
16754 * space, which means it is definitely not nested.
16755 */
16756+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16757+ je 1f
16758 cmpl $__KERNEL_CS, 16(%rsp)
16759 jne first_nmi
16760-
16761+1:
16762 /*
16763 * Check the special variable on the stack to see if NMIs are
16764 * executing.
16765@@ -1659,6 +2050,16 @@ restart_nmi:
16766 */
16767 call save_paranoid
16768 DEFAULT_FRAME 0
16769+#ifdef CONFIG_PAX_MEMORY_UDEREF
16770+ testb $3, CS(%rsp)
16771+ jnz 1f
16772+ pax_enter_kernel
16773+ jmp 2f
16774+1: pax_enter_kernel_user
16775+2:
16776+#else
16777+ pax_enter_kernel
16778+#endif
16779 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16780 movq %rsp,%rdi
16781 movq $-1,%rsi
16782@@ -1666,14 +2067,25 @@ restart_nmi:
16783 testl %ebx,%ebx /* swapgs needed? */
16784 jnz nmi_restore
16785 nmi_swapgs:
16786+#ifdef CONFIG_PAX_MEMORY_UDEREF
16787+ pax_exit_kernel_user
16788+#else
16789+ pax_exit_kernel
16790+#endif
16791 SWAPGS_UNSAFE_STACK
16792+ RESTORE_ALL 8
16793+ /* Clear the NMI executing stack variable */
16794+ movq $0, 10*8(%rsp)
16795+ jmp irq_return
16796 nmi_restore:
16797+ pax_exit_kernel
16798 RESTORE_ALL 8
16799+ pax_force_retaddr_bts
16800 /* Clear the NMI executing stack variable */
16801 movq $0, 10*8(%rsp)
16802 jmp irq_return
16803 CFI_ENDPROC
16804-END(nmi)
16805+ENDPROC(nmi)
16806
16807 /*
16808 * If an NMI hit an iret because of an exception or breakpoint,
16809@@ -1700,7 +2112,7 @@ ENTRY(ignore_sysret)
16810 mov $-ENOSYS,%eax
16811 sysret
16812 CFI_ENDPROC
16813-END(ignore_sysret)
16814+ENDPROC(ignore_sysret)
16815
16816 /*
16817 * End of kprobes section
16818diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16819index c9a281f..ce2f317 100644
16820--- a/arch/x86/kernel/ftrace.c
16821+++ b/arch/x86/kernel/ftrace.c
16822@@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16823 static const void *mod_code_newcode; /* holds the text to write to the IP */
16824
16825 static unsigned nmi_wait_count;
16826-static atomic_t nmi_update_count = ATOMIC_INIT(0);
16827+static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16828
16829 int ftrace_arch_read_dyn_info(char *buf, int size)
16830 {
16831@@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16832
16833 r = snprintf(buf, size, "%u %u",
16834 nmi_wait_count,
16835- atomic_read(&nmi_update_count));
16836+ atomic_read_unchecked(&nmi_update_count));
16837 return r;
16838 }
16839
16840@@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16841
16842 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16843 smp_rmb();
16844+ pax_open_kernel();
16845 ftrace_mod_code();
16846- atomic_inc(&nmi_update_count);
16847+ pax_close_kernel();
16848+ atomic_inc_unchecked(&nmi_update_count);
16849 }
16850 /* Must have previous changes seen before executions */
16851 smp_mb();
16852@@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16853 {
16854 unsigned char replaced[MCOUNT_INSN_SIZE];
16855
16856+ ip = ktla_ktva(ip);
16857+
16858 /*
16859 * Note: Due to modules and __init, code can
16860 * disappear and change, we need to protect against faulting
16861@@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16862 unsigned char old[MCOUNT_INSN_SIZE], *new;
16863 int ret;
16864
16865- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16866+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16867 new = ftrace_call_replace(ip, (unsigned long)func);
16868 ret = ftrace_modify_code(ip, old, new);
16869
16870@@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16871 {
16872 unsigned char code[MCOUNT_INSN_SIZE];
16873
16874+ ip = ktla_ktva(ip);
16875+
16876 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16877 return -EFAULT;
16878
16879diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16880index 51ff186..9e77418 100644
16881--- a/arch/x86/kernel/head32.c
16882+++ b/arch/x86/kernel/head32.c
16883@@ -19,6 +19,7 @@
16884 #include <asm/io_apic.h>
16885 #include <asm/bios_ebda.h>
16886 #include <asm/tlbflush.h>
16887+#include <asm/boot.h>
16888
16889 static void __init i386_default_early_setup(void)
16890 {
16891@@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16892
16893 void __init i386_start_kernel(void)
16894 {
16895- memblock_reserve(__pa_symbol(&_text),
16896- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16897+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16898
16899 #ifdef CONFIG_BLK_DEV_INITRD
16900 /* Reserve INITRD */
16901diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16902index ce0be7c..c41476e 100644
16903--- a/arch/x86/kernel/head_32.S
16904+++ b/arch/x86/kernel/head_32.S
16905@@ -25,6 +25,12 @@
16906 /* Physical address */
16907 #define pa(X) ((X) - __PAGE_OFFSET)
16908
16909+#ifdef CONFIG_PAX_KERNEXEC
16910+#define ta(X) (X)
16911+#else
16912+#define ta(X) ((X) - __PAGE_OFFSET)
16913+#endif
16914+
16915 /*
16916 * References to members of the new_cpu_data structure.
16917 */
16918@@ -54,11 +60,7 @@
16919 * and small than max_low_pfn, otherwise will waste some page table entries
16920 */
16921
16922-#if PTRS_PER_PMD > 1
16923-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16924-#else
16925-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16926-#endif
16927+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16928
16929 /* Number of possible pages in the lowmem region */
16930 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16931@@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16932 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16933
16934 /*
16935+ * Real beginning of normal "text" segment
16936+ */
16937+ENTRY(stext)
16938+ENTRY(_stext)
16939+
16940+/*
16941 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16942 * %esi points to the real-mode code as a 32-bit pointer.
16943 * CS and DS must be 4 GB flat segments, but we don't depend on
16944@@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16945 * can.
16946 */
16947 __HEAD
16948+
16949+#ifdef CONFIG_PAX_KERNEXEC
16950+ jmp startup_32
16951+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16952+.fill PAGE_SIZE-5,1,0xcc
16953+#endif
16954+
16955 ENTRY(startup_32)
16956 movl pa(stack_start),%ecx
16957
16958@@ -105,6 +120,57 @@ ENTRY(startup_32)
16959 2:
16960 leal -__PAGE_OFFSET(%ecx),%esp
16961
16962+#ifdef CONFIG_SMP
16963+ movl $pa(cpu_gdt_table),%edi
16964+ movl $__per_cpu_load,%eax
16965+ movw %ax,__KERNEL_PERCPU + 2(%edi)
16966+ rorl $16,%eax
16967+ movb %al,__KERNEL_PERCPU + 4(%edi)
16968+ movb %ah,__KERNEL_PERCPU + 7(%edi)
16969+ movl $__per_cpu_end - 1,%eax
16970+ subl $__per_cpu_start,%eax
16971+ movw %ax,__KERNEL_PERCPU + 0(%edi)
16972+#endif
16973+
16974+#ifdef CONFIG_PAX_MEMORY_UDEREF
16975+ movl $NR_CPUS,%ecx
16976+ movl $pa(cpu_gdt_table),%edi
16977+1:
16978+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16979+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16980+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16981+ addl $PAGE_SIZE_asm,%edi
16982+ loop 1b
16983+#endif
16984+
16985+#ifdef CONFIG_PAX_KERNEXEC
16986+ movl $pa(boot_gdt),%edi
16987+ movl $__LOAD_PHYSICAL_ADDR,%eax
16988+ movw %ax,__BOOT_CS + 2(%edi)
16989+ rorl $16,%eax
16990+ movb %al,__BOOT_CS + 4(%edi)
16991+ movb %ah,__BOOT_CS + 7(%edi)
16992+ rorl $16,%eax
16993+
16994+ ljmp $(__BOOT_CS),$1f
16995+1:
16996+
16997+ movl $NR_CPUS,%ecx
16998+ movl $pa(cpu_gdt_table),%edi
16999+ addl $__PAGE_OFFSET,%eax
17000+1:
17001+ movw %ax,__KERNEL_CS + 2(%edi)
17002+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
17003+ rorl $16,%eax
17004+ movb %al,__KERNEL_CS + 4(%edi)
17005+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
17006+ movb %ah,__KERNEL_CS + 7(%edi)
17007+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
17008+ rorl $16,%eax
17009+ addl $PAGE_SIZE_asm,%edi
17010+ loop 1b
17011+#endif
17012+
17013 /*
17014 * Clear BSS first so that there are no surprises...
17015 */
17016@@ -195,8 +261,11 @@ ENTRY(startup_32)
17017 movl %eax, pa(max_pfn_mapped)
17018
17019 /* Do early initialization of the fixmap area */
17020- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17021- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
17022+#ifdef CONFIG_COMPAT_VDSO
17023+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
17024+#else
17025+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
17026+#endif
17027 #else /* Not PAE */
17028
17029 page_pde_offset = (__PAGE_OFFSET >> 20);
17030@@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17031 movl %eax, pa(max_pfn_mapped)
17032
17033 /* Do early initialization of the fixmap area */
17034- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17035- movl %eax,pa(initial_page_table+0xffc)
17036+#ifdef CONFIG_COMPAT_VDSO
17037+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
17038+#else
17039+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
17040+#endif
17041 #endif
17042
17043 #ifdef CONFIG_PARAVIRT
17044@@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17045 cmpl $num_subarch_entries, %eax
17046 jae bad_subarch
17047
17048- movl pa(subarch_entries)(,%eax,4), %eax
17049- subl $__PAGE_OFFSET, %eax
17050- jmp *%eax
17051+ jmp *pa(subarch_entries)(,%eax,4)
17052
17053 bad_subarch:
17054 WEAK(lguest_entry)
17055@@ -255,10 +325,10 @@ WEAK(xen_entry)
17056 __INITDATA
17057
17058 subarch_entries:
17059- .long default_entry /* normal x86/PC */
17060- .long lguest_entry /* lguest hypervisor */
17061- .long xen_entry /* Xen hypervisor */
17062- .long default_entry /* Moorestown MID */
17063+ .long ta(default_entry) /* normal x86/PC */
17064+ .long ta(lguest_entry) /* lguest hypervisor */
17065+ .long ta(xen_entry) /* Xen hypervisor */
17066+ .long ta(default_entry) /* Moorestown MID */
17067 num_subarch_entries = (. - subarch_entries) / 4
17068 .previous
17069 #else
17070@@ -312,6 +382,7 @@ default_entry:
17071 orl %edx,%eax
17072 movl %eax,%cr4
17073
17074+#ifdef CONFIG_X86_PAE
17075 testb $X86_CR4_PAE, %al # check if PAE is enabled
17076 jz 6f
17077
17078@@ -340,6 +411,9 @@ default_entry:
17079 /* Make changes effective */
17080 wrmsr
17081
17082+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17083+#endif
17084+
17085 6:
17086
17087 /*
17088@@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
17089 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17090 movl %eax,%ss # after changing gdt.
17091
17092- movl $(__USER_DS),%eax # DS/ES contains default USER segment
17093+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17094 movl %eax,%ds
17095 movl %eax,%es
17096
17097@@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
17098 */
17099 cmpb $0,ready
17100 jne 1f
17101- movl $gdt_page,%eax
17102+ movl $cpu_gdt_table,%eax
17103 movl $stack_canary,%ecx
17104+#ifdef CONFIG_SMP
17105+ addl $__per_cpu_load,%ecx
17106+#endif
17107 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17108 shrl $16, %ecx
17109 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17110 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
17111 1:
17112-#endif
17113 movl $(__KERNEL_STACK_CANARY),%eax
17114+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17115+ movl $(__USER_DS),%eax
17116+#else
17117+ xorl %eax,%eax
17118+#endif
17119 movl %eax,%gs
17120
17121 xorl %eax,%eax # Clear LDT
17122@@ -558,22 +639,22 @@ early_page_fault:
17123 jmp early_fault
17124
17125 early_fault:
17126- cld
17127 #ifdef CONFIG_PRINTK
17128+ cmpl $1,%ss:early_recursion_flag
17129+ je hlt_loop
17130+ incl %ss:early_recursion_flag
17131+ cld
17132 pusha
17133 movl $(__KERNEL_DS),%eax
17134 movl %eax,%ds
17135 movl %eax,%es
17136- cmpl $2,early_recursion_flag
17137- je hlt_loop
17138- incl early_recursion_flag
17139 movl %cr2,%eax
17140 pushl %eax
17141 pushl %edx /* trapno */
17142 pushl $fault_msg
17143 call printk
17144+; call dump_stack
17145 #endif
17146- call dump_stack
17147 hlt_loop:
17148 hlt
17149 jmp hlt_loop
17150@@ -581,8 +662,11 @@ hlt_loop:
17151 /* This is the default interrupt "handler" :-) */
17152 ALIGN
17153 ignore_int:
17154- cld
17155 #ifdef CONFIG_PRINTK
17156+ cmpl $2,%ss:early_recursion_flag
17157+ je hlt_loop
17158+ incl %ss:early_recursion_flag
17159+ cld
17160 pushl %eax
17161 pushl %ecx
17162 pushl %edx
17163@@ -591,9 +675,6 @@ ignore_int:
17164 movl $(__KERNEL_DS),%eax
17165 movl %eax,%ds
17166 movl %eax,%es
17167- cmpl $2,early_recursion_flag
17168- je hlt_loop
17169- incl early_recursion_flag
17170 pushl 16(%esp)
17171 pushl 24(%esp)
17172 pushl 32(%esp)
17173@@ -622,29 +703,43 @@ ENTRY(initial_code)
17174 /*
17175 * BSS section
17176 */
17177-__PAGE_ALIGNED_BSS
17178- .align PAGE_SIZE
17179 #ifdef CONFIG_X86_PAE
17180+.section .initial_pg_pmd,"a",@progbits
17181 initial_pg_pmd:
17182 .fill 1024*KPMDS,4,0
17183 #else
17184+.section .initial_page_table,"a",@progbits
17185 ENTRY(initial_page_table)
17186 .fill 1024,4,0
17187 #endif
17188+.section .initial_pg_fixmap,"a",@progbits
17189 initial_pg_fixmap:
17190 .fill 1024,4,0
17191+.section .empty_zero_page,"a",@progbits
17192 ENTRY(empty_zero_page)
17193 .fill 4096,1,0
17194+.section .swapper_pg_dir,"a",@progbits
17195 ENTRY(swapper_pg_dir)
17196+#ifdef CONFIG_X86_PAE
17197+ .fill 4,8,0
17198+#else
17199 .fill 1024,4,0
17200+#endif
17201+
17202+/*
17203+ * The IDT has to be page-aligned to simplify the Pentium
17204+ * F0 0F bug workaround.. We have a special link segment
17205+ * for this.
17206+ */
17207+.section .idt,"a",@progbits
17208+ENTRY(idt_table)
17209+ .fill 256,8,0
17210
17211 /*
17212 * This starts the data section.
17213 */
17214 #ifdef CONFIG_X86_PAE
17215-__PAGE_ALIGNED_DATA
17216- /* Page-aligned for the benefit of paravirt? */
17217- .align PAGE_SIZE
17218+.section .initial_page_table,"a",@progbits
17219 ENTRY(initial_page_table)
17220 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17221 # if KPMDS == 3
17222@@ -663,18 +758,27 @@ ENTRY(initial_page_table)
17223 # error "Kernel PMDs should be 1, 2 or 3"
17224 # endif
17225 .align PAGE_SIZE /* needs to be page-sized too */
17226+
17227+#ifdef CONFIG_PAX_PER_CPU_PGD
17228+ENTRY(cpu_pgd)
17229+ .rept NR_CPUS
17230+ .fill 4,8,0
17231+ .endr
17232+#endif
17233+
17234 #endif
17235
17236 .data
17237 .balign 4
17238 ENTRY(stack_start)
17239- .long init_thread_union+THREAD_SIZE
17240+ .long init_thread_union+THREAD_SIZE-8
17241
17242+ready: .byte 0
17243+
17244+.section .rodata,"a",@progbits
17245 early_recursion_flag:
17246 .long 0
17247
17248-ready: .byte 0
17249-
17250 int_msg:
17251 .asciz "Unknown interrupt or fault at: %p %p %p\n"
17252
17253@@ -707,7 +811,7 @@ fault_msg:
17254 .word 0 # 32 bit align gdt_desc.address
17255 boot_gdt_descr:
17256 .word __BOOT_DS+7
17257- .long boot_gdt - __PAGE_OFFSET
17258+ .long pa(boot_gdt)
17259
17260 .word 0 # 32-bit align idt_desc.address
17261 idt_descr:
17262@@ -718,7 +822,7 @@ idt_descr:
17263 .word 0 # 32 bit align gdt_desc.address
17264 ENTRY(early_gdt_descr)
17265 .word GDT_ENTRIES*8-1
17266- .long gdt_page /* Overwritten for secondary CPUs */
17267+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17268
17269 /*
17270 * The boot_gdt must mirror the equivalent in setup.S and is
17271@@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
17272 .align L1_CACHE_BYTES
17273 ENTRY(boot_gdt)
17274 .fill GDT_ENTRY_BOOT_CS,8,0
17275- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17276- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17277+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17278+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17279+
17280+ .align PAGE_SIZE_asm
17281+ENTRY(cpu_gdt_table)
17282+ .rept NR_CPUS
17283+ .quad 0x0000000000000000 /* NULL descriptor */
17284+ .quad 0x0000000000000000 /* 0x0b reserved */
17285+ .quad 0x0000000000000000 /* 0x13 reserved */
17286+ .quad 0x0000000000000000 /* 0x1b reserved */
17287+
17288+#ifdef CONFIG_PAX_KERNEXEC
17289+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17290+#else
17291+ .quad 0x0000000000000000 /* 0x20 unused */
17292+#endif
17293+
17294+ .quad 0x0000000000000000 /* 0x28 unused */
17295+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17296+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17297+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17298+ .quad 0x0000000000000000 /* 0x4b reserved */
17299+ .quad 0x0000000000000000 /* 0x53 reserved */
17300+ .quad 0x0000000000000000 /* 0x5b reserved */
17301+
17302+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17303+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17304+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17305+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17306+
17307+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17308+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17309+
17310+ /*
17311+ * Segments used for calling PnP BIOS have byte granularity.
17312+ * The code segments and data segments have fixed 64k limits,
17313+ * the transfer segment sizes are set at run time.
17314+ */
17315+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17316+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17317+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17318+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17319+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17320+
17321+ /*
17322+ * The APM segments have byte granularity and their bases
17323+ * are set at run time. All have 64k limits.
17324+ */
17325+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17326+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17327+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17328+
17329+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17330+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17331+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17332+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17333+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17334+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17335+
17336+ /* Be sure this is zeroed to avoid false validations in Xen */
17337+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17338+ .endr
17339diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17340index 40f4eb3..6d24d9d 100644
17341--- a/arch/x86/kernel/head_64.S
17342+++ b/arch/x86/kernel/head_64.S
17343@@ -19,6 +19,8 @@
17344 #include <asm/cache.h>
17345 #include <asm/processor-flags.h>
17346 #include <asm/percpu.h>
17347+#include <asm/cpufeature.h>
17348+#include <asm/alternative-asm.h>
17349
17350 #ifdef CONFIG_PARAVIRT
17351 #include <asm/asm-offsets.h>
17352@@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17353 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17354 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17355 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17356+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17357+L3_VMALLOC_START = pud_index(VMALLOC_START)
17358+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17359+L3_VMALLOC_END = pud_index(VMALLOC_END)
17360+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17361+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17362
17363 .text
17364 __HEAD
17365@@ -85,35 +93,23 @@ startup_64:
17366 */
17367 addq %rbp, init_level4_pgt + 0(%rip)
17368 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17369+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17370+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17371+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17372 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17373
17374 addq %rbp, level3_ident_pgt + 0(%rip)
17375+#ifndef CONFIG_XEN
17376+ addq %rbp, level3_ident_pgt + 8(%rip)
17377+#endif
17378
17379- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17380- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17381+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17382+
17383+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17384+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17385
17386 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17387-
17388- /* Add an Identity mapping if I am above 1G */
17389- leaq _text(%rip), %rdi
17390- andq $PMD_PAGE_MASK, %rdi
17391-
17392- movq %rdi, %rax
17393- shrq $PUD_SHIFT, %rax
17394- andq $(PTRS_PER_PUD - 1), %rax
17395- jz ident_complete
17396-
17397- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17398- leaq level3_ident_pgt(%rip), %rbx
17399- movq %rdx, 0(%rbx, %rax, 8)
17400-
17401- movq %rdi, %rax
17402- shrq $PMD_SHIFT, %rax
17403- andq $(PTRS_PER_PMD - 1), %rax
17404- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17405- leaq level2_spare_pgt(%rip), %rbx
17406- movq %rdx, 0(%rbx, %rax, 8)
17407-ident_complete:
17408+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17409
17410 /*
17411 * Fixup the kernel text+data virtual addresses. Note that
17412@@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
17413 * after the boot processor executes this code.
17414 */
17415
17416- /* Enable PAE mode and PGE */
17417- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17418+ /* Enable PAE mode and PSE/PGE */
17419+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17420 movq %rax, %cr4
17421
17422 /* Setup early boot stage 4 level pagetables. */
17423@@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
17424 movl $MSR_EFER, %ecx
17425 rdmsr
17426 btsl $_EFER_SCE, %eax /* Enable System Call */
17427- btl $20,%edi /* No Execute supported? */
17428+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17429 jnc 1f
17430 btsl $_EFER_NX, %eax
17431+ leaq init_level4_pgt(%rip), %rdi
17432+#ifndef CONFIG_EFI
17433+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17434+#endif
17435+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17436+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17437+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17438+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17439 1: wrmsr /* Make changes effective */
17440
17441 /* Setup cr0 */
17442@@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
17443 * jump. In addition we need to ensure %cs is set so we make this
17444 * a far return.
17445 */
17446+ pax_set_fptr_mask
17447 movq initial_code(%rip),%rax
17448 pushq $0 # fake return address to stop unwinder
17449 pushq $__KERNEL_CS # set correct cs
17450@@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
17451 bad_address:
17452 jmp bad_address
17453
17454- .section ".init.text","ax"
17455+ __INIT
17456 #ifdef CONFIG_EARLY_PRINTK
17457 .globl early_idt_handlers
17458 early_idt_handlers:
17459@@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
17460 #endif /* EARLY_PRINTK */
17461 1: hlt
17462 jmp 1b
17463+ .previous
17464
17465 #ifdef CONFIG_EARLY_PRINTK
17466+ __INITDATA
17467 early_recursion_flag:
17468 .long 0
17469+ .previous
17470
17471+ .section .rodata,"a",@progbits
17472 early_idt_msg:
17473 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17474 early_idt_ripmsg:
17475 .asciz "RIP %s\n"
17476+ .previous
17477 #endif /* CONFIG_EARLY_PRINTK */
17478- .previous
17479
17480+ .section .rodata,"a",@progbits
17481 #define NEXT_PAGE(name) \
17482 .balign PAGE_SIZE; \
17483 ENTRY(name)
17484@@ -338,7 +348,6 @@ ENTRY(name)
17485 i = i + 1 ; \
17486 .endr
17487
17488- .data
17489 /*
17490 * This default setting generates an ident mapping at address 0x100000
17491 * and a mapping for the kernel that precisely maps virtual address
17492@@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
17493 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17494 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17495 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17496+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17497+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17498+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17499+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17500+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17501+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17502 .org init_level4_pgt + L4_START_KERNEL*8, 0
17503 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17504 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17505
17506+#ifdef CONFIG_PAX_PER_CPU_PGD
17507+NEXT_PAGE(cpu_pgd)
17508+ .rept NR_CPUS
17509+ .fill 512,8,0
17510+ .endr
17511+#endif
17512+
17513 NEXT_PAGE(level3_ident_pgt)
17514 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17515+#ifdef CONFIG_XEN
17516 .fill 511,8,0
17517+#else
17518+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17519+ .fill 510,8,0
17520+#endif
17521+
17522+NEXT_PAGE(level3_vmalloc_start_pgt)
17523+ .fill 512,8,0
17524+
17525+NEXT_PAGE(level3_vmalloc_end_pgt)
17526+ .fill 512,8,0
17527+
17528+NEXT_PAGE(level3_vmemmap_pgt)
17529+ .fill L3_VMEMMAP_START,8,0
17530+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17531
17532 NEXT_PAGE(level3_kernel_pgt)
17533 .fill L3_START_KERNEL,8,0
17534@@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
17535 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17536 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17537
17538+NEXT_PAGE(level2_vmemmap_pgt)
17539+ .fill 512,8,0
17540+
17541 NEXT_PAGE(level2_fixmap_pgt)
17542- .fill 506,8,0
17543- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17544- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17545- .fill 5,8,0
17546+ .fill 507,8,0
17547+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17548+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17549+ .fill 4,8,0
17550
17551-NEXT_PAGE(level1_fixmap_pgt)
17552+NEXT_PAGE(level1_vsyscall_pgt)
17553 .fill 512,8,0
17554
17555-NEXT_PAGE(level2_ident_pgt)
17556- /* Since I easily can, map the first 1G.
17557+ /* Since I easily can, map the first 2G.
17558 * Don't set NX because code runs from these pages.
17559 */
17560- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17561+NEXT_PAGE(level2_ident_pgt)
17562+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17563
17564 NEXT_PAGE(level2_kernel_pgt)
17565 /*
17566@@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
17567 * If you want to increase this then increase MODULES_VADDR
17568 * too.)
17569 */
17570- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17571- KERNEL_IMAGE_SIZE/PMD_SIZE)
17572-
17573-NEXT_PAGE(level2_spare_pgt)
17574- .fill 512, 8, 0
17575+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17576
17577 #undef PMDS
17578 #undef NEXT_PAGE
17579
17580- .data
17581+ .align PAGE_SIZE
17582+ENTRY(cpu_gdt_table)
17583+ .rept NR_CPUS
17584+ .quad 0x0000000000000000 /* NULL descriptor */
17585+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17586+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17587+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17588+ .quad 0x00cffb000000ffff /* __USER32_CS */
17589+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17590+ .quad 0x00affb000000ffff /* __USER_CS */
17591+
17592+#ifdef CONFIG_PAX_KERNEXEC
17593+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17594+#else
17595+ .quad 0x0 /* unused */
17596+#endif
17597+
17598+ .quad 0,0 /* TSS */
17599+ .quad 0,0 /* LDT */
17600+ .quad 0,0,0 /* three TLS descriptors */
17601+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17602+ /* asm/segment.h:GDT_ENTRIES must match this */
17603+
17604+ /* zero the remaining page */
17605+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17606+ .endr
17607+
17608 .align 16
17609 .globl early_gdt_descr
17610 early_gdt_descr:
17611 .word GDT_ENTRIES*8-1
17612 early_gdt_descr_base:
17613- .quad INIT_PER_CPU_VAR(gdt_page)
17614+ .quad cpu_gdt_table
17615
17616 ENTRY(phys_base)
17617 /* This must match the first entry in level2_kernel_pgt */
17618 .quad 0x0000000000000000
17619
17620 #include "../../x86/xen/xen-head.S"
17621-
17622- .section .bss, "aw", @nobits
17623+
17624+ .section .rodata,"a",@progbits
17625 .align L1_CACHE_BYTES
17626 ENTRY(idt_table)
17627- .skip IDT_ENTRIES * 16
17628+ .fill 512,8,0
17629
17630 .align L1_CACHE_BYTES
17631 ENTRY(nmi_idt_table)
17632- .skip IDT_ENTRIES * 16
17633+ .fill 512,8,0
17634
17635 __PAGE_ALIGNED_BSS
17636 .align PAGE_SIZE
17637diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17638index 9c3bd4a..e1d9b35 100644
17639--- a/arch/x86/kernel/i386_ksyms_32.c
17640+++ b/arch/x86/kernel/i386_ksyms_32.c
17641@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17642 EXPORT_SYMBOL(cmpxchg8b_emu);
17643 #endif
17644
17645+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17646+
17647 /* Networking helper routines. */
17648 EXPORT_SYMBOL(csum_partial_copy_generic);
17649+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17650+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17651
17652 EXPORT_SYMBOL(__get_user_1);
17653 EXPORT_SYMBOL(__get_user_2);
17654@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17655
17656 EXPORT_SYMBOL(csum_partial);
17657 EXPORT_SYMBOL(empty_zero_page);
17658+
17659+#ifdef CONFIG_PAX_KERNEXEC
17660+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17661+#endif
17662diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17663index 6104852..6114160 100644
17664--- a/arch/x86/kernel/i8259.c
17665+++ b/arch/x86/kernel/i8259.c
17666@@ -210,7 +210,7 @@ spurious_8259A_irq:
17667 "spurious 8259A interrupt: IRQ%d.\n", irq);
17668 spurious_irq_mask |= irqmask;
17669 }
17670- atomic_inc(&irq_err_count);
17671+ atomic_inc_unchecked(&irq_err_count);
17672 /*
17673 * Theoretically we do not have to handle this IRQ,
17674 * but in Linux this does not cause problems and is
17675diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17676index 43e9ccf..44ccf6f 100644
17677--- a/arch/x86/kernel/init_task.c
17678+++ b/arch/x86/kernel/init_task.c
17679@@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17680 * way process stacks are handled. This is done by having a special
17681 * "init_task" linker map entry..
17682 */
17683-union thread_union init_thread_union __init_task_data =
17684- { INIT_THREAD_INFO(init_task) };
17685+union thread_union init_thread_union __init_task_data;
17686
17687 /*
17688 * Initial task structure.
17689@@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17690 * section. Since TSS's are completely CPU-local, we want them
17691 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17692 */
17693-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17694-
17695+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17696+EXPORT_SYMBOL(init_tss);
17697diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17698index 8c96897..be66bfa 100644
17699--- a/arch/x86/kernel/ioport.c
17700+++ b/arch/x86/kernel/ioport.c
17701@@ -6,6 +6,7 @@
17702 #include <linux/sched.h>
17703 #include <linux/kernel.h>
17704 #include <linux/capability.h>
17705+#include <linux/security.h>
17706 #include <linux/errno.h>
17707 #include <linux/types.h>
17708 #include <linux/ioport.h>
17709@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17710
17711 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17712 return -EINVAL;
17713+#ifdef CONFIG_GRKERNSEC_IO
17714+ if (turn_on && grsec_disable_privio) {
17715+ gr_handle_ioperm();
17716+ return -EPERM;
17717+ }
17718+#endif
17719 if (turn_on && !capable(CAP_SYS_RAWIO))
17720 return -EPERM;
17721
17722@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17723 * because the ->io_bitmap_max value must match the bitmap
17724 * contents:
17725 */
17726- tss = &per_cpu(init_tss, get_cpu());
17727+ tss = init_tss + get_cpu();
17728
17729 if (turn_on)
17730 bitmap_clear(t->io_bitmap_ptr, from, num);
17731@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17732 return -EINVAL;
17733 /* Trying to gain more privileges? */
17734 if (level > old) {
17735+#ifdef CONFIG_GRKERNSEC_IO
17736+ if (grsec_disable_privio) {
17737+ gr_handle_iopl();
17738+ return -EPERM;
17739+ }
17740+#endif
17741 if (!capable(CAP_SYS_RAWIO))
17742 return -EPERM;
17743 }
17744diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17745index 7943e0c..dd32c5c 100644
17746--- a/arch/x86/kernel/irq.c
17747+++ b/arch/x86/kernel/irq.c
17748@@ -18,7 +18,7 @@
17749 #include <asm/mce.h>
17750 #include <asm/hw_irq.h>
17751
17752-atomic_t irq_err_count;
17753+atomic_unchecked_t irq_err_count;
17754
17755 /* Function pointer for generic interrupt vector handling */
17756 void (*x86_platform_ipi_callback)(void) = NULL;
17757@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17758 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17759 seq_printf(p, " Machine check polls\n");
17760 #endif
17761- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17762+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17763 #if defined(CONFIG_X86_IO_APIC)
17764- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17765+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17766 #endif
17767 return 0;
17768 }
17769@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17770
17771 u64 arch_irq_stat(void)
17772 {
17773- u64 sum = atomic_read(&irq_err_count);
17774+ u64 sum = atomic_read_unchecked(&irq_err_count);
17775
17776 #ifdef CONFIG_X86_IO_APIC
17777- sum += atomic_read(&irq_mis_count);
17778+ sum += atomic_read_unchecked(&irq_mis_count);
17779 #endif
17780 return sum;
17781 }
17782diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17783index 40fc861..9b8739b 100644
17784--- a/arch/x86/kernel/irq_32.c
17785+++ b/arch/x86/kernel/irq_32.c
17786@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17787 __asm__ __volatile__("andl %%esp,%0" :
17788 "=r" (sp) : "0" (THREAD_SIZE - 1));
17789
17790- return sp < (sizeof(struct thread_info) + STACK_WARN);
17791+ return sp < STACK_WARN;
17792 }
17793
17794 static void print_stack_overflow(void)
17795@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17796 * per-CPU IRQ handling contexts (thread information and stack)
17797 */
17798 union irq_ctx {
17799- struct thread_info tinfo;
17800- u32 stack[THREAD_SIZE/sizeof(u32)];
17801+ unsigned long previous_esp;
17802+ u32 stack[THREAD_SIZE/sizeof(u32)];
17803 } __attribute__((aligned(THREAD_SIZE)));
17804
17805 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17806@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17807 static inline int
17808 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17809 {
17810- union irq_ctx *curctx, *irqctx;
17811+ union irq_ctx *irqctx;
17812 u32 *isp, arg1, arg2;
17813
17814- curctx = (union irq_ctx *) current_thread_info();
17815 irqctx = __this_cpu_read(hardirq_ctx);
17816
17817 /*
17818@@ -92,21 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17819 * handler) we can't do that and just have to keep using the
17820 * current stack (which is the irq stack already after all)
17821 */
17822- if (unlikely(curctx == irqctx))
17823+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17824 return 0;
17825
17826 /* build the stack frame on the IRQ stack */
17827- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17828- irqctx->tinfo.task = curctx->tinfo.task;
17829- irqctx->tinfo.previous_esp = current_stack_pointer;
17830+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17831+ irqctx->previous_esp = current_stack_pointer;
17832
17833- /*
17834- * Copy the softirq bits in preempt_count so that the
17835- * softirq checks work in the hardirq context.
17836- */
17837- irqctx->tinfo.preempt_count =
17838- (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
17839- (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
17840+#ifdef CONFIG_PAX_MEMORY_UDEREF
17841+ __set_fs(MAKE_MM_SEG(0));
17842+#endif
17843
17844 if (unlikely(overflow))
17845 call_on_stack(print_stack_overflow, isp);
17846@@ -118,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17847 : "0" (irq), "1" (desc), "2" (isp),
17848 "D" (desc->handle_irq)
17849 : "memory", "cc", "ecx");
17850+
17851+#ifdef CONFIG_PAX_MEMORY_UDEREF
17852+ __set_fs(current_thread_info()->addr_limit);
17853+#endif
17854+
17855 return 1;
17856 }
17857
17858@@ -126,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17859 */
17860 void __cpuinit irq_ctx_init(int cpu)
17861 {
17862- union irq_ctx *irqctx;
17863-
17864 if (per_cpu(hardirq_ctx, cpu))
17865 return;
17866
17867- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17868- THREAD_FLAGS,
17869- THREAD_ORDER));
17870- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17871- irqctx->tinfo.cpu = cpu;
17872- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17873- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17874-
17875- per_cpu(hardirq_ctx, cpu) = irqctx;
17876-
17877- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17878- THREAD_FLAGS,
17879- THREAD_ORDER));
17880- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17881- irqctx->tinfo.cpu = cpu;
17882- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17883-
17884- per_cpu(softirq_ctx, cpu) = irqctx;
17885+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17886+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17887
17888 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17889 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17890@@ -157,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17891 asmlinkage void do_softirq(void)
17892 {
17893 unsigned long flags;
17894- struct thread_info *curctx;
17895 union irq_ctx *irqctx;
17896 u32 *isp;
17897
17898@@ -167,15 +147,22 @@ asmlinkage void do_softirq(void)
17899 local_irq_save(flags);
17900
17901 if (local_softirq_pending()) {
17902- curctx = current_thread_info();
17903 irqctx = __this_cpu_read(softirq_ctx);
17904- irqctx->tinfo.task = curctx->task;
17905- irqctx->tinfo.previous_esp = current_stack_pointer;
17906+ irqctx->previous_esp = current_stack_pointer;
17907
17908 /* build the stack frame on the softirq stack */
17909- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17910+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17911+
17912+#ifdef CONFIG_PAX_MEMORY_UDEREF
17913+ __set_fs(MAKE_MM_SEG(0));
17914+#endif
17915
17916 call_on_stack(__do_softirq, isp);
17917+
17918+#ifdef CONFIG_PAX_MEMORY_UDEREF
17919+ __set_fs(current_thread_info()->addr_limit);
17920+#endif
17921+
17922 /*
17923 * Shouldn't happen, we returned above if in_interrupt():
17924 */
17925diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17926index d04d3ec..ea4b374 100644
17927--- a/arch/x86/kernel/irq_64.c
17928+++ b/arch/x86/kernel/irq_64.c
17929@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17930 u64 estack_top, estack_bottom;
17931 u64 curbase = (u64)task_stack_page(current);
17932
17933- if (user_mode_vm(regs))
17934+ if (user_mode(regs))
17935 return;
17936
17937 if (regs->sp >= curbase + sizeof(struct thread_info) +
17938diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17939index 90fcf62..e682cdd 100644
17940--- a/arch/x86/kernel/kdebugfs.c
17941+++ b/arch/x86/kernel/kdebugfs.c
17942@@ -28,6 +28,8 @@ struct setup_data_node {
17943 };
17944
17945 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17946+ size_t count, loff_t *ppos) __size_overflow(3);
17947+static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17948 size_t count, loff_t *ppos)
17949 {
17950 struct setup_data_node *node = file->private_data;
17951diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17952index 2f45c4c..d95504f 100644
17953--- a/arch/x86/kernel/kgdb.c
17954+++ b/arch/x86/kernel/kgdb.c
17955@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17956 #ifdef CONFIG_X86_32
17957 switch (regno) {
17958 case GDB_SS:
17959- if (!user_mode_vm(regs))
17960+ if (!user_mode(regs))
17961 *(unsigned long *)mem = __KERNEL_DS;
17962 break;
17963 case GDB_SP:
17964- if (!user_mode_vm(regs))
17965+ if (!user_mode(regs))
17966 *(unsigned long *)mem = kernel_stack_pointer(regs);
17967 break;
17968 case GDB_GS:
17969@@ -475,12 +475,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17970 case 'k':
17971 /* clear the trace bit */
17972 linux_regs->flags &= ~X86_EFLAGS_TF;
17973- atomic_set(&kgdb_cpu_doing_single_step, -1);
17974+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17975
17976 /* set the trace bit if we're stepping */
17977 if (remcomInBuffer[0] == 's') {
17978 linux_regs->flags |= X86_EFLAGS_TF;
17979- atomic_set(&kgdb_cpu_doing_single_step,
17980+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17981 raw_smp_processor_id());
17982 }
17983
17984@@ -545,7 +545,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17985
17986 switch (cmd) {
17987 case DIE_DEBUG:
17988- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17989+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17990 if (user_mode(regs))
17991 return single_step_cont(regs, args);
17992 break;
17993diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17994index 7da647d..56fe348 100644
17995--- a/arch/x86/kernel/kprobes.c
17996+++ b/arch/x86/kernel/kprobes.c
17997@@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17998 } __attribute__((packed)) *insn;
17999
18000 insn = (struct __arch_relative_insn *)from;
18001+
18002+ pax_open_kernel();
18003 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
18004 insn->op = op;
18005+ pax_close_kernel();
18006 }
18007
18008 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
18009@@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
18010 kprobe_opcode_t opcode;
18011 kprobe_opcode_t *orig_opcodes = opcodes;
18012
18013- if (search_exception_tables((unsigned long)opcodes))
18014+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
18015 return 0; /* Page fault may occur on this address. */
18016
18017 retry:
18018@@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
18019 }
18020 }
18021 insn_get_length(&insn);
18022+ pax_open_kernel();
18023 memcpy(dest, insn.kaddr, insn.length);
18024+ pax_close_kernel();
18025
18026 #ifdef CONFIG_X86_64
18027 if (insn_rip_relative(&insn)) {
18028@@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
18029 (u8 *) dest;
18030 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18031 disp = (u8 *) dest + insn_offset_displacement(&insn);
18032+ pax_open_kernel();
18033 *(s32 *) disp = (s32) newdisp;
18034+ pax_close_kernel();
18035 }
18036 #endif
18037 return insn.length;
18038@@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
18039 */
18040 __copy_instruction(p->ainsn.insn, p->addr, 0);
18041
18042- if (can_boost(p->addr))
18043+ if (can_boost(ktla_ktva(p->addr)))
18044 p->ainsn.boostable = 0;
18045 else
18046 p->ainsn.boostable = -1;
18047
18048- p->opcode = *p->addr;
18049+ p->opcode = *(ktla_ktva(p->addr));
18050 }
18051
18052 int __kprobes arch_prepare_kprobe(struct kprobe *p)
18053@@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
18054 * nor set current_kprobe, because it doesn't use single
18055 * stepping.
18056 */
18057- regs->ip = (unsigned long)p->ainsn.insn;
18058+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18059 preempt_enable_no_resched();
18060 return;
18061 }
18062@@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
18063 if (p->opcode == BREAKPOINT_INSTRUCTION)
18064 regs->ip = (unsigned long)p->addr;
18065 else
18066- regs->ip = (unsigned long)p->ainsn.insn;
18067+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18068 }
18069
18070 /*
18071@@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18072 setup_singlestep(p, regs, kcb, 0);
18073 return 1;
18074 }
18075- } else if (*addr != BREAKPOINT_INSTRUCTION) {
18076+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18077 /*
18078 * The breakpoint instruction was removed right
18079 * after we hit it. Another cpu has removed
18080@@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18081 " movq %rax, 152(%rsp)\n"
18082 RESTORE_REGS_STRING
18083 " popfq\n"
18084+#ifdef KERNEXEC_PLUGIN
18085+ " btsq $63,(%rsp)\n"
18086+#endif
18087 #else
18088 " pushf\n"
18089 SAVE_REGS_STRING
18090@@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
18091 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18092 {
18093 unsigned long *tos = stack_addr(regs);
18094- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18095+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18096 unsigned long orig_ip = (unsigned long)p->addr;
18097 kprobe_opcode_t *insn = p->ainsn.insn;
18098
18099@@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
18100 struct die_args *args = data;
18101 int ret = NOTIFY_DONE;
18102
18103- if (args->regs && user_mode_vm(args->regs))
18104+ if (args->regs && user_mode(args->regs))
18105 return ret;
18106
18107 switch (val) {
18108@@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
18109 * Verify if the address gap is in 2GB range, because this uses
18110 * a relative jump.
18111 */
18112- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
18113+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
18114 if (abs(rel) > 0x7fffffff)
18115 return -ERANGE;
18116
18117@@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
18118 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
18119
18120 /* Set probe function call */
18121- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
18122+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
18123
18124 /* Set returning jmp instruction at the tail of out-of-line buffer */
18125 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
18126- (u8 *)op->kp.addr + op->optinsn.size);
18127+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
18128
18129 flush_icache_range((unsigned long) buf,
18130 (unsigned long) buf + TMPL_END_IDX +
18131@@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
18132 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
18133
18134 /* Backup instructions which will be replaced by jump address */
18135- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
18136+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
18137 RELATIVE_ADDR_SIZE);
18138
18139 insn_buf[0] = RELATIVEJUMP_OPCODE;
18140diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18141index ea69726..604d066 100644
18142--- a/arch/x86/kernel/ldt.c
18143+++ b/arch/x86/kernel/ldt.c
18144@@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18145 if (reload) {
18146 #ifdef CONFIG_SMP
18147 preempt_disable();
18148- load_LDT(pc);
18149+ load_LDT_nolock(pc);
18150 if (!cpumask_equal(mm_cpumask(current->mm),
18151 cpumask_of(smp_processor_id())))
18152 smp_call_function(flush_ldt, current->mm, 1);
18153 preempt_enable();
18154 #else
18155- load_LDT(pc);
18156+ load_LDT_nolock(pc);
18157 #endif
18158 }
18159 if (oldsize) {
18160@@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18161 return err;
18162
18163 for (i = 0; i < old->size; i++)
18164- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18165+ write_ldt_entry(new->ldt, i, old->ldt + i);
18166 return 0;
18167 }
18168
18169@@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18170 retval = copy_ldt(&mm->context, &old_mm->context);
18171 mutex_unlock(&old_mm->context.lock);
18172 }
18173+
18174+ if (tsk == current) {
18175+ mm->context.vdso = 0;
18176+
18177+#ifdef CONFIG_X86_32
18178+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18179+ mm->context.user_cs_base = 0UL;
18180+ mm->context.user_cs_limit = ~0UL;
18181+
18182+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18183+ cpus_clear(mm->context.cpu_user_cs_mask);
18184+#endif
18185+
18186+#endif
18187+#endif
18188+
18189+ }
18190+
18191 return retval;
18192 }
18193
18194@@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18195 }
18196 }
18197
18198+#ifdef CONFIG_PAX_SEGMEXEC
18199+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18200+ error = -EINVAL;
18201+ goto out_unlock;
18202+ }
18203+#endif
18204+
18205 fill_ldt(&ldt, &ldt_info);
18206 if (oldmode)
18207 ldt.avl = 0;
18208diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18209index a3fa43b..8966f4c 100644
18210--- a/arch/x86/kernel/machine_kexec_32.c
18211+++ b/arch/x86/kernel/machine_kexec_32.c
18212@@ -27,7 +27,7 @@
18213 #include <asm/cacheflush.h>
18214 #include <asm/debugreg.h>
18215
18216-static void set_idt(void *newidt, __u16 limit)
18217+static void set_idt(struct desc_struct *newidt, __u16 limit)
18218 {
18219 struct desc_ptr curidt;
18220
18221@@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
18222 }
18223
18224
18225-static void set_gdt(void *newgdt, __u16 limit)
18226+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18227 {
18228 struct desc_ptr curgdt;
18229
18230@@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
18231 }
18232
18233 control_page = page_address(image->control_code_page);
18234- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18235+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18236
18237 relocate_kernel_ptr = control_page;
18238 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18239diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18240index 3ca42d0..7cff8cc 100644
18241--- a/arch/x86/kernel/microcode_intel.c
18242+++ b/arch/x86/kernel/microcode_intel.c
18243@@ -436,13 +436,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18244
18245 static int get_ucode_user(void *to, const void *from, size_t n)
18246 {
18247- return copy_from_user(to, from, n);
18248+ return copy_from_user(to, (const void __force_user *)from, n);
18249 }
18250
18251 static enum ucode_state
18252 request_microcode_user(int cpu, const void __user *buf, size_t size)
18253 {
18254- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18255+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18256 }
18257
18258 static void microcode_fini_cpu(int cpu)
18259diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18260index 925179f..267ac7a 100644
18261--- a/arch/x86/kernel/module.c
18262+++ b/arch/x86/kernel/module.c
18263@@ -36,15 +36,60 @@
18264 #define DEBUGP(fmt...)
18265 #endif
18266
18267-void *module_alloc(unsigned long size)
18268+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18269 {
18270- if (PAGE_ALIGN(size) > MODULES_LEN)
18271+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18272 return NULL;
18273 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18274- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18275+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18276 -1, __builtin_return_address(0));
18277 }
18278
18279+void *module_alloc(unsigned long size)
18280+{
18281+
18282+#ifdef CONFIG_PAX_KERNEXEC
18283+ return __module_alloc(size, PAGE_KERNEL);
18284+#else
18285+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18286+#endif
18287+
18288+}
18289+
18290+#ifdef CONFIG_PAX_KERNEXEC
18291+#ifdef CONFIG_X86_32
18292+void *module_alloc_exec(unsigned long size)
18293+{
18294+ struct vm_struct *area;
18295+
18296+ if (size == 0)
18297+ return NULL;
18298+
18299+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18300+ return area ? area->addr : NULL;
18301+}
18302+EXPORT_SYMBOL(module_alloc_exec);
18303+
18304+void module_free_exec(struct module *mod, void *module_region)
18305+{
18306+ vunmap(module_region);
18307+}
18308+EXPORT_SYMBOL(module_free_exec);
18309+#else
18310+void module_free_exec(struct module *mod, void *module_region)
18311+{
18312+ module_free(mod, module_region);
18313+}
18314+EXPORT_SYMBOL(module_free_exec);
18315+
18316+void *module_alloc_exec(unsigned long size)
18317+{
18318+ return __module_alloc(size, PAGE_KERNEL_RX);
18319+}
18320+EXPORT_SYMBOL(module_alloc_exec);
18321+#endif
18322+#endif
18323+
18324 #ifdef CONFIG_X86_32
18325 int apply_relocate(Elf32_Shdr *sechdrs,
18326 const char *strtab,
18327@@ -55,14 +100,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18328 unsigned int i;
18329 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18330 Elf32_Sym *sym;
18331- uint32_t *location;
18332+ uint32_t *plocation, location;
18333
18334 DEBUGP("Applying relocate section %u to %u\n", relsec,
18335 sechdrs[relsec].sh_info);
18336 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18337 /* This is where to make the change */
18338- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18339- + rel[i].r_offset;
18340+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18341+ location = (uint32_t)plocation;
18342+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18343+ plocation = ktla_ktva((void *)plocation);
18344 /* This is the symbol it is referring to. Note that all
18345 undefined symbols have been resolved. */
18346 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18347@@ -71,11 +118,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18348 switch (ELF32_R_TYPE(rel[i].r_info)) {
18349 case R_386_32:
18350 /* We add the value into the location given */
18351- *location += sym->st_value;
18352+ pax_open_kernel();
18353+ *plocation += sym->st_value;
18354+ pax_close_kernel();
18355 break;
18356 case R_386_PC32:
18357 /* Add the value, subtract its postition */
18358- *location += sym->st_value - (uint32_t)location;
18359+ pax_open_kernel();
18360+ *plocation += sym->st_value - location;
18361+ pax_close_kernel();
18362 break;
18363 default:
18364 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18365@@ -120,21 +171,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18366 case R_X86_64_NONE:
18367 break;
18368 case R_X86_64_64:
18369+ pax_open_kernel();
18370 *(u64 *)loc = val;
18371+ pax_close_kernel();
18372 break;
18373 case R_X86_64_32:
18374+ pax_open_kernel();
18375 *(u32 *)loc = val;
18376+ pax_close_kernel();
18377 if (val != *(u32 *)loc)
18378 goto overflow;
18379 break;
18380 case R_X86_64_32S:
18381+ pax_open_kernel();
18382 *(s32 *)loc = val;
18383+ pax_close_kernel();
18384 if ((s64)val != *(s32 *)loc)
18385 goto overflow;
18386 break;
18387 case R_X86_64_PC32:
18388 val -= (u64)loc;
18389+ pax_open_kernel();
18390 *(u32 *)loc = val;
18391+ pax_close_kernel();
18392+
18393 #if 0
18394 if ((s64)val != *(s32 *)loc)
18395 goto overflow;
18396diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18397index 47acaf3..ec48ab6 100644
18398--- a/arch/x86/kernel/nmi.c
18399+++ b/arch/x86/kernel/nmi.c
18400@@ -505,6 +505,17 @@ static inline void nmi_nesting_postprocess(void)
18401 dotraplinkage notrace __kprobes void
18402 do_nmi(struct pt_regs *regs, long error_code)
18403 {
18404+
18405+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18406+ if (!user_mode(regs)) {
18407+ unsigned long cs = regs->cs & 0xFFFF;
18408+ unsigned long ip = ktva_ktla(regs->ip);
18409+
18410+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18411+ regs->ip = ip;
18412+ }
18413+#endif
18414+
18415 nmi_nesting_preprocess(regs);
18416
18417 nmi_enter();
18418diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18419index 676b8c7..870ba04 100644
18420--- a/arch/x86/kernel/paravirt-spinlocks.c
18421+++ b/arch/x86/kernel/paravirt-spinlocks.c
18422@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18423 arch_spin_lock(lock);
18424 }
18425
18426-struct pv_lock_ops pv_lock_ops = {
18427+struct pv_lock_ops pv_lock_ops __read_only = {
18428 #ifdef CONFIG_SMP
18429 .spin_is_locked = __ticket_spin_is_locked,
18430 .spin_is_contended = __ticket_spin_is_contended,
18431diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18432index d90272e..6bb013b 100644
18433--- a/arch/x86/kernel/paravirt.c
18434+++ b/arch/x86/kernel/paravirt.c
18435@@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
18436 {
18437 return x;
18438 }
18439+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18440+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18441+#endif
18442
18443 void __init default_banner(void)
18444 {
18445@@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18446 if (opfunc == NULL)
18447 /* If there's no function, patch it with a ud2a (BUG) */
18448 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18449- else if (opfunc == _paravirt_nop)
18450+ else if (opfunc == (void *)_paravirt_nop)
18451 /* If the operation is a nop, then nop the callsite */
18452 ret = paravirt_patch_nop();
18453
18454 /* identity functions just return their single argument */
18455- else if (opfunc == _paravirt_ident_32)
18456+ else if (opfunc == (void *)_paravirt_ident_32)
18457 ret = paravirt_patch_ident_32(insnbuf, len);
18458- else if (opfunc == _paravirt_ident_64)
18459+ else if (opfunc == (void *)_paravirt_ident_64)
18460 ret = paravirt_patch_ident_64(insnbuf, len);
18461+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18462+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18463+ ret = paravirt_patch_ident_64(insnbuf, len);
18464+#endif
18465
18466 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18467 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18468@@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18469 if (insn_len > len || start == NULL)
18470 insn_len = len;
18471 else
18472- memcpy(insnbuf, start, insn_len);
18473+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18474
18475 return insn_len;
18476 }
18477@@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
18478 preempt_enable();
18479 }
18480
18481-struct pv_info pv_info = {
18482+struct pv_info pv_info __read_only = {
18483 .name = "bare hardware",
18484 .paravirt_enabled = 0,
18485 .kernel_rpl = 0,
18486@@ -313,16 +320,16 @@ struct pv_info pv_info = {
18487 #endif
18488 };
18489
18490-struct pv_init_ops pv_init_ops = {
18491+struct pv_init_ops pv_init_ops __read_only = {
18492 .patch = native_patch,
18493 };
18494
18495-struct pv_time_ops pv_time_ops = {
18496+struct pv_time_ops pv_time_ops __read_only = {
18497 .sched_clock = native_sched_clock,
18498 .steal_clock = native_steal_clock,
18499 };
18500
18501-struct pv_irq_ops pv_irq_ops = {
18502+struct pv_irq_ops pv_irq_ops __read_only = {
18503 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18504 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18505 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18506@@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
18507 #endif
18508 };
18509
18510-struct pv_cpu_ops pv_cpu_ops = {
18511+struct pv_cpu_ops pv_cpu_ops __read_only = {
18512 .cpuid = native_cpuid,
18513 .get_debugreg = native_get_debugreg,
18514 .set_debugreg = native_set_debugreg,
18515@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18516 .end_context_switch = paravirt_nop,
18517 };
18518
18519-struct pv_apic_ops pv_apic_ops = {
18520+struct pv_apic_ops pv_apic_ops __read_only = {
18521 #ifdef CONFIG_X86_LOCAL_APIC
18522 .startup_ipi_hook = paravirt_nop,
18523 #endif
18524 };
18525
18526-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18527+#ifdef CONFIG_X86_32
18528+#ifdef CONFIG_X86_PAE
18529+/* 64-bit pagetable entries */
18530+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18531+#else
18532 /* 32-bit pagetable entries */
18533 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18534+#endif
18535 #else
18536 /* 64-bit pagetable entries */
18537 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18538 #endif
18539
18540-struct pv_mmu_ops pv_mmu_ops = {
18541+struct pv_mmu_ops pv_mmu_ops __read_only = {
18542
18543 .read_cr2 = native_read_cr2,
18544 .write_cr2 = native_write_cr2,
18545@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18546 .make_pud = PTE_IDENT,
18547
18548 .set_pgd = native_set_pgd,
18549+ .set_pgd_batched = native_set_pgd_batched,
18550 #endif
18551 #endif /* PAGETABLE_LEVELS >= 3 */
18552
18553@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18554 },
18555
18556 .set_fixmap = native_set_fixmap,
18557+
18558+#ifdef CONFIG_PAX_KERNEXEC
18559+ .pax_open_kernel = native_pax_open_kernel,
18560+ .pax_close_kernel = native_pax_close_kernel,
18561+#endif
18562+
18563 };
18564
18565 EXPORT_SYMBOL_GPL(pv_time_ops);
18566diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18567index 35ccf75..7a15747 100644
18568--- a/arch/x86/kernel/pci-iommu_table.c
18569+++ b/arch/x86/kernel/pci-iommu_table.c
18570@@ -2,7 +2,7 @@
18571 #include <asm/iommu_table.h>
18572 #include <linux/string.h>
18573 #include <linux/kallsyms.h>
18574-
18575+#include <linux/sched.h>
18576
18577 #define DEBUG 1
18578
18579diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18580index 15763af..da59ada 100644
18581--- a/arch/x86/kernel/process.c
18582+++ b/arch/x86/kernel/process.c
18583@@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
18584
18585 void free_thread_info(struct thread_info *ti)
18586 {
18587- free_thread_xstate(ti->task);
18588 free_pages((unsigned long)ti, THREAD_ORDER);
18589 }
18590
18591+static struct kmem_cache *task_struct_cachep;
18592+
18593 void arch_task_cache_init(void)
18594 {
18595- task_xstate_cachep =
18596- kmem_cache_create("task_xstate", xstate_size,
18597+ /* create a slab on which task_structs can be allocated */
18598+ task_struct_cachep =
18599+ kmem_cache_create("task_struct", sizeof(struct task_struct),
18600+ ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18601+
18602+ task_xstate_cachep =
18603+ kmem_cache_create("task_xstate", xstate_size,
18604 __alignof__(union thread_xstate),
18605- SLAB_PANIC | SLAB_NOTRACK, NULL);
18606+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18607+}
18608+
18609+struct task_struct *alloc_task_struct_node(int node)
18610+{
18611+ return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18612+}
18613+
18614+void free_task_struct(struct task_struct *task)
18615+{
18616+ free_thread_xstate(task);
18617+ kmem_cache_free(task_struct_cachep, task);
18618 }
18619
18620 /*
18621@@ -70,7 +87,7 @@ void exit_thread(void)
18622 unsigned long *bp = t->io_bitmap_ptr;
18623
18624 if (bp) {
18625- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18626+ struct tss_struct *tss = init_tss + get_cpu();
18627
18628 t->io_bitmap_ptr = NULL;
18629 clear_thread_flag(TIF_IO_BITMAP);
18630@@ -106,7 +123,7 @@ void show_regs_common(void)
18631
18632 printk(KERN_CONT "\n");
18633 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18634- current->pid, current->comm, print_tainted(),
18635+ task_pid_nr(current), current->comm, print_tainted(),
18636 init_utsname()->release,
18637 (int)strcspn(init_utsname()->version, " "),
18638 init_utsname()->version);
18639@@ -120,6 +137,9 @@ void flush_thread(void)
18640 {
18641 struct task_struct *tsk = current;
18642
18643+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18644+ loadsegment(gs, 0);
18645+#endif
18646 flush_ptrace_hw_breakpoint(tsk);
18647 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18648 /*
18649@@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18650 regs.di = (unsigned long) arg;
18651
18652 #ifdef CONFIG_X86_32
18653- regs.ds = __USER_DS;
18654- regs.es = __USER_DS;
18655+ regs.ds = __KERNEL_DS;
18656+ regs.es = __KERNEL_DS;
18657 regs.fs = __KERNEL_PERCPU;
18658- regs.gs = __KERNEL_STACK_CANARY;
18659+ savesegment(gs, regs.gs);
18660 #else
18661 regs.ss = __KERNEL_DS;
18662 #endif
18663@@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
18664
18665 return ret;
18666 }
18667-void stop_this_cpu(void *dummy)
18668+__noreturn void stop_this_cpu(void *dummy)
18669 {
18670 local_irq_disable();
18671 /*
18672@@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
18673 }
18674 early_param("idle", idle_setup);
18675
18676-unsigned long arch_align_stack(unsigned long sp)
18677+#ifdef CONFIG_PAX_RANDKSTACK
18678+void pax_randomize_kstack(struct pt_regs *regs)
18679 {
18680- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18681- sp -= get_random_int() % 8192;
18682- return sp & ~0xf;
18683-}
18684+ struct thread_struct *thread = &current->thread;
18685+ unsigned long time;
18686
18687-unsigned long arch_randomize_brk(struct mm_struct *mm)
18688-{
18689- unsigned long range_end = mm->brk + 0x02000000;
18690- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18691-}
18692+ if (!randomize_va_space)
18693+ return;
18694+
18695+ if (v8086_mode(regs))
18696+ return;
18697
18698+ rdtscl(time);
18699+
18700+ /* P4 seems to return a 0 LSB, ignore it */
18701+#ifdef CONFIG_MPENTIUM4
18702+ time &= 0x3EUL;
18703+ time <<= 2;
18704+#elif defined(CONFIG_X86_64)
18705+ time &= 0xFUL;
18706+ time <<= 4;
18707+#else
18708+ time &= 0x1FUL;
18709+ time <<= 3;
18710+#endif
18711+
18712+ thread->sp0 ^= time;
18713+ load_sp0(init_tss + smp_processor_id(), thread);
18714+
18715+#ifdef CONFIG_X86_64
18716+ percpu_write(kernel_stack, thread->sp0);
18717+#endif
18718+}
18719+#endif
18720diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18721index c08d1ff..6ae1c81 100644
18722--- a/arch/x86/kernel/process_32.c
18723+++ b/arch/x86/kernel/process_32.c
18724@@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18725 unsigned long thread_saved_pc(struct task_struct *tsk)
18726 {
18727 return ((unsigned long *)tsk->thread.sp)[3];
18728+//XXX return tsk->thread.eip;
18729 }
18730
18731 #ifndef CONFIG_SMP
18732@@ -132,15 +133,14 @@ void __show_regs(struct pt_regs *regs, int all)
18733 unsigned long sp;
18734 unsigned short ss, gs;
18735
18736- if (user_mode_vm(regs)) {
18737+ if (user_mode(regs)) {
18738 sp = regs->sp;
18739 ss = regs->ss & 0xffff;
18740- gs = get_user_gs(regs);
18741 } else {
18742 sp = kernel_stack_pointer(regs);
18743 savesegment(ss, ss);
18744- savesegment(gs, gs);
18745 }
18746+ gs = get_user_gs(regs);
18747
18748 show_regs_common();
18749
18750@@ -202,13 +202,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18751 struct task_struct *tsk;
18752 int err;
18753
18754- childregs = task_pt_regs(p);
18755+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18756 *childregs = *regs;
18757 childregs->ax = 0;
18758 childregs->sp = sp;
18759
18760 p->thread.sp = (unsigned long) childregs;
18761 p->thread.sp0 = (unsigned long) (childregs+1);
18762+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18763
18764 p->thread.ip = (unsigned long) ret_from_fork;
18765
18766@@ -299,7 +300,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18767 struct thread_struct *prev = &prev_p->thread,
18768 *next = &next_p->thread;
18769 int cpu = smp_processor_id();
18770- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18771+ struct tss_struct *tss = init_tss + cpu;
18772 fpu_switch_t fpu;
18773
18774 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18775@@ -323,6 +324,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18776 */
18777 lazy_save_gs(prev->gs);
18778
18779+#ifdef CONFIG_PAX_MEMORY_UDEREF
18780+ __set_fs(task_thread_info(next_p)->addr_limit);
18781+#endif
18782+
18783 /*
18784 * Load the per-thread Thread-Local Storage descriptor.
18785 */
18786@@ -353,6 +358,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18787 */
18788 arch_end_context_switch(next_p);
18789
18790+ percpu_write(current_task, next_p);
18791+ percpu_write(current_tinfo, &next_p->tinfo);
18792+
18793 /*
18794 * Restore %gs if needed (which is common)
18795 */
18796@@ -361,8 +369,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18797
18798 switch_fpu_finish(next_p, fpu);
18799
18800- percpu_write(current_task, next_p);
18801-
18802 return prev_p;
18803 }
18804
18805@@ -392,4 +398,3 @@ unsigned long get_wchan(struct task_struct *p)
18806 } while (count++ < 16);
18807 return 0;
18808 }
18809-
18810diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18811index cfa5c90..4facd28 100644
18812--- a/arch/x86/kernel/process_64.c
18813+++ b/arch/x86/kernel/process_64.c
18814@@ -89,7 +89,7 @@ static void __exit_idle(void)
18815 void exit_idle(void)
18816 {
18817 /* idle loop has pid 0 */
18818- if (current->pid)
18819+ if (task_pid_nr(current))
18820 return;
18821 __exit_idle();
18822 }
18823@@ -270,8 +270,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18824 struct pt_regs *childregs;
18825 struct task_struct *me = current;
18826
18827- childregs = ((struct pt_regs *)
18828- (THREAD_SIZE + task_stack_page(p))) - 1;
18829+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18830 *childregs = *regs;
18831
18832 childregs->ax = 0;
18833@@ -283,6 +282,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18834 p->thread.sp = (unsigned long) childregs;
18835 p->thread.sp0 = (unsigned long) (childregs+1);
18836 p->thread.usersp = me->thread.usersp;
18837+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18838
18839 set_tsk_thread_flag(p, TIF_FORK);
18840
18841@@ -385,7 +385,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18842 struct thread_struct *prev = &prev_p->thread;
18843 struct thread_struct *next = &next_p->thread;
18844 int cpu = smp_processor_id();
18845- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18846+ struct tss_struct *tss = init_tss + cpu;
18847 unsigned fsindex, gsindex;
18848 fpu_switch_t fpu;
18849
18850@@ -467,10 +467,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18851 prev->usersp = percpu_read(old_rsp);
18852 percpu_write(old_rsp, next->usersp);
18853 percpu_write(current_task, next_p);
18854+ percpu_write(current_tinfo, &next_p->tinfo);
18855
18856- percpu_write(kernel_stack,
18857- (unsigned long)task_stack_page(next_p) +
18858- THREAD_SIZE - KERNEL_STACK_OFFSET);
18859+ percpu_write(kernel_stack, next->sp0);
18860
18861 /*
18862 * Now maybe reload the debug registers and handle I/O bitmaps
18863@@ -525,12 +524,11 @@ unsigned long get_wchan(struct task_struct *p)
18864 if (!p || p == current || p->state == TASK_RUNNING)
18865 return 0;
18866 stack = (unsigned long)task_stack_page(p);
18867- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18868+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18869 return 0;
18870 fp = *(u64 *)(p->thread.sp);
18871 do {
18872- if (fp < (unsigned long)stack ||
18873- fp >= (unsigned long)stack+THREAD_SIZE)
18874+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18875 return 0;
18876 ip = *(u64 *)(fp+8);
18877 if (!in_sched_functions(ip))
18878diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18879index 5026738..c5925c0 100644
18880--- a/arch/x86/kernel/ptrace.c
18881+++ b/arch/x86/kernel/ptrace.c
18882@@ -823,7 +823,7 @@ long arch_ptrace(struct task_struct *child, long request,
18883 unsigned long addr, unsigned long data)
18884 {
18885 int ret;
18886- unsigned long __user *datap = (unsigned long __user *)data;
18887+ unsigned long __user *datap = (__force unsigned long __user *)data;
18888
18889 switch (request) {
18890 /* read the word at location addr in the USER area. */
18891@@ -908,14 +908,14 @@ long arch_ptrace(struct task_struct *child, long request,
18892 if ((int) addr < 0)
18893 return -EIO;
18894 ret = do_get_thread_area(child, addr,
18895- (struct user_desc __user *)data);
18896+ (__force struct user_desc __user *) data);
18897 break;
18898
18899 case PTRACE_SET_THREAD_AREA:
18900 if ((int) addr < 0)
18901 return -EIO;
18902 ret = do_set_thread_area(child, addr,
18903- (struct user_desc __user *)data, 0);
18904+ (__force struct user_desc __user *) data, 0);
18905 break;
18906 #endif
18907
18908@@ -1332,7 +1332,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18909 memset(info, 0, sizeof(*info));
18910 info->si_signo = SIGTRAP;
18911 info->si_code = si_code;
18912- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18913+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18914 }
18915
18916 void user_single_step_siginfo(struct task_struct *tsk,
18917@@ -1361,6 +1361,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18918 # define IS_IA32 0
18919 #endif
18920
18921+#ifdef CONFIG_GRKERNSEC_SETXID
18922+extern void gr_delayed_cred_worker(void);
18923+#endif
18924+
18925 /*
18926 * We must return the syscall number to actually look up in the table.
18927 * This can be -1L to skip running any syscall at all.
18928@@ -1369,6 +1373,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18929 {
18930 long ret = 0;
18931
18932+#ifdef CONFIG_GRKERNSEC_SETXID
18933+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18934+ gr_delayed_cred_worker();
18935+#endif
18936+
18937 /*
18938 * If we stepped into a sysenter/syscall insn, it trapped in
18939 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18940@@ -1412,6 +1421,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18941 {
18942 bool step;
18943
18944+#ifdef CONFIG_GRKERNSEC_SETXID
18945+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18946+ gr_delayed_cred_worker();
18947+#endif
18948+
18949 audit_syscall_exit(regs);
18950
18951 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18952diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18953index 42eb330..139955c 100644
18954--- a/arch/x86/kernel/pvclock.c
18955+++ b/arch/x86/kernel/pvclock.c
18956@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18957 return pv_tsc_khz;
18958 }
18959
18960-static atomic64_t last_value = ATOMIC64_INIT(0);
18961+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18962
18963 void pvclock_resume(void)
18964 {
18965- atomic64_set(&last_value, 0);
18966+ atomic64_set_unchecked(&last_value, 0);
18967 }
18968
18969 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18970@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18971 * updating at the same time, and one of them could be slightly behind,
18972 * making the assumption that last_value always go forward fail to hold.
18973 */
18974- last = atomic64_read(&last_value);
18975+ last = atomic64_read_unchecked(&last_value);
18976 do {
18977 if (ret < last)
18978 return last;
18979- last = atomic64_cmpxchg(&last_value, last, ret);
18980+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18981 } while (unlikely(last != ret));
18982
18983 return ret;
18984diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18985index d840e69..98e9581 100644
18986--- a/arch/x86/kernel/reboot.c
18987+++ b/arch/x86/kernel/reboot.c
18988@@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18989 EXPORT_SYMBOL(pm_power_off);
18990
18991 static const struct desc_ptr no_idt = {};
18992-static int reboot_mode;
18993+static unsigned short reboot_mode;
18994 enum reboot_type reboot_type = BOOT_ACPI;
18995 int reboot_force;
18996
18997@@ -335,13 +335,17 @@ core_initcall(reboot_init);
18998 extern const unsigned char machine_real_restart_asm[];
18999 extern const u64 machine_real_restart_gdt[3];
19000
19001-void machine_real_restart(unsigned int type)
19002+__noreturn void machine_real_restart(unsigned int type)
19003 {
19004 void *restart_va;
19005 unsigned long restart_pa;
19006- void (*restart_lowmem)(unsigned int);
19007+ void (* __noreturn restart_lowmem)(unsigned int);
19008 u64 *lowmem_gdt;
19009
19010+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19011+ struct desc_struct *gdt;
19012+#endif
19013+
19014 local_irq_disable();
19015
19016 /* Write zero to CMOS register number 0x0f, which the BIOS POST
19017@@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
19018 boot)". This seems like a fairly standard thing that gets set by
19019 REBOOT.COM programs, and the previous reset routine did this
19020 too. */
19021- *((unsigned short *)0x472) = reboot_mode;
19022+ *(unsigned short *)(__va(0x472)) = reboot_mode;
19023
19024 /* Patch the GDT in the low memory trampoline */
19025 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
19026
19027 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
19028 restart_pa = virt_to_phys(restart_va);
19029- restart_lowmem = (void (*)(unsigned int))restart_pa;
19030+ restart_lowmem = (void *)restart_pa;
19031
19032 /* GDT[0]: GDT self-pointer */
19033 lowmem_gdt[0] =
19034@@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
19035 GDT_ENTRY(0x009b, restart_pa, 0xffff);
19036
19037 /* Jump to the identity-mapped low memory code */
19038+
19039+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19040+ gdt = get_cpu_gdt_table(smp_processor_id());
19041+ pax_open_kernel();
19042+#ifdef CONFIG_PAX_MEMORY_UDEREF
19043+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
19044+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
19045+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
19046+#endif
19047+#ifdef CONFIG_PAX_KERNEXEC
19048+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
19049+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
19050+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
19051+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
19052+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
19053+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
19054+#endif
19055+ pax_close_kernel();
19056+#endif
19057+
19058+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19059+ asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
19060+ unreachable();
19061+#else
19062 restart_lowmem(type);
19063+#endif
19064+
19065 }
19066 #ifdef CONFIG_APM_MODULE
19067 EXPORT_SYMBOL(machine_real_restart);
19068@@ -556,7 +586,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
19069 * try to force a triple fault and then cycle between hitting the keyboard
19070 * controller and doing that
19071 */
19072-static void native_machine_emergency_restart(void)
19073+__noreturn static void native_machine_emergency_restart(void)
19074 {
19075 int i;
19076 int attempt = 0;
19077@@ -680,13 +710,13 @@ void native_machine_shutdown(void)
19078 #endif
19079 }
19080
19081-static void __machine_emergency_restart(int emergency)
19082+static __noreturn void __machine_emergency_restart(int emergency)
19083 {
19084 reboot_emergency = emergency;
19085 machine_ops.emergency_restart();
19086 }
19087
19088-static void native_machine_restart(char *__unused)
19089+static __noreturn void native_machine_restart(char *__unused)
19090 {
19091 printk("machine restart\n");
19092
19093@@ -695,7 +725,7 @@ static void native_machine_restart(char *__unused)
19094 __machine_emergency_restart(0);
19095 }
19096
19097-static void native_machine_halt(void)
19098+static __noreturn void native_machine_halt(void)
19099 {
19100 /* stop other cpus and apics */
19101 machine_shutdown();
19102@@ -706,7 +736,7 @@ static void native_machine_halt(void)
19103 stop_this_cpu(NULL);
19104 }
19105
19106-static void native_machine_power_off(void)
19107+__noreturn static void native_machine_power_off(void)
19108 {
19109 if (pm_power_off) {
19110 if (!reboot_force)
19111@@ -715,6 +745,7 @@ static void native_machine_power_off(void)
19112 }
19113 /* a fallback in case there is no PM info available */
19114 tboot_shutdown(TB_SHUTDOWN_HALT);
19115+ unreachable();
19116 }
19117
19118 struct machine_ops machine_ops = {
19119diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19120index 7a6f3b3..bed145d7 100644
19121--- a/arch/x86/kernel/relocate_kernel_64.S
19122+++ b/arch/x86/kernel/relocate_kernel_64.S
19123@@ -11,6 +11,7 @@
19124 #include <asm/kexec.h>
19125 #include <asm/processor-flags.h>
19126 #include <asm/pgtable_types.h>
19127+#include <asm/alternative-asm.h>
19128
19129 /*
19130 * Must be relocatable PIC code callable as a C function
19131@@ -160,13 +161,14 @@ identity_mapped:
19132 xorq %rbp, %rbp
19133 xorq %r8, %r8
19134 xorq %r9, %r9
19135- xorq %r10, %r9
19136+ xorq %r10, %r10
19137 xorq %r11, %r11
19138 xorq %r12, %r12
19139 xorq %r13, %r13
19140 xorq %r14, %r14
19141 xorq %r15, %r15
19142
19143+ pax_force_retaddr 0, 1
19144 ret
19145
19146 1:
19147diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19148index d7d5099..28555d0 100644
19149--- a/arch/x86/kernel/setup.c
19150+++ b/arch/x86/kernel/setup.c
19151@@ -448,7 +448,7 @@ static void __init parse_setup_data(void)
19152
19153 switch (data->type) {
19154 case SETUP_E820_EXT:
19155- parse_e820_ext(data);
19156+ parse_e820_ext((struct setup_data __force_kernel *)data);
19157 break;
19158 case SETUP_DTB:
19159 add_dtb(pa_data);
19160@@ -649,7 +649,7 @@ static void __init trim_bios_range(void)
19161 * area (640->1Mb) as ram even though it is not.
19162 * take them out.
19163 */
19164- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19165+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19166 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19167 }
19168
19169@@ -767,14 +767,14 @@ void __init setup_arch(char **cmdline_p)
19170
19171 if (!boot_params.hdr.root_flags)
19172 root_mountflags &= ~MS_RDONLY;
19173- init_mm.start_code = (unsigned long) _text;
19174- init_mm.end_code = (unsigned long) _etext;
19175+ init_mm.start_code = ktla_ktva((unsigned long) _text);
19176+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
19177 init_mm.end_data = (unsigned long) _edata;
19178 init_mm.brk = _brk_end;
19179
19180- code_resource.start = virt_to_phys(_text);
19181- code_resource.end = virt_to_phys(_etext)-1;
19182- data_resource.start = virt_to_phys(_etext);
19183+ code_resource.start = virt_to_phys(ktla_ktva(_text));
19184+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19185+ data_resource.start = virt_to_phys(_sdata);
19186 data_resource.end = virt_to_phys(_edata)-1;
19187 bss_resource.start = virt_to_phys(&__bss_start);
19188 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19189diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19190index 5a98aa2..2f9288d 100644
19191--- a/arch/x86/kernel/setup_percpu.c
19192+++ b/arch/x86/kernel/setup_percpu.c
19193@@ -21,19 +21,17 @@
19194 #include <asm/cpu.h>
19195 #include <asm/stackprotector.h>
19196
19197-DEFINE_PER_CPU(int, cpu_number);
19198+#ifdef CONFIG_SMP
19199+DEFINE_PER_CPU(unsigned int, cpu_number);
19200 EXPORT_PER_CPU_SYMBOL(cpu_number);
19201+#endif
19202
19203-#ifdef CONFIG_X86_64
19204 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19205-#else
19206-#define BOOT_PERCPU_OFFSET 0
19207-#endif
19208
19209 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19210 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19211
19212-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19213+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19214 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19215 };
19216 EXPORT_SYMBOL(__per_cpu_offset);
19217@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19218 {
19219 #ifdef CONFIG_X86_32
19220 struct desc_struct gdt;
19221+ unsigned long base = per_cpu_offset(cpu);
19222
19223- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19224- 0x2 | DESCTYPE_S, 0x8);
19225- gdt.s = 1;
19226+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19227+ 0x83 | DESCTYPE_S, 0xC);
19228 write_gdt_entry(get_cpu_gdt_table(cpu),
19229 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19230 #endif
19231@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19232 /* alrighty, percpu areas up and running */
19233 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19234 for_each_possible_cpu(cpu) {
19235+#ifdef CONFIG_CC_STACKPROTECTOR
19236+#ifdef CONFIG_X86_32
19237+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
19238+#endif
19239+#endif
19240 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19241 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19242 per_cpu(cpu_number, cpu) = cpu;
19243@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19244 */
19245 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19246 #endif
19247+#ifdef CONFIG_CC_STACKPROTECTOR
19248+#ifdef CONFIG_X86_32
19249+ if (!cpu)
19250+ per_cpu(stack_canary.canary, cpu) = canary;
19251+#endif
19252+#endif
19253 /*
19254 * Up to this point, the boot CPU has been using .init.data
19255 * area. Reload any changed state for the boot CPU.
19256diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19257index 46a01bd..2e88e6d 100644
19258--- a/arch/x86/kernel/signal.c
19259+++ b/arch/x86/kernel/signal.c
19260@@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
19261 * Align the stack pointer according to the i386 ABI,
19262 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19263 */
19264- sp = ((sp + 4) & -16ul) - 4;
19265+ sp = ((sp - 12) & -16ul) - 4;
19266 #else /* !CONFIG_X86_32 */
19267 sp = round_down(sp, 16) - 8;
19268 #endif
19269@@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19270 * Return an always-bogus address instead so we will die with SIGSEGV.
19271 */
19272 if (onsigstack && !likely(on_sig_stack(sp)))
19273- return (void __user *)-1L;
19274+ return (__force void __user *)-1L;
19275
19276 /* save i387 state */
19277 if (used_math() && save_i387_xstate(*fpstate) < 0)
19278- return (void __user *)-1L;
19279+ return (__force void __user *)-1L;
19280
19281 return (void __user *)sp;
19282 }
19283@@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19284 }
19285
19286 if (current->mm->context.vdso)
19287- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19288+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19289 else
19290- restorer = &frame->retcode;
19291+ restorer = (void __user *)&frame->retcode;
19292 if (ka->sa.sa_flags & SA_RESTORER)
19293 restorer = ka->sa.sa_restorer;
19294
19295@@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19296 * reasons and because gdb uses it as a signature to notice
19297 * signal handler stack frames.
19298 */
19299- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19300+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19301
19302 if (err)
19303 return -EFAULT;
19304@@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19305 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19306
19307 /* Set up to return from userspace. */
19308- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19309+ if (current->mm->context.vdso)
19310+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19311+ else
19312+ restorer = (void __user *)&frame->retcode;
19313 if (ka->sa.sa_flags & SA_RESTORER)
19314 restorer = ka->sa.sa_restorer;
19315 put_user_ex(restorer, &frame->pretcode);
19316@@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19317 * reasons and because gdb uses it as a signature to notice
19318 * signal handler stack frames.
19319 */
19320- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19321+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19322 } put_user_catch(err);
19323
19324 if (err)
19325@@ -765,7 +768,7 @@ static void do_signal(struct pt_regs *regs)
19326 * X86_32: vm86 regs switched out by assembly code before reaching
19327 * here, so testing against kernel CS suffices.
19328 */
19329- if (!user_mode(regs))
19330+ if (!user_mode_novm(regs))
19331 return;
19332
19333 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
19334diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19335index 66d250c..f1b10bd 100644
19336--- a/arch/x86/kernel/smpboot.c
19337+++ b/arch/x86/kernel/smpboot.c
19338@@ -715,17 +715,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
19339 set_idle_for_cpu(cpu, c_idle.idle);
19340 do_rest:
19341 per_cpu(current_task, cpu) = c_idle.idle;
19342+ per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
19343 #ifdef CONFIG_X86_32
19344 /* Stack for startup_32 can be just as for start_secondary onwards */
19345 irq_ctx_init(cpu);
19346 #else
19347 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
19348 initial_gs = per_cpu_offset(cpu);
19349- per_cpu(kernel_stack, cpu) =
19350- (unsigned long)task_stack_page(c_idle.idle) -
19351- KERNEL_STACK_OFFSET + THREAD_SIZE;
19352+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
19353 #endif
19354+
19355+ pax_open_kernel();
19356 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19357+ pax_close_kernel();
19358+
19359 initial_code = (unsigned long)start_secondary;
19360 stack_start = c_idle.idle->thread.sp;
19361
19362@@ -868,6 +871,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
19363
19364 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19365
19366+#ifdef CONFIG_PAX_PER_CPU_PGD
19367+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19368+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19369+ KERNEL_PGD_PTRS);
19370+#endif
19371+
19372 err = do_boot_cpu(apicid, cpu);
19373 if (err) {
19374 pr_debug("do_boot_cpu failed %d\n", err);
19375diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19376index c346d11..d43b163 100644
19377--- a/arch/x86/kernel/step.c
19378+++ b/arch/x86/kernel/step.c
19379@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19380 struct desc_struct *desc;
19381 unsigned long base;
19382
19383- seg &= ~7UL;
19384+ seg >>= 3;
19385
19386 mutex_lock(&child->mm->context.lock);
19387- if (unlikely((seg >> 3) >= child->mm->context.size))
19388+ if (unlikely(seg >= child->mm->context.size))
19389 addr = -1L; /* bogus selector, access would fault */
19390 else {
19391 desc = child->mm->context.ldt + seg;
19392@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19393 addr += base;
19394 }
19395 mutex_unlock(&child->mm->context.lock);
19396- }
19397+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19398+ addr = ktla_ktva(addr);
19399
19400 return addr;
19401 }
19402@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19403 unsigned char opcode[15];
19404 unsigned long addr = convert_ip_to_linear(child, regs);
19405
19406+ if (addr == -EINVAL)
19407+ return 0;
19408+
19409 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19410 for (i = 0; i < copied; i++) {
19411 switch (opcode[i]) {
19412diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19413index 0b0cb5f..db6b9ed 100644
19414--- a/arch/x86/kernel/sys_i386_32.c
19415+++ b/arch/x86/kernel/sys_i386_32.c
19416@@ -24,17 +24,224 @@
19417
19418 #include <asm/syscalls.h>
19419
19420-/*
19421- * Do a system call from kernel instead of calling sys_execve so we
19422- * end up with proper pt_regs.
19423- */
19424-int kernel_execve(const char *filename,
19425- const char *const argv[],
19426- const char *const envp[])
19427+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19428 {
19429- long __res;
19430- asm volatile ("int $0x80"
19431- : "=a" (__res)
19432- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19433- return __res;
19434+ unsigned long pax_task_size = TASK_SIZE;
19435+
19436+#ifdef CONFIG_PAX_SEGMEXEC
19437+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19438+ pax_task_size = SEGMEXEC_TASK_SIZE;
19439+#endif
19440+
19441+ if (len > pax_task_size || addr > pax_task_size - len)
19442+ return -EINVAL;
19443+
19444+ return 0;
19445+}
19446+
19447+unsigned long
19448+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19449+ unsigned long len, unsigned long pgoff, unsigned long flags)
19450+{
19451+ struct mm_struct *mm = current->mm;
19452+ struct vm_area_struct *vma;
19453+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19454+
19455+#ifdef CONFIG_PAX_SEGMEXEC
19456+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19457+ pax_task_size = SEGMEXEC_TASK_SIZE;
19458+#endif
19459+
19460+ pax_task_size -= PAGE_SIZE;
19461+
19462+ if (len > pax_task_size)
19463+ return -ENOMEM;
19464+
19465+ if (flags & MAP_FIXED)
19466+ return addr;
19467+
19468+#ifdef CONFIG_PAX_RANDMMAP
19469+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19470+#endif
19471+
19472+ if (addr) {
19473+ addr = PAGE_ALIGN(addr);
19474+ if (pax_task_size - len >= addr) {
19475+ vma = find_vma(mm, addr);
19476+ if (check_heap_stack_gap(vma, addr, len))
19477+ return addr;
19478+ }
19479+ }
19480+ if (len > mm->cached_hole_size) {
19481+ start_addr = addr = mm->free_area_cache;
19482+ } else {
19483+ start_addr = addr = mm->mmap_base;
19484+ mm->cached_hole_size = 0;
19485+ }
19486+
19487+#ifdef CONFIG_PAX_PAGEEXEC
19488+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19489+ start_addr = 0x00110000UL;
19490+
19491+#ifdef CONFIG_PAX_RANDMMAP
19492+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19493+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19494+#endif
19495+
19496+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19497+ start_addr = addr = mm->mmap_base;
19498+ else
19499+ addr = start_addr;
19500+ }
19501+#endif
19502+
19503+full_search:
19504+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19505+ /* At this point: (!vma || addr < vma->vm_end). */
19506+ if (pax_task_size - len < addr) {
19507+ /*
19508+ * Start a new search - just in case we missed
19509+ * some holes.
19510+ */
19511+ if (start_addr != mm->mmap_base) {
19512+ start_addr = addr = mm->mmap_base;
19513+ mm->cached_hole_size = 0;
19514+ goto full_search;
19515+ }
19516+ return -ENOMEM;
19517+ }
19518+ if (check_heap_stack_gap(vma, addr, len))
19519+ break;
19520+ if (addr + mm->cached_hole_size < vma->vm_start)
19521+ mm->cached_hole_size = vma->vm_start - addr;
19522+ addr = vma->vm_end;
19523+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19524+ start_addr = addr = mm->mmap_base;
19525+ mm->cached_hole_size = 0;
19526+ goto full_search;
19527+ }
19528+ }
19529+
19530+ /*
19531+ * Remember the place where we stopped the search:
19532+ */
19533+ mm->free_area_cache = addr + len;
19534+ return addr;
19535+}
19536+
19537+unsigned long
19538+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19539+ const unsigned long len, const unsigned long pgoff,
19540+ const unsigned long flags)
19541+{
19542+ struct vm_area_struct *vma;
19543+ struct mm_struct *mm = current->mm;
19544+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19545+
19546+#ifdef CONFIG_PAX_SEGMEXEC
19547+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19548+ pax_task_size = SEGMEXEC_TASK_SIZE;
19549+#endif
19550+
19551+ pax_task_size -= PAGE_SIZE;
19552+
19553+ /* requested length too big for entire address space */
19554+ if (len > pax_task_size)
19555+ return -ENOMEM;
19556+
19557+ if (flags & MAP_FIXED)
19558+ return addr;
19559+
19560+#ifdef CONFIG_PAX_PAGEEXEC
19561+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19562+ goto bottomup;
19563+#endif
19564+
19565+#ifdef CONFIG_PAX_RANDMMAP
19566+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19567+#endif
19568+
19569+ /* requesting a specific address */
19570+ if (addr) {
19571+ addr = PAGE_ALIGN(addr);
19572+ if (pax_task_size - len >= addr) {
19573+ vma = find_vma(mm, addr);
19574+ if (check_heap_stack_gap(vma, addr, len))
19575+ return addr;
19576+ }
19577+ }
19578+
19579+ /* check if free_area_cache is useful for us */
19580+ if (len <= mm->cached_hole_size) {
19581+ mm->cached_hole_size = 0;
19582+ mm->free_area_cache = mm->mmap_base;
19583+ }
19584+
19585+ /* either no address requested or can't fit in requested address hole */
19586+ addr = mm->free_area_cache;
19587+
19588+ /* make sure it can fit in the remaining address space */
19589+ if (addr > len) {
19590+ vma = find_vma(mm, addr-len);
19591+ if (check_heap_stack_gap(vma, addr - len, len))
19592+ /* remember the address as a hint for next time */
19593+ return (mm->free_area_cache = addr-len);
19594+ }
19595+
19596+ if (mm->mmap_base < len)
19597+ goto bottomup;
19598+
19599+ addr = mm->mmap_base-len;
19600+
19601+ do {
19602+ /*
19603+ * Lookup failure means no vma is above this address,
19604+ * else if new region fits below vma->vm_start,
19605+ * return with success:
19606+ */
19607+ vma = find_vma(mm, addr);
19608+ if (check_heap_stack_gap(vma, addr, len))
19609+ /* remember the address as a hint for next time */
19610+ return (mm->free_area_cache = addr);
19611+
19612+ /* remember the largest hole we saw so far */
19613+ if (addr + mm->cached_hole_size < vma->vm_start)
19614+ mm->cached_hole_size = vma->vm_start - addr;
19615+
19616+ /* try just below the current vma->vm_start */
19617+ addr = skip_heap_stack_gap(vma, len);
19618+ } while (!IS_ERR_VALUE(addr));
19619+
19620+bottomup:
19621+ /*
19622+ * A failed mmap() very likely causes application failure,
19623+ * so fall back to the bottom-up function here. This scenario
19624+ * can happen with large stack limits and large mmap()
19625+ * allocations.
19626+ */
19627+
19628+#ifdef CONFIG_PAX_SEGMEXEC
19629+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19630+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19631+ else
19632+#endif
19633+
19634+ mm->mmap_base = TASK_UNMAPPED_BASE;
19635+
19636+#ifdef CONFIG_PAX_RANDMMAP
19637+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19638+ mm->mmap_base += mm->delta_mmap;
19639+#endif
19640+
19641+ mm->free_area_cache = mm->mmap_base;
19642+ mm->cached_hole_size = ~0UL;
19643+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19644+ /*
19645+ * Restore the topdown base:
19646+ */
19647+ mm->mmap_base = base;
19648+ mm->free_area_cache = base;
19649+ mm->cached_hole_size = ~0UL;
19650+
19651+ return addr;
19652 }
19653diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19654index 0514890..3dbebce 100644
19655--- a/arch/x86/kernel/sys_x86_64.c
19656+++ b/arch/x86/kernel/sys_x86_64.c
19657@@ -95,8 +95,8 @@ out:
19658 return error;
19659 }
19660
19661-static void find_start_end(unsigned long flags, unsigned long *begin,
19662- unsigned long *end)
19663+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19664+ unsigned long *begin, unsigned long *end)
19665 {
19666 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
19667 unsigned long new_begin;
19668@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19669 *begin = new_begin;
19670 }
19671 } else {
19672- *begin = TASK_UNMAPPED_BASE;
19673+ *begin = mm->mmap_base;
19674 *end = TASK_SIZE;
19675 }
19676 }
19677@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19678 if (flags & MAP_FIXED)
19679 return addr;
19680
19681- find_start_end(flags, &begin, &end);
19682+ find_start_end(mm, flags, &begin, &end);
19683
19684 if (len > end)
19685 return -ENOMEM;
19686
19687+#ifdef CONFIG_PAX_RANDMMAP
19688+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19689+#endif
19690+
19691 if (addr) {
19692 addr = PAGE_ALIGN(addr);
19693 vma = find_vma(mm, addr);
19694- if (end - len >= addr &&
19695- (!vma || addr + len <= vma->vm_start))
19696+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19697 return addr;
19698 }
19699 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
19700@@ -172,7 +175,7 @@ full_search:
19701 }
19702 return -ENOMEM;
19703 }
19704- if (!vma || addr + len <= vma->vm_start) {
19705+ if (check_heap_stack_gap(vma, addr, len)) {
19706 /*
19707 * Remember the place where we stopped the search:
19708 */
19709@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19710 {
19711 struct vm_area_struct *vma;
19712 struct mm_struct *mm = current->mm;
19713- unsigned long addr = addr0;
19714+ unsigned long base = mm->mmap_base, addr = addr0;
19715
19716 /* requested length too big for entire address space */
19717 if (len > TASK_SIZE)
19718@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19719 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
19720 goto bottomup;
19721
19722+#ifdef CONFIG_PAX_RANDMMAP
19723+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19724+#endif
19725+
19726 /* requesting a specific address */
19727 if (addr) {
19728 addr = PAGE_ALIGN(addr);
19729- vma = find_vma(mm, addr);
19730- if (TASK_SIZE - len >= addr &&
19731- (!vma || addr + len <= vma->vm_start))
19732- return addr;
19733+ if (TASK_SIZE - len >= addr) {
19734+ vma = find_vma(mm, addr);
19735+ if (check_heap_stack_gap(vma, addr, len))
19736+ return addr;
19737+ }
19738 }
19739
19740 /* check if free_area_cache is useful for us */
19741@@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19742 ALIGN_TOPDOWN);
19743
19744 vma = find_vma(mm, tmp_addr);
19745- if (!vma || tmp_addr + len <= vma->vm_start)
19746+ if (check_heap_stack_gap(vma, tmp_addr, len))
19747 /* remember the address as a hint for next time */
19748 return mm->free_area_cache = tmp_addr;
19749 }
19750@@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19751 * return with success:
19752 */
19753 vma = find_vma(mm, addr);
19754- if (!vma || addr+len <= vma->vm_start)
19755+ if (check_heap_stack_gap(vma, addr, len))
19756 /* remember the address as a hint for next time */
19757 return mm->free_area_cache = addr;
19758
19759@@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19760 mm->cached_hole_size = vma->vm_start - addr;
19761
19762 /* try just below the current vma->vm_start */
19763- addr = vma->vm_start-len;
19764- } while (len < vma->vm_start);
19765+ addr = skip_heap_stack_gap(vma, len);
19766+ } while (!IS_ERR_VALUE(addr));
19767
19768 bottomup:
19769 /*
19770@@ -270,13 +278,21 @@ bottomup:
19771 * can happen with large stack limits and large mmap()
19772 * allocations.
19773 */
19774+ mm->mmap_base = TASK_UNMAPPED_BASE;
19775+
19776+#ifdef CONFIG_PAX_RANDMMAP
19777+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19778+ mm->mmap_base += mm->delta_mmap;
19779+#endif
19780+
19781+ mm->free_area_cache = mm->mmap_base;
19782 mm->cached_hole_size = ~0UL;
19783- mm->free_area_cache = TASK_UNMAPPED_BASE;
19784 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19785 /*
19786 * Restore the topdown base:
19787 */
19788- mm->free_area_cache = mm->mmap_base;
19789+ mm->mmap_base = base;
19790+ mm->free_area_cache = base;
19791 mm->cached_hole_size = ~0UL;
19792
19793 return addr;
19794diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19795index e2410e2..4fe3fbc 100644
19796--- a/arch/x86/kernel/tboot.c
19797+++ b/arch/x86/kernel/tboot.c
19798@@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19799
19800 void tboot_shutdown(u32 shutdown_type)
19801 {
19802- void (*shutdown)(void);
19803+ void (* __noreturn shutdown)(void);
19804
19805 if (!tboot_enabled())
19806 return;
19807@@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19808
19809 switch_to_tboot_pt();
19810
19811- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19812+ shutdown = (void *)tboot->shutdown_entry;
19813 shutdown();
19814
19815 /* should not reach here */
19816@@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19817 tboot_shutdown(acpi_shutdown_map[sleep_state]);
19818 }
19819
19820-static atomic_t ap_wfs_count;
19821+static atomic_unchecked_t ap_wfs_count;
19822
19823 static int tboot_wait_for_aps(int num_aps)
19824 {
19825@@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19826 {
19827 switch (action) {
19828 case CPU_DYING:
19829- atomic_inc(&ap_wfs_count);
19830+ atomic_inc_unchecked(&ap_wfs_count);
19831 if (num_online_cpus() == 1)
19832- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19833+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19834 return NOTIFY_BAD;
19835 break;
19836 }
19837@@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
19838
19839 tboot_create_trampoline();
19840
19841- atomic_set(&ap_wfs_count, 0);
19842+ atomic_set_unchecked(&ap_wfs_count, 0);
19843 register_hotcpu_notifier(&tboot_cpu_notifier);
19844 return 0;
19845 }
19846diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19847index dd5fbf4..b7f2232 100644
19848--- a/arch/x86/kernel/time.c
19849+++ b/arch/x86/kernel/time.c
19850@@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19851 {
19852 unsigned long pc = instruction_pointer(regs);
19853
19854- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19855+ if (!user_mode(regs) && in_lock_functions(pc)) {
19856 #ifdef CONFIG_FRAME_POINTER
19857- return *(unsigned long *)(regs->bp + sizeof(long));
19858+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19859 #else
19860 unsigned long *sp =
19861 (unsigned long *)kernel_stack_pointer(regs);
19862@@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19863 * or above a saved flags. Eflags has bits 22-31 zero,
19864 * kernel addresses don't.
19865 */
19866+
19867+#ifdef CONFIG_PAX_KERNEXEC
19868+ return ktla_ktva(sp[0]);
19869+#else
19870 if (sp[0] >> 22)
19871 return sp[0];
19872 if (sp[1] >> 22)
19873 return sp[1];
19874 #endif
19875+
19876+#endif
19877 }
19878 return pc;
19879 }
19880diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19881index bcfec2d..8f88b4a 100644
19882--- a/arch/x86/kernel/tls.c
19883+++ b/arch/x86/kernel/tls.c
19884@@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19885 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19886 return -EINVAL;
19887
19888+#ifdef CONFIG_PAX_SEGMEXEC
19889+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19890+ return -EINVAL;
19891+#endif
19892+
19893 set_tls_desc(p, idx, &info, 1);
19894
19895 return 0;
19896diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19897index 451c0a7..e57f551 100644
19898--- a/arch/x86/kernel/trampoline_32.S
19899+++ b/arch/x86/kernel/trampoline_32.S
19900@@ -32,6 +32,12 @@
19901 #include <asm/segment.h>
19902 #include <asm/page_types.h>
19903
19904+#ifdef CONFIG_PAX_KERNEXEC
19905+#define ta(X) (X)
19906+#else
19907+#define ta(X) ((X) - __PAGE_OFFSET)
19908+#endif
19909+
19910 #ifdef CONFIG_SMP
19911
19912 .section ".x86_trampoline","a"
19913@@ -62,7 +68,7 @@ r_base = .
19914 inc %ax # protected mode (PE) bit
19915 lmsw %ax # into protected mode
19916 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19917- ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19918+ ljmpl $__BOOT_CS, $ta(startup_32_smp)
19919
19920 # These need to be in the same 64K segment as the above;
19921 # hence we don't use the boot_gdt_descr defined in head.S
19922diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19923index 09ff517..df19fbff 100644
19924--- a/arch/x86/kernel/trampoline_64.S
19925+++ b/arch/x86/kernel/trampoline_64.S
19926@@ -90,7 +90,7 @@ startup_32:
19927 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19928 movl %eax, %ds
19929
19930- movl $X86_CR4_PAE, %eax
19931+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19932 movl %eax, %cr4 # Enable PAE mode
19933
19934 # Setup trampoline 4 level pagetables
19935@@ -138,7 +138,7 @@ tidt:
19936 # so the kernel can live anywhere
19937 .balign 4
19938 tgdt:
19939- .short tgdt_end - tgdt # gdt limit
19940+ .short tgdt_end - tgdt - 1 # gdt limit
19941 .long tgdt - r_base
19942 .short 0
19943 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19944diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19945index 4bbe04d..41d0943 100644
19946--- a/arch/x86/kernel/traps.c
19947+++ b/arch/x86/kernel/traps.c
19948@@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19949
19950 /* Do we ignore FPU interrupts ? */
19951 char ignore_fpu_irq;
19952-
19953-/*
19954- * The IDT has to be page-aligned to simplify the Pentium
19955- * F0 0F bug workaround.
19956- */
19957-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19958 #endif
19959
19960 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19961@@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19962 }
19963
19964 static void __kprobes
19965-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19966+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19967 long error_code, siginfo_t *info)
19968 {
19969 struct task_struct *tsk = current;
19970
19971 #ifdef CONFIG_X86_32
19972- if (regs->flags & X86_VM_MASK) {
19973+ if (v8086_mode(regs)) {
19974 /*
19975 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19976 * On nmi (interrupt 2), do_trap should not be called.
19977@@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19978 }
19979 #endif
19980
19981- if (!user_mode(regs))
19982+ if (!user_mode_novm(regs))
19983 goto kernel_trap;
19984
19985 #ifdef CONFIG_X86_32
19986@@ -148,7 +142,7 @@ trap_signal:
19987 printk_ratelimit()) {
19988 printk(KERN_INFO
19989 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19990- tsk->comm, tsk->pid, str,
19991+ tsk->comm, task_pid_nr(tsk), str,
19992 regs->ip, regs->sp, error_code);
19993 print_vma_addr(" in ", regs->ip);
19994 printk("\n");
19995@@ -165,8 +159,20 @@ kernel_trap:
19996 if (!fixup_exception(regs)) {
19997 tsk->thread.error_code = error_code;
19998 tsk->thread.trap_no = trapnr;
19999+
20000+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20001+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
20002+ str = "PAX: suspicious stack segment fault";
20003+#endif
20004+
20005 die(str, regs, error_code);
20006 }
20007+
20008+#ifdef CONFIG_PAX_REFCOUNT
20009+ if (trapnr == 4)
20010+ pax_report_refcount_overflow(regs);
20011+#endif
20012+
20013 return;
20014
20015 #ifdef CONFIG_X86_32
20016@@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
20017 conditional_sti(regs);
20018
20019 #ifdef CONFIG_X86_32
20020- if (regs->flags & X86_VM_MASK)
20021+ if (v8086_mode(regs))
20022 goto gp_in_vm86;
20023 #endif
20024
20025 tsk = current;
20026- if (!user_mode(regs))
20027+ if (!user_mode_novm(regs))
20028 goto gp_in_kernel;
20029
20030+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
20031+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
20032+ struct mm_struct *mm = tsk->mm;
20033+ unsigned long limit;
20034+
20035+ down_write(&mm->mmap_sem);
20036+ limit = mm->context.user_cs_limit;
20037+ if (limit < TASK_SIZE) {
20038+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
20039+ up_write(&mm->mmap_sem);
20040+ return;
20041+ }
20042+ up_write(&mm->mmap_sem);
20043+ }
20044+#endif
20045+
20046 tsk->thread.error_code = error_code;
20047 tsk->thread.trap_no = 13;
20048
20049@@ -295,6 +317,13 @@ gp_in_kernel:
20050 if (notify_die(DIE_GPF, "general protection fault", regs,
20051 error_code, 13, SIGSEGV) == NOTIFY_STOP)
20052 return;
20053+
20054+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20055+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
20056+ die("PAX: suspicious general protection fault", regs, error_code);
20057+ else
20058+#endif
20059+
20060 die("general protection fault", regs, error_code);
20061 }
20062
20063@@ -421,7 +450,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20064 /* It's safe to allow irq's after DR6 has been saved */
20065 preempt_conditional_sti(regs);
20066
20067- if (regs->flags & X86_VM_MASK) {
20068+ if (v8086_mode(regs)) {
20069 handle_vm86_trap((struct kernel_vm86_regs *) regs,
20070 error_code, 1);
20071 preempt_conditional_cli(regs);
20072@@ -436,7 +465,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20073 * We already checked v86 mode above, so we can check for kernel mode
20074 * by just checking the CPL of CS.
20075 */
20076- if ((dr6 & DR_STEP) && !user_mode(regs)) {
20077+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
20078 tsk->thread.debugreg6 &= ~DR_STEP;
20079 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
20080 regs->flags &= ~X86_EFLAGS_TF;
20081@@ -466,7 +495,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
20082 return;
20083 conditional_sti(regs);
20084
20085- if (!user_mode_vm(regs))
20086+ if (!user_mode(regs))
20087 {
20088 if (!fixup_exception(regs)) {
20089 task->thread.error_code = error_code;
20090diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
20091index b9242ba..50c5edd 100644
20092--- a/arch/x86/kernel/verify_cpu.S
20093+++ b/arch/x86/kernel/verify_cpu.S
20094@@ -20,6 +20,7 @@
20095 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
20096 * arch/x86/kernel/trampoline_64.S: secondary processor verification
20097 * arch/x86/kernel/head_32.S: processor startup
20098+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
20099 *
20100 * verify_cpu, returns the status of longmode and SSE in register %eax.
20101 * 0: Success 1: Failure
20102diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
20103index 328cb37..56556b4 100644
20104--- a/arch/x86/kernel/vm86_32.c
20105+++ b/arch/x86/kernel/vm86_32.c
20106@@ -41,6 +41,7 @@
20107 #include <linux/ptrace.h>
20108 #include <linux/audit.h>
20109 #include <linux/stddef.h>
20110+#include <linux/grsecurity.h>
20111
20112 #include <asm/uaccess.h>
20113 #include <asm/io.h>
20114@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
20115 do_exit(SIGSEGV);
20116 }
20117
20118- tss = &per_cpu(init_tss, get_cpu());
20119+ tss = init_tss + get_cpu();
20120 current->thread.sp0 = current->thread.saved_sp0;
20121 current->thread.sysenter_cs = __KERNEL_CS;
20122 load_sp0(tss, &current->thread);
20123@@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
20124 struct task_struct *tsk;
20125 int tmp, ret = -EPERM;
20126
20127+#ifdef CONFIG_GRKERNSEC_VM86
20128+ if (!capable(CAP_SYS_RAWIO)) {
20129+ gr_handle_vm86();
20130+ goto out;
20131+ }
20132+#endif
20133+
20134 tsk = current;
20135 if (tsk->thread.saved_sp0)
20136 goto out;
20137@@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
20138 int tmp, ret;
20139 struct vm86plus_struct __user *v86;
20140
20141+#ifdef CONFIG_GRKERNSEC_VM86
20142+ if (!capable(CAP_SYS_RAWIO)) {
20143+ gr_handle_vm86();
20144+ ret = -EPERM;
20145+ goto out;
20146+ }
20147+#endif
20148+
20149 tsk = current;
20150 switch (cmd) {
20151 case VM86_REQUEST_IRQ:
20152@@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20153 tsk->thread.saved_fs = info->regs32->fs;
20154 tsk->thread.saved_gs = get_user_gs(info->regs32);
20155
20156- tss = &per_cpu(init_tss, get_cpu());
20157+ tss = init_tss + get_cpu();
20158 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20159 if (cpu_has_sep)
20160 tsk->thread.sysenter_cs = 0;
20161@@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20162 goto cannot_handle;
20163 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20164 goto cannot_handle;
20165- intr_ptr = (unsigned long __user *) (i << 2);
20166+ intr_ptr = (__force unsigned long __user *) (i << 2);
20167 if (get_user(segoffs, intr_ptr))
20168 goto cannot_handle;
20169 if ((segoffs >> 16) == BIOSSEG)
20170diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20171index 0f703f1..9e15f64 100644
20172--- a/arch/x86/kernel/vmlinux.lds.S
20173+++ b/arch/x86/kernel/vmlinux.lds.S
20174@@ -26,6 +26,13 @@
20175 #include <asm/page_types.h>
20176 #include <asm/cache.h>
20177 #include <asm/boot.h>
20178+#include <asm/segment.h>
20179+
20180+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20181+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20182+#else
20183+#define __KERNEL_TEXT_OFFSET 0
20184+#endif
20185
20186 #undef i386 /* in case the preprocessor is a 32bit one */
20187
20188@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20189
20190 PHDRS {
20191 text PT_LOAD FLAGS(5); /* R_E */
20192+#ifdef CONFIG_X86_32
20193+ module PT_LOAD FLAGS(5); /* R_E */
20194+#endif
20195+#ifdef CONFIG_XEN
20196+ rodata PT_LOAD FLAGS(5); /* R_E */
20197+#else
20198+ rodata PT_LOAD FLAGS(4); /* R__ */
20199+#endif
20200 data PT_LOAD FLAGS(6); /* RW_ */
20201-#ifdef CONFIG_X86_64
20202+ init.begin PT_LOAD FLAGS(6); /* RW_ */
20203 #ifdef CONFIG_SMP
20204 percpu PT_LOAD FLAGS(6); /* RW_ */
20205 #endif
20206+ text.init PT_LOAD FLAGS(5); /* R_E */
20207+ text.exit PT_LOAD FLAGS(5); /* R_E */
20208 init PT_LOAD FLAGS(7); /* RWE */
20209-#endif
20210 note PT_NOTE FLAGS(0); /* ___ */
20211 }
20212
20213 SECTIONS
20214 {
20215 #ifdef CONFIG_X86_32
20216- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20217- phys_startup_32 = startup_32 - LOAD_OFFSET;
20218+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20219 #else
20220- . = __START_KERNEL;
20221- phys_startup_64 = startup_64 - LOAD_OFFSET;
20222+ . = __START_KERNEL;
20223 #endif
20224
20225 /* Text and read-only data */
20226- .text : AT(ADDR(.text) - LOAD_OFFSET) {
20227- _text = .;
20228+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20229 /* bootstrapping code */
20230+#ifdef CONFIG_X86_32
20231+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20232+#else
20233+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20234+#endif
20235+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20236+ _text = .;
20237 HEAD_TEXT
20238 #ifdef CONFIG_X86_32
20239 . = ALIGN(PAGE_SIZE);
20240@@ -108,13 +128,47 @@ SECTIONS
20241 IRQENTRY_TEXT
20242 *(.fixup)
20243 *(.gnu.warning)
20244- /* End of text section */
20245- _etext = .;
20246 } :text = 0x9090
20247
20248- NOTES :text :note
20249+ . += __KERNEL_TEXT_OFFSET;
20250
20251- EXCEPTION_TABLE(16) :text = 0x9090
20252+#ifdef CONFIG_X86_32
20253+ . = ALIGN(PAGE_SIZE);
20254+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20255+
20256+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20257+ MODULES_EXEC_VADDR = .;
20258+ BYTE(0)
20259+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20260+ . = ALIGN(HPAGE_SIZE);
20261+ MODULES_EXEC_END = . - 1;
20262+#endif
20263+
20264+ } :module
20265+#endif
20266+
20267+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20268+ /* End of text section */
20269+ _etext = . - __KERNEL_TEXT_OFFSET;
20270+ }
20271+
20272+#ifdef CONFIG_X86_32
20273+ . = ALIGN(PAGE_SIZE);
20274+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20275+ *(.idt)
20276+ . = ALIGN(PAGE_SIZE);
20277+ *(.empty_zero_page)
20278+ *(.initial_pg_fixmap)
20279+ *(.initial_pg_pmd)
20280+ *(.initial_page_table)
20281+ *(.swapper_pg_dir)
20282+ } :rodata
20283+#endif
20284+
20285+ . = ALIGN(PAGE_SIZE);
20286+ NOTES :rodata :note
20287+
20288+ EXCEPTION_TABLE(16) :rodata
20289
20290 #if defined(CONFIG_DEBUG_RODATA)
20291 /* .text should occupy whole number of pages */
20292@@ -126,16 +180,20 @@ SECTIONS
20293
20294 /* Data */
20295 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20296+
20297+#ifdef CONFIG_PAX_KERNEXEC
20298+ . = ALIGN(HPAGE_SIZE);
20299+#else
20300+ . = ALIGN(PAGE_SIZE);
20301+#endif
20302+
20303 /* Start of data section */
20304 _sdata = .;
20305
20306 /* init_task */
20307 INIT_TASK_DATA(THREAD_SIZE)
20308
20309-#ifdef CONFIG_X86_32
20310- /* 32 bit has nosave before _edata */
20311 NOSAVE_DATA
20312-#endif
20313
20314 PAGE_ALIGNED_DATA(PAGE_SIZE)
20315
20316@@ -176,12 +234,19 @@ SECTIONS
20317 #endif /* CONFIG_X86_64 */
20318
20319 /* Init code and data - will be freed after init */
20320- . = ALIGN(PAGE_SIZE);
20321 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20322+ BYTE(0)
20323+
20324+#ifdef CONFIG_PAX_KERNEXEC
20325+ . = ALIGN(HPAGE_SIZE);
20326+#else
20327+ . = ALIGN(PAGE_SIZE);
20328+#endif
20329+
20330 __init_begin = .; /* paired with __init_end */
20331- }
20332+ } :init.begin
20333
20334-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20335+#ifdef CONFIG_SMP
20336 /*
20337 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20338 * output PHDR, so the next output section - .init.text - should
20339@@ -190,12 +255,27 @@ SECTIONS
20340 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20341 #endif
20342
20343- INIT_TEXT_SECTION(PAGE_SIZE)
20344-#ifdef CONFIG_X86_64
20345- :init
20346-#endif
20347+ . = ALIGN(PAGE_SIZE);
20348+ init_begin = .;
20349+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20350+ VMLINUX_SYMBOL(_sinittext) = .;
20351+ INIT_TEXT
20352+ VMLINUX_SYMBOL(_einittext) = .;
20353+ . = ALIGN(PAGE_SIZE);
20354+ } :text.init
20355
20356- INIT_DATA_SECTION(16)
20357+ /*
20358+ * .exit.text is discard at runtime, not link time, to deal with
20359+ * references from .altinstructions and .eh_frame
20360+ */
20361+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20362+ EXIT_TEXT
20363+ . = ALIGN(16);
20364+ } :text.exit
20365+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20366+
20367+ . = ALIGN(PAGE_SIZE);
20368+ INIT_DATA_SECTION(16) :init
20369
20370 /*
20371 * Code and data for a variety of lowlevel trampolines, to be
20372@@ -269,19 +349,12 @@ SECTIONS
20373 }
20374
20375 . = ALIGN(8);
20376- /*
20377- * .exit.text is discard at runtime, not link time, to deal with
20378- * references from .altinstructions and .eh_frame
20379- */
20380- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20381- EXIT_TEXT
20382- }
20383
20384 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20385 EXIT_DATA
20386 }
20387
20388-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20389+#ifndef CONFIG_SMP
20390 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20391 #endif
20392
20393@@ -300,16 +373,10 @@ SECTIONS
20394 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20395 __smp_locks = .;
20396 *(.smp_locks)
20397- . = ALIGN(PAGE_SIZE);
20398 __smp_locks_end = .;
20399+ . = ALIGN(PAGE_SIZE);
20400 }
20401
20402-#ifdef CONFIG_X86_64
20403- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20404- NOSAVE_DATA
20405- }
20406-#endif
20407-
20408 /* BSS */
20409 . = ALIGN(PAGE_SIZE);
20410 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20411@@ -325,6 +392,7 @@ SECTIONS
20412 __brk_base = .;
20413 . += 64 * 1024; /* 64k alignment slop space */
20414 *(.brk_reservation) /* areas brk users have reserved */
20415+ . = ALIGN(HPAGE_SIZE);
20416 __brk_limit = .;
20417 }
20418
20419@@ -351,13 +419,12 @@ SECTIONS
20420 * for the boot processor.
20421 */
20422 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20423-INIT_PER_CPU(gdt_page);
20424 INIT_PER_CPU(irq_stack_union);
20425
20426 /*
20427 * Build-time check on the image size:
20428 */
20429-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20430+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20431 "kernel image bigger than KERNEL_IMAGE_SIZE");
20432
20433 #ifdef CONFIG_SMP
20434diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20435index b07ba93..a212969 100644
20436--- a/arch/x86/kernel/vsyscall_64.c
20437+++ b/arch/x86/kernel/vsyscall_64.c
20438@@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
20439 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
20440 };
20441
20442-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20443+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20444
20445 static int __init vsyscall_setup(char *str)
20446 {
20447 if (str) {
20448 if (!strcmp("emulate", str))
20449 vsyscall_mode = EMULATE;
20450- else if (!strcmp("native", str))
20451- vsyscall_mode = NATIVE;
20452 else if (!strcmp("none", str))
20453 vsyscall_mode = NONE;
20454 else
20455@@ -207,7 +205,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20456
20457 tsk = current;
20458 if (seccomp_mode(&tsk->seccomp))
20459- do_exit(SIGKILL);
20460+ do_group_exit(SIGKILL);
20461
20462 /*
20463 * With a real vsyscall, page faults cause SIGSEGV. We want to
20464@@ -279,8 +277,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20465 return true;
20466
20467 sigsegv:
20468- force_sig(SIGSEGV, current);
20469- return true;
20470+ do_group_exit(SIGKILL);
20471 }
20472
20473 /*
20474@@ -333,10 +330,7 @@ void __init map_vsyscall(void)
20475 extern char __vvar_page;
20476 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20477
20478- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20479- vsyscall_mode == NATIVE
20480- ? PAGE_KERNEL_VSYSCALL
20481- : PAGE_KERNEL_VVAR);
20482+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20483 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20484 (unsigned long)VSYSCALL_START);
20485
20486diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20487index 9796c2f..f686fbf 100644
20488--- a/arch/x86/kernel/x8664_ksyms_64.c
20489+++ b/arch/x86/kernel/x8664_ksyms_64.c
20490@@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20491 EXPORT_SYMBOL(copy_user_generic_string);
20492 EXPORT_SYMBOL(copy_user_generic_unrolled);
20493 EXPORT_SYMBOL(__copy_user_nocache);
20494-EXPORT_SYMBOL(_copy_from_user);
20495-EXPORT_SYMBOL(_copy_to_user);
20496
20497 EXPORT_SYMBOL(copy_page);
20498 EXPORT_SYMBOL(clear_page);
20499diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20500index 7110911..e8cdee5 100644
20501--- a/arch/x86/kernel/xsave.c
20502+++ b/arch/x86/kernel/xsave.c
20503@@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20504 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20505 return -EINVAL;
20506
20507- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20508+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20509 fx_sw_user->extended_size -
20510 FP_XSTATE_MAGIC2_SIZE));
20511 if (err)
20512@@ -266,7 +266,7 @@ fx_only:
20513 * the other extended state.
20514 */
20515 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20516- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20517+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20518 }
20519
20520 /*
20521@@ -295,7 +295,7 @@ int restore_i387_xstate(void __user *buf)
20522 if (use_xsave())
20523 err = restore_user_xstate(buf);
20524 else
20525- err = fxrstor_checking((__force struct i387_fxsave_struct *)
20526+ err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20527 buf);
20528 if (unlikely(err)) {
20529 /*
20530diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20531index 89b02bf..0f6511d 100644
20532--- a/arch/x86/kvm/cpuid.c
20533+++ b/arch/x86/kvm/cpuid.c
20534@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20535 struct kvm_cpuid2 *cpuid,
20536 struct kvm_cpuid_entry2 __user *entries)
20537 {
20538- int r;
20539+ int r, i;
20540
20541 r = -E2BIG;
20542 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20543 goto out;
20544 r = -EFAULT;
20545- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20546- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20547+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20548 goto out;
20549+ for (i = 0; i < cpuid->nent; ++i) {
20550+ struct kvm_cpuid_entry2 cpuid_entry;
20551+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20552+ goto out;
20553+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
20554+ }
20555 vcpu->arch.cpuid_nent = cpuid->nent;
20556 kvm_apic_set_version(vcpu);
20557 kvm_x86_ops->cpuid_update(vcpu);
20558@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20559 struct kvm_cpuid2 *cpuid,
20560 struct kvm_cpuid_entry2 __user *entries)
20561 {
20562- int r;
20563+ int r, i;
20564
20565 r = -E2BIG;
20566 if (cpuid->nent < vcpu->arch.cpuid_nent)
20567 goto out;
20568 r = -EFAULT;
20569- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20570- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20571+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20572 goto out;
20573+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20574+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20575+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20576+ goto out;
20577+ }
20578 return 0;
20579
20580 out:
20581diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20582index 0982507..7f6d72f 100644
20583--- a/arch/x86/kvm/emulate.c
20584+++ b/arch/x86/kvm/emulate.c
20585@@ -250,6 +250,7 @@ struct gprefix {
20586
20587 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20588 do { \
20589+ unsigned long _tmp; \
20590 __asm__ __volatile__ ( \
20591 _PRE_EFLAGS("0", "4", "2") \
20592 _op _suffix " %"_x"3,%1; " \
20593@@ -264,8 +265,6 @@ struct gprefix {
20594 /* Raw emulation: instruction has two explicit operands. */
20595 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20596 do { \
20597- unsigned long _tmp; \
20598- \
20599 switch ((ctxt)->dst.bytes) { \
20600 case 2: \
20601 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20602@@ -281,7 +280,6 @@ struct gprefix {
20603
20604 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20605 do { \
20606- unsigned long _tmp; \
20607 switch ((ctxt)->dst.bytes) { \
20608 case 1: \
20609 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20610diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20611index cfdc6e0..ab92e84 100644
20612--- a/arch/x86/kvm/lapic.c
20613+++ b/arch/x86/kvm/lapic.c
20614@@ -54,7 +54,7 @@
20615 #define APIC_BUS_CYCLE_NS 1
20616
20617 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20618-#define apic_debug(fmt, arg...)
20619+#define apic_debug(fmt, arg...) do {} while (0)
20620
20621 #define APIC_LVT_NUM 6
20622 /* 14 is the version for Xeon and Pentium 8.4.8*/
20623diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20624index 1561028..0ed7f14 100644
20625--- a/arch/x86/kvm/paging_tmpl.h
20626+++ b/arch/x86/kvm/paging_tmpl.h
20627@@ -197,7 +197,7 @@ retry_walk:
20628 if (unlikely(kvm_is_error_hva(host_addr)))
20629 goto error;
20630
20631- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20632+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20633 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20634 goto error;
20635
20636diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20637index e385214..f8df033 100644
20638--- a/arch/x86/kvm/svm.c
20639+++ b/arch/x86/kvm/svm.c
20640@@ -3420,7 +3420,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20641 int cpu = raw_smp_processor_id();
20642
20643 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20644+
20645+ pax_open_kernel();
20646 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20647+ pax_close_kernel();
20648+
20649 load_TR_desc();
20650 }
20651
20652@@ -3798,6 +3802,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20653 #endif
20654 #endif
20655
20656+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20657+ __set_fs(current_thread_info()->addr_limit);
20658+#endif
20659+
20660 reload_tss(vcpu);
20661
20662 local_irq_disable();
20663diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20664index a7a6f60..04b745a 100644
20665--- a/arch/x86/kvm/vmx.c
20666+++ b/arch/x86/kvm/vmx.c
20667@@ -1306,7 +1306,11 @@ static void reload_tss(void)
20668 struct desc_struct *descs;
20669
20670 descs = (void *)gdt->address;
20671+
20672+ pax_open_kernel();
20673 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20674+ pax_close_kernel();
20675+
20676 load_TR_desc();
20677 }
20678
20679@@ -2637,8 +2641,11 @@ static __init int hardware_setup(void)
20680 if (!cpu_has_vmx_flexpriority())
20681 flexpriority_enabled = 0;
20682
20683- if (!cpu_has_vmx_tpr_shadow())
20684- kvm_x86_ops->update_cr8_intercept = NULL;
20685+ if (!cpu_has_vmx_tpr_shadow()) {
20686+ pax_open_kernel();
20687+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20688+ pax_close_kernel();
20689+ }
20690
20691 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20692 kvm_disable_largepages();
20693@@ -3654,7 +3661,7 @@ static void vmx_set_constant_host_state(void)
20694 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20695
20696 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20697- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20698+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20699
20700 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20701 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20702@@ -6192,6 +6199,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20703 "jmp .Lkvm_vmx_return \n\t"
20704 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20705 ".Lkvm_vmx_return: "
20706+
20707+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20708+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20709+ ".Lkvm_vmx_return2: "
20710+#endif
20711+
20712 /* Save guest registers, load host registers, keep flags */
20713 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20714 "pop %0 \n\t"
20715@@ -6240,6 +6253,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20716 #endif
20717 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20718 [wordsize]"i"(sizeof(ulong))
20719+
20720+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20721+ ,[cs]"i"(__KERNEL_CS)
20722+#endif
20723+
20724 : "cc", "memory"
20725 , R"ax", R"bx", R"di", R"si"
20726 #ifdef CONFIG_X86_64
20727@@ -6268,7 +6286,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20728 }
20729 }
20730
20731- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
20732+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20733+
20734+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20735+ loadsegment(fs, __KERNEL_PERCPU);
20736+#endif
20737+
20738+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20739+ __set_fs(current_thread_info()->addr_limit);
20740+#endif
20741+
20742 vmx->loaded_vmcs->launched = 1;
20743
20744 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20745diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20746index 8d1c6c6..99c2d5f 100644
20747--- a/arch/x86/kvm/x86.c
20748+++ b/arch/x86/kvm/x86.c
20749@@ -1311,8 +1311,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20750 {
20751 struct kvm *kvm = vcpu->kvm;
20752 int lm = is_long_mode(vcpu);
20753- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20754- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20755+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20756+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20757 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20758 : kvm->arch.xen_hvm_config.blob_size_32;
20759 u32 page_num = data & ~PAGE_MASK;
20760@@ -2145,6 +2145,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20761 if (n < msr_list.nmsrs)
20762 goto out;
20763 r = -EFAULT;
20764+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20765+ goto out;
20766 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20767 num_msrs_to_save * sizeof(u32)))
20768 goto out;
20769@@ -2266,7 +2268,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20770 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20771 struct kvm_interrupt *irq)
20772 {
20773- if (irq->irq < 0 || irq->irq >= 256)
20774+ if (irq->irq >= 256)
20775 return -EINVAL;
20776 if (irqchip_in_kernel(vcpu->kvm))
20777 return -ENXIO;
20778@@ -4782,7 +4784,7 @@ static void kvm_set_mmio_spte_mask(void)
20779 kvm_mmu_set_mmio_spte_mask(mask);
20780 }
20781
20782-int kvm_arch_init(void *opaque)
20783+int kvm_arch_init(const void *opaque)
20784 {
20785 int r;
20786 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20787diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20788index 642d880..44e0f3f 100644
20789--- a/arch/x86/lguest/boot.c
20790+++ b/arch/x86/lguest/boot.c
20791@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20792 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20793 * Launcher to reboot us.
20794 */
20795-static void lguest_restart(char *reason)
20796+static __noreturn void lguest_restart(char *reason)
20797 {
20798 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20799+ BUG();
20800 }
20801
20802 /*G:050
20803diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
20804index 042f682..c92afb6 100644
20805--- a/arch/x86/lib/atomic64_32.c
20806+++ b/arch/x86/lib/atomic64_32.c
20807@@ -8,18 +8,30 @@
20808
20809 long long atomic64_read_cx8(long long, const atomic64_t *v);
20810 EXPORT_SYMBOL(atomic64_read_cx8);
20811+long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20812+EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
20813 long long atomic64_set_cx8(long long, const atomic64_t *v);
20814 EXPORT_SYMBOL(atomic64_set_cx8);
20815+long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20816+EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
20817 long long atomic64_xchg_cx8(long long, unsigned high);
20818 EXPORT_SYMBOL(atomic64_xchg_cx8);
20819 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
20820 EXPORT_SYMBOL(atomic64_add_return_cx8);
20821+long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20822+EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
20823 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
20824 EXPORT_SYMBOL(atomic64_sub_return_cx8);
20825+long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20826+EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
20827 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
20828 EXPORT_SYMBOL(atomic64_inc_return_cx8);
20829+long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20830+EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
20831 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
20832 EXPORT_SYMBOL(atomic64_dec_return_cx8);
20833+long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20834+EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
20835 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
20836 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
20837 int atomic64_inc_not_zero_cx8(atomic64_t *v);
20838@@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
20839 #ifndef CONFIG_X86_CMPXCHG64
20840 long long atomic64_read_386(long long, const atomic64_t *v);
20841 EXPORT_SYMBOL(atomic64_read_386);
20842+long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
20843+EXPORT_SYMBOL(atomic64_read_unchecked_386);
20844 long long atomic64_set_386(long long, const atomic64_t *v);
20845 EXPORT_SYMBOL(atomic64_set_386);
20846+long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
20847+EXPORT_SYMBOL(atomic64_set_unchecked_386);
20848 long long atomic64_xchg_386(long long, unsigned high);
20849 EXPORT_SYMBOL(atomic64_xchg_386);
20850 long long atomic64_add_return_386(long long a, atomic64_t *v);
20851 EXPORT_SYMBOL(atomic64_add_return_386);
20852+long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20853+EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
20854 long long atomic64_sub_return_386(long long a, atomic64_t *v);
20855 EXPORT_SYMBOL(atomic64_sub_return_386);
20856+long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20857+EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
20858 long long atomic64_inc_return_386(long long a, atomic64_t *v);
20859 EXPORT_SYMBOL(atomic64_inc_return_386);
20860+long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20861+EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
20862 long long atomic64_dec_return_386(long long a, atomic64_t *v);
20863 EXPORT_SYMBOL(atomic64_dec_return_386);
20864+long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20865+EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
20866 long long atomic64_add_386(long long a, atomic64_t *v);
20867 EXPORT_SYMBOL(atomic64_add_386);
20868+long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
20869+EXPORT_SYMBOL(atomic64_add_unchecked_386);
20870 long long atomic64_sub_386(long long a, atomic64_t *v);
20871 EXPORT_SYMBOL(atomic64_sub_386);
20872+long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
20873+EXPORT_SYMBOL(atomic64_sub_unchecked_386);
20874 long long atomic64_inc_386(long long a, atomic64_t *v);
20875 EXPORT_SYMBOL(atomic64_inc_386);
20876+long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
20877+EXPORT_SYMBOL(atomic64_inc_unchecked_386);
20878 long long atomic64_dec_386(long long a, atomic64_t *v);
20879 EXPORT_SYMBOL(atomic64_dec_386);
20880+long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
20881+EXPORT_SYMBOL(atomic64_dec_unchecked_386);
20882 long long atomic64_dec_if_positive_386(atomic64_t *v);
20883 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
20884 int atomic64_inc_not_zero_386(atomic64_t *v);
20885diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20886index e8e7e0d..56fd1b0 100644
20887--- a/arch/x86/lib/atomic64_386_32.S
20888+++ b/arch/x86/lib/atomic64_386_32.S
20889@@ -48,6 +48,10 @@ BEGIN(read)
20890 movl (v), %eax
20891 movl 4(v), %edx
20892 RET_ENDP
20893+BEGIN(read_unchecked)
20894+ movl (v), %eax
20895+ movl 4(v), %edx
20896+RET_ENDP
20897 #undef v
20898
20899 #define v %esi
20900@@ -55,6 +59,10 @@ BEGIN(set)
20901 movl %ebx, (v)
20902 movl %ecx, 4(v)
20903 RET_ENDP
20904+BEGIN(set_unchecked)
20905+ movl %ebx, (v)
20906+ movl %ecx, 4(v)
20907+RET_ENDP
20908 #undef v
20909
20910 #define v %esi
20911@@ -70,6 +78,20 @@ RET_ENDP
20912 BEGIN(add)
20913 addl %eax, (v)
20914 adcl %edx, 4(v)
20915+
20916+#ifdef CONFIG_PAX_REFCOUNT
20917+ jno 0f
20918+ subl %eax, (v)
20919+ sbbl %edx, 4(v)
20920+ int $4
20921+0:
20922+ _ASM_EXTABLE(0b, 0b)
20923+#endif
20924+
20925+RET_ENDP
20926+BEGIN(add_unchecked)
20927+ addl %eax, (v)
20928+ adcl %edx, 4(v)
20929 RET_ENDP
20930 #undef v
20931
20932@@ -77,6 +99,24 @@ RET_ENDP
20933 BEGIN(add_return)
20934 addl (v), %eax
20935 adcl 4(v), %edx
20936+
20937+#ifdef CONFIG_PAX_REFCOUNT
20938+ into
20939+1234:
20940+ _ASM_EXTABLE(1234b, 2f)
20941+#endif
20942+
20943+ movl %eax, (v)
20944+ movl %edx, 4(v)
20945+
20946+#ifdef CONFIG_PAX_REFCOUNT
20947+2:
20948+#endif
20949+
20950+RET_ENDP
20951+BEGIN(add_return_unchecked)
20952+ addl (v), %eax
20953+ adcl 4(v), %edx
20954 movl %eax, (v)
20955 movl %edx, 4(v)
20956 RET_ENDP
20957@@ -86,6 +126,20 @@ RET_ENDP
20958 BEGIN(sub)
20959 subl %eax, (v)
20960 sbbl %edx, 4(v)
20961+
20962+#ifdef CONFIG_PAX_REFCOUNT
20963+ jno 0f
20964+ addl %eax, (v)
20965+ adcl %edx, 4(v)
20966+ int $4
20967+0:
20968+ _ASM_EXTABLE(0b, 0b)
20969+#endif
20970+
20971+RET_ENDP
20972+BEGIN(sub_unchecked)
20973+ subl %eax, (v)
20974+ sbbl %edx, 4(v)
20975 RET_ENDP
20976 #undef v
20977
20978@@ -96,6 +150,27 @@ BEGIN(sub_return)
20979 sbbl $0, %edx
20980 addl (v), %eax
20981 adcl 4(v), %edx
20982+
20983+#ifdef CONFIG_PAX_REFCOUNT
20984+ into
20985+1234:
20986+ _ASM_EXTABLE(1234b, 2f)
20987+#endif
20988+
20989+ movl %eax, (v)
20990+ movl %edx, 4(v)
20991+
20992+#ifdef CONFIG_PAX_REFCOUNT
20993+2:
20994+#endif
20995+
20996+RET_ENDP
20997+BEGIN(sub_return_unchecked)
20998+ negl %edx
20999+ negl %eax
21000+ sbbl $0, %edx
21001+ addl (v), %eax
21002+ adcl 4(v), %edx
21003 movl %eax, (v)
21004 movl %edx, 4(v)
21005 RET_ENDP
21006@@ -105,6 +180,20 @@ RET_ENDP
21007 BEGIN(inc)
21008 addl $1, (v)
21009 adcl $0, 4(v)
21010+
21011+#ifdef CONFIG_PAX_REFCOUNT
21012+ jno 0f
21013+ subl $1, (v)
21014+ sbbl $0, 4(v)
21015+ int $4
21016+0:
21017+ _ASM_EXTABLE(0b, 0b)
21018+#endif
21019+
21020+RET_ENDP
21021+BEGIN(inc_unchecked)
21022+ addl $1, (v)
21023+ adcl $0, 4(v)
21024 RET_ENDP
21025 #undef v
21026
21027@@ -114,6 +203,26 @@ BEGIN(inc_return)
21028 movl 4(v), %edx
21029 addl $1, %eax
21030 adcl $0, %edx
21031+
21032+#ifdef CONFIG_PAX_REFCOUNT
21033+ into
21034+1234:
21035+ _ASM_EXTABLE(1234b, 2f)
21036+#endif
21037+
21038+ movl %eax, (v)
21039+ movl %edx, 4(v)
21040+
21041+#ifdef CONFIG_PAX_REFCOUNT
21042+2:
21043+#endif
21044+
21045+RET_ENDP
21046+BEGIN(inc_return_unchecked)
21047+ movl (v), %eax
21048+ movl 4(v), %edx
21049+ addl $1, %eax
21050+ adcl $0, %edx
21051 movl %eax, (v)
21052 movl %edx, 4(v)
21053 RET_ENDP
21054@@ -123,6 +232,20 @@ RET_ENDP
21055 BEGIN(dec)
21056 subl $1, (v)
21057 sbbl $0, 4(v)
21058+
21059+#ifdef CONFIG_PAX_REFCOUNT
21060+ jno 0f
21061+ addl $1, (v)
21062+ adcl $0, 4(v)
21063+ int $4
21064+0:
21065+ _ASM_EXTABLE(0b, 0b)
21066+#endif
21067+
21068+RET_ENDP
21069+BEGIN(dec_unchecked)
21070+ subl $1, (v)
21071+ sbbl $0, 4(v)
21072 RET_ENDP
21073 #undef v
21074
21075@@ -132,6 +255,26 @@ BEGIN(dec_return)
21076 movl 4(v), %edx
21077 subl $1, %eax
21078 sbbl $0, %edx
21079+
21080+#ifdef CONFIG_PAX_REFCOUNT
21081+ into
21082+1234:
21083+ _ASM_EXTABLE(1234b, 2f)
21084+#endif
21085+
21086+ movl %eax, (v)
21087+ movl %edx, 4(v)
21088+
21089+#ifdef CONFIG_PAX_REFCOUNT
21090+2:
21091+#endif
21092+
21093+RET_ENDP
21094+BEGIN(dec_return_unchecked)
21095+ movl (v), %eax
21096+ movl 4(v), %edx
21097+ subl $1, %eax
21098+ sbbl $0, %edx
21099 movl %eax, (v)
21100 movl %edx, 4(v)
21101 RET_ENDP
21102@@ -143,6 +286,13 @@ BEGIN(add_unless)
21103 adcl %edx, %edi
21104 addl (v), %eax
21105 adcl 4(v), %edx
21106+
21107+#ifdef CONFIG_PAX_REFCOUNT
21108+ into
21109+1234:
21110+ _ASM_EXTABLE(1234b, 2f)
21111+#endif
21112+
21113 cmpl %eax, %esi
21114 je 3f
21115 1:
21116@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
21117 1:
21118 addl $1, %eax
21119 adcl $0, %edx
21120+
21121+#ifdef CONFIG_PAX_REFCOUNT
21122+ into
21123+1234:
21124+ _ASM_EXTABLE(1234b, 2f)
21125+#endif
21126+
21127 movl %eax, (v)
21128 movl %edx, 4(v)
21129 movl $1, %eax
21130@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
21131 movl 4(v), %edx
21132 subl $1, %eax
21133 sbbl $0, %edx
21134+
21135+#ifdef CONFIG_PAX_REFCOUNT
21136+ into
21137+1234:
21138+ _ASM_EXTABLE(1234b, 1f)
21139+#endif
21140+
21141 js 1f
21142 movl %eax, (v)
21143 movl %edx, 4(v)
21144diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
21145index 391a083..3a2cf39 100644
21146--- a/arch/x86/lib/atomic64_cx8_32.S
21147+++ b/arch/x86/lib/atomic64_cx8_32.S
21148@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
21149 CFI_STARTPROC
21150
21151 read64 %ecx
21152+ pax_force_retaddr
21153 ret
21154 CFI_ENDPROC
21155 ENDPROC(atomic64_read_cx8)
21156
21157+ENTRY(atomic64_read_unchecked_cx8)
21158+ CFI_STARTPROC
21159+
21160+ read64 %ecx
21161+ pax_force_retaddr
21162+ ret
21163+ CFI_ENDPROC
21164+ENDPROC(atomic64_read_unchecked_cx8)
21165+
21166 ENTRY(atomic64_set_cx8)
21167 CFI_STARTPROC
21168
21169@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
21170 cmpxchg8b (%esi)
21171 jne 1b
21172
21173+ pax_force_retaddr
21174 ret
21175 CFI_ENDPROC
21176 ENDPROC(atomic64_set_cx8)
21177
21178+ENTRY(atomic64_set_unchecked_cx8)
21179+ CFI_STARTPROC
21180+
21181+1:
21182+/* we don't need LOCK_PREFIX since aligned 64-bit writes
21183+ * are atomic on 586 and newer */
21184+ cmpxchg8b (%esi)
21185+ jne 1b
21186+
21187+ pax_force_retaddr
21188+ ret
21189+ CFI_ENDPROC
21190+ENDPROC(atomic64_set_unchecked_cx8)
21191+
21192 ENTRY(atomic64_xchg_cx8)
21193 CFI_STARTPROC
21194
21195@@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
21196 cmpxchg8b (%esi)
21197 jne 1b
21198
21199+ pax_force_retaddr
21200 ret
21201 CFI_ENDPROC
21202 ENDPROC(atomic64_xchg_cx8)
21203
21204-.macro addsub_return func ins insc
21205-ENTRY(atomic64_\func\()_return_cx8)
21206+.macro addsub_return func ins insc unchecked=""
21207+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21208 CFI_STARTPROC
21209 SAVE ebp
21210 SAVE ebx
21211@@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21212 movl %edx, %ecx
21213 \ins\()l %esi, %ebx
21214 \insc\()l %edi, %ecx
21215+
21216+.ifb \unchecked
21217+#ifdef CONFIG_PAX_REFCOUNT
21218+ into
21219+2:
21220+ _ASM_EXTABLE(2b, 3f)
21221+#endif
21222+.endif
21223+
21224 LOCK_PREFIX
21225 cmpxchg8b (%ebp)
21226 jne 1b
21227-
21228-10:
21229 movl %ebx, %eax
21230 movl %ecx, %edx
21231+
21232+.ifb \unchecked
21233+#ifdef CONFIG_PAX_REFCOUNT
21234+3:
21235+#endif
21236+.endif
21237+
21238 RESTORE edi
21239 RESTORE esi
21240 RESTORE ebx
21241 RESTORE ebp
21242+ pax_force_retaddr
21243 ret
21244 CFI_ENDPROC
21245-ENDPROC(atomic64_\func\()_return_cx8)
21246+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21247 .endm
21248
21249 addsub_return add add adc
21250 addsub_return sub sub sbb
21251+addsub_return add add adc _unchecked
21252+addsub_return sub sub sbb _unchecked
21253
21254-.macro incdec_return func ins insc
21255-ENTRY(atomic64_\func\()_return_cx8)
21256+.macro incdec_return func ins insc unchecked=""
21257+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21258 CFI_STARTPROC
21259 SAVE ebx
21260
21261@@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21262 movl %edx, %ecx
21263 \ins\()l $1, %ebx
21264 \insc\()l $0, %ecx
21265+
21266+.ifb \unchecked
21267+#ifdef CONFIG_PAX_REFCOUNT
21268+ into
21269+2:
21270+ _ASM_EXTABLE(2b, 3f)
21271+#endif
21272+.endif
21273+
21274 LOCK_PREFIX
21275 cmpxchg8b (%esi)
21276 jne 1b
21277
21278-10:
21279 movl %ebx, %eax
21280 movl %ecx, %edx
21281+
21282+.ifb \unchecked
21283+#ifdef CONFIG_PAX_REFCOUNT
21284+3:
21285+#endif
21286+.endif
21287+
21288 RESTORE ebx
21289+ pax_force_retaddr
21290 ret
21291 CFI_ENDPROC
21292-ENDPROC(atomic64_\func\()_return_cx8)
21293+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21294 .endm
21295
21296 incdec_return inc add adc
21297 incdec_return dec sub sbb
21298+incdec_return inc add adc _unchecked
21299+incdec_return dec sub sbb _unchecked
21300
21301 ENTRY(atomic64_dec_if_positive_cx8)
21302 CFI_STARTPROC
21303@@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21304 movl %edx, %ecx
21305 subl $1, %ebx
21306 sbb $0, %ecx
21307+
21308+#ifdef CONFIG_PAX_REFCOUNT
21309+ into
21310+1234:
21311+ _ASM_EXTABLE(1234b, 2f)
21312+#endif
21313+
21314 js 2f
21315 LOCK_PREFIX
21316 cmpxchg8b (%esi)
21317@@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21318 movl %ebx, %eax
21319 movl %ecx, %edx
21320 RESTORE ebx
21321+ pax_force_retaddr
21322 ret
21323 CFI_ENDPROC
21324 ENDPROC(atomic64_dec_if_positive_cx8)
21325@@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
21326 movl %edx, %ecx
21327 addl %esi, %ebx
21328 adcl %edi, %ecx
21329+
21330+#ifdef CONFIG_PAX_REFCOUNT
21331+ into
21332+1234:
21333+ _ASM_EXTABLE(1234b, 3f)
21334+#endif
21335+
21336 LOCK_PREFIX
21337 cmpxchg8b (%ebp)
21338 jne 1b
21339@@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
21340 CFI_ADJUST_CFA_OFFSET -8
21341 RESTORE ebx
21342 RESTORE ebp
21343+ pax_force_retaddr
21344 ret
21345 4:
21346 cmpl %edx, 4(%esp)
21347@@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21348 movl %edx, %ecx
21349 addl $1, %ebx
21350 adcl $0, %ecx
21351+
21352+#ifdef CONFIG_PAX_REFCOUNT
21353+ into
21354+1234:
21355+ _ASM_EXTABLE(1234b, 3f)
21356+#endif
21357+
21358 LOCK_PREFIX
21359 cmpxchg8b (%esi)
21360 jne 1b
21361@@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21362 movl $1, %eax
21363 3:
21364 RESTORE ebx
21365+ pax_force_retaddr
21366 ret
21367 4:
21368 testl %edx, %edx
21369diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21370index 78d16a5..fbcf666 100644
21371--- a/arch/x86/lib/checksum_32.S
21372+++ b/arch/x86/lib/checksum_32.S
21373@@ -28,7 +28,8 @@
21374 #include <linux/linkage.h>
21375 #include <asm/dwarf2.h>
21376 #include <asm/errno.h>
21377-
21378+#include <asm/segment.h>
21379+
21380 /*
21381 * computes a partial checksum, e.g. for TCP/UDP fragments
21382 */
21383@@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21384
21385 #define ARGBASE 16
21386 #define FP 12
21387-
21388-ENTRY(csum_partial_copy_generic)
21389+
21390+ENTRY(csum_partial_copy_generic_to_user)
21391 CFI_STARTPROC
21392+
21393+#ifdef CONFIG_PAX_MEMORY_UDEREF
21394+ pushl_cfi %gs
21395+ popl_cfi %es
21396+ jmp csum_partial_copy_generic
21397+#endif
21398+
21399+ENTRY(csum_partial_copy_generic_from_user)
21400+
21401+#ifdef CONFIG_PAX_MEMORY_UDEREF
21402+ pushl_cfi %gs
21403+ popl_cfi %ds
21404+#endif
21405+
21406+ENTRY(csum_partial_copy_generic)
21407 subl $4,%esp
21408 CFI_ADJUST_CFA_OFFSET 4
21409 pushl_cfi %edi
21410@@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
21411 jmp 4f
21412 SRC(1: movw (%esi), %bx )
21413 addl $2, %esi
21414-DST( movw %bx, (%edi) )
21415+DST( movw %bx, %es:(%edi) )
21416 addl $2, %edi
21417 addw %bx, %ax
21418 adcl $0, %eax
21419@@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
21420 SRC(1: movl (%esi), %ebx )
21421 SRC( movl 4(%esi), %edx )
21422 adcl %ebx, %eax
21423-DST( movl %ebx, (%edi) )
21424+DST( movl %ebx, %es:(%edi) )
21425 adcl %edx, %eax
21426-DST( movl %edx, 4(%edi) )
21427+DST( movl %edx, %es:4(%edi) )
21428
21429 SRC( movl 8(%esi), %ebx )
21430 SRC( movl 12(%esi), %edx )
21431 adcl %ebx, %eax
21432-DST( movl %ebx, 8(%edi) )
21433+DST( movl %ebx, %es:8(%edi) )
21434 adcl %edx, %eax
21435-DST( movl %edx, 12(%edi) )
21436+DST( movl %edx, %es:12(%edi) )
21437
21438 SRC( movl 16(%esi), %ebx )
21439 SRC( movl 20(%esi), %edx )
21440 adcl %ebx, %eax
21441-DST( movl %ebx, 16(%edi) )
21442+DST( movl %ebx, %es:16(%edi) )
21443 adcl %edx, %eax
21444-DST( movl %edx, 20(%edi) )
21445+DST( movl %edx, %es:20(%edi) )
21446
21447 SRC( movl 24(%esi), %ebx )
21448 SRC( movl 28(%esi), %edx )
21449 adcl %ebx, %eax
21450-DST( movl %ebx, 24(%edi) )
21451+DST( movl %ebx, %es:24(%edi) )
21452 adcl %edx, %eax
21453-DST( movl %edx, 28(%edi) )
21454+DST( movl %edx, %es:28(%edi) )
21455
21456 lea 32(%esi), %esi
21457 lea 32(%edi), %edi
21458@@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
21459 shrl $2, %edx # This clears CF
21460 SRC(3: movl (%esi), %ebx )
21461 adcl %ebx, %eax
21462-DST( movl %ebx, (%edi) )
21463+DST( movl %ebx, %es:(%edi) )
21464 lea 4(%esi), %esi
21465 lea 4(%edi), %edi
21466 dec %edx
21467@@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
21468 jb 5f
21469 SRC( movw (%esi), %cx )
21470 leal 2(%esi), %esi
21471-DST( movw %cx, (%edi) )
21472+DST( movw %cx, %es:(%edi) )
21473 leal 2(%edi), %edi
21474 je 6f
21475 shll $16,%ecx
21476 SRC(5: movb (%esi), %cl )
21477-DST( movb %cl, (%edi) )
21478+DST( movb %cl, %es:(%edi) )
21479 6: addl %ecx, %eax
21480 adcl $0, %eax
21481 7:
21482@@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
21483
21484 6001:
21485 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21486- movl $-EFAULT, (%ebx)
21487+ movl $-EFAULT, %ss:(%ebx)
21488
21489 # zero the complete destination - computing the rest
21490 # is too much work
21491@@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
21492
21493 6002:
21494 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21495- movl $-EFAULT,(%ebx)
21496+ movl $-EFAULT,%ss:(%ebx)
21497 jmp 5000b
21498
21499 .previous
21500
21501+ pushl_cfi %ss
21502+ popl_cfi %ds
21503+ pushl_cfi %ss
21504+ popl_cfi %es
21505 popl_cfi %ebx
21506 CFI_RESTORE ebx
21507 popl_cfi %esi
21508@@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
21509 popl_cfi %ecx # equivalent to addl $4,%esp
21510 ret
21511 CFI_ENDPROC
21512-ENDPROC(csum_partial_copy_generic)
21513+ENDPROC(csum_partial_copy_generic_to_user)
21514
21515 #else
21516
21517 /* Version for PentiumII/PPro */
21518
21519 #define ROUND1(x) \
21520+ nop; nop; nop; \
21521 SRC(movl x(%esi), %ebx ) ; \
21522 addl %ebx, %eax ; \
21523- DST(movl %ebx, x(%edi) ) ;
21524+ DST(movl %ebx, %es:x(%edi)) ;
21525
21526 #define ROUND(x) \
21527+ nop; nop; nop; \
21528 SRC(movl x(%esi), %ebx ) ; \
21529 adcl %ebx, %eax ; \
21530- DST(movl %ebx, x(%edi) ) ;
21531+ DST(movl %ebx, %es:x(%edi)) ;
21532
21533 #define ARGBASE 12
21534-
21535-ENTRY(csum_partial_copy_generic)
21536+
21537+ENTRY(csum_partial_copy_generic_to_user)
21538 CFI_STARTPROC
21539+
21540+#ifdef CONFIG_PAX_MEMORY_UDEREF
21541+ pushl_cfi %gs
21542+ popl_cfi %es
21543+ jmp csum_partial_copy_generic
21544+#endif
21545+
21546+ENTRY(csum_partial_copy_generic_from_user)
21547+
21548+#ifdef CONFIG_PAX_MEMORY_UDEREF
21549+ pushl_cfi %gs
21550+ popl_cfi %ds
21551+#endif
21552+
21553+ENTRY(csum_partial_copy_generic)
21554 pushl_cfi %ebx
21555 CFI_REL_OFFSET ebx, 0
21556 pushl_cfi %edi
21557@@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
21558 subl %ebx, %edi
21559 lea -1(%esi),%edx
21560 andl $-32,%edx
21561- lea 3f(%ebx,%ebx), %ebx
21562+ lea 3f(%ebx,%ebx,2), %ebx
21563 testl %esi, %esi
21564 jmp *%ebx
21565 1: addl $64,%esi
21566@@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
21567 jb 5f
21568 SRC( movw (%esi), %dx )
21569 leal 2(%esi), %esi
21570-DST( movw %dx, (%edi) )
21571+DST( movw %dx, %es:(%edi) )
21572 leal 2(%edi), %edi
21573 je 6f
21574 shll $16,%edx
21575 5:
21576 SRC( movb (%esi), %dl )
21577-DST( movb %dl, (%edi) )
21578+DST( movb %dl, %es:(%edi) )
21579 6: addl %edx, %eax
21580 adcl $0, %eax
21581 7:
21582 .section .fixup, "ax"
21583 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21584- movl $-EFAULT, (%ebx)
21585+ movl $-EFAULT, %ss:(%ebx)
21586 # zero the complete destination (computing the rest is too much work)
21587 movl ARGBASE+8(%esp),%edi # dst
21588 movl ARGBASE+12(%esp),%ecx # len
21589@@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
21590 rep; stosb
21591 jmp 7b
21592 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21593- movl $-EFAULT, (%ebx)
21594+ movl $-EFAULT, %ss:(%ebx)
21595 jmp 7b
21596 .previous
21597
21598+#ifdef CONFIG_PAX_MEMORY_UDEREF
21599+ pushl_cfi %ss
21600+ popl_cfi %ds
21601+ pushl_cfi %ss
21602+ popl_cfi %es
21603+#endif
21604+
21605 popl_cfi %esi
21606 CFI_RESTORE esi
21607 popl_cfi %edi
21608@@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
21609 CFI_RESTORE ebx
21610 ret
21611 CFI_ENDPROC
21612-ENDPROC(csum_partial_copy_generic)
21613+ENDPROC(csum_partial_copy_generic_to_user)
21614
21615 #undef ROUND
21616 #undef ROUND1
21617diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21618index f2145cf..cea889d 100644
21619--- a/arch/x86/lib/clear_page_64.S
21620+++ b/arch/x86/lib/clear_page_64.S
21621@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21622 movl $4096/8,%ecx
21623 xorl %eax,%eax
21624 rep stosq
21625+ pax_force_retaddr
21626 ret
21627 CFI_ENDPROC
21628 ENDPROC(clear_page_c)
21629@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21630 movl $4096,%ecx
21631 xorl %eax,%eax
21632 rep stosb
21633+ pax_force_retaddr
21634 ret
21635 CFI_ENDPROC
21636 ENDPROC(clear_page_c_e)
21637@@ -43,6 +45,7 @@ ENTRY(clear_page)
21638 leaq 64(%rdi),%rdi
21639 jnz .Lloop
21640 nop
21641+ pax_force_retaddr
21642 ret
21643 CFI_ENDPROC
21644 .Lclear_page_end:
21645@@ -58,7 +61,7 @@ ENDPROC(clear_page)
21646
21647 #include <asm/cpufeature.h>
21648
21649- .section .altinstr_replacement,"ax"
21650+ .section .altinstr_replacement,"a"
21651 1: .byte 0xeb /* jmp <disp8> */
21652 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21653 2: .byte 0xeb /* jmp <disp8> */
21654diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21655index 1e572c5..2a162cd 100644
21656--- a/arch/x86/lib/cmpxchg16b_emu.S
21657+++ b/arch/x86/lib/cmpxchg16b_emu.S
21658@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21659
21660 popf
21661 mov $1, %al
21662+ pax_force_retaddr
21663 ret
21664
21665 not_same:
21666 popf
21667 xor %al,%al
21668+ pax_force_retaddr
21669 ret
21670
21671 CFI_ENDPROC
21672diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21673index 01c805b..dccb07f 100644
21674--- a/arch/x86/lib/copy_page_64.S
21675+++ b/arch/x86/lib/copy_page_64.S
21676@@ -9,6 +9,7 @@ copy_page_c:
21677 CFI_STARTPROC
21678 movl $4096/8,%ecx
21679 rep movsq
21680+ pax_force_retaddr
21681 ret
21682 CFI_ENDPROC
21683 ENDPROC(copy_page_c)
21684@@ -39,7 +40,7 @@ ENTRY(copy_page)
21685 movq 16 (%rsi), %rdx
21686 movq 24 (%rsi), %r8
21687 movq 32 (%rsi), %r9
21688- movq 40 (%rsi), %r10
21689+ movq 40 (%rsi), %r13
21690 movq 48 (%rsi), %r11
21691 movq 56 (%rsi), %r12
21692
21693@@ -50,7 +51,7 @@ ENTRY(copy_page)
21694 movq %rdx, 16 (%rdi)
21695 movq %r8, 24 (%rdi)
21696 movq %r9, 32 (%rdi)
21697- movq %r10, 40 (%rdi)
21698+ movq %r13, 40 (%rdi)
21699 movq %r11, 48 (%rdi)
21700 movq %r12, 56 (%rdi)
21701
21702@@ -69,7 +70,7 @@ ENTRY(copy_page)
21703 movq 16 (%rsi), %rdx
21704 movq 24 (%rsi), %r8
21705 movq 32 (%rsi), %r9
21706- movq 40 (%rsi), %r10
21707+ movq 40 (%rsi), %r13
21708 movq 48 (%rsi), %r11
21709 movq 56 (%rsi), %r12
21710
21711@@ -78,7 +79,7 @@ ENTRY(copy_page)
21712 movq %rdx, 16 (%rdi)
21713 movq %r8, 24 (%rdi)
21714 movq %r9, 32 (%rdi)
21715- movq %r10, 40 (%rdi)
21716+ movq %r13, 40 (%rdi)
21717 movq %r11, 48 (%rdi)
21718 movq %r12, 56 (%rdi)
21719
21720@@ -95,6 +96,7 @@ ENTRY(copy_page)
21721 CFI_RESTORE r13
21722 addq $3*8,%rsp
21723 CFI_ADJUST_CFA_OFFSET -3*8
21724+ pax_force_retaddr
21725 ret
21726 .Lcopy_page_end:
21727 CFI_ENDPROC
21728@@ -105,7 +107,7 @@ ENDPROC(copy_page)
21729
21730 #include <asm/cpufeature.h>
21731
21732- .section .altinstr_replacement,"ax"
21733+ .section .altinstr_replacement,"a"
21734 1: .byte 0xeb /* jmp <disp8> */
21735 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21736 2:
21737diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21738index 0248402..821c786 100644
21739--- a/arch/x86/lib/copy_user_64.S
21740+++ b/arch/x86/lib/copy_user_64.S
21741@@ -16,6 +16,7 @@
21742 #include <asm/thread_info.h>
21743 #include <asm/cpufeature.h>
21744 #include <asm/alternative-asm.h>
21745+#include <asm/pgtable.h>
21746
21747 /*
21748 * By placing feature2 after feature1 in altinstructions section, we logically
21749@@ -29,7 +30,7 @@
21750 .byte 0xe9 /* 32bit jump */
21751 .long \orig-1f /* by default jump to orig */
21752 1:
21753- .section .altinstr_replacement,"ax"
21754+ .section .altinstr_replacement,"a"
21755 2: .byte 0xe9 /* near jump with 32bit immediate */
21756 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21757 3: .byte 0xe9 /* near jump with 32bit immediate */
21758@@ -71,47 +72,20 @@
21759 #endif
21760 .endm
21761
21762-/* Standard copy_to_user with segment limit checking */
21763-ENTRY(_copy_to_user)
21764- CFI_STARTPROC
21765- GET_THREAD_INFO(%rax)
21766- movq %rdi,%rcx
21767- addq %rdx,%rcx
21768- jc bad_to_user
21769- cmpq TI_addr_limit(%rax),%rcx
21770- ja bad_to_user
21771- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21772- copy_user_generic_unrolled,copy_user_generic_string, \
21773- copy_user_enhanced_fast_string
21774- CFI_ENDPROC
21775-ENDPROC(_copy_to_user)
21776-
21777-/* Standard copy_from_user with segment limit checking */
21778-ENTRY(_copy_from_user)
21779- CFI_STARTPROC
21780- GET_THREAD_INFO(%rax)
21781- movq %rsi,%rcx
21782- addq %rdx,%rcx
21783- jc bad_from_user
21784- cmpq TI_addr_limit(%rax),%rcx
21785- ja bad_from_user
21786- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21787- copy_user_generic_unrolled,copy_user_generic_string, \
21788- copy_user_enhanced_fast_string
21789- CFI_ENDPROC
21790-ENDPROC(_copy_from_user)
21791-
21792 .section .fixup,"ax"
21793 /* must zero dest */
21794 ENTRY(bad_from_user)
21795 bad_from_user:
21796 CFI_STARTPROC
21797+ testl %edx,%edx
21798+ js bad_to_user
21799 movl %edx,%ecx
21800 xorl %eax,%eax
21801 rep
21802 stosb
21803 bad_to_user:
21804 movl %edx,%eax
21805+ pax_force_retaddr
21806 ret
21807 CFI_ENDPROC
21808 ENDPROC(bad_from_user)
21809@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21810 jz 17f
21811 1: movq (%rsi),%r8
21812 2: movq 1*8(%rsi),%r9
21813-3: movq 2*8(%rsi),%r10
21814+3: movq 2*8(%rsi),%rax
21815 4: movq 3*8(%rsi),%r11
21816 5: movq %r8,(%rdi)
21817 6: movq %r9,1*8(%rdi)
21818-7: movq %r10,2*8(%rdi)
21819+7: movq %rax,2*8(%rdi)
21820 8: movq %r11,3*8(%rdi)
21821 9: movq 4*8(%rsi),%r8
21822 10: movq 5*8(%rsi),%r9
21823-11: movq 6*8(%rsi),%r10
21824+11: movq 6*8(%rsi),%rax
21825 12: movq 7*8(%rsi),%r11
21826 13: movq %r8,4*8(%rdi)
21827 14: movq %r9,5*8(%rdi)
21828-15: movq %r10,6*8(%rdi)
21829+15: movq %rax,6*8(%rdi)
21830 16: movq %r11,7*8(%rdi)
21831 leaq 64(%rsi),%rsi
21832 leaq 64(%rdi),%rdi
21833@@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
21834 decl %ecx
21835 jnz 21b
21836 23: xor %eax,%eax
21837+ pax_force_retaddr
21838 ret
21839
21840 .section .fixup,"ax"
21841@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21842 3: rep
21843 movsb
21844 4: xorl %eax,%eax
21845+ pax_force_retaddr
21846 ret
21847
21848 .section .fixup,"ax"
21849@@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
21850 1: rep
21851 movsb
21852 2: xorl %eax,%eax
21853+ pax_force_retaddr
21854 ret
21855
21856 .section .fixup,"ax"
21857diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21858index cb0c112..e3a6895 100644
21859--- a/arch/x86/lib/copy_user_nocache_64.S
21860+++ b/arch/x86/lib/copy_user_nocache_64.S
21861@@ -8,12 +8,14 @@
21862
21863 #include <linux/linkage.h>
21864 #include <asm/dwarf2.h>
21865+#include <asm/alternative-asm.h>
21866
21867 #define FIX_ALIGNMENT 1
21868
21869 #include <asm/current.h>
21870 #include <asm/asm-offsets.h>
21871 #include <asm/thread_info.h>
21872+#include <asm/pgtable.h>
21873
21874 .macro ALIGN_DESTINATION
21875 #ifdef FIX_ALIGNMENT
21876@@ -50,6 +52,15 @@
21877 */
21878 ENTRY(__copy_user_nocache)
21879 CFI_STARTPROC
21880+
21881+#ifdef CONFIG_PAX_MEMORY_UDEREF
21882+ mov $PAX_USER_SHADOW_BASE,%rcx
21883+ cmp %rcx,%rsi
21884+ jae 1f
21885+ add %rcx,%rsi
21886+1:
21887+#endif
21888+
21889 cmpl $8,%edx
21890 jb 20f /* less then 8 bytes, go to byte copy loop */
21891 ALIGN_DESTINATION
21892@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21893 jz 17f
21894 1: movq (%rsi),%r8
21895 2: movq 1*8(%rsi),%r9
21896-3: movq 2*8(%rsi),%r10
21897+3: movq 2*8(%rsi),%rax
21898 4: movq 3*8(%rsi),%r11
21899 5: movnti %r8,(%rdi)
21900 6: movnti %r9,1*8(%rdi)
21901-7: movnti %r10,2*8(%rdi)
21902+7: movnti %rax,2*8(%rdi)
21903 8: movnti %r11,3*8(%rdi)
21904 9: movq 4*8(%rsi),%r8
21905 10: movq 5*8(%rsi),%r9
21906-11: movq 6*8(%rsi),%r10
21907+11: movq 6*8(%rsi),%rax
21908 12: movq 7*8(%rsi),%r11
21909 13: movnti %r8,4*8(%rdi)
21910 14: movnti %r9,5*8(%rdi)
21911-15: movnti %r10,6*8(%rdi)
21912+15: movnti %rax,6*8(%rdi)
21913 16: movnti %r11,7*8(%rdi)
21914 leaq 64(%rsi),%rsi
21915 leaq 64(%rdi),%rdi
21916@@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21917 jnz 21b
21918 23: xorl %eax,%eax
21919 sfence
21920+ pax_force_retaddr
21921 ret
21922
21923 .section .fixup,"ax"
21924diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21925index fb903b7..c92b7f7 100644
21926--- a/arch/x86/lib/csum-copy_64.S
21927+++ b/arch/x86/lib/csum-copy_64.S
21928@@ -8,6 +8,7 @@
21929 #include <linux/linkage.h>
21930 #include <asm/dwarf2.h>
21931 #include <asm/errno.h>
21932+#include <asm/alternative-asm.h>
21933
21934 /*
21935 * Checksum copy with exception handling.
21936@@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21937 CFI_RESTORE rbp
21938 addq $7*8, %rsp
21939 CFI_ADJUST_CFA_OFFSET -7*8
21940+ pax_force_retaddr 0, 1
21941 ret
21942 CFI_RESTORE_STATE
21943
21944diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21945index 459b58a..9570bc7 100644
21946--- a/arch/x86/lib/csum-wrappers_64.c
21947+++ b/arch/x86/lib/csum-wrappers_64.c
21948@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21949 len -= 2;
21950 }
21951 }
21952- isum = csum_partial_copy_generic((__force const void *)src,
21953+
21954+#ifdef CONFIG_PAX_MEMORY_UDEREF
21955+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21956+ src += PAX_USER_SHADOW_BASE;
21957+#endif
21958+
21959+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
21960 dst, len, isum, errp, NULL);
21961 if (unlikely(*errp))
21962 goto out_err;
21963@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21964 }
21965
21966 *errp = 0;
21967- return csum_partial_copy_generic(src, (void __force *)dst,
21968+
21969+#ifdef CONFIG_PAX_MEMORY_UDEREF
21970+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21971+ dst += PAX_USER_SHADOW_BASE;
21972+#endif
21973+
21974+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21975 len, isum, NULL, errp);
21976 }
21977 EXPORT_SYMBOL(csum_partial_copy_to_user);
21978diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21979index 51f1504..ddac4c1 100644
21980--- a/arch/x86/lib/getuser.S
21981+++ b/arch/x86/lib/getuser.S
21982@@ -33,15 +33,38 @@
21983 #include <asm/asm-offsets.h>
21984 #include <asm/thread_info.h>
21985 #include <asm/asm.h>
21986+#include <asm/segment.h>
21987+#include <asm/pgtable.h>
21988+#include <asm/alternative-asm.h>
21989+
21990+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21991+#define __copyuser_seg gs;
21992+#else
21993+#define __copyuser_seg
21994+#endif
21995
21996 .text
21997 ENTRY(__get_user_1)
21998 CFI_STARTPROC
21999+
22000+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22001 GET_THREAD_INFO(%_ASM_DX)
22002 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22003 jae bad_get_user
22004-1: movzb (%_ASM_AX),%edx
22005+
22006+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22007+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22008+ cmp %_ASM_DX,%_ASM_AX
22009+ jae 1234f
22010+ add %_ASM_DX,%_ASM_AX
22011+1234:
22012+#endif
22013+
22014+#endif
22015+
22016+1: __copyuser_seg movzb (%_ASM_AX),%edx
22017 xor %eax,%eax
22018+ pax_force_retaddr
22019 ret
22020 CFI_ENDPROC
22021 ENDPROC(__get_user_1)
22022@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
22023 ENTRY(__get_user_2)
22024 CFI_STARTPROC
22025 add $1,%_ASM_AX
22026+
22027+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22028 jc bad_get_user
22029 GET_THREAD_INFO(%_ASM_DX)
22030 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22031 jae bad_get_user
22032-2: movzwl -1(%_ASM_AX),%edx
22033+
22034+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22035+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22036+ cmp %_ASM_DX,%_ASM_AX
22037+ jae 1234f
22038+ add %_ASM_DX,%_ASM_AX
22039+1234:
22040+#endif
22041+
22042+#endif
22043+
22044+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
22045 xor %eax,%eax
22046+ pax_force_retaddr
22047 ret
22048 CFI_ENDPROC
22049 ENDPROC(__get_user_2)
22050@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
22051 ENTRY(__get_user_4)
22052 CFI_STARTPROC
22053 add $3,%_ASM_AX
22054+
22055+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22056 jc bad_get_user
22057 GET_THREAD_INFO(%_ASM_DX)
22058 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22059 jae bad_get_user
22060-3: mov -3(%_ASM_AX),%edx
22061+
22062+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22063+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22064+ cmp %_ASM_DX,%_ASM_AX
22065+ jae 1234f
22066+ add %_ASM_DX,%_ASM_AX
22067+1234:
22068+#endif
22069+
22070+#endif
22071+
22072+3: __copyuser_seg mov -3(%_ASM_AX),%edx
22073 xor %eax,%eax
22074+ pax_force_retaddr
22075 ret
22076 CFI_ENDPROC
22077 ENDPROC(__get_user_4)
22078@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
22079 GET_THREAD_INFO(%_ASM_DX)
22080 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22081 jae bad_get_user
22082+
22083+#ifdef CONFIG_PAX_MEMORY_UDEREF
22084+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22085+ cmp %_ASM_DX,%_ASM_AX
22086+ jae 1234f
22087+ add %_ASM_DX,%_ASM_AX
22088+1234:
22089+#endif
22090+
22091 4: movq -7(%_ASM_AX),%_ASM_DX
22092 xor %eax,%eax
22093+ pax_force_retaddr
22094 ret
22095 CFI_ENDPROC
22096 ENDPROC(__get_user_8)
22097@@ -91,6 +152,7 @@ bad_get_user:
22098 CFI_STARTPROC
22099 xor %edx,%edx
22100 mov $(-EFAULT),%_ASM_AX
22101+ pax_force_retaddr
22102 ret
22103 CFI_ENDPROC
22104 END(bad_get_user)
22105diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
22106index 5a1f9f3..ba9f577 100644
22107--- a/arch/x86/lib/insn.c
22108+++ b/arch/x86/lib/insn.c
22109@@ -21,6 +21,11 @@
22110 #include <linux/string.h>
22111 #include <asm/inat.h>
22112 #include <asm/insn.h>
22113+#ifdef __KERNEL__
22114+#include <asm/pgtable_types.h>
22115+#else
22116+#define ktla_ktva(addr) addr
22117+#endif
22118
22119 /* Verify next sizeof(t) bytes can be on the same instruction */
22120 #define validate_next(t, insn, n) \
22121@@ -49,8 +54,8 @@
22122 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
22123 {
22124 memset(insn, 0, sizeof(*insn));
22125- insn->kaddr = kaddr;
22126- insn->next_byte = kaddr;
22127+ insn->kaddr = ktla_ktva(kaddr);
22128+ insn->next_byte = ktla_ktva(kaddr);
22129 insn->x86_64 = x86_64 ? 1 : 0;
22130 insn->opnd_bytes = 4;
22131 if (x86_64)
22132diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22133index 05a95e7..326f2fa 100644
22134--- a/arch/x86/lib/iomap_copy_64.S
22135+++ b/arch/x86/lib/iomap_copy_64.S
22136@@ -17,6 +17,7 @@
22137
22138 #include <linux/linkage.h>
22139 #include <asm/dwarf2.h>
22140+#include <asm/alternative-asm.h>
22141
22142 /*
22143 * override generic version in lib/iomap_copy.c
22144@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22145 CFI_STARTPROC
22146 movl %edx,%ecx
22147 rep movsd
22148+ pax_force_retaddr
22149 ret
22150 CFI_ENDPROC
22151 ENDPROC(__iowrite32_copy)
22152diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22153index efbf2a0..8893637 100644
22154--- a/arch/x86/lib/memcpy_64.S
22155+++ b/arch/x86/lib/memcpy_64.S
22156@@ -34,6 +34,7 @@
22157 rep movsq
22158 movl %edx, %ecx
22159 rep movsb
22160+ pax_force_retaddr
22161 ret
22162 .Lmemcpy_e:
22163 .previous
22164@@ -51,6 +52,7 @@
22165
22166 movl %edx, %ecx
22167 rep movsb
22168+ pax_force_retaddr
22169 ret
22170 .Lmemcpy_e_e:
22171 .previous
22172@@ -81,13 +83,13 @@ ENTRY(memcpy)
22173 */
22174 movq 0*8(%rsi), %r8
22175 movq 1*8(%rsi), %r9
22176- movq 2*8(%rsi), %r10
22177+ movq 2*8(%rsi), %rcx
22178 movq 3*8(%rsi), %r11
22179 leaq 4*8(%rsi), %rsi
22180
22181 movq %r8, 0*8(%rdi)
22182 movq %r9, 1*8(%rdi)
22183- movq %r10, 2*8(%rdi)
22184+ movq %rcx, 2*8(%rdi)
22185 movq %r11, 3*8(%rdi)
22186 leaq 4*8(%rdi), %rdi
22187 jae .Lcopy_forward_loop
22188@@ -110,12 +112,12 @@ ENTRY(memcpy)
22189 subq $0x20, %rdx
22190 movq -1*8(%rsi), %r8
22191 movq -2*8(%rsi), %r9
22192- movq -3*8(%rsi), %r10
22193+ movq -3*8(%rsi), %rcx
22194 movq -4*8(%rsi), %r11
22195 leaq -4*8(%rsi), %rsi
22196 movq %r8, -1*8(%rdi)
22197 movq %r9, -2*8(%rdi)
22198- movq %r10, -3*8(%rdi)
22199+ movq %rcx, -3*8(%rdi)
22200 movq %r11, -4*8(%rdi)
22201 leaq -4*8(%rdi), %rdi
22202 jae .Lcopy_backward_loop
22203@@ -135,12 +137,13 @@ ENTRY(memcpy)
22204 */
22205 movq 0*8(%rsi), %r8
22206 movq 1*8(%rsi), %r9
22207- movq -2*8(%rsi, %rdx), %r10
22208+ movq -2*8(%rsi, %rdx), %rcx
22209 movq -1*8(%rsi, %rdx), %r11
22210 movq %r8, 0*8(%rdi)
22211 movq %r9, 1*8(%rdi)
22212- movq %r10, -2*8(%rdi, %rdx)
22213+ movq %rcx, -2*8(%rdi, %rdx)
22214 movq %r11, -1*8(%rdi, %rdx)
22215+ pax_force_retaddr
22216 retq
22217 .p2align 4
22218 .Lless_16bytes:
22219@@ -153,6 +156,7 @@ ENTRY(memcpy)
22220 movq -1*8(%rsi, %rdx), %r9
22221 movq %r8, 0*8(%rdi)
22222 movq %r9, -1*8(%rdi, %rdx)
22223+ pax_force_retaddr
22224 retq
22225 .p2align 4
22226 .Lless_8bytes:
22227@@ -166,6 +170,7 @@ ENTRY(memcpy)
22228 movl -4(%rsi, %rdx), %r8d
22229 movl %ecx, (%rdi)
22230 movl %r8d, -4(%rdi, %rdx)
22231+ pax_force_retaddr
22232 retq
22233 .p2align 4
22234 .Lless_3bytes:
22235@@ -183,6 +188,7 @@ ENTRY(memcpy)
22236 jnz .Lloop_1
22237
22238 .Lend:
22239+ pax_force_retaddr
22240 retq
22241 CFI_ENDPROC
22242 ENDPROC(memcpy)
22243diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22244index ee16461..c39c199 100644
22245--- a/arch/x86/lib/memmove_64.S
22246+++ b/arch/x86/lib/memmove_64.S
22247@@ -61,13 +61,13 @@ ENTRY(memmove)
22248 5:
22249 sub $0x20, %rdx
22250 movq 0*8(%rsi), %r11
22251- movq 1*8(%rsi), %r10
22252+ movq 1*8(%rsi), %rcx
22253 movq 2*8(%rsi), %r9
22254 movq 3*8(%rsi), %r8
22255 leaq 4*8(%rsi), %rsi
22256
22257 movq %r11, 0*8(%rdi)
22258- movq %r10, 1*8(%rdi)
22259+ movq %rcx, 1*8(%rdi)
22260 movq %r9, 2*8(%rdi)
22261 movq %r8, 3*8(%rdi)
22262 leaq 4*8(%rdi), %rdi
22263@@ -81,10 +81,10 @@ ENTRY(memmove)
22264 4:
22265 movq %rdx, %rcx
22266 movq -8(%rsi, %rdx), %r11
22267- lea -8(%rdi, %rdx), %r10
22268+ lea -8(%rdi, %rdx), %r9
22269 shrq $3, %rcx
22270 rep movsq
22271- movq %r11, (%r10)
22272+ movq %r11, (%r9)
22273 jmp 13f
22274 .Lmemmove_end_forward:
22275
22276@@ -95,14 +95,14 @@ ENTRY(memmove)
22277 7:
22278 movq %rdx, %rcx
22279 movq (%rsi), %r11
22280- movq %rdi, %r10
22281+ movq %rdi, %r9
22282 leaq -8(%rsi, %rdx), %rsi
22283 leaq -8(%rdi, %rdx), %rdi
22284 shrq $3, %rcx
22285 std
22286 rep movsq
22287 cld
22288- movq %r11, (%r10)
22289+ movq %r11, (%r9)
22290 jmp 13f
22291
22292 /*
22293@@ -127,13 +127,13 @@ ENTRY(memmove)
22294 8:
22295 subq $0x20, %rdx
22296 movq -1*8(%rsi), %r11
22297- movq -2*8(%rsi), %r10
22298+ movq -2*8(%rsi), %rcx
22299 movq -3*8(%rsi), %r9
22300 movq -4*8(%rsi), %r8
22301 leaq -4*8(%rsi), %rsi
22302
22303 movq %r11, -1*8(%rdi)
22304- movq %r10, -2*8(%rdi)
22305+ movq %rcx, -2*8(%rdi)
22306 movq %r9, -3*8(%rdi)
22307 movq %r8, -4*8(%rdi)
22308 leaq -4*8(%rdi), %rdi
22309@@ -151,11 +151,11 @@ ENTRY(memmove)
22310 * Move data from 16 bytes to 31 bytes.
22311 */
22312 movq 0*8(%rsi), %r11
22313- movq 1*8(%rsi), %r10
22314+ movq 1*8(%rsi), %rcx
22315 movq -2*8(%rsi, %rdx), %r9
22316 movq -1*8(%rsi, %rdx), %r8
22317 movq %r11, 0*8(%rdi)
22318- movq %r10, 1*8(%rdi)
22319+ movq %rcx, 1*8(%rdi)
22320 movq %r9, -2*8(%rdi, %rdx)
22321 movq %r8, -1*8(%rdi, %rdx)
22322 jmp 13f
22323@@ -167,9 +167,9 @@ ENTRY(memmove)
22324 * Move data from 8 bytes to 15 bytes.
22325 */
22326 movq 0*8(%rsi), %r11
22327- movq -1*8(%rsi, %rdx), %r10
22328+ movq -1*8(%rsi, %rdx), %r9
22329 movq %r11, 0*8(%rdi)
22330- movq %r10, -1*8(%rdi, %rdx)
22331+ movq %r9, -1*8(%rdi, %rdx)
22332 jmp 13f
22333 10:
22334 cmpq $4, %rdx
22335@@ -178,9 +178,9 @@ ENTRY(memmove)
22336 * Move data from 4 bytes to 7 bytes.
22337 */
22338 movl (%rsi), %r11d
22339- movl -4(%rsi, %rdx), %r10d
22340+ movl -4(%rsi, %rdx), %r9d
22341 movl %r11d, (%rdi)
22342- movl %r10d, -4(%rdi, %rdx)
22343+ movl %r9d, -4(%rdi, %rdx)
22344 jmp 13f
22345 11:
22346 cmp $2, %rdx
22347@@ -189,9 +189,9 @@ ENTRY(memmove)
22348 * Move data from 2 bytes to 3 bytes.
22349 */
22350 movw (%rsi), %r11w
22351- movw -2(%rsi, %rdx), %r10w
22352+ movw -2(%rsi, %rdx), %r9w
22353 movw %r11w, (%rdi)
22354- movw %r10w, -2(%rdi, %rdx)
22355+ movw %r9w, -2(%rdi, %rdx)
22356 jmp 13f
22357 12:
22358 cmp $1, %rdx
22359@@ -202,6 +202,7 @@ ENTRY(memmove)
22360 movb (%rsi), %r11b
22361 movb %r11b, (%rdi)
22362 13:
22363+ pax_force_retaddr
22364 retq
22365 CFI_ENDPROC
22366
22367@@ -210,6 +211,7 @@ ENTRY(memmove)
22368 /* Forward moving data. */
22369 movq %rdx, %rcx
22370 rep movsb
22371+ pax_force_retaddr
22372 retq
22373 .Lmemmove_end_forward_efs:
22374 .previous
22375diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22376index 79bd454..dff325a 100644
22377--- a/arch/x86/lib/memset_64.S
22378+++ b/arch/x86/lib/memset_64.S
22379@@ -31,6 +31,7 @@
22380 movl %r8d,%ecx
22381 rep stosb
22382 movq %r9,%rax
22383+ pax_force_retaddr
22384 ret
22385 .Lmemset_e:
22386 .previous
22387@@ -53,6 +54,7 @@
22388 movl %edx,%ecx
22389 rep stosb
22390 movq %r9,%rax
22391+ pax_force_retaddr
22392 ret
22393 .Lmemset_e_e:
22394 .previous
22395@@ -60,13 +62,13 @@
22396 ENTRY(memset)
22397 ENTRY(__memset)
22398 CFI_STARTPROC
22399- movq %rdi,%r10
22400 movq %rdx,%r11
22401
22402 /* expand byte value */
22403 movzbl %sil,%ecx
22404 movabs $0x0101010101010101,%rax
22405 mul %rcx /* with rax, clobbers rdx */
22406+ movq %rdi,%rdx
22407
22408 /* align dst */
22409 movl %edi,%r9d
22410@@ -120,7 +122,8 @@ ENTRY(__memset)
22411 jnz .Lloop_1
22412
22413 .Lende:
22414- movq %r10,%rax
22415+ movq %rdx,%rax
22416+ pax_force_retaddr
22417 ret
22418
22419 CFI_RESTORE_STATE
22420diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22421index c9f2d9b..e7fd2c0 100644
22422--- a/arch/x86/lib/mmx_32.c
22423+++ b/arch/x86/lib/mmx_32.c
22424@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22425 {
22426 void *p;
22427 int i;
22428+ unsigned long cr0;
22429
22430 if (unlikely(in_interrupt()))
22431 return __memcpy(to, from, len);
22432@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22433 kernel_fpu_begin();
22434
22435 __asm__ __volatile__ (
22436- "1: prefetch (%0)\n" /* This set is 28 bytes */
22437- " prefetch 64(%0)\n"
22438- " prefetch 128(%0)\n"
22439- " prefetch 192(%0)\n"
22440- " prefetch 256(%0)\n"
22441+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22442+ " prefetch 64(%1)\n"
22443+ " prefetch 128(%1)\n"
22444+ " prefetch 192(%1)\n"
22445+ " prefetch 256(%1)\n"
22446 "2: \n"
22447 ".section .fixup, \"ax\"\n"
22448- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22449+ "3: \n"
22450+
22451+#ifdef CONFIG_PAX_KERNEXEC
22452+ " movl %%cr0, %0\n"
22453+ " movl %0, %%eax\n"
22454+ " andl $0xFFFEFFFF, %%eax\n"
22455+ " movl %%eax, %%cr0\n"
22456+#endif
22457+
22458+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22459+
22460+#ifdef CONFIG_PAX_KERNEXEC
22461+ " movl %0, %%cr0\n"
22462+#endif
22463+
22464 " jmp 2b\n"
22465 ".previous\n"
22466 _ASM_EXTABLE(1b, 3b)
22467- : : "r" (from));
22468+ : "=&r" (cr0) : "r" (from) : "ax");
22469
22470 for ( ; i > 5; i--) {
22471 __asm__ __volatile__ (
22472- "1: prefetch 320(%0)\n"
22473- "2: movq (%0), %%mm0\n"
22474- " movq 8(%0), %%mm1\n"
22475- " movq 16(%0), %%mm2\n"
22476- " movq 24(%0), %%mm3\n"
22477- " movq %%mm0, (%1)\n"
22478- " movq %%mm1, 8(%1)\n"
22479- " movq %%mm2, 16(%1)\n"
22480- " movq %%mm3, 24(%1)\n"
22481- " movq 32(%0), %%mm0\n"
22482- " movq 40(%0), %%mm1\n"
22483- " movq 48(%0), %%mm2\n"
22484- " movq 56(%0), %%mm3\n"
22485- " movq %%mm0, 32(%1)\n"
22486- " movq %%mm1, 40(%1)\n"
22487- " movq %%mm2, 48(%1)\n"
22488- " movq %%mm3, 56(%1)\n"
22489+ "1: prefetch 320(%1)\n"
22490+ "2: movq (%1), %%mm0\n"
22491+ " movq 8(%1), %%mm1\n"
22492+ " movq 16(%1), %%mm2\n"
22493+ " movq 24(%1), %%mm3\n"
22494+ " movq %%mm0, (%2)\n"
22495+ " movq %%mm1, 8(%2)\n"
22496+ " movq %%mm2, 16(%2)\n"
22497+ " movq %%mm3, 24(%2)\n"
22498+ " movq 32(%1), %%mm0\n"
22499+ " movq 40(%1), %%mm1\n"
22500+ " movq 48(%1), %%mm2\n"
22501+ " movq 56(%1), %%mm3\n"
22502+ " movq %%mm0, 32(%2)\n"
22503+ " movq %%mm1, 40(%2)\n"
22504+ " movq %%mm2, 48(%2)\n"
22505+ " movq %%mm3, 56(%2)\n"
22506 ".section .fixup, \"ax\"\n"
22507- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22508+ "3:\n"
22509+
22510+#ifdef CONFIG_PAX_KERNEXEC
22511+ " movl %%cr0, %0\n"
22512+ " movl %0, %%eax\n"
22513+ " andl $0xFFFEFFFF, %%eax\n"
22514+ " movl %%eax, %%cr0\n"
22515+#endif
22516+
22517+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22518+
22519+#ifdef CONFIG_PAX_KERNEXEC
22520+ " movl %0, %%cr0\n"
22521+#endif
22522+
22523 " jmp 2b\n"
22524 ".previous\n"
22525 _ASM_EXTABLE(1b, 3b)
22526- : : "r" (from), "r" (to) : "memory");
22527+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22528
22529 from += 64;
22530 to += 64;
22531@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22532 static void fast_copy_page(void *to, void *from)
22533 {
22534 int i;
22535+ unsigned long cr0;
22536
22537 kernel_fpu_begin();
22538
22539@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22540 * but that is for later. -AV
22541 */
22542 __asm__ __volatile__(
22543- "1: prefetch (%0)\n"
22544- " prefetch 64(%0)\n"
22545- " prefetch 128(%0)\n"
22546- " prefetch 192(%0)\n"
22547- " prefetch 256(%0)\n"
22548+ "1: prefetch (%1)\n"
22549+ " prefetch 64(%1)\n"
22550+ " prefetch 128(%1)\n"
22551+ " prefetch 192(%1)\n"
22552+ " prefetch 256(%1)\n"
22553 "2: \n"
22554 ".section .fixup, \"ax\"\n"
22555- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22556+ "3: \n"
22557+
22558+#ifdef CONFIG_PAX_KERNEXEC
22559+ " movl %%cr0, %0\n"
22560+ " movl %0, %%eax\n"
22561+ " andl $0xFFFEFFFF, %%eax\n"
22562+ " movl %%eax, %%cr0\n"
22563+#endif
22564+
22565+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22566+
22567+#ifdef CONFIG_PAX_KERNEXEC
22568+ " movl %0, %%cr0\n"
22569+#endif
22570+
22571 " jmp 2b\n"
22572 ".previous\n"
22573- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22574+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22575
22576 for (i = 0; i < (4096-320)/64; i++) {
22577 __asm__ __volatile__ (
22578- "1: prefetch 320(%0)\n"
22579- "2: movq (%0), %%mm0\n"
22580- " movntq %%mm0, (%1)\n"
22581- " movq 8(%0), %%mm1\n"
22582- " movntq %%mm1, 8(%1)\n"
22583- " movq 16(%0), %%mm2\n"
22584- " movntq %%mm2, 16(%1)\n"
22585- " movq 24(%0), %%mm3\n"
22586- " movntq %%mm3, 24(%1)\n"
22587- " movq 32(%0), %%mm4\n"
22588- " movntq %%mm4, 32(%1)\n"
22589- " movq 40(%0), %%mm5\n"
22590- " movntq %%mm5, 40(%1)\n"
22591- " movq 48(%0), %%mm6\n"
22592- " movntq %%mm6, 48(%1)\n"
22593- " movq 56(%0), %%mm7\n"
22594- " movntq %%mm7, 56(%1)\n"
22595+ "1: prefetch 320(%1)\n"
22596+ "2: movq (%1), %%mm0\n"
22597+ " movntq %%mm0, (%2)\n"
22598+ " movq 8(%1), %%mm1\n"
22599+ " movntq %%mm1, 8(%2)\n"
22600+ " movq 16(%1), %%mm2\n"
22601+ " movntq %%mm2, 16(%2)\n"
22602+ " movq 24(%1), %%mm3\n"
22603+ " movntq %%mm3, 24(%2)\n"
22604+ " movq 32(%1), %%mm4\n"
22605+ " movntq %%mm4, 32(%2)\n"
22606+ " movq 40(%1), %%mm5\n"
22607+ " movntq %%mm5, 40(%2)\n"
22608+ " movq 48(%1), %%mm6\n"
22609+ " movntq %%mm6, 48(%2)\n"
22610+ " movq 56(%1), %%mm7\n"
22611+ " movntq %%mm7, 56(%2)\n"
22612 ".section .fixup, \"ax\"\n"
22613- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22614+ "3:\n"
22615+
22616+#ifdef CONFIG_PAX_KERNEXEC
22617+ " movl %%cr0, %0\n"
22618+ " movl %0, %%eax\n"
22619+ " andl $0xFFFEFFFF, %%eax\n"
22620+ " movl %%eax, %%cr0\n"
22621+#endif
22622+
22623+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22624+
22625+#ifdef CONFIG_PAX_KERNEXEC
22626+ " movl %0, %%cr0\n"
22627+#endif
22628+
22629 " jmp 2b\n"
22630 ".previous\n"
22631- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22632+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22633
22634 from += 64;
22635 to += 64;
22636@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22637 static void fast_copy_page(void *to, void *from)
22638 {
22639 int i;
22640+ unsigned long cr0;
22641
22642 kernel_fpu_begin();
22643
22644 __asm__ __volatile__ (
22645- "1: prefetch (%0)\n"
22646- " prefetch 64(%0)\n"
22647- " prefetch 128(%0)\n"
22648- " prefetch 192(%0)\n"
22649- " prefetch 256(%0)\n"
22650+ "1: prefetch (%1)\n"
22651+ " prefetch 64(%1)\n"
22652+ " prefetch 128(%1)\n"
22653+ " prefetch 192(%1)\n"
22654+ " prefetch 256(%1)\n"
22655 "2: \n"
22656 ".section .fixup, \"ax\"\n"
22657- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22658+ "3: \n"
22659+
22660+#ifdef CONFIG_PAX_KERNEXEC
22661+ " movl %%cr0, %0\n"
22662+ " movl %0, %%eax\n"
22663+ " andl $0xFFFEFFFF, %%eax\n"
22664+ " movl %%eax, %%cr0\n"
22665+#endif
22666+
22667+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22668+
22669+#ifdef CONFIG_PAX_KERNEXEC
22670+ " movl %0, %%cr0\n"
22671+#endif
22672+
22673 " jmp 2b\n"
22674 ".previous\n"
22675- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22676+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22677
22678 for (i = 0; i < 4096/64; i++) {
22679 __asm__ __volatile__ (
22680- "1: prefetch 320(%0)\n"
22681- "2: movq (%0), %%mm0\n"
22682- " movq 8(%0), %%mm1\n"
22683- " movq 16(%0), %%mm2\n"
22684- " movq 24(%0), %%mm3\n"
22685- " movq %%mm0, (%1)\n"
22686- " movq %%mm1, 8(%1)\n"
22687- " movq %%mm2, 16(%1)\n"
22688- " movq %%mm3, 24(%1)\n"
22689- " movq 32(%0), %%mm0\n"
22690- " movq 40(%0), %%mm1\n"
22691- " movq 48(%0), %%mm2\n"
22692- " movq 56(%0), %%mm3\n"
22693- " movq %%mm0, 32(%1)\n"
22694- " movq %%mm1, 40(%1)\n"
22695- " movq %%mm2, 48(%1)\n"
22696- " movq %%mm3, 56(%1)\n"
22697+ "1: prefetch 320(%1)\n"
22698+ "2: movq (%1), %%mm0\n"
22699+ " movq 8(%1), %%mm1\n"
22700+ " movq 16(%1), %%mm2\n"
22701+ " movq 24(%1), %%mm3\n"
22702+ " movq %%mm0, (%2)\n"
22703+ " movq %%mm1, 8(%2)\n"
22704+ " movq %%mm2, 16(%2)\n"
22705+ " movq %%mm3, 24(%2)\n"
22706+ " movq 32(%1), %%mm0\n"
22707+ " movq 40(%1), %%mm1\n"
22708+ " movq 48(%1), %%mm2\n"
22709+ " movq 56(%1), %%mm3\n"
22710+ " movq %%mm0, 32(%2)\n"
22711+ " movq %%mm1, 40(%2)\n"
22712+ " movq %%mm2, 48(%2)\n"
22713+ " movq %%mm3, 56(%2)\n"
22714 ".section .fixup, \"ax\"\n"
22715- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22716+ "3:\n"
22717+
22718+#ifdef CONFIG_PAX_KERNEXEC
22719+ " movl %%cr0, %0\n"
22720+ " movl %0, %%eax\n"
22721+ " andl $0xFFFEFFFF, %%eax\n"
22722+ " movl %%eax, %%cr0\n"
22723+#endif
22724+
22725+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22726+
22727+#ifdef CONFIG_PAX_KERNEXEC
22728+ " movl %0, %%cr0\n"
22729+#endif
22730+
22731 " jmp 2b\n"
22732 ".previous\n"
22733 _ASM_EXTABLE(1b, 3b)
22734- : : "r" (from), "r" (to) : "memory");
22735+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22736
22737 from += 64;
22738 to += 64;
22739diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22740index 69fa106..adda88b 100644
22741--- a/arch/x86/lib/msr-reg.S
22742+++ b/arch/x86/lib/msr-reg.S
22743@@ -3,6 +3,7 @@
22744 #include <asm/dwarf2.h>
22745 #include <asm/asm.h>
22746 #include <asm/msr.h>
22747+#include <asm/alternative-asm.h>
22748
22749 #ifdef CONFIG_X86_64
22750 /*
22751@@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22752 CFI_STARTPROC
22753 pushq_cfi %rbx
22754 pushq_cfi %rbp
22755- movq %rdi, %r10 /* Save pointer */
22756+ movq %rdi, %r9 /* Save pointer */
22757 xorl %r11d, %r11d /* Return value */
22758 movl (%rdi), %eax
22759 movl 4(%rdi), %ecx
22760@@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22761 movl 28(%rdi), %edi
22762 CFI_REMEMBER_STATE
22763 1: \op
22764-2: movl %eax, (%r10)
22765+2: movl %eax, (%r9)
22766 movl %r11d, %eax /* Return value */
22767- movl %ecx, 4(%r10)
22768- movl %edx, 8(%r10)
22769- movl %ebx, 12(%r10)
22770- movl %ebp, 20(%r10)
22771- movl %esi, 24(%r10)
22772- movl %edi, 28(%r10)
22773+ movl %ecx, 4(%r9)
22774+ movl %edx, 8(%r9)
22775+ movl %ebx, 12(%r9)
22776+ movl %ebp, 20(%r9)
22777+ movl %esi, 24(%r9)
22778+ movl %edi, 28(%r9)
22779 popq_cfi %rbp
22780 popq_cfi %rbx
22781+ pax_force_retaddr
22782 ret
22783 3:
22784 CFI_RESTORE_STATE
22785diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22786index 36b0d15..d381858 100644
22787--- a/arch/x86/lib/putuser.S
22788+++ b/arch/x86/lib/putuser.S
22789@@ -15,7 +15,9 @@
22790 #include <asm/thread_info.h>
22791 #include <asm/errno.h>
22792 #include <asm/asm.h>
22793-
22794+#include <asm/segment.h>
22795+#include <asm/pgtable.h>
22796+#include <asm/alternative-asm.h>
22797
22798 /*
22799 * __put_user_X
22800@@ -29,52 +31,119 @@
22801 * as they get called from within inline assembly.
22802 */
22803
22804-#define ENTER CFI_STARTPROC ; \
22805- GET_THREAD_INFO(%_ASM_BX)
22806-#define EXIT ret ; \
22807+#define ENTER CFI_STARTPROC
22808+#define EXIT pax_force_retaddr; ret ; \
22809 CFI_ENDPROC
22810
22811+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22812+#define _DEST %_ASM_CX,%_ASM_BX
22813+#else
22814+#define _DEST %_ASM_CX
22815+#endif
22816+
22817+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22818+#define __copyuser_seg gs;
22819+#else
22820+#define __copyuser_seg
22821+#endif
22822+
22823 .text
22824 ENTRY(__put_user_1)
22825 ENTER
22826+
22827+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22828+ GET_THREAD_INFO(%_ASM_BX)
22829 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22830 jae bad_put_user
22831-1: movb %al,(%_ASM_CX)
22832+
22833+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22834+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22835+ cmp %_ASM_BX,%_ASM_CX
22836+ jb 1234f
22837+ xor %ebx,%ebx
22838+1234:
22839+#endif
22840+
22841+#endif
22842+
22843+1: __copyuser_seg movb %al,(_DEST)
22844 xor %eax,%eax
22845 EXIT
22846 ENDPROC(__put_user_1)
22847
22848 ENTRY(__put_user_2)
22849 ENTER
22850+
22851+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22852+ GET_THREAD_INFO(%_ASM_BX)
22853 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22854 sub $1,%_ASM_BX
22855 cmp %_ASM_BX,%_ASM_CX
22856 jae bad_put_user
22857-2: movw %ax,(%_ASM_CX)
22858+
22859+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22860+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22861+ cmp %_ASM_BX,%_ASM_CX
22862+ jb 1234f
22863+ xor %ebx,%ebx
22864+1234:
22865+#endif
22866+
22867+#endif
22868+
22869+2: __copyuser_seg movw %ax,(_DEST)
22870 xor %eax,%eax
22871 EXIT
22872 ENDPROC(__put_user_2)
22873
22874 ENTRY(__put_user_4)
22875 ENTER
22876+
22877+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22878+ GET_THREAD_INFO(%_ASM_BX)
22879 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22880 sub $3,%_ASM_BX
22881 cmp %_ASM_BX,%_ASM_CX
22882 jae bad_put_user
22883-3: movl %eax,(%_ASM_CX)
22884+
22885+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22886+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22887+ cmp %_ASM_BX,%_ASM_CX
22888+ jb 1234f
22889+ xor %ebx,%ebx
22890+1234:
22891+#endif
22892+
22893+#endif
22894+
22895+3: __copyuser_seg movl %eax,(_DEST)
22896 xor %eax,%eax
22897 EXIT
22898 ENDPROC(__put_user_4)
22899
22900 ENTRY(__put_user_8)
22901 ENTER
22902+
22903+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22904+ GET_THREAD_INFO(%_ASM_BX)
22905 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22906 sub $7,%_ASM_BX
22907 cmp %_ASM_BX,%_ASM_CX
22908 jae bad_put_user
22909-4: mov %_ASM_AX,(%_ASM_CX)
22910+
22911+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22912+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22913+ cmp %_ASM_BX,%_ASM_CX
22914+ jb 1234f
22915+ xor %ebx,%ebx
22916+1234:
22917+#endif
22918+
22919+#endif
22920+
22921+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22922 #ifdef CONFIG_X86_32
22923-5: movl %edx,4(%_ASM_CX)
22924+5: __copyuser_seg movl %edx,4(_DEST)
22925 #endif
22926 xor %eax,%eax
22927 EXIT
22928diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22929index 1cad221..de671ee 100644
22930--- a/arch/x86/lib/rwlock.S
22931+++ b/arch/x86/lib/rwlock.S
22932@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22933 FRAME
22934 0: LOCK_PREFIX
22935 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22936+
22937+#ifdef CONFIG_PAX_REFCOUNT
22938+ jno 1234f
22939+ LOCK_PREFIX
22940+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22941+ int $4
22942+1234:
22943+ _ASM_EXTABLE(1234b, 1234b)
22944+#endif
22945+
22946 1: rep; nop
22947 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22948 jne 1b
22949 LOCK_PREFIX
22950 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22951+
22952+#ifdef CONFIG_PAX_REFCOUNT
22953+ jno 1234f
22954+ LOCK_PREFIX
22955+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22956+ int $4
22957+1234:
22958+ _ASM_EXTABLE(1234b, 1234b)
22959+#endif
22960+
22961 jnz 0b
22962 ENDFRAME
22963+ pax_force_retaddr
22964 ret
22965 CFI_ENDPROC
22966 END(__write_lock_failed)
22967@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22968 FRAME
22969 0: LOCK_PREFIX
22970 READ_LOCK_SIZE(inc) (%__lock_ptr)
22971+
22972+#ifdef CONFIG_PAX_REFCOUNT
22973+ jno 1234f
22974+ LOCK_PREFIX
22975+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22976+ int $4
22977+1234:
22978+ _ASM_EXTABLE(1234b, 1234b)
22979+#endif
22980+
22981 1: rep; nop
22982 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22983 js 1b
22984 LOCK_PREFIX
22985 READ_LOCK_SIZE(dec) (%__lock_ptr)
22986+
22987+#ifdef CONFIG_PAX_REFCOUNT
22988+ jno 1234f
22989+ LOCK_PREFIX
22990+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22991+ int $4
22992+1234:
22993+ _ASM_EXTABLE(1234b, 1234b)
22994+#endif
22995+
22996 js 0b
22997 ENDFRAME
22998+ pax_force_retaddr
22999 ret
23000 CFI_ENDPROC
23001 END(__read_lock_failed)
23002diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
23003index 5dff5f0..cadebf4 100644
23004--- a/arch/x86/lib/rwsem.S
23005+++ b/arch/x86/lib/rwsem.S
23006@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
23007 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
23008 CFI_RESTORE __ASM_REG(dx)
23009 restore_common_regs
23010+ pax_force_retaddr
23011 ret
23012 CFI_ENDPROC
23013 ENDPROC(call_rwsem_down_read_failed)
23014@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
23015 movq %rax,%rdi
23016 call rwsem_down_write_failed
23017 restore_common_regs
23018+ pax_force_retaddr
23019 ret
23020 CFI_ENDPROC
23021 ENDPROC(call_rwsem_down_write_failed)
23022@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
23023 movq %rax,%rdi
23024 call rwsem_wake
23025 restore_common_regs
23026-1: ret
23027+1: pax_force_retaddr
23028+ ret
23029 CFI_ENDPROC
23030 ENDPROC(call_rwsem_wake)
23031
23032@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
23033 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
23034 CFI_RESTORE __ASM_REG(dx)
23035 restore_common_regs
23036+ pax_force_retaddr
23037 ret
23038 CFI_ENDPROC
23039 ENDPROC(call_rwsem_downgrade_wake)
23040diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
23041index a63efd6..ccecad8 100644
23042--- a/arch/x86/lib/thunk_64.S
23043+++ b/arch/x86/lib/thunk_64.S
23044@@ -8,6 +8,7 @@
23045 #include <linux/linkage.h>
23046 #include <asm/dwarf2.h>
23047 #include <asm/calling.h>
23048+#include <asm/alternative-asm.h>
23049
23050 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
23051 .macro THUNK name, func, put_ret_addr_in_rdi=0
23052@@ -41,5 +42,6 @@
23053 SAVE_ARGS
23054 restore:
23055 RESTORE_ARGS
23056+ pax_force_retaddr
23057 ret
23058 CFI_ENDPROC
23059diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
23060index e218d5d..a99a1eb 100644
23061--- a/arch/x86/lib/usercopy_32.c
23062+++ b/arch/x86/lib/usercopy_32.c
23063@@ -43,7 +43,7 @@ do { \
23064 __asm__ __volatile__( \
23065 " testl %1,%1\n" \
23066 " jz 2f\n" \
23067- "0: lodsb\n" \
23068+ "0: "__copyuser_seg"lodsb\n" \
23069 " stosb\n" \
23070 " testb %%al,%%al\n" \
23071 " jz 1f\n" \
23072@@ -128,10 +128,12 @@ do { \
23073 int __d0; \
23074 might_fault(); \
23075 __asm__ __volatile__( \
23076+ __COPYUSER_SET_ES \
23077 "0: rep; stosl\n" \
23078 " movl %2,%0\n" \
23079 "1: rep; stosb\n" \
23080 "2:\n" \
23081+ __COPYUSER_RESTORE_ES \
23082 ".section .fixup,\"ax\"\n" \
23083 "3: lea 0(%2,%0,4),%0\n" \
23084 " jmp 2b\n" \
23085@@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
23086 might_fault();
23087
23088 __asm__ __volatile__(
23089+ __COPYUSER_SET_ES
23090 " testl %0, %0\n"
23091 " jz 3f\n"
23092 " andl %0,%%ecx\n"
23093@@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
23094 " subl %%ecx,%0\n"
23095 " addl %0,%%eax\n"
23096 "1:\n"
23097+ __COPYUSER_RESTORE_ES
23098 ".section .fixup,\"ax\"\n"
23099 "2: xorl %%eax,%%eax\n"
23100 " jmp 1b\n"
23101@@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
23102
23103 #ifdef CONFIG_X86_INTEL_USERCOPY
23104 static unsigned long
23105-__copy_user_intel(void __user *to, const void *from, unsigned long size)
23106+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
23107 {
23108 int d0, d1;
23109 __asm__ __volatile__(
23110@@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23111 " .align 2,0x90\n"
23112 "3: movl 0(%4), %%eax\n"
23113 "4: movl 4(%4), %%edx\n"
23114- "5: movl %%eax, 0(%3)\n"
23115- "6: movl %%edx, 4(%3)\n"
23116+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
23117+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
23118 "7: movl 8(%4), %%eax\n"
23119 "8: movl 12(%4),%%edx\n"
23120- "9: movl %%eax, 8(%3)\n"
23121- "10: movl %%edx, 12(%3)\n"
23122+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
23123+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
23124 "11: movl 16(%4), %%eax\n"
23125 "12: movl 20(%4), %%edx\n"
23126- "13: movl %%eax, 16(%3)\n"
23127- "14: movl %%edx, 20(%3)\n"
23128+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
23129+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
23130 "15: movl 24(%4), %%eax\n"
23131 "16: movl 28(%4), %%edx\n"
23132- "17: movl %%eax, 24(%3)\n"
23133- "18: movl %%edx, 28(%3)\n"
23134+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
23135+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
23136 "19: movl 32(%4), %%eax\n"
23137 "20: movl 36(%4), %%edx\n"
23138- "21: movl %%eax, 32(%3)\n"
23139- "22: movl %%edx, 36(%3)\n"
23140+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
23141+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
23142 "23: movl 40(%4), %%eax\n"
23143 "24: movl 44(%4), %%edx\n"
23144- "25: movl %%eax, 40(%3)\n"
23145- "26: movl %%edx, 44(%3)\n"
23146+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
23147+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
23148 "27: movl 48(%4), %%eax\n"
23149 "28: movl 52(%4), %%edx\n"
23150- "29: movl %%eax, 48(%3)\n"
23151- "30: movl %%edx, 52(%3)\n"
23152+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23153+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23154 "31: movl 56(%4), %%eax\n"
23155 "32: movl 60(%4), %%edx\n"
23156- "33: movl %%eax, 56(%3)\n"
23157- "34: movl %%edx, 60(%3)\n"
23158+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23159+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23160 " addl $-64, %0\n"
23161 " addl $64, %4\n"
23162 " addl $64, %3\n"
23163@@ -278,10 +282,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23164 " shrl $2, %0\n"
23165 " andl $3, %%eax\n"
23166 " cld\n"
23167+ __COPYUSER_SET_ES
23168 "99: rep; movsl\n"
23169 "36: movl %%eax, %0\n"
23170 "37: rep; movsb\n"
23171 "100:\n"
23172+ __COPYUSER_RESTORE_ES
23173 ".section .fixup,\"ax\"\n"
23174 "101: lea 0(%%eax,%0,4),%0\n"
23175 " jmp 100b\n"
23176@@ -334,46 +340,155 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23177 }
23178
23179 static unsigned long
23180+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23181+{
23182+ int d0, d1;
23183+ __asm__ __volatile__(
23184+ " .align 2,0x90\n"
23185+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23186+ " cmpl $67, %0\n"
23187+ " jbe 3f\n"
23188+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23189+ " .align 2,0x90\n"
23190+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23191+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23192+ "5: movl %%eax, 0(%3)\n"
23193+ "6: movl %%edx, 4(%3)\n"
23194+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23195+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23196+ "9: movl %%eax, 8(%3)\n"
23197+ "10: movl %%edx, 12(%3)\n"
23198+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23199+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23200+ "13: movl %%eax, 16(%3)\n"
23201+ "14: movl %%edx, 20(%3)\n"
23202+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23203+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23204+ "17: movl %%eax, 24(%3)\n"
23205+ "18: movl %%edx, 28(%3)\n"
23206+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23207+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23208+ "21: movl %%eax, 32(%3)\n"
23209+ "22: movl %%edx, 36(%3)\n"
23210+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23211+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23212+ "25: movl %%eax, 40(%3)\n"
23213+ "26: movl %%edx, 44(%3)\n"
23214+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23215+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23216+ "29: movl %%eax, 48(%3)\n"
23217+ "30: movl %%edx, 52(%3)\n"
23218+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23219+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23220+ "33: movl %%eax, 56(%3)\n"
23221+ "34: movl %%edx, 60(%3)\n"
23222+ " addl $-64, %0\n"
23223+ " addl $64, %4\n"
23224+ " addl $64, %3\n"
23225+ " cmpl $63, %0\n"
23226+ " ja 1b\n"
23227+ "35: movl %0, %%eax\n"
23228+ " shrl $2, %0\n"
23229+ " andl $3, %%eax\n"
23230+ " cld\n"
23231+ "99: rep; "__copyuser_seg" movsl\n"
23232+ "36: movl %%eax, %0\n"
23233+ "37: rep; "__copyuser_seg" movsb\n"
23234+ "100:\n"
23235+ ".section .fixup,\"ax\"\n"
23236+ "101: lea 0(%%eax,%0,4),%0\n"
23237+ " jmp 100b\n"
23238+ ".previous\n"
23239+ ".section __ex_table,\"a\"\n"
23240+ " .align 4\n"
23241+ " .long 1b,100b\n"
23242+ " .long 2b,100b\n"
23243+ " .long 3b,100b\n"
23244+ " .long 4b,100b\n"
23245+ " .long 5b,100b\n"
23246+ " .long 6b,100b\n"
23247+ " .long 7b,100b\n"
23248+ " .long 8b,100b\n"
23249+ " .long 9b,100b\n"
23250+ " .long 10b,100b\n"
23251+ " .long 11b,100b\n"
23252+ " .long 12b,100b\n"
23253+ " .long 13b,100b\n"
23254+ " .long 14b,100b\n"
23255+ " .long 15b,100b\n"
23256+ " .long 16b,100b\n"
23257+ " .long 17b,100b\n"
23258+ " .long 18b,100b\n"
23259+ " .long 19b,100b\n"
23260+ " .long 20b,100b\n"
23261+ " .long 21b,100b\n"
23262+ " .long 22b,100b\n"
23263+ " .long 23b,100b\n"
23264+ " .long 24b,100b\n"
23265+ " .long 25b,100b\n"
23266+ " .long 26b,100b\n"
23267+ " .long 27b,100b\n"
23268+ " .long 28b,100b\n"
23269+ " .long 29b,100b\n"
23270+ " .long 30b,100b\n"
23271+ " .long 31b,100b\n"
23272+ " .long 32b,100b\n"
23273+ " .long 33b,100b\n"
23274+ " .long 34b,100b\n"
23275+ " .long 35b,100b\n"
23276+ " .long 36b,100b\n"
23277+ " .long 37b,100b\n"
23278+ " .long 99b,101b\n"
23279+ ".previous"
23280+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
23281+ : "1"(to), "2"(from), "0"(size)
23282+ : "eax", "edx", "memory");
23283+ return size;
23284+}
23285+
23286+static unsigned long
23287+__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
23288+static unsigned long
23289 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23290 {
23291 int d0, d1;
23292 __asm__ __volatile__(
23293 " .align 2,0x90\n"
23294- "0: movl 32(%4), %%eax\n"
23295+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23296 " cmpl $67, %0\n"
23297 " jbe 2f\n"
23298- "1: movl 64(%4), %%eax\n"
23299+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23300 " .align 2,0x90\n"
23301- "2: movl 0(%4), %%eax\n"
23302- "21: movl 4(%4), %%edx\n"
23303+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23304+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23305 " movl %%eax, 0(%3)\n"
23306 " movl %%edx, 4(%3)\n"
23307- "3: movl 8(%4), %%eax\n"
23308- "31: movl 12(%4),%%edx\n"
23309+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23310+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23311 " movl %%eax, 8(%3)\n"
23312 " movl %%edx, 12(%3)\n"
23313- "4: movl 16(%4), %%eax\n"
23314- "41: movl 20(%4), %%edx\n"
23315+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23316+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23317 " movl %%eax, 16(%3)\n"
23318 " movl %%edx, 20(%3)\n"
23319- "10: movl 24(%4), %%eax\n"
23320- "51: movl 28(%4), %%edx\n"
23321+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23322+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23323 " movl %%eax, 24(%3)\n"
23324 " movl %%edx, 28(%3)\n"
23325- "11: movl 32(%4), %%eax\n"
23326- "61: movl 36(%4), %%edx\n"
23327+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23328+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23329 " movl %%eax, 32(%3)\n"
23330 " movl %%edx, 36(%3)\n"
23331- "12: movl 40(%4), %%eax\n"
23332- "71: movl 44(%4), %%edx\n"
23333+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23334+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23335 " movl %%eax, 40(%3)\n"
23336 " movl %%edx, 44(%3)\n"
23337- "13: movl 48(%4), %%eax\n"
23338- "81: movl 52(%4), %%edx\n"
23339+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23340+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23341 " movl %%eax, 48(%3)\n"
23342 " movl %%edx, 52(%3)\n"
23343- "14: movl 56(%4), %%eax\n"
23344- "91: movl 60(%4), %%edx\n"
23345+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23346+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23347 " movl %%eax, 56(%3)\n"
23348 " movl %%edx, 60(%3)\n"
23349 " addl $-64, %0\n"
23350@@ -385,9 +500,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23351 " shrl $2, %0\n"
23352 " andl $3, %%eax\n"
23353 " cld\n"
23354- "6: rep; movsl\n"
23355+ "6: rep; "__copyuser_seg" movsl\n"
23356 " movl %%eax,%0\n"
23357- "7: rep; movsb\n"
23358+ "7: rep; "__copyuser_seg" movsb\n"
23359 "8:\n"
23360 ".section .fixup,\"ax\"\n"
23361 "9: lea 0(%%eax,%0,4),%0\n"
23362@@ -434,47 +549,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23363 */
23364
23365 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23366+ const void __user *from, unsigned long size) __size_overflow(3);
23367+static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23368 const void __user *from, unsigned long size)
23369 {
23370 int d0, d1;
23371
23372 __asm__ __volatile__(
23373 " .align 2,0x90\n"
23374- "0: movl 32(%4), %%eax\n"
23375+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23376 " cmpl $67, %0\n"
23377 " jbe 2f\n"
23378- "1: movl 64(%4), %%eax\n"
23379+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23380 " .align 2,0x90\n"
23381- "2: movl 0(%4), %%eax\n"
23382- "21: movl 4(%4), %%edx\n"
23383+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23384+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23385 " movnti %%eax, 0(%3)\n"
23386 " movnti %%edx, 4(%3)\n"
23387- "3: movl 8(%4), %%eax\n"
23388- "31: movl 12(%4),%%edx\n"
23389+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23390+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23391 " movnti %%eax, 8(%3)\n"
23392 " movnti %%edx, 12(%3)\n"
23393- "4: movl 16(%4), %%eax\n"
23394- "41: movl 20(%4), %%edx\n"
23395+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23396+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23397 " movnti %%eax, 16(%3)\n"
23398 " movnti %%edx, 20(%3)\n"
23399- "10: movl 24(%4), %%eax\n"
23400- "51: movl 28(%4), %%edx\n"
23401+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23402+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23403 " movnti %%eax, 24(%3)\n"
23404 " movnti %%edx, 28(%3)\n"
23405- "11: movl 32(%4), %%eax\n"
23406- "61: movl 36(%4), %%edx\n"
23407+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23408+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23409 " movnti %%eax, 32(%3)\n"
23410 " movnti %%edx, 36(%3)\n"
23411- "12: movl 40(%4), %%eax\n"
23412- "71: movl 44(%4), %%edx\n"
23413+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23414+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23415 " movnti %%eax, 40(%3)\n"
23416 " movnti %%edx, 44(%3)\n"
23417- "13: movl 48(%4), %%eax\n"
23418- "81: movl 52(%4), %%edx\n"
23419+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23420+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23421 " movnti %%eax, 48(%3)\n"
23422 " movnti %%edx, 52(%3)\n"
23423- "14: movl 56(%4), %%eax\n"
23424- "91: movl 60(%4), %%edx\n"
23425+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23426+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23427 " movnti %%eax, 56(%3)\n"
23428 " movnti %%edx, 60(%3)\n"
23429 " addl $-64, %0\n"
23430@@ -487,9 +604,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23431 " shrl $2, %0\n"
23432 " andl $3, %%eax\n"
23433 " cld\n"
23434- "6: rep; movsl\n"
23435+ "6: rep; "__copyuser_seg" movsl\n"
23436 " movl %%eax,%0\n"
23437- "7: rep; movsb\n"
23438+ "7: rep; "__copyuser_seg" movsb\n"
23439 "8:\n"
23440 ".section .fixup,\"ax\"\n"
23441 "9: lea 0(%%eax,%0,4),%0\n"
23442@@ -531,47 +648,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23443 }
23444
23445 static unsigned long __copy_user_intel_nocache(void *to,
23446+ const void __user *from, unsigned long size) __size_overflow(3);
23447+static unsigned long __copy_user_intel_nocache(void *to,
23448 const void __user *from, unsigned long size)
23449 {
23450 int d0, d1;
23451
23452 __asm__ __volatile__(
23453 " .align 2,0x90\n"
23454- "0: movl 32(%4), %%eax\n"
23455+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23456 " cmpl $67, %0\n"
23457 " jbe 2f\n"
23458- "1: movl 64(%4), %%eax\n"
23459+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23460 " .align 2,0x90\n"
23461- "2: movl 0(%4), %%eax\n"
23462- "21: movl 4(%4), %%edx\n"
23463+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23464+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23465 " movnti %%eax, 0(%3)\n"
23466 " movnti %%edx, 4(%3)\n"
23467- "3: movl 8(%4), %%eax\n"
23468- "31: movl 12(%4),%%edx\n"
23469+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23470+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23471 " movnti %%eax, 8(%3)\n"
23472 " movnti %%edx, 12(%3)\n"
23473- "4: movl 16(%4), %%eax\n"
23474- "41: movl 20(%4), %%edx\n"
23475+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23476+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23477 " movnti %%eax, 16(%3)\n"
23478 " movnti %%edx, 20(%3)\n"
23479- "10: movl 24(%4), %%eax\n"
23480- "51: movl 28(%4), %%edx\n"
23481+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23482+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23483 " movnti %%eax, 24(%3)\n"
23484 " movnti %%edx, 28(%3)\n"
23485- "11: movl 32(%4), %%eax\n"
23486- "61: movl 36(%4), %%edx\n"
23487+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23488+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23489 " movnti %%eax, 32(%3)\n"
23490 " movnti %%edx, 36(%3)\n"
23491- "12: movl 40(%4), %%eax\n"
23492- "71: movl 44(%4), %%edx\n"
23493+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23494+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23495 " movnti %%eax, 40(%3)\n"
23496 " movnti %%edx, 44(%3)\n"
23497- "13: movl 48(%4), %%eax\n"
23498- "81: movl 52(%4), %%edx\n"
23499+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23500+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23501 " movnti %%eax, 48(%3)\n"
23502 " movnti %%edx, 52(%3)\n"
23503- "14: movl 56(%4), %%eax\n"
23504- "91: movl 60(%4), %%edx\n"
23505+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23506+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23507 " movnti %%eax, 56(%3)\n"
23508 " movnti %%edx, 60(%3)\n"
23509 " addl $-64, %0\n"
23510@@ -584,9 +703,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23511 " shrl $2, %0\n"
23512 " andl $3, %%eax\n"
23513 " cld\n"
23514- "6: rep; movsl\n"
23515+ "6: rep; "__copyuser_seg" movsl\n"
23516 " movl %%eax,%0\n"
23517- "7: rep; movsb\n"
23518+ "7: rep; "__copyuser_seg" movsb\n"
23519 "8:\n"
23520 ".section .fixup,\"ax\"\n"
23521 "9: lea 0(%%eax,%0,4),%0\n"
23522@@ -629,32 +748,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23523 */
23524 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23525 unsigned long size);
23526-unsigned long __copy_user_intel(void __user *to, const void *from,
23527+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23528+ unsigned long size);
23529+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23530 unsigned long size);
23531 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23532 const void __user *from, unsigned long size);
23533 #endif /* CONFIG_X86_INTEL_USERCOPY */
23534
23535 /* Generic arbitrary sized copy. */
23536-#define __copy_user(to, from, size) \
23537+#define __copy_user(to, from, size, prefix, set, restore) \
23538 do { \
23539 int __d0, __d1, __d2; \
23540 __asm__ __volatile__( \
23541+ set \
23542 " cmp $7,%0\n" \
23543 " jbe 1f\n" \
23544 " movl %1,%0\n" \
23545 " negl %0\n" \
23546 " andl $7,%0\n" \
23547 " subl %0,%3\n" \
23548- "4: rep; movsb\n" \
23549+ "4: rep; "prefix"movsb\n" \
23550 " movl %3,%0\n" \
23551 " shrl $2,%0\n" \
23552 " andl $3,%3\n" \
23553 " .align 2,0x90\n" \
23554- "0: rep; movsl\n" \
23555+ "0: rep; "prefix"movsl\n" \
23556 " movl %3,%0\n" \
23557- "1: rep; movsb\n" \
23558+ "1: rep; "prefix"movsb\n" \
23559 "2:\n" \
23560+ restore \
23561 ".section .fixup,\"ax\"\n" \
23562 "5: addl %3,%0\n" \
23563 " jmp 2b\n" \
23564@@ -682,14 +805,14 @@ do { \
23565 " negl %0\n" \
23566 " andl $7,%0\n" \
23567 " subl %0,%3\n" \
23568- "4: rep; movsb\n" \
23569+ "4: rep; "__copyuser_seg"movsb\n" \
23570 " movl %3,%0\n" \
23571 " shrl $2,%0\n" \
23572 " andl $3,%3\n" \
23573 " .align 2,0x90\n" \
23574- "0: rep; movsl\n" \
23575+ "0: rep; "__copyuser_seg"movsl\n" \
23576 " movl %3,%0\n" \
23577- "1: rep; movsb\n" \
23578+ "1: rep; "__copyuser_seg"movsb\n" \
23579 "2:\n" \
23580 ".section .fixup,\"ax\"\n" \
23581 "5: addl %3,%0\n" \
23582@@ -775,9 +898,9 @@ survive:
23583 }
23584 #endif
23585 if (movsl_is_ok(to, from, n))
23586- __copy_user(to, from, n);
23587+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23588 else
23589- n = __copy_user_intel(to, from, n);
23590+ n = __generic_copy_to_user_intel(to, from, n);
23591 return n;
23592 }
23593 EXPORT_SYMBOL(__copy_to_user_ll);
23594@@ -797,10 +920,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23595 unsigned long n)
23596 {
23597 if (movsl_is_ok(to, from, n))
23598- __copy_user(to, from, n);
23599+ __copy_user(to, from, n, __copyuser_seg, "", "");
23600 else
23601- n = __copy_user_intel((void __user *)to,
23602- (const void *)from, n);
23603+ n = __generic_copy_from_user_intel(to, from, n);
23604 return n;
23605 }
23606 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23607@@ -827,65 +949,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23608 if (n > 64 && cpu_has_xmm2)
23609 n = __copy_user_intel_nocache(to, from, n);
23610 else
23611- __copy_user(to, from, n);
23612+ __copy_user(to, from, n, __copyuser_seg, "", "");
23613 #else
23614- __copy_user(to, from, n);
23615+ __copy_user(to, from, n, __copyuser_seg, "", "");
23616 #endif
23617 return n;
23618 }
23619 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23620
23621-/**
23622- * copy_to_user: - Copy a block of data into user space.
23623- * @to: Destination address, in user space.
23624- * @from: Source address, in kernel space.
23625- * @n: Number of bytes to copy.
23626- *
23627- * Context: User context only. This function may sleep.
23628- *
23629- * Copy data from kernel space to user space.
23630- *
23631- * Returns number of bytes that could not be copied.
23632- * On success, this will be zero.
23633- */
23634-unsigned long
23635-copy_to_user(void __user *to, const void *from, unsigned long n)
23636-{
23637- if (access_ok(VERIFY_WRITE, to, n))
23638- n = __copy_to_user(to, from, n);
23639- return n;
23640-}
23641-EXPORT_SYMBOL(copy_to_user);
23642-
23643-/**
23644- * copy_from_user: - Copy a block of data from user space.
23645- * @to: Destination address, in kernel space.
23646- * @from: Source address, in user space.
23647- * @n: Number of bytes to copy.
23648- *
23649- * Context: User context only. This function may sleep.
23650- *
23651- * Copy data from user space to kernel space.
23652- *
23653- * Returns number of bytes that could not be copied.
23654- * On success, this will be zero.
23655- *
23656- * If some data could not be copied, this function will pad the copied
23657- * data to the requested size using zero bytes.
23658- */
23659-unsigned long
23660-_copy_from_user(void *to, const void __user *from, unsigned long n)
23661-{
23662- if (access_ok(VERIFY_READ, from, n))
23663- n = __copy_from_user(to, from, n);
23664- else
23665- memset(to, 0, n);
23666- return n;
23667-}
23668-EXPORT_SYMBOL(_copy_from_user);
23669-
23670 void copy_from_user_overflow(void)
23671 {
23672 WARN(1, "Buffer overflow detected!\n");
23673 }
23674 EXPORT_SYMBOL(copy_from_user_overflow);
23675+
23676+void copy_to_user_overflow(void)
23677+{
23678+ WARN(1, "Buffer overflow detected!\n");
23679+}
23680+EXPORT_SYMBOL(copy_to_user_overflow);
23681+
23682+#ifdef CONFIG_PAX_MEMORY_UDEREF
23683+void __set_fs(mm_segment_t x)
23684+{
23685+ switch (x.seg) {
23686+ case 0:
23687+ loadsegment(gs, 0);
23688+ break;
23689+ case TASK_SIZE_MAX:
23690+ loadsegment(gs, __USER_DS);
23691+ break;
23692+ case -1UL:
23693+ loadsegment(gs, __KERNEL_DS);
23694+ break;
23695+ default:
23696+ BUG();
23697+ }
23698+ return;
23699+}
23700+EXPORT_SYMBOL(__set_fs);
23701+
23702+void set_fs(mm_segment_t x)
23703+{
23704+ current_thread_info()->addr_limit = x;
23705+ __set_fs(x);
23706+}
23707+EXPORT_SYMBOL(set_fs);
23708+#endif
23709diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23710index b7c2849..8633ad8 100644
23711--- a/arch/x86/lib/usercopy_64.c
23712+++ b/arch/x86/lib/usercopy_64.c
23713@@ -42,6 +42,12 @@ long
23714 __strncpy_from_user(char *dst, const char __user *src, long count)
23715 {
23716 long res;
23717+
23718+#ifdef CONFIG_PAX_MEMORY_UDEREF
23719+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
23720+ src += PAX_USER_SHADOW_BASE;
23721+#endif
23722+
23723 __do_strncpy_from_user(dst, src, count, res);
23724 return res;
23725 }
23726@@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23727 {
23728 long __d0;
23729 might_fault();
23730+
23731+#ifdef CONFIG_PAX_MEMORY_UDEREF
23732+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23733+ addr += PAX_USER_SHADOW_BASE;
23734+#endif
23735+
23736 /* no memory constraint because it doesn't change any memory gcc knows
23737 about */
23738 asm volatile(
23739@@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
23740 }
23741 EXPORT_SYMBOL(strlen_user);
23742
23743-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23744+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23745 {
23746- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23747- return copy_user_generic((__force void *)to, (__force void *)from, len);
23748- }
23749- return len;
23750+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23751+
23752+#ifdef CONFIG_PAX_MEMORY_UDEREF
23753+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23754+ to += PAX_USER_SHADOW_BASE;
23755+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23756+ from += PAX_USER_SHADOW_BASE;
23757+#endif
23758+
23759+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23760+ }
23761+ return len;
23762 }
23763 EXPORT_SYMBOL(copy_in_user);
23764
23765@@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
23766 * it is not necessary to optimize tail handling.
23767 */
23768 unsigned long
23769-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23770+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23771 {
23772 char c;
23773 unsigned zero_len;
23774diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23775index 1fb85db..8b3540b 100644
23776--- a/arch/x86/mm/extable.c
23777+++ b/arch/x86/mm/extable.c
23778@@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
23779 const struct exception_table_entry *fixup;
23780
23781 #ifdef CONFIG_PNPBIOS
23782- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23783+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23784 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23785 extern u32 pnp_bios_is_utter_crap;
23786 pnp_bios_is_utter_crap = 1;
23787diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23788index f0b4caf..d92fd42 100644
23789--- a/arch/x86/mm/fault.c
23790+++ b/arch/x86/mm/fault.c
23791@@ -13,11 +13,18 @@
23792 #include <linux/perf_event.h> /* perf_sw_event */
23793 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23794 #include <linux/prefetch.h> /* prefetchw */
23795+#include <linux/unistd.h>
23796+#include <linux/compiler.h>
23797
23798 #include <asm/traps.h> /* dotraplinkage, ... */
23799 #include <asm/pgalloc.h> /* pgd_*(), ... */
23800 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23801 #include <asm/fixmap.h> /* VSYSCALL_START */
23802+#include <asm/tlbflush.h>
23803+
23804+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23805+#include <asm/stacktrace.h>
23806+#endif
23807
23808 /*
23809 * Page fault error code bits:
23810@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23811 int ret = 0;
23812
23813 /* kprobe_running() needs smp_processor_id() */
23814- if (kprobes_built_in() && !user_mode_vm(regs)) {
23815+ if (kprobes_built_in() && !user_mode(regs)) {
23816 preempt_disable();
23817 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23818 ret = 1;
23819@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23820 return !instr_lo || (instr_lo>>1) == 1;
23821 case 0x00:
23822 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23823- if (probe_kernel_address(instr, opcode))
23824+ if (user_mode(regs)) {
23825+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23826+ return 0;
23827+ } else if (probe_kernel_address(instr, opcode))
23828 return 0;
23829
23830 *prefetch = (instr_lo == 0xF) &&
23831@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23832 while (instr < max_instr) {
23833 unsigned char opcode;
23834
23835- if (probe_kernel_address(instr, opcode))
23836+ if (user_mode(regs)) {
23837+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23838+ break;
23839+ } else if (probe_kernel_address(instr, opcode))
23840 break;
23841
23842 instr++;
23843@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23844 force_sig_info(si_signo, &info, tsk);
23845 }
23846
23847+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23848+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23849+#endif
23850+
23851+#ifdef CONFIG_PAX_EMUTRAMP
23852+static int pax_handle_fetch_fault(struct pt_regs *regs);
23853+#endif
23854+
23855+#ifdef CONFIG_PAX_PAGEEXEC
23856+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23857+{
23858+ pgd_t *pgd;
23859+ pud_t *pud;
23860+ pmd_t *pmd;
23861+
23862+ pgd = pgd_offset(mm, address);
23863+ if (!pgd_present(*pgd))
23864+ return NULL;
23865+ pud = pud_offset(pgd, address);
23866+ if (!pud_present(*pud))
23867+ return NULL;
23868+ pmd = pmd_offset(pud, address);
23869+ if (!pmd_present(*pmd))
23870+ return NULL;
23871+ return pmd;
23872+}
23873+#endif
23874+
23875 DEFINE_SPINLOCK(pgd_lock);
23876 LIST_HEAD(pgd_list);
23877
23878@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23879 for (address = VMALLOC_START & PMD_MASK;
23880 address >= TASK_SIZE && address < FIXADDR_TOP;
23881 address += PMD_SIZE) {
23882+
23883+#ifdef CONFIG_PAX_PER_CPU_PGD
23884+ unsigned long cpu;
23885+#else
23886 struct page *page;
23887+#endif
23888
23889 spin_lock(&pgd_lock);
23890+
23891+#ifdef CONFIG_PAX_PER_CPU_PGD
23892+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23893+ pgd_t *pgd = get_cpu_pgd(cpu);
23894+ pmd_t *ret;
23895+#else
23896 list_for_each_entry(page, &pgd_list, lru) {
23897+ pgd_t *pgd = page_address(page);
23898 spinlock_t *pgt_lock;
23899 pmd_t *ret;
23900
23901@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23902 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23903
23904 spin_lock(pgt_lock);
23905- ret = vmalloc_sync_one(page_address(page), address);
23906+#endif
23907+
23908+ ret = vmalloc_sync_one(pgd, address);
23909+
23910+#ifndef CONFIG_PAX_PER_CPU_PGD
23911 spin_unlock(pgt_lock);
23912+#endif
23913
23914 if (!ret)
23915 break;
23916@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23917 * an interrupt in the middle of a task switch..
23918 */
23919 pgd_paddr = read_cr3();
23920+
23921+#ifdef CONFIG_PAX_PER_CPU_PGD
23922+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23923+#endif
23924+
23925 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23926 if (!pmd_k)
23927 return -1;
23928@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23929 * happen within a race in page table update. In the later
23930 * case just flush:
23931 */
23932+
23933+#ifdef CONFIG_PAX_PER_CPU_PGD
23934+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23935+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23936+#else
23937 pgd = pgd_offset(current->active_mm, address);
23938+#endif
23939+
23940 pgd_ref = pgd_offset_k(address);
23941 if (pgd_none(*pgd_ref))
23942 return -1;
23943@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23944 static int is_errata100(struct pt_regs *regs, unsigned long address)
23945 {
23946 #ifdef CONFIG_X86_64
23947- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23948+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23949 return 1;
23950 #endif
23951 return 0;
23952@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23953 }
23954
23955 static const char nx_warning[] = KERN_CRIT
23956-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23957+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23958
23959 static void
23960 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23961@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23962 if (!oops_may_print())
23963 return;
23964
23965- if (error_code & PF_INSTR) {
23966+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23967 unsigned int level;
23968
23969 pte_t *pte = lookup_address(address, &level);
23970
23971 if (pte && pte_present(*pte) && !pte_exec(*pte))
23972- printk(nx_warning, current_uid());
23973+ printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23974 }
23975
23976+#ifdef CONFIG_PAX_KERNEXEC
23977+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23978+ if (current->signal->curr_ip)
23979+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23980+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23981+ else
23982+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23983+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23984+ }
23985+#endif
23986+
23987 printk(KERN_ALERT "BUG: unable to handle kernel ");
23988 if (address < PAGE_SIZE)
23989 printk(KERN_CONT "NULL pointer dereference");
23990@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23991 }
23992 #endif
23993
23994+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23995+ if (pax_is_fetch_fault(regs, error_code, address)) {
23996+
23997+#ifdef CONFIG_PAX_EMUTRAMP
23998+ switch (pax_handle_fetch_fault(regs)) {
23999+ case 2:
24000+ return;
24001+ }
24002+#endif
24003+
24004+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24005+ do_group_exit(SIGKILL);
24006+ }
24007+#endif
24008+
24009 if (unlikely(show_unhandled_signals))
24010 show_signal_msg(regs, error_code, address, tsk);
24011
24012@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
24013 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
24014 printk(KERN_ERR
24015 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
24016- tsk->comm, tsk->pid, address);
24017+ tsk->comm, task_pid_nr(tsk), address);
24018 code = BUS_MCEERR_AR;
24019 }
24020 #endif
24021@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
24022 return 1;
24023 }
24024
24025+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24026+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
24027+{
24028+ pte_t *pte;
24029+ pmd_t *pmd;
24030+ spinlock_t *ptl;
24031+ unsigned char pte_mask;
24032+
24033+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
24034+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
24035+ return 0;
24036+
24037+ /* PaX: it's our fault, let's handle it if we can */
24038+
24039+ /* PaX: take a look at read faults before acquiring any locks */
24040+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
24041+ /* instruction fetch attempt from a protected page in user mode */
24042+ up_read(&mm->mmap_sem);
24043+
24044+#ifdef CONFIG_PAX_EMUTRAMP
24045+ switch (pax_handle_fetch_fault(regs)) {
24046+ case 2:
24047+ return 1;
24048+ }
24049+#endif
24050+
24051+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24052+ do_group_exit(SIGKILL);
24053+ }
24054+
24055+ pmd = pax_get_pmd(mm, address);
24056+ if (unlikely(!pmd))
24057+ return 0;
24058+
24059+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
24060+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
24061+ pte_unmap_unlock(pte, ptl);
24062+ return 0;
24063+ }
24064+
24065+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
24066+ /* write attempt to a protected page in user mode */
24067+ pte_unmap_unlock(pte, ptl);
24068+ return 0;
24069+ }
24070+
24071+#ifdef CONFIG_SMP
24072+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
24073+#else
24074+ if (likely(address > get_limit(regs->cs)))
24075+#endif
24076+ {
24077+ set_pte(pte, pte_mkread(*pte));
24078+ __flush_tlb_one(address);
24079+ pte_unmap_unlock(pte, ptl);
24080+ up_read(&mm->mmap_sem);
24081+ return 1;
24082+ }
24083+
24084+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
24085+
24086+ /*
24087+ * PaX: fill DTLB with user rights and retry
24088+ */
24089+ __asm__ __volatile__ (
24090+ "orb %2,(%1)\n"
24091+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
24092+/*
24093+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
24094+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
24095+ * page fault when examined during a TLB load attempt. this is true not only
24096+ * for PTEs holding a non-present entry but also present entries that will
24097+ * raise a page fault (such as those set up by PaX, or the copy-on-write
24098+ * mechanism). in effect it means that we do *not* need to flush the TLBs
24099+ * for our target pages since their PTEs are simply not in the TLBs at all.
24100+
24101+ * the best thing in omitting it is that we gain around 15-20% speed in the
24102+ * fast path of the page fault handler and can get rid of tracing since we
24103+ * can no longer flush unintended entries.
24104+ */
24105+ "invlpg (%0)\n"
24106+#endif
24107+ __copyuser_seg"testb $0,(%0)\n"
24108+ "xorb %3,(%1)\n"
24109+ :
24110+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
24111+ : "memory", "cc");
24112+ pte_unmap_unlock(pte, ptl);
24113+ up_read(&mm->mmap_sem);
24114+ return 1;
24115+}
24116+#endif
24117+
24118 /*
24119 * Handle a spurious fault caused by a stale TLB entry.
24120 *
24121@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
24122 static inline int
24123 access_error(unsigned long error_code, struct vm_area_struct *vma)
24124 {
24125+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24126+ return 1;
24127+
24128 if (error_code & PF_WRITE) {
24129 /* write, present and write, not present: */
24130 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24131@@ -1005,18 +1197,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24132 {
24133 struct vm_area_struct *vma;
24134 struct task_struct *tsk;
24135- unsigned long address;
24136 struct mm_struct *mm;
24137 int fault;
24138 int write = error_code & PF_WRITE;
24139 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
24140 (write ? FAULT_FLAG_WRITE : 0);
24141
24142- tsk = current;
24143- mm = tsk->mm;
24144-
24145 /* Get the faulting address: */
24146- address = read_cr2();
24147+ unsigned long address = read_cr2();
24148+
24149+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24150+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24151+ if (!search_exception_tables(regs->ip)) {
24152+ bad_area_nosemaphore(regs, error_code, address);
24153+ return;
24154+ }
24155+ if (address < PAX_USER_SHADOW_BASE) {
24156+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24157+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24158+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24159+ } else
24160+ address -= PAX_USER_SHADOW_BASE;
24161+ }
24162+#endif
24163+
24164+ tsk = current;
24165+ mm = tsk->mm;
24166
24167 /*
24168 * Detect and handle instructions that would cause a page fault for
24169@@ -1077,7 +1283,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24170 * User-mode registers count as a user access even for any
24171 * potential system fault or CPU buglet:
24172 */
24173- if (user_mode_vm(regs)) {
24174+ if (user_mode(regs)) {
24175 local_irq_enable();
24176 error_code |= PF_USER;
24177 } else {
24178@@ -1132,6 +1338,11 @@ retry:
24179 might_sleep();
24180 }
24181
24182+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24183+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24184+ return;
24185+#endif
24186+
24187 vma = find_vma(mm, address);
24188 if (unlikely(!vma)) {
24189 bad_area(regs, error_code, address);
24190@@ -1143,18 +1354,24 @@ retry:
24191 bad_area(regs, error_code, address);
24192 return;
24193 }
24194- if (error_code & PF_USER) {
24195- /*
24196- * Accessing the stack below %sp is always a bug.
24197- * The large cushion allows instructions like enter
24198- * and pusha to work. ("enter $65535, $31" pushes
24199- * 32 pointers and then decrements %sp by 65535.)
24200- */
24201- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24202- bad_area(regs, error_code, address);
24203- return;
24204- }
24205+ /*
24206+ * Accessing the stack below %sp is always a bug.
24207+ * The large cushion allows instructions like enter
24208+ * and pusha to work. ("enter $65535, $31" pushes
24209+ * 32 pointers and then decrements %sp by 65535.)
24210+ */
24211+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24212+ bad_area(regs, error_code, address);
24213+ return;
24214 }
24215+
24216+#ifdef CONFIG_PAX_SEGMEXEC
24217+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24218+ bad_area(regs, error_code, address);
24219+ return;
24220+ }
24221+#endif
24222+
24223 if (unlikely(expand_stack(vma, address))) {
24224 bad_area(regs, error_code, address);
24225 return;
24226@@ -1209,3 +1426,292 @@ good_area:
24227
24228 up_read(&mm->mmap_sem);
24229 }
24230+
24231+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24232+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24233+{
24234+ struct mm_struct *mm = current->mm;
24235+ unsigned long ip = regs->ip;
24236+
24237+ if (v8086_mode(regs))
24238+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24239+
24240+#ifdef CONFIG_PAX_PAGEEXEC
24241+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24242+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24243+ return true;
24244+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24245+ return true;
24246+ return false;
24247+ }
24248+#endif
24249+
24250+#ifdef CONFIG_PAX_SEGMEXEC
24251+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24252+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24253+ return true;
24254+ return false;
24255+ }
24256+#endif
24257+
24258+ return false;
24259+}
24260+#endif
24261+
24262+#ifdef CONFIG_PAX_EMUTRAMP
24263+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24264+{
24265+ int err;
24266+
24267+ do { /* PaX: libffi trampoline emulation */
24268+ unsigned char mov, jmp;
24269+ unsigned int addr1, addr2;
24270+
24271+#ifdef CONFIG_X86_64
24272+ if ((regs->ip + 9) >> 32)
24273+ break;
24274+#endif
24275+
24276+ err = get_user(mov, (unsigned char __user *)regs->ip);
24277+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24278+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24279+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24280+
24281+ if (err)
24282+ break;
24283+
24284+ if (mov == 0xB8 && jmp == 0xE9) {
24285+ regs->ax = addr1;
24286+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24287+ return 2;
24288+ }
24289+ } while (0);
24290+
24291+ do { /* PaX: gcc trampoline emulation #1 */
24292+ unsigned char mov1, mov2;
24293+ unsigned short jmp;
24294+ unsigned int addr1, addr2;
24295+
24296+#ifdef CONFIG_X86_64
24297+ if ((regs->ip + 11) >> 32)
24298+ break;
24299+#endif
24300+
24301+ err = get_user(mov1, (unsigned char __user *)regs->ip);
24302+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24303+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24304+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24305+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24306+
24307+ if (err)
24308+ break;
24309+
24310+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24311+ regs->cx = addr1;
24312+ regs->ax = addr2;
24313+ regs->ip = addr2;
24314+ return 2;
24315+ }
24316+ } while (0);
24317+
24318+ do { /* PaX: gcc trampoline emulation #2 */
24319+ unsigned char mov, jmp;
24320+ unsigned int addr1, addr2;
24321+
24322+#ifdef CONFIG_X86_64
24323+ if ((regs->ip + 9) >> 32)
24324+ break;
24325+#endif
24326+
24327+ err = get_user(mov, (unsigned char __user *)regs->ip);
24328+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24329+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24330+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24331+
24332+ if (err)
24333+ break;
24334+
24335+ if (mov == 0xB9 && jmp == 0xE9) {
24336+ regs->cx = addr1;
24337+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24338+ return 2;
24339+ }
24340+ } while (0);
24341+
24342+ return 1; /* PaX in action */
24343+}
24344+
24345+#ifdef CONFIG_X86_64
24346+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24347+{
24348+ int err;
24349+
24350+ do { /* PaX: libffi trampoline emulation */
24351+ unsigned short mov1, mov2, jmp1;
24352+ unsigned char stcclc, jmp2;
24353+ unsigned long addr1, addr2;
24354+
24355+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24356+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24357+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24358+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24359+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24360+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24361+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24362+
24363+ if (err)
24364+ break;
24365+
24366+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24367+ regs->r11 = addr1;
24368+ regs->r10 = addr2;
24369+ if (stcclc == 0xF8)
24370+ regs->flags &= ~X86_EFLAGS_CF;
24371+ else
24372+ regs->flags |= X86_EFLAGS_CF;
24373+ regs->ip = addr1;
24374+ return 2;
24375+ }
24376+ } while (0);
24377+
24378+ do { /* PaX: gcc trampoline emulation #1 */
24379+ unsigned short mov1, mov2, jmp1;
24380+ unsigned char jmp2;
24381+ unsigned int addr1;
24382+ unsigned long addr2;
24383+
24384+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24385+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24386+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24387+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24388+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24389+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24390+
24391+ if (err)
24392+ break;
24393+
24394+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24395+ regs->r11 = addr1;
24396+ regs->r10 = addr2;
24397+ regs->ip = addr1;
24398+ return 2;
24399+ }
24400+ } while (0);
24401+
24402+ do { /* PaX: gcc trampoline emulation #2 */
24403+ unsigned short mov1, mov2, jmp1;
24404+ unsigned char jmp2;
24405+ unsigned long addr1, addr2;
24406+
24407+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24408+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24409+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24410+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24411+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24412+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24413+
24414+ if (err)
24415+ break;
24416+
24417+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24418+ regs->r11 = addr1;
24419+ regs->r10 = addr2;
24420+ regs->ip = addr1;
24421+ return 2;
24422+ }
24423+ } while (0);
24424+
24425+ return 1; /* PaX in action */
24426+}
24427+#endif
24428+
24429+/*
24430+ * PaX: decide what to do with offenders (regs->ip = fault address)
24431+ *
24432+ * returns 1 when task should be killed
24433+ * 2 when gcc trampoline was detected
24434+ */
24435+static int pax_handle_fetch_fault(struct pt_regs *regs)
24436+{
24437+ if (v8086_mode(regs))
24438+ return 1;
24439+
24440+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24441+ return 1;
24442+
24443+#ifdef CONFIG_X86_32
24444+ return pax_handle_fetch_fault_32(regs);
24445+#else
24446+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24447+ return pax_handle_fetch_fault_32(regs);
24448+ else
24449+ return pax_handle_fetch_fault_64(regs);
24450+#endif
24451+}
24452+#endif
24453+
24454+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24455+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24456+{
24457+ long i;
24458+
24459+ printk(KERN_ERR "PAX: bytes at PC: ");
24460+ for (i = 0; i < 20; i++) {
24461+ unsigned char c;
24462+ if (get_user(c, (unsigned char __force_user *)pc+i))
24463+ printk(KERN_CONT "?? ");
24464+ else
24465+ printk(KERN_CONT "%02x ", c);
24466+ }
24467+ printk("\n");
24468+
24469+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24470+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24471+ unsigned long c;
24472+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24473+#ifdef CONFIG_X86_32
24474+ printk(KERN_CONT "???????? ");
24475+#else
24476+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24477+ printk(KERN_CONT "???????? ???????? ");
24478+ else
24479+ printk(KERN_CONT "???????????????? ");
24480+#endif
24481+ } else {
24482+#ifdef CONFIG_X86_64
24483+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24484+ printk(KERN_CONT "%08x ", (unsigned int)c);
24485+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24486+ } else
24487+#endif
24488+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24489+ }
24490+ }
24491+ printk("\n");
24492+}
24493+#endif
24494+
24495+/**
24496+ * probe_kernel_write(): safely attempt to write to a location
24497+ * @dst: address to write to
24498+ * @src: pointer to the data that shall be written
24499+ * @size: size of the data chunk
24500+ *
24501+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24502+ * happens, handle that and return -EFAULT.
24503+ */
24504+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24505+{
24506+ long ret;
24507+ mm_segment_t old_fs = get_fs();
24508+
24509+ set_fs(KERNEL_DS);
24510+ pagefault_disable();
24511+ pax_open_kernel();
24512+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24513+ pax_close_kernel();
24514+ pagefault_enable();
24515+ set_fs(old_fs);
24516+
24517+ return ret ? -EFAULT : 0;
24518+}
24519diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24520index dd74e46..7d26398 100644
24521--- a/arch/x86/mm/gup.c
24522+++ b/arch/x86/mm/gup.c
24523@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24524 addr = start;
24525 len = (unsigned long) nr_pages << PAGE_SHIFT;
24526 end = start + len;
24527- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24528+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24529 (void __user *)start, len)))
24530 return 0;
24531
24532diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24533index f4f29b1..5cac4fb 100644
24534--- a/arch/x86/mm/highmem_32.c
24535+++ b/arch/x86/mm/highmem_32.c
24536@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24537 idx = type + KM_TYPE_NR*smp_processor_id();
24538 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24539 BUG_ON(!pte_none(*(kmap_pte-idx)));
24540+
24541+ pax_open_kernel();
24542 set_pte(kmap_pte-idx, mk_pte(page, prot));
24543+ pax_close_kernel();
24544+
24545 arch_flush_lazy_mmu_mode();
24546
24547 return (void *)vaddr;
24548diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24549index 8ecbb4b..a269cab 100644
24550--- a/arch/x86/mm/hugetlbpage.c
24551+++ b/arch/x86/mm/hugetlbpage.c
24552@@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24553 struct hstate *h = hstate_file(file);
24554 struct mm_struct *mm = current->mm;
24555 struct vm_area_struct *vma;
24556- unsigned long start_addr;
24557+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24558+
24559+#ifdef CONFIG_PAX_SEGMEXEC
24560+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24561+ pax_task_size = SEGMEXEC_TASK_SIZE;
24562+#endif
24563+
24564+ pax_task_size -= PAGE_SIZE;
24565
24566 if (len > mm->cached_hole_size) {
24567- start_addr = mm->free_area_cache;
24568+ start_addr = mm->free_area_cache;
24569 } else {
24570- start_addr = TASK_UNMAPPED_BASE;
24571- mm->cached_hole_size = 0;
24572+ start_addr = mm->mmap_base;
24573+ mm->cached_hole_size = 0;
24574 }
24575
24576 full_search:
24577@@ -280,26 +287,27 @@ full_search:
24578
24579 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24580 /* At this point: (!vma || addr < vma->vm_end). */
24581- if (TASK_SIZE - len < addr) {
24582+ if (pax_task_size - len < addr) {
24583 /*
24584 * Start a new search - just in case we missed
24585 * some holes.
24586 */
24587- if (start_addr != TASK_UNMAPPED_BASE) {
24588- start_addr = TASK_UNMAPPED_BASE;
24589+ if (start_addr != mm->mmap_base) {
24590+ start_addr = mm->mmap_base;
24591 mm->cached_hole_size = 0;
24592 goto full_search;
24593 }
24594 return -ENOMEM;
24595 }
24596- if (!vma || addr + len <= vma->vm_start) {
24597- mm->free_area_cache = addr + len;
24598- return addr;
24599- }
24600+ if (check_heap_stack_gap(vma, addr, len))
24601+ break;
24602 if (addr + mm->cached_hole_size < vma->vm_start)
24603 mm->cached_hole_size = vma->vm_start - addr;
24604 addr = ALIGN(vma->vm_end, huge_page_size(h));
24605 }
24606+
24607+ mm->free_area_cache = addr + len;
24608+ return addr;
24609 }
24610
24611 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24612@@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24613 {
24614 struct hstate *h = hstate_file(file);
24615 struct mm_struct *mm = current->mm;
24616- struct vm_area_struct *vma, *prev_vma;
24617- unsigned long base = mm->mmap_base, addr = addr0;
24618+ struct vm_area_struct *vma;
24619+ unsigned long base = mm->mmap_base, addr;
24620 unsigned long largest_hole = mm->cached_hole_size;
24621- int first_time = 1;
24622
24623 /* don't allow allocations above current base */
24624 if (mm->free_area_cache > base)
24625@@ -321,14 +328,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24626 largest_hole = 0;
24627 mm->free_area_cache = base;
24628 }
24629-try_again:
24630+
24631 /* make sure it can fit in the remaining address space */
24632 if (mm->free_area_cache < len)
24633 goto fail;
24634
24635 /* either no address requested or can't fit in requested address hole */
24636- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24637+ addr = (mm->free_area_cache - len);
24638 do {
24639+ addr &= huge_page_mask(h);
24640 /*
24641 * Lookup failure means no vma is above this address,
24642 * i.e. return with success:
24643@@ -341,46 +349,47 @@ try_again:
24644 * new region fits between prev_vma->vm_end and
24645 * vma->vm_start, use it:
24646 */
24647- prev_vma = vma->vm_prev;
24648- if (addr + len <= vma->vm_start &&
24649- (!prev_vma || (addr >= prev_vma->vm_end))) {
24650+ if (check_heap_stack_gap(vma, addr, len)) {
24651 /* remember the address as a hint for next time */
24652- mm->cached_hole_size = largest_hole;
24653- return (mm->free_area_cache = addr);
24654- } else {
24655- /* pull free_area_cache down to the first hole */
24656- if (mm->free_area_cache == vma->vm_end) {
24657- mm->free_area_cache = vma->vm_start;
24658- mm->cached_hole_size = largest_hole;
24659- }
24660+ mm->cached_hole_size = largest_hole;
24661+ return (mm->free_area_cache = addr);
24662+ }
24663+ /* pull free_area_cache down to the first hole */
24664+ if (mm->free_area_cache == vma->vm_end) {
24665+ mm->free_area_cache = vma->vm_start;
24666+ mm->cached_hole_size = largest_hole;
24667 }
24668
24669 /* remember the largest hole we saw so far */
24670 if (addr + largest_hole < vma->vm_start)
24671- largest_hole = vma->vm_start - addr;
24672+ largest_hole = vma->vm_start - addr;
24673
24674 /* try just below the current vma->vm_start */
24675- addr = (vma->vm_start - len) & huge_page_mask(h);
24676- } while (len <= vma->vm_start);
24677+ addr = skip_heap_stack_gap(vma, len);
24678+ } while (!IS_ERR_VALUE(addr));
24679
24680 fail:
24681 /*
24682- * if hint left us with no space for the requested
24683- * mapping then try again:
24684- */
24685- if (first_time) {
24686- mm->free_area_cache = base;
24687- largest_hole = 0;
24688- first_time = 0;
24689- goto try_again;
24690- }
24691- /*
24692 * A failed mmap() very likely causes application failure,
24693 * so fall back to the bottom-up function here. This scenario
24694 * can happen with large stack limits and large mmap()
24695 * allocations.
24696 */
24697- mm->free_area_cache = TASK_UNMAPPED_BASE;
24698+
24699+#ifdef CONFIG_PAX_SEGMEXEC
24700+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24701+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24702+ else
24703+#endif
24704+
24705+ mm->mmap_base = TASK_UNMAPPED_BASE;
24706+
24707+#ifdef CONFIG_PAX_RANDMMAP
24708+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24709+ mm->mmap_base += mm->delta_mmap;
24710+#endif
24711+
24712+ mm->free_area_cache = mm->mmap_base;
24713 mm->cached_hole_size = ~0UL;
24714 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24715 len, pgoff, flags);
24716@@ -388,6 +397,7 @@ fail:
24717 /*
24718 * Restore the topdown base:
24719 */
24720+ mm->mmap_base = base;
24721 mm->free_area_cache = base;
24722 mm->cached_hole_size = ~0UL;
24723
24724@@ -401,10 +411,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24725 struct hstate *h = hstate_file(file);
24726 struct mm_struct *mm = current->mm;
24727 struct vm_area_struct *vma;
24728+ unsigned long pax_task_size = TASK_SIZE;
24729
24730 if (len & ~huge_page_mask(h))
24731 return -EINVAL;
24732- if (len > TASK_SIZE)
24733+
24734+#ifdef CONFIG_PAX_SEGMEXEC
24735+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24736+ pax_task_size = SEGMEXEC_TASK_SIZE;
24737+#endif
24738+
24739+ pax_task_size -= PAGE_SIZE;
24740+
24741+ if (len > pax_task_size)
24742 return -ENOMEM;
24743
24744 if (flags & MAP_FIXED) {
24745@@ -416,8 +435,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24746 if (addr) {
24747 addr = ALIGN(addr, huge_page_size(h));
24748 vma = find_vma(mm, addr);
24749- if (TASK_SIZE - len >= addr &&
24750- (!vma || addr + len <= vma->vm_start))
24751+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24752 return addr;
24753 }
24754 if (mm->get_unmapped_area == arch_get_unmapped_area)
24755diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24756index 6cabf65..9976a56 100644
24757--- a/arch/x86/mm/init.c
24758+++ b/arch/x86/mm/init.c
24759@@ -17,6 +17,8 @@
24760 #include <asm/tlb.h>
24761 #include <asm/proto.h>
24762 #include <asm/dma.h> /* for MAX_DMA_PFN */
24763+#include <asm/desc.h>
24764+#include <asm/bios_ebda.h>
24765
24766 unsigned long __initdata pgt_buf_start;
24767 unsigned long __meminitdata pgt_buf_end;
24768@@ -33,7 +35,7 @@ int direct_gbpages
24769 static void __init find_early_table_space(unsigned long end, int use_pse,
24770 int use_gbpages)
24771 {
24772- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24773+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24774 phys_addr_t base;
24775
24776 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24777@@ -312,10 +314,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24778 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24779 * mmio resources as well as potential bios/acpi data regions.
24780 */
24781+
24782+#ifdef CONFIG_GRKERNSEC_KMEM
24783+static unsigned int ebda_start __read_only;
24784+static unsigned int ebda_end __read_only;
24785+#endif
24786+
24787 int devmem_is_allowed(unsigned long pagenr)
24788 {
24789+#ifdef CONFIG_GRKERNSEC_KMEM
24790+ /* allow BDA */
24791+ if (!pagenr)
24792+ return 1;
24793+ /* allow EBDA */
24794+ if (pagenr >= ebda_start && pagenr < ebda_end)
24795+ return 1;
24796+#else
24797+ if (!pagenr)
24798+ return 1;
24799+#ifdef CONFIG_VM86
24800+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24801+ return 1;
24802+#endif
24803+#endif
24804+
24805+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24806+ return 1;
24807+#ifdef CONFIG_GRKERNSEC_KMEM
24808+ /* throw out everything else below 1MB */
24809 if (pagenr <= 256)
24810- return 1;
24811+ return 0;
24812+#endif
24813 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24814 return 0;
24815 if (!page_is_ram(pagenr))
24816@@ -372,8 +401,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24817 #endif
24818 }
24819
24820+#ifdef CONFIG_GRKERNSEC_KMEM
24821+static inline void gr_init_ebda(void)
24822+{
24823+ unsigned int ebda_addr;
24824+ unsigned int ebda_size = 0;
24825+
24826+ ebda_addr = get_bios_ebda();
24827+ if (ebda_addr) {
24828+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24829+ ebda_size <<= 10;
24830+ }
24831+ if (ebda_addr && ebda_size) {
24832+ ebda_start = ebda_addr >> PAGE_SHIFT;
24833+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24834+ } else {
24835+ ebda_start = 0x9f000 >> PAGE_SHIFT;
24836+ ebda_end = 0xa0000 >> PAGE_SHIFT;
24837+ }
24838+}
24839+#else
24840+static inline void gr_init_ebda(void) { }
24841+#endif
24842+
24843 void free_initmem(void)
24844 {
24845+#ifdef CONFIG_PAX_KERNEXEC
24846+#ifdef CONFIG_X86_32
24847+ /* PaX: limit KERNEL_CS to actual size */
24848+ unsigned long addr, limit;
24849+ struct desc_struct d;
24850+ int cpu;
24851+#endif
24852+#endif
24853+#ifndef CONFIG_X86_PAE
24854+ pgd_t *pgd;
24855+ pud_t *pud;
24856+ pmd_t *pmd;
24857+ unsigned long addr, end;
24858+#endif
24859+
24860+ gr_init_ebda();
24861+
24862+#ifdef CONFIG_PAX_KERNEXEC
24863+#ifdef CONFIG_X86_32
24864+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24865+ limit = (limit - 1UL) >> PAGE_SHIFT;
24866+
24867+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24868+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24869+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24870+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24871+ }
24872+
24873+ /* PaX: make KERNEL_CS read-only */
24874+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24875+ if (!paravirt_enabled())
24876+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24877+/*
24878+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24879+ pgd = pgd_offset_k(addr);
24880+ pud = pud_offset(pgd, addr);
24881+ pmd = pmd_offset(pud, addr);
24882+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24883+ }
24884+*/
24885+#ifdef CONFIG_X86_PAE
24886+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24887+/*
24888+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24889+ pgd = pgd_offset_k(addr);
24890+ pud = pud_offset(pgd, addr);
24891+ pmd = pmd_offset(pud, addr);
24892+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24893+ }
24894+*/
24895+#endif
24896+
24897+#ifdef CONFIG_MODULES
24898+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24899+#endif
24900+
24901+#else
24902+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24903+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24904+ pgd = pgd_offset_k(addr);
24905+ pud = pud_offset(pgd, addr);
24906+ pmd = pmd_offset(pud, addr);
24907+ if (!pmd_present(*pmd))
24908+ continue;
24909+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24910+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24911+ else
24912+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24913+ }
24914+
24915+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24916+ end = addr + KERNEL_IMAGE_SIZE;
24917+ for (; addr < end; addr += PMD_SIZE) {
24918+ pgd = pgd_offset_k(addr);
24919+ pud = pud_offset(pgd, addr);
24920+ pmd = pmd_offset(pud, addr);
24921+ if (!pmd_present(*pmd))
24922+ continue;
24923+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24924+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24925+ }
24926+#endif
24927+
24928+ flush_tlb_all();
24929+#endif
24930+
24931 free_init_pages("unused kernel memory",
24932 (unsigned long)(&__init_begin),
24933 (unsigned long)(&__init_end));
24934diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24935index 8663f6c..829ae76 100644
24936--- a/arch/x86/mm/init_32.c
24937+++ b/arch/x86/mm/init_32.c
24938@@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
24939 }
24940
24941 /*
24942- * Creates a middle page table and puts a pointer to it in the
24943- * given global directory entry. This only returns the gd entry
24944- * in non-PAE compilation mode, since the middle layer is folded.
24945- */
24946-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24947-{
24948- pud_t *pud;
24949- pmd_t *pmd_table;
24950-
24951-#ifdef CONFIG_X86_PAE
24952- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24953- if (after_bootmem)
24954- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24955- else
24956- pmd_table = (pmd_t *)alloc_low_page();
24957- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24958- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24959- pud = pud_offset(pgd, 0);
24960- BUG_ON(pmd_table != pmd_offset(pud, 0));
24961-
24962- return pmd_table;
24963- }
24964-#endif
24965- pud = pud_offset(pgd, 0);
24966- pmd_table = pmd_offset(pud, 0);
24967-
24968- return pmd_table;
24969-}
24970-
24971-/*
24972 * Create a page table and place a pointer to it in a middle page
24973 * directory entry:
24974 */
24975@@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24976 page_table = (pte_t *)alloc_low_page();
24977
24978 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24979+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24980+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24981+#else
24982 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24983+#endif
24984 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24985 }
24986
24987 return pte_offset_kernel(pmd, 0);
24988 }
24989
24990+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24991+{
24992+ pud_t *pud;
24993+ pmd_t *pmd_table;
24994+
24995+ pud = pud_offset(pgd, 0);
24996+ pmd_table = pmd_offset(pud, 0);
24997+
24998+ return pmd_table;
24999+}
25000+
25001 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
25002 {
25003 int pgd_idx = pgd_index(vaddr);
25004@@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25005 int pgd_idx, pmd_idx;
25006 unsigned long vaddr;
25007 pgd_t *pgd;
25008+ pud_t *pud;
25009 pmd_t *pmd;
25010 pte_t *pte = NULL;
25011
25012@@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25013 pgd = pgd_base + pgd_idx;
25014
25015 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
25016- pmd = one_md_table_init(pgd);
25017- pmd = pmd + pmd_index(vaddr);
25018+ pud = pud_offset(pgd, vaddr);
25019+ pmd = pmd_offset(pud, vaddr);
25020+
25021+#ifdef CONFIG_X86_PAE
25022+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25023+#endif
25024+
25025 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
25026 pmd++, pmd_idx++) {
25027 pte = page_table_kmap_check(one_page_table_init(pmd),
25028@@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25029 }
25030 }
25031
25032-static inline int is_kernel_text(unsigned long addr)
25033+static inline int is_kernel_text(unsigned long start, unsigned long end)
25034 {
25035- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
25036- return 1;
25037- return 0;
25038+ if ((start > ktla_ktva((unsigned long)_etext) ||
25039+ end <= ktla_ktva((unsigned long)_stext)) &&
25040+ (start > ktla_ktva((unsigned long)_einittext) ||
25041+ end <= ktla_ktva((unsigned long)_sinittext)) &&
25042+
25043+#ifdef CONFIG_ACPI_SLEEP
25044+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
25045+#endif
25046+
25047+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
25048+ return 0;
25049+ return 1;
25050 }
25051
25052 /*
25053@@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
25054 unsigned long last_map_addr = end;
25055 unsigned long start_pfn, end_pfn;
25056 pgd_t *pgd_base = swapper_pg_dir;
25057- int pgd_idx, pmd_idx, pte_ofs;
25058+ unsigned int pgd_idx, pmd_idx, pte_ofs;
25059 unsigned long pfn;
25060 pgd_t *pgd;
25061+ pud_t *pud;
25062 pmd_t *pmd;
25063 pte_t *pte;
25064 unsigned pages_2m, pages_4k;
25065@@ -281,8 +282,13 @@ repeat:
25066 pfn = start_pfn;
25067 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25068 pgd = pgd_base + pgd_idx;
25069- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
25070- pmd = one_md_table_init(pgd);
25071+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
25072+ pud = pud_offset(pgd, 0);
25073+ pmd = pmd_offset(pud, 0);
25074+
25075+#ifdef CONFIG_X86_PAE
25076+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25077+#endif
25078
25079 if (pfn >= end_pfn)
25080 continue;
25081@@ -294,14 +300,13 @@ repeat:
25082 #endif
25083 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
25084 pmd++, pmd_idx++) {
25085- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
25086+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
25087
25088 /*
25089 * Map with big pages if possible, otherwise
25090 * create normal page tables:
25091 */
25092 if (use_pse) {
25093- unsigned int addr2;
25094 pgprot_t prot = PAGE_KERNEL_LARGE;
25095 /*
25096 * first pass will use the same initial
25097@@ -311,11 +316,7 @@ repeat:
25098 __pgprot(PTE_IDENT_ATTR |
25099 _PAGE_PSE);
25100
25101- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
25102- PAGE_OFFSET + PAGE_SIZE-1;
25103-
25104- if (is_kernel_text(addr) ||
25105- is_kernel_text(addr2))
25106+ if (is_kernel_text(address, address + PMD_SIZE))
25107 prot = PAGE_KERNEL_LARGE_EXEC;
25108
25109 pages_2m++;
25110@@ -332,7 +333,7 @@ repeat:
25111 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25112 pte += pte_ofs;
25113 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
25114- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
25115+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
25116 pgprot_t prot = PAGE_KERNEL;
25117 /*
25118 * first pass will use the same initial
25119@@ -340,7 +341,7 @@ repeat:
25120 */
25121 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
25122
25123- if (is_kernel_text(addr))
25124+ if (is_kernel_text(address, address + PAGE_SIZE))
25125 prot = PAGE_KERNEL_EXEC;
25126
25127 pages_4k++;
25128@@ -466,7 +467,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
25129
25130 pud = pud_offset(pgd, va);
25131 pmd = pmd_offset(pud, va);
25132- if (!pmd_present(*pmd))
25133+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
25134 break;
25135
25136 pte = pte_offset_kernel(pmd, va);
25137@@ -518,12 +519,10 @@ void __init early_ioremap_page_table_range_init(void)
25138
25139 static void __init pagetable_init(void)
25140 {
25141- pgd_t *pgd_base = swapper_pg_dir;
25142-
25143- permanent_kmaps_init(pgd_base);
25144+ permanent_kmaps_init(swapper_pg_dir);
25145 }
25146
25147-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25148+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25149 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25150
25151 /* user-defined highmem size */
25152@@ -735,6 +734,12 @@ void __init mem_init(void)
25153
25154 pci_iommu_alloc();
25155
25156+#ifdef CONFIG_PAX_PER_CPU_PGD
25157+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25158+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25159+ KERNEL_PGD_PTRS);
25160+#endif
25161+
25162 #ifdef CONFIG_FLATMEM
25163 BUG_ON(!mem_map);
25164 #endif
25165@@ -761,7 +766,7 @@ void __init mem_init(void)
25166 reservedpages++;
25167
25168 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25169- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25170+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25171 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25172
25173 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25174@@ -802,10 +807,10 @@ void __init mem_init(void)
25175 ((unsigned long)&__init_end -
25176 (unsigned long)&__init_begin) >> 10,
25177
25178- (unsigned long)&_etext, (unsigned long)&_edata,
25179- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25180+ (unsigned long)&_sdata, (unsigned long)&_edata,
25181+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25182
25183- (unsigned long)&_text, (unsigned long)&_etext,
25184+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25185 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25186
25187 /*
25188@@ -883,6 +888,7 @@ void set_kernel_text_rw(void)
25189 if (!kernel_set_to_readonly)
25190 return;
25191
25192+ start = ktla_ktva(start);
25193 pr_debug("Set kernel text: %lx - %lx for read write\n",
25194 start, start+size);
25195
25196@@ -897,6 +903,7 @@ void set_kernel_text_ro(void)
25197 if (!kernel_set_to_readonly)
25198 return;
25199
25200+ start = ktla_ktva(start);
25201 pr_debug("Set kernel text: %lx - %lx for read only\n",
25202 start, start+size);
25203
25204@@ -925,6 +932,7 @@ void mark_rodata_ro(void)
25205 unsigned long start = PFN_ALIGN(_text);
25206 unsigned long size = PFN_ALIGN(_etext) - start;
25207
25208+ start = ktla_ktva(start);
25209 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25210 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25211 size >> 10);
25212diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25213index 436a030..4f97ffc 100644
25214--- a/arch/x86/mm/init_64.c
25215+++ b/arch/x86/mm/init_64.c
25216@@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25217 * around without checking the pgd every time.
25218 */
25219
25220-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25221+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25222 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25223
25224 int force_personality32;
25225@@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25226
25227 for (address = start; address <= end; address += PGDIR_SIZE) {
25228 const pgd_t *pgd_ref = pgd_offset_k(address);
25229+
25230+#ifdef CONFIG_PAX_PER_CPU_PGD
25231+ unsigned long cpu;
25232+#else
25233 struct page *page;
25234+#endif
25235
25236 if (pgd_none(*pgd_ref))
25237 continue;
25238
25239 spin_lock(&pgd_lock);
25240+
25241+#ifdef CONFIG_PAX_PER_CPU_PGD
25242+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25243+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
25244+#else
25245 list_for_each_entry(page, &pgd_list, lru) {
25246 pgd_t *pgd;
25247 spinlock_t *pgt_lock;
25248@@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25249 /* the pgt_lock only for Xen */
25250 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25251 spin_lock(pgt_lock);
25252+#endif
25253
25254 if (pgd_none(*pgd))
25255 set_pgd(pgd, *pgd_ref);
25256@@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25257 BUG_ON(pgd_page_vaddr(*pgd)
25258 != pgd_page_vaddr(*pgd_ref));
25259
25260+#ifndef CONFIG_PAX_PER_CPU_PGD
25261 spin_unlock(pgt_lock);
25262+#endif
25263+
25264 }
25265 spin_unlock(&pgd_lock);
25266 }
25267@@ -162,7 +176,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25268 {
25269 if (pgd_none(*pgd)) {
25270 pud_t *pud = (pud_t *)spp_getpage();
25271- pgd_populate(&init_mm, pgd, pud);
25272+ pgd_populate_kernel(&init_mm, pgd, pud);
25273 if (pud != pud_offset(pgd, 0))
25274 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25275 pud, pud_offset(pgd, 0));
25276@@ -174,7 +188,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25277 {
25278 if (pud_none(*pud)) {
25279 pmd_t *pmd = (pmd_t *) spp_getpage();
25280- pud_populate(&init_mm, pud, pmd);
25281+ pud_populate_kernel(&init_mm, pud, pmd);
25282 if (pmd != pmd_offset(pud, 0))
25283 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25284 pmd, pmd_offset(pud, 0));
25285@@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25286 pmd = fill_pmd(pud, vaddr);
25287 pte = fill_pte(pmd, vaddr);
25288
25289+ pax_open_kernel();
25290 set_pte(pte, new_pte);
25291+ pax_close_kernel();
25292
25293 /*
25294 * It's enough to flush this one mapping.
25295@@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25296 pgd = pgd_offset_k((unsigned long)__va(phys));
25297 if (pgd_none(*pgd)) {
25298 pud = (pud_t *) spp_getpage();
25299- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25300- _PAGE_USER));
25301+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25302 }
25303 pud = pud_offset(pgd, (unsigned long)__va(phys));
25304 if (pud_none(*pud)) {
25305 pmd = (pmd_t *) spp_getpage();
25306- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25307- _PAGE_USER));
25308+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25309 }
25310 pmd = pmd_offset(pud, phys);
25311 BUG_ON(!pmd_none(*pmd));
25312@@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25313 if (pfn >= pgt_buf_top)
25314 panic("alloc_low_page: ran out of memory");
25315
25316- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25317+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25318 clear_page(adr);
25319 *phys = pfn * PAGE_SIZE;
25320 return adr;
25321@@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
25322
25323 phys = __pa(virt);
25324 left = phys & (PAGE_SIZE - 1);
25325- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25326+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25327 adr = (void *)(((unsigned long)adr) | left);
25328
25329 return adr;
25330@@ -546,7 +560,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25331 unmap_low_page(pmd);
25332
25333 spin_lock(&init_mm.page_table_lock);
25334- pud_populate(&init_mm, pud, __va(pmd_phys));
25335+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25336 spin_unlock(&init_mm.page_table_lock);
25337 }
25338 __flush_tlb_all();
25339@@ -592,7 +606,7 @@ kernel_physical_mapping_init(unsigned long start,
25340 unmap_low_page(pud);
25341
25342 spin_lock(&init_mm.page_table_lock);
25343- pgd_populate(&init_mm, pgd, __va(pud_phys));
25344+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25345 spin_unlock(&init_mm.page_table_lock);
25346 pgd_changed = true;
25347 }
25348@@ -684,6 +698,12 @@ void __init mem_init(void)
25349
25350 pci_iommu_alloc();
25351
25352+#ifdef CONFIG_PAX_PER_CPU_PGD
25353+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25354+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25355+ KERNEL_PGD_PTRS);
25356+#endif
25357+
25358 /* clear_bss() already clear the empty_zero_page */
25359
25360 reservedpages = 0;
25361@@ -844,8 +864,8 @@ int kern_addr_valid(unsigned long addr)
25362 static struct vm_area_struct gate_vma = {
25363 .vm_start = VSYSCALL_START,
25364 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25365- .vm_page_prot = PAGE_READONLY_EXEC,
25366- .vm_flags = VM_READ | VM_EXEC
25367+ .vm_page_prot = PAGE_READONLY,
25368+ .vm_flags = VM_READ
25369 };
25370
25371 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25372@@ -879,7 +899,7 @@ int in_gate_area_no_mm(unsigned long addr)
25373
25374 const char *arch_vma_name(struct vm_area_struct *vma)
25375 {
25376- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25377+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25378 return "[vdso]";
25379 if (vma == &gate_vma)
25380 return "[vsyscall]";
25381diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25382index 7b179b4..6bd1777 100644
25383--- a/arch/x86/mm/iomap_32.c
25384+++ b/arch/x86/mm/iomap_32.c
25385@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25386 type = kmap_atomic_idx_push();
25387 idx = type + KM_TYPE_NR * smp_processor_id();
25388 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25389+
25390+ pax_open_kernel();
25391 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25392+ pax_close_kernel();
25393+
25394 arch_flush_lazy_mmu_mode();
25395
25396 return (void *)vaddr;
25397diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25398index be1ef57..55f0160 100644
25399--- a/arch/x86/mm/ioremap.c
25400+++ b/arch/x86/mm/ioremap.c
25401@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25402 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25403 int is_ram = page_is_ram(pfn);
25404
25405- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25406+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25407 return NULL;
25408 WARN_ON_ONCE(is_ram);
25409 }
25410@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25411
25412 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25413 if (page_is_ram(start >> PAGE_SHIFT))
25414+#ifdef CONFIG_HIGHMEM
25415+ if ((start >> PAGE_SHIFT) < max_low_pfn)
25416+#endif
25417 return __va(phys);
25418
25419 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25420@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25421 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25422
25423 static __initdata int after_paging_init;
25424-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25425+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25426
25427 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25428 {
25429@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25430 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25431
25432 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25433- memset(bm_pte, 0, sizeof(bm_pte));
25434- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25435+ pmd_populate_user(&init_mm, pmd, bm_pte);
25436
25437 /*
25438 * The boot-ioremap range spans multiple pmds, for which
25439diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25440index d87dd6d..bf3fa66 100644
25441--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25442+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25443@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25444 * memory (e.g. tracked pages)? For now, we need this to avoid
25445 * invoking kmemcheck for PnP BIOS calls.
25446 */
25447- if (regs->flags & X86_VM_MASK)
25448+ if (v8086_mode(regs))
25449 return false;
25450- if (regs->cs != __KERNEL_CS)
25451+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25452 return false;
25453
25454 pte = kmemcheck_pte_lookup(address);
25455diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25456index 845df68..1d8d29f 100644
25457--- a/arch/x86/mm/mmap.c
25458+++ b/arch/x86/mm/mmap.c
25459@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25460 * Leave an at least ~128 MB hole with possible stack randomization.
25461 */
25462 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25463-#define MAX_GAP (TASK_SIZE/6*5)
25464+#define MAX_GAP (pax_task_size/6*5)
25465
25466 static int mmap_is_legacy(void)
25467 {
25468@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25469 return rnd << PAGE_SHIFT;
25470 }
25471
25472-static unsigned long mmap_base(void)
25473+static unsigned long mmap_base(struct mm_struct *mm)
25474 {
25475 unsigned long gap = rlimit(RLIMIT_STACK);
25476+ unsigned long pax_task_size = TASK_SIZE;
25477+
25478+#ifdef CONFIG_PAX_SEGMEXEC
25479+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25480+ pax_task_size = SEGMEXEC_TASK_SIZE;
25481+#endif
25482
25483 if (gap < MIN_GAP)
25484 gap = MIN_GAP;
25485 else if (gap > MAX_GAP)
25486 gap = MAX_GAP;
25487
25488- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25489+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25490 }
25491
25492 /*
25493 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25494 * does, but not when emulating X86_32
25495 */
25496-static unsigned long mmap_legacy_base(void)
25497+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25498 {
25499- if (mmap_is_ia32())
25500+ if (mmap_is_ia32()) {
25501+
25502+#ifdef CONFIG_PAX_SEGMEXEC
25503+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25504+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25505+ else
25506+#endif
25507+
25508 return TASK_UNMAPPED_BASE;
25509- else
25510+ } else
25511 return TASK_UNMAPPED_BASE + mmap_rnd();
25512 }
25513
25514@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25515 void arch_pick_mmap_layout(struct mm_struct *mm)
25516 {
25517 if (mmap_is_legacy()) {
25518- mm->mmap_base = mmap_legacy_base();
25519+ mm->mmap_base = mmap_legacy_base(mm);
25520+
25521+#ifdef CONFIG_PAX_RANDMMAP
25522+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25523+ mm->mmap_base += mm->delta_mmap;
25524+#endif
25525+
25526 mm->get_unmapped_area = arch_get_unmapped_area;
25527 mm->unmap_area = arch_unmap_area;
25528 } else {
25529- mm->mmap_base = mmap_base();
25530+ mm->mmap_base = mmap_base(mm);
25531+
25532+#ifdef CONFIG_PAX_RANDMMAP
25533+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25534+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25535+#endif
25536+
25537 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25538 mm->unmap_area = arch_unmap_area_topdown;
25539 }
25540diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25541index dc0b727..dc9d71a 100644
25542--- a/arch/x86/mm/mmio-mod.c
25543+++ b/arch/x86/mm/mmio-mod.c
25544@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25545 break;
25546 default:
25547 {
25548- unsigned char *ip = (unsigned char *)instptr;
25549+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25550 my_trace->opcode = MMIO_UNKNOWN_OP;
25551 my_trace->width = 0;
25552 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25553@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25554 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25555 void __iomem *addr)
25556 {
25557- static atomic_t next_id;
25558+ static atomic_unchecked_t next_id;
25559 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25560 /* These are page-unaligned. */
25561 struct mmiotrace_map map = {
25562@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25563 .private = trace
25564 },
25565 .phys = offset,
25566- .id = atomic_inc_return(&next_id)
25567+ .id = atomic_inc_return_unchecked(&next_id)
25568 };
25569 map.map_id = trace->id;
25570
25571diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25572index b008656..773eac2 100644
25573--- a/arch/x86/mm/pageattr-test.c
25574+++ b/arch/x86/mm/pageattr-test.c
25575@@ -36,7 +36,7 @@ enum {
25576
25577 static int pte_testbit(pte_t pte)
25578 {
25579- return pte_flags(pte) & _PAGE_UNUSED1;
25580+ return pte_flags(pte) & _PAGE_CPA_TEST;
25581 }
25582
25583 struct split_state {
25584diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25585index e1ebde3..b1e1db38 100644
25586--- a/arch/x86/mm/pageattr.c
25587+++ b/arch/x86/mm/pageattr.c
25588@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25589 */
25590 #ifdef CONFIG_PCI_BIOS
25591 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25592- pgprot_val(forbidden) |= _PAGE_NX;
25593+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25594 #endif
25595
25596 /*
25597@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25598 * Does not cover __inittext since that is gone later on. On
25599 * 64bit we do not enforce !NX on the low mapping
25600 */
25601- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25602- pgprot_val(forbidden) |= _PAGE_NX;
25603+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25604+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25605
25606+#ifdef CONFIG_DEBUG_RODATA
25607 /*
25608 * The .rodata section needs to be read-only. Using the pfn
25609 * catches all aliases.
25610@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25611 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25612 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25613 pgprot_val(forbidden) |= _PAGE_RW;
25614+#endif
25615
25616 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25617 /*
25618@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25619 }
25620 #endif
25621
25622+#ifdef CONFIG_PAX_KERNEXEC
25623+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25624+ pgprot_val(forbidden) |= _PAGE_RW;
25625+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25626+ }
25627+#endif
25628+
25629 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25630
25631 return prot;
25632@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25633 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25634 {
25635 /* change init_mm */
25636+ pax_open_kernel();
25637 set_pte_atomic(kpte, pte);
25638+
25639 #ifdef CONFIG_X86_32
25640 if (!SHARED_KERNEL_PMD) {
25641+
25642+#ifdef CONFIG_PAX_PER_CPU_PGD
25643+ unsigned long cpu;
25644+#else
25645 struct page *page;
25646+#endif
25647
25648+#ifdef CONFIG_PAX_PER_CPU_PGD
25649+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25650+ pgd_t *pgd = get_cpu_pgd(cpu);
25651+#else
25652 list_for_each_entry(page, &pgd_list, lru) {
25653- pgd_t *pgd;
25654+ pgd_t *pgd = (pgd_t *)page_address(page);
25655+#endif
25656+
25657 pud_t *pud;
25658 pmd_t *pmd;
25659
25660- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25661+ pgd += pgd_index(address);
25662 pud = pud_offset(pgd, address);
25663 pmd = pmd_offset(pud, address);
25664 set_pte_atomic((pte_t *)pmd, pte);
25665 }
25666 }
25667 #endif
25668+ pax_close_kernel();
25669 }
25670
25671 static int
25672diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25673index f6ff57b..481690f 100644
25674--- a/arch/x86/mm/pat.c
25675+++ b/arch/x86/mm/pat.c
25676@@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
25677
25678 if (!entry) {
25679 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25680- current->comm, current->pid, start, end);
25681+ current->comm, task_pid_nr(current), start, end);
25682 return -EINVAL;
25683 }
25684
25685@@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25686 while (cursor < to) {
25687 if (!devmem_is_allowed(pfn)) {
25688 printk(KERN_INFO
25689- "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25690- current->comm, from, to);
25691+ "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25692+ current->comm, from, to, cursor);
25693 return 0;
25694 }
25695 cursor += PAGE_SIZE;
25696@@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25697 printk(KERN_INFO
25698 "%s:%d ioremap_change_attr failed %s "
25699 "for %Lx-%Lx\n",
25700- current->comm, current->pid,
25701+ current->comm, task_pid_nr(current),
25702 cattr_name(flags),
25703 base, (unsigned long long)(base + size));
25704 return -EINVAL;
25705@@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25706 if (want_flags != flags) {
25707 printk(KERN_WARNING
25708 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
25709- current->comm, current->pid,
25710+ current->comm, task_pid_nr(current),
25711 cattr_name(want_flags),
25712 (unsigned long long)paddr,
25713 (unsigned long long)(paddr + size),
25714@@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25715 free_memtype(paddr, paddr + size);
25716 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25717 " for %Lx-%Lx, got %s\n",
25718- current->comm, current->pid,
25719+ current->comm, task_pid_nr(current),
25720 cattr_name(want_flags),
25721 (unsigned long long)paddr,
25722 (unsigned long long)(paddr + size),
25723diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25724index 9f0614d..92ae64a 100644
25725--- a/arch/x86/mm/pf_in.c
25726+++ b/arch/x86/mm/pf_in.c
25727@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25728 int i;
25729 enum reason_type rv = OTHERS;
25730
25731- p = (unsigned char *)ins_addr;
25732+ p = (unsigned char *)ktla_ktva(ins_addr);
25733 p += skip_prefix(p, &prf);
25734 p += get_opcode(p, &opcode);
25735
25736@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25737 struct prefix_bits prf;
25738 int i;
25739
25740- p = (unsigned char *)ins_addr;
25741+ p = (unsigned char *)ktla_ktva(ins_addr);
25742 p += skip_prefix(p, &prf);
25743 p += get_opcode(p, &opcode);
25744
25745@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25746 struct prefix_bits prf;
25747 int i;
25748
25749- p = (unsigned char *)ins_addr;
25750+ p = (unsigned char *)ktla_ktva(ins_addr);
25751 p += skip_prefix(p, &prf);
25752 p += get_opcode(p, &opcode);
25753
25754@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25755 struct prefix_bits prf;
25756 int i;
25757
25758- p = (unsigned char *)ins_addr;
25759+ p = (unsigned char *)ktla_ktva(ins_addr);
25760 p += skip_prefix(p, &prf);
25761 p += get_opcode(p, &opcode);
25762 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25763@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25764 struct prefix_bits prf;
25765 int i;
25766
25767- p = (unsigned char *)ins_addr;
25768+ p = (unsigned char *)ktla_ktva(ins_addr);
25769 p += skip_prefix(p, &prf);
25770 p += get_opcode(p, &opcode);
25771 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25772diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25773index 8573b83..4f3ed7e 100644
25774--- a/arch/x86/mm/pgtable.c
25775+++ b/arch/x86/mm/pgtable.c
25776@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25777 list_del(&page->lru);
25778 }
25779
25780-#define UNSHARED_PTRS_PER_PGD \
25781- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25782+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25783+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25784
25785+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25786+{
25787+ unsigned int count = USER_PGD_PTRS;
25788
25789+ while (count--)
25790+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25791+}
25792+#endif
25793+
25794+#ifdef CONFIG_PAX_PER_CPU_PGD
25795+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25796+{
25797+ unsigned int count = USER_PGD_PTRS;
25798+
25799+ while (count--) {
25800+ pgd_t pgd;
25801+
25802+#ifdef CONFIG_X86_64
25803+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25804+#else
25805+ pgd = *src++;
25806+#endif
25807+
25808+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25809+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25810+#endif
25811+
25812+ *dst++ = pgd;
25813+ }
25814+
25815+}
25816+#endif
25817+
25818+#ifdef CONFIG_X86_64
25819+#define pxd_t pud_t
25820+#define pyd_t pgd_t
25821+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25822+#define pxd_free(mm, pud) pud_free((mm), (pud))
25823+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25824+#define pyd_offset(mm, address) pgd_offset((mm), (address))
25825+#define PYD_SIZE PGDIR_SIZE
25826+#else
25827+#define pxd_t pmd_t
25828+#define pyd_t pud_t
25829+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25830+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25831+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25832+#define pyd_offset(mm, address) pud_offset((mm), (address))
25833+#define PYD_SIZE PUD_SIZE
25834+#endif
25835+
25836+#ifdef CONFIG_PAX_PER_CPU_PGD
25837+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25838+static inline void pgd_dtor(pgd_t *pgd) {}
25839+#else
25840 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25841 {
25842 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25843@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25844 pgd_list_del(pgd);
25845 spin_unlock(&pgd_lock);
25846 }
25847+#endif
25848
25849 /*
25850 * List of all pgd's needed for non-PAE so it can invalidate entries
25851@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25852 * -- wli
25853 */
25854
25855-#ifdef CONFIG_X86_PAE
25856+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25857 /*
25858 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25859 * updating the top-level pagetable entries to guarantee the
25860@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25861 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25862 * and initialize the kernel pmds here.
25863 */
25864-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25865+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25866
25867 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25868 {
25869@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25870 */
25871 flush_tlb_mm(mm);
25872 }
25873+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25874+#define PREALLOCATED_PXDS USER_PGD_PTRS
25875 #else /* !CONFIG_X86_PAE */
25876
25877 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25878-#define PREALLOCATED_PMDS 0
25879+#define PREALLOCATED_PXDS 0
25880
25881 #endif /* CONFIG_X86_PAE */
25882
25883-static void free_pmds(pmd_t *pmds[])
25884+static void free_pxds(pxd_t *pxds[])
25885 {
25886 int i;
25887
25888- for(i = 0; i < PREALLOCATED_PMDS; i++)
25889- if (pmds[i])
25890- free_page((unsigned long)pmds[i]);
25891+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25892+ if (pxds[i])
25893+ free_page((unsigned long)pxds[i]);
25894 }
25895
25896-static int preallocate_pmds(pmd_t *pmds[])
25897+static int preallocate_pxds(pxd_t *pxds[])
25898 {
25899 int i;
25900 bool failed = false;
25901
25902- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25903- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25904- if (pmd == NULL)
25905+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25906+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25907+ if (pxd == NULL)
25908 failed = true;
25909- pmds[i] = pmd;
25910+ pxds[i] = pxd;
25911 }
25912
25913 if (failed) {
25914- free_pmds(pmds);
25915+ free_pxds(pxds);
25916 return -ENOMEM;
25917 }
25918
25919@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25920 * preallocate which never got a corresponding vma will need to be
25921 * freed manually.
25922 */
25923-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25924+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25925 {
25926 int i;
25927
25928- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25929+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25930 pgd_t pgd = pgdp[i];
25931
25932 if (pgd_val(pgd) != 0) {
25933- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25934+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25935
25936- pgdp[i] = native_make_pgd(0);
25937+ set_pgd(pgdp + i, native_make_pgd(0));
25938
25939- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25940- pmd_free(mm, pmd);
25941+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25942+ pxd_free(mm, pxd);
25943 }
25944 }
25945 }
25946
25947-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25948+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25949 {
25950- pud_t *pud;
25951+ pyd_t *pyd;
25952 unsigned long addr;
25953 int i;
25954
25955- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25956+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25957 return;
25958
25959- pud = pud_offset(pgd, 0);
25960+#ifdef CONFIG_X86_64
25961+ pyd = pyd_offset(mm, 0L);
25962+#else
25963+ pyd = pyd_offset(pgd, 0L);
25964+#endif
25965
25966- for (addr = i = 0; i < PREALLOCATED_PMDS;
25967- i++, pud++, addr += PUD_SIZE) {
25968- pmd_t *pmd = pmds[i];
25969+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25970+ i++, pyd++, addr += PYD_SIZE) {
25971+ pxd_t *pxd = pxds[i];
25972
25973 if (i >= KERNEL_PGD_BOUNDARY)
25974- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25975- sizeof(pmd_t) * PTRS_PER_PMD);
25976+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25977+ sizeof(pxd_t) * PTRS_PER_PMD);
25978
25979- pud_populate(mm, pud, pmd);
25980+ pyd_populate(mm, pyd, pxd);
25981 }
25982 }
25983
25984 pgd_t *pgd_alloc(struct mm_struct *mm)
25985 {
25986 pgd_t *pgd;
25987- pmd_t *pmds[PREALLOCATED_PMDS];
25988+ pxd_t *pxds[PREALLOCATED_PXDS];
25989
25990 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25991
25992@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25993
25994 mm->pgd = pgd;
25995
25996- if (preallocate_pmds(pmds) != 0)
25997+ if (preallocate_pxds(pxds) != 0)
25998 goto out_free_pgd;
25999
26000 if (paravirt_pgd_alloc(mm) != 0)
26001- goto out_free_pmds;
26002+ goto out_free_pxds;
26003
26004 /*
26005 * Make sure that pre-populating the pmds is atomic with
26006@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
26007 spin_lock(&pgd_lock);
26008
26009 pgd_ctor(mm, pgd);
26010- pgd_prepopulate_pmd(mm, pgd, pmds);
26011+ pgd_prepopulate_pxd(mm, pgd, pxds);
26012
26013 spin_unlock(&pgd_lock);
26014
26015 return pgd;
26016
26017-out_free_pmds:
26018- free_pmds(pmds);
26019+out_free_pxds:
26020+ free_pxds(pxds);
26021 out_free_pgd:
26022 free_page((unsigned long)pgd);
26023 out:
26024@@ -295,7 +356,7 @@ out:
26025
26026 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
26027 {
26028- pgd_mop_up_pmds(mm, pgd);
26029+ pgd_mop_up_pxds(mm, pgd);
26030 pgd_dtor(pgd);
26031 paravirt_pgd_free(mm, pgd);
26032 free_page((unsigned long)pgd);
26033diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
26034index cac7184..09a39fa 100644
26035--- a/arch/x86/mm/pgtable_32.c
26036+++ b/arch/x86/mm/pgtable_32.c
26037@@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
26038 return;
26039 }
26040 pte = pte_offset_kernel(pmd, vaddr);
26041+
26042+ pax_open_kernel();
26043 if (pte_val(pteval))
26044 set_pte_at(&init_mm, vaddr, pte, pteval);
26045 else
26046 pte_clear(&init_mm, vaddr, pte);
26047+ pax_close_kernel();
26048
26049 /*
26050 * It's enough to flush this one mapping.
26051diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
26052index 410531d..0f16030 100644
26053--- a/arch/x86/mm/setup_nx.c
26054+++ b/arch/x86/mm/setup_nx.c
26055@@ -5,8 +5,10 @@
26056 #include <asm/pgtable.h>
26057 #include <asm/proto.h>
26058
26059+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26060 static int disable_nx __cpuinitdata;
26061
26062+#ifndef CONFIG_PAX_PAGEEXEC
26063 /*
26064 * noexec = on|off
26065 *
26066@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
26067 return 0;
26068 }
26069 early_param("noexec", noexec_setup);
26070+#endif
26071+
26072+#endif
26073
26074 void __cpuinit x86_configure_nx(void)
26075 {
26076+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26077 if (cpu_has_nx && !disable_nx)
26078 __supported_pte_mask |= _PAGE_NX;
26079 else
26080+#endif
26081 __supported_pte_mask &= ~_PAGE_NX;
26082 }
26083
26084diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
26085index d6c0418..06a0ad5 100644
26086--- a/arch/x86/mm/tlb.c
26087+++ b/arch/x86/mm/tlb.c
26088@@ -65,7 +65,11 @@ void leave_mm(int cpu)
26089 BUG();
26090 cpumask_clear_cpu(cpu,
26091 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
26092+
26093+#ifndef CONFIG_PAX_PER_CPU_PGD
26094 load_cr3(swapper_pg_dir);
26095+#endif
26096+
26097 }
26098 EXPORT_SYMBOL_GPL(leave_mm);
26099
26100diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
26101index 6687022..ceabcfa 100644
26102--- a/arch/x86/net/bpf_jit.S
26103+++ b/arch/x86/net/bpf_jit.S
26104@@ -9,6 +9,7 @@
26105 */
26106 #include <linux/linkage.h>
26107 #include <asm/dwarf2.h>
26108+#include <asm/alternative-asm.h>
26109
26110 /*
26111 * Calling convention :
26112@@ -35,6 +36,7 @@ sk_load_word:
26113 jle bpf_slow_path_word
26114 mov (SKBDATA,%rsi),%eax
26115 bswap %eax /* ntohl() */
26116+ pax_force_retaddr
26117 ret
26118
26119
26120@@ -53,6 +55,7 @@ sk_load_half:
26121 jle bpf_slow_path_half
26122 movzwl (SKBDATA,%rsi),%eax
26123 rol $8,%ax # ntohs()
26124+ pax_force_retaddr
26125 ret
26126
26127 sk_load_byte_ind:
26128@@ -66,6 +69,7 @@ sk_load_byte:
26129 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
26130 jle bpf_slow_path_byte
26131 movzbl (SKBDATA,%rsi),%eax
26132+ pax_force_retaddr
26133 ret
26134
26135 /**
26136@@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
26137 movzbl (SKBDATA,%rsi),%ebx
26138 and $15,%bl
26139 shl $2,%bl
26140+ pax_force_retaddr
26141 ret
26142 CFI_ENDPROC
26143 ENDPROC(sk_load_byte_msh)
26144@@ -91,6 +96,7 @@ bpf_error:
26145 xor %eax,%eax
26146 mov -8(%rbp),%rbx
26147 leaveq
26148+ pax_force_retaddr
26149 ret
26150
26151 /* rsi contains offset and can be scratched */
26152@@ -113,6 +119,7 @@ bpf_slow_path_word:
26153 js bpf_error
26154 mov -12(%rbp),%eax
26155 bswap %eax
26156+ pax_force_retaddr
26157 ret
26158
26159 bpf_slow_path_half:
26160@@ -121,12 +128,14 @@ bpf_slow_path_half:
26161 mov -12(%rbp),%ax
26162 rol $8,%ax
26163 movzwl %ax,%eax
26164+ pax_force_retaddr
26165 ret
26166
26167 bpf_slow_path_byte:
26168 bpf_slow_path_common(1)
26169 js bpf_error
26170 movzbl -12(%rbp),%eax
26171+ pax_force_retaddr
26172 ret
26173
26174 bpf_slow_path_byte_msh:
26175@@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
26176 and $15,%al
26177 shl $2,%al
26178 xchg %eax,%ebx
26179+ pax_force_retaddr
26180 ret
26181diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26182index 5a5b6e4..201d42e 100644
26183--- a/arch/x86/net/bpf_jit_comp.c
26184+++ b/arch/x86/net/bpf_jit_comp.c
26185@@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
26186 set_fs(old_fs);
26187 }
26188
26189+struct bpf_jit_work {
26190+ struct work_struct work;
26191+ void *image;
26192+};
26193
26194 void bpf_jit_compile(struct sk_filter *fp)
26195 {
26196@@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26197 if (addrs == NULL)
26198 return;
26199
26200+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26201+ if (!fp->work)
26202+ goto out;
26203+
26204 /* Before first pass, make a rough estimation of addrs[]
26205 * each bpf instruction is translated to less than 64 bytes
26206 */
26207@@ -477,7 +485,7 @@ void bpf_jit_compile(struct sk_filter *fp)
26208 common_load: seen |= SEEN_DATAREF;
26209 if ((int)K < 0) {
26210 /* Abort the JIT because __load_pointer() is needed. */
26211- goto out;
26212+ goto error;
26213 }
26214 t_offset = func - (image + addrs[i]);
26215 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
26216@@ -492,7 +500,7 @@ common_load: seen |= SEEN_DATAREF;
26217 case BPF_S_LDX_B_MSH:
26218 if ((int)K < 0) {
26219 /* Abort the JIT because __load_pointer() is needed. */
26220- goto out;
26221+ goto error;
26222 }
26223 seen |= SEEN_DATAREF | SEEN_XREG;
26224 t_offset = sk_load_byte_msh - (image + addrs[i]);
26225@@ -582,17 +590,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26226 break;
26227 default:
26228 /* hmm, too complex filter, give up with jit compiler */
26229- goto out;
26230+ goto error;
26231 }
26232 ilen = prog - temp;
26233 if (image) {
26234 if (unlikely(proglen + ilen > oldproglen)) {
26235 pr_err("bpb_jit_compile fatal error\n");
26236- kfree(addrs);
26237- module_free(NULL, image);
26238- return;
26239+ module_free_exec(NULL, image);
26240+ goto error;
26241 }
26242+ pax_open_kernel();
26243 memcpy(image + proglen, temp, ilen);
26244+ pax_close_kernel();
26245 }
26246 proglen += ilen;
26247 addrs[i] = proglen;
26248@@ -613,11 +622,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26249 break;
26250 }
26251 if (proglen == oldproglen) {
26252- image = module_alloc(max_t(unsigned int,
26253- proglen,
26254- sizeof(struct work_struct)));
26255+ image = module_alloc_exec(proglen);
26256 if (!image)
26257- goto out;
26258+ goto error;
26259 }
26260 oldproglen = proglen;
26261 }
26262@@ -633,7 +640,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26263 bpf_flush_icache(image, image + proglen);
26264
26265 fp->bpf_func = (void *)image;
26266- }
26267+ } else
26268+error:
26269+ kfree(fp->work);
26270+
26271 out:
26272 kfree(addrs);
26273 return;
26274@@ -641,18 +651,20 @@ out:
26275
26276 static void jit_free_defer(struct work_struct *arg)
26277 {
26278- module_free(NULL, arg);
26279+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26280+ kfree(arg);
26281 }
26282
26283 /* run from softirq, we must use a work_struct to call
26284- * module_free() from process context
26285+ * module_free_exec() from process context
26286 */
26287 void bpf_jit_free(struct sk_filter *fp)
26288 {
26289 if (fp->bpf_func != sk_run_filter) {
26290- struct work_struct *work = (struct work_struct *)fp->bpf_func;
26291+ struct work_struct *work = &fp->work->work;
26292
26293 INIT_WORK(work, jit_free_defer);
26294+ fp->work->image = fp->bpf_func;
26295 schedule_work(work);
26296 }
26297 }
26298diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26299index bff89df..377758a 100644
26300--- a/arch/x86/oprofile/backtrace.c
26301+++ b/arch/x86/oprofile/backtrace.c
26302@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26303 struct stack_frame_ia32 *fp;
26304 unsigned long bytes;
26305
26306- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26307+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26308 if (bytes != sizeof(bufhead))
26309 return NULL;
26310
26311- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26312+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26313
26314 oprofile_add_trace(bufhead[0].return_address);
26315
26316@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26317 struct stack_frame bufhead[2];
26318 unsigned long bytes;
26319
26320- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26321+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26322 if (bytes != sizeof(bufhead))
26323 return NULL;
26324
26325@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26326 {
26327 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26328
26329- if (!user_mode_vm(regs)) {
26330+ if (!user_mode(regs)) {
26331 unsigned long stack = kernel_stack_pointer(regs);
26332 if (depth)
26333 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26334diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26335index cb29191..036766d 100644
26336--- a/arch/x86/pci/mrst.c
26337+++ b/arch/x86/pci/mrst.c
26338@@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
26339 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
26340 pci_mmcfg_late_init();
26341 pcibios_enable_irq = mrst_pci_irq_enable;
26342- pci_root_ops = pci_mrst_ops;
26343+ pax_open_kernel();
26344+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26345+ pax_close_kernel();
26346 /* Continue with standard init */
26347 return 1;
26348 }
26349diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26350index da8fe05..7ee6704 100644
26351--- a/arch/x86/pci/pcbios.c
26352+++ b/arch/x86/pci/pcbios.c
26353@@ -79,50 +79,93 @@ union bios32 {
26354 static struct {
26355 unsigned long address;
26356 unsigned short segment;
26357-} bios32_indirect = { 0, __KERNEL_CS };
26358+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26359
26360 /*
26361 * Returns the entry point for the given service, NULL on error
26362 */
26363
26364-static unsigned long bios32_service(unsigned long service)
26365+static unsigned long __devinit bios32_service(unsigned long service)
26366 {
26367 unsigned char return_code; /* %al */
26368 unsigned long address; /* %ebx */
26369 unsigned long length; /* %ecx */
26370 unsigned long entry; /* %edx */
26371 unsigned long flags;
26372+ struct desc_struct d, *gdt;
26373
26374 local_irq_save(flags);
26375- __asm__("lcall *(%%edi); cld"
26376+
26377+ gdt = get_cpu_gdt_table(smp_processor_id());
26378+
26379+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26380+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26381+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26382+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26383+
26384+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26385 : "=a" (return_code),
26386 "=b" (address),
26387 "=c" (length),
26388 "=d" (entry)
26389 : "0" (service),
26390 "1" (0),
26391- "D" (&bios32_indirect));
26392+ "D" (&bios32_indirect),
26393+ "r"(__PCIBIOS_DS)
26394+ : "memory");
26395+
26396+ pax_open_kernel();
26397+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26398+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26399+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26400+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26401+ pax_close_kernel();
26402+
26403 local_irq_restore(flags);
26404
26405 switch (return_code) {
26406- case 0:
26407- return address + entry;
26408- case 0x80: /* Not present */
26409- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26410- return 0;
26411- default: /* Shouldn't happen */
26412- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26413- service, return_code);
26414+ case 0: {
26415+ int cpu;
26416+ unsigned char flags;
26417+
26418+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26419+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26420+ printk(KERN_WARNING "bios32_service: not valid\n");
26421 return 0;
26422+ }
26423+ address = address + PAGE_OFFSET;
26424+ length += 16UL; /* some BIOSs underreport this... */
26425+ flags = 4;
26426+ if (length >= 64*1024*1024) {
26427+ length >>= PAGE_SHIFT;
26428+ flags |= 8;
26429+ }
26430+
26431+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26432+ gdt = get_cpu_gdt_table(cpu);
26433+ pack_descriptor(&d, address, length, 0x9b, flags);
26434+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26435+ pack_descriptor(&d, address, length, 0x93, flags);
26436+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26437+ }
26438+ return entry;
26439+ }
26440+ case 0x80: /* Not present */
26441+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26442+ return 0;
26443+ default: /* Shouldn't happen */
26444+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26445+ service, return_code);
26446+ return 0;
26447 }
26448 }
26449
26450 static struct {
26451 unsigned long address;
26452 unsigned short segment;
26453-} pci_indirect = { 0, __KERNEL_CS };
26454+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26455
26456-static int pci_bios_present;
26457+static int pci_bios_present __read_only;
26458
26459 static int __devinit check_pcibios(void)
26460 {
26461@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26462 unsigned long flags, pcibios_entry;
26463
26464 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26465- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26466+ pci_indirect.address = pcibios_entry;
26467
26468 local_irq_save(flags);
26469- __asm__(
26470- "lcall *(%%edi); cld\n\t"
26471+ __asm__("movw %w6, %%ds\n\t"
26472+ "lcall *%%ss:(%%edi); cld\n\t"
26473+ "push %%ss\n\t"
26474+ "pop %%ds\n\t"
26475 "jc 1f\n\t"
26476 "xor %%ah, %%ah\n"
26477 "1:"
26478@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26479 "=b" (ebx),
26480 "=c" (ecx)
26481 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26482- "D" (&pci_indirect)
26483+ "D" (&pci_indirect),
26484+ "r" (__PCIBIOS_DS)
26485 : "memory");
26486 local_irq_restore(flags);
26487
26488@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26489
26490 switch (len) {
26491 case 1:
26492- __asm__("lcall *(%%esi); cld\n\t"
26493+ __asm__("movw %w6, %%ds\n\t"
26494+ "lcall *%%ss:(%%esi); cld\n\t"
26495+ "push %%ss\n\t"
26496+ "pop %%ds\n\t"
26497 "jc 1f\n\t"
26498 "xor %%ah, %%ah\n"
26499 "1:"
26500@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26501 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26502 "b" (bx),
26503 "D" ((long)reg),
26504- "S" (&pci_indirect));
26505+ "S" (&pci_indirect),
26506+ "r" (__PCIBIOS_DS));
26507 /*
26508 * Zero-extend the result beyond 8 bits, do not trust the
26509 * BIOS having done it:
26510@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26511 *value &= 0xff;
26512 break;
26513 case 2:
26514- __asm__("lcall *(%%esi); cld\n\t"
26515+ __asm__("movw %w6, %%ds\n\t"
26516+ "lcall *%%ss:(%%esi); cld\n\t"
26517+ "push %%ss\n\t"
26518+ "pop %%ds\n\t"
26519 "jc 1f\n\t"
26520 "xor %%ah, %%ah\n"
26521 "1:"
26522@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26523 : "1" (PCIBIOS_READ_CONFIG_WORD),
26524 "b" (bx),
26525 "D" ((long)reg),
26526- "S" (&pci_indirect));
26527+ "S" (&pci_indirect),
26528+ "r" (__PCIBIOS_DS));
26529 /*
26530 * Zero-extend the result beyond 16 bits, do not trust the
26531 * BIOS having done it:
26532@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26533 *value &= 0xffff;
26534 break;
26535 case 4:
26536- __asm__("lcall *(%%esi); cld\n\t"
26537+ __asm__("movw %w6, %%ds\n\t"
26538+ "lcall *%%ss:(%%esi); cld\n\t"
26539+ "push %%ss\n\t"
26540+ "pop %%ds\n\t"
26541 "jc 1f\n\t"
26542 "xor %%ah, %%ah\n"
26543 "1:"
26544@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26545 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26546 "b" (bx),
26547 "D" ((long)reg),
26548- "S" (&pci_indirect));
26549+ "S" (&pci_indirect),
26550+ "r" (__PCIBIOS_DS));
26551 break;
26552 }
26553
26554@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26555
26556 switch (len) {
26557 case 1:
26558- __asm__("lcall *(%%esi); cld\n\t"
26559+ __asm__("movw %w6, %%ds\n\t"
26560+ "lcall *%%ss:(%%esi); cld\n\t"
26561+ "push %%ss\n\t"
26562+ "pop %%ds\n\t"
26563 "jc 1f\n\t"
26564 "xor %%ah, %%ah\n"
26565 "1:"
26566@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26567 "c" (value),
26568 "b" (bx),
26569 "D" ((long)reg),
26570- "S" (&pci_indirect));
26571+ "S" (&pci_indirect),
26572+ "r" (__PCIBIOS_DS));
26573 break;
26574 case 2:
26575- __asm__("lcall *(%%esi); cld\n\t"
26576+ __asm__("movw %w6, %%ds\n\t"
26577+ "lcall *%%ss:(%%esi); cld\n\t"
26578+ "push %%ss\n\t"
26579+ "pop %%ds\n\t"
26580 "jc 1f\n\t"
26581 "xor %%ah, %%ah\n"
26582 "1:"
26583@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26584 "c" (value),
26585 "b" (bx),
26586 "D" ((long)reg),
26587- "S" (&pci_indirect));
26588+ "S" (&pci_indirect),
26589+ "r" (__PCIBIOS_DS));
26590 break;
26591 case 4:
26592- __asm__("lcall *(%%esi); cld\n\t"
26593+ __asm__("movw %w6, %%ds\n\t"
26594+ "lcall *%%ss:(%%esi); cld\n\t"
26595+ "push %%ss\n\t"
26596+ "pop %%ds\n\t"
26597 "jc 1f\n\t"
26598 "xor %%ah, %%ah\n"
26599 "1:"
26600@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26601 "c" (value),
26602 "b" (bx),
26603 "D" ((long)reg),
26604- "S" (&pci_indirect));
26605+ "S" (&pci_indirect),
26606+ "r" (__PCIBIOS_DS));
26607 break;
26608 }
26609
26610@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26611
26612 DBG("PCI: Fetching IRQ routing table... ");
26613 __asm__("push %%es\n\t"
26614+ "movw %w8, %%ds\n\t"
26615 "push %%ds\n\t"
26616 "pop %%es\n\t"
26617- "lcall *(%%esi); cld\n\t"
26618+ "lcall *%%ss:(%%esi); cld\n\t"
26619 "pop %%es\n\t"
26620+ "push %%ss\n\t"
26621+ "pop %%ds\n"
26622 "jc 1f\n\t"
26623 "xor %%ah, %%ah\n"
26624 "1:"
26625@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26626 "1" (0),
26627 "D" ((long) &opt),
26628 "S" (&pci_indirect),
26629- "m" (opt)
26630+ "m" (opt),
26631+ "r" (__PCIBIOS_DS)
26632 : "memory");
26633 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26634 if (ret & 0xff00)
26635@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26636 {
26637 int ret;
26638
26639- __asm__("lcall *(%%esi); cld\n\t"
26640+ __asm__("movw %w5, %%ds\n\t"
26641+ "lcall *%%ss:(%%esi); cld\n\t"
26642+ "push %%ss\n\t"
26643+ "pop %%ds\n"
26644 "jc 1f\n\t"
26645 "xor %%ah, %%ah\n"
26646 "1:"
26647@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26648 : "0" (PCIBIOS_SET_PCI_HW_INT),
26649 "b" ((dev->bus->number << 8) | dev->devfn),
26650 "c" ((irq << 8) | (pin + 10)),
26651- "S" (&pci_indirect));
26652+ "S" (&pci_indirect),
26653+ "r" (__PCIBIOS_DS));
26654 return !(ret & 0xff00);
26655 }
26656 EXPORT_SYMBOL(pcibios_set_irq_routing);
26657diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26658index 40e4469..1ab536e 100644
26659--- a/arch/x86/platform/efi/efi_32.c
26660+++ b/arch/x86/platform/efi/efi_32.c
26661@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26662 {
26663 struct desc_ptr gdt_descr;
26664
26665+#ifdef CONFIG_PAX_KERNEXEC
26666+ struct desc_struct d;
26667+#endif
26668+
26669 local_irq_save(efi_rt_eflags);
26670
26671 load_cr3(initial_page_table);
26672 __flush_tlb_all();
26673
26674+#ifdef CONFIG_PAX_KERNEXEC
26675+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26676+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26677+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26678+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26679+#endif
26680+
26681 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26682 gdt_descr.size = GDT_SIZE - 1;
26683 load_gdt(&gdt_descr);
26684@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26685 {
26686 struct desc_ptr gdt_descr;
26687
26688+#ifdef CONFIG_PAX_KERNEXEC
26689+ struct desc_struct d;
26690+
26691+ memset(&d, 0, sizeof d);
26692+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26693+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26694+#endif
26695+
26696 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26697 gdt_descr.size = GDT_SIZE - 1;
26698 load_gdt(&gdt_descr);
26699diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26700index fbe66e6..c5c0dd2 100644
26701--- a/arch/x86/platform/efi/efi_stub_32.S
26702+++ b/arch/x86/platform/efi/efi_stub_32.S
26703@@ -6,7 +6,9 @@
26704 */
26705
26706 #include <linux/linkage.h>
26707+#include <linux/init.h>
26708 #include <asm/page_types.h>
26709+#include <asm/segment.h>
26710
26711 /*
26712 * efi_call_phys(void *, ...) is a function with variable parameters.
26713@@ -20,7 +22,7 @@
26714 * service functions will comply with gcc calling convention, too.
26715 */
26716
26717-.text
26718+__INIT
26719 ENTRY(efi_call_phys)
26720 /*
26721 * 0. The function can only be called in Linux kernel. So CS has been
26722@@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26723 * The mapping of lower virtual memory has been created in prelog and
26724 * epilog.
26725 */
26726- movl $1f, %edx
26727- subl $__PAGE_OFFSET, %edx
26728- jmp *%edx
26729+ movl $(__KERNEXEC_EFI_DS), %edx
26730+ mov %edx, %ds
26731+ mov %edx, %es
26732+ mov %edx, %ss
26733+ ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26734 1:
26735
26736 /*
26737@@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26738 * parameter 2, ..., param n. To make things easy, we save the return
26739 * address of efi_call_phys in a global variable.
26740 */
26741- popl %edx
26742- movl %edx, saved_return_addr
26743- /* get the function pointer into ECX*/
26744- popl %ecx
26745- movl %ecx, efi_rt_function_ptr
26746- movl $2f, %edx
26747- subl $__PAGE_OFFSET, %edx
26748- pushl %edx
26749+ popl (saved_return_addr)
26750+ popl (efi_rt_function_ptr)
26751
26752 /*
26753 * 3. Clear PG bit in %CR0.
26754@@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
26755 /*
26756 * 5. Call the physical function.
26757 */
26758- jmp *%ecx
26759+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
26760
26761-2:
26762 /*
26763 * 6. After EFI runtime service returns, control will return to
26764 * following instruction. We'd better readjust stack pointer first.
26765@@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
26766 movl %cr0, %edx
26767 orl $0x80000000, %edx
26768 movl %edx, %cr0
26769- jmp 1f
26770-1:
26771+
26772 /*
26773 * 8. Now restore the virtual mode from flat mode by
26774 * adding EIP with PAGE_OFFSET.
26775 */
26776- movl $1f, %edx
26777- jmp *%edx
26778+ ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
26779 1:
26780+ movl $(__KERNEL_DS), %edx
26781+ mov %edx, %ds
26782+ mov %edx, %es
26783+ mov %edx, %ss
26784
26785 /*
26786 * 9. Balance the stack. And because EAX contain the return value,
26787 * we'd better not clobber it.
26788 */
26789- leal efi_rt_function_ptr, %edx
26790- movl (%edx), %ecx
26791- pushl %ecx
26792+ pushl (efi_rt_function_ptr)
26793
26794 /*
26795- * 10. Push the saved return address onto the stack and return.
26796+ * 10. Return to the saved return address.
26797 */
26798- leal saved_return_addr, %edx
26799- movl (%edx), %ecx
26800- pushl %ecx
26801- ret
26802+ jmpl *(saved_return_addr)
26803 ENDPROC(efi_call_phys)
26804 .previous
26805
26806-.data
26807+__INITDATA
26808 saved_return_addr:
26809 .long 0
26810 efi_rt_function_ptr:
26811diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26812index 4c07cca..2c8427d 100644
26813--- a/arch/x86/platform/efi/efi_stub_64.S
26814+++ b/arch/x86/platform/efi/efi_stub_64.S
26815@@ -7,6 +7,7 @@
26816 */
26817
26818 #include <linux/linkage.h>
26819+#include <asm/alternative-asm.h>
26820
26821 #define SAVE_XMM \
26822 mov %rsp, %rax; \
26823@@ -40,6 +41,7 @@ ENTRY(efi_call0)
26824 call *%rdi
26825 addq $32, %rsp
26826 RESTORE_XMM
26827+ pax_force_retaddr 0, 1
26828 ret
26829 ENDPROC(efi_call0)
26830
26831@@ -50,6 +52,7 @@ ENTRY(efi_call1)
26832 call *%rdi
26833 addq $32, %rsp
26834 RESTORE_XMM
26835+ pax_force_retaddr 0, 1
26836 ret
26837 ENDPROC(efi_call1)
26838
26839@@ -60,6 +63,7 @@ ENTRY(efi_call2)
26840 call *%rdi
26841 addq $32, %rsp
26842 RESTORE_XMM
26843+ pax_force_retaddr 0, 1
26844 ret
26845 ENDPROC(efi_call2)
26846
26847@@ -71,6 +75,7 @@ ENTRY(efi_call3)
26848 call *%rdi
26849 addq $32, %rsp
26850 RESTORE_XMM
26851+ pax_force_retaddr 0, 1
26852 ret
26853 ENDPROC(efi_call3)
26854
26855@@ -83,6 +88,7 @@ ENTRY(efi_call4)
26856 call *%rdi
26857 addq $32, %rsp
26858 RESTORE_XMM
26859+ pax_force_retaddr 0, 1
26860 ret
26861 ENDPROC(efi_call4)
26862
26863@@ -96,6 +102,7 @@ ENTRY(efi_call5)
26864 call *%rdi
26865 addq $48, %rsp
26866 RESTORE_XMM
26867+ pax_force_retaddr 0, 1
26868 ret
26869 ENDPROC(efi_call5)
26870
26871@@ -112,5 +119,6 @@ ENTRY(efi_call6)
26872 call *%rdi
26873 addq $48, %rsp
26874 RESTORE_XMM
26875+ pax_force_retaddr 0, 1
26876 ret
26877 ENDPROC(efi_call6)
26878diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26879index 475e2cd..1b8e708 100644
26880--- a/arch/x86/platform/mrst/mrst.c
26881+++ b/arch/x86/platform/mrst/mrst.c
26882@@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26883 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26884 int sfi_mrtc_num;
26885
26886-static void mrst_power_off(void)
26887+static __noreturn void mrst_power_off(void)
26888 {
26889 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26890 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
26891+ BUG();
26892 }
26893
26894-static void mrst_reboot(void)
26895+static __noreturn void mrst_reboot(void)
26896 {
26897 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26898 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
26899 else
26900 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26901+ BUG();
26902 }
26903
26904 /* parse all the mtimer info to a static mtimer array */
26905diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26906index f10c0af..3ec1f95 100644
26907--- a/arch/x86/power/cpu.c
26908+++ b/arch/x86/power/cpu.c
26909@@ -131,7 +131,7 @@ static void do_fpu_end(void)
26910 static void fix_processor_context(void)
26911 {
26912 int cpu = smp_processor_id();
26913- struct tss_struct *t = &per_cpu(init_tss, cpu);
26914+ struct tss_struct *t = init_tss + cpu;
26915
26916 set_tss_desc(cpu, t); /*
26917 * This just modifies memory; should not be
26918@@ -141,7 +141,9 @@ static void fix_processor_context(void)
26919 */
26920
26921 #ifdef CONFIG_X86_64
26922+ pax_open_kernel();
26923 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26924+ pax_close_kernel();
26925
26926 syscall_init(); /* This sets MSR_*STAR and related */
26927 #endif
26928diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26929index 5d17950..2253fc9 100644
26930--- a/arch/x86/vdso/Makefile
26931+++ b/arch/x86/vdso/Makefile
26932@@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
26933 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26934 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26935
26936-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26937+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26938 GCOV_PROFILE := n
26939
26940 #
26941diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26942index 468d591..8e80a0a 100644
26943--- a/arch/x86/vdso/vdso32-setup.c
26944+++ b/arch/x86/vdso/vdso32-setup.c
26945@@ -25,6 +25,7 @@
26946 #include <asm/tlbflush.h>
26947 #include <asm/vdso.h>
26948 #include <asm/proto.h>
26949+#include <asm/mman.h>
26950
26951 enum {
26952 VDSO_DISABLED = 0,
26953@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26954 void enable_sep_cpu(void)
26955 {
26956 int cpu = get_cpu();
26957- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26958+ struct tss_struct *tss = init_tss + cpu;
26959
26960 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26961 put_cpu();
26962@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26963 gate_vma.vm_start = FIXADDR_USER_START;
26964 gate_vma.vm_end = FIXADDR_USER_END;
26965 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26966- gate_vma.vm_page_prot = __P101;
26967+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26968 /*
26969 * Make sure the vDSO gets into every core dump.
26970 * Dumping its contents makes post-mortem fully interpretable later
26971@@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26972 if (compat)
26973 addr = VDSO_HIGH_BASE;
26974 else {
26975- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26976+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26977 if (IS_ERR_VALUE(addr)) {
26978 ret = addr;
26979 goto up_fail;
26980 }
26981 }
26982
26983- current->mm->context.vdso = (void *)addr;
26984+ current->mm->context.vdso = addr;
26985
26986 if (compat_uses_vma || !compat) {
26987 /*
26988@@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26989 }
26990
26991 current_thread_info()->sysenter_return =
26992- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26993+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26994
26995 up_fail:
26996 if (ret)
26997- current->mm->context.vdso = NULL;
26998+ current->mm->context.vdso = 0;
26999
27000 up_write(&mm->mmap_sem);
27001
27002@@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
27003
27004 const char *arch_vma_name(struct vm_area_struct *vma)
27005 {
27006- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27007+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27008 return "[vdso]";
27009+
27010+#ifdef CONFIG_PAX_SEGMEXEC
27011+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27012+ return "[vdso]";
27013+#endif
27014+
27015 return NULL;
27016 }
27017
27018@@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27019 * Check to see if the corresponding task was created in compat vdso
27020 * mode.
27021 */
27022- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27023+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27024 return &gate_vma;
27025 return NULL;
27026 }
27027diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27028index 153407c..611cba9 100644
27029--- a/arch/x86/vdso/vma.c
27030+++ b/arch/x86/vdso/vma.c
27031@@ -16,8 +16,6 @@
27032 #include <asm/vdso.h>
27033 #include <asm/page.h>
27034
27035-unsigned int __read_mostly vdso_enabled = 1;
27036-
27037 extern char vdso_start[], vdso_end[];
27038 extern unsigned short vdso_sync_cpuid;
27039
27040@@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27041 * unaligned here as a result of stack start randomization.
27042 */
27043 addr = PAGE_ALIGN(addr);
27044- addr = align_addr(addr, NULL, ALIGN_VDSO);
27045
27046 return addr;
27047 }
27048@@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27049 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27050 {
27051 struct mm_struct *mm = current->mm;
27052- unsigned long addr;
27053+ unsigned long addr = 0;
27054 int ret;
27055
27056- if (!vdso_enabled)
27057- return 0;
27058-
27059 down_write(&mm->mmap_sem);
27060+
27061+#ifdef CONFIG_PAX_RANDMMAP
27062+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27063+#endif
27064+
27065 addr = vdso_addr(mm->start_stack, vdso_size);
27066+ addr = align_addr(addr, NULL, ALIGN_VDSO);
27067 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
27068 if (IS_ERR_VALUE(addr)) {
27069 ret = addr;
27070 goto up_fail;
27071 }
27072
27073- current->mm->context.vdso = (void *)addr;
27074+ mm->context.vdso = addr;
27075
27076 ret = install_special_mapping(mm, addr, vdso_size,
27077 VM_READ|VM_EXEC|
27078 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
27079 VM_ALWAYSDUMP,
27080 vdso_pages);
27081- if (ret) {
27082- current->mm->context.vdso = NULL;
27083- goto up_fail;
27084- }
27085+
27086+ if (ret)
27087+ mm->context.vdso = 0;
27088
27089 up_fail:
27090 up_write(&mm->mmap_sem);
27091 return ret;
27092 }
27093-
27094-static __init int vdso_setup(char *s)
27095-{
27096- vdso_enabled = simple_strtoul(s, NULL, 0);
27097- return 0;
27098-}
27099-__setup("vdso=", vdso_setup);
27100diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27101index 4e517d4..68a48f5 100644
27102--- a/arch/x86/xen/enlighten.c
27103+++ b/arch/x86/xen/enlighten.c
27104@@ -86,8 +86,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27105
27106 struct shared_info xen_dummy_shared_info;
27107
27108-void *xen_initial_gdt;
27109-
27110 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27111 __read_mostly int xen_have_vector_callback;
27112 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27113@@ -1030,30 +1028,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27114 #endif
27115 };
27116
27117-static void xen_reboot(int reason)
27118+static __noreturn void xen_reboot(int reason)
27119 {
27120 struct sched_shutdown r = { .reason = reason };
27121
27122- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27123- BUG();
27124+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27125+ BUG();
27126 }
27127
27128-static void xen_restart(char *msg)
27129+static __noreturn void xen_restart(char *msg)
27130 {
27131 xen_reboot(SHUTDOWN_reboot);
27132 }
27133
27134-static void xen_emergency_restart(void)
27135+static __noreturn void xen_emergency_restart(void)
27136 {
27137 xen_reboot(SHUTDOWN_reboot);
27138 }
27139
27140-static void xen_machine_halt(void)
27141+static __noreturn void xen_machine_halt(void)
27142 {
27143 xen_reboot(SHUTDOWN_poweroff);
27144 }
27145
27146-static void xen_machine_power_off(void)
27147+static __noreturn void xen_machine_power_off(void)
27148 {
27149 if (pm_power_off)
27150 pm_power_off();
27151@@ -1156,7 +1154,17 @@ asmlinkage void __init xen_start_kernel(void)
27152 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27153
27154 /* Work out if we support NX */
27155- x86_configure_nx();
27156+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27157+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27158+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27159+ unsigned l, h;
27160+
27161+ __supported_pte_mask |= _PAGE_NX;
27162+ rdmsr(MSR_EFER, l, h);
27163+ l |= EFER_NX;
27164+ wrmsr(MSR_EFER, l, h);
27165+ }
27166+#endif
27167
27168 xen_setup_features();
27169
27170@@ -1187,13 +1195,6 @@ asmlinkage void __init xen_start_kernel(void)
27171
27172 machine_ops = xen_machine_ops;
27173
27174- /*
27175- * The only reliable way to retain the initial address of the
27176- * percpu gdt_page is to remember it here, so we can go and
27177- * mark it RW later, when the initial percpu area is freed.
27178- */
27179- xen_initial_gdt = &per_cpu(gdt_page, 0);
27180-
27181 xen_smp_init();
27182
27183 #ifdef CONFIG_ACPI_NUMA
27184diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27185index dc19347..1b07a2c 100644
27186--- a/arch/x86/xen/mmu.c
27187+++ b/arch/x86/xen/mmu.c
27188@@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27189 convert_pfn_mfn(init_level4_pgt);
27190 convert_pfn_mfn(level3_ident_pgt);
27191 convert_pfn_mfn(level3_kernel_pgt);
27192+ convert_pfn_mfn(level3_vmalloc_start_pgt);
27193+ convert_pfn_mfn(level3_vmalloc_end_pgt);
27194+ convert_pfn_mfn(level3_vmemmap_pgt);
27195
27196 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27197 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27198@@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27199 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27200 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27201 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27202+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27203+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27204+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27205 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27206+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27207 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27208 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27209
27210@@ -1963,6 +1970,7 @@ static void __init xen_post_allocator_init(void)
27211 pv_mmu_ops.set_pud = xen_set_pud;
27212 #if PAGETABLE_LEVELS == 4
27213 pv_mmu_ops.set_pgd = xen_set_pgd;
27214+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27215 #endif
27216
27217 /* This will work as long as patching hasn't happened yet
27218@@ -2044,6 +2052,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27219 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27220 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27221 .set_pgd = xen_set_pgd_hyper,
27222+ .set_pgd_batched = xen_set_pgd_hyper,
27223
27224 .alloc_pud = xen_alloc_pmd_init,
27225 .release_pud = xen_release_pmd_init,
27226diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27227index f2ce60a..14e08dc 100644
27228--- a/arch/x86/xen/smp.c
27229+++ b/arch/x86/xen/smp.c
27230@@ -209,11 +209,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27231 {
27232 BUG_ON(smp_processor_id() != 0);
27233 native_smp_prepare_boot_cpu();
27234-
27235- /* We've switched to the "real" per-cpu gdt, so make sure the
27236- old memory can be recycled */
27237- make_lowmem_page_readwrite(xen_initial_gdt);
27238-
27239 xen_filter_cpu_maps();
27240 xen_setup_vcpu_info_placement();
27241 }
27242@@ -290,12 +285,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27243 gdt = get_cpu_gdt_table(cpu);
27244
27245 ctxt->flags = VGCF_IN_KERNEL;
27246- ctxt->user_regs.ds = __USER_DS;
27247- ctxt->user_regs.es = __USER_DS;
27248+ ctxt->user_regs.ds = __KERNEL_DS;
27249+ ctxt->user_regs.es = __KERNEL_DS;
27250 ctxt->user_regs.ss = __KERNEL_DS;
27251 #ifdef CONFIG_X86_32
27252 ctxt->user_regs.fs = __KERNEL_PERCPU;
27253- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27254+ savesegment(gs, ctxt->user_regs.gs);
27255 #else
27256 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27257 #endif
27258@@ -346,13 +341,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
27259 int rc;
27260
27261 per_cpu(current_task, cpu) = idle;
27262+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27263 #ifdef CONFIG_X86_32
27264 irq_ctx_init(cpu);
27265 #else
27266 clear_tsk_thread_flag(idle, TIF_FORK);
27267- per_cpu(kernel_stack, cpu) =
27268- (unsigned long)task_stack_page(idle) -
27269- KERNEL_STACK_OFFSET + THREAD_SIZE;
27270+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27271 #endif
27272 xen_setup_runstate_info(cpu);
27273 xen_setup_timer(cpu);
27274diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27275index b040b0e..8cc4fe0 100644
27276--- a/arch/x86/xen/xen-asm_32.S
27277+++ b/arch/x86/xen/xen-asm_32.S
27278@@ -83,14 +83,14 @@ ENTRY(xen_iret)
27279 ESP_OFFSET=4 # bytes pushed onto stack
27280
27281 /*
27282- * Store vcpu_info pointer for easy access. Do it this way to
27283- * avoid having to reload %fs
27284+ * Store vcpu_info pointer for easy access.
27285 */
27286 #ifdef CONFIG_SMP
27287- GET_THREAD_INFO(%eax)
27288- movl TI_cpu(%eax), %eax
27289- movl __per_cpu_offset(,%eax,4), %eax
27290- mov xen_vcpu(%eax), %eax
27291+ push %fs
27292+ mov $(__KERNEL_PERCPU), %eax
27293+ mov %eax, %fs
27294+ mov PER_CPU_VAR(xen_vcpu), %eax
27295+ pop %fs
27296 #else
27297 movl xen_vcpu, %eax
27298 #endif
27299diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27300index aaa7291..3f77960 100644
27301--- a/arch/x86/xen/xen-head.S
27302+++ b/arch/x86/xen/xen-head.S
27303@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27304 #ifdef CONFIG_X86_32
27305 mov %esi,xen_start_info
27306 mov $init_thread_union+THREAD_SIZE,%esp
27307+#ifdef CONFIG_SMP
27308+ movl $cpu_gdt_table,%edi
27309+ movl $__per_cpu_load,%eax
27310+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27311+ rorl $16,%eax
27312+ movb %al,__KERNEL_PERCPU + 4(%edi)
27313+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27314+ movl $__per_cpu_end - 1,%eax
27315+ subl $__per_cpu_start,%eax
27316+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27317+#endif
27318 #else
27319 mov %rsi,xen_start_info
27320 mov $init_thread_union+THREAD_SIZE,%rsp
27321diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27322index b095739..8c17bcd 100644
27323--- a/arch/x86/xen/xen-ops.h
27324+++ b/arch/x86/xen/xen-ops.h
27325@@ -10,8 +10,6 @@
27326 extern const char xen_hypervisor_callback[];
27327 extern const char xen_failsafe_callback[];
27328
27329-extern void *xen_initial_gdt;
27330-
27331 struct trap_info;
27332 void xen_copy_trap_info(struct trap_info *traps);
27333
27334diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27335index 525bd3d..ef888b1 100644
27336--- a/arch/xtensa/variants/dc232b/include/variant/core.h
27337+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27338@@ -119,9 +119,9 @@
27339 ----------------------------------------------------------------------*/
27340
27341 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27342-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27343 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27344 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27345+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27346
27347 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27348 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27349diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27350index 2f33760..835e50a 100644
27351--- a/arch/xtensa/variants/fsf/include/variant/core.h
27352+++ b/arch/xtensa/variants/fsf/include/variant/core.h
27353@@ -11,6 +11,7 @@
27354 #ifndef _XTENSA_CORE_H
27355 #define _XTENSA_CORE_H
27356
27357+#include <linux/const.h>
27358
27359 /****************************************************************************
27360 Parameters Useful for Any Code, USER or PRIVILEGED
27361@@ -112,9 +113,9 @@
27362 ----------------------------------------------------------------------*/
27363
27364 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27365-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27366 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27367 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27368+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27369
27370 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27371 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27372diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27373index af00795..2bb8105 100644
27374--- a/arch/xtensa/variants/s6000/include/variant/core.h
27375+++ b/arch/xtensa/variants/s6000/include/variant/core.h
27376@@ -11,6 +11,7 @@
27377 #ifndef _XTENSA_CORE_CONFIGURATION_H
27378 #define _XTENSA_CORE_CONFIGURATION_H
27379
27380+#include <linux/const.h>
27381
27382 /****************************************************************************
27383 Parameters Useful for Any Code, USER or PRIVILEGED
27384@@ -118,9 +119,9 @@
27385 ----------------------------------------------------------------------*/
27386
27387 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27388-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27389 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27390 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27391+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27392
27393 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27394 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27395diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27396index 58916af..9cb880b 100644
27397--- a/block/blk-iopoll.c
27398+++ b/block/blk-iopoll.c
27399@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27400 }
27401 EXPORT_SYMBOL(blk_iopoll_complete);
27402
27403-static void blk_iopoll_softirq(struct softirq_action *h)
27404+static void blk_iopoll_softirq(void)
27405 {
27406 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27407 int rearm = 0, budget = blk_iopoll_budget;
27408diff --git a/block/blk-map.c b/block/blk-map.c
27409index 623e1cd..ca1e109 100644
27410--- a/block/blk-map.c
27411+++ b/block/blk-map.c
27412@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27413 if (!len || !kbuf)
27414 return -EINVAL;
27415
27416- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27417+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27418 if (do_copy)
27419 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27420 else
27421diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27422index 1366a89..e17f54b 100644
27423--- a/block/blk-softirq.c
27424+++ b/block/blk-softirq.c
27425@@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27426 * Softirq action handler - move entries to local list and loop over them
27427 * while passing them to the queue registered handler.
27428 */
27429-static void blk_done_softirq(struct softirq_action *h)
27430+static void blk_done_softirq(void)
27431 {
27432 struct list_head *cpu_list, local_list;
27433
27434diff --git a/block/bsg.c b/block/bsg.c
27435index ff64ae3..593560c 100644
27436--- a/block/bsg.c
27437+++ b/block/bsg.c
27438@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27439 struct sg_io_v4 *hdr, struct bsg_device *bd,
27440 fmode_t has_write_perm)
27441 {
27442+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27443+ unsigned char *cmdptr;
27444+
27445 if (hdr->request_len > BLK_MAX_CDB) {
27446 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27447 if (!rq->cmd)
27448 return -ENOMEM;
27449- }
27450+ cmdptr = rq->cmd;
27451+ } else
27452+ cmdptr = tmpcmd;
27453
27454- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27455+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27456 hdr->request_len))
27457 return -EFAULT;
27458
27459+ if (cmdptr != rq->cmd)
27460+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27461+
27462 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27463 if (blk_verify_command(rq->cmd, has_write_perm))
27464 return -EPERM;
27465diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27466index 7c668c8..db3521c 100644
27467--- a/block/compat_ioctl.c
27468+++ b/block/compat_ioctl.c
27469@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27470 err |= __get_user(f->spec1, &uf->spec1);
27471 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27472 err |= __get_user(name, &uf->name);
27473- f->name = compat_ptr(name);
27474+ f->name = (void __force_kernel *)compat_ptr(name);
27475 if (err) {
27476 err = -EFAULT;
27477 goto out;
27478diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27479index 6296b40..417c00f 100644
27480--- a/block/partitions/efi.c
27481+++ b/block/partitions/efi.c
27482@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27483 if (!gpt)
27484 return NULL;
27485
27486+ if (!le32_to_cpu(gpt->num_partition_entries))
27487+ return NULL;
27488+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27489+ if (!pte)
27490+ return NULL;
27491+
27492 count = le32_to_cpu(gpt->num_partition_entries) *
27493 le32_to_cpu(gpt->sizeof_partition_entry);
27494- if (!count)
27495- return NULL;
27496- pte = kzalloc(count, GFP_KERNEL);
27497- if (!pte)
27498- return NULL;
27499-
27500 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27501 (u8 *) pte,
27502 count) < count) {
27503diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27504index 260fa80..e8f3caf 100644
27505--- a/block/scsi_ioctl.c
27506+++ b/block/scsi_ioctl.c
27507@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27508 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27509 struct sg_io_hdr *hdr, fmode_t mode)
27510 {
27511- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27512+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27513+ unsigned char *cmdptr;
27514+
27515+ if (rq->cmd != rq->__cmd)
27516+ cmdptr = rq->cmd;
27517+ else
27518+ cmdptr = tmpcmd;
27519+
27520+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27521 return -EFAULT;
27522+
27523+ if (cmdptr != rq->cmd)
27524+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27525+
27526 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27527 return -EPERM;
27528
27529@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27530 int err;
27531 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27532 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27533+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27534+ unsigned char *cmdptr;
27535
27536 if (!sic)
27537 return -EINVAL;
27538@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27539 */
27540 err = -EFAULT;
27541 rq->cmd_len = cmdlen;
27542- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27543+
27544+ if (rq->cmd != rq->__cmd)
27545+ cmdptr = rq->cmd;
27546+ else
27547+ cmdptr = tmpcmd;
27548+
27549+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27550 goto error;
27551
27552+ if (rq->cmd != cmdptr)
27553+ memcpy(rq->cmd, cmdptr, cmdlen);
27554+
27555 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27556 goto error;
27557
27558diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27559index 671d4d6..5f24030 100644
27560--- a/crypto/cryptd.c
27561+++ b/crypto/cryptd.c
27562@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27563
27564 struct cryptd_blkcipher_request_ctx {
27565 crypto_completion_t complete;
27566-};
27567+} __no_const;
27568
27569 struct cryptd_hash_ctx {
27570 struct crypto_shash *child;
27571@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27572
27573 struct cryptd_aead_request_ctx {
27574 crypto_completion_t complete;
27575-};
27576+} __no_const;
27577
27578 static void cryptd_queue_worker(struct work_struct *work);
27579
27580diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27581index 5d41894..22021e4 100644
27582--- a/drivers/acpi/apei/cper.c
27583+++ b/drivers/acpi/apei/cper.c
27584@@ -38,12 +38,12 @@
27585 */
27586 u64 cper_next_record_id(void)
27587 {
27588- static atomic64_t seq;
27589+ static atomic64_unchecked_t seq;
27590
27591- if (!atomic64_read(&seq))
27592- atomic64_set(&seq, ((u64)get_seconds()) << 32);
27593+ if (!atomic64_read_unchecked(&seq))
27594+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27595
27596- return atomic64_inc_return(&seq);
27597+ return atomic64_inc_return_unchecked(&seq);
27598 }
27599 EXPORT_SYMBOL_GPL(cper_next_record_id);
27600
27601diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27602index b258cab..3fb7da7 100644
27603--- a/drivers/acpi/ec_sys.c
27604+++ b/drivers/acpi/ec_sys.c
27605@@ -12,6 +12,7 @@
27606 #include <linux/acpi.h>
27607 #include <linux/debugfs.h>
27608 #include <linux/module.h>
27609+#include <linux/uaccess.h>
27610 #include "internal.h"
27611
27612 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27613@@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27614 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27615 */
27616 unsigned int size = EC_SPACE_SIZE;
27617- u8 *data = (u8 *) buf;
27618+ u8 data;
27619 loff_t init_off = *off;
27620 int err = 0;
27621
27622@@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27623 size = count;
27624
27625 while (size) {
27626- err = ec_read(*off, &data[*off - init_off]);
27627+ err = ec_read(*off, &data);
27628 if (err)
27629 return err;
27630+ if (put_user(data, &buf[*off - init_off]))
27631+ return -EFAULT;
27632 *off += 1;
27633 size--;
27634 }
27635@@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27636
27637 unsigned int size = count;
27638 loff_t init_off = *off;
27639- u8 *data = (u8 *) buf;
27640 int err = 0;
27641
27642 if (*off >= EC_SPACE_SIZE)
27643@@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27644 }
27645
27646 while (size) {
27647- u8 byte_write = data[*off - init_off];
27648+ u8 byte_write;
27649+ if (get_user(byte_write, &buf[*off - init_off]))
27650+ return -EFAULT;
27651 err = ec_write(*off, byte_write);
27652 if (err)
27653 return err;
27654diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27655index 251c7b62..000462d 100644
27656--- a/drivers/acpi/proc.c
27657+++ b/drivers/acpi/proc.c
27658@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27659 size_t count, loff_t * ppos)
27660 {
27661 struct list_head *node, *next;
27662- char strbuf[5];
27663- char str[5] = "";
27664- unsigned int len = count;
27665+ char strbuf[5] = {0};
27666
27667- if (len > 4)
27668- len = 4;
27669- if (len < 0)
27670+ if (count > 4)
27671+ count = 4;
27672+ if (copy_from_user(strbuf, buffer, count))
27673 return -EFAULT;
27674-
27675- if (copy_from_user(strbuf, buffer, len))
27676- return -EFAULT;
27677- strbuf[len] = '\0';
27678- sscanf(strbuf, "%s", str);
27679+ strbuf[count] = '\0';
27680
27681 mutex_lock(&acpi_device_lock);
27682 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27683@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27684 if (!dev->wakeup.flags.valid)
27685 continue;
27686
27687- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27688+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27689 if (device_can_wakeup(&dev->dev)) {
27690 bool enable = !device_may_wakeup(&dev->dev);
27691 device_set_wakeup_enable(&dev->dev, enable);
27692diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27693index 8ae05ce..7dbbed9 100644
27694--- a/drivers/acpi/processor_driver.c
27695+++ b/drivers/acpi/processor_driver.c
27696@@ -555,7 +555,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27697 return 0;
27698 #endif
27699
27700- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27701+ BUG_ON(pr->id >= nr_cpu_ids);
27702
27703 /*
27704 * Buggy BIOS check
27705diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27706index c06e0ec..a2c06ba 100644
27707--- a/drivers/ata/libata-core.c
27708+++ b/drivers/ata/libata-core.c
27709@@ -4736,7 +4736,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27710 struct ata_port *ap;
27711 unsigned int tag;
27712
27713- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27714+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27715 ap = qc->ap;
27716
27717 qc->flags = 0;
27718@@ -4752,7 +4752,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27719 struct ata_port *ap;
27720 struct ata_link *link;
27721
27722- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27723+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27724 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27725 ap = qc->ap;
27726 link = qc->dev->link;
27727@@ -5816,6 +5816,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27728 return;
27729
27730 spin_lock(&lock);
27731+ pax_open_kernel();
27732
27733 for (cur = ops->inherits; cur; cur = cur->inherits) {
27734 void **inherit = (void **)cur;
27735@@ -5829,8 +5830,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27736 if (IS_ERR(*pp))
27737 *pp = NULL;
27738
27739- ops->inherits = NULL;
27740+ *(struct ata_port_operations **)&ops->inherits = NULL;
27741
27742+ pax_close_kernel();
27743 spin_unlock(&lock);
27744 }
27745
27746diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27747index 048589f..4002b98 100644
27748--- a/drivers/ata/pata_arasan_cf.c
27749+++ b/drivers/ata/pata_arasan_cf.c
27750@@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27751 /* Handle platform specific quirks */
27752 if (pdata->quirk) {
27753 if (pdata->quirk & CF_BROKEN_PIO) {
27754- ap->ops->set_piomode = NULL;
27755+ pax_open_kernel();
27756+ *(void **)&ap->ops->set_piomode = NULL;
27757+ pax_close_kernel();
27758 ap->pio_mask = 0;
27759 }
27760 if (pdata->quirk & CF_BROKEN_MWDMA)
27761diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27762index f9b983a..887b9d8 100644
27763--- a/drivers/atm/adummy.c
27764+++ b/drivers/atm/adummy.c
27765@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27766 vcc->pop(vcc, skb);
27767 else
27768 dev_kfree_skb_any(skb);
27769- atomic_inc(&vcc->stats->tx);
27770+ atomic_inc_unchecked(&vcc->stats->tx);
27771
27772 return 0;
27773 }
27774diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27775index f8f41e0..1f987dd 100644
27776--- a/drivers/atm/ambassador.c
27777+++ b/drivers/atm/ambassador.c
27778@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27779 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27780
27781 // VC layer stats
27782- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27783+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27784
27785 // free the descriptor
27786 kfree (tx_descr);
27787@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27788 dump_skb ("<<<", vc, skb);
27789
27790 // VC layer stats
27791- atomic_inc(&atm_vcc->stats->rx);
27792+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27793 __net_timestamp(skb);
27794 // end of our responsibility
27795 atm_vcc->push (atm_vcc, skb);
27796@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27797 } else {
27798 PRINTK (KERN_INFO, "dropped over-size frame");
27799 // should we count this?
27800- atomic_inc(&atm_vcc->stats->rx_drop);
27801+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27802 }
27803
27804 } else {
27805@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27806 }
27807
27808 if (check_area (skb->data, skb->len)) {
27809- atomic_inc(&atm_vcc->stats->tx_err);
27810+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27811 return -ENOMEM; // ?
27812 }
27813
27814diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27815index b22d71c..d6e1049 100644
27816--- a/drivers/atm/atmtcp.c
27817+++ b/drivers/atm/atmtcp.c
27818@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27819 if (vcc->pop) vcc->pop(vcc,skb);
27820 else dev_kfree_skb(skb);
27821 if (dev_data) return 0;
27822- atomic_inc(&vcc->stats->tx_err);
27823+ atomic_inc_unchecked(&vcc->stats->tx_err);
27824 return -ENOLINK;
27825 }
27826 size = skb->len+sizeof(struct atmtcp_hdr);
27827@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27828 if (!new_skb) {
27829 if (vcc->pop) vcc->pop(vcc,skb);
27830 else dev_kfree_skb(skb);
27831- atomic_inc(&vcc->stats->tx_err);
27832+ atomic_inc_unchecked(&vcc->stats->tx_err);
27833 return -ENOBUFS;
27834 }
27835 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27836@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27837 if (vcc->pop) vcc->pop(vcc,skb);
27838 else dev_kfree_skb(skb);
27839 out_vcc->push(out_vcc,new_skb);
27840- atomic_inc(&vcc->stats->tx);
27841- atomic_inc(&out_vcc->stats->rx);
27842+ atomic_inc_unchecked(&vcc->stats->tx);
27843+ atomic_inc_unchecked(&out_vcc->stats->rx);
27844 return 0;
27845 }
27846
27847@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27848 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27849 read_unlock(&vcc_sklist_lock);
27850 if (!out_vcc) {
27851- atomic_inc(&vcc->stats->tx_err);
27852+ atomic_inc_unchecked(&vcc->stats->tx_err);
27853 goto done;
27854 }
27855 skb_pull(skb,sizeof(struct atmtcp_hdr));
27856@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27857 __net_timestamp(new_skb);
27858 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27859 out_vcc->push(out_vcc,new_skb);
27860- atomic_inc(&vcc->stats->tx);
27861- atomic_inc(&out_vcc->stats->rx);
27862+ atomic_inc_unchecked(&vcc->stats->tx);
27863+ atomic_inc_unchecked(&out_vcc->stats->rx);
27864 done:
27865 if (vcc->pop) vcc->pop(vcc,skb);
27866 else dev_kfree_skb(skb);
27867diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27868index 956e9ac..133516d 100644
27869--- a/drivers/atm/eni.c
27870+++ b/drivers/atm/eni.c
27871@@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27872 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27873 vcc->dev->number);
27874 length = 0;
27875- atomic_inc(&vcc->stats->rx_err);
27876+ atomic_inc_unchecked(&vcc->stats->rx_err);
27877 }
27878 else {
27879 length = ATM_CELL_SIZE-1; /* no HEC */
27880@@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27881 size);
27882 }
27883 eff = length = 0;
27884- atomic_inc(&vcc->stats->rx_err);
27885+ atomic_inc_unchecked(&vcc->stats->rx_err);
27886 }
27887 else {
27888 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27889@@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27890 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27891 vcc->dev->number,vcc->vci,length,size << 2,descr);
27892 length = eff = 0;
27893- atomic_inc(&vcc->stats->rx_err);
27894+ atomic_inc_unchecked(&vcc->stats->rx_err);
27895 }
27896 }
27897 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27898@@ -771,7 +771,7 @@ rx_dequeued++;
27899 vcc->push(vcc,skb);
27900 pushed++;
27901 }
27902- atomic_inc(&vcc->stats->rx);
27903+ atomic_inc_unchecked(&vcc->stats->rx);
27904 }
27905 wake_up(&eni_dev->rx_wait);
27906 }
27907@@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
27908 PCI_DMA_TODEVICE);
27909 if (vcc->pop) vcc->pop(vcc,skb);
27910 else dev_kfree_skb_irq(skb);
27911- atomic_inc(&vcc->stats->tx);
27912+ atomic_inc_unchecked(&vcc->stats->tx);
27913 wake_up(&eni_dev->tx_wait);
27914 dma_complete++;
27915 }
27916@@ -1569,7 +1569,7 @@ tx_complete++;
27917 /*--------------------------------- entries ---------------------------------*/
27918
27919
27920-static const char *media_name[] __devinitdata = {
27921+static const char *media_name[] __devinitconst = {
27922 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27923 "UTP", "05?", "06?", "07?", /* 4- 7 */
27924 "TAXI","09?", "10?", "11?", /* 8-11 */
27925diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27926index 5072f8a..fa52520d 100644
27927--- a/drivers/atm/firestream.c
27928+++ b/drivers/atm/firestream.c
27929@@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27930 }
27931 }
27932
27933- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27934+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27935
27936 fs_dprintk (FS_DEBUG_TXMEM, "i");
27937 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27938@@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27939 #endif
27940 skb_put (skb, qe->p1 & 0xffff);
27941 ATM_SKB(skb)->vcc = atm_vcc;
27942- atomic_inc(&atm_vcc->stats->rx);
27943+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27944 __net_timestamp(skb);
27945 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27946 atm_vcc->push (atm_vcc, skb);
27947@@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27948 kfree (pe);
27949 }
27950 if (atm_vcc)
27951- atomic_inc(&atm_vcc->stats->rx_drop);
27952+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27953 break;
27954 case 0x1f: /* Reassembly abort: no buffers. */
27955 /* Silently increment error counter. */
27956 if (atm_vcc)
27957- atomic_inc(&atm_vcc->stats->rx_drop);
27958+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27959 break;
27960 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27961 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27962diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27963index 361f5ae..7fc552d 100644
27964--- a/drivers/atm/fore200e.c
27965+++ b/drivers/atm/fore200e.c
27966@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27967 #endif
27968 /* check error condition */
27969 if (*entry->status & STATUS_ERROR)
27970- atomic_inc(&vcc->stats->tx_err);
27971+ atomic_inc_unchecked(&vcc->stats->tx_err);
27972 else
27973- atomic_inc(&vcc->stats->tx);
27974+ atomic_inc_unchecked(&vcc->stats->tx);
27975 }
27976 }
27977
27978@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27979 if (skb == NULL) {
27980 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27981
27982- atomic_inc(&vcc->stats->rx_drop);
27983+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27984 return -ENOMEM;
27985 }
27986
27987@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27988
27989 dev_kfree_skb_any(skb);
27990
27991- atomic_inc(&vcc->stats->rx_drop);
27992+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27993 return -ENOMEM;
27994 }
27995
27996 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27997
27998 vcc->push(vcc, skb);
27999- atomic_inc(&vcc->stats->rx);
28000+ atomic_inc_unchecked(&vcc->stats->rx);
28001
28002 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28003
28004@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28005 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28006 fore200e->atm_dev->number,
28007 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28008- atomic_inc(&vcc->stats->rx_err);
28009+ atomic_inc_unchecked(&vcc->stats->rx_err);
28010 }
28011 }
28012
28013@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28014 goto retry_here;
28015 }
28016
28017- atomic_inc(&vcc->stats->tx_err);
28018+ atomic_inc_unchecked(&vcc->stats->tx_err);
28019
28020 fore200e->tx_sat++;
28021 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28022diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28023index b182c2f..1c6fa8a 100644
28024--- a/drivers/atm/he.c
28025+++ b/drivers/atm/he.c
28026@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28027
28028 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28029 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28030- atomic_inc(&vcc->stats->rx_drop);
28031+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28032 goto return_host_buffers;
28033 }
28034
28035@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28036 RBRQ_LEN_ERR(he_dev->rbrq_head)
28037 ? "LEN_ERR" : "",
28038 vcc->vpi, vcc->vci);
28039- atomic_inc(&vcc->stats->rx_err);
28040+ atomic_inc_unchecked(&vcc->stats->rx_err);
28041 goto return_host_buffers;
28042 }
28043
28044@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28045 vcc->push(vcc, skb);
28046 spin_lock(&he_dev->global_lock);
28047
28048- atomic_inc(&vcc->stats->rx);
28049+ atomic_inc_unchecked(&vcc->stats->rx);
28050
28051 return_host_buffers:
28052 ++pdus_assembled;
28053@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28054 tpd->vcc->pop(tpd->vcc, tpd->skb);
28055 else
28056 dev_kfree_skb_any(tpd->skb);
28057- atomic_inc(&tpd->vcc->stats->tx_err);
28058+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28059 }
28060 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28061 return;
28062@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28063 vcc->pop(vcc, skb);
28064 else
28065 dev_kfree_skb_any(skb);
28066- atomic_inc(&vcc->stats->tx_err);
28067+ atomic_inc_unchecked(&vcc->stats->tx_err);
28068 return -EINVAL;
28069 }
28070
28071@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28072 vcc->pop(vcc, skb);
28073 else
28074 dev_kfree_skb_any(skb);
28075- atomic_inc(&vcc->stats->tx_err);
28076+ atomic_inc_unchecked(&vcc->stats->tx_err);
28077 return -EINVAL;
28078 }
28079 #endif
28080@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28081 vcc->pop(vcc, skb);
28082 else
28083 dev_kfree_skb_any(skb);
28084- atomic_inc(&vcc->stats->tx_err);
28085+ atomic_inc_unchecked(&vcc->stats->tx_err);
28086 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28087 return -ENOMEM;
28088 }
28089@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28090 vcc->pop(vcc, skb);
28091 else
28092 dev_kfree_skb_any(skb);
28093- atomic_inc(&vcc->stats->tx_err);
28094+ atomic_inc_unchecked(&vcc->stats->tx_err);
28095 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28096 return -ENOMEM;
28097 }
28098@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28099 __enqueue_tpd(he_dev, tpd, cid);
28100 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28101
28102- atomic_inc(&vcc->stats->tx);
28103+ atomic_inc_unchecked(&vcc->stats->tx);
28104
28105 return 0;
28106 }
28107diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28108index b812103..e391a49 100644
28109--- a/drivers/atm/horizon.c
28110+++ b/drivers/atm/horizon.c
28111@@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28112 {
28113 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28114 // VC layer stats
28115- atomic_inc(&vcc->stats->rx);
28116+ atomic_inc_unchecked(&vcc->stats->rx);
28117 __net_timestamp(skb);
28118 // end of our responsibility
28119 vcc->push (vcc, skb);
28120@@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28121 dev->tx_iovec = NULL;
28122
28123 // VC layer stats
28124- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28125+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28126
28127 // free the skb
28128 hrz_kfree_skb (skb);
28129diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28130index 1c05212..c28e200 100644
28131--- a/drivers/atm/idt77252.c
28132+++ b/drivers/atm/idt77252.c
28133@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28134 else
28135 dev_kfree_skb(skb);
28136
28137- atomic_inc(&vcc->stats->tx);
28138+ atomic_inc_unchecked(&vcc->stats->tx);
28139 }
28140
28141 atomic_dec(&scq->used);
28142@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28143 if ((sb = dev_alloc_skb(64)) == NULL) {
28144 printk("%s: Can't allocate buffers for aal0.\n",
28145 card->name);
28146- atomic_add(i, &vcc->stats->rx_drop);
28147+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28148 break;
28149 }
28150 if (!atm_charge(vcc, sb->truesize)) {
28151 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28152 card->name);
28153- atomic_add(i - 1, &vcc->stats->rx_drop);
28154+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28155 dev_kfree_skb(sb);
28156 break;
28157 }
28158@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28159 ATM_SKB(sb)->vcc = vcc;
28160 __net_timestamp(sb);
28161 vcc->push(vcc, sb);
28162- atomic_inc(&vcc->stats->rx);
28163+ atomic_inc_unchecked(&vcc->stats->rx);
28164
28165 cell += ATM_CELL_PAYLOAD;
28166 }
28167@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28168 "(CDC: %08x)\n",
28169 card->name, len, rpp->len, readl(SAR_REG_CDC));
28170 recycle_rx_pool_skb(card, rpp);
28171- atomic_inc(&vcc->stats->rx_err);
28172+ atomic_inc_unchecked(&vcc->stats->rx_err);
28173 return;
28174 }
28175 if (stat & SAR_RSQE_CRC) {
28176 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28177 recycle_rx_pool_skb(card, rpp);
28178- atomic_inc(&vcc->stats->rx_err);
28179+ atomic_inc_unchecked(&vcc->stats->rx_err);
28180 return;
28181 }
28182 if (skb_queue_len(&rpp->queue) > 1) {
28183@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28184 RXPRINTK("%s: Can't alloc RX skb.\n",
28185 card->name);
28186 recycle_rx_pool_skb(card, rpp);
28187- atomic_inc(&vcc->stats->rx_err);
28188+ atomic_inc_unchecked(&vcc->stats->rx_err);
28189 return;
28190 }
28191 if (!atm_charge(vcc, skb->truesize)) {
28192@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28193 __net_timestamp(skb);
28194
28195 vcc->push(vcc, skb);
28196- atomic_inc(&vcc->stats->rx);
28197+ atomic_inc_unchecked(&vcc->stats->rx);
28198
28199 return;
28200 }
28201@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28202 __net_timestamp(skb);
28203
28204 vcc->push(vcc, skb);
28205- atomic_inc(&vcc->stats->rx);
28206+ atomic_inc_unchecked(&vcc->stats->rx);
28207
28208 if (skb->truesize > SAR_FB_SIZE_3)
28209 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28210@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28211 if (vcc->qos.aal != ATM_AAL0) {
28212 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28213 card->name, vpi, vci);
28214- atomic_inc(&vcc->stats->rx_drop);
28215+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28216 goto drop;
28217 }
28218
28219 if ((sb = dev_alloc_skb(64)) == NULL) {
28220 printk("%s: Can't allocate buffers for AAL0.\n",
28221 card->name);
28222- atomic_inc(&vcc->stats->rx_err);
28223+ atomic_inc_unchecked(&vcc->stats->rx_err);
28224 goto drop;
28225 }
28226
28227@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28228 ATM_SKB(sb)->vcc = vcc;
28229 __net_timestamp(sb);
28230 vcc->push(vcc, sb);
28231- atomic_inc(&vcc->stats->rx);
28232+ atomic_inc_unchecked(&vcc->stats->rx);
28233
28234 drop:
28235 skb_pull(queue, 64);
28236@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28237
28238 if (vc == NULL) {
28239 printk("%s: NULL connection in send().\n", card->name);
28240- atomic_inc(&vcc->stats->tx_err);
28241+ atomic_inc_unchecked(&vcc->stats->tx_err);
28242 dev_kfree_skb(skb);
28243 return -EINVAL;
28244 }
28245 if (!test_bit(VCF_TX, &vc->flags)) {
28246 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28247- atomic_inc(&vcc->stats->tx_err);
28248+ atomic_inc_unchecked(&vcc->stats->tx_err);
28249 dev_kfree_skb(skb);
28250 return -EINVAL;
28251 }
28252@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28253 break;
28254 default:
28255 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28256- atomic_inc(&vcc->stats->tx_err);
28257+ atomic_inc_unchecked(&vcc->stats->tx_err);
28258 dev_kfree_skb(skb);
28259 return -EINVAL;
28260 }
28261
28262 if (skb_shinfo(skb)->nr_frags != 0) {
28263 printk("%s: No scatter-gather yet.\n", card->name);
28264- atomic_inc(&vcc->stats->tx_err);
28265+ atomic_inc_unchecked(&vcc->stats->tx_err);
28266 dev_kfree_skb(skb);
28267 return -EINVAL;
28268 }
28269@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28270
28271 err = queue_skb(card, vc, skb, oam);
28272 if (err) {
28273- atomic_inc(&vcc->stats->tx_err);
28274+ atomic_inc_unchecked(&vcc->stats->tx_err);
28275 dev_kfree_skb(skb);
28276 return err;
28277 }
28278@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28279 skb = dev_alloc_skb(64);
28280 if (!skb) {
28281 printk("%s: Out of memory in send_oam().\n", card->name);
28282- atomic_inc(&vcc->stats->tx_err);
28283+ atomic_inc_unchecked(&vcc->stats->tx_err);
28284 return -ENOMEM;
28285 }
28286 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28287diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28288index 9e373ba..cf93727 100644
28289--- a/drivers/atm/iphase.c
28290+++ b/drivers/atm/iphase.c
28291@@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
28292 status = (u_short) (buf_desc_ptr->desc_mode);
28293 if (status & (RX_CER | RX_PTE | RX_OFL))
28294 {
28295- atomic_inc(&vcc->stats->rx_err);
28296+ atomic_inc_unchecked(&vcc->stats->rx_err);
28297 IF_ERR(printk("IA: bad packet, dropping it");)
28298 if (status & RX_CER) {
28299 IF_ERR(printk(" cause: packet CRC error\n");)
28300@@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
28301 len = dma_addr - buf_addr;
28302 if (len > iadev->rx_buf_sz) {
28303 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28304- atomic_inc(&vcc->stats->rx_err);
28305+ atomic_inc_unchecked(&vcc->stats->rx_err);
28306 goto out_free_desc;
28307 }
28308
28309@@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28310 ia_vcc = INPH_IA_VCC(vcc);
28311 if (ia_vcc == NULL)
28312 {
28313- atomic_inc(&vcc->stats->rx_err);
28314+ atomic_inc_unchecked(&vcc->stats->rx_err);
28315 atm_return(vcc, skb->truesize);
28316 dev_kfree_skb_any(skb);
28317 goto INCR_DLE;
28318@@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28319 if ((length > iadev->rx_buf_sz) || (length >
28320 (skb->len - sizeof(struct cpcs_trailer))))
28321 {
28322- atomic_inc(&vcc->stats->rx_err);
28323+ atomic_inc_unchecked(&vcc->stats->rx_err);
28324 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28325 length, skb->len);)
28326 atm_return(vcc, skb->truesize);
28327@@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28328
28329 IF_RX(printk("rx_dle_intr: skb push");)
28330 vcc->push(vcc,skb);
28331- atomic_inc(&vcc->stats->rx);
28332+ atomic_inc_unchecked(&vcc->stats->rx);
28333 iadev->rx_pkt_cnt++;
28334 }
28335 INCR_DLE:
28336@@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28337 {
28338 struct k_sonet_stats *stats;
28339 stats = &PRIV(_ia_dev[board])->sonet_stats;
28340- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28341- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28342- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28343- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28344- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28345- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28346- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28347- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28348- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28349+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28350+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28351+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28352+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28353+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28354+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28355+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28356+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28357+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28358 }
28359 ia_cmds.status = 0;
28360 break;
28361@@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28362 if ((desc == 0) || (desc > iadev->num_tx_desc))
28363 {
28364 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28365- atomic_inc(&vcc->stats->tx);
28366+ atomic_inc_unchecked(&vcc->stats->tx);
28367 if (vcc->pop)
28368 vcc->pop(vcc, skb);
28369 else
28370@@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28371 ATM_DESC(skb) = vcc->vci;
28372 skb_queue_tail(&iadev->tx_dma_q, skb);
28373
28374- atomic_inc(&vcc->stats->tx);
28375+ atomic_inc_unchecked(&vcc->stats->tx);
28376 iadev->tx_pkt_cnt++;
28377 /* Increment transaction counter */
28378 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28379
28380 #if 0
28381 /* add flow control logic */
28382- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28383+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28384 if (iavcc->vc_desc_cnt > 10) {
28385 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28386 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28387diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28388index f556969..0da15eb 100644
28389--- a/drivers/atm/lanai.c
28390+++ b/drivers/atm/lanai.c
28391@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28392 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28393 lanai_endtx(lanai, lvcc);
28394 lanai_free_skb(lvcc->tx.atmvcc, skb);
28395- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28396+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28397 }
28398
28399 /* Try to fill the buffer - don't call unless there is backlog */
28400@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28401 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28402 __net_timestamp(skb);
28403 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28404- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28405+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28406 out:
28407 lvcc->rx.buf.ptr = end;
28408 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28409@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28410 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28411 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28412 lanai->stats.service_rxnotaal5++;
28413- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28414+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28415 return 0;
28416 }
28417 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28418@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28419 int bytes;
28420 read_unlock(&vcc_sklist_lock);
28421 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28422- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28423+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28424 lvcc->stats.x.aal5.service_trash++;
28425 bytes = (SERVICE_GET_END(s) * 16) -
28426 (((unsigned long) lvcc->rx.buf.ptr) -
28427@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28428 }
28429 if (s & SERVICE_STREAM) {
28430 read_unlock(&vcc_sklist_lock);
28431- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28432+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28433 lvcc->stats.x.aal5.service_stream++;
28434 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28435 "PDU on VCI %d!\n", lanai->number, vci);
28436@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28437 return 0;
28438 }
28439 DPRINTK("got rx crc error on vci %d\n", vci);
28440- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28441+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28442 lvcc->stats.x.aal5.service_rxcrc++;
28443 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28444 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28445diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28446index 1c70c45..300718d 100644
28447--- a/drivers/atm/nicstar.c
28448+++ b/drivers/atm/nicstar.c
28449@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28450 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28451 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28452 card->index);
28453- atomic_inc(&vcc->stats->tx_err);
28454+ atomic_inc_unchecked(&vcc->stats->tx_err);
28455 dev_kfree_skb_any(skb);
28456 return -EINVAL;
28457 }
28458@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28459 if (!vc->tx) {
28460 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28461 card->index);
28462- atomic_inc(&vcc->stats->tx_err);
28463+ atomic_inc_unchecked(&vcc->stats->tx_err);
28464 dev_kfree_skb_any(skb);
28465 return -EINVAL;
28466 }
28467@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28468 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28469 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28470 card->index);
28471- atomic_inc(&vcc->stats->tx_err);
28472+ atomic_inc_unchecked(&vcc->stats->tx_err);
28473 dev_kfree_skb_any(skb);
28474 return -EINVAL;
28475 }
28476
28477 if (skb_shinfo(skb)->nr_frags != 0) {
28478 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28479- atomic_inc(&vcc->stats->tx_err);
28480+ atomic_inc_unchecked(&vcc->stats->tx_err);
28481 dev_kfree_skb_any(skb);
28482 return -EINVAL;
28483 }
28484@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28485 }
28486
28487 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28488- atomic_inc(&vcc->stats->tx_err);
28489+ atomic_inc_unchecked(&vcc->stats->tx_err);
28490 dev_kfree_skb_any(skb);
28491 return -EIO;
28492 }
28493- atomic_inc(&vcc->stats->tx);
28494+ atomic_inc_unchecked(&vcc->stats->tx);
28495
28496 return 0;
28497 }
28498@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28499 printk
28500 ("nicstar%d: Can't allocate buffers for aal0.\n",
28501 card->index);
28502- atomic_add(i, &vcc->stats->rx_drop);
28503+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28504 break;
28505 }
28506 if (!atm_charge(vcc, sb->truesize)) {
28507 RXPRINTK
28508 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28509 card->index);
28510- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28511+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28512 dev_kfree_skb_any(sb);
28513 break;
28514 }
28515@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28516 ATM_SKB(sb)->vcc = vcc;
28517 __net_timestamp(sb);
28518 vcc->push(vcc, sb);
28519- atomic_inc(&vcc->stats->rx);
28520+ atomic_inc_unchecked(&vcc->stats->rx);
28521 cell += ATM_CELL_PAYLOAD;
28522 }
28523
28524@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28525 if (iovb == NULL) {
28526 printk("nicstar%d: Out of iovec buffers.\n",
28527 card->index);
28528- atomic_inc(&vcc->stats->rx_drop);
28529+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28530 recycle_rx_buf(card, skb);
28531 return;
28532 }
28533@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28534 small or large buffer itself. */
28535 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28536 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28537- atomic_inc(&vcc->stats->rx_err);
28538+ atomic_inc_unchecked(&vcc->stats->rx_err);
28539 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28540 NS_MAX_IOVECS);
28541 NS_PRV_IOVCNT(iovb) = 0;
28542@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28543 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28544 card->index);
28545 which_list(card, skb);
28546- atomic_inc(&vcc->stats->rx_err);
28547+ atomic_inc_unchecked(&vcc->stats->rx_err);
28548 recycle_rx_buf(card, skb);
28549 vc->rx_iov = NULL;
28550 recycle_iov_buf(card, iovb);
28551@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28552 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28553 card->index);
28554 which_list(card, skb);
28555- atomic_inc(&vcc->stats->rx_err);
28556+ atomic_inc_unchecked(&vcc->stats->rx_err);
28557 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28558 NS_PRV_IOVCNT(iovb));
28559 vc->rx_iov = NULL;
28560@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28561 printk(" - PDU size mismatch.\n");
28562 else
28563 printk(".\n");
28564- atomic_inc(&vcc->stats->rx_err);
28565+ atomic_inc_unchecked(&vcc->stats->rx_err);
28566 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28567 NS_PRV_IOVCNT(iovb));
28568 vc->rx_iov = NULL;
28569@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28570 /* skb points to a small buffer */
28571 if (!atm_charge(vcc, skb->truesize)) {
28572 push_rxbufs(card, skb);
28573- atomic_inc(&vcc->stats->rx_drop);
28574+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28575 } else {
28576 skb_put(skb, len);
28577 dequeue_sm_buf(card, skb);
28578@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28579 ATM_SKB(skb)->vcc = vcc;
28580 __net_timestamp(skb);
28581 vcc->push(vcc, skb);
28582- atomic_inc(&vcc->stats->rx);
28583+ atomic_inc_unchecked(&vcc->stats->rx);
28584 }
28585 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28586 struct sk_buff *sb;
28587@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28588 if (len <= NS_SMBUFSIZE) {
28589 if (!atm_charge(vcc, sb->truesize)) {
28590 push_rxbufs(card, sb);
28591- atomic_inc(&vcc->stats->rx_drop);
28592+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28593 } else {
28594 skb_put(sb, len);
28595 dequeue_sm_buf(card, sb);
28596@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28597 ATM_SKB(sb)->vcc = vcc;
28598 __net_timestamp(sb);
28599 vcc->push(vcc, sb);
28600- atomic_inc(&vcc->stats->rx);
28601+ atomic_inc_unchecked(&vcc->stats->rx);
28602 }
28603
28604 push_rxbufs(card, skb);
28605@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28606
28607 if (!atm_charge(vcc, skb->truesize)) {
28608 push_rxbufs(card, skb);
28609- atomic_inc(&vcc->stats->rx_drop);
28610+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28611 } else {
28612 dequeue_lg_buf(card, skb);
28613 #ifdef NS_USE_DESTRUCTORS
28614@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28615 ATM_SKB(skb)->vcc = vcc;
28616 __net_timestamp(skb);
28617 vcc->push(vcc, skb);
28618- atomic_inc(&vcc->stats->rx);
28619+ atomic_inc_unchecked(&vcc->stats->rx);
28620 }
28621
28622 push_rxbufs(card, sb);
28623@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28624 printk
28625 ("nicstar%d: Out of huge buffers.\n",
28626 card->index);
28627- atomic_inc(&vcc->stats->rx_drop);
28628+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28629 recycle_iovec_rx_bufs(card,
28630 (struct iovec *)
28631 iovb->data,
28632@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28633 card->hbpool.count++;
28634 } else
28635 dev_kfree_skb_any(hb);
28636- atomic_inc(&vcc->stats->rx_drop);
28637+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28638 } else {
28639 /* Copy the small buffer to the huge buffer */
28640 sb = (struct sk_buff *)iov->iov_base;
28641@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28642 #endif /* NS_USE_DESTRUCTORS */
28643 __net_timestamp(hb);
28644 vcc->push(vcc, hb);
28645- atomic_inc(&vcc->stats->rx);
28646+ atomic_inc_unchecked(&vcc->stats->rx);
28647 }
28648 }
28649
28650diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28651index e8cd652..bbbd1fc 100644
28652--- a/drivers/atm/solos-pci.c
28653+++ b/drivers/atm/solos-pci.c
28654@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28655 }
28656 atm_charge(vcc, skb->truesize);
28657 vcc->push(vcc, skb);
28658- atomic_inc(&vcc->stats->rx);
28659+ atomic_inc_unchecked(&vcc->stats->rx);
28660 break;
28661
28662 case PKT_STATUS:
28663@@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28664 vcc = SKB_CB(oldskb)->vcc;
28665
28666 if (vcc) {
28667- atomic_inc(&vcc->stats->tx);
28668+ atomic_inc_unchecked(&vcc->stats->tx);
28669 solos_pop(vcc, oldskb);
28670 } else
28671 dev_kfree_skb_irq(oldskb);
28672diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28673index 90f1ccc..04c4a1e 100644
28674--- a/drivers/atm/suni.c
28675+++ b/drivers/atm/suni.c
28676@@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28677
28678
28679 #define ADD_LIMITED(s,v) \
28680- atomic_add((v),&stats->s); \
28681- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28682+ atomic_add_unchecked((v),&stats->s); \
28683+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28684
28685
28686 static void suni_hz(unsigned long from_timer)
28687diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28688index 5120a96..e2572bd 100644
28689--- a/drivers/atm/uPD98402.c
28690+++ b/drivers/atm/uPD98402.c
28691@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28692 struct sonet_stats tmp;
28693 int error = 0;
28694
28695- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28696+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28697 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28698 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28699 if (zero && !error) {
28700@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28701
28702
28703 #define ADD_LIMITED(s,v) \
28704- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28705- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28706- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28707+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28708+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28709+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28710
28711
28712 static void stat_event(struct atm_dev *dev)
28713@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28714 if (reason & uPD98402_INT_PFM) stat_event(dev);
28715 if (reason & uPD98402_INT_PCO) {
28716 (void) GET(PCOCR); /* clear interrupt cause */
28717- atomic_add(GET(HECCT),
28718+ atomic_add_unchecked(GET(HECCT),
28719 &PRIV(dev)->sonet_stats.uncorr_hcs);
28720 }
28721 if ((reason & uPD98402_INT_RFO) &&
28722@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28723 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28724 uPD98402_INT_LOS),PIMR); /* enable them */
28725 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28726- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28727- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28728- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28729+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28730+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28731+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28732 return 0;
28733 }
28734
28735diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28736index d889f56..17eb71e 100644
28737--- a/drivers/atm/zatm.c
28738+++ b/drivers/atm/zatm.c
28739@@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28740 }
28741 if (!size) {
28742 dev_kfree_skb_irq(skb);
28743- if (vcc) atomic_inc(&vcc->stats->rx_err);
28744+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28745 continue;
28746 }
28747 if (!atm_charge(vcc,skb->truesize)) {
28748@@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28749 skb->len = size;
28750 ATM_SKB(skb)->vcc = vcc;
28751 vcc->push(vcc,skb);
28752- atomic_inc(&vcc->stats->rx);
28753+ atomic_inc_unchecked(&vcc->stats->rx);
28754 }
28755 zout(pos & 0xffff,MTA(mbx));
28756 #if 0 /* probably a stupid idea */
28757@@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28758 skb_queue_head(&zatm_vcc->backlog,skb);
28759 break;
28760 }
28761- atomic_inc(&vcc->stats->tx);
28762+ atomic_inc_unchecked(&vcc->stats->tx);
28763 wake_up(&zatm_vcc->tx_wait);
28764 }
28765
28766diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28767index 8493536..31adee0 100644
28768--- a/drivers/base/devtmpfs.c
28769+++ b/drivers/base/devtmpfs.c
28770@@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28771 if (!thread)
28772 return 0;
28773
28774- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28775+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28776 if (err)
28777 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28778 else
28779diff --git a/drivers/base/node.c b/drivers/base/node.c
28780index 90aa2a1..af1a177 100644
28781--- a/drivers/base/node.c
28782+++ b/drivers/base/node.c
28783@@ -592,11 +592,9 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
28784 {
28785 int n;
28786
28787- n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
28788- if (n > 0 && PAGE_SIZE > n + 1) {
28789- *(buf + n++) = '\n';
28790- *(buf + n++) = '\0';
28791- }
28792+ n = nodelist_scnprintf(buf, PAGE_SIZE-2, node_states[state]);
28793+ buf[n++] = '\n';
28794+ buf[n] = '\0';
28795 return n;
28796 }
28797
28798diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28799index caf995f..6f76697 100644
28800--- a/drivers/base/power/wakeup.c
28801+++ b/drivers/base/power/wakeup.c
28802@@ -30,14 +30,14 @@ bool events_check_enabled;
28803 * They need to be modified together atomically, so it's better to use one
28804 * atomic variable to hold them both.
28805 */
28806-static atomic_t combined_event_count = ATOMIC_INIT(0);
28807+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28808
28809 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28810 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28811
28812 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28813 {
28814- unsigned int comb = atomic_read(&combined_event_count);
28815+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
28816
28817 *cnt = (comb >> IN_PROGRESS_BITS);
28818 *inpr = comb & MAX_IN_PROGRESS;
28819@@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28820 ws->last_time = ktime_get();
28821
28822 /* Increment the counter of events in progress. */
28823- atomic_inc(&combined_event_count);
28824+ atomic_inc_unchecked(&combined_event_count);
28825 }
28826
28827 /**
28828@@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28829 * Increment the counter of registered wakeup events and decrement the
28830 * couter of wakeup events in progress simultaneously.
28831 */
28832- atomic_add(MAX_IN_PROGRESS, &combined_event_count);
28833+ atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28834 }
28835
28836 /**
28837diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28838index b0f553b..77b928b 100644
28839--- a/drivers/block/cciss.c
28840+++ b/drivers/block/cciss.c
28841@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28842 int err;
28843 u32 cp;
28844
28845+ memset(&arg64, 0, sizeof(arg64));
28846+
28847 err = 0;
28848 err |=
28849 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28850@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28851 while (!list_empty(&h->reqQ)) {
28852 c = list_entry(h->reqQ.next, CommandList_struct, list);
28853 /* can't do anything if fifo is full */
28854- if ((h->access.fifo_full(h))) {
28855+ if ((h->access->fifo_full(h))) {
28856 dev_warn(&h->pdev->dev, "fifo full\n");
28857 break;
28858 }
28859@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28860 h->Qdepth--;
28861
28862 /* Tell the controller execute command */
28863- h->access.submit_command(h, c);
28864+ h->access->submit_command(h, c);
28865
28866 /* Put job onto the completed Q */
28867 addQ(&h->cmpQ, c);
28868@@ -3443,17 +3445,17 @@ startio:
28869
28870 static inline unsigned long get_next_completion(ctlr_info_t *h)
28871 {
28872- return h->access.command_completed(h);
28873+ return h->access->command_completed(h);
28874 }
28875
28876 static inline int interrupt_pending(ctlr_info_t *h)
28877 {
28878- return h->access.intr_pending(h);
28879+ return h->access->intr_pending(h);
28880 }
28881
28882 static inline long interrupt_not_for_us(ctlr_info_t *h)
28883 {
28884- return ((h->access.intr_pending(h) == 0) ||
28885+ return ((h->access->intr_pending(h) == 0) ||
28886 (h->interrupts_enabled == 0));
28887 }
28888
28889@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28890 u32 a;
28891
28892 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28893- return h->access.command_completed(h);
28894+ return h->access->command_completed(h);
28895
28896 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28897 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28898@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28899 trans_support & CFGTBL_Trans_use_short_tags);
28900
28901 /* Change the access methods to the performant access methods */
28902- h->access = SA5_performant_access;
28903+ h->access = &SA5_performant_access;
28904 h->transMethod = CFGTBL_Trans_Performant;
28905
28906 return;
28907@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28908 if (prod_index < 0)
28909 return -ENODEV;
28910 h->product_name = products[prod_index].product_name;
28911- h->access = *(products[prod_index].access);
28912+ h->access = products[prod_index].access;
28913
28914 if (cciss_board_disabled(h)) {
28915 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28916@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28917 }
28918
28919 /* make sure the board interrupts are off */
28920- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28921+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28922 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28923 if (rc)
28924 goto clean2;
28925@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28926 * fake ones to scoop up any residual completions.
28927 */
28928 spin_lock_irqsave(&h->lock, flags);
28929- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28930+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28931 spin_unlock_irqrestore(&h->lock, flags);
28932 free_irq(h->intr[h->intr_mode], h);
28933 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28934@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28935 dev_info(&h->pdev->dev, "Board READY.\n");
28936 dev_info(&h->pdev->dev,
28937 "Waiting for stale completions to drain.\n");
28938- h->access.set_intr_mask(h, CCISS_INTR_ON);
28939+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28940 msleep(10000);
28941- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28942+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28943
28944 rc = controller_reset_failed(h->cfgtable);
28945 if (rc)
28946@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28947 cciss_scsi_setup(h);
28948
28949 /* Turn the interrupts on so we can service requests */
28950- h->access.set_intr_mask(h, CCISS_INTR_ON);
28951+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28952
28953 /* Get the firmware version */
28954 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28955@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28956 kfree(flush_buf);
28957 if (return_code != IO_OK)
28958 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28959- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28960+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28961 free_irq(h->intr[h->intr_mode], h);
28962 }
28963
28964diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28965index 7fda30e..eb5dfe0 100644
28966--- a/drivers/block/cciss.h
28967+++ b/drivers/block/cciss.h
28968@@ -101,7 +101,7 @@ struct ctlr_info
28969 /* information about each logical volume */
28970 drive_info_struct *drv[CISS_MAX_LUN];
28971
28972- struct access_method access;
28973+ struct access_method *access;
28974
28975 /* queue and queue Info */
28976 struct list_head reqQ;
28977diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28978index 9125bbe..eede5c8 100644
28979--- a/drivers/block/cpqarray.c
28980+++ b/drivers/block/cpqarray.c
28981@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28982 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28983 goto Enomem4;
28984 }
28985- hba[i]->access.set_intr_mask(hba[i], 0);
28986+ hba[i]->access->set_intr_mask(hba[i], 0);
28987 if (request_irq(hba[i]->intr, do_ida_intr,
28988 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28989 {
28990@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28991 add_timer(&hba[i]->timer);
28992
28993 /* Enable IRQ now that spinlock and rate limit timer are set up */
28994- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28995+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28996
28997 for(j=0; j<NWD; j++) {
28998 struct gendisk *disk = ida_gendisk[i][j];
28999@@ -694,7 +694,7 @@ DBGINFO(
29000 for(i=0; i<NR_PRODUCTS; i++) {
29001 if (board_id == products[i].board_id) {
29002 c->product_name = products[i].product_name;
29003- c->access = *(products[i].access);
29004+ c->access = products[i].access;
29005 break;
29006 }
29007 }
29008@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29009 hba[ctlr]->intr = intr;
29010 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29011 hba[ctlr]->product_name = products[j].product_name;
29012- hba[ctlr]->access = *(products[j].access);
29013+ hba[ctlr]->access = products[j].access;
29014 hba[ctlr]->ctlr = ctlr;
29015 hba[ctlr]->board_id = board_id;
29016 hba[ctlr]->pci_dev = NULL; /* not PCI */
29017@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29018
29019 while((c = h->reqQ) != NULL) {
29020 /* Can't do anything if we're busy */
29021- if (h->access.fifo_full(h) == 0)
29022+ if (h->access->fifo_full(h) == 0)
29023 return;
29024
29025 /* Get the first entry from the request Q */
29026@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29027 h->Qdepth--;
29028
29029 /* Tell the controller to do our bidding */
29030- h->access.submit_command(h, c);
29031+ h->access->submit_command(h, c);
29032
29033 /* Get onto the completion Q */
29034 addQ(&h->cmpQ, c);
29035@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29036 unsigned long flags;
29037 __u32 a,a1;
29038
29039- istat = h->access.intr_pending(h);
29040+ istat = h->access->intr_pending(h);
29041 /* Is this interrupt for us? */
29042 if (istat == 0)
29043 return IRQ_NONE;
29044@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29045 */
29046 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29047 if (istat & FIFO_NOT_EMPTY) {
29048- while((a = h->access.command_completed(h))) {
29049+ while((a = h->access->command_completed(h))) {
29050 a1 = a; a &= ~3;
29051 if ((c = h->cmpQ) == NULL)
29052 {
29053@@ -1449,11 +1449,11 @@ static int sendcmd(
29054 /*
29055 * Disable interrupt
29056 */
29057- info_p->access.set_intr_mask(info_p, 0);
29058+ info_p->access->set_intr_mask(info_p, 0);
29059 /* Make sure there is room in the command FIFO */
29060 /* Actually it should be completely empty at this time. */
29061 for (i = 200000; i > 0; i--) {
29062- temp = info_p->access.fifo_full(info_p);
29063+ temp = info_p->access->fifo_full(info_p);
29064 if (temp != 0) {
29065 break;
29066 }
29067@@ -1466,7 +1466,7 @@ DBG(
29068 /*
29069 * Send the cmd
29070 */
29071- info_p->access.submit_command(info_p, c);
29072+ info_p->access->submit_command(info_p, c);
29073 complete = pollcomplete(ctlr);
29074
29075 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29076@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29077 * we check the new geometry. Then turn interrupts back on when
29078 * we're done.
29079 */
29080- host->access.set_intr_mask(host, 0);
29081+ host->access->set_intr_mask(host, 0);
29082 getgeometry(ctlr);
29083- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29084+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29085
29086 for(i=0; i<NWD; i++) {
29087 struct gendisk *disk = ida_gendisk[ctlr][i];
29088@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29089 /* Wait (up to 2 seconds) for a command to complete */
29090
29091 for (i = 200000; i > 0; i--) {
29092- done = hba[ctlr]->access.command_completed(hba[ctlr]);
29093+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
29094 if (done == 0) {
29095 udelay(10); /* a short fixed delay */
29096 } else
29097diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29098index be73e9d..7fbf140 100644
29099--- a/drivers/block/cpqarray.h
29100+++ b/drivers/block/cpqarray.h
29101@@ -99,7 +99,7 @@ struct ctlr_info {
29102 drv_info_t drv[NWD];
29103 struct proc_dir_entry *proc;
29104
29105- struct access_method access;
29106+ struct access_method *access;
29107
29108 cmdlist_t *reqQ;
29109 cmdlist_t *cmpQ;
29110diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29111index 8d68056..e67050f 100644
29112--- a/drivers/block/drbd/drbd_int.h
29113+++ b/drivers/block/drbd/drbd_int.h
29114@@ -736,7 +736,7 @@ struct drbd_request;
29115 struct drbd_epoch {
29116 struct list_head list;
29117 unsigned int barrier_nr;
29118- atomic_t epoch_size; /* increased on every request added. */
29119+ atomic_unchecked_t epoch_size; /* increased on every request added. */
29120 atomic_t active; /* increased on every req. added, and dec on every finished. */
29121 unsigned long flags;
29122 };
29123@@ -1108,7 +1108,7 @@ struct drbd_conf {
29124 void *int_dig_in;
29125 void *int_dig_vv;
29126 wait_queue_head_t seq_wait;
29127- atomic_t packet_seq;
29128+ atomic_unchecked_t packet_seq;
29129 unsigned int peer_seq;
29130 spinlock_t peer_seq_lock;
29131 unsigned int minor;
29132@@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29133
29134 static inline void drbd_tcp_cork(struct socket *sock)
29135 {
29136- int __user val = 1;
29137+ int val = 1;
29138 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29139- (char __user *)&val, sizeof(val));
29140+ (char __force_user *)&val, sizeof(val));
29141 }
29142
29143 static inline void drbd_tcp_uncork(struct socket *sock)
29144 {
29145- int __user val = 0;
29146+ int val = 0;
29147 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29148- (char __user *)&val, sizeof(val));
29149+ (char __force_user *)&val, sizeof(val));
29150 }
29151
29152 static inline void drbd_tcp_nodelay(struct socket *sock)
29153 {
29154- int __user val = 1;
29155+ int val = 1;
29156 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29157- (char __user *)&val, sizeof(val));
29158+ (char __force_user *)&val, sizeof(val));
29159 }
29160
29161 static inline void drbd_tcp_quickack(struct socket *sock)
29162 {
29163- int __user val = 2;
29164+ int val = 2;
29165 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29166- (char __user *)&val, sizeof(val));
29167+ (char __force_user *)&val, sizeof(val));
29168 }
29169
29170 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29171diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29172index 211fc44..c5116f1 100644
29173--- a/drivers/block/drbd/drbd_main.c
29174+++ b/drivers/block/drbd/drbd_main.c
29175@@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29176 p.sector = sector;
29177 p.block_id = block_id;
29178 p.blksize = blksize;
29179- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29180+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29181
29182 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29183 return false;
29184@@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29185 p.sector = cpu_to_be64(req->sector);
29186 p.block_id = (unsigned long)req;
29187 p.seq_num = cpu_to_be32(req->seq_num =
29188- atomic_add_return(1, &mdev->packet_seq));
29189+ atomic_add_return_unchecked(1, &mdev->packet_seq));
29190
29191 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29192
29193@@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29194 atomic_set(&mdev->unacked_cnt, 0);
29195 atomic_set(&mdev->local_cnt, 0);
29196 atomic_set(&mdev->net_cnt, 0);
29197- atomic_set(&mdev->packet_seq, 0);
29198+ atomic_set_unchecked(&mdev->packet_seq, 0);
29199 atomic_set(&mdev->pp_in_use, 0);
29200 atomic_set(&mdev->pp_in_use_by_net, 0);
29201 atomic_set(&mdev->rs_sect_in, 0);
29202@@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29203 mdev->receiver.t_state);
29204
29205 /* no need to lock it, I'm the only thread alive */
29206- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29207- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29208+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29209+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29210 mdev->al_writ_cnt =
29211 mdev->bm_writ_cnt =
29212 mdev->read_cnt =
29213diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29214index af2a250..0fdeb75 100644
29215--- a/drivers/block/drbd/drbd_nl.c
29216+++ b/drivers/block/drbd/drbd_nl.c
29217@@ -2297,7 +2297,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29218 return;
29219 }
29220
29221- if (!cap_raised(current_cap(), CAP_SYS_ADMIN)) {
29222+ if (!capable(CAP_SYS_ADMIN)) {
29223 retcode = ERR_PERM;
29224 goto fail;
29225 }
29226@@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29227 module_put(THIS_MODULE);
29228 }
29229
29230-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29231+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29232
29233 static unsigned short *
29234 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29235@@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29236 cn_reply->id.idx = CN_IDX_DRBD;
29237 cn_reply->id.val = CN_VAL_DRBD;
29238
29239- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29240+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29241 cn_reply->ack = 0; /* not used here. */
29242 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29243 (int)((char *)tl - (char *)reply->tag_list);
29244@@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29245 cn_reply->id.idx = CN_IDX_DRBD;
29246 cn_reply->id.val = CN_VAL_DRBD;
29247
29248- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29249+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29250 cn_reply->ack = 0; /* not used here. */
29251 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29252 (int)((char *)tl - (char *)reply->tag_list);
29253@@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29254 cn_reply->id.idx = CN_IDX_DRBD;
29255 cn_reply->id.val = CN_VAL_DRBD;
29256
29257- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29258+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29259 cn_reply->ack = 0; // not used here.
29260 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29261 (int)((char*)tl - (char*)reply->tag_list);
29262@@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29263 cn_reply->id.idx = CN_IDX_DRBD;
29264 cn_reply->id.val = CN_VAL_DRBD;
29265
29266- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29267+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29268 cn_reply->ack = 0; /* not used here. */
29269 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29270 (int)((char *)tl - (char *)reply->tag_list);
29271diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29272index 43beaca..4a5b1dd 100644
29273--- a/drivers/block/drbd/drbd_receiver.c
29274+++ b/drivers/block/drbd/drbd_receiver.c
29275@@ -894,7 +894,7 @@ retry:
29276 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29277 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29278
29279- atomic_set(&mdev->packet_seq, 0);
29280+ atomic_set_unchecked(&mdev->packet_seq, 0);
29281 mdev->peer_seq = 0;
29282
29283 drbd_thread_start(&mdev->asender);
29284@@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29285 do {
29286 next_epoch = NULL;
29287
29288- epoch_size = atomic_read(&epoch->epoch_size);
29289+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29290
29291 switch (ev & ~EV_CLEANUP) {
29292 case EV_PUT:
29293@@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29294 rv = FE_DESTROYED;
29295 } else {
29296 epoch->flags = 0;
29297- atomic_set(&epoch->epoch_size, 0);
29298+ atomic_set_unchecked(&epoch->epoch_size, 0);
29299 /* atomic_set(&epoch->active, 0); is already zero */
29300 if (rv == FE_STILL_LIVE)
29301 rv = FE_RECYCLED;
29302@@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29303 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29304 drbd_flush(mdev);
29305
29306- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29307+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29308 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29309 if (epoch)
29310 break;
29311 }
29312
29313 epoch = mdev->current_epoch;
29314- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29315+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29316
29317 D_ASSERT(atomic_read(&epoch->active) == 0);
29318 D_ASSERT(epoch->flags == 0);
29319@@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29320 }
29321
29322 epoch->flags = 0;
29323- atomic_set(&epoch->epoch_size, 0);
29324+ atomic_set_unchecked(&epoch->epoch_size, 0);
29325 atomic_set(&epoch->active, 0);
29326
29327 spin_lock(&mdev->epoch_lock);
29328- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29329+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29330 list_add(&epoch->list, &mdev->current_epoch->list);
29331 mdev->current_epoch = epoch;
29332 mdev->epochs++;
29333@@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29334 spin_unlock(&mdev->peer_seq_lock);
29335
29336 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29337- atomic_inc(&mdev->current_epoch->epoch_size);
29338+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29339 return drbd_drain_block(mdev, data_size);
29340 }
29341
29342@@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29343
29344 spin_lock(&mdev->epoch_lock);
29345 e->epoch = mdev->current_epoch;
29346- atomic_inc(&e->epoch->epoch_size);
29347+ atomic_inc_unchecked(&e->epoch->epoch_size);
29348 atomic_inc(&e->epoch->active);
29349 spin_unlock(&mdev->epoch_lock);
29350
29351@@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29352 D_ASSERT(list_empty(&mdev->done_ee));
29353
29354 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29355- atomic_set(&mdev->current_epoch->epoch_size, 0);
29356+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29357 D_ASSERT(list_empty(&mdev->current_epoch->list));
29358 }
29359
29360diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29361index cd50435..ba1ffb5 100644
29362--- a/drivers/block/loop.c
29363+++ b/drivers/block/loop.c
29364@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29365 mm_segment_t old_fs = get_fs();
29366
29367 set_fs(get_ds());
29368- bw = file->f_op->write(file, buf, len, &pos);
29369+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29370 set_fs(old_fs);
29371 if (likely(bw == len))
29372 return 0;
29373diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29374index 4364303..9adf4ee 100644
29375--- a/drivers/char/Kconfig
29376+++ b/drivers/char/Kconfig
29377@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29378
29379 config DEVKMEM
29380 bool "/dev/kmem virtual device support"
29381- default y
29382+ default n
29383+ depends on !GRKERNSEC_KMEM
29384 help
29385 Say Y here if you want to support the /dev/kmem device. The
29386 /dev/kmem device is rarely used, but can be used for certain
29387@@ -596,6 +597,7 @@ config DEVPORT
29388 bool
29389 depends on !M68K
29390 depends on ISA || PCI
29391+ depends on !GRKERNSEC_KMEM
29392 default y
29393
29394 source "drivers/s390/char/Kconfig"
29395diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29396index 2e04433..22afc64 100644
29397--- a/drivers/char/agp/frontend.c
29398+++ b/drivers/char/agp/frontend.c
29399@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29400 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29401 return -EFAULT;
29402
29403- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29404+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29405 return -EFAULT;
29406
29407 client = agp_find_client_by_pid(reserve.pid);
29408diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
29409index 095ab90..afad0a4 100644
29410--- a/drivers/char/briq_panel.c
29411+++ b/drivers/char/briq_panel.c
29412@@ -9,6 +9,7 @@
29413 #include <linux/types.h>
29414 #include <linux/errno.h>
29415 #include <linux/tty.h>
29416+#include <linux/mutex.h>
29417 #include <linux/timer.h>
29418 #include <linux/kernel.h>
29419 #include <linux/wait.h>
29420@@ -34,6 +35,7 @@ static int vfd_is_open;
29421 static unsigned char vfd[40];
29422 static int vfd_cursor;
29423 static unsigned char ledpb, led;
29424+static DEFINE_MUTEX(vfd_mutex);
29425
29426 static void update_vfd(void)
29427 {
29428@@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29429 if (!vfd_is_open)
29430 return -EBUSY;
29431
29432+ mutex_lock(&vfd_mutex);
29433 for (;;) {
29434 char c;
29435 if (!indx)
29436 break;
29437- if (get_user(c, buf))
29438+ if (get_user(c, buf)) {
29439+ mutex_unlock(&vfd_mutex);
29440 return -EFAULT;
29441+ }
29442 if (esc) {
29443 set_led(c);
29444 esc = 0;
29445@@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29446 buf++;
29447 }
29448 update_vfd();
29449+ mutex_unlock(&vfd_mutex);
29450
29451 return len;
29452 }
29453diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29454index f773a9d..65cd683 100644
29455--- a/drivers/char/genrtc.c
29456+++ b/drivers/char/genrtc.c
29457@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
29458 switch (cmd) {
29459
29460 case RTC_PLL_GET:
29461+ memset(&pll, 0, sizeof(pll));
29462 if (get_rtc_pll(&pll))
29463 return -EINVAL;
29464 else
29465diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29466index 0833896..cccce52 100644
29467--- a/drivers/char/hpet.c
29468+++ b/drivers/char/hpet.c
29469@@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29470 }
29471
29472 static int
29473-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29474+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29475 struct hpet_info *info)
29476 {
29477 struct hpet_timer __iomem *timer;
29478diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29479index 58c0e63..46c16bf 100644
29480--- a/drivers/char/ipmi/ipmi_msghandler.c
29481+++ b/drivers/char/ipmi/ipmi_msghandler.c
29482@@ -415,7 +415,7 @@ struct ipmi_smi {
29483 struct proc_dir_entry *proc_dir;
29484 char proc_dir_name[10];
29485
29486- atomic_t stats[IPMI_NUM_STATS];
29487+ atomic_unchecked_t stats[IPMI_NUM_STATS];
29488
29489 /*
29490 * run_to_completion duplicate of smb_info, smi_info
29491@@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29492
29493
29494 #define ipmi_inc_stat(intf, stat) \
29495- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29496+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29497 #define ipmi_get_stat(intf, stat) \
29498- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29499+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29500
29501 static int is_lan_addr(struct ipmi_addr *addr)
29502 {
29503@@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29504 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29505 init_waitqueue_head(&intf->waitq);
29506 for (i = 0; i < IPMI_NUM_STATS; i++)
29507- atomic_set(&intf->stats[i], 0);
29508+ atomic_set_unchecked(&intf->stats[i], 0);
29509
29510 intf->proc_dir = NULL;
29511
29512diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29513index 50fcf9c..91b5528 100644
29514--- a/drivers/char/ipmi/ipmi_si_intf.c
29515+++ b/drivers/char/ipmi/ipmi_si_intf.c
29516@@ -277,7 +277,7 @@ struct smi_info {
29517 unsigned char slave_addr;
29518
29519 /* Counters and things for the proc filesystem. */
29520- atomic_t stats[SI_NUM_STATS];
29521+ atomic_unchecked_t stats[SI_NUM_STATS];
29522
29523 struct task_struct *thread;
29524
29525@@ -286,9 +286,9 @@ struct smi_info {
29526 };
29527
29528 #define smi_inc_stat(smi, stat) \
29529- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29530+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29531 #define smi_get_stat(smi, stat) \
29532- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29533+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29534
29535 #define SI_MAX_PARMS 4
29536
29537@@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
29538 atomic_set(&new_smi->req_events, 0);
29539 new_smi->run_to_completion = 0;
29540 for (i = 0; i < SI_NUM_STATS; i++)
29541- atomic_set(&new_smi->stats[i], 0);
29542+ atomic_set_unchecked(&new_smi->stats[i], 0);
29543
29544 new_smi->interrupt_disabled = 1;
29545 atomic_set(&new_smi->stop_operation, 0);
29546diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29547index 1aeaaba..e018570 100644
29548--- a/drivers/char/mbcs.c
29549+++ b/drivers/char/mbcs.c
29550@@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
29551 return 0;
29552 }
29553
29554-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29555+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29556 {
29557 .part_num = MBCS_PART_NUM,
29558 .mfg_num = MBCS_MFG_NUM,
29559diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29560index d6e9d08..4493e89 100644
29561--- a/drivers/char/mem.c
29562+++ b/drivers/char/mem.c
29563@@ -18,6 +18,7 @@
29564 #include <linux/raw.h>
29565 #include <linux/tty.h>
29566 #include <linux/capability.h>
29567+#include <linux/security.h>
29568 #include <linux/ptrace.h>
29569 #include <linux/device.h>
29570 #include <linux/highmem.h>
29571@@ -35,6 +36,10 @@
29572 # include <linux/efi.h>
29573 #endif
29574
29575+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29576+extern const struct file_operations grsec_fops;
29577+#endif
29578+
29579 static inline unsigned long size_inside_page(unsigned long start,
29580 unsigned long size)
29581 {
29582@@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29583
29584 while (cursor < to) {
29585 if (!devmem_is_allowed(pfn)) {
29586+#ifdef CONFIG_GRKERNSEC_KMEM
29587+ gr_handle_mem_readwrite(from, to);
29588+#else
29589 printk(KERN_INFO
29590 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29591 current->comm, from, to);
29592+#endif
29593 return 0;
29594 }
29595 cursor += PAGE_SIZE;
29596@@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29597 }
29598 return 1;
29599 }
29600+#elif defined(CONFIG_GRKERNSEC_KMEM)
29601+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29602+{
29603+ return 0;
29604+}
29605 #else
29606 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29607 {
29608@@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29609
29610 while (count > 0) {
29611 unsigned long remaining;
29612+ char *temp;
29613
29614 sz = size_inside_page(p, count);
29615
29616@@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29617 if (!ptr)
29618 return -EFAULT;
29619
29620- remaining = copy_to_user(buf, ptr, sz);
29621+#ifdef CONFIG_PAX_USERCOPY
29622+ temp = kmalloc(sz, GFP_KERNEL);
29623+ if (!temp) {
29624+ unxlate_dev_mem_ptr(p, ptr);
29625+ return -ENOMEM;
29626+ }
29627+ memcpy(temp, ptr, sz);
29628+#else
29629+ temp = ptr;
29630+#endif
29631+
29632+ remaining = copy_to_user(buf, temp, sz);
29633+
29634+#ifdef CONFIG_PAX_USERCOPY
29635+ kfree(temp);
29636+#endif
29637+
29638 unxlate_dev_mem_ptr(p, ptr);
29639 if (remaining)
29640 return -EFAULT;
29641@@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29642 size_t count, loff_t *ppos)
29643 {
29644 unsigned long p = *ppos;
29645- ssize_t low_count, read, sz;
29646+ ssize_t low_count, read, sz, err = 0;
29647 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29648- int err = 0;
29649
29650 read = 0;
29651 if (p < (unsigned long) high_memory) {
29652@@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29653 }
29654 #endif
29655 while (low_count > 0) {
29656+ char *temp;
29657+
29658 sz = size_inside_page(p, low_count);
29659
29660 /*
29661@@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29662 */
29663 kbuf = xlate_dev_kmem_ptr((char *)p);
29664
29665- if (copy_to_user(buf, kbuf, sz))
29666+#ifdef CONFIG_PAX_USERCOPY
29667+ temp = kmalloc(sz, GFP_KERNEL);
29668+ if (!temp)
29669+ return -ENOMEM;
29670+ memcpy(temp, kbuf, sz);
29671+#else
29672+ temp = kbuf;
29673+#endif
29674+
29675+ err = copy_to_user(buf, temp, sz);
29676+
29677+#ifdef CONFIG_PAX_USERCOPY
29678+ kfree(temp);
29679+#endif
29680+
29681+ if (err)
29682 return -EFAULT;
29683 buf += sz;
29684 p += sz;
29685@@ -867,6 +914,9 @@ static const struct memdev {
29686 #ifdef CONFIG_CRASH_DUMP
29687 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29688 #endif
29689+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29690+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29691+#endif
29692 };
29693
29694 static int memory_open(struct inode *inode, struct file *filp)
29695diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29696index da3cfee..a5a6606 100644
29697--- a/drivers/char/nvram.c
29698+++ b/drivers/char/nvram.c
29699@@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29700
29701 spin_unlock_irq(&rtc_lock);
29702
29703- if (copy_to_user(buf, contents, tmp - contents))
29704+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29705 return -EFAULT;
29706
29707 *ppos = i;
29708diff --git a/drivers/char/random.c b/drivers/char/random.c
29709index 54ca8b2..4a092ed 100644
29710--- a/drivers/char/random.c
29711+++ b/drivers/char/random.c
29712@@ -261,8 +261,13 @@
29713 /*
29714 * Configuration information
29715 */
29716+#ifdef CONFIG_GRKERNSEC_RANDNET
29717+#define INPUT_POOL_WORDS 512
29718+#define OUTPUT_POOL_WORDS 128
29719+#else
29720 #define INPUT_POOL_WORDS 128
29721 #define OUTPUT_POOL_WORDS 32
29722+#endif
29723 #define SEC_XFER_SIZE 512
29724 #define EXTRACT_SIZE 10
29725
29726@@ -300,10 +305,17 @@ static struct poolinfo {
29727 int poolwords;
29728 int tap1, tap2, tap3, tap4, tap5;
29729 } poolinfo_table[] = {
29730+#ifdef CONFIG_GRKERNSEC_RANDNET
29731+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29732+ { 512, 411, 308, 208, 104, 1 },
29733+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29734+ { 128, 103, 76, 51, 25, 1 },
29735+#else
29736 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29737 { 128, 103, 76, 51, 25, 1 },
29738 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29739 { 32, 26, 20, 14, 7, 1 },
29740+#endif
29741 #if 0
29742 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29743 { 2048, 1638, 1231, 819, 411, 1 },
29744@@ -913,7 +925,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29745
29746 extract_buf(r, tmp);
29747 i = min_t(int, nbytes, EXTRACT_SIZE);
29748- if (copy_to_user(buf, tmp, i)) {
29749+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29750 ret = -EFAULT;
29751 break;
29752 }
29753@@ -1238,7 +1250,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29754 #include <linux/sysctl.h>
29755
29756 static int min_read_thresh = 8, min_write_thresh;
29757-static int max_read_thresh = INPUT_POOL_WORDS * 32;
29758+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29759 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29760 static char sysctl_bootid[16];
29761
29762@@ -1260,10 +1272,15 @@ static int proc_do_uuid(ctl_table *table, int write,
29763 uuid = table->data;
29764 if (!uuid) {
29765 uuid = tmp_uuid;
29766- uuid[8] = 0;
29767- }
29768- if (uuid[8] == 0)
29769 generate_random_uuid(uuid);
29770+ } else {
29771+ static DEFINE_SPINLOCK(bootid_spinlock);
29772+
29773+ spin_lock(&bootid_spinlock);
29774+ if (!uuid[8])
29775+ generate_random_uuid(uuid);
29776+ spin_unlock(&bootid_spinlock);
29777+ }
29778
29779 sprintf(buf, "%pU", uuid);
29780
29781diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29782index 1ee8ce7..b778bef 100644
29783--- a/drivers/char/sonypi.c
29784+++ b/drivers/char/sonypi.c
29785@@ -55,6 +55,7 @@
29786 #include <asm/uaccess.h>
29787 #include <asm/io.h>
29788 #include <asm/system.h>
29789+#include <asm/local.h>
29790
29791 #include <linux/sonypi.h>
29792
29793@@ -491,7 +492,7 @@ static struct sonypi_device {
29794 spinlock_t fifo_lock;
29795 wait_queue_head_t fifo_proc_list;
29796 struct fasync_struct *fifo_async;
29797- int open_count;
29798+ local_t open_count;
29799 int model;
29800 struct input_dev *input_jog_dev;
29801 struct input_dev *input_key_dev;
29802@@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29803 static int sonypi_misc_release(struct inode *inode, struct file *file)
29804 {
29805 mutex_lock(&sonypi_device.lock);
29806- sonypi_device.open_count--;
29807+ local_dec(&sonypi_device.open_count);
29808 mutex_unlock(&sonypi_device.lock);
29809 return 0;
29810 }
29811@@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29812 {
29813 mutex_lock(&sonypi_device.lock);
29814 /* Flush input queue on first open */
29815- if (!sonypi_device.open_count)
29816+ if (!local_read(&sonypi_device.open_count))
29817 kfifo_reset(&sonypi_device.fifo);
29818- sonypi_device.open_count++;
29819+ local_inc(&sonypi_device.open_count);
29820 mutex_unlock(&sonypi_device.lock);
29821
29822 return 0;
29823diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29824index ad7c732..5aa8054 100644
29825--- a/drivers/char/tpm/tpm.c
29826+++ b/drivers/char/tpm/tpm.c
29827@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29828 chip->vendor.req_complete_val)
29829 goto out_recv;
29830
29831- if ((status == chip->vendor.req_canceled)) {
29832+ if (status == chip->vendor.req_canceled) {
29833 dev_err(chip->dev, "Operation Canceled\n");
29834 rc = -ECANCELED;
29835 goto out;
29836diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29837index 0636520..169c1d0 100644
29838--- a/drivers/char/tpm/tpm_bios.c
29839+++ b/drivers/char/tpm/tpm_bios.c
29840@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29841 event = addr;
29842
29843 if ((event->event_type == 0 && event->event_size == 0) ||
29844- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29845+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29846 return NULL;
29847
29848 return addr;
29849@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29850 return NULL;
29851
29852 if ((event->event_type == 0 && event->event_size == 0) ||
29853- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29854+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29855 return NULL;
29856
29857 (*pos)++;
29858@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29859 int i;
29860
29861 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29862- seq_putc(m, data[i]);
29863+ if (!seq_putc(m, data[i]))
29864+ return -EFAULT;
29865
29866 return 0;
29867 }
29868@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29869 log->bios_event_log_end = log->bios_event_log + len;
29870
29871 virt = acpi_os_map_memory(start, len);
29872+ if (!virt) {
29873+ kfree(log->bios_event_log);
29874+ log->bios_event_log = NULL;
29875+ return -EFAULT;
29876+ }
29877
29878- memcpy(log->bios_event_log, virt, len);
29879+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29880
29881 acpi_os_unmap_memory(virt, len);
29882 return 0;
29883diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29884index 41fc148..0dba6dd 100644
29885--- a/drivers/char/virtio_console.c
29886+++ b/drivers/char/virtio_console.c
29887@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29888 if (to_user) {
29889 ssize_t ret;
29890
29891- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29892+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29893 if (ret)
29894 return -EFAULT;
29895 } else {
29896@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29897 if (!port_has_data(port) && !port->host_connected)
29898 return 0;
29899
29900- return fill_readbuf(port, ubuf, count, true);
29901+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29902 }
29903
29904 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29905diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
29906index c9eee6d..f9d5280 100644
29907--- a/drivers/edac/amd64_edac.c
29908+++ b/drivers/edac/amd64_edac.c
29909@@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
29910 * PCI core identifies what devices are on a system during boot, and then
29911 * inquiry this table to see if this driver is for a given device found.
29912 */
29913-static const struct pci_device_id amd64_pci_table[] __devinitdata = {
29914+static const struct pci_device_id amd64_pci_table[] __devinitconst = {
29915 {
29916 .vendor = PCI_VENDOR_ID_AMD,
29917 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
29918diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
29919index e47e73b..348e0bd 100644
29920--- a/drivers/edac/amd76x_edac.c
29921+++ b/drivers/edac/amd76x_edac.c
29922@@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
29923 edac_mc_free(mci);
29924 }
29925
29926-static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
29927+static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
29928 {
29929 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29930 AMD762},
29931diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
29932index 1af531a..3a8ff27 100644
29933--- a/drivers/edac/e752x_edac.c
29934+++ b/drivers/edac/e752x_edac.c
29935@@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
29936 edac_mc_free(mci);
29937 }
29938
29939-static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
29940+static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
29941 {
29942 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29943 E7520},
29944diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
29945index 6ffb6d2..383d8d7 100644
29946--- a/drivers/edac/e7xxx_edac.c
29947+++ b/drivers/edac/e7xxx_edac.c
29948@@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
29949 edac_mc_free(mci);
29950 }
29951
29952-static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
29953+static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
29954 {
29955 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29956 E7205},
29957diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29958index 97f5064..202b6e6 100644
29959--- a/drivers/edac/edac_pci_sysfs.c
29960+++ b/drivers/edac/edac_pci_sysfs.c
29961@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29962 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29963 static int edac_pci_poll_msec = 1000; /* one second workq period */
29964
29965-static atomic_t pci_parity_count = ATOMIC_INIT(0);
29966-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29967+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29968+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29969
29970 static struct kobject *edac_pci_top_main_kobj;
29971 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29972@@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29973 edac_printk(KERN_CRIT, EDAC_PCI,
29974 "Signaled System Error on %s\n",
29975 pci_name(dev));
29976- atomic_inc(&pci_nonparity_count);
29977+ atomic_inc_unchecked(&pci_nonparity_count);
29978 }
29979
29980 if (status & (PCI_STATUS_PARITY)) {
29981@@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29982 "Master Data Parity Error on %s\n",
29983 pci_name(dev));
29984
29985- atomic_inc(&pci_parity_count);
29986+ atomic_inc_unchecked(&pci_parity_count);
29987 }
29988
29989 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29990@@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29991 "Detected Parity Error on %s\n",
29992 pci_name(dev));
29993
29994- atomic_inc(&pci_parity_count);
29995+ atomic_inc_unchecked(&pci_parity_count);
29996 }
29997 }
29998
29999@@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30000 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30001 "Signaled System Error on %s\n",
30002 pci_name(dev));
30003- atomic_inc(&pci_nonparity_count);
30004+ atomic_inc_unchecked(&pci_nonparity_count);
30005 }
30006
30007 if (status & (PCI_STATUS_PARITY)) {
30008@@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30009 "Master Data Parity Error on "
30010 "%s\n", pci_name(dev));
30011
30012- atomic_inc(&pci_parity_count);
30013+ atomic_inc_unchecked(&pci_parity_count);
30014 }
30015
30016 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30017@@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30018 "Detected Parity Error on %s\n",
30019 pci_name(dev));
30020
30021- atomic_inc(&pci_parity_count);
30022+ atomic_inc_unchecked(&pci_parity_count);
30023 }
30024 }
30025 }
30026@@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
30027 if (!check_pci_errors)
30028 return;
30029
30030- before_count = atomic_read(&pci_parity_count);
30031+ before_count = atomic_read_unchecked(&pci_parity_count);
30032
30033 /* scan all PCI devices looking for a Parity Error on devices and
30034 * bridges.
30035@@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
30036 /* Only if operator has selected panic on PCI Error */
30037 if (edac_pci_get_panic_on_pe()) {
30038 /* If the count is different 'after' from 'before' */
30039- if (before_count != atomic_read(&pci_parity_count))
30040+ if (before_count != atomic_read_unchecked(&pci_parity_count))
30041 panic("EDAC: PCI Parity Error");
30042 }
30043 }
30044diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
30045index c0510b3..6e2a954 100644
30046--- a/drivers/edac/i3000_edac.c
30047+++ b/drivers/edac/i3000_edac.c
30048@@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
30049 edac_mc_free(mci);
30050 }
30051
30052-static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
30053+static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
30054 {
30055 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30056 I3000},
30057diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
30058index 73f55e200..5faaf59 100644
30059--- a/drivers/edac/i3200_edac.c
30060+++ b/drivers/edac/i3200_edac.c
30061@@ -445,7 +445,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
30062 edac_mc_free(mci);
30063 }
30064
30065-static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
30066+static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
30067 {
30068 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30069 I3200},
30070diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
30071index 4dc3ac2..67d05a6 100644
30072--- a/drivers/edac/i5000_edac.c
30073+++ b/drivers/edac/i5000_edac.c
30074@@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
30075 *
30076 * The "E500P" device is the first device supported.
30077 */
30078-static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
30079+static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
30080 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
30081 .driver_data = I5000P},
30082
30083diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
30084index bcbdeec..9886d16 100644
30085--- a/drivers/edac/i5100_edac.c
30086+++ b/drivers/edac/i5100_edac.c
30087@@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
30088 edac_mc_free(mci);
30089 }
30090
30091-static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
30092+static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
30093 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
30094 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
30095 { 0, }
30096diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
30097index 74d6ec34..baff517 100644
30098--- a/drivers/edac/i5400_edac.c
30099+++ b/drivers/edac/i5400_edac.c
30100@@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
30101 *
30102 * The "E500P" device is the first device supported.
30103 */
30104-static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
30105+static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
30106 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
30107 {0,} /* 0 terminated list. */
30108 };
30109diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
30110index 6104dba..e7ea8e1 100644
30111--- a/drivers/edac/i7300_edac.c
30112+++ b/drivers/edac/i7300_edac.c
30113@@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
30114 *
30115 * Has only 8086:360c PCI ID
30116 */
30117-static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
30118+static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
30119 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
30120 {0,} /* 0 terminated list. */
30121 };
30122diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
30123index 8568d9b..42b2fa8 100644
30124--- a/drivers/edac/i7core_edac.c
30125+++ b/drivers/edac/i7core_edac.c
30126@@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
30127 /*
30128 * pci_device_id table for which devices we are looking for
30129 */
30130-static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
30131+static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
30132 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
30133 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
30134 {0,} /* 0 terminated list. */
30135diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
30136index 4329d39..f3022ef 100644
30137--- a/drivers/edac/i82443bxgx_edac.c
30138+++ b/drivers/edac/i82443bxgx_edac.c
30139@@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
30140
30141 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
30142
30143-static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
30144+static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
30145 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
30146 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
30147 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
30148diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
30149index 931a057..fd28340 100644
30150--- a/drivers/edac/i82860_edac.c
30151+++ b/drivers/edac/i82860_edac.c
30152@@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
30153 edac_mc_free(mci);
30154 }
30155
30156-static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
30157+static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
30158 {
30159 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30160 I82860},
30161diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
30162index 33864c6..01edc61 100644
30163--- a/drivers/edac/i82875p_edac.c
30164+++ b/drivers/edac/i82875p_edac.c
30165@@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
30166 edac_mc_free(mci);
30167 }
30168
30169-static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
30170+static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
30171 {
30172 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30173 I82875P},
30174diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
30175index 4184e01..dcb2cd3 100644
30176--- a/drivers/edac/i82975x_edac.c
30177+++ b/drivers/edac/i82975x_edac.c
30178@@ -612,7 +612,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
30179 edac_mc_free(mci);
30180 }
30181
30182-static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
30183+static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
30184 {
30185 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30186 I82975X
30187diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30188index 0106747..0b40417 100644
30189--- a/drivers/edac/mce_amd.h
30190+++ b/drivers/edac/mce_amd.h
30191@@ -83,7 +83,7 @@ struct amd_decoder_ops {
30192 bool (*dc_mce)(u16, u8);
30193 bool (*ic_mce)(u16, u8);
30194 bool (*nb_mce)(u16, u8);
30195-};
30196+} __no_const;
30197
30198 void amd_report_gart_errors(bool);
30199 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30200diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
30201index e294e1b..a41b05b 100644
30202--- a/drivers/edac/r82600_edac.c
30203+++ b/drivers/edac/r82600_edac.c
30204@@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
30205 edac_mc_free(mci);
30206 }
30207
30208-static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
30209+static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
30210 {
30211 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
30212 },
30213diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
30214index 1dc118d..8c68af9 100644
30215--- a/drivers/edac/sb_edac.c
30216+++ b/drivers/edac/sb_edac.c
30217@@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
30218 /*
30219 * pci_device_id table for which devices we are looking for
30220 */
30221-static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
30222+static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
30223 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
30224 {0,} /* 0 terminated list. */
30225 };
30226diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
30227index b6f47de..c5acf3a 100644
30228--- a/drivers/edac/x38_edac.c
30229+++ b/drivers/edac/x38_edac.c
30230@@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
30231 edac_mc_free(mci);
30232 }
30233
30234-static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
30235+static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
30236 {
30237 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30238 X38},
30239diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30240index 85661b0..c784559a 100644
30241--- a/drivers/firewire/core-card.c
30242+++ b/drivers/firewire/core-card.c
30243@@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
30244
30245 void fw_core_remove_card(struct fw_card *card)
30246 {
30247- struct fw_card_driver dummy_driver = dummy_driver_template;
30248+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
30249
30250 card->driver->update_phy_reg(card, 4,
30251 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30252diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30253index 4799393..37bd3ab 100644
30254--- a/drivers/firewire/core-cdev.c
30255+++ b/drivers/firewire/core-cdev.c
30256@@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
30257 int ret;
30258
30259 if ((request->channels == 0 && request->bandwidth == 0) ||
30260- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30261- request->bandwidth < 0)
30262+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30263 return -EINVAL;
30264
30265 r = kmalloc(sizeof(*r), GFP_KERNEL);
30266diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30267index 855ab3f..11f4bbd 100644
30268--- a/drivers/firewire/core-transaction.c
30269+++ b/drivers/firewire/core-transaction.c
30270@@ -37,6 +37,7 @@
30271 #include <linux/timer.h>
30272 #include <linux/types.h>
30273 #include <linux/workqueue.h>
30274+#include <linux/sched.h>
30275
30276 #include <asm/byteorder.h>
30277
30278diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30279index b45be57..5fad18b 100644
30280--- a/drivers/firewire/core.h
30281+++ b/drivers/firewire/core.h
30282@@ -101,6 +101,7 @@ struct fw_card_driver {
30283
30284 int (*stop_iso)(struct fw_iso_context *ctx);
30285 };
30286+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30287
30288 void fw_card_initialize(struct fw_card *card,
30289 const struct fw_card_driver *driver, struct device *device);
30290diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30291index 153980b..4b4d046 100644
30292--- a/drivers/firmware/dmi_scan.c
30293+++ b/drivers/firmware/dmi_scan.c
30294@@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
30295 }
30296 }
30297 else {
30298- /*
30299- * no iounmap() for that ioremap(); it would be a no-op, but
30300- * it's so early in setup that sucker gets confused into doing
30301- * what it shouldn't if we actually call it.
30302- */
30303 p = dmi_ioremap(0xF0000, 0x10000);
30304 if (p == NULL)
30305 goto error;
30306@@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30307 if (buf == NULL)
30308 return -1;
30309
30310- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30311+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30312
30313 iounmap(buf);
30314 return 0;
30315diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30316index 82d5c20..44a7177 100644
30317--- a/drivers/gpio/gpio-vr41xx.c
30318+++ b/drivers/gpio/gpio-vr41xx.c
30319@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30320 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30321 maskl, pendl, maskh, pendh);
30322
30323- atomic_inc(&irq_err_count);
30324+ atomic_inc_unchecked(&irq_err_count);
30325
30326 return -EINVAL;
30327 }
30328diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30329index 84a4a80..ce0306e 100644
30330--- a/drivers/gpu/drm/drm_crtc_helper.c
30331+++ b/drivers/gpu/drm/drm_crtc_helper.c
30332@@ -280,7 +280,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30333 struct drm_crtc *tmp;
30334 int crtc_mask = 1;
30335
30336- WARN(!crtc, "checking null crtc?\n");
30337+ BUG_ON(!crtc);
30338
30339 dev = crtc->dev;
30340
30341diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30342index ebf7d3f..d64c436 100644
30343--- a/drivers/gpu/drm/drm_drv.c
30344+++ b/drivers/gpu/drm/drm_drv.c
30345@@ -312,7 +312,7 @@ module_exit(drm_core_exit);
30346 /**
30347 * Copy and IOCTL return string to user space
30348 */
30349-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30350+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30351 {
30352 int len;
30353
30354@@ -391,7 +391,7 @@ long drm_ioctl(struct file *filp,
30355
30356 dev = file_priv->minor->dev;
30357 atomic_inc(&dev->ioctl_count);
30358- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30359+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30360 ++file_priv->ioctl_count;
30361
30362 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30363diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30364index 6263b01..7987f55 100644
30365--- a/drivers/gpu/drm/drm_fops.c
30366+++ b/drivers/gpu/drm/drm_fops.c
30367@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30368 }
30369
30370 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30371- atomic_set(&dev->counts[i], 0);
30372+ atomic_set_unchecked(&dev->counts[i], 0);
30373
30374 dev->sigdata.lock = NULL;
30375
30376@@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
30377
30378 retcode = drm_open_helper(inode, filp, dev);
30379 if (!retcode) {
30380- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30381- if (!dev->open_count++)
30382+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30383+ if (local_inc_return(&dev->open_count) == 1)
30384 retcode = drm_setup(dev);
30385 }
30386 if (!retcode) {
30387@@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
30388
30389 mutex_lock(&drm_global_mutex);
30390
30391- DRM_DEBUG("open_count = %d\n", dev->open_count);
30392+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30393
30394 if (dev->driver->preclose)
30395 dev->driver->preclose(dev, file_priv);
30396@@ -482,10 +482,10 @@ int drm_release(struct inode *inode, struct file *filp)
30397 * Begin inline drm_release
30398 */
30399
30400- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30401+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30402 task_pid_nr(current),
30403 (long)old_encode_dev(file_priv->minor->device),
30404- dev->open_count);
30405+ local_read(&dev->open_count));
30406
30407 /* Release any auth tokens that might point to this file_priv,
30408 (do that under the drm_global_mutex) */
30409@@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
30410 * End inline drm_release
30411 */
30412
30413- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30414- if (!--dev->open_count) {
30415+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30416+ if (local_dec_and_test(&dev->open_count)) {
30417 if (atomic_read(&dev->ioctl_count)) {
30418 DRM_ERROR("Device busy: %d\n",
30419 atomic_read(&dev->ioctl_count));
30420diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30421index c87dc96..326055d 100644
30422--- a/drivers/gpu/drm/drm_global.c
30423+++ b/drivers/gpu/drm/drm_global.c
30424@@ -36,7 +36,7 @@
30425 struct drm_global_item {
30426 struct mutex mutex;
30427 void *object;
30428- int refcount;
30429+ atomic_t refcount;
30430 };
30431
30432 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30433@@ -49,7 +49,7 @@ void drm_global_init(void)
30434 struct drm_global_item *item = &glob[i];
30435 mutex_init(&item->mutex);
30436 item->object = NULL;
30437- item->refcount = 0;
30438+ atomic_set(&item->refcount, 0);
30439 }
30440 }
30441
30442@@ -59,7 +59,7 @@ void drm_global_release(void)
30443 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30444 struct drm_global_item *item = &glob[i];
30445 BUG_ON(item->object != NULL);
30446- BUG_ON(item->refcount != 0);
30447+ BUG_ON(atomic_read(&item->refcount) != 0);
30448 }
30449 }
30450
30451@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30452 void *object;
30453
30454 mutex_lock(&item->mutex);
30455- if (item->refcount == 0) {
30456+ if (atomic_read(&item->refcount) == 0) {
30457 item->object = kzalloc(ref->size, GFP_KERNEL);
30458 if (unlikely(item->object == NULL)) {
30459 ret = -ENOMEM;
30460@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30461 goto out_err;
30462
30463 }
30464- ++item->refcount;
30465+ atomic_inc(&item->refcount);
30466 ref->object = item->object;
30467 object = item->object;
30468 mutex_unlock(&item->mutex);
30469@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30470 struct drm_global_item *item = &glob[ref->global_type];
30471
30472 mutex_lock(&item->mutex);
30473- BUG_ON(item->refcount == 0);
30474+ BUG_ON(atomic_read(&item->refcount) == 0);
30475 BUG_ON(ref->object != item->object);
30476- if (--item->refcount == 0) {
30477+ if (atomic_dec_and_test(&item->refcount)) {
30478 ref->release(ref);
30479 item->object = NULL;
30480 }
30481diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30482index ab1162d..42587b2 100644
30483--- a/drivers/gpu/drm/drm_info.c
30484+++ b/drivers/gpu/drm/drm_info.c
30485@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30486 struct drm_local_map *map;
30487 struct drm_map_list *r_list;
30488
30489- /* Hardcoded from _DRM_FRAME_BUFFER,
30490- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30491- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30492- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30493+ static const char * const types[] = {
30494+ [_DRM_FRAME_BUFFER] = "FB",
30495+ [_DRM_REGISTERS] = "REG",
30496+ [_DRM_SHM] = "SHM",
30497+ [_DRM_AGP] = "AGP",
30498+ [_DRM_SCATTER_GATHER] = "SG",
30499+ [_DRM_CONSISTENT] = "PCI",
30500+ [_DRM_GEM] = "GEM" };
30501 const char *type;
30502 int i;
30503
30504@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30505 map = r_list->map;
30506 if (!map)
30507 continue;
30508- if (map->type < 0 || map->type > 5)
30509+ if (map->type >= ARRAY_SIZE(types))
30510 type = "??";
30511 else
30512 type = types[map->type];
30513@@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30514 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30515 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30516 vma->vm_flags & VM_IO ? 'i' : '-',
30517+#ifdef CONFIG_GRKERNSEC_HIDESYM
30518+ 0);
30519+#else
30520 vma->vm_pgoff);
30521+#endif
30522
30523 #if defined(__i386__)
30524 pgprot = pgprot_val(vma->vm_page_prot);
30525diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30526index 637fcc3..e890b33 100644
30527--- a/drivers/gpu/drm/drm_ioc32.c
30528+++ b/drivers/gpu/drm/drm_ioc32.c
30529@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30530 request = compat_alloc_user_space(nbytes);
30531 if (!access_ok(VERIFY_WRITE, request, nbytes))
30532 return -EFAULT;
30533- list = (struct drm_buf_desc *) (request + 1);
30534+ list = (struct drm_buf_desc __user *) (request + 1);
30535
30536 if (__put_user(count, &request->count)
30537 || __put_user(list, &request->list))
30538@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30539 request = compat_alloc_user_space(nbytes);
30540 if (!access_ok(VERIFY_WRITE, request, nbytes))
30541 return -EFAULT;
30542- list = (struct drm_buf_pub *) (request + 1);
30543+ list = (struct drm_buf_pub __user *) (request + 1);
30544
30545 if (__put_user(count, &request->count)
30546 || __put_user(list, &request->list))
30547diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30548index 956fd38..e52167a 100644
30549--- a/drivers/gpu/drm/drm_ioctl.c
30550+++ b/drivers/gpu/drm/drm_ioctl.c
30551@@ -251,7 +251,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30552 stats->data[i].value =
30553 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30554 else
30555- stats->data[i].value = atomic_read(&dev->counts[i]);
30556+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30557 stats->data[i].type = dev->types[i];
30558 }
30559
30560diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30561index c79c713..2048588 100644
30562--- a/drivers/gpu/drm/drm_lock.c
30563+++ b/drivers/gpu/drm/drm_lock.c
30564@@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30565 if (drm_lock_take(&master->lock, lock->context)) {
30566 master->lock.file_priv = file_priv;
30567 master->lock.lock_time = jiffies;
30568- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30569+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30570 break; /* Got lock */
30571 }
30572
30573@@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30574 return -EINVAL;
30575 }
30576
30577- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30578+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30579
30580 if (drm_lock_free(&master->lock, lock->context)) {
30581 /* FIXME: Should really bail out here. */
30582diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30583index 7f4b4e1..bf4def2 100644
30584--- a/drivers/gpu/drm/i810/i810_dma.c
30585+++ b/drivers/gpu/drm/i810/i810_dma.c
30586@@ -948,8 +948,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30587 dma->buflist[vertex->idx],
30588 vertex->discard, vertex->used);
30589
30590- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30591- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30592+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30593+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30594 sarea_priv->last_enqueue = dev_priv->counter - 1;
30595 sarea_priv->last_dispatch = (int)hw_status[5];
30596
30597@@ -1109,8 +1109,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30598 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30599 mc->last_render);
30600
30601- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30602- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30603+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30604+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30605 sarea_priv->last_enqueue = dev_priv->counter - 1;
30606 sarea_priv->last_dispatch = (int)hw_status[5];
30607
30608diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30609index c9339f4..f5e1b9d 100644
30610--- a/drivers/gpu/drm/i810/i810_drv.h
30611+++ b/drivers/gpu/drm/i810/i810_drv.h
30612@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30613 int page_flipping;
30614
30615 wait_queue_head_t irq_queue;
30616- atomic_t irq_received;
30617- atomic_t irq_emitted;
30618+ atomic_unchecked_t irq_received;
30619+ atomic_unchecked_t irq_emitted;
30620
30621 int front_offset;
30622 } drm_i810_private_t;
30623diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30624index deaa657..e0fd296 100644
30625--- a/drivers/gpu/drm/i915/i915_debugfs.c
30626+++ b/drivers/gpu/drm/i915/i915_debugfs.c
30627@@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30628 I915_READ(GTIMR));
30629 }
30630 seq_printf(m, "Interrupts received: %d\n",
30631- atomic_read(&dev_priv->irq_received));
30632+ atomic_read_unchecked(&dev_priv->irq_received));
30633 for (i = 0; i < I915_NUM_RINGS; i++) {
30634 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30635 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30636@@ -1321,7 +1321,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
30637 return ret;
30638
30639 if (opregion->header)
30640- seq_write(m, opregion->header, OPREGION_SIZE);
30641+ seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
30642
30643 mutex_unlock(&dev->struct_mutex);
30644
30645diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30646index ddfe3d9..f6e6b21 100644
30647--- a/drivers/gpu/drm/i915/i915_dma.c
30648+++ b/drivers/gpu/drm/i915/i915_dma.c
30649@@ -1175,7 +1175,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30650 bool can_switch;
30651
30652 spin_lock(&dev->count_lock);
30653- can_switch = (dev->open_count == 0);
30654+ can_switch = (local_read(&dev->open_count) == 0);
30655 spin_unlock(&dev->count_lock);
30656 return can_switch;
30657 }
30658diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30659index 9689ca3..294f9c1 100644
30660--- a/drivers/gpu/drm/i915/i915_drv.h
30661+++ b/drivers/gpu/drm/i915/i915_drv.h
30662@@ -231,7 +231,7 @@ struct drm_i915_display_funcs {
30663 /* render clock increase/decrease */
30664 /* display clock increase/decrease */
30665 /* pll clock increase/decrease */
30666-};
30667+} __no_const;
30668
30669 struct intel_device_info {
30670 u8 gen;
30671@@ -320,7 +320,7 @@ typedef struct drm_i915_private {
30672 int current_page;
30673 int page_flipping;
30674
30675- atomic_t irq_received;
30676+ atomic_unchecked_t irq_received;
30677
30678 /* protects the irq masks */
30679 spinlock_t irq_lock;
30680@@ -896,7 +896,7 @@ struct drm_i915_gem_object {
30681 * will be page flipped away on the next vblank. When it
30682 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30683 */
30684- atomic_t pending_flip;
30685+ atomic_unchecked_t pending_flip;
30686 };
30687
30688 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30689@@ -1276,7 +1276,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
30690 extern void intel_teardown_gmbus(struct drm_device *dev);
30691 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30692 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30693-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30694+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30695 {
30696 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30697 }
30698diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30699index e159e33..cdcc663 100644
30700--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30701+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30702@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30703 i915_gem_clflush_object(obj);
30704
30705 if (obj->base.pending_write_domain)
30706- cd->flips |= atomic_read(&obj->pending_flip);
30707+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30708
30709 /* The actual obj->write_domain will be updated with
30710 * pending_write_domain after we emit the accumulated flush for all
30711@@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30712
30713 static int
30714 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30715- int count)
30716+ unsigned int count)
30717 {
30718- int i;
30719+ unsigned int i;
30720
30721 for (i = 0; i < count; i++) {
30722 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30723diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30724index 5bd4361..0241a42 100644
30725--- a/drivers/gpu/drm/i915/i915_irq.c
30726+++ b/drivers/gpu/drm/i915/i915_irq.c
30727@@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30728 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30729 struct drm_i915_master_private *master_priv;
30730
30731- atomic_inc(&dev_priv->irq_received);
30732+ atomic_inc_unchecked(&dev_priv->irq_received);
30733
30734 /* disable master interrupt before clearing iir */
30735 de_ier = I915_READ(DEIER);
30736@@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30737 struct drm_i915_master_private *master_priv;
30738 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
30739
30740- atomic_inc(&dev_priv->irq_received);
30741+ atomic_inc_unchecked(&dev_priv->irq_received);
30742
30743 if (IS_GEN6(dev))
30744 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
30745@@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
30746 int ret = IRQ_NONE, pipe;
30747 bool blc_event = false;
30748
30749- atomic_inc(&dev_priv->irq_received);
30750+ atomic_inc_unchecked(&dev_priv->irq_received);
30751
30752 iir = I915_READ(IIR);
30753
30754@@ -1743,7 +1743,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30755 {
30756 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30757
30758- atomic_set(&dev_priv->irq_received, 0);
30759+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30760
30761 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30762 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30763@@ -1932,7 +1932,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
30764 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30765 int pipe;
30766
30767- atomic_set(&dev_priv->irq_received, 0);
30768+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30769
30770 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30771 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30772diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30773index 2163818..cede019 100644
30774--- a/drivers/gpu/drm/i915/intel_display.c
30775+++ b/drivers/gpu/drm/i915/intel_display.c
30776@@ -2238,7 +2238,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
30777
30778 wait_event(dev_priv->pending_flip_queue,
30779 atomic_read(&dev_priv->mm.wedged) ||
30780- atomic_read(&obj->pending_flip) == 0);
30781+ atomic_read_unchecked(&obj->pending_flip) == 0);
30782
30783 /* Big Hammer, we also need to ensure that any pending
30784 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30785@@ -2859,7 +2859,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
30786 obj = to_intel_framebuffer(crtc->fb)->obj;
30787 dev_priv = crtc->dev->dev_private;
30788 wait_event(dev_priv->pending_flip_queue,
30789- atomic_read(&obj->pending_flip) == 0);
30790+ atomic_read_unchecked(&obj->pending_flip) == 0);
30791 }
30792
30793 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
30794@@ -7171,7 +7171,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30795
30796 atomic_clear_mask(1 << intel_crtc->plane,
30797 &obj->pending_flip.counter);
30798- if (atomic_read(&obj->pending_flip) == 0)
30799+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
30800 wake_up(&dev_priv->pending_flip_queue);
30801
30802 schedule_work(&work->work);
30803@@ -7354,7 +7354,13 @@ static int intel_gen6_queue_flip(struct drm_device *dev,
30804 OUT_RING(fb->pitches[0] | obj->tiling_mode);
30805 OUT_RING(obj->gtt_offset);
30806
30807- pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
30808+ /* Contrary to the suggestions in the documentation,
30809+ * "Enable Panel Fitter" does not seem to be required when page
30810+ * flipping with a non-native mode, and worse causes a normal
30811+ * modeset to fail.
30812+ * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
30813+ */
30814+ pf = 0;
30815 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
30816 OUT_RING(pf | pipesrc);
30817 ADVANCE_LP_RING();
30818@@ -7461,7 +7467,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30819 /* Block clients from rendering to the new back buffer until
30820 * the flip occurs and the object is no longer visible.
30821 */
30822- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30823+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30824
30825 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30826 if (ret)
30827@@ -7475,7 +7481,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30828 return 0;
30829
30830 cleanup_pending:
30831- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30832+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30833 drm_gem_object_unreference(&work->old_fb_obj->base);
30834 drm_gem_object_unreference(&obj->base);
30835 mutex_unlock(&dev->struct_mutex);
30836diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30837index 54558a0..2d97005 100644
30838--- a/drivers/gpu/drm/mga/mga_drv.h
30839+++ b/drivers/gpu/drm/mga/mga_drv.h
30840@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30841 u32 clear_cmd;
30842 u32 maccess;
30843
30844- atomic_t vbl_received; /**< Number of vblanks received. */
30845+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30846 wait_queue_head_t fence_queue;
30847- atomic_t last_fence_retired;
30848+ atomic_unchecked_t last_fence_retired;
30849 u32 next_fence_to_post;
30850
30851 unsigned int fb_cpp;
30852diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30853index 2581202..f230a8d9 100644
30854--- a/drivers/gpu/drm/mga/mga_irq.c
30855+++ b/drivers/gpu/drm/mga/mga_irq.c
30856@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30857 if (crtc != 0)
30858 return 0;
30859
30860- return atomic_read(&dev_priv->vbl_received);
30861+ return atomic_read_unchecked(&dev_priv->vbl_received);
30862 }
30863
30864
30865@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30866 /* VBLANK interrupt */
30867 if (status & MGA_VLINEPEN) {
30868 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30869- atomic_inc(&dev_priv->vbl_received);
30870+ atomic_inc_unchecked(&dev_priv->vbl_received);
30871 drm_handle_vblank(dev, 0);
30872 handled = 1;
30873 }
30874@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30875 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30876 MGA_WRITE(MGA_PRIMEND, prim_end);
30877
30878- atomic_inc(&dev_priv->last_fence_retired);
30879+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
30880 DRM_WAKEUP(&dev_priv->fence_queue);
30881 handled = 1;
30882 }
30883@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30884 * using fences.
30885 */
30886 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30887- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30888+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30889 - *sequence) <= (1 << 23)));
30890
30891 *sequence = cur_fence;
30892diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30893index e5cbead..6c354a3 100644
30894--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30895+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30896@@ -199,7 +199,7 @@ struct methods {
30897 const char desc[8];
30898 void (*loadbios)(struct drm_device *, uint8_t *);
30899 const bool rw;
30900-};
30901+} __do_const;
30902
30903 static struct methods shadow_methods[] = {
30904 { "PRAMIN", load_vbios_pramin, true },
30905@@ -5290,7 +5290,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30906 struct bit_table {
30907 const char id;
30908 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30909-};
30910+} __no_const;
30911
30912 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30913
30914diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30915index b827098..c31a797 100644
30916--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30917+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30918@@ -242,7 +242,7 @@ struct nouveau_channel {
30919 struct list_head pending;
30920 uint32_t sequence;
30921 uint32_t sequence_ack;
30922- atomic_t last_sequence_irq;
30923+ atomic_unchecked_t last_sequence_irq;
30924 struct nouveau_vma vma;
30925 } fence;
30926
30927@@ -323,7 +323,7 @@ struct nouveau_exec_engine {
30928 u32 handle, u16 class);
30929 void (*set_tile_region)(struct drm_device *dev, int i);
30930 void (*tlb_flush)(struct drm_device *, int engine);
30931-};
30932+} __no_const;
30933
30934 struct nouveau_instmem_engine {
30935 void *priv;
30936@@ -345,13 +345,13 @@ struct nouveau_instmem_engine {
30937 struct nouveau_mc_engine {
30938 int (*init)(struct drm_device *dev);
30939 void (*takedown)(struct drm_device *dev);
30940-};
30941+} __no_const;
30942
30943 struct nouveau_timer_engine {
30944 int (*init)(struct drm_device *dev);
30945 void (*takedown)(struct drm_device *dev);
30946 uint64_t (*read)(struct drm_device *dev);
30947-};
30948+} __no_const;
30949
30950 struct nouveau_fb_engine {
30951 int num_tiles;
30952@@ -566,7 +566,7 @@ struct nouveau_vram_engine {
30953 void (*put)(struct drm_device *, struct nouveau_mem **);
30954
30955 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30956-};
30957+} __no_const;
30958
30959 struct nouveau_engine {
30960 struct nouveau_instmem_engine instmem;
30961@@ -714,7 +714,7 @@ struct drm_nouveau_private {
30962 struct drm_global_reference mem_global_ref;
30963 struct ttm_bo_global_ref bo_global_ref;
30964 struct ttm_bo_device bdev;
30965- atomic_t validate_sequence;
30966+ atomic_unchecked_t validate_sequence;
30967 } ttm;
30968
30969 struct {
30970diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30971index 2f6daae..c9d7b9e 100644
30972--- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30973+++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30974@@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30975 if (USE_REFCNT(dev))
30976 sequence = nvchan_rd32(chan, 0x48);
30977 else
30978- sequence = atomic_read(&chan->fence.last_sequence_irq);
30979+ sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30980
30981 if (chan->fence.sequence_ack == sequence)
30982 goto out;
30983@@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30984 return ret;
30985 }
30986
30987- atomic_set(&chan->fence.last_sequence_irq, 0);
30988+ atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30989 return 0;
30990 }
30991
30992diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30993index 7ce3fde..cb3ea04 100644
30994--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30995+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30996@@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30997 int trycnt = 0;
30998 int ret, i;
30999
31000- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
31001+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
31002 retry:
31003 if (++trycnt > 100000) {
31004 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
31005diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
31006index f80c5e0..936baa7 100644
31007--- a/drivers/gpu/drm/nouveau/nouveau_state.c
31008+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
31009@@ -543,7 +543,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
31010 bool can_switch;
31011
31012 spin_lock(&dev->count_lock);
31013- can_switch = (dev->open_count == 0);
31014+ can_switch = (local_read(&dev->open_count) == 0);
31015 spin_unlock(&dev->count_lock);
31016 return can_switch;
31017 }
31018diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
31019index dbdea8e..cd6eeeb 100644
31020--- a/drivers/gpu/drm/nouveau/nv04_graph.c
31021+++ b/drivers/gpu/drm/nouveau/nv04_graph.c
31022@@ -554,7 +554,7 @@ static int
31023 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
31024 u32 class, u32 mthd, u32 data)
31025 {
31026- atomic_set(&chan->fence.last_sequence_irq, data);
31027+ atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
31028 return 0;
31029 }
31030
31031diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31032index bcac90b..53bfc76 100644
31033--- a/drivers/gpu/drm/r128/r128_cce.c
31034+++ b/drivers/gpu/drm/r128/r128_cce.c
31035@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31036
31037 /* GH: Simple idle check.
31038 */
31039- atomic_set(&dev_priv->idle_count, 0);
31040+ atomic_set_unchecked(&dev_priv->idle_count, 0);
31041
31042 /* We don't support anything other than bus-mastering ring mode,
31043 * but the ring can be in either AGP or PCI space for the ring
31044diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31045index 930c71b..499aded 100644
31046--- a/drivers/gpu/drm/r128/r128_drv.h
31047+++ b/drivers/gpu/drm/r128/r128_drv.h
31048@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31049 int is_pci;
31050 unsigned long cce_buffers_offset;
31051
31052- atomic_t idle_count;
31053+ atomic_unchecked_t idle_count;
31054
31055 int page_flipping;
31056 int current_page;
31057 u32 crtc_offset;
31058 u32 crtc_offset_cntl;
31059
31060- atomic_t vbl_received;
31061+ atomic_unchecked_t vbl_received;
31062
31063 u32 color_fmt;
31064 unsigned int front_offset;
31065diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31066index 429d5a0..7e899ed 100644
31067--- a/drivers/gpu/drm/r128/r128_irq.c
31068+++ b/drivers/gpu/drm/r128/r128_irq.c
31069@@ -42,7 +42,7 @@ u32 r128_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 r128_driver_irq_handler(DRM_IRQ_ARGS)
31078@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31079 /* VBLANK interrupt */
31080 if (status & R128_CRTC_VBLANK_INT) {
31081 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31082- atomic_inc(&dev_priv->vbl_received);
31083+ atomic_inc_unchecked(&dev_priv->vbl_received);
31084 drm_handle_vblank(dev, 0);
31085 return IRQ_HANDLED;
31086 }
31087diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31088index a9e33ce..09edd4b 100644
31089--- a/drivers/gpu/drm/r128/r128_state.c
31090+++ b/drivers/gpu/drm/r128/r128_state.c
31091@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31092
31093 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31094 {
31095- if (atomic_read(&dev_priv->idle_count) == 0)
31096+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31097 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31098 else
31099- atomic_set(&dev_priv->idle_count, 0);
31100+ atomic_set_unchecked(&dev_priv->idle_count, 0);
31101 }
31102
31103 #endif
31104diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31105index 5a82b6b..9e69c73 100644
31106--- a/drivers/gpu/drm/radeon/mkregtable.c
31107+++ b/drivers/gpu/drm/radeon/mkregtable.c
31108@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31109 regex_t mask_rex;
31110 regmatch_t match[4];
31111 char buf[1024];
31112- size_t end;
31113+ long end;
31114 int len;
31115 int done = 0;
31116 int r;
31117 unsigned o;
31118 struct offset *offset;
31119 char last_reg_s[10];
31120- int last_reg;
31121+ unsigned long last_reg;
31122
31123 if (regcomp
31124 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31125diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31126index 1668ec1..30ebdab 100644
31127--- a/drivers/gpu/drm/radeon/radeon.h
31128+++ b/drivers/gpu/drm/radeon/radeon.h
31129@@ -250,7 +250,7 @@ struct radeon_fence_driver {
31130 uint32_t scratch_reg;
31131 uint64_t gpu_addr;
31132 volatile uint32_t *cpu_addr;
31133- atomic_t seq;
31134+ atomic_unchecked_t seq;
31135 uint32_t last_seq;
31136 unsigned long last_jiffies;
31137 unsigned long last_timeout;
31138@@ -752,7 +752,7 @@ struct r600_blit_cp_primitives {
31139 int x2, int y2);
31140 void (*draw_auto)(struct radeon_device *rdev);
31141 void (*set_default_state)(struct radeon_device *rdev);
31142-};
31143+} __no_const;
31144
31145 struct r600_blit {
31146 struct mutex mutex;
31147@@ -1201,7 +1201,7 @@ struct radeon_asic {
31148 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
31149 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31150 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31151-};
31152+} __no_const;
31153
31154 /*
31155 * Asic structures
31156diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31157index 49f7cb7..2fcb48f 100644
31158--- a/drivers/gpu/drm/radeon/radeon_device.c
31159+++ b/drivers/gpu/drm/radeon/radeon_device.c
31160@@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31161 bool can_switch;
31162
31163 spin_lock(&dev->count_lock);
31164- can_switch = (dev->open_count == 0);
31165+ can_switch = (local_read(&dev->open_count) == 0);
31166 spin_unlock(&dev->count_lock);
31167 return can_switch;
31168 }
31169diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31170index a1b59ca..86f2d44 100644
31171--- a/drivers/gpu/drm/radeon/radeon_drv.h
31172+++ b/drivers/gpu/drm/radeon/radeon_drv.h
31173@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31174
31175 /* SW interrupt */
31176 wait_queue_head_t swi_queue;
31177- atomic_t swi_emitted;
31178+ atomic_unchecked_t swi_emitted;
31179 int vblank_crtc;
31180 uint32_t irq_enable_reg;
31181 uint32_t r500_disp_irq_reg;
31182diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
31183index 4bd36a3..e66fe9c 100644
31184--- a/drivers/gpu/drm/radeon/radeon_fence.c
31185+++ b/drivers/gpu/drm/radeon/radeon_fence.c
31186@@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
31187 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
31188 return 0;
31189 }
31190- fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
31191+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
31192 if (!rdev->ring[fence->ring].ready)
31193 /* FIXME: cp is not running assume everythings is done right
31194 * away
31195@@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
31196 }
31197 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
31198 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
31199- radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
31200+ radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
31201 rdev->fence_drv[ring].initialized = true;
31202 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
31203 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
31204@@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
31205 rdev->fence_drv[ring].scratch_reg = -1;
31206 rdev->fence_drv[ring].cpu_addr = NULL;
31207 rdev->fence_drv[ring].gpu_addr = 0;
31208- atomic_set(&rdev->fence_drv[ring].seq, 0);
31209+ atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
31210 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
31211 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
31212 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
31213diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31214index 48b7cea..342236f 100644
31215--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31216+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31217@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31218 request = compat_alloc_user_space(sizeof(*request));
31219 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31220 || __put_user(req32.param, &request->param)
31221- || __put_user((void __user *)(unsigned long)req32.value,
31222+ || __put_user((unsigned long)req32.value,
31223 &request->value))
31224 return -EFAULT;
31225
31226diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31227index 00da384..32f972d 100644
31228--- a/drivers/gpu/drm/radeon/radeon_irq.c
31229+++ b/drivers/gpu/drm/radeon/radeon_irq.c
31230@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31231 unsigned int ret;
31232 RING_LOCALS;
31233
31234- atomic_inc(&dev_priv->swi_emitted);
31235- ret = atomic_read(&dev_priv->swi_emitted);
31236+ atomic_inc_unchecked(&dev_priv->swi_emitted);
31237+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31238
31239 BEGIN_RING(4);
31240 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31241@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31242 drm_radeon_private_t *dev_priv =
31243 (drm_radeon_private_t *) dev->dev_private;
31244
31245- atomic_set(&dev_priv->swi_emitted, 0);
31246+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31247 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31248
31249 dev->max_vblank_count = 0x001fffff;
31250diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31251index e8422ae..d22d4a8 100644
31252--- a/drivers/gpu/drm/radeon/radeon_state.c
31253+++ b/drivers/gpu/drm/radeon/radeon_state.c
31254@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31255 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31256 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31257
31258- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31259+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31260 sarea_priv->nbox * sizeof(depth_boxes[0])))
31261 return -EFAULT;
31262
31263@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31264 {
31265 drm_radeon_private_t *dev_priv = dev->dev_private;
31266 drm_radeon_getparam_t *param = data;
31267- int value;
31268+ int value = 0;
31269
31270 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31271
31272diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31273index c421e77..e6bf2e8 100644
31274--- a/drivers/gpu/drm/radeon/radeon_ttm.c
31275+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31276@@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31277 }
31278 if (unlikely(ttm_vm_ops == NULL)) {
31279 ttm_vm_ops = vma->vm_ops;
31280- radeon_ttm_vm_ops = *ttm_vm_ops;
31281- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31282+ pax_open_kernel();
31283+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31284+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31285+ pax_close_kernel();
31286 }
31287 vma->vm_ops = &radeon_ttm_vm_ops;
31288 return 0;
31289diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31290index f68dff2..8df955c 100644
31291--- a/drivers/gpu/drm/radeon/rs690.c
31292+++ b/drivers/gpu/drm/radeon/rs690.c
31293@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31294 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31295 rdev->pm.sideport_bandwidth.full)
31296 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31297- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31298+ read_delay_latency.full = dfixed_const(800 * 1000);
31299 read_delay_latency.full = dfixed_div(read_delay_latency,
31300 rdev->pm.igp_sideport_mclk);
31301+ a.full = dfixed_const(370);
31302+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31303 } else {
31304 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31305 rdev->pm.k8_bandwidth.full)
31306diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31307index 499debd..66fce72 100644
31308--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31309+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31310@@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
31311 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31312 struct shrink_control *sc)
31313 {
31314- static atomic_t start_pool = ATOMIC_INIT(0);
31315+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31316 unsigned i;
31317- unsigned pool_offset = atomic_add_return(1, &start_pool);
31318+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31319 struct ttm_page_pool *pool;
31320 int shrink_pages = sc->nr_to_scan;
31321
31322diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31323index 88edacc..1e5412b 100644
31324--- a/drivers/gpu/drm/via/via_drv.h
31325+++ b/drivers/gpu/drm/via/via_drv.h
31326@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31327 typedef uint32_t maskarray_t[5];
31328
31329 typedef struct drm_via_irq {
31330- atomic_t irq_received;
31331+ atomic_unchecked_t irq_received;
31332 uint32_t pending_mask;
31333 uint32_t enable_mask;
31334 wait_queue_head_t irq_queue;
31335@@ -75,7 +75,7 @@ typedef struct drm_via_private {
31336 struct timeval last_vblank;
31337 int last_vblank_valid;
31338 unsigned usec_per_vblank;
31339- atomic_t vbl_received;
31340+ atomic_unchecked_t vbl_received;
31341 drm_via_state_t hc_state;
31342 char pci_buf[VIA_PCI_BUF_SIZE];
31343 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31344diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31345index d391f48..10c8ca3 100644
31346--- a/drivers/gpu/drm/via/via_irq.c
31347+++ b/drivers/gpu/drm/via/via_irq.c
31348@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31349 if (crtc != 0)
31350 return 0;
31351
31352- return atomic_read(&dev_priv->vbl_received);
31353+ return atomic_read_unchecked(&dev_priv->vbl_received);
31354 }
31355
31356 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31357@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31358
31359 status = VIA_READ(VIA_REG_INTERRUPT);
31360 if (status & VIA_IRQ_VBLANK_PENDING) {
31361- atomic_inc(&dev_priv->vbl_received);
31362- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31363+ atomic_inc_unchecked(&dev_priv->vbl_received);
31364+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31365 do_gettimeofday(&cur_vblank);
31366 if (dev_priv->last_vblank_valid) {
31367 dev_priv->usec_per_vblank =
31368@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31369 dev_priv->last_vblank = cur_vblank;
31370 dev_priv->last_vblank_valid = 1;
31371 }
31372- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31373+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31374 DRM_DEBUG("US per vblank is: %u\n",
31375 dev_priv->usec_per_vblank);
31376 }
31377@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31378
31379 for (i = 0; i < dev_priv->num_irqs; ++i) {
31380 if (status & cur_irq->pending_mask) {
31381- atomic_inc(&cur_irq->irq_received);
31382+ atomic_inc_unchecked(&cur_irq->irq_received);
31383 DRM_WAKEUP(&cur_irq->irq_queue);
31384 handled = 1;
31385 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31386@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31387 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31388 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31389 masks[irq][4]));
31390- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31391+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31392 } else {
31393 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31394 (((cur_irq_sequence =
31395- atomic_read(&cur_irq->irq_received)) -
31396+ atomic_read_unchecked(&cur_irq->irq_received)) -
31397 *sequence) <= (1 << 23)));
31398 }
31399 *sequence = cur_irq_sequence;
31400@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31401 }
31402
31403 for (i = 0; i < dev_priv->num_irqs; ++i) {
31404- atomic_set(&cur_irq->irq_received, 0);
31405+ atomic_set_unchecked(&cur_irq->irq_received, 0);
31406 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31407 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31408 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31409@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31410 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31411 case VIA_IRQ_RELATIVE:
31412 irqwait->request.sequence +=
31413- atomic_read(&cur_irq->irq_received);
31414+ atomic_read_unchecked(&cur_irq->irq_received);
31415 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31416 case VIA_IRQ_ABSOLUTE:
31417 break;
31418diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31419index dc27970..f18b008 100644
31420--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31421+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31422@@ -260,7 +260,7 @@ struct vmw_private {
31423 * Fencing and IRQs.
31424 */
31425
31426- atomic_t marker_seq;
31427+ atomic_unchecked_t marker_seq;
31428 wait_queue_head_t fence_queue;
31429 wait_queue_head_t fifo_queue;
31430 int fence_queue_waiters; /* Protected by hw_mutex */
31431diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31432index a0c2f12..68ae6cb 100644
31433--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31434+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31435@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31436 (unsigned int) min,
31437 (unsigned int) fifo->capabilities);
31438
31439- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31440+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31441 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31442 vmw_marker_queue_init(&fifo->marker_queue);
31443 return vmw_fifo_send_fence(dev_priv, &dummy);
31444@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31445 if (reserveable)
31446 iowrite32(bytes, fifo_mem +
31447 SVGA_FIFO_RESERVED);
31448- return fifo_mem + (next_cmd >> 2);
31449+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31450 } else {
31451 need_bounce = true;
31452 }
31453@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31454
31455 fm = vmw_fifo_reserve(dev_priv, bytes);
31456 if (unlikely(fm == NULL)) {
31457- *seqno = atomic_read(&dev_priv->marker_seq);
31458+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31459 ret = -ENOMEM;
31460 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31461 false, 3*HZ);
31462@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31463 }
31464
31465 do {
31466- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31467+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31468 } while (*seqno == 0);
31469
31470 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31471diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31472index cabc95f..14b3d77 100644
31473--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31474+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31475@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31476 * emitted. Then the fence is stale and signaled.
31477 */
31478
31479- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31480+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31481 > VMW_FENCE_WRAP);
31482
31483 return ret;
31484@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31485
31486 if (fifo_idle)
31487 down_read(&fifo_state->rwsem);
31488- signal_seq = atomic_read(&dev_priv->marker_seq);
31489+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31490 ret = 0;
31491
31492 for (;;) {
31493diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31494index 8a8725c..afed796 100644
31495--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31496+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31497@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31498 while (!vmw_lag_lt(queue, us)) {
31499 spin_lock(&queue->lock);
31500 if (list_empty(&queue->head))
31501- seqno = atomic_read(&dev_priv->marker_seq);
31502+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31503 else {
31504 marker = list_first_entry(&queue->head,
31505 struct vmw_marker, head);
31506diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31507index 75dbe34..f9204a8 100644
31508--- a/drivers/hid/hid-core.c
31509+++ b/drivers/hid/hid-core.c
31510@@ -2021,7 +2021,7 @@ static bool hid_ignore(struct hid_device *hdev)
31511
31512 int hid_add_device(struct hid_device *hdev)
31513 {
31514- static atomic_t id = ATOMIC_INIT(0);
31515+ static atomic_unchecked_t id = ATOMIC_INIT(0);
31516 int ret;
31517
31518 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31519@@ -2036,7 +2036,7 @@ int hid_add_device(struct hid_device *hdev)
31520 /* XXX hack, any other cleaner solution after the driver core
31521 * is converted to allow more than 20 bytes as the device name? */
31522 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31523- hdev->vendor, hdev->product, atomic_inc_return(&id));
31524+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31525
31526 hid_debug_register(hdev, dev_name(&hdev->dev));
31527 ret = device_add(&hdev->dev);
31528diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31529index b1ec0e2..c295a61 100644
31530--- a/drivers/hid/usbhid/hiddev.c
31531+++ b/drivers/hid/usbhid/hiddev.c
31532@@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31533 break;
31534
31535 case HIDIOCAPPLICATION:
31536- if (arg < 0 || arg >= hid->maxapplication)
31537+ if (arg >= hid->maxapplication)
31538 break;
31539
31540 for (i = 0; i < hid->maxcollection; i++)
31541diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31542index 4065374..10ed7dc 100644
31543--- a/drivers/hv/channel.c
31544+++ b/drivers/hv/channel.c
31545@@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31546 int ret = 0;
31547 int t;
31548
31549- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31550- atomic_inc(&vmbus_connection.next_gpadl_handle);
31551+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31552+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31553
31554 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31555 if (ret)
31556diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31557index 12aa97f..c0679f7 100644
31558--- a/drivers/hv/hv.c
31559+++ b/drivers/hv/hv.c
31560@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31561 u64 output_address = (output) ? virt_to_phys(output) : 0;
31562 u32 output_address_hi = output_address >> 32;
31563 u32 output_address_lo = output_address & 0xFFFFFFFF;
31564- void *hypercall_page = hv_context.hypercall_page;
31565+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31566
31567 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31568 "=a"(hv_status_lo) : "d" (control_hi),
31569diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31570index 6d7d286..92b0873 100644
31571--- a/drivers/hv/hyperv_vmbus.h
31572+++ b/drivers/hv/hyperv_vmbus.h
31573@@ -556,7 +556,7 @@ enum vmbus_connect_state {
31574 struct vmbus_connection {
31575 enum vmbus_connect_state conn_state;
31576
31577- atomic_t next_gpadl_handle;
31578+ atomic_unchecked_t next_gpadl_handle;
31579
31580 /*
31581 * Represents channel interrupts. Each bit position represents a
31582diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31583index a220e57..428f54d 100644
31584--- a/drivers/hv/vmbus_drv.c
31585+++ b/drivers/hv/vmbus_drv.c
31586@@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31587 {
31588 int ret = 0;
31589
31590- static atomic_t device_num = ATOMIC_INIT(0);
31591+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31592
31593 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31594- atomic_inc_return(&device_num));
31595+ atomic_inc_return_unchecked(&device_num));
31596
31597 child_device_obj->device.bus = &hv_bus;
31598 child_device_obj->device.parent = &hv_acpi_dev->dev;
31599diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31600index 554f046..f8b4729 100644
31601--- a/drivers/hwmon/acpi_power_meter.c
31602+++ b/drivers/hwmon/acpi_power_meter.c
31603@@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31604 return res;
31605
31606 temp /= 1000;
31607- if (temp < 0)
31608- return -EINVAL;
31609
31610 mutex_lock(&resource->lock);
31611 resource->trip[attr->index - 7] = temp;
31612diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31613index 91fdd1f..b66a686 100644
31614--- a/drivers/hwmon/sht15.c
31615+++ b/drivers/hwmon/sht15.c
31616@@ -166,7 +166,7 @@ struct sht15_data {
31617 int supply_uV;
31618 bool supply_uV_valid;
31619 struct work_struct update_supply_work;
31620- atomic_t interrupt_handled;
31621+ atomic_unchecked_t interrupt_handled;
31622 };
31623
31624 /**
31625@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31626 return ret;
31627
31628 gpio_direction_input(data->pdata->gpio_data);
31629- atomic_set(&data->interrupt_handled, 0);
31630+ atomic_set_unchecked(&data->interrupt_handled, 0);
31631
31632 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31633 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31634 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31635 /* Only relevant if the interrupt hasn't occurred. */
31636- if (!atomic_read(&data->interrupt_handled))
31637+ if (!atomic_read_unchecked(&data->interrupt_handled))
31638 schedule_work(&data->read_work);
31639 }
31640 ret = wait_event_timeout(data->wait_queue,
31641@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31642
31643 /* First disable the interrupt */
31644 disable_irq_nosync(irq);
31645- atomic_inc(&data->interrupt_handled);
31646+ atomic_inc_unchecked(&data->interrupt_handled);
31647 /* Then schedule a reading work struct */
31648 if (data->state != SHT15_READING_NOTHING)
31649 schedule_work(&data->read_work);
31650@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31651 * If not, then start the interrupt again - care here as could
31652 * have gone low in meantime so verify it hasn't!
31653 */
31654- atomic_set(&data->interrupt_handled, 0);
31655+ atomic_set_unchecked(&data->interrupt_handled, 0);
31656 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31657 /* If still not occurred or another handler has been scheduled */
31658 if (gpio_get_value(data->pdata->gpio_data)
31659- || atomic_read(&data->interrupt_handled))
31660+ || atomic_read_unchecked(&data->interrupt_handled))
31661 return;
31662 }
31663
31664diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31665index 378fcb5..5e91fa8 100644
31666--- a/drivers/i2c/busses/i2c-amd756-s4882.c
31667+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31668@@ -43,7 +43,7 @@
31669 extern struct i2c_adapter amd756_smbus;
31670
31671 static struct i2c_adapter *s4882_adapter;
31672-static struct i2c_algorithm *s4882_algo;
31673+static i2c_algorithm_no_const *s4882_algo;
31674
31675 /* Wrapper access functions for multiplexed SMBus */
31676 static DEFINE_MUTEX(amd756_lock);
31677diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31678index 29015eb..af2d8e9 100644
31679--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31680+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31681@@ -41,7 +41,7 @@
31682 extern struct i2c_adapter *nforce2_smbus;
31683
31684 static struct i2c_adapter *s4985_adapter;
31685-static struct i2c_algorithm *s4985_algo;
31686+static i2c_algorithm_no_const *s4985_algo;
31687
31688 /* Wrapper access functions for multiplexed SMBus */
31689 static DEFINE_MUTEX(nforce2_lock);
31690diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31691index d7a4833..7fae376 100644
31692--- a/drivers/i2c/i2c-mux.c
31693+++ b/drivers/i2c/i2c-mux.c
31694@@ -28,7 +28,7 @@
31695 /* multiplexer per channel data */
31696 struct i2c_mux_priv {
31697 struct i2c_adapter adap;
31698- struct i2c_algorithm algo;
31699+ i2c_algorithm_no_const algo;
31700
31701 struct i2c_adapter *parent;
31702 void *mux_dev; /* the mux chip/device */
31703diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31704index 57d00ca..0145194 100644
31705--- a/drivers/ide/aec62xx.c
31706+++ b/drivers/ide/aec62xx.c
31707@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31708 .cable_detect = atp86x_cable_detect,
31709 };
31710
31711-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31712+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31713 { /* 0: AEC6210 */
31714 .name = DRV_NAME,
31715 .init_chipset = init_chipset_aec62xx,
31716diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31717index 2c8016a..911a27c 100644
31718--- a/drivers/ide/alim15x3.c
31719+++ b/drivers/ide/alim15x3.c
31720@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31721 .dma_sff_read_status = ide_dma_sff_read_status,
31722 };
31723
31724-static const struct ide_port_info ali15x3_chipset __devinitdata = {
31725+static const struct ide_port_info ali15x3_chipset __devinitconst = {
31726 .name = DRV_NAME,
31727 .init_chipset = init_chipset_ali15x3,
31728 .init_hwif = init_hwif_ali15x3,
31729diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31730index 3747b25..56fc995 100644
31731--- a/drivers/ide/amd74xx.c
31732+++ b/drivers/ide/amd74xx.c
31733@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31734 .udma_mask = udma, \
31735 }
31736
31737-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31738+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31739 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31740 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31741 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31742diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31743index 15f0ead..cb43480 100644
31744--- a/drivers/ide/atiixp.c
31745+++ b/drivers/ide/atiixp.c
31746@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31747 .cable_detect = atiixp_cable_detect,
31748 };
31749
31750-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31751+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31752 { /* 0: IXP200/300/400/700 */
31753 .name = DRV_NAME,
31754 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31755diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31756index 5f80312..d1fc438 100644
31757--- a/drivers/ide/cmd64x.c
31758+++ b/drivers/ide/cmd64x.c
31759@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31760 .dma_sff_read_status = ide_dma_sff_read_status,
31761 };
31762
31763-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31764+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31765 { /* 0: CMD643 */
31766 .name = DRV_NAME,
31767 .init_chipset = init_chipset_cmd64x,
31768diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31769index 2c1e5f7..1444762 100644
31770--- a/drivers/ide/cs5520.c
31771+++ b/drivers/ide/cs5520.c
31772@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31773 .set_dma_mode = cs5520_set_dma_mode,
31774 };
31775
31776-static const struct ide_port_info cyrix_chipset __devinitdata = {
31777+static const struct ide_port_info cyrix_chipset __devinitconst = {
31778 .name = DRV_NAME,
31779 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31780 .port_ops = &cs5520_port_ops,
31781diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31782index 4dc4eb9..49b40ad 100644
31783--- a/drivers/ide/cs5530.c
31784+++ b/drivers/ide/cs5530.c
31785@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31786 .udma_filter = cs5530_udma_filter,
31787 };
31788
31789-static const struct ide_port_info cs5530_chipset __devinitdata = {
31790+static const struct ide_port_info cs5530_chipset __devinitconst = {
31791 .name = DRV_NAME,
31792 .init_chipset = init_chipset_cs5530,
31793 .init_hwif = init_hwif_cs5530,
31794diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31795index 5059faf..18d4c85 100644
31796--- a/drivers/ide/cs5535.c
31797+++ b/drivers/ide/cs5535.c
31798@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31799 .cable_detect = cs5535_cable_detect,
31800 };
31801
31802-static const struct ide_port_info cs5535_chipset __devinitdata = {
31803+static const struct ide_port_info cs5535_chipset __devinitconst = {
31804 .name = DRV_NAME,
31805 .port_ops = &cs5535_port_ops,
31806 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31807diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31808index 847553f..3ffb49d 100644
31809--- a/drivers/ide/cy82c693.c
31810+++ b/drivers/ide/cy82c693.c
31811@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31812 .set_dma_mode = cy82c693_set_dma_mode,
31813 };
31814
31815-static const struct ide_port_info cy82c693_chipset __devinitdata = {
31816+static const struct ide_port_info cy82c693_chipset __devinitconst = {
31817 .name = DRV_NAME,
31818 .init_iops = init_iops_cy82c693,
31819 .port_ops = &cy82c693_port_ops,
31820diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31821index 58c51cd..4aec3b8 100644
31822--- a/drivers/ide/hpt366.c
31823+++ b/drivers/ide/hpt366.c
31824@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31825 }
31826 };
31827
31828-static const struct hpt_info hpt36x __devinitdata = {
31829+static const struct hpt_info hpt36x __devinitconst = {
31830 .chip_name = "HPT36x",
31831 .chip_type = HPT36x,
31832 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31833@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31834 .timings = &hpt36x_timings
31835 };
31836
31837-static const struct hpt_info hpt370 __devinitdata = {
31838+static const struct hpt_info hpt370 __devinitconst = {
31839 .chip_name = "HPT370",
31840 .chip_type = HPT370,
31841 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31842@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31843 .timings = &hpt37x_timings
31844 };
31845
31846-static const struct hpt_info hpt370a __devinitdata = {
31847+static const struct hpt_info hpt370a __devinitconst = {
31848 .chip_name = "HPT370A",
31849 .chip_type = HPT370A,
31850 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31851@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31852 .timings = &hpt37x_timings
31853 };
31854
31855-static const struct hpt_info hpt374 __devinitdata = {
31856+static const struct hpt_info hpt374 __devinitconst = {
31857 .chip_name = "HPT374",
31858 .chip_type = HPT374,
31859 .udma_mask = ATA_UDMA5,
31860@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31861 .timings = &hpt37x_timings
31862 };
31863
31864-static const struct hpt_info hpt372 __devinitdata = {
31865+static const struct hpt_info hpt372 __devinitconst = {
31866 .chip_name = "HPT372",
31867 .chip_type = HPT372,
31868 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31869@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31870 .timings = &hpt37x_timings
31871 };
31872
31873-static const struct hpt_info hpt372a __devinitdata = {
31874+static const struct hpt_info hpt372a __devinitconst = {
31875 .chip_name = "HPT372A",
31876 .chip_type = HPT372A,
31877 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31878@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31879 .timings = &hpt37x_timings
31880 };
31881
31882-static const struct hpt_info hpt302 __devinitdata = {
31883+static const struct hpt_info hpt302 __devinitconst = {
31884 .chip_name = "HPT302",
31885 .chip_type = HPT302,
31886 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31887@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31888 .timings = &hpt37x_timings
31889 };
31890
31891-static const struct hpt_info hpt371 __devinitdata = {
31892+static const struct hpt_info hpt371 __devinitconst = {
31893 .chip_name = "HPT371",
31894 .chip_type = HPT371,
31895 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31896@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31897 .timings = &hpt37x_timings
31898 };
31899
31900-static const struct hpt_info hpt372n __devinitdata = {
31901+static const struct hpt_info hpt372n __devinitconst = {
31902 .chip_name = "HPT372N",
31903 .chip_type = HPT372N,
31904 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31905@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31906 .timings = &hpt37x_timings
31907 };
31908
31909-static const struct hpt_info hpt302n __devinitdata = {
31910+static const struct hpt_info hpt302n __devinitconst = {
31911 .chip_name = "HPT302N",
31912 .chip_type = HPT302N,
31913 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31914@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31915 .timings = &hpt37x_timings
31916 };
31917
31918-static const struct hpt_info hpt371n __devinitdata = {
31919+static const struct hpt_info hpt371n __devinitconst = {
31920 .chip_name = "HPT371N",
31921 .chip_type = HPT371N,
31922 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31923@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31924 .dma_sff_read_status = ide_dma_sff_read_status,
31925 };
31926
31927-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31928+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31929 { /* 0: HPT36x */
31930 .name = DRV_NAME,
31931 .init_chipset = init_chipset_hpt366,
31932diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31933index 8126824..55a2798 100644
31934--- a/drivers/ide/ide-cd.c
31935+++ b/drivers/ide/ide-cd.c
31936@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31937 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31938 if ((unsigned long)buf & alignment
31939 || blk_rq_bytes(rq) & q->dma_pad_mask
31940- || object_is_on_stack(buf))
31941+ || object_starts_on_stack(buf))
31942 drive->dma = 0;
31943 }
31944 }
31945diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31946index 7f56b73..dab5b67 100644
31947--- a/drivers/ide/ide-pci-generic.c
31948+++ b/drivers/ide/ide-pci-generic.c
31949@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31950 .udma_mask = ATA_UDMA6, \
31951 }
31952
31953-static const struct ide_port_info generic_chipsets[] __devinitdata = {
31954+static const struct ide_port_info generic_chipsets[] __devinitconst = {
31955 /* 0: Unknown */
31956 DECLARE_GENERIC_PCI_DEV(0),
31957
31958diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31959index 560e66d..d5dd180 100644
31960--- a/drivers/ide/it8172.c
31961+++ b/drivers/ide/it8172.c
31962@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31963 .set_dma_mode = it8172_set_dma_mode,
31964 };
31965
31966-static const struct ide_port_info it8172_port_info __devinitdata = {
31967+static const struct ide_port_info it8172_port_info __devinitconst = {
31968 .name = DRV_NAME,
31969 .port_ops = &it8172_port_ops,
31970 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31971diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31972index 46816ba..1847aeb 100644
31973--- a/drivers/ide/it8213.c
31974+++ b/drivers/ide/it8213.c
31975@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31976 .cable_detect = it8213_cable_detect,
31977 };
31978
31979-static const struct ide_port_info it8213_chipset __devinitdata = {
31980+static const struct ide_port_info it8213_chipset __devinitconst = {
31981 .name = DRV_NAME,
31982 .enablebits = { {0x41, 0x80, 0x80} },
31983 .port_ops = &it8213_port_ops,
31984diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31985index 2e3169f..c5611db 100644
31986--- a/drivers/ide/it821x.c
31987+++ b/drivers/ide/it821x.c
31988@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31989 .cable_detect = it821x_cable_detect,
31990 };
31991
31992-static const struct ide_port_info it821x_chipset __devinitdata = {
31993+static const struct ide_port_info it821x_chipset __devinitconst = {
31994 .name = DRV_NAME,
31995 .init_chipset = init_chipset_it821x,
31996 .init_hwif = init_hwif_it821x,
31997diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31998index 74c2c4a..efddd7d 100644
31999--- a/drivers/ide/jmicron.c
32000+++ b/drivers/ide/jmicron.c
32001@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
32002 .cable_detect = jmicron_cable_detect,
32003 };
32004
32005-static const struct ide_port_info jmicron_chipset __devinitdata = {
32006+static const struct ide_port_info jmicron_chipset __devinitconst = {
32007 .name = DRV_NAME,
32008 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
32009 .port_ops = &jmicron_port_ops,
32010diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
32011index 95327a2..73f78d8 100644
32012--- a/drivers/ide/ns87415.c
32013+++ b/drivers/ide/ns87415.c
32014@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
32015 .dma_sff_read_status = superio_dma_sff_read_status,
32016 };
32017
32018-static const struct ide_port_info ns87415_chipset __devinitdata = {
32019+static const struct ide_port_info ns87415_chipset __devinitconst = {
32020 .name = DRV_NAME,
32021 .init_hwif = init_hwif_ns87415,
32022 .tp_ops = &ns87415_tp_ops,
32023diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
32024index 1a53a4c..39edc66 100644
32025--- a/drivers/ide/opti621.c
32026+++ b/drivers/ide/opti621.c
32027@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
32028 .set_pio_mode = opti621_set_pio_mode,
32029 };
32030
32031-static const struct ide_port_info opti621_chipset __devinitdata = {
32032+static const struct ide_port_info opti621_chipset __devinitconst = {
32033 .name = DRV_NAME,
32034 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
32035 .port_ops = &opti621_port_ops,
32036diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
32037index 9546fe2..2e5ceb6 100644
32038--- a/drivers/ide/pdc202xx_new.c
32039+++ b/drivers/ide/pdc202xx_new.c
32040@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
32041 .udma_mask = udma, \
32042 }
32043
32044-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
32045+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
32046 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32047 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32048 };
32049diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32050index 3a35ec6..5634510 100644
32051--- a/drivers/ide/pdc202xx_old.c
32052+++ b/drivers/ide/pdc202xx_old.c
32053@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32054 .max_sectors = sectors, \
32055 }
32056
32057-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32058+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32059 { /* 0: PDC20246 */
32060 .name = DRV_NAME,
32061 .init_chipset = init_chipset_pdc202xx,
32062diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32063index 1892e81..fe0fd60 100644
32064--- a/drivers/ide/piix.c
32065+++ b/drivers/ide/piix.c
32066@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32067 .udma_mask = udma, \
32068 }
32069
32070-static const struct ide_port_info piix_pci_info[] __devinitdata = {
32071+static const struct ide_port_info piix_pci_info[] __devinitconst = {
32072 /* 0: MPIIX */
32073 { /*
32074 * MPIIX actually has only a single IDE channel mapped to
32075diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32076index a6414a8..c04173e 100644
32077--- a/drivers/ide/rz1000.c
32078+++ b/drivers/ide/rz1000.c
32079@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32080 }
32081 }
32082
32083-static const struct ide_port_info rz1000_chipset __devinitdata = {
32084+static const struct ide_port_info rz1000_chipset __devinitconst = {
32085 .name = DRV_NAME,
32086 .host_flags = IDE_HFLAG_NO_DMA,
32087 };
32088diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32089index 356b9b5..d4758eb 100644
32090--- a/drivers/ide/sc1200.c
32091+++ b/drivers/ide/sc1200.c
32092@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32093 .dma_sff_read_status = ide_dma_sff_read_status,
32094 };
32095
32096-static const struct ide_port_info sc1200_chipset __devinitdata = {
32097+static const struct ide_port_info sc1200_chipset __devinitconst = {
32098 .name = DRV_NAME,
32099 .port_ops = &sc1200_port_ops,
32100 .dma_ops = &sc1200_dma_ops,
32101diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32102index b7f5b0c..9701038 100644
32103--- a/drivers/ide/scc_pata.c
32104+++ b/drivers/ide/scc_pata.c
32105@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32106 .dma_sff_read_status = scc_dma_sff_read_status,
32107 };
32108
32109-static const struct ide_port_info scc_chipset __devinitdata = {
32110+static const struct ide_port_info scc_chipset __devinitconst = {
32111 .name = "sccIDE",
32112 .init_iops = init_iops_scc,
32113 .init_dma = scc_init_dma,
32114diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32115index 35fb8da..24d72ef 100644
32116--- a/drivers/ide/serverworks.c
32117+++ b/drivers/ide/serverworks.c
32118@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32119 .cable_detect = svwks_cable_detect,
32120 };
32121
32122-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32123+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32124 { /* 0: OSB4 */
32125 .name = DRV_NAME,
32126 .init_chipset = init_chipset_svwks,
32127diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32128index ddeda44..46f7e30 100644
32129--- a/drivers/ide/siimage.c
32130+++ b/drivers/ide/siimage.c
32131@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32132 .udma_mask = ATA_UDMA6, \
32133 }
32134
32135-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32136+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32137 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32138 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32139 };
32140diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32141index 4a00225..09e61b4 100644
32142--- a/drivers/ide/sis5513.c
32143+++ b/drivers/ide/sis5513.c
32144@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32145 .cable_detect = sis_cable_detect,
32146 };
32147
32148-static const struct ide_port_info sis5513_chipset __devinitdata = {
32149+static const struct ide_port_info sis5513_chipset __devinitconst = {
32150 .name = DRV_NAME,
32151 .init_chipset = init_chipset_sis5513,
32152 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32153diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32154index f21dc2a..d051cd2 100644
32155--- a/drivers/ide/sl82c105.c
32156+++ b/drivers/ide/sl82c105.c
32157@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32158 .dma_sff_read_status = ide_dma_sff_read_status,
32159 };
32160
32161-static const struct ide_port_info sl82c105_chipset __devinitdata = {
32162+static const struct ide_port_info sl82c105_chipset __devinitconst = {
32163 .name = DRV_NAME,
32164 .init_chipset = init_chipset_sl82c105,
32165 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32166diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32167index 864ffe0..863a5e9 100644
32168--- a/drivers/ide/slc90e66.c
32169+++ b/drivers/ide/slc90e66.c
32170@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32171 .cable_detect = slc90e66_cable_detect,
32172 };
32173
32174-static const struct ide_port_info slc90e66_chipset __devinitdata = {
32175+static const struct ide_port_info slc90e66_chipset __devinitconst = {
32176 .name = DRV_NAME,
32177 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32178 .port_ops = &slc90e66_port_ops,
32179diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32180index 4799d5c..1794678 100644
32181--- a/drivers/ide/tc86c001.c
32182+++ b/drivers/ide/tc86c001.c
32183@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32184 .dma_sff_read_status = ide_dma_sff_read_status,
32185 };
32186
32187-static const struct ide_port_info tc86c001_chipset __devinitdata = {
32188+static const struct ide_port_info tc86c001_chipset __devinitconst = {
32189 .name = DRV_NAME,
32190 .init_hwif = init_hwif_tc86c001,
32191 .port_ops = &tc86c001_port_ops,
32192diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32193index 281c914..55ce1b8 100644
32194--- a/drivers/ide/triflex.c
32195+++ b/drivers/ide/triflex.c
32196@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32197 .set_dma_mode = triflex_set_mode,
32198 };
32199
32200-static const struct ide_port_info triflex_device __devinitdata = {
32201+static const struct ide_port_info triflex_device __devinitconst = {
32202 .name = DRV_NAME,
32203 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32204 .port_ops = &triflex_port_ops,
32205diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32206index 4b42ca0..e494a98 100644
32207--- a/drivers/ide/trm290.c
32208+++ b/drivers/ide/trm290.c
32209@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32210 .dma_check = trm290_dma_check,
32211 };
32212
32213-static const struct ide_port_info trm290_chipset __devinitdata = {
32214+static const struct ide_port_info trm290_chipset __devinitconst = {
32215 .name = DRV_NAME,
32216 .init_hwif = init_hwif_trm290,
32217 .tp_ops = &trm290_tp_ops,
32218diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32219index f46f49c..eb77678 100644
32220--- a/drivers/ide/via82cxxx.c
32221+++ b/drivers/ide/via82cxxx.c
32222@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32223 .cable_detect = via82cxxx_cable_detect,
32224 };
32225
32226-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32227+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32228 .name = DRV_NAME,
32229 .init_chipset = init_chipset_via82cxxx,
32230 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32231diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32232index 73d4531..c90cd2d 100644
32233--- a/drivers/ieee802154/fakehard.c
32234+++ b/drivers/ieee802154/fakehard.c
32235@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32236 phy->transmit_power = 0xbf;
32237
32238 dev->netdev_ops = &fake_ops;
32239- dev->ml_priv = &fake_mlme;
32240+ dev->ml_priv = (void *)&fake_mlme;
32241
32242 priv = netdev_priv(dev);
32243 priv->phy = phy;
32244diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32245index c889aae..6cf5aa7 100644
32246--- a/drivers/infiniband/core/cm.c
32247+++ b/drivers/infiniband/core/cm.c
32248@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32249
32250 struct cm_counter_group {
32251 struct kobject obj;
32252- atomic_long_t counter[CM_ATTR_COUNT];
32253+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32254 };
32255
32256 struct cm_counter_attribute {
32257@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32258 struct ib_mad_send_buf *msg = NULL;
32259 int ret;
32260
32261- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32262+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32263 counter[CM_REQ_COUNTER]);
32264
32265 /* Quick state check to discard duplicate REQs. */
32266@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32267 if (!cm_id_priv)
32268 return;
32269
32270- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32271+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32272 counter[CM_REP_COUNTER]);
32273 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32274 if (ret)
32275@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32276 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32277 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32278 spin_unlock_irq(&cm_id_priv->lock);
32279- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32280+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32281 counter[CM_RTU_COUNTER]);
32282 goto out;
32283 }
32284@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32285 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32286 dreq_msg->local_comm_id);
32287 if (!cm_id_priv) {
32288- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32289+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32290 counter[CM_DREQ_COUNTER]);
32291 cm_issue_drep(work->port, work->mad_recv_wc);
32292 return -EINVAL;
32293@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32294 case IB_CM_MRA_REP_RCVD:
32295 break;
32296 case IB_CM_TIMEWAIT:
32297- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32298+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32299 counter[CM_DREQ_COUNTER]);
32300 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32301 goto unlock;
32302@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32303 cm_free_msg(msg);
32304 goto deref;
32305 case IB_CM_DREQ_RCVD:
32306- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32307+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32308 counter[CM_DREQ_COUNTER]);
32309 goto unlock;
32310 default:
32311@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32312 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32313 cm_id_priv->msg, timeout)) {
32314 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32315- atomic_long_inc(&work->port->
32316+ atomic_long_inc_unchecked(&work->port->
32317 counter_group[CM_RECV_DUPLICATES].
32318 counter[CM_MRA_COUNTER]);
32319 goto out;
32320@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32321 break;
32322 case IB_CM_MRA_REQ_RCVD:
32323 case IB_CM_MRA_REP_RCVD:
32324- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32325+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32326 counter[CM_MRA_COUNTER]);
32327 /* fall through */
32328 default:
32329@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32330 case IB_CM_LAP_IDLE:
32331 break;
32332 case IB_CM_MRA_LAP_SENT:
32333- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32334+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32335 counter[CM_LAP_COUNTER]);
32336 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32337 goto unlock;
32338@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32339 cm_free_msg(msg);
32340 goto deref;
32341 case IB_CM_LAP_RCVD:
32342- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32343+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32344 counter[CM_LAP_COUNTER]);
32345 goto unlock;
32346 default:
32347@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32348 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32349 if (cur_cm_id_priv) {
32350 spin_unlock_irq(&cm.lock);
32351- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32352+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32353 counter[CM_SIDR_REQ_COUNTER]);
32354 goto out; /* Duplicate message. */
32355 }
32356@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32357 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32358 msg->retries = 1;
32359
32360- atomic_long_add(1 + msg->retries,
32361+ atomic_long_add_unchecked(1 + msg->retries,
32362 &port->counter_group[CM_XMIT].counter[attr_index]);
32363 if (msg->retries)
32364- atomic_long_add(msg->retries,
32365+ atomic_long_add_unchecked(msg->retries,
32366 &port->counter_group[CM_XMIT_RETRIES].
32367 counter[attr_index]);
32368
32369@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32370 }
32371
32372 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32373- atomic_long_inc(&port->counter_group[CM_RECV].
32374+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32375 counter[attr_id - CM_ATTR_ID_OFFSET]);
32376
32377 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32378@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32379 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32380
32381 return sprintf(buf, "%ld\n",
32382- atomic_long_read(&group->counter[cm_attr->index]));
32383+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32384 }
32385
32386 static const struct sysfs_ops cm_counter_ops = {
32387diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32388index 176c8f9..2627b62 100644
32389--- a/drivers/infiniband/core/fmr_pool.c
32390+++ b/drivers/infiniband/core/fmr_pool.c
32391@@ -98,8 +98,8 @@ struct ib_fmr_pool {
32392
32393 struct task_struct *thread;
32394
32395- atomic_t req_ser;
32396- atomic_t flush_ser;
32397+ atomic_unchecked_t req_ser;
32398+ atomic_unchecked_t flush_ser;
32399
32400 wait_queue_head_t force_wait;
32401 };
32402@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32403 struct ib_fmr_pool *pool = pool_ptr;
32404
32405 do {
32406- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32407+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32408 ib_fmr_batch_release(pool);
32409
32410- atomic_inc(&pool->flush_ser);
32411+ atomic_inc_unchecked(&pool->flush_ser);
32412 wake_up_interruptible(&pool->force_wait);
32413
32414 if (pool->flush_function)
32415@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32416 }
32417
32418 set_current_state(TASK_INTERRUPTIBLE);
32419- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32420+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32421 !kthread_should_stop())
32422 schedule();
32423 __set_current_state(TASK_RUNNING);
32424@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32425 pool->dirty_watermark = params->dirty_watermark;
32426 pool->dirty_len = 0;
32427 spin_lock_init(&pool->pool_lock);
32428- atomic_set(&pool->req_ser, 0);
32429- atomic_set(&pool->flush_ser, 0);
32430+ atomic_set_unchecked(&pool->req_ser, 0);
32431+ atomic_set_unchecked(&pool->flush_ser, 0);
32432 init_waitqueue_head(&pool->force_wait);
32433
32434 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32435@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32436 }
32437 spin_unlock_irq(&pool->pool_lock);
32438
32439- serial = atomic_inc_return(&pool->req_ser);
32440+ serial = atomic_inc_return_unchecked(&pool->req_ser);
32441 wake_up_process(pool->thread);
32442
32443 if (wait_event_interruptible(pool->force_wait,
32444- atomic_read(&pool->flush_ser) - serial >= 0))
32445+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32446 return -EINTR;
32447
32448 return 0;
32449@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32450 } else {
32451 list_add_tail(&fmr->list, &pool->dirty_list);
32452 if (++pool->dirty_len >= pool->dirty_watermark) {
32453- atomic_inc(&pool->req_ser);
32454+ atomic_inc_unchecked(&pool->req_ser);
32455 wake_up_process(pool->thread);
32456 }
32457 }
32458diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32459index 40c8353..946b0e4 100644
32460--- a/drivers/infiniband/hw/cxgb4/mem.c
32461+++ b/drivers/infiniband/hw/cxgb4/mem.c
32462@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32463 int err;
32464 struct fw_ri_tpte tpt;
32465 u32 stag_idx;
32466- static atomic_t key;
32467+ static atomic_unchecked_t key;
32468
32469 if (c4iw_fatal_error(rdev))
32470 return -EIO;
32471@@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32472 &rdev->resource.tpt_fifo_lock);
32473 if (!stag_idx)
32474 return -ENOMEM;
32475- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32476+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32477 }
32478 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32479 __func__, stag_state, type, pdid, stag_idx);
32480diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32481index 79b3dbc..96e5fcc 100644
32482--- a/drivers/infiniband/hw/ipath/ipath_rc.c
32483+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32484@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32485 struct ib_atomic_eth *ateth;
32486 struct ipath_ack_entry *e;
32487 u64 vaddr;
32488- atomic64_t *maddr;
32489+ atomic64_unchecked_t *maddr;
32490 u64 sdata;
32491 u32 rkey;
32492 u8 next;
32493@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32494 IB_ACCESS_REMOTE_ATOMIC)))
32495 goto nack_acc_unlck;
32496 /* Perform atomic OP and save result. */
32497- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32498+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32499 sdata = be64_to_cpu(ateth->swap_data);
32500 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32501 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32502- (u64) atomic64_add_return(sdata, maddr) - sdata :
32503+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32504 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32505 be64_to_cpu(ateth->compare_data),
32506 sdata);
32507diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32508index 1f95bba..9530f87 100644
32509--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32510+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32511@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32512 unsigned long flags;
32513 struct ib_wc wc;
32514 u64 sdata;
32515- atomic64_t *maddr;
32516+ atomic64_unchecked_t *maddr;
32517 enum ib_wc_status send_status;
32518
32519 /*
32520@@ -382,11 +382,11 @@ again:
32521 IB_ACCESS_REMOTE_ATOMIC)))
32522 goto acc_err;
32523 /* Perform atomic OP and save result. */
32524- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32525+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32526 sdata = wqe->wr.wr.atomic.compare_add;
32527 *(u64 *) sqp->s_sge.sge.vaddr =
32528 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32529- (u64) atomic64_add_return(sdata, maddr) - sdata :
32530+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32531 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32532 sdata, wqe->wr.wr.atomic.swap);
32533 goto send_comp;
32534diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32535index 7140199..da60063 100644
32536--- a/drivers/infiniband/hw/nes/nes.c
32537+++ b/drivers/infiniband/hw/nes/nes.c
32538@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32539 LIST_HEAD(nes_adapter_list);
32540 static LIST_HEAD(nes_dev_list);
32541
32542-atomic_t qps_destroyed;
32543+atomic_unchecked_t qps_destroyed;
32544
32545 static unsigned int ee_flsh_adapter;
32546 static unsigned int sysfs_nonidx_addr;
32547@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32548 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32549 struct nes_adapter *nesadapter = nesdev->nesadapter;
32550
32551- atomic_inc(&qps_destroyed);
32552+ atomic_inc_unchecked(&qps_destroyed);
32553
32554 /* Free the control structures */
32555
32556diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32557index c438e46..ca30356 100644
32558--- a/drivers/infiniband/hw/nes/nes.h
32559+++ b/drivers/infiniband/hw/nes/nes.h
32560@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32561 extern unsigned int wqm_quanta;
32562 extern struct list_head nes_adapter_list;
32563
32564-extern atomic_t cm_connects;
32565-extern atomic_t cm_accepts;
32566-extern atomic_t cm_disconnects;
32567-extern atomic_t cm_closes;
32568-extern atomic_t cm_connecteds;
32569-extern atomic_t cm_connect_reqs;
32570-extern atomic_t cm_rejects;
32571-extern atomic_t mod_qp_timouts;
32572-extern atomic_t qps_created;
32573-extern atomic_t qps_destroyed;
32574-extern atomic_t sw_qps_destroyed;
32575+extern atomic_unchecked_t cm_connects;
32576+extern atomic_unchecked_t cm_accepts;
32577+extern atomic_unchecked_t cm_disconnects;
32578+extern atomic_unchecked_t cm_closes;
32579+extern atomic_unchecked_t cm_connecteds;
32580+extern atomic_unchecked_t cm_connect_reqs;
32581+extern atomic_unchecked_t cm_rejects;
32582+extern atomic_unchecked_t mod_qp_timouts;
32583+extern atomic_unchecked_t qps_created;
32584+extern atomic_unchecked_t qps_destroyed;
32585+extern atomic_unchecked_t sw_qps_destroyed;
32586 extern u32 mh_detected;
32587 extern u32 mh_pauses_sent;
32588 extern u32 cm_packets_sent;
32589@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32590 extern u32 cm_packets_received;
32591 extern u32 cm_packets_dropped;
32592 extern u32 cm_packets_retrans;
32593-extern atomic_t cm_listens_created;
32594-extern atomic_t cm_listens_destroyed;
32595+extern atomic_unchecked_t cm_listens_created;
32596+extern atomic_unchecked_t cm_listens_destroyed;
32597 extern u32 cm_backlog_drops;
32598-extern atomic_t cm_loopbacks;
32599-extern atomic_t cm_nodes_created;
32600-extern atomic_t cm_nodes_destroyed;
32601-extern atomic_t cm_accel_dropped_pkts;
32602-extern atomic_t cm_resets_recvd;
32603-extern atomic_t pau_qps_created;
32604-extern atomic_t pau_qps_destroyed;
32605+extern atomic_unchecked_t cm_loopbacks;
32606+extern atomic_unchecked_t cm_nodes_created;
32607+extern atomic_unchecked_t cm_nodes_destroyed;
32608+extern atomic_unchecked_t cm_accel_dropped_pkts;
32609+extern atomic_unchecked_t cm_resets_recvd;
32610+extern atomic_unchecked_t pau_qps_created;
32611+extern atomic_unchecked_t pau_qps_destroyed;
32612
32613 extern u32 int_mod_timer_init;
32614 extern u32 int_mod_cq_depth_256;
32615diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32616index a4972ab..1bcfc31 100644
32617--- a/drivers/infiniband/hw/nes/nes_cm.c
32618+++ b/drivers/infiniband/hw/nes/nes_cm.c
32619@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32620 u32 cm_packets_retrans;
32621 u32 cm_packets_created;
32622 u32 cm_packets_received;
32623-atomic_t cm_listens_created;
32624-atomic_t cm_listens_destroyed;
32625+atomic_unchecked_t cm_listens_created;
32626+atomic_unchecked_t cm_listens_destroyed;
32627 u32 cm_backlog_drops;
32628-atomic_t cm_loopbacks;
32629-atomic_t cm_nodes_created;
32630-atomic_t cm_nodes_destroyed;
32631-atomic_t cm_accel_dropped_pkts;
32632-atomic_t cm_resets_recvd;
32633+atomic_unchecked_t cm_loopbacks;
32634+atomic_unchecked_t cm_nodes_created;
32635+atomic_unchecked_t cm_nodes_destroyed;
32636+atomic_unchecked_t cm_accel_dropped_pkts;
32637+atomic_unchecked_t cm_resets_recvd;
32638
32639 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32640 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32641@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32642
32643 static struct nes_cm_core *g_cm_core;
32644
32645-atomic_t cm_connects;
32646-atomic_t cm_accepts;
32647-atomic_t cm_disconnects;
32648-atomic_t cm_closes;
32649-atomic_t cm_connecteds;
32650-atomic_t cm_connect_reqs;
32651-atomic_t cm_rejects;
32652+atomic_unchecked_t cm_connects;
32653+atomic_unchecked_t cm_accepts;
32654+atomic_unchecked_t cm_disconnects;
32655+atomic_unchecked_t cm_closes;
32656+atomic_unchecked_t cm_connecteds;
32657+atomic_unchecked_t cm_connect_reqs;
32658+atomic_unchecked_t cm_rejects;
32659
32660 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32661 {
32662@@ -1274,7 +1274,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32663 kfree(listener);
32664 listener = NULL;
32665 ret = 0;
32666- atomic_inc(&cm_listens_destroyed);
32667+ atomic_inc_unchecked(&cm_listens_destroyed);
32668 } else {
32669 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32670 }
32671@@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32672 cm_node->rem_mac);
32673
32674 add_hte_node(cm_core, cm_node);
32675- atomic_inc(&cm_nodes_created);
32676+ atomic_inc_unchecked(&cm_nodes_created);
32677
32678 return cm_node;
32679 }
32680@@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32681 }
32682
32683 atomic_dec(&cm_core->node_cnt);
32684- atomic_inc(&cm_nodes_destroyed);
32685+ atomic_inc_unchecked(&cm_nodes_destroyed);
32686 nesqp = cm_node->nesqp;
32687 if (nesqp) {
32688 nesqp->cm_node = NULL;
32689@@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32690
32691 static void drop_packet(struct sk_buff *skb)
32692 {
32693- atomic_inc(&cm_accel_dropped_pkts);
32694+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32695 dev_kfree_skb_any(skb);
32696 }
32697
32698@@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32699 {
32700
32701 int reset = 0; /* whether to send reset in case of err.. */
32702- atomic_inc(&cm_resets_recvd);
32703+ atomic_inc_unchecked(&cm_resets_recvd);
32704 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32705 " refcnt=%d\n", cm_node, cm_node->state,
32706 atomic_read(&cm_node->ref_count));
32707@@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32708 rem_ref_cm_node(cm_node->cm_core, cm_node);
32709 return NULL;
32710 }
32711- atomic_inc(&cm_loopbacks);
32712+ atomic_inc_unchecked(&cm_loopbacks);
32713 loopbackremotenode->loopbackpartner = cm_node;
32714 loopbackremotenode->tcp_cntxt.rcv_wscale =
32715 NES_CM_DEFAULT_RCV_WND_SCALE;
32716@@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32717 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32718 else {
32719 rem_ref_cm_node(cm_core, cm_node);
32720- atomic_inc(&cm_accel_dropped_pkts);
32721+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32722 dev_kfree_skb_any(skb);
32723 }
32724 break;
32725@@ -2881,7 +2881,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32726
32727 if ((cm_id) && (cm_id->event_handler)) {
32728 if (issue_disconn) {
32729- atomic_inc(&cm_disconnects);
32730+ atomic_inc_unchecked(&cm_disconnects);
32731 cm_event.event = IW_CM_EVENT_DISCONNECT;
32732 cm_event.status = disconn_status;
32733 cm_event.local_addr = cm_id->local_addr;
32734@@ -2903,7 +2903,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32735 }
32736
32737 if (issue_close) {
32738- atomic_inc(&cm_closes);
32739+ atomic_inc_unchecked(&cm_closes);
32740 nes_disconnect(nesqp, 1);
32741
32742 cm_id->provider_data = nesqp;
32743@@ -3039,7 +3039,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32744
32745 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32746 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32747- atomic_inc(&cm_accepts);
32748+ atomic_inc_unchecked(&cm_accepts);
32749
32750 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32751 netdev_refcnt_read(nesvnic->netdev));
32752@@ -3241,7 +3241,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32753 struct nes_cm_core *cm_core;
32754 u8 *start_buff;
32755
32756- atomic_inc(&cm_rejects);
32757+ atomic_inc_unchecked(&cm_rejects);
32758 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32759 loopback = cm_node->loopbackpartner;
32760 cm_core = cm_node->cm_core;
32761@@ -3301,7 +3301,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32762 ntohl(cm_id->local_addr.sin_addr.s_addr),
32763 ntohs(cm_id->local_addr.sin_port));
32764
32765- atomic_inc(&cm_connects);
32766+ atomic_inc_unchecked(&cm_connects);
32767 nesqp->active_conn = 1;
32768
32769 /* cache the cm_id in the qp */
32770@@ -3407,7 +3407,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32771 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32772 return err;
32773 }
32774- atomic_inc(&cm_listens_created);
32775+ atomic_inc_unchecked(&cm_listens_created);
32776 }
32777
32778 cm_id->add_ref(cm_id);
32779@@ -3508,7 +3508,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32780
32781 if (nesqp->destroyed)
32782 return;
32783- atomic_inc(&cm_connecteds);
32784+ atomic_inc_unchecked(&cm_connecteds);
32785 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32786 " local port 0x%04X. jiffies = %lu.\n",
32787 nesqp->hwqp.qp_id,
32788@@ -3695,7 +3695,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32789
32790 cm_id->add_ref(cm_id);
32791 ret = cm_id->event_handler(cm_id, &cm_event);
32792- atomic_inc(&cm_closes);
32793+ atomic_inc_unchecked(&cm_closes);
32794 cm_event.event = IW_CM_EVENT_CLOSE;
32795 cm_event.status = 0;
32796 cm_event.provider_data = cm_id->provider_data;
32797@@ -3731,7 +3731,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32798 return;
32799 cm_id = cm_node->cm_id;
32800
32801- atomic_inc(&cm_connect_reqs);
32802+ atomic_inc_unchecked(&cm_connect_reqs);
32803 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32804 cm_node, cm_id, jiffies);
32805
32806@@ -3771,7 +3771,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32807 return;
32808 cm_id = cm_node->cm_id;
32809
32810- atomic_inc(&cm_connect_reqs);
32811+ atomic_inc_unchecked(&cm_connect_reqs);
32812 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32813 cm_node, cm_id, jiffies);
32814
32815diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32816index 3ba7be3..c81f6ff 100644
32817--- a/drivers/infiniband/hw/nes/nes_mgt.c
32818+++ b/drivers/infiniband/hw/nes/nes_mgt.c
32819@@ -40,8 +40,8 @@
32820 #include "nes.h"
32821 #include "nes_mgt.h"
32822
32823-atomic_t pau_qps_created;
32824-atomic_t pau_qps_destroyed;
32825+atomic_unchecked_t pau_qps_created;
32826+atomic_unchecked_t pau_qps_destroyed;
32827
32828 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32829 {
32830@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32831 {
32832 struct sk_buff *skb;
32833 unsigned long flags;
32834- atomic_inc(&pau_qps_destroyed);
32835+ atomic_inc_unchecked(&pau_qps_destroyed);
32836
32837 /* Free packets that have not yet been forwarded */
32838 /* Lock is acquired by skb_dequeue when removing the skb */
32839@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32840 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32841 skb_queue_head_init(&nesqp->pau_list);
32842 spin_lock_init(&nesqp->pau_lock);
32843- atomic_inc(&pau_qps_created);
32844+ atomic_inc_unchecked(&pau_qps_created);
32845 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32846 }
32847
32848diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32849index f3a3ecf..57d311d 100644
32850--- a/drivers/infiniband/hw/nes/nes_nic.c
32851+++ b/drivers/infiniband/hw/nes/nes_nic.c
32852@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32853 target_stat_values[++index] = mh_detected;
32854 target_stat_values[++index] = mh_pauses_sent;
32855 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32856- target_stat_values[++index] = atomic_read(&cm_connects);
32857- target_stat_values[++index] = atomic_read(&cm_accepts);
32858- target_stat_values[++index] = atomic_read(&cm_disconnects);
32859- target_stat_values[++index] = atomic_read(&cm_connecteds);
32860- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32861- target_stat_values[++index] = atomic_read(&cm_rejects);
32862- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32863- target_stat_values[++index] = atomic_read(&qps_created);
32864- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32865- target_stat_values[++index] = atomic_read(&qps_destroyed);
32866- target_stat_values[++index] = atomic_read(&cm_closes);
32867+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32868+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32869+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32870+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32871+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32872+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32873+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32874+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32875+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32876+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32877+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32878 target_stat_values[++index] = cm_packets_sent;
32879 target_stat_values[++index] = cm_packets_bounced;
32880 target_stat_values[++index] = cm_packets_created;
32881 target_stat_values[++index] = cm_packets_received;
32882 target_stat_values[++index] = cm_packets_dropped;
32883 target_stat_values[++index] = cm_packets_retrans;
32884- target_stat_values[++index] = atomic_read(&cm_listens_created);
32885- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32886+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32887+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32888 target_stat_values[++index] = cm_backlog_drops;
32889- target_stat_values[++index] = atomic_read(&cm_loopbacks);
32890- target_stat_values[++index] = atomic_read(&cm_nodes_created);
32891- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32892- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32893- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32894+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32895+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32896+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32897+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32898+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32899 target_stat_values[++index] = nesadapter->free_4kpbl;
32900 target_stat_values[++index] = nesadapter->free_256pbl;
32901 target_stat_values[++index] = int_mod_timer_init;
32902 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32903 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32904 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32905- target_stat_values[++index] = atomic_read(&pau_qps_created);
32906- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32907+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32908+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32909 }
32910
32911 /**
32912diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32913index 0927b5c..ed67986 100644
32914--- a/drivers/infiniband/hw/nes/nes_verbs.c
32915+++ b/drivers/infiniband/hw/nes/nes_verbs.c
32916@@ -46,9 +46,9 @@
32917
32918 #include <rdma/ib_umem.h>
32919
32920-atomic_t mod_qp_timouts;
32921-atomic_t qps_created;
32922-atomic_t sw_qps_destroyed;
32923+atomic_unchecked_t mod_qp_timouts;
32924+atomic_unchecked_t qps_created;
32925+atomic_unchecked_t sw_qps_destroyed;
32926
32927 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32928
32929@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32930 if (init_attr->create_flags)
32931 return ERR_PTR(-EINVAL);
32932
32933- atomic_inc(&qps_created);
32934+ atomic_inc_unchecked(&qps_created);
32935 switch (init_attr->qp_type) {
32936 case IB_QPT_RC:
32937 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32938@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32939 struct iw_cm_event cm_event;
32940 int ret = 0;
32941
32942- atomic_inc(&sw_qps_destroyed);
32943+ atomic_inc_unchecked(&sw_qps_destroyed);
32944 nesqp->destroyed = 1;
32945
32946 /* Blow away the connection if it exists. */
32947diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32948index b881bdc..c2e360c 100644
32949--- a/drivers/infiniband/hw/qib/qib.h
32950+++ b/drivers/infiniband/hw/qib/qib.h
32951@@ -51,6 +51,7 @@
32952 #include <linux/completion.h>
32953 #include <linux/kref.h>
32954 #include <linux/sched.h>
32955+#include <linux/slab.h>
32956
32957 #include "qib_common.h"
32958 #include "qib_verbs.h"
32959diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32960index c351aa4..e6967c2 100644
32961--- a/drivers/input/gameport/gameport.c
32962+++ b/drivers/input/gameport/gameport.c
32963@@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32964 */
32965 static void gameport_init_port(struct gameport *gameport)
32966 {
32967- static atomic_t gameport_no = ATOMIC_INIT(0);
32968+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32969
32970 __module_get(THIS_MODULE);
32971
32972 mutex_init(&gameport->drv_mutex);
32973 device_initialize(&gameport->dev);
32974 dev_set_name(&gameport->dev, "gameport%lu",
32975- (unsigned long)atomic_inc_return(&gameport_no) - 1);
32976+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32977 gameport->dev.bus = &gameport_bus;
32978 gameport->dev.release = gameport_release_port;
32979 if (gameport->parent)
32980diff --git a/drivers/input/input.c b/drivers/input/input.c
32981index 1f78c95..3cddc6c 100644
32982--- a/drivers/input/input.c
32983+++ b/drivers/input/input.c
32984@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32985 */
32986 int input_register_device(struct input_dev *dev)
32987 {
32988- static atomic_t input_no = ATOMIC_INIT(0);
32989+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32990 struct input_handler *handler;
32991 const char *path;
32992 int error;
32993@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32994 dev->setkeycode = input_default_setkeycode;
32995
32996 dev_set_name(&dev->dev, "input%ld",
32997- (unsigned long) atomic_inc_return(&input_no) - 1);
32998+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32999
33000 error = device_add(&dev->dev);
33001 if (error)
33002diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
33003index b8d8611..7a4a04b 100644
33004--- a/drivers/input/joystick/sidewinder.c
33005+++ b/drivers/input/joystick/sidewinder.c
33006@@ -30,6 +30,7 @@
33007 #include <linux/kernel.h>
33008 #include <linux/module.h>
33009 #include <linux/slab.h>
33010+#include <linux/sched.h>
33011 #include <linux/init.h>
33012 #include <linux/input.h>
33013 #include <linux/gameport.h>
33014diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
33015index fd7a0d5..a4af10c 100644
33016--- a/drivers/input/joystick/xpad.c
33017+++ b/drivers/input/joystick/xpad.c
33018@@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
33019
33020 static int xpad_led_probe(struct usb_xpad *xpad)
33021 {
33022- static atomic_t led_seq = ATOMIC_INIT(0);
33023+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
33024 long led_no;
33025 struct xpad_led *led;
33026 struct led_classdev *led_cdev;
33027@@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
33028 if (!led)
33029 return -ENOMEM;
33030
33031- led_no = (long)atomic_inc_return(&led_seq) - 1;
33032+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
33033
33034 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
33035 led->xpad = xpad;
33036diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
33037index 0110b5a..d3ad144 100644
33038--- a/drivers/input/mousedev.c
33039+++ b/drivers/input/mousedev.c
33040@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
33041
33042 spin_unlock_irq(&client->packet_lock);
33043
33044- if (copy_to_user(buffer, data, count))
33045+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
33046 return -EFAULT;
33047
33048 return count;
33049diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33050index ba70058..571d25d 100644
33051--- a/drivers/input/serio/serio.c
33052+++ b/drivers/input/serio/serio.c
33053@@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
33054 */
33055 static void serio_init_port(struct serio *serio)
33056 {
33057- static atomic_t serio_no = ATOMIC_INIT(0);
33058+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33059
33060 __module_get(THIS_MODULE);
33061
33062@@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
33063 mutex_init(&serio->drv_mutex);
33064 device_initialize(&serio->dev);
33065 dev_set_name(&serio->dev, "serio%ld",
33066- (long)atomic_inc_return(&serio_no) - 1);
33067+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
33068 serio->dev.bus = &serio_bus;
33069 serio->dev.release = serio_release_port;
33070 serio->dev.groups = serio_device_attr_groups;
33071diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33072index e44933d..9ba484a 100644
33073--- a/drivers/isdn/capi/capi.c
33074+++ b/drivers/isdn/capi/capi.c
33075@@ -83,8 +83,8 @@ struct capiminor {
33076
33077 struct capi20_appl *ap;
33078 u32 ncci;
33079- atomic_t datahandle;
33080- atomic_t msgid;
33081+ atomic_unchecked_t datahandle;
33082+ atomic_unchecked_t msgid;
33083
33084 struct tty_port port;
33085 int ttyinstop;
33086@@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33087 capimsg_setu16(s, 2, mp->ap->applid);
33088 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33089 capimsg_setu8 (s, 5, CAPI_RESP);
33090- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33091+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33092 capimsg_setu32(s, 8, mp->ncci);
33093 capimsg_setu16(s, 12, datahandle);
33094 }
33095@@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
33096 mp->outbytes -= len;
33097 spin_unlock_bh(&mp->outlock);
33098
33099- datahandle = atomic_inc_return(&mp->datahandle);
33100+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33101 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33102 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33103 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33104 capimsg_setu16(skb->data, 2, mp->ap->applid);
33105 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33106 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33107- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33108+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33109 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33110 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33111 capimsg_setu16(skb->data, 16, len); /* Data length */
33112diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
33113index db621db..825ea1a 100644
33114--- a/drivers/isdn/gigaset/common.c
33115+++ b/drivers/isdn/gigaset/common.c
33116@@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
33117 cs->commands_pending = 0;
33118 cs->cur_at_seq = 0;
33119 cs->gotfwver = -1;
33120- cs->open_count = 0;
33121+ local_set(&cs->open_count, 0);
33122 cs->dev = NULL;
33123 cs->tty = NULL;
33124 cs->tty_dev = NULL;
33125diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
33126index 212efaf..f187c6b 100644
33127--- a/drivers/isdn/gigaset/gigaset.h
33128+++ b/drivers/isdn/gigaset/gigaset.h
33129@@ -35,6 +35,7 @@
33130 #include <linux/tty_driver.h>
33131 #include <linux/list.h>
33132 #include <linux/atomic.h>
33133+#include <asm/local.h>
33134
33135 #define GIG_VERSION {0, 5, 0, 0}
33136 #define GIG_COMPAT {0, 4, 0, 0}
33137@@ -433,7 +434,7 @@ struct cardstate {
33138 spinlock_t cmdlock;
33139 unsigned curlen, cmdbytes;
33140
33141- unsigned open_count;
33142+ local_t open_count;
33143 struct tty_struct *tty;
33144 struct tasklet_struct if_wake_tasklet;
33145 unsigned control_state;
33146diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33147index ee0a549..a7c9798 100644
33148--- a/drivers/isdn/gigaset/interface.c
33149+++ b/drivers/isdn/gigaset/interface.c
33150@@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33151 }
33152 tty->driver_data = cs;
33153
33154- ++cs->open_count;
33155-
33156- if (cs->open_count == 1) {
33157+ if (local_inc_return(&cs->open_count) == 1) {
33158 spin_lock_irqsave(&cs->lock, flags);
33159 cs->tty = tty;
33160 spin_unlock_irqrestore(&cs->lock, flags);
33161@@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33162
33163 if (!cs->connected)
33164 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33165- else if (!cs->open_count)
33166+ else if (!local_read(&cs->open_count))
33167 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33168 else {
33169- if (!--cs->open_count) {
33170+ if (!local_dec_return(&cs->open_count)) {
33171 spin_lock_irqsave(&cs->lock, flags);
33172 cs->tty = NULL;
33173 spin_unlock_irqrestore(&cs->lock, flags);
33174@@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
33175 if (!cs->connected) {
33176 gig_dbg(DEBUG_IF, "not connected");
33177 retval = -ENODEV;
33178- } else if (!cs->open_count)
33179+ } else if (!local_read(&cs->open_count))
33180 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33181 else {
33182 retval = 0;
33183@@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
33184 retval = -ENODEV;
33185 goto done;
33186 }
33187- if (!cs->open_count) {
33188+ if (!local_read(&cs->open_count)) {
33189 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33190 retval = -ENODEV;
33191 goto done;
33192@@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
33193 if (!cs->connected) {
33194 gig_dbg(DEBUG_IF, "not connected");
33195 retval = -ENODEV;
33196- } else if (!cs->open_count)
33197+ } else if (!local_read(&cs->open_count))
33198 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33199 else if (cs->mstate != MS_LOCKED) {
33200 dev_warn(cs->dev, "can't write to unlocked device\n");
33201@@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
33202
33203 if (!cs->connected)
33204 gig_dbg(DEBUG_IF, "not connected");
33205- else if (!cs->open_count)
33206+ else if (!local_read(&cs->open_count))
33207 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33208 else if (cs->mstate != MS_LOCKED)
33209 dev_warn(cs->dev, "can't write to unlocked device\n");
33210@@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
33211
33212 if (!cs->connected)
33213 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33214- else if (!cs->open_count)
33215+ else if (!local_read(&cs->open_count))
33216 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33217 else
33218 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
33219@@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
33220
33221 if (!cs->connected)
33222 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33223- else if (!cs->open_count)
33224+ else if (!local_read(&cs->open_count))
33225 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33226 else
33227 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
33228@@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
33229 goto out;
33230 }
33231
33232- if (!cs->open_count) {
33233+ if (!local_read(&cs->open_count)) {
33234 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33235 goto out;
33236 }
33237diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33238index 2a57da59..e7a12ed 100644
33239--- a/drivers/isdn/hardware/avm/b1.c
33240+++ b/drivers/isdn/hardware/avm/b1.c
33241@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
33242 }
33243 if (left) {
33244 if (t4file->user) {
33245- if (copy_from_user(buf, dp, left))
33246+ if (left > sizeof buf || copy_from_user(buf, dp, left))
33247 return -EFAULT;
33248 } else {
33249 memcpy(buf, dp, left);
33250@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
33251 }
33252 if (left) {
33253 if (config->user) {
33254- if (copy_from_user(buf, dp, left))
33255+ if (left > sizeof buf || copy_from_user(buf, dp, left))
33256 return -EFAULT;
33257 } else {
33258 memcpy(buf, dp, left);
33259diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33260index 85784a7..a19ca98 100644
33261--- a/drivers/isdn/hardware/eicon/divasync.h
33262+++ b/drivers/isdn/hardware/eicon/divasync.h
33263@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33264 } diva_didd_add_adapter_t;
33265 typedef struct _diva_didd_remove_adapter {
33266 IDI_CALL p_request;
33267-} diva_didd_remove_adapter_t;
33268+} __no_const diva_didd_remove_adapter_t;
33269 typedef struct _diva_didd_read_adapter_array {
33270 void * buffer;
33271 dword length;
33272diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33273index a3bd163..8956575 100644
33274--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33275+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33276@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33277 typedef struct _diva_os_idi_adapter_interface {
33278 diva_init_card_proc_t cleanup_adapter_proc;
33279 diva_cmd_card_proc_t cmd_proc;
33280-} diva_os_idi_adapter_interface_t;
33281+} __no_const diva_os_idi_adapter_interface_t;
33282
33283 typedef struct _diva_os_xdi_adapter {
33284 struct list_head link;
33285diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33286index 1f355bb..43f1fea 100644
33287--- a/drivers/isdn/icn/icn.c
33288+++ b/drivers/isdn/icn/icn.c
33289@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
33290 if (count > len)
33291 count = len;
33292 if (user) {
33293- if (copy_from_user(msg, buf, count))
33294+ if (count > sizeof msg || copy_from_user(msg, buf, count))
33295 return -EFAULT;
33296 } else
33297 memcpy(msg, buf, count);
33298diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
33299index 8bc4915..4cc6a2e 100644
33300--- a/drivers/leds/leds-mc13783.c
33301+++ b/drivers/leds/leds-mc13783.c
33302@@ -280,7 +280,7 @@ static int __devinit mc13783_led_probe(struct platform_device *pdev)
33303 return -EINVAL;
33304 }
33305
33306- led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
33307+ led = kcalloc(pdata->num_leds, sizeof(*led), GFP_KERNEL);
33308 if (led == NULL) {
33309 dev_err(&pdev->dev, "failed to alloc memory\n");
33310 return -ENOMEM;
33311diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33312index b5fdcb7..5b6c59f 100644
33313--- a/drivers/lguest/core.c
33314+++ b/drivers/lguest/core.c
33315@@ -92,9 +92,17 @@ static __init int map_switcher(void)
33316 * it's worked so far. The end address needs +1 because __get_vm_area
33317 * allocates an extra guard page, so we need space for that.
33318 */
33319+
33320+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33321+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33322+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33323+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33324+#else
33325 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33326 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33327 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33328+#endif
33329+
33330 if (!switcher_vma) {
33331 err = -ENOMEM;
33332 printk("lguest: could not map switcher pages high\n");
33333@@ -119,7 +127,7 @@ static __init int map_switcher(void)
33334 * Now the Switcher is mapped at the right address, we can't fail!
33335 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33336 */
33337- memcpy(switcher_vma->addr, start_switcher_text,
33338+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33339 end_switcher_text - start_switcher_text);
33340
33341 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33342diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33343index 3980903..ce25c5e 100644
33344--- a/drivers/lguest/x86/core.c
33345+++ b/drivers/lguest/x86/core.c
33346@@ -59,7 +59,7 @@ static struct {
33347 /* Offset from where switcher.S was compiled to where we've copied it */
33348 static unsigned long switcher_offset(void)
33349 {
33350- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33351+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33352 }
33353
33354 /* This cpu's struct lguest_pages. */
33355@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33356 * These copies are pretty cheap, so we do them unconditionally: */
33357 /* Save the current Host top-level page directory.
33358 */
33359+
33360+#ifdef CONFIG_PAX_PER_CPU_PGD
33361+ pages->state.host_cr3 = read_cr3();
33362+#else
33363 pages->state.host_cr3 = __pa(current->mm->pgd);
33364+#endif
33365+
33366 /*
33367 * Set up the Guest's page tables to see this CPU's pages (and no
33368 * other CPU's pages).
33369@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33370 * compiled-in switcher code and the high-mapped copy we just made.
33371 */
33372 for (i = 0; i < IDT_ENTRIES; i++)
33373- default_idt_entries[i] += switcher_offset();
33374+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33375
33376 /*
33377 * Set up the Switcher's per-cpu areas.
33378@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33379 * it will be undisturbed when we switch. To change %cs and jump we
33380 * need this structure to feed to Intel's "lcall" instruction.
33381 */
33382- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33383+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33384 lguest_entry.segment = LGUEST_CS;
33385
33386 /*
33387diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33388index 40634b0..4f5855e 100644
33389--- a/drivers/lguest/x86/switcher_32.S
33390+++ b/drivers/lguest/x86/switcher_32.S
33391@@ -87,6 +87,7 @@
33392 #include <asm/page.h>
33393 #include <asm/segment.h>
33394 #include <asm/lguest.h>
33395+#include <asm/processor-flags.h>
33396
33397 // We mark the start of the code to copy
33398 // It's placed in .text tho it's never run here
33399@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33400 // Changes type when we load it: damn Intel!
33401 // For after we switch over our page tables
33402 // That entry will be read-only: we'd crash.
33403+
33404+#ifdef CONFIG_PAX_KERNEXEC
33405+ mov %cr0, %edx
33406+ xor $X86_CR0_WP, %edx
33407+ mov %edx, %cr0
33408+#endif
33409+
33410 movl $(GDT_ENTRY_TSS*8), %edx
33411 ltr %dx
33412
33413@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33414 // Let's clear it again for our return.
33415 // The GDT descriptor of the Host
33416 // Points to the table after two "size" bytes
33417- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33418+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33419 // Clear "used" from type field (byte 5, bit 2)
33420- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33421+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33422+
33423+#ifdef CONFIG_PAX_KERNEXEC
33424+ mov %cr0, %eax
33425+ xor $X86_CR0_WP, %eax
33426+ mov %eax, %cr0
33427+#endif
33428
33429 // Once our page table's switched, the Guest is live!
33430 // The Host fades as we run this final step.
33431@@ -295,13 +309,12 @@ deliver_to_host:
33432 // I consulted gcc, and it gave
33433 // These instructions, which I gladly credit:
33434 leal (%edx,%ebx,8), %eax
33435- movzwl (%eax),%edx
33436- movl 4(%eax), %eax
33437- xorw %ax, %ax
33438- orl %eax, %edx
33439+ movl 4(%eax), %edx
33440+ movw (%eax), %dx
33441 // Now the address of the handler's in %edx
33442 // We call it now: its "iret" drops us home.
33443- jmp *%edx
33444+ ljmp $__KERNEL_CS, $1f
33445+1: jmp *%edx
33446
33447 // Every interrupt can come to us here
33448 // But we must truly tell each apart.
33449diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33450index 4daf9e5..b8d1d0f 100644
33451--- a/drivers/macintosh/macio_asic.c
33452+++ b/drivers/macintosh/macio_asic.c
33453@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33454 * MacIO is matched against any Apple ID, it's probe() function
33455 * will then decide wether it applies or not
33456 */
33457-static const struct pci_device_id __devinitdata pci_ids [] = { {
33458+static const struct pci_device_id __devinitconst pci_ids [] = { {
33459 .vendor = PCI_VENDOR_ID_APPLE,
33460 .device = PCI_ANY_ID,
33461 .subvendor = PCI_ANY_ID,
33462diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33463index 1ce84ed..0fdd40a 100644
33464--- a/drivers/md/dm-ioctl.c
33465+++ b/drivers/md/dm-ioctl.c
33466@@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33467 cmd == DM_LIST_VERSIONS_CMD)
33468 return 0;
33469
33470- if ((cmd == DM_DEV_CREATE_CMD)) {
33471+ if (cmd == DM_DEV_CREATE_CMD) {
33472 if (!*param->name) {
33473 DMWARN("name not supplied when creating device");
33474 return -EINVAL;
33475diff --git a/drivers/md/dm-log-userspace-transfer.c b/drivers/md/dm-log-userspace-transfer.c
33476index 1f23e04..08d9a20 100644
33477--- a/drivers/md/dm-log-userspace-transfer.c
33478+++ b/drivers/md/dm-log-userspace-transfer.c
33479@@ -134,7 +134,7 @@ static void cn_ulog_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
33480 {
33481 struct dm_ulog_request *tfr = (struct dm_ulog_request *)(msg + 1);
33482
33483- if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
33484+ if (!capable(CAP_SYS_ADMIN))
33485 return;
33486
33487 spin_lock(&receiving_list_lock);
33488diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33489index 9bfd057..01180bc 100644
33490--- a/drivers/md/dm-raid1.c
33491+++ b/drivers/md/dm-raid1.c
33492@@ -40,7 +40,7 @@ enum dm_raid1_error {
33493
33494 struct mirror {
33495 struct mirror_set *ms;
33496- atomic_t error_count;
33497+ atomic_unchecked_t error_count;
33498 unsigned long error_type;
33499 struct dm_dev *dev;
33500 sector_t offset;
33501@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33502 struct mirror *m;
33503
33504 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33505- if (!atomic_read(&m->error_count))
33506+ if (!atomic_read_unchecked(&m->error_count))
33507 return m;
33508
33509 return NULL;
33510@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33511 * simple way to tell if a device has encountered
33512 * errors.
33513 */
33514- atomic_inc(&m->error_count);
33515+ atomic_inc_unchecked(&m->error_count);
33516
33517 if (test_and_set_bit(error_type, &m->error_type))
33518 return;
33519@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33520 struct mirror *m = get_default_mirror(ms);
33521
33522 do {
33523- if (likely(!atomic_read(&m->error_count)))
33524+ if (likely(!atomic_read_unchecked(&m->error_count)))
33525 return m;
33526
33527 if (m-- == ms->mirror)
33528@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33529 {
33530 struct mirror *default_mirror = get_default_mirror(m->ms);
33531
33532- return !atomic_read(&default_mirror->error_count);
33533+ return !atomic_read_unchecked(&default_mirror->error_count);
33534 }
33535
33536 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33537@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33538 */
33539 if (likely(region_in_sync(ms, region, 1)))
33540 m = choose_mirror(ms, bio->bi_sector);
33541- else if (m && atomic_read(&m->error_count))
33542+ else if (m && atomic_read_unchecked(&m->error_count))
33543 m = NULL;
33544
33545 if (likely(m))
33546@@ -937,7 +937,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33547 }
33548
33549 ms->mirror[mirror].ms = ms;
33550- atomic_set(&(ms->mirror[mirror].error_count), 0);
33551+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33552 ms->mirror[mirror].error_type = 0;
33553 ms->mirror[mirror].offset = offset;
33554
33555@@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_target *ti)
33556 */
33557 static char device_status_char(struct mirror *m)
33558 {
33559- if (!atomic_read(&(m->error_count)))
33560+ if (!atomic_read_unchecked(&(m->error_count)))
33561 return 'A';
33562
33563 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33564diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33565index 3d80cf0..b77cc47 100644
33566--- a/drivers/md/dm-stripe.c
33567+++ b/drivers/md/dm-stripe.c
33568@@ -20,7 +20,7 @@ struct stripe {
33569 struct dm_dev *dev;
33570 sector_t physical_start;
33571
33572- atomic_t error_count;
33573+ atomic_unchecked_t error_count;
33574 };
33575
33576 struct stripe_c {
33577@@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33578 kfree(sc);
33579 return r;
33580 }
33581- atomic_set(&(sc->stripe[i].error_count), 0);
33582+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33583 }
33584
33585 ti->private = sc;
33586@@ -314,7 +314,7 @@ static int stripe_status(struct dm_target *ti,
33587 DMEMIT("%d ", sc->stripes);
33588 for (i = 0; i < sc->stripes; i++) {
33589 DMEMIT("%s ", sc->stripe[i].dev->name);
33590- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33591+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33592 'D' : 'A';
33593 }
33594 buffer[i] = '\0';
33595@@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33596 */
33597 for (i = 0; i < sc->stripes; i++)
33598 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33599- atomic_inc(&(sc->stripe[i].error_count));
33600- if (atomic_read(&(sc->stripe[i].error_count)) <
33601+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
33602+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33603 DM_IO_ERROR_THRESHOLD)
33604 schedule_work(&sc->trigger_event);
33605 }
33606diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33607index 63cc542..8d45caf3 100644
33608--- a/drivers/md/dm-table.c
33609+++ b/drivers/md/dm-table.c
33610@@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33611 if (!dev_size)
33612 return 0;
33613
33614- if ((start >= dev_size) || (start + len > dev_size)) {
33615+ if ((start >= dev_size) || (len > dev_size - start)) {
33616 DMWARN("%s: %s too small for target: "
33617 "start=%llu, len=%llu, dev_size=%llu",
33618 dm_device_name(ti->table->md), bdevname(bdev, b),
33619diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33620index 237571a..fb6d19b 100644
33621--- a/drivers/md/dm-thin-metadata.c
33622+++ b/drivers/md/dm-thin-metadata.c
33623@@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33624
33625 pmd->info.tm = tm;
33626 pmd->info.levels = 2;
33627- pmd->info.value_type.context = pmd->data_sm;
33628+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33629 pmd->info.value_type.size = sizeof(__le64);
33630 pmd->info.value_type.inc = data_block_inc;
33631 pmd->info.value_type.dec = data_block_dec;
33632@@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33633
33634 pmd->bl_info.tm = tm;
33635 pmd->bl_info.levels = 1;
33636- pmd->bl_info.value_type.context = pmd->data_sm;
33637+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33638 pmd->bl_info.value_type.size = sizeof(__le64);
33639 pmd->bl_info.value_type.inc = data_block_inc;
33640 pmd->bl_info.value_type.dec = data_block_dec;
33641diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33642index b89c548..2af3ce4 100644
33643--- a/drivers/md/dm.c
33644+++ b/drivers/md/dm.c
33645@@ -176,9 +176,9 @@ struct mapped_device {
33646 /*
33647 * Event handling.
33648 */
33649- atomic_t event_nr;
33650+ atomic_unchecked_t event_nr;
33651 wait_queue_head_t eventq;
33652- atomic_t uevent_seq;
33653+ atomic_unchecked_t uevent_seq;
33654 struct list_head uevent_list;
33655 spinlock_t uevent_lock; /* Protect access to uevent_list */
33656
33657@@ -1844,8 +1844,8 @@ static struct mapped_device *alloc_dev(int minor)
33658 rwlock_init(&md->map_lock);
33659 atomic_set(&md->holders, 1);
33660 atomic_set(&md->open_count, 0);
33661- atomic_set(&md->event_nr, 0);
33662- atomic_set(&md->uevent_seq, 0);
33663+ atomic_set_unchecked(&md->event_nr, 0);
33664+ atomic_set_unchecked(&md->uevent_seq, 0);
33665 INIT_LIST_HEAD(&md->uevent_list);
33666 spin_lock_init(&md->uevent_lock);
33667
33668@@ -1979,7 +1979,7 @@ static void event_callback(void *context)
33669
33670 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33671
33672- atomic_inc(&md->event_nr);
33673+ atomic_inc_unchecked(&md->event_nr);
33674 wake_up(&md->eventq);
33675 }
33676
33677@@ -2621,18 +2621,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33678
33679 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33680 {
33681- return atomic_add_return(1, &md->uevent_seq);
33682+ return atomic_add_return_unchecked(1, &md->uevent_seq);
33683 }
33684
33685 uint32_t dm_get_event_nr(struct mapped_device *md)
33686 {
33687- return atomic_read(&md->event_nr);
33688+ return atomic_read_unchecked(&md->event_nr);
33689 }
33690
33691 int dm_wait_event(struct mapped_device *md, int event_nr)
33692 {
33693 return wait_event_interruptible(md->eventq,
33694- (event_nr != atomic_read(&md->event_nr)));
33695+ (event_nr != atomic_read_unchecked(&md->event_nr)));
33696 }
33697
33698 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33699diff --git a/drivers/md/md.c b/drivers/md/md.c
33700index 363aaf4..d875264 100644
33701--- a/drivers/md/md.c
33702+++ b/drivers/md/md.c
33703@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33704 * start build, activate spare
33705 */
33706 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33707-static atomic_t md_event_count;
33708+static atomic_unchecked_t md_event_count;
33709 void md_new_event(struct mddev *mddev)
33710 {
33711- atomic_inc(&md_event_count);
33712+ atomic_inc_unchecked(&md_event_count);
33713 wake_up(&md_event_waiters);
33714 }
33715 EXPORT_SYMBOL_GPL(md_new_event);
33716@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33717 */
33718 static void md_new_event_inintr(struct mddev *mddev)
33719 {
33720- atomic_inc(&md_event_count);
33721+ atomic_inc_unchecked(&md_event_count);
33722 wake_up(&md_event_waiters);
33723 }
33724
33725@@ -1526,7 +1526,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33726
33727 rdev->preferred_minor = 0xffff;
33728 rdev->data_offset = le64_to_cpu(sb->data_offset);
33729- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33730+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33731
33732 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33733 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33734@@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33735 else
33736 sb->resync_offset = cpu_to_le64(0);
33737
33738- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33739+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33740
33741 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33742 sb->size = cpu_to_le64(mddev->dev_sectors);
33743@@ -2691,7 +2691,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33744 static ssize_t
33745 errors_show(struct md_rdev *rdev, char *page)
33746 {
33747- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33748+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33749 }
33750
33751 static ssize_t
33752@@ -2700,7 +2700,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33753 char *e;
33754 unsigned long n = simple_strtoul(buf, &e, 10);
33755 if (*buf && (*e == 0 || *e == '\n')) {
33756- atomic_set(&rdev->corrected_errors, n);
33757+ atomic_set_unchecked(&rdev->corrected_errors, n);
33758 return len;
33759 }
33760 return -EINVAL;
33761@@ -3086,8 +3086,8 @@ int md_rdev_init(struct md_rdev *rdev)
33762 rdev->sb_loaded = 0;
33763 rdev->bb_page = NULL;
33764 atomic_set(&rdev->nr_pending, 0);
33765- atomic_set(&rdev->read_errors, 0);
33766- atomic_set(&rdev->corrected_errors, 0);
33767+ atomic_set_unchecked(&rdev->read_errors, 0);
33768+ atomic_set_unchecked(&rdev->corrected_errors, 0);
33769
33770 INIT_LIST_HEAD(&rdev->same_set);
33771 init_waitqueue_head(&rdev->blocked_wait);
33772@@ -6738,7 +6738,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33773
33774 spin_unlock(&pers_lock);
33775 seq_printf(seq, "\n");
33776- seq->poll_event = atomic_read(&md_event_count);
33777+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33778 return 0;
33779 }
33780 if (v == (void*)2) {
33781@@ -6830,7 +6830,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33782 chunk_kb ? "KB" : "B");
33783 if (bitmap->file) {
33784 seq_printf(seq, ", file: ");
33785- seq_path(seq, &bitmap->file->f_path, " \t\n");
33786+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33787 }
33788
33789 seq_printf(seq, "\n");
33790@@ -6861,7 +6861,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33791 return error;
33792
33793 seq = file->private_data;
33794- seq->poll_event = atomic_read(&md_event_count);
33795+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33796 return error;
33797 }
33798
33799@@ -6875,7 +6875,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33800 /* always allow read */
33801 mask = POLLIN | POLLRDNORM;
33802
33803- if (seq->poll_event != atomic_read(&md_event_count))
33804+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33805 mask |= POLLERR | POLLPRI;
33806 return mask;
33807 }
33808@@ -6919,7 +6919,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33809 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33810 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33811 (int)part_stat_read(&disk->part0, sectors[1]) -
33812- atomic_read(&disk->sync_io);
33813+ atomic_read_unchecked(&disk->sync_io);
33814 /* sync IO will cause sync_io to increase before the disk_stats
33815 * as sync_io is counted when a request starts, and
33816 * disk_stats is counted when it completes.
33817diff --git a/drivers/md/md.h b/drivers/md/md.h
33818index 44c63df..b795d1a 100644
33819--- a/drivers/md/md.h
33820+++ b/drivers/md/md.h
33821@@ -93,13 +93,13 @@ struct md_rdev {
33822 * only maintained for arrays that
33823 * support hot removal
33824 */
33825- atomic_t read_errors; /* number of consecutive read errors that
33826+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
33827 * we have tried to ignore.
33828 */
33829 struct timespec last_read_error; /* monotonic time since our
33830 * last read error
33831 */
33832- atomic_t corrected_errors; /* number of corrected read errors,
33833+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33834 * for reporting to userspace and storing
33835 * in superblock.
33836 */
33837@@ -421,7 +421,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33838
33839 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33840 {
33841- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33842+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33843 }
33844
33845 struct md_personality
33846diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33847index 50ed53b..4f29d7d 100644
33848--- a/drivers/md/persistent-data/dm-space-map-checker.c
33849+++ b/drivers/md/persistent-data/dm-space-map-checker.c
33850@@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
33851 /*----------------------------------------------------------------*/
33852
33853 struct sm_checker {
33854- struct dm_space_map sm;
33855+ dm_space_map_no_const sm;
33856
33857 struct count_array old_counts;
33858 struct count_array counts;
33859diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33860index fc469ba..2d91555 100644
33861--- a/drivers/md/persistent-data/dm-space-map-disk.c
33862+++ b/drivers/md/persistent-data/dm-space-map-disk.c
33863@@ -23,7 +23,7 @@
33864 * Space map interface.
33865 */
33866 struct sm_disk {
33867- struct dm_space_map sm;
33868+ dm_space_map_no_const sm;
33869
33870 struct ll_disk ll;
33871 struct ll_disk old_ll;
33872diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33873index e89ae5e..062e4c2 100644
33874--- a/drivers/md/persistent-data/dm-space-map-metadata.c
33875+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33876@@ -43,7 +43,7 @@ struct block_op {
33877 };
33878
33879 struct sm_metadata {
33880- struct dm_space_map sm;
33881+ dm_space_map_no_const sm;
33882
33883 struct ll_disk ll;
33884 struct ll_disk old_ll;
33885diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33886index 1cbfc6b..56e1dbb 100644
33887--- a/drivers/md/persistent-data/dm-space-map.h
33888+++ b/drivers/md/persistent-data/dm-space-map.h
33889@@ -60,6 +60,7 @@ struct dm_space_map {
33890 int (*root_size)(struct dm_space_map *sm, size_t *result);
33891 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33892 };
33893+typedef struct dm_space_map __no_const dm_space_map_no_const;
33894
33895 /*----------------------------------------------------------------*/
33896
33897diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33898index edc735a..e9b97f1 100644
33899--- a/drivers/md/raid1.c
33900+++ b/drivers/md/raid1.c
33901@@ -1645,7 +1645,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33902 if (r1_sync_page_io(rdev, sect, s,
33903 bio->bi_io_vec[idx].bv_page,
33904 READ) != 0)
33905- atomic_add(s, &rdev->corrected_errors);
33906+ atomic_add_unchecked(s, &rdev->corrected_errors);
33907 }
33908 sectors -= s;
33909 sect += s;
33910@@ -1859,7 +1859,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33911 test_bit(In_sync, &rdev->flags)) {
33912 if (r1_sync_page_io(rdev, sect, s,
33913 conf->tmppage, READ)) {
33914- atomic_add(s, &rdev->corrected_errors);
33915+ atomic_add_unchecked(s, &rdev->corrected_errors);
33916 printk(KERN_INFO
33917 "md/raid1:%s: read error corrected "
33918 "(%d sectors at %llu on %s)\n",
33919diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33920index 1898389..a3aa617 100644
33921--- a/drivers/md/raid10.c
33922+++ b/drivers/md/raid10.c
33923@@ -1636,7 +1636,7 @@ static void end_sync_read(struct bio *bio, int error)
33924 /* The write handler will notice the lack of
33925 * R10BIO_Uptodate and record any errors etc
33926 */
33927- atomic_add(r10_bio->sectors,
33928+ atomic_add_unchecked(r10_bio->sectors,
33929 &conf->mirrors[d].rdev->corrected_errors);
33930
33931 /* for reconstruct, we always reschedule after a read.
33932@@ -1987,7 +1987,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33933 {
33934 struct timespec cur_time_mon;
33935 unsigned long hours_since_last;
33936- unsigned int read_errors = atomic_read(&rdev->read_errors);
33937+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33938
33939 ktime_get_ts(&cur_time_mon);
33940
33941@@ -2009,9 +2009,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33942 * overflowing the shift of read_errors by hours_since_last.
33943 */
33944 if (hours_since_last >= 8 * sizeof(read_errors))
33945- atomic_set(&rdev->read_errors, 0);
33946+ atomic_set_unchecked(&rdev->read_errors, 0);
33947 else
33948- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33949+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33950 }
33951
33952 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33953@@ -2065,8 +2065,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33954 return;
33955
33956 check_decay_read_errors(mddev, rdev);
33957- atomic_inc(&rdev->read_errors);
33958- if (atomic_read(&rdev->read_errors) > max_read_errors) {
33959+ atomic_inc_unchecked(&rdev->read_errors);
33960+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33961 char b[BDEVNAME_SIZE];
33962 bdevname(rdev->bdev, b);
33963
33964@@ -2074,7 +2074,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33965 "md/raid10:%s: %s: Raid device exceeded "
33966 "read_error threshold [cur %d:max %d]\n",
33967 mdname(mddev), b,
33968- atomic_read(&rdev->read_errors), max_read_errors);
33969+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33970 printk(KERN_NOTICE
33971 "md/raid10:%s: %s: Failing raid device\n",
33972 mdname(mddev), b);
33973@@ -2223,7 +2223,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33974 (unsigned long long)(
33975 sect + rdev->data_offset),
33976 bdevname(rdev->bdev, b));
33977- atomic_add(s, &rdev->corrected_errors);
33978+ atomic_add_unchecked(s, &rdev->corrected_errors);
33979 }
33980
33981 rdev_dec_pending(rdev, mddev);
33982diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33983index d1162e5..c7cd902 100644
33984--- a/drivers/md/raid5.c
33985+++ b/drivers/md/raid5.c
33986@@ -1687,18 +1687,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
33987 (unsigned long long)(sh->sector
33988 + rdev->data_offset),
33989 bdevname(rdev->bdev, b));
33990- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33991+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33992 clear_bit(R5_ReadError, &sh->dev[i].flags);
33993 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33994 }
33995- if (atomic_read(&rdev->read_errors))
33996- atomic_set(&rdev->read_errors, 0);
33997+ if (atomic_read_unchecked(&rdev->read_errors))
33998+ atomic_set_unchecked(&rdev->read_errors, 0);
33999 } else {
34000 const char *bdn = bdevname(rdev->bdev, b);
34001 int retry = 0;
34002
34003 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
34004- atomic_inc(&rdev->read_errors);
34005+ atomic_inc_unchecked(&rdev->read_errors);
34006 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
34007 printk_ratelimited(
34008 KERN_WARNING
34009@@ -1727,7 +1727,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
34010 (unsigned long long)(sh->sector
34011 + rdev->data_offset),
34012 bdn);
34013- else if (atomic_read(&rdev->read_errors)
34014+ else if (atomic_read_unchecked(&rdev->read_errors)
34015 > conf->max_nr_stripes)
34016 printk(KERN_WARNING
34017 "md/raid:%s: Too many read errors, failing device %s.\n",
34018diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
34019index ce4f858..7bcfb46 100644
34020--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
34021+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
34022@@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
34023 .subvendor = _subvend, .subdevice = _subdev, \
34024 .driver_data = (unsigned long)&_driverdata }
34025
34026-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
34027+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
34028 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
34029 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
34030 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
34031diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
34032index a7d876f..8c21b61 100644
34033--- a/drivers/media/dvb/dvb-core/dvb_demux.h
34034+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
34035@@ -73,7 +73,7 @@ struct dvb_demux_feed {
34036 union {
34037 dmx_ts_cb ts;
34038 dmx_section_cb sec;
34039- } cb;
34040+ } __no_const cb;
34041
34042 struct dvb_demux *demux;
34043 void *priv;
34044diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
34045index 00a6732..70a682e 100644
34046--- a/drivers/media/dvb/dvb-core/dvbdev.c
34047+++ b/drivers/media/dvb/dvb-core/dvbdev.c
34048@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
34049 const struct dvb_device *template, void *priv, int type)
34050 {
34051 struct dvb_device *dvbdev;
34052- struct file_operations *dvbdevfops;
34053+ file_operations_no_const *dvbdevfops;
34054 struct device *clsdev;
34055 int minor;
34056 int id;
34057diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
34058index 3940bb0..fb3952a 100644
34059--- a/drivers/media/dvb/dvb-usb/cxusb.c
34060+++ b/drivers/media/dvb/dvb-usb/cxusb.c
34061@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
34062
34063 struct dib0700_adapter_state {
34064 int (*set_param_save) (struct dvb_frontend *);
34065-};
34066+} __no_const;
34067
34068 static int dib7070_set_param_override(struct dvb_frontend *fe)
34069 {
34070diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
34071index 451c5a7..649f711 100644
34072--- a/drivers/media/dvb/dvb-usb/dw2102.c
34073+++ b/drivers/media/dvb/dvb-usb/dw2102.c
34074@@ -95,7 +95,7 @@ struct su3000_state {
34075
34076 struct s6x0_state {
34077 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
34078-};
34079+} __no_const;
34080
34081 /* debug */
34082 static int dvb_usb_dw2102_debug;
34083diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
34084index 404f63a..4796533 100644
34085--- a/drivers/media/dvb/frontends/dib3000.h
34086+++ b/drivers/media/dvb/frontends/dib3000.h
34087@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
34088 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
34089 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
34090 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
34091-};
34092+} __no_const;
34093
34094 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
34095 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
34096diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
34097index 8418c02..8555013 100644
34098--- a/drivers/media/dvb/ngene/ngene-cards.c
34099+++ b/drivers/media/dvb/ngene/ngene-cards.c
34100@@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
34101
34102 /****************************************************************************/
34103
34104-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
34105+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34106 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34107 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34108 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34109diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34110index 16a089f..ab1667d 100644
34111--- a/drivers/media/radio/radio-cadet.c
34112+++ b/drivers/media/radio/radio-cadet.c
34113@@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34114 unsigned char readbuf[RDS_BUFFER];
34115 int i = 0;
34116
34117+ if (count > RDS_BUFFER)
34118+ return -EFAULT;
34119 mutex_lock(&dev->lock);
34120 if (dev->rdsstat == 0) {
34121 dev->rdsstat = 1;
34122diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34123index 9cde353..8c6a1c3 100644
34124--- a/drivers/media/video/au0828/au0828.h
34125+++ b/drivers/media/video/au0828/au0828.h
34126@@ -191,7 +191,7 @@ struct au0828_dev {
34127
34128 /* I2C */
34129 struct i2c_adapter i2c_adap;
34130- struct i2c_algorithm i2c_algo;
34131+ i2c_algorithm_no_const i2c_algo;
34132 struct i2c_client i2c_client;
34133 u32 i2c_rc;
34134
34135diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34136index 04bf662..e0ac026 100644
34137--- a/drivers/media/video/cx88/cx88-alsa.c
34138+++ b/drivers/media/video/cx88/cx88-alsa.c
34139@@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34140 * Only boards with eeprom and byte 1 at eeprom=1 have it
34141 */
34142
34143-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34144+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34145 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34146 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34147 {0, }
34148diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34149index 1fb7d5b..3901e77 100644
34150--- a/drivers/media/video/omap/omap_vout.c
34151+++ b/drivers/media/video/omap/omap_vout.c
34152@@ -64,7 +64,6 @@ enum omap_vout_channels {
34153 OMAP_VIDEO2,
34154 };
34155
34156-static struct videobuf_queue_ops video_vbq_ops;
34157 /* Variables configurable through module params*/
34158 static u32 video1_numbuffers = 3;
34159 static u32 video2_numbuffers = 3;
34160@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34161 {
34162 struct videobuf_queue *q;
34163 struct omap_vout_device *vout = NULL;
34164+ static struct videobuf_queue_ops video_vbq_ops = {
34165+ .buf_setup = omap_vout_buffer_setup,
34166+ .buf_prepare = omap_vout_buffer_prepare,
34167+ .buf_release = omap_vout_buffer_release,
34168+ .buf_queue = omap_vout_buffer_queue,
34169+ };
34170
34171 vout = video_drvdata(file);
34172 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34173@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34174 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34175
34176 q = &vout->vbq;
34177- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34178- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34179- video_vbq_ops.buf_release = omap_vout_buffer_release;
34180- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34181 spin_lock_init(&vout->vbq_lock);
34182
34183 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34184diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34185index 305e6aa..0143317 100644
34186--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34187+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34188@@ -196,7 +196,7 @@ struct pvr2_hdw {
34189
34190 /* I2C stuff */
34191 struct i2c_adapter i2c_adap;
34192- struct i2c_algorithm i2c_algo;
34193+ i2c_algorithm_no_const i2c_algo;
34194 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34195 int i2c_cx25840_hack_state;
34196 int i2c_linked;
34197diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34198index 4ed1c7c2..8f15e13 100644
34199--- a/drivers/media/video/timblogiw.c
34200+++ b/drivers/media/video/timblogiw.c
34201@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34202
34203 /* Platform device functions */
34204
34205-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34206+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34207 .vidioc_querycap = timblogiw_querycap,
34208 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34209 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34210@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34211 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34212 };
34213
34214-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34215+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34216 .owner = THIS_MODULE,
34217 .open = timblogiw_open,
34218 .release = timblogiw_close,
34219diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34220index a7dc467..a55c423 100644
34221--- a/drivers/message/fusion/mptbase.c
34222+++ b/drivers/message/fusion/mptbase.c
34223@@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34224 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34225 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34226
34227+#ifdef CONFIG_GRKERNSEC_HIDESYM
34228+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34229+#else
34230 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34231 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34232+#endif
34233+
34234 /*
34235 * Rounding UP to nearest 4-kB boundary here...
34236 */
34237diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34238index 551262e..7551198 100644
34239--- a/drivers/message/fusion/mptsas.c
34240+++ b/drivers/message/fusion/mptsas.c
34241@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34242 return 0;
34243 }
34244
34245+static inline void
34246+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34247+{
34248+ if (phy_info->port_details) {
34249+ phy_info->port_details->rphy = rphy;
34250+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34251+ ioc->name, rphy));
34252+ }
34253+
34254+ if (rphy) {
34255+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34256+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34257+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34258+ ioc->name, rphy, rphy->dev.release));
34259+ }
34260+}
34261+
34262 /* no mutex */
34263 static void
34264 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34265@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34266 return NULL;
34267 }
34268
34269-static inline void
34270-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34271-{
34272- if (phy_info->port_details) {
34273- phy_info->port_details->rphy = rphy;
34274- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34275- ioc->name, rphy));
34276- }
34277-
34278- if (rphy) {
34279- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34280- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34281- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34282- ioc->name, rphy, rphy->dev.release));
34283- }
34284-}
34285-
34286 static inline struct sas_port *
34287 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34288 {
34289diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34290index 0c3ced7..1fe34ec 100644
34291--- a/drivers/message/fusion/mptscsih.c
34292+++ b/drivers/message/fusion/mptscsih.c
34293@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34294
34295 h = shost_priv(SChost);
34296
34297- if (h) {
34298- if (h->info_kbuf == NULL)
34299- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34300- return h->info_kbuf;
34301- h->info_kbuf[0] = '\0';
34302+ if (!h)
34303+ return NULL;
34304
34305- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34306- h->info_kbuf[size-1] = '\0';
34307- }
34308+ if (h->info_kbuf == NULL)
34309+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34310+ return h->info_kbuf;
34311+ h->info_kbuf[0] = '\0';
34312+
34313+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34314+ h->info_kbuf[size-1] = '\0';
34315
34316 return h->info_kbuf;
34317 }
34318diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34319index 6d115c7..58ff7fd 100644
34320--- a/drivers/message/i2o/i2o_proc.c
34321+++ b/drivers/message/i2o/i2o_proc.c
34322@@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34323 "Array Controller Device"
34324 };
34325
34326-static char *chtostr(u8 * chars, int n)
34327-{
34328- char tmp[256];
34329- tmp[0] = 0;
34330- return strncat(tmp, (char *)chars, n);
34331-}
34332-
34333 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34334 char *group)
34335 {
34336@@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34337
34338 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34339 seq_printf(seq, "%-#8x", ddm_table.module_id);
34340- seq_printf(seq, "%-29s",
34341- chtostr(ddm_table.module_name_version, 28));
34342+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34343 seq_printf(seq, "%9d ", ddm_table.data_size);
34344 seq_printf(seq, "%8d", ddm_table.code_size);
34345
34346@@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34347
34348 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34349 seq_printf(seq, "%-#8x", dst->module_id);
34350- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34351- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34352+ seq_printf(seq, "%-.28s", dst->module_name_version);
34353+ seq_printf(seq, "%-.8s", dst->date);
34354 seq_printf(seq, "%8d ", dst->module_size);
34355 seq_printf(seq, "%8d ", dst->mpb_size);
34356 seq_printf(seq, "0x%04x", dst->module_flags);
34357@@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34358 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34359 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34360 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34361- seq_printf(seq, "Vendor info : %s\n",
34362- chtostr((u8 *) (work32 + 2), 16));
34363- seq_printf(seq, "Product info : %s\n",
34364- chtostr((u8 *) (work32 + 6), 16));
34365- seq_printf(seq, "Description : %s\n",
34366- chtostr((u8 *) (work32 + 10), 16));
34367- seq_printf(seq, "Product rev. : %s\n",
34368- chtostr((u8 *) (work32 + 14), 8));
34369+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34370+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34371+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34372+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34373
34374 seq_printf(seq, "Serial number : ");
34375 print_serial_number(seq, (u8 *) (work32 + 16),
34376@@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34377 }
34378
34379 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34380- seq_printf(seq, "Module name : %s\n",
34381- chtostr(result.module_name, 24));
34382- seq_printf(seq, "Module revision : %s\n",
34383- chtostr(result.module_rev, 8));
34384+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
34385+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34386
34387 seq_printf(seq, "Serial number : ");
34388 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34389@@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34390 return 0;
34391 }
34392
34393- seq_printf(seq, "Device name : %s\n",
34394- chtostr(result.device_name, 64));
34395- seq_printf(seq, "Service name : %s\n",
34396- chtostr(result.service_name, 64));
34397- seq_printf(seq, "Physical name : %s\n",
34398- chtostr(result.physical_location, 64));
34399- seq_printf(seq, "Instance number : %s\n",
34400- chtostr(result.instance_number, 4));
34401+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
34402+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
34403+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34404+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34405
34406 return 0;
34407 }
34408diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34409index a8c08f3..155fe3d 100644
34410--- a/drivers/message/i2o/iop.c
34411+++ b/drivers/message/i2o/iop.c
34412@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34413
34414 spin_lock_irqsave(&c->context_list_lock, flags);
34415
34416- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34417- atomic_inc(&c->context_list_counter);
34418+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34419+ atomic_inc_unchecked(&c->context_list_counter);
34420
34421- entry->context = atomic_read(&c->context_list_counter);
34422+ entry->context = atomic_read_unchecked(&c->context_list_counter);
34423
34424 list_add(&entry->list, &c->context_list);
34425
34426@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34427
34428 #if BITS_PER_LONG == 64
34429 spin_lock_init(&c->context_list_lock);
34430- atomic_set(&c->context_list_counter, 0);
34431+ atomic_set_unchecked(&c->context_list_counter, 0);
34432 INIT_LIST_HEAD(&c->context_list);
34433 #endif
34434
34435diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34436index 7ce65f4..e66e9bc 100644
34437--- a/drivers/mfd/abx500-core.c
34438+++ b/drivers/mfd/abx500-core.c
34439@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34440
34441 struct abx500_device_entry {
34442 struct list_head list;
34443- struct abx500_ops ops;
34444+ abx500_ops_no_const ops;
34445 struct device *dev;
34446 };
34447
34448diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34449index a9223ed..4127b13 100644
34450--- a/drivers/mfd/janz-cmodio.c
34451+++ b/drivers/mfd/janz-cmodio.c
34452@@ -13,6 +13,7 @@
34453
34454 #include <linux/kernel.h>
34455 #include <linux/module.h>
34456+#include <linux/slab.h>
34457 #include <linux/init.h>
34458 #include <linux/pci.h>
34459 #include <linux/interrupt.h>
34460diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34461index a981e2a..5ca0c8b 100644
34462--- a/drivers/misc/lis3lv02d/lis3lv02d.c
34463+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34464@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34465 * the lid is closed. This leads to interrupts as soon as a little move
34466 * is done.
34467 */
34468- atomic_inc(&lis3->count);
34469+ atomic_inc_unchecked(&lis3->count);
34470
34471 wake_up_interruptible(&lis3->misc_wait);
34472 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34473@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34474 if (lis3->pm_dev)
34475 pm_runtime_get_sync(lis3->pm_dev);
34476
34477- atomic_set(&lis3->count, 0);
34478+ atomic_set_unchecked(&lis3->count, 0);
34479 return 0;
34480 }
34481
34482@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34483 add_wait_queue(&lis3->misc_wait, &wait);
34484 while (true) {
34485 set_current_state(TASK_INTERRUPTIBLE);
34486- data = atomic_xchg(&lis3->count, 0);
34487+ data = atomic_xchg_unchecked(&lis3->count, 0);
34488 if (data)
34489 break;
34490
34491@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34492 struct lis3lv02d, miscdev);
34493
34494 poll_wait(file, &lis3->misc_wait, wait);
34495- if (atomic_read(&lis3->count))
34496+ if (atomic_read_unchecked(&lis3->count))
34497 return POLLIN | POLLRDNORM;
34498 return 0;
34499 }
34500diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34501index 2b1482a..5d33616 100644
34502--- a/drivers/misc/lis3lv02d/lis3lv02d.h
34503+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34504@@ -266,7 +266,7 @@ struct lis3lv02d {
34505 struct input_polled_dev *idev; /* input device */
34506 struct platform_device *pdev; /* platform device */
34507 struct regulator_bulk_data regulators[2];
34508- atomic_t count; /* interrupt count after last read */
34509+ atomic_unchecked_t count; /* interrupt count after last read */
34510 union axis_conversion ac; /* hw -> logical axis */
34511 int mapped_btns[3];
34512
34513diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34514index 2f30bad..c4c13d0 100644
34515--- a/drivers/misc/sgi-gru/gruhandles.c
34516+++ b/drivers/misc/sgi-gru/gruhandles.c
34517@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34518 unsigned long nsec;
34519
34520 nsec = CLKS2NSEC(clks);
34521- atomic_long_inc(&mcs_op_statistics[op].count);
34522- atomic_long_add(nsec, &mcs_op_statistics[op].total);
34523+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34524+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34525 if (mcs_op_statistics[op].max < nsec)
34526 mcs_op_statistics[op].max = nsec;
34527 }
34528diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34529index 950dbe9..eeef0f8 100644
34530--- a/drivers/misc/sgi-gru/gruprocfs.c
34531+++ b/drivers/misc/sgi-gru/gruprocfs.c
34532@@ -32,9 +32,9 @@
34533
34534 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34535
34536-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34537+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34538 {
34539- unsigned long val = atomic_long_read(v);
34540+ unsigned long val = atomic_long_read_unchecked(v);
34541
34542 seq_printf(s, "%16lu %s\n", val, id);
34543 }
34544@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34545
34546 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34547 for (op = 0; op < mcsop_last; op++) {
34548- count = atomic_long_read(&mcs_op_statistics[op].count);
34549- total = atomic_long_read(&mcs_op_statistics[op].total);
34550+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34551+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34552 max = mcs_op_statistics[op].max;
34553 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34554 count ? total / count : 0, max);
34555diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34556index 5c3ce24..4915ccb 100644
34557--- a/drivers/misc/sgi-gru/grutables.h
34558+++ b/drivers/misc/sgi-gru/grutables.h
34559@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34560 * GRU statistics.
34561 */
34562 struct gru_stats_s {
34563- atomic_long_t vdata_alloc;
34564- atomic_long_t vdata_free;
34565- atomic_long_t gts_alloc;
34566- atomic_long_t gts_free;
34567- atomic_long_t gms_alloc;
34568- atomic_long_t gms_free;
34569- atomic_long_t gts_double_allocate;
34570- atomic_long_t assign_context;
34571- atomic_long_t assign_context_failed;
34572- atomic_long_t free_context;
34573- atomic_long_t load_user_context;
34574- atomic_long_t load_kernel_context;
34575- atomic_long_t lock_kernel_context;
34576- atomic_long_t unlock_kernel_context;
34577- atomic_long_t steal_user_context;
34578- atomic_long_t steal_kernel_context;
34579- atomic_long_t steal_context_failed;
34580- atomic_long_t nopfn;
34581- atomic_long_t asid_new;
34582- atomic_long_t asid_next;
34583- atomic_long_t asid_wrap;
34584- atomic_long_t asid_reuse;
34585- atomic_long_t intr;
34586- atomic_long_t intr_cbr;
34587- atomic_long_t intr_tfh;
34588- atomic_long_t intr_spurious;
34589- atomic_long_t intr_mm_lock_failed;
34590- atomic_long_t call_os;
34591- atomic_long_t call_os_wait_queue;
34592- atomic_long_t user_flush_tlb;
34593- atomic_long_t user_unload_context;
34594- atomic_long_t user_exception;
34595- atomic_long_t set_context_option;
34596- atomic_long_t check_context_retarget_intr;
34597- atomic_long_t check_context_unload;
34598- atomic_long_t tlb_dropin;
34599- atomic_long_t tlb_preload_page;
34600- atomic_long_t tlb_dropin_fail_no_asid;
34601- atomic_long_t tlb_dropin_fail_upm;
34602- atomic_long_t tlb_dropin_fail_invalid;
34603- atomic_long_t tlb_dropin_fail_range_active;
34604- atomic_long_t tlb_dropin_fail_idle;
34605- atomic_long_t tlb_dropin_fail_fmm;
34606- atomic_long_t tlb_dropin_fail_no_exception;
34607- atomic_long_t tfh_stale_on_fault;
34608- atomic_long_t mmu_invalidate_range;
34609- atomic_long_t mmu_invalidate_page;
34610- atomic_long_t flush_tlb;
34611- atomic_long_t flush_tlb_gru;
34612- atomic_long_t flush_tlb_gru_tgh;
34613- atomic_long_t flush_tlb_gru_zero_asid;
34614+ atomic_long_unchecked_t vdata_alloc;
34615+ atomic_long_unchecked_t vdata_free;
34616+ atomic_long_unchecked_t gts_alloc;
34617+ atomic_long_unchecked_t gts_free;
34618+ atomic_long_unchecked_t gms_alloc;
34619+ atomic_long_unchecked_t gms_free;
34620+ atomic_long_unchecked_t gts_double_allocate;
34621+ atomic_long_unchecked_t assign_context;
34622+ atomic_long_unchecked_t assign_context_failed;
34623+ atomic_long_unchecked_t free_context;
34624+ atomic_long_unchecked_t load_user_context;
34625+ atomic_long_unchecked_t load_kernel_context;
34626+ atomic_long_unchecked_t lock_kernel_context;
34627+ atomic_long_unchecked_t unlock_kernel_context;
34628+ atomic_long_unchecked_t steal_user_context;
34629+ atomic_long_unchecked_t steal_kernel_context;
34630+ atomic_long_unchecked_t steal_context_failed;
34631+ atomic_long_unchecked_t nopfn;
34632+ atomic_long_unchecked_t asid_new;
34633+ atomic_long_unchecked_t asid_next;
34634+ atomic_long_unchecked_t asid_wrap;
34635+ atomic_long_unchecked_t asid_reuse;
34636+ atomic_long_unchecked_t intr;
34637+ atomic_long_unchecked_t intr_cbr;
34638+ atomic_long_unchecked_t intr_tfh;
34639+ atomic_long_unchecked_t intr_spurious;
34640+ atomic_long_unchecked_t intr_mm_lock_failed;
34641+ atomic_long_unchecked_t call_os;
34642+ atomic_long_unchecked_t call_os_wait_queue;
34643+ atomic_long_unchecked_t user_flush_tlb;
34644+ atomic_long_unchecked_t user_unload_context;
34645+ atomic_long_unchecked_t user_exception;
34646+ atomic_long_unchecked_t set_context_option;
34647+ atomic_long_unchecked_t check_context_retarget_intr;
34648+ atomic_long_unchecked_t check_context_unload;
34649+ atomic_long_unchecked_t tlb_dropin;
34650+ atomic_long_unchecked_t tlb_preload_page;
34651+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34652+ atomic_long_unchecked_t tlb_dropin_fail_upm;
34653+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
34654+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
34655+ atomic_long_unchecked_t tlb_dropin_fail_idle;
34656+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
34657+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34658+ atomic_long_unchecked_t tfh_stale_on_fault;
34659+ atomic_long_unchecked_t mmu_invalidate_range;
34660+ atomic_long_unchecked_t mmu_invalidate_page;
34661+ atomic_long_unchecked_t flush_tlb;
34662+ atomic_long_unchecked_t flush_tlb_gru;
34663+ atomic_long_unchecked_t flush_tlb_gru_tgh;
34664+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34665
34666- atomic_long_t copy_gpa;
34667- atomic_long_t read_gpa;
34668+ atomic_long_unchecked_t copy_gpa;
34669+ atomic_long_unchecked_t read_gpa;
34670
34671- atomic_long_t mesq_receive;
34672- atomic_long_t mesq_receive_none;
34673- atomic_long_t mesq_send;
34674- atomic_long_t mesq_send_failed;
34675- atomic_long_t mesq_noop;
34676- atomic_long_t mesq_send_unexpected_error;
34677- atomic_long_t mesq_send_lb_overflow;
34678- atomic_long_t mesq_send_qlimit_reached;
34679- atomic_long_t mesq_send_amo_nacked;
34680- atomic_long_t mesq_send_put_nacked;
34681- atomic_long_t mesq_page_overflow;
34682- atomic_long_t mesq_qf_locked;
34683- atomic_long_t mesq_qf_noop_not_full;
34684- atomic_long_t mesq_qf_switch_head_failed;
34685- atomic_long_t mesq_qf_unexpected_error;
34686- atomic_long_t mesq_noop_unexpected_error;
34687- atomic_long_t mesq_noop_lb_overflow;
34688- atomic_long_t mesq_noop_qlimit_reached;
34689- atomic_long_t mesq_noop_amo_nacked;
34690- atomic_long_t mesq_noop_put_nacked;
34691- atomic_long_t mesq_noop_page_overflow;
34692+ atomic_long_unchecked_t mesq_receive;
34693+ atomic_long_unchecked_t mesq_receive_none;
34694+ atomic_long_unchecked_t mesq_send;
34695+ atomic_long_unchecked_t mesq_send_failed;
34696+ atomic_long_unchecked_t mesq_noop;
34697+ atomic_long_unchecked_t mesq_send_unexpected_error;
34698+ atomic_long_unchecked_t mesq_send_lb_overflow;
34699+ atomic_long_unchecked_t mesq_send_qlimit_reached;
34700+ atomic_long_unchecked_t mesq_send_amo_nacked;
34701+ atomic_long_unchecked_t mesq_send_put_nacked;
34702+ atomic_long_unchecked_t mesq_page_overflow;
34703+ atomic_long_unchecked_t mesq_qf_locked;
34704+ atomic_long_unchecked_t mesq_qf_noop_not_full;
34705+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
34706+ atomic_long_unchecked_t mesq_qf_unexpected_error;
34707+ atomic_long_unchecked_t mesq_noop_unexpected_error;
34708+ atomic_long_unchecked_t mesq_noop_lb_overflow;
34709+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
34710+ atomic_long_unchecked_t mesq_noop_amo_nacked;
34711+ atomic_long_unchecked_t mesq_noop_put_nacked;
34712+ atomic_long_unchecked_t mesq_noop_page_overflow;
34713
34714 };
34715
34716@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34717 tghop_invalidate, mcsop_last};
34718
34719 struct mcs_op_statistic {
34720- atomic_long_t count;
34721- atomic_long_t total;
34722+ atomic_long_unchecked_t count;
34723+ atomic_long_unchecked_t total;
34724 unsigned long max;
34725 };
34726
34727@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34728
34729 #define STAT(id) do { \
34730 if (gru_options & OPT_STATS) \
34731- atomic_long_inc(&gru_stats.id); \
34732+ atomic_long_inc_unchecked(&gru_stats.id); \
34733 } while (0)
34734
34735 #ifdef CONFIG_SGI_GRU_DEBUG
34736diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34737index 851b2f2..a4ec097 100644
34738--- a/drivers/misc/sgi-xp/xp.h
34739+++ b/drivers/misc/sgi-xp/xp.h
34740@@ -289,7 +289,7 @@ struct xpc_interface {
34741 xpc_notify_func, void *);
34742 void (*received) (short, int, void *);
34743 enum xp_retval (*partid_to_nasids) (short, void *);
34744-};
34745+} __no_const;
34746
34747 extern struct xpc_interface xpc_interface;
34748
34749diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34750index b94d5f7..7f494c5 100644
34751--- a/drivers/misc/sgi-xp/xpc.h
34752+++ b/drivers/misc/sgi-xp/xpc.h
34753@@ -835,6 +835,7 @@ struct xpc_arch_operations {
34754 void (*received_payload) (struct xpc_channel *, void *);
34755 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34756 };
34757+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34758
34759 /* struct xpc_partition act_state values (for XPC HB) */
34760
34761@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34762 /* found in xpc_main.c */
34763 extern struct device *xpc_part;
34764 extern struct device *xpc_chan;
34765-extern struct xpc_arch_operations xpc_arch_ops;
34766+extern xpc_arch_operations_no_const xpc_arch_ops;
34767 extern int xpc_disengage_timelimit;
34768 extern int xpc_disengage_timedout;
34769 extern int xpc_activate_IRQ_rcvd;
34770diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34771index 8d082b4..aa749ae 100644
34772--- a/drivers/misc/sgi-xp/xpc_main.c
34773+++ b/drivers/misc/sgi-xp/xpc_main.c
34774@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34775 .notifier_call = xpc_system_die,
34776 };
34777
34778-struct xpc_arch_operations xpc_arch_ops;
34779+xpc_arch_operations_no_const xpc_arch_ops;
34780
34781 /*
34782 * Timer function to enforce the timelimit on the partition disengage.
34783diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34784index 6ebdc40..9edf5d8 100644
34785--- a/drivers/mmc/host/sdhci-pci.c
34786+++ b/drivers/mmc/host/sdhci-pci.c
34787@@ -631,7 +631,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34788 .probe = via_probe,
34789 };
34790
34791-static const struct pci_device_id pci_ids[] __devinitdata = {
34792+static const struct pci_device_id pci_ids[] __devinitconst = {
34793 {
34794 .vendor = PCI_VENDOR_ID_RICOH,
34795 .device = PCI_DEVICE_ID_RICOH_R5C822,
34796diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34797index 87a431c..4959b43 100644
34798--- a/drivers/mtd/devices/doc2000.c
34799+++ b/drivers/mtd/devices/doc2000.c
34800@@ -764,7 +764,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34801
34802 /* The ECC will not be calculated correctly if less than 512 is written */
34803 /* DBB-
34804- if (len != 0x200 && eccbuf)
34805+ if (len != 0x200)
34806 printk(KERN_WARNING
34807 "ECC needs a full sector write (adr: %lx size %lx)\n",
34808 (long) to, (long) len);
34809diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
34810index 9eacf67..4534b5b 100644
34811--- a/drivers/mtd/devices/doc2001.c
34812+++ b/drivers/mtd/devices/doc2001.c
34813@@ -384,7 +384,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
34814 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
34815
34816 /* Don't allow read past end of device */
34817- if (from >= this->totlen)
34818+ if (from >= this->totlen || !len)
34819 return -EINVAL;
34820
34821 /* Don't allow a single read to cross a 512-byte block boundary */
34822diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34823index 3984d48..28aa897 100644
34824--- a/drivers/mtd/nand/denali.c
34825+++ b/drivers/mtd/nand/denali.c
34826@@ -26,6 +26,7 @@
34827 #include <linux/pci.h>
34828 #include <linux/mtd/mtd.h>
34829 #include <linux/module.h>
34830+#include <linux/slab.h>
34831
34832 #include "denali.h"
34833
34834diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34835index 51b9d6a..52af9a7 100644
34836--- a/drivers/mtd/nftlmount.c
34837+++ b/drivers/mtd/nftlmount.c
34838@@ -24,6 +24,7 @@
34839 #include <asm/errno.h>
34840 #include <linux/delay.h>
34841 #include <linux/slab.h>
34842+#include <linux/sched.h>
34843 #include <linux/mtd/mtd.h>
34844 #include <linux/mtd/nand.h>
34845 #include <linux/mtd/nftl.h>
34846diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34847index 071f4c8..440862e 100644
34848--- a/drivers/net/ethernet/atheros/atlx/atl2.c
34849+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34850@@ -2862,7 +2862,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34851 */
34852
34853 #define ATL2_PARAM(X, desc) \
34854- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34855+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34856 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34857 MODULE_PARM_DESC(X, desc);
34858 #else
34859diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34860index 66da39f..5dc436d 100644
34861--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34862+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34863@@ -473,7 +473,7 @@ struct bnx2x_rx_mode_obj {
34864
34865 int (*wait_comp)(struct bnx2x *bp,
34866 struct bnx2x_rx_mode_ramrod_params *p);
34867-};
34868+} __no_const;
34869
34870 /********************** Set multicast group ***********************************/
34871
34872diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34873index aea8f72..fcebf75 100644
34874--- a/drivers/net/ethernet/broadcom/tg3.h
34875+++ b/drivers/net/ethernet/broadcom/tg3.h
34876@@ -140,6 +140,7 @@
34877 #define CHIPREV_ID_5750_A0 0x4000
34878 #define CHIPREV_ID_5750_A1 0x4001
34879 #define CHIPREV_ID_5750_A3 0x4003
34880+#define CHIPREV_ID_5750_C1 0x4201
34881 #define CHIPREV_ID_5750_C2 0x4202
34882 #define CHIPREV_ID_5752_A0_HW 0x5000
34883 #define CHIPREV_ID_5752_A0 0x6000
34884diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34885index c4e8643..0979484 100644
34886--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34887+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34888@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34889 */
34890 struct l2t_skb_cb {
34891 arp_failure_handler_func arp_failure_handler;
34892-};
34893+} __no_const;
34894
34895 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34896
34897diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34898index 4d71f5a..8004440 100644
34899--- a/drivers/net/ethernet/dec/tulip/de4x5.c
34900+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34901@@ -5392,7 +5392,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34902 for (i=0; i<ETH_ALEN; i++) {
34903 tmp.addr[i] = dev->dev_addr[i];
34904 }
34905- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34906+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34907 break;
34908
34909 case DE4X5_SET_HWADDR: /* Set the hardware address */
34910@@ -5432,7 +5432,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34911 spin_lock_irqsave(&lp->lock, flags);
34912 memcpy(&statbuf, &lp->pktStats, ioc->len);
34913 spin_unlock_irqrestore(&lp->lock, flags);
34914- if (copy_to_user(ioc->data, &statbuf, ioc->len))
34915+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34916 return -EFAULT;
34917 break;
34918 }
34919diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34920index 14d5b61..1398636 100644
34921--- a/drivers/net/ethernet/dec/tulip/eeprom.c
34922+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34923@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34924 {NULL}};
34925
34926
34927-static const char *block_name[] __devinitdata = {
34928+static const char *block_name[] __devinitconst = {
34929 "21140 non-MII",
34930 "21140 MII PHY",
34931 "21142 Serial PHY",
34932diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34933index 52da7b2..4ddfe1c 100644
34934--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34935+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34936@@ -236,7 +236,7 @@ struct pci_id_info {
34937 int drv_flags; /* Driver use, intended as capability flags. */
34938 };
34939
34940-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34941+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34942 { /* Sometime a Level-One switch card. */
34943 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34944 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34945diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34946index 28a3a9b..d96cb63 100644
34947--- a/drivers/net/ethernet/dlink/sundance.c
34948+++ b/drivers/net/ethernet/dlink/sundance.c
34949@@ -218,7 +218,7 @@ enum {
34950 struct pci_id_info {
34951 const char *name;
34952 };
34953-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34954+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34955 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34956 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34957 {"D-Link DFE-580TX 4 port Server Adapter"},
34958diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34959index e703d64..d62ecf9 100644
34960--- a/drivers/net/ethernet/emulex/benet/be_main.c
34961+++ b/drivers/net/ethernet/emulex/benet/be_main.c
34962@@ -402,7 +402,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34963
34964 if (wrapped)
34965 newacc += 65536;
34966- ACCESS_ONCE(*acc) = newacc;
34967+ ACCESS_ONCE_RW(*acc) = newacc;
34968 }
34969
34970 void be_parse_stats(struct be_adapter *adapter)
34971diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34972index 47f85c3..82ab6c4 100644
34973--- a/drivers/net/ethernet/faraday/ftgmac100.c
34974+++ b/drivers/net/ethernet/faraday/ftgmac100.c
34975@@ -31,6 +31,8 @@
34976 #include <linux/netdevice.h>
34977 #include <linux/phy.h>
34978 #include <linux/platform_device.h>
34979+#include <linux/interrupt.h>
34980+#include <linux/irqreturn.h>
34981 #include <net/ip.h>
34982
34983 #include "ftgmac100.h"
34984diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34985index bb336a0..4b472da 100644
34986--- a/drivers/net/ethernet/faraday/ftmac100.c
34987+++ b/drivers/net/ethernet/faraday/ftmac100.c
34988@@ -31,6 +31,8 @@
34989 #include <linux/module.h>
34990 #include <linux/netdevice.h>
34991 #include <linux/platform_device.h>
34992+#include <linux/interrupt.h>
34993+#include <linux/irqreturn.h>
34994
34995 #include "ftmac100.h"
34996
34997diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34998index c82d444..0007fb4 100644
34999--- a/drivers/net/ethernet/fealnx.c
35000+++ b/drivers/net/ethernet/fealnx.c
35001@@ -150,7 +150,7 @@ struct chip_info {
35002 int flags;
35003 };
35004
35005-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
35006+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
35007 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35008 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
35009 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35010diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
35011index e1159e5..e18684d 100644
35012--- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
35013+++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
35014@@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
35015 {
35016 struct e1000_hw *hw = &adapter->hw;
35017 struct e1000_mac_info *mac = &hw->mac;
35018- struct e1000_mac_operations *func = &mac->ops;
35019+ e1000_mac_operations_no_const *func = &mac->ops;
35020
35021 /* Set media type */
35022 switch (adapter->pdev->device) {
35023diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
35024index a3e65fd..f451444 100644
35025--- a/drivers/net/ethernet/intel/e1000e/82571.c
35026+++ b/drivers/net/ethernet/intel/e1000e/82571.c
35027@@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
35028 {
35029 struct e1000_hw *hw = &adapter->hw;
35030 struct e1000_mac_info *mac = &hw->mac;
35031- struct e1000_mac_operations *func = &mac->ops;
35032+ e1000_mac_operations_no_const *func = &mac->ops;
35033 u32 swsm = 0;
35034 u32 swsm2 = 0;
35035 bool force_clear_smbi = false;
35036diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35037index 2967039..ca8c40c 100644
35038--- a/drivers/net/ethernet/intel/e1000e/hw.h
35039+++ b/drivers/net/ethernet/intel/e1000e/hw.h
35040@@ -778,6 +778,7 @@ struct e1000_mac_operations {
35041 void (*write_vfta)(struct e1000_hw *, u32, u32);
35042 s32 (*read_mac_addr)(struct e1000_hw *);
35043 };
35044+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35045
35046 /*
35047 * When to use various PHY register access functions:
35048@@ -818,6 +819,7 @@ struct e1000_phy_operations {
35049 void (*power_up)(struct e1000_hw *);
35050 void (*power_down)(struct e1000_hw *);
35051 };
35052+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35053
35054 /* Function pointers for the NVM. */
35055 struct e1000_nvm_operations {
35056@@ -829,9 +831,10 @@ struct e1000_nvm_operations {
35057 s32 (*validate)(struct e1000_hw *);
35058 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35059 };
35060+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35061
35062 struct e1000_mac_info {
35063- struct e1000_mac_operations ops;
35064+ e1000_mac_operations_no_const ops;
35065 u8 addr[ETH_ALEN];
35066 u8 perm_addr[ETH_ALEN];
35067
35068@@ -872,7 +875,7 @@ struct e1000_mac_info {
35069 };
35070
35071 struct e1000_phy_info {
35072- struct e1000_phy_operations ops;
35073+ e1000_phy_operations_no_const ops;
35074
35075 enum e1000_phy_type type;
35076
35077@@ -906,7 +909,7 @@ struct e1000_phy_info {
35078 };
35079
35080 struct e1000_nvm_info {
35081- struct e1000_nvm_operations ops;
35082+ e1000_nvm_operations_no_const ops;
35083
35084 enum e1000_nvm_type type;
35085 enum e1000_nvm_override override;
35086diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35087index f67cbd3..cef9e3d 100644
35088--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35089+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35090@@ -314,6 +314,7 @@ struct e1000_mac_operations {
35091 s32 (*read_mac_addr)(struct e1000_hw *);
35092 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
35093 };
35094+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35095
35096 struct e1000_phy_operations {
35097 s32 (*acquire)(struct e1000_hw *);
35098@@ -330,6 +331,7 @@ struct e1000_phy_operations {
35099 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35100 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35101 };
35102+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35103
35104 struct e1000_nvm_operations {
35105 s32 (*acquire)(struct e1000_hw *);
35106@@ -339,6 +341,7 @@ struct e1000_nvm_operations {
35107 s32 (*update)(struct e1000_hw *);
35108 s32 (*validate)(struct e1000_hw *);
35109 };
35110+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35111
35112 struct e1000_info {
35113 s32 (*get_invariants)(struct e1000_hw *);
35114@@ -350,7 +353,7 @@ struct e1000_info {
35115 extern const struct e1000_info e1000_82575_info;
35116
35117 struct e1000_mac_info {
35118- struct e1000_mac_operations ops;
35119+ e1000_mac_operations_no_const ops;
35120
35121 u8 addr[6];
35122 u8 perm_addr[6];
35123@@ -388,7 +391,7 @@ struct e1000_mac_info {
35124 };
35125
35126 struct e1000_phy_info {
35127- struct e1000_phy_operations ops;
35128+ e1000_phy_operations_no_const ops;
35129
35130 enum e1000_phy_type type;
35131
35132@@ -423,7 +426,7 @@ struct e1000_phy_info {
35133 };
35134
35135 struct e1000_nvm_info {
35136- struct e1000_nvm_operations ops;
35137+ e1000_nvm_operations_no_const ops;
35138 enum e1000_nvm_type type;
35139 enum e1000_nvm_override override;
35140
35141@@ -468,6 +471,7 @@ struct e1000_mbx_operations {
35142 s32 (*check_for_ack)(struct e1000_hw *, u16);
35143 s32 (*check_for_rst)(struct e1000_hw *, u16);
35144 };
35145+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35146
35147 struct e1000_mbx_stats {
35148 u32 msgs_tx;
35149@@ -479,7 +483,7 @@ struct e1000_mbx_stats {
35150 };
35151
35152 struct e1000_mbx_info {
35153- struct e1000_mbx_operations ops;
35154+ e1000_mbx_operations_no_const ops;
35155 struct e1000_mbx_stats stats;
35156 u32 timeout;
35157 u32 usec_delay;
35158diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35159index 57db3c6..aa825fc 100644
35160--- a/drivers/net/ethernet/intel/igbvf/vf.h
35161+++ b/drivers/net/ethernet/intel/igbvf/vf.h
35162@@ -189,9 +189,10 @@ struct e1000_mac_operations {
35163 s32 (*read_mac_addr)(struct e1000_hw *);
35164 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35165 };
35166+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35167
35168 struct e1000_mac_info {
35169- struct e1000_mac_operations ops;
35170+ e1000_mac_operations_no_const ops;
35171 u8 addr[6];
35172 u8 perm_addr[6];
35173
35174@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35175 s32 (*check_for_ack)(struct e1000_hw *);
35176 s32 (*check_for_rst)(struct e1000_hw *);
35177 };
35178+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35179
35180 struct e1000_mbx_stats {
35181 u32 msgs_tx;
35182@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35183 };
35184
35185 struct e1000_mbx_info {
35186- struct e1000_mbx_operations ops;
35187+ e1000_mbx_operations_no_const ops;
35188 struct e1000_mbx_stats stats;
35189 u32 timeout;
35190 u32 usec_delay;
35191diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35192index 9b95bef..7e254ee 100644
35193--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35194+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35195@@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
35196 s32 (*update_checksum)(struct ixgbe_hw *);
35197 u16 (*calc_checksum)(struct ixgbe_hw *);
35198 };
35199+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35200
35201 struct ixgbe_mac_operations {
35202 s32 (*init_hw)(struct ixgbe_hw *);
35203@@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
35204 /* Manageability interface */
35205 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
35206 };
35207+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35208
35209 struct ixgbe_phy_operations {
35210 s32 (*identify)(struct ixgbe_hw *);
35211@@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
35212 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35213 s32 (*check_overtemp)(struct ixgbe_hw *);
35214 };
35215+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35216
35217 struct ixgbe_eeprom_info {
35218- struct ixgbe_eeprom_operations ops;
35219+ ixgbe_eeprom_operations_no_const ops;
35220 enum ixgbe_eeprom_type type;
35221 u32 semaphore_delay;
35222 u16 word_size;
35223@@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
35224
35225 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35226 struct ixgbe_mac_info {
35227- struct ixgbe_mac_operations ops;
35228+ ixgbe_mac_operations_no_const ops;
35229 enum ixgbe_mac_type type;
35230 u8 addr[ETH_ALEN];
35231 u8 perm_addr[ETH_ALEN];
35232@@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
35233 };
35234
35235 struct ixgbe_phy_info {
35236- struct ixgbe_phy_operations ops;
35237+ ixgbe_phy_operations_no_const ops;
35238 struct mdio_if_info mdio;
35239 enum ixgbe_phy_type type;
35240 u32 id;
35241@@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
35242 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35243 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35244 };
35245+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35246
35247 struct ixgbe_mbx_stats {
35248 u32 msgs_tx;
35249@@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
35250 };
35251
35252 struct ixgbe_mbx_info {
35253- struct ixgbe_mbx_operations ops;
35254+ ixgbe_mbx_operations_no_const ops;
35255 struct ixgbe_mbx_stats stats;
35256 u32 timeout;
35257 u32 usec_delay;
35258diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35259index 25c951d..cc7cf33 100644
35260--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35261+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35262@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35263 s32 (*clear_vfta)(struct ixgbe_hw *);
35264 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35265 };
35266+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35267
35268 enum ixgbe_mac_type {
35269 ixgbe_mac_unknown = 0,
35270@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35271 };
35272
35273 struct ixgbe_mac_info {
35274- struct ixgbe_mac_operations ops;
35275+ ixgbe_mac_operations_no_const ops;
35276 u8 addr[6];
35277 u8 perm_addr[6];
35278
35279@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35280 s32 (*check_for_ack)(struct ixgbe_hw *);
35281 s32 (*check_for_rst)(struct ixgbe_hw *);
35282 };
35283+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35284
35285 struct ixgbe_mbx_stats {
35286 u32 msgs_tx;
35287@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35288 };
35289
35290 struct ixgbe_mbx_info {
35291- struct ixgbe_mbx_operations ops;
35292+ ixgbe_mbx_operations_no_const ops;
35293 struct ixgbe_mbx_stats stats;
35294 u32 timeout;
35295 u32 udelay;
35296diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35297index 8bf22b6..7f5baaa 100644
35298--- a/drivers/net/ethernet/mellanox/mlx4/main.c
35299+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35300@@ -41,6 +41,7 @@
35301 #include <linux/slab.h>
35302 #include <linux/io-mapping.h>
35303 #include <linux/delay.h>
35304+#include <linux/sched.h>
35305
35306 #include <linux/mlx4/device.h>
35307 #include <linux/mlx4/doorbell.h>
35308diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35309index 5046a64..71ca936 100644
35310--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35311+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35312@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35313 void (*link_down)(struct __vxge_hw_device *devh);
35314 void (*crit_err)(struct __vxge_hw_device *devh,
35315 enum vxge_hw_event type, u64 ext_data);
35316-};
35317+} __no_const;
35318
35319 /*
35320 * struct __vxge_hw_blockpool_entry - Block private data structure
35321diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35322index 4a518a3..936b334 100644
35323--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35324+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35325@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35326 struct vxge_hw_mempool_dma *dma_object,
35327 u32 index,
35328 u32 is_last);
35329-};
35330+} __no_const;
35331
35332 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35333 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35334diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35335index bbacb37..d60887d 100644
35336--- a/drivers/net/ethernet/realtek/r8169.c
35337+++ b/drivers/net/ethernet/realtek/r8169.c
35338@@ -695,17 +695,17 @@ struct rtl8169_private {
35339 struct mdio_ops {
35340 void (*write)(void __iomem *, int, int);
35341 int (*read)(void __iomem *, int);
35342- } mdio_ops;
35343+ } __no_const mdio_ops;
35344
35345 struct pll_power_ops {
35346 void (*down)(struct rtl8169_private *);
35347 void (*up)(struct rtl8169_private *);
35348- } pll_power_ops;
35349+ } __no_const pll_power_ops;
35350
35351 struct jumbo_ops {
35352 void (*enable)(struct rtl8169_private *);
35353 void (*disable)(struct rtl8169_private *);
35354- } jumbo_ops;
35355+ } __no_const jumbo_ops;
35356
35357 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35358 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35359diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35360index 5b118cd..858b523 100644
35361--- a/drivers/net/ethernet/sis/sis190.c
35362+++ b/drivers/net/ethernet/sis/sis190.c
35363@@ -1622,7 +1622,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35364 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35365 struct net_device *dev)
35366 {
35367- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35368+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35369 struct sis190_private *tp = netdev_priv(dev);
35370 struct pci_dev *isa_bridge;
35371 u8 reg, tmp8;
35372diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35373index c07cfe9..81cbf7e 100644
35374--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35375+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35376@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35377
35378 writel(value, ioaddr + MMC_CNTRL);
35379
35380- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35381- MMC_CNTRL, value);
35382+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35383+// MMC_CNTRL, value);
35384 }
35385
35386 /* To mask all all interrupts.*/
35387diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
35388index 6ee593a..3f513b1 100644
35389--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
35390+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
35391@@ -1585,7 +1585,7 @@ static const struct file_operations stmmac_rings_status_fops = {
35392 .open = stmmac_sysfs_ring_open,
35393 .read = seq_read,
35394 .llseek = seq_lseek,
35395- .release = seq_release,
35396+ .release = single_release,
35397 };
35398
35399 static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v)
35400@@ -1657,7 +1657,7 @@ static const struct file_operations stmmac_dma_cap_fops = {
35401 .open = stmmac_sysfs_dma_cap_open,
35402 .read = seq_read,
35403 .llseek = seq_lseek,
35404- .release = seq_release,
35405+ .release = single_release,
35406 };
35407
35408 static int stmmac_init_fs(struct net_device *dev)
35409diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35410index dec5836..6d4db7d 100644
35411--- a/drivers/net/hyperv/hyperv_net.h
35412+++ b/drivers/net/hyperv/hyperv_net.h
35413@@ -97,7 +97,7 @@ struct rndis_device {
35414
35415 enum rndis_device_state state;
35416 bool link_state;
35417- atomic_t new_req_id;
35418+ atomic_unchecked_t new_req_id;
35419
35420 spinlock_t request_lock;
35421 struct list_head req_list;
35422diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35423index 133b7fb..d58c559 100644
35424--- a/drivers/net/hyperv/rndis_filter.c
35425+++ b/drivers/net/hyperv/rndis_filter.c
35426@@ -96,7 +96,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35427 * template
35428 */
35429 set = &rndis_msg->msg.set_req;
35430- set->req_id = atomic_inc_return(&dev->new_req_id);
35431+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35432
35433 /* Add to the request list */
35434 spin_lock_irqsave(&dev->request_lock, flags);
35435@@ -627,7 +627,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35436
35437 /* Setup the rndis set */
35438 halt = &request->request_msg.msg.halt_req;
35439- halt->req_id = atomic_inc_return(&dev->new_req_id);
35440+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35441
35442 /* Ignore return since this msg is optional. */
35443 rndis_filter_send_request(dev, request);
35444diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
35445index 58dc117..f140c77 100644
35446--- a/drivers/net/macvtap.c
35447+++ b/drivers/net/macvtap.c
35448@@ -526,6 +526,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
35449 }
35450 base = (unsigned long)from->iov_base + offset1;
35451 size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
35452+ if (i + size >= MAX_SKB_FRAGS)
35453+ return -EFAULT;
35454 num_pages = get_user_pages_fast(base, size, 0, &page[i]);
35455 if ((num_pages != size) ||
35456 (num_pages > MAX_SKB_FRAGS - skb_shinfo(skb)->nr_frags))
35457diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35458index 3ed983c..a1bb418 100644
35459--- a/drivers/net/ppp/ppp_generic.c
35460+++ b/drivers/net/ppp/ppp_generic.c
35461@@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35462 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35463 struct ppp_stats stats;
35464 struct ppp_comp_stats cstats;
35465- char *vers;
35466
35467 switch (cmd) {
35468 case SIOCGPPPSTATS:
35469@@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35470 break;
35471
35472 case SIOCGPPPVER:
35473- vers = PPP_VERSION;
35474- if (copy_to_user(addr, vers, strlen(vers) + 1))
35475+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35476 break;
35477 err = 0;
35478 break;
35479diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
35480index 515f122..41dd273 100644
35481--- a/drivers/net/tokenring/abyss.c
35482+++ b/drivers/net/tokenring/abyss.c
35483@@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
35484
35485 static int __init abyss_init (void)
35486 {
35487- abyss_netdev_ops = tms380tr_netdev_ops;
35488+ pax_open_kernel();
35489+ memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35490
35491- abyss_netdev_ops.ndo_open = abyss_open;
35492- abyss_netdev_ops.ndo_stop = abyss_close;
35493+ *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35494+ *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35495+ pax_close_kernel();
35496
35497 return pci_register_driver(&abyss_driver);
35498 }
35499diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
35500index 6153cfd..cf69c1c 100644
35501--- a/drivers/net/tokenring/madgemc.c
35502+++ b/drivers/net/tokenring/madgemc.c
35503@@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
35504
35505 static int __init madgemc_init (void)
35506 {
35507- madgemc_netdev_ops = tms380tr_netdev_ops;
35508- madgemc_netdev_ops.ndo_open = madgemc_open;
35509- madgemc_netdev_ops.ndo_stop = madgemc_close;
35510+ pax_open_kernel();
35511+ memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35512+ *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35513+ *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35514+ pax_close_kernel();
35515
35516 return mca_register_driver (&madgemc_driver);
35517 }
35518diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
35519index 8d362e6..f91cc52 100644
35520--- a/drivers/net/tokenring/proteon.c
35521+++ b/drivers/net/tokenring/proteon.c
35522@@ -353,9 +353,11 @@ static int __init proteon_init(void)
35523 struct platform_device *pdev;
35524 int i, num = 0, err = 0;
35525
35526- proteon_netdev_ops = tms380tr_netdev_ops;
35527- proteon_netdev_ops.ndo_open = proteon_open;
35528- proteon_netdev_ops.ndo_stop = tms380tr_close;
35529+ pax_open_kernel();
35530+ memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35531+ *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35532+ *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35533+ pax_close_kernel();
35534
35535 err = platform_driver_register(&proteon_driver);
35536 if (err)
35537diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
35538index 46db5c5..37c1536 100644
35539--- a/drivers/net/tokenring/skisa.c
35540+++ b/drivers/net/tokenring/skisa.c
35541@@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
35542 struct platform_device *pdev;
35543 int i, num = 0, err = 0;
35544
35545- sk_isa_netdev_ops = tms380tr_netdev_ops;
35546- sk_isa_netdev_ops.ndo_open = sk_isa_open;
35547- sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35548+ pax_open_kernel();
35549+ memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35550+ *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35551+ *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35552+ pax_close_kernel();
35553
35554 err = platform_driver_register(&sk_isa_driver);
35555 if (err)
35556diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35557index e1324b4..e1b0041 100644
35558--- a/drivers/net/usb/hso.c
35559+++ b/drivers/net/usb/hso.c
35560@@ -71,7 +71,7 @@
35561 #include <asm/byteorder.h>
35562 #include <linux/serial_core.h>
35563 #include <linux/serial.h>
35564-
35565+#include <asm/local.h>
35566
35567 #define MOD_AUTHOR "Option Wireless"
35568 #define MOD_DESCRIPTION "USB High Speed Option driver"
35569@@ -257,7 +257,7 @@ struct hso_serial {
35570
35571 /* from usb_serial_port */
35572 struct tty_struct *tty;
35573- int open_count;
35574+ local_t open_count;
35575 spinlock_t serial_lock;
35576
35577 int (*write_data) (struct hso_serial *serial);
35578@@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35579 struct urb *urb;
35580
35581 urb = serial->rx_urb[0];
35582- if (serial->open_count > 0) {
35583+ if (local_read(&serial->open_count) > 0) {
35584 count = put_rxbuf_data(urb, serial);
35585 if (count == -1)
35586 return;
35587@@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35588 DUMP1(urb->transfer_buffer, urb->actual_length);
35589
35590 /* Anyone listening? */
35591- if (serial->open_count == 0)
35592+ if (local_read(&serial->open_count) == 0)
35593 return;
35594
35595 if (status == 0) {
35596@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35597 spin_unlock_irq(&serial->serial_lock);
35598
35599 /* check for port already opened, if not set the termios */
35600- serial->open_count++;
35601- if (serial->open_count == 1) {
35602+ if (local_inc_return(&serial->open_count) == 1) {
35603 serial->rx_state = RX_IDLE;
35604 /* Force default termio settings */
35605 _hso_serial_set_termios(tty, NULL);
35606@@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35607 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35608 if (result) {
35609 hso_stop_serial_device(serial->parent);
35610- serial->open_count--;
35611+ local_dec(&serial->open_count);
35612 kref_put(&serial->parent->ref, hso_serial_ref_free);
35613 }
35614 } else {
35615@@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35616
35617 /* reset the rts and dtr */
35618 /* do the actual close */
35619- serial->open_count--;
35620+ local_dec(&serial->open_count);
35621
35622- if (serial->open_count <= 0) {
35623- serial->open_count = 0;
35624+ if (local_read(&serial->open_count) <= 0) {
35625+ local_set(&serial->open_count, 0);
35626 spin_lock_irq(&serial->serial_lock);
35627 if (serial->tty == tty) {
35628 serial->tty->driver_data = NULL;
35629@@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35630
35631 /* the actual setup */
35632 spin_lock_irqsave(&serial->serial_lock, flags);
35633- if (serial->open_count)
35634+ if (local_read(&serial->open_count))
35635 _hso_serial_set_termios(tty, old);
35636 else
35637 tty->termios = old;
35638@@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
35639 D1("Pending read interrupt on port %d\n", i);
35640 spin_lock(&serial->serial_lock);
35641 if (serial->rx_state == RX_IDLE &&
35642- serial->open_count > 0) {
35643+ local_read(&serial->open_count) > 0) {
35644 /* Setup and send a ctrl req read on
35645 * port i */
35646 if (!serial->rx_urb_filled[0]) {
35647@@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
35648 /* Start all serial ports */
35649 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35650 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35651- if (dev2ser(serial_table[i])->open_count) {
35652+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
35653 result =
35654 hso_start_serial_device(serial_table[i], GFP_NOIO);
35655 hso_kick_transmit(dev2ser(serial_table[i]));
35656diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35657index efc0111..79c8f5b 100644
35658--- a/drivers/net/wireless/ath/ath.h
35659+++ b/drivers/net/wireless/ath/ath.h
35660@@ -119,6 +119,7 @@ struct ath_ops {
35661 void (*write_flush) (void *);
35662 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35663 };
35664+typedef struct ath_ops __no_const ath_ops_no_const;
35665
35666 struct ath_common;
35667 struct ath_bus_ops;
35668diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35669index 7b6417b..ab5db98 100644
35670--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35671+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35672@@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35673 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35674 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35675
35676- ACCESS_ONCE(ads->ds_link) = i->link;
35677- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35678+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
35679+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35680
35681 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35682 ctl6 = SM(i->keytype, AR_EncrType);
35683@@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35684
35685 if ((i->is_first || i->is_last) &&
35686 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35687- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35688+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35689 | set11nTries(i->rates, 1)
35690 | set11nTries(i->rates, 2)
35691 | set11nTries(i->rates, 3)
35692 | (i->dur_update ? AR_DurUpdateEna : 0)
35693 | SM(0, AR_BurstDur);
35694
35695- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35696+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35697 | set11nRate(i->rates, 1)
35698 | set11nRate(i->rates, 2)
35699 | set11nRate(i->rates, 3);
35700 } else {
35701- ACCESS_ONCE(ads->ds_ctl2) = 0;
35702- ACCESS_ONCE(ads->ds_ctl3) = 0;
35703+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35704+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35705 }
35706
35707 if (!i->is_first) {
35708- ACCESS_ONCE(ads->ds_ctl0) = 0;
35709- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35710- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35711+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35712+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35713+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35714 return;
35715 }
35716
35717@@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35718 break;
35719 }
35720
35721- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35722+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35723 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35724 | SM(i->txpower, AR_XmitPower)
35725 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35726@@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35727 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35728 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35729
35730- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35731- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35732+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35733+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35734
35735 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35736 return;
35737
35738- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35739+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35740 | set11nPktDurRTSCTS(i->rates, 1);
35741
35742- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35743+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35744 | set11nPktDurRTSCTS(i->rates, 3);
35745
35746- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35747+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35748 | set11nRateFlags(i->rates, 1)
35749 | set11nRateFlags(i->rates, 2)
35750 | set11nRateFlags(i->rates, 3)
35751diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35752index 09b8c9d..905339e 100644
35753--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35754+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35755@@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35756 (i->qcu << AR_TxQcuNum_S) | 0x17;
35757
35758 checksum += val;
35759- ACCESS_ONCE(ads->info) = val;
35760+ ACCESS_ONCE_RW(ads->info) = val;
35761
35762 checksum += i->link;
35763- ACCESS_ONCE(ads->link) = i->link;
35764+ ACCESS_ONCE_RW(ads->link) = i->link;
35765
35766 checksum += i->buf_addr[0];
35767- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35768+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35769 checksum += i->buf_addr[1];
35770- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35771+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35772 checksum += i->buf_addr[2];
35773- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35774+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35775 checksum += i->buf_addr[3];
35776- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35777+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35778
35779 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35780- ACCESS_ONCE(ads->ctl3) = val;
35781+ ACCESS_ONCE_RW(ads->ctl3) = val;
35782 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35783- ACCESS_ONCE(ads->ctl5) = val;
35784+ ACCESS_ONCE_RW(ads->ctl5) = val;
35785 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35786- ACCESS_ONCE(ads->ctl7) = val;
35787+ ACCESS_ONCE_RW(ads->ctl7) = val;
35788 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35789- ACCESS_ONCE(ads->ctl9) = val;
35790+ ACCESS_ONCE_RW(ads->ctl9) = val;
35791
35792 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35793- ACCESS_ONCE(ads->ctl10) = checksum;
35794+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
35795
35796 if (i->is_first || i->is_last) {
35797- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35798+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35799 | set11nTries(i->rates, 1)
35800 | set11nTries(i->rates, 2)
35801 | set11nTries(i->rates, 3)
35802 | (i->dur_update ? AR_DurUpdateEna : 0)
35803 | SM(0, AR_BurstDur);
35804
35805- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35806+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35807 | set11nRate(i->rates, 1)
35808 | set11nRate(i->rates, 2)
35809 | set11nRate(i->rates, 3);
35810 } else {
35811- ACCESS_ONCE(ads->ctl13) = 0;
35812- ACCESS_ONCE(ads->ctl14) = 0;
35813+ ACCESS_ONCE_RW(ads->ctl13) = 0;
35814+ ACCESS_ONCE_RW(ads->ctl14) = 0;
35815 }
35816
35817 ads->ctl20 = 0;
35818@@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35819
35820 ctl17 = SM(i->keytype, AR_EncrType);
35821 if (!i->is_first) {
35822- ACCESS_ONCE(ads->ctl11) = 0;
35823- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35824- ACCESS_ONCE(ads->ctl15) = 0;
35825- ACCESS_ONCE(ads->ctl16) = 0;
35826- ACCESS_ONCE(ads->ctl17) = ctl17;
35827- ACCESS_ONCE(ads->ctl18) = 0;
35828- ACCESS_ONCE(ads->ctl19) = 0;
35829+ ACCESS_ONCE_RW(ads->ctl11) = 0;
35830+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35831+ ACCESS_ONCE_RW(ads->ctl15) = 0;
35832+ ACCESS_ONCE_RW(ads->ctl16) = 0;
35833+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35834+ ACCESS_ONCE_RW(ads->ctl18) = 0;
35835+ ACCESS_ONCE_RW(ads->ctl19) = 0;
35836 return;
35837 }
35838
35839- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35840+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35841 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35842 | SM(i->txpower, AR_XmitPower)
35843 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35844@@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35845 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35846 ctl12 |= SM(val, AR_PAPRDChainMask);
35847
35848- ACCESS_ONCE(ads->ctl12) = ctl12;
35849- ACCESS_ONCE(ads->ctl17) = ctl17;
35850+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35851+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35852
35853- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35854+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35855 | set11nPktDurRTSCTS(i->rates, 1);
35856
35857- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35858+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35859 | set11nPktDurRTSCTS(i->rates, 3);
35860
35861- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35862+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35863 | set11nRateFlags(i->rates, 1)
35864 | set11nRateFlags(i->rates, 2)
35865 | set11nRateFlags(i->rates, 3)
35866 | SM(i->rtscts_rate, AR_RTSCTSRate);
35867
35868- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35869+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35870 }
35871
35872 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35873diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35874index c8261d4..8d88929 100644
35875--- a/drivers/net/wireless/ath/ath9k/hw.h
35876+++ b/drivers/net/wireless/ath/ath9k/hw.h
35877@@ -773,7 +773,7 @@ struct ath_hw_private_ops {
35878
35879 /* ANI */
35880 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35881-};
35882+} __no_const;
35883
35884 /**
35885 * struct ath_hw_ops - callbacks used by hardware code and driver code
35886@@ -803,7 +803,7 @@ struct ath_hw_ops {
35887 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35888 struct ath_hw_antcomb_conf *antconf);
35889
35890-};
35891+} __no_const;
35892
35893 struct ath_nf_limits {
35894 s16 max;
35895@@ -823,7 +823,7 @@ enum ath_cal_list {
35896 #define AH_FASTCC 0x4
35897
35898 struct ath_hw {
35899- struct ath_ops reg_ops;
35900+ ath_ops_no_const reg_ops;
35901
35902 struct ieee80211_hw *hw;
35903 struct ath_common common;
35904diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35905index af00e2c..ab04d34 100644
35906--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35907+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35908@@ -545,7 +545,7 @@ struct phy_func_ptr {
35909 void (*carrsuppr)(struct brcms_phy *);
35910 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35911 void (*detach)(struct brcms_phy *);
35912-};
35913+} __no_const;
35914
35915 struct brcms_phy {
35916 struct brcms_phy_pub pubpi_ro;
35917diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35918index a2ec369..36fdf14 100644
35919--- a/drivers/net/wireless/iwlegacy/3945-mac.c
35920+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35921@@ -3646,7 +3646,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35922 */
35923 if (il3945_mod_params.disable_hw_scan) {
35924 D_INFO("Disabling hw_scan\n");
35925- il3945_hw_ops.hw_scan = NULL;
35926+ pax_open_kernel();
35927+ *(void **)&il3945_hw_ops.hw_scan = NULL;
35928+ pax_close_kernel();
35929 }
35930
35931 D_INFO("*** LOAD DRIVER ***\n");
35932diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
35933index f8fc239..8cade22 100644
35934--- a/drivers/net/wireless/iwlwifi/iwl-debug.h
35935+++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
35936@@ -86,8 +86,8 @@ do { \
35937 } while (0)
35938
35939 #else
35940-#define IWL_DEBUG(m, level, fmt, args...)
35941-#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
35942+#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
35943+#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
35944 #define iwl_print_hex_dump(m, level, p, len)
35945 #define IWL_DEBUG_QUIET_RFKILL(p, fmt, args...) \
35946 do { \
35947diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35948index 4b9e730..7603659 100644
35949--- a/drivers/net/wireless/mac80211_hwsim.c
35950+++ b/drivers/net/wireless/mac80211_hwsim.c
35951@@ -1677,9 +1677,11 @@ static int __init init_mac80211_hwsim(void)
35952 return -EINVAL;
35953
35954 if (fake_hw_scan) {
35955- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35956- mac80211_hwsim_ops.sw_scan_start = NULL;
35957- mac80211_hwsim_ops.sw_scan_complete = NULL;
35958+ pax_open_kernel();
35959+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35960+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35961+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35962+ pax_close_kernel();
35963 }
35964
35965 spin_lock_init(&hwsim_radio_lock);
35966diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35967index 3186aa4..b35b09f 100644
35968--- a/drivers/net/wireless/mwifiex/main.h
35969+++ b/drivers/net/wireless/mwifiex/main.h
35970@@ -536,7 +536,7 @@ struct mwifiex_if_ops {
35971 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35972 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
35973 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35974-};
35975+} __no_const;
35976
35977 struct mwifiex_adapter {
35978 u8 iface_type;
35979diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35980index a330c69..a81540f 100644
35981--- a/drivers/net/wireless/rndis_wlan.c
35982+++ b/drivers/net/wireless/rndis_wlan.c
35983@@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35984
35985 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35986
35987- if (rts_threshold < 0 || rts_threshold > 2347)
35988+ if (rts_threshold > 2347)
35989 rts_threshold = 2347;
35990
35991 tmp = cpu_to_le32(rts_threshold);
35992diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35993index a77f1bb..c608b2b 100644
35994--- a/drivers/net/wireless/wl1251/wl1251.h
35995+++ b/drivers/net/wireless/wl1251/wl1251.h
35996@@ -266,7 +266,7 @@ struct wl1251_if_operations {
35997 void (*reset)(struct wl1251 *wl);
35998 void (*enable_irq)(struct wl1251 *wl);
35999 void (*disable_irq)(struct wl1251 *wl);
36000-};
36001+} __no_const;
36002
36003 struct wl1251 {
36004 struct ieee80211_hw *hw;
36005diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36006index f34b5b2..b5abb9f 100644
36007--- a/drivers/oprofile/buffer_sync.c
36008+++ b/drivers/oprofile/buffer_sync.c
36009@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36010 if (cookie == NO_COOKIE)
36011 offset = pc;
36012 if (cookie == INVALID_COOKIE) {
36013- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36014+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36015 offset = pc;
36016 }
36017 if (cookie != last_cookie) {
36018@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36019 /* add userspace sample */
36020
36021 if (!mm) {
36022- atomic_inc(&oprofile_stats.sample_lost_no_mm);
36023+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36024 return 0;
36025 }
36026
36027 cookie = lookup_dcookie(mm, s->eip, &offset);
36028
36029 if (cookie == INVALID_COOKIE) {
36030- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36031+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36032 return 0;
36033 }
36034
36035@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36036 /* ignore backtraces if failed to add a sample */
36037 if (state == sb_bt_start) {
36038 state = sb_bt_ignore;
36039- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36040+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36041 }
36042 }
36043 release_mm(mm);
36044diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36045index c0cc4e7..44d4e54 100644
36046--- a/drivers/oprofile/event_buffer.c
36047+++ b/drivers/oprofile/event_buffer.c
36048@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36049 }
36050
36051 if (buffer_pos == buffer_size) {
36052- atomic_inc(&oprofile_stats.event_lost_overflow);
36053+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36054 return;
36055 }
36056
36057diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36058index ed2c3ec..deda85a 100644
36059--- a/drivers/oprofile/oprof.c
36060+++ b/drivers/oprofile/oprof.c
36061@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36062 if (oprofile_ops.switch_events())
36063 return;
36064
36065- atomic_inc(&oprofile_stats.multiplex_counter);
36066+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36067 start_switch_worker();
36068 }
36069
36070diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36071index 917d28e..d62d981 100644
36072--- a/drivers/oprofile/oprofile_stats.c
36073+++ b/drivers/oprofile/oprofile_stats.c
36074@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36075 cpu_buf->sample_invalid_eip = 0;
36076 }
36077
36078- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36079- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36080- atomic_set(&oprofile_stats.event_lost_overflow, 0);
36081- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36082- atomic_set(&oprofile_stats.multiplex_counter, 0);
36083+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36084+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36085+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36086+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36087+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36088 }
36089
36090
36091diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36092index 38b6fc0..b5cbfce 100644
36093--- a/drivers/oprofile/oprofile_stats.h
36094+++ b/drivers/oprofile/oprofile_stats.h
36095@@ -13,11 +13,11 @@
36096 #include <linux/atomic.h>
36097
36098 struct oprofile_stat_struct {
36099- atomic_t sample_lost_no_mm;
36100- atomic_t sample_lost_no_mapping;
36101- atomic_t bt_lost_no_mapping;
36102- atomic_t event_lost_overflow;
36103- atomic_t multiplex_counter;
36104+ atomic_unchecked_t sample_lost_no_mm;
36105+ atomic_unchecked_t sample_lost_no_mapping;
36106+ atomic_unchecked_t bt_lost_no_mapping;
36107+ atomic_unchecked_t event_lost_overflow;
36108+ atomic_unchecked_t multiplex_counter;
36109 };
36110
36111 extern struct oprofile_stat_struct oprofile_stats;
36112diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36113index 2f0aa0f..90fab02 100644
36114--- a/drivers/oprofile/oprofilefs.c
36115+++ b/drivers/oprofile/oprofilefs.c
36116@@ -193,7 +193,7 @@ static const struct file_operations atomic_ro_fops = {
36117
36118
36119 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36120- char const *name, atomic_t *val)
36121+ char const *name, atomic_unchecked_t *val)
36122 {
36123 return __oprofilefs_create_file(sb, root, name,
36124 &atomic_ro_fops, 0444, val);
36125diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36126index 3f56bc0..707d642 100644
36127--- a/drivers/parport/procfs.c
36128+++ b/drivers/parport/procfs.c
36129@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36130
36131 *ppos += len;
36132
36133- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36134+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36135 }
36136
36137 #ifdef CONFIG_PARPORT_1284
36138@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36139
36140 *ppos += len;
36141
36142- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36143+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36144 }
36145 #endif /* IEEE1284.3 support. */
36146
36147diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36148index 9fff878..ad0ad53 100644
36149--- a/drivers/pci/hotplug/cpci_hotplug.h
36150+++ b/drivers/pci/hotplug/cpci_hotplug.h
36151@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36152 int (*hardware_test) (struct slot* slot, u32 value);
36153 u8 (*get_power) (struct slot* slot);
36154 int (*set_power) (struct slot* slot, int value);
36155-};
36156+} __no_const;
36157
36158 struct cpci_hp_controller {
36159 unsigned int irq;
36160diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36161index 76ba8a1..20ca857 100644
36162--- a/drivers/pci/hotplug/cpqphp_nvram.c
36163+++ b/drivers/pci/hotplug/cpqphp_nvram.c
36164@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36165
36166 void compaq_nvram_init (void __iomem *rom_start)
36167 {
36168+
36169+#ifndef CONFIG_PAX_KERNEXEC
36170 if (rom_start) {
36171 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36172 }
36173+#endif
36174+
36175 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36176
36177 /* initialize our int15 lock */
36178diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36179index 2275162..95f1a92 100644
36180--- a/drivers/pci/pcie/aspm.c
36181+++ b/drivers/pci/pcie/aspm.c
36182@@ -27,9 +27,9 @@
36183 #define MODULE_PARAM_PREFIX "pcie_aspm."
36184
36185 /* Note: those are not register definitions */
36186-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36187-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36188-#define ASPM_STATE_L1 (4) /* L1 state */
36189+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36190+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36191+#define ASPM_STATE_L1 (4U) /* L1 state */
36192 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36193 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36194
36195diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36196index 71eac9c..2de27ef 100644
36197--- a/drivers/pci/probe.c
36198+++ b/drivers/pci/probe.c
36199@@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36200 u32 l, sz, mask;
36201 u16 orig_cmd;
36202
36203- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36204+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36205
36206 if (!dev->mmio_always_on) {
36207 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36208diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36209index 27911b5..5b6db88 100644
36210--- a/drivers/pci/proc.c
36211+++ b/drivers/pci/proc.c
36212@@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36213 static int __init pci_proc_init(void)
36214 {
36215 struct pci_dev *dev = NULL;
36216+
36217+#ifdef CONFIG_GRKERNSEC_PROC_ADD
36218+#ifdef CONFIG_GRKERNSEC_PROC_USER
36219+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36220+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36221+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36222+#endif
36223+#else
36224 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36225+#endif
36226 proc_create("devices", 0, proc_bus_pci_dir,
36227 &proc_bus_pci_dev_operations);
36228 proc_initialized = 1;
36229diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36230index ea0c607..58c4628 100644
36231--- a/drivers/platform/x86/thinkpad_acpi.c
36232+++ b/drivers/platform/x86/thinkpad_acpi.c
36233@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
36234 return 0;
36235 }
36236
36237-void static hotkey_mask_warn_incomplete_mask(void)
36238+static void hotkey_mask_warn_incomplete_mask(void)
36239 {
36240 /* log only what the user can fix... */
36241 const u32 wantedmask = hotkey_driver_mask &
36242@@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36243 }
36244 }
36245
36246-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36247- struct tp_nvram_state *newn,
36248- const u32 event_mask)
36249-{
36250-
36251 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36252 do { \
36253 if ((event_mask & (1 << __scancode)) && \
36254@@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36255 tpacpi_hotkey_send_key(__scancode); \
36256 } while (0)
36257
36258- void issue_volchange(const unsigned int oldvol,
36259- const unsigned int newvol)
36260- {
36261- unsigned int i = oldvol;
36262+static void issue_volchange(const unsigned int oldvol,
36263+ const unsigned int newvol,
36264+ const u32 event_mask)
36265+{
36266+ unsigned int i = oldvol;
36267
36268- while (i > newvol) {
36269- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36270- i--;
36271- }
36272- while (i < newvol) {
36273- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36274- i++;
36275- }
36276+ while (i > newvol) {
36277+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36278+ i--;
36279 }
36280+ while (i < newvol) {
36281+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36282+ i++;
36283+ }
36284+}
36285
36286- void issue_brightnesschange(const unsigned int oldbrt,
36287- const unsigned int newbrt)
36288- {
36289- unsigned int i = oldbrt;
36290+static void issue_brightnesschange(const unsigned int oldbrt,
36291+ const unsigned int newbrt,
36292+ const u32 event_mask)
36293+{
36294+ unsigned int i = oldbrt;
36295
36296- while (i > newbrt) {
36297- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36298- i--;
36299- }
36300- while (i < newbrt) {
36301- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36302- i++;
36303- }
36304+ while (i > newbrt) {
36305+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36306+ i--;
36307+ }
36308+ while (i < newbrt) {
36309+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36310+ i++;
36311 }
36312+}
36313
36314+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36315+ struct tp_nvram_state *newn,
36316+ const u32 event_mask)
36317+{
36318 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36319 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36320 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36321@@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36322 oldn->volume_level != newn->volume_level) {
36323 /* recently muted, or repeated mute keypress, or
36324 * multiple presses ending in mute */
36325- issue_volchange(oldn->volume_level, newn->volume_level);
36326+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36327 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36328 }
36329 } else {
36330@@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36331 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36332 }
36333 if (oldn->volume_level != newn->volume_level) {
36334- issue_volchange(oldn->volume_level, newn->volume_level);
36335+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36336 } else if (oldn->volume_toggle != newn->volume_toggle) {
36337 /* repeated vol up/down keypress at end of scale ? */
36338 if (newn->volume_level == 0)
36339@@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36340 /* handle brightness */
36341 if (oldn->brightness_level != newn->brightness_level) {
36342 issue_brightnesschange(oldn->brightness_level,
36343- newn->brightness_level);
36344+ newn->brightness_level,
36345+ event_mask);
36346 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36347 /* repeated key presses that didn't change state */
36348 if (newn->brightness_level == 0)
36349@@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36350 && !tp_features.bright_unkfw)
36351 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36352 }
36353+}
36354
36355 #undef TPACPI_COMPARE_KEY
36356 #undef TPACPI_MAY_SEND_KEY
36357-}
36358
36359 /*
36360 * Polling driver
36361diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36362index b859d16..5cc6b1a 100644
36363--- a/drivers/pnp/pnpbios/bioscalls.c
36364+++ b/drivers/pnp/pnpbios/bioscalls.c
36365@@ -59,7 +59,7 @@ do { \
36366 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36367 } while(0)
36368
36369-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36370+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36371 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36372
36373 /*
36374@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36375
36376 cpu = get_cpu();
36377 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36378+
36379+ pax_open_kernel();
36380 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36381+ pax_close_kernel();
36382
36383 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36384 spin_lock_irqsave(&pnp_bios_lock, flags);
36385@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36386 :"memory");
36387 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36388
36389+ pax_open_kernel();
36390 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36391+ pax_close_kernel();
36392+
36393 put_cpu();
36394
36395 /* If we get here and this is set then the PnP BIOS faulted on us. */
36396@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36397 return status;
36398 }
36399
36400-void pnpbios_calls_init(union pnp_bios_install_struct *header)
36401+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36402 {
36403 int i;
36404
36405@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36406 pnp_bios_callpoint.offset = header->fields.pm16offset;
36407 pnp_bios_callpoint.segment = PNP_CS16;
36408
36409+ pax_open_kernel();
36410+
36411 for_each_possible_cpu(i) {
36412 struct desc_struct *gdt = get_cpu_gdt_table(i);
36413 if (!gdt)
36414@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36415 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36416 (unsigned long)__va(header->fields.pm16dseg));
36417 }
36418+
36419+ pax_close_kernel();
36420 }
36421diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36422index b0ecacb..7c9da2e 100644
36423--- a/drivers/pnp/resource.c
36424+++ b/drivers/pnp/resource.c
36425@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36426 return 1;
36427
36428 /* check if the resource is valid */
36429- if (*irq < 0 || *irq > 15)
36430+ if (*irq > 15)
36431 return 0;
36432
36433 /* check if the resource is reserved */
36434@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36435 return 1;
36436
36437 /* check if the resource is valid */
36438- if (*dma < 0 || *dma == 4 || *dma > 7)
36439+ if (*dma == 4 || *dma > 7)
36440 return 0;
36441
36442 /* check if the resource is reserved */
36443diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36444index 1ed6ea0..77c0bd2 100644
36445--- a/drivers/power/bq27x00_battery.c
36446+++ b/drivers/power/bq27x00_battery.c
36447@@ -72,7 +72,7 @@
36448 struct bq27x00_device_info;
36449 struct bq27x00_access_methods {
36450 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36451-};
36452+} __no_const;
36453
36454 enum bq27x00_chip { BQ27000, BQ27500 };
36455
36456diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36457index a838e66..a9e1665 100644
36458--- a/drivers/regulator/max8660.c
36459+++ b/drivers/regulator/max8660.c
36460@@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36461 max8660->shadow_regs[MAX8660_OVER1] = 5;
36462 } else {
36463 /* Otherwise devices can be toggled via software */
36464- max8660_dcdc_ops.enable = max8660_dcdc_enable;
36465- max8660_dcdc_ops.disable = max8660_dcdc_disable;
36466+ pax_open_kernel();
36467+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36468+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36469+ pax_close_kernel();
36470 }
36471
36472 /*
36473diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36474index e8cfc99..072aee2 100644
36475--- a/drivers/regulator/mc13892-regulator.c
36476+++ b/drivers/regulator/mc13892-regulator.c
36477@@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36478 }
36479 mc13xxx_unlock(mc13892);
36480
36481- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36482+ pax_open_kernel();
36483+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36484 = mc13892_vcam_set_mode;
36485- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36486+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36487 = mc13892_vcam_get_mode;
36488+ pax_close_kernel();
36489
36490 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36491 ARRAY_SIZE(mc13892_regulators));
36492diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36493index cace6d3..f623fda 100644
36494--- a/drivers/rtc/rtc-dev.c
36495+++ b/drivers/rtc/rtc-dev.c
36496@@ -14,6 +14,7 @@
36497 #include <linux/module.h>
36498 #include <linux/rtc.h>
36499 #include <linux/sched.h>
36500+#include <linux/grsecurity.h>
36501 #include "rtc-core.h"
36502
36503 static dev_t rtc_devt;
36504@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36505 if (copy_from_user(&tm, uarg, sizeof(tm)))
36506 return -EFAULT;
36507
36508+ gr_log_timechange();
36509+
36510 return rtc_set_time(rtc, &tm);
36511
36512 case RTC_PIE_ON:
36513diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36514index ffb5878..e6d785c 100644
36515--- a/drivers/scsi/aacraid/aacraid.h
36516+++ b/drivers/scsi/aacraid/aacraid.h
36517@@ -492,7 +492,7 @@ struct adapter_ops
36518 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36519 /* Administrative operations */
36520 int (*adapter_comm)(struct aac_dev * dev, int comm);
36521-};
36522+} __no_const;
36523
36524 /*
36525 * Define which interrupt handler needs to be installed
36526diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36527index 705e13e..91c873c 100644
36528--- a/drivers/scsi/aacraid/linit.c
36529+++ b/drivers/scsi/aacraid/linit.c
36530@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36531 #elif defined(__devinitconst)
36532 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36533 #else
36534-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36535+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36536 #endif
36537 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36538 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36539diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36540index d5ff142..49c0ebb 100644
36541--- a/drivers/scsi/aic94xx/aic94xx_init.c
36542+++ b/drivers/scsi/aic94xx/aic94xx_init.c
36543@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36544 .lldd_control_phy = asd_control_phy,
36545 };
36546
36547-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36548+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36549 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36550 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36551 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36552diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36553index a796de9..1ef20e1 100644
36554--- a/drivers/scsi/bfa/bfa.h
36555+++ b/drivers/scsi/bfa/bfa.h
36556@@ -196,7 +196,7 @@ struct bfa_hwif_s {
36557 u32 *end);
36558 int cpe_vec_q0;
36559 int rme_vec_q0;
36560-};
36561+} __no_const;
36562 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36563
36564 struct bfa_faa_cbfn_s {
36565diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36566index f0f80e2..8ec946b 100644
36567--- a/drivers/scsi/bfa/bfa_fcpim.c
36568+++ b/drivers/scsi/bfa/bfa_fcpim.c
36569@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36570
36571 bfa_iotag_attach(fcp);
36572
36573- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36574+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36575 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36576 (fcp->num_itns * sizeof(struct bfa_itn_s));
36577 memset(fcp->itn_arr, 0,
36578@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36579 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36580 {
36581 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36582- struct bfa_itn_s *itn;
36583+ bfa_itn_s_no_const *itn;
36584
36585 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36586 itn->isr = isr;
36587diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36588index 36f26da..38a34a8 100644
36589--- a/drivers/scsi/bfa/bfa_fcpim.h
36590+++ b/drivers/scsi/bfa/bfa_fcpim.h
36591@@ -37,6 +37,7 @@ struct bfa_iotag_s {
36592 struct bfa_itn_s {
36593 bfa_isr_func_t isr;
36594 };
36595+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36596
36597 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36598 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36599@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36600 struct list_head iotag_tio_free_q; /* free IO resources */
36601 struct list_head iotag_unused_q; /* unused IO resources*/
36602 struct bfa_iotag_s *iotag_arr;
36603- struct bfa_itn_s *itn_arr;
36604+ bfa_itn_s_no_const *itn_arr;
36605 int num_ioim_reqs;
36606 int num_fwtio_reqs;
36607 int num_itns;
36608diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36609index 546d46b..642fa5b 100644
36610--- a/drivers/scsi/bfa/bfa_ioc.h
36611+++ b/drivers/scsi/bfa/bfa_ioc.h
36612@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36613 bfa_ioc_disable_cbfn_t disable_cbfn;
36614 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36615 bfa_ioc_reset_cbfn_t reset_cbfn;
36616-};
36617+} __no_const;
36618
36619 /*
36620 * IOC event notification mechanism.
36621@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36622 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36623 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36624 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36625-};
36626+} __no_const;
36627
36628 /*
36629 * Queue element to wait for room in request queue. FIFO order is
36630diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36631index 351dc0b..951dc32 100644
36632--- a/drivers/scsi/hosts.c
36633+++ b/drivers/scsi/hosts.c
36634@@ -42,7 +42,7 @@
36635 #include "scsi_logging.h"
36636
36637
36638-static atomic_t scsi_host_next_hn; /* host_no for next new host */
36639+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36640
36641
36642 static void scsi_host_cls_release(struct device *dev)
36643@@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36644 * subtract one because we increment first then return, but we need to
36645 * know what the next host number was before increment
36646 */
36647- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36648+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36649 shost->dma_channel = 0xff;
36650
36651 /* These three are default values which can be overridden */
36652diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36653index b96962c..0c82ec2 100644
36654--- a/drivers/scsi/hpsa.c
36655+++ b/drivers/scsi/hpsa.c
36656@@ -507,7 +507,7 @@ static inline u32 next_command(struct ctlr_info *h)
36657 u32 a;
36658
36659 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36660- return h->access.command_completed(h);
36661+ return h->access->command_completed(h);
36662
36663 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36664 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36665@@ -2991,7 +2991,7 @@ static void start_io(struct ctlr_info *h)
36666 while (!list_empty(&h->reqQ)) {
36667 c = list_entry(h->reqQ.next, struct CommandList, list);
36668 /* can't do anything if fifo is full */
36669- if ((h->access.fifo_full(h))) {
36670+ if ((h->access->fifo_full(h))) {
36671 dev_warn(&h->pdev->dev, "fifo full\n");
36672 break;
36673 }
36674@@ -3001,7 +3001,7 @@ static void start_io(struct ctlr_info *h)
36675 h->Qdepth--;
36676
36677 /* Tell the controller execute command */
36678- h->access.submit_command(h, c);
36679+ h->access->submit_command(h, c);
36680
36681 /* Put job onto the completed Q */
36682 addQ(&h->cmpQ, c);
36683@@ -3010,17 +3010,17 @@ static void start_io(struct ctlr_info *h)
36684
36685 static inline unsigned long get_next_completion(struct ctlr_info *h)
36686 {
36687- return h->access.command_completed(h);
36688+ return h->access->command_completed(h);
36689 }
36690
36691 static inline bool interrupt_pending(struct ctlr_info *h)
36692 {
36693- return h->access.intr_pending(h);
36694+ return h->access->intr_pending(h);
36695 }
36696
36697 static inline long interrupt_not_for_us(struct ctlr_info *h)
36698 {
36699- return (h->access.intr_pending(h) == 0) ||
36700+ return (h->access->intr_pending(h) == 0) ||
36701 (h->interrupts_enabled == 0);
36702 }
36703
36704@@ -3919,7 +3919,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36705 if (prod_index < 0)
36706 return -ENODEV;
36707 h->product_name = products[prod_index].product_name;
36708- h->access = *(products[prod_index].access);
36709+ h->access = products[prod_index].access;
36710
36711 if (hpsa_board_disabled(h->pdev)) {
36712 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36713@@ -4164,7 +4164,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36714
36715 assert_spin_locked(&lockup_detector_lock);
36716 remove_ctlr_from_lockup_detector_list(h);
36717- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36718+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36719 spin_lock_irqsave(&h->lock, flags);
36720 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36721 spin_unlock_irqrestore(&h->lock, flags);
36722@@ -4344,7 +4344,7 @@ reinit_after_soft_reset:
36723 }
36724
36725 /* make sure the board interrupts are off */
36726- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36727+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36728
36729 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36730 goto clean2;
36731@@ -4378,7 +4378,7 @@ reinit_after_soft_reset:
36732 * fake ones to scoop up any residual completions.
36733 */
36734 spin_lock_irqsave(&h->lock, flags);
36735- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36736+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36737 spin_unlock_irqrestore(&h->lock, flags);
36738 free_irq(h->intr[h->intr_mode], h);
36739 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36740@@ -4397,9 +4397,9 @@ reinit_after_soft_reset:
36741 dev_info(&h->pdev->dev, "Board READY.\n");
36742 dev_info(&h->pdev->dev,
36743 "Waiting for stale completions to drain.\n");
36744- h->access.set_intr_mask(h, HPSA_INTR_ON);
36745+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36746 msleep(10000);
36747- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36748+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36749
36750 rc = controller_reset_failed(h->cfgtable);
36751 if (rc)
36752@@ -4420,7 +4420,7 @@ reinit_after_soft_reset:
36753 }
36754
36755 /* Turn the interrupts on so we can service requests */
36756- h->access.set_intr_mask(h, HPSA_INTR_ON);
36757+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36758
36759 hpsa_hba_inquiry(h);
36760 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36761@@ -4472,7 +4472,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36762 * To write all data in the battery backed cache to disks
36763 */
36764 hpsa_flush_cache(h);
36765- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36766+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36767 free_irq(h->intr[h->intr_mode], h);
36768 #ifdef CONFIG_PCI_MSI
36769 if (h->msix_vector)
36770@@ -4636,7 +4636,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36771 return;
36772 }
36773 /* Change the access methods to the performant access methods */
36774- h->access = SA5_performant_access;
36775+ h->access = &SA5_performant_access;
36776 h->transMethod = CFGTBL_Trans_Performant;
36777 }
36778
36779diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36780index 91edafb..a9b88ec 100644
36781--- a/drivers/scsi/hpsa.h
36782+++ b/drivers/scsi/hpsa.h
36783@@ -73,7 +73,7 @@ struct ctlr_info {
36784 unsigned int msix_vector;
36785 unsigned int msi_vector;
36786 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36787- struct access_method access;
36788+ struct access_method *access;
36789
36790 /* queue and queue Info */
36791 struct list_head reqQ;
36792diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36793index f2df059..a3a9930 100644
36794--- a/drivers/scsi/ips.h
36795+++ b/drivers/scsi/ips.h
36796@@ -1027,7 +1027,7 @@ typedef struct {
36797 int (*intr)(struct ips_ha *);
36798 void (*enableint)(struct ips_ha *);
36799 uint32_t (*statupd)(struct ips_ha *);
36800-} ips_hw_func_t;
36801+} __no_const ips_hw_func_t;
36802
36803 typedef struct ips_ha {
36804 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36805diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36806index 4d70d96..84d0573 100644
36807--- a/drivers/scsi/libfc/fc_exch.c
36808+++ b/drivers/scsi/libfc/fc_exch.c
36809@@ -105,12 +105,12 @@ struct fc_exch_mgr {
36810 * all together if not used XXX
36811 */
36812 struct {
36813- atomic_t no_free_exch;
36814- atomic_t no_free_exch_xid;
36815- atomic_t xid_not_found;
36816- atomic_t xid_busy;
36817- atomic_t seq_not_found;
36818- atomic_t non_bls_resp;
36819+ atomic_unchecked_t no_free_exch;
36820+ atomic_unchecked_t no_free_exch_xid;
36821+ atomic_unchecked_t xid_not_found;
36822+ atomic_unchecked_t xid_busy;
36823+ atomic_unchecked_t seq_not_found;
36824+ atomic_unchecked_t non_bls_resp;
36825 } stats;
36826 };
36827
36828@@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36829 /* allocate memory for exchange */
36830 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36831 if (!ep) {
36832- atomic_inc(&mp->stats.no_free_exch);
36833+ atomic_inc_unchecked(&mp->stats.no_free_exch);
36834 goto out;
36835 }
36836 memset(ep, 0, sizeof(*ep));
36837@@ -780,7 +780,7 @@ out:
36838 return ep;
36839 err:
36840 spin_unlock_bh(&pool->lock);
36841- atomic_inc(&mp->stats.no_free_exch_xid);
36842+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36843 mempool_free(ep, mp->ep_pool);
36844 return NULL;
36845 }
36846@@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36847 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36848 ep = fc_exch_find(mp, xid);
36849 if (!ep) {
36850- atomic_inc(&mp->stats.xid_not_found);
36851+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36852 reject = FC_RJT_OX_ID;
36853 goto out;
36854 }
36855@@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36856 ep = fc_exch_find(mp, xid);
36857 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36858 if (ep) {
36859- atomic_inc(&mp->stats.xid_busy);
36860+ atomic_inc_unchecked(&mp->stats.xid_busy);
36861 reject = FC_RJT_RX_ID;
36862 goto rel;
36863 }
36864@@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36865 }
36866 xid = ep->xid; /* get our XID */
36867 } else if (!ep) {
36868- atomic_inc(&mp->stats.xid_not_found);
36869+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36870 reject = FC_RJT_RX_ID; /* XID not found */
36871 goto out;
36872 }
36873@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36874 } else {
36875 sp = &ep->seq;
36876 if (sp->id != fh->fh_seq_id) {
36877- atomic_inc(&mp->stats.seq_not_found);
36878+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36879 if (f_ctl & FC_FC_END_SEQ) {
36880 /*
36881 * Update sequence_id based on incoming last
36882@@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36883
36884 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36885 if (!ep) {
36886- atomic_inc(&mp->stats.xid_not_found);
36887+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36888 goto out;
36889 }
36890 if (ep->esb_stat & ESB_ST_COMPLETE) {
36891- atomic_inc(&mp->stats.xid_not_found);
36892+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36893 goto rel;
36894 }
36895 if (ep->rxid == FC_XID_UNKNOWN)
36896 ep->rxid = ntohs(fh->fh_rx_id);
36897 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36898- atomic_inc(&mp->stats.xid_not_found);
36899+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36900 goto rel;
36901 }
36902 if (ep->did != ntoh24(fh->fh_s_id) &&
36903 ep->did != FC_FID_FLOGI) {
36904- atomic_inc(&mp->stats.xid_not_found);
36905+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36906 goto rel;
36907 }
36908 sof = fr_sof(fp);
36909@@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36910 sp->ssb_stat |= SSB_ST_RESP;
36911 sp->id = fh->fh_seq_id;
36912 } else if (sp->id != fh->fh_seq_id) {
36913- atomic_inc(&mp->stats.seq_not_found);
36914+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36915 goto rel;
36916 }
36917
36918@@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36919 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36920
36921 if (!sp)
36922- atomic_inc(&mp->stats.xid_not_found);
36923+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36924 else
36925- atomic_inc(&mp->stats.non_bls_resp);
36926+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
36927
36928 fc_frame_free(fp);
36929 }
36930diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36931index db9238f..4378ed2 100644
36932--- a/drivers/scsi/libsas/sas_ata.c
36933+++ b/drivers/scsi/libsas/sas_ata.c
36934@@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
36935 .postreset = ata_std_postreset,
36936 .error_handler = ata_std_error_handler,
36937 .post_internal_cmd = sas_ata_post_internal,
36938- .qc_defer = ata_std_qc_defer,
36939+ .qc_defer = ata_std_qc_defer,
36940 .qc_prep = ata_noop_qc_prep,
36941 .qc_issue = sas_ata_qc_issue,
36942 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36943diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36944index 825f930..ce42672 100644
36945--- a/drivers/scsi/lpfc/lpfc.h
36946+++ b/drivers/scsi/lpfc/lpfc.h
36947@@ -413,7 +413,7 @@ struct lpfc_vport {
36948 struct dentry *debug_nodelist;
36949 struct dentry *vport_debugfs_root;
36950 struct lpfc_debugfs_trc *disc_trc;
36951- atomic_t disc_trc_cnt;
36952+ atomic_unchecked_t disc_trc_cnt;
36953 #endif
36954 uint8_t stat_data_enabled;
36955 uint8_t stat_data_blocked;
36956@@ -821,8 +821,8 @@ struct lpfc_hba {
36957 struct timer_list fabric_block_timer;
36958 unsigned long bit_flags;
36959 #define FABRIC_COMANDS_BLOCKED 0
36960- atomic_t num_rsrc_err;
36961- atomic_t num_cmd_success;
36962+ atomic_unchecked_t num_rsrc_err;
36963+ atomic_unchecked_t num_cmd_success;
36964 unsigned long last_rsrc_error_time;
36965 unsigned long last_ramp_down_time;
36966 unsigned long last_ramp_up_time;
36967@@ -852,7 +852,7 @@ struct lpfc_hba {
36968
36969 struct dentry *debug_slow_ring_trc;
36970 struct lpfc_debugfs_trc *slow_ring_trc;
36971- atomic_t slow_ring_trc_cnt;
36972+ atomic_unchecked_t slow_ring_trc_cnt;
36973 /* iDiag debugfs sub-directory */
36974 struct dentry *idiag_root;
36975 struct dentry *idiag_pci_cfg;
36976diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36977index 3587a3f..d45b81b 100644
36978--- a/drivers/scsi/lpfc/lpfc_debugfs.c
36979+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36980@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36981
36982 #include <linux/debugfs.h>
36983
36984-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36985+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36986 static unsigned long lpfc_debugfs_start_time = 0L;
36987
36988 /* iDiag */
36989@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36990 lpfc_debugfs_enable = 0;
36991
36992 len = 0;
36993- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36994+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36995 (lpfc_debugfs_max_disc_trc - 1);
36996 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36997 dtp = vport->disc_trc + i;
36998@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36999 lpfc_debugfs_enable = 0;
37000
37001 len = 0;
37002- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37003+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37004 (lpfc_debugfs_max_slow_ring_trc - 1);
37005 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37006 dtp = phba->slow_ring_trc + i;
37007@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37008 !vport || !vport->disc_trc)
37009 return;
37010
37011- index = atomic_inc_return(&vport->disc_trc_cnt) &
37012+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37013 (lpfc_debugfs_max_disc_trc - 1);
37014 dtp = vport->disc_trc + index;
37015 dtp->fmt = fmt;
37016 dtp->data1 = data1;
37017 dtp->data2 = data2;
37018 dtp->data3 = data3;
37019- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37020+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37021 dtp->jif = jiffies;
37022 #endif
37023 return;
37024@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37025 !phba || !phba->slow_ring_trc)
37026 return;
37027
37028- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37029+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37030 (lpfc_debugfs_max_slow_ring_trc - 1);
37031 dtp = phba->slow_ring_trc + index;
37032 dtp->fmt = fmt;
37033 dtp->data1 = data1;
37034 dtp->data2 = data2;
37035 dtp->data3 = data3;
37036- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37037+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37038 dtp->jif = jiffies;
37039 #endif
37040 return;
37041@@ -4040,7 +4040,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37042 "slow_ring buffer\n");
37043 goto debug_failed;
37044 }
37045- atomic_set(&phba->slow_ring_trc_cnt, 0);
37046+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37047 memset(phba->slow_ring_trc, 0,
37048 (sizeof(struct lpfc_debugfs_trc) *
37049 lpfc_debugfs_max_slow_ring_trc));
37050@@ -4086,7 +4086,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37051 "buffer\n");
37052 goto debug_failed;
37053 }
37054- atomic_set(&vport->disc_trc_cnt, 0);
37055+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37056
37057 snprintf(name, sizeof(name), "discovery_trace");
37058 vport->debug_disc_trc =
37059diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37060index dfea2da..8e17227 100644
37061--- a/drivers/scsi/lpfc/lpfc_init.c
37062+++ b/drivers/scsi/lpfc/lpfc_init.c
37063@@ -10145,8 +10145,10 @@ lpfc_init(void)
37064 printk(LPFC_COPYRIGHT "\n");
37065
37066 if (lpfc_enable_npiv) {
37067- lpfc_transport_functions.vport_create = lpfc_vport_create;
37068- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37069+ pax_open_kernel();
37070+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37071+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37072+ pax_close_kernel();
37073 }
37074 lpfc_transport_template =
37075 fc_attach_transport(&lpfc_transport_functions);
37076diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37077index c60f5d0..751535c 100644
37078--- a/drivers/scsi/lpfc/lpfc_scsi.c
37079+++ b/drivers/scsi/lpfc/lpfc_scsi.c
37080@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37081 uint32_t evt_posted;
37082
37083 spin_lock_irqsave(&phba->hbalock, flags);
37084- atomic_inc(&phba->num_rsrc_err);
37085+ atomic_inc_unchecked(&phba->num_rsrc_err);
37086 phba->last_rsrc_error_time = jiffies;
37087
37088 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37089@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37090 unsigned long flags;
37091 struct lpfc_hba *phba = vport->phba;
37092 uint32_t evt_posted;
37093- atomic_inc(&phba->num_cmd_success);
37094+ atomic_inc_unchecked(&phba->num_cmd_success);
37095
37096 if (vport->cfg_lun_queue_depth <= queue_depth)
37097 return;
37098@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37099 unsigned long num_rsrc_err, num_cmd_success;
37100 int i;
37101
37102- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37103- num_cmd_success = atomic_read(&phba->num_cmd_success);
37104+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37105+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37106
37107 vports = lpfc_create_vport_work_array(phba);
37108 if (vports != NULL)
37109@@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37110 }
37111 }
37112 lpfc_destroy_vport_work_array(phba, vports);
37113- atomic_set(&phba->num_rsrc_err, 0);
37114- atomic_set(&phba->num_cmd_success, 0);
37115+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37116+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37117 }
37118
37119 /**
37120@@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37121 }
37122 }
37123 lpfc_destroy_vport_work_array(phba, vports);
37124- atomic_set(&phba->num_rsrc_err, 0);
37125- atomic_set(&phba->num_cmd_success, 0);
37126+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37127+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37128 }
37129
37130 /**
37131diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37132index ea8a0b4..812a124 100644
37133--- a/drivers/scsi/pmcraid.c
37134+++ b/drivers/scsi/pmcraid.c
37135@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37136 res->scsi_dev = scsi_dev;
37137 scsi_dev->hostdata = res;
37138 res->change_detected = 0;
37139- atomic_set(&res->read_failures, 0);
37140- atomic_set(&res->write_failures, 0);
37141+ atomic_set_unchecked(&res->read_failures, 0);
37142+ atomic_set_unchecked(&res->write_failures, 0);
37143 rc = 0;
37144 }
37145 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37146@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37147
37148 /* If this was a SCSI read/write command keep count of errors */
37149 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37150- atomic_inc(&res->read_failures);
37151+ atomic_inc_unchecked(&res->read_failures);
37152 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37153- atomic_inc(&res->write_failures);
37154+ atomic_inc_unchecked(&res->write_failures);
37155
37156 if (!RES_IS_GSCSI(res->cfg_entry) &&
37157 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37158@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37159 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37160 * hrrq_id assigned here in queuecommand
37161 */
37162- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37163+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37164 pinstance->num_hrrq;
37165 cmd->cmd_done = pmcraid_io_done;
37166
37167@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37168 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37169 * hrrq_id assigned here in queuecommand
37170 */
37171- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37172+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37173 pinstance->num_hrrq;
37174
37175 if (request_size) {
37176@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37177
37178 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37179 /* add resources only after host is added into system */
37180- if (!atomic_read(&pinstance->expose_resources))
37181+ if (!atomic_read_unchecked(&pinstance->expose_resources))
37182 return;
37183
37184 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37185@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37186 init_waitqueue_head(&pinstance->reset_wait_q);
37187
37188 atomic_set(&pinstance->outstanding_cmds, 0);
37189- atomic_set(&pinstance->last_message_id, 0);
37190- atomic_set(&pinstance->expose_resources, 0);
37191+ atomic_set_unchecked(&pinstance->last_message_id, 0);
37192+ atomic_set_unchecked(&pinstance->expose_resources, 0);
37193
37194 INIT_LIST_HEAD(&pinstance->free_res_q);
37195 INIT_LIST_HEAD(&pinstance->used_res_q);
37196@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37197 /* Schedule worker thread to handle CCN and take care of adding and
37198 * removing devices to OS
37199 */
37200- atomic_set(&pinstance->expose_resources, 1);
37201+ atomic_set_unchecked(&pinstance->expose_resources, 1);
37202 schedule_work(&pinstance->worker_q);
37203 return rc;
37204
37205diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37206index ca496c7..9c791d5 100644
37207--- a/drivers/scsi/pmcraid.h
37208+++ b/drivers/scsi/pmcraid.h
37209@@ -748,7 +748,7 @@ struct pmcraid_instance {
37210 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37211
37212 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37213- atomic_t last_message_id;
37214+ atomic_unchecked_t last_message_id;
37215
37216 /* configuration table */
37217 struct pmcraid_config_table *cfg_table;
37218@@ -777,7 +777,7 @@ struct pmcraid_instance {
37219 atomic_t outstanding_cmds;
37220
37221 /* should add/delete resources to mid-layer now ?*/
37222- atomic_t expose_resources;
37223+ atomic_unchecked_t expose_resources;
37224
37225
37226
37227@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37228 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37229 };
37230 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37231- atomic_t read_failures; /* count of failed READ commands */
37232- atomic_t write_failures; /* count of failed WRITE commands */
37233+ atomic_unchecked_t read_failures; /* count of failed READ commands */
37234+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37235
37236 /* To indicate add/delete/modify during CCN */
37237 u8 change_detected;
37238diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37239index af1003f..be55a75 100644
37240--- a/drivers/scsi/qla2xxx/qla_def.h
37241+++ b/drivers/scsi/qla2xxx/qla_def.h
37242@@ -2247,7 +2247,7 @@ struct isp_operations {
37243 int (*start_scsi) (srb_t *);
37244 int (*abort_isp) (struct scsi_qla_host *);
37245 int (*iospace_config)(struct qla_hw_data*);
37246-};
37247+} __no_const;
37248
37249 /* MSI-X Support *************************************************************/
37250
37251diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37252index bfe6854..ceac088 100644
37253--- a/drivers/scsi/qla4xxx/ql4_def.h
37254+++ b/drivers/scsi/qla4xxx/ql4_def.h
37255@@ -261,7 +261,7 @@ struct ddb_entry {
37256 * (4000 only) */
37257 atomic_t relogin_timer; /* Max Time to wait for
37258 * relogin to complete */
37259- atomic_t relogin_retry_count; /* Num of times relogin has been
37260+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37261 * retried */
37262 uint32_t default_time2wait; /* Default Min time between
37263 * relogins (+aens) */
37264diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37265index ce6d3b7..73fac54 100644
37266--- a/drivers/scsi/qla4xxx/ql4_os.c
37267+++ b/drivers/scsi/qla4xxx/ql4_os.c
37268@@ -2178,12 +2178,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37269 */
37270 if (!iscsi_is_session_online(cls_sess)) {
37271 /* Reset retry relogin timer */
37272- atomic_inc(&ddb_entry->relogin_retry_count);
37273+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37274 DEBUG2(ql4_printk(KERN_INFO, ha,
37275 "%s: index[%d] relogin timed out-retrying"
37276 " relogin (%d), retry (%d)\n", __func__,
37277 ddb_entry->fw_ddb_index,
37278- atomic_read(&ddb_entry->relogin_retry_count),
37279+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37280 ddb_entry->default_time2wait + 4));
37281 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37282 atomic_set(&ddb_entry->retry_relogin_timer,
37283@@ -3953,7 +3953,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37284
37285 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37286 atomic_set(&ddb_entry->relogin_timer, 0);
37287- atomic_set(&ddb_entry->relogin_retry_count, 0);
37288+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37289 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37290 ddb_entry->default_relogin_timeout =
37291 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37292diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37293index 2aeb2e9..46e3925 100644
37294--- a/drivers/scsi/scsi.c
37295+++ b/drivers/scsi/scsi.c
37296@@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37297 unsigned long timeout;
37298 int rtn = 0;
37299
37300- atomic_inc(&cmd->device->iorequest_cnt);
37301+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37302
37303 /* check if the device is still usable */
37304 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37305diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37306index b2c95db..227d74e 100644
37307--- a/drivers/scsi/scsi_lib.c
37308+++ b/drivers/scsi/scsi_lib.c
37309@@ -1411,7 +1411,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37310 shost = sdev->host;
37311 scsi_init_cmd_errh(cmd);
37312 cmd->result = DID_NO_CONNECT << 16;
37313- atomic_inc(&cmd->device->iorequest_cnt);
37314+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37315
37316 /*
37317 * SCSI request completion path will do scsi_device_unbusy(),
37318@@ -1437,9 +1437,9 @@ static void scsi_softirq_done(struct request *rq)
37319
37320 INIT_LIST_HEAD(&cmd->eh_entry);
37321
37322- atomic_inc(&cmd->device->iodone_cnt);
37323+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
37324 if (cmd->result)
37325- atomic_inc(&cmd->device->ioerr_cnt);
37326+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37327
37328 disposition = scsi_decide_disposition(cmd);
37329 if (disposition != SUCCESS &&
37330diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37331index 04c2a27..9d8bd66 100644
37332--- a/drivers/scsi/scsi_sysfs.c
37333+++ b/drivers/scsi/scsi_sysfs.c
37334@@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37335 char *buf) \
37336 { \
37337 struct scsi_device *sdev = to_scsi_device(dev); \
37338- unsigned long long count = atomic_read(&sdev->field); \
37339+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
37340 return snprintf(buf, 20, "0x%llx\n", count); \
37341 } \
37342 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37343diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37344index 84a1fdf..693b0d6 100644
37345--- a/drivers/scsi/scsi_tgt_lib.c
37346+++ b/drivers/scsi/scsi_tgt_lib.c
37347@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37348 int err;
37349
37350 dprintk("%lx %u\n", uaddr, len);
37351- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37352+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37353 if (err) {
37354 /*
37355 * TODO: need to fixup sg_tablesize, max_segment_size,
37356diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37357index f59d4a0..1d89407 100644
37358--- a/drivers/scsi/scsi_transport_fc.c
37359+++ b/drivers/scsi/scsi_transport_fc.c
37360@@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37361 * Netlink Infrastructure
37362 */
37363
37364-static atomic_t fc_event_seq;
37365+static atomic_unchecked_t fc_event_seq;
37366
37367 /**
37368 * fc_get_event_number - Obtain the next sequential FC event number
37369@@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
37370 u32
37371 fc_get_event_number(void)
37372 {
37373- return atomic_add_return(1, &fc_event_seq);
37374+ return atomic_add_return_unchecked(1, &fc_event_seq);
37375 }
37376 EXPORT_SYMBOL(fc_get_event_number);
37377
37378@@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
37379 {
37380 int error;
37381
37382- atomic_set(&fc_event_seq, 0);
37383+ atomic_set_unchecked(&fc_event_seq, 0);
37384
37385 error = transport_class_register(&fc_host_class);
37386 if (error)
37387@@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37388 char *cp;
37389
37390 *val = simple_strtoul(buf, &cp, 0);
37391- if ((*cp && (*cp != '\n')) || (*val < 0))
37392+ if (*cp && (*cp != '\n'))
37393 return -EINVAL;
37394 /*
37395 * Check for overflow; dev_loss_tmo is u32
37396diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37397index e3e3c7d..ebdab62 100644
37398--- a/drivers/scsi/scsi_transport_iscsi.c
37399+++ b/drivers/scsi/scsi_transport_iscsi.c
37400@@ -79,7 +79,7 @@ struct iscsi_internal {
37401 struct transport_container session_cont;
37402 };
37403
37404-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37405+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37406 static struct workqueue_struct *iscsi_eh_timer_workq;
37407
37408 static DEFINE_IDA(iscsi_sess_ida);
37409@@ -1063,7 +1063,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37410 int err;
37411
37412 ihost = shost->shost_data;
37413- session->sid = atomic_add_return(1, &iscsi_session_nr);
37414+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37415
37416 if (target_id == ISCSI_MAX_TARGET) {
37417 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37418@@ -2680,7 +2680,7 @@ static __init int iscsi_transport_init(void)
37419 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37420 ISCSI_TRANSPORT_VERSION);
37421
37422- atomic_set(&iscsi_session_nr, 0);
37423+ atomic_set_unchecked(&iscsi_session_nr, 0);
37424
37425 err = class_register(&iscsi_transport_class);
37426 if (err)
37427diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37428index 21a045e..ec89e03 100644
37429--- a/drivers/scsi/scsi_transport_srp.c
37430+++ b/drivers/scsi/scsi_transport_srp.c
37431@@ -33,7 +33,7 @@
37432 #include "scsi_transport_srp_internal.h"
37433
37434 struct srp_host_attrs {
37435- atomic_t next_port_id;
37436+ atomic_unchecked_t next_port_id;
37437 };
37438 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37439
37440@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37441 struct Scsi_Host *shost = dev_to_shost(dev);
37442 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37443
37444- atomic_set(&srp_host->next_port_id, 0);
37445+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37446 return 0;
37447 }
37448
37449@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37450 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37451 rport->roles = ids->roles;
37452
37453- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37454+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37455 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37456
37457 transport_setup_device(&rport->dev);
37458diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37459index eacd46b..e3f4d62 100644
37460--- a/drivers/scsi/sg.c
37461+++ b/drivers/scsi/sg.c
37462@@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37463 sdp->disk->disk_name,
37464 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37465 NULL,
37466- (char *)arg);
37467+ (char __user *)arg);
37468 case BLKTRACESTART:
37469 return blk_trace_startstop(sdp->device->request_queue, 1);
37470 case BLKTRACESTOP:
37471@@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
37472 const struct file_operations * fops;
37473 };
37474
37475-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37476+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37477 {"allow_dio", &adio_fops},
37478 {"debug", &debug_fops},
37479 {"def_reserved_size", &dressz_fops},
37480@@ -2332,7 +2332,7 @@ sg_proc_init(void)
37481 if (!sg_proc_sgp)
37482 return 1;
37483 for (k = 0; k < num_leaves; ++k) {
37484- struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37485+ const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37486 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
37487 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
37488 }
37489diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
37490index f64250e..1ee3049 100644
37491--- a/drivers/spi/spi-dw-pci.c
37492+++ b/drivers/spi/spi-dw-pci.c
37493@@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
37494 #define spi_resume NULL
37495 #endif
37496
37497-static const struct pci_device_id pci_ids[] __devinitdata = {
37498+static const struct pci_device_id pci_ids[] __devinitconst = {
37499 /* Intel MID platform SPI controller 0 */
37500 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
37501 {},
37502diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37503index b2ccdea..84cde75 100644
37504--- a/drivers/spi/spi.c
37505+++ b/drivers/spi/spi.c
37506@@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
37507 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37508
37509 /* portable code must never pass more than 32 bytes */
37510-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37511+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37512
37513 static u8 *buf;
37514
37515diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37516index 400df8c..065d4f4 100644
37517--- a/drivers/staging/octeon/ethernet-rx.c
37518+++ b/drivers/staging/octeon/ethernet-rx.c
37519@@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37520 /* Increment RX stats for virtual ports */
37521 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37522 #ifdef CONFIG_64BIT
37523- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37524- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37525+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37526+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37527 #else
37528- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37529- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37530+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37531+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37532 #endif
37533 }
37534 netif_receive_skb(skb);
37535@@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37536 dev->name);
37537 */
37538 #ifdef CONFIG_64BIT
37539- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37540+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37541 #else
37542- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37543+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37544 #endif
37545 dev_kfree_skb_irq(skb);
37546 }
37547diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37548index 9112cd8..92f8d51 100644
37549--- a/drivers/staging/octeon/ethernet.c
37550+++ b/drivers/staging/octeon/ethernet.c
37551@@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37552 * since the RX tasklet also increments it.
37553 */
37554 #ifdef CONFIG_64BIT
37555- atomic64_add(rx_status.dropped_packets,
37556- (atomic64_t *)&priv->stats.rx_dropped);
37557+ atomic64_add_unchecked(rx_status.dropped_packets,
37558+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37559 #else
37560- atomic_add(rx_status.dropped_packets,
37561- (atomic_t *)&priv->stats.rx_dropped);
37562+ atomic_add_unchecked(rx_status.dropped_packets,
37563+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37564 #endif
37565 }
37566
37567diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37568index 86308a0..feaa925 100644
37569--- a/drivers/staging/rtl8712/rtl871x_io.h
37570+++ b/drivers/staging/rtl8712/rtl871x_io.h
37571@@ -108,7 +108,7 @@ struct _io_ops {
37572 u8 *pmem);
37573 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37574 u8 *pmem);
37575-};
37576+} __no_const;
37577
37578 struct io_req {
37579 struct list_head list;
37580diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37581index c7b5e8b..783d6cb 100644
37582--- a/drivers/staging/sbe-2t3e3/netdev.c
37583+++ b/drivers/staging/sbe-2t3e3/netdev.c
37584@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37585 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37586
37587 if (rlen)
37588- if (copy_to_user(data, &resp, rlen))
37589+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37590 return -EFAULT;
37591
37592 return 0;
37593diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37594index 42cdafe..2769103 100644
37595--- a/drivers/staging/speakup/speakup_soft.c
37596+++ b/drivers/staging/speakup/speakup_soft.c
37597@@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37598 break;
37599 } else if (!initialized) {
37600 if (*init) {
37601- ch = *init;
37602 init++;
37603 } else {
37604 initialized = 1;
37605 }
37606+ ch = *init;
37607 } else {
37608 ch = synth_buffer_getc();
37609 }
37610diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37611index b8f8c48..1fc5025 100644
37612--- a/drivers/staging/usbip/usbip_common.h
37613+++ b/drivers/staging/usbip/usbip_common.h
37614@@ -289,7 +289,7 @@ struct usbip_device {
37615 void (*shutdown)(struct usbip_device *);
37616 void (*reset)(struct usbip_device *);
37617 void (*unusable)(struct usbip_device *);
37618- } eh_ops;
37619+ } __no_const eh_ops;
37620 };
37621
37622 /* usbip_common.c */
37623diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37624index 88b3298..3783eee 100644
37625--- a/drivers/staging/usbip/vhci.h
37626+++ b/drivers/staging/usbip/vhci.h
37627@@ -88,7 +88,7 @@ struct vhci_hcd {
37628 unsigned resuming:1;
37629 unsigned long re_timeout;
37630
37631- atomic_t seqnum;
37632+ atomic_unchecked_t seqnum;
37633
37634 /*
37635 * NOTE:
37636diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37637index 2ee97e2..0420b86 100644
37638--- a/drivers/staging/usbip/vhci_hcd.c
37639+++ b/drivers/staging/usbip/vhci_hcd.c
37640@@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
37641 return;
37642 }
37643
37644- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37645+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37646 if (priv->seqnum == 0xffff)
37647 dev_info(&urb->dev->dev, "seqnum max\n");
37648
37649@@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37650 return -ENOMEM;
37651 }
37652
37653- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37654+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37655 if (unlink->seqnum == 0xffff)
37656 pr_info("seqnum max\n");
37657
37658@@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
37659 vdev->rhport = rhport;
37660 }
37661
37662- atomic_set(&vhci->seqnum, 0);
37663+ atomic_set_unchecked(&vhci->seqnum, 0);
37664 spin_lock_init(&vhci->lock);
37665
37666 hcd->power_budget = 0; /* no limit */
37667diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37668index 3f511b4..d3dbc1e 100644
37669--- a/drivers/staging/usbip/vhci_rx.c
37670+++ b/drivers/staging/usbip/vhci_rx.c
37671@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37672 if (!urb) {
37673 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37674 pr_info("max seqnum %d\n",
37675- atomic_read(&the_controller->seqnum));
37676+ atomic_read_unchecked(&the_controller->seqnum));
37677 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37678 return;
37679 }
37680diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37681index 7735027..30eed13 100644
37682--- a/drivers/staging/vt6655/hostap.c
37683+++ b/drivers/staging/vt6655/hostap.c
37684@@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37685 *
37686 */
37687
37688+static net_device_ops_no_const apdev_netdev_ops;
37689+
37690 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37691 {
37692 PSDevice apdev_priv;
37693 struct net_device *dev = pDevice->dev;
37694 int ret;
37695- const struct net_device_ops apdev_netdev_ops = {
37696- .ndo_start_xmit = pDevice->tx_80211,
37697- };
37698
37699 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37700
37701@@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37702 *apdev_priv = *pDevice;
37703 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37704
37705+ /* only half broken now */
37706+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37707 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37708
37709 pDevice->apdev->type = ARPHRD_IEEE80211;
37710diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37711index 51b5adf..098e320 100644
37712--- a/drivers/staging/vt6656/hostap.c
37713+++ b/drivers/staging/vt6656/hostap.c
37714@@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37715 *
37716 */
37717
37718+static net_device_ops_no_const apdev_netdev_ops;
37719+
37720 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37721 {
37722 PSDevice apdev_priv;
37723 struct net_device *dev = pDevice->dev;
37724 int ret;
37725- const struct net_device_ops apdev_netdev_ops = {
37726- .ndo_start_xmit = pDevice->tx_80211,
37727- };
37728
37729 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37730
37731@@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37732 *apdev_priv = *pDevice;
37733 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37734
37735+ /* only half broken now */
37736+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37737 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37738
37739 pDevice->apdev->type = ARPHRD_IEEE80211;
37740diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37741index 7843dfd..3db105f 100644
37742--- a/drivers/staging/wlan-ng/hfa384x_usb.c
37743+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37744@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37745
37746 struct usbctlx_completor {
37747 int (*complete) (struct usbctlx_completor *);
37748-};
37749+} __no_const;
37750
37751 static int
37752 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37753diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37754index 1ca66ea..76f1343 100644
37755--- a/drivers/staging/zcache/tmem.c
37756+++ b/drivers/staging/zcache/tmem.c
37757@@ -39,7 +39,7 @@
37758 * A tmem host implementation must use this function to register callbacks
37759 * for memory allocation.
37760 */
37761-static struct tmem_hostops tmem_hostops;
37762+static tmem_hostops_no_const tmem_hostops;
37763
37764 static void tmem_objnode_tree_init(void);
37765
37766@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37767 * A tmem host implementation must use this function to register
37768 * callbacks for a page-accessible memory (PAM) implementation
37769 */
37770-static struct tmem_pamops tmem_pamops;
37771+static tmem_pamops_no_const tmem_pamops;
37772
37773 void tmem_register_pamops(struct tmem_pamops *m)
37774 {
37775diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37776index ed147c4..94fc3c6 100644
37777--- a/drivers/staging/zcache/tmem.h
37778+++ b/drivers/staging/zcache/tmem.h
37779@@ -180,6 +180,7 @@ struct tmem_pamops {
37780 void (*new_obj)(struct tmem_obj *);
37781 int (*replace_in_obj)(void *, struct tmem_obj *);
37782 };
37783+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37784 extern void tmem_register_pamops(struct tmem_pamops *m);
37785
37786 /* memory allocation methods provided by the host implementation */
37787@@ -189,6 +190,7 @@ struct tmem_hostops {
37788 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37789 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37790 };
37791+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37792 extern void tmem_register_hostops(struct tmem_hostops *m);
37793
37794 /* core tmem accessor functions */
37795diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
37796index 97c74ee..7f6d77d 100644
37797--- a/drivers/target/iscsi/iscsi_target.c
37798+++ b/drivers/target/iscsi/iscsi_target.c
37799@@ -1361,7 +1361,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
37800 * outstanding_r2ts reaches zero, go ahead and send the delayed
37801 * TASK_ABORTED status.
37802 */
37803- if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
37804+ if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
37805 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
37806 if (--cmd->outstanding_r2ts < 1) {
37807 iscsit_stop_dataout_timer(cmd);
37808diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37809index dcb0618..97e3d85 100644
37810--- a/drivers/target/target_core_tmr.c
37811+++ b/drivers/target/target_core_tmr.c
37812@@ -260,7 +260,7 @@ static void core_tmr_drain_task_list(
37813 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37814 cmd->t_task_list_num,
37815 atomic_read(&cmd->t_task_cdbs_left),
37816- atomic_read(&cmd->t_task_cdbs_sent),
37817+ atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37818 atomic_read(&cmd->t_transport_active),
37819 atomic_read(&cmd->t_transport_stop),
37820 atomic_read(&cmd->t_transport_sent));
37821@@ -291,7 +291,7 @@ static void core_tmr_drain_task_list(
37822 pr_debug("LUN_RESET: got t_transport_active = 1 for"
37823 " task: %p, t_fe_count: %d dev: %p\n", task,
37824 fe_count, dev);
37825- atomic_set(&cmd->t_transport_aborted, 1);
37826+ atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37827 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37828
37829 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37830@@ -299,7 +299,7 @@ static void core_tmr_drain_task_list(
37831 }
37832 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
37833 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
37834- atomic_set(&cmd->t_transport_aborted, 1);
37835+ atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37836 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37837
37838 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37839diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37840index cd5cd95..5249d30 100644
37841--- a/drivers/target/target_core_transport.c
37842+++ b/drivers/target/target_core_transport.c
37843@@ -1330,7 +1330,7 @@ struct se_device *transport_add_device_to_core_hba(
37844 spin_lock_init(&dev->se_port_lock);
37845 spin_lock_init(&dev->se_tmr_lock);
37846 spin_lock_init(&dev->qf_cmd_lock);
37847- atomic_set(&dev->dev_ordered_id, 0);
37848+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
37849
37850 se_dev_set_default_attribs(dev, dev_limits);
37851
37852@@ -1517,7 +1517,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37853 * Used to determine when ORDERED commands should go from
37854 * Dormant to Active status.
37855 */
37856- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37857+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37858 smp_mb__after_atomic_inc();
37859 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37860 cmd->se_ordered_id, cmd->sam_task_attr,
37861@@ -1862,7 +1862,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
37862 " t_transport_active: %d t_transport_stop: %d"
37863 " t_transport_sent: %d\n", cmd->t_task_list_num,
37864 atomic_read(&cmd->t_task_cdbs_left),
37865- atomic_read(&cmd->t_task_cdbs_sent),
37866+ atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37867 atomic_read(&cmd->t_task_cdbs_ex_left),
37868 atomic_read(&cmd->t_transport_active),
37869 atomic_read(&cmd->t_transport_stop),
37870@@ -2121,9 +2121,9 @@ check_depth:
37871 cmd = task->task_se_cmd;
37872 spin_lock_irqsave(&cmd->t_state_lock, flags);
37873 task->task_flags |= (TF_ACTIVE | TF_SENT);
37874- atomic_inc(&cmd->t_task_cdbs_sent);
37875+ atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37876
37877- if (atomic_read(&cmd->t_task_cdbs_sent) ==
37878+ if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37879 cmd->t_task_list_num)
37880 atomic_set(&cmd->t_transport_sent, 1);
37881
37882@@ -4348,7 +4348,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
37883 atomic_set(&cmd->transport_lun_stop, 0);
37884 }
37885 if (!atomic_read(&cmd->t_transport_active) ||
37886- atomic_read(&cmd->t_transport_aborted)) {
37887+ atomic_read_unchecked(&cmd->t_transport_aborted)) {
37888 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37889 return false;
37890 }
37891@@ -4597,7 +4597,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
37892 {
37893 int ret = 0;
37894
37895- if (atomic_read(&cmd->t_transport_aborted) != 0) {
37896+ if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
37897 if (!send_status ||
37898 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
37899 return 1;
37900@@ -4634,7 +4634,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
37901 */
37902 if (cmd->data_direction == DMA_TO_DEVICE) {
37903 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
37904- atomic_inc(&cmd->t_transport_aborted);
37905+ atomic_inc_unchecked(&cmd->t_transport_aborted);
37906 smp_mb__after_atomic_inc();
37907 }
37908 }
37909diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37910index b9040be..e3f5aab 100644
37911--- a/drivers/tty/hvc/hvcs.c
37912+++ b/drivers/tty/hvc/hvcs.c
37913@@ -83,6 +83,7 @@
37914 #include <asm/hvcserver.h>
37915 #include <asm/uaccess.h>
37916 #include <asm/vio.h>
37917+#include <asm/local.h>
37918
37919 /*
37920 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37921@@ -270,7 +271,7 @@ struct hvcs_struct {
37922 unsigned int index;
37923
37924 struct tty_struct *tty;
37925- int open_count;
37926+ local_t open_count;
37927
37928 /*
37929 * Used to tell the driver kernel_thread what operations need to take
37930@@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37931
37932 spin_lock_irqsave(&hvcsd->lock, flags);
37933
37934- if (hvcsd->open_count > 0) {
37935+ if (local_read(&hvcsd->open_count) > 0) {
37936 spin_unlock_irqrestore(&hvcsd->lock, flags);
37937 printk(KERN_INFO "HVCS: vterm state unchanged. "
37938 "The hvcs device node is still in use.\n");
37939@@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37940 if ((retval = hvcs_partner_connect(hvcsd)))
37941 goto error_release;
37942
37943- hvcsd->open_count = 1;
37944+ local_set(&hvcsd->open_count, 1);
37945 hvcsd->tty = tty;
37946 tty->driver_data = hvcsd;
37947
37948@@ -1179,7 +1180,7 @@ fast_open:
37949
37950 spin_lock_irqsave(&hvcsd->lock, flags);
37951 kref_get(&hvcsd->kref);
37952- hvcsd->open_count++;
37953+ local_inc(&hvcsd->open_count);
37954 hvcsd->todo_mask |= HVCS_SCHED_READ;
37955 spin_unlock_irqrestore(&hvcsd->lock, flags);
37956
37957@@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37958 hvcsd = tty->driver_data;
37959
37960 spin_lock_irqsave(&hvcsd->lock, flags);
37961- if (--hvcsd->open_count == 0) {
37962+ if (local_dec_and_test(&hvcsd->open_count)) {
37963
37964 vio_disable_interrupts(hvcsd->vdev);
37965
37966@@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37967 free_irq(irq, hvcsd);
37968 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37969 return;
37970- } else if (hvcsd->open_count < 0) {
37971+ } else if (local_read(&hvcsd->open_count) < 0) {
37972 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37973 " is missmanaged.\n",
37974- hvcsd->vdev->unit_address, hvcsd->open_count);
37975+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37976 }
37977
37978 spin_unlock_irqrestore(&hvcsd->lock, flags);
37979@@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37980
37981 spin_lock_irqsave(&hvcsd->lock, flags);
37982 /* Preserve this so that we know how many kref refs to put */
37983- temp_open_count = hvcsd->open_count;
37984+ temp_open_count = local_read(&hvcsd->open_count);
37985
37986 /*
37987 * Don't kref put inside the spinlock because the destruction
37988@@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37989 hvcsd->tty->driver_data = NULL;
37990 hvcsd->tty = NULL;
37991
37992- hvcsd->open_count = 0;
37993+ local_set(&hvcsd->open_count, 0);
37994
37995 /* This will drop any buffered data on the floor which is OK in a hangup
37996 * scenario. */
37997@@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
37998 * the middle of a write operation? This is a crummy place to do this
37999 * but we want to keep it all in the spinlock.
38000 */
38001- if (hvcsd->open_count <= 0) {
38002+ if (local_read(&hvcsd->open_count) <= 0) {
38003 spin_unlock_irqrestore(&hvcsd->lock, flags);
38004 return -ENODEV;
38005 }
38006@@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38007 {
38008 struct hvcs_struct *hvcsd = tty->driver_data;
38009
38010- if (!hvcsd || hvcsd->open_count <= 0)
38011+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
38012 return 0;
38013
38014 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38015diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38016index ef92869..f4ebd88 100644
38017--- a/drivers/tty/ipwireless/tty.c
38018+++ b/drivers/tty/ipwireless/tty.c
38019@@ -29,6 +29,7 @@
38020 #include <linux/tty_driver.h>
38021 #include <linux/tty_flip.h>
38022 #include <linux/uaccess.h>
38023+#include <asm/local.h>
38024
38025 #include "tty.h"
38026 #include "network.h"
38027@@ -51,7 +52,7 @@ struct ipw_tty {
38028 int tty_type;
38029 struct ipw_network *network;
38030 struct tty_struct *linux_tty;
38031- int open_count;
38032+ local_t open_count;
38033 unsigned int control_lines;
38034 struct mutex ipw_tty_mutex;
38035 int tx_bytes_queued;
38036@@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38037 mutex_unlock(&tty->ipw_tty_mutex);
38038 return -ENODEV;
38039 }
38040- if (tty->open_count == 0)
38041+ if (local_read(&tty->open_count) == 0)
38042 tty->tx_bytes_queued = 0;
38043
38044- tty->open_count++;
38045+ local_inc(&tty->open_count);
38046
38047 tty->linux_tty = linux_tty;
38048 linux_tty->driver_data = tty;
38049@@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38050
38051 static void do_ipw_close(struct ipw_tty *tty)
38052 {
38053- tty->open_count--;
38054-
38055- if (tty->open_count == 0) {
38056+ if (local_dec_return(&tty->open_count) == 0) {
38057 struct tty_struct *linux_tty = tty->linux_tty;
38058
38059 if (linux_tty != NULL) {
38060@@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38061 return;
38062
38063 mutex_lock(&tty->ipw_tty_mutex);
38064- if (tty->open_count == 0) {
38065+ if (local_read(&tty->open_count) == 0) {
38066 mutex_unlock(&tty->ipw_tty_mutex);
38067 return;
38068 }
38069@@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38070 return;
38071 }
38072
38073- if (!tty->open_count) {
38074+ if (!local_read(&tty->open_count)) {
38075 mutex_unlock(&tty->ipw_tty_mutex);
38076 return;
38077 }
38078@@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38079 return -ENODEV;
38080
38081 mutex_lock(&tty->ipw_tty_mutex);
38082- if (!tty->open_count) {
38083+ if (!local_read(&tty->open_count)) {
38084 mutex_unlock(&tty->ipw_tty_mutex);
38085 return -EINVAL;
38086 }
38087@@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38088 if (!tty)
38089 return -ENODEV;
38090
38091- if (!tty->open_count)
38092+ if (!local_read(&tty->open_count))
38093 return -EINVAL;
38094
38095 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38096@@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38097 if (!tty)
38098 return 0;
38099
38100- if (!tty->open_count)
38101+ if (!local_read(&tty->open_count))
38102 return 0;
38103
38104 return tty->tx_bytes_queued;
38105@@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38106 if (!tty)
38107 return -ENODEV;
38108
38109- if (!tty->open_count)
38110+ if (!local_read(&tty->open_count))
38111 return -EINVAL;
38112
38113 return get_control_lines(tty);
38114@@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38115 if (!tty)
38116 return -ENODEV;
38117
38118- if (!tty->open_count)
38119+ if (!local_read(&tty->open_count))
38120 return -EINVAL;
38121
38122 return set_control_lines(tty, set, clear);
38123@@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38124 if (!tty)
38125 return -ENODEV;
38126
38127- if (!tty->open_count)
38128+ if (!local_read(&tty->open_count))
38129 return -EINVAL;
38130
38131 /* FIXME: Exactly how is the tty object locked here .. */
38132@@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38133 against a parallel ioctl etc */
38134 mutex_lock(&ttyj->ipw_tty_mutex);
38135 }
38136- while (ttyj->open_count)
38137+ while (local_read(&ttyj->open_count))
38138 do_ipw_close(ttyj);
38139 ipwireless_disassociate_network_ttys(network,
38140 ttyj->channel_idx);
38141diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38142index fc7bbba..9527e93 100644
38143--- a/drivers/tty/n_gsm.c
38144+++ b/drivers/tty/n_gsm.c
38145@@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38146 kref_init(&dlci->ref);
38147 mutex_init(&dlci->mutex);
38148 dlci->fifo = &dlci->_fifo;
38149- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38150+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38151 kfree(dlci);
38152 return NULL;
38153 }
38154diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38155index d2256d0..97476fa 100644
38156--- a/drivers/tty/n_tty.c
38157+++ b/drivers/tty/n_tty.c
38158@@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38159 {
38160 *ops = tty_ldisc_N_TTY;
38161 ops->owner = NULL;
38162- ops->refcount = ops->flags = 0;
38163+ atomic_set(&ops->refcount, 0);
38164+ ops->flags = 0;
38165 }
38166 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38167diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38168index d8653ab..f8afd9d 100644
38169--- a/drivers/tty/pty.c
38170+++ b/drivers/tty/pty.c
38171@@ -765,8 +765,10 @@ static void __init unix98_pty_init(void)
38172 register_sysctl_table(pty_root_table);
38173
38174 /* Now create the /dev/ptmx special device */
38175+ pax_open_kernel();
38176 tty_default_fops(&ptmx_fops);
38177- ptmx_fops.open = ptmx_open;
38178+ *(void **)&ptmx_fops.open = ptmx_open;
38179+ pax_close_kernel();
38180
38181 cdev_init(&ptmx_cdev, &ptmx_fops);
38182 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38183diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38184index 2b42a01..32a2ed3 100644
38185--- a/drivers/tty/serial/kgdboc.c
38186+++ b/drivers/tty/serial/kgdboc.c
38187@@ -24,8 +24,9 @@
38188 #define MAX_CONFIG_LEN 40
38189
38190 static struct kgdb_io kgdboc_io_ops;
38191+static struct kgdb_io kgdboc_io_ops_console;
38192
38193-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38194+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38195 static int configured = -1;
38196
38197 static char config[MAX_CONFIG_LEN];
38198@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38199 kgdboc_unregister_kbd();
38200 if (configured == 1)
38201 kgdb_unregister_io_module(&kgdboc_io_ops);
38202+ else if (configured == 2)
38203+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
38204 }
38205
38206 static int configure_kgdboc(void)
38207@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38208 int err;
38209 char *cptr = config;
38210 struct console *cons;
38211+ int is_console = 0;
38212
38213 err = kgdboc_option_setup(config);
38214 if (err || !strlen(config) || isspace(config[0]))
38215 goto noconfig;
38216
38217 err = -ENODEV;
38218- kgdboc_io_ops.is_console = 0;
38219 kgdb_tty_driver = NULL;
38220
38221 kgdboc_use_kms = 0;
38222@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38223 int idx;
38224 if (cons->device && cons->device(cons, &idx) == p &&
38225 idx == tty_line) {
38226- kgdboc_io_ops.is_console = 1;
38227+ is_console = 1;
38228 break;
38229 }
38230 cons = cons->next;
38231@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38232 kgdb_tty_line = tty_line;
38233
38234 do_register:
38235- err = kgdb_register_io_module(&kgdboc_io_ops);
38236+ if (is_console) {
38237+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
38238+ configured = 2;
38239+ } else {
38240+ err = kgdb_register_io_module(&kgdboc_io_ops);
38241+ configured = 1;
38242+ }
38243 if (err)
38244 goto noconfig;
38245
38246- configured = 1;
38247-
38248 return 0;
38249
38250 noconfig:
38251@@ -213,7 +220,7 @@ noconfig:
38252 static int __init init_kgdboc(void)
38253 {
38254 /* Already configured? */
38255- if (configured == 1)
38256+ if (configured >= 1)
38257 return 0;
38258
38259 return configure_kgdboc();
38260@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38261 if (config[len - 1] == '\n')
38262 config[len - 1] = '\0';
38263
38264- if (configured == 1)
38265+ if (configured >= 1)
38266 cleanup_kgdboc();
38267
38268 /* Go and configure with the new params. */
38269@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38270 .post_exception = kgdboc_post_exp_handler,
38271 };
38272
38273+static struct kgdb_io kgdboc_io_ops_console = {
38274+ .name = "kgdboc",
38275+ .read_char = kgdboc_get_char,
38276+ .write_char = kgdboc_put_char,
38277+ .pre_exception = kgdboc_pre_exp_handler,
38278+ .post_exception = kgdboc_post_exp_handler,
38279+ .is_console = 1
38280+};
38281+
38282 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38283 /* This is only available if kgdboc is a built in for early debugging */
38284 static int __init kgdboc_early_init(char *opt)
38285diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38286index 7867b7c..b3c119d 100644
38287--- a/drivers/tty/sysrq.c
38288+++ b/drivers/tty/sysrq.c
38289@@ -862,7 +862,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38290 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38291 size_t count, loff_t *ppos)
38292 {
38293- if (count) {
38294+ if (count && capable(CAP_SYS_ADMIN)) {
38295 char c;
38296
38297 if (get_user(c, buf))
38298diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38299index e41b9bb..84002fb 100644
38300--- a/drivers/tty/tty_io.c
38301+++ b/drivers/tty/tty_io.c
38302@@ -3291,7 +3291,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38303
38304 void tty_default_fops(struct file_operations *fops)
38305 {
38306- *fops = tty_fops;
38307+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38308 }
38309
38310 /*
38311diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38312index 24b95db..9c078d0 100644
38313--- a/drivers/tty/tty_ldisc.c
38314+++ b/drivers/tty/tty_ldisc.c
38315@@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38316 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38317 struct tty_ldisc_ops *ldo = ld->ops;
38318
38319- ldo->refcount--;
38320+ atomic_dec(&ldo->refcount);
38321 module_put(ldo->owner);
38322 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38323
38324@@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38325 spin_lock_irqsave(&tty_ldisc_lock, flags);
38326 tty_ldiscs[disc] = new_ldisc;
38327 new_ldisc->num = disc;
38328- new_ldisc->refcount = 0;
38329+ atomic_set(&new_ldisc->refcount, 0);
38330 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38331
38332 return ret;
38333@@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
38334 return -EINVAL;
38335
38336 spin_lock_irqsave(&tty_ldisc_lock, flags);
38337- if (tty_ldiscs[disc]->refcount)
38338+ if (atomic_read(&tty_ldiscs[disc]->refcount))
38339 ret = -EBUSY;
38340 else
38341 tty_ldiscs[disc] = NULL;
38342@@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38343 if (ldops) {
38344 ret = ERR_PTR(-EAGAIN);
38345 if (try_module_get(ldops->owner)) {
38346- ldops->refcount++;
38347+ atomic_inc(&ldops->refcount);
38348 ret = ldops;
38349 }
38350 }
38351@@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38352 unsigned long flags;
38353
38354 spin_lock_irqsave(&tty_ldisc_lock, flags);
38355- ldops->refcount--;
38356+ atomic_dec(&ldops->refcount);
38357 module_put(ldops->owner);
38358 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38359 }
38360diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38361index a605549..6bd3c96 100644
38362--- a/drivers/tty/vt/keyboard.c
38363+++ b/drivers/tty/vt/keyboard.c
38364@@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38365 kbd->kbdmode == VC_OFF) &&
38366 value != KVAL(K_SAK))
38367 return; /* SAK is allowed even in raw mode */
38368+
38369+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38370+ {
38371+ void *func = fn_handler[value];
38372+ if (func == fn_show_state || func == fn_show_ptregs ||
38373+ func == fn_show_mem)
38374+ return;
38375+ }
38376+#endif
38377+
38378 fn_handler[value](vc);
38379 }
38380
38381diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
38382index 65447c5..0526f0a 100644
38383--- a/drivers/tty/vt/vt_ioctl.c
38384+++ b/drivers/tty/vt/vt_ioctl.c
38385@@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38386 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38387 return -EFAULT;
38388
38389- if (!capable(CAP_SYS_TTY_CONFIG))
38390- perm = 0;
38391-
38392 switch (cmd) {
38393 case KDGKBENT:
38394 key_map = key_maps[s];
38395@@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38396 val = (i ? K_HOLE : K_NOSUCHMAP);
38397 return put_user(val, &user_kbe->kb_value);
38398 case KDSKBENT:
38399+ if (!capable(CAP_SYS_TTY_CONFIG))
38400+ perm = 0;
38401+
38402 if (!perm)
38403 return -EPERM;
38404 if (!i && v == K_NOSUCHMAP) {
38405@@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38406 int i, j, k;
38407 int ret;
38408
38409- if (!capable(CAP_SYS_TTY_CONFIG))
38410- perm = 0;
38411-
38412 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38413 if (!kbs) {
38414 ret = -ENOMEM;
38415@@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38416 kfree(kbs);
38417 return ((p && *p) ? -EOVERFLOW : 0);
38418 case KDSKBSENT:
38419+ if (!capable(CAP_SYS_TTY_CONFIG))
38420+ perm = 0;
38421+
38422 if (!perm) {
38423 ret = -EPERM;
38424 goto reterr;
38425diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38426index a783d53..cb30d94 100644
38427--- a/drivers/uio/uio.c
38428+++ b/drivers/uio/uio.c
38429@@ -25,6 +25,7 @@
38430 #include <linux/kobject.h>
38431 #include <linux/cdev.h>
38432 #include <linux/uio_driver.h>
38433+#include <asm/local.h>
38434
38435 #define UIO_MAX_DEVICES (1U << MINORBITS)
38436
38437@@ -32,10 +33,10 @@ struct uio_device {
38438 struct module *owner;
38439 struct device *dev;
38440 int minor;
38441- atomic_t event;
38442+ atomic_unchecked_t event;
38443 struct fasync_struct *async_queue;
38444 wait_queue_head_t wait;
38445- int vma_count;
38446+ local_t vma_count;
38447 struct uio_info *info;
38448 struct kobject *map_dir;
38449 struct kobject *portio_dir;
38450@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38451 struct device_attribute *attr, char *buf)
38452 {
38453 struct uio_device *idev = dev_get_drvdata(dev);
38454- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38455+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38456 }
38457
38458 static struct device_attribute uio_class_attributes[] = {
38459@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38460 {
38461 struct uio_device *idev = info->uio_dev;
38462
38463- atomic_inc(&idev->event);
38464+ atomic_inc_unchecked(&idev->event);
38465 wake_up_interruptible(&idev->wait);
38466 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38467 }
38468@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38469 }
38470
38471 listener->dev = idev;
38472- listener->event_count = atomic_read(&idev->event);
38473+ listener->event_count = atomic_read_unchecked(&idev->event);
38474 filep->private_data = listener;
38475
38476 if (idev->info->open) {
38477@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38478 return -EIO;
38479
38480 poll_wait(filep, &idev->wait, wait);
38481- if (listener->event_count != atomic_read(&idev->event))
38482+ if (listener->event_count != atomic_read_unchecked(&idev->event))
38483 return POLLIN | POLLRDNORM;
38484 return 0;
38485 }
38486@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38487 do {
38488 set_current_state(TASK_INTERRUPTIBLE);
38489
38490- event_count = atomic_read(&idev->event);
38491+ event_count = atomic_read_unchecked(&idev->event);
38492 if (event_count != listener->event_count) {
38493 if (copy_to_user(buf, &event_count, count))
38494 retval = -EFAULT;
38495@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38496 static void uio_vma_open(struct vm_area_struct *vma)
38497 {
38498 struct uio_device *idev = vma->vm_private_data;
38499- idev->vma_count++;
38500+ local_inc(&idev->vma_count);
38501 }
38502
38503 static void uio_vma_close(struct vm_area_struct *vma)
38504 {
38505 struct uio_device *idev = vma->vm_private_data;
38506- idev->vma_count--;
38507+ local_dec(&idev->vma_count);
38508 }
38509
38510 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38511@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38512 idev->owner = owner;
38513 idev->info = info;
38514 init_waitqueue_head(&idev->wait);
38515- atomic_set(&idev->event, 0);
38516+ atomic_set_unchecked(&idev->event, 0);
38517
38518 ret = uio_get_minor(idev);
38519 if (ret)
38520diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38521index 98b89fe..aff824e 100644
38522--- a/drivers/usb/atm/cxacru.c
38523+++ b/drivers/usb/atm/cxacru.c
38524@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38525 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38526 if (ret < 2)
38527 return -EINVAL;
38528- if (index < 0 || index > 0x7f)
38529+ if (index > 0x7f)
38530 return -EINVAL;
38531 pos += tmp;
38532
38533diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38534index d3448ca..d2864ca 100644
38535--- a/drivers/usb/atm/usbatm.c
38536+++ b/drivers/usb/atm/usbatm.c
38537@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38538 if (printk_ratelimit())
38539 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38540 __func__, vpi, vci);
38541- atomic_inc(&vcc->stats->rx_err);
38542+ atomic_inc_unchecked(&vcc->stats->rx_err);
38543 return;
38544 }
38545
38546@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38547 if (length > ATM_MAX_AAL5_PDU) {
38548 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38549 __func__, length, vcc);
38550- atomic_inc(&vcc->stats->rx_err);
38551+ atomic_inc_unchecked(&vcc->stats->rx_err);
38552 goto out;
38553 }
38554
38555@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38556 if (sarb->len < pdu_length) {
38557 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38558 __func__, pdu_length, sarb->len, vcc);
38559- atomic_inc(&vcc->stats->rx_err);
38560+ atomic_inc_unchecked(&vcc->stats->rx_err);
38561 goto out;
38562 }
38563
38564 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38565 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38566 __func__, vcc);
38567- atomic_inc(&vcc->stats->rx_err);
38568+ atomic_inc_unchecked(&vcc->stats->rx_err);
38569 goto out;
38570 }
38571
38572@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38573 if (printk_ratelimit())
38574 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38575 __func__, length);
38576- atomic_inc(&vcc->stats->rx_drop);
38577+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38578 goto out;
38579 }
38580
38581@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38582
38583 vcc->push(vcc, skb);
38584
38585- atomic_inc(&vcc->stats->rx);
38586+ atomic_inc_unchecked(&vcc->stats->rx);
38587 out:
38588 skb_trim(sarb, 0);
38589 }
38590@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38591 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38592
38593 usbatm_pop(vcc, skb);
38594- atomic_inc(&vcc->stats->tx);
38595+ atomic_inc_unchecked(&vcc->stats->tx);
38596
38597 skb = skb_dequeue(&instance->sndqueue);
38598 }
38599@@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38600 if (!left--)
38601 return sprintf(page,
38602 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38603- atomic_read(&atm_dev->stats.aal5.tx),
38604- atomic_read(&atm_dev->stats.aal5.tx_err),
38605- atomic_read(&atm_dev->stats.aal5.rx),
38606- atomic_read(&atm_dev->stats.aal5.rx_err),
38607- atomic_read(&atm_dev->stats.aal5.rx_drop));
38608+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38609+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38610+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38611+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38612+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38613
38614 if (!left--) {
38615 if (instance->disconnected)
38616diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38617index d956965..4179a77 100644
38618--- a/drivers/usb/core/devices.c
38619+++ b/drivers/usb/core/devices.c
38620@@ -126,7 +126,7 @@ static const char format_endpt[] =
38621 * time it gets called.
38622 */
38623 static struct device_connect_event {
38624- atomic_t count;
38625+ atomic_unchecked_t count;
38626 wait_queue_head_t wait;
38627 } device_event = {
38628 .count = ATOMIC_INIT(1),
38629@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38630
38631 void usbfs_conn_disc_event(void)
38632 {
38633- atomic_add(2, &device_event.count);
38634+ atomic_add_unchecked(2, &device_event.count);
38635 wake_up(&device_event.wait);
38636 }
38637
38638@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38639
38640 poll_wait(file, &device_event.wait, wait);
38641
38642- event_count = atomic_read(&device_event.count);
38643+ event_count = atomic_read_unchecked(&device_event.count);
38644 if (file->f_version != event_count) {
38645 file->f_version = event_count;
38646 return POLLIN | POLLRDNORM;
38647diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38648index 1fc8f12..20647c1 100644
38649--- a/drivers/usb/early/ehci-dbgp.c
38650+++ b/drivers/usb/early/ehci-dbgp.c
38651@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38652
38653 #ifdef CONFIG_KGDB
38654 static struct kgdb_io kgdbdbgp_io_ops;
38655-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38656+static struct kgdb_io kgdbdbgp_io_ops_console;
38657+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38658 #else
38659 #define dbgp_kgdb_mode (0)
38660 #endif
38661@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38662 .write_char = kgdbdbgp_write_char,
38663 };
38664
38665+static struct kgdb_io kgdbdbgp_io_ops_console = {
38666+ .name = "kgdbdbgp",
38667+ .read_char = kgdbdbgp_read_char,
38668+ .write_char = kgdbdbgp_write_char,
38669+ .is_console = 1
38670+};
38671+
38672 static int kgdbdbgp_wait_time;
38673
38674 static int __init kgdbdbgp_parse_config(char *str)
38675@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38676 ptr++;
38677 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38678 }
38679- kgdb_register_io_module(&kgdbdbgp_io_ops);
38680- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38681+ if (early_dbgp_console.index != -1)
38682+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38683+ else
38684+ kgdb_register_io_module(&kgdbdbgp_io_ops);
38685
38686 return 0;
38687 }
38688diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38689index d6bea3e..60b250e 100644
38690--- a/drivers/usb/wusbcore/wa-hc.h
38691+++ b/drivers/usb/wusbcore/wa-hc.h
38692@@ -192,7 +192,7 @@ struct wahc {
38693 struct list_head xfer_delayed_list;
38694 spinlock_t xfer_list_lock;
38695 struct work_struct xfer_work;
38696- atomic_t xfer_id_count;
38697+ atomic_unchecked_t xfer_id_count;
38698 };
38699
38700
38701@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38702 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38703 spin_lock_init(&wa->xfer_list_lock);
38704 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38705- atomic_set(&wa->xfer_id_count, 1);
38706+ atomic_set_unchecked(&wa->xfer_id_count, 1);
38707 }
38708
38709 /**
38710diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38711index 57c01ab..8a05959 100644
38712--- a/drivers/usb/wusbcore/wa-xfer.c
38713+++ b/drivers/usb/wusbcore/wa-xfer.c
38714@@ -296,7 +296,7 @@ out:
38715 */
38716 static void wa_xfer_id_init(struct wa_xfer *xfer)
38717 {
38718- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38719+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38720 }
38721
38722 /*
38723diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38724index c14c42b..f955cc2 100644
38725--- a/drivers/vhost/vhost.c
38726+++ b/drivers/vhost/vhost.c
38727@@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38728 return 0;
38729 }
38730
38731-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38732+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38733 {
38734 struct file *eventfp, *filep = NULL,
38735 *pollstart = NULL, *pollstop = NULL;
38736diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38737index b0b2ac3..89a4399 100644
38738--- a/drivers/video/aty/aty128fb.c
38739+++ b/drivers/video/aty/aty128fb.c
38740@@ -148,7 +148,7 @@ enum {
38741 };
38742
38743 /* Must match above enum */
38744-static const char *r128_family[] __devinitdata = {
38745+static const char *r128_family[] __devinitconst = {
38746 "AGP",
38747 "PCI",
38748 "PRO AGP",
38749diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38750index 5c3960d..15cf8fc 100644
38751--- a/drivers/video/fbcmap.c
38752+++ b/drivers/video/fbcmap.c
38753@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38754 rc = -ENODEV;
38755 goto out;
38756 }
38757- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38758- !info->fbops->fb_setcmap)) {
38759+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38760 rc = -EINVAL;
38761 goto out1;
38762 }
38763diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38764index c6ce416..3b9b642 100644
38765--- a/drivers/video/fbmem.c
38766+++ b/drivers/video/fbmem.c
38767@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38768 image->dx += image->width + 8;
38769 }
38770 } else if (rotate == FB_ROTATE_UD) {
38771- for (x = 0; x < num && image->dx >= 0; x++) {
38772+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38773 info->fbops->fb_imageblit(info, image);
38774 image->dx -= image->width + 8;
38775 }
38776@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38777 image->dy += image->height + 8;
38778 }
38779 } else if (rotate == FB_ROTATE_CCW) {
38780- for (x = 0; x < num && image->dy >= 0; x++) {
38781+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38782 info->fbops->fb_imageblit(info, image);
38783 image->dy -= image->height + 8;
38784 }
38785@@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38786 return -EFAULT;
38787 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38788 return -EINVAL;
38789- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38790+ if (con2fb.framebuffer >= FB_MAX)
38791 return -EINVAL;
38792 if (!registered_fb[con2fb.framebuffer])
38793 request_module("fb%d", con2fb.framebuffer);
38794diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38795index 5a5d092..265c5ed 100644
38796--- a/drivers/video/geode/gx1fb_core.c
38797+++ b/drivers/video/geode/gx1fb_core.c
38798@@ -29,7 +29,7 @@ static int crt_option = 1;
38799 static char panel_option[32] = "";
38800
38801 /* Modes relevant to the GX1 (taken from modedb.c) */
38802-static const struct fb_videomode __devinitdata gx1_modedb[] = {
38803+static const struct fb_videomode __devinitconst gx1_modedb[] = {
38804 /* 640x480-60 VESA */
38805 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38806 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38807diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38808index 0fad23f..0e9afa4 100644
38809--- a/drivers/video/gxt4500.c
38810+++ b/drivers/video/gxt4500.c
38811@@ -156,7 +156,7 @@ struct gxt4500_par {
38812 static char *mode_option;
38813
38814 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38815-static const struct fb_videomode defaultmode __devinitdata = {
38816+static const struct fb_videomode defaultmode __devinitconst = {
38817 .refresh = 60,
38818 .xres = 1280,
38819 .yres = 1024,
38820@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38821 return 0;
38822 }
38823
38824-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38825+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38826 .id = "IBM GXT4500P",
38827 .type = FB_TYPE_PACKED_PIXELS,
38828 .visual = FB_VISUAL_PSEUDOCOLOR,
38829diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38830index 7672d2e..b56437f 100644
38831--- a/drivers/video/i810/i810_accel.c
38832+++ b/drivers/video/i810/i810_accel.c
38833@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38834 }
38835 }
38836 printk("ringbuffer lockup!!!\n");
38837+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38838 i810_report_error(mmio);
38839 par->dev_flags |= LOCKUP;
38840 info->pixmap.scan_align = 1;
38841diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38842index b83f361..2b05a91 100644
38843--- a/drivers/video/i810/i810_main.c
38844+++ b/drivers/video/i810/i810_main.c
38845@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38846 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38847
38848 /* PCI */
38849-static const char *i810_pci_list[] __devinitdata = {
38850+static const char *i810_pci_list[] __devinitconst = {
38851 "Intel(R) 810 Framebuffer Device" ,
38852 "Intel(R) 810-DC100 Framebuffer Device" ,
38853 "Intel(R) 810E Framebuffer Device" ,
38854diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38855index de36693..3c63fc2 100644
38856--- a/drivers/video/jz4740_fb.c
38857+++ b/drivers/video/jz4740_fb.c
38858@@ -136,7 +136,7 @@ struct jzfb {
38859 uint32_t pseudo_palette[16];
38860 };
38861
38862-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38863+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38864 .id = "JZ4740 FB",
38865 .type = FB_TYPE_PACKED_PIXELS,
38866 .visual = FB_VISUAL_TRUECOLOR,
38867diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38868index 3c14e43..eafa544 100644
38869--- a/drivers/video/logo/logo_linux_clut224.ppm
38870+++ b/drivers/video/logo/logo_linux_clut224.ppm
38871@@ -1,1604 +1,1123 @@
38872 P3
38873-# Standard 224-color Linux logo
38874 80 80
38875 255
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 0 0 0
38885- 6 6 6 6 6 6 10 10 10 10 10 10
38886- 10 10 10 6 6 6 6 6 6 6 6 6
38887- 0 0 0 0 0 0 0 0 0 0 0 0
38888- 0 0 0 0 0 0 0 0 0 0 0 0
38889- 0 0 0 0 0 0 0 0 0 0 0 0
38890- 0 0 0 0 0 0 0 0 0 0 0 0
38891- 0 0 0 0 0 0 0 0 0 0 0 0
38892- 0 0 0 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 6 6 6 10 10 10 14 14 14
38905- 22 22 22 26 26 26 30 30 30 34 34 34
38906- 30 30 30 30 30 30 26 26 26 18 18 18
38907- 14 14 14 10 10 10 6 6 6 0 0 0
38908- 0 0 0 0 0 0 0 0 0 0 0 0
38909- 0 0 0 0 0 0 0 0 0 0 0 0
38910- 0 0 0 0 0 0 0 0 0 0 0 0
38911- 0 0 0 0 0 0 0 0 0 0 0 0
38912- 0 0 0 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 1 0 0 1 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- 6 6 6 14 14 14 26 26 26 42 42 42
38925- 54 54 54 66 66 66 78 78 78 78 78 78
38926- 78 78 78 74 74 74 66 66 66 54 54 54
38927- 42 42 42 26 26 26 18 18 18 10 10 10
38928- 6 6 6 0 0 0 0 0 0 0 0 0
38929- 0 0 0 0 0 0 0 0 0 0 0 0
38930- 0 0 0 0 0 0 0 0 0 0 0 0
38931- 0 0 0 0 0 0 0 0 0 0 0 0
38932- 0 0 0 0 0 0 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 1 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 10 10 10
38944- 22 22 22 42 42 42 66 66 66 86 86 86
38945- 66 66 66 38 38 38 38 38 38 22 22 22
38946- 26 26 26 34 34 34 54 54 54 66 66 66
38947- 86 86 86 70 70 70 46 46 46 26 26 26
38948- 14 14 14 6 6 6 0 0 0 0 0 0
38949- 0 0 0 0 0 0 0 0 0 0 0 0
38950- 0 0 0 0 0 0 0 0 0 0 0 0
38951- 0 0 0 0 0 0 0 0 0 0 0 0
38952- 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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 10 10 10 26 26 26
38964- 50 50 50 82 82 82 58 58 58 6 6 6
38965- 2 2 6 2 2 6 2 2 6 2 2 6
38966- 2 2 6 2 2 6 2 2 6 2 2 6
38967- 6 6 6 54 54 54 86 86 86 66 66 66
38968- 38 38 38 18 18 18 6 6 6 0 0 0
38969- 0 0 0 0 0 0 0 0 0 0 0 0
38970- 0 0 0 0 0 0 0 0 0 0 0 0
38971- 0 0 0 0 0 0 0 0 0 0 0 0
38972- 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
38984- 78 78 78 34 34 34 2 2 6 2 2 6
38985- 2 2 6 2 2 6 2 2 6 2 2 6
38986- 2 2 6 2 2 6 2 2 6 2 2 6
38987- 2 2 6 2 2 6 6 6 6 70 70 70
38988- 78 78 78 46 46 46 22 22 22 6 6 6
38989- 0 0 0 0 0 0 0 0 0 0 0 0
38990- 0 0 0 0 0 0 0 0 0 0 0 0
38991- 0 0 0 0 0 0 0 0 0 0 0 0
38992- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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- 6 6 6 18 18 18 42 42 42 82 82 82
39004- 26 26 26 2 2 6 2 2 6 2 2 6
39005- 2 2 6 2 2 6 2 2 6 2 2 6
39006- 2 2 6 2 2 6 2 2 6 14 14 14
39007- 46 46 46 34 34 34 6 6 6 2 2 6
39008- 42 42 42 78 78 78 42 42 42 18 18 18
39009- 6 6 6 0 0 0 0 0 0 0 0 0
39010- 0 0 0 0 0 0 0 0 0 0 0 0
39011- 0 0 0 0 0 0 0 0 0 0 0 0
39012- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0 0 0 1 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- 10 10 10 30 30 30 66 66 66 58 58 58
39024- 2 2 6 2 2 6 2 2 6 2 2 6
39025- 2 2 6 2 2 6 2 2 6 2 2 6
39026- 2 2 6 2 2 6 2 2 6 26 26 26
39027- 86 86 86 101 101 101 46 46 46 10 10 10
39028- 2 2 6 58 58 58 70 70 70 34 34 34
39029- 10 10 10 0 0 0 0 0 0 0 0 0
39030- 0 0 0 0 0 0 0 0 0 0 0 0
39031- 0 0 0 0 0 0 0 0 0 0 0 0
39032- 0 0 0 0 0 0 0 0 0 0 0 0
39033- 0 0 0 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 1 0 0 1 0 0 1 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- 14 14 14 42 42 42 86 86 86 10 10 10
39044- 2 2 6 2 2 6 2 2 6 2 2 6
39045- 2 2 6 2 2 6 2 2 6 2 2 6
39046- 2 2 6 2 2 6 2 2 6 30 30 30
39047- 94 94 94 94 94 94 58 58 58 26 26 26
39048- 2 2 6 6 6 6 78 78 78 54 54 54
39049- 22 22 22 6 6 6 0 0 0 0 0 0
39050- 0 0 0 0 0 0 0 0 0 0 0 0
39051- 0 0 0 0 0 0 0 0 0 0 0 0
39052- 0 0 0 0 0 0 0 0 0 0 0 0
39053- 0 0 0 0 0 0 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 6 6 6
39063- 22 22 22 62 62 62 62 62 62 2 2 6
39064- 2 2 6 2 2 6 2 2 6 2 2 6
39065- 2 2 6 2 2 6 2 2 6 2 2 6
39066- 2 2 6 2 2 6 2 2 6 26 26 26
39067- 54 54 54 38 38 38 18 18 18 10 10 10
39068- 2 2 6 2 2 6 34 34 34 82 82 82
39069- 38 38 38 14 14 14 0 0 0 0 0 0
39070- 0 0 0 0 0 0 0 0 0 0 0 0
39071- 0 0 0 0 0 0 0 0 0 0 0 0
39072- 0 0 0 0 0 0 0 0 0 0 0 0
39073- 0 0 0 0 0 0 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 1 0 0 1 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 6 6 6
39083- 30 30 30 78 78 78 30 30 30 2 2 6
39084- 2 2 6 2 2 6 2 2 6 2 2 6
39085- 2 2 6 2 2 6 2 2 6 2 2 6
39086- 2 2 6 2 2 6 2 2 6 10 10 10
39087- 10 10 10 2 2 6 2 2 6 2 2 6
39088- 2 2 6 2 2 6 2 2 6 78 78 78
39089- 50 50 50 18 18 18 6 6 6 0 0 0
39090- 0 0 0 0 0 0 0 0 0 0 0 0
39091- 0 0 0 0 0 0 0 0 0 0 0 0
39092- 0 0 0 0 0 0 0 0 0 0 0 0
39093- 0 0 0 0 0 0 0 0 0 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 1 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 10 10 10
39103- 38 38 38 86 86 86 14 14 14 2 2 6
39104- 2 2 6 2 2 6 2 2 6 2 2 6
39105- 2 2 6 2 2 6 2 2 6 2 2 6
39106- 2 2 6 2 2 6 2 2 6 2 2 6
39107- 2 2 6 2 2 6 2 2 6 2 2 6
39108- 2 2 6 2 2 6 2 2 6 54 54 54
39109- 66 66 66 26 26 26 6 6 6 0 0 0
39110- 0 0 0 0 0 0 0 0 0 0 0 0
39111- 0 0 0 0 0 0 0 0 0 0 0 0
39112- 0 0 0 0 0 0 0 0 0 0 0 0
39113- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 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 14 14 14
39123- 42 42 42 82 82 82 2 2 6 2 2 6
39124- 2 2 6 6 6 6 10 10 10 2 2 6
39125- 2 2 6 2 2 6 2 2 6 2 2 6
39126- 2 2 6 2 2 6 2 2 6 6 6 6
39127- 14 14 14 10 10 10 2 2 6 2 2 6
39128- 2 2 6 2 2 6 2 2 6 18 18 18
39129- 82 82 82 34 34 34 10 10 10 0 0 0
39130- 0 0 0 0 0 0 0 0 0 0 0 0
39131- 0 0 0 0 0 0 0 0 0 0 0 0
39132- 0 0 0 0 0 0 0 0 0 0 0 0
39133- 0 0 0 0 0 0 0 0 0 0 0 0
39134- 0 0 0 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 1 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 14 14 14
39143- 46 46 46 86 86 86 2 2 6 2 2 6
39144- 6 6 6 6 6 6 22 22 22 34 34 34
39145- 6 6 6 2 2 6 2 2 6 2 2 6
39146- 2 2 6 2 2 6 18 18 18 34 34 34
39147- 10 10 10 50 50 50 22 22 22 2 2 6
39148- 2 2 6 2 2 6 2 2 6 10 10 10
39149- 86 86 86 42 42 42 14 14 14 0 0 0
39150- 0 0 0 0 0 0 0 0 0 0 0 0
39151- 0 0 0 0 0 0 0 0 0 0 0 0
39152- 0 0 0 0 0 0 0 0 0 0 0 0
39153- 0 0 0 0 0 0 0 0 0 0 0 0
39154- 0 0 0 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 1 0 0 1 0 0 1 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 14 14 14
39163- 46 46 46 86 86 86 2 2 6 2 2 6
39164- 38 38 38 116 116 116 94 94 94 22 22 22
39165- 22 22 22 2 2 6 2 2 6 2 2 6
39166- 14 14 14 86 86 86 138 138 138 162 162 162
39167-154 154 154 38 38 38 26 26 26 6 6 6
39168- 2 2 6 2 2 6 2 2 6 2 2 6
39169- 86 86 86 46 46 46 14 14 14 0 0 0
39170- 0 0 0 0 0 0 0 0 0 0 0 0
39171- 0 0 0 0 0 0 0 0 0 0 0 0
39172- 0 0 0 0 0 0 0 0 0 0 0 0
39173- 0 0 0 0 0 0 0 0 0 0 0 0
39174- 0 0 0 0 0 0 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 14 14 14
39183- 46 46 46 86 86 86 2 2 6 14 14 14
39184-134 134 134 198 198 198 195 195 195 116 116 116
39185- 10 10 10 2 2 6 2 2 6 6 6 6
39186-101 98 89 187 187 187 210 210 210 218 218 218
39187-214 214 214 134 134 134 14 14 14 6 6 6
39188- 2 2 6 2 2 6 2 2 6 2 2 6
39189- 86 86 86 50 50 50 18 18 18 6 6 6
39190- 0 0 0 0 0 0 0 0 0 0 0 0
39191- 0 0 0 0 0 0 0 0 0 0 0 0
39192- 0 0 0 0 0 0 0 0 0 0 0 0
39193- 0 0 0 0 0 0 0 0 0 0 0 0
39194- 0 0 0 0 0 0 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 1 0 0 0
39197- 0 0 1 0 0 1 0 0 1 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 14 14 14
39203- 46 46 46 86 86 86 2 2 6 54 54 54
39204-218 218 218 195 195 195 226 226 226 246 246 246
39205- 58 58 58 2 2 6 2 2 6 30 30 30
39206-210 210 210 253 253 253 174 174 174 123 123 123
39207-221 221 221 234 234 234 74 74 74 2 2 6
39208- 2 2 6 2 2 6 2 2 6 2 2 6
39209- 70 70 70 58 58 58 22 22 22 6 6 6
39210- 0 0 0 0 0 0 0 0 0 0 0 0
39211- 0 0 0 0 0 0 0 0 0 0 0 0
39212- 0 0 0 0 0 0 0 0 0 0 0 0
39213- 0 0 0 0 0 0 0 0 0 0 0 0
39214- 0 0 0 0 0 0 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- 46 46 46 82 82 82 2 2 6 106 106 106
39224-170 170 170 26 26 26 86 86 86 226 226 226
39225-123 123 123 10 10 10 14 14 14 46 46 46
39226-231 231 231 190 190 190 6 6 6 70 70 70
39227- 90 90 90 238 238 238 158 158 158 2 2 6
39228- 2 2 6 2 2 6 2 2 6 2 2 6
39229- 70 70 70 58 58 58 22 22 22 6 6 6
39230- 0 0 0 0 0 0 0 0 0 0 0 0
39231- 0 0 0 0 0 0 0 0 0 0 0 0
39232- 0 0 0 0 0 0 0 0 0 0 0 0
39233- 0 0 0 0 0 0 0 0 0 0 0 0
39234- 0 0 0 0 0 0 0 0 0 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 1 0 0 0
39237- 0 0 1 0 0 1 0 0 1 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 0 0 0 14 14 14
39243- 42 42 42 86 86 86 6 6 6 116 116 116
39244-106 106 106 6 6 6 70 70 70 149 149 149
39245-128 128 128 18 18 18 38 38 38 54 54 54
39246-221 221 221 106 106 106 2 2 6 14 14 14
39247- 46 46 46 190 190 190 198 198 198 2 2 6
39248- 2 2 6 2 2 6 2 2 6 2 2 6
39249- 74 74 74 62 62 62 22 22 22 6 6 6
39250- 0 0 0 0 0 0 0 0 0 0 0 0
39251- 0 0 0 0 0 0 0 0 0 0 0 0
39252- 0 0 0 0 0 0 0 0 0 0 0 0
39253- 0 0 0 0 0 0 0 0 0 0 0 0
39254- 0 0 0 0 0 0 0 0 0 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 1 0 0 0
39257- 0 0 1 0 0 0 0 0 1 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 0 0 0 14 14 14
39263- 42 42 42 94 94 94 14 14 14 101 101 101
39264-128 128 128 2 2 6 18 18 18 116 116 116
39265-118 98 46 121 92 8 121 92 8 98 78 10
39266-162 162 162 106 106 106 2 2 6 2 2 6
39267- 2 2 6 195 195 195 195 195 195 6 6 6
39268- 2 2 6 2 2 6 2 2 6 2 2 6
39269- 74 74 74 62 62 62 22 22 22 6 6 6
39270- 0 0 0 0 0 0 0 0 0 0 0 0
39271- 0 0 0 0 0 0 0 0 0 0 0 0
39272- 0 0 0 0 0 0 0 0 0 0 0 0
39273- 0 0 0 0 0 0 0 0 0 0 0 0
39274- 0 0 0 0 0 0 0 0 0 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 1 0 0 1
39277- 0 0 1 0 0 0 0 0 1 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 0 0 0 0 0 0 10 10 10
39283- 38 38 38 90 90 90 14 14 14 58 58 58
39284-210 210 210 26 26 26 54 38 6 154 114 10
39285-226 170 11 236 186 11 225 175 15 184 144 12
39286-215 174 15 175 146 61 37 26 9 2 2 6
39287- 70 70 70 246 246 246 138 138 138 2 2 6
39288- 2 2 6 2 2 6 2 2 6 2 2 6
39289- 70 70 70 66 66 66 26 26 26 6 6 6
39290- 0 0 0 0 0 0 0 0 0 0 0 0
39291- 0 0 0 0 0 0 0 0 0 0 0 0
39292- 0 0 0 0 0 0 0 0 0 0 0 0
39293- 0 0 0 0 0 0 0 0 0 0 0 0
39294- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0 0 0 10 10 10
39303- 38 38 38 86 86 86 14 14 14 10 10 10
39304-195 195 195 188 164 115 192 133 9 225 175 15
39305-239 182 13 234 190 10 232 195 16 232 200 30
39306-245 207 45 241 208 19 232 195 16 184 144 12
39307-218 194 134 211 206 186 42 42 42 2 2 6
39308- 2 2 6 2 2 6 2 2 6 2 2 6
39309- 50 50 50 74 74 74 30 30 30 6 6 6
39310- 0 0 0 0 0 0 0 0 0 0 0 0
39311- 0 0 0 0 0 0 0 0 0 0 0 0
39312- 0 0 0 0 0 0 0 0 0 0 0 0
39313- 0 0 0 0 0 0 0 0 0 0 0 0
39314- 0 0 0 0 0 0 0 0 0 0 0 0
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- 0 0 0 0 0 0 0 0 0 10 10 10
39323- 34 34 34 86 86 86 14 14 14 2 2 6
39324-121 87 25 192 133 9 219 162 10 239 182 13
39325-236 186 11 232 195 16 241 208 19 244 214 54
39326-246 218 60 246 218 38 246 215 20 241 208 19
39327-241 208 19 226 184 13 121 87 25 2 2 6
39328- 2 2 6 2 2 6 2 2 6 2 2 6
39329- 50 50 50 82 82 82 34 34 34 10 10 10
39330- 0 0 0 0 0 0 0 0 0 0 0 0
39331- 0 0 0 0 0 0 0 0 0 0 0 0
39332- 0 0 0 0 0 0 0 0 0 0 0 0
39333- 0 0 0 0 0 0 0 0 0 0 0 0
39334- 0 0 0 0 0 0 0 0 0 0 0 0
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- 0 0 0 0 0 0 0 0 0 10 10 10
39343- 34 34 34 82 82 82 30 30 30 61 42 6
39344-180 123 7 206 145 10 230 174 11 239 182 13
39345-234 190 10 238 202 15 241 208 19 246 218 74
39346-246 218 38 246 215 20 246 215 20 246 215 20
39347-226 184 13 215 174 15 184 144 12 6 6 6
39348- 2 2 6 2 2 6 2 2 6 2 2 6
39349- 26 26 26 94 94 94 42 42 42 14 14 14
39350- 0 0 0 0 0 0 0 0 0 0 0 0
39351- 0 0 0 0 0 0 0 0 0 0 0 0
39352- 0 0 0 0 0 0 0 0 0 0 0 0
39353- 0 0 0 0 0 0 0 0 0 0 0 0
39354- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0
39362- 0 0 0 0 0 0 0 0 0 10 10 10
39363- 30 30 30 78 78 78 50 50 50 104 69 6
39364-192 133 9 216 158 10 236 178 12 236 186 11
39365-232 195 16 241 208 19 244 214 54 245 215 43
39366-246 215 20 246 215 20 241 208 19 198 155 10
39367-200 144 11 216 158 10 156 118 10 2 2 6
39368- 2 2 6 2 2 6 2 2 6 2 2 6
39369- 6 6 6 90 90 90 54 54 54 18 18 18
39370- 6 6 6 0 0 0 0 0 0 0 0 0
39371- 0 0 0 0 0 0 0 0 0 0 0 0
39372- 0 0 0 0 0 0 0 0 0 0 0 0
39373- 0 0 0 0 0 0 0 0 0 0 0 0
39374- 0 0 0 0 0 0 0 0 0 0 0 0
39375- 0 0 0 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 0 0 0
39382- 0 0 0 0 0 0 0 0 0 10 10 10
39383- 30 30 30 78 78 78 46 46 46 22 22 22
39384-137 92 6 210 162 10 239 182 13 238 190 10
39385-238 202 15 241 208 19 246 215 20 246 215 20
39386-241 208 19 203 166 17 185 133 11 210 150 10
39387-216 158 10 210 150 10 102 78 10 2 2 6
39388- 6 6 6 54 54 54 14 14 14 2 2 6
39389- 2 2 6 62 62 62 74 74 74 30 30 30
39390- 10 10 10 0 0 0 0 0 0 0 0 0
39391- 0 0 0 0 0 0 0 0 0 0 0 0
39392- 0 0 0 0 0 0 0 0 0 0 0 0
39393- 0 0 0 0 0 0 0 0 0 0 0 0
39394- 0 0 0 0 0 0 0 0 0 0 0 0
39395- 0 0 0 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 0 0 0
39402- 0 0 0 0 0 0 0 0 0 10 10 10
39403- 34 34 34 78 78 78 50 50 50 6 6 6
39404- 94 70 30 139 102 15 190 146 13 226 184 13
39405-232 200 30 232 195 16 215 174 15 190 146 13
39406-168 122 10 192 133 9 210 150 10 213 154 11
39407-202 150 34 182 157 106 101 98 89 2 2 6
39408- 2 2 6 78 78 78 116 116 116 58 58 58
39409- 2 2 6 22 22 22 90 90 90 46 46 46
39410- 18 18 18 6 6 6 0 0 0 0 0 0
39411- 0 0 0 0 0 0 0 0 0 0 0 0
39412- 0 0 0 0 0 0 0 0 0 0 0 0
39413- 0 0 0 0 0 0 0 0 0 0 0 0
39414- 0 0 0 0 0 0 0 0 0 0 0 0
39415- 0 0 0 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 0 0 0 0 0 0
39422- 0 0 0 0 0 0 0 0 0 10 10 10
39423- 38 38 38 86 86 86 50 50 50 6 6 6
39424-128 128 128 174 154 114 156 107 11 168 122 10
39425-198 155 10 184 144 12 197 138 11 200 144 11
39426-206 145 10 206 145 10 197 138 11 188 164 115
39427-195 195 195 198 198 198 174 174 174 14 14 14
39428- 2 2 6 22 22 22 116 116 116 116 116 116
39429- 22 22 22 2 2 6 74 74 74 70 70 70
39430- 30 30 30 10 10 10 0 0 0 0 0 0
39431- 0 0 0 0 0 0 0 0 0 0 0 0
39432- 0 0 0 0 0 0 0 0 0 0 0 0
39433- 0 0 0 0 0 0 0 0 0 0 0 0
39434- 0 0 0 0 0 0 0 0 0 0 0 0
39435- 0 0 0 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 0 0 0 0 0 0
39442- 0 0 0 0 0 0 6 6 6 18 18 18
39443- 50 50 50 101 101 101 26 26 26 10 10 10
39444-138 138 138 190 190 190 174 154 114 156 107 11
39445-197 138 11 200 144 11 197 138 11 192 133 9
39446-180 123 7 190 142 34 190 178 144 187 187 187
39447-202 202 202 221 221 221 214 214 214 66 66 66
39448- 2 2 6 2 2 6 50 50 50 62 62 62
39449- 6 6 6 2 2 6 10 10 10 90 90 90
39450- 50 50 50 18 18 18 6 6 6 0 0 0
39451- 0 0 0 0 0 0 0 0 0 0 0 0
39452- 0 0 0 0 0 0 0 0 0 0 0 0
39453- 0 0 0 0 0 0 0 0 0 0 0 0
39454- 0 0 0 0 0 0 0 0 0 0 0 0
39455- 0 0 0 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 0 0 0 0 0 0
39462- 0 0 0 0 0 0 10 10 10 34 34 34
39463- 74 74 74 74 74 74 2 2 6 6 6 6
39464-144 144 144 198 198 198 190 190 190 178 166 146
39465-154 121 60 156 107 11 156 107 11 168 124 44
39466-174 154 114 187 187 187 190 190 190 210 210 210
39467-246 246 246 253 253 253 253 253 253 182 182 182
39468- 6 6 6 2 2 6 2 2 6 2 2 6
39469- 2 2 6 2 2 6 2 2 6 62 62 62
39470- 74 74 74 34 34 34 14 14 14 0 0 0
39471- 0 0 0 0 0 0 0 0 0 0 0 0
39472- 0 0 0 0 0 0 0 0 0 0 0 0
39473- 0 0 0 0 0 0 0 0 0 0 0 0
39474- 0 0 0 0 0 0 0 0 0 0 0 0
39475- 0 0 0 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 0 0 0 0 0 0
39482- 0 0 0 10 10 10 22 22 22 54 54 54
39483- 94 94 94 18 18 18 2 2 6 46 46 46
39484-234 234 234 221 221 221 190 190 190 190 190 190
39485-190 190 190 187 187 187 187 187 187 190 190 190
39486-190 190 190 195 195 195 214 214 214 242 242 242
39487-253 253 253 253 253 253 253 253 253 253 253 253
39488- 82 82 82 2 2 6 2 2 6 2 2 6
39489- 2 2 6 2 2 6 2 2 6 14 14 14
39490- 86 86 86 54 54 54 22 22 22 6 6 6
39491- 0 0 0 0 0 0 0 0 0 0 0 0
39492- 0 0 0 0 0 0 0 0 0 0 0 0
39493- 0 0 0 0 0 0 0 0 0 0 0 0
39494- 0 0 0 0 0 0 0 0 0 0 0 0
39495- 0 0 0 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 0 0 0
39501- 0 0 0 0 0 0 0 0 0 0 0 0
39502- 6 6 6 18 18 18 46 46 46 90 90 90
39503- 46 46 46 18 18 18 6 6 6 182 182 182
39504-253 253 253 246 246 246 206 206 206 190 190 190
39505-190 190 190 190 190 190 190 190 190 190 190 190
39506-206 206 206 231 231 231 250 250 250 253 253 253
39507-253 253 253 253 253 253 253 253 253 253 253 253
39508-202 202 202 14 14 14 2 2 6 2 2 6
39509- 2 2 6 2 2 6 2 2 6 2 2 6
39510- 42 42 42 86 86 86 42 42 42 18 18 18
39511- 6 6 6 0 0 0 0 0 0 0 0 0
39512- 0 0 0 0 0 0 0 0 0 0 0 0
39513- 0 0 0 0 0 0 0 0 0 0 0 0
39514- 0 0 0 0 0 0 0 0 0 0 0 0
39515- 0 0 0 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 0 0 0 0 0 0 0 0 0
39521- 0 0 0 0 0 0 0 0 0 6 6 6
39522- 14 14 14 38 38 38 74 74 74 66 66 66
39523- 2 2 6 6 6 6 90 90 90 250 250 250
39524-253 253 253 253 253 253 238 238 238 198 198 198
39525-190 190 190 190 190 190 195 195 195 221 221 221
39526-246 246 246 253 253 253 253 253 253 253 253 253
39527-253 253 253 253 253 253 253 253 253 253 253 253
39528-253 253 253 82 82 82 2 2 6 2 2 6
39529- 2 2 6 2 2 6 2 2 6 2 2 6
39530- 2 2 6 78 78 78 70 70 70 34 34 34
39531- 14 14 14 6 6 6 0 0 0 0 0 0
39532- 0 0 0 0 0 0 0 0 0 0 0 0
39533- 0 0 0 0 0 0 0 0 0 0 0 0
39534- 0 0 0 0 0 0 0 0 0 0 0 0
39535- 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
39541- 0 0 0 0 0 0 0 0 0 14 14 14
39542- 34 34 34 66 66 66 78 78 78 6 6 6
39543- 2 2 6 18 18 18 218 218 218 253 253 253
39544-253 253 253 253 253 253 253 253 253 246 246 246
39545-226 226 226 231 231 231 246 246 246 253 253 253
39546-253 253 253 253 253 253 253 253 253 253 253 253
39547-253 253 253 253 253 253 253 253 253 253 253 253
39548-253 253 253 178 178 178 2 2 6 2 2 6
39549- 2 2 6 2 2 6 2 2 6 2 2 6
39550- 2 2 6 18 18 18 90 90 90 62 62 62
39551- 30 30 30 10 10 10 0 0 0 0 0 0
39552- 0 0 0 0 0 0 0 0 0 0 0 0
39553- 0 0 0 0 0 0 0 0 0 0 0 0
39554- 0 0 0 0 0 0 0 0 0 0 0 0
39555- 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
39561- 0 0 0 0 0 0 10 10 10 26 26 26
39562- 58 58 58 90 90 90 18 18 18 2 2 6
39563- 2 2 6 110 110 110 253 253 253 253 253 253
39564-253 253 253 253 253 253 253 253 253 253 253 253
39565-250 250 250 253 253 253 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 231 231 231 18 18 18 2 2 6
39569- 2 2 6 2 2 6 2 2 6 2 2 6
39570- 2 2 6 2 2 6 18 18 18 94 94 94
39571- 54 54 54 26 26 26 10 10 10 0 0 0
39572- 0 0 0 0 0 0 0 0 0 0 0 0
39573- 0 0 0 0 0 0 0 0 0 0 0 0
39574- 0 0 0 0 0 0 0 0 0 0 0 0
39575- 0 0 0 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 0 0 0
39580- 0 0 0 0 0 0 0 0 0 0 0 0
39581- 0 0 0 6 6 6 22 22 22 50 50 50
39582- 90 90 90 26 26 26 2 2 6 2 2 6
39583- 14 14 14 195 195 195 250 250 250 253 253 253
39584-253 253 253 253 253 253 253 253 253 253 253 253
39585-253 253 253 253 253 253 253 253 253 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-250 250 250 242 242 242 54 54 54 2 2 6
39589- 2 2 6 2 2 6 2 2 6 2 2 6
39590- 2 2 6 2 2 6 2 2 6 38 38 38
39591- 86 86 86 50 50 50 22 22 22 6 6 6
39592- 0 0 0 0 0 0 0 0 0 0 0 0
39593- 0 0 0 0 0 0 0 0 0 0 0 0
39594- 0 0 0 0 0 0 0 0 0 0 0 0
39595- 0 0 0 0 0 0 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 0 0 0
39600- 0 0 0 0 0 0 0 0 0 0 0 0
39601- 6 6 6 14 14 14 38 38 38 82 82 82
39602- 34 34 34 2 2 6 2 2 6 2 2 6
39603- 42 42 42 195 195 195 246 246 246 253 253 253
39604-253 253 253 253 253 253 253 253 253 250 250 250
39605-242 242 242 242 242 242 250 250 250 253 253 253
39606-253 253 253 253 253 253 253 253 253 253 253 253
39607-253 253 253 250 250 250 246 246 246 238 238 238
39608-226 226 226 231 231 231 101 101 101 6 6 6
39609- 2 2 6 2 2 6 2 2 6 2 2 6
39610- 2 2 6 2 2 6 2 2 6 2 2 6
39611- 38 38 38 82 82 82 42 42 42 14 14 14
39612- 6 6 6 0 0 0 0 0 0 0 0 0
39613- 0 0 0 0 0 0 0 0 0 0 0 0
39614- 0 0 0 0 0 0 0 0 0 0 0 0
39615- 0 0 0 0 0 0 0 0 0 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 0 0 0
39620- 0 0 0 0 0 0 0 0 0 0 0 0
39621- 10 10 10 26 26 26 62 62 62 66 66 66
39622- 2 2 6 2 2 6 2 2 6 6 6 6
39623- 70 70 70 170 170 170 206 206 206 234 234 234
39624-246 246 246 250 250 250 250 250 250 238 238 238
39625-226 226 226 231 231 231 238 238 238 250 250 250
39626-250 250 250 250 250 250 246 246 246 231 231 231
39627-214 214 214 206 206 206 202 202 202 202 202 202
39628-198 198 198 202 202 202 182 182 182 18 18 18
39629- 2 2 6 2 2 6 2 2 6 2 2 6
39630- 2 2 6 2 2 6 2 2 6 2 2 6
39631- 2 2 6 62 62 62 66 66 66 30 30 30
39632- 10 10 10 0 0 0 0 0 0 0 0 0
39633- 0 0 0 0 0 0 0 0 0 0 0 0
39634- 0 0 0 0 0 0 0 0 0 0 0 0
39635- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0
39640- 0 0 0 0 0 0 0 0 0 0 0 0
39641- 14 14 14 42 42 42 82 82 82 18 18 18
39642- 2 2 6 2 2 6 2 2 6 10 10 10
39643- 94 94 94 182 182 182 218 218 218 242 242 242
39644-250 250 250 253 253 253 253 253 253 250 250 250
39645-234 234 234 253 253 253 253 253 253 253 253 253
39646-253 253 253 253 253 253 253 253 253 246 246 246
39647-238 238 238 226 226 226 210 210 210 202 202 202
39648-195 195 195 195 195 195 210 210 210 158 158 158
39649- 6 6 6 14 14 14 50 50 50 14 14 14
39650- 2 2 6 2 2 6 2 2 6 2 2 6
39651- 2 2 6 6 6 6 86 86 86 46 46 46
39652- 18 18 18 6 6 6 0 0 0 0 0 0
39653- 0 0 0 0 0 0 0 0 0 0 0 0
39654- 0 0 0 0 0 0 0 0 0 0 0 0
39655- 0 0 0 0 0 0 0 0 0 0 0 0
39656- 0 0 0 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 0 0 0
39660- 0 0 0 0 0 0 0 0 0 6 6 6
39661- 22 22 22 54 54 54 70 70 70 2 2 6
39662- 2 2 6 10 10 10 2 2 6 22 22 22
39663-166 166 166 231 231 231 250 250 250 253 253 253
39664-253 253 253 253 253 253 253 253 253 250 250 250
39665-242 242 242 253 253 253 253 253 253 253 253 253
39666-253 253 253 253 253 253 253 253 253 253 253 253
39667-253 253 253 253 253 253 253 253 253 246 246 246
39668-231 231 231 206 206 206 198 198 198 226 226 226
39669- 94 94 94 2 2 6 6 6 6 38 38 38
39670- 30 30 30 2 2 6 2 2 6 2 2 6
39671- 2 2 6 2 2 6 62 62 62 66 66 66
39672- 26 26 26 10 10 10 0 0 0 0 0 0
39673- 0 0 0 0 0 0 0 0 0 0 0 0
39674- 0 0 0 0 0 0 0 0 0 0 0 0
39675- 0 0 0 0 0 0 0 0 0 0 0 0
39676- 0 0 0 0 0 0 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 0 0 0
39680- 0 0 0 0 0 0 0 0 0 10 10 10
39681- 30 30 30 74 74 74 50 50 50 2 2 6
39682- 26 26 26 26 26 26 2 2 6 106 106 106
39683-238 238 238 253 253 253 253 253 253 253 253 253
39684-253 253 253 253 253 253 253 253 253 253 253 253
39685-253 253 253 253 253 253 253 253 253 253 253 253
39686-253 253 253 253 253 253 253 253 253 253 253 253
39687-253 253 253 253 253 253 253 253 253 253 253 253
39688-253 253 253 246 246 246 218 218 218 202 202 202
39689-210 210 210 14 14 14 2 2 6 2 2 6
39690- 30 30 30 22 22 22 2 2 6 2 2 6
39691- 2 2 6 2 2 6 18 18 18 86 86 86
39692- 42 42 42 14 14 14 0 0 0 0 0 0
39693- 0 0 0 0 0 0 0 0 0 0 0 0
39694- 0 0 0 0 0 0 0 0 0 0 0 0
39695- 0 0 0 0 0 0 0 0 0 0 0 0
39696- 0 0 0 0 0 0 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 0 0 0
39700- 0 0 0 0 0 0 0 0 0 14 14 14
39701- 42 42 42 90 90 90 22 22 22 2 2 6
39702- 42 42 42 2 2 6 18 18 18 218 218 218
39703-253 253 253 253 253 253 253 253 253 253 253 253
39704-253 253 253 253 253 253 253 253 253 253 253 253
39705-253 253 253 253 253 253 253 253 253 253 253 253
39706-253 253 253 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 250 250 250 221 221 221
39709-218 218 218 101 101 101 2 2 6 14 14 14
39710- 18 18 18 38 38 38 10 10 10 2 2 6
39711- 2 2 6 2 2 6 2 2 6 78 78 78
39712- 58 58 58 22 22 22 6 6 6 0 0 0
39713- 0 0 0 0 0 0 0 0 0 0 0 0
39714- 0 0 0 0 0 0 0 0 0 0 0 0
39715- 0 0 0 0 0 0 0 0 0 0 0 0
39716- 0 0 0 0 0 0 0 0 0 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 0 0 0
39720- 0 0 0 0 0 0 6 6 6 18 18 18
39721- 54 54 54 82 82 82 2 2 6 26 26 26
39722- 22 22 22 2 2 6 123 123 123 253 253 253
39723-253 253 253 253 253 253 253 253 253 253 253 253
39724-253 253 253 253 253 253 253 253 253 253 253 253
39725-253 253 253 253 253 253 253 253 253 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 250 250 250
39729-238 238 238 198 198 198 6 6 6 38 38 38
39730- 58 58 58 26 26 26 38 38 38 2 2 6
39731- 2 2 6 2 2 6 2 2 6 46 46 46
39732- 78 78 78 30 30 30 10 10 10 0 0 0
39733- 0 0 0 0 0 0 0 0 0 0 0 0
39734- 0 0 0 0 0 0 0 0 0 0 0 0
39735- 0 0 0 0 0 0 0 0 0 0 0 0
39736- 0 0 0 0 0 0 0 0 0 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 0 0 0
39740- 0 0 0 0 0 0 10 10 10 30 30 30
39741- 74 74 74 58 58 58 2 2 6 42 42 42
39742- 2 2 6 22 22 22 231 231 231 253 253 253
39743-253 253 253 253 253 253 253 253 253 253 253 253
39744-253 253 253 253 253 253 253 253 253 250 250 250
39745-253 253 253 253 253 253 253 253 253 253 253 253
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 246 246 246 46 46 46 38 38 38
39750- 42 42 42 14 14 14 38 38 38 14 14 14
39751- 2 2 6 2 2 6 2 2 6 6 6 6
39752- 86 86 86 46 46 46 14 14 14 0 0 0
39753- 0 0 0 0 0 0 0 0 0 0 0 0
39754- 0 0 0 0 0 0 0 0 0 0 0 0
39755- 0 0 0 0 0 0 0 0 0 0 0 0
39756- 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0
39760- 0 0 0 6 6 6 14 14 14 42 42 42
39761- 90 90 90 18 18 18 18 18 18 26 26 26
39762- 2 2 6 116 116 116 253 253 253 253 253 253
39763-253 253 253 253 253 253 253 253 253 253 253 253
39764-253 253 253 253 253 253 250 250 250 238 238 238
39765-253 253 253 253 253 253 253 253 253 253 253 253
39766-253 253 253 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-253 253 253 253 253 253 94 94 94 6 6 6
39770- 2 2 6 2 2 6 10 10 10 34 34 34
39771- 2 2 6 2 2 6 2 2 6 2 2 6
39772- 74 74 74 58 58 58 22 22 22 6 6 6
39773- 0 0 0 0 0 0 0 0 0 0 0 0
39774- 0 0 0 0 0 0 0 0 0 0 0 0
39775- 0 0 0 0 0 0 0 0 0 0 0 0
39776- 0 0 0 0 0 0 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 0 0 0 0 0 0
39780- 0 0 0 10 10 10 26 26 26 66 66 66
39781- 82 82 82 2 2 6 38 38 38 6 6 6
39782- 14 14 14 210 210 210 253 253 253 253 253 253
39783-253 253 253 253 253 253 253 253 253 253 253 253
39784-253 253 253 253 253 253 246 246 246 242 242 242
39785-253 253 253 253 253 253 253 253 253 253 253 253
39786-253 253 253 253 253 253 253 253 253 253 253 253
39787-253 253 253 253 253 253 253 253 253 253 253 253
39788-253 253 253 253 253 253 253 253 253 253 253 253
39789-253 253 253 253 253 253 144 144 144 2 2 6
39790- 2 2 6 2 2 6 2 2 6 46 46 46
39791- 2 2 6 2 2 6 2 2 6 2 2 6
39792- 42 42 42 74 74 74 30 30 30 10 10 10
39793- 0 0 0 0 0 0 0 0 0 0 0 0
39794- 0 0 0 0 0 0 0 0 0 0 0 0
39795- 0 0 0 0 0 0 0 0 0 0 0 0
39796- 0 0 0 0 0 0 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 0 0 0 0 0 0
39800- 6 6 6 14 14 14 42 42 42 90 90 90
39801- 26 26 26 6 6 6 42 42 42 2 2 6
39802- 74 74 74 250 250 250 253 253 253 253 253 253
39803-253 253 253 253 253 253 253 253 253 253 253 253
39804-253 253 253 253 253 253 242 242 242 242 242 242
39805-253 253 253 253 253 253 253 253 253 253 253 253
39806-253 253 253 253 253 253 253 253 253 253 253 253
39807-253 253 253 253 253 253 253 253 253 253 253 253
39808-253 253 253 253 253 253 253 253 253 253 253 253
39809-253 253 253 253 253 253 182 182 182 2 2 6
39810- 2 2 6 2 2 6 2 2 6 46 46 46
39811- 2 2 6 2 2 6 2 2 6 2 2 6
39812- 10 10 10 86 86 86 38 38 38 10 10 10
39813- 0 0 0 0 0 0 0 0 0 0 0 0
39814- 0 0 0 0 0 0 0 0 0 0 0 0
39815- 0 0 0 0 0 0 0 0 0 0 0 0
39816- 0 0 0 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 0 0 0 0 0 0
39820- 10 10 10 26 26 26 66 66 66 82 82 82
39821- 2 2 6 22 22 22 18 18 18 2 2 6
39822-149 149 149 253 253 253 253 253 253 253 253 253
39823-253 253 253 253 253 253 253 253 253 253 253 253
39824-253 253 253 253 253 253 234 234 234 242 242 242
39825-253 253 253 253 253 253 253 253 253 253 253 253
39826-253 253 253 253 253 253 253 253 253 253 253 253
39827-253 253 253 253 253 253 253 253 253 253 253 253
39828-253 253 253 253 253 253 253 253 253 253 253 253
39829-253 253 253 253 253 253 206 206 206 2 2 6
39830- 2 2 6 2 2 6 2 2 6 38 38 38
39831- 2 2 6 2 2 6 2 2 6 2 2 6
39832- 6 6 6 86 86 86 46 46 46 14 14 14
39833- 0 0 0 0 0 0 0 0 0 0 0 0
39834- 0 0 0 0 0 0 0 0 0 0 0 0
39835- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
39840- 18 18 18 46 46 46 86 86 86 18 18 18
39841- 2 2 6 34 34 34 10 10 10 6 6 6
39842-210 210 210 253 253 253 253 253 253 253 253 253
39843-253 253 253 253 253 253 253 253 253 253 253 253
39844-253 253 253 253 253 253 234 234 234 242 242 242
39845-253 253 253 253 253 253 253 253 253 253 253 253
39846-253 253 253 253 253 253 253 253 253 253 253 253
39847-253 253 253 253 253 253 253 253 253 253 253 253
39848-253 253 253 253 253 253 253 253 253 253 253 253
39849-253 253 253 253 253 253 221 221 221 6 6 6
39850- 2 2 6 2 2 6 6 6 6 30 30 30
39851- 2 2 6 2 2 6 2 2 6 2 2 6
39852- 2 2 6 82 82 82 54 54 54 18 18 18
39853- 6 6 6 0 0 0 0 0 0 0 0 0
39854- 0 0 0 0 0 0 0 0 0 0 0 0
39855- 0 0 0 0 0 0 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 10 10 10
39860- 26 26 26 66 66 66 62 62 62 2 2 6
39861- 2 2 6 38 38 38 10 10 10 26 26 26
39862-238 238 238 253 253 253 253 253 253 253 253 253
39863-253 253 253 253 253 253 253 253 253 253 253 253
39864-253 253 253 253 253 253 231 231 231 238 238 238
39865-253 253 253 253 253 253 253 253 253 253 253 253
39866-253 253 253 253 253 253 253 253 253 253 253 253
39867-253 253 253 253 253 253 253 253 253 253 253 253
39868-253 253 253 253 253 253 253 253 253 253 253 253
39869-253 253 253 253 253 253 231 231 231 6 6 6
39870- 2 2 6 2 2 6 10 10 10 30 30 30
39871- 2 2 6 2 2 6 2 2 6 2 2 6
39872- 2 2 6 66 66 66 58 58 58 22 22 22
39873- 6 6 6 0 0 0 0 0 0 0 0 0
39874- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
39880- 38 38 38 78 78 78 6 6 6 2 2 6
39881- 2 2 6 46 46 46 14 14 14 42 42 42
39882-246 246 246 253 253 253 253 253 253 253 253 253
39883-253 253 253 253 253 253 253 253 253 253 253 253
39884-253 253 253 253 253 253 231 231 231 242 242 242
39885-253 253 253 253 253 253 253 253 253 253 253 253
39886-253 253 253 253 253 253 253 253 253 253 253 253
39887-253 253 253 253 253 253 253 253 253 253 253 253
39888-253 253 253 253 253 253 253 253 253 253 253 253
39889-253 253 253 253 253 253 234 234 234 10 10 10
39890- 2 2 6 2 2 6 22 22 22 14 14 14
39891- 2 2 6 2 2 6 2 2 6 2 2 6
39892- 2 2 6 66 66 66 62 62 62 22 22 22
39893- 6 6 6 0 0 0 0 0 0 0 0 0
39894- 0 0 0 0 0 0 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 6 6 6 18 18 18
39900- 50 50 50 74 74 74 2 2 6 2 2 6
39901- 14 14 14 70 70 70 34 34 34 62 62 62
39902-250 250 250 253 253 253 253 253 253 253 253 253
39903-253 253 253 253 253 253 253 253 253 253 253 253
39904-253 253 253 253 253 253 231 231 231 246 246 246
39905-253 253 253 253 253 253 253 253 253 253 253 253
39906-253 253 253 253 253 253 253 253 253 253 253 253
39907-253 253 253 253 253 253 253 253 253 253 253 253
39908-253 253 253 253 253 253 253 253 253 253 253 253
39909-253 253 253 253 253 253 234 234 234 14 14 14
39910- 2 2 6 2 2 6 30 30 30 2 2 6
39911- 2 2 6 2 2 6 2 2 6 2 2 6
39912- 2 2 6 66 66 66 62 62 62 22 22 22
39913- 6 6 6 0 0 0 0 0 0 0 0 0
39914- 0 0 0 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 6 6 6 18 18 18
39920- 54 54 54 62 62 62 2 2 6 2 2 6
39921- 2 2 6 30 30 30 46 46 46 70 70 70
39922-250 250 250 253 253 253 253 253 253 253 253 253
39923-253 253 253 253 253 253 253 253 253 253 253 253
39924-253 253 253 253 253 253 231 231 231 246 246 246
39925-253 253 253 253 253 253 253 253 253 253 253 253
39926-253 253 253 253 253 253 253 253 253 253 253 253
39927-253 253 253 253 253 253 253 253 253 253 253 253
39928-253 253 253 253 253 253 253 253 253 253 253 253
39929-253 253 253 253 253 253 226 226 226 10 10 10
39930- 2 2 6 6 6 6 30 30 30 2 2 6
39931- 2 2 6 2 2 6 2 2 6 2 2 6
39932- 2 2 6 66 66 66 58 58 58 22 22 22
39933- 6 6 6 0 0 0 0 0 0 0 0 0
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 6 6 6 22 22 22
39940- 58 58 58 62 62 62 2 2 6 2 2 6
39941- 2 2 6 2 2 6 30 30 30 78 78 78
39942-250 250 250 253 253 253 253 253 253 253 253 253
39943-253 253 253 253 253 253 253 253 253 253 253 253
39944-253 253 253 253 253 253 231 231 231 246 246 246
39945-253 253 253 253 253 253 253 253 253 253 253 253
39946-253 253 253 253 253 253 253 253 253 253 253 253
39947-253 253 253 253 253 253 253 253 253 253 253 253
39948-253 253 253 253 253 253 253 253 253 253 253 253
39949-253 253 253 253 253 253 206 206 206 2 2 6
39950- 22 22 22 34 34 34 18 14 6 22 22 22
39951- 26 26 26 18 18 18 6 6 6 2 2 6
39952- 2 2 6 82 82 82 54 54 54 18 18 18
39953- 6 6 6 0 0 0 0 0 0 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 6 6 6 26 26 26
39960- 62 62 62 106 106 106 74 54 14 185 133 11
39961-210 162 10 121 92 8 6 6 6 62 62 62
39962-238 238 238 253 253 253 253 253 253 253 253 253
39963-253 253 253 253 253 253 253 253 253 253 253 253
39964-253 253 253 253 253 253 231 231 231 246 246 246
39965-253 253 253 253 253 253 253 253 253 253 253 253
39966-253 253 253 253 253 253 253 253 253 253 253 253
39967-253 253 253 253 253 253 253 253 253 253 253 253
39968-253 253 253 253 253 253 253 253 253 253 253 253
39969-253 253 253 253 253 253 158 158 158 18 18 18
39970- 14 14 14 2 2 6 2 2 6 2 2 6
39971- 6 6 6 18 18 18 66 66 66 38 38 38
39972- 6 6 6 94 94 94 50 50 50 18 18 18
39973- 6 6 6 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 6 6 6
39979- 10 10 10 10 10 10 18 18 18 38 38 38
39980- 78 78 78 142 134 106 216 158 10 242 186 14
39981-246 190 14 246 190 14 156 118 10 10 10 10
39982- 90 90 90 238 238 238 253 253 253 253 253 253
39983-253 253 253 253 253 253 253 253 253 253 253 253
39984-253 253 253 253 253 253 231 231 231 250 250 250
39985-253 253 253 253 253 253 253 253 253 253 253 253
39986-253 253 253 253 253 253 253 253 253 253 253 253
39987-253 253 253 253 253 253 253 253 253 253 253 253
39988-253 253 253 253 253 253 253 253 253 246 230 190
39989-238 204 91 238 204 91 181 142 44 37 26 9
39990- 2 2 6 2 2 6 2 2 6 2 2 6
39991- 2 2 6 2 2 6 38 38 38 46 46 46
39992- 26 26 26 106 106 106 54 54 54 18 18 18
39993- 6 6 6 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- 0 0 0 6 6 6 14 14 14 22 22 22
39999- 30 30 30 38 38 38 50 50 50 70 70 70
40000-106 106 106 190 142 34 226 170 11 242 186 14
40001-246 190 14 246 190 14 246 190 14 154 114 10
40002- 6 6 6 74 74 74 226 226 226 253 253 253
40003-253 253 253 253 253 253 253 253 253 253 253 253
40004-253 253 253 253 253 253 231 231 231 250 250 250
40005-253 253 253 253 253 253 253 253 253 253 253 253
40006-253 253 253 253 253 253 253 253 253 253 253 253
40007-253 253 253 253 253 253 253 253 253 253 253 253
40008-253 253 253 253 253 253 253 253 253 228 184 62
40009-241 196 14 241 208 19 232 195 16 38 30 10
40010- 2 2 6 2 2 6 2 2 6 2 2 6
40011- 2 2 6 6 6 6 30 30 30 26 26 26
40012-203 166 17 154 142 90 66 66 66 26 26 26
40013- 6 6 6 0 0 0 0 0 0 0 0 0
40014- 0 0 0 0 0 0 0 0 0 0 0 0
40015- 0 0 0 0 0 0 0 0 0 0 0 0
40016- 0 0 0 0 0 0 0 0 0 0 0 0
40017- 0 0 0 0 0 0 0 0 0 0 0 0
40018- 6 6 6 18 18 18 38 38 38 58 58 58
40019- 78 78 78 86 86 86 101 101 101 123 123 123
40020-175 146 61 210 150 10 234 174 13 246 186 14
40021-246 190 14 246 190 14 246 190 14 238 190 10
40022-102 78 10 2 2 6 46 46 46 198 198 198
40023-253 253 253 253 253 253 253 253 253 253 253 253
40024-253 253 253 253 253 253 234 234 234 242 242 242
40025-253 253 253 253 253 253 253 253 253 253 253 253
40026-253 253 253 253 253 253 253 253 253 253 253 253
40027-253 253 253 253 253 253 253 253 253 253 253 253
40028-253 253 253 253 253 253 253 253 253 224 178 62
40029-242 186 14 241 196 14 210 166 10 22 18 6
40030- 2 2 6 2 2 6 2 2 6 2 2 6
40031- 2 2 6 2 2 6 6 6 6 121 92 8
40032-238 202 15 232 195 16 82 82 82 34 34 34
40033- 10 10 10 0 0 0 0 0 0 0 0 0
40034- 0 0 0 0 0 0 0 0 0 0 0 0
40035- 0 0 0 0 0 0 0 0 0 0 0 0
40036- 0 0 0 0 0 0 0 0 0 0 0 0
40037- 0 0 0 0 0 0 0 0 0 0 0 0
40038- 14 14 14 38 38 38 70 70 70 154 122 46
40039-190 142 34 200 144 11 197 138 11 197 138 11
40040-213 154 11 226 170 11 242 186 14 246 190 14
40041-246 190 14 246 190 14 246 190 14 246 190 14
40042-225 175 15 46 32 6 2 2 6 22 22 22
40043-158 158 158 250 250 250 253 253 253 253 253 253
40044-253 253 253 253 253 253 253 253 253 253 253 253
40045-253 253 253 253 253 253 253 253 253 253 253 253
40046-253 253 253 253 253 253 253 253 253 253 253 253
40047-253 253 253 253 253 253 253 253 253 253 253 253
40048-253 253 253 250 250 250 242 242 242 224 178 62
40049-239 182 13 236 186 11 213 154 11 46 32 6
40050- 2 2 6 2 2 6 2 2 6 2 2 6
40051- 2 2 6 2 2 6 61 42 6 225 175 15
40052-238 190 10 236 186 11 112 100 78 42 42 42
40053- 14 14 14 0 0 0 0 0 0 0 0 0
40054- 0 0 0 0 0 0 0 0 0 0 0 0
40055- 0 0 0 0 0 0 0 0 0 0 0 0
40056- 0 0 0 0 0 0 0 0 0 0 0 0
40057- 0 0 0 0 0 0 0 0 0 6 6 6
40058- 22 22 22 54 54 54 154 122 46 213 154 11
40059-226 170 11 230 174 11 226 170 11 226 170 11
40060-236 178 12 242 186 14 246 190 14 246 190 14
40061-246 190 14 246 190 14 246 190 14 246 190 14
40062-241 196 14 184 144 12 10 10 10 2 2 6
40063- 6 6 6 116 116 116 242 242 242 253 253 253
40064-253 253 253 253 253 253 253 253 253 253 253 253
40065-253 253 253 253 253 253 253 253 253 253 253 253
40066-253 253 253 253 253 253 253 253 253 253 253 253
40067-253 253 253 253 253 253 253 253 253 253 253 253
40068-253 253 253 231 231 231 198 198 198 214 170 54
40069-236 178 12 236 178 12 210 150 10 137 92 6
40070- 18 14 6 2 2 6 2 2 6 2 2 6
40071- 6 6 6 70 47 6 200 144 11 236 178 12
40072-239 182 13 239 182 13 124 112 88 58 58 58
40073- 22 22 22 6 6 6 0 0 0 0 0 0
40074- 0 0 0 0 0 0 0 0 0 0 0 0
40075- 0 0 0 0 0 0 0 0 0 0 0 0
40076- 0 0 0 0 0 0 0 0 0 0 0 0
40077- 0 0 0 0 0 0 0 0 0 10 10 10
40078- 30 30 30 70 70 70 180 133 36 226 170 11
40079-239 182 13 242 186 14 242 186 14 246 186 14
40080-246 190 14 246 190 14 246 190 14 246 190 14
40081-246 190 14 246 190 14 246 190 14 246 190 14
40082-246 190 14 232 195 16 98 70 6 2 2 6
40083- 2 2 6 2 2 6 66 66 66 221 221 221
40084-253 253 253 253 253 253 253 253 253 253 253 253
40085-253 253 253 253 253 253 253 253 253 253 253 253
40086-253 253 253 253 253 253 253 253 253 253 253 253
40087-253 253 253 253 253 253 253 253 253 253 253 253
40088-253 253 253 206 206 206 198 198 198 214 166 58
40089-230 174 11 230 174 11 216 158 10 192 133 9
40090-163 110 8 116 81 8 102 78 10 116 81 8
40091-167 114 7 197 138 11 226 170 11 239 182 13
40092-242 186 14 242 186 14 162 146 94 78 78 78
40093- 34 34 34 14 14 14 6 6 6 0 0 0
40094- 0 0 0 0 0 0 0 0 0 0 0 0
40095- 0 0 0 0 0 0 0 0 0 0 0 0
40096- 0 0 0 0 0 0 0 0 0 0 0 0
40097- 0 0 0 0 0 0 0 0 0 6 6 6
40098- 30 30 30 78 78 78 190 142 34 226 170 11
40099-239 182 13 246 190 14 246 190 14 246 190 14
40100-246 190 14 246 190 14 246 190 14 246 190 14
40101-246 190 14 246 190 14 246 190 14 246 190 14
40102-246 190 14 241 196 14 203 166 17 22 18 6
40103- 2 2 6 2 2 6 2 2 6 38 38 38
40104-218 218 218 253 253 253 253 253 253 253 253 253
40105-253 253 253 253 253 253 253 253 253 253 253 253
40106-253 253 253 253 253 253 253 253 253 253 253 253
40107-253 253 253 253 253 253 253 253 253 253 253 253
40108-250 250 250 206 206 206 198 198 198 202 162 69
40109-226 170 11 236 178 12 224 166 10 210 150 10
40110-200 144 11 197 138 11 192 133 9 197 138 11
40111-210 150 10 226 170 11 242 186 14 246 190 14
40112-246 190 14 246 186 14 225 175 15 124 112 88
40113- 62 62 62 30 30 30 14 14 14 6 6 6
40114- 0 0 0 0 0 0 0 0 0 0 0 0
40115- 0 0 0 0 0 0 0 0 0 0 0 0
40116- 0 0 0 0 0 0 0 0 0 0 0 0
40117- 0 0 0 0 0 0 0 0 0 10 10 10
40118- 30 30 30 78 78 78 174 135 50 224 166 10
40119-239 182 13 246 190 14 246 190 14 246 190 14
40120-246 190 14 246 190 14 246 190 14 246 190 14
40121-246 190 14 246 190 14 246 190 14 246 190 14
40122-246 190 14 246 190 14 241 196 14 139 102 15
40123- 2 2 6 2 2 6 2 2 6 2 2 6
40124- 78 78 78 250 250 250 253 253 253 253 253 253
40125-253 253 253 253 253 253 253 253 253 253 253 253
40126-253 253 253 253 253 253 253 253 253 253 253 253
40127-253 253 253 253 253 253 253 253 253 253 253 253
40128-250 250 250 214 214 214 198 198 198 190 150 46
40129-219 162 10 236 178 12 234 174 13 224 166 10
40130-216 158 10 213 154 11 213 154 11 216 158 10
40131-226 170 11 239 182 13 246 190 14 246 190 14
40132-246 190 14 246 190 14 242 186 14 206 162 42
40133-101 101 101 58 58 58 30 30 30 14 14 14
40134- 6 6 6 0 0 0 0 0 0 0 0 0
40135- 0 0 0 0 0 0 0 0 0 0 0 0
40136- 0 0 0 0 0 0 0 0 0 0 0 0
40137- 0 0 0 0 0 0 0 0 0 10 10 10
40138- 30 30 30 74 74 74 174 135 50 216 158 10
40139-236 178 12 246 190 14 246 190 14 246 190 14
40140-246 190 14 246 190 14 246 190 14 246 190 14
40141-246 190 14 246 190 14 246 190 14 246 190 14
40142-246 190 14 246 190 14 241 196 14 226 184 13
40143- 61 42 6 2 2 6 2 2 6 2 2 6
40144- 22 22 22 238 238 238 253 253 253 253 253 253
40145-253 253 253 253 253 253 253 253 253 253 253 253
40146-253 253 253 253 253 253 253 253 253 253 253 253
40147-253 253 253 253 253 253 253 253 253 253 253 253
40148-253 253 253 226 226 226 187 187 187 180 133 36
40149-216 158 10 236 178 12 239 182 13 236 178 12
40150-230 174 11 226 170 11 226 170 11 230 174 11
40151-236 178 12 242 186 14 246 190 14 246 190 14
40152-246 190 14 246 190 14 246 186 14 239 182 13
40153-206 162 42 106 106 106 66 66 66 34 34 34
40154- 14 14 14 6 6 6 0 0 0 0 0 0
40155- 0 0 0 0 0 0 0 0 0 0 0 0
40156- 0 0 0 0 0 0 0 0 0 0 0 0
40157- 0 0 0 0 0 0 0 0 0 6 6 6
40158- 26 26 26 70 70 70 163 133 67 213 154 11
40159-236 178 12 246 190 14 246 190 14 246 190 14
40160-246 190 14 246 190 14 246 190 14 246 190 14
40161-246 190 14 246 190 14 246 190 14 246 190 14
40162-246 190 14 246 190 14 246 190 14 241 196 14
40163-190 146 13 18 14 6 2 2 6 2 2 6
40164- 46 46 46 246 246 246 253 253 253 253 253 253
40165-253 253 253 253 253 253 253 253 253 253 253 253
40166-253 253 253 253 253 253 253 253 253 253 253 253
40167-253 253 253 253 253 253 253 253 253 253 253 253
40168-253 253 253 221 221 221 86 86 86 156 107 11
40169-216 158 10 236 178 12 242 186 14 246 186 14
40170-242 186 14 239 182 13 239 182 13 242 186 14
40171-242 186 14 246 186 14 246 190 14 246 190 14
40172-246 190 14 246 190 14 246 190 14 246 190 14
40173-242 186 14 225 175 15 142 122 72 66 66 66
40174- 30 30 30 10 10 10 0 0 0 0 0 0
40175- 0 0 0 0 0 0 0 0 0 0 0 0
40176- 0 0 0 0 0 0 0 0 0 0 0 0
40177- 0 0 0 0 0 0 0 0 0 6 6 6
40178- 26 26 26 70 70 70 163 133 67 210 150 10
40179-236 178 12 246 190 14 246 190 14 246 190 14
40180-246 190 14 246 190 14 246 190 14 246 190 14
40181-246 190 14 246 190 14 246 190 14 246 190 14
40182-246 190 14 246 190 14 246 190 14 246 190 14
40183-232 195 16 121 92 8 34 34 34 106 106 106
40184-221 221 221 253 253 253 253 253 253 253 253 253
40185-253 253 253 253 253 253 253 253 253 253 253 253
40186-253 253 253 253 253 253 253 253 253 253 253 253
40187-253 253 253 253 253 253 253 253 253 253 253 253
40188-242 242 242 82 82 82 18 14 6 163 110 8
40189-216 158 10 236 178 12 242 186 14 246 190 14
40190-246 190 14 246 190 14 246 190 14 246 190 14
40191-246 190 14 246 190 14 246 190 14 246 190 14
40192-246 190 14 246 190 14 246 190 14 246 190 14
40193-246 190 14 246 190 14 242 186 14 163 133 67
40194- 46 46 46 18 18 18 6 6 6 0 0 0
40195- 0 0 0 0 0 0 0 0 0 0 0 0
40196- 0 0 0 0 0 0 0 0 0 0 0 0
40197- 0 0 0 0 0 0 0 0 0 10 10 10
40198- 30 30 30 78 78 78 163 133 67 210 150 10
40199-236 178 12 246 186 14 246 190 14 246 190 14
40200-246 190 14 246 190 14 246 190 14 246 190 14
40201-246 190 14 246 190 14 246 190 14 246 190 14
40202-246 190 14 246 190 14 246 190 14 246 190 14
40203-241 196 14 215 174 15 190 178 144 253 253 253
40204-253 253 253 253 253 253 253 253 253 253 253 253
40205-253 253 253 253 253 253 253 253 253 253 253 253
40206-253 253 253 253 253 253 253 253 253 253 253 253
40207-253 253 253 253 253 253 253 253 253 218 218 218
40208- 58 58 58 2 2 6 22 18 6 167 114 7
40209-216 158 10 236 178 12 246 186 14 246 190 14
40210-246 190 14 246 190 14 246 190 14 246 190 14
40211-246 190 14 246 190 14 246 190 14 246 190 14
40212-246 190 14 246 190 14 246 190 14 246 190 14
40213-246 190 14 246 186 14 242 186 14 190 150 46
40214- 54 54 54 22 22 22 6 6 6 0 0 0
40215- 0 0 0 0 0 0 0 0 0 0 0 0
40216- 0 0 0 0 0 0 0 0 0 0 0 0
40217- 0 0 0 0 0 0 0 0 0 14 14 14
40218- 38 38 38 86 86 86 180 133 36 213 154 11
40219-236 178 12 246 186 14 246 190 14 246 190 14
40220-246 190 14 246 190 14 246 190 14 246 190 14
40221-246 190 14 246 190 14 246 190 14 246 190 14
40222-246 190 14 246 190 14 246 190 14 246 190 14
40223-246 190 14 232 195 16 190 146 13 214 214 214
40224-253 253 253 253 253 253 253 253 253 253 253 253
40225-253 253 253 253 253 253 253 253 253 253 253 253
40226-253 253 253 253 253 253 253 253 253 253 253 253
40227-253 253 253 250 250 250 170 170 170 26 26 26
40228- 2 2 6 2 2 6 37 26 9 163 110 8
40229-219 162 10 239 182 13 246 186 14 246 190 14
40230-246 190 14 246 190 14 246 190 14 246 190 14
40231-246 190 14 246 190 14 246 190 14 246 190 14
40232-246 190 14 246 190 14 246 190 14 246 190 14
40233-246 186 14 236 178 12 224 166 10 142 122 72
40234- 46 46 46 18 18 18 6 6 6 0 0 0
40235- 0 0 0 0 0 0 0 0 0 0 0 0
40236- 0 0 0 0 0 0 0 0 0 0 0 0
40237- 0 0 0 0 0 0 6 6 6 18 18 18
40238- 50 50 50 109 106 95 192 133 9 224 166 10
40239-242 186 14 246 190 14 246 190 14 246 190 14
40240-246 190 14 246 190 14 246 190 14 246 190 14
40241-246 190 14 246 190 14 246 190 14 246 190 14
40242-246 190 14 246 190 14 246 190 14 246 190 14
40243-242 186 14 226 184 13 210 162 10 142 110 46
40244-226 226 226 253 253 253 253 253 253 253 253 253
40245-253 253 253 253 253 253 253 253 253 253 253 253
40246-253 253 253 253 253 253 253 253 253 253 253 253
40247-198 198 198 66 66 66 2 2 6 2 2 6
40248- 2 2 6 2 2 6 50 34 6 156 107 11
40249-219 162 10 239 182 13 246 186 14 246 190 14
40250-246 190 14 246 190 14 246 190 14 246 190 14
40251-246 190 14 246 190 14 246 190 14 246 190 14
40252-246 190 14 246 190 14 246 190 14 242 186 14
40253-234 174 13 213 154 11 154 122 46 66 66 66
40254- 30 30 30 10 10 10 0 0 0 0 0 0
40255- 0 0 0 0 0 0 0 0 0 0 0 0
40256- 0 0 0 0 0 0 0 0 0 0 0 0
40257- 0 0 0 0 0 0 6 6 6 22 22 22
40258- 58 58 58 154 121 60 206 145 10 234 174 13
40259-242 186 14 246 186 14 246 190 14 246 190 14
40260-246 190 14 246 190 14 246 190 14 246 190 14
40261-246 190 14 246 190 14 246 190 14 246 190 14
40262-246 190 14 246 190 14 246 190 14 246 190 14
40263-246 186 14 236 178 12 210 162 10 163 110 8
40264- 61 42 6 138 138 138 218 218 218 250 250 250
40265-253 253 253 253 253 253 253 253 253 250 250 250
40266-242 242 242 210 210 210 144 144 144 66 66 66
40267- 6 6 6 2 2 6 2 2 6 2 2 6
40268- 2 2 6 2 2 6 61 42 6 163 110 8
40269-216 158 10 236 178 12 246 190 14 246 190 14
40270-246 190 14 246 190 14 246 190 14 246 190 14
40271-246 190 14 246 190 14 246 190 14 246 190 14
40272-246 190 14 239 182 13 230 174 11 216 158 10
40273-190 142 34 124 112 88 70 70 70 38 38 38
40274- 18 18 18 6 6 6 0 0 0 0 0 0
40275- 0 0 0 0 0 0 0 0 0 0 0 0
40276- 0 0 0 0 0 0 0 0 0 0 0 0
40277- 0 0 0 0 0 0 6 6 6 22 22 22
40278- 62 62 62 168 124 44 206 145 10 224 166 10
40279-236 178 12 239 182 13 242 186 14 242 186 14
40280-246 186 14 246 190 14 246 190 14 246 190 14
40281-246 190 14 246 190 14 246 190 14 246 190 14
40282-246 190 14 246 190 14 246 190 14 246 190 14
40283-246 190 14 236 178 12 216 158 10 175 118 6
40284- 80 54 7 2 2 6 6 6 6 30 30 30
40285- 54 54 54 62 62 62 50 50 50 38 38 38
40286- 14 14 14 2 2 6 2 2 6 2 2 6
40287- 2 2 6 2 2 6 2 2 6 2 2 6
40288- 2 2 6 6 6 6 80 54 7 167 114 7
40289-213 154 11 236 178 12 246 190 14 246 190 14
40290-246 190 14 246 190 14 246 190 14 246 190 14
40291-246 190 14 242 186 14 239 182 13 239 182 13
40292-230 174 11 210 150 10 174 135 50 124 112 88
40293- 82 82 82 54 54 54 34 34 34 18 18 18
40294- 6 6 6 0 0 0 0 0 0 0 0 0
40295- 0 0 0 0 0 0 0 0 0 0 0 0
40296- 0 0 0 0 0 0 0 0 0 0 0 0
40297- 0 0 0 0 0 0 6 6 6 18 18 18
40298- 50 50 50 158 118 36 192 133 9 200 144 11
40299-216 158 10 219 162 10 224 166 10 226 170 11
40300-230 174 11 236 178 12 239 182 13 239 182 13
40301-242 186 14 246 186 14 246 190 14 246 190 14
40302-246 190 14 246 190 14 246 190 14 246 190 14
40303-246 186 14 230 174 11 210 150 10 163 110 8
40304-104 69 6 10 10 10 2 2 6 2 2 6
40305- 2 2 6 2 2 6 2 2 6 2 2 6
40306- 2 2 6 2 2 6 2 2 6 2 2 6
40307- 2 2 6 2 2 6 2 2 6 2 2 6
40308- 2 2 6 6 6 6 91 60 6 167 114 7
40309-206 145 10 230 174 11 242 186 14 246 190 14
40310-246 190 14 246 190 14 246 186 14 242 186 14
40311-239 182 13 230 174 11 224 166 10 213 154 11
40312-180 133 36 124 112 88 86 86 86 58 58 58
40313- 38 38 38 22 22 22 10 10 10 6 6 6
40314- 0 0 0 0 0 0 0 0 0 0 0 0
40315- 0 0 0 0 0 0 0 0 0 0 0 0
40316- 0 0 0 0 0 0 0 0 0 0 0 0
40317- 0 0 0 0 0 0 0 0 0 14 14 14
40318- 34 34 34 70 70 70 138 110 50 158 118 36
40319-167 114 7 180 123 7 192 133 9 197 138 11
40320-200 144 11 206 145 10 213 154 11 219 162 10
40321-224 166 10 230 174 11 239 182 13 242 186 14
40322-246 186 14 246 186 14 246 186 14 246 186 14
40323-239 182 13 216 158 10 185 133 11 152 99 6
40324-104 69 6 18 14 6 2 2 6 2 2 6
40325- 2 2 6 2 2 6 2 2 6 2 2 6
40326- 2 2 6 2 2 6 2 2 6 2 2 6
40327- 2 2 6 2 2 6 2 2 6 2 2 6
40328- 2 2 6 6 6 6 80 54 7 152 99 6
40329-192 133 9 219 162 10 236 178 12 239 182 13
40330-246 186 14 242 186 14 239 182 13 236 178 12
40331-224 166 10 206 145 10 192 133 9 154 121 60
40332- 94 94 94 62 62 62 42 42 42 22 22 22
40333- 14 14 14 6 6 6 0 0 0 0 0 0
40334- 0 0 0 0 0 0 0 0 0 0 0 0
40335- 0 0 0 0 0 0 0 0 0 0 0 0
40336- 0 0 0 0 0 0 0 0 0 0 0 0
40337- 0 0 0 0 0 0 0 0 0 6 6 6
40338- 18 18 18 34 34 34 58 58 58 78 78 78
40339-101 98 89 124 112 88 142 110 46 156 107 11
40340-163 110 8 167 114 7 175 118 6 180 123 7
40341-185 133 11 197 138 11 210 150 10 219 162 10
40342-226 170 11 236 178 12 236 178 12 234 174 13
40343-219 162 10 197 138 11 163 110 8 130 83 6
40344- 91 60 6 10 10 10 2 2 6 2 2 6
40345- 18 18 18 38 38 38 38 38 38 38 38 38
40346- 38 38 38 38 38 38 38 38 38 38 38 38
40347- 38 38 38 38 38 38 26 26 26 2 2 6
40348- 2 2 6 6 6 6 70 47 6 137 92 6
40349-175 118 6 200 144 11 219 162 10 230 174 11
40350-234 174 13 230 174 11 219 162 10 210 150 10
40351-192 133 9 163 110 8 124 112 88 82 82 82
40352- 50 50 50 30 30 30 14 14 14 6 6 6
40353- 0 0 0 0 0 0 0 0 0 0 0 0
40354- 0 0 0 0 0 0 0 0 0 0 0 0
40355- 0 0 0 0 0 0 0 0 0 0 0 0
40356- 0 0 0 0 0 0 0 0 0 0 0 0
40357- 0 0 0 0 0 0 0 0 0 0 0 0
40358- 6 6 6 14 14 14 22 22 22 34 34 34
40359- 42 42 42 58 58 58 74 74 74 86 86 86
40360-101 98 89 122 102 70 130 98 46 121 87 25
40361-137 92 6 152 99 6 163 110 8 180 123 7
40362-185 133 11 197 138 11 206 145 10 200 144 11
40363-180 123 7 156 107 11 130 83 6 104 69 6
40364- 50 34 6 54 54 54 110 110 110 101 98 89
40365- 86 86 86 82 82 82 78 78 78 78 78 78
40366- 78 78 78 78 78 78 78 78 78 78 78 78
40367- 78 78 78 82 82 82 86 86 86 94 94 94
40368-106 106 106 101 101 101 86 66 34 124 80 6
40369-156 107 11 180 123 7 192 133 9 200 144 11
40370-206 145 10 200 144 11 192 133 9 175 118 6
40371-139 102 15 109 106 95 70 70 70 42 42 42
40372- 22 22 22 10 10 10 0 0 0 0 0 0
40373- 0 0 0 0 0 0 0 0 0 0 0 0
40374- 0 0 0 0 0 0 0 0 0 0 0 0
40375- 0 0 0 0 0 0 0 0 0 0 0 0
40376- 0 0 0 0 0 0 0 0 0 0 0 0
40377- 0 0 0 0 0 0 0 0 0 0 0 0
40378- 0 0 0 0 0 0 6 6 6 10 10 10
40379- 14 14 14 22 22 22 30 30 30 38 38 38
40380- 50 50 50 62 62 62 74 74 74 90 90 90
40381-101 98 89 112 100 78 121 87 25 124 80 6
40382-137 92 6 152 99 6 152 99 6 152 99 6
40383-138 86 6 124 80 6 98 70 6 86 66 30
40384-101 98 89 82 82 82 58 58 58 46 46 46
40385- 38 38 38 34 34 34 34 34 34 34 34 34
40386- 34 34 34 34 34 34 34 34 34 34 34 34
40387- 34 34 34 34 34 34 38 38 38 42 42 42
40388- 54 54 54 82 82 82 94 86 76 91 60 6
40389-134 86 6 156 107 11 167 114 7 175 118 6
40390-175 118 6 167 114 7 152 99 6 121 87 25
40391-101 98 89 62 62 62 34 34 34 18 18 18
40392- 6 6 6 0 0 0 0 0 0 0 0 0
40393- 0 0 0 0 0 0 0 0 0 0 0 0
40394- 0 0 0 0 0 0 0 0 0 0 0 0
40395- 0 0 0 0 0 0 0 0 0 0 0 0
40396- 0 0 0 0 0 0 0 0 0 0 0 0
40397- 0 0 0 0 0 0 0 0 0 0 0 0
40398- 0 0 0 0 0 0 0 0 0 0 0 0
40399- 0 0 0 6 6 6 6 6 6 10 10 10
40400- 18 18 18 22 22 22 30 30 30 42 42 42
40401- 50 50 50 66 66 66 86 86 86 101 98 89
40402-106 86 58 98 70 6 104 69 6 104 69 6
40403-104 69 6 91 60 6 82 62 34 90 90 90
40404- 62 62 62 38 38 38 22 22 22 14 14 14
40405- 10 10 10 10 10 10 10 10 10 10 10 10
40406- 10 10 10 10 10 10 6 6 6 10 10 10
40407- 10 10 10 10 10 10 10 10 10 14 14 14
40408- 22 22 22 42 42 42 70 70 70 89 81 66
40409- 80 54 7 104 69 6 124 80 6 137 92 6
40410-134 86 6 116 81 8 100 82 52 86 86 86
40411- 58 58 58 30 30 30 14 14 14 6 6 6
40412- 0 0 0 0 0 0 0 0 0 0 0 0
40413- 0 0 0 0 0 0 0 0 0 0 0 0
40414- 0 0 0 0 0 0 0 0 0 0 0 0
40415- 0 0 0 0 0 0 0 0 0 0 0 0
40416- 0 0 0 0 0 0 0 0 0 0 0 0
40417- 0 0 0 0 0 0 0 0 0 0 0 0
40418- 0 0 0 0 0 0 0 0 0 0 0 0
40419- 0 0 0 0 0 0 0 0 0 0 0 0
40420- 0 0 0 6 6 6 10 10 10 14 14 14
40421- 18 18 18 26 26 26 38 38 38 54 54 54
40422- 70 70 70 86 86 86 94 86 76 89 81 66
40423- 89 81 66 86 86 86 74 74 74 50 50 50
40424- 30 30 30 14 14 14 6 6 6 0 0 0
40425- 0 0 0 0 0 0 0 0 0 0 0 0
40426- 0 0 0 0 0 0 0 0 0 0 0 0
40427- 0 0 0 0 0 0 0 0 0 0 0 0
40428- 6 6 6 18 18 18 34 34 34 58 58 58
40429- 82 82 82 89 81 66 89 81 66 89 81 66
40430- 94 86 66 94 86 76 74 74 74 50 50 50
40431- 26 26 26 14 14 14 6 6 6 0 0 0
40432- 0 0 0 0 0 0 0 0 0 0 0 0
40433- 0 0 0 0 0 0 0 0 0 0 0 0
40434- 0 0 0 0 0 0 0 0 0 0 0 0
40435- 0 0 0 0 0 0 0 0 0 0 0 0
40436- 0 0 0 0 0 0 0 0 0 0 0 0
40437- 0 0 0 0 0 0 0 0 0 0 0 0
40438- 0 0 0 0 0 0 0 0 0 0 0 0
40439- 0 0 0 0 0 0 0 0 0 0 0 0
40440- 0 0 0 0 0 0 0 0 0 0 0 0
40441- 6 6 6 6 6 6 14 14 14 18 18 18
40442- 30 30 30 38 38 38 46 46 46 54 54 54
40443- 50 50 50 42 42 42 30 30 30 18 18 18
40444- 10 10 10 0 0 0 0 0 0 0 0 0
40445- 0 0 0 0 0 0 0 0 0 0 0 0
40446- 0 0 0 0 0 0 0 0 0 0 0 0
40447- 0 0 0 0 0 0 0 0 0 0 0 0
40448- 0 0 0 6 6 6 14 14 14 26 26 26
40449- 38 38 38 50 50 50 58 58 58 58 58 58
40450- 54 54 54 42 42 42 30 30 30 18 18 18
40451- 10 10 10 0 0 0 0 0 0 0 0 0
40452- 0 0 0 0 0 0 0 0 0 0 0 0
40453- 0 0 0 0 0 0 0 0 0 0 0 0
40454- 0 0 0 0 0 0 0 0 0 0 0 0
40455- 0 0 0 0 0 0 0 0 0 0 0 0
40456- 0 0 0 0 0 0 0 0 0 0 0 0
40457- 0 0 0 0 0 0 0 0 0 0 0 0
40458- 0 0 0 0 0 0 0 0 0 0 0 0
40459- 0 0 0 0 0 0 0 0 0 0 0 0
40460- 0 0 0 0 0 0 0 0 0 0 0 0
40461- 0 0 0 0 0 0 0 0 0 6 6 6
40462- 6 6 6 10 10 10 14 14 14 18 18 18
40463- 18 18 18 14 14 14 10 10 10 6 6 6
40464- 0 0 0 0 0 0 0 0 0 0 0 0
40465- 0 0 0 0 0 0 0 0 0 0 0 0
40466- 0 0 0 0 0 0 0 0 0 0 0 0
40467- 0 0 0 0 0 0 0 0 0 0 0 0
40468- 0 0 0 0 0 0 0 0 0 6 6 6
40469- 14 14 14 18 18 18 22 22 22 22 22 22
40470- 18 18 18 14 14 14 10 10 10 6 6 6
40471- 0 0 0 0 0 0 0 0 0 0 0 0
40472- 0 0 0 0 0 0 0 0 0 0 0 0
40473- 0 0 0 0 0 0 0 0 0 0 0 0
40474- 0 0 0 0 0 0 0 0 0 0 0 0
40475- 0 0 0 0 0 0 0 0 0 0 0 0
40476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40480+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40481+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40484+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40489+4 4 4 4 4 4
40490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40492+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40495+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40497+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40498+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40503+4 4 4 4 4 4
40504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40506+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40509+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40512+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40517+4 4 4 4 4 4
40518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40520+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40523+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40526+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40530+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40531+4 4 4 4 4 4
40532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40533+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40534+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40537+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40540+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40545+4 4 4 4 4 4
40546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40554+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40559+4 4 4 4 4 4
40560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40564+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40565+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40568+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40569+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40570+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40571+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40573+4 4 4 4 4 4
40574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40578+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40579+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40580+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40583+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40584+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40585+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40586+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40587+4 4 4 4 4 4
40588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40592+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40593+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40594+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40597+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40598+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40599+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40600+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40601+4 4 4 4 4 4
40602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40605+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40606+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40607+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40608+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40610+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40611+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40612+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40613+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40614+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40615+4 4 4 4 4 4
40616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40619+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40620+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40621+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40622+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40623+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40624+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40625+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40626+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40627+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40628+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40629+4 4 4 4 4 4
40630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40633+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40634+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40635+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40636+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40637+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40638+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40639+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40640+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40641+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40642+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40643+4 4 4 4 4 4
40644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40646+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40647+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40648+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40649+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40650+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40651+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40652+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40653+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40654+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40655+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40656+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40657+4 4 4 4 4 4
40658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40660+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40661+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40662+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40663+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40664+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40665+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40666+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40667+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40668+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40669+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40670+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40671+4 4 4 4 4 4
40672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40674+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40675+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40676+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40677+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40678+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40679+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40680+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40681+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40682+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40683+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40684+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40685+4 4 4 4 4 4
40686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40688+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40689+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40690+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40691+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40692+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40693+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40694+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40695+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40696+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40697+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40698+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40699+4 4 4 4 4 4
40700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40701+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40702+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40703+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40704+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40705+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40706+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40707+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40708+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40709+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40710+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40711+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40712+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40713+4 4 4 4 4 4
40714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40715+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40716+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40717+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40718+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40719+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40720+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40721+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40722+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40723+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40724+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40725+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40726+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40727+0 0 0 4 4 4
40728+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40729+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40730+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40731+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40732+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40733+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40734+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40735+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40736+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40737+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40738+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40739+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40740+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40741+2 0 0 0 0 0
40742+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40743+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40744+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40745+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40746+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40747+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40748+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40749+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40750+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40751+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40752+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40753+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40754+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40755+37 38 37 0 0 0
40756+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40757+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40758+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40759+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40760+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40761+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40762+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40763+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40764+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40765+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40766+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40767+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40768+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40769+85 115 134 4 0 0
40770+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40771+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40772+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40773+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40774+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40775+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40776+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40777+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40778+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40779+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40780+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40781+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40782+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40783+60 73 81 4 0 0
40784+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40785+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40786+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40787+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40788+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40789+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40790+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40791+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40792+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40793+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40794+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40795+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40796+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40797+16 19 21 4 0 0
40798+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40799+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40800+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40801+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40802+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40803+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40804+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40805+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40806+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40807+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40808+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40809+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40810+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40811+4 0 0 4 3 3
40812+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40813+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40814+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40816+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40817+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40818+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40819+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40820+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40821+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40822+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40823+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40824+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40825+3 2 2 4 4 4
40826+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40827+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40828+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40829+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40830+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40831+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40832+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40833+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40834+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40835+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40836+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40837+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40838+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40839+4 4 4 4 4 4
40840+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40841+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40842+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40843+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40844+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40845+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40846+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40847+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40848+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40849+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40850+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40851+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40852+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40853+4 4 4 4 4 4
40854+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40855+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40856+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40857+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40858+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40859+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40860+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40861+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40862+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40863+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40864+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40865+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40866+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40867+5 5 5 5 5 5
40868+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40869+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40870+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40871+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40872+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40873+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40874+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40875+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40876+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40877+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40878+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40879+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40880+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40881+5 5 5 4 4 4
40882+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40883+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40884+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40885+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40886+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40887+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40888+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40889+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40890+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40891+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40892+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40893+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40895+4 4 4 4 4 4
40896+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40897+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40898+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40899+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40900+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40901+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40902+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40903+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40904+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40905+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40906+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40907+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
40908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40909+4 4 4 4 4 4
40910+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
40911+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40912+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40913+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40914+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40915+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
40916+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
40917+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
40918+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
40919+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
40920+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
40921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40923+4 4 4 4 4 4
40924+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
40925+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
40926+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
40927+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
40928+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40929+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40930+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40931+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
40932+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
40933+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
40934+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
40935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40937+4 4 4 4 4 4
40938+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
40939+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
40940+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
40941+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
40942+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40943+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
40944+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40945+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
40946+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
40947+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
40948+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40949+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
40952+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
40953+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
40954+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
40955+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
40956+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40957+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
40958+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
40959+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
40960+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
40961+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
40962+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
40963+4 4 4 4 4 4 4 4 4 4 4 4 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
40966+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
40967+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
40968+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
40969+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
40970+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40971+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
40972+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
40973+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
40974+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
40975+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
40976+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
40977+4 4 4 4 4 4 4 4 4 4 4 4 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
40980+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
40981+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
40982+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
40983+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40984+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
40985+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
40986+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
40987+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
40988+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
40989+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
40990+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40991+4 4 4 4 4 4 4 4 4 4 4 4 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
40994+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
40995+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
40996+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
40997+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40998+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40999+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41000+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41001+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41002+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41003+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41004+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41005+4 4 4 4 4 4 4 4 4 4 4 4 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
41008+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41009+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41010+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41011+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41012+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41013+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41014+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41015+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41016+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41017+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41018+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41019+4 4 4 4 4 4 4 4 4 4 4 4 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
41022+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41023+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41024+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41025+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41026+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41027+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41028+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41029+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41030+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41031+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41032+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41033+4 4 4 4 4 4 4 4 4 4 4 4 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
41036+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41037+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41038+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41039+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41040+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41041+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41042+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41043+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41044+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41045+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41046+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41047+4 4 4 4 4 4 4 4 4 4 4 4 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
41050+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41051+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41052+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41053+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41054+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41055+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41056+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41057+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41058+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41059+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41060+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41061+4 4 4 4 4 4 4 4 4 4 4 4 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
41064+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41065+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41066+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41067+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41068+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41069+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41070+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41071+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41072+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41073+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41074+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41075+4 4 4 4 4 4 4 4 4 4 4 4 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
41078+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41079+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41080+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41081+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41082+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41083+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41084+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41085+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41086+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41087+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41088+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41089+4 4 4 4 4 4 4 4 4 4 4 4 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
41092+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41093+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41094+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41095+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41096+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41097+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41098+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41099+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41100+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41101+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41102+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41103+4 4 4 4 4 4 4 4 4 4 4 4 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
41106+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41107+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41108+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41109+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41110+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41111+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41112+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41113+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41114+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41115+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41116+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41119+4 4 4 4 4 4
41120+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41121+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41122+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41123+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41124+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41125+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41126+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41127+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41128+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41129+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41130+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41133+4 4 4 4 4 4
41134+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41135+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41136+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41137+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41138+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41139+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41140+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41141+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41142+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41143+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41144+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41147+4 4 4 4 4 4
41148+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41149+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41150+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41151+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41152+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41153+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41154+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41155+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41156+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41157+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41158+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41161+4 4 4 4 4 4
41162+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41163+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41164+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41165+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41166+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41167+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41168+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41169+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41170+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41171+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41172+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41175+4 4 4 4 4 4
41176+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41177+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41178+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41179+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41180+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41181+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41182+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41183+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41184+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41185+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41186+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41189+4 4 4 4 4 4
41190+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41191+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41192+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41193+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41194+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41195+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41196+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41197+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41198+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41199+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41200+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41203+4 4 4 4 4 4
41204+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41205+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41206+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41207+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41208+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41209+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41210+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41211+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41212+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41213+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41214+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41217+4 4 4 4 4 4
41218+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41219+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41220+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41221+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41222+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41223+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41224+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41225+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41226+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41227+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41228+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41231+4 4 4 4 4 4
41232+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41233+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41234+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41235+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41236+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41237+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41238+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41239+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41240+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41241+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41242+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41245+4 4 4 4 4 4
41246+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41247+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41248+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41249+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41250+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41251+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41252+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41253+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41254+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41255+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41256+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41259+4 4 4 4 4 4
41260+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41261+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41262+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41263+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41264+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41265+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41266+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41267+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41268+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41269+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41270+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41273+4 4 4 4 4 4
41274+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41275+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41276+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41277+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41278+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41279+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41280+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41281+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41282+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41283+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41284+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41287+4 4 4 4 4 4
41288+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41289+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41290+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41291+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41292+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41293+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41294+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41295+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41296+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41297+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41301+4 4 4 4 4 4
41302+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41303+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41304+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41305+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41306+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41307+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41308+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41309+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41310+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41311+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41315+4 4 4 4 4 4
41316+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41317+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41318+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41319+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41320+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41321+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41322+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41323+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41324+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41325+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41326+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41329+4 4 4 4 4 4
41330+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41331+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41332+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41333+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41334+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41335+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41336+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41337+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41338+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41339+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343+4 4 4 4 4 4
41344+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41345+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41346+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41347+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41348+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41349+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41350+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41351+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41352+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357+4 4 4 4 4 4
41358+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41359+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41360+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41361+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41362+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41363+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41364+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41365+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41366+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41368+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41371+4 4 4 4 4 4
41372+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41373+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41374+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41375+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41376+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41377+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41378+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41379+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41380+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41382+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41385+4 4 4 4 4 4
41386+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41387+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41388+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41389+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41390+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41391+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41392+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41393+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41399+4 4 4 4 4 4
41400+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41401+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41402+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41403+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41404+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41405+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41406+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41407+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41413+4 4 4 4 4 4
41414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41415+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41416+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41417+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41418+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41419+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41420+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41421+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41427+4 4 4 4 4 4
41428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41429+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41430+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41431+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41432+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41433+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41434+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41435+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41441+4 4 4 4 4 4
41442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41443+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41444+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41445+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41446+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41447+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41448+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41449+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41453+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41455+4 4 4 4 4 4
41456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41458+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41459+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41460+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41461+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41462+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41463+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41466+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41467+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41469+4 4 4 4 4 4
41470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41473+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41474+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41475+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41476+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41480+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41481+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41483+4 4 4 4 4 4
41484+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41487+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41488+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41489+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41490+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41492+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41495+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41497+4 4 4 4 4 4
41498+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41501+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41502+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41503+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41504+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41506+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41509+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41511+4 4 4 4 4 4
41512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41515+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41516+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41517+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41518+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41520+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41523+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41525+4 4 4 4 4 4
41526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41527+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41530+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41531+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41532+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41533+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41534+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41537+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41539+4 4 4 4 4 4
41540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41541+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41544+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41545+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41546+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41553+4 4 4 4 4 4
41554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41558+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41559+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41560+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41567+4 4 4 4 4 4
41568+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41572+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41573+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41579+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41581+4 4 4 4 4 4
41582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41586+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41587+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41595+4 4 4 4 4 4
41596diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41597index a40c05e..785c583 100644
41598--- a/drivers/video/udlfb.c
41599+++ b/drivers/video/udlfb.c
41600@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41601 dlfb_urb_completion(urb);
41602
41603 error:
41604- atomic_add(bytes_sent, &dev->bytes_sent);
41605- atomic_add(bytes_identical, &dev->bytes_identical);
41606- atomic_add(width*height*2, &dev->bytes_rendered);
41607+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41608+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41609+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41610 end_cycles = get_cycles();
41611- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41612+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41613 >> 10)), /* Kcycles */
41614 &dev->cpu_kcycles_used);
41615
41616@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41617 dlfb_urb_completion(urb);
41618
41619 error:
41620- atomic_add(bytes_sent, &dev->bytes_sent);
41621- atomic_add(bytes_identical, &dev->bytes_identical);
41622- atomic_add(bytes_rendered, &dev->bytes_rendered);
41623+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41624+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41625+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41626 end_cycles = get_cycles();
41627- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41628+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41629 >> 10)), /* Kcycles */
41630 &dev->cpu_kcycles_used);
41631 }
41632@@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41633 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41634 struct dlfb_data *dev = fb_info->par;
41635 return snprintf(buf, PAGE_SIZE, "%u\n",
41636- atomic_read(&dev->bytes_rendered));
41637+ atomic_read_unchecked(&dev->bytes_rendered));
41638 }
41639
41640 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41641@@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41642 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41643 struct dlfb_data *dev = fb_info->par;
41644 return snprintf(buf, PAGE_SIZE, "%u\n",
41645- atomic_read(&dev->bytes_identical));
41646+ atomic_read_unchecked(&dev->bytes_identical));
41647 }
41648
41649 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41650@@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41651 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41652 struct dlfb_data *dev = fb_info->par;
41653 return snprintf(buf, PAGE_SIZE, "%u\n",
41654- atomic_read(&dev->bytes_sent));
41655+ atomic_read_unchecked(&dev->bytes_sent));
41656 }
41657
41658 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41659@@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41660 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41661 struct dlfb_data *dev = fb_info->par;
41662 return snprintf(buf, PAGE_SIZE, "%u\n",
41663- atomic_read(&dev->cpu_kcycles_used));
41664+ atomic_read_unchecked(&dev->cpu_kcycles_used));
41665 }
41666
41667 static ssize_t edid_show(
41668@@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41669 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41670 struct dlfb_data *dev = fb_info->par;
41671
41672- atomic_set(&dev->bytes_rendered, 0);
41673- atomic_set(&dev->bytes_identical, 0);
41674- atomic_set(&dev->bytes_sent, 0);
41675- atomic_set(&dev->cpu_kcycles_used, 0);
41676+ atomic_set_unchecked(&dev->bytes_rendered, 0);
41677+ atomic_set_unchecked(&dev->bytes_identical, 0);
41678+ atomic_set_unchecked(&dev->bytes_sent, 0);
41679+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41680
41681 return count;
41682 }
41683diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41684index 8408543..d6f20f1 100644
41685--- a/drivers/video/uvesafb.c
41686+++ b/drivers/video/uvesafb.c
41687@@ -19,6 +19,7 @@
41688 #include <linux/io.h>
41689 #include <linux/mutex.h>
41690 #include <linux/slab.h>
41691+#include <linux/moduleloader.h>
41692 #include <video/edid.h>
41693 #include <video/uvesafb.h>
41694 #ifdef CONFIG_X86
41695@@ -73,7 +74,7 @@ static void uvesafb_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *ns
41696 struct uvesafb_task *utask;
41697 struct uvesafb_ktask *task;
41698
41699- if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
41700+ if (!capable(CAP_SYS_ADMIN))
41701 return;
41702
41703 if (msg->seq >= UVESAFB_TASKS_MAX)
41704@@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
41705 NULL,
41706 };
41707
41708- return call_usermodehelper(v86d_path, argv, envp, 1);
41709+ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
41710 }
41711
41712 /*
41713@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41714 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41715 par->pmi_setpal = par->ypan = 0;
41716 } else {
41717+
41718+#ifdef CONFIG_PAX_KERNEXEC
41719+#ifdef CONFIG_MODULES
41720+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41721+#endif
41722+ if (!par->pmi_code) {
41723+ par->pmi_setpal = par->ypan = 0;
41724+ return 0;
41725+ }
41726+#endif
41727+
41728 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41729 + task->t.regs.edi);
41730+
41731+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41732+ pax_open_kernel();
41733+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41734+ pax_close_kernel();
41735+
41736+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41737+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41738+#else
41739 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41740 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41741+#endif
41742+
41743 printk(KERN_INFO "uvesafb: protected mode interface info at "
41744 "%04x:%04x\n",
41745 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41746@@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
41747 par->ypan = ypan;
41748
41749 if (par->pmi_setpal || par->ypan) {
41750+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
41751 if (__supported_pte_mask & _PAGE_NX) {
41752 par->pmi_setpal = par->ypan = 0;
41753 printk(KERN_WARNING "uvesafb: NX protection is actively."
41754 "We have better not to use the PMI.\n");
41755- } else {
41756+ } else
41757+#endif
41758 uvesafb_vbe_getpmi(task, par);
41759- }
41760 }
41761 #else
41762 /* The protected mode interface is not available on non-x86. */
41763@@ -1828,6 +1852,11 @@ out:
41764 if (par->vbe_modes)
41765 kfree(par->vbe_modes);
41766
41767+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41768+ if (par->pmi_code)
41769+ module_free_exec(NULL, par->pmi_code);
41770+#endif
41771+
41772 framebuffer_release(info);
41773 return err;
41774 }
41775@@ -1854,6 +1883,12 @@ static int uvesafb_remove(struct platform_device *dev)
41776 kfree(par->vbe_state_orig);
41777 if (par->vbe_state_saved)
41778 kfree(par->vbe_state_saved);
41779+
41780+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41781+ if (par->pmi_code)
41782+ module_free_exec(NULL, par->pmi_code);
41783+#endif
41784+
41785 }
41786
41787 framebuffer_release(info);
41788diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41789index 501b340..86bd4cf 100644
41790--- a/drivers/video/vesafb.c
41791+++ b/drivers/video/vesafb.c
41792@@ -9,6 +9,7 @@
41793 */
41794
41795 #include <linux/module.h>
41796+#include <linux/moduleloader.h>
41797 #include <linux/kernel.h>
41798 #include <linux/errno.h>
41799 #include <linux/string.h>
41800@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41801 static int vram_total __initdata; /* Set total amount of memory */
41802 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41803 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41804-static void (*pmi_start)(void) __read_mostly;
41805-static void (*pmi_pal) (void) __read_mostly;
41806+static void (*pmi_start)(void) __read_only;
41807+static void (*pmi_pal) (void) __read_only;
41808 static int depth __read_mostly;
41809 static int vga_compat __read_mostly;
41810 /* --------------------------------------------------------------------- */
41811@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41812 unsigned int size_vmode;
41813 unsigned int size_remap;
41814 unsigned int size_total;
41815+ void *pmi_code = NULL;
41816
41817 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41818 return -ENODEV;
41819@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41820 size_remap = size_total;
41821 vesafb_fix.smem_len = size_remap;
41822
41823-#ifndef __i386__
41824- screen_info.vesapm_seg = 0;
41825-#endif
41826-
41827 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41828 printk(KERN_WARNING
41829 "vesafb: cannot reserve video memory at 0x%lx\n",
41830@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41831 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41832 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41833
41834+#ifdef __i386__
41835+
41836+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41837+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
41838+ if (!pmi_code)
41839+#elif !defined(CONFIG_PAX_KERNEXEC)
41840+ if (0)
41841+#endif
41842+
41843+#endif
41844+ screen_info.vesapm_seg = 0;
41845+
41846 if (screen_info.vesapm_seg) {
41847- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41848- screen_info.vesapm_seg,screen_info.vesapm_off);
41849+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41850+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41851 }
41852
41853 if (screen_info.vesapm_seg < 0xc000)
41854@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41855
41856 if (ypan || pmi_setpal) {
41857 unsigned short *pmi_base;
41858+
41859 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41860- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41861- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41862+
41863+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41864+ pax_open_kernel();
41865+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41866+#else
41867+ pmi_code = pmi_base;
41868+#endif
41869+
41870+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41871+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41872+
41873+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41874+ pmi_start = ktva_ktla(pmi_start);
41875+ pmi_pal = ktva_ktla(pmi_pal);
41876+ pax_close_kernel();
41877+#endif
41878+
41879 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41880 if (pmi_base[3]) {
41881 printk(KERN_INFO "vesafb: pmi: ports = ");
41882@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41883 info->node, info->fix.id);
41884 return 0;
41885 err:
41886+
41887+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41888+ module_free_exec(NULL, pmi_code);
41889+#endif
41890+
41891 if (info->screen_base)
41892 iounmap(info->screen_base);
41893 framebuffer_release(info);
41894diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41895index 88714ae..16c2e11 100644
41896--- a/drivers/video/via/via_clock.h
41897+++ b/drivers/video/via/via_clock.h
41898@@ -56,7 +56,7 @@ struct via_clock {
41899
41900 void (*set_engine_pll_state)(u8 state);
41901 void (*set_engine_pll)(struct via_pll_config config);
41902-};
41903+} __no_const;
41904
41905
41906 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41907diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41908index e56c934..fc22f4b 100644
41909--- a/drivers/xen/xen-pciback/conf_space.h
41910+++ b/drivers/xen/xen-pciback/conf_space.h
41911@@ -44,15 +44,15 @@ struct config_field {
41912 struct {
41913 conf_dword_write write;
41914 conf_dword_read read;
41915- } dw;
41916+ } __no_const dw;
41917 struct {
41918 conf_word_write write;
41919 conf_word_read read;
41920- } w;
41921+ } __no_const w;
41922 struct {
41923 conf_byte_write write;
41924 conf_byte_read read;
41925- } b;
41926+ } __no_const b;
41927 } u;
41928 struct list_head list;
41929 };
41930diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
41931index 014c8dd..6f3dfe6 100644
41932--- a/fs/9p/vfs_inode.c
41933+++ b/fs/9p/vfs_inode.c
41934@@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41935 void
41936 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41937 {
41938- char *s = nd_get_link(nd);
41939+ const char *s = nd_get_link(nd);
41940
41941 p9_debug(P9_DEBUG_VFS, " %s %s\n",
41942 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
41943diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
41944index e95d1b6..3454244 100644
41945--- a/fs/Kconfig.binfmt
41946+++ b/fs/Kconfig.binfmt
41947@@ -89,7 +89,7 @@ config HAVE_AOUT
41948
41949 config BINFMT_AOUT
41950 tristate "Kernel support for a.out and ECOFF binaries"
41951- depends on HAVE_AOUT
41952+ depends on HAVE_AOUT && BROKEN
41953 ---help---
41954 A.out (Assembler.OUTput) is a set of formats for libraries and
41955 executables used in the earliest versions of UNIX. Linux used
41956diff --git a/fs/aio.c b/fs/aio.c
41957index b9d64d8..86cb1d5 100644
41958--- a/fs/aio.c
41959+++ b/fs/aio.c
41960@@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
41961 size += sizeof(struct io_event) * nr_events;
41962 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
41963
41964- if (nr_pages < 0)
41965+ if (nr_pages <= 0)
41966 return -EINVAL;
41967
41968 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
41969@@ -1461,22 +1461,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
41970 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41971 {
41972 ssize_t ret;
41973+ struct iovec iovstack;
41974
41975 #ifdef CONFIG_COMPAT
41976 if (compat)
41977 ret = compat_rw_copy_check_uvector(type,
41978 (struct compat_iovec __user *)kiocb->ki_buf,
41979- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41980+ kiocb->ki_nbytes, 1, &iovstack,
41981 &kiocb->ki_iovec, 1);
41982 else
41983 #endif
41984 ret = rw_copy_check_uvector(type,
41985 (struct iovec __user *)kiocb->ki_buf,
41986- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41987+ kiocb->ki_nbytes, 1, &iovstack,
41988 &kiocb->ki_iovec, 1);
41989 if (ret < 0)
41990 goto out;
41991
41992+ if (kiocb->ki_iovec == &iovstack) {
41993+ kiocb->ki_inline_vec = iovstack;
41994+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
41995+ }
41996 kiocb->ki_nr_segs = kiocb->ki_nbytes;
41997 kiocb->ki_cur_seg = 0;
41998 /* ki_nbytes/left now reflect bytes instead of segs */
41999diff --git a/fs/attr.c b/fs/attr.c
42000index 95053ad..2cc93ca 100644
42001--- a/fs/attr.c
42002+++ b/fs/attr.c
42003@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42004 unsigned long limit;
42005
42006 limit = rlimit(RLIMIT_FSIZE);
42007+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42008 if (limit != RLIM_INFINITY && offset > limit)
42009 goto out_sig;
42010 if (offset > inode->i_sb->s_maxbytes)
42011diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42012index f624cd0..3d9a559 100644
42013--- a/fs/autofs4/waitq.c
42014+++ b/fs/autofs4/waitq.c
42015@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42016 {
42017 unsigned long sigpipe, flags;
42018 mm_segment_t fs;
42019- const char *data = (const char *)addr;
42020+ const char __user *data = (const char __force_user *)addr;
42021 ssize_t wr = 0;
42022
42023 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42024diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42025index 6e6d536..457113a 100644
42026--- a/fs/befs/linuxvfs.c
42027+++ b/fs/befs/linuxvfs.c
42028@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42029 {
42030 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42031 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42032- char *link = nd_get_link(nd);
42033+ const char *link = nd_get_link(nd);
42034 if (!IS_ERR(link))
42035 kfree(link);
42036 }
42037diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42038index 1ff9405..f1e376a 100644
42039--- a/fs/binfmt_aout.c
42040+++ b/fs/binfmt_aout.c
42041@@ -16,6 +16,7 @@
42042 #include <linux/string.h>
42043 #include <linux/fs.h>
42044 #include <linux/file.h>
42045+#include <linux/security.h>
42046 #include <linux/stat.h>
42047 #include <linux/fcntl.h>
42048 #include <linux/ptrace.h>
42049@@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42050 #endif
42051 # define START_STACK(u) ((void __user *)u.start_stack)
42052
42053+ memset(&dump, 0, sizeof(dump));
42054+
42055 fs = get_fs();
42056 set_fs(KERNEL_DS);
42057 has_dumped = 1;
42058@@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42059
42060 /* If the size of the dump file exceeds the rlimit, then see what would happen
42061 if we wrote the stack, but not the data area. */
42062+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42063 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42064 dump.u_dsize = 0;
42065
42066 /* Make sure we have enough room to write the stack and data areas. */
42067+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42068 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42069 dump.u_ssize = 0;
42070
42071@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42072 rlim = rlimit(RLIMIT_DATA);
42073 if (rlim >= RLIM_INFINITY)
42074 rlim = ~0;
42075+
42076+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42077 if (ex.a_data + ex.a_bss > rlim)
42078 return -ENOMEM;
42079
42080@@ -269,6 +276,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42081 install_exec_creds(bprm);
42082 current->flags &= ~PF_FORKNOEXEC;
42083
42084+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42085+ current->mm->pax_flags = 0UL;
42086+#endif
42087+
42088+#ifdef CONFIG_PAX_PAGEEXEC
42089+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42090+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42091+
42092+#ifdef CONFIG_PAX_EMUTRAMP
42093+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42094+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42095+#endif
42096+
42097+#ifdef CONFIG_PAX_MPROTECT
42098+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42099+ current->mm->pax_flags |= MF_PAX_MPROTECT;
42100+#endif
42101+
42102+ }
42103+#endif
42104+
42105 if (N_MAGIC(ex) == OMAGIC) {
42106 unsigned long text_addr, map_size;
42107 loff_t pos;
42108@@ -341,7 +369,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42109
42110 down_write(&current->mm->mmap_sem);
42111 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42112- PROT_READ | PROT_WRITE | PROT_EXEC,
42113+ PROT_READ | PROT_WRITE,
42114 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42115 fd_offset + ex.a_text);
42116 up_write(&current->mm->mmap_sem);
42117diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42118index 07d096c..25762af 100644
42119--- a/fs/binfmt_elf.c
42120+++ b/fs/binfmt_elf.c
42121@@ -32,6 +32,7 @@
42122 #include <linux/elf.h>
42123 #include <linux/utsname.h>
42124 #include <linux/coredump.h>
42125+#include <linux/xattr.h>
42126 #include <asm/uaccess.h>
42127 #include <asm/param.h>
42128 #include <asm/page.h>
42129@@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42130 #define elf_core_dump NULL
42131 #endif
42132
42133+#ifdef CONFIG_PAX_MPROTECT
42134+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42135+#endif
42136+
42137 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42138 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42139 #else
42140@@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
42141 .load_binary = load_elf_binary,
42142 .load_shlib = load_elf_library,
42143 .core_dump = elf_core_dump,
42144+
42145+#ifdef CONFIG_PAX_MPROTECT
42146+ .handle_mprotect= elf_handle_mprotect,
42147+#endif
42148+
42149 .min_coredump = ELF_EXEC_PAGESIZE,
42150 };
42151
42152@@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
42153
42154 static int set_brk(unsigned long start, unsigned long end)
42155 {
42156+ unsigned long e = end;
42157+
42158 start = ELF_PAGEALIGN(start);
42159 end = ELF_PAGEALIGN(end);
42160 if (end > start) {
42161@@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
42162 if (BAD_ADDR(addr))
42163 return addr;
42164 }
42165- current->mm->start_brk = current->mm->brk = end;
42166+ current->mm->start_brk = current->mm->brk = e;
42167 return 0;
42168 }
42169
42170@@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42171 elf_addr_t __user *u_rand_bytes;
42172 const char *k_platform = ELF_PLATFORM;
42173 const char *k_base_platform = ELF_BASE_PLATFORM;
42174- unsigned char k_rand_bytes[16];
42175+ u32 k_rand_bytes[4];
42176 int items;
42177 elf_addr_t *elf_info;
42178 int ei_index = 0;
42179 const struct cred *cred = current_cred();
42180 struct vm_area_struct *vma;
42181+ unsigned long saved_auxv[AT_VECTOR_SIZE];
42182
42183 /*
42184 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42185@@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42186 * Generate 16 random bytes for userspace PRNG seeding.
42187 */
42188 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42189- u_rand_bytes = (elf_addr_t __user *)
42190- STACK_ALLOC(p, sizeof(k_rand_bytes));
42191+ srandom32(k_rand_bytes[0] ^ random32());
42192+ srandom32(k_rand_bytes[1] ^ random32());
42193+ srandom32(k_rand_bytes[2] ^ random32());
42194+ srandom32(k_rand_bytes[3] ^ random32());
42195+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
42196+ u_rand_bytes = (elf_addr_t __user *) p;
42197 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42198 return -EFAULT;
42199
42200@@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42201 return -EFAULT;
42202 current->mm->env_end = p;
42203
42204+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42205+
42206 /* Put the elf_info on the stack in the right place. */
42207 sp = (elf_addr_t __user *)envp + 1;
42208- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42209+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42210 return -EFAULT;
42211 return 0;
42212 }
42213@@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42214 {
42215 struct elf_phdr *elf_phdata;
42216 struct elf_phdr *eppnt;
42217- unsigned long load_addr = 0;
42218+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42219 int load_addr_set = 0;
42220 unsigned long last_bss = 0, elf_bss = 0;
42221- unsigned long error = ~0UL;
42222+ unsigned long error = -EINVAL;
42223 unsigned long total_size;
42224 int retval, i, size;
42225
42226@@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42227 goto out_close;
42228 }
42229
42230+#ifdef CONFIG_PAX_SEGMEXEC
42231+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42232+ pax_task_size = SEGMEXEC_TASK_SIZE;
42233+#endif
42234+
42235 eppnt = elf_phdata;
42236 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42237 if (eppnt->p_type == PT_LOAD) {
42238@@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42239 k = load_addr + eppnt->p_vaddr;
42240 if (BAD_ADDR(k) ||
42241 eppnt->p_filesz > eppnt->p_memsz ||
42242- eppnt->p_memsz > TASK_SIZE ||
42243- TASK_SIZE - eppnt->p_memsz < k) {
42244+ eppnt->p_memsz > pax_task_size ||
42245+ pax_task_size - eppnt->p_memsz < k) {
42246 error = -ENOMEM;
42247 goto out_close;
42248 }
42249@@ -528,6 +552,351 @@ out:
42250 return error;
42251 }
42252
42253+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42254+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42255+{
42256+ unsigned long pax_flags = 0UL;
42257+
42258+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42259+
42260+#ifdef CONFIG_PAX_PAGEEXEC
42261+ if (elf_phdata->p_flags & PF_PAGEEXEC)
42262+ pax_flags |= MF_PAX_PAGEEXEC;
42263+#endif
42264+
42265+#ifdef CONFIG_PAX_SEGMEXEC
42266+ if (elf_phdata->p_flags & PF_SEGMEXEC)
42267+ pax_flags |= MF_PAX_SEGMEXEC;
42268+#endif
42269+
42270+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42271+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42272+ if ((__supported_pte_mask & _PAGE_NX))
42273+ pax_flags &= ~MF_PAX_SEGMEXEC;
42274+ else
42275+ pax_flags &= ~MF_PAX_PAGEEXEC;
42276+ }
42277+#endif
42278+
42279+#ifdef CONFIG_PAX_EMUTRAMP
42280+ if (elf_phdata->p_flags & PF_EMUTRAMP)
42281+ pax_flags |= MF_PAX_EMUTRAMP;
42282+#endif
42283+
42284+#ifdef CONFIG_PAX_MPROTECT
42285+ if (elf_phdata->p_flags & PF_MPROTECT)
42286+ pax_flags |= MF_PAX_MPROTECT;
42287+#endif
42288+
42289+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42290+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42291+ pax_flags |= MF_PAX_RANDMMAP;
42292+#endif
42293+
42294+#endif
42295+
42296+ return pax_flags;
42297+}
42298+
42299+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42300+{
42301+ unsigned long pax_flags = 0UL;
42302+
42303+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42304+
42305+#ifdef CONFIG_PAX_PAGEEXEC
42306+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42307+ pax_flags |= MF_PAX_PAGEEXEC;
42308+#endif
42309+
42310+#ifdef CONFIG_PAX_SEGMEXEC
42311+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42312+ pax_flags |= MF_PAX_SEGMEXEC;
42313+#endif
42314+
42315+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42316+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42317+ if ((__supported_pte_mask & _PAGE_NX))
42318+ pax_flags &= ~MF_PAX_SEGMEXEC;
42319+ else
42320+ pax_flags &= ~MF_PAX_PAGEEXEC;
42321+ }
42322+#endif
42323+
42324+#ifdef CONFIG_PAX_EMUTRAMP
42325+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42326+ pax_flags |= MF_PAX_EMUTRAMP;
42327+#endif
42328+
42329+#ifdef CONFIG_PAX_MPROTECT
42330+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42331+ pax_flags |= MF_PAX_MPROTECT;
42332+#endif
42333+
42334+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42335+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42336+ pax_flags |= MF_PAX_RANDMMAP;
42337+#endif
42338+
42339+#endif
42340+
42341+ return pax_flags;
42342+}
42343+
42344+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42345+{
42346+ unsigned long pax_flags = 0UL;
42347+
42348+#ifdef CONFIG_PAX_EI_PAX
42349+
42350+#ifdef CONFIG_PAX_PAGEEXEC
42351+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42352+ pax_flags |= MF_PAX_PAGEEXEC;
42353+#endif
42354+
42355+#ifdef CONFIG_PAX_SEGMEXEC
42356+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42357+ pax_flags |= MF_PAX_SEGMEXEC;
42358+#endif
42359+
42360+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42361+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42362+ if ((__supported_pte_mask & _PAGE_NX))
42363+ pax_flags &= ~MF_PAX_SEGMEXEC;
42364+ else
42365+ pax_flags &= ~MF_PAX_PAGEEXEC;
42366+ }
42367+#endif
42368+
42369+#ifdef CONFIG_PAX_EMUTRAMP
42370+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42371+ pax_flags |= MF_PAX_EMUTRAMP;
42372+#endif
42373+
42374+#ifdef CONFIG_PAX_MPROTECT
42375+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42376+ pax_flags |= MF_PAX_MPROTECT;
42377+#endif
42378+
42379+#ifdef CONFIG_PAX_ASLR
42380+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42381+ pax_flags |= MF_PAX_RANDMMAP;
42382+#endif
42383+
42384+#else
42385+
42386+#ifdef CONFIG_PAX_PAGEEXEC
42387+ pax_flags |= MF_PAX_PAGEEXEC;
42388+#endif
42389+
42390+#ifdef CONFIG_PAX_MPROTECT
42391+ pax_flags |= MF_PAX_MPROTECT;
42392+#endif
42393+
42394+#ifdef CONFIG_PAX_RANDMMAP
42395+ pax_flags |= MF_PAX_RANDMMAP;
42396+#endif
42397+
42398+#ifdef CONFIG_PAX_SEGMEXEC
42399+ if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
42400+ pax_flags &= ~MF_PAX_PAGEEXEC;
42401+ pax_flags |= MF_PAX_SEGMEXEC;
42402+ }
42403+#endif
42404+
42405+#endif
42406+
42407+ return pax_flags;
42408+}
42409+
42410+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42411+{
42412+
42413+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42414+ unsigned long i;
42415+
42416+ for (i = 0UL; i < elf_ex->e_phnum; i++)
42417+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42418+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42419+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42420+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42421+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42422+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42423+ return ~0UL;
42424+
42425+#ifdef CONFIG_PAX_SOFTMODE
42426+ if (pax_softmode)
42427+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42428+ else
42429+#endif
42430+
42431+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42432+ break;
42433+ }
42434+#endif
42435+
42436+ return ~0UL;
42437+}
42438+
42439+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42440+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42441+{
42442+ unsigned long pax_flags = 0UL;
42443+
42444+#ifdef CONFIG_PAX_PAGEEXEC
42445+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42446+ pax_flags |= MF_PAX_PAGEEXEC;
42447+#endif
42448+
42449+#ifdef CONFIG_PAX_SEGMEXEC
42450+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42451+ pax_flags |= MF_PAX_SEGMEXEC;
42452+#endif
42453+
42454+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42455+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42456+ if ((__supported_pte_mask & _PAGE_NX))
42457+ pax_flags &= ~MF_PAX_SEGMEXEC;
42458+ else
42459+ pax_flags &= ~MF_PAX_PAGEEXEC;
42460+ }
42461+#endif
42462+
42463+#ifdef CONFIG_PAX_EMUTRAMP
42464+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42465+ pax_flags |= MF_PAX_EMUTRAMP;
42466+#endif
42467+
42468+#ifdef CONFIG_PAX_MPROTECT
42469+ if (pax_flags_softmode & MF_PAX_MPROTECT)
42470+ pax_flags |= MF_PAX_MPROTECT;
42471+#endif
42472+
42473+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42474+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42475+ pax_flags |= MF_PAX_RANDMMAP;
42476+#endif
42477+
42478+ return pax_flags;
42479+}
42480+
42481+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42482+{
42483+ unsigned long pax_flags = 0UL;
42484+
42485+#ifdef CONFIG_PAX_PAGEEXEC
42486+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42487+ pax_flags |= MF_PAX_PAGEEXEC;
42488+#endif
42489+
42490+#ifdef CONFIG_PAX_SEGMEXEC
42491+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42492+ pax_flags |= MF_PAX_SEGMEXEC;
42493+#endif
42494+
42495+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42496+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42497+ if ((__supported_pte_mask & _PAGE_NX))
42498+ pax_flags &= ~MF_PAX_SEGMEXEC;
42499+ else
42500+ pax_flags &= ~MF_PAX_PAGEEXEC;
42501+ }
42502+#endif
42503+
42504+#ifdef CONFIG_PAX_EMUTRAMP
42505+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42506+ pax_flags |= MF_PAX_EMUTRAMP;
42507+#endif
42508+
42509+#ifdef CONFIG_PAX_MPROTECT
42510+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42511+ pax_flags |= MF_PAX_MPROTECT;
42512+#endif
42513+
42514+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42515+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42516+ pax_flags |= MF_PAX_RANDMMAP;
42517+#endif
42518+
42519+ return pax_flags;
42520+}
42521+#endif
42522+
42523+static unsigned long pax_parse_xattr_pax(struct file * const file)
42524+{
42525+
42526+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42527+ ssize_t xattr_size, i;
42528+ unsigned char xattr_value[5];
42529+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42530+
42531+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42532+ if (xattr_size <= 0)
42533+ return ~0UL;
42534+
42535+ for (i = 0; i < xattr_size; i++)
42536+ switch (xattr_value[i]) {
42537+ default:
42538+ return ~0UL;
42539+
42540+#define parse_flag(option1, option2, flag) \
42541+ case option1: \
42542+ pax_flags_hardmode |= MF_PAX_##flag; \
42543+ break; \
42544+ case option2: \
42545+ pax_flags_softmode |= MF_PAX_##flag; \
42546+ break;
42547+
42548+ parse_flag('p', 'P', PAGEEXEC);
42549+ parse_flag('e', 'E', EMUTRAMP);
42550+ parse_flag('m', 'M', MPROTECT);
42551+ parse_flag('r', 'R', RANDMMAP);
42552+ parse_flag('s', 'S', SEGMEXEC);
42553+
42554+#undef parse_flag
42555+ }
42556+
42557+ if (pax_flags_hardmode & pax_flags_softmode)
42558+ return ~0UL;
42559+
42560+#ifdef CONFIG_PAX_SOFTMODE
42561+ if (pax_softmode)
42562+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42563+ else
42564+#endif
42565+
42566+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42567+#else
42568+ return ~0UL;
42569+#endif
42570+
42571+}
42572+
42573+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42574+{
42575+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42576+
42577+ pax_flags = pax_parse_ei_pax(elf_ex);
42578+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42579+ xattr_pax_flags = pax_parse_xattr_pax(file);
42580+
42581+ if (pt_pax_flags == ~0UL)
42582+ pt_pax_flags = xattr_pax_flags;
42583+ else if (xattr_pax_flags == ~0UL)
42584+ xattr_pax_flags = pt_pax_flags;
42585+ if (pt_pax_flags != xattr_pax_flags)
42586+ return -EINVAL;
42587+ if (pt_pax_flags != ~0UL)
42588+ pax_flags = pt_pax_flags;
42589+
42590+ if (0 > pax_check_flags(&pax_flags))
42591+ return -EINVAL;
42592+
42593+ current->mm->pax_flags = pax_flags;
42594+ return 0;
42595+}
42596+#endif
42597+
42598 /*
42599 * These are the functions used to load ELF style executables and shared
42600 * libraries. There is no binary dependent code anywhere else.
42601@@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42602 {
42603 unsigned int random_variable = 0;
42604
42605+#ifdef CONFIG_PAX_RANDUSTACK
42606+ if (randomize_va_space)
42607+ return stack_top - current->mm->delta_stack;
42608+#endif
42609+
42610 if ((current->flags & PF_RANDOMIZE) &&
42611 !(current->personality & ADDR_NO_RANDOMIZE)) {
42612 random_variable = get_random_int() & STACK_RND_MASK;
42613@@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42614 unsigned long load_addr = 0, load_bias = 0;
42615 int load_addr_set = 0;
42616 char * elf_interpreter = NULL;
42617- unsigned long error;
42618+ unsigned long error = 0;
42619 struct elf_phdr *elf_ppnt, *elf_phdata;
42620 unsigned long elf_bss, elf_brk;
42621 int retval, i;
42622@@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42623 unsigned long start_code, end_code, start_data, end_data;
42624 unsigned long reloc_func_desc __maybe_unused = 0;
42625 int executable_stack = EXSTACK_DEFAULT;
42626- unsigned long def_flags = 0;
42627 struct {
42628 struct elfhdr elf_ex;
42629 struct elfhdr interp_elf_ex;
42630 } *loc;
42631+ unsigned long pax_task_size = TASK_SIZE;
42632
42633 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42634 if (!loc) {
42635@@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42636
42637 /* OK, This is the point of no return */
42638 current->flags &= ~PF_FORKNOEXEC;
42639- current->mm->def_flags = def_flags;
42640+
42641+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42642+ current->mm->pax_flags = 0UL;
42643+#endif
42644+
42645+#ifdef CONFIG_PAX_DLRESOLVE
42646+ current->mm->call_dl_resolve = 0UL;
42647+#endif
42648+
42649+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42650+ current->mm->call_syscall = 0UL;
42651+#endif
42652+
42653+#ifdef CONFIG_PAX_ASLR
42654+ current->mm->delta_mmap = 0UL;
42655+ current->mm->delta_stack = 0UL;
42656+#endif
42657+
42658+ current->mm->def_flags = 0;
42659+
42660+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42661+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42662+ send_sig(SIGKILL, current, 0);
42663+ goto out_free_dentry;
42664+ }
42665+#endif
42666+
42667+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42668+ pax_set_initial_flags(bprm);
42669+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42670+ if (pax_set_initial_flags_func)
42671+ (pax_set_initial_flags_func)(bprm);
42672+#endif
42673+
42674+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42675+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42676+ current->mm->context.user_cs_limit = PAGE_SIZE;
42677+ current->mm->def_flags |= VM_PAGEEXEC;
42678+ }
42679+#endif
42680+
42681+#ifdef CONFIG_PAX_SEGMEXEC
42682+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42683+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42684+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42685+ pax_task_size = SEGMEXEC_TASK_SIZE;
42686+ current->mm->def_flags |= VM_NOHUGEPAGE;
42687+ }
42688+#endif
42689+
42690+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42691+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42692+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42693+ put_cpu();
42694+ }
42695+#endif
42696
42697 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42698 may depend on the personality. */
42699 SET_PERSONALITY(loc->elf_ex);
42700+
42701+#ifdef CONFIG_PAX_ASLR
42702+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42703+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42704+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42705+ }
42706+#endif
42707+
42708+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42709+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42710+ executable_stack = EXSTACK_DISABLE_X;
42711+ current->personality &= ~READ_IMPLIES_EXEC;
42712+ } else
42713+#endif
42714+
42715 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42716 current->personality |= READ_IMPLIES_EXEC;
42717
42718@@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42719 #else
42720 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42721 #endif
42722+
42723+#ifdef CONFIG_PAX_RANDMMAP
42724+ /* PaX: randomize base address at the default exe base if requested */
42725+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42726+#ifdef CONFIG_SPARC64
42727+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42728+#else
42729+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42730+#endif
42731+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42732+ elf_flags |= MAP_FIXED;
42733+ }
42734+#endif
42735+
42736 }
42737
42738 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42739@@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42740 * allowed task size. Note that p_filesz must always be
42741 * <= p_memsz so it is only necessary to check p_memsz.
42742 */
42743- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42744- elf_ppnt->p_memsz > TASK_SIZE ||
42745- TASK_SIZE - elf_ppnt->p_memsz < k) {
42746+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42747+ elf_ppnt->p_memsz > pax_task_size ||
42748+ pax_task_size - elf_ppnt->p_memsz < k) {
42749 /* set_brk can never work. Avoid overflows. */
42750 send_sig(SIGKILL, current, 0);
42751 retval = -EINVAL;
42752@@ -881,11 +1339,40 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42753 goto out_free_dentry;
42754 }
42755 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42756- send_sig(SIGSEGV, current, 0);
42757- retval = -EFAULT; /* Nobody gets to see this, but.. */
42758- goto out_free_dentry;
42759+ /*
42760+ * This bss-zeroing can fail if the ELF
42761+ * file specifies odd protections. So
42762+ * we don't check the return value
42763+ */
42764 }
42765
42766+#ifdef CONFIG_PAX_RANDMMAP
42767+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42768+ unsigned long start, size;
42769+
42770+ start = ELF_PAGEALIGN(elf_brk);
42771+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42772+ down_write(&current->mm->mmap_sem);
42773+ retval = -ENOMEM;
42774+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42775+ unsigned long prot = PROT_NONE;
42776+
42777+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42778+// if (current->personality & ADDR_NO_RANDOMIZE)
42779+// prot = PROT_READ;
42780+ start = do_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42781+ retval = IS_ERR_VALUE(start) ? start : 0;
42782+ }
42783+ up_write(&current->mm->mmap_sem);
42784+ if (retval == 0)
42785+ retval = set_brk(start + size, start + size + PAGE_SIZE);
42786+ if (retval < 0) {
42787+ send_sig(SIGKILL, current, 0);
42788+ goto out_free_dentry;
42789+ }
42790+ }
42791+#endif
42792+
42793 if (elf_interpreter) {
42794 unsigned long uninitialized_var(interp_map_addr);
42795
42796@@ -1098,7 +1585,7 @@ out:
42797 * Decide what to dump of a segment, part, all or none.
42798 */
42799 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42800- unsigned long mm_flags)
42801+ unsigned long mm_flags, long signr)
42802 {
42803 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42804
42805@@ -1132,7 +1619,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42806 if (vma->vm_file == NULL)
42807 return 0;
42808
42809- if (FILTER(MAPPED_PRIVATE))
42810+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42811 goto whole;
42812
42813 /*
42814@@ -1354,9 +1841,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42815 {
42816 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42817 int i = 0;
42818- do
42819+ do {
42820 i += 2;
42821- while (auxv[i - 2] != AT_NULL);
42822+ } while (auxv[i - 2] != AT_NULL);
42823 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42824 }
42825
42826@@ -1862,14 +2349,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42827 }
42828
42829 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42830- unsigned long mm_flags)
42831+ struct coredump_params *cprm)
42832 {
42833 struct vm_area_struct *vma;
42834 size_t size = 0;
42835
42836 for (vma = first_vma(current, gate_vma); vma != NULL;
42837 vma = next_vma(vma, gate_vma))
42838- size += vma_dump_size(vma, mm_flags);
42839+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42840 return size;
42841 }
42842
42843@@ -1963,7 +2450,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42844
42845 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42846
42847- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42848+ offset += elf_core_vma_data_size(gate_vma, cprm);
42849 offset += elf_core_extra_data_size();
42850 e_shoff = offset;
42851
42852@@ -1977,10 +2464,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42853 offset = dataoff;
42854
42855 size += sizeof(*elf);
42856+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42857 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42858 goto end_coredump;
42859
42860 size += sizeof(*phdr4note);
42861+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42862 if (size > cprm->limit
42863 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42864 goto end_coredump;
42865@@ -1994,7 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42866 phdr.p_offset = offset;
42867 phdr.p_vaddr = vma->vm_start;
42868 phdr.p_paddr = 0;
42869- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42870+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42871 phdr.p_memsz = vma->vm_end - vma->vm_start;
42872 offset += phdr.p_filesz;
42873 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42874@@ -2005,6 +2494,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42875 phdr.p_align = ELF_EXEC_PAGESIZE;
42876
42877 size += sizeof(phdr);
42878+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42879 if (size > cprm->limit
42880 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42881 goto end_coredump;
42882@@ -2029,7 +2519,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42883 unsigned long addr;
42884 unsigned long end;
42885
42886- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42887+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42888
42889 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42890 struct page *page;
42891@@ -2038,6 +2528,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42892 page = get_dump_page(addr);
42893 if (page) {
42894 void *kaddr = kmap(page);
42895+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42896 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42897 !dump_write(cprm->file, kaddr,
42898 PAGE_SIZE);
42899@@ -2055,6 +2546,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42900
42901 if (e_phnum == PN_XNUM) {
42902 size += sizeof(*shdr4extnum);
42903+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42904 if (size > cprm->limit
42905 || !dump_write(cprm->file, shdr4extnum,
42906 sizeof(*shdr4extnum)))
42907@@ -2075,6 +2567,97 @@ out:
42908
42909 #endif /* CONFIG_ELF_CORE */
42910
42911+#ifdef CONFIG_PAX_MPROTECT
42912+/* PaX: non-PIC ELF libraries need relocations on their executable segments
42913+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42914+ * we'll remove VM_MAYWRITE for good on RELRO segments.
42915+ *
42916+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42917+ * basis because we want to allow the common case and not the special ones.
42918+ */
42919+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42920+{
42921+ struct elfhdr elf_h;
42922+ struct elf_phdr elf_p;
42923+ unsigned long i;
42924+ unsigned long oldflags;
42925+ bool is_textrel_rw, is_textrel_rx, is_relro;
42926+
42927+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42928+ return;
42929+
42930+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42931+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42932+
42933+#ifdef CONFIG_PAX_ELFRELOCS
42934+ /* possible TEXTREL */
42935+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42936+ 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);
42937+#else
42938+ is_textrel_rw = false;
42939+ is_textrel_rx = false;
42940+#endif
42941+
42942+ /* possible RELRO */
42943+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
42944+
42945+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
42946+ return;
42947+
42948+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
42949+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
42950+
42951+#ifdef CONFIG_PAX_ETEXECRELOCS
42952+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42953+#else
42954+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
42955+#endif
42956+
42957+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42958+ !elf_check_arch(&elf_h) ||
42959+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
42960+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
42961+ return;
42962+
42963+ for (i = 0UL; i < elf_h.e_phnum; i++) {
42964+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
42965+ return;
42966+ switch (elf_p.p_type) {
42967+ case PT_DYNAMIC:
42968+ if (!is_textrel_rw && !is_textrel_rx)
42969+ continue;
42970+ i = 0UL;
42971+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
42972+ elf_dyn dyn;
42973+
42974+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
42975+ return;
42976+ if (dyn.d_tag == DT_NULL)
42977+ return;
42978+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
42979+ gr_log_textrel(vma);
42980+ if (is_textrel_rw)
42981+ vma->vm_flags |= VM_MAYWRITE;
42982+ else
42983+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
42984+ vma->vm_flags &= ~VM_MAYWRITE;
42985+ return;
42986+ }
42987+ i++;
42988+ }
42989+ return;
42990+
42991+ case PT_GNU_RELRO:
42992+ if (!is_relro)
42993+ continue;
42994+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
42995+ vma->vm_flags &= ~VM_MAYWRITE;
42996+ return;
42997+ }
42998+ }
42999+}
43000+#endif
43001+
43002 static int __init init_elf_binfmt(void)
43003 {
43004 return register_binfmt(&elf_format);
43005diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43006index 1bffbe0..c8c283e 100644
43007--- a/fs/binfmt_flat.c
43008+++ b/fs/binfmt_flat.c
43009@@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43010 realdatastart = (unsigned long) -ENOMEM;
43011 printk("Unable to allocate RAM for process data, errno %d\n",
43012 (int)-realdatastart);
43013+ down_write(&current->mm->mmap_sem);
43014 do_munmap(current->mm, textpos, text_len);
43015+ up_write(&current->mm->mmap_sem);
43016 ret = realdatastart;
43017 goto err;
43018 }
43019@@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43020 }
43021 if (IS_ERR_VALUE(result)) {
43022 printk("Unable to read data+bss, errno %d\n", (int)-result);
43023+ down_write(&current->mm->mmap_sem);
43024 do_munmap(current->mm, textpos, text_len);
43025 do_munmap(current->mm, realdatastart, len);
43026+ up_write(&current->mm->mmap_sem);
43027 ret = result;
43028 goto err;
43029 }
43030@@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43031 }
43032 if (IS_ERR_VALUE(result)) {
43033 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43034+ down_write(&current->mm->mmap_sem);
43035 do_munmap(current->mm, textpos, text_len + data_len + extra +
43036 MAX_SHARED_LIBS * sizeof(unsigned long));
43037+ up_write(&current->mm->mmap_sem);
43038 ret = result;
43039 goto err;
43040 }
43041diff --git a/fs/bio.c b/fs/bio.c
43042index b980ecd..74800bf 100644
43043--- a/fs/bio.c
43044+++ b/fs/bio.c
43045@@ -833,7 +833,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43046 /*
43047 * Overflow, abort
43048 */
43049- if (end < start)
43050+ if (end < start || end - start > INT_MAX - nr_pages)
43051 return ERR_PTR(-EINVAL);
43052
43053 nr_pages += end - start;
43054@@ -1229,7 +1229,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43055 const int read = bio_data_dir(bio) == READ;
43056 struct bio_map_data *bmd = bio->bi_private;
43057 int i;
43058- char *p = bmd->sgvecs[0].iov_base;
43059+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43060
43061 __bio_for_each_segment(bvec, bio, i, 0) {
43062 char *addr = page_address(bvec->bv_page);
43063diff --git a/fs/block_dev.c b/fs/block_dev.c
43064index 5e9f198..6bf9b1c 100644
43065--- a/fs/block_dev.c
43066+++ b/fs/block_dev.c
43067@@ -703,7 +703,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43068 else if (bdev->bd_contains == bdev)
43069 return true; /* is a whole device which isn't held */
43070
43071- else if (whole->bd_holder == bd_may_claim)
43072+ else if (whole->bd_holder == (void *)bd_may_claim)
43073 return true; /* is a partition of a device that is being partitioned */
43074 else if (whole->bd_holder != NULL)
43075 return false; /* is a partition of a held device */
43076diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43077index d986824..af1befd 100644
43078--- a/fs/btrfs/check-integrity.c
43079+++ b/fs/btrfs/check-integrity.c
43080@@ -157,7 +157,7 @@ struct btrfsic_block {
43081 union {
43082 bio_end_io_t *bio;
43083 bh_end_io_t *bh;
43084- } orig_bio_bh_end_io;
43085+ } __no_const orig_bio_bh_end_io;
43086 int submit_bio_bh_rw;
43087 u64 flush_gen; /* only valid if !never_written */
43088 };
43089diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43090index 0639a55..7d9e07f 100644
43091--- a/fs/btrfs/ctree.c
43092+++ b/fs/btrfs/ctree.c
43093@@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43094 free_extent_buffer(buf);
43095 add_root_to_dirty_list(root);
43096 } else {
43097- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43098- parent_start = parent->start;
43099- else
43100+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43101+ if (parent)
43102+ parent_start = parent->start;
43103+ else
43104+ parent_start = 0;
43105+ } else
43106 parent_start = 0;
43107
43108 WARN_ON(trans->transid != btrfs_header_generation(parent));
43109diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43110index 892b347..b3db246 100644
43111--- a/fs/btrfs/inode.c
43112+++ b/fs/btrfs/inode.c
43113@@ -6930,7 +6930,7 @@ fail:
43114 return -ENOMEM;
43115 }
43116
43117-static int btrfs_getattr(struct vfsmount *mnt,
43118+int btrfs_getattr(struct vfsmount *mnt,
43119 struct dentry *dentry, struct kstat *stat)
43120 {
43121 struct inode *inode = dentry->d_inode;
43122@@ -6944,6 +6944,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43123 return 0;
43124 }
43125
43126+EXPORT_SYMBOL(btrfs_getattr);
43127+
43128+dev_t get_btrfs_dev_from_inode(struct inode *inode)
43129+{
43130+ return BTRFS_I(inode)->root->anon_dev;
43131+}
43132+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43133+
43134 /*
43135 * If a file is moved, it will inherit the cow and compression flags of the new
43136 * directory.
43137diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43138index 1b36f19..5ac7360 100644
43139--- a/fs/btrfs/ioctl.c
43140+++ b/fs/btrfs/ioctl.c
43141@@ -2783,9 +2783,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43142 for (i = 0; i < num_types; i++) {
43143 struct btrfs_space_info *tmp;
43144
43145+ /* Don't copy in more than we allocated */
43146 if (!slot_count)
43147 break;
43148
43149+ slot_count--;
43150+
43151 info = NULL;
43152 rcu_read_lock();
43153 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43154@@ -2807,15 +2810,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43155 memcpy(dest, &space, sizeof(space));
43156 dest++;
43157 space_args.total_spaces++;
43158- slot_count--;
43159 }
43160- if (!slot_count)
43161- break;
43162 }
43163 up_read(&info->groups_sem);
43164 }
43165
43166- user_dest = (struct btrfs_ioctl_space_info *)
43167+ user_dest = (struct btrfs_ioctl_space_info __user *)
43168 (arg + sizeof(struct btrfs_ioctl_space_args));
43169
43170 if (copy_to_user(user_dest, dest_orig, alloc_size))
43171diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43172index 8c1aae2..1e46446 100644
43173--- a/fs/btrfs/relocation.c
43174+++ b/fs/btrfs/relocation.c
43175@@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43176 }
43177 spin_unlock(&rc->reloc_root_tree.lock);
43178
43179- BUG_ON((struct btrfs_root *)node->data != root);
43180+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
43181
43182 if (!del) {
43183 spin_lock(&rc->reloc_root_tree.lock);
43184diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43185index 622f469..e8d2d55 100644
43186--- a/fs/cachefiles/bind.c
43187+++ b/fs/cachefiles/bind.c
43188@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43189 args);
43190
43191 /* start by checking things over */
43192- ASSERT(cache->fstop_percent >= 0 &&
43193- cache->fstop_percent < cache->fcull_percent &&
43194+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
43195 cache->fcull_percent < cache->frun_percent &&
43196 cache->frun_percent < 100);
43197
43198- ASSERT(cache->bstop_percent >= 0 &&
43199- cache->bstop_percent < cache->bcull_percent &&
43200+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
43201 cache->bcull_percent < cache->brun_percent &&
43202 cache->brun_percent < 100);
43203
43204diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43205index 0a1467b..6a53245 100644
43206--- a/fs/cachefiles/daemon.c
43207+++ b/fs/cachefiles/daemon.c
43208@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43209 if (n > buflen)
43210 return -EMSGSIZE;
43211
43212- if (copy_to_user(_buffer, buffer, n) != 0)
43213+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43214 return -EFAULT;
43215
43216 return n;
43217@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43218 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43219 return -EIO;
43220
43221- if (datalen < 0 || datalen > PAGE_SIZE - 1)
43222+ if (datalen > PAGE_SIZE - 1)
43223 return -EOPNOTSUPP;
43224
43225 /* drag the command string into the kernel so we can parse it */
43226@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43227 if (args[0] != '%' || args[1] != '\0')
43228 return -EINVAL;
43229
43230- if (fstop < 0 || fstop >= cache->fcull_percent)
43231+ if (fstop >= cache->fcull_percent)
43232 return cachefiles_daemon_range_error(cache, args);
43233
43234 cache->fstop_percent = fstop;
43235@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43236 if (args[0] != '%' || args[1] != '\0')
43237 return -EINVAL;
43238
43239- if (bstop < 0 || bstop >= cache->bcull_percent)
43240+ if (bstop >= cache->bcull_percent)
43241 return cachefiles_daemon_range_error(cache, args);
43242
43243 cache->bstop_percent = bstop;
43244diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43245index bd6bc1b..b627b53 100644
43246--- a/fs/cachefiles/internal.h
43247+++ b/fs/cachefiles/internal.h
43248@@ -57,7 +57,7 @@ struct cachefiles_cache {
43249 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43250 struct rb_root active_nodes; /* active nodes (can't be culled) */
43251 rwlock_t active_lock; /* lock for active_nodes */
43252- atomic_t gravecounter; /* graveyard uniquifier */
43253+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43254 unsigned frun_percent; /* when to stop culling (% files) */
43255 unsigned fcull_percent; /* when to start culling (% files) */
43256 unsigned fstop_percent; /* when to stop allocating (% files) */
43257@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43258 * proc.c
43259 */
43260 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43261-extern atomic_t cachefiles_lookup_histogram[HZ];
43262-extern atomic_t cachefiles_mkdir_histogram[HZ];
43263-extern atomic_t cachefiles_create_histogram[HZ];
43264+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43265+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43266+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43267
43268 extern int __init cachefiles_proc_init(void);
43269 extern void cachefiles_proc_cleanup(void);
43270 static inline
43271-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43272+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43273 {
43274 unsigned long jif = jiffies - start_jif;
43275 if (jif >= HZ)
43276 jif = HZ - 1;
43277- atomic_inc(&histogram[jif]);
43278+ atomic_inc_unchecked(&histogram[jif]);
43279 }
43280
43281 #else
43282diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43283index a0358c2..d6137f2 100644
43284--- a/fs/cachefiles/namei.c
43285+++ b/fs/cachefiles/namei.c
43286@@ -318,7 +318,7 @@ try_again:
43287 /* first step is to make up a grave dentry in the graveyard */
43288 sprintf(nbuffer, "%08x%08x",
43289 (uint32_t) get_seconds(),
43290- (uint32_t) atomic_inc_return(&cache->gravecounter));
43291+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43292
43293 /* do the multiway lock magic */
43294 trap = lock_rename(cache->graveyard, dir);
43295diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43296index eccd339..4c1d995 100644
43297--- a/fs/cachefiles/proc.c
43298+++ b/fs/cachefiles/proc.c
43299@@ -14,9 +14,9 @@
43300 #include <linux/seq_file.h>
43301 #include "internal.h"
43302
43303-atomic_t cachefiles_lookup_histogram[HZ];
43304-atomic_t cachefiles_mkdir_histogram[HZ];
43305-atomic_t cachefiles_create_histogram[HZ];
43306+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43307+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43308+atomic_unchecked_t cachefiles_create_histogram[HZ];
43309
43310 /*
43311 * display the latency histogram
43312@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43313 return 0;
43314 default:
43315 index = (unsigned long) v - 3;
43316- x = atomic_read(&cachefiles_lookup_histogram[index]);
43317- y = atomic_read(&cachefiles_mkdir_histogram[index]);
43318- z = atomic_read(&cachefiles_create_histogram[index]);
43319+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43320+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43321+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43322 if (x == 0 && y == 0 && z == 0)
43323 return 0;
43324
43325diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43326index 0e3c092..818480e 100644
43327--- a/fs/cachefiles/rdwr.c
43328+++ b/fs/cachefiles/rdwr.c
43329@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43330 old_fs = get_fs();
43331 set_fs(KERNEL_DS);
43332 ret = file->f_op->write(
43333- file, (const void __user *) data, len, &pos);
43334+ file, (const void __force_user *) data, len, &pos);
43335 set_fs(old_fs);
43336 kunmap(page);
43337 if (ret != len)
43338diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43339index 3e8094b..cb3ff3d 100644
43340--- a/fs/ceph/dir.c
43341+++ b/fs/ceph/dir.c
43342@@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43343 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43344 struct ceph_mds_client *mdsc = fsc->mdsc;
43345 unsigned frag = fpos_frag(filp->f_pos);
43346- int off = fpos_off(filp->f_pos);
43347+ unsigned int off = fpos_off(filp->f_pos);
43348 int err;
43349 u32 ftype;
43350 struct ceph_mds_reply_info_parsed *rinfo;
43351@@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43352 if (nd &&
43353 (nd->flags & LOOKUP_OPEN) &&
43354 !(nd->intent.open.flags & O_CREAT)) {
43355- int mode = nd->intent.open.create_mode & ~current->fs->umask;
43356+ int mode = nd->intent.open.create_mode & ~current_umask();
43357 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43358 }
43359
43360diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43361index 24b3dfc..3cd5454 100644
43362--- a/fs/cifs/cifs_debug.c
43363+++ b/fs/cifs/cifs_debug.c
43364@@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43365
43366 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43367 #ifdef CONFIG_CIFS_STATS2
43368- atomic_set(&totBufAllocCount, 0);
43369- atomic_set(&totSmBufAllocCount, 0);
43370+ atomic_set_unchecked(&totBufAllocCount, 0);
43371+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43372 #endif /* CONFIG_CIFS_STATS2 */
43373 spin_lock(&cifs_tcp_ses_lock);
43374 list_for_each(tmp1, &cifs_tcp_ses_list) {
43375@@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43376 tcon = list_entry(tmp3,
43377 struct cifs_tcon,
43378 tcon_list);
43379- atomic_set(&tcon->num_smbs_sent, 0);
43380- atomic_set(&tcon->num_writes, 0);
43381- atomic_set(&tcon->num_reads, 0);
43382- atomic_set(&tcon->num_oplock_brks, 0);
43383- atomic_set(&tcon->num_opens, 0);
43384- atomic_set(&tcon->num_posixopens, 0);
43385- atomic_set(&tcon->num_posixmkdirs, 0);
43386- atomic_set(&tcon->num_closes, 0);
43387- atomic_set(&tcon->num_deletes, 0);
43388- atomic_set(&tcon->num_mkdirs, 0);
43389- atomic_set(&tcon->num_rmdirs, 0);
43390- atomic_set(&tcon->num_renames, 0);
43391- atomic_set(&tcon->num_t2renames, 0);
43392- atomic_set(&tcon->num_ffirst, 0);
43393- atomic_set(&tcon->num_fnext, 0);
43394- atomic_set(&tcon->num_fclose, 0);
43395- atomic_set(&tcon->num_hardlinks, 0);
43396- atomic_set(&tcon->num_symlinks, 0);
43397- atomic_set(&tcon->num_locks, 0);
43398+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43399+ atomic_set_unchecked(&tcon->num_writes, 0);
43400+ atomic_set_unchecked(&tcon->num_reads, 0);
43401+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43402+ atomic_set_unchecked(&tcon->num_opens, 0);
43403+ atomic_set_unchecked(&tcon->num_posixopens, 0);
43404+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43405+ atomic_set_unchecked(&tcon->num_closes, 0);
43406+ atomic_set_unchecked(&tcon->num_deletes, 0);
43407+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
43408+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
43409+ atomic_set_unchecked(&tcon->num_renames, 0);
43410+ atomic_set_unchecked(&tcon->num_t2renames, 0);
43411+ atomic_set_unchecked(&tcon->num_ffirst, 0);
43412+ atomic_set_unchecked(&tcon->num_fnext, 0);
43413+ atomic_set_unchecked(&tcon->num_fclose, 0);
43414+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
43415+ atomic_set_unchecked(&tcon->num_symlinks, 0);
43416+ atomic_set_unchecked(&tcon->num_locks, 0);
43417 }
43418 }
43419 }
43420@@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43421 smBufAllocCount.counter, cifs_min_small);
43422 #ifdef CONFIG_CIFS_STATS2
43423 seq_printf(m, "Total Large %d Small %d Allocations\n",
43424- atomic_read(&totBufAllocCount),
43425- atomic_read(&totSmBufAllocCount));
43426+ atomic_read_unchecked(&totBufAllocCount),
43427+ atomic_read_unchecked(&totSmBufAllocCount));
43428 #endif /* CONFIG_CIFS_STATS2 */
43429
43430 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43431@@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43432 if (tcon->need_reconnect)
43433 seq_puts(m, "\tDISCONNECTED ");
43434 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43435- atomic_read(&tcon->num_smbs_sent),
43436- atomic_read(&tcon->num_oplock_brks));
43437+ atomic_read_unchecked(&tcon->num_smbs_sent),
43438+ atomic_read_unchecked(&tcon->num_oplock_brks));
43439 seq_printf(m, "\nReads: %d Bytes: %lld",
43440- atomic_read(&tcon->num_reads),
43441+ atomic_read_unchecked(&tcon->num_reads),
43442 (long long)(tcon->bytes_read));
43443 seq_printf(m, "\nWrites: %d Bytes: %lld",
43444- atomic_read(&tcon->num_writes),
43445+ atomic_read_unchecked(&tcon->num_writes),
43446 (long long)(tcon->bytes_written));
43447 seq_printf(m, "\nFlushes: %d",
43448- atomic_read(&tcon->num_flushes));
43449+ atomic_read_unchecked(&tcon->num_flushes));
43450 seq_printf(m, "\nLocks: %d HardLinks: %d "
43451 "Symlinks: %d",
43452- atomic_read(&tcon->num_locks),
43453- atomic_read(&tcon->num_hardlinks),
43454- atomic_read(&tcon->num_symlinks));
43455+ atomic_read_unchecked(&tcon->num_locks),
43456+ atomic_read_unchecked(&tcon->num_hardlinks),
43457+ atomic_read_unchecked(&tcon->num_symlinks));
43458 seq_printf(m, "\nOpens: %d Closes: %d "
43459 "Deletes: %d",
43460- atomic_read(&tcon->num_opens),
43461- atomic_read(&tcon->num_closes),
43462- atomic_read(&tcon->num_deletes));
43463+ atomic_read_unchecked(&tcon->num_opens),
43464+ atomic_read_unchecked(&tcon->num_closes),
43465+ atomic_read_unchecked(&tcon->num_deletes));
43466 seq_printf(m, "\nPosix Opens: %d "
43467 "Posix Mkdirs: %d",
43468- atomic_read(&tcon->num_posixopens),
43469- atomic_read(&tcon->num_posixmkdirs));
43470+ atomic_read_unchecked(&tcon->num_posixopens),
43471+ atomic_read_unchecked(&tcon->num_posixmkdirs));
43472 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43473- atomic_read(&tcon->num_mkdirs),
43474- atomic_read(&tcon->num_rmdirs));
43475+ atomic_read_unchecked(&tcon->num_mkdirs),
43476+ atomic_read_unchecked(&tcon->num_rmdirs));
43477 seq_printf(m, "\nRenames: %d T2 Renames %d",
43478- atomic_read(&tcon->num_renames),
43479- atomic_read(&tcon->num_t2renames));
43480+ atomic_read_unchecked(&tcon->num_renames),
43481+ atomic_read_unchecked(&tcon->num_t2renames));
43482 seq_printf(m, "\nFindFirst: %d FNext %d "
43483 "FClose %d",
43484- atomic_read(&tcon->num_ffirst),
43485- atomic_read(&tcon->num_fnext),
43486- atomic_read(&tcon->num_fclose));
43487+ atomic_read_unchecked(&tcon->num_ffirst),
43488+ atomic_read_unchecked(&tcon->num_fnext),
43489+ atomic_read_unchecked(&tcon->num_fclose));
43490 }
43491 }
43492 }
43493diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43494index 70dd381..b8ce03b 100644
43495--- a/fs/cifs/cifsfs.c
43496+++ b/fs/cifs/cifsfs.c
43497@@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
43498 cifs_req_cachep = kmem_cache_create("cifs_request",
43499 CIFSMaxBufSize +
43500 MAX_CIFS_HDR_SIZE, 0,
43501- SLAB_HWCACHE_ALIGN, NULL);
43502+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43503 if (cifs_req_cachep == NULL)
43504 return -ENOMEM;
43505
43506@@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
43507 efficient to alloc 1 per page off the slab compared to 17K (5page)
43508 alloc of large cifs buffers even when page debugging is on */
43509 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43510- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43511+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43512 NULL);
43513 if (cifs_sm_req_cachep == NULL) {
43514 mempool_destroy(cifs_req_poolp);
43515@@ -1101,8 +1101,8 @@ init_cifs(void)
43516 atomic_set(&bufAllocCount, 0);
43517 atomic_set(&smBufAllocCount, 0);
43518 #ifdef CONFIG_CIFS_STATS2
43519- atomic_set(&totBufAllocCount, 0);
43520- atomic_set(&totSmBufAllocCount, 0);
43521+ atomic_set_unchecked(&totBufAllocCount, 0);
43522+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43523 #endif /* CONFIG_CIFS_STATS2 */
43524
43525 atomic_set(&midCount, 0);
43526diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43527index d47d20a..77e8b33 100644
43528--- a/fs/cifs/cifsglob.h
43529+++ b/fs/cifs/cifsglob.h
43530@@ -388,28 +388,28 @@ struct cifs_tcon {
43531 __u16 Flags; /* optional support bits */
43532 enum statusEnum tidStatus;
43533 #ifdef CONFIG_CIFS_STATS
43534- atomic_t num_smbs_sent;
43535- atomic_t num_writes;
43536- atomic_t num_reads;
43537- atomic_t num_flushes;
43538- atomic_t num_oplock_brks;
43539- atomic_t num_opens;
43540- atomic_t num_closes;
43541- atomic_t num_deletes;
43542- atomic_t num_mkdirs;
43543- atomic_t num_posixopens;
43544- atomic_t num_posixmkdirs;
43545- atomic_t num_rmdirs;
43546- atomic_t num_renames;
43547- atomic_t num_t2renames;
43548- atomic_t num_ffirst;
43549- atomic_t num_fnext;
43550- atomic_t num_fclose;
43551- atomic_t num_hardlinks;
43552- atomic_t num_symlinks;
43553- atomic_t num_locks;
43554- atomic_t num_acl_get;
43555- atomic_t num_acl_set;
43556+ atomic_unchecked_t num_smbs_sent;
43557+ atomic_unchecked_t num_writes;
43558+ atomic_unchecked_t num_reads;
43559+ atomic_unchecked_t num_flushes;
43560+ atomic_unchecked_t num_oplock_brks;
43561+ atomic_unchecked_t num_opens;
43562+ atomic_unchecked_t num_closes;
43563+ atomic_unchecked_t num_deletes;
43564+ atomic_unchecked_t num_mkdirs;
43565+ atomic_unchecked_t num_posixopens;
43566+ atomic_unchecked_t num_posixmkdirs;
43567+ atomic_unchecked_t num_rmdirs;
43568+ atomic_unchecked_t num_renames;
43569+ atomic_unchecked_t num_t2renames;
43570+ atomic_unchecked_t num_ffirst;
43571+ atomic_unchecked_t num_fnext;
43572+ atomic_unchecked_t num_fclose;
43573+ atomic_unchecked_t num_hardlinks;
43574+ atomic_unchecked_t num_symlinks;
43575+ atomic_unchecked_t num_locks;
43576+ atomic_unchecked_t num_acl_get;
43577+ atomic_unchecked_t num_acl_set;
43578 #ifdef CONFIG_CIFS_STATS2
43579 unsigned long long time_writes;
43580 unsigned long long time_reads;
43581@@ -624,7 +624,7 @@ convert_delimiter(char *path, char delim)
43582 }
43583
43584 #ifdef CONFIG_CIFS_STATS
43585-#define cifs_stats_inc atomic_inc
43586+#define cifs_stats_inc atomic_inc_unchecked
43587
43588 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43589 unsigned int bytes)
43590@@ -983,8 +983,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43591 /* Various Debug counters */
43592 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43593 #ifdef CONFIG_CIFS_STATS2
43594-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43595-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43596+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43597+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43598 #endif
43599 GLOBAL_EXTERN atomic_t smBufAllocCount;
43600 GLOBAL_EXTERN atomic_t midCount;
43601diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43602index 6b0e064..94e6c3c 100644
43603--- a/fs/cifs/link.c
43604+++ b/fs/cifs/link.c
43605@@ -600,7 +600,7 @@ symlink_exit:
43606
43607 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43608 {
43609- char *p = nd_get_link(nd);
43610+ const char *p = nd_get_link(nd);
43611 if (!IS_ERR(p))
43612 kfree(p);
43613 }
43614diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43615index 703ef5c..2a44ed5 100644
43616--- a/fs/cifs/misc.c
43617+++ b/fs/cifs/misc.c
43618@@ -156,7 +156,7 @@ cifs_buf_get(void)
43619 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43620 atomic_inc(&bufAllocCount);
43621 #ifdef CONFIG_CIFS_STATS2
43622- atomic_inc(&totBufAllocCount);
43623+ atomic_inc_unchecked(&totBufAllocCount);
43624 #endif /* CONFIG_CIFS_STATS2 */
43625 }
43626
43627@@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43628 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43629 atomic_inc(&smBufAllocCount);
43630 #ifdef CONFIG_CIFS_STATS2
43631- atomic_inc(&totSmBufAllocCount);
43632+ atomic_inc_unchecked(&totSmBufAllocCount);
43633 #endif /* CONFIG_CIFS_STATS2 */
43634
43635 }
43636diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43637index 6901578..d402eb5 100644
43638--- a/fs/coda/cache.c
43639+++ b/fs/coda/cache.c
43640@@ -24,7 +24,7 @@
43641 #include "coda_linux.h"
43642 #include "coda_cache.h"
43643
43644-static atomic_t permission_epoch = ATOMIC_INIT(0);
43645+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43646
43647 /* replace or extend an acl cache hit */
43648 void coda_cache_enter(struct inode *inode, int mask)
43649@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43650 struct coda_inode_info *cii = ITOC(inode);
43651
43652 spin_lock(&cii->c_lock);
43653- cii->c_cached_epoch = atomic_read(&permission_epoch);
43654+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43655 if (cii->c_uid != current_fsuid()) {
43656 cii->c_uid = current_fsuid();
43657 cii->c_cached_perm = mask;
43658@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43659 {
43660 struct coda_inode_info *cii = ITOC(inode);
43661 spin_lock(&cii->c_lock);
43662- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43663+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43664 spin_unlock(&cii->c_lock);
43665 }
43666
43667 /* remove all acl caches */
43668 void coda_cache_clear_all(struct super_block *sb)
43669 {
43670- atomic_inc(&permission_epoch);
43671+ atomic_inc_unchecked(&permission_epoch);
43672 }
43673
43674
43675@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43676 spin_lock(&cii->c_lock);
43677 hit = (mask & cii->c_cached_perm) == mask &&
43678 cii->c_uid == current_fsuid() &&
43679- cii->c_cached_epoch == atomic_read(&permission_epoch);
43680+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43681 spin_unlock(&cii->c_lock);
43682
43683 return hit;
43684diff --git a/fs/compat.c b/fs/compat.c
43685index 07880ba..3fb2862 100644
43686--- a/fs/compat.c
43687+++ b/fs/compat.c
43688@@ -491,7 +491,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43689
43690 set_fs(KERNEL_DS);
43691 /* The __user pointer cast is valid because of the set_fs() */
43692- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43693+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43694 set_fs(oldfs);
43695 /* truncating is ok because it's a user address */
43696 if (!ret)
43697@@ -549,7 +549,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43698 goto out;
43699
43700 ret = -EINVAL;
43701- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43702+ if (nr_segs > UIO_MAXIOV)
43703 goto out;
43704 if (nr_segs > fast_segs) {
43705 ret = -ENOMEM;
43706@@ -832,6 +832,7 @@ struct compat_old_linux_dirent {
43707
43708 struct compat_readdir_callback {
43709 struct compat_old_linux_dirent __user *dirent;
43710+ struct file * file;
43711 int result;
43712 };
43713
43714@@ -849,6 +850,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43715 buf->result = -EOVERFLOW;
43716 return -EOVERFLOW;
43717 }
43718+
43719+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43720+ return 0;
43721+
43722 buf->result++;
43723 dirent = buf->dirent;
43724 if (!access_ok(VERIFY_WRITE, dirent,
43725@@ -881,6 +886,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43726
43727 buf.result = 0;
43728 buf.dirent = dirent;
43729+ buf.file = file;
43730
43731 error = vfs_readdir(file, compat_fillonedir, &buf);
43732 if (buf.result)
43733@@ -901,6 +907,7 @@ struct compat_linux_dirent {
43734 struct compat_getdents_callback {
43735 struct compat_linux_dirent __user *current_dir;
43736 struct compat_linux_dirent __user *previous;
43737+ struct file * file;
43738 int count;
43739 int error;
43740 };
43741@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43742 buf->error = -EOVERFLOW;
43743 return -EOVERFLOW;
43744 }
43745+
43746+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43747+ return 0;
43748+
43749 dirent = buf->previous;
43750 if (dirent) {
43751 if (__put_user(offset, &dirent->d_off))
43752@@ -969,6 +980,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43753 buf.previous = NULL;
43754 buf.count = count;
43755 buf.error = 0;
43756+ buf.file = file;
43757
43758 error = vfs_readdir(file, compat_filldir, &buf);
43759 if (error >= 0)
43760@@ -990,6 +1002,7 @@ out:
43761 struct compat_getdents_callback64 {
43762 struct linux_dirent64 __user *current_dir;
43763 struct linux_dirent64 __user *previous;
43764+ struct file * file;
43765 int count;
43766 int error;
43767 };
43768@@ -1006,6 +1019,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43769 buf->error = -EINVAL; /* only used if we fail.. */
43770 if (reclen > buf->count)
43771 return -EINVAL;
43772+
43773+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43774+ return 0;
43775+
43776 dirent = buf->previous;
43777
43778 if (dirent) {
43779@@ -1057,13 +1074,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43780 buf.previous = NULL;
43781 buf.count = count;
43782 buf.error = 0;
43783+ buf.file = file;
43784
43785 error = vfs_readdir(file, compat_filldir64, &buf);
43786 if (error >= 0)
43787 error = buf.error;
43788 lastdirent = buf.previous;
43789 if (lastdirent) {
43790- typeof(lastdirent->d_off) d_off = file->f_pos;
43791+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43792 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43793 error = -EFAULT;
43794 else
43795diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43796index 112e45a..b59845b 100644
43797--- a/fs/compat_binfmt_elf.c
43798+++ b/fs/compat_binfmt_elf.c
43799@@ -30,11 +30,13 @@
43800 #undef elf_phdr
43801 #undef elf_shdr
43802 #undef elf_note
43803+#undef elf_dyn
43804 #undef elf_addr_t
43805 #define elfhdr elf32_hdr
43806 #define elf_phdr elf32_phdr
43807 #define elf_shdr elf32_shdr
43808 #define elf_note elf32_note
43809+#define elf_dyn Elf32_Dyn
43810 #define elf_addr_t Elf32_Addr
43811
43812 /*
43813diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43814index a26bea1..ae23e72 100644
43815--- a/fs/compat_ioctl.c
43816+++ b/fs/compat_ioctl.c
43817@@ -211,6 +211,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43818
43819 err = get_user(palp, &up->palette);
43820 err |= get_user(length, &up->length);
43821+ if (err)
43822+ return -EFAULT;
43823
43824 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43825 err = put_user(compat_ptr(palp), &up_native->palette);
43826@@ -622,7 +624,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43827 return -EFAULT;
43828 if (__get_user(udata, &ss32->iomem_base))
43829 return -EFAULT;
43830- ss.iomem_base = compat_ptr(udata);
43831+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43832 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43833 __get_user(ss.port_high, &ss32->port_high))
43834 return -EFAULT;
43835@@ -797,7 +799,7 @@ static int compat_ioctl_preallocate(struct file *file,
43836 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43837 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43838 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43839- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43840+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43841 return -EFAULT;
43842
43843 return ioctl_preallocate(file, p);
43844@@ -1611,8 +1613,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43845 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43846 {
43847 unsigned int a, b;
43848- a = *(unsigned int *)p;
43849- b = *(unsigned int *)q;
43850+ a = *(const unsigned int *)p;
43851+ b = *(const unsigned int *)q;
43852 if (a > b)
43853 return 1;
43854 if (a < b)
43855diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43856index 5ddd7eb..c18bf04 100644
43857--- a/fs/configfs/dir.c
43858+++ b/fs/configfs/dir.c
43859@@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43860 }
43861 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43862 struct configfs_dirent *next;
43863- const char * name;
43864+ const unsigned char * name;
43865+ char d_name[sizeof(next->s_dentry->d_iname)];
43866 int len;
43867 struct inode *inode = NULL;
43868
43869@@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43870 continue;
43871
43872 name = configfs_get_name(next);
43873- len = strlen(name);
43874+ if (next->s_dentry && name == next->s_dentry->d_iname) {
43875+ len = next->s_dentry->d_name.len;
43876+ memcpy(d_name, name, len);
43877+ name = d_name;
43878+ } else
43879+ len = strlen(name);
43880
43881 /*
43882 * We'll have a dentry and an inode for
43883diff --git a/fs/dcache.c b/fs/dcache.c
43884index 2576d14..0cec38d 100644
43885--- a/fs/dcache.c
43886+++ b/fs/dcache.c
43887@@ -105,10 +105,10 @@ static unsigned int d_hash_shift __read_mostly;
43888 static struct hlist_bl_head *dentry_hashtable __read_mostly;
43889
43890 static inline struct hlist_bl_head *d_hash(const struct dentry *parent,
43891- unsigned long hash)
43892+ unsigned int hash)
43893 {
43894- hash += ((unsigned long) parent ^ GOLDEN_RATIO_PRIME) / L1_CACHE_BYTES;
43895- hash = hash ^ ((hash ^ GOLDEN_RATIO_PRIME) >> D_HASHBITS);
43896+ hash += (unsigned long) parent / L1_CACHE_BYTES;
43897+ hash = hash + (hash >> D_HASHBITS);
43898 return dentry_hashtable + (hash & D_HASHMASK);
43899 }
43900
43901@@ -3067,7 +3067,7 @@ void __init vfs_caches_init(unsigned long mempages)
43902 mempages -= reserve;
43903
43904 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43905- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43906+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43907
43908 dcache_init();
43909 inode_init();
43910diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
43911index 956d5dd..e755e04 100644
43912--- a/fs/debugfs/inode.c
43913+++ b/fs/debugfs/inode.c
43914@@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
43915 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
43916 {
43917 return debugfs_create_file(name,
43918+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43919+ S_IFDIR | S_IRWXU,
43920+#else
43921 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43922+#endif
43923 parent, NULL, NULL);
43924 }
43925 EXPORT_SYMBOL_GPL(debugfs_create_dir);
43926diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43927index ab35b11..b30af66 100644
43928--- a/fs/ecryptfs/inode.c
43929+++ b/fs/ecryptfs/inode.c
43930@@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43931 old_fs = get_fs();
43932 set_fs(get_ds());
43933 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43934- (char __user *)lower_buf,
43935+ (char __force_user *)lower_buf,
43936 lower_bufsiz);
43937 set_fs(old_fs);
43938 if (rc < 0)
43939@@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43940 }
43941 old_fs = get_fs();
43942 set_fs(get_ds());
43943- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43944+ rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43945 set_fs(old_fs);
43946 if (rc < 0) {
43947 kfree(buf);
43948@@ -733,7 +733,7 @@ out:
43949 static void
43950 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43951 {
43952- char *buf = nd_get_link(nd);
43953+ const char *buf = nd_get_link(nd);
43954 if (!IS_ERR(buf)) {
43955 /* Free the char* */
43956 kfree(buf);
43957diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43958index 3a06f40..f7af544 100644
43959--- a/fs/ecryptfs/miscdev.c
43960+++ b/fs/ecryptfs/miscdev.c
43961@@ -345,7 +345,7 @@ check_list:
43962 goto out_unlock_msg_ctx;
43963 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
43964 if (msg_ctx->msg) {
43965- if (copy_to_user(&buf[i], packet_length, packet_length_size))
43966+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43967 goto out_unlock_msg_ctx;
43968 i += packet_length_size;
43969 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43970diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43971index b2a34a1..162fa69 100644
43972--- a/fs/ecryptfs/read_write.c
43973+++ b/fs/ecryptfs/read_write.c
43974@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43975 return -EIO;
43976 fs_save = get_fs();
43977 set_fs(get_ds());
43978- rc = vfs_write(lower_file, data, size, &offset);
43979+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
43980 set_fs(fs_save);
43981 mark_inode_dirty_sync(ecryptfs_inode);
43982 return rc;
43983@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
43984 return -EIO;
43985 fs_save = get_fs();
43986 set_fs(get_ds());
43987- rc = vfs_read(lower_file, data, size, &offset);
43988+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
43989 set_fs(fs_save);
43990 return rc;
43991 }
43992diff --git a/fs/exec.c b/fs/exec.c
43993index ae42277..32c9035 100644
43994--- a/fs/exec.c
43995+++ b/fs/exec.c
43996@@ -55,6 +55,13 @@
43997 #include <linux/pipe_fs_i.h>
43998 #include <linux/oom.h>
43999 #include <linux/compat.h>
44000+#include <linux/random.h>
44001+#include <linux/seq_file.h>
44002+
44003+#ifdef CONFIG_PAX_REFCOUNT
44004+#include <linux/kallsyms.h>
44005+#include <linux/kdebug.h>
44006+#endif
44007
44008 #include <asm/uaccess.h>
44009 #include <asm/mmu_context.h>
44010@@ -63,6 +70,15 @@
44011 #include <trace/events/task.h>
44012 #include "internal.h"
44013
44014+#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
44015+void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
44016+#endif
44017+
44018+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44019+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44020+EXPORT_SYMBOL(pax_set_initial_flags_func);
44021+#endif
44022+
44023 int core_uses_pid;
44024 char core_pattern[CORENAME_MAX_SIZE] = "core";
44025 unsigned int core_pipe_limit;
44026@@ -72,7 +88,7 @@ struct core_name {
44027 char *corename;
44028 int used, size;
44029 };
44030-static atomic_t call_count = ATOMIC_INIT(1);
44031+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44032
44033 /* The maximal length of core_pattern is also specified in sysctl.c */
44034
44035@@ -190,18 +206,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44036 int write)
44037 {
44038 struct page *page;
44039- int ret;
44040
44041-#ifdef CONFIG_STACK_GROWSUP
44042- if (write) {
44043- ret = expand_downwards(bprm->vma, pos);
44044- if (ret < 0)
44045- return NULL;
44046- }
44047-#endif
44048- ret = get_user_pages(current, bprm->mm, pos,
44049- 1, write, 1, &page, NULL);
44050- if (ret <= 0)
44051+ if (0 > expand_downwards(bprm->vma, pos))
44052+ return NULL;
44053+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44054 return NULL;
44055
44056 if (write) {
44057@@ -217,6 +225,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44058 if (size <= ARG_MAX)
44059 return page;
44060
44061+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44062+ // only allow 512KB for argv+env on suid/sgid binaries
44063+ // to prevent easy ASLR exhaustion
44064+ if (((bprm->cred->euid != current_euid()) ||
44065+ (bprm->cred->egid != current_egid())) &&
44066+ (size > (512 * 1024))) {
44067+ put_page(page);
44068+ return NULL;
44069+ }
44070+#endif
44071+
44072 /*
44073 * Limit to 1/4-th the stack size for the argv+env strings.
44074 * This ensures that:
44075@@ -276,6 +295,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44076 vma->vm_end = STACK_TOP_MAX;
44077 vma->vm_start = vma->vm_end - PAGE_SIZE;
44078 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44079+
44080+#ifdef CONFIG_PAX_SEGMEXEC
44081+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44082+#endif
44083+
44084 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44085 INIT_LIST_HEAD(&vma->anon_vma_chain);
44086
44087@@ -290,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44088 mm->stack_vm = mm->total_vm = 1;
44089 up_write(&mm->mmap_sem);
44090 bprm->p = vma->vm_end - sizeof(void *);
44091+
44092+#ifdef CONFIG_PAX_RANDUSTACK
44093+ if (randomize_va_space)
44094+ bprm->p ^= random32() & ~PAGE_MASK;
44095+#endif
44096+
44097 return 0;
44098 err:
44099 up_write(&mm->mmap_sem);
44100@@ -398,19 +428,7 @@ err:
44101 return err;
44102 }
44103
44104-struct user_arg_ptr {
44105-#ifdef CONFIG_COMPAT
44106- bool is_compat;
44107-#endif
44108- union {
44109- const char __user *const __user *native;
44110-#ifdef CONFIG_COMPAT
44111- compat_uptr_t __user *compat;
44112-#endif
44113- } ptr;
44114-};
44115-
44116-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44117+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44118 {
44119 const char __user *native;
44120
44121@@ -419,14 +437,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44122 compat_uptr_t compat;
44123
44124 if (get_user(compat, argv.ptr.compat + nr))
44125- return ERR_PTR(-EFAULT);
44126+ return (const char __force_user *)ERR_PTR(-EFAULT);
44127
44128 return compat_ptr(compat);
44129 }
44130 #endif
44131
44132 if (get_user(native, argv.ptr.native + nr))
44133- return ERR_PTR(-EFAULT);
44134+ return (const char __force_user *)ERR_PTR(-EFAULT);
44135
44136 return native;
44137 }
44138@@ -445,7 +463,7 @@ static int count(struct user_arg_ptr argv, int max)
44139 if (!p)
44140 break;
44141
44142- if (IS_ERR(p))
44143+ if (IS_ERR((const char __force_kernel *)p))
44144 return -EFAULT;
44145
44146 if (i++ >= max)
44147@@ -479,7 +497,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44148
44149 ret = -EFAULT;
44150 str = get_user_arg_ptr(argv, argc);
44151- if (IS_ERR(str))
44152+ if (IS_ERR((const char __force_kernel *)str))
44153 goto out;
44154
44155 len = strnlen_user(str, MAX_ARG_STRLEN);
44156@@ -561,7 +579,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44157 int r;
44158 mm_segment_t oldfs = get_fs();
44159 struct user_arg_ptr argv = {
44160- .ptr.native = (const char __user *const __user *)__argv,
44161+ .ptr.native = (const char __force_user *const __force_user *)__argv,
44162 };
44163
44164 set_fs(KERNEL_DS);
44165@@ -596,7 +614,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44166 unsigned long new_end = old_end - shift;
44167 struct mmu_gather tlb;
44168
44169- BUG_ON(new_start > new_end);
44170+ if (new_start >= new_end || new_start < mmap_min_addr)
44171+ return -ENOMEM;
44172
44173 /*
44174 * ensure there are no vmas between where we want to go
44175@@ -605,6 +624,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44176 if (vma != find_vma(mm, new_start))
44177 return -EFAULT;
44178
44179+#ifdef CONFIG_PAX_SEGMEXEC
44180+ BUG_ON(pax_find_mirror_vma(vma));
44181+#endif
44182+
44183 /*
44184 * cover the whole range: [new_start, old_end)
44185 */
44186@@ -685,10 +708,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44187 stack_top = arch_align_stack(stack_top);
44188 stack_top = PAGE_ALIGN(stack_top);
44189
44190- if (unlikely(stack_top < mmap_min_addr) ||
44191- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44192- return -ENOMEM;
44193-
44194 stack_shift = vma->vm_end - stack_top;
44195
44196 bprm->p -= stack_shift;
44197@@ -700,8 +719,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44198 bprm->exec -= stack_shift;
44199
44200 down_write(&mm->mmap_sem);
44201+
44202+ /* Move stack pages down in memory. */
44203+ if (stack_shift) {
44204+ ret = shift_arg_pages(vma, stack_shift);
44205+ if (ret)
44206+ goto out_unlock;
44207+ }
44208+
44209 vm_flags = VM_STACK_FLAGS;
44210
44211+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44212+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44213+ vm_flags &= ~VM_EXEC;
44214+
44215+#ifdef CONFIG_PAX_MPROTECT
44216+ if (mm->pax_flags & MF_PAX_MPROTECT)
44217+ vm_flags &= ~VM_MAYEXEC;
44218+#endif
44219+
44220+ }
44221+#endif
44222+
44223 /*
44224 * Adjust stack execute permissions; explicitly enable for
44225 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44226@@ -720,13 +759,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44227 goto out_unlock;
44228 BUG_ON(prev != vma);
44229
44230- /* Move stack pages down in memory. */
44231- if (stack_shift) {
44232- ret = shift_arg_pages(vma, stack_shift);
44233- if (ret)
44234- goto out_unlock;
44235- }
44236-
44237 /* mprotect_fixup is overkill to remove the temporary stack flags */
44238 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44239
44240@@ -807,7 +839,7 @@ int kernel_read(struct file *file, loff_t offset,
44241 old_fs = get_fs();
44242 set_fs(get_ds());
44243 /* The cast to a user pointer is valid due to the set_fs() */
44244- result = vfs_read(file, (void __user *)addr, count, &pos);
44245+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
44246 set_fs(old_fs);
44247 return result;
44248 }
44249@@ -1255,7 +1287,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44250 }
44251 rcu_read_unlock();
44252
44253- if (p->fs->users > n_fs) {
44254+ if (atomic_read(&p->fs->users) > n_fs) {
44255 bprm->unsafe |= LSM_UNSAFE_SHARE;
44256 } else {
44257 res = -EAGAIN;
44258@@ -1450,6 +1482,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44259
44260 EXPORT_SYMBOL(search_binary_handler);
44261
44262+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44263+static DEFINE_PER_CPU(u64, exec_counter);
44264+static int __init init_exec_counters(void)
44265+{
44266+ unsigned int cpu;
44267+
44268+ for_each_possible_cpu(cpu) {
44269+ per_cpu(exec_counter, cpu) = (u64)cpu;
44270+ }
44271+
44272+ return 0;
44273+}
44274+early_initcall(init_exec_counters);
44275+static inline void increment_exec_counter(void)
44276+{
44277+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
44278+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44279+}
44280+#else
44281+static inline void increment_exec_counter(void) {}
44282+#endif
44283+
44284 /*
44285 * sys_execve() executes a new program.
44286 */
44287@@ -1458,6 +1512,11 @@ static int do_execve_common(const char *filename,
44288 struct user_arg_ptr envp,
44289 struct pt_regs *regs)
44290 {
44291+#ifdef CONFIG_GRKERNSEC
44292+ struct file *old_exec_file;
44293+ struct acl_subject_label *old_acl;
44294+ struct rlimit old_rlim[RLIM_NLIMITS];
44295+#endif
44296 struct linux_binprm *bprm;
44297 struct file *file;
44298 struct files_struct *displaced;
44299@@ -1465,6 +1524,8 @@ static int do_execve_common(const char *filename,
44300 int retval;
44301 const struct cred *cred = current_cred();
44302
44303+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44304+
44305 /*
44306 * We move the actual failure in case of RLIMIT_NPROC excess from
44307 * set*uid() to execve() because too many poorly written programs
44308@@ -1505,12 +1566,27 @@ static int do_execve_common(const char *filename,
44309 if (IS_ERR(file))
44310 goto out_unmark;
44311
44312+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
44313+ retval = -EPERM;
44314+ goto out_file;
44315+ }
44316+
44317 sched_exec();
44318
44319 bprm->file = file;
44320 bprm->filename = filename;
44321 bprm->interp = filename;
44322
44323+ if (gr_process_user_ban()) {
44324+ retval = -EPERM;
44325+ goto out_file;
44326+ }
44327+
44328+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44329+ retval = -EACCES;
44330+ goto out_file;
44331+ }
44332+
44333 retval = bprm_mm_init(bprm);
44334 if (retval)
44335 goto out_file;
44336@@ -1527,24 +1603,65 @@ static int do_execve_common(const char *filename,
44337 if (retval < 0)
44338 goto out;
44339
44340+#ifdef CONFIG_GRKERNSEC
44341+ old_acl = current->acl;
44342+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44343+ old_exec_file = current->exec_file;
44344+ get_file(file);
44345+ current->exec_file = file;
44346+#endif
44347+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44348+ /* limit suid stack to 8MB
44349+ we saved the old limits above and will restore them if this exec fails
44350+ */
44351+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44352+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44353+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44354+#endif
44355+
44356+ if (!gr_tpe_allow(file)) {
44357+ retval = -EACCES;
44358+ goto out_fail;
44359+ }
44360+
44361+ if (gr_check_crash_exec(file)) {
44362+ retval = -EACCES;
44363+ goto out_fail;
44364+ }
44365+
44366+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44367+ bprm->unsafe);
44368+ if (retval < 0)
44369+ goto out_fail;
44370+
44371 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44372 if (retval < 0)
44373- goto out;
44374+ goto out_fail;
44375
44376 bprm->exec = bprm->p;
44377 retval = copy_strings(bprm->envc, envp, bprm);
44378 if (retval < 0)
44379- goto out;
44380+ goto out_fail;
44381
44382 retval = copy_strings(bprm->argc, argv, bprm);
44383 if (retval < 0)
44384- goto out;
44385+ goto out_fail;
44386+
44387+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44388+
44389+ gr_handle_exec_args(bprm, argv);
44390
44391 retval = search_binary_handler(bprm,regs);
44392 if (retval < 0)
44393- goto out;
44394+ goto out_fail;
44395+#ifdef CONFIG_GRKERNSEC
44396+ if (old_exec_file)
44397+ fput(old_exec_file);
44398+#endif
44399
44400 /* execve succeeded */
44401+
44402+ increment_exec_counter();
44403 current->fs->in_exec = 0;
44404 current->in_execve = 0;
44405 acct_update_integrals(current);
44406@@ -1553,6 +1670,14 @@ static int do_execve_common(const char *filename,
44407 put_files_struct(displaced);
44408 return retval;
44409
44410+out_fail:
44411+#ifdef CONFIG_GRKERNSEC
44412+ current->acl = old_acl;
44413+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44414+ fput(current->exec_file);
44415+ current->exec_file = old_exec_file;
44416+#endif
44417+
44418 out:
44419 if (bprm->mm) {
44420 acct_arg_size(bprm, 0);
44421@@ -1626,7 +1751,7 @@ static int expand_corename(struct core_name *cn)
44422 {
44423 char *old_corename = cn->corename;
44424
44425- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44426+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44427 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44428
44429 if (!cn->corename) {
44430@@ -1723,7 +1848,7 @@ static int format_corename(struct core_name *cn, long signr)
44431 int pid_in_pattern = 0;
44432 int err = 0;
44433
44434- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44435+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44436 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44437 cn->used = 0;
44438
44439@@ -1820,6 +1945,228 @@ out:
44440 return ispipe;
44441 }
44442
44443+int pax_check_flags(unsigned long *flags)
44444+{
44445+ int retval = 0;
44446+
44447+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44448+ if (*flags & MF_PAX_SEGMEXEC)
44449+ {
44450+ *flags &= ~MF_PAX_SEGMEXEC;
44451+ retval = -EINVAL;
44452+ }
44453+#endif
44454+
44455+ if ((*flags & MF_PAX_PAGEEXEC)
44456+
44457+#ifdef CONFIG_PAX_PAGEEXEC
44458+ && (*flags & MF_PAX_SEGMEXEC)
44459+#endif
44460+
44461+ )
44462+ {
44463+ *flags &= ~MF_PAX_PAGEEXEC;
44464+ retval = -EINVAL;
44465+ }
44466+
44467+ if ((*flags & MF_PAX_MPROTECT)
44468+
44469+#ifdef CONFIG_PAX_MPROTECT
44470+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44471+#endif
44472+
44473+ )
44474+ {
44475+ *flags &= ~MF_PAX_MPROTECT;
44476+ retval = -EINVAL;
44477+ }
44478+
44479+ if ((*flags & MF_PAX_EMUTRAMP)
44480+
44481+#ifdef CONFIG_PAX_EMUTRAMP
44482+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44483+#endif
44484+
44485+ )
44486+ {
44487+ *flags &= ~MF_PAX_EMUTRAMP;
44488+ retval = -EINVAL;
44489+ }
44490+
44491+ return retval;
44492+}
44493+
44494+EXPORT_SYMBOL(pax_check_flags);
44495+
44496+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44497+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44498+{
44499+ struct task_struct *tsk = current;
44500+ struct mm_struct *mm = current->mm;
44501+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44502+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44503+ char *path_exec = NULL;
44504+ char *path_fault = NULL;
44505+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
44506+
44507+ if (buffer_exec && buffer_fault) {
44508+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44509+
44510+ down_read(&mm->mmap_sem);
44511+ vma = mm->mmap;
44512+ while (vma && (!vma_exec || !vma_fault)) {
44513+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44514+ vma_exec = vma;
44515+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44516+ vma_fault = vma;
44517+ vma = vma->vm_next;
44518+ }
44519+ if (vma_exec) {
44520+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44521+ if (IS_ERR(path_exec))
44522+ path_exec = "<path too long>";
44523+ else {
44524+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44525+ if (path_exec) {
44526+ *path_exec = 0;
44527+ path_exec = buffer_exec;
44528+ } else
44529+ path_exec = "<path too long>";
44530+ }
44531+ }
44532+ if (vma_fault) {
44533+ start = vma_fault->vm_start;
44534+ end = vma_fault->vm_end;
44535+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44536+ if (vma_fault->vm_file) {
44537+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44538+ if (IS_ERR(path_fault))
44539+ path_fault = "<path too long>";
44540+ else {
44541+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44542+ if (path_fault) {
44543+ *path_fault = 0;
44544+ path_fault = buffer_fault;
44545+ } else
44546+ path_fault = "<path too long>";
44547+ }
44548+ } else
44549+ path_fault = "<anonymous mapping>";
44550+ }
44551+ up_read(&mm->mmap_sem);
44552+ }
44553+ if (tsk->signal->curr_ip)
44554+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44555+ else
44556+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44557+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44558+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44559+ task_uid(tsk), task_euid(tsk), pc, sp);
44560+ free_page((unsigned long)buffer_exec);
44561+ free_page((unsigned long)buffer_fault);
44562+ pax_report_insns(regs, pc, sp);
44563+ do_coredump(SIGKILL, SIGKILL, regs);
44564+}
44565+#endif
44566+
44567+#ifdef CONFIG_PAX_REFCOUNT
44568+void pax_report_refcount_overflow(struct pt_regs *regs)
44569+{
44570+ if (current->signal->curr_ip)
44571+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44572+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44573+ else
44574+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44575+ current->comm, task_pid_nr(current), current_uid(), current_euid());
44576+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44577+ show_regs(regs);
44578+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44579+}
44580+#endif
44581+
44582+#ifdef CONFIG_PAX_USERCOPY
44583+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44584+int object_is_on_stack(const void *obj, unsigned long len)
44585+{
44586+ const void * const stack = task_stack_page(current);
44587+ const void * const stackend = stack + THREAD_SIZE;
44588+
44589+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44590+ const void *frame = NULL;
44591+ const void *oldframe;
44592+#endif
44593+
44594+ if (obj + len < obj)
44595+ return -1;
44596+
44597+ if (obj + len <= stack || stackend <= obj)
44598+ return 0;
44599+
44600+ if (obj < stack || stackend < obj + len)
44601+ return -1;
44602+
44603+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44604+ oldframe = __builtin_frame_address(1);
44605+ if (oldframe)
44606+ frame = __builtin_frame_address(2);
44607+ /*
44608+ low ----------------------------------------------> high
44609+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
44610+ ^----------------^
44611+ allow copies only within here
44612+ */
44613+ while (stack <= frame && frame < stackend) {
44614+ /* if obj + len extends past the last frame, this
44615+ check won't pass and the next frame will be 0,
44616+ causing us to bail out and correctly report
44617+ the copy as invalid
44618+ */
44619+ if (obj + len <= frame)
44620+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44621+ oldframe = frame;
44622+ frame = *(const void * const *)frame;
44623+ }
44624+ return -1;
44625+#else
44626+ return 1;
44627+#endif
44628+}
44629+
44630+__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44631+{
44632+ if (current->signal->curr_ip)
44633+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44634+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44635+ else
44636+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44637+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44638+ dump_stack();
44639+ gr_handle_kernel_exploit();
44640+ do_group_exit(SIGKILL);
44641+}
44642+#endif
44643+
44644+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44645+void pax_track_stack(void)
44646+{
44647+ unsigned long sp = (unsigned long)&sp;
44648+ if (sp < current_thread_info()->lowest_stack &&
44649+ sp > (unsigned long)task_stack_page(current))
44650+ current_thread_info()->lowest_stack = sp;
44651+}
44652+EXPORT_SYMBOL(pax_track_stack);
44653+#endif
44654+
44655+#ifdef CONFIG_PAX_SIZE_OVERFLOW
44656+void report_size_overflow(const char *file, unsigned int line, const char *func)
44657+{
44658+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44659+ dump_stack();
44660+ do_group_exit(SIGKILL);
44661+}
44662+EXPORT_SYMBOL(report_size_overflow);
44663+#endif
44664+
44665 static int zap_process(struct task_struct *start, int exit_code)
44666 {
44667 struct task_struct *t;
44668@@ -2017,17 +2364,17 @@ static void wait_for_dump_helpers(struct file *file)
44669 pipe = file->f_path.dentry->d_inode->i_pipe;
44670
44671 pipe_lock(pipe);
44672- pipe->readers++;
44673- pipe->writers--;
44674+ atomic_inc(&pipe->readers);
44675+ atomic_dec(&pipe->writers);
44676
44677- while ((pipe->readers > 1) && (!signal_pending(current))) {
44678+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44679 wake_up_interruptible_sync(&pipe->wait);
44680 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44681 pipe_wait(pipe);
44682 }
44683
44684- pipe->readers--;
44685- pipe->writers++;
44686+ atomic_dec(&pipe->readers);
44687+ atomic_inc(&pipe->writers);
44688 pipe_unlock(pipe);
44689
44690 }
44691@@ -2088,7 +2435,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44692 int retval = 0;
44693 int flag = 0;
44694 int ispipe;
44695- static atomic_t core_dump_count = ATOMIC_INIT(0);
44696+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44697 struct coredump_params cprm = {
44698 .signr = signr,
44699 .regs = regs,
44700@@ -2103,6 +2450,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44701
44702 audit_core_dumps(signr);
44703
44704+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44705+ gr_handle_brute_attach(current, cprm.mm_flags);
44706+
44707 binfmt = mm->binfmt;
44708 if (!binfmt || !binfmt->core_dump)
44709 goto fail;
44710@@ -2170,7 +2520,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44711 }
44712 cprm.limit = RLIM_INFINITY;
44713
44714- dump_count = atomic_inc_return(&core_dump_count);
44715+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
44716 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44717 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44718 task_tgid_vnr(current), current->comm);
44719@@ -2197,6 +2547,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44720 } else {
44721 struct inode *inode;
44722
44723+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44724+
44725 if (cprm.limit < binfmt->min_coredump)
44726 goto fail_unlock;
44727
44728@@ -2240,7 +2592,7 @@ close_fail:
44729 filp_close(cprm.file, NULL);
44730 fail_dropcount:
44731 if (ispipe)
44732- atomic_dec(&core_dump_count);
44733+ atomic_dec_unchecked(&core_dump_count);
44734 fail_unlock:
44735 kfree(cn.corename);
44736 fail_corename:
44737@@ -2259,7 +2611,7 @@ fail:
44738 */
44739 int dump_write(struct file *file, const void *addr, int nr)
44740 {
44741- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44742+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44743 }
44744 EXPORT_SYMBOL(dump_write);
44745
44746diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44747index a8cbe1b..fed04cb 100644
44748--- a/fs/ext2/balloc.c
44749+++ b/fs/ext2/balloc.c
44750@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44751
44752 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44753 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44754- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44755+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44756 sbi->s_resuid != current_fsuid() &&
44757 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44758 return 0;
44759diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44760index a203892..4e64db5 100644
44761--- a/fs/ext3/balloc.c
44762+++ b/fs/ext3/balloc.c
44763@@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
44764
44765 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44766 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44767- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44768+ if (free_blocks < root_blocks + 1 &&
44769 !use_reservation && sbi->s_resuid != current_fsuid() &&
44770- (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44771+ (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
44772+ !capable_nolog(CAP_SYS_RESOURCE)) {
44773 return 0;
44774 }
44775 return 1;
44776diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44777index f9e2cd8..bfdc476 100644
44778--- a/fs/ext4/balloc.c
44779+++ b/fs/ext4/balloc.c
44780@@ -438,8 +438,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
44781 /* Hm, nope. Are (enough) root reserved clusters available? */
44782 if (sbi->s_resuid == current_fsuid() ||
44783 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44784- capable(CAP_SYS_RESOURCE) ||
44785- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44786+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44787+ capable_nolog(CAP_SYS_RESOURCE)) {
44788
44789 if (free_clusters >= (nclusters + dirty_clusters))
44790 return 1;
44791diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44792index 9983ba8..2a5272c 100644
44793--- a/fs/ext4/ext4.h
44794+++ b/fs/ext4/ext4.h
44795@@ -1217,19 +1217,19 @@ struct ext4_sb_info {
44796 unsigned long s_mb_last_start;
44797
44798 /* stats for buddy allocator */
44799- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44800- atomic_t s_bal_success; /* we found long enough chunks */
44801- atomic_t s_bal_allocated; /* in blocks */
44802- atomic_t s_bal_ex_scanned; /* total extents scanned */
44803- atomic_t s_bal_goals; /* goal hits */
44804- atomic_t s_bal_breaks; /* too long searches */
44805- atomic_t s_bal_2orders; /* 2^order hits */
44806+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44807+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44808+ atomic_unchecked_t s_bal_allocated; /* in blocks */
44809+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44810+ atomic_unchecked_t s_bal_goals; /* goal hits */
44811+ atomic_unchecked_t s_bal_breaks; /* too long searches */
44812+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44813 spinlock_t s_bal_lock;
44814 unsigned long s_mb_buddies_generated;
44815 unsigned long long s_mb_generation_time;
44816- atomic_t s_mb_lost_chunks;
44817- atomic_t s_mb_preallocated;
44818- atomic_t s_mb_discarded;
44819+ atomic_unchecked_t s_mb_lost_chunks;
44820+ atomic_unchecked_t s_mb_preallocated;
44821+ atomic_unchecked_t s_mb_discarded;
44822 atomic_t s_lock_busy;
44823
44824 /* locality groups */
44825diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44826index cb990b2..4820141 100644
44827--- a/fs/ext4/mballoc.c
44828+++ b/fs/ext4/mballoc.c
44829@@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44830 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44831
44832 if (EXT4_SB(sb)->s_mb_stats)
44833- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44834+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44835
44836 break;
44837 }
44838@@ -2088,7 +2088,7 @@ repeat:
44839 ac->ac_status = AC_STATUS_CONTINUE;
44840 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44841 cr = 3;
44842- atomic_inc(&sbi->s_mb_lost_chunks);
44843+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44844 goto repeat;
44845 }
44846 }
44847@@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
44848 if (sbi->s_mb_stats) {
44849 ext4_msg(sb, KERN_INFO,
44850 "mballoc: %u blocks %u reqs (%u success)",
44851- atomic_read(&sbi->s_bal_allocated),
44852- atomic_read(&sbi->s_bal_reqs),
44853- atomic_read(&sbi->s_bal_success));
44854+ atomic_read_unchecked(&sbi->s_bal_allocated),
44855+ atomic_read_unchecked(&sbi->s_bal_reqs),
44856+ atomic_read_unchecked(&sbi->s_bal_success));
44857 ext4_msg(sb, KERN_INFO,
44858 "mballoc: %u extents scanned, %u goal hits, "
44859 "%u 2^N hits, %u breaks, %u lost",
44860- atomic_read(&sbi->s_bal_ex_scanned),
44861- atomic_read(&sbi->s_bal_goals),
44862- atomic_read(&sbi->s_bal_2orders),
44863- atomic_read(&sbi->s_bal_breaks),
44864- atomic_read(&sbi->s_mb_lost_chunks));
44865+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44866+ atomic_read_unchecked(&sbi->s_bal_goals),
44867+ atomic_read_unchecked(&sbi->s_bal_2orders),
44868+ atomic_read_unchecked(&sbi->s_bal_breaks),
44869+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44870 ext4_msg(sb, KERN_INFO,
44871 "mballoc: %lu generated and it took %Lu",
44872 sbi->s_mb_buddies_generated,
44873 sbi->s_mb_generation_time);
44874 ext4_msg(sb, KERN_INFO,
44875 "mballoc: %u preallocated, %u discarded",
44876- atomic_read(&sbi->s_mb_preallocated),
44877- atomic_read(&sbi->s_mb_discarded));
44878+ atomic_read_unchecked(&sbi->s_mb_preallocated),
44879+ atomic_read_unchecked(&sbi->s_mb_discarded));
44880 }
44881
44882 free_percpu(sbi->s_locality_groups);
44883@@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44884 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44885
44886 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44887- atomic_inc(&sbi->s_bal_reqs);
44888- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44889+ atomic_inc_unchecked(&sbi->s_bal_reqs);
44890+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44891 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44892- atomic_inc(&sbi->s_bal_success);
44893- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44894+ atomic_inc_unchecked(&sbi->s_bal_success);
44895+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44896 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44897 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44898- atomic_inc(&sbi->s_bal_goals);
44899+ atomic_inc_unchecked(&sbi->s_bal_goals);
44900 if (ac->ac_found > sbi->s_mb_max_to_scan)
44901- atomic_inc(&sbi->s_bal_breaks);
44902+ atomic_inc_unchecked(&sbi->s_bal_breaks);
44903 }
44904
44905 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44906@@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44907 trace_ext4_mb_new_inode_pa(ac, pa);
44908
44909 ext4_mb_use_inode_pa(ac, pa);
44910- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
44911+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
44912
44913 ei = EXT4_I(ac->ac_inode);
44914 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44915@@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44916 trace_ext4_mb_new_group_pa(ac, pa);
44917
44918 ext4_mb_use_group_pa(ac, pa);
44919- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44920+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44921
44922 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44923 lg = ac->ac_lg;
44924@@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44925 * from the bitmap and continue.
44926 */
44927 }
44928- atomic_add(free, &sbi->s_mb_discarded);
44929+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
44930
44931 return err;
44932 }
44933@@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44934 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44935 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44936 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44937- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44938+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44939 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44940
44941 return 0;
44942diff --git a/fs/fcntl.c b/fs/fcntl.c
44943index 22764c7..86372c9 100644
44944--- a/fs/fcntl.c
44945+++ b/fs/fcntl.c
44946@@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44947 if (err)
44948 return err;
44949
44950+ if (gr_handle_chroot_fowner(pid, type))
44951+ return -ENOENT;
44952+ if (gr_check_protected_task_fowner(pid, type))
44953+ return -EACCES;
44954+
44955 f_modown(filp, pid, type, force);
44956 return 0;
44957 }
44958@@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44959
44960 static int f_setown_ex(struct file *filp, unsigned long arg)
44961 {
44962- struct f_owner_ex * __user owner_p = (void * __user)arg;
44963+ struct f_owner_ex __user *owner_p = (void __user *)arg;
44964 struct f_owner_ex owner;
44965 struct pid *pid;
44966 int type;
44967@@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44968
44969 static int f_getown_ex(struct file *filp, unsigned long arg)
44970 {
44971- struct f_owner_ex * __user owner_p = (void * __user)arg;
44972+ struct f_owner_ex __user *owner_p = (void __user *)arg;
44973 struct f_owner_ex owner;
44974 int ret = 0;
44975
44976@@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44977 switch (cmd) {
44978 case F_DUPFD:
44979 case F_DUPFD_CLOEXEC:
44980+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44981 if (arg >= rlimit(RLIMIT_NOFILE))
44982 break;
44983 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44984diff --git a/fs/fifo.c b/fs/fifo.c
44985index b1a524d..4ee270e 100644
44986--- a/fs/fifo.c
44987+++ b/fs/fifo.c
44988@@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44989 */
44990 filp->f_op = &read_pipefifo_fops;
44991 pipe->r_counter++;
44992- if (pipe->readers++ == 0)
44993+ if (atomic_inc_return(&pipe->readers) == 1)
44994 wake_up_partner(inode);
44995
44996- if (!pipe->writers) {
44997+ if (!atomic_read(&pipe->writers)) {
44998 if ((filp->f_flags & O_NONBLOCK)) {
44999 /* suppress POLLHUP until we have
45000 * seen a writer */
45001@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45002 * errno=ENXIO when there is no process reading the FIFO.
45003 */
45004 ret = -ENXIO;
45005- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45006+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45007 goto err;
45008
45009 filp->f_op = &write_pipefifo_fops;
45010 pipe->w_counter++;
45011- if (!pipe->writers++)
45012+ if (atomic_inc_return(&pipe->writers) == 1)
45013 wake_up_partner(inode);
45014
45015- if (!pipe->readers) {
45016+ if (!atomic_read(&pipe->readers)) {
45017 wait_for_partner(inode, &pipe->r_counter);
45018 if (signal_pending(current))
45019 goto err_wr;
45020@@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45021 */
45022 filp->f_op = &rdwr_pipefifo_fops;
45023
45024- pipe->readers++;
45025- pipe->writers++;
45026+ atomic_inc(&pipe->readers);
45027+ atomic_inc(&pipe->writers);
45028 pipe->r_counter++;
45029 pipe->w_counter++;
45030- if (pipe->readers == 1 || pipe->writers == 1)
45031+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45032 wake_up_partner(inode);
45033 break;
45034
45035@@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45036 return 0;
45037
45038 err_rd:
45039- if (!--pipe->readers)
45040+ if (atomic_dec_and_test(&pipe->readers))
45041 wake_up_interruptible(&pipe->wait);
45042 ret = -ERESTARTSYS;
45043 goto err;
45044
45045 err_wr:
45046- if (!--pipe->writers)
45047+ if (atomic_dec_and_test(&pipe->writers))
45048 wake_up_interruptible(&pipe->wait);
45049 ret = -ERESTARTSYS;
45050 goto err;
45051
45052 err:
45053- if (!pipe->readers && !pipe->writers)
45054+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45055 free_pipe_info(inode);
45056
45057 err_nocleanup:
45058diff --git a/fs/file.c b/fs/file.c
45059index 4c6992d..104cdea 100644
45060--- a/fs/file.c
45061+++ b/fs/file.c
45062@@ -15,6 +15,7 @@
45063 #include <linux/slab.h>
45064 #include <linux/vmalloc.h>
45065 #include <linux/file.h>
45066+#include <linux/security.h>
45067 #include <linux/fdtable.h>
45068 #include <linux/bitops.h>
45069 #include <linux/interrupt.h>
45070@@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
45071 * N.B. For clone tasks sharing a files structure, this test
45072 * will limit the total number of files that can be opened.
45073 */
45074+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45075 if (nr >= rlimit(RLIMIT_NOFILE))
45076 return -EMFILE;
45077
45078diff --git a/fs/filesystems.c b/fs/filesystems.c
45079index 96f2428..f5eeb8e 100644
45080--- a/fs/filesystems.c
45081+++ b/fs/filesystems.c
45082@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45083 int len = dot ? dot - name : strlen(name);
45084
45085 fs = __get_fs_type(name, len);
45086+
45087+#ifdef CONFIG_GRKERNSEC_MODHARDEN
45088+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45089+#else
45090 if (!fs && (request_module("%.*s", len, name) == 0))
45091+#endif
45092 fs = __get_fs_type(name, len);
45093
45094 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45095diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45096index 78b519c..a8b4979 100644
45097--- a/fs/fs_struct.c
45098+++ b/fs/fs_struct.c
45099@@ -4,6 +4,7 @@
45100 #include <linux/path.h>
45101 #include <linux/slab.h>
45102 #include <linux/fs_struct.h>
45103+#include <linux/grsecurity.h>
45104 #include "internal.h"
45105
45106 static inline void path_get_longterm(struct path *path)
45107@@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45108 old_root = fs->root;
45109 fs->root = *path;
45110 path_get_longterm(path);
45111+ gr_set_chroot_entries(current, path);
45112 write_seqcount_end(&fs->seq);
45113 spin_unlock(&fs->lock);
45114 if (old_root.dentry)
45115@@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45116 && fs->root.mnt == old_root->mnt) {
45117 path_get_longterm(new_root);
45118 fs->root = *new_root;
45119+ gr_set_chroot_entries(p, new_root);
45120 count++;
45121 }
45122 if (fs->pwd.dentry == old_root->dentry
45123@@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
45124 spin_lock(&fs->lock);
45125 write_seqcount_begin(&fs->seq);
45126 tsk->fs = NULL;
45127- kill = !--fs->users;
45128+ gr_clear_chroot_entries(tsk);
45129+ kill = !atomic_dec_return(&fs->users);
45130 write_seqcount_end(&fs->seq);
45131 spin_unlock(&fs->lock);
45132 task_unlock(tsk);
45133@@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45134 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45135 /* We don't need to lock fs - think why ;-) */
45136 if (fs) {
45137- fs->users = 1;
45138+ atomic_set(&fs->users, 1);
45139 fs->in_exec = 0;
45140 spin_lock_init(&fs->lock);
45141 seqcount_init(&fs->seq);
45142@@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45143 spin_lock(&old->lock);
45144 fs->root = old->root;
45145 path_get_longterm(&fs->root);
45146+ /* instead of calling gr_set_chroot_entries here,
45147+ we call it from every caller of this function
45148+ */
45149 fs->pwd = old->pwd;
45150 path_get_longterm(&fs->pwd);
45151 spin_unlock(&old->lock);
45152@@ -150,8 +157,9 @@ int unshare_fs_struct(void)
45153
45154 task_lock(current);
45155 spin_lock(&fs->lock);
45156- kill = !--fs->users;
45157+ kill = !atomic_dec_return(&fs->users);
45158 current->fs = new_fs;
45159+ gr_set_chroot_entries(current, &new_fs->root);
45160 spin_unlock(&fs->lock);
45161 task_unlock(current);
45162
45163@@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45164
45165 int current_umask(void)
45166 {
45167- return current->fs->umask;
45168+ return current->fs->umask | gr_acl_umask();
45169 }
45170 EXPORT_SYMBOL(current_umask);
45171
45172 /* to be mentioned only in INIT_TASK */
45173 struct fs_struct init_fs = {
45174- .users = 1,
45175+ .users = ATOMIC_INIT(1),
45176 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45177 .seq = SEQCNT_ZERO,
45178 .umask = 0022,
45179@@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
45180 task_lock(current);
45181
45182 spin_lock(&init_fs.lock);
45183- init_fs.users++;
45184+ atomic_inc(&init_fs.users);
45185 spin_unlock(&init_fs.lock);
45186
45187 spin_lock(&fs->lock);
45188 current->fs = &init_fs;
45189- kill = !--fs->users;
45190+ gr_set_chroot_entries(current, &current->fs->root);
45191+ kill = !atomic_dec_return(&fs->users);
45192 spin_unlock(&fs->lock);
45193
45194 task_unlock(current);
45195diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45196index 9905350..02eaec4 100644
45197--- a/fs/fscache/cookie.c
45198+++ b/fs/fscache/cookie.c
45199@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45200 parent ? (char *) parent->def->name : "<no-parent>",
45201 def->name, netfs_data);
45202
45203- fscache_stat(&fscache_n_acquires);
45204+ fscache_stat_unchecked(&fscache_n_acquires);
45205
45206 /* if there's no parent cookie, then we don't create one here either */
45207 if (!parent) {
45208- fscache_stat(&fscache_n_acquires_null);
45209+ fscache_stat_unchecked(&fscache_n_acquires_null);
45210 _leave(" [no parent]");
45211 return NULL;
45212 }
45213@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45214 /* allocate and initialise a cookie */
45215 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45216 if (!cookie) {
45217- fscache_stat(&fscache_n_acquires_oom);
45218+ fscache_stat_unchecked(&fscache_n_acquires_oom);
45219 _leave(" [ENOMEM]");
45220 return NULL;
45221 }
45222@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45223
45224 switch (cookie->def->type) {
45225 case FSCACHE_COOKIE_TYPE_INDEX:
45226- fscache_stat(&fscache_n_cookie_index);
45227+ fscache_stat_unchecked(&fscache_n_cookie_index);
45228 break;
45229 case FSCACHE_COOKIE_TYPE_DATAFILE:
45230- fscache_stat(&fscache_n_cookie_data);
45231+ fscache_stat_unchecked(&fscache_n_cookie_data);
45232 break;
45233 default:
45234- fscache_stat(&fscache_n_cookie_special);
45235+ fscache_stat_unchecked(&fscache_n_cookie_special);
45236 break;
45237 }
45238
45239@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45240 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45241 atomic_dec(&parent->n_children);
45242 __fscache_cookie_put(cookie);
45243- fscache_stat(&fscache_n_acquires_nobufs);
45244+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45245 _leave(" = NULL");
45246 return NULL;
45247 }
45248 }
45249
45250- fscache_stat(&fscache_n_acquires_ok);
45251+ fscache_stat_unchecked(&fscache_n_acquires_ok);
45252 _leave(" = %p", cookie);
45253 return cookie;
45254 }
45255@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45256 cache = fscache_select_cache_for_object(cookie->parent);
45257 if (!cache) {
45258 up_read(&fscache_addremove_sem);
45259- fscache_stat(&fscache_n_acquires_no_cache);
45260+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45261 _leave(" = -ENOMEDIUM [no cache]");
45262 return -ENOMEDIUM;
45263 }
45264@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45265 object = cache->ops->alloc_object(cache, cookie);
45266 fscache_stat_d(&fscache_n_cop_alloc_object);
45267 if (IS_ERR(object)) {
45268- fscache_stat(&fscache_n_object_no_alloc);
45269+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
45270 ret = PTR_ERR(object);
45271 goto error;
45272 }
45273
45274- fscache_stat(&fscache_n_object_alloc);
45275+ fscache_stat_unchecked(&fscache_n_object_alloc);
45276
45277 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45278
45279@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45280 struct fscache_object *object;
45281 struct hlist_node *_p;
45282
45283- fscache_stat(&fscache_n_updates);
45284+ fscache_stat_unchecked(&fscache_n_updates);
45285
45286 if (!cookie) {
45287- fscache_stat(&fscache_n_updates_null);
45288+ fscache_stat_unchecked(&fscache_n_updates_null);
45289 _leave(" [no cookie]");
45290 return;
45291 }
45292@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45293 struct fscache_object *object;
45294 unsigned long event;
45295
45296- fscache_stat(&fscache_n_relinquishes);
45297+ fscache_stat_unchecked(&fscache_n_relinquishes);
45298 if (retire)
45299- fscache_stat(&fscache_n_relinquishes_retire);
45300+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45301
45302 if (!cookie) {
45303- fscache_stat(&fscache_n_relinquishes_null);
45304+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
45305 _leave(" [no cookie]");
45306 return;
45307 }
45308@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45309
45310 /* wait for the cookie to finish being instantiated (or to fail) */
45311 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45312- fscache_stat(&fscache_n_relinquishes_waitcrt);
45313+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45314 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45315 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45316 }
45317diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45318index f6aad48..88dcf26 100644
45319--- a/fs/fscache/internal.h
45320+++ b/fs/fscache/internal.h
45321@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45322 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45323 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45324
45325-extern atomic_t fscache_n_op_pend;
45326-extern atomic_t fscache_n_op_run;
45327-extern atomic_t fscache_n_op_enqueue;
45328-extern atomic_t fscache_n_op_deferred_release;
45329-extern atomic_t fscache_n_op_release;
45330-extern atomic_t fscache_n_op_gc;
45331-extern atomic_t fscache_n_op_cancelled;
45332-extern atomic_t fscache_n_op_rejected;
45333+extern atomic_unchecked_t fscache_n_op_pend;
45334+extern atomic_unchecked_t fscache_n_op_run;
45335+extern atomic_unchecked_t fscache_n_op_enqueue;
45336+extern atomic_unchecked_t fscache_n_op_deferred_release;
45337+extern atomic_unchecked_t fscache_n_op_release;
45338+extern atomic_unchecked_t fscache_n_op_gc;
45339+extern atomic_unchecked_t fscache_n_op_cancelled;
45340+extern atomic_unchecked_t fscache_n_op_rejected;
45341
45342-extern atomic_t fscache_n_attr_changed;
45343-extern atomic_t fscache_n_attr_changed_ok;
45344-extern atomic_t fscache_n_attr_changed_nobufs;
45345-extern atomic_t fscache_n_attr_changed_nomem;
45346-extern atomic_t fscache_n_attr_changed_calls;
45347+extern atomic_unchecked_t fscache_n_attr_changed;
45348+extern atomic_unchecked_t fscache_n_attr_changed_ok;
45349+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45350+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45351+extern atomic_unchecked_t fscache_n_attr_changed_calls;
45352
45353-extern atomic_t fscache_n_allocs;
45354-extern atomic_t fscache_n_allocs_ok;
45355-extern atomic_t fscache_n_allocs_wait;
45356-extern atomic_t fscache_n_allocs_nobufs;
45357-extern atomic_t fscache_n_allocs_intr;
45358-extern atomic_t fscache_n_allocs_object_dead;
45359-extern atomic_t fscache_n_alloc_ops;
45360-extern atomic_t fscache_n_alloc_op_waits;
45361+extern atomic_unchecked_t fscache_n_allocs;
45362+extern atomic_unchecked_t fscache_n_allocs_ok;
45363+extern atomic_unchecked_t fscache_n_allocs_wait;
45364+extern atomic_unchecked_t fscache_n_allocs_nobufs;
45365+extern atomic_unchecked_t fscache_n_allocs_intr;
45366+extern atomic_unchecked_t fscache_n_allocs_object_dead;
45367+extern atomic_unchecked_t fscache_n_alloc_ops;
45368+extern atomic_unchecked_t fscache_n_alloc_op_waits;
45369
45370-extern atomic_t fscache_n_retrievals;
45371-extern atomic_t fscache_n_retrievals_ok;
45372-extern atomic_t fscache_n_retrievals_wait;
45373-extern atomic_t fscache_n_retrievals_nodata;
45374-extern atomic_t fscache_n_retrievals_nobufs;
45375-extern atomic_t fscache_n_retrievals_intr;
45376-extern atomic_t fscache_n_retrievals_nomem;
45377-extern atomic_t fscache_n_retrievals_object_dead;
45378-extern atomic_t fscache_n_retrieval_ops;
45379-extern atomic_t fscache_n_retrieval_op_waits;
45380+extern atomic_unchecked_t fscache_n_retrievals;
45381+extern atomic_unchecked_t fscache_n_retrievals_ok;
45382+extern atomic_unchecked_t fscache_n_retrievals_wait;
45383+extern atomic_unchecked_t fscache_n_retrievals_nodata;
45384+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45385+extern atomic_unchecked_t fscache_n_retrievals_intr;
45386+extern atomic_unchecked_t fscache_n_retrievals_nomem;
45387+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45388+extern atomic_unchecked_t fscache_n_retrieval_ops;
45389+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45390
45391-extern atomic_t fscache_n_stores;
45392-extern atomic_t fscache_n_stores_ok;
45393-extern atomic_t fscache_n_stores_again;
45394-extern atomic_t fscache_n_stores_nobufs;
45395-extern atomic_t fscache_n_stores_oom;
45396-extern atomic_t fscache_n_store_ops;
45397-extern atomic_t fscache_n_store_calls;
45398-extern atomic_t fscache_n_store_pages;
45399-extern atomic_t fscache_n_store_radix_deletes;
45400-extern atomic_t fscache_n_store_pages_over_limit;
45401+extern atomic_unchecked_t fscache_n_stores;
45402+extern atomic_unchecked_t fscache_n_stores_ok;
45403+extern atomic_unchecked_t fscache_n_stores_again;
45404+extern atomic_unchecked_t fscache_n_stores_nobufs;
45405+extern atomic_unchecked_t fscache_n_stores_oom;
45406+extern atomic_unchecked_t fscache_n_store_ops;
45407+extern atomic_unchecked_t fscache_n_store_calls;
45408+extern atomic_unchecked_t fscache_n_store_pages;
45409+extern atomic_unchecked_t fscache_n_store_radix_deletes;
45410+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45411
45412-extern atomic_t fscache_n_store_vmscan_not_storing;
45413-extern atomic_t fscache_n_store_vmscan_gone;
45414-extern atomic_t fscache_n_store_vmscan_busy;
45415-extern atomic_t fscache_n_store_vmscan_cancelled;
45416+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45417+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45418+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45419+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45420
45421-extern atomic_t fscache_n_marks;
45422-extern atomic_t fscache_n_uncaches;
45423+extern atomic_unchecked_t fscache_n_marks;
45424+extern atomic_unchecked_t fscache_n_uncaches;
45425
45426-extern atomic_t fscache_n_acquires;
45427-extern atomic_t fscache_n_acquires_null;
45428-extern atomic_t fscache_n_acquires_no_cache;
45429-extern atomic_t fscache_n_acquires_ok;
45430-extern atomic_t fscache_n_acquires_nobufs;
45431-extern atomic_t fscache_n_acquires_oom;
45432+extern atomic_unchecked_t fscache_n_acquires;
45433+extern atomic_unchecked_t fscache_n_acquires_null;
45434+extern atomic_unchecked_t fscache_n_acquires_no_cache;
45435+extern atomic_unchecked_t fscache_n_acquires_ok;
45436+extern atomic_unchecked_t fscache_n_acquires_nobufs;
45437+extern atomic_unchecked_t fscache_n_acquires_oom;
45438
45439-extern atomic_t fscache_n_updates;
45440-extern atomic_t fscache_n_updates_null;
45441-extern atomic_t fscache_n_updates_run;
45442+extern atomic_unchecked_t fscache_n_updates;
45443+extern atomic_unchecked_t fscache_n_updates_null;
45444+extern atomic_unchecked_t fscache_n_updates_run;
45445
45446-extern atomic_t fscache_n_relinquishes;
45447-extern atomic_t fscache_n_relinquishes_null;
45448-extern atomic_t fscache_n_relinquishes_waitcrt;
45449-extern atomic_t fscache_n_relinquishes_retire;
45450+extern atomic_unchecked_t fscache_n_relinquishes;
45451+extern atomic_unchecked_t fscache_n_relinquishes_null;
45452+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45453+extern atomic_unchecked_t fscache_n_relinquishes_retire;
45454
45455-extern atomic_t fscache_n_cookie_index;
45456-extern atomic_t fscache_n_cookie_data;
45457-extern atomic_t fscache_n_cookie_special;
45458+extern atomic_unchecked_t fscache_n_cookie_index;
45459+extern atomic_unchecked_t fscache_n_cookie_data;
45460+extern atomic_unchecked_t fscache_n_cookie_special;
45461
45462-extern atomic_t fscache_n_object_alloc;
45463-extern atomic_t fscache_n_object_no_alloc;
45464-extern atomic_t fscache_n_object_lookups;
45465-extern atomic_t fscache_n_object_lookups_negative;
45466-extern atomic_t fscache_n_object_lookups_positive;
45467-extern atomic_t fscache_n_object_lookups_timed_out;
45468-extern atomic_t fscache_n_object_created;
45469-extern atomic_t fscache_n_object_avail;
45470-extern atomic_t fscache_n_object_dead;
45471+extern atomic_unchecked_t fscache_n_object_alloc;
45472+extern atomic_unchecked_t fscache_n_object_no_alloc;
45473+extern atomic_unchecked_t fscache_n_object_lookups;
45474+extern atomic_unchecked_t fscache_n_object_lookups_negative;
45475+extern atomic_unchecked_t fscache_n_object_lookups_positive;
45476+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45477+extern atomic_unchecked_t fscache_n_object_created;
45478+extern atomic_unchecked_t fscache_n_object_avail;
45479+extern atomic_unchecked_t fscache_n_object_dead;
45480
45481-extern atomic_t fscache_n_checkaux_none;
45482-extern atomic_t fscache_n_checkaux_okay;
45483-extern atomic_t fscache_n_checkaux_update;
45484-extern atomic_t fscache_n_checkaux_obsolete;
45485+extern atomic_unchecked_t fscache_n_checkaux_none;
45486+extern atomic_unchecked_t fscache_n_checkaux_okay;
45487+extern atomic_unchecked_t fscache_n_checkaux_update;
45488+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45489
45490 extern atomic_t fscache_n_cop_alloc_object;
45491 extern atomic_t fscache_n_cop_lookup_object;
45492@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45493 atomic_inc(stat);
45494 }
45495
45496+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45497+{
45498+ atomic_inc_unchecked(stat);
45499+}
45500+
45501 static inline void fscache_stat_d(atomic_t *stat)
45502 {
45503 atomic_dec(stat);
45504@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45505
45506 #define __fscache_stat(stat) (NULL)
45507 #define fscache_stat(stat) do {} while (0)
45508+#define fscache_stat_unchecked(stat) do {} while (0)
45509 #define fscache_stat_d(stat) do {} while (0)
45510 #endif
45511
45512diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45513index b6b897c..0ffff9c 100644
45514--- a/fs/fscache/object.c
45515+++ b/fs/fscache/object.c
45516@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45517 /* update the object metadata on disk */
45518 case FSCACHE_OBJECT_UPDATING:
45519 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45520- fscache_stat(&fscache_n_updates_run);
45521+ fscache_stat_unchecked(&fscache_n_updates_run);
45522 fscache_stat(&fscache_n_cop_update_object);
45523 object->cache->ops->update_object(object);
45524 fscache_stat_d(&fscache_n_cop_update_object);
45525@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45526 spin_lock(&object->lock);
45527 object->state = FSCACHE_OBJECT_DEAD;
45528 spin_unlock(&object->lock);
45529- fscache_stat(&fscache_n_object_dead);
45530+ fscache_stat_unchecked(&fscache_n_object_dead);
45531 goto terminal_transit;
45532
45533 /* handle the parent cache of this object being withdrawn from
45534@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45535 spin_lock(&object->lock);
45536 object->state = FSCACHE_OBJECT_DEAD;
45537 spin_unlock(&object->lock);
45538- fscache_stat(&fscache_n_object_dead);
45539+ fscache_stat_unchecked(&fscache_n_object_dead);
45540 goto terminal_transit;
45541
45542 /* complain about the object being woken up once it is
45543@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45544 parent->cookie->def->name, cookie->def->name,
45545 object->cache->tag->name);
45546
45547- fscache_stat(&fscache_n_object_lookups);
45548+ fscache_stat_unchecked(&fscache_n_object_lookups);
45549 fscache_stat(&fscache_n_cop_lookup_object);
45550 ret = object->cache->ops->lookup_object(object);
45551 fscache_stat_d(&fscache_n_cop_lookup_object);
45552@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45553 if (ret == -ETIMEDOUT) {
45554 /* probably stuck behind another object, so move this one to
45555 * the back of the queue */
45556- fscache_stat(&fscache_n_object_lookups_timed_out);
45557+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45558 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45559 }
45560
45561@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45562
45563 spin_lock(&object->lock);
45564 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45565- fscache_stat(&fscache_n_object_lookups_negative);
45566+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45567
45568 /* transit here to allow write requests to begin stacking up
45569 * and read requests to begin returning ENODATA */
45570@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45571 * result, in which case there may be data available */
45572 spin_lock(&object->lock);
45573 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45574- fscache_stat(&fscache_n_object_lookups_positive);
45575+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45576
45577 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45578
45579@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45580 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45581 } else {
45582 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45583- fscache_stat(&fscache_n_object_created);
45584+ fscache_stat_unchecked(&fscache_n_object_created);
45585
45586 object->state = FSCACHE_OBJECT_AVAILABLE;
45587 spin_unlock(&object->lock);
45588@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45589 fscache_enqueue_dependents(object);
45590
45591 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45592- fscache_stat(&fscache_n_object_avail);
45593+ fscache_stat_unchecked(&fscache_n_object_avail);
45594
45595 _leave("");
45596 }
45597@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45598 enum fscache_checkaux result;
45599
45600 if (!object->cookie->def->check_aux) {
45601- fscache_stat(&fscache_n_checkaux_none);
45602+ fscache_stat_unchecked(&fscache_n_checkaux_none);
45603 return FSCACHE_CHECKAUX_OKAY;
45604 }
45605
45606@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45607 switch (result) {
45608 /* entry okay as is */
45609 case FSCACHE_CHECKAUX_OKAY:
45610- fscache_stat(&fscache_n_checkaux_okay);
45611+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
45612 break;
45613
45614 /* entry requires update */
45615 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45616- fscache_stat(&fscache_n_checkaux_update);
45617+ fscache_stat_unchecked(&fscache_n_checkaux_update);
45618 break;
45619
45620 /* entry requires deletion */
45621 case FSCACHE_CHECKAUX_OBSOLETE:
45622- fscache_stat(&fscache_n_checkaux_obsolete);
45623+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45624 break;
45625
45626 default:
45627diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45628index 30afdfa..2256596 100644
45629--- a/fs/fscache/operation.c
45630+++ b/fs/fscache/operation.c
45631@@ -17,7 +17,7 @@
45632 #include <linux/slab.h>
45633 #include "internal.h"
45634
45635-atomic_t fscache_op_debug_id;
45636+atomic_unchecked_t fscache_op_debug_id;
45637 EXPORT_SYMBOL(fscache_op_debug_id);
45638
45639 /**
45640@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45641 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45642 ASSERTCMP(atomic_read(&op->usage), >, 0);
45643
45644- fscache_stat(&fscache_n_op_enqueue);
45645+ fscache_stat_unchecked(&fscache_n_op_enqueue);
45646 switch (op->flags & FSCACHE_OP_TYPE) {
45647 case FSCACHE_OP_ASYNC:
45648 _debug("queue async");
45649@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45650 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45651 if (op->processor)
45652 fscache_enqueue_operation(op);
45653- fscache_stat(&fscache_n_op_run);
45654+ fscache_stat_unchecked(&fscache_n_op_run);
45655 }
45656
45657 /*
45658@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45659 if (object->n_ops > 1) {
45660 atomic_inc(&op->usage);
45661 list_add_tail(&op->pend_link, &object->pending_ops);
45662- fscache_stat(&fscache_n_op_pend);
45663+ fscache_stat_unchecked(&fscache_n_op_pend);
45664 } else if (!list_empty(&object->pending_ops)) {
45665 atomic_inc(&op->usage);
45666 list_add_tail(&op->pend_link, &object->pending_ops);
45667- fscache_stat(&fscache_n_op_pend);
45668+ fscache_stat_unchecked(&fscache_n_op_pend);
45669 fscache_start_operations(object);
45670 } else {
45671 ASSERTCMP(object->n_in_progress, ==, 0);
45672@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45673 object->n_exclusive++; /* reads and writes must wait */
45674 atomic_inc(&op->usage);
45675 list_add_tail(&op->pend_link, &object->pending_ops);
45676- fscache_stat(&fscache_n_op_pend);
45677+ fscache_stat_unchecked(&fscache_n_op_pend);
45678 ret = 0;
45679 } else {
45680 /* not allowed to submit ops in any other state */
45681@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45682 if (object->n_exclusive > 0) {
45683 atomic_inc(&op->usage);
45684 list_add_tail(&op->pend_link, &object->pending_ops);
45685- fscache_stat(&fscache_n_op_pend);
45686+ fscache_stat_unchecked(&fscache_n_op_pend);
45687 } else if (!list_empty(&object->pending_ops)) {
45688 atomic_inc(&op->usage);
45689 list_add_tail(&op->pend_link, &object->pending_ops);
45690- fscache_stat(&fscache_n_op_pend);
45691+ fscache_stat_unchecked(&fscache_n_op_pend);
45692 fscache_start_operations(object);
45693 } else {
45694 ASSERTCMP(object->n_exclusive, ==, 0);
45695@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45696 object->n_ops++;
45697 atomic_inc(&op->usage);
45698 list_add_tail(&op->pend_link, &object->pending_ops);
45699- fscache_stat(&fscache_n_op_pend);
45700+ fscache_stat_unchecked(&fscache_n_op_pend);
45701 ret = 0;
45702 } else if (object->state == FSCACHE_OBJECT_DYING ||
45703 object->state == FSCACHE_OBJECT_LC_DYING ||
45704 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45705- fscache_stat(&fscache_n_op_rejected);
45706+ fscache_stat_unchecked(&fscache_n_op_rejected);
45707 ret = -ENOBUFS;
45708 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45709 fscache_report_unexpected_submission(object, op, ostate);
45710@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45711
45712 ret = -EBUSY;
45713 if (!list_empty(&op->pend_link)) {
45714- fscache_stat(&fscache_n_op_cancelled);
45715+ fscache_stat_unchecked(&fscache_n_op_cancelled);
45716 list_del_init(&op->pend_link);
45717 object->n_ops--;
45718 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45719@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45720 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45721 BUG();
45722
45723- fscache_stat(&fscache_n_op_release);
45724+ fscache_stat_unchecked(&fscache_n_op_release);
45725
45726 if (op->release) {
45727 op->release(op);
45728@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45729 * lock, and defer it otherwise */
45730 if (!spin_trylock(&object->lock)) {
45731 _debug("defer put");
45732- fscache_stat(&fscache_n_op_deferred_release);
45733+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
45734
45735 cache = object->cache;
45736 spin_lock(&cache->op_gc_list_lock);
45737@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45738
45739 _debug("GC DEFERRED REL OBJ%x OP%x",
45740 object->debug_id, op->debug_id);
45741- fscache_stat(&fscache_n_op_gc);
45742+ fscache_stat_unchecked(&fscache_n_op_gc);
45743
45744 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45745
45746diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45747index 3f7a59b..cf196cc 100644
45748--- a/fs/fscache/page.c
45749+++ b/fs/fscache/page.c
45750@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45751 val = radix_tree_lookup(&cookie->stores, page->index);
45752 if (!val) {
45753 rcu_read_unlock();
45754- fscache_stat(&fscache_n_store_vmscan_not_storing);
45755+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45756 __fscache_uncache_page(cookie, page);
45757 return true;
45758 }
45759@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45760 spin_unlock(&cookie->stores_lock);
45761
45762 if (xpage) {
45763- fscache_stat(&fscache_n_store_vmscan_cancelled);
45764- fscache_stat(&fscache_n_store_radix_deletes);
45765+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45766+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45767 ASSERTCMP(xpage, ==, page);
45768 } else {
45769- fscache_stat(&fscache_n_store_vmscan_gone);
45770+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45771 }
45772
45773 wake_up_bit(&cookie->flags, 0);
45774@@ -107,7 +107,7 @@ page_busy:
45775 /* we might want to wait here, but that could deadlock the allocator as
45776 * the work threads writing to the cache may all end up sleeping
45777 * on memory allocation */
45778- fscache_stat(&fscache_n_store_vmscan_busy);
45779+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45780 return false;
45781 }
45782 EXPORT_SYMBOL(__fscache_maybe_release_page);
45783@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45784 FSCACHE_COOKIE_STORING_TAG);
45785 if (!radix_tree_tag_get(&cookie->stores, page->index,
45786 FSCACHE_COOKIE_PENDING_TAG)) {
45787- fscache_stat(&fscache_n_store_radix_deletes);
45788+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45789 xpage = radix_tree_delete(&cookie->stores, page->index);
45790 }
45791 spin_unlock(&cookie->stores_lock);
45792@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45793
45794 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45795
45796- fscache_stat(&fscache_n_attr_changed_calls);
45797+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45798
45799 if (fscache_object_is_active(object)) {
45800 fscache_stat(&fscache_n_cop_attr_changed);
45801@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45802
45803 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45804
45805- fscache_stat(&fscache_n_attr_changed);
45806+ fscache_stat_unchecked(&fscache_n_attr_changed);
45807
45808 op = kzalloc(sizeof(*op), GFP_KERNEL);
45809 if (!op) {
45810- fscache_stat(&fscache_n_attr_changed_nomem);
45811+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45812 _leave(" = -ENOMEM");
45813 return -ENOMEM;
45814 }
45815@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45816 if (fscache_submit_exclusive_op(object, op) < 0)
45817 goto nobufs;
45818 spin_unlock(&cookie->lock);
45819- fscache_stat(&fscache_n_attr_changed_ok);
45820+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45821 fscache_put_operation(op);
45822 _leave(" = 0");
45823 return 0;
45824@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45825 nobufs:
45826 spin_unlock(&cookie->lock);
45827 kfree(op);
45828- fscache_stat(&fscache_n_attr_changed_nobufs);
45829+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45830 _leave(" = %d", -ENOBUFS);
45831 return -ENOBUFS;
45832 }
45833@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45834 /* allocate a retrieval operation and attempt to submit it */
45835 op = kzalloc(sizeof(*op), GFP_NOIO);
45836 if (!op) {
45837- fscache_stat(&fscache_n_retrievals_nomem);
45838+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45839 return NULL;
45840 }
45841
45842@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45843 return 0;
45844 }
45845
45846- fscache_stat(&fscache_n_retrievals_wait);
45847+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
45848
45849 jif = jiffies;
45850 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45851 fscache_wait_bit_interruptible,
45852 TASK_INTERRUPTIBLE) != 0) {
45853- fscache_stat(&fscache_n_retrievals_intr);
45854+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
45855 _leave(" = -ERESTARTSYS");
45856 return -ERESTARTSYS;
45857 }
45858@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45859 */
45860 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45861 struct fscache_retrieval *op,
45862- atomic_t *stat_op_waits,
45863- atomic_t *stat_object_dead)
45864+ atomic_unchecked_t *stat_op_waits,
45865+ atomic_unchecked_t *stat_object_dead)
45866 {
45867 int ret;
45868
45869@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45870 goto check_if_dead;
45871
45872 _debug(">>> WT");
45873- fscache_stat(stat_op_waits);
45874+ fscache_stat_unchecked(stat_op_waits);
45875 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45876 fscache_wait_bit_interruptible,
45877 TASK_INTERRUPTIBLE) < 0) {
45878@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45879
45880 check_if_dead:
45881 if (unlikely(fscache_object_is_dead(object))) {
45882- fscache_stat(stat_object_dead);
45883+ fscache_stat_unchecked(stat_object_dead);
45884 return -ENOBUFS;
45885 }
45886 return 0;
45887@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45888
45889 _enter("%p,%p,,,", cookie, page);
45890
45891- fscache_stat(&fscache_n_retrievals);
45892+ fscache_stat_unchecked(&fscache_n_retrievals);
45893
45894 if (hlist_empty(&cookie->backing_objects))
45895 goto nobufs;
45896@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45897 goto nobufs_unlock;
45898 spin_unlock(&cookie->lock);
45899
45900- fscache_stat(&fscache_n_retrieval_ops);
45901+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
45902
45903 /* pin the netfs read context in case we need to do the actual netfs
45904 * read because we've encountered a cache read failure */
45905@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45906
45907 error:
45908 if (ret == -ENOMEM)
45909- fscache_stat(&fscache_n_retrievals_nomem);
45910+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45911 else if (ret == -ERESTARTSYS)
45912- fscache_stat(&fscache_n_retrievals_intr);
45913+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
45914 else if (ret == -ENODATA)
45915- fscache_stat(&fscache_n_retrievals_nodata);
45916+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45917 else if (ret < 0)
45918- fscache_stat(&fscache_n_retrievals_nobufs);
45919+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45920 else
45921- fscache_stat(&fscache_n_retrievals_ok);
45922+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
45923
45924 fscache_put_retrieval(op);
45925 _leave(" = %d", ret);
45926@@ -429,7 +429,7 @@ nobufs_unlock:
45927 spin_unlock(&cookie->lock);
45928 kfree(op);
45929 nobufs:
45930- fscache_stat(&fscache_n_retrievals_nobufs);
45931+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45932 _leave(" = -ENOBUFS");
45933 return -ENOBUFS;
45934 }
45935@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45936
45937 _enter("%p,,%d,,,", cookie, *nr_pages);
45938
45939- fscache_stat(&fscache_n_retrievals);
45940+ fscache_stat_unchecked(&fscache_n_retrievals);
45941
45942 if (hlist_empty(&cookie->backing_objects))
45943 goto nobufs;
45944@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45945 goto nobufs_unlock;
45946 spin_unlock(&cookie->lock);
45947
45948- fscache_stat(&fscache_n_retrieval_ops);
45949+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
45950
45951 /* pin the netfs read context in case we need to do the actual netfs
45952 * read because we've encountered a cache read failure */
45953@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45954
45955 error:
45956 if (ret == -ENOMEM)
45957- fscache_stat(&fscache_n_retrievals_nomem);
45958+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45959 else if (ret == -ERESTARTSYS)
45960- fscache_stat(&fscache_n_retrievals_intr);
45961+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
45962 else if (ret == -ENODATA)
45963- fscache_stat(&fscache_n_retrievals_nodata);
45964+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45965 else if (ret < 0)
45966- fscache_stat(&fscache_n_retrievals_nobufs);
45967+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45968 else
45969- fscache_stat(&fscache_n_retrievals_ok);
45970+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
45971
45972 fscache_put_retrieval(op);
45973 _leave(" = %d", ret);
45974@@ -545,7 +545,7 @@ nobufs_unlock:
45975 spin_unlock(&cookie->lock);
45976 kfree(op);
45977 nobufs:
45978- fscache_stat(&fscache_n_retrievals_nobufs);
45979+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45980 _leave(" = -ENOBUFS");
45981 return -ENOBUFS;
45982 }
45983@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45984
45985 _enter("%p,%p,,,", cookie, page);
45986
45987- fscache_stat(&fscache_n_allocs);
45988+ fscache_stat_unchecked(&fscache_n_allocs);
45989
45990 if (hlist_empty(&cookie->backing_objects))
45991 goto nobufs;
45992@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45993 goto nobufs_unlock;
45994 spin_unlock(&cookie->lock);
45995
45996- fscache_stat(&fscache_n_alloc_ops);
45997+ fscache_stat_unchecked(&fscache_n_alloc_ops);
45998
45999 ret = fscache_wait_for_retrieval_activation(
46000 object, op,
46001@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46002
46003 error:
46004 if (ret == -ERESTARTSYS)
46005- fscache_stat(&fscache_n_allocs_intr);
46006+ fscache_stat_unchecked(&fscache_n_allocs_intr);
46007 else if (ret < 0)
46008- fscache_stat(&fscache_n_allocs_nobufs);
46009+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46010 else
46011- fscache_stat(&fscache_n_allocs_ok);
46012+ fscache_stat_unchecked(&fscache_n_allocs_ok);
46013
46014 fscache_put_retrieval(op);
46015 _leave(" = %d", ret);
46016@@ -625,7 +625,7 @@ nobufs_unlock:
46017 spin_unlock(&cookie->lock);
46018 kfree(op);
46019 nobufs:
46020- fscache_stat(&fscache_n_allocs_nobufs);
46021+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46022 _leave(" = -ENOBUFS");
46023 return -ENOBUFS;
46024 }
46025@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46026
46027 spin_lock(&cookie->stores_lock);
46028
46029- fscache_stat(&fscache_n_store_calls);
46030+ fscache_stat_unchecked(&fscache_n_store_calls);
46031
46032 /* find a page to store */
46033 page = NULL;
46034@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46035 page = results[0];
46036 _debug("gang %d [%lx]", n, page->index);
46037 if (page->index > op->store_limit) {
46038- fscache_stat(&fscache_n_store_pages_over_limit);
46039+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46040 goto superseded;
46041 }
46042
46043@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46044 spin_unlock(&cookie->stores_lock);
46045 spin_unlock(&object->lock);
46046
46047- fscache_stat(&fscache_n_store_pages);
46048+ fscache_stat_unchecked(&fscache_n_store_pages);
46049 fscache_stat(&fscache_n_cop_write_page);
46050 ret = object->cache->ops->write_page(op, page);
46051 fscache_stat_d(&fscache_n_cop_write_page);
46052@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46053 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46054 ASSERT(PageFsCache(page));
46055
46056- fscache_stat(&fscache_n_stores);
46057+ fscache_stat_unchecked(&fscache_n_stores);
46058
46059 op = kzalloc(sizeof(*op), GFP_NOIO);
46060 if (!op)
46061@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46062 spin_unlock(&cookie->stores_lock);
46063 spin_unlock(&object->lock);
46064
46065- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46066+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46067 op->store_limit = object->store_limit;
46068
46069 if (fscache_submit_op(object, &op->op) < 0)
46070@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46071
46072 spin_unlock(&cookie->lock);
46073 radix_tree_preload_end();
46074- fscache_stat(&fscache_n_store_ops);
46075- fscache_stat(&fscache_n_stores_ok);
46076+ fscache_stat_unchecked(&fscache_n_store_ops);
46077+ fscache_stat_unchecked(&fscache_n_stores_ok);
46078
46079 /* the work queue now carries its own ref on the object */
46080 fscache_put_operation(&op->op);
46081@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46082 return 0;
46083
46084 already_queued:
46085- fscache_stat(&fscache_n_stores_again);
46086+ fscache_stat_unchecked(&fscache_n_stores_again);
46087 already_pending:
46088 spin_unlock(&cookie->stores_lock);
46089 spin_unlock(&object->lock);
46090 spin_unlock(&cookie->lock);
46091 radix_tree_preload_end();
46092 kfree(op);
46093- fscache_stat(&fscache_n_stores_ok);
46094+ fscache_stat_unchecked(&fscache_n_stores_ok);
46095 _leave(" = 0");
46096 return 0;
46097
46098@@ -851,14 +851,14 @@ nobufs:
46099 spin_unlock(&cookie->lock);
46100 radix_tree_preload_end();
46101 kfree(op);
46102- fscache_stat(&fscache_n_stores_nobufs);
46103+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
46104 _leave(" = -ENOBUFS");
46105 return -ENOBUFS;
46106
46107 nomem_free:
46108 kfree(op);
46109 nomem:
46110- fscache_stat(&fscache_n_stores_oom);
46111+ fscache_stat_unchecked(&fscache_n_stores_oom);
46112 _leave(" = -ENOMEM");
46113 return -ENOMEM;
46114 }
46115@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46116 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46117 ASSERTCMP(page, !=, NULL);
46118
46119- fscache_stat(&fscache_n_uncaches);
46120+ fscache_stat_unchecked(&fscache_n_uncaches);
46121
46122 /* cache withdrawal may beat us to it */
46123 if (!PageFsCache(page))
46124@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46125 unsigned long loop;
46126
46127 #ifdef CONFIG_FSCACHE_STATS
46128- atomic_add(pagevec->nr, &fscache_n_marks);
46129+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46130 #endif
46131
46132 for (loop = 0; loop < pagevec->nr; loop++) {
46133diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46134index 4765190..2a067f2 100644
46135--- a/fs/fscache/stats.c
46136+++ b/fs/fscache/stats.c
46137@@ -18,95 +18,95 @@
46138 /*
46139 * operation counters
46140 */
46141-atomic_t fscache_n_op_pend;
46142-atomic_t fscache_n_op_run;
46143-atomic_t fscache_n_op_enqueue;
46144-atomic_t fscache_n_op_requeue;
46145-atomic_t fscache_n_op_deferred_release;
46146-atomic_t fscache_n_op_release;
46147-atomic_t fscache_n_op_gc;
46148-atomic_t fscache_n_op_cancelled;
46149-atomic_t fscache_n_op_rejected;
46150+atomic_unchecked_t fscache_n_op_pend;
46151+atomic_unchecked_t fscache_n_op_run;
46152+atomic_unchecked_t fscache_n_op_enqueue;
46153+atomic_unchecked_t fscache_n_op_requeue;
46154+atomic_unchecked_t fscache_n_op_deferred_release;
46155+atomic_unchecked_t fscache_n_op_release;
46156+atomic_unchecked_t fscache_n_op_gc;
46157+atomic_unchecked_t fscache_n_op_cancelled;
46158+atomic_unchecked_t fscache_n_op_rejected;
46159
46160-atomic_t fscache_n_attr_changed;
46161-atomic_t fscache_n_attr_changed_ok;
46162-atomic_t fscache_n_attr_changed_nobufs;
46163-atomic_t fscache_n_attr_changed_nomem;
46164-atomic_t fscache_n_attr_changed_calls;
46165+atomic_unchecked_t fscache_n_attr_changed;
46166+atomic_unchecked_t fscache_n_attr_changed_ok;
46167+atomic_unchecked_t fscache_n_attr_changed_nobufs;
46168+atomic_unchecked_t fscache_n_attr_changed_nomem;
46169+atomic_unchecked_t fscache_n_attr_changed_calls;
46170
46171-atomic_t fscache_n_allocs;
46172-atomic_t fscache_n_allocs_ok;
46173-atomic_t fscache_n_allocs_wait;
46174-atomic_t fscache_n_allocs_nobufs;
46175-atomic_t fscache_n_allocs_intr;
46176-atomic_t fscache_n_allocs_object_dead;
46177-atomic_t fscache_n_alloc_ops;
46178-atomic_t fscache_n_alloc_op_waits;
46179+atomic_unchecked_t fscache_n_allocs;
46180+atomic_unchecked_t fscache_n_allocs_ok;
46181+atomic_unchecked_t fscache_n_allocs_wait;
46182+atomic_unchecked_t fscache_n_allocs_nobufs;
46183+atomic_unchecked_t fscache_n_allocs_intr;
46184+atomic_unchecked_t fscache_n_allocs_object_dead;
46185+atomic_unchecked_t fscache_n_alloc_ops;
46186+atomic_unchecked_t fscache_n_alloc_op_waits;
46187
46188-atomic_t fscache_n_retrievals;
46189-atomic_t fscache_n_retrievals_ok;
46190-atomic_t fscache_n_retrievals_wait;
46191-atomic_t fscache_n_retrievals_nodata;
46192-atomic_t fscache_n_retrievals_nobufs;
46193-atomic_t fscache_n_retrievals_intr;
46194-atomic_t fscache_n_retrievals_nomem;
46195-atomic_t fscache_n_retrievals_object_dead;
46196-atomic_t fscache_n_retrieval_ops;
46197-atomic_t fscache_n_retrieval_op_waits;
46198+atomic_unchecked_t fscache_n_retrievals;
46199+atomic_unchecked_t fscache_n_retrievals_ok;
46200+atomic_unchecked_t fscache_n_retrievals_wait;
46201+atomic_unchecked_t fscache_n_retrievals_nodata;
46202+atomic_unchecked_t fscache_n_retrievals_nobufs;
46203+atomic_unchecked_t fscache_n_retrievals_intr;
46204+atomic_unchecked_t fscache_n_retrievals_nomem;
46205+atomic_unchecked_t fscache_n_retrievals_object_dead;
46206+atomic_unchecked_t fscache_n_retrieval_ops;
46207+atomic_unchecked_t fscache_n_retrieval_op_waits;
46208
46209-atomic_t fscache_n_stores;
46210-atomic_t fscache_n_stores_ok;
46211-atomic_t fscache_n_stores_again;
46212-atomic_t fscache_n_stores_nobufs;
46213-atomic_t fscache_n_stores_oom;
46214-atomic_t fscache_n_store_ops;
46215-atomic_t fscache_n_store_calls;
46216-atomic_t fscache_n_store_pages;
46217-atomic_t fscache_n_store_radix_deletes;
46218-atomic_t fscache_n_store_pages_over_limit;
46219+atomic_unchecked_t fscache_n_stores;
46220+atomic_unchecked_t fscache_n_stores_ok;
46221+atomic_unchecked_t fscache_n_stores_again;
46222+atomic_unchecked_t fscache_n_stores_nobufs;
46223+atomic_unchecked_t fscache_n_stores_oom;
46224+atomic_unchecked_t fscache_n_store_ops;
46225+atomic_unchecked_t fscache_n_store_calls;
46226+atomic_unchecked_t fscache_n_store_pages;
46227+atomic_unchecked_t fscache_n_store_radix_deletes;
46228+atomic_unchecked_t fscache_n_store_pages_over_limit;
46229
46230-atomic_t fscache_n_store_vmscan_not_storing;
46231-atomic_t fscache_n_store_vmscan_gone;
46232-atomic_t fscache_n_store_vmscan_busy;
46233-atomic_t fscache_n_store_vmscan_cancelled;
46234+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46235+atomic_unchecked_t fscache_n_store_vmscan_gone;
46236+atomic_unchecked_t fscache_n_store_vmscan_busy;
46237+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46238
46239-atomic_t fscache_n_marks;
46240-atomic_t fscache_n_uncaches;
46241+atomic_unchecked_t fscache_n_marks;
46242+atomic_unchecked_t fscache_n_uncaches;
46243
46244-atomic_t fscache_n_acquires;
46245-atomic_t fscache_n_acquires_null;
46246-atomic_t fscache_n_acquires_no_cache;
46247-atomic_t fscache_n_acquires_ok;
46248-atomic_t fscache_n_acquires_nobufs;
46249-atomic_t fscache_n_acquires_oom;
46250+atomic_unchecked_t fscache_n_acquires;
46251+atomic_unchecked_t fscache_n_acquires_null;
46252+atomic_unchecked_t fscache_n_acquires_no_cache;
46253+atomic_unchecked_t fscache_n_acquires_ok;
46254+atomic_unchecked_t fscache_n_acquires_nobufs;
46255+atomic_unchecked_t fscache_n_acquires_oom;
46256
46257-atomic_t fscache_n_updates;
46258-atomic_t fscache_n_updates_null;
46259-atomic_t fscache_n_updates_run;
46260+atomic_unchecked_t fscache_n_updates;
46261+atomic_unchecked_t fscache_n_updates_null;
46262+atomic_unchecked_t fscache_n_updates_run;
46263
46264-atomic_t fscache_n_relinquishes;
46265-atomic_t fscache_n_relinquishes_null;
46266-atomic_t fscache_n_relinquishes_waitcrt;
46267-atomic_t fscache_n_relinquishes_retire;
46268+atomic_unchecked_t fscache_n_relinquishes;
46269+atomic_unchecked_t fscache_n_relinquishes_null;
46270+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46271+atomic_unchecked_t fscache_n_relinquishes_retire;
46272
46273-atomic_t fscache_n_cookie_index;
46274-atomic_t fscache_n_cookie_data;
46275-atomic_t fscache_n_cookie_special;
46276+atomic_unchecked_t fscache_n_cookie_index;
46277+atomic_unchecked_t fscache_n_cookie_data;
46278+atomic_unchecked_t fscache_n_cookie_special;
46279
46280-atomic_t fscache_n_object_alloc;
46281-atomic_t fscache_n_object_no_alloc;
46282-atomic_t fscache_n_object_lookups;
46283-atomic_t fscache_n_object_lookups_negative;
46284-atomic_t fscache_n_object_lookups_positive;
46285-atomic_t fscache_n_object_lookups_timed_out;
46286-atomic_t fscache_n_object_created;
46287-atomic_t fscache_n_object_avail;
46288-atomic_t fscache_n_object_dead;
46289+atomic_unchecked_t fscache_n_object_alloc;
46290+atomic_unchecked_t fscache_n_object_no_alloc;
46291+atomic_unchecked_t fscache_n_object_lookups;
46292+atomic_unchecked_t fscache_n_object_lookups_negative;
46293+atomic_unchecked_t fscache_n_object_lookups_positive;
46294+atomic_unchecked_t fscache_n_object_lookups_timed_out;
46295+atomic_unchecked_t fscache_n_object_created;
46296+atomic_unchecked_t fscache_n_object_avail;
46297+atomic_unchecked_t fscache_n_object_dead;
46298
46299-atomic_t fscache_n_checkaux_none;
46300-atomic_t fscache_n_checkaux_okay;
46301-atomic_t fscache_n_checkaux_update;
46302-atomic_t fscache_n_checkaux_obsolete;
46303+atomic_unchecked_t fscache_n_checkaux_none;
46304+atomic_unchecked_t fscache_n_checkaux_okay;
46305+atomic_unchecked_t fscache_n_checkaux_update;
46306+atomic_unchecked_t fscache_n_checkaux_obsolete;
46307
46308 atomic_t fscache_n_cop_alloc_object;
46309 atomic_t fscache_n_cop_lookup_object;
46310@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46311 seq_puts(m, "FS-Cache statistics\n");
46312
46313 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46314- atomic_read(&fscache_n_cookie_index),
46315- atomic_read(&fscache_n_cookie_data),
46316- atomic_read(&fscache_n_cookie_special));
46317+ atomic_read_unchecked(&fscache_n_cookie_index),
46318+ atomic_read_unchecked(&fscache_n_cookie_data),
46319+ atomic_read_unchecked(&fscache_n_cookie_special));
46320
46321 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46322- atomic_read(&fscache_n_object_alloc),
46323- atomic_read(&fscache_n_object_no_alloc),
46324- atomic_read(&fscache_n_object_avail),
46325- atomic_read(&fscache_n_object_dead));
46326+ atomic_read_unchecked(&fscache_n_object_alloc),
46327+ atomic_read_unchecked(&fscache_n_object_no_alloc),
46328+ atomic_read_unchecked(&fscache_n_object_avail),
46329+ atomic_read_unchecked(&fscache_n_object_dead));
46330 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46331- atomic_read(&fscache_n_checkaux_none),
46332- atomic_read(&fscache_n_checkaux_okay),
46333- atomic_read(&fscache_n_checkaux_update),
46334- atomic_read(&fscache_n_checkaux_obsolete));
46335+ atomic_read_unchecked(&fscache_n_checkaux_none),
46336+ atomic_read_unchecked(&fscache_n_checkaux_okay),
46337+ atomic_read_unchecked(&fscache_n_checkaux_update),
46338+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46339
46340 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46341- atomic_read(&fscache_n_marks),
46342- atomic_read(&fscache_n_uncaches));
46343+ atomic_read_unchecked(&fscache_n_marks),
46344+ atomic_read_unchecked(&fscache_n_uncaches));
46345
46346 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46347 " oom=%u\n",
46348- atomic_read(&fscache_n_acquires),
46349- atomic_read(&fscache_n_acquires_null),
46350- atomic_read(&fscache_n_acquires_no_cache),
46351- atomic_read(&fscache_n_acquires_ok),
46352- atomic_read(&fscache_n_acquires_nobufs),
46353- atomic_read(&fscache_n_acquires_oom));
46354+ atomic_read_unchecked(&fscache_n_acquires),
46355+ atomic_read_unchecked(&fscache_n_acquires_null),
46356+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
46357+ atomic_read_unchecked(&fscache_n_acquires_ok),
46358+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
46359+ atomic_read_unchecked(&fscache_n_acquires_oom));
46360
46361 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46362- atomic_read(&fscache_n_object_lookups),
46363- atomic_read(&fscache_n_object_lookups_negative),
46364- atomic_read(&fscache_n_object_lookups_positive),
46365- atomic_read(&fscache_n_object_created),
46366- atomic_read(&fscache_n_object_lookups_timed_out));
46367+ atomic_read_unchecked(&fscache_n_object_lookups),
46368+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
46369+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
46370+ atomic_read_unchecked(&fscache_n_object_created),
46371+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46372
46373 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46374- atomic_read(&fscache_n_updates),
46375- atomic_read(&fscache_n_updates_null),
46376- atomic_read(&fscache_n_updates_run));
46377+ atomic_read_unchecked(&fscache_n_updates),
46378+ atomic_read_unchecked(&fscache_n_updates_null),
46379+ atomic_read_unchecked(&fscache_n_updates_run));
46380
46381 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46382- atomic_read(&fscache_n_relinquishes),
46383- atomic_read(&fscache_n_relinquishes_null),
46384- atomic_read(&fscache_n_relinquishes_waitcrt),
46385- atomic_read(&fscache_n_relinquishes_retire));
46386+ atomic_read_unchecked(&fscache_n_relinquishes),
46387+ atomic_read_unchecked(&fscache_n_relinquishes_null),
46388+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46389+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
46390
46391 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46392- atomic_read(&fscache_n_attr_changed),
46393- atomic_read(&fscache_n_attr_changed_ok),
46394- atomic_read(&fscache_n_attr_changed_nobufs),
46395- atomic_read(&fscache_n_attr_changed_nomem),
46396- atomic_read(&fscache_n_attr_changed_calls));
46397+ atomic_read_unchecked(&fscache_n_attr_changed),
46398+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
46399+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46400+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46401+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
46402
46403 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46404- atomic_read(&fscache_n_allocs),
46405- atomic_read(&fscache_n_allocs_ok),
46406- atomic_read(&fscache_n_allocs_wait),
46407- atomic_read(&fscache_n_allocs_nobufs),
46408- atomic_read(&fscache_n_allocs_intr));
46409+ atomic_read_unchecked(&fscache_n_allocs),
46410+ atomic_read_unchecked(&fscache_n_allocs_ok),
46411+ atomic_read_unchecked(&fscache_n_allocs_wait),
46412+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
46413+ atomic_read_unchecked(&fscache_n_allocs_intr));
46414 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46415- atomic_read(&fscache_n_alloc_ops),
46416- atomic_read(&fscache_n_alloc_op_waits),
46417- atomic_read(&fscache_n_allocs_object_dead));
46418+ atomic_read_unchecked(&fscache_n_alloc_ops),
46419+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
46420+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
46421
46422 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46423 " int=%u oom=%u\n",
46424- atomic_read(&fscache_n_retrievals),
46425- atomic_read(&fscache_n_retrievals_ok),
46426- atomic_read(&fscache_n_retrievals_wait),
46427- atomic_read(&fscache_n_retrievals_nodata),
46428- atomic_read(&fscache_n_retrievals_nobufs),
46429- atomic_read(&fscache_n_retrievals_intr),
46430- atomic_read(&fscache_n_retrievals_nomem));
46431+ atomic_read_unchecked(&fscache_n_retrievals),
46432+ atomic_read_unchecked(&fscache_n_retrievals_ok),
46433+ atomic_read_unchecked(&fscache_n_retrievals_wait),
46434+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
46435+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46436+ atomic_read_unchecked(&fscache_n_retrievals_intr),
46437+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
46438 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46439- atomic_read(&fscache_n_retrieval_ops),
46440- atomic_read(&fscache_n_retrieval_op_waits),
46441- atomic_read(&fscache_n_retrievals_object_dead));
46442+ atomic_read_unchecked(&fscache_n_retrieval_ops),
46443+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46444+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46445
46446 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46447- atomic_read(&fscache_n_stores),
46448- atomic_read(&fscache_n_stores_ok),
46449- atomic_read(&fscache_n_stores_again),
46450- atomic_read(&fscache_n_stores_nobufs),
46451- atomic_read(&fscache_n_stores_oom));
46452+ atomic_read_unchecked(&fscache_n_stores),
46453+ atomic_read_unchecked(&fscache_n_stores_ok),
46454+ atomic_read_unchecked(&fscache_n_stores_again),
46455+ atomic_read_unchecked(&fscache_n_stores_nobufs),
46456+ atomic_read_unchecked(&fscache_n_stores_oom));
46457 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46458- atomic_read(&fscache_n_store_ops),
46459- atomic_read(&fscache_n_store_calls),
46460- atomic_read(&fscache_n_store_pages),
46461- atomic_read(&fscache_n_store_radix_deletes),
46462- atomic_read(&fscache_n_store_pages_over_limit));
46463+ atomic_read_unchecked(&fscache_n_store_ops),
46464+ atomic_read_unchecked(&fscache_n_store_calls),
46465+ atomic_read_unchecked(&fscache_n_store_pages),
46466+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
46467+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46468
46469 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46470- atomic_read(&fscache_n_store_vmscan_not_storing),
46471- atomic_read(&fscache_n_store_vmscan_gone),
46472- atomic_read(&fscache_n_store_vmscan_busy),
46473- atomic_read(&fscache_n_store_vmscan_cancelled));
46474+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46475+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46476+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46477+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46478
46479 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46480- atomic_read(&fscache_n_op_pend),
46481- atomic_read(&fscache_n_op_run),
46482- atomic_read(&fscache_n_op_enqueue),
46483- atomic_read(&fscache_n_op_cancelled),
46484- atomic_read(&fscache_n_op_rejected));
46485+ atomic_read_unchecked(&fscache_n_op_pend),
46486+ atomic_read_unchecked(&fscache_n_op_run),
46487+ atomic_read_unchecked(&fscache_n_op_enqueue),
46488+ atomic_read_unchecked(&fscache_n_op_cancelled),
46489+ atomic_read_unchecked(&fscache_n_op_rejected));
46490 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46491- atomic_read(&fscache_n_op_deferred_release),
46492- atomic_read(&fscache_n_op_release),
46493- atomic_read(&fscache_n_op_gc));
46494+ atomic_read_unchecked(&fscache_n_op_deferred_release),
46495+ atomic_read_unchecked(&fscache_n_op_release),
46496+ atomic_read_unchecked(&fscache_n_op_gc));
46497
46498 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46499 atomic_read(&fscache_n_cop_alloc_object),
46500diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46501index 3426521..3b75162 100644
46502--- a/fs/fuse/cuse.c
46503+++ b/fs/fuse/cuse.c
46504@@ -587,10 +587,12 @@ static int __init cuse_init(void)
46505 INIT_LIST_HEAD(&cuse_conntbl[i]);
46506
46507 /* inherit and extend fuse_dev_operations */
46508- cuse_channel_fops = fuse_dev_operations;
46509- cuse_channel_fops.owner = THIS_MODULE;
46510- cuse_channel_fops.open = cuse_channel_open;
46511- cuse_channel_fops.release = cuse_channel_release;
46512+ pax_open_kernel();
46513+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46514+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46515+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
46516+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
46517+ pax_close_kernel();
46518
46519 cuse_class = class_create(THIS_MODULE, "cuse");
46520 if (IS_ERR(cuse_class))
46521diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46522index 5f3368a..8306426 100644
46523--- a/fs/fuse/dev.c
46524+++ b/fs/fuse/dev.c
46525@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46526 ret = 0;
46527 pipe_lock(pipe);
46528
46529- if (!pipe->readers) {
46530+ if (!atomic_read(&pipe->readers)) {
46531 send_sig(SIGPIPE, current, 0);
46532 if (!ret)
46533 ret = -EPIPE;
46534diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46535index 2066328..f5add3b 100644
46536--- a/fs/fuse/dir.c
46537+++ b/fs/fuse/dir.c
46538@@ -1175,7 +1175,7 @@ static char *read_link(struct dentry *dentry)
46539 return link;
46540 }
46541
46542-static void free_link(char *link)
46543+static void free_link(const char *link)
46544 {
46545 if (!IS_ERR(link))
46546 free_page((unsigned long) link);
46547diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46548index 5698746..6086012 100644
46549--- a/fs/gfs2/inode.c
46550+++ b/fs/gfs2/inode.c
46551@@ -1487,7 +1487,7 @@ out:
46552
46553 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46554 {
46555- char *s = nd_get_link(nd);
46556+ const char *s = nd_get_link(nd);
46557 if (!IS_ERR(s))
46558 kfree(s);
46559 }
46560diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46561index c60267e..193d9e4 100644
46562--- a/fs/hugetlbfs/inode.c
46563+++ b/fs/hugetlbfs/inode.c
46564@@ -902,7 +902,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46565 .kill_sb = kill_litter_super,
46566 };
46567
46568-static struct vfsmount *hugetlbfs_vfsmount;
46569+struct vfsmount *hugetlbfs_vfsmount;
46570
46571 static int can_do_hugetlb_shm(void)
46572 {
46573diff --git a/fs/inode.c b/fs/inode.c
46574index 83ab215..8842101 100644
46575--- a/fs/inode.c
46576+++ b/fs/inode.c
46577@@ -870,8 +870,8 @@ unsigned int get_next_ino(void)
46578
46579 #ifdef CONFIG_SMP
46580 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46581- static atomic_t shared_last_ino;
46582- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46583+ static atomic_unchecked_t shared_last_ino;
46584+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46585
46586 res = next - LAST_INO_BATCH;
46587 }
46588diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46589index eafb8d3..f423d37 100644
46590--- a/fs/jffs2/erase.c
46591+++ b/fs/jffs2/erase.c
46592@@ -438,7 +438,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46593 struct jffs2_unknown_node marker = {
46594 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46595 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46596- .totlen = cpu_to_je32(c->cleanmarker_size)
46597+ .totlen = cpu_to_je32(c->cleanmarker_size),
46598+ .hdr_crc = cpu_to_je32(0)
46599 };
46600
46601 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46602diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46603index 30e8f47..21f600c 100644
46604--- a/fs/jffs2/wbuf.c
46605+++ b/fs/jffs2/wbuf.c
46606@@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46607 {
46608 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46609 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46610- .totlen = constant_cpu_to_je32(8)
46611+ .totlen = constant_cpu_to_je32(8),
46612+ .hdr_crc = constant_cpu_to_je32(0)
46613 };
46614
46615 /*
46616diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46617index 682bca6..86b8e6e 100644
46618--- a/fs/jfs/super.c
46619+++ b/fs/jfs/super.c
46620@@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46621
46622 jfs_inode_cachep =
46623 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46624- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46625+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46626 init_once);
46627 if (jfs_inode_cachep == NULL)
46628 return -ENOMEM;
46629diff --git a/fs/libfs.c b/fs/libfs.c
46630index 5b2dbb3..7442d54 100644
46631--- a/fs/libfs.c
46632+++ b/fs/libfs.c
46633@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46634
46635 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46636 struct dentry *next;
46637+ char d_name[sizeof(next->d_iname)];
46638+ const unsigned char *name;
46639+
46640 next = list_entry(p, struct dentry, d_u.d_child);
46641 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46642 if (!simple_positive(next)) {
46643@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46644
46645 spin_unlock(&next->d_lock);
46646 spin_unlock(&dentry->d_lock);
46647- if (filldir(dirent, next->d_name.name,
46648+ name = next->d_name.name;
46649+ if (name == next->d_iname) {
46650+ memcpy(d_name, name, next->d_name.len);
46651+ name = d_name;
46652+ }
46653+ if (filldir(dirent, name,
46654 next->d_name.len, filp->f_pos,
46655 next->d_inode->i_ino,
46656 dt_type(next->d_inode)) < 0)
46657diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46658index 8392cb8..80d6193 100644
46659--- a/fs/lockd/clntproc.c
46660+++ b/fs/lockd/clntproc.c
46661@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46662 /*
46663 * Cookie counter for NLM requests
46664 */
46665-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46666+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46667
46668 void nlmclnt_next_cookie(struct nlm_cookie *c)
46669 {
46670- u32 cookie = atomic_inc_return(&nlm_cookie);
46671+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46672
46673 memcpy(c->data, &cookie, 4);
46674 c->len=4;
46675diff --git a/fs/locks.c b/fs/locks.c
46676index 0d68f1f..f216b79 100644
46677--- a/fs/locks.c
46678+++ b/fs/locks.c
46679@@ -2075,16 +2075,16 @@ void locks_remove_flock(struct file *filp)
46680 return;
46681
46682 if (filp->f_op && filp->f_op->flock) {
46683- struct file_lock fl = {
46684+ struct file_lock flock = {
46685 .fl_pid = current->tgid,
46686 .fl_file = filp,
46687 .fl_flags = FL_FLOCK,
46688 .fl_type = F_UNLCK,
46689 .fl_end = OFFSET_MAX,
46690 };
46691- filp->f_op->flock(filp, F_SETLKW, &fl);
46692- if (fl.fl_ops && fl.fl_ops->fl_release_private)
46693- fl.fl_ops->fl_release_private(&fl);
46694+ filp->f_op->flock(filp, F_SETLKW, &flock);
46695+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
46696+ flock.fl_ops->fl_release_private(&flock);
46697 }
46698
46699 lock_flocks();
46700diff --git a/fs/namei.c b/fs/namei.c
46701index 46ea9cc..c7cf3a3 100644
46702--- a/fs/namei.c
46703+++ b/fs/namei.c
46704@@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
46705 if (ret != -EACCES)
46706 return ret;
46707
46708+#ifdef CONFIG_GRKERNSEC
46709+ /* we'll block if we have to log due to a denied capability use */
46710+ if (mask & MAY_NOT_BLOCK)
46711+ return -ECHILD;
46712+#endif
46713+
46714 if (S_ISDIR(inode->i_mode)) {
46715 /* DACs are overridable for directories */
46716- if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46717- return 0;
46718 if (!(mask & MAY_WRITE))
46719- if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46720+ if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46721+ ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46722 return 0;
46723+ if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46724+ return 0;
46725 return -EACCES;
46726 }
46727 /*
46728+ * Searching includes executable on directories, else just read.
46729+ */
46730+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46731+ if (mask == MAY_READ)
46732+ if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46733+ ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46734+ return 0;
46735+
46736+ /*
46737 * Read/write DACs are always overridable.
46738 * Executable DACs are overridable when there is
46739 * at least one exec bit set.
46740@@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
46741 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46742 return 0;
46743
46744- /*
46745- * Searching includes executable on directories, else just read.
46746- */
46747- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46748- if (mask == MAY_READ)
46749- if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46750- return 0;
46751-
46752 return -EACCES;
46753 }
46754
46755@@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
46756 return error;
46757 }
46758
46759+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
46760+ dentry->d_inode, dentry, nd->path.mnt)) {
46761+ error = -EACCES;
46762+ *p = ERR_PTR(error); /* no ->put_link(), please */
46763+ path_put(&nd->path);
46764+ return error;
46765+ }
46766+
46767 nd->last_type = LAST_BIND;
46768 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
46769 error = PTR_ERR(*p);
46770 if (!IS_ERR(*p)) {
46771- char *s = nd_get_link(nd);
46772+ const char *s = nd_get_link(nd);
46773 error = 0;
46774 if (s)
46775 error = __vfs_follow_link(nd, s);
46776@@ -1650,6 +1666,21 @@ static int path_lookupat(int dfd, const char *name,
46777 if (!err)
46778 err = complete_walk(nd);
46779
46780+ if (!(nd->flags & LOOKUP_PARENT)) {
46781+#ifdef CONFIG_GRKERNSEC
46782+ if (flags & LOOKUP_RCU) {
46783+ if (!err)
46784+ path_put(&nd->path);
46785+ err = -ECHILD;
46786+ } else
46787+#endif
46788+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46789+ if (!err)
46790+ path_put(&nd->path);
46791+ err = -ENOENT;
46792+ }
46793+ }
46794+
46795 if (!err && nd->flags & LOOKUP_DIRECTORY) {
46796 if (!nd->inode->i_op->lookup) {
46797 path_put(&nd->path);
46798@@ -1677,6 +1708,15 @@ static int do_path_lookup(int dfd, const char *name,
46799 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
46800
46801 if (likely(!retval)) {
46802+ if (*name != '/' && nd->path.dentry && nd->inode) {
46803+#ifdef CONFIG_GRKERNSEC
46804+ if (flags & LOOKUP_RCU)
46805+ return -ECHILD;
46806+#endif
46807+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
46808+ return -ENOENT;
46809+ }
46810+
46811 if (unlikely(!audit_dummy_context())) {
46812 if (nd->path.dentry && nd->inode)
46813 audit_inode(name, nd->path.dentry);
46814@@ -2071,6 +2111,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
46815 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
46816 return -EPERM;
46817
46818+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
46819+ return -EPERM;
46820+ if (gr_handle_rawio(inode))
46821+ return -EPERM;
46822+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
46823+ return -EACCES;
46824+
46825 return 0;
46826 }
46827
46828@@ -2132,6 +2179,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46829 error = complete_walk(nd);
46830 if (error)
46831 return ERR_PTR(error);
46832+#ifdef CONFIG_GRKERNSEC
46833+ if (nd->flags & LOOKUP_RCU) {
46834+ error = -ECHILD;
46835+ goto exit;
46836+ }
46837+#endif
46838+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46839+ error = -ENOENT;
46840+ goto exit;
46841+ }
46842 audit_inode(pathname, nd->path.dentry);
46843 if (open_flag & O_CREAT) {
46844 error = -EISDIR;
46845@@ -2142,6 +2199,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46846 error = complete_walk(nd);
46847 if (error)
46848 return ERR_PTR(error);
46849+#ifdef CONFIG_GRKERNSEC
46850+ if (nd->flags & LOOKUP_RCU) {
46851+ error = -ECHILD;
46852+ goto exit;
46853+ }
46854+#endif
46855+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
46856+ error = -ENOENT;
46857+ goto exit;
46858+ }
46859 audit_inode(pathname, dir);
46860 goto ok;
46861 }
46862@@ -2163,6 +2230,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46863 error = complete_walk(nd);
46864 if (error)
46865 return ERR_PTR(error);
46866+#ifdef CONFIG_GRKERNSEC
46867+ if (nd->flags & LOOKUP_RCU) {
46868+ error = -ECHILD;
46869+ goto exit;
46870+ }
46871+#endif
46872+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46873+ error = -ENOENT;
46874+ goto exit;
46875+ }
46876
46877 error = -ENOTDIR;
46878 if (nd->flags & LOOKUP_DIRECTORY) {
46879@@ -2203,6 +2280,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46880 /* Negative dentry, just create the file */
46881 if (!dentry->d_inode) {
46882 umode_t mode = op->mode;
46883+
46884+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
46885+ error = -EACCES;
46886+ goto exit_mutex_unlock;
46887+ }
46888+
46889 if (!IS_POSIXACL(dir->d_inode))
46890 mode &= ~current_umask();
46891 /*
46892@@ -2226,6 +2309,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46893 error = vfs_create(dir->d_inode, dentry, mode, nd);
46894 if (error)
46895 goto exit_mutex_unlock;
46896+ else
46897+ gr_handle_create(path->dentry, path->mnt);
46898 mutex_unlock(&dir->d_inode->i_mutex);
46899 dput(nd->path.dentry);
46900 nd->path.dentry = dentry;
46901@@ -2235,6 +2320,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46902 /*
46903 * It already exists.
46904 */
46905+
46906+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
46907+ error = -ENOENT;
46908+ goto exit_mutex_unlock;
46909+ }
46910+
46911+ /* only check if O_CREAT is specified, all other checks need to go
46912+ into may_open */
46913+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
46914+ error = -EACCES;
46915+ goto exit_mutex_unlock;
46916+ }
46917+
46918 mutex_unlock(&dir->d_inode->i_mutex);
46919 audit_inode(pathname, path->dentry);
46920
46921@@ -2447,6 +2545,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
46922 *path = nd.path;
46923 return dentry;
46924 eexist:
46925+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
46926+ dput(dentry);
46927+ dentry = ERR_PTR(-ENOENT);
46928+ goto fail;
46929+ }
46930 dput(dentry);
46931 dentry = ERR_PTR(-EEXIST);
46932 fail:
46933@@ -2469,6 +2572,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
46934 }
46935 EXPORT_SYMBOL(user_path_create);
46936
46937+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
46938+{
46939+ char *tmp = getname(pathname);
46940+ struct dentry *res;
46941+ if (IS_ERR(tmp))
46942+ return ERR_CAST(tmp);
46943+ res = kern_path_create(dfd, tmp, path, is_dir);
46944+ if (IS_ERR(res))
46945+ putname(tmp);
46946+ else
46947+ *to = tmp;
46948+ return res;
46949+}
46950+
46951 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
46952 {
46953 int error = may_create(dir, dentry);
46954@@ -2536,6 +2653,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46955 error = mnt_want_write(path.mnt);
46956 if (error)
46957 goto out_dput;
46958+
46959+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
46960+ error = -EPERM;
46961+ goto out_drop_write;
46962+ }
46963+
46964+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
46965+ error = -EACCES;
46966+ goto out_drop_write;
46967+ }
46968+
46969 error = security_path_mknod(&path, dentry, mode, dev);
46970 if (error)
46971 goto out_drop_write;
46972@@ -2553,6 +2681,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46973 }
46974 out_drop_write:
46975 mnt_drop_write(path.mnt);
46976+
46977+ if (!error)
46978+ gr_handle_create(dentry, path.mnt);
46979 out_dput:
46980 dput(dentry);
46981 mutex_unlock(&path.dentry->d_inode->i_mutex);
46982@@ -2602,12 +2733,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
46983 error = mnt_want_write(path.mnt);
46984 if (error)
46985 goto out_dput;
46986+
46987+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
46988+ error = -EACCES;
46989+ goto out_drop_write;
46990+ }
46991+
46992 error = security_path_mkdir(&path, dentry, mode);
46993 if (error)
46994 goto out_drop_write;
46995 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
46996 out_drop_write:
46997 mnt_drop_write(path.mnt);
46998+
46999+ if (!error)
47000+ gr_handle_create(dentry, path.mnt);
47001 out_dput:
47002 dput(dentry);
47003 mutex_unlock(&path.dentry->d_inode->i_mutex);
47004@@ -2687,6 +2827,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47005 char * name;
47006 struct dentry *dentry;
47007 struct nameidata nd;
47008+ ino_t saved_ino = 0;
47009+ dev_t saved_dev = 0;
47010
47011 error = user_path_parent(dfd, pathname, &nd, &name);
47012 if (error)
47013@@ -2715,6 +2857,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47014 error = -ENOENT;
47015 goto exit3;
47016 }
47017+
47018+ saved_ino = dentry->d_inode->i_ino;
47019+ saved_dev = gr_get_dev_from_dentry(dentry);
47020+
47021+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47022+ error = -EACCES;
47023+ goto exit3;
47024+ }
47025+
47026 error = mnt_want_write(nd.path.mnt);
47027 if (error)
47028 goto exit3;
47029@@ -2722,6 +2873,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47030 if (error)
47031 goto exit4;
47032 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47033+ if (!error && (saved_dev || saved_ino))
47034+ gr_handle_delete(saved_ino, saved_dev);
47035 exit4:
47036 mnt_drop_write(nd.path.mnt);
47037 exit3:
47038@@ -2784,6 +2937,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47039 struct dentry *dentry;
47040 struct nameidata nd;
47041 struct inode *inode = NULL;
47042+ ino_t saved_ino = 0;
47043+ dev_t saved_dev = 0;
47044
47045 error = user_path_parent(dfd, pathname, &nd, &name);
47046 if (error)
47047@@ -2806,6 +2961,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47048 if (!inode)
47049 goto slashes;
47050 ihold(inode);
47051+
47052+ if (inode->i_nlink <= 1) {
47053+ saved_ino = inode->i_ino;
47054+ saved_dev = gr_get_dev_from_dentry(dentry);
47055+ }
47056+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47057+ error = -EACCES;
47058+ goto exit2;
47059+ }
47060+
47061 error = mnt_want_write(nd.path.mnt);
47062 if (error)
47063 goto exit2;
47064@@ -2813,6 +2978,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47065 if (error)
47066 goto exit3;
47067 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47068+ if (!error && (saved_ino || saved_dev))
47069+ gr_handle_delete(saved_ino, saved_dev);
47070 exit3:
47071 mnt_drop_write(nd.path.mnt);
47072 exit2:
47073@@ -2888,10 +3055,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47074 error = mnt_want_write(path.mnt);
47075 if (error)
47076 goto out_dput;
47077+
47078+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47079+ error = -EACCES;
47080+ goto out_drop_write;
47081+ }
47082+
47083 error = security_path_symlink(&path, dentry, from);
47084 if (error)
47085 goto out_drop_write;
47086 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47087+ if (!error)
47088+ gr_handle_create(dentry, path.mnt);
47089 out_drop_write:
47090 mnt_drop_write(path.mnt);
47091 out_dput:
47092@@ -2963,6 +3138,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47093 {
47094 struct dentry *new_dentry;
47095 struct path old_path, new_path;
47096+ char *to = NULL;
47097 int how = 0;
47098 int error;
47099
47100@@ -2986,7 +3162,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47101 if (error)
47102 return error;
47103
47104- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47105+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47106 error = PTR_ERR(new_dentry);
47107 if (IS_ERR(new_dentry))
47108 goto out;
47109@@ -2997,13 +3173,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47110 error = mnt_want_write(new_path.mnt);
47111 if (error)
47112 goto out_dput;
47113+
47114+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47115+ old_path.dentry->d_inode,
47116+ old_path.dentry->d_inode->i_mode, to)) {
47117+ error = -EACCES;
47118+ goto out_drop_write;
47119+ }
47120+
47121+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47122+ old_path.dentry, old_path.mnt, to)) {
47123+ error = -EACCES;
47124+ goto out_drop_write;
47125+ }
47126+
47127 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47128 if (error)
47129 goto out_drop_write;
47130 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47131+ if (!error)
47132+ gr_handle_create(new_dentry, new_path.mnt);
47133 out_drop_write:
47134 mnt_drop_write(new_path.mnt);
47135 out_dput:
47136+ putname(to);
47137 dput(new_dentry);
47138 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47139 path_put(&new_path);
47140@@ -3231,6 +3424,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47141 if (new_dentry == trap)
47142 goto exit5;
47143
47144+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47145+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
47146+ to);
47147+ if (error)
47148+ goto exit5;
47149+
47150 error = mnt_want_write(oldnd.path.mnt);
47151 if (error)
47152 goto exit5;
47153@@ -3240,6 +3439,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47154 goto exit6;
47155 error = vfs_rename(old_dir->d_inode, old_dentry,
47156 new_dir->d_inode, new_dentry);
47157+ if (!error)
47158+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47159+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47160 exit6:
47161 mnt_drop_write(oldnd.path.mnt);
47162 exit5:
47163@@ -3265,6 +3467,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47164
47165 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47166 {
47167+ char tmpbuf[64];
47168+ const char *newlink;
47169 int len;
47170
47171 len = PTR_ERR(link);
47172@@ -3274,7 +3478,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47173 len = strlen(link);
47174 if (len > (unsigned) buflen)
47175 len = buflen;
47176- if (copy_to_user(buffer, link, len))
47177+
47178+ if (len < sizeof(tmpbuf)) {
47179+ memcpy(tmpbuf, link, len);
47180+ newlink = tmpbuf;
47181+ } else
47182+ newlink = link;
47183+
47184+ if (copy_to_user(buffer, newlink, len))
47185 len = -EFAULT;
47186 out:
47187 return len;
47188diff --git a/fs/namespace.c b/fs/namespace.c
47189index e608199..9609cb9 100644
47190--- a/fs/namespace.c
47191+++ b/fs/namespace.c
47192@@ -1155,6 +1155,9 @@ static int do_umount(struct mount *mnt, int flags)
47193 if (!(sb->s_flags & MS_RDONLY))
47194 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47195 up_write(&sb->s_umount);
47196+
47197+ gr_log_remount(mnt->mnt_devname, retval);
47198+
47199 return retval;
47200 }
47201
47202@@ -1174,6 +1177,9 @@ static int do_umount(struct mount *mnt, int flags)
47203 br_write_unlock(vfsmount_lock);
47204 up_write(&namespace_sem);
47205 release_mounts(&umount_list);
47206+
47207+ gr_log_unmount(mnt->mnt_devname, retval);
47208+
47209 return retval;
47210 }
47211
47212@@ -2175,6 +2181,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47213 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47214 MS_STRICTATIME);
47215
47216+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47217+ retval = -EPERM;
47218+ goto dput_out;
47219+ }
47220+
47221+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47222+ retval = -EPERM;
47223+ goto dput_out;
47224+ }
47225+
47226 if (flags & MS_REMOUNT)
47227 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47228 data_page);
47229@@ -2189,6 +2205,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47230 dev_name, data_page);
47231 dput_out:
47232 path_put(&path);
47233+
47234+ gr_log_mount(dev_name, dir_name, retval);
47235+
47236 return retval;
47237 }
47238
47239@@ -2470,6 +2489,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47240 if (error)
47241 goto out2;
47242
47243+ if (gr_handle_chroot_pivot()) {
47244+ error = -EPERM;
47245+ goto out2;
47246+ }
47247+
47248 get_fs_root(current->fs, &root);
47249 error = lock_mount(&old);
47250 if (error)
47251diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47252index f649fba..236bf92 100644
47253--- a/fs/nfs/inode.c
47254+++ b/fs/nfs/inode.c
47255@@ -151,7 +151,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47256 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47257 nfsi->attrtimeo_timestamp = jiffies;
47258
47259- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47260+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47261 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47262 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47263 else
47264@@ -1003,16 +1003,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47265 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47266 }
47267
47268-static atomic_long_t nfs_attr_generation_counter;
47269+static atomic_long_unchecked_t nfs_attr_generation_counter;
47270
47271 static unsigned long nfs_read_attr_generation_counter(void)
47272 {
47273- return atomic_long_read(&nfs_attr_generation_counter);
47274+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47275 }
47276
47277 unsigned long nfs_inc_attr_generation_counter(void)
47278 {
47279- return atomic_long_inc_return(&nfs_attr_generation_counter);
47280+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47281 }
47282
47283 void nfs_fattr_init(struct nfs_fattr *fattr)
47284diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47285index b96fe94..a4dbece 100644
47286--- a/fs/nfsd/vfs.c
47287+++ b/fs/nfsd/vfs.c
47288@@ -925,7 +925,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47289 } else {
47290 oldfs = get_fs();
47291 set_fs(KERNEL_DS);
47292- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47293+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47294 set_fs(oldfs);
47295 }
47296
47297@@ -1029,7 +1029,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47298
47299 /* Write the data. */
47300 oldfs = get_fs(); set_fs(KERNEL_DS);
47301- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47302+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47303 set_fs(oldfs);
47304 if (host_err < 0)
47305 goto out_nfserr;
47306@@ -1564,7 +1564,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47307 */
47308
47309 oldfs = get_fs(); set_fs(KERNEL_DS);
47310- host_err = inode->i_op->readlink(dentry, buf, *lenp);
47311+ host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
47312 set_fs(oldfs);
47313
47314 if (host_err < 0)
47315diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47316index 3568c8a..e0240d8 100644
47317--- a/fs/notify/fanotify/fanotify_user.c
47318+++ b/fs/notify/fanotify/fanotify_user.c
47319@@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47320 goto out_close_fd;
47321
47322 ret = -EFAULT;
47323- if (copy_to_user(buf, &fanotify_event_metadata,
47324+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47325+ copy_to_user(buf, &fanotify_event_metadata,
47326 fanotify_event_metadata.event_len))
47327 goto out_kill_access_response;
47328
47329diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47330index ee18815..7aa5d01 100644
47331--- a/fs/notify/notification.c
47332+++ b/fs/notify/notification.c
47333@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47334 * get set to 0 so it will never get 'freed'
47335 */
47336 static struct fsnotify_event *q_overflow_event;
47337-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47338+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47339
47340 /**
47341 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47342@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47343 */
47344 u32 fsnotify_get_cookie(void)
47345 {
47346- return atomic_inc_return(&fsnotify_sync_cookie);
47347+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47348 }
47349 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47350
47351diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47352index 99e3610..02c1068 100644
47353--- a/fs/ntfs/dir.c
47354+++ b/fs/ntfs/dir.c
47355@@ -1329,7 +1329,7 @@ find_next_index_buffer:
47356 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47357 ~(s64)(ndir->itype.index.block_size - 1)));
47358 /* Bounds checks. */
47359- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47360+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47361 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47362 "inode 0x%lx or driver bug.", vdir->i_ino);
47363 goto err_out;
47364diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47365index c587e2d..3641eaa 100644
47366--- a/fs/ntfs/file.c
47367+++ b/fs/ntfs/file.c
47368@@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47369 #endif /* NTFS_RW */
47370 };
47371
47372-const struct file_operations ntfs_empty_file_ops = {};
47373+const struct file_operations ntfs_empty_file_ops __read_only;
47374
47375-const struct inode_operations ntfs_empty_inode_ops = {};
47376+const struct inode_operations ntfs_empty_inode_ops __read_only;
47377diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47378index 210c352..a174f83 100644
47379--- a/fs/ocfs2/localalloc.c
47380+++ b/fs/ocfs2/localalloc.c
47381@@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47382 goto bail;
47383 }
47384
47385- atomic_inc(&osb->alloc_stats.moves);
47386+ atomic_inc_unchecked(&osb->alloc_stats.moves);
47387
47388 bail:
47389 if (handle)
47390diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47391index d355e6e..578d905 100644
47392--- a/fs/ocfs2/ocfs2.h
47393+++ b/fs/ocfs2/ocfs2.h
47394@@ -235,11 +235,11 @@ enum ocfs2_vol_state
47395
47396 struct ocfs2_alloc_stats
47397 {
47398- atomic_t moves;
47399- atomic_t local_data;
47400- atomic_t bitmap_data;
47401- atomic_t bg_allocs;
47402- atomic_t bg_extends;
47403+ atomic_unchecked_t moves;
47404+ atomic_unchecked_t local_data;
47405+ atomic_unchecked_t bitmap_data;
47406+ atomic_unchecked_t bg_allocs;
47407+ atomic_unchecked_t bg_extends;
47408 };
47409
47410 enum ocfs2_local_alloc_state
47411diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47412index f169da4..9112253 100644
47413--- a/fs/ocfs2/suballoc.c
47414+++ b/fs/ocfs2/suballoc.c
47415@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47416 mlog_errno(status);
47417 goto bail;
47418 }
47419- atomic_inc(&osb->alloc_stats.bg_extends);
47420+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47421
47422 /* You should never ask for this much metadata */
47423 BUG_ON(bits_wanted >
47424@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47425 mlog_errno(status);
47426 goto bail;
47427 }
47428- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47429+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47430
47431 *suballoc_loc = res.sr_bg_blkno;
47432 *suballoc_bit_start = res.sr_bit_offset;
47433@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47434 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47435 res->sr_bits);
47436
47437- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47438+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47439
47440 BUG_ON(res->sr_bits != 1);
47441
47442@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47443 mlog_errno(status);
47444 goto bail;
47445 }
47446- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47447+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47448
47449 BUG_ON(res.sr_bits != 1);
47450
47451@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47452 cluster_start,
47453 num_clusters);
47454 if (!status)
47455- atomic_inc(&osb->alloc_stats.local_data);
47456+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
47457 } else {
47458 if (min_clusters > (osb->bitmap_cpg - 1)) {
47459 /* The only paths asking for contiguousness
47460@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47461 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47462 res.sr_bg_blkno,
47463 res.sr_bit_offset);
47464- atomic_inc(&osb->alloc_stats.bitmap_data);
47465+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47466 *num_clusters = res.sr_bits;
47467 }
47468 }
47469diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47470index 604e12c..8426483 100644
47471--- a/fs/ocfs2/super.c
47472+++ b/fs/ocfs2/super.c
47473@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47474 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47475 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47476 "Stats",
47477- atomic_read(&osb->alloc_stats.bitmap_data),
47478- atomic_read(&osb->alloc_stats.local_data),
47479- atomic_read(&osb->alloc_stats.bg_allocs),
47480- atomic_read(&osb->alloc_stats.moves),
47481- atomic_read(&osb->alloc_stats.bg_extends));
47482+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47483+ atomic_read_unchecked(&osb->alloc_stats.local_data),
47484+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47485+ atomic_read_unchecked(&osb->alloc_stats.moves),
47486+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47487
47488 out += snprintf(buf + out, len - out,
47489 "%10s => State: %u Descriptor: %llu Size: %u bits "
47490@@ -2117,11 +2117,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47491 spin_lock_init(&osb->osb_xattr_lock);
47492 ocfs2_init_steal_slots(osb);
47493
47494- atomic_set(&osb->alloc_stats.moves, 0);
47495- atomic_set(&osb->alloc_stats.local_data, 0);
47496- atomic_set(&osb->alloc_stats.bitmap_data, 0);
47497- atomic_set(&osb->alloc_stats.bg_allocs, 0);
47498- atomic_set(&osb->alloc_stats.bg_extends, 0);
47499+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47500+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47501+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47502+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47503+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47504
47505 /* Copy the blockcheck stats from the superblock probe */
47506 osb->osb_ecc_stats = *stats;
47507diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47508index 5d22872..523db20 100644
47509--- a/fs/ocfs2/symlink.c
47510+++ b/fs/ocfs2/symlink.c
47511@@ -142,7 +142,7 @@ bail:
47512
47513 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47514 {
47515- char *link = nd_get_link(nd);
47516+ const char *link = nd_get_link(nd);
47517 if (!IS_ERR(link))
47518 kfree(link);
47519 }
47520diff --git a/fs/open.c b/fs/open.c
47521index 77becc0..aad7bd9 100644
47522--- a/fs/open.c
47523+++ b/fs/open.c
47524@@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47525 error = locks_verify_truncate(inode, NULL, length);
47526 if (!error)
47527 error = security_path_truncate(&path);
47528+
47529+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47530+ error = -EACCES;
47531+
47532 if (!error)
47533 error = do_truncate(path.dentry, length, 0, NULL);
47534
47535@@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47536 if (__mnt_is_readonly(path.mnt))
47537 res = -EROFS;
47538
47539+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47540+ res = -EACCES;
47541+
47542 out_path_release:
47543 path_put(&path);
47544 out:
47545@@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47546 if (error)
47547 goto dput_and_out;
47548
47549+ gr_log_chdir(path.dentry, path.mnt);
47550+
47551 set_fs_pwd(current->fs, &path);
47552
47553 dput_and_out:
47554@@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47555 goto out_putf;
47556
47557 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47558+
47559+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47560+ error = -EPERM;
47561+
47562+ if (!error)
47563+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47564+
47565 if (!error)
47566 set_fs_pwd(current->fs, &file->f_path);
47567 out_putf:
47568@@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47569 if (error)
47570 goto dput_and_out;
47571
47572+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47573+ goto dput_and_out;
47574+
47575 set_fs_root(current->fs, &path);
47576+
47577+ gr_handle_chroot_chdir(&path);
47578+
47579 error = 0;
47580 dput_and_out:
47581 path_put(&path);
47582@@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
47583 if (error)
47584 return error;
47585 mutex_lock(&inode->i_mutex);
47586+
47587+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47588+ error = -EACCES;
47589+ goto out_unlock;
47590+ }
47591+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47592+ error = -EACCES;
47593+ goto out_unlock;
47594+ }
47595+
47596 error = security_path_chmod(path, mode);
47597 if (error)
47598 goto out_unlock;
47599@@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47600 int error;
47601 struct iattr newattrs;
47602
47603+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
47604+ return -EACCES;
47605+
47606 newattrs.ia_valid = ATTR_CTIME;
47607 if (user != (uid_t) -1) {
47608 newattrs.ia_valid |= ATTR_UID;
47609diff --git a/fs/pipe.c b/fs/pipe.c
47610index 82e651b..8a68573 100644
47611--- a/fs/pipe.c
47612+++ b/fs/pipe.c
47613@@ -437,9 +437,9 @@ redo:
47614 }
47615 if (bufs) /* More to do? */
47616 continue;
47617- if (!pipe->writers)
47618+ if (!atomic_read(&pipe->writers))
47619 break;
47620- if (!pipe->waiting_writers) {
47621+ if (!atomic_read(&pipe->waiting_writers)) {
47622 /* syscall merging: Usually we must not sleep
47623 * if O_NONBLOCK is set, or if we got some data.
47624 * But if a writer sleeps in kernel space, then
47625@@ -503,7 +503,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47626 mutex_lock(&inode->i_mutex);
47627 pipe = inode->i_pipe;
47628
47629- if (!pipe->readers) {
47630+ if (!atomic_read(&pipe->readers)) {
47631 send_sig(SIGPIPE, current, 0);
47632 ret = -EPIPE;
47633 goto out;
47634@@ -552,7 +552,7 @@ redo1:
47635 for (;;) {
47636 int bufs;
47637
47638- if (!pipe->readers) {
47639+ if (!atomic_read(&pipe->readers)) {
47640 send_sig(SIGPIPE, current, 0);
47641 if (!ret)
47642 ret = -EPIPE;
47643@@ -643,9 +643,9 @@ redo2:
47644 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47645 do_wakeup = 0;
47646 }
47647- pipe->waiting_writers++;
47648+ atomic_inc(&pipe->waiting_writers);
47649 pipe_wait(pipe);
47650- pipe->waiting_writers--;
47651+ atomic_dec(&pipe->waiting_writers);
47652 }
47653 out:
47654 mutex_unlock(&inode->i_mutex);
47655@@ -712,7 +712,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47656 mask = 0;
47657 if (filp->f_mode & FMODE_READ) {
47658 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47659- if (!pipe->writers && filp->f_version != pipe->w_counter)
47660+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47661 mask |= POLLHUP;
47662 }
47663
47664@@ -722,7 +722,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47665 * Most Unices do not set POLLERR for FIFOs but on Linux they
47666 * behave exactly like pipes for poll().
47667 */
47668- if (!pipe->readers)
47669+ if (!atomic_read(&pipe->readers))
47670 mask |= POLLERR;
47671 }
47672
47673@@ -736,10 +736,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47674
47675 mutex_lock(&inode->i_mutex);
47676 pipe = inode->i_pipe;
47677- pipe->readers -= decr;
47678- pipe->writers -= decw;
47679+ atomic_sub(decr, &pipe->readers);
47680+ atomic_sub(decw, &pipe->writers);
47681
47682- if (!pipe->readers && !pipe->writers) {
47683+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47684 free_pipe_info(inode);
47685 } else {
47686 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47687@@ -829,7 +829,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47688
47689 if (inode->i_pipe) {
47690 ret = 0;
47691- inode->i_pipe->readers++;
47692+ atomic_inc(&inode->i_pipe->readers);
47693 }
47694
47695 mutex_unlock(&inode->i_mutex);
47696@@ -846,7 +846,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
47697
47698 if (inode->i_pipe) {
47699 ret = 0;
47700- inode->i_pipe->writers++;
47701+ atomic_inc(&inode->i_pipe->writers);
47702 }
47703
47704 mutex_unlock(&inode->i_mutex);
47705@@ -864,9 +864,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
47706 if (inode->i_pipe) {
47707 ret = 0;
47708 if (filp->f_mode & FMODE_READ)
47709- inode->i_pipe->readers++;
47710+ atomic_inc(&inode->i_pipe->readers);
47711 if (filp->f_mode & FMODE_WRITE)
47712- inode->i_pipe->writers++;
47713+ atomic_inc(&inode->i_pipe->writers);
47714 }
47715
47716 mutex_unlock(&inode->i_mutex);
47717@@ -958,7 +958,7 @@ void free_pipe_info(struct inode *inode)
47718 inode->i_pipe = NULL;
47719 }
47720
47721-static struct vfsmount *pipe_mnt __read_mostly;
47722+struct vfsmount *pipe_mnt __read_mostly;
47723
47724 /*
47725 * pipefs_dname() is called from d_path().
47726@@ -988,7 +988,8 @@ static struct inode * get_pipe_inode(void)
47727 goto fail_iput;
47728 inode->i_pipe = pipe;
47729
47730- pipe->readers = pipe->writers = 1;
47731+ atomic_set(&pipe->readers, 1);
47732+ atomic_set(&pipe->writers, 1);
47733 inode->i_fop = &rdwr_pipefifo_fops;
47734
47735 /*
47736diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
47737index 15af622..0e9f4467 100644
47738--- a/fs/proc/Kconfig
47739+++ b/fs/proc/Kconfig
47740@@ -30,12 +30,12 @@ config PROC_FS
47741
47742 config PROC_KCORE
47743 bool "/proc/kcore support" if !ARM
47744- depends on PROC_FS && MMU
47745+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
47746
47747 config PROC_VMCORE
47748 bool "/proc/vmcore support"
47749- depends on PROC_FS && CRASH_DUMP
47750- default y
47751+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
47752+ default n
47753 help
47754 Exports the dump image of crashed kernel in ELF format.
47755
47756@@ -59,8 +59,8 @@ config PROC_SYSCTL
47757 limited in memory.
47758
47759 config PROC_PAGE_MONITOR
47760- default y
47761- depends on PROC_FS && MMU
47762+ default n
47763+ depends on PROC_FS && MMU && !GRKERNSEC
47764 bool "Enable /proc page monitoring" if EXPERT
47765 help
47766 Various /proc files exist to monitor process memory utilization:
47767diff --git a/fs/proc/array.c b/fs/proc/array.c
47768index c602b8d..a7de642 100644
47769--- a/fs/proc/array.c
47770+++ b/fs/proc/array.c
47771@@ -60,6 +60,7 @@
47772 #include <linux/tty.h>
47773 #include <linux/string.h>
47774 #include <linux/mman.h>
47775+#include <linux/grsecurity.h>
47776 #include <linux/proc_fs.h>
47777 #include <linux/ioport.h>
47778 #include <linux/uaccess.h>
47779@@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
47780 seq_putc(m, '\n');
47781 }
47782
47783+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47784+static inline void task_pax(struct seq_file *m, struct task_struct *p)
47785+{
47786+ if (p->mm)
47787+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
47788+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
47789+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
47790+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
47791+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
47792+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
47793+ else
47794+ seq_printf(m, "PaX:\t-----\n");
47795+}
47796+#endif
47797+
47798 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47799 struct pid *pid, struct task_struct *task)
47800 {
47801@@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47802 task_cpus_allowed(m, task);
47803 cpuset_task_status_allowed(m, task);
47804 task_context_switch_counts(m, task);
47805+
47806+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47807+ task_pax(m, task);
47808+#endif
47809+
47810+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
47811+ task_grsec_rbac(m, task);
47812+#endif
47813+
47814 return 0;
47815 }
47816
47817+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47818+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47819+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
47820+ _mm->pax_flags & MF_PAX_SEGMEXEC))
47821+#endif
47822+
47823 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47824 struct pid *pid, struct task_struct *task, int whole)
47825 {
47826@@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47827 char tcomm[sizeof(task->comm)];
47828 unsigned long flags;
47829
47830+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47831+ if (current->exec_id != m->exec_id) {
47832+ gr_log_badprocpid("stat");
47833+ return 0;
47834+ }
47835+#endif
47836+
47837 state = *get_task_state(task);
47838 vsize = eip = esp = 0;
47839 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47840@@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47841 gtime = task->gtime;
47842 }
47843
47844+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47845+ if (PAX_RAND_FLAGS(mm)) {
47846+ eip = 0;
47847+ esp = 0;
47848+ wchan = 0;
47849+ }
47850+#endif
47851+#ifdef CONFIG_GRKERNSEC_HIDESYM
47852+ wchan = 0;
47853+ eip =0;
47854+ esp =0;
47855+#endif
47856+
47857 /* scale priority and nice values from timeslices to -20..20 */
47858 /* to make it look like a "normal" Unix priority/nice value */
47859 priority = task_prio(task);
47860@@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47861 vsize,
47862 mm ? get_mm_rss(mm) : 0,
47863 rsslim,
47864+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47865+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
47866+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
47867+ PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
47868+#else
47869 mm ? (permitted ? mm->start_code : 1) : 0,
47870 mm ? (permitted ? mm->end_code : 1) : 0,
47871 (permitted && mm) ? mm->start_stack : 0,
47872+#endif
47873 esp,
47874 eip,
47875 /* The signal information here is obsolete.
47876@@ -536,8 +593,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47877 struct pid *pid, struct task_struct *task)
47878 {
47879 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
47880- struct mm_struct *mm = get_task_mm(task);
47881+ struct mm_struct *mm;
47882
47883+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47884+ if (current->exec_id != m->exec_id) {
47885+ gr_log_badprocpid("statm");
47886+ return 0;
47887+ }
47888+#endif
47889+ mm = get_task_mm(task);
47890 if (mm) {
47891 size = task_statm(mm, &shared, &text, &data, &resident);
47892 mmput(mm);
47893@@ -547,3 +611,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47894
47895 return 0;
47896 }
47897+
47898+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47899+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
47900+{
47901+ u32 curr_ip = 0;
47902+ unsigned long flags;
47903+
47904+ if (lock_task_sighand(task, &flags)) {
47905+ curr_ip = task->signal->curr_ip;
47906+ unlock_task_sighand(task, &flags);
47907+ }
47908+
47909+ return sprintf(buffer, "%pI4\n", &curr_ip);
47910+}
47911+#endif
47912diff --git a/fs/proc/base.c b/fs/proc/base.c
47913index d4548dd..d101f84 100644
47914--- a/fs/proc/base.c
47915+++ b/fs/proc/base.c
47916@@ -109,6 +109,14 @@ struct pid_entry {
47917 union proc_op op;
47918 };
47919
47920+struct getdents_callback {
47921+ struct linux_dirent __user * current_dir;
47922+ struct linux_dirent __user * previous;
47923+ struct file * file;
47924+ int count;
47925+ int error;
47926+};
47927+
47928 #define NOD(NAME, MODE, IOP, FOP, OP) { \
47929 .name = (NAME), \
47930 .len = sizeof(NAME) - 1, \
47931@@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
47932 if (!mm->arg_end)
47933 goto out_mm; /* Shh! No looking before we're done */
47934
47935+ if (gr_acl_handle_procpidmem(task))
47936+ goto out_mm;
47937+
47938 len = mm->arg_end - mm->arg_start;
47939
47940 if (len > PAGE_SIZE)
47941@@ -240,12 +251,28 @@ out:
47942 return res;
47943 }
47944
47945+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47946+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47947+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
47948+ _mm->pax_flags & MF_PAX_SEGMEXEC))
47949+#endif
47950+
47951 static int proc_pid_auxv(struct task_struct *task, char *buffer)
47952 {
47953 struct mm_struct *mm = mm_for_maps(task);
47954 int res = PTR_ERR(mm);
47955 if (mm && !IS_ERR(mm)) {
47956 unsigned int nwords = 0;
47957+
47958+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47959+ /* allow if we're currently ptracing this task */
47960+ if (PAX_RAND_FLAGS(mm) &&
47961+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
47962+ mmput(mm);
47963+ return 0;
47964+ }
47965+#endif
47966+
47967 do {
47968 nwords += 2;
47969 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
47970@@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
47971 }
47972
47973
47974-#ifdef CONFIG_KALLSYMS
47975+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47976 /*
47977 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
47978 * Returns the resolved symbol. If that fails, simply return the address.
47979@@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
47980 mutex_unlock(&task->signal->cred_guard_mutex);
47981 }
47982
47983-#ifdef CONFIG_STACKTRACE
47984+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47985
47986 #define MAX_STACK_TRACE_DEPTH 64
47987
47988@@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
47989 return count;
47990 }
47991
47992-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47993+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47994 static int proc_pid_syscall(struct task_struct *task, char *buffer)
47995 {
47996 long nr;
47997@@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
47998 /************************************************************************/
47999
48000 /* permission checks */
48001-static int proc_fd_access_allowed(struct inode *inode)
48002+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48003 {
48004 struct task_struct *task;
48005 int allowed = 0;
48006@@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48007 */
48008 task = get_proc_task(inode);
48009 if (task) {
48010- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48011+ if (log)
48012+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48013+ else
48014+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48015 put_task_struct(task);
48016 }
48017 return allowed;
48018@@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48019 struct task_struct *task,
48020 int hide_pid_min)
48021 {
48022+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48023+ return false;
48024+
48025+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48026+ rcu_read_lock();
48027+ {
48028+ const struct cred *tmpcred = current_cred();
48029+ const struct cred *cred = __task_cred(task);
48030+
48031+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48032+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48033+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48034+#endif
48035+ ) {
48036+ rcu_read_unlock();
48037+ return true;
48038+ }
48039+ }
48040+ rcu_read_unlock();
48041+
48042+ if (!pid->hide_pid)
48043+ return false;
48044+#endif
48045+
48046 if (pid->hide_pid < hide_pid_min)
48047 return true;
48048 if (in_group_p(pid->pid_gid))
48049 return true;
48050+
48051 return ptrace_may_access(task, PTRACE_MODE_READ);
48052 }
48053
48054@@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48055 put_task_struct(task);
48056
48057 if (!has_perms) {
48058+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48059+ {
48060+#else
48061 if (pid->hide_pid == 2) {
48062+#endif
48063 /*
48064 * Let's make getdents(), stat(), and open()
48065 * consistent with each other. If a process
48066@@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
48067 file->f_mode |= FMODE_UNSIGNED_OFFSET;
48068 file->private_data = mm;
48069
48070+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48071+ file->f_version = current->exec_id;
48072+#endif
48073+
48074 return 0;
48075 }
48076
48077@@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48078 ssize_t copied;
48079 char *page;
48080
48081+#ifdef CONFIG_GRKERNSEC
48082+ if (write)
48083+ return -EPERM;
48084+#endif
48085+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48086+ if (file->f_version != current->exec_id) {
48087+ gr_log_badprocpid("mem");
48088+ return 0;
48089+ }
48090+#endif
48091+
48092 if (!mm)
48093 return 0;
48094
48095@@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48096 if (!task)
48097 goto out_no_task;
48098
48099+ if (gr_acl_handle_procpidmem(task))
48100+ goto out;
48101+
48102 ret = -ENOMEM;
48103 page = (char *)__get_free_page(GFP_TEMPORARY);
48104 if (!page)
48105@@ -1434,7 +1511,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48106 path_put(&nd->path);
48107
48108 /* Are we allowed to snoop on the tasks file descriptors? */
48109- if (!proc_fd_access_allowed(inode))
48110+ if (!proc_fd_access_allowed(inode, 0))
48111 goto out;
48112
48113 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48114@@ -1473,8 +1550,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48115 struct path path;
48116
48117 /* Are we allowed to snoop on the tasks file descriptors? */
48118- if (!proc_fd_access_allowed(inode))
48119- goto out;
48120+ /* logging this is needed for learning on chromium to work properly,
48121+ but we don't want to flood the logs from 'ps' which does a readlink
48122+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48123+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
48124+ */
48125+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48126+ if (!proc_fd_access_allowed(inode,0))
48127+ goto out;
48128+ } else {
48129+ if (!proc_fd_access_allowed(inode,1))
48130+ goto out;
48131+ }
48132
48133 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48134 if (error)
48135@@ -1539,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48136 rcu_read_lock();
48137 cred = __task_cred(task);
48138 inode->i_uid = cred->euid;
48139+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48140+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48141+#else
48142 inode->i_gid = cred->egid;
48143+#endif
48144 rcu_read_unlock();
48145 }
48146 security_task_to_inode(task, inode);
48147@@ -1575,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48148 return -ENOENT;
48149 }
48150 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48151+#ifdef CONFIG_GRKERNSEC_PROC_USER
48152+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48153+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48154+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48155+#endif
48156 task_dumpable(task)) {
48157 cred = __task_cred(task);
48158 stat->uid = cred->euid;
48159+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48160+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48161+#else
48162 stat->gid = cred->egid;
48163+#endif
48164 }
48165 }
48166 rcu_read_unlock();
48167@@ -1616,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48168
48169 if (task) {
48170 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48171+#ifdef CONFIG_GRKERNSEC_PROC_USER
48172+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48173+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48174+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48175+#endif
48176 task_dumpable(task)) {
48177 rcu_read_lock();
48178 cred = __task_cred(task);
48179 inode->i_uid = cred->euid;
48180+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48181+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48182+#else
48183 inode->i_gid = cred->egid;
48184+#endif
48185 rcu_read_unlock();
48186 } else {
48187 inode->i_uid = 0;
48188@@ -1738,7 +1847,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48189 int fd = proc_fd(inode);
48190
48191 if (task) {
48192- files = get_files_struct(task);
48193+ if (!gr_acl_handle_procpidmem(task))
48194+ files = get_files_struct(task);
48195 put_task_struct(task);
48196 }
48197 if (files) {
48198@@ -2355,11 +2465,21 @@ static const struct file_operations proc_map_files_operations = {
48199 */
48200 static int proc_fd_permission(struct inode *inode, int mask)
48201 {
48202+ struct task_struct *task;
48203 int rv = generic_permission(inode, mask);
48204- if (rv == 0)
48205- return 0;
48206+
48207 if (task_pid(current) == proc_pid(inode))
48208 rv = 0;
48209+
48210+ task = get_proc_task(inode);
48211+ if (task == NULL)
48212+ return rv;
48213+
48214+ if (gr_acl_handle_procpidmem(task))
48215+ rv = -EACCES;
48216+
48217+ put_task_struct(task);
48218+
48219 return rv;
48220 }
48221
48222@@ -2469,6 +2589,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48223 if (!task)
48224 goto out_no_task;
48225
48226+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48227+ goto out;
48228+
48229 /*
48230 * Yes, it does not scale. And it should not. Don't add
48231 * new entries into /proc/<tgid>/ without very good reasons.
48232@@ -2513,6 +2636,9 @@ static int proc_pident_readdir(struct file *filp,
48233 if (!task)
48234 goto out_no_task;
48235
48236+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48237+ goto out;
48238+
48239 ret = 0;
48240 i = filp->f_pos;
48241 switch (i) {
48242@@ -2783,7 +2909,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48243 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48244 void *cookie)
48245 {
48246- char *s = nd_get_link(nd);
48247+ const char *s = nd_get_link(nd);
48248 if (!IS_ERR(s))
48249 __putname(s);
48250 }
48251@@ -2984,7 +3110,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48252 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48253 #endif
48254 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48255-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48256+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48257 INF("syscall", S_IRUGO, proc_pid_syscall),
48258 #endif
48259 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48260@@ -3009,10 +3135,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48261 #ifdef CONFIG_SECURITY
48262 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48263 #endif
48264-#ifdef CONFIG_KALLSYMS
48265+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48266 INF("wchan", S_IRUGO, proc_pid_wchan),
48267 #endif
48268-#ifdef CONFIG_STACKTRACE
48269+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48270 ONE("stack", S_IRUGO, proc_pid_stack),
48271 #endif
48272 #ifdef CONFIG_SCHEDSTATS
48273@@ -3046,6 +3172,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48274 #ifdef CONFIG_HARDWALL
48275 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48276 #endif
48277+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48278+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48279+#endif
48280 };
48281
48282 static int proc_tgid_base_readdir(struct file * filp,
48283@@ -3172,7 +3301,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48284 if (!inode)
48285 goto out;
48286
48287+#ifdef CONFIG_GRKERNSEC_PROC_USER
48288+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48289+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48290+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48291+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48292+#else
48293 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48294+#endif
48295 inode->i_op = &proc_tgid_base_inode_operations;
48296 inode->i_fop = &proc_tgid_base_operations;
48297 inode->i_flags|=S_IMMUTABLE;
48298@@ -3214,7 +3350,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48299 if (!task)
48300 goto out;
48301
48302+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48303+ goto out_put_task;
48304+
48305 result = proc_pid_instantiate(dir, dentry, task, NULL);
48306+out_put_task:
48307 put_task_struct(task);
48308 out:
48309 return result;
48310@@ -3277,6 +3417,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48311 static int fake_filldir(void *buf, const char *name, int namelen,
48312 loff_t offset, u64 ino, unsigned d_type)
48313 {
48314+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
48315+ __buf->error = -EINVAL;
48316 return 0;
48317 }
48318
48319@@ -3343,7 +3485,7 @@ static const struct pid_entry tid_base_stuff[] = {
48320 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48321 #endif
48322 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48323-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48324+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48325 INF("syscall", S_IRUGO, proc_pid_syscall),
48326 #endif
48327 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48328@@ -3367,10 +3509,10 @@ static const struct pid_entry tid_base_stuff[] = {
48329 #ifdef CONFIG_SECURITY
48330 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48331 #endif
48332-#ifdef CONFIG_KALLSYMS
48333+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48334 INF("wchan", S_IRUGO, proc_pid_wchan),
48335 #endif
48336-#ifdef CONFIG_STACKTRACE
48337+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48338 ONE("stack", S_IRUGO, proc_pid_stack),
48339 #endif
48340 #ifdef CONFIG_SCHEDSTATS
48341diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48342index 82676e3..5f8518a 100644
48343--- a/fs/proc/cmdline.c
48344+++ b/fs/proc/cmdline.c
48345@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48346
48347 static int __init proc_cmdline_init(void)
48348 {
48349+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48350+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48351+#else
48352 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48353+#endif
48354 return 0;
48355 }
48356 module_init(proc_cmdline_init);
48357diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48358index b143471..bb105e5 100644
48359--- a/fs/proc/devices.c
48360+++ b/fs/proc/devices.c
48361@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48362
48363 static int __init proc_devices_init(void)
48364 {
48365+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48366+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48367+#else
48368 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48369+#endif
48370 return 0;
48371 }
48372 module_init(proc_devices_init);
48373diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48374index 84fd323..f698a32 100644
48375--- a/fs/proc/inode.c
48376+++ b/fs/proc/inode.c
48377@@ -21,12 +21,18 @@
48378 #include <linux/seq_file.h>
48379 #include <linux/slab.h>
48380 #include <linux/mount.h>
48381+#include <linux/grsecurity.h>
48382
48383 #include <asm/system.h>
48384 #include <asm/uaccess.h>
48385
48386 #include "internal.h"
48387
48388+#ifdef CONFIG_PROC_SYSCTL
48389+extern const struct inode_operations proc_sys_inode_operations;
48390+extern const struct inode_operations proc_sys_dir_operations;
48391+#endif
48392+
48393 static void proc_evict_inode(struct inode *inode)
48394 {
48395 struct proc_dir_entry *de;
48396@@ -52,6 +58,13 @@ static void proc_evict_inode(struct inode *inode)
48397 ns_ops = PROC_I(inode)->ns_ops;
48398 if (ns_ops && ns_ops->put)
48399 ns_ops->put(PROC_I(inode)->ns);
48400+
48401+#ifdef CONFIG_PROC_SYSCTL
48402+ if (inode->i_op == &proc_sys_inode_operations ||
48403+ inode->i_op == &proc_sys_dir_operations)
48404+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48405+#endif
48406+
48407 }
48408
48409 static struct kmem_cache * proc_inode_cachep;
48410@@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48411 if (de->mode) {
48412 inode->i_mode = de->mode;
48413 inode->i_uid = de->uid;
48414+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48415+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48416+#else
48417 inode->i_gid = de->gid;
48418+#endif
48419 }
48420 if (de->size)
48421 inode->i_size = de->size;
48422diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48423index 2925775..4f08fae 100644
48424--- a/fs/proc/internal.h
48425+++ b/fs/proc/internal.h
48426@@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48427 struct pid *pid, struct task_struct *task);
48428 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48429 struct pid *pid, struct task_struct *task);
48430+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48431+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48432+#endif
48433 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48434
48435 extern const struct file_operations proc_maps_operations;
48436diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48437index d245cb2..f4e8498 100644
48438--- a/fs/proc/kcore.c
48439+++ b/fs/proc/kcore.c
48440@@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48441 * the addresses in the elf_phdr on our list.
48442 */
48443 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48444- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48445+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48446+ if (tsz > buflen)
48447 tsz = buflen;
48448-
48449+
48450 while (buflen) {
48451 struct kcore_list *m;
48452
48453@@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48454 kfree(elf_buf);
48455 } else {
48456 if (kern_addr_valid(start)) {
48457- unsigned long n;
48458+ char *elf_buf;
48459+ mm_segment_t oldfs;
48460
48461- n = copy_to_user(buffer, (char *)start, tsz);
48462- /*
48463- * We cannot distingush between fault on source
48464- * and fault on destination. When this happens
48465- * we clear too and hope it will trigger the
48466- * EFAULT again.
48467- */
48468- if (n) {
48469- if (clear_user(buffer + tsz - n,
48470- n))
48471+ elf_buf = kmalloc(tsz, GFP_KERNEL);
48472+ if (!elf_buf)
48473+ return -ENOMEM;
48474+ oldfs = get_fs();
48475+ set_fs(KERNEL_DS);
48476+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48477+ set_fs(oldfs);
48478+ if (copy_to_user(buffer, elf_buf, tsz)) {
48479+ kfree(elf_buf);
48480 return -EFAULT;
48481+ }
48482 }
48483+ set_fs(oldfs);
48484+ kfree(elf_buf);
48485 } else {
48486 if (clear_user(buffer, tsz))
48487 return -EFAULT;
48488@@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48489
48490 static int open_kcore(struct inode *inode, struct file *filp)
48491 {
48492+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48493+ return -EPERM;
48494+#endif
48495 if (!capable(CAP_SYS_RAWIO))
48496 return -EPERM;
48497 if (kcore_need_update)
48498diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48499index 80e4645..53e5fcf 100644
48500--- a/fs/proc/meminfo.c
48501+++ b/fs/proc/meminfo.c
48502@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48503 vmi.used >> 10,
48504 vmi.largest_chunk >> 10
48505 #ifdef CONFIG_MEMORY_FAILURE
48506- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48507+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48508 #endif
48509 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48510 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48511diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48512index b1822dd..df622cb 100644
48513--- a/fs/proc/nommu.c
48514+++ b/fs/proc/nommu.c
48515@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48516 if (len < 1)
48517 len = 1;
48518 seq_printf(m, "%*c", len, ' ');
48519- seq_path(m, &file->f_path, "");
48520+ seq_path(m, &file->f_path, "\n\\");
48521 }
48522
48523 seq_putc(m, '\n');
48524diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48525index 06e1cc1..177cd98 100644
48526--- a/fs/proc/proc_net.c
48527+++ b/fs/proc/proc_net.c
48528@@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48529 struct task_struct *task;
48530 struct nsproxy *ns;
48531 struct net *net = NULL;
48532+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48533+ const struct cred *cred = current_cred();
48534+#endif
48535+
48536+#ifdef CONFIG_GRKERNSEC_PROC_USER
48537+ if (cred->fsuid)
48538+ return net;
48539+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48540+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48541+ return net;
48542+#endif
48543
48544 rcu_read_lock();
48545 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48546diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48547index 53c3bce..10ad159 100644
48548--- a/fs/proc/proc_sysctl.c
48549+++ b/fs/proc/proc_sysctl.c
48550@@ -9,11 +9,13 @@
48551 #include <linux/namei.h>
48552 #include "internal.h"
48553
48554+extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
48555+
48556 static const struct dentry_operations proc_sys_dentry_operations;
48557 static const struct file_operations proc_sys_file_operations;
48558-static const struct inode_operations proc_sys_inode_operations;
48559+const struct inode_operations proc_sys_inode_operations;
48560 static const struct file_operations proc_sys_dir_file_operations;
48561-static const struct inode_operations proc_sys_dir_operations;
48562+const struct inode_operations proc_sys_dir_operations;
48563
48564 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48565 {
48566@@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48567
48568 err = NULL;
48569 d_set_d_op(dentry, &proc_sys_dentry_operations);
48570+
48571+ gr_handle_proc_create(dentry, inode);
48572+
48573 d_add(dentry, inode);
48574
48575+ if (gr_handle_sysctl(p, MAY_EXEC))
48576+ err = ERR_PTR(-ENOENT);
48577+
48578 out:
48579 sysctl_head_finish(head);
48580 return err;
48581@@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48582 if (!table->proc_handler)
48583 goto out;
48584
48585+#ifdef CONFIG_GRKERNSEC
48586+ error = -EPERM;
48587+ if (write && !capable(CAP_SYS_ADMIN))
48588+ goto out;
48589+#endif
48590+
48591 /* careful: calling conventions are nasty here */
48592 res = count;
48593 error = table->proc_handler(table, write, buf, &res, ppos);
48594@@ -260,6 +274,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48595 return -ENOMEM;
48596 } else {
48597 d_set_d_op(child, &proc_sys_dentry_operations);
48598+
48599+ gr_handle_proc_create(child, inode);
48600+
48601 d_add(child, inode);
48602 }
48603 } else {
48604@@ -288,6 +305,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48605 if (*pos < file->f_pos)
48606 continue;
48607
48608+ if (gr_handle_sysctl(table, 0))
48609+ continue;
48610+
48611 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
48612 if (res)
48613 return res;
48614@@ -413,6 +433,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48615 if (IS_ERR(head))
48616 return PTR_ERR(head);
48617
48618+ if (table && gr_handle_sysctl(table, MAY_EXEC))
48619+ return -ENOENT;
48620+
48621 generic_fillattr(inode, stat);
48622 if (table)
48623 stat->mode = (stat->mode & S_IFMT) | table->mode;
48624@@ -435,13 +458,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
48625 .llseek = generic_file_llseek,
48626 };
48627
48628-static const struct inode_operations proc_sys_inode_operations = {
48629+const struct inode_operations proc_sys_inode_operations = {
48630 .permission = proc_sys_permission,
48631 .setattr = proc_sys_setattr,
48632 .getattr = proc_sys_getattr,
48633 };
48634
48635-static const struct inode_operations proc_sys_dir_operations = {
48636+const struct inode_operations proc_sys_dir_operations = {
48637 .lookup = proc_sys_lookup,
48638 .permission = proc_sys_permission,
48639 .setattr = proc_sys_setattr,
48640diff --git a/fs/proc/root.c b/fs/proc/root.c
48641index 46a15d8..335631a 100644
48642--- a/fs/proc/root.c
48643+++ b/fs/proc/root.c
48644@@ -187,7 +187,15 @@ void __init proc_root_init(void)
48645 #ifdef CONFIG_PROC_DEVICETREE
48646 proc_device_tree_init();
48647 #endif
48648+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48649+#ifdef CONFIG_GRKERNSEC_PROC_USER
48650+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48651+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48652+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48653+#endif
48654+#else
48655 proc_mkdir("bus", NULL);
48656+#endif
48657 proc_sys_init();
48658 }
48659
48660diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48661index 3efa725..23c925b 100644
48662--- a/fs/proc/task_mmu.c
48663+++ b/fs/proc/task_mmu.c
48664@@ -11,6 +11,7 @@
48665 #include <linux/rmap.h>
48666 #include <linux/swap.h>
48667 #include <linux/swapops.h>
48668+#include <linux/grsecurity.h>
48669
48670 #include <asm/elf.h>
48671 #include <asm/uaccess.h>
48672@@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48673 "VmExe:\t%8lu kB\n"
48674 "VmLib:\t%8lu kB\n"
48675 "VmPTE:\t%8lu kB\n"
48676- "VmSwap:\t%8lu kB\n",
48677- hiwater_vm << (PAGE_SHIFT-10),
48678+ "VmSwap:\t%8lu kB\n"
48679+
48680+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48681+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
48682+#endif
48683+
48684+ ,hiwater_vm << (PAGE_SHIFT-10),
48685 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
48686 mm->locked_vm << (PAGE_SHIFT-10),
48687 mm->pinned_vm << (PAGE_SHIFT-10),
48688@@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48689 data << (PAGE_SHIFT-10),
48690 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
48691 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
48692- swap << (PAGE_SHIFT-10));
48693+ swap << (PAGE_SHIFT-10)
48694+
48695+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48696+ , mm->context.user_cs_base, mm->context.user_cs_limit
48697+#endif
48698+
48699+ );
48700 }
48701
48702 unsigned long task_vsize(struct mm_struct *mm)
48703@@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
48704 return ret;
48705 }
48706
48707+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48708+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48709+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48710+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48711+#endif
48712+
48713 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48714 {
48715 struct mm_struct *mm = vma->vm_mm;
48716@@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48717 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
48718 }
48719
48720- /* We don't show the stack guard page in /proc/maps */
48721+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48722+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
48723+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
48724+#else
48725 start = vma->vm_start;
48726- if (stack_guard_page_start(vma, start))
48727- start += PAGE_SIZE;
48728 end = vma->vm_end;
48729- if (stack_guard_page_end(vma, end))
48730- end -= PAGE_SIZE;
48731+#endif
48732
48733 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
48734 start,
48735@@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48736 flags & VM_WRITE ? 'w' : '-',
48737 flags & VM_EXEC ? 'x' : '-',
48738 flags & VM_MAYSHARE ? 's' : 'p',
48739+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48740+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
48741+#else
48742 pgoff,
48743+#endif
48744 MAJOR(dev), MINOR(dev), ino, &len);
48745
48746 /*
48747@@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48748 */
48749 if (file) {
48750 pad_len_spaces(m, len);
48751- seq_path(m, &file->f_path, "\n");
48752+ seq_path(m, &file->f_path, "\n\\");
48753 } else {
48754 const char *name = arch_vma_name(vma);
48755 if (!name) {
48756@@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48757 if (vma->vm_start <= mm->brk &&
48758 vma->vm_end >= mm->start_brk) {
48759 name = "[heap]";
48760- } else if (vma->vm_start <= mm->start_stack &&
48761- vma->vm_end >= mm->start_stack) {
48762+ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
48763+ (vma->vm_start <= mm->start_stack &&
48764+ vma->vm_end >= mm->start_stack)) {
48765 name = "[stack]";
48766 }
48767 } else {
48768@@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
48769 struct proc_maps_private *priv = m->private;
48770 struct task_struct *task = priv->task;
48771
48772+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48773+ if (current->exec_id != m->exec_id) {
48774+ gr_log_badprocpid("maps");
48775+ return 0;
48776+ }
48777+#endif
48778+
48779 show_map_vma(m, vma);
48780
48781 if (m->count < m->size) /* vma is copied successfully */
48782@@ -437,12 +467,23 @@ static int show_smap(struct seq_file *m, void *v)
48783 .private = &mss,
48784 };
48785
48786+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48787+ if (current->exec_id != m->exec_id) {
48788+ gr_log_badprocpid("smaps");
48789+ return 0;
48790+ }
48791+#endif
48792 memset(&mss, 0, sizeof mss);
48793- mss.vma = vma;
48794- /* mmap_sem is held in m_start */
48795- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48796- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48797-
48798+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48799+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
48800+#endif
48801+ mss.vma = vma;
48802+ /* mmap_sem is held in m_start */
48803+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48804+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48805+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48806+ }
48807+#endif
48808 show_map_vma(m, vma);
48809
48810 seq_printf(m,
48811@@ -460,7 +501,11 @@ static int show_smap(struct seq_file *m, void *v)
48812 "KernelPageSize: %8lu kB\n"
48813 "MMUPageSize: %8lu kB\n"
48814 "Locked: %8lu kB\n",
48815+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48816+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
48817+#else
48818 (vma->vm_end - vma->vm_start) >> 10,
48819+#endif
48820 mss.resident >> 10,
48821 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
48822 mss.shared_clean >> 10,
48823@@ -1024,6 +1069,13 @@ static int show_numa_map(struct seq_file *m, void *v)
48824 int n;
48825 char buffer[50];
48826
48827+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48828+ if (current->exec_id != m->exec_id) {
48829+ gr_log_badprocpid("numa_maps");
48830+ return 0;
48831+ }
48832+#endif
48833+
48834 if (!mm)
48835 return 0;
48836
48837@@ -1041,11 +1093,15 @@ static int show_numa_map(struct seq_file *m, void *v)
48838 mpol_to_str(buffer, sizeof(buffer), pol, 0);
48839 mpol_cond_put(pol);
48840
48841+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48842+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
48843+#else
48844 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
48845+#endif
48846
48847 if (file) {
48848 seq_printf(m, " file=");
48849- seq_path(m, &file->f_path, "\n\t= ");
48850+ seq_path(m, &file->f_path, "\n\t\\= ");
48851 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
48852 seq_printf(m, " heap");
48853 } else if (vma->vm_start <= mm->start_stack &&
48854diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
48855index 980de54..2a4db5f 100644
48856--- a/fs/proc/task_nommu.c
48857+++ b/fs/proc/task_nommu.c
48858@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48859 else
48860 bytes += kobjsize(mm);
48861
48862- if (current->fs && current->fs->users > 1)
48863+ if (current->fs && atomic_read(&current->fs->users) > 1)
48864 sbytes += kobjsize(current->fs);
48865 else
48866 bytes += kobjsize(current->fs);
48867@@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
48868
48869 if (file) {
48870 pad_len_spaces(m, len);
48871- seq_path(m, &file->f_path, "");
48872+ seq_path(m, &file->f_path, "\n\\");
48873 } else if (mm) {
48874 if (vma->vm_start <= mm->start_stack &&
48875 vma->vm_end >= mm->start_stack) {
48876diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
48877index d67908b..d13f6a6 100644
48878--- a/fs/quota/netlink.c
48879+++ b/fs/quota/netlink.c
48880@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
48881 void quota_send_warning(short type, unsigned int id, dev_t dev,
48882 const char warntype)
48883 {
48884- static atomic_t seq;
48885+ static atomic_unchecked_t seq;
48886 struct sk_buff *skb;
48887 void *msg_head;
48888 int ret;
48889@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
48890 "VFS: Not enough memory to send quota warning.\n");
48891 return;
48892 }
48893- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
48894+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
48895 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
48896 if (!msg_head) {
48897 printk(KERN_ERR
48898diff --git a/fs/readdir.c b/fs/readdir.c
48899index 356f715..c918d38 100644
48900--- a/fs/readdir.c
48901+++ b/fs/readdir.c
48902@@ -17,6 +17,7 @@
48903 #include <linux/security.h>
48904 #include <linux/syscalls.h>
48905 #include <linux/unistd.h>
48906+#include <linux/namei.h>
48907
48908 #include <asm/uaccess.h>
48909
48910@@ -67,6 +68,7 @@ struct old_linux_dirent {
48911
48912 struct readdir_callback {
48913 struct old_linux_dirent __user * dirent;
48914+ struct file * file;
48915 int result;
48916 };
48917
48918@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
48919 buf->result = -EOVERFLOW;
48920 return -EOVERFLOW;
48921 }
48922+
48923+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48924+ return 0;
48925+
48926 buf->result++;
48927 dirent = buf->dirent;
48928 if (!access_ok(VERIFY_WRITE, dirent,
48929@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
48930
48931 buf.result = 0;
48932 buf.dirent = dirent;
48933+ buf.file = file;
48934
48935 error = vfs_readdir(file, fillonedir, &buf);
48936 if (buf.result)
48937@@ -142,6 +149,7 @@ struct linux_dirent {
48938 struct getdents_callback {
48939 struct linux_dirent __user * current_dir;
48940 struct linux_dirent __user * previous;
48941+ struct file * file;
48942 int count;
48943 int error;
48944 };
48945@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
48946 buf->error = -EOVERFLOW;
48947 return -EOVERFLOW;
48948 }
48949+
48950+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48951+ return 0;
48952+
48953 dirent = buf->previous;
48954 if (dirent) {
48955 if (__put_user(offset, &dirent->d_off))
48956@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
48957 buf.previous = NULL;
48958 buf.count = count;
48959 buf.error = 0;
48960+ buf.file = file;
48961
48962 error = vfs_readdir(file, filldir, &buf);
48963 if (error >= 0)
48964@@ -229,6 +242,7 @@ out:
48965 struct getdents_callback64 {
48966 struct linux_dirent64 __user * current_dir;
48967 struct linux_dirent64 __user * previous;
48968+ struct file *file;
48969 int count;
48970 int error;
48971 };
48972@@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
48973 buf->error = -EINVAL; /* only used if we fail.. */
48974 if (reclen > buf->count)
48975 return -EINVAL;
48976+
48977+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48978+ return 0;
48979+
48980 dirent = buf->previous;
48981 if (dirent) {
48982 if (__put_user(offset, &dirent->d_off))
48983@@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48984
48985 buf.current_dir = dirent;
48986 buf.previous = NULL;
48987+ buf.file = file;
48988 buf.count = count;
48989 buf.error = 0;
48990
48991@@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48992 error = buf.error;
48993 lastdirent = buf.previous;
48994 if (lastdirent) {
48995- typeof(lastdirent->d_off) d_off = file->f_pos;
48996+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
48997 if (__put_user(d_off, &lastdirent->d_off))
48998 error = -EFAULT;
48999 else
49000diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49001index 60c0804..d814f98 100644
49002--- a/fs/reiserfs/do_balan.c
49003+++ b/fs/reiserfs/do_balan.c
49004@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49005 return;
49006 }
49007
49008- atomic_inc(&(fs_generation(tb->tb_sb)));
49009+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49010 do_balance_starts(tb);
49011
49012 /* balance leaf returns 0 except if combining L R and S into
49013diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49014index 7a99811..a7c96c4 100644
49015--- a/fs/reiserfs/procfs.c
49016+++ b/fs/reiserfs/procfs.c
49017@@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49018 "SMALL_TAILS " : "NO_TAILS ",
49019 replay_only(sb) ? "REPLAY_ONLY " : "",
49020 convert_reiserfs(sb) ? "CONV " : "",
49021- atomic_read(&r->s_generation_counter),
49022+ atomic_read_unchecked(&r->s_generation_counter),
49023 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49024 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49025 SF(s_good_search_by_key_reada), SF(s_bmaps),
49026diff --git a/fs/select.c b/fs/select.c
49027index e782258..3b4b44c 100644
49028--- a/fs/select.c
49029+++ b/fs/select.c
49030@@ -20,6 +20,7 @@
49031 #include <linux/module.h>
49032 #include <linux/slab.h>
49033 #include <linux/poll.h>
49034+#include <linux/security.h>
49035 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49036 #include <linux/file.h>
49037 #include <linux/fdtable.h>
49038@@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49039 struct poll_list *walk = head;
49040 unsigned long todo = nfds;
49041
49042+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49043 if (nfds > rlimit(RLIMIT_NOFILE))
49044 return -EINVAL;
49045
49046diff --git a/fs/seq_file.c b/fs/seq_file.c
49047index 4023d6b..ab46c6a 100644
49048--- a/fs/seq_file.c
49049+++ b/fs/seq_file.c
49050@@ -9,6 +9,7 @@
49051 #include <linux/module.h>
49052 #include <linux/seq_file.h>
49053 #include <linux/slab.h>
49054+#include <linux/sched.h>
49055
49056 #include <asm/uaccess.h>
49057 #include <asm/page.h>
49058@@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49059 memset(p, 0, sizeof(*p));
49060 mutex_init(&p->lock);
49061 p->op = op;
49062+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49063+ p->exec_id = current->exec_id;
49064+#endif
49065
49066 /*
49067 * Wrappers around seq_open(e.g. swaps_open) need to be
49068@@ -549,7 +553,7 @@ static void single_stop(struct seq_file *p, void *v)
49069 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49070 void *data)
49071 {
49072- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49073+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49074 int res = -ENOMEM;
49075
49076 if (op) {
49077diff --git a/fs/splice.c b/fs/splice.c
49078index 96d7b28..fd465ac 100644
49079--- a/fs/splice.c
49080+++ b/fs/splice.c
49081@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49082 pipe_lock(pipe);
49083
49084 for (;;) {
49085- if (!pipe->readers) {
49086+ if (!atomic_read(&pipe->readers)) {
49087 send_sig(SIGPIPE, current, 0);
49088 if (!ret)
49089 ret = -EPIPE;
49090@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49091 do_wakeup = 0;
49092 }
49093
49094- pipe->waiting_writers++;
49095+ atomic_inc(&pipe->waiting_writers);
49096 pipe_wait(pipe);
49097- pipe->waiting_writers--;
49098+ atomic_dec(&pipe->waiting_writers);
49099 }
49100
49101 pipe_unlock(pipe);
49102@@ -560,7 +560,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49103 old_fs = get_fs();
49104 set_fs(get_ds());
49105 /* The cast to a user pointer is valid due to the set_fs() */
49106- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49107+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49108 set_fs(old_fs);
49109
49110 return res;
49111@@ -575,7 +575,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49112 old_fs = get_fs();
49113 set_fs(get_ds());
49114 /* The cast to a user pointer is valid due to the set_fs() */
49115- res = vfs_write(file, (const char __user *)buf, count, &pos);
49116+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49117 set_fs(old_fs);
49118
49119 return res;
49120@@ -626,7 +626,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49121 goto err;
49122
49123 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49124- vec[i].iov_base = (void __user *) page_address(page);
49125+ vec[i].iov_base = (void __force_user *) page_address(page);
49126 vec[i].iov_len = this_len;
49127 spd.pages[i] = page;
49128 spd.nr_pages++;
49129@@ -848,10 +848,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49130 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49131 {
49132 while (!pipe->nrbufs) {
49133- if (!pipe->writers)
49134+ if (!atomic_read(&pipe->writers))
49135 return 0;
49136
49137- if (!pipe->waiting_writers && sd->num_spliced)
49138+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49139 return 0;
49140
49141 if (sd->flags & SPLICE_F_NONBLOCK)
49142@@ -1184,7 +1184,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49143 * out of the pipe right after the splice_to_pipe(). So set
49144 * PIPE_READERS appropriately.
49145 */
49146- pipe->readers = 1;
49147+ atomic_set(&pipe->readers, 1);
49148
49149 current->splice_pipe = pipe;
49150 }
49151@@ -1736,9 +1736,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49152 ret = -ERESTARTSYS;
49153 break;
49154 }
49155- if (!pipe->writers)
49156+ if (!atomic_read(&pipe->writers))
49157 break;
49158- if (!pipe->waiting_writers) {
49159+ if (!atomic_read(&pipe->waiting_writers)) {
49160 if (flags & SPLICE_F_NONBLOCK) {
49161 ret = -EAGAIN;
49162 break;
49163@@ -1770,7 +1770,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49164 pipe_lock(pipe);
49165
49166 while (pipe->nrbufs >= pipe->buffers) {
49167- if (!pipe->readers) {
49168+ if (!atomic_read(&pipe->readers)) {
49169 send_sig(SIGPIPE, current, 0);
49170 ret = -EPIPE;
49171 break;
49172@@ -1783,9 +1783,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49173 ret = -ERESTARTSYS;
49174 break;
49175 }
49176- pipe->waiting_writers++;
49177+ atomic_inc(&pipe->waiting_writers);
49178 pipe_wait(pipe);
49179- pipe->waiting_writers--;
49180+ atomic_dec(&pipe->waiting_writers);
49181 }
49182
49183 pipe_unlock(pipe);
49184@@ -1821,14 +1821,14 @@ retry:
49185 pipe_double_lock(ipipe, opipe);
49186
49187 do {
49188- if (!opipe->readers) {
49189+ if (!atomic_read(&opipe->readers)) {
49190 send_sig(SIGPIPE, current, 0);
49191 if (!ret)
49192 ret = -EPIPE;
49193 break;
49194 }
49195
49196- if (!ipipe->nrbufs && !ipipe->writers)
49197+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49198 break;
49199
49200 /*
49201@@ -1925,7 +1925,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49202 pipe_double_lock(ipipe, opipe);
49203
49204 do {
49205- if (!opipe->readers) {
49206+ if (!atomic_read(&opipe->readers)) {
49207 send_sig(SIGPIPE, current, 0);
49208 if (!ret)
49209 ret = -EPIPE;
49210@@ -1970,7 +1970,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49211 * return EAGAIN if we have the potential of some data in the
49212 * future, otherwise just return 0
49213 */
49214- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49215+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49216 ret = -EAGAIN;
49217
49218 pipe_unlock(ipipe);
49219diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49220index 7fdf6a7..e6cd8ad 100644
49221--- a/fs/sysfs/dir.c
49222+++ b/fs/sysfs/dir.c
49223@@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49224 struct sysfs_dirent *sd;
49225 int rc;
49226
49227+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49228+ const char *parent_name = parent_sd->s_name;
49229+
49230+ mode = S_IFDIR | S_IRWXU;
49231+
49232+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49233+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49234+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49235+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49236+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49237+#endif
49238+
49239 /* allocate */
49240 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49241 if (!sd)
49242diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49243index 00012e3..8392349 100644
49244--- a/fs/sysfs/file.c
49245+++ b/fs/sysfs/file.c
49246@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49247
49248 struct sysfs_open_dirent {
49249 atomic_t refcnt;
49250- atomic_t event;
49251+ atomic_unchecked_t event;
49252 wait_queue_head_t poll;
49253 struct list_head buffers; /* goes through sysfs_buffer.list */
49254 };
49255@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49256 if (!sysfs_get_active(attr_sd))
49257 return -ENODEV;
49258
49259- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49260+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49261 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49262
49263 sysfs_put_active(attr_sd);
49264@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49265 return -ENOMEM;
49266
49267 atomic_set(&new_od->refcnt, 0);
49268- atomic_set(&new_od->event, 1);
49269+ atomic_set_unchecked(&new_od->event, 1);
49270 init_waitqueue_head(&new_od->poll);
49271 INIT_LIST_HEAD(&new_od->buffers);
49272 goto retry;
49273@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49274
49275 sysfs_put_active(attr_sd);
49276
49277- if (buffer->event != atomic_read(&od->event))
49278+ if (buffer->event != atomic_read_unchecked(&od->event))
49279 goto trigger;
49280
49281 return DEFAULT_POLLMASK;
49282@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49283
49284 od = sd->s_attr.open;
49285 if (od) {
49286- atomic_inc(&od->event);
49287+ atomic_inc_unchecked(&od->event);
49288 wake_up_interruptible(&od->poll);
49289 }
49290
49291diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49292index a7ac78f..02158e1 100644
49293--- a/fs/sysfs/symlink.c
49294+++ b/fs/sysfs/symlink.c
49295@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49296
49297 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49298 {
49299- char *page = nd_get_link(nd);
49300+ const char *page = nd_get_link(nd);
49301 if (!IS_ERR(page))
49302 free_page((unsigned long)page);
49303 }
49304diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49305index c175b4d..8f36a16 100644
49306--- a/fs/udf/misc.c
49307+++ b/fs/udf/misc.c
49308@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49309
49310 u8 udf_tag_checksum(const struct tag *t)
49311 {
49312- u8 *data = (u8 *)t;
49313+ const u8 *data = (const u8 *)t;
49314 u8 checksum = 0;
49315 int i;
49316 for (i = 0; i < sizeof(struct tag); ++i)
49317diff --git a/fs/utimes.c b/fs/utimes.c
49318index ba653f3..06ea4b1 100644
49319--- a/fs/utimes.c
49320+++ b/fs/utimes.c
49321@@ -1,6 +1,7 @@
49322 #include <linux/compiler.h>
49323 #include <linux/file.h>
49324 #include <linux/fs.h>
49325+#include <linux/security.h>
49326 #include <linux/linkage.h>
49327 #include <linux/mount.h>
49328 #include <linux/namei.h>
49329@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49330 goto mnt_drop_write_and_out;
49331 }
49332 }
49333+
49334+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49335+ error = -EACCES;
49336+ goto mnt_drop_write_and_out;
49337+ }
49338+
49339 mutex_lock(&inode->i_mutex);
49340 error = notify_change(path->dentry, &newattrs);
49341 mutex_unlock(&inode->i_mutex);
49342diff --git a/fs/xattr.c b/fs/xattr.c
49343index 82f4337..236473c 100644
49344--- a/fs/xattr.c
49345+++ b/fs/xattr.c
49346@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49347 * Extended attribute SET operations
49348 */
49349 static long
49350-setxattr(struct dentry *d, const char __user *name, const void __user *value,
49351+setxattr(struct path *path, const char __user *name, const void __user *value,
49352 size_t size, int flags)
49353 {
49354 int error;
49355@@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49356 return PTR_ERR(kvalue);
49357 }
49358
49359- error = vfs_setxattr(d, kname, kvalue, size, flags);
49360+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49361+ error = -EACCES;
49362+ goto out;
49363+ }
49364+
49365+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49366+out:
49367 kfree(kvalue);
49368 return error;
49369 }
49370@@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49371 return error;
49372 error = mnt_want_write(path.mnt);
49373 if (!error) {
49374- error = setxattr(path.dentry, name, value, size, flags);
49375+ error = setxattr(&path, name, value, size, flags);
49376 mnt_drop_write(path.mnt);
49377 }
49378 path_put(&path);
49379@@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49380 return error;
49381 error = mnt_want_write(path.mnt);
49382 if (!error) {
49383- error = setxattr(path.dentry, name, value, size, flags);
49384+ error = setxattr(&path, name, value, size, flags);
49385 mnt_drop_write(path.mnt);
49386 }
49387 path_put(&path);
49388@@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49389 const void __user *,value, size_t, size, int, flags)
49390 {
49391 struct file *f;
49392- struct dentry *dentry;
49393 int error = -EBADF;
49394
49395 f = fget(fd);
49396 if (!f)
49397 return error;
49398- dentry = f->f_path.dentry;
49399- audit_inode(NULL, dentry);
49400+ audit_inode(NULL, f->f_path.dentry);
49401 error = mnt_want_write_file(f);
49402 if (!error) {
49403- error = setxattr(dentry, name, value, size, flags);
49404+ error = setxattr(&f->f_path, name, value, size, flags);
49405 mnt_drop_write_file(f);
49406 }
49407 fput(f);
49408diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49409index 8d5a506..7f62712 100644
49410--- a/fs/xattr_acl.c
49411+++ b/fs/xattr_acl.c
49412@@ -17,8 +17,8 @@
49413 struct posix_acl *
49414 posix_acl_from_xattr(const void *value, size_t size)
49415 {
49416- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49417- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49418+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49419+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49420 int count;
49421 struct posix_acl *acl;
49422 struct posix_acl_entry *acl_e;
49423diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49424index 188ef2f..adcf864 100644
49425--- a/fs/xfs/xfs_bmap.c
49426+++ b/fs/xfs/xfs_bmap.c
49427@@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
49428 int nmap,
49429 int ret_nmap);
49430 #else
49431-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49432+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49433 #endif /* DEBUG */
49434
49435 STATIC int
49436diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49437index 79d05e8..e3e5861 100644
49438--- a/fs/xfs/xfs_dir2_sf.c
49439+++ b/fs/xfs/xfs_dir2_sf.c
49440@@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49441 }
49442
49443 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49444- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49445+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49446+ char name[sfep->namelen];
49447+ memcpy(name, sfep->name, sfep->namelen);
49448+ if (filldir(dirent, name, sfep->namelen,
49449+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
49450+ *offset = off & 0x7fffffff;
49451+ return 0;
49452+ }
49453+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49454 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49455 *offset = off & 0x7fffffff;
49456 return 0;
49457diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49458index 76f3ca5..f57f712 100644
49459--- a/fs/xfs/xfs_ioctl.c
49460+++ b/fs/xfs/xfs_ioctl.c
49461@@ -128,7 +128,7 @@ xfs_find_handle(
49462 }
49463
49464 error = -EFAULT;
49465- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49466+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49467 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49468 goto out_put;
49469
49470diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49471index ab30253..4d86958 100644
49472--- a/fs/xfs/xfs_iops.c
49473+++ b/fs/xfs/xfs_iops.c
49474@@ -447,7 +447,7 @@ xfs_vn_put_link(
49475 struct nameidata *nd,
49476 void *p)
49477 {
49478- char *s = nd_get_link(nd);
49479+ const char *s = nd_get_link(nd);
49480
49481 if (!IS_ERR(s))
49482 kfree(s);
49483diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49484new file mode 100644
49485index 0000000..2645296
49486--- /dev/null
49487+++ b/grsecurity/Kconfig
49488@@ -0,0 +1,1079 @@
49489+#
49490+# grecurity configuration
49491+#
49492+
49493+menu "Grsecurity"
49494+
49495+config GRKERNSEC
49496+ bool "Grsecurity"
49497+ select CRYPTO
49498+ select CRYPTO_SHA256
49499+ help
49500+ If you say Y here, you will be able to configure many features
49501+ that will enhance the security of your system. It is highly
49502+ recommended that you say Y here and read through the help
49503+ for each option so that you fully understand the features and
49504+ can evaluate their usefulness for your machine.
49505+
49506+choice
49507+ prompt "Security Level"
49508+ depends on GRKERNSEC
49509+ default GRKERNSEC_CUSTOM
49510+
49511+config GRKERNSEC_LOW
49512+ bool "Low"
49513+ select GRKERNSEC_LINK
49514+ select GRKERNSEC_FIFO
49515+ select GRKERNSEC_RANDNET
49516+ select GRKERNSEC_DMESG
49517+ select GRKERNSEC_CHROOT
49518+ select GRKERNSEC_CHROOT_CHDIR
49519+
49520+ help
49521+ If you choose this option, several of the grsecurity options will
49522+ be enabled that will give you greater protection against a number
49523+ of attacks, while assuring that none of your software will have any
49524+ conflicts with the additional security measures. If you run a lot
49525+ of unusual software, or you are having problems with the higher
49526+ security levels, you should say Y here. With this option, the
49527+ following features are enabled:
49528+
49529+ - Linking restrictions
49530+ - FIFO restrictions
49531+ - Restricted dmesg
49532+ - Enforced chdir("/") on chroot
49533+ - Runtime module disabling
49534+
49535+config GRKERNSEC_MEDIUM
49536+ bool "Medium"
49537+ select PAX
49538+ select PAX_EI_PAX
49539+ select PAX_PT_PAX_FLAGS
49540+ select PAX_HAVE_ACL_FLAGS
49541+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49542+ select GRKERNSEC_CHROOT
49543+ select GRKERNSEC_CHROOT_SYSCTL
49544+ select GRKERNSEC_LINK
49545+ select GRKERNSEC_FIFO
49546+ select GRKERNSEC_DMESG
49547+ select GRKERNSEC_RANDNET
49548+ select GRKERNSEC_FORKFAIL
49549+ select GRKERNSEC_TIME
49550+ select GRKERNSEC_SIGNAL
49551+ select GRKERNSEC_CHROOT
49552+ select GRKERNSEC_CHROOT_UNIX
49553+ select GRKERNSEC_CHROOT_MOUNT
49554+ select GRKERNSEC_CHROOT_PIVOT
49555+ select GRKERNSEC_CHROOT_DOUBLE
49556+ select GRKERNSEC_CHROOT_CHDIR
49557+ select GRKERNSEC_CHROOT_MKNOD
49558+ select GRKERNSEC_PROC
49559+ select GRKERNSEC_PROC_USERGROUP
49560+ select PAX_RANDUSTACK
49561+ select PAX_ASLR
49562+ select PAX_RANDMMAP
49563+ select PAX_REFCOUNT if (X86 || SPARC64)
49564+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
49565+
49566+ help
49567+ If you say Y here, several features in addition to those included
49568+ in the low additional security level will be enabled. These
49569+ features provide even more security to your system, though in rare
49570+ cases they may be incompatible with very old or poorly written
49571+ software. If you enable this option, make sure that your auth
49572+ service (identd) is running as gid 1001. With this option,
49573+ the following features (in addition to those provided in the
49574+ low additional security level) will be enabled:
49575+
49576+ - Failed fork logging
49577+ - Time change logging
49578+ - Signal logging
49579+ - Deny mounts in chroot
49580+ - Deny double chrooting
49581+ - Deny sysctl writes in chroot
49582+ - Deny mknod in chroot
49583+ - Deny access to abstract AF_UNIX sockets out of chroot
49584+ - Deny pivot_root in chroot
49585+ - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
49586+ - /proc restrictions with special GID set to 10 (usually wheel)
49587+ - Address Space Layout Randomization (ASLR)
49588+ - Prevent exploitation of most refcount overflows
49589+ - Bounds checking of copying between the kernel and userland
49590+
49591+config GRKERNSEC_HIGH
49592+ bool "High"
49593+ select GRKERNSEC_LINK
49594+ select GRKERNSEC_FIFO
49595+ select GRKERNSEC_DMESG
49596+ select GRKERNSEC_FORKFAIL
49597+ select GRKERNSEC_TIME
49598+ select GRKERNSEC_SIGNAL
49599+ select GRKERNSEC_CHROOT
49600+ select GRKERNSEC_CHROOT_SHMAT
49601+ select GRKERNSEC_CHROOT_UNIX
49602+ select GRKERNSEC_CHROOT_MOUNT
49603+ select GRKERNSEC_CHROOT_FCHDIR
49604+ select GRKERNSEC_CHROOT_PIVOT
49605+ select GRKERNSEC_CHROOT_DOUBLE
49606+ select GRKERNSEC_CHROOT_CHDIR
49607+ select GRKERNSEC_CHROOT_MKNOD
49608+ select GRKERNSEC_CHROOT_CAPS
49609+ select GRKERNSEC_CHROOT_SYSCTL
49610+ select GRKERNSEC_CHROOT_FINDTASK
49611+ select GRKERNSEC_SYSFS_RESTRICT
49612+ select GRKERNSEC_PROC
49613+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49614+ select GRKERNSEC_HIDESYM
49615+ select GRKERNSEC_BRUTE
49616+ select GRKERNSEC_PROC_USERGROUP
49617+ select GRKERNSEC_KMEM
49618+ select GRKERNSEC_RESLOG
49619+ select GRKERNSEC_RANDNET
49620+ select GRKERNSEC_PROC_ADD
49621+ select GRKERNSEC_CHROOT_CHMOD
49622+ select GRKERNSEC_CHROOT_NICE
49623+ select GRKERNSEC_SETXID if (X86 || SPARC64 || PPC || ARM || MIPS)
49624+ select GRKERNSEC_AUDIT_MOUNT
49625+ select GRKERNSEC_MODHARDEN if (MODULES)
49626+ select GRKERNSEC_HARDEN_PTRACE
49627+ select GRKERNSEC_PTRACE_READEXEC
49628+ select GRKERNSEC_VM86 if (X86_32)
49629+ select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
49630+ select PAX
49631+ select PAX_RANDUSTACK
49632+ select PAX_ASLR
49633+ select PAX_RANDMMAP
49634+ select PAX_NOEXEC
49635+ select PAX_MPROTECT
49636+ select PAX_EI_PAX
49637+ select PAX_PT_PAX_FLAGS
49638+ select PAX_HAVE_ACL_FLAGS
49639+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
49640+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
49641+ select PAX_RANDKSTACK if (X86_TSC && X86)
49642+ select PAX_SEGMEXEC if (X86_32)
49643+ select PAX_PAGEEXEC
49644+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
49645+ select PAX_EMUTRAMP if (PARISC)
49646+ select PAX_EMUSIGRT if (PARISC)
49647+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
49648+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
49649+ select PAX_REFCOUNT if (X86 || SPARC64)
49650+ select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
49651+ help
49652+ If you say Y here, many of the features of grsecurity will be
49653+ enabled, which will protect you against many kinds of attacks
49654+ against your system. The heightened security comes at a cost
49655+ of an increased chance of incompatibilities with rare software
49656+ on your machine. Since this security level enables PaX, you should
49657+ view <http://pax.grsecurity.net> and read about the PaX
49658+ project. While you are there, download chpax and run it on
49659+ binaries that cause problems with PaX. Also remember that
49660+ since the /proc restrictions are enabled, you must run your
49661+ identd as gid 1001. This security level enables the following
49662+ features in addition to those listed in the low and medium
49663+ security levels:
49664+
49665+ - Additional /proc restrictions
49666+ - Chmod restrictions in chroot
49667+ - No signals, ptrace, or viewing of processes outside of chroot
49668+ - Capability restrictions in chroot
49669+ - Deny fchdir out of chroot
49670+ - Priority restrictions in chroot
49671+ - Segmentation-based implementation of PaX
49672+ - Mprotect restrictions
49673+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
49674+ - Kernel stack randomization
49675+ - Mount/unmount/remount logging
49676+ - Kernel symbol hiding
49677+ - Hardening of module auto-loading
49678+ - Ptrace restrictions
49679+ - Restricted vm86 mode
49680+ - Restricted sysfs/debugfs
49681+ - Active kernel exploit response
49682+
49683+config GRKERNSEC_CUSTOM
49684+ bool "Custom"
49685+ help
49686+ If you say Y here, you will be able to configure every grsecurity
49687+ option, which allows you to enable many more features that aren't
49688+ covered in the basic security levels. These additional features
49689+ include TPE, socket restrictions, and the sysctl system for
49690+ grsecurity. It is advised that you read through the help for
49691+ each option to determine its usefulness in your situation.
49692+
49693+endchoice
49694+
49695+menu "Memory Protections"
49696+depends on GRKERNSEC
49697+
49698+config GRKERNSEC_KMEM
49699+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49700+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49701+ help
49702+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49703+ be written to or read from to modify or leak the contents of the running
49704+ kernel. /dev/port will also not be allowed to be opened. If you have module
49705+ support disabled, enabling this will close up four ways that are
49706+ currently used to insert malicious code into the running kernel.
49707+ Even with all these features enabled, we still highly recommend that
49708+ you use the RBAC system, as it is still possible for an attacker to
49709+ modify the running kernel through privileged I/O granted by ioperm/iopl.
49710+ If you are not using XFree86, you may be able to stop this additional
49711+ case by enabling the 'Disable privileged I/O' option. Though nothing
49712+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
49713+ but only to video memory, which is the only writing we allow in this
49714+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
49715+ not be allowed to mprotect it with PROT_WRITE later.
49716+ It is highly recommended that you say Y here if you meet all the
49717+ conditions above.
49718+
49719+config GRKERNSEC_VM86
49720+ bool "Restrict VM86 mode"
49721+ depends on X86_32
49722+
49723+ help
49724+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
49725+ make use of a special execution mode on 32bit x86 processors called
49726+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
49727+ video cards and will still work with this option enabled. The purpose
49728+ of the option is to prevent exploitation of emulation errors in
49729+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
49730+ Nearly all users should be able to enable this option.
49731+
49732+config GRKERNSEC_IO
49733+ bool "Disable privileged I/O"
49734+ depends on X86
49735+ select RTC_CLASS
49736+ select RTC_INTF_DEV
49737+ select RTC_DRV_CMOS
49738+
49739+ help
49740+ If you say Y here, all ioperm and iopl calls will return an error.
49741+ Ioperm and iopl can be used to modify the running kernel.
49742+ Unfortunately, some programs need this access to operate properly,
49743+ the most notable of which are XFree86 and hwclock. hwclock can be
49744+ remedied by having RTC support in the kernel, so real-time
49745+ clock support is enabled if this option is enabled, to ensure
49746+ that hwclock operates correctly. XFree86 still will not
49747+ operate correctly with this option enabled, so DO NOT CHOOSE Y
49748+ IF YOU USE XFree86. If you use XFree86 and you still want to
49749+ protect your kernel against modification, use the RBAC system.
49750+
49751+config GRKERNSEC_PROC_MEMMAP
49752+ bool "Harden ASLR against information leaks and entropy reduction"
49753+ default y if (PAX_NOEXEC || PAX_ASLR)
49754+ depends on PAX_NOEXEC || PAX_ASLR
49755+ help
49756+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
49757+ give no information about the addresses of its mappings if
49758+ PaX features that rely on random addresses are enabled on the task.
49759+ In addition to sanitizing this information and disabling other
49760+ dangerous sources of information, this option causes reads of sensitive
49761+ /proc/<pid> entries where the file descriptor was opened in a different
49762+ task than the one performing the read. Such attempts are logged.
49763+ This option also limits argv/env strings for suid/sgid binaries
49764+ to 512KB to prevent a complete exhaustion of the stack entropy provided
49765+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
49766+ binaries to prevent alternative mmap layouts from being abused.
49767+
49768+ If you use PaX it is essential that you say Y here as it closes up
49769+ several holes that make full ASLR useless locally.
49770+
49771+config GRKERNSEC_BRUTE
49772+ bool "Deter exploit bruteforcing"
49773+ help
49774+ If you say Y here, attempts to bruteforce exploits against forking
49775+ daemons such as apache or sshd, as well as against suid/sgid binaries
49776+ will be deterred. When a child of a forking daemon is killed by PaX
49777+ or crashes due to an illegal instruction or other suspicious signal,
49778+ the parent process will be delayed 30 seconds upon every subsequent
49779+ fork until the administrator is able to assess the situation and
49780+ restart the daemon.
49781+ In the suid/sgid case, the attempt is logged, the user has all their
49782+ processes terminated, and they are prevented from executing any further
49783+ processes for 15 minutes.
49784+ It is recommended that you also enable signal logging in the auditing
49785+ section so that logs are generated when a process triggers a suspicious
49786+ signal.
49787+ If the sysctl option is enabled, a sysctl option with name
49788+ "deter_bruteforce" is created.
49789+
49790+
49791+config GRKERNSEC_MODHARDEN
49792+ bool "Harden module auto-loading"
49793+ depends on MODULES
49794+ help
49795+ If you say Y here, module auto-loading in response to use of some
49796+ feature implemented by an unloaded module will be restricted to
49797+ root users. Enabling this option helps defend against attacks
49798+ by unprivileged users who abuse the auto-loading behavior to
49799+ cause a vulnerable module to load that is then exploited.
49800+
49801+ If this option prevents a legitimate use of auto-loading for a
49802+ non-root user, the administrator can execute modprobe manually
49803+ with the exact name of the module mentioned in the alert log.
49804+ Alternatively, the administrator can add the module to the list
49805+ of modules loaded at boot by modifying init scripts.
49806+
49807+ Modification of init scripts will most likely be needed on
49808+ Ubuntu servers with encrypted home directory support enabled,
49809+ as the first non-root user logging in will cause the ecb(aes),
49810+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
49811+
49812+config GRKERNSEC_HIDESYM
49813+ bool "Hide kernel symbols"
49814+ help
49815+ If you say Y here, getting information on loaded modules, and
49816+ displaying all kernel symbols through a syscall will be restricted
49817+ to users with CAP_SYS_MODULE. For software compatibility reasons,
49818+ /proc/kallsyms will be restricted to the root user. The RBAC
49819+ system can hide that entry even from root.
49820+
49821+ This option also prevents leaking of kernel addresses through
49822+ several /proc entries.
49823+
49824+ Note that this option is only effective provided the following
49825+ conditions are met:
49826+ 1) The kernel using grsecurity is not precompiled by some distribution
49827+ 2) You have also enabled GRKERNSEC_DMESG
49828+ 3) You are using the RBAC system and hiding other files such as your
49829+ kernel image and System.map. Alternatively, enabling this option
49830+ causes the permissions on /boot, /lib/modules, and the kernel
49831+ source directory to change at compile time to prevent
49832+ reading by non-root users.
49833+ If the above conditions are met, this option will aid in providing a
49834+ useful protection against local kernel exploitation of overflows
49835+ and arbitrary read/write vulnerabilities.
49836+
49837+config GRKERNSEC_KERN_LOCKOUT
49838+ bool "Active kernel exploit response"
49839+ depends on X86 || ARM || PPC || SPARC
49840+ help
49841+ If you say Y here, when a PaX alert is triggered due to suspicious
49842+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
49843+ or an OOPs occurs due to bad memory accesses, instead of just
49844+ terminating the offending process (and potentially allowing
49845+ a subsequent exploit from the same user), we will take one of two
49846+ actions:
49847+ If the user was root, we will panic the system
49848+ If the user was non-root, we will log the attempt, terminate
49849+ all processes owned by the user, then prevent them from creating
49850+ any new processes until the system is restarted
49851+ This deters repeated kernel exploitation/bruteforcing attempts
49852+ and is useful for later forensics.
49853+
49854+endmenu
49855+menu "Role Based Access Control Options"
49856+depends on GRKERNSEC
49857+
49858+config GRKERNSEC_RBAC_DEBUG
49859+ bool
49860+
49861+config GRKERNSEC_NO_RBAC
49862+ bool "Disable RBAC system"
49863+ help
49864+ If you say Y here, the /dev/grsec device will be removed from the kernel,
49865+ preventing the RBAC system from being enabled. You should only say Y
49866+ here if you have no intention of using the RBAC system, so as to prevent
49867+ an attacker with root access from misusing the RBAC system to hide files
49868+ and processes when loadable module support and /dev/[k]mem have been
49869+ locked down.
49870+
49871+config GRKERNSEC_ACL_HIDEKERN
49872+ bool "Hide kernel processes"
49873+ help
49874+ If you say Y here, all kernel threads will be hidden to all
49875+ processes but those whose subject has the "view hidden processes"
49876+ flag.
49877+
49878+config GRKERNSEC_ACL_MAXTRIES
49879+ int "Maximum tries before password lockout"
49880+ default 3
49881+ help
49882+ This option enforces the maximum number of times a user can attempt
49883+ to authorize themselves with the grsecurity RBAC system before being
49884+ denied the ability to attempt authorization again for a specified time.
49885+ The lower the number, the harder it will be to brute-force a password.
49886+
49887+config GRKERNSEC_ACL_TIMEOUT
49888+ int "Time to wait after max password tries, in seconds"
49889+ default 30
49890+ help
49891+ This option specifies the time the user must wait after attempting to
49892+ authorize to the RBAC system with the maximum number of invalid
49893+ passwords. The higher the number, the harder it will be to brute-force
49894+ a password.
49895+
49896+endmenu
49897+menu "Filesystem Protections"
49898+depends on GRKERNSEC
49899+
49900+config GRKERNSEC_PROC
49901+ bool "Proc restrictions"
49902+ help
49903+ If you say Y here, the permissions of the /proc filesystem
49904+ will be altered to enhance system security and privacy. You MUST
49905+ choose either a user only restriction or a user and group restriction.
49906+ Depending upon the option you choose, you can either restrict users to
49907+ see only the processes they themselves run, or choose a group that can
49908+ view all processes and files normally restricted to root if you choose
49909+ the "restrict to user only" option. NOTE: If you're running identd or
49910+ ntpd as a non-root user, you will have to run it as the group you
49911+ specify here.
49912+
49913+config GRKERNSEC_PROC_USER
49914+ bool "Restrict /proc to user only"
49915+ depends on GRKERNSEC_PROC
49916+ help
49917+ If you say Y here, non-root users will only be able to view their own
49918+ processes, and restricts them from viewing network-related information,
49919+ and viewing kernel symbol and module information.
49920+
49921+config GRKERNSEC_PROC_USERGROUP
49922+ bool "Allow special group"
49923+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
49924+ help
49925+ If you say Y here, you will be able to select a group that will be
49926+ able to view all processes and network-related information. If you've
49927+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
49928+ remain hidden. This option is useful if you want to run identd as
49929+ a non-root user.
49930+
49931+config GRKERNSEC_PROC_GID
49932+ int "GID for special group"
49933+ depends on GRKERNSEC_PROC_USERGROUP
49934+ default 1001
49935+
49936+config GRKERNSEC_PROC_ADD
49937+ bool "Additional restrictions"
49938+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
49939+ help
49940+ If you say Y here, additional restrictions will be placed on
49941+ /proc that keep normal users from viewing device information and
49942+ slabinfo information that could be useful for exploits.
49943+
49944+config GRKERNSEC_LINK
49945+ bool "Linking restrictions"
49946+ help
49947+ If you say Y here, /tmp race exploits will be prevented, since users
49948+ will no longer be able to follow symlinks owned by other users in
49949+ world-writable +t directories (e.g. /tmp), unless the owner of the
49950+ symlink is the owner of the directory. users will also not be
49951+ able to hardlink to files they do not own. If the sysctl option is
49952+ enabled, a sysctl option with name "linking_restrictions" is created.
49953+
49954+config GRKERNSEC_FIFO
49955+ bool "FIFO restrictions"
49956+ help
49957+ If you say Y here, users will not be able to write to FIFOs they don't
49958+ own in world-writable +t directories (e.g. /tmp), unless the owner of
49959+ the FIFO is the same owner of the directory it's held in. If the sysctl
49960+ option is enabled, a sysctl option with name "fifo_restrictions" is
49961+ created.
49962+
49963+config GRKERNSEC_SYSFS_RESTRICT
49964+ bool "Sysfs/debugfs restriction"
49965+ depends on SYSFS
49966+ help
49967+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
49968+ any filesystem normally mounted under it (e.g. debugfs) will be
49969+ mostly accessible only by root. These filesystems generally provide access
49970+ to hardware and debug information that isn't appropriate for unprivileged
49971+ users of the system. Sysfs and debugfs have also become a large source
49972+ of new vulnerabilities, ranging from infoleaks to local compromise.
49973+ There has been very little oversight with an eye toward security involved
49974+ in adding new exporters of information to these filesystems, so their
49975+ use is discouraged.
49976+ For reasons of compatibility, a few directories have been whitelisted
49977+ for access by non-root users:
49978+ /sys/fs/selinux
49979+ /sys/fs/fuse
49980+ /sys/devices/system/cpu
49981+
49982+config GRKERNSEC_ROFS
49983+ bool "Runtime read-only mount protection"
49984+ help
49985+ If you say Y here, a sysctl option with name "romount_protect" will
49986+ be created. By setting this option to 1 at runtime, filesystems
49987+ will be protected in the following ways:
49988+ * No new writable mounts will be allowed
49989+ * Existing read-only mounts won't be able to be remounted read/write
49990+ * Write operations will be denied on all block devices
49991+ This option acts independently of grsec_lock: once it is set to 1,
49992+ it cannot be turned off. Therefore, please be mindful of the resulting
49993+ behavior if this option is enabled in an init script on a read-only
49994+ filesystem. This feature is mainly intended for secure embedded systems.
49995+
49996+config GRKERNSEC_CHROOT
49997+ bool "Chroot jail restrictions"
49998+ help
49999+ If you say Y here, you will be able to choose several options that will
50000+ make breaking out of a chrooted jail much more difficult. If you
50001+ encounter no software incompatibilities with the following options, it
50002+ is recommended that you enable each one.
50003+
50004+config GRKERNSEC_CHROOT_MOUNT
50005+ bool "Deny mounts"
50006+ depends on GRKERNSEC_CHROOT
50007+ help
50008+ If you say Y here, processes inside a chroot will not be able to
50009+ mount or remount filesystems. If the sysctl option is enabled, a
50010+ sysctl option with name "chroot_deny_mount" is created.
50011+
50012+config GRKERNSEC_CHROOT_DOUBLE
50013+ bool "Deny double-chroots"
50014+ depends on GRKERNSEC_CHROOT
50015+ help
50016+ If you say Y here, processes inside a chroot will not be able to chroot
50017+ again outside the chroot. This is a widely used method of breaking
50018+ out of a chroot jail and should not be allowed. If the sysctl
50019+ option is enabled, a sysctl option with name
50020+ "chroot_deny_chroot" is created.
50021+
50022+config GRKERNSEC_CHROOT_PIVOT
50023+ bool "Deny pivot_root in chroot"
50024+ depends on GRKERNSEC_CHROOT
50025+ help
50026+ If you say Y here, processes inside a chroot will not be able to use
50027+ a function called pivot_root() that was introduced in Linux 2.3.41. It
50028+ works similar to chroot in that it changes the root filesystem. This
50029+ function could be misused in a chrooted process to attempt to break out
50030+ of the chroot, and therefore should not be allowed. If the sysctl
50031+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
50032+ created.
50033+
50034+config GRKERNSEC_CHROOT_CHDIR
50035+ bool "Enforce chdir(\"/\") on all chroots"
50036+ depends on GRKERNSEC_CHROOT
50037+ help
50038+ If you say Y here, the current working directory of all newly-chrooted
50039+ applications will be set to the the root directory of the chroot.
50040+ The man page on chroot(2) states:
50041+ Note that this call does not change the current working
50042+ directory, so that `.' can be outside the tree rooted at
50043+ `/'. In particular, the super-user can escape from a
50044+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50045+
50046+ It is recommended that you say Y here, since it's not known to break
50047+ any software. If the sysctl option is enabled, a sysctl option with
50048+ name "chroot_enforce_chdir" is created.
50049+
50050+config GRKERNSEC_CHROOT_CHMOD
50051+ bool "Deny (f)chmod +s"
50052+ depends on GRKERNSEC_CHROOT
50053+ help
50054+ If you say Y here, processes inside a chroot will not be able to chmod
50055+ or fchmod files to make them have suid or sgid bits. This protects
50056+ against another published method of breaking a chroot. If the sysctl
50057+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
50058+ created.
50059+
50060+config GRKERNSEC_CHROOT_FCHDIR
50061+ bool "Deny fchdir out of chroot"
50062+ depends on GRKERNSEC_CHROOT
50063+ help
50064+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
50065+ to a file descriptor of the chrooting process that points to a directory
50066+ outside the filesystem will be stopped. If the sysctl option
50067+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50068+
50069+config GRKERNSEC_CHROOT_MKNOD
50070+ bool "Deny mknod"
50071+ depends on GRKERNSEC_CHROOT
50072+ help
50073+ If you say Y here, processes inside a chroot will not be allowed to
50074+ mknod. The problem with using mknod inside a chroot is that it
50075+ would allow an attacker to create a device entry that is the same
50076+ as one on the physical root of your system, which could range from
50077+ anything from the console device to a device for your harddrive (which
50078+ they could then use to wipe the drive or steal data). It is recommended
50079+ that you say Y here, unless you run into software incompatibilities.
50080+ If the sysctl option is enabled, a sysctl option with name
50081+ "chroot_deny_mknod" is created.
50082+
50083+config GRKERNSEC_CHROOT_SHMAT
50084+ bool "Deny shmat() out of chroot"
50085+ depends on GRKERNSEC_CHROOT
50086+ help
50087+ If you say Y here, processes inside a chroot will not be able to attach
50088+ to shared memory segments that were created outside of the chroot jail.
50089+ It is recommended that you say Y here. If the sysctl option is enabled,
50090+ a sysctl option with name "chroot_deny_shmat" is created.
50091+
50092+config GRKERNSEC_CHROOT_UNIX
50093+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
50094+ depends on GRKERNSEC_CHROOT
50095+ help
50096+ If you say Y here, processes inside a chroot will not be able to
50097+ connect to abstract (meaning not belonging to a filesystem) Unix
50098+ domain sockets that were bound outside of a chroot. It is recommended
50099+ that you say Y here. If the sysctl option is enabled, a sysctl option
50100+ with name "chroot_deny_unix" is created.
50101+
50102+config GRKERNSEC_CHROOT_FINDTASK
50103+ bool "Protect outside processes"
50104+ depends on GRKERNSEC_CHROOT
50105+ help
50106+ If you say Y here, processes inside a chroot will not be able to
50107+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50108+ getsid, or view any process outside of the chroot. If the sysctl
50109+ option is enabled, a sysctl option with name "chroot_findtask" is
50110+ created.
50111+
50112+config GRKERNSEC_CHROOT_NICE
50113+ bool "Restrict priority changes"
50114+ depends on GRKERNSEC_CHROOT
50115+ help
50116+ If you say Y here, processes inside a chroot will not be able to raise
50117+ the priority of processes in the chroot, or alter the priority of
50118+ processes outside the chroot. This provides more security than simply
50119+ removing CAP_SYS_NICE from the process' capability set. If the
50120+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50121+ is created.
50122+
50123+config GRKERNSEC_CHROOT_SYSCTL
50124+ bool "Deny sysctl writes"
50125+ depends on GRKERNSEC_CHROOT
50126+ help
50127+ If you say Y here, an attacker in a chroot will not be able to
50128+ write to sysctl entries, either by sysctl(2) or through a /proc
50129+ interface. It is strongly recommended that you say Y here. If the
50130+ sysctl option is enabled, a sysctl option with name
50131+ "chroot_deny_sysctl" is created.
50132+
50133+config GRKERNSEC_CHROOT_CAPS
50134+ bool "Capability restrictions"
50135+ depends on GRKERNSEC_CHROOT
50136+ help
50137+ If you say Y here, the capabilities on all processes within a
50138+ chroot jail will be lowered to stop module insertion, raw i/o,
50139+ system and net admin tasks, rebooting the system, modifying immutable
50140+ files, modifying IPC owned by another, and changing the system time.
50141+ This is left an option because it can break some apps. Disable this
50142+ if your chrooted apps are having problems performing those kinds of
50143+ tasks. If the sysctl option is enabled, a sysctl option with
50144+ name "chroot_caps" is created.
50145+
50146+endmenu
50147+menu "Kernel Auditing"
50148+depends on GRKERNSEC
50149+
50150+config GRKERNSEC_AUDIT_GROUP
50151+ bool "Single group for auditing"
50152+ help
50153+ If you say Y here, the exec, chdir, and (un)mount logging features
50154+ will only operate on a group you specify. This option is recommended
50155+ if you only want to watch certain users instead of having a large
50156+ amount of logs from the entire system. If the sysctl option is enabled,
50157+ a sysctl option with name "audit_group" is created.
50158+
50159+config GRKERNSEC_AUDIT_GID
50160+ int "GID for auditing"
50161+ depends on GRKERNSEC_AUDIT_GROUP
50162+ default 1007
50163+
50164+config GRKERNSEC_EXECLOG
50165+ bool "Exec logging"
50166+ help
50167+ If you say Y here, all execve() calls will be logged (since the
50168+ other exec*() calls are frontends to execve(), all execution
50169+ will be logged). Useful for shell-servers that like to keep track
50170+ of their users. If the sysctl option is enabled, a sysctl option with
50171+ name "exec_logging" is created.
50172+ WARNING: This option when enabled will produce a LOT of logs, especially
50173+ on an active system.
50174+
50175+config GRKERNSEC_RESLOG
50176+ bool "Resource logging"
50177+ help
50178+ If you say Y here, all attempts to overstep resource limits will
50179+ be logged with the resource name, the requested size, and the current
50180+ limit. It is highly recommended that you say Y here. If the sysctl
50181+ option is enabled, a sysctl option with name "resource_logging" is
50182+ created. If the RBAC system is enabled, the sysctl value is ignored.
50183+
50184+config GRKERNSEC_CHROOT_EXECLOG
50185+ bool "Log execs within chroot"
50186+ help
50187+ If you say Y here, all executions inside a chroot jail will be logged
50188+ to syslog. This can cause a large amount of logs if certain
50189+ applications (eg. djb's daemontools) are installed on the system, and
50190+ is therefore left as an option. If the sysctl option is enabled, a
50191+ sysctl option with name "chroot_execlog" is created.
50192+
50193+config GRKERNSEC_AUDIT_PTRACE
50194+ bool "Ptrace logging"
50195+ help
50196+ If you say Y here, all attempts to attach to a process via ptrace
50197+ will be logged. If the sysctl option is enabled, a sysctl option
50198+ with name "audit_ptrace" is created.
50199+
50200+config GRKERNSEC_AUDIT_CHDIR
50201+ bool "Chdir logging"
50202+ help
50203+ If you say Y here, all chdir() calls will be logged. If the sysctl
50204+ option is enabled, a sysctl option with name "audit_chdir" is created.
50205+
50206+config GRKERNSEC_AUDIT_MOUNT
50207+ bool "(Un)Mount logging"
50208+ help
50209+ If you say Y here, all mounts and unmounts will be logged. If the
50210+ sysctl option is enabled, a sysctl option with name "audit_mount" is
50211+ created.
50212+
50213+config GRKERNSEC_SIGNAL
50214+ bool "Signal logging"
50215+ help
50216+ If you say Y here, certain important signals will be logged, such as
50217+ SIGSEGV, which will as a result inform you of when a error in a program
50218+ occurred, which in some cases could mean a possible exploit attempt.
50219+ If the sysctl option is enabled, a sysctl option with name
50220+ "signal_logging" is created.
50221+
50222+config GRKERNSEC_FORKFAIL
50223+ bool "Fork failure logging"
50224+ help
50225+ If you say Y here, all failed fork() attempts will be logged.
50226+ This could suggest a fork bomb, or someone attempting to overstep
50227+ their process limit. If the sysctl option is enabled, a sysctl option
50228+ with name "forkfail_logging" is created.
50229+
50230+config GRKERNSEC_TIME
50231+ bool "Time change logging"
50232+ help
50233+ If you say Y here, any changes of the system clock will be logged.
50234+ If the sysctl option is enabled, a sysctl option with name
50235+ "timechange_logging" is created.
50236+
50237+config GRKERNSEC_PROC_IPADDR
50238+ bool "/proc/<pid>/ipaddr support"
50239+ help
50240+ If you say Y here, a new entry will be added to each /proc/<pid>
50241+ directory that contains the IP address of the person using the task.
50242+ The IP is carried across local TCP and AF_UNIX stream sockets.
50243+ This information can be useful for IDS/IPSes to perform remote response
50244+ to a local attack. The entry is readable by only the owner of the
50245+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50246+ the RBAC system), and thus does not create privacy concerns.
50247+
50248+config GRKERNSEC_RWXMAP_LOG
50249+ bool 'Denied RWX mmap/mprotect logging'
50250+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50251+ help
50252+ If you say Y here, calls to mmap() and mprotect() with explicit
50253+ usage of PROT_WRITE and PROT_EXEC together will be logged when
50254+ denied by the PAX_MPROTECT feature. If the sysctl option is
50255+ enabled, a sysctl option with name "rwxmap_logging" is created.
50256+
50257+config GRKERNSEC_AUDIT_TEXTREL
50258+ bool 'ELF text relocations logging (READ HELP)'
50259+ depends on PAX_MPROTECT
50260+ help
50261+ If you say Y here, text relocations will be logged with the filename
50262+ of the offending library or binary. The purpose of the feature is
50263+ to help Linux distribution developers get rid of libraries and
50264+ binaries that need text relocations which hinder the future progress
50265+ of PaX. Only Linux distribution developers should say Y here, and
50266+ never on a production machine, as this option creates an information
50267+ leak that could aid an attacker in defeating the randomization of
50268+ a single memory region. If the sysctl option is enabled, a sysctl
50269+ option with name "audit_textrel" is created.
50270+
50271+endmenu
50272+
50273+menu "Executable Protections"
50274+depends on GRKERNSEC
50275+
50276+config GRKERNSEC_DMESG
50277+ bool "Dmesg(8) restriction"
50278+ help
50279+ If you say Y here, non-root users will not be able to use dmesg(8)
50280+ to view up to the last 4kb of messages in the kernel's log buffer.
50281+ The kernel's log buffer often contains kernel addresses and other
50282+ identifying information useful to an attacker in fingerprinting a
50283+ system for a targeted exploit.
50284+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
50285+ created.
50286+
50287+config GRKERNSEC_HARDEN_PTRACE
50288+ bool "Deter ptrace-based process snooping"
50289+ help
50290+ If you say Y here, TTY sniffers and other malicious monitoring
50291+ programs implemented through ptrace will be defeated. If you
50292+ have been using the RBAC system, this option has already been
50293+ enabled for several years for all users, with the ability to make
50294+ fine-grained exceptions.
50295+
50296+ This option only affects the ability of non-root users to ptrace
50297+ processes that are not a descendent of the ptracing process.
50298+ This means that strace ./binary and gdb ./binary will still work,
50299+ but attaching to arbitrary processes will not. If the sysctl
50300+ option is enabled, a sysctl option with name "harden_ptrace" is
50301+ created.
50302+
50303+config GRKERNSEC_PTRACE_READEXEC
50304+ bool "Require read access to ptrace sensitive binaries"
50305+ help
50306+ If you say Y here, unprivileged users will not be able to ptrace unreadable
50307+ binaries. This option is useful in environments that
50308+ remove the read bits (e.g. file mode 4711) from suid binaries to
50309+ prevent infoleaking of their contents. This option adds
50310+ consistency to the use of that file mode, as the binary could normally
50311+ be read out when run without privileges while ptracing.
50312+
50313+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50314+ is created.
50315+
50316+config GRKERNSEC_SETXID
50317+ bool "Enforce consistent multithreaded privileges"
50318+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
50319+ help
50320+ If you say Y here, a change from a root uid to a non-root uid
50321+ in a multithreaded application will cause the resulting uids,
50322+ gids, supplementary groups, and capabilities in that thread
50323+ to be propagated to the other threads of the process. In most
50324+ cases this is unnecessary, as glibc will emulate this behavior
50325+ on behalf of the application. Other libcs do not act in the
50326+ same way, allowing the other threads of the process to continue
50327+ running with root privileges. If the sysctl option is enabled,
50328+ a sysctl option with name "consistent_setxid" is created.
50329+
50330+config GRKERNSEC_TPE
50331+ bool "Trusted Path Execution (TPE)"
50332+ help
50333+ If you say Y here, you will be able to choose a gid to add to the
50334+ supplementary groups of users you want to mark as "untrusted."
50335+ These users will not be able to execute any files that are not in
50336+ root-owned directories writable only by root. If the sysctl option
50337+ is enabled, a sysctl option with name "tpe" is created.
50338+
50339+config GRKERNSEC_TPE_ALL
50340+ bool "Partially restrict all non-root users"
50341+ depends on GRKERNSEC_TPE
50342+ help
50343+ If you say Y here, all non-root users will be covered under
50344+ a weaker TPE restriction. This is separate from, and in addition to,
50345+ the main TPE options that you have selected elsewhere. Thus, if a
50346+ "trusted" GID is chosen, this restriction applies to even that GID.
50347+ Under this restriction, all non-root users will only be allowed to
50348+ execute files in directories they own that are not group or
50349+ world-writable, or in directories owned by root and writable only by
50350+ root. If the sysctl option is enabled, a sysctl option with name
50351+ "tpe_restrict_all" is created.
50352+
50353+config GRKERNSEC_TPE_INVERT
50354+ bool "Invert GID option"
50355+ depends on GRKERNSEC_TPE
50356+ help
50357+ If you say Y here, the group you specify in the TPE configuration will
50358+ decide what group TPE restrictions will be *disabled* for. This
50359+ option is useful if you want TPE restrictions to be applied to most
50360+ users on the system. If the sysctl option is enabled, a sysctl option
50361+ with name "tpe_invert" is created. Unlike other sysctl options, this
50362+ entry will default to on for backward-compatibility.
50363+
50364+config GRKERNSEC_TPE_GID
50365+ int "GID for untrusted users"
50366+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50367+ default 1005
50368+ help
50369+ Setting this GID determines what group TPE restrictions will be
50370+ *enabled* for. If the sysctl option is enabled, a sysctl option
50371+ with name "tpe_gid" is created.
50372+
50373+config GRKERNSEC_TPE_GID
50374+ int "GID for trusted users"
50375+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50376+ default 1005
50377+ help
50378+ Setting this GID determines what group TPE restrictions will be
50379+ *disabled* for. If the sysctl option is enabled, a sysctl option
50380+ with name "tpe_gid" is created.
50381+
50382+endmenu
50383+menu "Network Protections"
50384+depends on GRKERNSEC
50385+
50386+config GRKERNSEC_RANDNET
50387+ bool "Larger entropy pools"
50388+ help
50389+ If you say Y here, the entropy pools used for many features of Linux
50390+ and grsecurity will be doubled in size. Since several grsecurity
50391+ features use additional randomness, it is recommended that you say Y
50392+ here. Saying Y here has a similar effect as modifying
50393+ /proc/sys/kernel/random/poolsize.
50394+
50395+config GRKERNSEC_BLACKHOLE
50396+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50397+ depends on NET
50398+ help
50399+ If you say Y here, neither TCP resets nor ICMP
50400+ destination-unreachable packets will be sent in response to packets
50401+ sent to ports for which no associated listening process exists.
50402+ This feature supports both IPV4 and IPV6 and exempts the
50403+ loopback interface from blackholing. Enabling this feature
50404+ makes a host more resilient to DoS attacks and reduces network
50405+ visibility against scanners.
50406+
50407+ The blackhole feature as-implemented is equivalent to the FreeBSD
50408+ blackhole feature, as it prevents RST responses to all packets, not
50409+ just SYNs. Under most application behavior this causes no
50410+ problems, but applications (like haproxy) may not close certain
50411+ connections in a way that cleanly terminates them on the remote
50412+ end, leaving the remote host in LAST_ACK state. Because of this
50413+ side-effect and to prevent intentional LAST_ACK DoSes, this
50414+ feature also adds automatic mitigation against such attacks.
50415+ The mitigation drastically reduces the amount of time a socket
50416+ can spend in LAST_ACK state. If you're using haproxy and not
50417+ all servers it connects to have this option enabled, consider
50418+ disabling this feature on the haproxy host.
50419+
50420+ If the sysctl option is enabled, two sysctl options with names
50421+ "ip_blackhole" and "lastack_retries" will be created.
50422+ While "ip_blackhole" takes the standard zero/non-zero on/off
50423+ toggle, "lastack_retries" uses the same kinds of values as
50424+ "tcp_retries1" and "tcp_retries2". The default value of 4
50425+ prevents a socket from lasting more than 45 seconds in LAST_ACK
50426+ state.
50427+
50428+config GRKERNSEC_SOCKET
50429+ bool "Socket restrictions"
50430+ depends on NET
50431+ help
50432+ If you say Y here, you will be able to choose from several options.
50433+ If you assign a GID on your system and add it to the supplementary
50434+ groups of users you want to restrict socket access to, this patch
50435+ will perform up to three things, based on the option(s) you choose.
50436+
50437+config GRKERNSEC_SOCKET_ALL
50438+ bool "Deny any sockets to group"
50439+ depends on GRKERNSEC_SOCKET
50440+ help
50441+ If you say Y here, you will be able to choose a GID of whose users will
50442+ be unable to connect to other hosts from your machine or run server
50443+ applications from your machine. If the sysctl option is enabled, a
50444+ sysctl option with name "socket_all" is created.
50445+
50446+config GRKERNSEC_SOCKET_ALL_GID
50447+ int "GID to deny all sockets for"
50448+ depends on GRKERNSEC_SOCKET_ALL
50449+ default 1004
50450+ help
50451+ Here you can choose the GID to disable socket access for. Remember to
50452+ add the users you want socket access disabled for to the GID
50453+ specified here. If the sysctl option is enabled, a sysctl option
50454+ with name "socket_all_gid" is created.
50455+
50456+config GRKERNSEC_SOCKET_CLIENT
50457+ bool "Deny client sockets to group"
50458+ depends on GRKERNSEC_SOCKET
50459+ help
50460+ If you say Y here, you will be able to choose a GID of whose users will
50461+ be unable to connect to other hosts from your machine, but will be
50462+ able to run servers. If this option is enabled, all users in the group
50463+ you specify will have to use passive mode when initiating ftp transfers
50464+ from the shell on your machine. If the sysctl option is enabled, a
50465+ sysctl option with name "socket_client" is created.
50466+
50467+config GRKERNSEC_SOCKET_CLIENT_GID
50468+ int "GID to deny client sockets for"
50469+ depends on GRKERNSEC_SOCKET_CLIENT
50470+ default 1003
50471+ help
50472+ Here you can choose the GID to disable client socket access for.
50473+ Remember to add the users you want client socket access disabled for to
50474+ the GID specified here. If the sysctl option is enabled, a sysctl
50475+ option with name "socket_client_gid" is created.
50476+
50477+config GRKERNSEC_SOCKET_SERVER
50478+ bool "Deny server sockets to group"
50479+ depends on GRKERNSEC_SOCKET
50480+ help
50481+ If you say Y here, you will be able to choose a GID of whose users will
50482+ be unable to run server applications from your machine. If the sysctl
50483+ option is enabled, a sysctl option with name "socket_server" is created.
50484+
50485+config GRKERNSEC_SOCKET_SERVER_GID
50486+ int "GID to deny server sockets for"
50487+ depends on GRKERNSEC_SOCKET_SERVER
50488+ default 1002
50489+ help
50490+ Here you can choose the GID to disable server socket access for.
50491+ Remember to add the users you want server socket access disabled for to
50492+ the GID specified here. If the sysctl option is enabled, a sysctl
50493+ option with name "socket_server_gid" is created.
50494+
50495+endmenu
50496+menu "Sysctl support"
50497+depends on GRKERNSEC && SYSCTL
50498+
50499+config GRKERNSEC_SYSCTL
50500+ bool "Sysctl support"
50501+ help
50502+ If you say Y here, you will be able to change the options that
50503+ grsecurity runs with at bootup, without having to recompile your
50504+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50505+ to enable (1) or disable (0) various features. All the sysctl entries
50506+ are mutable until the "grsec_lock" entry is set to a non-zero value.
50507+ All features enabled in the kernel configuration are disabled at boot
50508+ if you do not say Y to the "Turn on features by default" option.
50509+ All options should be set at startup, and the grsec_lock entry should
50510+ be set to a non-zero value after all the options are set.
50511+ *THIS IS EXTREMELY IMPORTANT*
50512+
50513+config GRKERNSEC_SYSCTL_DISTRO
50514+ bool "Extra sysctl support for distro makers (READ HELP)"
50515+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50516+ help
50517+ If you say Y here, additional sysctl options will be created
50518+ for features that affect processes running as root. Therefore,
50519+ it is critical when using this option that the grsec_lock entry be
50520+ enabled after boot. Only distros with prebuilt kernel packages
50521+ with this option enabled that can ensure grsec_lock is enabled
50522+ after boot should use this option.
50523+ *Failure to set grsec_lock after boot makes all grsec features
50524+ this option covers useless*
50525+
50526+ Currently this option creates the following sysctl entries:
50527+ "Disable Privileged I/O": "disable_priv_io"
50528+
50529+config GRKERNSEC_SYSCTL_ON
50530+ bool "Turn on features by default"
50531+ depends on GRKERNSEC_SYSCTL
50532+ help
50533+ If you say Y here, instead of having all features enabled in the
50534+ kernel configuration disabled at boot time, the features will be
50535+ enabled at boot time. It is recommended you say Y here unless
50536+ there is some reason you would want all sysctl-tunable features to
50537+ be disabled by default. As mentioned elsewhere, it is important
50538+ to enable the grsec_lock entry once you have finished modifying
50539+ the sysctl entries.
50540+
50541+endmenu
50542+menu "Logging Options"
50543+depends on GRKERNSEC
50544+
50545+config GRKERNSEC_FLOODTIME
50546+ int "Seconds in between log messages (minimum)"
50547+ default 10
50548+ help
50549+ This option allows you to enforce the number of seconds between
50550+ grsecurity log messages. The default should be suitable for most
50551+ people, however, if you choose to change it, choose a value small enough
50552+ to allow informative logs to be produced, but large enough to
50553+ prevent flooding.
50554+
50555+config GRKERNSEC_FLOODBURST
50556+ int "Number of messages in a burst (maximum)"
50557+ default 6
50558+ help
50559+ This option allows you to choose the maximum number of messages allowed
50560+ within the flood time interval you chose in a separate option. The
50561+ default should be suitable for most people, however if you find that
50562+ many of your logs are being interpreted as flooding, you may want to
50563+ raise this value.
50564+
50565+endmenu
50566+
50567+endmenu
50568diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50569new file mode 100644
50570index 0000000..1b9afa9
50571--- /dev/null
50572+++ b/grsecurity/Makefile
50573@@ -0,0 +1,38 @@
50574+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50575+# during 2001-2009 it has been completely redesigned by Brad Spengler
50576+# into an RBAC system
50577+#
50578+# All code in this directory and various hooks inserted throughout the kernel
50579+# are copyright Brad Spengler - Open Source Security, Inc., and released
50580+# under the GPL v2 or higher
50581+
50582+KBUILD_CFLAGS += -Werror
50583+
50584+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50585+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
50586+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50587+
50588+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50589+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50590+ gracl_learn.o grsec_log.o
50591+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50592+
50593+ifdef CONFIG_NET
50594+obj-y += grsec_sock.o
50595+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50596+endif
50597+
50598+ifndef CONFIG_GRKERNSEC
50599+obj-y += grsec_disabled.o
50600+endif
50601+
50602+ifdef CONFIG_GRKERNSEC_HIDESYM
50603+extra-y := grsec_hidesym.o
50604+$(obj)/grsec_hidesym.o:
50605+ @-chmod -f 500 /boot
50606+ @-chmod -f 500 /lib/modules
50607+ @-chmod -f 500 /lib64/modules
50608+ @-chmod -f 500 /lib32/modules
50609+ @-chmod -f 700 .
50610+ @echo ' grsec: protected kernel image paths'
50611+endif
50612diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50613new file mode 100644
50614index 0000000..a6d83f0
50615--- /dev/null
50616+++ b/grsecurity/gracl.c
50617@@ -0,0 +1,4193 @@
50618+#include <linux/kernel.h>
50619+#include <linux/module.h>
50620+#include <linux/sched.h>
50621+#include <linux/mm.h>
50622+#include <linux/file.h>
50623+#include <linux/fs.h>
50624+#include <linux/namei.h>
50625+#include <linux/mount.h>
50626+#include <linux/tty.h>
50627+#include <linux/proc_fs.h>
50628+#include <linux/lglock.h>
50629+#include <linux/slab.h>
50630+#include <linux/vmalloc.h>
50631+#include <linux/types.h>
50632+#include <linux/sysctl.h>
50633+#include <linux/netdevice.h>
50634+#include <linux/ptrace.h>
50635+#include <linux/gracl.h>
50636+#include <linux/gralloc.h>
50637+#include <linux/security.h>
50638+#include <linux/grinternal.h>
50639+#include <linux/pid_namespace.h>
50640+#include <linux/fdtable.h>
50641+#include <linux/percpu.h>
50642+#include "../fs/mount.h"
50643+
50644+#include <asm/uaccess.h>
50645+#include <asm/errno.h>
50646+#include <asm/mman.h>
50647+
50648+static struct acl_role_db acl_role_set;
50649+static struct name_db name_set;
50650+static struct inodev_db inodev_set;
50651+
50652+/* for keeping track of userspace pointers used for subjects, so we
50653+ can share references in the kernel as well
50654+*/
50655+
50656+static struct path real_root;
50657+
50658+static struct acl_subj_map_db subj_map_set;
50659+
50660+static struct acl_role_label *default_role;
50661+
50662+static struct acl_role_label *role_list;
50663+
50664+static u16 acl_sp_role_value;
50665+
50666+extern char *gr_shared_page[4];
50667+static DEFINE_MUTEX(gr_dev_mutex);
50668+DEFINE_RWLOCK(gr_inode_lock);
50669+
50670+struct gr_arg *gr_usermode;
50671+
50672+static unsigned int gr_status __read_only = GR_STATUS_INIT;
50673+
50674+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
50675+extern void gr_clear_learn_entries(void);
50676+
50677+#ifdef CONFIG_GRKERNSEC_RESLOG
50678+extern void gr_log_resource(const struct task_struct *task,
50679+ const int res, const unsigned long wanted, const int gt);
50680+#endif
50681+
50682+unsigned char *gr_system_salt;
50683+unsigned char *gr_system_sum;
50684+
50685+static struct sprole_pw **acl_special_roles = NULL;
50686+static __u16 num_sprole_pws = 0;
50687+
50688+static struct acl_role_label *kernel_role = NULL;
50689+
50690+static unsigned int gr_auth_attempts = 0;
50691+static unsigned long gr_auth_expires = 0UL;
50692+
50693+#ifdef CONFIG_NET
50694+extern struct vfsmount *sock_mnt;
50695+#endif
50696+
50697+extern struct vfsmount *pipe_mnt;
50698+extern struct vfsmount *shm_mnt;
50699+#ifdef CONFIG_HUGETLBFS
50700+extern struct vfsmount *hugetlbfs_vfsmount;
50701+#endif
50702+
50703+static struct acl_object_label *fakefs_obj_rw;
50704+static struct acl_object_label *fakefs_obj_rwx;
50705+
50706+extern int gr_init_uidset(void);
50707+extern void gr_free_uidset(void);
50708+extern void gr_remove_uid(uid_t uid);
50709+extern int gr_find_uid(uid_t uid);
50710+
50711+DECLARE_BRLOCK(vfsmount_lock);
50712+
50713+__inline__ int
50714+gr_acl_is_enabled(void)
50715+{
50716+ return (gr_status & GR_READY);
50717+}
50718+
50719+#ifdef CONFIG_BTRFS_FS
50720+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
50721+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
50722+#endif
50723+
50724+static inline dev_t __get_dev(const struct dentry *dentry)
50725+{
50726+#ifdef CONFIG_BTRFS_FS
50727+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
50728+ return get_btrfs_dev_from_inode(dentry->d_inode);
50729+ else
50730+#endif
50731+ return dentry->d_inode->i_sb->s_dev;
50732+}
50733+
50734+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50735+{
50736+ return __get_dev(dentry);
50737+}
50738+
50739+static char gr_task_roletype_to_char(struct task_struct *task)
50740+{
50741+ switch (task->role->roletype &
50742+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
50743+ GR_ROLE_SPECIAL)) {
50744+ case GR_ROLE_DEFAULT:
50745+ return 'D';
50746+ case GR_ROLE_USER:
50747+ return 'U';
50748+ case GR_ROLE_GROUP:
50749+ return 'G';
50750+ case GR_ROLE_SPECIAL:
50751+ return 'S';
50752+ }
50753+
50754+ return 'X';
50755+}
50756+
50757+char gr_roletype_to_char(void)
50758+{
50759+ return gr_task_roletype_to_char(current);
50760+}
50761+
50762+__inline__ int
50763+gr_acl_tpe_check(void)
50764+{
50765+ if (unlikely(!(gr_status & GR_READY)))
50766+ return 0;
50767+ if (current->role->roletype & GR_ROLE_TPE)
50768+ return 1;
50769+ else
50770+ return 0;
50771+}
50772+
50773+int
50774+gr_handle_rawio(const struct inode *inode)
50775+{
50776+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50777+ if (inode && S_ISBLK(inode->i_mode) &&
50778+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
50779+ !capable(CAP_SYS_RAWIO))
50780+ return 1;
50781+#endif
50782+ return 0;
50783+}
50784+
50785+static int
50786+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
50787+{
50788+ if (likely(lena != lenb))
50789+ return 0;
50790+
50791+ return !memcmp(a, b, lena);
50792+}
50793+
50794+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
50795+{
50796+ *buflen -= namelen;
50797+ if (*buflen < 0)
50798+ return -ENAMETOOLONG;
50799+ *buffer -= namelen;
50800+ memcpy(*buffer, str, namelen);
50801+ return 0;
50802+}
50803+
50804+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
50805+{
50806+ return prepend(buffer, buflen, name->name, name->len);
50807+}
50808+
50809+static int prepend_path(const struct path *path, struct path *root,
50810+ char **buffer, int *buflen)
50811+{
50812+ struct dentry *dentry = path->dentry;
50813+ struct vfsmount *vfsmnt = path->mnt;
50814+ struct mount *mnt = real_mount(vfsmnt);
50815+ bool slash = false;
50816+ int error = 0;
50817+
50818+ while (dentry != root->dentry || vfsmnt != root->mnt) {
50819+ struct dentry * parent;
50820+
50821+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
50822+ /* Global root? */
50823+ if (!mnt_has_parent(mnt)) {
50824+ goto out;
50825+ }
50826+ dentry = mnt->mnt_mountpoint;
50827+ mnt = mnt->mnt_parent;
50828+ vfsmnt = &mnt->mnt;
50829+ continue;
50830+ }
50831+ parent = dentry->d_parent;
50832+ prefetch(parent);
50833+ spin_lock(&dentry->d_lock);
50834+ error = prepend_name(buffer, buflen, &dentry->d_name);
50835+ spin_unlock(&dentry->d_lock);
50836+ if (!error)
50837+ error = prepend(buffer, buflen, "/", 1);
50838+ if (error)
50839+ break;
50840+
50841+ slash = true;
50842+ dentry = parent;
50843+ }
50844+
50845+out:
50846+ if (!error && !slash)
50847+ error = prepend(buffer, buflen, "/", 1);
50848+
50849+ return error;
50850+}
50851+
50852+/* this must be called with vfsmount_lock and rename_lock held */
50853+
50854+static char *__our_d_path(const struct path *path, struct path *root,
50855+ char *buf, int buflen)
50856+{
50857+ char *res = buf + buflen;
50858+ int error;
50859+
50860+ prepend(&res, &buflen, "\0", 1);
50861+ error = prepend_path(path, root, &res, &buflen);
50862+ if (error)
50863+ return ERR_PTR(error);
50864+
50865+ return res;
50866+}
50867+
50868+static char *
50869+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
50870+{
50871+ char *retval;
50872+
50873+ retval = __our_d_path(path, root, buf, buflen);
50874+ if (unlikely(IS_ERR(retval)))
50875+ retval = strcpy(buf, "<path too long>");
50876+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
50877+ retval[1] = '\0';
50878+
50879+ return retval;
50880+}
50881+
50882+static char *
50883+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50884+ char *buf, int buflen)
50885+{
50886+ struct path path;
50887+ char *res;
50888+
50889+ path.dentry = (struct dentry *)dentry;
50890+ path.mnt = (struct vfsmount *)vfsmnt;
50891+
50892+ /* we can use real_root.dentry, real_root.mnt, because this is only called
50893+ by the RBAC system */
50894+ res = gen_full_path(&path, &real_root, buf, buflen);
50895+
50896+ return res;
50897+}
50898+
50899+static char *
50900+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50901+ char *buf, int buflen)
50902+{
50903+ char *res;
50904+ struct path path;
50905+ struct path root;
50906+ struct task_struct *reaper = &init_task;
50907+
50908+ path.dentry = (struct dentry *)dentry;
50909+ path.mnt = (struct vfsmount *)vfsmnt;
50910+
50911+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
50912+ get_fs_root(reaper->fs, &root);
50913+
50914+ write_seqlock(&rename_lock);
50915+ br_read_lock(vfsmount_lock);
50916+ res = gen_full_path(&path, &root, buf, buflen);
50917+ br_read_unlock(vfsmount_lock);
50918+ write_sequnlock(&rename_lock);
50919+
50920+ path_put(&root);
50921+ return res;
50922+}
50923+
50924+static char *
50925+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50926+{
50927+ char *ret;
50928+ write_seqlock(&rename_lock);
50929+ br_read_lock(vfsmount_lock);
50930+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50931+ PAGE_SIZE);
50932+ br_read_unlock(vfsmount_lock);
50933+ write_sequnlock(&rename_lock);
50934+ return ret;
50935+}
50936+
50937+static char *
50938+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50939+{
50940+ char *ret;
50941+ char *buf;
50942+ int buflen;
50943+
50944+ write_seqlock(&rename_lock);
50945+ br_read_lock(vfsmount_lock);
50946+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50947+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
50948+ buflen = (int)(ret - buf);
50949+ if (buflen >= 5)
50950+ prepend(&ret, &buflen, "/proc", 5);
50951+ else
50952+ ret = strcpy(buf, "<path too long>");
50953+ br_read_unlock(vfsmount_lock);
50954+ write_sequnlock(&rename_lock);
50955+ return ret;
50956+}
50957+
50958+char *
50959+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
50960+{
50961+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50962+ PAGE_SIZE);
50963+}
50964+
50965+char *
50966+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
50967+{
50968+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
50969+ PAGE_SIZE);
50970+}
50971+
50972+char *
50973+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
50974+{
50975+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
50976+ PAGE_SIZE);
50977+}
50978+
50979+char *
50980+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
50981+{
50982+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
50983+ PAGE_SIZE);
50984+}
50985+
50986+char *
50987+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
50988+{
50989+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
50990+ PAGE_SIZE);
50991+}
50992+
50993+__inline__ __u32
50994+to_gr_audit(const __u32 reqmode)
50995+{
50996+ /* masks off auditable permission flags, then shifts them to create
50997+ auditing flags, and adds the special case of append auditing if
50998+ we're requesting write */
50999+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51000+}
51001+
51002+struct acl_subject_label *
51003+lookup_subject_map(const struct acl_subject_label *userp)
51004+{
51005+ unsigned int index = shash(userp, subj_map_set.s_size);
51006+ struct subject_map *match;
51007+
51008+ match = subj_map_set.s_hash[index];
51009+
51010+ while (match && match->user != userp)
51011+ match = match->next;
51012+
51013+ if (match != NULL)
51014+ return match->kernel;
51015+ else
51016+ return NULL;
51017+}
51018+
51019+static void
51020+insert_subj_map_entry(struct subject_map *subjmap)
51021+{
51022+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51023+ struct subject_map **curr;
51024+
51025+ subjmap->prev = NULL;
51026+
51027+ curr = &subj_map_set.s_hash[index];
51028+ if (*curr != NULL)
51029+ (*curr)->prev = subjmap;
51030+
51031+ subjmap->next = *curr;
51032+ *curr = subjmap;
51033+
51034+ return;
51035+}
51036+
51037+static struct acl_role_label *
51038+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51039+ const gid_t gid)
51040+{
51041+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51042+ struct acl_role_label *match;
51043+ struct role_allowed_ip *ipp;
51044+ unsigned int x;
51045+ u32 curr_ip = task->signal->curr_ip;
51046+
51047+ task->signal->saved_ip = curr_ip;
51048+
51049+ match = acl_role_set.r_hash[index];
51050+
51051+ while (match) {
51052+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51053+ for (x = 0; x < match->domain_child_num; x++) {
51054+ if (match->domain_children[x] == uid)
51055+ goto found;
51056+ }
51057+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51058+ break;
51059+ match = match->next;
51060+ }
51061+found:
51062+ if (match == NULL) {
51063+ try_group:
51064+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51065+ match = acl_role_set.r_hash[index];
51066+
51067+ while (match) {
51068+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51069+ for (x = 0; x < match->domain_child_num; x++) {
51070+ if (match->domain_children[x] == gid)
51071+ goto found2;
51072+ }
51073+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51074+ break;
51075+ match = match->next;
51076+ }
51077+found2:
51078+ if (match == NULL)
51079+ match = default_role;
51080+ if (match->allowed_ips == NULL)
51081+ return match;
51082+ else {
51083+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51084+ if (likely
51085+ ((ntohl(curr_ip) & ipp->netmask) ==
51086+ (ntohl(ipp->addr) & ipp->netmask)))
51087+ return match;
51088+ }
51089+ match = default_role;
51090+ }
51091+ } else if (match->allowed_ips == NULL) {
51092+ return match;
51093+ } else {
51094+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51095+ if (likely
51096+ ((ntohl(curr_ip) & ipp->netmask) ==
51097+ (ntohl(ipp->addr) & ipp->netmask)))
51098+ return match;
51099+ }
51100+ goto try_group;
51101+ }
51102+
51103+ return match;
51104+}
51105+
51106+struct acl_subject_label *
51107+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51108+ const struct acl_role_label *role)
51109+{
51110+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51111+ struct acl_subject_label *match;
51112+
51113+ match = role->subj_hash[index];
51114+
51115+ while (match && (match->inode != ino || match->device != dev ||
51116+ (match->mode & GR_DELETED))) {
51117+ match = match->next;
51118+ }
51119+
51120+ if (match && !(match->mode & GR_DELETED))
51121+ return match;
51122+ else
51123+ return NULL;
51124+}
51125+
51126+struct acl_subject_label *
51127+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51128+ const struct acl_role_label *role)
51129+{
51130+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51131+ struct acl_subject_label *match;
51132+
51133+ match = role->subj_hash[index];
51134+
51135+ while (match && (match->inode != ino || match->device != dev ||
51136+ !(match->mode & GR_DELETED))) {
51137+ match = match->next;
51138+ }
51139+
51140+ if (match && (match->mode & GR_DELETED))
51141+ return match;
51142+ else
51143+ return NULL;
51144+}
51145+
51146+static struct acl_object_label *
51147+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51148+ const struct acl_subject_label *subj)
51149+{
51150+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51151+ struct acl_object_label *match;
51152+
51153+ match = subj->obj_hash[index];
51154+
51155+ while (match && (match->inode != ino || match->device != dev ||
51156+ (match->mode & GR_DELETED))) {
51157+ match = match->next;
51158+ }
51159+
51160+ if (match && !(match->mode & GR_DELETED))
51161+ return match;
51162+ else
51163+ return NULL;
51164+}
51165+
51166+static struct acl_object_label *
51167+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51168+ const struct acl_subject_label *subj)
51169+{
51170+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51171+ struct acl_object_label *match;
51172+
51173+ match = subj->obj_hash[index];
51174+
51175+ while (match && (match->inode != ino || match->device != dev ||
51176+ !(match->mode & GR_DELETED))) {
51177+ match = match->next;
51178+ }
51179+
51180+ if (match && (match->mode & GR_DELETED))
51181+ return match;
51182+
51183+ match = subj->obj_hash[index];
51184+
51185+ while (match && (match->inode != ino || match->device != dev ||
51186+ (match->mode & GR_DELETED))) {
51187+ match = match->next;
51188+ }
51189+
51190+ if (match && !(match->mode & GR_DELETED))
51191+ return match;
51192+ else
51193+ return NULL;
51194+}
51195+
51196+static struct name_entry *
51197+lookup_name_entry(const char *name)
51198+{
51199+ unsigned int len = strlen(name);
51200+ unsigned int key = full_name_hash(name, len);
51201+ unsigned int index = key % name_set.n_size;
51202+ struct name_entry *match;
51203+
51204+ match = name_set.n_hash[index];
51205+
51206+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51207+ match = match->next;
51208+
51209+ return match;
51210+}
51211+
51212+static struct name_entry *
51213+lookup_name_entry_create(const char *name)
51214+{
51215+ unsigned int len = strlen(name);
51216+ unsigned int key = full_name_hash(name, len);
51217+ unsigned int index = key % name_set.n_size;
51218+ struct name_entry *match;
51219+
51220+ match = name_set.n_hash[index];
51221+
51222+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51223+ !match->deleted))
51224+ match = match->next;
51225+
51226+ if (match && match->deleted)
51227+ return match;
51228+
51229+ match = name_set.n_hash[index];
51230+
51231+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51232+ match->deleted))
51233+ match = match->next;
51234+
51235+ if (match && !match->deleted)
51236+ return match;
51237+ else
51238+ return NULL;
51239+}
51240+
51241+static struct inodev_entry *
51242+lookup_inodev_entry(const ino_t ino, const dev_t dev)
51243+{
51244+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
51245+ struct inodev_entry *match;
51246+
51247+ match = inodev_set.i_hash[index];
51248+
51249+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51250+ match = match->next;
51251+
51252+ return match;
51253+}
51254+
51255+static void
51256+insert_inodev_entry(struct inodev_entry *entry)
51257+{
51258+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51259+ inodev_set.i_size);
51260+ struct inodev_entry **curr;
51261+
51262+ entry->prev = NULL;
51263+
51264+ curr = &inodev_set.i_hash[index];
51265+ if (*curr != NULL)
51266+ (*curr)->prev = entry;
51267+
51268+ entry->next = *curr;
51269+ *curr = entry;
51270+
51271+ return;
51272+}
51273+
51274+static void
51275+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51276+{
51277+ unsigned int index =
51278+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51279+ struct acl_role_label **curr;
51280+ struct acl_role_label *tmp, *tmp2;
51281+
51282+ curr = &acl_role_set.r_hash[index];
51283+
51284+ /* simple case, slot is empty, just set it to our role */
51285+ if (*curr == NULL) {
51286+ *curr = role;
51287+ } else {
51288+ /* example:
51289+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
51290+ 2 -> 3
51291+ */
51292+ /* first check to see if we can already be reached via this slot */
51293+ tmp = *curr;
51294+ while (tmp && tmp != role)
51295+ tmp = tmp->next;
51296+ if (tmp == role) {
51297+ /* we don't need to add ourselves to this slot's chain */
51298+ return;
51299+ }
51300+ /* we need to add ourselves to this chain, two cases */
51301+ if (role->next == NULL) {
51302+ /* simple case, append the current chain to our role */
51303+ role->next = *curr;
51304+ *curr = role;
51305+ } else {
51306+ /* 1 -> 2 -> 3 -> 4
51307+ 2 -> 3 -> 4
51308+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51309+ */
51310+ /* trickier case: walk our role's chain until we find
51311+ the role for the start of the current slot's chain */
51312+ tmp = role;
51313+ tmp2 = *curr;
51314+ while (tmp->next && tmp->next != tmp2)
51315+ tmp = tmp->next;
51316+ if (tmp->next == tmp2) {
51317+ /* from example above, we found 3, so just
51318+ replace this slot's chain with ours */
51319+ *curr = role;
51320+ } else {
51321+ /* we didn't find a subset of our role's chain
51322+ in the current slot's chain, so append their
51323+ chain to ours, and set us as the first role in
51324+ the slot's chain
51325+
51326+ we could fold this case with the case above,
51327+ but making it explicit for clarity
51328+ */
51329+ tmp->next = tmp2;
51330+ *curr = role;
51331+ }
51332+ }
51333+ }
51334+
51335+ return;
51336+}
51337+
51338+static void
51339+insert_acl_role_label(struct acl_role_label *role)
51340+{
51341+ int i;
51342+
51343+ if (role_list == NULL) {
51344+ role_list = role;
51345+ role->prev = NULL;
51346+ } else {
51347+ role->prev = role_list;
51348+ role_list = role;
51349+ }
51350+
51351+ /* used for hash chains */
51352+ role->next = NULL;
51353+
51354+ if (role->roletype & GR_ROLE_DOMAIN) {
51355+ for (i = 0; i < role->domain_child_num; i++)
51356+ __insert_acl_role_label(role, role->domain_children[i]);
51357+ } else
51358+ __insert_acl_role_label(role, role->uidgid);
51359+}
51360+
51361+static int
51362+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51363+{
51364+ struct name_entry **curr, *nentry;
51365+ struct inodev_entry *ientry;
51366+ unsigned int len = strlen(name);
51367+ unsigned int key = full_name_hash(name, len);
51368+ unsigned int index = key % name_set.n_size;
51369+
51370+ curr = &name_set.n_hash[index];
51371+
51372+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51373+ curr = &((*curr)->next);
51374+
51375+ if (*curr != NULL)
51376+ return 1;
51377+
51378+ nentry = acl_alloc(sizeof (struct name_entry));
51379+ if (nentry == NULL)
51380+ return 0;
51381+ ientry = acl_alloc(sizeof (struct inodev_entry));
51382+ if (ientry == NULL)
51383+ return 0;
51384+ ientry->nentry = nentry;
51385+
51386+ nentry->key = key;
51387+ nentry->name = name;
51388+ nentry->inode = inode;
51389+ nentry->device = device;
51390+ nentry->len = len;
51391+ nentry->deleted = deleted;
51392+
51393+ nentry->prev = NULL;
51394+ curr = &name_set.n_hash[index];
51395+ if (*curr != NULL)
51396+ (*curr)->prev = nentry;
51397+ nentry->next = *curr;
51398+ *curr = nentry;
51399+
51400+ /* insert us into the table searchable by inode/dev */
51401+ insert_inodev_entry(ientry);
51402+
51403+ return 1;
51404+}
51405+
51406+static void
51407+insert_acl_obj_label(struct acl_object_label *obj,
51408+ struct acl_subject_label *subj)
51409+{
51410+ unsigned int index =
51411+ fhash(obj->inode, obj->device, subj->obj_hash_size);
51412+ struct acl_object_label **curr;
51413+
51414+
51415+ obj->prev = NULL;
51416+
51417+ curr = &subj->obj_hash[index];
51418+ if (*curr != NULL)
51419+ (*curr)->prev = obj;
51420+
51421+ obj->next = *curr;
51422+ *curr = obj;
51423+
51424+ return;
51425+}
51426+
51427+static void
51428+insert_acl_subj_label(struct acl_subject_label *obj,
51429+ struct acl_role_label *role)
51430+{
51431+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51432+ struct acl_subject_label **curr;
51433+
51434+ obj->prev = NULL;
51435+
51436+ curr = &role->subj_hash[index];
51437+ if (*curr != NULL)
51438+ (*curr)->prev = obj;
51439+
51440+ obj->next = *curr;
51441+ *curr = obj;
51442+
51443+ return;
51444+}
51445+
51446+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51447+
51448+static void *
51449+create_table(__u32 * len, int elementsize)
51450+{
51451+ unsigned int table_sizes[] = {
51452+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51453+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51454+ 4194301, 8388593, 16777213, 33554393, 67108859
51455+ };
51456+ void *newtable = NULL;
51457+ unsigned int pwr = 0;
51458+
51459+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51460+ table_sizes[pwr] <= *len)
51461+ pwr++;
51462+
51463+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51464+ return newtable;
51465+
51466+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51467+ newtable =
51468+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51469+ else
51470+ newtable = vmalloc(table_sizes[pwr] * elementsize);
51471+
51472+ *len = table_sizes[pwr];
51473+
51474+ return newtable;
51475+}
51476+
51477+static int
51478+init_variables(const struct gr_arg *arg)
51479+{
51480+ struct task_struct *reaper = &init_task;
51481+ unsigned int stacksize;
51482+
51483+ subj_map_set.s_size = arg->role_db.num_subjects;
51484+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51485+ name_set.n_size = arg->role_db.num_objects;
51486+ inodev_set.i_size = arg->role_db.num_objects;
51487+
51488+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
51489+ !name_set.n_size || !inodev_set.i_size)
51490+ return 1;
51491+
51492+ if (!gr_init_uidset())
51493+ return 1;
51494+
51495+ /* set up the stack that holds allocation info */
51496+
51497+ stacksize = arg->role_db.num_pointers + 5;
51498+
51499+ if (!acl_alloc_stack_init(stacksize))
51500+ return 1;
51501+
51502+ /* grab reference for the real root dentry and vfsmount */
51503+ get_fs_root(reaper->fs, &real_root);
51504+
51505+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51506+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51507+#endif
51508+
51509+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51510+ if (fakefs_obj_rw == NULL)
51511+ return 1;
51512+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51513+
51514+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51515+ if (fakefs_obj_rwx == NULL)
51516+ return 1;
51517+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51518+
51519+ subj_map_set.s_hash =
51520+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51521+ acl_role_set.r_hash =
51522+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51523+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51524+ inodev_set.i_hash =
51525+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51526+
51527+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51528+ !name_set.n_hash || !inodev_set.i_hash)
51529+ return 1;
51530+
51531+ memset(subj_map_set.s_hash, 0,
51532+ sizeof(struct subject_map *) * subj_map_set.s_size);
51533+ memset(acl_role_set.r_hash, 0,
51534+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
51535+ memset(name_set.n_hash, 0,
51536+ sizeof (struct name_entry *) * name_set.n_size);
51537+ memset(inodev_set.i_hash, 0,
51538+ sizeof (struct inodev_entry *) * inodev_set.i_size);
51539+
51540+ return 0;
51541+}
51542+
51543+/* free information not needed after startup
51544+ currently contains user->kernel pointer mappings for subjects
51545+*/
51546+
51547+static void
51548+free_init_variables(void)
51549+{
51550+ __u32 i;
51551+
51552+ if (subj_map_set.s_hash) {
51553+ for (i = 0; i < subj_map_set.s_size; i++) {
51554+ if (subj_map_set.s_hash[i]) {
51555+ kfree(subj_map_set.s_hash[i]);
51556+ subj_map_set.s_hash[i] = NULL;
51557+ }
51558+ }
51559+
51560+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51561+ PAGE_SIZE)
51562+ kfree(subj_map_set.s_hash);
51563+ else
51564+ vfree(subj_map_set.s_hash);
51565+ }
51566+
51567+ return;
51568+}
51569+
51570+static void
51571+free_variables(void)
51572+{
51573+ struct acl_subject_label *s;
51574+ struct acl_role_label *r;
51575+ struct task_struct *task, *task2;
51576+ unsigned int x;
51577+
51578+ gr_clear_learn_entries();
51579+
51580+ read_lock(&tasklist_lock);
51581+ do_each_thread(task2, task) {
51582+ task->acl_sp_role = 0;
51583+ task->acl_role_id = 0;
51584+ task->acl = NULL;
51585+ task->role = NULL;
51586+ } while_each_thread(task2, task);
51587+ read_unlock(&tasklist_lock);
51588+
51589+ /* release the reference to the real root dentry and vfsmount */
51590+ path_put(&real_root);
51591+ memset(&real_root, 0, sizeof(real_root));
51592+
51593+ /* free all object hash tables */
51594+
51595+ FOR_EACH_ROLE_START(r)
51596+ if (r->subj_hash == NULL)
51597+ goto next_role;
51598+ FOR_EACH_SUBJECT_START(r, s, x)
51599+ if (s->obj_hash == NULL)
51600+ break;
51601+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51602+ kfree(s->obj_hash);
51603+ else
51604+ vfree(s->obj_hash);
51605+ FOR_EACH_SUBJECT_END(s, x)
51606+ FOR_EACH_NESTED_SUBJECT_START(r, s)
51607+ if (s->obj_hash == NULL)
51608+ break;
51609+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51610+ kfree(s->obj_hash);
51611+ else
51612+ vfree(s->obj_hash);
51613+ FOR_EACH_NESTED_SUBJECT_END(s)
51614+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51615+ kfree(r->subj_hash);
51616+ else
51617+ vfree(r->subj_hash);
51618+ r->subj_hash = NULL;
51619+next_role:
51620+ FOR_EACH_ROLE_END(r)
51621+
51622+ acl_free_all();
51623+
51624+ if (acl_role_set.r_hash) {
51625+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51626+ PAGE_SIZE)
51627+ kfree(acl_role_set.r_hash);
51628+ else
51629+ vfree(acl_role_set.r_hash);
51630+ }
51631+ if (name_set.n_hash) {
51632+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
51633+ PAGE_SIZE)
51634+ kfree(name_set.n_hash);
51635+ else
51636+ vfree(name_set.n_hash);
51637+ }
51638+
51639+ if (inodev_set.i_hash) {
51640+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51641+ PAGE_SIZE)
51642+ kfree(inodev_set.i_hash);
51643+ else
51644+ vfree(inodev_set.i_hash);
51645+ }
51646+
51647+ gr_free_uidset();
51648+
51649+ memset(&name_set, 0, sizeof (struct name_db));
51650+ memset(&inodev_set, 0, sizeof (struct inodev_db));
51651+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51652+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51653+
51654+ default_role = NULL;
51655+ kernel_role = NULL;
51656+ role_list = NULL;
51657+
51658+ return;
51659+}
51660+
51661+static __u32
51662+count_user_objs(struct acl_object_label *userp)
51663+{
51664+ struct acl_object_label o_tmp;
51665+ __u32 num = 0;
51666+
51667+ while (userp) {
51668+ if (copy_from_user(&o_tmp, userp,
51669+ sizeof (struct acl_object_label)))
51670+ break;
51671+
51672+ userp = o_tmp.prev;
51673+ num++;
51674+ }
51675+
51676+ return num;
51677+}
51678+
51679+static struct acl_subject_label *
51680+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
51681+
51682+static int
51683+copy_user_glob(struct acl_object_label *obj)
51684+{
51685+ struct acl_object_label *g_tmp, **guser;
51686+ unsigned int len;
51687+ char *tmp;
51688+
51689+ if (obj->globbed == NULL)
51690+ return 0;
51691+
51692+ guser = &obj->globbed;
51693+ while (*guser) {
51694+ g_tmp = (struct acl_object_label *)
51695+ acl_alloc(sizeof (struct acl_object_label));
51696+ if (g_tmp == NULL)
51697+ return -ENOMEM;
51698+
51699+ if (copy_from_user(g_tmp, *guser,
51700+ sizeof (struct acl_object_label)))
51701+ return -EFAULT;
51702+
51703+ len = strnlen_user(g_tmp->filename, PATH_MAX);
51704+
51705+ if (!len || len >= PATH_MAX)
51706+ return -EINVAL;
51707+
51708+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51709+ return -ENOMEM;
51710+
51711+ if (copy_from_user(tmp, g_tmp->filename, len))
51712+ return -EFAULT;
51713+ tmp[len-1] = '\0';
51714+ g_tmp->filename = tmp;
51715+
51716+ *guser = g_tmp;
51717+ guser = &(g_tmp->next);
51718+ }
51719+
51720+ return 0;
51721+}
51722+
51723+static int
51724+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
51725+ struct acl_role_label *role)
51726+{
51727+ struct acl_object_label *o_tmp;
51728+ unsigned int len;
51729+ int ret;
51730+ char *tmp;
51731+
51732+ while (userp) {
51733+ if ((o_tmp = (struct acl_object_label *)
51734+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
51735+ return -ENOMEM;
51736+
51737+ if (copy_from_user(o_tmp, userp,
51738+ sizeof (struct acl_object_label)))
51739+ return -EFAULT;
51740+
51741+ userp = o_tmp->prev;
51742+
51743+ len = strnlen_user(o_tmp->filename, PATH_MAX);
51744+
51745+ if (!len || len >= PATH_MAX)
51746+ return -EINVAL;
51747+
51748+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51749+ return -ENOMEM;
51750+
51751+ if (copy_from_user(tmp, o_tmp->filename, len))
51752+ return -EFAULT;
51753+ tmp[len-1] = '\0';
51754+ o_tmp->filename = tmp;
51755+
51756+ insert_acl_obj_label(o_tmp, subj);
51757+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
51758+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
51759+ return -ENOMEM;
51760+
51761+ ret = copy_user_glob(o_tmp);
51762+ if (ret)
51763+ return ret;
51764+
51765+ if (o_tmp->nested) {
51766+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
51767+ if (IS_ERR(o_tmp->nested))
51768+ return PTR_ERR(o_tmp->nested);
51769+
51770+ /* insert into nested subject list */
51771+ o_tmp->nested->next = role->hash->first;
51772+ role->hash->first = o_tmp->nested;
51773+ }
51774+ }
51775+
51776+ return 0;
51777+}
51778+
51779+static __u32
51780+count_user_subjs(struct acl_subject_label *userp)
51781+{
51782+ struct acl_subject_label s_tmp;
51783+ __u32 num = 0;
51784+
51785+ while (userp) {
51786+ if (copy_from_user(&s_tmp, userp,
51787+ sizeof (struct acl_subject_label)))
51788+ break;
51789+
51790+ userp = s_tmp.prev;
51791+ /* do not count nested subjects against this count, since
51792+ they are not included in the hash table, but are
51793+ attached to objects. We have already counted
51794+ the subjects in userspace for the allocation
51795+ stack
51796+ */
51797+ if (!(s_tmp.mode & GR_NESTED))
51798+ num++;
51799+ }
51800+
51801+ return num;
51802+}
51803+
51804+static int
51805+copy_user_allowedips(struct acl_role_label *rolep)
51806+{
51807+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
51808+
51809+ ruserip = rolep->allowed_ips;
51810+
51811+ while (ruserip) {
51812+ rlast = rtmp;
51813+
51814+ if ((rtmp = (struct role_allowed_ip *)
51815+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
51816+ return -ENOMEM;
51817+
51818+ if (copy_from_user(rtmp, ruserip,
51819+ sizeof (struct role_allowed_ip)))
51820+ return -EFAULT;
51821+
51822+ ruserip = rtmp->prev;
51823+
51824+ if (!rlast) {
51825+ rtmp->prev = NULL;
51826+ rolep->allowed_ips = rtmp;
51827+ } else {
51828+ rlast->next = rtmp;
51829+ rtmp->prev = rlast;
51830+ }
51831+
51832+ if (!ruserip)
51833+ rtmp->next = NULL;
51834+ }
51835+
51836+ return 0;
51837+}
51838+
51839+static int
51840+copy_user_transitions(struct acl_role_label *rolep)
51841+{
51842+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
51843+
51844+ unsigned int len;
51845+ char *tmp;
51846+
51847+ rusertp = rolep->transitions;
51848+
51849+ while (rusertp) {
51850+ rlast = rtmp;
51851+
51852+ if ((rtmp = (struct role_transition *)
51853+ acl_alloc(sizeof (struct role_transition))) == NULL)
51854+ return -ENOMEM;
51855+
51856+ if (copy_from_user(rtmp, rusertp,
51857+ sizeof (struct role_transition)))
51858+ return -EFAULT;
51859+
51860+ rusertp = rtmp->prev;
51861+
51862+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
51863+
51864+ if (!len || len >= GR_SPROLE_LEN)
51865+ return -EINVAL;
51866+
51867+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51868+ return -ENOMEM;
51869+
51870+ if (copy_from_user(tmp, rtmp->rolename, len))
51871+ return -EFAULT;
51872+ tmp[len-1] = '\0';
51873+ rtmp->rolename = tmp;
51874+
51875+ if (!rlast) {
51876+ rtmp->prev = NULL;
51877+ rolep->transitions = rtmp;
51878+ } else {
51879+ rlast->next = rtmp;
51880+ rtmp->prev = rlast;
51881+ }
51882+
51883+ if (!rusertp)
51884+ rtmp->next = NULL;
51885+ }
51886+
51887+ return 0;
51888+}
51889+
51890+static struct acl_subject_label *
51891+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
51892+{
51893+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
51894+ unsigned int len;
51895+ char *tmp;
51896+ __u32 num_objs;
51897+ struct acl_ip_label **i_tmp, *i_utmp2;
51898+ struct gr_hash_struct ghash;
51899+ struct subject_map *subjmap;
51900+ unsigned int i_num;
51901+ int err;
51902+
51903+ s_tmp = lookup_subject_map(userp);
51904+
51905+ /* we've already copied this subject into the kernel, just return
51906+ the reference to it, and don't copy it over again
51907+ */
51908+ if (s_tmp)
51909+ return(s_tmp);
51910+
51911+ if ((s_tmp = (struct acl_subject_label *)
51912+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
51913+ return ERR_PTR(-ENOMEM);
51914+
51915+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
51916+ if (subjmap == NULL)
51917+ return ERR_PTR(-ENOMEM);
51918+
51919+ subjmap->user = userp;
51920+ subjmap->kernel = s_tmp;
51921+ insert_subj_map_entry(subjmap);
51922+
51923+ if (copy_from_user(s_tmp, userp,
51924+ sizeof (struct acl_subject_label)))
51925+ return ERR_PTR(-EFAULT);
51926+
51927+ len = strnlen_user(s_tmp->filename, PATH_MAX);
51928+
51929+ if (!len || len >= PATH_MAX)
51930+ return ERR_PTR(-EINVAL);
51931+
51932+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51933+ return ERR_PTR(-ENOMEM);
51934+
51935+ if (copy_from_user(tmp, s_tmp->filename, len))
51936+ return ERR_PTR(-EFAULT);
51937+ tmp[len-1] = '\0';
51938+ s_tmp->filename = tmp;
51939+
51940+ if (!strcmp(s_tmp->filename, "/"))
51941+ role->root_label = s_tmp;
51942+
51943+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
51944+ return ERR_PTR(-EFAULT);
51945+
51946+ /* copy user and group transition tables */
51947+
51948+ if (s_tmp->user_trans_num) {
51949+ uid_t *uidlist;
51950+
51951+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
51952+ if (uidlist == NULL)
51953+ return ERR_PTR(-ENOMEM);
51954+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
51955+ return ERR_PTR(-EFAULT);
51956+
51957+ s_tmp->user_transitions = uidlist;
51958+ }
51959+
51960+ if (s_tmp->group_trans_num) {
51961+ gid_t *gidlist;
51962+
51963+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
51964+ if (gidlist == NULL)
51965+ return ERR_PTR(-ENOMEM);
51966+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
51967+ return ERR_PTR(-EFAULT);
51968+
51969+ s_tmp->group_transitions = gidlist;
51970+ }
51971+
51972+ /* set up object hash table */
51973+ num_objs = count_user_objs(ghash.first);
51974+
51975+ s_tmp->obj_hash_size = num_objs;
51976+ s_tmp->obj_hash =
51977+ (struct acl_object_label **)
51978+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
51979+
51980+ if (!s_tmp->obj_hash)
51981+ return ERR_PTR(-ENOMEM);
51982+
51983+ memset(s_tmp->obj_hash, 0,
51984+ s_tmp->obj_hash_size *
51985+ sizeof (struct acl_object_label *));
51986+
51987+ /* add in objects */
51988+ err = copy_user_objs(ghash.first, s_tmp, role);
51989+
51990+ if (err)
51991+ return ERR_PTR(err);
51992+
51993+ /* set pointer for parent subject */
51994+ if (s_tmp->parent_subject) {
51995+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
51996+
51997+ if (IS_ERR(s_tmp2))
51998+ return s_tmp2;
51999+
52000+ s_tmp->parent_subject = s_tmp2;
52001+ }
52002+
52003+ /* add in ip acls */
52004+
52005+ if (!s_tmp->ip_num) {
52006+ s_tmp->ips = NULL;
52007+ goto insert;
52008+ }
52009+
52010+ i_tmp =
52011+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52012+ sizeof (struct acl_ip_label *));
52013+
52014+ if (!i_tmp)
52015+ return ERR_PTR(-ENOMEM);
52016+
52017+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52018+ *(i_tmp + i_num) =
52019+ (struct acl_ip_label *)
52020+ acl_alloc(sizeof (struct acl_ip_label));
52021+ if (!*(i_tmp + i_num))
52022+ return ERR_PTR(-ENOMEM);
52023+
52024+ if (copy_from_user
52025+ (&i_utmp2, s_tmp->ips + i_num,
52026+ sizeof (struct acl_ip_label *)))
52027+ return ERR_PTR(-EFAULT);
52028+
52029+ if (copy_from_user
52030+ (*(i_tmp + i_num), i_utmp2,
52031+ sizeof (struct acl_ip_label)))
52032+ return ERR_PTR(-EFAULT);
52033+
52034+ if ((*(i_tmp + i_num))->iface == NULL)
52035+ continue;
52036+
52037+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52038+ if (!len || len >= IFNAMSIZ)
52039+ return ERR_PTR(-EINVAL);
52040+ tmp = acl_alloc(len);
52041+ if (tmp == NULL)
52042+ return ERR_PTR(-ENOMEM);
52043+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52044+ return ERR_PTR(-EFAULT);
52045+ (*(i_tmp + i_num))->iface = tmp;
52046+ }
52047+
52048+ s_tmp->ips = i_tmp;
52049+
52050+insert:
52051+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52052+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52053+ return ERR_PTR(-ENOMEM);
52054+
52055+ return s_tmp;
52056+}
52057+
52058+static int
52059+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52060+{
52061+ struct acl_subject_label s_pre;
52062+ struct acl_subject_label * ret;
52063+ int err;
52064+
52065+ while (userp) {
52066+ if (copy_from_user(&s_pre, userp,
52067+ sizeof (struct acl_subject_label)))
52068+ return -EFAULT;
52069+
52070+ /* do not add nested subjects here, add
52071+ while parsing objects
52072+ */
52073+
52074+ if (s_pre.mode & GR_NESTED) {
52075+ userp = s_pre.prev;
52076+ continue;
52077+ }
52078+
52079+ ret = do_copy_user_subj(userp, role);
52080+
52081+ err = PTR_ERR(ret);
52082+ if (IS_ERR(ret))
52083+ return err;
52084+
52085+ insert_acl_subj_label(ret, role);
52086+
52087+ userp = s_pre.prev;
52088+ }
52089+
52090+ return 0;
52091+}
52092+
52093+static int
52094+copy_user_acl(struct gr_arg *arg)
52095+{
52096+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52097+ struct sprole_pw *sptmp;
52098+ struct gr_hash_struct *ghash;
52099+ uid_t *domainlist;
52100+ unsigned int r_num;
52101+ unsigned int len;
52102+ char *tmp;
52103+ int err = 0;
52104+ __u16 i;
52105+ __u32 num_subjs;
52106+
52107+ /* we need a default and kernel role */
52108+ if (arg->role_db.num_roles < 2)
52109+ return -EINVAL;
52110+
52111+ /* copy special role authentication info from userspace */
52112+
52113+ num_sprole_pws = arg->num_sprole_pws;
52114+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52115+
52116+ if (!acl_special_roles && num_sprole_pws)
52117+ return -ENOMEM;
52118+
52119+ for (i = 0; i < num_sprole_pws; i++) {
52120+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52121+ if (!sptmp)
52122+ return -ENOMEM;
52123+ if (copy_from_user(sptmp, arg->sprole_pws + i,
52124+ sizeof (struct sprole_pw)))
52125+ return -EFAULT;
52126+
52127+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52128+
52129+ if (!len || len >= GR_SPROLE_LEN)
52130+ return -EINVAL;
52131+
52132+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52133+ return -ENOMEM;
52134+
52135+ if (copy_from_user(tmp, sptmp->rolename, len))
52136+ return -EFAULT;
52137+
52138+ tmp[len-1] = '\0';
52139+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52140+ printk(KERN_ALERT "Copying special role %s\n", tmp);
52141+#endif
52142+ sptmp->rolename = tmp;
52143+ acl_special_roles[i] = sptmp;
52144+ }
52145+
52146+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52147+
52148+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52149+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
52150+
52151+ if (!r_tmp)
52152+ return -ENOMEM;
52153+
52154+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
52155+ sizeof (struct acl_role_label *)))
52156+ return -EFAULT;
52157+
52158+ if (copy_from_user(r_tmp, r_utmp2,
52159+ sizeof (struct acl_role_label)))
52160+ return -EFAULT;
52161+
52162+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52163+
52164+ if (!len || len >= PATH_MAX)
52165+ return -EINVAL;
52166+
52167+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52168+ return -ENOMEM;
52169+
52170+ if (copy_from_user(tmp, r_tmp->rolename, len))
52171+ return -EFAULT;
52172+
52173+ tmp[len-1] = '\0';
52174+ r_tmp->rolename = tmp;
52175+
52176+ if (!strcmp(r_tmp->rolename, "default")
52177+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52178+ default_role = r_tmp;
52179+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52180+ kernel_role = r_tmp;
52181+ }
52182+
52183+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52184+ return -ENOMEM;
52185+
52186+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52187+ return -EFAULT;
52188+
52189+ r_tmp->hash = ghash;
52190+
52191+ num_subjs = count_user_subjs(r_tmp->hash->first);
52192+
52193+ r_tmp->subj_hash_size = num_subjs;
52194+ r_tmp->subj_hash =
52195+ (struct acl_subject_label **)
52196+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52197+
52198+ if (!r_tmp->subj_hash)
52199+ return -ENOMEM;
52200+
52201+ err = copy_user_allowedips(r_tmp);
52202+ if (err)
52203+ return err;
52204+
52205+ /* copy domain info */
52206+ if (r_tmp->domain_children != NULL) {
52207+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52208+ if (domainlist == NULL)
52209+ return -ENOMEM;
52210+
52211+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52212+ return -EFAULT;
52213+
52214+ r_tmp->domain_children = domainlist;
52215+ }
52216+
52217+ err = copy_user_transitions(r_tmp);
52218+ if (err)
52219+ return err;
52220+
52221+ memset(r_tmp->subj_hash, 0,
52222+ r_tmp->subj_hash_size *
52223+ sizeof (struct acl_subject_label *));
52224+
52225+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52226+
52227+ if (err)
52228+ return err;
52229+
52230+ /* set nested subject list to null */
52231+ r_tmp->hash->first = NULL;
52232+
52233+ insert_acl_role_label(r_tmp);
52234+ }
52235+
52236+ if (default_role == NULL || kernel_role == NULL)
52237+ return -EINVAL;
52238+
52239+ return err;
52240+}
52241+
52242+static int
52243+gracl_init(struct gr_arg *args)
52244+{
52245+ int error = 0;
52246+
52247+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52248+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52249+
52250+ if (init_variables(args)) {
52251+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52252+ error = -ENOMEM;
52253+ free_variables();
52254+ goto out;
52255+ }
52256+
52257+ error = copy_user_acl(args);
52258+ free_init_variables();
52259+ if (error) {
52260+ free_variables();
52261+ goto out;
52262+ }
52263+
52264+ if ((error = gr_set_acls(0))) {
52265+ free_variables();
52266+ goto out;
52267+ }
52268+
52269+ pax_open_kernel();
52270+ gr_status |= GR_READY;
52271+ pax_close_kernel();
52272+
52273+ out:
52274+ return error;
52275+}
52276+
52277+/* derived from glibc fnmatch() 0: match, 1: no match*/
52278+
52279+static int
52280+glob_match(const char *p, const char *n)
52281+{
52282+ char c;
52283+
52284+ while ((c = *p++) != '\0') {
52285+ switch (c) {
52286+ case '?':
52287+ if (*n == '\0')
52288+ return 1;
52289+ else if (*n == '/')
52290+ return 1;
52291+ break;
52292+ case '\\':
52293+ if (*n != c)
52294+ return 1;
52295+ break;
52296+ case '*':
52297+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
52298+ if (*n == '/')
52299+ return 1;
52300+ else if (c == '?') {
52301+ if (*n == '\0')
52302+ return 1;
52303+ else
52304+ ++n;
52305+ }
52306+ }
52307+ if (c == '\0') {
52308+ return 0;
52309+ } else {
52310+ const char *endp;
52311+
52312+ if ((endp = strchr(n, '/')) == NULL)
52313+ endp = n + strlen(n);
52314+
52315+ if (c == '[') {
52316+ for (--p; n < endp; ++n)
52317+ if (!glob_match(p, n))
52318+ return 0;
52319+ } else if (c == '/') {
52320+ while (*n != '\0' && *n != '/')
52321+ ++n;
52322+ if (*n == '/' && !glob_match(p, n + 1))
52323+ return 0;
52324+ } else {
52325+ for (--p; n < endp; ++n)
52326+ if (*n == c && !glob_match(p, n))
52327+ return 0;
52328+ }
52329+
52330+ return 1;
52331+ }
52332+ case '[':
52333+ {
52334+ int not;
52335+ char cold;
52336+
52337+ if (*n == '\0' || *n == '/')
52338+ return 1;
52339+
52340+ not = (*p == '!' || *p == '^');
52341+ if (not)
52342+ ++p;
52343+
52344+ c = *p++;
52345+ for (;;) {
52346+ unsigned char fn = (unsigned char)*n;
52347+
52348+ if (c == '\0')
52349+ return 1;
52350+ else {
52351+ if (c == fn)
52352+ goto matched;
52353+ cold = c;
52354+ c = *p++;
52355+
52356+ if (c == '-' && *p != ']') {
52357+ unsigned char cend = *p++;
52358+
52359+ if (cend == '\0')
52360+ return 1;
52361+
52362+ if (cold <= fn && fn <= cend)
52363+ goto matched;
52364+
52365+ c = *p++;
52366+ }
52367+ }
52368+
52369+ if (c == ']')
52370+ break;
52371+ }
52372+ if (!not)
52373+ return 1;
52374+ break;
52375+ matched:
52376+ while (c != ']') {
52377+ if (c == '\0')
52378+ return 1;
52379+
52380+ c = *p++;
52381+ }
52382+ if (not)
52383+ return 1;
52384+ }
52385+ break;
52386+ default:
52387+ if (c != *n)
52388+ return 1;
52389+ }
52390+
52391+ ++n;
52392+ }
52393+
52394+ if (*n == '\0')
52395+ return 0;
52396+
52397+ if (*n == '/')
52398+ return 0;
52399+
52400+ return 1;
52401+}
52402+
52403+static struct acl_object_label *
52404+chk_glob_label(struct acl_object_label *globbed,
52405+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52406+{
52407+ struct acl_object_label *tmp;
52408+
52409+ if (*path == NULL)
52410+ *path = gr_to_filename_nolock(dentry, mnt);
52411+
52412+ tmp = globbed;
52413+
52414+ while (tmp) {
52415+ if (!glob_match(tmp->filename, *path))
52416+ return tmp;
52417+ tmp = tmp->next;
52418+ }
52419+
52420+ return NULL;
52421+}
52422+
52423+static struct acl_object_label *
52424+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52425+ const ino_t curr_ino, const dev_t curr_dev,
52426+ const struct acl_subject_label *subj, char **path, const int checkglob)
52427+{
52428+ struct acl_subject_label *tmpsubj;
52429+ struct acl_object_label *retval;
52430+ struct acl_object_label *retval2;
52431+
52432+ tmpsubj = (struct acl_subject_label *) subj;
52433+ read_lock(&gr_inode_lock);
52434+ do {
52435+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52436+ if (retval) {
52437+ if (checkglob && retval->globbed) {
52438+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52439+ if (retval2)
52440+ retval = retval2;
52441+ }
52442+ break;
52443+ }
52444+ } while ((tmpsubj = tmpsubj->parent_subject));
52445+ read_unlock(&gr_inode_lock);
52446+
52447+ return retval;
52448+}
52449+
52450+static __inline__ struct acl_object_label *
52451+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52452+ struct dentry *curr_dentry,
52453+ const struct acl_subject_label *subj, char **path, const int checkglob)
52454+{
52455+ int newglob = checkglob;
52456+ ino_t inode;
52457+ dev_t device;
52458+
52459+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52460+ as we don't want a / * rule to match instead of the / object
52461+ don't do this for create lookups that call this function though, since they're looking up
52462+ on the parent and thus need globbing checks on all paths
52463+ */
52464+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52465+ newglob = GR_NO_GLOB;
52466+
52467+ spin_lock(&curr_dentry->d_lock);
52468+ inode = curr_dentry->d_inode->i_ino;
52469+ device = __get_dev(curr_dentry);
52470+ spin_unlock(&curr_dentry->d_lock);
52471+
52472+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52473+}
52474+
52475+static struct acl_object_label *
52476+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52477+ const struct acl_subject_label *subj, char *path, const int checkglob)
52478+{
52479+ struct dentry *dentry = (struct dentry *) l_dentry;
52480+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52481+ struct mount *real_mnt = real_mount(mnt);
52482+ struct acl_object_label *retval;
52483+ struct dentry *parent;
52484+
52485+ write_seqlock(&rename_lock);
52486+ br_read_lock(vfsmount_lock);
52487+
52488+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52489+#ifdef CONFIG_NET
52490+ mnt == sock_mnt ||
52491+#endif
52492+#ifdef CONFIG_HUGETLBFS
52493+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52494+#endif
52495+ /* ignore Eric Biederman */
52496+ IS_PRIVATE(l_dentry->d_inode))) {
52497+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52498+ goto out;
52499+ }
52500+
52501+ for (;;) {
52502+ if (dentry == real_root.dentry && mnt == real_root.mnt)
52503+ break;
52504+
52505+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52506+ if (!mnt_has_parent(real_mnt))
52507+ break;
52508+
52509+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52510+ if (retval != NULL)
52511+ goto out;
52512+
52513+ dentry = real_mnt->mnt_mountpoint;
52514+ real_mnt = real_mnt->mnt_parent;
52515+ mnt = &real_mnt->mnt;
52516+ continue;
52517+ }
52518+
52519+ parent = dentry->d_parent;
52520+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52521+ if (retval != NULL)
52522+ goto out;
52523+
52524+ dentry = parent;
52525+ }
52526+
52527+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52528+
52529+ /* real_root is pinned so we don't have to hold a reference */
52530+ if (retval == NULL)
52531+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52532+out:
52533+ br_read_unlock(vfsmount_lock);
52534+ write_sequnlock(&rename_lock);
52535+
52536+ BUG_ON(retval == NULL);
52537+
52538+ return retval;
52539+}
52540+
52541+static __inline__ struct acl_object_label *
52542+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52543+ const struct acl_subject_label *subj)
52544+{
52545+ char *path = NULL;
52546+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52547+}
52548+
52549+static __inline__ struct acl_object_label *
52550+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52551+ const struct acl_subject_label *subj)
52552+{
52553+ char *path = NULL;
52554+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52555+}
52556+
52557+static __inline__ struct acl_object_label *
52558+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52559+ const struct acl_subject_label *subj, char *path)
52560+{
52561+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52562+}
52563+
52564+static struct acl_subject_label *
52565+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52566+ const struct acl_role_label *role)
52567+{
52568+ struct dentry *dentry = (struct dentry *) l_dentry;
52569+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52570+ struct mount *real_mnt = real_mount(mnt);
52571+ struct acl_subject_label *retval;
52572+ struct dentry *parent;
52573+
52574+ write_seqlock(&rename_lock);
52575+ br_read_lock(vfsmount_lock);
52576+
52577+ for (;;) {
52578+ if (dentry == real_root.dentry && mnt == real_root.mnt)
52579+ break;
52580+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52581+ if (!mnt_has_parent(real_mnt))
52582+ break;
52583+
52584+ spin_lock(&dentry->d_lock);
52585+ read_lock(&gr_inode_lock);
52586+ retval =
52587+ lookup_acl_subj_label(dentry->d_inode->i_ino,
52588+ __get_dev(dentry), role);
52589+ read_unlock(&gr_inode_lock);
52590+ spin_unlock(&dentry->d_lock);
52591+ if (retval != NULL)
52592+ goto out;
52593+
52594+ dentry = real_mnt->mnt_mountpoint;
52595+ real_mnt = real_mnt->mnt_parent;
52596+ mnt = &real_mnt->mnt;
52597+ continue;
52598+ }
52599+
52600+ spin_lock(&dentry->d_lock);
52601+ read_lock(&gr_inode_lock);
52602+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52603+ __get_dev(dentry), role);
52604+ read_unlock(&gr_inode_lock);
52605+ parent = dentry->d_parent;
52606+ spin_unlock(&dentry->d_lock);
52607+
52608+ if (retval != NULL)
52609+ goto out;
52610+
52611+ dentry = parent;
52612+ }
52613+
52614+ spin_lock(&dentry->d_lock);
52615+ read_lock(&gr_inode_lock);
52616+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52617+ __get_dev(dentry), role);
52618+ read_unlock(&gr_inode_lock);
52619+ spin_unlock(&dentry->d_lock);
52620+
52621+ if (unlikely(retval == NULL)) {
52622+ /* real_root is pinned, we don't need to hold a reference */
52623+ read_lock(&gr_inode_lock);
52624+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52625+ __get_dev(real_root.dentry), role);
52626+ read_unlock(&gr_inode_lock);
52627+ }
52628+out:
52629+ br_read_unlock(vfsmount_lock);
52630+ write_sequnlock(&rename_lock);
52631+
52632+ BUG_ON(retval == NULL);
52633+
52634+ return retval;
52635+}
52636+
52637+static void
52638+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52639+{
52640+ struct task_struct *task = current;
52641+ const struct cred *cred = current_cred();
52642+
52643+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52644+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52645+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52646+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52647+
52648+ return;
52649+}
52650+
52651+static void
52652+gr_log_learn_sysctl(const char *path, const __u32 mode)
52653+{
52654+ struct task_struct *task = current;
52655+ const struct cred *cred = current_cred();
52656+
52657+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52658+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52659+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52660+ 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
52661+
52662+ return;
52663+}
52664+
52665+static void
52666+gr_log_learn_id_change(const char type, const unsigned int real,
52667+ const unsigned int effective, const unsigned int fs)
52668+{
52669+ struct task_struct *task = current;
52670+ const struct cred *cred = current_cred();
52671+
52672+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52673+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52674+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52675+ type, real, effective, fs, &task->signal->saved_ip);
52676+
52677+ return;
52678+}
52679+
52680+__u32
52681+gr_search_file(const struct dentry * dentry, const __u32 mode,
52682+ const struct vfsmount * mnt)
52683+{
52684+ __u32 retval = mode;
52685+ struct acl_subject_label *curracl;
52686+ struct acl_object_label *currobj;
52687+
52688+ if (unlikely(!(gr_status & GR_READY)))
52689+ return (mode & ~GR_AUDITS);
52690+
52691+ curracl = current->acl;
52692+
52693+ currobj = chk_obj_label(dentry, mnt, curracl);
52694+ retval = currobj->mode & mode;
52695+
52696+ /* if we're opening a specified transfer file for writing
52697+ (e.g. /dev/initctl), then transfer our role to init
52698+ */
52699+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
52700+ current->role->roletype & GR_ROLE_PERSIST)) {
52701+ struct task_struct *task = init_pid_ns.child_reaper;
52702+
52703+ if (task->role != current->role) {
52704+ task->acl_sp_role = 0;
52705+ task->acl_role_id = current->acl_role_id;
52706+ task->role = current->role;
52707+ rcu_read_lock();
52708+ read_lock(&grsec_exec_file_lock);
52709+ gr_apply_subject_to_task(task);
52710+ read_unlock(&grsec_exec_file_lock);
52711+ rcu_read_unlock();
52712+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
52713+ }
52714+ }
52715+
52716+ if (unlikely
52717+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
52718+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
52719+ __u32 new_mode = mode;
52720+
52721+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52722+
52723+ retval = new_mode;
52724+
52725+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
52726+ new_mode |= GR_INHERIT;
52727+
52728+ if (!(mode & GR_NOLEARN))
52729+ gr_log_learn(dentry, mnt, new_mode);
52730+ }
52731+
52732+ return retval;
52733+}
52734+
52735+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
52736+ const struct dentry *parent,
52737+ const struct vfsmount *mnt)
52738+{
52739+ struct name_entry *match;
52740+ struct acl_object_label *matchpo;
52741+ struct acl_subject_label *curracl;
52742+ char *path;
52743+
52744+ if (unlikely(!(gr_status & GR_READY)))
52745+ return NULL;
52746+
52747+ preempt_disable();
52748+ path = gr_to_filename_rbac(new_dentry, mnt);
52749+ match = lookup_name_entry_create(path);
52750+
52751+ curracl = current->acl;
52752+
52753+ if (match) {
52754+ read_lock(&gr_inode_lock);
52755+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
52756+ read_unlock(&gr_inode_lock);
52757+
52758+ if (matchpo) {
52759+ preempt_enable();
52760+ return matchpo;
52761+ }
52762+ }
52763+
52764+ // lookup parent
52765+
52766+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
52767+
52768+ preempt_enable();
52769+ return matchpo;
52770+}
52771+
52772+__u32
52773+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
52774+ const struct vfsmount * mnt, const __u32 mode)
52775+{
52776+ struct acl_object_label *matchpo;
52777+ __u32 retval;
52778+
52779+ if (unlikely(!(gr_status & GR_READY)))
52780+ return (mode & ~GR_AUDITS);
52781+
52782+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
52783+
52784+ retval = matchpo->mode & mode;
52785+
52786+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
52787+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52788+ __u32 new_mode = mode;
52789+
52790+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52791+
52792+ gr_log_learn(new_dentry, mnt, new_mode);
52793+ return new_mode;
52794+ }
52795+
52796+ return retval;
52797+}
52798+
52799+__u32
52800+gr_check_link(const struct dentry * new_dentry,
52801+ const struct dentry * parent_dentry,
52802+ const struct vfsmount * parent_mnt,
52803+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
52804+{
52805+ struct acl_object_label *obj;
52806+ __u32 oldmode, newmode;
52807+ __u32 needmode;
52808+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
52809+ GR_DELETE | GR_INHERIT;
52810+
52811+ if (unlikely(!(gr_status & GR_READY)))
52812+ return (GR_CREATE | GR_LINK);
52813+
52814+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
52815+ oldmode = obj->mode;
52816+
52817+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
52818+ newmode = obj->mode;
52819+
52820+ needmode = newmode & checkmodes;
52821+
52822+ // old name for hardlink must have at least the permissions of the new name
52823+ if ((oldmode & needmode) != needmode)
52824+ goto bad;
52825+
52826+ // if old name had restrictions/auditing, make sure the new name does as well
52827+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
52828+
52829+ // don't allow hardlinking of suid/sgid files without permission
52830+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52831+ needmode |= GR_SETID;
52832+
52833+ if ((newmode & needmode) != needmode)
52834+ goto bad;
52835+
52836+ // enforce minimum permissions
52837+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
52838+ return newmode;
52839+bad:
52840+ needmode = oldmode;
52841+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52842+ needmode |= GR_SETID;
52843+
52844+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
52845+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
52846+ return (GR_CREATE | GR_LINK);
52847+ } else if (newmode & GR_SUPPRESS)
52848+ return GR_SUPPRESS;
52849+ else
52850+ return 0;
52851+}
52852+
52853+int
52854+gr_check_hidden_task(const struct task_struct *task)
52855+{
52856+ if (unlikely(!(gr_status & GR_READY)))
52857+ return 0;
52858+
52859+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
52860+ return 1;
52861+
52862+ return 0;
52863+}
52864+
52865+int
52866+gr_check_protected_task(const struct task_struct *task)
52867+{
52868+ if (unlikely(!(gr_status & GR_READY) || !task))
52869+ return 0;
52870+
52871+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52872+ task->acl != current->acl)
52873+ return 1;
52874+
52875+ return 0;
52876+}
52877+
52878+int
52879+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
52880+{
52881+ struct task_struct *p;
52882+ int ret = 0;
52883+
52884+ if (unlikely(!(gr_status & GR_READY) || !pid))
52885+ return ret;
52886+
52887+ read_lock(&tasklist_lock);
52888+ do_each_pid_task(pid, type, p) {
52889+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52890+ p->acl != current->acl) {
52891+ ret = 1;
52892+ goto out;
52893+ }
52894+ } while_each_pid_task(pid, type, p);
52895+out:
52896+ read_unlock(&tasklist_lock);
52897+
52898+ return ret;
52899+}
52900+
52901+void
52902+gr_copy_label(struct task_struct *tsk)
52903+{
52904+ /* plain copying of fields is already done by dup_task_struct */
52905+ tsk->signal->used_accept = 0;
52906+ tsk->acl_sp_role = 0;
52907+ //tsk->acl_role_id = current->acl_role_id;
52908+ //tsk->acl = current->acl;
52909+ //tsk->role = current->role;
52910+ tsk->signal->curr_ip = current->signal->curr_ip;
52911+ tsk->signal->saved_ip = current->signal->saved_ip;
52912+ if (current->exec_file)
52913+ get_file(current->exec_file);
52914+ //tsk->exec_file = current->exec_file;
52915+ //tsk->is_writable = current->is_writable;
52916+ if (unlikely(current->signal->used_accept)) {
52917+ current->signal->curr_ip = 0;
52918+ current->signal->saved_ip = 0;
52919+ }
52920+
52921+ return;
52922+}
52923+
52924+static void
52925+gr_set_proc_res(struct task_struct *task)
52926+{
52927+ struct acl_subject_label *proc;
52928+ unsigned short i;
52929+
52930+ proc = task->acl;
52931+
52932+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
52933+ return;
52934+
52935+ for (i = 0; i < RLIM_NLIMITS; i++) {
52936+ if (!(proc->resmask & (1 << i)))
52937+ continue;
52938+
52939+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
52940+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
52941+ }
52942+
52943+ return;
52944+}
52945+
52946+extern int __gr_process_user_ban(struct user_struct *user);
52947+
52948+int
52949+gr_check_user_change(int real, int effective, int fs)
52950+{
52951+ unsigned int i;
52952+ __u16 num;
52953+ uid_t *uidlist;
52954+ int curuid;
52955+ int realok = 0;
52956+ int effectiveok = 0;
52957+ int fsok = 0;
52958+
52959+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
52960+ struct user_struct *user;
52961+
52962+ if (real == -1)
52963+ goto skipit;
52964+
52965+ user = find_user(real);
52966+ if (user == NULL)
52967+ goto skipit;
52968+
52969+ if (__gr_process_user_ban(user)) {
52970+ /* for find_user */
52971+ free_uid(user);
52972+ return 1;
52973+ }
52974+
52975+ /* for find_user */
52976+ free_uid(user);
52977+
52978+skipit:
52979+#endif
52980+
52981+ if (unlikely(!(gr_status & GR_READY)))
52982+ return 0;
52983+
52984+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52985+ gr_log_learn_id_change('u', real, effective, fs);
52986+
52987+ num = current->acl->user_trans_num;
52988+ uidlist = current->acl->user_transitions;
52989+
52990+ if (uidlist == NULL)
52991+ return 0;
52992+
52993+ if (real == -1)
52994+ realok = 1;
52995+ if (effective == -1)
52996+ effectiveok = 1;
52997+ if (fs == -1)
52998+ fsok = 1;
52999+
53000+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
53001+ for (i = 0; i < num; i++) {
53002+ curuid = (int)uidlist[i];
53003+ if (real == curuid)
53004+ realok = 1;
53005+ if (effective == curuid)
53006+ effectiveok = 1;
53007+ if (fs == curuid)
53008+ fsok = 1;
53009+ }
53010+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
53011+ for (i = 0; i < num; i++) {
53012+ curuid = (int)uidlist[i];
53013+ if (real == curuid)
53014+ break;
53015+ if (effective == curuid)
53016+ break;
53017+ if (fs == curuid)
53018+ break;
53019+ }
53020+ /* not in deny list */
53021+ if (i == num) {
53022+ realok = 1;
53023+ effectiveok = 1;
53024+ fsok = 1;
53025+ }
53026+ }
53027+
53028+ if (realok && effectiveok && fsok)
53029+ return 0;
53030+ else {
53031+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53032+ return 1;
53033+ }
53034+}
53035+
53036+int
53037+gr_check_group_change(int real, int effective, int fs)
53038+{
53039+ unsigned int i;
53040+ __u16 num;
53041+ gid_t *gidlist;
53042+ int curgid;
53043+ int realok = 0;
53044+ int effectiveok = 0;
53045+ int fsok = 0;
53046+
53047+ if (unlikely(!(gr_status & GR_READY)))
53048+ return 0;
53049+
53050+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53051+ gr_log_learn_id_change('g', real, effective, fs);
53052+
53053+ num = current->acl->group_trans_num;
53054+ gidlist = current->acl->group_transitions;
53055+
53056+ if (gidlist == NULL)
53057+ return 0;
53058+
53059+ if (real == -1)
53060+ realok = 1;
53061+ if (effective == -1)
53062+ effectiveok = 1;
53063+ if (fs == -1)
53064+ fsok = 1;
53065+
53066+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
53067+ for (i = 0; i < num; i++) {
53068+ curgid = (int)gidlist[i];
53069+ if (real == curgid)
53070+ realok = 1;
53071+ if (effective == curgid)
53072+ effectiveok = 1;
53073+ if (fs == curgid)
53074+ fsok = 1;
53075+ }
53076+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
53077+ for (i = 0; i < num; i++) {
53078+ curgid = (int)gidlist[i];
53079+ if (real == curgid)
53080+ break;
53081+ if (effective == curgid)
53082+ break;
53083+ if (fs == curgid)
53084+ break;
53085+ }
53086+ /* not in deny list */
53087+ if (i == num) {
53088+ realok = 1;
53089+ effectiveok = 1;
53090+ fsok = 1;
53091+ }
53092+ }
53093+
53094+ if (realok && effectiveok && fsok)
53095+ return 0;
53096+ else {
53097+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53098+ return 1;
53099+ }
53100+}
53101+
53102+extern int gr_acl_is_capable(const int cap);
53103+
53104+void
53105+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53106+{
53107+ struct acl_role_label *role = task->role;
53108+ struct acl_subject_label *subj = NULL;
53109+ struct acl_object_label *obj;
53110+ struct file *filp;
53111+
53112+ if (unlikely(!(gr_status & GR_READY)))
53113+ return;
53114+
53115+ filp = task->exec_file;
53116+
53117+ /* kernel process, we'll give them the kernel role */
53118+ if (unlikely(!filp)) {
53119+ task->role = kernel_role;
53120+ task->acl = kernel_role->root_label;
53121+ return;
53122+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53123+ role = lookup_acl_role_label(task, uid, gid);
53124+
53125+ /* don't change the role if we're not a privileged process */
53126+ if (role && task->role != role &&
53127+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53128+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53129+ return;
53130+
53131+ /* perform subject lookup in possibly new role
53132+ we can use this result below in the case where role == task->role
53133+ */
53134+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53135+
53136+ /* if we changed uid/gid, but result in the same role
53137+ and are using inheritance, don't lose the inherited subject
53138+ if current subject is other than what normal lookup
53139+ would result in, we arrived via inheritance, don't
53140+ lose subject
53141+ */
53142+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53143+ (subj == task->acl)))
53144+ task->acl = subj;
53145+
53146+ task->role = role;
53147+
53148+ task->is_writable = 0;
53149+
53150+ /* ignore additional mmap checks for processes that are writable
53151+ by the default ACL */
53152+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53153+ if (unlikely(obj->mode & GR_WRITE))
53154+ task->is_writable = 1;
53155+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53156+ if (unlikely(obj->mode & GR_WRITE))
53157+ task->is_writable = 1;
53158+
53159+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53160+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53161+#endif
53162+
53163+ gr_set_proc_res(task);
53164+
53165+ return;
53166+}
53167+
53168+int
53169+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53170+ const int unsafe_flags)
53171+{
53172+ struct task_struct *task = current;
53173+ struct acl_subject_label *newacl;
53174+ struct acl_object_label *obj;
53175+ __u32 retmode;
53176+
53177+ if (unlikely(!(gr_status & GR_READY)))
53178+ return 0;
53179+
53180+ newacl = chk_subj_label(dentry, mnt, task->role);
53181+
53182+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53183+ did an exec
53184+ */
53185+ rcu_read_lock();
53186+ read_lock(&tasklist_lock);
53187+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53188+ (task->parent->acl->mode & GR_POVERRIDE))) {
53189+ read_unlock(&tasklist_lock);
53190+ rcu_read_unlock();
53191+ goto skip_check;
53192+ }
53193+ read_unlock(&tasklist_lock);
53194+ rcu_read_unlock();
53195+
53196+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53197+ !(task->role->roletype & GR_ROLE_GOD) &&
53198+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53199+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53200+ if (unsafe_flags & LSM_UNSAFE_SHARE)
53201+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53202+ else
53203+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53204+ return -EACCES;
53205+ }
53206+
53207+skip_check:
53208+
53209+ obj = chk_obj_label(dentry, mnt, task->acl);
53210+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53211+
53212+ if (!(task->acl->mode & GR_INHERITLEARN) &&
53213+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53214+ if (obj->nested)
53215+ task->acl = obj->nested;
53216+ else
53217+ task->acl = newacl;
53218+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53219+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53220+
53221+ task->is_writable = 0;
53222+
53223+ /* ignore additional mmap checks for processes that are writable
53224+ by the default ACL */
53225+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
53226+ if (unlikely(obj->mode & GR_WRITE))
53227+ task->is_writable = 1;
53228+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
53229+ if (unlikely(obj->mode & GR_WRITE))
53230+ task->is_writable = 1;
53231+
53232+ gr_set_proc_res(task);
53233+
53234+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53235+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53236+#endif
53237+ return 0;
53238+}
53239+
53240+/* always called with valid inodev ptr */
53241+static void
53242+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53243+{
53244+ struct acl_object_label *matchpo;
53245+ struct acl_subject_label *matchps;
53246+ struct acl_subject_label *subj;
53247+ struct acl_role_label *role;
53248+ unsigned int x;
53249+
53250+ FOR_EACH_ROLE_START(role)
53251+ FOR_EACH_SUBJECT_START(role, subj, x)
53252+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53253+ matchpo->mode |= GR_DELETED;
53254+ FOR_EACH_SUBJECT_END(subj,x)
53255+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53256+ if (subj->inode == ino && subj->device == dev)
53257+ subj->mode |= GR_DELETED;
53258+ FOR_EACH_NESTED_SUBJECT_END(subj)
53259+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53260+ matchps->mode |= GR_DELETED;
53261+ FOR_EACH_ROLE_END(role)
53262+
53263+ inodev->nentry->deleted = 1;
53264+
53265+ return;
53266+}
53267+
53268+void
53269+gr_handle_delete(const ino_t ino, const dev_t dev)
53270+{
53271+ struct inodev_entry *inodev;
53272+
53273+ if (unlikely(!(gr_status & GR_READY)))
53274+ return;
53275+
53276+ write_lock(&gr_inode_lock);
53277+ inodev = lookup_inodev_entry(ino, dev);
53278+ if (inodev != NULL)
53279+ do_handle_delete(inodev, ino, dev);
53280+ write_unlock(&gr_inode_lock);
53281+
53282+ return;
53283+}
53284+
53285+static void
53286+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53287+ const ino_t newinode, const dev_t newdevice,
53288+ struct acl_subject_label *subj)
53289+{
53290+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53291+ struct acl_object_label *match;
53292+
53293+ match = subj->obj_hash[index];
53294+
53295+ while (match && (match->inode != oldinode ||
53296+ match->device != olddevice ||
53297+ !(match->mode & GR_DELETED)))
53298+ match = match->next;
53299+
53300+ if (match && (match->inode == oldinode)
53301+ && (match->device == olddevice)
53302+ && (match->mode & GR_DELETED)) {
53303+ if (match->prev == NULL) {
53304+ subj->obj_hash[index] = match->next;
53305+ if (match->next != NULL)
53306+ match->next->prev = NULL;
53307+ } else {
53308+ match->prev->next = match->next;
53309+ if (match->next != NULL)
53310+ match->next->prev = match->prev;
53311+ }
53312+ match->prev = NULL;
53313+ match->next = NULL;
53314+ match->inode = newinode;
53315+ match->device = newdevice;
53316+ match->mode &= ~GR_DELETED;
53317+
53318+ insert_acl_obj_label(match, subj);
53319+ }
53320+
53321+ return;
53322+}
53323+
53324+static void
53325+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53326+ const ino_t newinode, const dev_t newdevice,
53327+ struct acl_role_label *role)
53328+{
53329+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53330+ struct acl_subject_label *match;
53331+
53332+ match = role->subj_hash[index];
53333+
53334+ while (match && (match->inode != oldinode ||
53335+ match->device != olddevice ||
53336+ !(match->mode & GR_DELETED)))
53337+ match = match->next;
53338+
53339+ if (match && (match->inode == oldinode)
53340+ && (match->device == olddevice)
53341+ && (match->mode & GR_DELETED)) {
53342+ if (match->prev == NULL) {
53343+ role->subj_hash[index] = match->next;
53344+ if (match->next != NULL)
53345+ match->next->prev = NULL;
53346+ } else {
53347+ match->prev->next = match->next;
53348+ if (match->next != NULL)
53349+ match->next->prev = match->prev;
53350+ }
53351+ match->prev = NULL;
53352+ match->next = NULL;
53353+ match->inode = newinode;
53354+ match->device = newdevice;
53355+ match->mode &= ~GR_DELETED;
53356+
53357+ insert_acl_subj_label(match, role);
53358+ }
53359+
53360+ return;
53361+}
53362+
53363+static void
53364+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53365+ const ino_t newinode, const dev_t newdevice)
53366+{
53367+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53368+ struct inodev_entry *match;
53369+
53370+ match = inodev_set.i_hash[index];
53371+
53372+ while (match && (match->nentry->inode != oldinode ||
53373+ match->nentry->device != olddevice || !match->nentry->deleted))
53374+ match = match->next;
53375+
53376+ if (match && (match->nentry->inode == oldinode)
53377+ && (match->nentry->device == olddevice) &&
53378+ match->nentry->deleted) {
53379+ if (match->prev == NULL) {
53380+ inodev_set.i_hash[index] = match->next;
53381+ if (match->next != NULL)
53382+ match->next->prev = NULL;
53383+ } else {
53384+ match->prev->next = match->next;
53385+ if (match->next != NULL)
53386+ match->next->prev = match->prev;
53387+ }
53388+ match->prev = NULL;
53389+ match->next = NULL;
53390+ match->nentry->inode = newinode;
53391+ match->nentry->device = newdevice;
53392+ match->nentry->deleted = 0;
53393+
53394+ insert_inodev_entry(match);
53395+ }
53396+
53397+ return;
53398+}
53399+
53400+static void
53401+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53402+{
53403+ struct acl_subject_label *subj;
53404+ struct acl_role_label *role;
53405+ unsigned int x;
53406+
53407+ FOR_EACH_ROLE_START(role)
53408+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53409+
53410+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53411+ if ((subj->inode == ino) && (subj->device == dev)) {
53412+ subj->inode = ino;
53413+ subj->device = dev;
53414+ }
53415+ FOR_EACH_NESTED_SUBJECT_END(subj)
53416+ FOR_EACH_SUBJECT_START(role, subj, x)
53417+ update_acl_obj_label(matchn->inode, matchn->device,
53418+ ino, dev, subj);
53419+ FOR_EACH_SUBJECT_END(subj,x)
53420+ FOR_EACH_ROLE_END(role)
53421+
53422+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53423+
53424+ return;
53425+}
53426+
53427+static void
53428+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53429+ const struct vfsmount *mnt)
53430+{
53431+ ino_t ino = dentry->d_inode->i_ino;
53432+ dev_t dev = __get_dev(dentry);
53433+
53434+ __do_handle_create(matchn, ino, dev);
53435+
53436+ return;
53437+}
53438+
53439+void
53440+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53441+{
53442+ struct name_entry *matchn;
53443+
53444+ if (unlikely(!(gr_status & GR_READY)))
53445+ return;
53446+
53447+ preempt_disable();
53448+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53449+
53450+ if (unlikely((unsigned long)matchn)) {
53451+ write_lock(&gr_inode_lock);
53452+ do_handle_create(matchn, dentry, mnt);
53453+ write_unlock(&gr_inode_lock);
53454+ }
53455+ preempt_enable();
53456+
53457+ return;
53458+}
53459+
53460+void
53461+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53462+{
53463+ struct name_entry *matchn;
53464+
53465+ if (unlikely(!(gr_status & GR_READY)))
53466+ return;
53467+
53468+ preempt_disable();
53469+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53470+
53471+ if (unlikely((unsigned long)matchn)) {
53472+ write_lock(&gr_inode_lock);
53473+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53474+ write_unlock(&gr_inode_lock);
53475+ }
53476+ preempt_enable();
53477+
53478+ return;
53479+}
53480+
53481+void
53482+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53483+ struct dentry *old_dentry,
53484+ struct dentry *new_dentry,
53485+ struct vfsmount *mnt, const __u8 replace)
53486+{
53487+ struct name_entry *matchn;
53488+ struct inodev_entry *inodev;
53489+ struct inode *inode = new_dentry->d_inode;
53490+ ino_t old_ino = old_dentry->d_inode->i_ino;
53491+ dev_t old_dev = __get_dev(old_dentry);
53492+
53493+ /* vfs_rename swaps the name and parent link for old_dentry and
53494+ new_dentry
53495+ at this point, old_dentry has the new name, parent link, and inode
53496+ for the renamed file
53497+ if a file is being replaced by a rename, new_dentry has the inode
53498+ and name for the replaced file
53499+ */
53500+
53501+ if (unlikely(!(gr_status & GR_READY)))
53502+ return;
53503+
53504+ preempt_disable();
53505+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53506+
53507+ /* we wouldn't have to check d_inode if it weren't for
53508+ NFS silly-renaming
53509+ */
53510+
53511+ write_lock(&gr_inode_lock);
53512+ if (unlikely(replace && inode)) {
53513+ ino_t new_ino = inode->i_ino;
53514+ dev_t new_dev = __get_dev(new_dentry);
53515+
53516+ inodev = lookup_inodev_entry(new_ino, new_dev);
53517+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53518+ do_handle_delete(inodev, new_ino, new_dev);
53519+ }
53520+
53521+ inodev = lookup_inodev_entry(old_ino, old_dev);
53522+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53523+ do_handle_delete(inodev, old_ino, old_dev);
53524+
53525+ if (unlikely((unsigned long)matchn))
53526+ do_handle_create(matchn, old_dentry, mnt);
53527+
53528+ write_unlock(&gr_inode_lock);
53529+ preempt_enable();
53530+
53531+ return;
53532+}
53533+
53534+static int
53535+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53536+ unsigned char **sum)
53537+{
53538+ struct acl_role_label *r;
53539+ struct role_allowed_ip *ipp;
53540+ struct role_transition *trans;
53541+ unsigned int i;
53542+ int found = 0;
53543+ u32 curr_ip = current->signal->curr_ip;
53544+
53545+ current->signal->saved_ip = curr_ip;
53546+
53547+ /* check transition table */
53548+
53549+ for (trans = current->role->transitions; trans; trans = trans->next) {
53550+ if (!strcmp(rolename, trans->rolename)) {
53551+ found = 1;
53552+ break;
53553+ }
53554+ }
53555+
53556+ if (!found)
53557+ return 0;
53558+
53559+ /* handle special roles that do not require authentication
53560+ and check ip */
53561+
53562+ FOR_EACH_ROLE_START(r)
53563+ if (!strcmp(rolename, r->rolename) &&
53564+ (r->roletype & GR_ROLE_SPECIAL)) {
53565+ found = 0;
53566+ if (r->allowed_ips != NULL) {
53567+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53568+ if ((ntohl(curr_ip) & ipp->netmask) ==
53569+ (ntohl(ipp->addr) & ipp->netmask))
53570+ found = 1;
53571+ }
53572+ } else
53573+ found = 2;
53574+ if (!found)
53575+ return 0;
53576+
53577+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53578+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53579+ *salt = NULL;
53580+ *sum = NULL;
53581+ return 1;
53582+ }
53583+ }
53584+ FOR_EACH_ROLE_END(r)
53585+
53586+ for (i = 0; i < num_sprole_pws; i++) {
53587+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53588+ *salt = acl_special_roles[i]->salt;
53589+ *sum = acl_special_roles[i]->sum;
53590+ return 1;
53591+ }
53592+ }
53593+
53594+ return 0;
53595+}
53596+
53597+static void
53598+assign_special_role(char *rolename)
53599+{
53600+ struct acl_object_label *obj;
53601+ struct acl_role_label *r;
53602+ struct acl_role_label *assigned = NULL;
53603+ struct task_struct *tsk;
53604+ struct file *filp;
53605+
53606+ FOR_EACH_ROLE_START(r)
53607+ if (!strcmp(rolename, r->rolename) &&
53608+ (r->roletype & GR_ROLE_SPECIAL)) {
53609+ assigned = r;
53610+ break;
53611+ }
53612+ FOR_EACH_ROLE_END(r)
53613+
53614+ if (!assigned)
53615+ return;
53616+
53617+ read_lock(&tasklist_lock);
53618+ read_lock(&grsec_exec_file_lock);
53619+
53620+ tsk = current->real_parent;
53621+ if (tsk == NULL)
53622+ goto out_unlock;
53623+
53624+ filp = tsk->exec_file;
53625+ if (filp == NULL)
53626+ goto out_unlock;
53627+
53628+ tsk->is_writable = 0;
53629+
53630+ tsk->acl_sp_role = 1;
53631+ tsk->acl_role_id = ++acl_sp_role_value;
53632+ tsk->role = assigned;
53633+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53634+
53635+ /* ignore additional mmap checks for processes that are writable
53636+ by the default ACL */
53637+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53638+ if (unlikely(obj->mode & GR_WRITE))
53639+ tsk->is_writable = 1;
53640+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53641+ if (unlikely(obj->mode & GR_WRITE))
53642+ tsk->is_writable = 1;
53643+
53644+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53645+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53646+#endif
53647+
53648+out_unlock:
53649+ read_unlock(&grsec_exec_file_lock);
53650+ read_unlock(&tasklist_lock);
53651+ return;
53652+}
53653+
53654+int gr_check_secure_terminal(struct task_struct *task)
53655+{
53656+ struct task_struct *p, *p2, *p3;
53657+ struct files_struct *files;
53658+ struct fdtable *fdt;
53659+ struct file *our_file = NULL, *file;
53660+ int i;
53661+
53662+ if (task->signal->tty == NULL)
53663+ return 1;
53664+
53665+ files = get_files_struct(task);
53666+ if (files != NULL) {
53667+ rcu_read_lock();
53668+ fdt = files_fdtable(files);
53669+ for (i=0; i < fdt->max_fds; i++) {
53670+ file = fcheck_files(files, i);
53671+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53672+ get_file(file);
53673+ our_file = file;
53674+ }
53675+ }
53676+ rcu_read_unlock();
53677+ put_files_struct(files);
53678+ }
53679+
53680+ if (our_file == NULL)
53681+ return 1;
53682+
53683+ read_lock(&tasklist_lock);
53684+ do_each_thread(p2, p) {
53685+ files = get_files_struct(p);
53686+ if (files == NULL ||
53687+ (p->signal && p->signal->tty == task->signal->tty)) {
53688+ if (files != NULL)
53689+ put_files_struct(files);
53690+ continue;
53691+ }
53692+ rcu_read_lock();
53693+ fdt = files_fdtable(files);
53694+ for (i=0; i < fdt->max_fds; i++) {
53695+ file = fcheck_files(files, i);
53696+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
53697+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
53698+ p3 = task;
53699+ while (p3->pid > 0) {
53700+ if (p3 == p)
53701+ break;
53702+ p3 = p3->real_parent;
53703+ }
53704+ if (p3 == p)
53705+ break;
53706+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
53707+ gr_handle_alertkill(p);
53708+ rcu_read_unlock();
53709+ put_files_struct(files);
53710+ read_unlock(&tasklist_lock);
53711+ fput(our_file);
53712+ return 0;
53713+ }
53714+ }
53715+ rcu_read_unlock();
53716+ put_files_struct(files);
53717+ } while_each_thread(p2, p);
53718+ read_unlock(&tasklist_lock);
53719+
53720+ fput(our_file);
53721+ return 1;
53722+}
53723+
53724+ssize_t
53725+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
53726+{
53727+ struct gr_arg_wrapper uwrap;
53728+ unsigned char *sprole_salt = NULL;
53729+ unsigned char *sprole_sum = NULL;
53730+ int error = sizeof (struct gr_arg_wrapper);
53731+ int error2 = 0;
53732+
53733+ mutex_lock(&gr_dev_mutex);
53734+
53735+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
53736+ error = -EPERM;
53737+ goto out;
53738+ }
53739+
53740+ if (count != sizeof (struct gr_arg_wrapper)) {
53741+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
53742+ error = -EINVAL;
53743+ goto out;
53744+ }
53745+
53746+
53747+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
53748+ gr_auth_expires = 0;
53749+ gr_auth_attempts = 0;
53750+ }
53751+
53752+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
53753+ error = -EFAULT;
53754+ goto out;
53755+ }
53756+
53757+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
53758+ error = -EINVAL;
53759+ goto out;
53760+ }
53761+
53762+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
53763+ error = -EFAULT;
53764+ goto out;
53765+ }
53766+
53767+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53768+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53769+ time_after(gr_auth_expires, get_seconds())) {
53770+ error = -EBUSY;
53771+ goto out;
53772+ }
53773+
53774+ /* if non-root trying to do anything other than use a special role,
53775+ do not attempt authentication, do not count towards authentication
53776+ locking
53777+ */
53778+
53779+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
53780+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53781+ current_uid()) {
53782+ error = -EPERM;
53783+ goto out;
53784+ }
53785+
53786+ /* ensure pw and special role name are null terminated */
53787+
53788+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
53789+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
53790+
53791+ /* Okay.
53792+ * We have our enough of the argument structure..(we have yet
53793+ * to copy_from_user the tables themselves) . Copy the tables
53794+ * only if we need them, i.e. for loading operations. */
53795+
53796+ switch (gr_usermode->mode) {
53797+ case GR_STATUS:
53798+ if (gr_status & GR_READY) {
53799+ error = 1;
53800+ if (!gr_check_secure_terminal(current))
53801+ error = 3;
53802+ } else
53803+ error = 2;
53804+ goto out;
53805+ case GR_SHUTDOWN:
53806+ if ((gr_status & GR_READY)
53807+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53808+ pax_open_kernel();
53809+ gr_status &= ~GR_READY;
53810+ pax_close_kernel();
53811+
53812+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
53813+ free_variables();
53814+ memset(gr_usermode, 0, sizeof (struct gr_arg));
53815+ memset(gr_system_salt, 0, GR_SALT_LEN);
53816+ memset(gr_system_sum, 0, GR_SHA_LEN);
53817+ } else if (gr_status & GR_READY) {
53818+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
53819+ error = -EPERM;
53820+ } else {
53821+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
53822+ error = -EAGAIN;
53823+ }
53824+ break;
53825+ case GR_ENABLE:
53826+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
53827+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
53828+ else {
53829+ if (gr_status & GR_READY)
53830+ error = -EAGAIN;
53831+ else
53832+ error = error2;
53833+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
53834+ }
53835+ break;
53836+ case GR_RELOAD:
53837+ if (!(gr_status & GR_READY)) {
53838+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
53839+ error = -EAGAIN;
53840+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53841+ preempt_disable();
53842+
53843+ pax_open_kernel();
53844+ gr_status &= ~GR_READY;
53845+ pax_close_kernel();
53846+
53847+ free_variables();
53848+ if (!(error2 = gracl_init(gr_usermode))) {
53849+ preempt_enable();
53850+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
53851+ } else {
53852+ preempt_enable();
53853+ error = error2;
53854+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53855+ }
53856+ } else {
53857+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53858+ error = -EPERM;
53859+ }
53860+ break;
53861+ case GR_SEGVMOD:
53862+ if (unlikely(!(gr_status & GR_READY))) {
53863+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
53864+ error = -EAGAIN;
53865+ break;
53866+ }
53867+
53868+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53869+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
53870+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
53871+ struct acl_subject_label *segvacl;
53872+ segvacl =
53873+ lookup_acl_subj_label(gr_usermode->segv_inode,
53874+ gr_usermode->segv_device,
53875+ current->role);
53876+ if (segvacl) {
53877+ segvacl->crashes = 0;
53878+ segvacl->expires = 0;
53879+ }
53880+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
53881+ gr_remove_uid(gr_usermode->segv_uid);
53882+ }
53883+ } else {
53884+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
53885+ error = -EPERM;
53886+ }
53887+ break;
53888+ case GR_SPROLE:
53889+ case GR_SPROLEPAM:
53890+ if (unlikely(!(gr_status & GR_READY))) {
53891+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
53892+ error = -EAGAIN;
53893+ break;
53894+ }
53895+
53896+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
53897+ current->role->expires = 0;
53898+ current->role->auth_attempts = 0;
53899+ }
53900+
53901+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53902+ time_after(current->role->expires, get_seconds())) {
53903+ error = -EBUSY;
53904+ goto out;
53905+ }
53906+
53907+ if (lookup_special_role_auth
53908+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
53909+ && ((!sprole_salt && !sprole_sum)
53910+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
53911+ char *p = "";
53912+ assign_special_role(gr_usermode->sp_role);
53913+ read_lock(&tasklist_lock);
53914+ if (current->real_parent)
53915+ p = current->real_parent->role->rolename;
53916+ read_unlock(&tasklist_lock);
53917+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
53918+ p, acl_sp_role_value);
53919+ } else {
53920+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
53921+ error = -EPERM;
53922+ if(!(current->role->auth_attempts++))
53923+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53924+
53925+ goto out;
53926+ }
53927+ break;
53928+ case GR_UNSPROLE:
53929+ if (unlikely(!(gr_status & GR_READY))) {
53930+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
53931+ error = -EAGAIN;
53932+ break;
53933+ }
53934+
53935+ if (current->role->roletype & GR_ROLE_SPECIAL) {
53936+ char *p = "";
53937+ int i = 0;
53938+
53939+ read_lock(&tasklist_lock);
53940+ if (current->real_parent) {
53941+ p = current->real_parent->role->rolename;
53942+ i = current->real_parent->acl_role_id;
53943+ }
53944+ read_unlock(&tasklist_lock);
53945+
53946+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
53947+ gr_set_acls(1);
53948+ } else {
53949+ error = -EPERM;
53950+ goto out;
53951+ }
53952+ break;
53953+ default:
53954+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
53955+ error = -EINVAL;
53956+ break;
53957+ }
53958+
53959+ if (error != -EPERM)
53960+ goto out;
53961+
53962+ if(!(gr_auth_attempts++))
53963+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53964+
53965+ out:
53966+ mutex_unlock(&gr_dev_mutex);
53967+ return error;
53968+}
53969+
53970+/* must be called with
53971+ rcu_read_lock();
53972+ read_lock(&tasklist_lock);
53973+ read_lock(&grsec_exec_file_lock);
53974+*/
53975+int gr_apply_subject_to_task(struct task_struct *task)
53976+{
53977+ struct acl_object_label *obj;
53978+ char *tmpname;
53979+ struct acl_subject_label *tmpsubj;
53980+ struct file *filp;
53981+ struct name_entry *nmatch;
53982+
53983+ filp = task->exec_file;
53984+ if (filp == NULL)
53985+ return 0;
53986+
53987+ /* the following is to apply the correct subject
53988+ on binaries running when the RBAC system
53989+ is enabled, when the binaries have been
53990+ replaced or deleted since their execution
53991+ -----
53992+ when the RBAC system starts, the inode/dev
53993+ from exec_file will be one the RBAC system
53994+ is unaware of. It only knows the inode/dev
53995+ of the present file on disk, or the absence
53996+ of it.
53997+ */
53998+ preempt_disable();
53999+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54000+
54001+ nmatch = lookup_name_entry(tmpname);
54002+ preempt_enable();
54003+ tmpsubj = NULL;
54004+ if (nmatch) {
54005+ if (nmatch->deleted)
54006+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54007+ else
54008+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54009+ if (tmpsubj != NULL)
54010+ task->acl = tmpsubj;
54011+ }
54012+ if (tmpsubj == NULL)
54013+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54014+ task->role);
54015+ if (task->acl) {
54016+ task->is_writable = 0;
54017+ /* ignore additional mmap checks for processes that are writable
54018+ by the default ACL */
54019+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54020+ if (unlikely(obj->mode & GR_WRITE))
54021+ task->is_writable = 1;
54022+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54023+ if (unlikely(obj->mode & GR_WRITE))
54024+ task->is_writable = 1;
54025+
54026+ gr_set_proc_res(task);
54027+
54028+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54029+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54030+#endif
54031+ } else {
54032+ return 1;
54033+ }
54034+
54035+ return 0;
54036+}
54037+
54038+int
54039+gr_set_acls(const int type)
54040+{
54041+ struct task_struct *task, *task2;
54042+ struct acl_role_label *role = current->role;
54043+ __u16 acl_role_id = current->acl_role_id;
54044+ const struct cred *cred;
54045+ int ret;
54046+
54047+ rcu_read_lock();
54048+ read_lock(&tasklist_lock);
54049+ read_lock(&grsec_exec_file_lock);
54050+ do_each_thread(task2, task) {
54051+ /* check to see if we're called from the exit handler,
54052+ if so, only replace ACLs that have inherited the admin
54053+ ACL */
54054+
54055+ if (type && (task->role != role ||
54056+ task->acl_role_id != acl_role_id))
54057+ continue;
54058+
54059+ task->acl_role_id = 0;
54060+ task->acl_sp_role = 0;
54061+
54062+ if (task->exec_file) {
54063+ cred = __task_cred(task);
54064+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54065+ ret = gr_apply_subject_to_task(task);
54066+ if (ret) {
54067+ read_unlock(&grsec_exec_file_lock);
54068+ read_unlock(&tasklist_lock);
54069+ rcu_read_unlock();
54070+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54071+ return ret;
54072+ }
54073+ } else {
54074+ // it's a kernel process
54075+ task->role = kernel_role;
54076+ task->acl = kernel_role->root_label;
54077+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54078+ task->acl->mode &= ~GR_PROCFIND;
54079+#endif
54080+ }
54081+ } while_each_thread(task2, task);
54082+ read_unlock(&grsec_exec_file_lock);
54083+ read_unlock(&tasklist_lock);
54084+ rcu_read_unlock();
54085+
54086+ return 0;
54087+}
54088+
54089+void
54090+gr_learn_resource(const struct task_struct *task,
54091+ const int res, const unsigned long wanted, const int gt)
54092+{
54093+ struct acl_subject_label *acl;
54094+ const struct cred *cred;
54095+
54096+ if (unlikely((gr_status & GR_READY) &&
54097+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54098+ goto skip_reslog;
54099+
54100+#ifdef CONFIG_GRKERNSEC_RESLOG
54101+ gr_log_resource(task, res, wanted, gt);
54102+#endif
54103+ skip_reslog:
54104+
54105+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54106+ return;
54107+
54108+ acl = task->acl;
54109+
54110+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54111+ !(acl->resmask & (1 << (unsigned short) res))))
54112+ return;
54113+
54114+ if (wanted >= acl->res[res].rlim_cur) {
54115+ unsigned long res_add;
54116+
54117+ res_add = wanted;
54118+ switch (res) {
54119+ case RLIMIT_CPU:
54120+ res_add += GR_RLIM_CPU_BUMP;
54121+ break;
54122+ case RLIMIT_FSIZE:
54123+ res_add += GR_RLIM_FSIZE_BUMP;
54124+ break;
54125+ case RLIMIT_DATA:
54126+ res_add += GR_RLIM_DATA_BUMP;
54127+ break;
54128+ case RLIMIT_STACK:
54129+ res_add += GR_RLIM_STACK_BUMP;
54130+ break;
54131+ case RLIMIT_CORE:
54132+ res_add += GR_RLIM_CORE_BUMP;
54133+ break;
54134+ case RLIMIT_RSS:
54135+ res_add += GR_RLIM_RSS_BUMP;
54136+ break;
54137+ case RLIMIT_NPROC:
54138+ res_add += GR_RLIM_NPROC_BUMP;
54139+ break;
54140+ case RLIMIT_NOFILE:
54141+ res_add += GR_RLIM_NOFILE_BUMP;
54142+ break;
54143+ case RLIMIT_MEMLOCK:
54144+ res_add += GR_RLIM_MEMLOCK_BUMP;
54145+ break;
54146+ case RLIMIT_AS:
54147+ res_add += GR_RLIM_AS_BUMP;
54148+ break;
54149+ case RLIMIT_LOCKS:
54150+ res_add += GR_RLIM_LOCKS_BUMP;
54151+ break;
54152+ case RLIMIT_SIGPENDING:
54153+ res_add += GR_RLIM_SIGPENDING_BUMP;
54154+ break;
54155+ case RLIMIT_MSGQUEUE:
54156+ res_add += GR_RLIM_MSGQUEUE_BUMP;
54157+ break;
54158+ case RLIMIT_NICE:
54159+ res_add += GR_RLIM_NICE_BUMP;
54160+ break;
54161+ case RLIMIT_RTPRIO:
54162+ res_add += GR_RLIM_RTPRIO_BUMP;
54163+ break;
54164+ case RLIMIT_RTTIME:
54165+ res_add += GR_RLIM_RTTIME_BUMP;
54166+ break;
54167+ }
54168+
54169+ acl->res[res].rlim_cur = res_add;
54170+
54171+ if (wanted > acl->res[res].rlim_max)
54172+ acl->res[res].rlim_max = res_add;
54173+
54174+ /* only log the subject filename, since resource logging is supported for
54175+ single-subject learning only */
54176+ rcu_read_lock();
54177+ cred = __task_cred(task);
54178+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54179+ task->role->roletype, cred->uid, cred->gid, acl->filename,
54180+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54181+ "", (unsigned long) res, &task->signal->saved_ip);
54182+ rcu_read_unlock();
54183+ }
54184+
54185+ return;
54186+}
54187+
54188+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54189+void
54190+pax_set_initial_flags(struct linux_binprm *bprm)
54191+{
54192+ struct task_struct *task = current;
54193+ struct acl_subject_label *proc;
54194+ unsigned long flags;
54195+
54196+ if (unlikely(!(gr_status & GR_READY)))
54197+ return;
54198+
54199+ flags = pax_get_flags(task);
54200+
54201+ proc = task->acl;
54202+
54203+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54204+ flags &= ~MF_PAX_PAGEEXEC;
54205+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54206+ flags &= ~MF_PAX_SEGMEXEC;
54207+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54208+ flags &= ~MF_PAX_RANDMMAP;
54209+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54210+ flags &= ~MF_PAX_EMUTRAMP;
54211+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54212+ flags &= ~MF_PAX_MPROTECT;
54213+
54214+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54215+ flags |= MF_PAX_PAGEEXEC;
54216+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54217+ flags |= MF_PAX_SEGMEXEC;
54218+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54219+ flags |= MF_PAX_RANDMMAP;
54220+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54221+ flags |= MF_PAX_EMUTRAMP;
54222+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54223+ flags |= MF_PAX_MPROTECT;
54224+
54225+ pax_set_flags(task, flags);
54226+
54227+ return;
54228+}
54229+#endif
54230+
54231+#ifdef CONFIG_SYSCTL
54232+/* Eric Biederman likes breaking userland ABI and every inode-based security
54233+ system to save 35kb of memory */
54234+
54235+/* we modify the passed in filename, but adjust it back before returning */
54236+static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54237+{
54238+ struct name_entry *nmatch;
54239+ char *p, *lastp = NULL;
54240+ struct acl_object_label *obj = NULL, *tmp;
54241+ struct acl_subject_label *tmpsubj;
54242+ char c = '\0';
54243+
54244+ read_lock(&gr_inode_lock);
54245+
54246+ p = name + len - 1;
54247+ do {
54248+ nmatch = lookup_name_entry(name);
54249+ if (lastp != NULL)
54250+ *lastp = c;
54251+
54252+ if (nmatch == NULL)
54253+ goto next_component;
54254+ tmpsubj = current->acl;
54255+ do {
54256+ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54257+ if (obj != NULL) {
54258+ tmp = obj->globbed;
54259+ while (tmp) {
54260+ if (!glob_match(tmp->filename, name)) {
54261+ obj = tmp;
54262+ goto found_obj;
54263+ }
54264+ tmp = tmp->next;
54265+ }
54266+ goto found_obj;
54267+ }
54268+ } while ((tmpsubj = tmpsubj->parent_subject));
54269+next_component:
54270+ /* end case */
54271+ if (p == name)
54272+ break;
54273+
54274+ while (*p != '/')
54275+ p--;
54276+ if (p == name)
54277+ lastp = p + 1;
54278+ else {
54279+ lastp = p;
54280+ p--;
54281+ }
54282+ c = *lastp;
54283+ *lastp = '\0';
54284+ } while (1);
54285+found_obj:
54286+ read_unlock(&gr_inode_lock);
54287+ /* obj returned will always be non-null */
54288+ return obj;
54289+}
54290+
54291+/* returns 0 when allowing, non-zero on error
54292+ op of 0 is used for readdir, so we don't log the names of hidden files
54293+*/
54294+__u32
54295+gr_handle_sysctl(const struct ctl_table *table, const int op)
54296+{
54297+ struct ctl_table *tmp;
54298+ const char *proc_sys = "/proc/sys";
54299+ char *path;
54300+ struct acl_object_label *obj;
54301+ unsigned short len = 0, pos = 0, depth = 0, i;
54302+ __u32 err = 0;
54303+ __u32 mode = 0;
54304+
54305+ if (unlikely(!(gr_status & GR_READY)))
54306+ return 0;
54307+
54308+ /* for now, ignore operations on non-sysctl entries if it's not a
54309+ readdir*/
54310+ if (table->child != NULL && op != 0)
54311+ return 0;
54312+
54313+ mode |= GR_FIND;
54314+ /* it's only a read if it's an entry, read on dirs is for readdir */
54315+ if (op & MAY_READ)
54316+ mode |= GR_READ;
54317+ if (op & MAY_WRITE)
54318+ mode |= GR_WRITE;
54319+
54320+ preempt_disable();
54321+
54322+ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54323+
54324+ /* it's only a read/write if it's an actual entry, not a dir
54325+ (which are opened for readdir)
54326+ */
54327+
54328+ /* convert the requested sysctl entry into a pathname */
54329+
54330+ for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54331+ len += strlen(tmp->procname);
54332+ len++;
54333+ depth++;
54334+ }
54335+
54336+ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
54337+ /* deny */
54338+ goto out;
54339+ }
54340+
54341+ memset(path, 0, PAGE_SIZE);
54342+
54343+ memcpy(path, proc_sys, strlen(proc_sys));
54344+
54345+ pos += strlen(proc_sys);
54346+
54347+ for (; depth > 0; depth--) {
54348+ path[pos] = '/';
54349+ pos++;
54350+ for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54351+ if (depth == i) {
54352+ memcpy(path + pos, tmp->procname,
54353+ strlen(tmp->procname));
54354+ pos += strlen(tmp->procname);
54355+ }
54356+ i++;
54357+ }
54358+ }
54359+
54360+ obj = gr_lookup_by_name(path, pos);
54361+ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
54362+
54363+ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
54364+ ((err & mode) != mode))) {
54365+ __u32 new_mode = mode;
54366+
54367+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54368+
54369+ err = 0;
54370+ gr_log_learn_sysctl(path, new_mode);
54371+ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
54372+ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
54373+ err = -ENOENT;
54374+ } else if (!(err & GR_FIND)) {
54375+ err = -ENOENT;
54376+ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
54377+ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
54378+ path, (mode & GR_READ) ? " reading" : "",
54379+ (mode & GR_WRITE) ? " writing" : "");
54380+ err = -EACCES;
54381+ } else if ((err & mode) != mode) {
54382+ err = -EACCES;
54383+ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
54384+ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
54385+ path, (mode & GR_READ) ? " reading" : "",
54386+ (mode & GR_WRITE) ? " writing" : "");
54387+ err = 0;
54388+ } else
54389+ err = 0;
54390+
54391+ out:
54392+ preempt_enable();
54393+
54394+ return err;
54395+}
54396+#endif
54397+
54398+int
54399+gr_handle_proc_ptrace(struct task_struct *task)
54400+{
54401+ struct file *filp;
54402+ struct task_struct *tmp = task;
54403+ struct task_struct *curtemp = current;
54404+ __u32 retmode;
54405+
54406+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54407+ if (unlikely(!(gr_status & GR_READY)))
54408+ return 0;
54409+#endif
54410+
54411+ read_lock(&tasklist_lock);
54412+ read_lock(&grsec_exec_file_lock);
54413+ filp = task->exec_file;
54414+
54415+ while (tmp->pid > 0) {
54416+ if (tmp == curtemp)
54417+ break;
54418+ tmp = tmp->real_parent;
54419+ }
54420+
54421+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54422+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54423+ read_unlock(&grsec_exec_file_lock);
54424+ read_unlock(&tasklist_lock);
54425+ return 1;
54426+ }
54427+
54428+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54429+ if (!(gr_status & GR_READY)) {
54430+ read_unlock(&grsec_exec_file_lock);
54431+ read_unlock(&tasklist_lock);
54432+ return 0;
54433+ }
54434+#endif
54435+
54436+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54437+ read_unlock(&grsec_exec_file_lock);
54438+ read_unlock(&tasklist_lock);
54439+
54440+ if (retmode & GR_NOPTRACE)
54441+ return 1;
54442+
54443+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54444+ && (current->acl != task->acl || (current->acl != current->role->root_label
54445+ && current->pid != task->pid)))
54446+ return 1;
54447+
54448+ return 0;
54449+}
54450+
54451+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54452+{
54453+ if (unlikely(!(gr_status & GR_READY)))
54454+ return;
54455+
54456+ if (!(current->role->roletype & GR_ROLE_GOD))
54457+ return;
54458+
54459+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54460+ p->role->rolename, gr_task_roletype_to_char(p),
54461+ p->acl->filename);
54462+}
54463+
54464+int
54465+gr_handle_ptrace(struct task_struct *task, const long request)
54466+{
54467+ struct task_struct *tmp = task;
54468+ struct task_struct *curtemp = current;
54469+ __u32 retmode;
54470+
54471+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54472+ if (unlikely(!(gr_status & GR_READY)))
54473+ return 0;
54474+#endif
54475+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
54476+ read_lock(&tasklist_lock);
54477+ while (tmp->pid > 0) {
54478+ if (tmp == curtemp)
54479+ break;
54480+ tmp = tmp->real_parent;
54481+ }
54482+
54483+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54484+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54485+ read_unlock(&tasklist_lock);
54486+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54487+ return 1;
54488+ }
54489+ read_unlock(&tasklist_lock);
54490+ }
54491+
54492+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54493+ if (!(gr_status & GR_READY))
54494+ return 0;
54495+#endif
54496+
54497+ read_lock(&grsec_exec_file_lock);
54498+ if (unlikely(!task->exec_file)) {
54499+ read_unlock(&grsec_exec_file_lock);
54500+ return 0;
54501+ }
54502+
54503+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54504+ read_unlock(&grsec_exec_file_lock);
54505+
54506+ if (retmode & GR_NOPTRACE) {
54507+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54508+ return 1;
54509+ }
54510+
54511+ if (retmode & GR_PTRACERD) {
54512+ switch (request) {
54513+ case PTRACE_SEIZE:
54514+ case PTRACE_POKETEXT:
54515+ case PTRACE_POKEDATA:
54516+ case PTRACE_POKEUSR:
54517+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54518+ case PTRACE_SETREGS:
54519+ case PTRACE_SETFPREGS:
54520+#endif
54521+#ifdef CONFIG_X86
54522+ case PTRACE_SETFPXREGS:
54523+#endif
54524+#ifdef CONFIG_ALTIVEC
54525+ case PTRACE_SETVRREGS:
54526+#endif
54527+ return 1;
54528+ default:
54529+ return 0;
54530+ }
54531+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
54532+ !(current->role->roletype & GR_ROLE_GOD) &&
54533+ (current->acl != task->acl)) {
54534+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54535+ return 1;
54536+ }
54537+
54538+ return 0;
54539+}
54540+
54541+static int is_writable_mmap(const struct file *filp)
54542+{
54543+ struct task_struct *task = current;
54544+ struct acl_object_label *obj, *obj2;
54545+
54546+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54547+ !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))) {
54548+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54549+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54550+ task->role->root_label);
54551+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54552+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54553+ return 1;
54554+ }
54555+ }
54556+ return 0;
54557+}
54558+
54559+int
54560+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54561+{
54562+ __u32 mode;
54563+
54564+ if (unlikely(!file || !(prot & PROT_EXEC)))
54565+ return 1;
54566+
54567+ if (is_writable_mmap(file))
54568+ return 0;
54569+
54570+ mode =
54571+ gr_search_file(file->f_path.dentry,
54572+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54573+ file->f_path.mnt);
54574+
54575+ if (!gr_tpe_allow(file))
54576+ return 0;
54577+
54578+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54579+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54580+ return 0;
54581+ } else if (unlikely(!(mode & GR_EXEC))) {
54582+ return 0;
54583+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54584+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54585+ return 1;
54586+ }
54587+
54588+ return 1;
54589+}
54590+
54591+int
54592+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54593+{
54594+ __u32 mode;
54595+
54596+ if (unlikely(!file || !(prot & PROT_EXEC)))
54597+ return 1;
54598+
54599+ if (is_writable_mmap(file))
54600+ return 0;
54601+
54602+ mode =
54603+ gr_search_file(file->f_path.dentry,
54604+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54605+ file->f_path.mnt);
54606+
54607+ if (!gr_tpe_allow(file))
54608+ return 0;
54609+
54610+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54611+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54612+ return 0;
54613+ } else if (unlikely(!(mode & GR_EXEC))) {
54614+ return 0;
54615+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54616+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54617+ return 1;
54618+ }
54619+
54620+ return 1;
54621+}
54622+
54623+void
54624+gr_acl_handle_psacct(struct task_struct *task, const long code)
54625+{
54626+ unsigned long runtime;
54627+ unsigned long cputime;
54628+ unsigned int wday, cday;
54629+ __u8 whr, chr;
54630+ __u8 wmin, cmin;
54631+ __u8 wsec, csec;
54632+ struct timespec timeval;
54633+
54634+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54635+ !(task->acl->mode & GR_PROCACCT)))
54636+ return;
54637+
54638+ do_posix_clock_monotonic_gettime(&timeval);
54639+ runtime = timeval.tv_sec - task->start_time.tv_sec;
54640+ wday = runtime / (3600 * 24);
54641+ runtime -= wday * (3600 * 24);
54642+ whr = runtime / 3600;
54643+ runtime -= whr * 3600;
54644+ wmin = runtime / 60;
54645+ runtime -= wmin * 60;
54646+ wsec = runtime;
54647+
54648+ cputime = (task->utime + task->stime) / HZ;
54649+ cday = cputime / (3600 * 24);
54650+ cputime -= cday * (3600 * 24);
54651+ chr = cputime / 3600;
54652+ cputime -= chr * 3600;
54653+ cmin = cputime / 60;
54654+ cputime -= cmin * 60;
54655+ csec = cputime;
54656+
54657+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54658+
54659+ return;
54660+}
54661+
54662+void gr_set_kernel_label(struct task_struct *task)
54663+{
54664+ if (gr_status & GR_READY) {
54665+ task->role = kernel_role;
54666+ task->acl = kernel_role->root_label;
54667+ }
54668+ return;
54669+}
54670+
54671+#ifdef CONFIG_TASKSTATS
54672+int gr_is_taskstats_denied(int pid)
54673+{
54674+ struct task_struct *task;
54675+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54676+ const struct cred *cred;
54677+#endif
54678+ int ret = 0;
54679+
54680+ /* restrict taskstats viewing to un-chrooted root users
54681+ who have the 'view' subject flag if the RBAC system is enabled
54682+ */
54683+
54684+ rcu_read_lock();
54685+ read_lock(&tasklist_lock);
54686+ task = find_task_by_vpid(pid);
54687+ if (task) {
54688+#ifdef CONFIG_GRKERNSEC_CHROOT
54689+ if (proc_is_chrooted(task))
54690+ ret = -EACCES;
54691+#endif
54692+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54693+ cred = __task_cred(task);
54694+#ifdef CONFIG_GRKERNSEC_PROC_USER
54695+ if (cred->uid != 0)
54696+ ret = -EACCES;
54697+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54698+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54699+ ret = -EACCES;
54700+#endif
54701+#endif
54702+ if (gr_status & GR_READY) {
54703+ if (!(task->acl->mode & GR_VIEW))
54704+ ret = -EACCES;
54705+ }
54706+ } else
54707+ ret = -ENOENT;
54708+
54709+ read_unlock(&tasklist_lock);
54710+ rcu_read_unlock();
54711+
54712+ return ret;
54713+}
54714+#endif
54715+
54716+/* AUXV entries are filled via a descendant of search_binary_handler
54717+ after we've already applied the subject for the target
54718+*/
54719+int gr_acl_enable_at_secure(void)
54720+{
54721+ if (unlikely(!(gr_status & GR_READY)))
54722+ return 0;
54723+
54724+ if (current->acl->mode & GR_ATSECURE)
54725+ return 1;
54726+
54727+ return 0;
54728+}
54729+
54730+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54731+{
54732+ struct task_struct *task = current;
54733+ struct dentry *dentry = file->f_path.dentry;
54734+ struct vfsmount *mnt = file->f_path.mnt;
54735+ struct acl_object_label *obj, *tmp;
54736+ struct acl_subject_label *subj;
54737+ unsigned int bufsize;
54738+ int is_not_root;
54739+ char *path;
54740+ dev_t dev = __get_dev(dentry);
54741+
54742+ if (unlikely(!(gr_status & GR_READY)))
54743+ return 1;
54744+
54745+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54746+ return 1;
54747+
54748+ /* ignore Eric Biederman */
54749+ if (IS_PRIVATE(dentry->d_inode))
54750+ return 1;
54751+
54752+ subj = task->acl;
54753+ do {
54754+ obj = lookup_acl_obj_label(ino, dev, subj);
54755+ if (obj != NULL)
54756+ return (obj->mode & GR_FIND) ? 1 : 0;
54757+ } while ((subj = subj->parent_subject));
54758+
54759+ /* this is purely an optimization since we're looking for an object
54760+ for the directory we're doing a readdir on
54761+ if it's possible for any globbed object to match the entry we're
54762+ filling into the directory, then the object we find here will be
54763+ an anchor point with attached globbed objects
54764+ */
54765+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54766+ if (obj->globbed == NULL)
54767+ return (obj->mode & GR_FIND) ? 1 : 0;
54768+
54769+ is_not_root = ((obj->filename[0] == '/') &&
54770+ (obj->filename[1] == '\0')) ? 0 : 1;
54771+ bufsize = PAGE_SIZE - namelen - is_not_root;
54772+
54773+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
54774+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54775+ return 1;
54776+
54777+ preempt_disable();
54778+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54779+ bufsize);
54780+
54781+ bufsize = strlen(path);
54782+
54783+ /* if base is "/", don't append an additional slash */
54784+ if (is_not_root)
54785+ *(path + bufsize) = '/';
54786+ memcpy(path + bufsize + is_not_root, name, namelen);
54787+ *(path + bufsize + namelen + is_not_root) = '\0';
54788+
54789+ tmp = obj->globbed;
54790+ while (tmp) {
54791+ if (!glob_match(tmp->filename, path)) {
54792+ preempt_enable();
54793+ return (tmp->mode & GR_FIND) ? 1 : 0;
54794+ }
54795+ tmp = tmp->next;
54796+ }
54797+ preempt_enable();
54798+ return (obj->mode & GR_FIND) ? 1 : 0;
54799+}
54800+
54801+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54802+EXPORT_SYMBOL(gr_acl_is_enabled);
54803+#endif
54804+EXPORT_SYMBOL(gr_learn_resource);
54805+EXPORT_SYMBOL(gr_set_kernel_label);
54806+#ifdef CONFIG_SECURITY
54807+EXPORT_SYMBOL(gr_check_user_change);
54808+EXPORT_SYMBOL(gr_check_group_change);
54809+#endif
54810+
54811diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54812new file mode 100644
54813index 0000000..34fefda
54814--- /dev/null
54815+++ b/grsecurity/gracl_alloc.c
54816@@ -0,0 +1,105 @@
54817+#include <linux/kernel.h>
54818+#include <linux/mm.h>
54819+#include <linux/slab.h>
54820+#include <linux/vmalloc.h>
54821+#include <linux/gracl.h>
54822+#include <linux/grsecurity.h>
54823+
54824+static unsigned long alloc_stack_next = 1;
54825+static unsigned long alloc_stack_size = 1;
54826+static void **alloc_stack;
54827+
54828+static __inline__ int
54829+alloc_pop(void)
54830+{
54831+ if (alloc_stack_next == 1)
54832+ return 0;
54833+
54834+ kfree(alloc_stack[alloc_stack_next - 2]);
54835+
54836+ alloc_stack_next--;
54837+
54838+ return 1;
54839+}
54840+
54841+static __inline__ int
54842+alloc_push(void *buf)
54843+{
54844+ if (alloc_stack_next >= alloc_stack_size)
54845+ return 1;
54846+
54847+ alloc_stack[alloc_stack_next - 1] = buf;
54848+
54849+ alloc_stack_next++;
54850+
54851+ return 0;
54852+}
54853+
54854+void *
54855+acl_alloc(unsigned long len)
54856+{
54857+ void *ret = NULL;
54858+
54859+ if (!len || len > PAGE_SIZE)
54860+ goto out;
54861+
54862+ ret = kmalloc(len, GFP_KERNEL);
54863+
54864+ if (ret) {
54865+ if (alloc_push(ret)) {
54866+ kfree(ret);
54867+ ret = NULL;
54868+ }
54869+ }
54870+
54871+out:
54872+ return ret;
54873+}
54874+
54875+void *
54876+acl_alloc_num(unsigned long num, unsigned long len)
54877+{
54878+ if (!len || (num > (PAGE_SIZE / len)))
54879+ return NULL;
54880+
54881+ return acl_alloc(num * len);
54882+}
54883+
54884+void
54885+acl_free_all(void)
54886+{
54887+ if (gr_acl_is_enabled() || !alloc_stack)
54888+ return;
54889+
54890+ while (alloc_pop()) ;
54891+
54892+ if (alloc_stack) {
54893+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
54894+ kfree(alloc_stack);
54895+ else
54896+ vfree(alloc_stack);
54897+ }
54898+
54899+ alloc_stack = NULL;
54900+ alloc_stack_size = 1;
54901+ alloc_stack_next = 1;
54902+
54903+ return;
54904+}
54905+
54906+int
54907+acl_alloc_stack_init(unsigned long size)
54908+{
54909+ if ((size * sizeof (void *)) <= PAGE_SIZE)
54910+ alloc_stack =
54911+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
54912+ else
54913+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
54914+
54915+ alloc_stack_size = size;
54916+
54917+ if (!alloc_stack)
54918+ return 0;
54919+ else
54920+ return 1;
54921+}
54922diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
54923new file mode 100644
54924index 0000000..6d21049
54925--- /dev/null
54926+++ b/grsecurity/gracl_cap.c
54927@@ -0,0 +1,110 @@
54928+#include <linux/kernel.h>
54929+#include <linux/module.h>
54930+#include <linux/sched.h>
54931+#include <linux/gracl.h>
54932+#include <linux/grsecurity.h>
54933+#include <linux/grinternal.h>
54934+
54935+extern const char *captab_log[];
54936+extern int captab_log_entries;
54937+
54938+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
54939+{
54940+ struct acl_subject_label *curracl;
54941+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54942+ kernel_cap_t cap_audit = __cap_empty_set;
54943+
54944+ if (!gr_acl_is_enabled())
54945+ return 1;
54946+
54947+ curracl = task->acl;
54948+
54949+ cap_drop = curracl->cap_lower;
54950+ cap_mask = curracl->cap_mask;
54951+ cap_audit = curracl->cap_invert_audit;
54952+
54953+ while ((curracl = curracl->parent_subject)) {
54954+ /* if the cap isn't specified in the current computed mask but is specified in the
54955+ current level subject, and is lowered in the current level subject, then add
54956+ it to the set of dropped capabilities
54957+ otherwise, add the current level subject's mask to the current computed mask
54958+ */
54959+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54960+ cap_raise(cap_mask, cap);
54961+ if (cap_raised(curracl->cap_lower, cap))
54962+ cap_raise(cap_drop, cap);
54963+ if (cap_raised(curracl->cap_invert_audit, cap))
54964+ cap_raise(cap_audit, cap);
54965+ }
54966+ }
54967+
54968+ if (!cap_raised(cap_drop, cap)) {
54969+ if (cap_raised(cap_audit, cap))
54970+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
54971+ return 1;
54972+ }
54973+
54974+ curracl = task->acl;
54975+
54976+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
54977+ && cap_raised(cred->cap_effective, cap)) {
54978+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54979+ task->role->roletype, cred->uid,
54980+ cred->gid, task->exec_file ?
54981+ gr_to_filename(task->exec_file->f_path.dentry,
54982+ task->exec_file->f_path.mnt) : curracl->filename,
54983+ curracl->filename, 0UL,
54984+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
54985+ return 1;
54986+ }
54987+
54988+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
54989+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
54990+
54991+ return 0;
54992+}
54993+
54994+int
54995+gr_acl_is_capable(const int cap)
54996+{
54997+ return gr_task_acl_is_capable(current, current_cred(), cap);
54998+}
54999+
55000+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55001+{
55002+ struct acl_subject_label *curracl;
55003+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55004+
55005+ if (!gr_acl_is_enabled())
55006+ return 1;
55007+
55008+ curracl = task->acl;
55009+
55010+ cap_drop = curracl->cap_lower;
55011+ cap_mask = curracl->cap_mask;
55012+
55013+ while ((curracl = curracl->parent_subject)) {
55014+ /* if the cap isn't specified in the current computed mask but is specified in the
55015+ current level subject, and is lowered in the current level subject, then add
55016+ it to the set of dropped capabilities
55017+ otherwise, add the current level subject's mask to the current computed mask
55018+ */
55019+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55020+ cap_raise(cap_mask, cap);
55021+ if (cap_raised(curracl->cap_lower, cap))
55022+ cap_raise(cap_drop, cap);
55023+ }
55024+ }
55025+
55026+ if (!cap_raised(cap_drop, cap))
55027+ return 1;
55028+
55029+ return 0;
55030+}
55031+
55032+int
55033+gr_acl_is_capable_nolog(const int cap)
55034+{
55035+ return gr_task_acl_is_capable_nolog(current, cap);
55036+}
55037+
55038diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55039new file mode 100644
55040index 0000000..88d0e87
55041--- /dev/null
55042+++ b/grsecurity/gracl_fs.c
55043@@ -0,0 +1,435 @@
55044+#include <linux/kernel.h>
55045+#include <linux/sched.h>
55046+#include <linux/types.h>
55047+#include <linux/fs.h>
55048+#include <linux/file.h>
55049+#include <linux/stat.h>
55050+#include <linux/grsecurity.h>
55051+#include <linux/grinternal.h>
55052+#include <linux/gracl.h>
55053+
55054+umode_t
55055+gr_acl_umask(void)
55056+{
55057+ if (unlikely(!gr_acl_is_enabled()))
55058+ return 0;
55059+
55060+ return current->role->umask;
55061+}
55062+
55063+__u32
55064+gr_acl_handle_hidden_file(const struct dentry * dentry,
55065+ const struct vfsmount * mnt)
55066+{
55067+ __u32 mode;
55068+
55069+ if (unlikely(!dentry->d_inode))
55070+ return GR_FIND;
55071+
55072+ mode =
55073+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55074+
55075+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55076+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55077+ return mode;
55078+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55079+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55080+ return 0;
55081+ } else if (unlikely(!(mode & GR_FIND)))
55082+ return 0;
55083+
55084+ return GR_FIND;
55085+}
55086+
55087+__u32
55088+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55089+ int acc_mode)
55090+{
55091+ __u32 reqmode = GR_FIND;
55092+ __u32 mode;
55093+
55094+ if (unlikely(!dentry->d_inode))
55095+ return reqmode;
55096+
55097+ if (acc_mode & MAY_APPEND)
55098+ reqmode |= GR_APPEND;
55099+ else if (acc_mode & MAY_WRITE)
55100+ reqmode |= GR_WRITE;
55101+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55102+ reqmode |= GR_READ;
55103+
55104+ mode =
55105+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55106+ mnt);
55107+
55108+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55109+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55110+ reqmode & GR_READ ? " reading" : "",
55111+ reqmode & GR_WRITE ? " writing" : reqmode &
55112+ GR_APPEND ? " appending" : "");
55113+ return reqmode;
55114+ } else
55115+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55116+ {
55117+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55118+ reqmode & GR_READ ? " reading" : "",
55119+ reqmode & GR_WRITE ? " writing" : reqmode &
55120+ GR_APPEND ? " appending" : "");
55121+ return 0;
55122+ } else if (unlikely((mode & reqmode) != reqmode))
55123+ return 0;
55124+
55125+ return reqmode;
55126+}
55127+
55128+__u32
55129+gr_acl_handle_creat(const struct dentry * dentry,
55130+ const struct dentry * p_dentry,
55131+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55132+ const int imode)
55133+{
55134+ __u32 reqmode = GR_WRITE | GR_CREATE;
55135+ __u32 mode;
55136+
55137+ if (acc_mode & MAY_APPEND)
55138+ reqmode |= GR_APPEND;
55139+ // if a directory was required or the directory already exists, then
55140+ // don't count this open as a read
55141+ if ((acc_mode & MAY_READ) &&
55142+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55143+ reqmode |= GR_READ;
55144+ if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
55145+ reqmode |= GR_SETID;
55146+
55147+ mode =
55148+ gr_check_create(dentry, p_dentry, p_mnt,
55149+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55150+
55151+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55152+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55153+ reqmode & GR_READ ? " reading" : "",
55154+ reqmode & GR_WRITE ? " writing" : reqmode &
55155+ GR_APPEND ? " appending" : "");
55156+ return reqmode;
55157+ } else
55158+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55159+ {
55160+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55161+ reqmode & GR_READ ? " reading" : "",
55162+ reqmode & GR_WRITE ? " writing" : reqmode &
55163+ GR_APPEND ? " appending" : "");
55164+ return 0;
55165+ } else if (unlikely((mode & reqmode) != reqmode))
55166+ return 0;
55167+
55168+ return reqmode;
55169+}
55170+
55171+__u32
55172+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55173+ const int fmode)
55174+{
55175+ __u32 mode, reqmode = GR_FIND;
55176+
55177+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55178+ reqmode |= GR_EXEC;
55179+ if (fmode & S_IWOTH)
55180+ reqmode |= GR_WRITE;
55181+ if (fmode & S_IROTH)
55182+ reqmode |= GR_READ;
55183+
55184+ mode =
55185+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55186+ mnt);
55187+
55188+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55189+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55190+ reqmode & GR_READ ? " reading" : "",
55191+ reqmode & GR_WRITE ? " writing" : "",
55192+ reqmode & GR_EXEC ? " executing" : "");
55193+ return reqmode;
55194+ } else
55195+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55196+ {
55197+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55198+ reqmode & GR_READ ? " reading" : "",
55199+ reqmode & GR_WRITE ? " writing" : "",
55200+ reqmode & GR_EXEC ? " executing" : "");
55201+ return 0;
55202+ } else if (unlikely((mode & reqmode) != reqmode))
55203+ return 0;
55204+
55205+ return reqmode;
55206+}
55207+
55208+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55209+{
55210+ __u32 mode;
55211+
55212+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55213+
55214+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55215+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55216+ return mode;
55217+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55218+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55219+ return 0;
55220+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55221+ return 0;
55222+
55223+ return (reqmode);
55224+}
55225+
55226+__u32
55227+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55228+{
55229+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55230+}
55231+
55232+__u32
55233+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55234+{
55235+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55236+}
55237+
55238+__u32
55239+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55240+{
55241+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55242+}
55243+
55244+__u32
55245+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55246+{
55247+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55248+}
55249+
55250+__u32
55251+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55252+ umode_t *modeptr)
55253+{
55254+ umode_t mode;
55255+
55256+ *modeptr &= ~gr_acl_umask();
55257+ mode = *modeptr;
55258+
55259+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55260+ return 1;
55261+
55262+ if (unlikely(mode & (S_ISUID | S_ISGID))) {
55263+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55264+ GR_CHMOD_ACL_MSG);
55265+ } else {
55266+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55267+ }
55268+}
55269+
55270+__u32
55271+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55272+{
55273+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55274+}
55275+
55276+__u32
55277+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55278+{
55279+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55280+}
55281+
55282+__u32
55283+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55284+{
55285+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55286+}
55287+
55288+__u32
55289+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55290+{
55291+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55292+ GR_UNIXCONNECT_ACL_MSG);
55293+}
55294+
55295+/* hardlinks require at minimum create and link permission,
55296+ any additional privilege required is based on the
55297+ privilege of the file being linked to
55298+*/
55299+__u32
55300+gr_acl_handle_link(const struct dentry * new_dentry,
55301+ const struct dentry * parent_dentry,
55302+ const struct vfsmount * parent_mnt,
55303+ const struct dentry * old_dentry,
55304+ const struct vfsmount * old_mnt, const char *to)
55305+{
55306+ __u32 mode;
55307+ __u32 needmode = GR_CREATE | GR_LINK;
55308+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55309+
55310+ mode =
55311+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55312+ old_mnt);
55313+
55314+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55315+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55316+ return mode;
55317+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55318+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55319+ return 0;
55320+ } else if (unlikely((mode & needmode) != needmode))
55321+ return 0;
55322+
55323+ return 1;
55324+}
55325+
55326+__u32
55327+gr_acl_handle_symlink(const struct dentry * new_dentry,
55328+ const struct dentry * parent_dentry,
55329+ const struct vfsmount * parent_mnt, const char *from)
55330+{
55331+ __u32 needmode = GR_WRITE | GR_CREATE;
55332+ __u32 mode;
55333+
55334+ mode =
55335+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
55336+ GR_CREATE | GR_AUDIT_CREATE |
55337+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55338+
55339+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55340+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55341+ return mode;
55342+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55343+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55344+ return 0;
55345+ } else if (unlikely((mode & needmode) != needmode))
55346+ return 0;
55347+
55348+ return (GR_WRITE | GR_CREATE);
55349+}
55350+
55351+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)
55352+{
55353+ __u32 mode;
55354+
55355+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55356+
55357+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55358+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55359+ return mode;
55360+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55361+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55362+ return 0;
55363+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55364+ return 0;
55365+
55366+ return (reqmode);
55367+}
55368+
55369+__u32
55370+gr_acl_handle_mknod(const struct dentry * new_dentry,
55371+ const struct dentry * parent_dentry,
55372+ const struct vfsmount * parent_mnt,
55373+ const int mode)
55374+{
55375+ __u32 reqmode = GR_WRITE | GR_CREATE;
55376+ if (unlikely(mode & (S_ISUID | S_ISGID)))
55377+ reqmode |= GR_SETID;
55378+
55379+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55380+ reqmode, GR_MKNOD_ACL_MSG);
55381+}
55382+
55383+__u32
55384+gr_acl_handle_mkdir(const struct dentry *new_dentry,
55385+ const struct dentry *parent_dentry,
55386+ const struct vfsmount *parent_mnt)
55387+{
55388+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55389+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55390+}
55391+
55392+#define RENAME_CHECK_SUCCESS(old, new) \
55393+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55394+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55395+
55396+int
55397+gr_acl_handle_rename(struct dentry *new_dentry,
55398+ struct dentry *parent_dentry,
55399+ const struct vfsmount *parent_mnt,
55400+ struct dentry *old_dentry,
55401+ struct inode *old_parent_inode,
55402+ struct vfsmount *old_mnt, const char *newname)
55403+{
55404+ __u32 comp1, comp2;
55405+ int error = 0;
55406+
55407+ if (unlikely(!gr_acl_is_enabled()))
55408+ return 0;
55409+
55410+ if (!new_dentry->d_inode) {
55411+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55412+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55413+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55414+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55415+ GR_DELETE | GR_AUDIT_DELETE |
55416+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55417+ GR_SUPPRESS, old_mnt);
55418+ } else {
55419+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55420+ GR_CREATE | GR_DELETE |
55421+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55422+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55423+ GR_SUPPRESS, parent_mnt);
55424+ comp2 =
55425+ gr_search_file(old_dentry,
55426+ GR_READ | GR_WRITE | GR_AUDIT_READ |
55427+ GR_DELETE | GR_AUDIT_DELETE |
55428+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55429+ }
55430+
55431+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55432+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55433+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55434+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55435+ && !(comp2 & GR_SUPPRESS)) {
55436+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55437+ error = -EACCES;
55438+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55439+ error = -EACCES;
55440+
55441+ return error;
55442+}
55443+
55444+void
55445+gr_acl_handle_exit(void)
55446+{
55447+ u16 id;
55448+ char *rolename;
55449+ struct file *exec_file;
55450+
55451+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55452+ !(current->role->roletype & GR_ROLE_PERSIST))) {
55453+ id = current->acl_role_id;
55454+ rolename = current->role->rolename;
55455+ gr_set_acls(1);
55456+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55457+ }
55458+
55459+ write_lock(&grsec_exec_file_lock);
55460+ exec_file = current->exec_file;
55461+ current->exec_file = NULL;
55462+ write_unlock(&grsec_exec_file_lock);
55463+
55464+ if (exec_file)
55465+ fput(exec_file);
55466+}
55467+
55468+int
55469+gr_acl_handle_procpidmem(const struct task_struct *task)
55470+{
55471+ if (unlikely(!gr_acl_is_enabled()))
55472+ return 0;
55473+
55474+ if (task != current && task->acl->mode & GR_PROTPROCFD)
55475+ return -EACCES;
55476+
55477+ return 0;
55478+}
55479diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55480new file mode 100644
55481index 0000000..58800a7
55482--- /dev/null
55483+++ b/grsecurity/gracl_ip.c
55484@@ -0,0 +1,384 @@
55485+#include <linux/kernel.h>
55486+#include <asm/uaccess.h>
55487+#include <asm/errno.h>
55488+#include <net/sock.h>
55489+#include <linux/file.h>
55490+#include <linux/fs.h>
55491+#include <linux/net.h>
55492+#include <linux/in.h>
55493+#include <linux/skbuff.h>
55494+#include <linux/ip.h>
55495+#include <linux/udp.h>
55496+#include <linux/types.h>
55497+#include <linux/sched.h>
55498+#include <linux/netdevice.h>
55499+#include <linux/inetdevice.h>
55500+#include <linux/gracl.h>
55501+#include <linux/grsecurity.h>
55502+#include <linux/grinternal.h>
55503+
55504+#define GR_BIND 0x01
55505+#define GR_CONNECT 0x02
55506+#define GR_INVERT 0x04
55507+#define GR_BINDOVERRIDE 0x08
55508+#define GR_CONNECTOVERRIDE 0x10
55509+#define GR_SOCK_FAMILY 0x20
55510+
55511+static const char * gr_protocols[IPPROTO_MAX] = {
55512+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55513+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55514+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55515+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55516+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55517+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55518+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55519+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55520+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55521+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55522+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55523+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55524+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55525+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55526+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55527+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55528+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55529+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55530+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55531+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55532+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55533+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55534+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55535+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55536+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55537+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55538+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55539+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55540+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55541+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55542+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55543+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55544+ };
55545+
55546+static const char * gr_socktypes[SOCK_MAX] = {
55547+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55548+ "unknown:7", "unknown:8", "unknown:9", "packet"
55549+ };
55550+
55551+static const char * gr_sockfamilies[AF_MAX+1] = {
55552+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55553+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55554+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55555+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55556+ };
55557+
55558+const char *
55559+gr_proto_to_name(unsigned char proto)
55560+{
55561+ return gr_protocols[proto];
55562+}
55563+
55564+const char *
55565+gr_socktype_to_name(unsigned char type)
55566+{
55567+ return gr_socktypes[type];
55568+}
55569+
55570+const char *
55571+gr_sockfamily_to_name(unsigned char family)
55572+{
55573+ return gr_sockfamilies[family];
55574+}
55575+
55576+int
55577+gr_search_socket(const int domain, const int type, const int protocol)
55578+{
55579+ struct acl_subject_label *curr;
55580+ const struct cred *cred = current_cred();
55581+
55582+ if (unlikely(!gr_acl_is_enabled()))
55583+ goto exit;
55584+
55585+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
55586+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55587+ goto exit; // let the kernel handle it
55588+
55589+ curr = current->acl;
55590+
55591+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55592+ /* the family is allowed, if this is PF_INET allow it only if
55593+ the extra sock type/protocol checks pass */
55594+ if (domain == PF_INET)
55595+ goto inet_check;
55596+ goto exit;
55597+ } else {
55598+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55599+ __u32 fakeip = 0;
55600+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55601+ current->role->roletype, cred->uid,
55602+ cred->gid, current->exec_file ?
55603+ gr_to_filename(current->exec_file->f_path.dentry,
55604+ current->exec_file->f_path.mnt) :
55605+ curr->filename, curr->filename,
55606+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55607+ &current->signal->saved_ip);
55608+ goto exit;
55609+ }
55610+ goto exit_fail;
55611+ }
55612+
55613+inet_check:
55614+ /* the rest of this checking is for IPv4 only */
55615+ if (!curr->ips)
55616+ goto exit;
55617+
55618+ if ((curr->ip_type & (1 << type)) &&
55619+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55620+ goto exit;
55621+
55622+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55623+ /* we don't place acls on raw sockets , and sometimes
55624+ dgram/ip sockets are opened for ioctl and not
55625+ bind/connect, so we'll fake a bind learn log */
55626+ if (type == SOCK_RAW || type == SOCK_PACKET) {
55627+ __u32 fakeip = 0;
55628+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55629+ current->role->roletype, cred->uid,
55630+ cred->gid, current->exec_file ?
55631+ gr_to_filename(current->exec_file->f_path.dentry,
55632+ current->exec_file->f_path.mnt) :
55633+ curr->filename, curr->filename,
55634+ &fakeip, 0, type,
55635+ protocol, GR_CONNECT, &current->signal->saved_ip);
55636+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55637+ __u32 fakeip = 0;
55638+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55639+ current->role->roletype, cred->uid,
55640+ cred->gid, current->exec_file ?
55641+ gr_to_filename(current->exec_file->f_path.dentry,
55642+ current->exec_file->f_path.mnt) :
55643+ curr->filename, curr->filename,
55644+ &fakeip, 0, type,
55645+ protocol, GR_BIND, &current->signal->saved_ip);
55646+ }
55647+ /* we'll log when they use connect or bind */
55648+ goto exit;
55649+ }
55650+
55651+exit_fail:
55652+ if (domain == PF_INET)
55653+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55654+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
55655+ else
55656+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55657+ gr_socktype_to_name(type), protocol);
55658+
55659+ return 0;
55660+exit:
55661+ return 1;
55662+}
55663+
55664+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)
55665+{
55666+ if ((ip->mode & mode) &&
55667+ (ip_port >= ip->low) &&
55668+ (ip_port <= ip->high) &&
55669+ ((ntohl(ip_addr) & our_netmask) ==
55670+ (ntohl(our_addr) & our_netmask))
55671+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55672+ && (ip->type & (1 << type))) {
55673+ if (ip->mode & GR_INVERT)
55674+ return 2; // specifically denied
55675+ else
55676+ return 1; // allowed
55677+ }
55678+
55679+ return 0; // not specifically allowed, may continue parsing
55680+}
55681+
55682+static int
55683+gr_search_connectbind(const int full_mode, struct sock *sk,
55684+ struct sockaddr_in *addr, const int type)
55685+{
55686+ char iface[IFNAMSIZ] = {0};
55687+ struct acl_subject_label *curr;
55688+ struct acl_ip_label *ip;
55689+ struct inet_sock *isk;
55690+ struct net_device *dev;
55691+ struct in_device *idev;
55692+ unsigned long i;
55693+ int ret;
55694+ int mode = full_mode & (GR_BIND | GR_CONNECT);
55695+ __u32 ip_addr = 0;
55696+ __u32 our_addr;
55697+ __u32 our_netmask;
55698+ char *p;
55699+ __u16 ip_port = 0;
55700+ const struct cred *cred = current_cred();
55701+
55702+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55703+ return 0;
55704+
55705+ curr = current->acl;
55706+ isk = inet_sk(sk);
55707+
55708+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55709+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55710+ addr->sin_addr.s_addr = curr->inaddr_any_override;
55711+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55712+ struct sockaddr_in saddr;
55713+ int err;
55714+
55715+ saddr.sin_family = AF_INET;
55716+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
55717+ saddr.sin_port = isk->inet_sport;
55718+
55719+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55720+ if (err)
55721+ return err;
55722+
55723+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55724+ if (err)
55725+ return err;
55726+ }
55727+
55728+ if (!curr->ips)
55729+ return 0;
55730+
55731+ ip_addr = addr->sin_addr.s_addr;
55732+ ip_port = ntohs(addr->sin_port);
55733+
55734+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55735+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55736+ current->role->roletype, cred->uid,
55737+ cred->gid, current->exec_file ?
55738+ gr_to_filename(current->exec_file->f_path.dentry,
55739+ current->exec_file->f_path.mnt) :
55740+ curr->filename, curr->filename,
55741+ &ip_addr, ip_port, type,
55742+ sk->sk_protocol, mode, &current->signal->saved_ip);
55743+ return 0;
55744+ }
55745+
55746+ for (i = 0; i < curr->ip_num; i++) {
55747+ ip = *(curr->ips + i);
55748+ if (ip->iface != NULL) {
55749+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
55750+ p = strchr(iface, ':');
55751+ if (p != NULL)
55752+ *p = '\0';
55753+ dev = dev_get_by_name(sock_net(sk), iface);
55754+ if (dev == NULL)
55755+ continue;
55756+ idev = in_dev_get(dev);
55757+ if (idev == NULL) {
55758+ dev_put(dev);
55759+ continue;
55760+ }
55761+ rcu_read_lock();
55762+ for_ifa(idev) {
55763+ if (!strcmp(ip->iface, ifa->ifa_label)) {
55764+ our_addr = ifa->ifa_address;
55765+ our_netmask = 0xffffffff;
55766+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55767+ if (ret == 1) {
55768+ rcu_read_unlock();
55769+ in_dev_put(idev);
55770+ dev_put(dev);
55771+ return 0;
55772+ } else if (ret == 2) {
55773+ rcu_read_unlock();
55774+ in_dev_put(idev);
55775+ dev_put(dev);
55776+ goto denied;
55777+ }
55778+ }
55779+ } endfor_ifa(idev);
55780+ rcu_read_unlock();
55781+ in_dev_put(idev);
55782+ dev_put(dev);
55783+ } else {
55784+ our_addr = ip->addr;
55785+ our_netmask = ip->netmask;
55786+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55787+ if (ret == 1)
55788+ return 0;
55789+ else if (ret == 2)
55790+ goto denied;
55791+ }
55792+ }
55793+
55794+denied:
55795+ if (mode == GR_BIND)
55796+ 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));
55797+ else if (mode == GR_CONNECT)
55798+ 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));
55799+
55800+ return -EACCES;
55801+}
55802+
55803+int
55804+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55805+{
55806+ /* always allow disconnection of dgram sockets with connect */
55807+ if (addr->sin_family == AF_UNSPEC)
55808+ return 0;
55809+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55810+}
55811+
55812+int
55813+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55814+{
55815+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55816+}
55817+
55818+int gr_search_listen(struct socket *sock)
55819+{
55820+ struct sock *sk = sock->sk;
55821+ struct sockaddr_in addr;
55822+
55823+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55824+ addr.sin_port = inet_sk(sk)->inet_sport;
55825+
55826+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55827+}
55828+
55829+int gr_search_accept(struct socket *sock)
55830+{
55831+ struct sock *sk = sock->sk;
55832+ struct sockaddr_in addr;
55833+
55834+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55835+ addr.sin_port = inet_sk(sk)->inet_sport;
55836+
55837+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55838+}
55839+
55840+int
55841+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
55842+{
55843+ if (addr)
55844+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
55845+ else {
55846+ struct sockaddr_in sin;
55847+ const struct inet_sock *inet = inet_sk(sk);
55848+
55849+ sin.sin_addr.s_addr = inet->inet_daddr;
55850+ sin.sin_port = inet->inet_dport;
55851+
55852+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55853+ }
55854+}
55855+
55856+int
55857+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
55858+{
55859+ struct sockaddr_in sin;
55860+
55861+ if (unlikely(skb->len < sizeof (struct udphdr)))
55862+ return 0; // skip this packet
55863+
55864+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
55865+ sin.sin_port = udp_hdr(skb)->source;
55866+
55867+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55868+}
55869diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
55870new file mode 100644
55871index 0000000..25f54ef
55872--- /dev/null
55873+++ b/grsecurity/gracl_learn.c
55874@@ -0,0 +1,207 @@
55875+#include <linux/kernel.h>
55876+#include <linux/mm.h>
55877+#include <linux/sched.h>
55878+#include <linux/poll.h>
55879+#include <linux/string.h>
55880+#include <linux/file.h>
55881+#include <linux/types.h>
55882+#include <linux/vmalloc.h>
55883+#include <linux/grinternal.h>
55884+
55885+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
55886+ size_t count, loff_t *ppos);
55887+extern int gr_acl_is_enabled(void);
55888+
55889+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
55890+static int gr_learn_attached;
55891+
55892+/* use a 512k buffer */
55893+#define LEARN_BUFFER_SIZE (512 * 1024)
55894+
55895+static DEFINE_SPINLOCK(gr_learn_lock);
55896+static DEFINE_MUTEX(gr_learn_user_mutex);
55897+
55898+/* we need to maintain two buffers, so that the kernel context of grlearn
55899+ uses a semaphore around the userspace copying, and the other kernel contexts
55900+ use a spinlock when copying into the buffer, since they cannot sleep
55901+*/
55902+static char *learn_buffer;
55903+static char *learn_buffer_user;
55904+static int learn_buffer_len;
55905+static int learn_buffer_user_len;
55906+
55907+static ssize_t
55908+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
55909+{
55910+ DECLARE_WAITQUEUE(wait, current);
55911+ ssize_t retval = 0;
55912+
55913+ add_wait_queue(&learn_wait, &wait);
55914+ set_current_state(TASK_INTERRUPTIBLE);
55915+ do {
55916+ mutex_lock(&gr_learn_user_mutex);
55917+ spin_lock(&gr_learn_lock);
55918+ if (learn_buffer_len)
55919+ break;
55920+ spin_unlock(&gr_learn_lock);
55921+ mutex_unlock(&gr_learn_user_mutex);
55922+ if (file->f_flags & O_NONBLOCK) {
55923+ retval = -EAGAIN;
55924+ goto out;
55925+ }
55926+ if (signal_pending(current)) {
55927+ retval = -ERESTARTSYS;
55928+ goto out;
55929+ }
55930+
55931+ schedule();
55932+ } while (1);
55933+
55934+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
55935+ learn_buffer_user_len = learn_buffer_len;
55936+ retval = learn_buffer_len;
55937+ learn_buffer_len = 0;
55938+
55939+ spin_unlock(&gr_learn_lock);
55940+
55941+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
55942+ retval = -EFAULT;
55943+
55944+ mutex_unlock(&gr_learn_user_mutex);
55945+out:
55946+ set_current_state(TASK_RUNNING);
55947+ remove_wait_queue(&learn_wait, &wait);
55948+ return retval;
55949+}
55950+
55951+static unsigned int
55952+poll_learn(struct file * file, poll_table * wait)
55953+{
55954+ poll_wait(file, &learn_wait, wait);
55955+
55956+ if (learn_buffer_len)
55957+ return (POLLIN | POLLRDNORM);
55958+
55959+ return 0;
55960+}
55961+
55962+void
55963+gr_clear_learn_entries(void)
55964+{
55965+ char *tmp;
55966+
55967+ mutex_lock(&gr_learn_user_mutex);
55968+ spin_lock(&gr_learn_lock);
55969+ tmp = learn_buffer;
55970+ learn_buffer = NULL;
55971+ spin_unlock(&gr_learn_lock);
55972+ if (tmp)
55973+ vfree(tmp);
55974+ if (learn_buffer_user != NULL) {
55975+ vfree(learn_buffer_user);
55976+ learn_buffer_user = NULL;
55977+ }
55978+ learn_buffer_len = 0;
55979+ mutex_unlock(&gr_learn_user_mutex);
55980+
55981+ return;
55982+}
55983+
55984+void
55985+gr_add_learn_entry(const char *fmt, ...)
55986+{
55987+ va_list args;
55988+ unsigned int len;
55989+
55990+ if (!gr_learn_attached)
55991+ return;
55992+
55993+ spin_lock(&gr_learn_lock);
55994+
55995+ /* leave a gap at the end so we know when it's "full" but don't have to
55996+ compute the exact length of the string we're trying to append
55997+ */
55998+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
55999+ spin_unlock(&gr_learn_lock);
56000+ wake_up_interruptible(&learn_wait);
56001+ return;
56002+ }
56003+ if (learn_buffer == NULL) {
56004+ spin_unlock(&gr_learn_lock);
56005+ return;
56006+ }
56007+
56008+ va_start(args, fmt);
56009+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56010+ va_end(args);
56011+
56012+ learn_buffer_len += len + 1;
56013+
56014+ spin_unlock(&gr_learn_lock);
56015+ wake_up_interruptible(&learn_wait);
56016+
56017+ return;
56018+}
56019+
56020+static int
56021+open_learn(struct inode *inode, struct file *file)
56022+{
56023+ if (file->f_mode & FMODE_READ && gr_learn_attached)
56024+ return -EBUSY;
56025+ if (file->f_mode & FMODE_READ) {
56026+ int retval = 0;
56027+ mutex_lock(&gr_learn_user_mutex);
56028+ if (learn_buffer == NULL)
56029+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56030+ if (learn_buffer_user == NULL)
56031+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56032+ if (learn_buffer == NULL) {
56033+ retval = -ENOMEM;
56034+ goto out_error;
56035+ }
56036+ if (learn_buffer_user == NULL) {
56037+ retval = -ENOMEM;
56038+ goto out_error;
56039+ }
56040+ learn_buffer_len = 0;
56041+ learn_buffer_user_len = 0;
56042+ gr_learn_attached = 1;
56043+out_error:
56044+ mutex_unlock(&gr_learn_user_mutex);
56045+ return retval;
56046+ }
56047+ return 0;
56048+}
56049+
56050+static int
56051+close_learn(struct inode *inode, struct file *file)
56052+{
56053+ if (file->f_mode & FMODE_READ) {
56054+ char *tmp = NULL;
56055+ mutex_lock(&gr_learn_user_mutex);
56056+ spin_lock(&gr_learn_lock);
56057+ tmp = learn_buffer;
56058+ learn_buffer = NULL;
56059+ spin_unlock(&gr_learn_lock);
56060+ if (tmp)
56061+ vfree(tmp);
56062+ if (learn_buffer_user != NULL) {
56063+ vfree(learn_buffer_user);
56064+ learn_buffer_user = NULL;
56065+ }
56066+ learn_buffer_len = 0;
56067+ learn_buffer_user_len = 0;
56068+ gr_learn_attached = 0;
56069+ mutex_unlock(&gr_learn_user_mutex);
56070+ }
56071+
56072+ return 0;
56073+}
56074+
56075+const struct file_operations grsec_fops = {
56076+ .read = read_learn,
56077+ .write = write_grsec_handler,
56078+ .open = open_learn,
56079+ .release = close_learn,
56080+ .poll = poll_learn,
56081+};
56082diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56083new file mode 100644
56084index 0000000..39645c9
56085--- /dev/null
56086+++ b/grsecurity/gracl_res.c
56087@@ -0,0 +1,68 @@
56088+#include <linux/kernel.h>
56089+#include <linux/sched.h>
56090+#include <linux/gracl.h>
56091+#include <linux/grinternal.h>
56092+
56093+static const char *restab_log[] = {
56094+ [RLIMIT_CPU] = "RLIMIT_CPU",
56095+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56096+ [RLIMIT_DATA] = "RLIMIT_DATA",
56097+ [RLIMIT_STACK] = "RLIMIT_STACK",
56098+ [RLIMIT_CORE] = "RLIMIT_CORE",
56099+ [RLIMIT_RSS] = "RLIMIT_RSS",
56100+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
56101+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56102+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56103+ [RLIMIT_AS] = "RLIMIT_AS",
56104+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56105+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56106+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56107+ [RLIMIT_NICE] = "RLIMIT_NICE",
56108+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56109+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56110+ [GR_CRASH_RES] = "RLIMIT_CRASH"
56111+};
56112+
56113+void
56114+gr_log_resource(const struct task_struct *task,
56115+ const int res, const unsigned long wanted, const int gt)
56116+{
56117+ const struct cred *cred;
56118+ unsigned long rlim;
56119+
56120+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
56121+ return;
56122+
56123+ // not yet supported resource
56124+ if (unlikely(!restab_log[res]))
56125+ return;
56126+
56127+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56128+ rlim = task_rlimit_max(task, res);
56129+ else
56130+ rlim = task_rlimit(task, res);
56131+
56132+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56133+ return;
56134+
56135+ rcu_read_lock();
56136+ cred = __task_cred(task);
56137+
56138+ if (res == RLIMIT_NPROC &&
56139+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56140+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56141+ goto out_rcu_unlock;
56142+ else if (res == RLIMIT_MEMLOCK &&
56143+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56144+ goto out_rcu_unlock;
56145+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56146+ goto out_rcu_unlock;
56147+ rcu_read_unlock();
56148+
56149+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56150+
56151+ return;
56152+out_rcu_unlock:
56153+ rcu_read_unlock();
56154+ return;
56155+}
56156diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56157new file mode 100644
56158index 0000000..5556be3
56159--- /dev/null
56160+++ b/grsecurity/gracl_segv.c
56161@@ -0,0 +1,299 @@
56162+#include <linux/kernel.h>
56163+#include <linux/mm.h>
56164+#include <asm/uaccess.h>
56165+#include <asm/errno.h>
56166+#include <asm/mman.h>
56167+#include <net/sock.h>
56168+#include <linux/file.h>
56169+#include <linux/fs.h>
56170+#include <linux/net.h>
56171+#include <linux/in.h>
56172+#include <linux/slab.h>
56173+#include <linux/types.h>
56174+#include <linux/sched.h>
56175+#include <linux/timer.h>
56176+#include <linux/gracl.h>
56177+#include <linux/grsecurity.h>
56178+#include <linux/grinternal.h>
56179+
56180+static struct crash_uid *uid_set;
56181+static unsigned short uid_used;
56182+static DEFINE_SPINLOCK(gr_uid_lock);
56183+extern rwlock_t gr_inode_lock;
56184+extern struct acl_subject_label *
56185+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56186+ struct acl_role_label *role);
56187+
56188+#ifdef CONFIG_BTRFS_FS
56189+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56190+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56191+#endif
56192+
56193+static inline dev_t __get_dev(const struct dentry *dentry)
56194+{
56195+#ifdef CONFIG_BTRFS_FS
56196+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56197+ return get_btrfs_dev_from_inode(dentry->d_inode);
56198+ else
56199+#endif
56200+ return dentry->d_inode->i_sb->s_dev;
56201+}
56202+
56203+int
56204+gr_init_uidset(void)
56205+{
56206+ uid_set =
56207+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56208+ uid_used = 0;
56209+
56210+ return uid_set ? 1 : 0;
56211+}
56212+
56213+void
56214+gr_free_uidset(void)
56215+{
56216+ if (uid_set)
56217+ kfree(uid_set);
56218+
56219+ return;
56220+}
56221+
56222+int
56223+gr_find_uid(const uid_t uid)
56224+{
56225+ struct crash_uid *tmp = uid_set;
56226+ uid_t buid;
56227+ int low = 0, high = uid_used - 1, mid;
56228+
56229+ while (high >= low) {
56230+ mid = (low + high) >> 1;
56231+ buid = tmp[mid].uid;
56232+ if (buid == uid)
56233+ return mid;
56234+ if (buid > uid)
56235+ high = mid - 1;
56236+ if (buid < uid)
56237+ low = mid + 1;
56238+ }
56239+
56240+ return -1;
56241+}
56242+
56243+static __inline__ void
56244+gr_insertsort(void)
56245+{
56246+ unsigned short i, j;
56247+ struct crash_uid index;
56248+
56249+ for (i = 1; i < uid_used; i++) {
56250+ index = uid_set[i];
56251+ j = i;
56252+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56253+ uid_set[j] = uid_set[j - 1];
56254+ j--;
56255+ }
56256+ uid_set[j] = index;
56257+ }
56258+
56259+ return;
56260+}
56261+
56262+static __inline__ void
56263+gr_insert_uid(const uid_t uid, const unsigned long expires)
56264+{
56265+ int loc;
56266+
56267+ if (uid_used == GR_UIDTABLE_MAX)
56268+ return;
56269+
56270+ loc = gr_find_uid(uid);
56271+
56272+ if (loc >= 0) {
56273+ uid_set[loc].expires = expires;
56274+ return;
56275+ }
56276+
56277+ uid_set[uid_used].uid = uid;
56278+ uid_set[uid_used].expires = expires;
56279+ uid_used++;
56280+
56281+ gr_insertsort();
56282+
56283+ return;
56284+}
56285+
56286+void
56287+gr_remove_uid(const unsigned short loc)
56288+{
56289+ unsigned short i;
56290+
56291+ for (i = loc + 1; i < uid_used; i++)
56292+ uid_set[i - 1] = uid_set[i];
56293+
56294+ uid_used--;
56295+
56296+ return;
56297+}
56298+
56299+int
56300+gr_check_crash_uid(const uid_t uid)
56301+{
56302+ int loc;
56303+ int ret = 0;
56304+
56305+ if (unlikely(!gr_acl_is_enabled()))
56306+ return 0;
56307+
56308+ spin_lock(&gr_uid_lock);
56309+ loc = gr_find_uid(uid);
56310+
56311+ if (loc < 0)
56312+ goto out_unlock;
56313+
56314+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
56315+ gr_remove_uid(loc);
56316+ else
56317+ ret = 1;
56318+
56319+out_unlock:
56320+ spin_unlock(&gr_uid_lock);
56321+ return ret;
56322+}
56323+
56324+static __inline__ int
56325+proc_is_setxid(const struct cred *cred)
56326+{
56327+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
56328+ cred->uid != cred->fsuid)
56329+ return 1;
56330+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56331+ cred->gid != cred->fsgid)
56332+ return 1;
56333+
56334+ return 0;
56335+}
56336+
56337+extern int gr_fake_force_sig(int sig, struct task_struct *t);
56338+
56339+void
56340+gr_handle_crash(struct task_struct *task, const int sig)
56341+{
56342+ struct acl_subject_label *curr;
56343+ struct task_struct *tsk, *tsk2;
56344+ const struct cred *cred;
56345+ const struct cred *cred2;
56346+
56347+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56348+ return;
56349+
56350+ if (unlikely(!gr_acl_is_enabled()))
56351+ return;
56352+
56353+ curr = task->acl;
56354+
56355+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
56356+ return;
56357+
56358+ if (time_before_eq(curr->expires, get_seconds())) {
56359+ curr->expires = 0;
56360+ curr->crashes = 0;
56361+ }
56362+
56363+ curr->crashes++;
56364+
56365+ if (!curr->expires)
56366+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56367+
56368+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56369+ time_after(curr->expires, get_seconds())) {
56370+ rcu_read_lock();
56371+ cred = __task_cred(task);
56372+ if (cred->uid && proc_is_setxid(cred)) {
56373+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56374+ spin_lock(&gr_uid_lock);
56375+ gr_insert_uid(cred->uid, curr->expires);
56376+ spin_unlock(&gr_uid_lock);
56377+ curr->expires = 0;
56378+ curr->crashes = 0;
56379+ read_lock(&tasklist_lock);
56380+ do_each_thread(tsk2, tsk) {
56381+ cred2 = __task_cred(tsk);
56382+ if (tsk != task && cred2->uid == cred->uid)
56383+ gr_fake_force_sig(SIGKILL, tsk);
56384+ } while_each_thread(tsk2, tsk);
56385+ read_unlock(&tasklist_lock);
56386+ } else {
56387+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56388+ read_lock(&tasklist_lock);
56389+ read_lock(&grsec_exec_file_lock);
56390+ do_each_thread(tsk2, tsk) {
56391+ if (likely(tsk != task)) {
56392+ // if this thread has the same subject as the one that triggered
56393+ // RES_CRASH and it's the same binary, kill it
56394+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56395+ gr_fake_force_sig(SIGKILL, tsk);
56396+ }
56397+ } while_each_thread(tsk2, tsk);
56398+ read_unlock(&grsec_exec_file_lock);
56399+ read_unlock(&tasklist_lock);
56400+ }
56401+ rcu_read_unlock();
56402+ }
56403+
56404+ return;
56405+}
56406+
56407+int
56408+gr_check_crash_exec(const struct file *filp)
56409+{
56410+ struct acl_subject_label *curr;
56411+
56412+ if (unlikely(!gr_acl_is_enabled()))
56413+ return 0;
56414+
56415+ read_lock(&gr_inode_lock);
56416+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56417+ __get_dev(filp->f_path.dentry),
56418+ current->role);
56419+ read_unlock(&gr_inode_lock);
56420+
56421+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56422+ (!curr->crashes && !curr->expires))
56423+ return 0;
56424+
56425+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56426+ time_after(curr->expires, get_seconds()))
56427+ return 1;
56428+ else if (time_before_eq(curr->expires, get_seconds())) {
56429+ curr->crashes = 0;
56430+ curr->expires = 0;
56431+ }
56432+
56433+ return 0;
56434+}
56435+
56436+void
56437+gr_handle_alertkill(struct task_struct *task)
56438+{
56439+ struct acl_subject_label *curracl;
56440+ __u32 curr_ip;
56441+ struct task_struct *p, *p2;
56442+
56443+ if (unlikely(!gr_acl_is_enabled()))
56444+ return;
56445+
56446+ curracl = task->acl;
56447+ curr_ip = task->signal->curr_ip;
56448+
56449+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56450+ read_lock(&tasklist_lock);
56451+ do_each_thread(p2, p) {
56452+ if (p->signal->curr_ip == curr_ip)
56453+ gr_fake_force_sig(SIGKILL, p);
56454+ } while_each_thread(p2, p);
56455+ read_unlock(&tasklist_lock);
56456+ } else if (curracl->mode & GR_KILLPROC)
56457+ gr_fake_force_sig(SIGKILL, task);
56458+
56459+ return;
56460+}
56461diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56462new file mode 100644
56463index 0000000..9d83a69
56464--- /dev/null
56465+++ b/grsecurity/gracl_shm.c
56466@@ -0,0 +1,40 @@
56467+#include <linux/kernel.h>
56468+#include <linux/mm.h>
56469+#include <linux/sched.h>
56470+#include <linux/file.h>
56471+#include <linux/ipc.h>
56472+#include <linux/gracl.h>
56473+#include <linux/grsecurity.h>
56474+#include <linux/grinternal.h>
56475+
56476+int
56477+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56478+ const time_t shm_createtime, const uid_t cuid, const int shmid)
56479+{
56480+ struct task_struct *task;
56481+
56482+ if (!gr_acl_is_enabled())
56483+ return 1;
56484+
56485+ rcu_read_lock();
56486+ read_lock(&tasklist_lock);
56487+
56488+ task = find_task_by_vpid(shm_cprid);
56489+
56490+ if (unlikely(!task))
56491+ task = find_task_by_vpid(shm_lapid);
56492+
56493+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56494+ (task->pid == shm_lapid)) &&
56495+ (task->acl->mode & GR_PROTSHM) &&
56496+ (task->acl != current->acl))) {
56497+ read_unlock(&tasklist_lock);
56498+ rcu_read_unlock();
56499+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56500+ return 0;
56501+ }
56502+ read_unlock(&tasklist_lock);
56503+ rcu_read_unlock();
56504+
56505+ return 1;
56506+}
56507diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56508new file mode 100644
56509index 0000000..bc0be01
56510--- /dev/null
56511+++ b/grsecurity/grsec_chdir.c
56512@@ -0,0 +1,19 @@
56513+#include <linux/kernel.h>
56514+#include <linux/sched.h>
56515+#include <linux/fs.h>
56516+#include <linux/file.h>
56517+#include <linux/grsecurity.h>
56518+#include <linux/grinternal.h>
56519+
56520+void
56521+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56522+{
56523+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56524+ if ((grsec_enable_chdir && grsec_enable_group &&
56525+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56526+ !grsec_enable_group)) {
56527+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56528+ }
56529+#endif
56530+ return;
56531+}
56532diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56533new file mode 100644
56534index 0000000..9807ee2
56535--- /dev/null
56536+++ b/grsecurity/grsec_chroot.c
56537@@ -0,0 +1,368 @@
56538+#include <linux/kernel.h>
56539+#include <linux/module.h>
56540+#include <linux/sched.h>
56541+#include <linux/file.h>
56542+#include <linux/fs.h>
56543+#include <linux/mount.h>
56544+#include <linux/types.h>
56545+#include "../fs/mount.h"
56546+#include <linux/grsecurity.h>
56547+#include <linux/grinternal.h>
56548+
56549+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56550+{
56551+#ifdef CONFIG_GRKERNSEC
56552+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56553+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56554+ task->gr_is_chrooted = 1;
56555+ else
56556+ task->gr_is_chrooted = 0;
56557+
56558+ task->gr_chroot_dentry = path->dentry;
56559+#endif
56560+ return;
56561+}
56562+
56563+void gr_clear_chroot_entries(struct task_struct *task)
56564+{
56565+#ifdef CONFIG_GRKERNSEC
56566+ task->gr_is_chrooted = 0;
56567+ task->gr_chroot_dentry = NULL;
56568+#endif
56569+ return;
56570+}
56571+
56572+int
56573+gr_handle_chroot_unix(const pid_t pid)
56574+{
56575+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56576+ struct task_struct *p;
56577+
56578+ if (unlikely(!grsec_enable_chroot_unix))
56579+ return 1;
56580+
56581+ if (likely(!proc_is_chrooted(current)))
56582+ return 1;
56583+
56584+ rcu_read_lock();
56585+ read_lock(&tasklist_lock);
56586+ p = find_task_by_vpid_unrestricted(pid);
56587+ if (unlikely(p && !have_same_root(current, p))) {
56588+ read_unlock(&tasklist_lock);
56589+ rcu_read_unlock();
56590+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56591+ return 0;
56592+ }
56593+ read_unlock(&tasklist_lock);
56594+ rcu_read_unlock();
56595+#endif
56596+ return 1;
56597+}
56598+
56599+int
56600+gr_handle_chroot_nice(void)
56601+{
56602+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56603+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56604+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56605+ return -EPERM;
56606+ }
56607+#endif
56608+ return 0;
56609+}
56610+
56611+int
56612+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56613+{
56614+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56615+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56616+ && proc_is_chrooted(current)) {
56617+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56618+ return -EACCES;
56619+ }
56620+#endif
56621+ return 0;
56622+}
56623+
56624+int
56625+gr_handle_chroot_rawio(const struct inode *inode)
56626+{
56627+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56628+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56629+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56630+ return 1;
56631+#endif
56632+ return 0;
56633+}
56634+
56635+int
56636+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56637+{
56638+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56639+ struct task_struct *p;
56640+ int ret = 0;
56641+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56642+ return ret;
56643+
56644+ read_lock(&tasklist_lock);
56645+ do_each_pid_task(pid, type, p) {
56646+ if (!have_same_root(current, p)) {
56647+ ret = 1;
56648+ goto out;
56649+ }
56650+ } while_each_pid_task(pid, type, p);
56651+out:
56652+ read_unlock(&tasklist_lock);
56653+ return ret;
56654+#endif
56655+ return 0;
56656+}
56657+
56658+int
56659+gr_pid_is_chrooted(struct task_struct *p)
56660+{
56661+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56662+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56663+ return 0;
56664+
56665+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56666+ !have_same_root(current, p)) {
56667+ return 1;
56668+ }
56669+#endif
56670+ return 0;
56671+}
56672+
56673+EXPORT_SYMBOL(gr_pid_is_chrooted);
56674+
56675+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56676+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56677+{
56678+ struct path path, currentroot;
56679+ int ret = 0;
56680+
56681+ path.dentry = (struct dentry *)u_dentry;
56682+ path.mnt = (struct vfsmount *)u_mnt;
56683+ get_fs_root(current->fs, &currentroot);
56684+ if (path_is_under(&path, &currentroot))
56685+ ret = 1;
56686+ path_put(&currentroot);
56687+
56688+ return ret;
56689+}
56690+#endif
56691+
56692+int
56693+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56694+{
56695+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56696+ if (!grsec_enable_chroot_fchdir)
56697+ return 1;
56698+
56699+ if (!proc_is_chrooted(current))
56700+ return 1;
56701+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56702+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56703+ return 0;
56704+ }
56705+#endif
56706+ return 1;
56707+}
56708+
56709+int
56710+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56711+ const time_t shm_createtime)
56712+{
56713+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56714+ struct task_struct *p;
56715+ time_t starttime;
56716+
56717+ if (unlikely(!grsec_enable_chroot_shmat))
56718+ return 1;
56719+
56720+ if (likely(!proc_is_chrooted(current)))
56721+ return 1;
56722+
56723+ rcu_read_lock();
56724+ read_lock(&tasklist_lock);
56725+
56726+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56727+ starttime = p->start_time.tv_sec;
56728+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56729+ if (have_same_root(current, p)) {
56730+ goto allow;
56731+ } else {
56732+ read_unlock(&tasklist_lock);
56733+ rcu_read_unlock();
56734+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56735+ return 0;
56736+ }
56737+ }
56738+ /* creator exited, pid reuse, fall through to next check */
56739+ }
56740+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56741+ if (unlikely(!have_same_root(current, p))) {
56742+ read_unlock(&tasklist_lock);
56743+ rcu_read_unlock();
56744+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56745+ return 0;
56746+ }
56747+ }
56748+
56749+allow:
56750+ read_unlock(&tasklist_lock);
56751+ rcu_read_unlock();
56752+#endif
56753+ return 1;
56754+}
56755+
56756+void
56757+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56758+{
56759+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56760+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56761+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56762+#endif
56763+ return;
56764+}
56765+
56766+int
56767+gr_handle_chroot_mknod(const struct dentry *dentry,
56768+ const struct vfsmount *mnt, const int mode)
56769+{
56770+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56771+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56772+ proc_is_chrooted(current)) {
56773+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56774+ return -EPERM;
56775+ }
56776+#endif
56777+ return 0;
56778+}
56779+
56780+int
56781+gr_handle_chroot_mount(const struct dentry *dentry,
56782+ const struct vfsmount *mnt, const char *dev_name)
56783+{
56784+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56785+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56786+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56787+ return -EPERM;
56788+ }
56789+#endif
56790+ return 0;
56791+}
56792+
56793+int
56794+gr_handle_chroot_pivot(void)
56795+{
56796+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56797+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56798+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56799+ return -EPERM;
56800+ }
56801+#endif
56802+ return 0;
56803+}
56804+
56805+int
56806+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56807+{
56808+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56809+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56810+ !gr_is_outside_chroot(dentry, mnt)) {
56811+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56812+ return -EPERM;
56813+ }
56814+#endif
56815+ return 0;
56816+}
56817+
56818+extern const char *captab_log[];
56819+extern int captab_log_entries;
56820+
56821+int
56822+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56823+{
56824+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56825+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56826+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56827+ if (cap_raised(chroot_caps, cap)) {
56828+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
56829+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
56830+ }
56831+ return 0;
56832+ }
56833+ }
56834+#endif
56835+ return 1;
56836+}
56837+
56838+int
56839+gr_chroot_is_capable(const int cap)
56840+{
56841+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56842+ return gr_task_chroot_is_capable(current, current_cred(), cap);
56843+#endif
56844+ return 1;
56845+}
56846+
56847+int
56848+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
56849+{
56850+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56851+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56852+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56853+ if (cap_raised(chroot_caps, cap)) {
56854+ return 0;
56855+ }
56856+ }
56857+#endif
56858+ return 1;
56859+}
56860+
56861+int
56862+gr_chroot_is_capable_nolog(const int cap)
56863+{
56864+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56865+ return gr_task_chroot_is_capable_nolog(current, cap);
56866+#endif
56867+ return 1;
56868+}
56869+
56870+int
56871+gr_handle_chroot_sysctl(const int op)
56872+{
56873+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56874+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
56875+ proc_is_chrooted(current))
56876+ return -EACCES;
56877+#endif
56878+ return 0;
56879+}
56880+
56881+void
56882+gr_handle_chroot_chdir(struct path *path)
56883+{
56884+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56885+ if (grsec_enable_chroot_chdir)
56886+ set_fs_pwd(current->fs, path);
56887+#endif
56888+ return;
56889+}
56890+
56891+int
56892+gr_handle_chroot_chmod(const struct dentry *dentry,
56893+ const struct vfsmount *mnt, const int mode)
56894+{
56895+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56896+ /* allow chmod +s on directories, but not files */
56897+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
56898+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
56899+ proc_is_chrooted(current)) {
56900+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
56901+ return -EPERM;
56902+ }
56903+#endif
56904+ return 0;
56905+}
56906diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
56907new file mode 100644
56908index 0000000..213ad8b
56909--- /dev/null
56910+++ b/grsecurity/grsec_disabled.c
56911@@ -0,0 +1,437 @@
56912+#include <linux/kernel.h>
56913+#include <linux/module.h>
56914+#include <linux/sched.h>
56915+#include <linux/file.h>
56916+#include <linux/fs.h>
56917+#include <linux/kdev_t.h>
56918+#include <linux/net.h>
56919+#include <linux/in.h>
56920+#include <linux/ip.h>
56921+#include <linux/skbuff.h>
56922+#include <linux/sysctl.h>
56923+
56924+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56925+void
56926+pax_set_initial_flags(struct linux_binprm *bprm)
56927+{
56928+ return;
56929+}
56930+#endif
56931+
56932+#ifdef CONFIG_SYSCTL
56933+__u32
56934+gr_handle_sysctl(const struct ctl_table * table, const int op)
56935+{
56936+ return 0;
56937+}
56938+#endif
56939+
56940+#ifdef CONFIG_TASKSTATS
56941+int gr_is_taskstats_denied(int pid)
56942+{
56943+ return 0;
56944+}
56945+#endif
56946+
56947+int
56948+gr_acl_is_enabled(void)
56949+{
56950+ return 0;
56951+}
56952+
56953+void
56954+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56955+{
56956+ return;
56957+}
56958+
56959+int
56960+gr_handle_rawio(const struct inode *inode)
56961+{
56962+ return 0;
56963+}
56964+
56965+void
56966+gr_acl_handle_psacct(struct task_struct *task, const long code)
56967+{
56968+ return;
56969+}
56970+
56971+int
56972+gr_handle_ptrace(struct task_struct *task, const long request)
56973+{
56974+ return 0;
56975+}
56976+
56977+int
56978+gr_handle_proc_ptrace(struct task_struct *task)
56979+{
56980+ return 0;
56981+}
56982+
56983+void
56984+gr_learn_resource(const struct task_struct *task,
56985+ const int res, const unsigned long wanted, const int gt)
56986+{
56987+ return;
56988+}
56989+
56990+int
56991+gr_set_acls(const int type)
56992+{
56993+ return 0;
56994+}
56995+
56996+int
56997+gr_check_hidden_task(const struct task_struct *tsk)
56998+{
56999+ return 0;
57000+}
57001+
57002+int
57003+gr_check_protected_task(const struct task_struct *task)
57004+{
57005+ return 0;
57006+}
57007+
57008+int
57009+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57010+{
57011+ return 0;
57012+}
57013+
57014+void
57015+gr_copy_label(struct task_struct *tsk)
57016+{
57017+ return;
57018+}
57019+
57020+void
57021+gr_set_pax_flags(struct task_struct *task)
57022+{
57023+ return;
57024+}
57025+
57026+int
57027+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57028+ const int unsafe_share)
57029+{
57030+ return 0;
57031+}
57032+
57033+void
57034+gr_handle_delete(const ino_t ino, const dev_t dev)
57035+{
57036+ return;
57037+}
57038+
57039+void
57040+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57041+{
57042+ return;
57043+}
57044+
57045+void
57046+gr_handle_crash(struct task_struct *task, const int sig)
57047+{
57048+ return;
57049+}
57050+
57051+int
57052+gr_check_crash_exec(const struct file *filp)
57053+{
57054+ return 0;
57055+}
57056+
57057+int
57058+gr_check_crash_uid(const uid_t uid)
57059+{
57060+ return 0;
57061+}
57062+
57063+void
57064+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57065+ struct dentry *old_dentry,
57066+ struct dentry *new_dentry,
57067+ struct vfsmount *mnt, const __u8 replace)
57068+{
57069+ return;
57070+}
57071+
57072+int
57073+gr_search_socket(const int family, const int type, const int protocol)
57074+{
57075+ return 1;
57076+}
57077+
57078+int
57079+gr_search_connectbind(const int mode, const struct socket *sock,
57080+ const struct sockaddr_in *addr)
57081+{
57082+ return 0;
57083+}
57084+
57085+void
57086+gr_handle_alertkill(struct task_struct *task)
57087+{
57088+ return;
57089+}
57090+
57091+__u32
57092+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57093+{
57094+ return 1;
57095+}
57096+
57097+__u32
57098+gr_acl_handle_hidden_file(const struct dentry * dentry,
57099+ const struct vfsmount * mnt)
57100+{
57101+ return 1;
57102+}
57103+
57104+__u32
57105+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57106+ int acc_mode)
57107+{
57108+ return 1;
57109+}
57110+
57111+__u32
57112+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57113+{
57114+ return 1;
57115+}
57116+
57117+__u32
57118+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57119+{
57120+ return 1;
57121+}
57122+
57123+int
57124+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57125+ unsigned int *vm_flags)
57126+{
57127+ return 1;
57128+}
57129+
57130+__u32
57131+gr_acl_handle_truncate(const struct dentry * dentry,
57132+ const struct vfsmount * mnt)
57133+{
57134+ return 1;
57135+}
57136+
57137+__u32
57138+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57139+{
57140+ return 1;
57141+}
57142+
57143+__u32
57144+gr_acl_handle_access(const struct dentry * dentry,
57145+ const struct vfsmount * mnt, const int fmode)
57146+{
57147+ return 1;
57148+}
57149+
57150+__u32
57151+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57152+ umode_t *mode)
57153+{
57154+ return 1;
57155+}
57156+
57157+__u32
57158+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57159+{
57160+ return 1;
57161+}
57162+
57163+__u32
57164+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57165+{
57166+ return 1;
57167+}
57168+
57169+void
57170+grsecurity_init(void)
57171+{
57172+ return;
57173+}
57174+
57175+umode_t gr_acl_umask(void)
57176+{
57177+ return 0;
57178+}
57179+
57180+__u32
57181+gr_acl_handle_mknod(const struct dentry * new_dentry,
57182+ const struct dentry * parent_dentry,
57183+ const struct vfsmount * parent_mnt,
57184+ const int mode)
57185+{
57186+ return 1;
57187+}
57188+
57189+__u32
57190+gr_acl_handle_mkdir(const struct dentry * new_dentry,
57191+ const struct dentry * parent_dentry,
57192+ const struct vfsmount * parent_mnt)
57193+{
57194+ return 1;
57195+}
57196+
57197+__u32
57198+gr_acl_handle_symlink(const struct dentry * new_dentry,
57199+ const struct dentry * parent_dentry,
57200+ const struct vfsmount * parent_mnt, const char *from)
57201+{
57202+ return 1;
57203+}
57204+
57205+__u32
57206+gr_acl_handle_link(const struct dentry * new_dentry,
57207+ const struct dentry * parent_dentry,
57208+ const struct vfsmount * parent_mnt,
57209+ const struct dentry * old_dentry,
57210+ const struct vfsmount * old_mnt, const char *to)
57211+{
57212+ return 1;
57213+}
57214+
57215+int
57216+gr_acl_handle_rename(const struct dentry *new_dentry,
57217+ const struct dentry *parent_dentry,
57218+ const struct vfsmount *parent_mnt,
57219+ const struct dentry *old_dentry,
57220+ const struct inode *old_parent_inode,
57221+ const struct vfsmount *old_mnt, const char *newname)
57222+{
57223+ return 0;
57224+}
57225+
57226+int
57227+gr_acl_handle_filldir(const struct file *file, const char *name,
57228+ const int namelen, const ino_t ino)
57229+{
57230+ return 1;
57231+}
57232+
57233+int
57234+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57235+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57236+{
57237+ return 1;
57238+}
57239+
57240+int
57241+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57242+{
57243+ return 0;
57244+}
57245+
57246+int
57247+gr_search_accept(const struct socket *sock)
57248+{
57249+ return 0;
57250+}
57251+
57252+int
57253+gr_search_listen(const struct socket *sock)
57254+{
57255+ return 0;
57256+}
57257+
57258+int
57259+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57260+{
57261+ return 0;
57262+}
57263+
57264+__u32
57265+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57266+{
57267+ return 1;
57268+}
57269+
57270+__u32
57271+gr_acl_handle_creat(const struct dentry * dentry,
57272+ const struct dentry * p_dentry,
57273+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57274+ const int imode)
57275+{
57276+ return 1;
57277+}
57278+
57279+void
57280+gr_acl_handle_exit(void)
57281+{
57282+ return;
57283+}
57284+
57285+int
57286+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57287+{
57288+ return 1;
57289+}
57290+
57291+void
57292+gr_set_role_label(const uid_t uid, const gid_t gid)
57293+{
57294+ return;
57295+}
57296+
57297+int
57298+gr_acl_handle_procpidmem(const struct task_struct *task)
57299+{
57300+ return 0;
57301+}
57302+
57303+int
57304+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57305+{
57306+ return 0;
57307+}
57308+
57309+int
57310+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57311+{
57312+ return 0;
57313+}
57314+
57315+void
57316+gr_set_kernel_label(struct task_struct *task)
57317+{
57318+ return;
57319+}
57320+
57321+int
57322+gr_check_user_change(int real, int effective, int fs)
57323+{
57324+ return 0;
57325+}
57326+
57327+int
57328+gr_check_group_change(int real, int effective, int fs)
57329+{
57330+ return 0;
57331+}
57332+
57333+int gr_acl_enable_at_secure(void)
57334+{
57335+ return 0;
57336+}
57337+
57338+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57339+{
57340+ return dentry->d_inode->i_sb->s_dev;
57341+}
57342+
57343+EXPORT_SYMBOL(gr_learn_resource);
57344+EXPORT_SYMBOL(gr_set_kernel_label);
57345+#ifdef CONFIG_SECURITY
57346+EXPORT_SYMBOL(gr_check_user_change);
57347+EXPORT_SYMBOL(gr_check_group_change);
57348+#endif
57349diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57350new file mode 100644
57351index 0000000..abfa971
57352--- /dev/null
57353+++ b/grsecurity/grsec_exec.c
57354@@ -0,0 +1,174 @@
57355+#include <linux/kernel.h>
57356+#include <linux/sched.h>
57357+#include <linux/file.h>
57358+#include <linux/binfmts.h>
57359+#include <linux/fs.h>
57360+#include <linux/types.h>
57361+#include <linux/grdefs.h>
57362+#include <linux/grsecurity.h>
57363+#include <linux/grinternal.h>
57364+#include <linux/capability.h>
57365+#include <linux/module.h>
57366+
57367+#include <asm/uaccess.h>
57368+
57369+#ifdef CONFIG_GRKERNSEC_EXECLOG
57370+static char gr_exec_arg_buf[132];
57371+static DEFINE_MUTEX(gr_exec_arg_mutex);
57372+#endif
57373+
57374+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57375+
57376+void
57377+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57378+{
57379+#ifdef CONFIG_GRKERNSEC_EXECLOG
57380+ char *grarg = gr_exec_arg_buf;
57381+ unsigned int i, x, execlen = 0;
57382+ char c;
57383+
57384+ if (!((grsec_enable_execlog && grsec_enable_group &&
57385+ in_group_p(grsec_audit_gid))
57386+ || (grsec_enable_execlog && !grsec_enable_group)))
57387+ return;
57388+
57389+ mutex_lock(&gr_exec_arg_mutex);
57390+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
57391+
57392+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
57393+ const char __user *p;
57394+ unsigned int len;
57395+
57396+ p = get_user_arg_ptr(argv, i);
57397+ if (IS_ERR(p))
57398+ goto log;
57399+
57400+ len = strnlen_user(p, 128 - execlen);
57401+ if (len > 128 - execlen)
57402+ len = 128 - execlen;
57403+ else if (len > 0)
57404+ len--;
57405+ if (copy_from_user(grarg + execlen, p, len))
57406+ goto log;
57407+
57408+ /* rewrite unprintable characters */
57409+ for (x = 0; x < len; x++) {
57410+ c = *(grarg + execlen + x);
57411+ if (c < 32 || c > 126)
57412+ *(grarg + execlen + x) = ' ';
57413+ }
57414+
57415+ execlen += len;
57416+ *(grarg + execlen) = ' ';
57417+ *(grarg + execlen + 1) = '\0';
57418+ execlen++;
57419+ }
57420+
57421+ log:
57422+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57423+ bprm->file->f_path.mnt, grarg);
57424+ mutex_unlock(&gr_exec_arg_mutex);
57425+#endif
57426+ return;
57427+}
57428+
57429+#ifdef CONFIG_GRKERNSEC
57430+extern int gr_acl_is_capable(const int cap);
57431+extern int gr_acl_is_capable_nolog(const int cap);
57432+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57433+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57434+extern int gr_chroot_is_capable(const int cap);
57435+extern int gr_chroot_is_capable_nolog(const int cap);
57436+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57437+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57438+#endif
57439+
57440+const char *captab_log[] = {
57441+ "CAP_CHOWN",
57442+ "CAP_DAC_OVERRIDE",
57443+ "CAP_DAC_READ_SEARCH",
57444+ "CAP_FOWNER",
57445+ "CAP_FSETID",
57446+ "CAP_KILL",
57447+ "CAP_SETGID",
57448+ "CAP_SETUID",
57449+ "CAP_SETPCAP",
57450+ "CAP_LINUX_IMMUTABLE",
57451+ "CAP_NET_BIND_SERVICE",
57452+ "CAP_NET_BROADCAST",
57453+ "CAP_NET_ADMIN",
57454+ "CAP_NET_RAW",
57455+ "CAP_IPC_LOCK",
57456+ "CAP_IPC_OWNER",
57457+ "CAP_SYS_MODULE",
57458+ "CAP_SYS_RAWIO",
57459+ "CAP_SYS_CHROOT",
57460+ "CAP_SYS_PTRACE",
57461+ "CAP_SYS_PACCT",
57462+ "CAP_SYS_ADMIN",
57463+ "CAP_SYS_BOOT",
57464+ "CAP_SYS_NICE",
57465+ "CAP_SYS_RESOURCE",
57466+ "CAP_SYS_TIME",
57467+ "CAP_SYS_TTY_CONFIG",
57468+ "CAP_MKNOD",
57469+ "CAP_LEASE",
57470+ "CAP_AUDIT_WRITE",
57471+ "CAP_AUDIT_CONTROL",
57472+ "CAP_SETFCAP",
57473+ "CAP_MAC_OVERRIDE",
57474+ "CAP_MAC_ADMIN",
57475+ "CAP_SYSLOG",
57476+ "CAP_WAKE_ALARM"
57477+};
57478+
57479+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57480+
57481+int gr_is_capable(const int cap)
57482+{
57483+#ifdef CONFIG_GRKERNSEC
57484+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57485+ return 1;
57486+ return 0;
57487+#else
57488+ return 1;
57489+#endif
57490+}
57491+
57492+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57493+{
57494+#ifdef CONFIG_GRKERNSEC
57495+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57496+ return 1;
57497+ return 0;
57498+#else
57499+ return 1;
57500+#endif
57501+}
57502+
57503+int gr_is_capable_nolog(const int cap)
57504+{
57505+#ifdef CONFIG_GRKERNSEC
57506+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57507+ return 1;
57508+ return 0;
57509+#else
57510+ return 1;
57511+#endif
57512+}
57513+
57514+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57515+{
57516+#ifdef CONFIG_GRKERNSEC
57517+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57518+ return 1;
57519+ return 0;
57520+#else
57521+ return 1;
57522+#endif
57523+}
57524+
57525+EXPORT_SYMBOL(gr_is_capable);
57526+EXPORT_SYMBOL(gr_is_capable_nolog);
57527+EXPORT_SYMBOL(gr_task_is_capable);
57528+EXPORT_SYMBOL(gr_task_is_capable_nolog);
57529diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57530new file mode 100644
57531index 0000000..d3ee748
57532--- /dev/null
57533+++ b/grsecurity/grsec_fifo.c
57534@@ -0,0 +1,24 @@
57535+#include <linux/kernel.h>
57536+#include <linux/sched.h>
57537+#include <linux/fs.h>
57538+#include <linux/file.h>
57539+#include <linux/grinternal.h>
57540+
57541+int
57542+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57543+ const struct dentry *dir, const int flag, const int acc_mode)
57544+{
57545+#ifdef CONFIG_GRKERNSEC_FIFO
57546+ const struct cred *cred = current_cred();
57547+
57548+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57549+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57550+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57551+ (cred->fsuid != dentry->d_inode->i_uid)) {
57552+ if (!inode_permission(dentry->d_inode, acc_mode))
57553+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57554+ return -EACCES;
57555+ }
57556+#endif
57557+ return 0;
57558+}
57559diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57560new file mode 100644
57561index 0000000..8ca18bf
57562--- /dev/null
57563+++ b/grsecurity/grsec_fork.c
57564@@ -0,0 +1,23 @@
57565+#include <linux/kernel.h>
57566+#include <linux/sched.h>
57567+#include <linux/grsecurity.h>
57568+#include <linux/grinternal.h>
57569+#include <linux/errno.h>
57570+
57571+void
57572+gr_log_forkfail(const int retval)
57573+{
57574+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57575+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57576+ switch (retval) {
57577+ case -EAGAIN:
57578+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57579+ break;
57580+ case -ENOMEM:
57581+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57582+ break;
57583+ }
57584+ }
57585+#endif
57586+ return;
57587+}
57588diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57589new file mode 100644
57590index 0000000..01ddde4
57591--- /dev/null
57592+++ b/grsecurity/grsec_init.c
57593@@ -0,0 +1,277 @@
57594+#include <linux/kernel.h>
57595+#include <linux/sched.h>
57596+#include <linux/mm.h>
57597+#include <linux/gracl.h>
57598+#include <linux/slab.h>
57599+#include <linux/vmalloc.h>
57600+#include <linux/percpu.h>
57601+#include <linux/module.h>
57602+
57603+int grsec_enable_ptrace_readexec;
57604+int grsec_enable_setxid;
57605+int grsec_enable_brute;
57606+int grsec_enable_link;
57607+int grsec_enable_dmesg;
57608+int grsec_enable_harden_ptrace;
57609+int grsec_enable_fifo;
57610+int grsec_enable_execlog;
57611+int grsec_enable_signal;
57612+int grsec_enable_forkfail;
57613+int grsec_enable_audit_ptrace;
57614+int grsec_enable_time;
57615+int grsec_enable_audit_textrel;
57616+int grsec_enable_group;
57617+int grsec_audit_gid;
57618+int grsec_enable_chdir;
57619+int grsec_enable_mount;
57620+int grsec_enable_rofs;
57621+int grsec_enable_chroot_findtask;
57622+int grsec_enable_chroot_mount;
57623+int grsec_enable_chroot_shmat;
57624+int grsec_enable_chroot_fchdir;
57625+int grsec_enable_chroot_double;
57626+int grsec_enable_chroot_pivot;
57627+int grsec_enable_chroot_chdir;
57628+int grsec_enable_chroot_chmod;
57629+int grsec_enable_chroot_mknod;
57630+int grsec_enable_chroot_nice;
57631+int grsec_enable_chroot_execlog;
57632+int grsec_enable_chroot_caps;
57633+int grsec_enable_chroot_sysctl;
57634+int grsec_enable_chroot_unix;
57635+int grsec_enable_tpe;
57636+int grsec_tpe_gid;
57637+int grsec_enable_blackhole;
57638+#ifdef CONFIG_IPV6_MODULE
57639+EXPORT_SYMBOL(grsec_enable_blackhole);
57640+#endif
57641+int grsec_lastack_retries;
57642+int grsec_enable_tpe_all;
57643+int grsec_enable_tpe_invert;
57644+int grsec_enable_socket_all;
57645+int grsec_socket_all_gid;
57646+int grsec_enable_socket_client;
57647+int grsec_socket_client_gid;
57648+int grsec_enable_socket_server;
57649+int grsec_socket_server_gid;
57650+int grsec_resource_logging;
57651+int grsec_disable_privio;
57652+int grsec_enable_log_rwxmaps;
57653+int grsec_lock;
57654+
57655+DEFINE_SPINLOCK(grsec_alert_lock);
57656+unsigned long grsec_alert_wtime = 0;
57657+unsigned long grsec_alert_fyet = 0;
57658+
57659+DEFINE_SPINLOCK(grsec_audit_lock);
57660+
57661+DEFINE_RWLOCK(grsec_exec_file_lock);
57662+
57663+char *gr_shared_page[4];
57664+
57665+char *gr_alert_log_fmt;
57666+char *gr_audit_log_fmt;
57667+char *gr_alert_log_buf;
57668+char *gr_audit_log_buf;
57669+
57670+extern struct gr_arg *gr_usermode;
57671+extern unsigned char *gr_system_salt;
57672+extern unsigned char *gr_system_sum;
57673+
57674+void __init
57675+grsecurity_init(void)
57676+{
57677+ int j;
57678+ /* create the per-cpu shared pages */
57679+
57680+#ifdef CONFIG_X86
57681+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57682+#endif
57683+
57684+ for (j = 0; j < 4; j++) {
57685+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57686+ if (gr_shared_page[j] == NULL) {
57687+ panic("Unable to allocate grsecurity shared page");
57688+ return;
57689+ }
57690+ }
57691+
57692+ /* allocate log buffers */
57693+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57694+ if (!gr_alert_log_fmt) {
57695+ panic("Unable to allocate grsecurity alert log format buffer");
57696+ return;
57697+ }
57698+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57699+ if (!gr_audit_log_fmt) {
57700+ panic("Unable to allocate grsecurity audit log format buffer");
57701+ return;
57702+ }
57703+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57704+ if (!gr_alert_log_buf) {
57705+ panic("Unable to allocate grsecurity alert log buffer");
57706+ return;
57707+ }
57708+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57709+ if (!gr_audit_log_buf) {
57710+ panic("Unable to allocate grsecurity audit log buffer");
57711+ return;
57712+ }
57713+
57714+ /* allocate memory for authentication structure */
57715+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57716+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57717+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57718+
57719+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57720+ panic("Unable to allocate grsecurity authentication structure");
57721+ return;
57722+ }
57723+
57724+
57725+#ifdef CONFIG_GRKERNSEC_IO
57726+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57727+ grsec_disable_privio = 1;
57728+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57729+ grsec_disable_privio = 1;
57730+#else
57731+ grsec_disable_privio = 0;
57732+#endif
57733+#endif
57734+
57735+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57736+ /* for backward compatibility, tpe_invert always defaults to on if
57737+ enabled in the kernel
57738+ */
57739+ grsec_enable_tpe_invert = 1;
57740+#endif
57741+
57742+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57743+#ifndef CONFIG_GRKERNSEC_SYSCTL
57744+ grsec_lock = 1;
57745+#endif
57746+
57747+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57748+ grsec_enable_audit_textrel = 1;
57749+#endif
57750+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57751+ grsec_enable_log_rwxmaps = 1;
57752+#endif
57753+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57754+ grsec_enable_group = 1;
57755+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57756+#endif
57757+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57758+ grsec_enable_ptrace_readexec = 1;
57759+#endif
57760+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57761+ grsec_enable_chdir = 1;
57762+#endif
57763+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57764+ grsec_enable_harden_ptrace = 1;
57765+#endif
57766+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57767+ grsec_enable_mount = 1;
57768+#endif
57769+#ifdef CONFIG_GRKERNSEC_LINK
57770+ grsec_enable_link = 1;
57771+#endif
57772+#ifdef CONFIG_GRKERNSEC_BRUTE
57773+ grsec_enable_brute = 1;
57774+#endif
57775+#ifdef CONFIG_GRKERNSEC_DMESG
57776+ grsec_enable_dmesg = 1;
57777+#endif
57778+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57779+ grsec_enable_blackhole = 1;
57780+ grsec_lastack_retries = 4;
57781+#endif
57782+#ifdef CONFIG_GRKERNSEC_FIFO
57783+ grsec_enable_fifo = 1;
57784+#endif
57785+#ifdef CONFIG_GRKERNSEC_EXECLOG
57786+ grsec_enable_execlog = 1;
57787+#endif
57788+#ifdef CONFIG_GRKERNSEC_SETXID
57789+ grsec_enable_setxid = 1;
57790+#endif
57791+#ifdef CONFIG_GRKERNSEC_SIGNAL
57792+ grsec_enable_signal = 1;
57793+#endif
57794+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57795+ grsec_enable_forkfail = 1;
57796+#endif
57797+#ifdef CONFIG_GRKERNSEC_TIME
57798+ grsec_enable_time = 1;
57799+#endif
57800+#ifdef CONFIG_GRKERNSEC_RESLOG
57801+ grsec_resource_logging = 1;
57802+#endif
57803+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57804+ grsec_enable_chroot_findtask = 1;
57805+#endif
57806+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57807+ grsec_enable_chroot_unix = 1;
57808+#endif
57809+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57810+ grsec_enable_chroot_mount = 1;
57811+#endif
57812+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57813+ grsec_enable_chroot_fchdir = 1;
57814+#endif
57815+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57816+ grsec_enable_chroot_shmat = 1;
57817+#endif
57818+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57819+ grsec_enable_audit_ptrace = 1;
57820+#endif
57821+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57822+ grsec_enable_chroot_double = 1;
57823+#endif
57824+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57825+ grsec_enable_chroot_pivot = 1;
57826+#endif
57827+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57828+ grsec_enable_chroot_chdir = 1;
57829+#endif
57830+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57831+ grsec_enable_chroot_chmod = 1;
57832+#endif
57833+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57834+ grsec_enable_chroot_mknod = 1;
57835+#endif
57836+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57837+ grsec_enable_chroot_nice = 1;
57838+#endif
57839+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57840+ grsec_enable_chroot_execlog = 1;
57841+#endif
57842+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57843+ grsec_enable_chroot_caps = 1;
57844+#endif
57845+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57846+ grsec_enable_chroot_sysctl = 1;
57847+#endif
57848+#ifdef CONFIG_GRKERNSEC_TPE
57849+ grsec_enable_tpe = 1;
57850+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
57851+#ifdef CONFIG_GRKERNSEC_TPE_ALL
57852+ grsec_enable_tpe_all = 1;
57853+#endif
57854+#endif
57855+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57856+ grsec_enable_socket_all = 1;
57857+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
57858+#endif
57859+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57860+ grsec_enable_socket_client = 1;
57861+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
57862+#endif
57863+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57864+ grsec_enable_socket_server = 1;
57865+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
57866+#endif
57867+#endif
57868+
57869+ return;
57870+}
57871diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
57872new file mode 100644
57873index 0000000..3efe141
57874--- /dev/null
57875+++ b/grsecurity/grsec_link.c
57876@@ -0,0 +1,43 @@
57877+#include <linux/kernel.h>
57878+#include <linux/sched.h>
57879+#include <linux/fs.h>
57880+#include <linux/file.h>
57881+#include <linux/grinternal.h>
57882+
57883+int
57884+gr_handle_follow_link(const struct inode *parent,
57885+ const struct inode *inode,
57886+ const struct dentry *dentry, const struct vfsmount *mnt)
57887+{
57888+#ifdef CONFIG_GRKERNSEC_LINK
57889+ const struct cred *cred = current_cred();
57890+
57891+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
57892+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
57893+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
57894+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
57895+ return -EACCES;
57896+ }
57897+#endif
57898+ return 0;
57899+}
57900+
57901+int
57902+gr_handle_hardlink(const struct dentry *dentry,
57903+ const struct vfsmount *mnt,
57904+ struct inode *inode, const int mode, const char *to)
57905+{
57906+#ifdef CONFIG_GRKERNSEC_LINK
57907+ const struct cred *cred = current_cred();
57908+
57909+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
57910+ (!S_ISREG(mode) || (mode & S_ISUID) ||
57911+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
57912+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
57913+ !capable(CAP_FOWNER) && cred->uid) {
57914+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
57915+ return -EPERM;
57916+ }
57917+#endif
57918+ return 0;
57919+}
57920diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
57921new file mode 100644
57922index 0000000..a45d2e9
57923--- /dev/null
57924+++ b/grsecurity/grsec_log.c
57925@@ -0,0 +1,322 @@
57926+#include <linux/kernel.h>
57927+#include <linux/sched.h>
57928+#include <linux/file.h>
57929+#include <linux/tty.h>
57930+#include <linux/fs.h>
57931+#include <linux/grinternal.h>
57932+
57933+#ifdef CONFIG_TREE_PREEMPT_RCU
57934+#define DISABLE_PREEMPT() preempt_disable()
57935+#define ENABLE_PREEMPT() preempt_enable()
57936+#else
57937+#define DISABLE_PREEMPT()
57938+#define ENABLE_PREEMPT()
57939+#endif
57940+
57941+#define BEGIN_LOCKS(x) \
57942+ DISABLE_PREEMPT(); \
57943+ rcu_read_lock(); \
57944+ read_lock(&tasklist_lock); \
57945+ read_lock(&grsec_exec_file_lock); \
57946+ if (x != GR_DO_AUDIT) \
57947+ spin_lock(&grsec_alert_lock); \
57948+ else \
57949+ spin_lock(&grsec_audit_lock)
57950+
57951+#define END_LOCKS(x) \
57952+ if (x != GR_DO_AUDIT) \
57953+ spin_unlock(&grsec_alert_lock); \
57954+ else \
57955+ spin_unlock(&grsec_audit_lock); \
57956+ read_unlock(&grsec_exec_file_lock); \
57957+ read_unlock(&tasklist_lock); \
57958+ rcu_read_unlock(); \
57959+ ENABLE_PREEMPT(); \
57960+ if (x == GR_DONT_AUDIT) \
57961+ gr_handle_alertkill(current)
57962+
57963+enum {
57964+ FLOODING,
57965+ NO_FLOODING
57966+};
57967+
57968+extern char *gr_alert_log_fmt;
57969+extern char *gr_audit_log_fmt;
57970+extern char *gr_alert_log_buf;
57971+extern char *gr_audit_log_buf;
57972+
57973+static int gr_log_start(int audit)
57974+{
57975+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
57976+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
57977+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57978+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
57979+ unsigned long curr_secs = get_seconds();
57980+
57981+ if (audit == GR_DO_AUDIT)
57982+ goto set_fmt;
57983+
57984+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
57985+ grsec_alert_wtime = curr_secs;
57986+ grsec_alert_fyet = 0;
57987+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
57988+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
57989+ grsec_alert_fyet++;
57990+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
57991+ grsec_alert_wtime = curr_secs;
57992+ grsec_alert_fyet++;
57993+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
57994+ return FLOODING;
57995+ }
57996+ else return FLOODING;
57997+
57998+set_fmt:
57999+#endif
58000+ memset(buf, 0, PAGE_SIZE);
58001+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
58002+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58003+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58004+ } else if (current->signal->curr_ip) {
58005+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58006+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58007+ } else if (gr_acl_is_enabled()) {
58008+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58009+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58010+ } else {
58011+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
58012+ strcpy(buf, fmt);
58013+ }
58014+
58015+ return NO_FLOODING;
58016+}
58017+
58018+static void gr_log_middle(int audit, const char *msg, va_list ap)
58019+ __attribute__ ((format (printf, 2, 0)));
58020+
58021+static void gr_log_middle(int audit, const char *msg, va_list ap)
58022+{
58023+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58024+ unsigned int len = strlen(buf);
58025+
58026+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58027+
58028+ return;
58029+}
58030+
58031+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58032+ __attribute__ ((format (printf, 2, 3)));
58033+
58034+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58035+{
58036+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58037+ unsigned int len = strlen(buf);
58038+ va_list ap;
58039+
58040+ va_start(ap, msg);
58041+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58042+ va_end(ap);
58043+
58044+ return;
58045+}
58046+
58047+static void gr_log_end(int audit, int append_default)
58048+{
58049+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58050+
58051+ if (append_default) {
58052+ unsigned int len = strlen(buf);
58053+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58054+ }
58055+
58056+ printk("%s\n", buf);
58057+
58058+ return;
58059+}
58060+
58061+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58062+{
58063+ int logtype;
58064+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58065+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58066+ void *voidptr = NULL;
58067+ int num1 = 0, num2 = 0;
58068+ unsigned long ulong1 = 0, ulong2 = 0;
58069+ struct dentry *dentry = NULL;
58070+ struct vfsmount *mnt = NULL;
58071+ struct file *file = NULL;
58072+ struct task_struct *task = NULL;
58073+ const struct cred *cred, *pcred;
58074+ va_list ap;
58075+
58076+ BEGIN_LOCKS(audit);
58077+ logtype = gr_log_start(audit);
58078+ if (logtype == FLOODING) {
58079+ END_LOCKS(audit);
58080+ return;
58081+ }
58082+ va_start(ap, argtypes);
58083+ switch (argtypes) {
58084+ case GR_TTYSNIFF:
58085+ task = va_arg(ap, struct task_struct *);
58086+ 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);
58087+ break;
58088+ case GR_SYSCTL_HIDDEN:
58089+ str1 = va_arg(ap, char *);
58090+ gr_log_middle_varargs(audit, msg, result, str1);
58091+ break;
58092+ case GR_RBAC:
58093+ dentry = va_arg(ap, struct dentry *);
58094+ mnt = va_arg(ap, struct vfsmount *);
58095+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58096+ break;
58097+ case GR_RBAC_STR:
58098+ dentry = va_arg(ap, struct dentry *);
58099+ mnt = va_arg(ap, struct vfsmount *);
58100+ str1 = va_arg(ap, char *);
58101+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58102+ break;
58103+ case GR_STR_RBAC:
58104+ str1 = va_arg(ap, char *);
58105+ dentry = va_arg(ap, struct dentry *);
58106+ mnt = va_arg(ap, struct vfsmount *);
58107+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58108+ break;
58109+ case GR_RBAC_MODE2:
58110+ dentry = va_arg(ap, struct dentry *);
58111+ mnt = va_arg(ap, struct vfsmount *);
58112+ str1 = va_arg(ap, char *);
58113+ str2 = va_arg(ap, char *);
58114+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58115+ break;
58116+ case GR_RBAC_MODE3:
58117+ dentry = va_arg(ap, struct dentry *);
58118+ mnt = va_arg(ap, struct vfsmount *);
58119+ str1 = va_arg(ap, char *);
58120+ str2 = va_arg(ap, char *);
58121+ str3 = va_arg(ap, char *);
58122+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58123+ break;
58124+ case GR_FILENAME:
58125+ dentry = va_arg(ap, struct dentry *);
58126+ mnt = va_arg(ap, struct vfsmount *);
58127+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58128+ break;
58129+ case GR_STR_FILENAME:
58130+ str1 = va_arg(ap, char *);
58131+ dentry = va_arg(ap, struct dentry *);
58132+ mnt = va_arg(ap, struct vfsmount *);
58133+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58134+ break;
58135+ case GR_FILENAME_STR:
58136+ dentry = va_arg(ap, struct dentry *);
58137+ mnt = va_arg(ap, struct vfsmount *);
58138+ str1 = va_arg(ap, char *);
58139+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58140+ break;
58141+ case GR_FILENAME_TWO_INT:
58142+ dentry = va_arg(ap, struct dentry *);
58143+ mnt = va_arg(ap, struct vfsmount *);
58144+ num1 = va_arg(ap, int);
58145+ num2 = va_arg(ap, int);
58146+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58147+ break;
58148+ case GR_FILENAME_TWO_INT_STR:
58149+ dentry = va_arg(ap, struct dentry *);
58150+ mnt = va_arg(ap, struct vfsmount *);
58151+ num1 = va_arg(ap, int);
58152+ num2 = va_arg(ap, int);
58153+ str1 = va_arg(ap, char *);
58154+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58155+ break;
58156+ case GR_TEXTREL:
58157+ file = va_arg(ap, struct file *);
58158+ ulong1 = va_arg(ap, unsigned long);
58159+ ulong2 = va_arg(ap, unsigned long);
58160+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58161+ break;
58162+ case GR_PTRACE:
58163+ task = va_arg(ap, struct task_struct *);
58164+ 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);
58165+ break;
58166+ case GR_RESOURCE:
58167+ task = va_arg(ap, struct task_struct *);
58168+ cred = __task_cred(task);
58169+ pcred = __task_cred(task->real_parent);
58170+ ulong1 = va_arg(ap, unsigned long);
58171+ str1 = va_arg(ap, char *);
58172+ ulong2 = va_arg(ap, unsigned long);
58173+ 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);
58174+ break;
58175+ case GR_CAP:
58176+ task = va_arg(ap, struct task_struct *);
58177+ cred = __task_cred(task);
58178+ pcred = __task_cred(task->real_parent);
58179+ str1 = va_arg(ap, char *);
58180+ 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);
58181+ break;
58182+ case GR_SIG:
58183+ str1 = va_arg(ap, char *);
58184+ voidptr = va_arg(ap, void *);
58185+ gr_log_middle_varargs(audit, msg, str1, voidptr);
58186+ break;
58187+ case GR_SIG2:
58188+ task = va_arg(ap, struct task_struct *);
58189+ cred = __task_cred(task);
58190+ pcred = __task_cred(task->real_parent);
58191+ num1 = va_arg(ap, int);
58192+ 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);
58193+ break;
58194+ case GR_CRASH1:
58195+ task = va_arg(ap, struct task_struct *);
58196+ cred = __task_cred(task);
58197+ pcred = __task_cred(task->real_parent);
58198+ ulong1 = va_arg(ap, unsigned long);
58199+ 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);
58200+ break;
58201+ case GR_CRASH2:
58202+ task = va_arg(ap, struct task_struct *);
58203+ cred = __task_cred(task);
58204+ pcred = __task_cred(task->real_parent);
58205+ ulong1 = va_arg(ap, unsigned long);
58206+ 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);
58207+ break;
58208+ case GR_RWXMAP:
58209+ file = va_arg(ap, struct file *);
58210+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58211+ break;
58212+ case GR_PSACCT:
58213+ {
58214+ unsigned int wday, cday;
58215+ __u8 whr, chr;
58216+ __u8 wmin, cmin;
58217+ __u8 wsec, csec;
58218+ char cur_tty[64] = { 0 };
58219+ char parent_tty[64] = { 0 };
58220+
58221+ task = va_arg(ap, struct task_struct *);
58222+ wday = va_arg(ap, unsigned int);
58223+ cday = va_arg(ap, unsigned int);
58224+ whr = va_arg(ap, int);
58225+ chr = va_arg(ap, int);
58226+ wmin = va_arg(ap, int);
58227+ cmin = va_arg(ap, int);
58228+ wsec = va_arg(ap, int);
58229+ csec = va_arg(ap, int);
58230+ ulong1 = va_arg(ap, unsigned long);
58231+ cred = __task_cred(task);
58232+ pcred = __task_cred(task->real_parent);
58233+
58234+ 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);
58235+ }
58236+ break;
58237+ default:
58238+ gr_log_middle(audit, msg, ap);
58239+ }
58240+ va_end(ap);
58241+ // these don't need DEFAULTSECARGS printed on the end
58242+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58243+ gr_log_end(audit, 0);
58244+ else
58245+ gr_log_end(audit, 1);
58246+ END_LOCKS(audit);
58247+}
58248diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58249new file mode 100644
58250index 0000000..f536303
58251--- /dev/null
58252+++ b/grsecurity/grsec_mem.c
58253@@ -0,0 +1,40 @@
58254+#include <linux/kernel.h>
58255+#include <linux/sched.h>
58256+#include <linux/mm.h>
58257+#include <linux/mman.h>
58258+#include <linux/grinternal.h>
58259+
58260+void
58261+gr_handle_ioperm(void)
58262+{
58263+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58264+ return;
58265+}
58266+
58267+void
58268+gr_handle_iopl(void)
58269+{
58270+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58271+ return;
58272+}
58273+
58274+void
58275+gr_handle_mem_readwrite(u64 from, u64 to)
58276+{
58277+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58278+ return;
58279+}
58280+
58281+void
58282+gr_handle_vm86(void)
58283+{
58284+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58285+ return;
58286+}
58287+
58288+void
58289+gr_log_badprocpid(const char *entry)
58290+{
58291+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58292+ return;
58293+}
58294diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58295new file mode 100644
58296index 0000000..2131422
58297--- /dev/null
58298+++ b/grsecurity/grsec_mount.c
58299@@ -0,0 +1,62 @@
58300+#include <linux/kernel.h>
58301+#include <linux/sched.h>
58302+#include <linux/mount.h>
58303+#include <linux/grsecurity.h>
58304+#include <linux/grinternal.h>
58305+
58306+void
58307+gr_log_remount(const char *devname, const int retval)
58308+{
58309+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58310+ if (grsec_enable_mount && (retval >= 0))
58311+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58312+#endif
58313+ return;
58314+}
58315+
58316+void
58317+gr_log_unmount(const char *devname, const int retval)
58318+{
58319+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58320+ if (grsec_enable_mount && (retval >= 0))
58321+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58322+#endif
58323+ return;
58324+}
58325+
58326+void
58327+gr_log_mount(const char *from, const char *to, const int retval)
58328+{
58329+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58330+ if (grsec_enable_mount && (retval >= 0))
58331+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58332+#endif
58333+ return;
58334+}
58335+
58336+int
58337+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58338+{
58339+#ifdef CONFIG_GRKERNSEC_ROFS
58340+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58341+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58342+ return -EPERM;
58343+ } else
58344+ return 0;
58345+#endif
58346+ return 0;
58347+}
58348+
58349+int
58350+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58351+{
58352+#ifdef CONFIG_GRKERNSEC_ROFS
58353+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58354+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58355+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58356+ return -EPERM;
58357+ } else
58358+ return 0;
58359+#endif
58360+ return 0;
58361+}
58362diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58363new file mode 100644
58364index 0000000..a3b12a0
58365--- /dev/null
58366+++ b/grsecurity/grsec_pax.c
58367@@ -0,0 +1,36 @@
58368+#include <linux/kernel.h>
58369+#include <linux/sched.h>
58370+#include <linux/mm.h>
58371+#include <linux/file.h>
58372+#include <linux/grinternal.h>
58373+#include <linux/grsecurity.h>
58374+
58375+void
58376+gr_log_textrel(struct vm_area_struct * vma)
58377+{
58378+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58379+ if (grsec_enable_audit_textrel)
58380+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58381+#endif
58382+ return;
58383+}
58384+
58385+void
58386+gr_log_rwxmmap(struct file *file)
58387+{
58388+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58389+ if (grsec_enable_log_rwxmaps)
58390+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58391+#endif
58392+ return;
58393+}
58394+
58395+void
58396+gr_log_rwxmprotect(struct file *file)
58397+{
58398+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58399+ if (grsec_enable_log_rwxmaps)
58400+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58401+#endif
58402+ return;
58403+}
58404diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58405new file mode 100644
58406index 0000000..f7f29aa
58407--- /dev/null
58408+++ b/grsecurity/grsec_ptrace.c
58409@@ -0,0 +1,30 @@
58410+#include <linux/kernel.h>
58411+#include <linux/sched.h>
58412+#include <linux/grinternal.h>
58413+#include <linux/security.h>
58414+
58415+void
58416+gr_audit_ptrace(struct task_struct *task)
58417+{
58418+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58419+ if (grsec_enable_audit_ptrace)
58420+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58421+#endif
58422+ return;
58423+}
58424+
58425+int
58426+gr_ptrace_readexec(struct file *file, int unsafe_flags)
58427+{
58428+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58429+ const struct dentry *dentry = file->f_path.dentry;
58430+ const struct vfsmount *mnt = file->f_path.mnt;
58431+
58432+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58433+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58434+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58435+ return -EACCES;
58436+ }
58437+#endif
58438+ return 0;
58439+}
58440diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58441new file mode 100644
58442index 0000000..7a5b2de
58443--- /dev/null
58444+++ b/grsecurity/grsec_sig.c
58445@@ -0,0 +1,207 @@
58446+#include <linux/kernel.h>
58447+#include <linux/sched.h>
58448+#include <linux/delay.h>
58449+#include <linux/grsecurity.h>
58450+#include <linux/grinternal.h>
58451+#include <linux/hardirq.h>
58452+
58453+char *signames[] = {
58454+ [SIGSEGV] = "Segmentation fault",
58455+ [SIGILL] = "Illegal instruction",
58456+ [SIGABRT] = "Abort",
58457+ [SIGBUS] = "Invalid alignment/Bus error"
58458+};
58459+
58460+void
58461+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58462+{
58463+#ifdef CONFIG_GRKERNSEC_SIGNAL
58464+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58465+ (sig == SIGABRT) || (sig == SIGBUS))) {
58466+ if (t->pid == current->pid) {
58467+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58468+ } else {
58469+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58470+ }
58471+ }
58472+#endif
58473+ return;
58474+}
58475+
58476+int
58477+gr_handle_signal(const struct task_struct *p, const int sig)
58478+{
58479+#ifdef CONFIG_GRKERNSEC
58480+ /* ignore the 0 signal for protected task checks */
58481+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58482+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58483+ return -EPERM;
58484+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58485+ return -EPERM;
58486+ }
58487+#endif
58488+ return 0;
58489+}
58490+
58491+#ifdef CONFIG_GRKERNSEC
58492+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58493+
58494+int gr_fake_force_sig(int sig, struct task_struct *t)
58495+{
58496+ unsigned long int flags;
58497+ int ret, blocked, ignored;
58498+ struct k_sigaction *action;
58499+
58500+ spin_lock_irqsave(&t->sighand->siglock, flags);
58501+ action = &t->sighand->action[sig-1];
58502+ ignored = action->sa.sa_handler == SIG_IGN;
58503+ blocked = sigismember(&t->blocked, sig);
58504+ if (blocked || ignored) {
58505+ action->sa.sa_handler = SIG_DFL;
58506+ if (blocked) {
58507+ sigdelset(&t->blocked, sig);
58508+ recalc_sigpending_and_wake(t);
58509+ }
58510+ }
58511+ if (action->sa.sa_handler == SIG_DFL)
58512+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
58513+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58514+
58515+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
58516+
58517+ return ret;
58518+}
58519+#endif
58520+
58521+#ifdef CONFIG_GRKERNSEC_BRUTE
58522+#define GR_USER_BAN_TIME (15 * 60)
58523+
58524+static int __get_dumpable(unsigned long mm_flags)
58525+{
58526+ int ret;
58527+
58528+ ret = mm_flags & MMF_DUMPABLE_MASK;
58529+ return (ret >= 2) ? 2 : ret;
58530+}
58531+#endif
58532+
58533+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58534+{
58535+#ifdef CONFIG_GRKERNSEC_BRUTE
58536+ uid_t uid = 0;
58537+
58538+ if (!grsec_enable_brute)
58539+ return;
58540+
58541+ rcu_read_lock();
58542+ read_lock(&tasklist_lock);
58543+ read_lock(&grsec_exec_file_lock);
58544+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58545+ p->real_parent->brute = 1;
58546+ else {
58547+ const struct cred *cred = __task_cred(p), *cred2;
58548+ struct task_struct *tsk, *tsk2;
58549+
58550+ if (!__get_dumpable(mm_flags) && cred->uid) {
58551+ struct user_struct *user;
58552+
58553+ uid = cred->uid;
58554+
58555+ /* this is put upon execution past expiration */
58556+ user = find_user(uid);
58557+ if (user == NULL)
58558+ goto unlock;
58559+ user->banned = 1;
58560+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58561+ if (user->ban_expires == ~0UL)
58562+ user->ban_expires--;
58563+
58564+ do_each_thread(tsk2, tsk) {
58565+ cred2 = __task_cred(tsk);
58566+ if (tsk != p && cred2->uid == uid)
58567+ gr_fake_force_sig(SIGKILL, tsk);
58568+ } while_each_thread(tsk2, tsk);
58569+ }
58570+ }
58571+unlock:
58572+ read_unlock(&grsec_exec_file_lock);
58573+ read_unlock(&tasklist_lock);
58574+ rcu_read_unlock();
58575+
58576+ if (uid)
58577+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58578+
58579+#endif
58580+ return;
58581+}
58582+
58583+void gr_handle_brute_check(void)
58584+{
58585+#ifdef CONFIG_GRKERNSEC_BRUTE
58586+ if (current->brute)
58587+ msleep(30 * 1000);
58588+#endif
58589+ return;
58590+}
58591+
58592+void gr_handle_kernel_exploit(void)
58593+{
58594+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58595+ const struct cred *cred;
58596+ struct task_struct *tsk, *tsk2;
58597+ struct user_struct *user;
58598+ uid_t uid;
58599+
58600+ if (in_irq() || in_serving_softirq() || in_nmi())
58601+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58602+
58603+ uid = current_uid();
58604+
58605+ if (uid == 0)
58606+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
58607+ else {
58608+ /* kill all the processes of this user, hold a reference
58609+ to their creds struct, and prevent them from creating
58610+ another process until system reset
58611+ */
58612+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58613+ /* we intentionally leak this ref */
58614+ user = get_uid(current->cred->user);
58615+ if (user) {
58616+ user->banned = 1;
58617+ user->ban_expires = ~0UL;
58618+ }
58619+
58620+ read_lock(&tasklist_lock);
58621+ do_each_thread(tsk2, tsk) {
58622+ cred = __task_cred(tsk);
58623+ if (cred->uid == uid)
58624+ gr_fake_force_sig(SIGKILL, tsk);
58625+ } while_each_thread(tsk2, tsk);
58626+ read_unlock(&tasklist_lock);
58627+ }
58628+#endif
58629+}
58630+
58631+int __gr_process_user_ban(struct user_struct *user)
58632+{
58633+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58634+ if (unlikely(user->banned)) {
58635+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58636+ user->banned = 0;
58637+ user->ban_expires = 0;
58638+ free_uid(user);
58639+ } else
58640+ return -EPERM;
58641+ }
58642+#endif
58643+ return 0;
58644+}
58645+
58646+int gr_process_user_ban(void)
58647+{
58648+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58649+ return __gr_process_user_ban(current->cred->user);
58650+#endif
58651+ return 0;
58652+}
58653diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58654new file mode 100644
58655index 0000000..4030d57
58656--- /dev/null
58657+++ b/grsecurity/grsec_sock.c
58658@@ -0,0 +1,244 @@
58659+#include <linux/kernel.h>
58660+#include <linux/module.h>
58661+#include <linux/sched.h>
58662+#include <linux/file.h>
58663+#include <linux/net.h>
58664+#include <linux/in.h>
58665+#include <linux/ip.h>
58666+#include <net/sock.h>
58667+#include <net/inet_sock.h>
58668+#include <linux/grsecurity.h>
58669+#include <linux/grinternal.h>
58670+#include <linux/gracl.h>
58671+
58672+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58673+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58674+
58675+EXPORT_SYMBOL(gr_search_udp_recvmsg);
58676+EXPORT_SYMBOL(gr_search_udp_sendmsg);
58677+
58678+#ifdef CONFIG_UNIX_MODULE
58679+EXPORT_SYMBOL(gr_acl_handle_unix);
58680+EXPORT_SYMBOL(gr_acl_handle_mknod);
58681+EXPORT_SYMBOL(gr_handle_chroot_unix);
58682+EXPORT_SYMBOL(gr_handle_create);
58683+#endif
58684+
58685+#ifdef CONFIG_GRKERNSEC
58686+#define gr_conn_table_size 32749
58687+struct conn_table_entry {
58688+ struct conn_table_entry *next;
58689+ struct signal_struct *sig;
58690+};
58691+
58692+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58693+DEFINE_SPINLOCK(gr_conn_table_lock);
58694+
58695+extern const char * gr_socktype_to_name(unsigned char type);
58696+extern const char * gr_proto_to_name(unsigned char proto);
58697+extern const char * gr_sockfamily_to_name(unsigned char family);
58698+
58699+static __inline__ int
58700+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58701+{
58702+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58703+}
58704+
58705+static __inline__ int
58706+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58707+ __u16 sport, __u16 dport)
58708+{
58709+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58710+ sig->gr_sport == sport && sig->gr_dport == dport))
58711+ return 1;
58712+ else
58713+ return 0;
58714+}
58715+
58716+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58717+{
58718+ struct conn_table_entry **match;
58719+ unsigned int index;
58720+
58721+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58722+ sig->gr_sport, sig->gr_dport,
58723+ gr_conn_table_size);
58724+
58725+ newent->sig = sig;
58726+
58727+ match = &gr_conn_table[index];
58728+ newent->next = *match;
58729+ *match = newent;
58730+
58731+ return;
58732+}
58733+
58734+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58735+{
58736+ struct conn_table_entry *match, *last = NULL;
58737+ unsigned int index;
58738+
58739+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58740+ sig->gr_sport, sig->gr_dport,
58741+ gr_conn_table_size);
58742+
58743+ match = gr_conn_table[index];
58744+ while (match && !conn_match(match->sig,
58745+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58746+ sig->gr_dport)) {
58747+ last = match;
58748+ match = match->next;
58749+ }
58750+
58751+ if (match) {
58752+ if (last)
58753+ last->next = match->next;
58754+ else
58755+ gr_conn_table[index] = NULL;
58756+ kfree(match);
58757+ }
58758+
58759+ return;
58760+}
58761+
58762+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58763+ __u16 sport, __u16 dport)
58764+{
58765+ struct conn_table_entry *match;
58766+ unsigned int index;
58767+
58768+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58769+
58770+ match = gr_conn_table[index];
58771+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58772+ match = match->next;
58773+
58774+ if (match)
58775+ return match->sig;
58776+ else
58777+ return NULL;
58778+}
58779+
58780+#endif
58781+
58782+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58783+{
58784+#ifdef CONFIG_GRKERNSEC
58785+ struct signal_struct *sig = task->signal;
58786+ struct conn_table_entry *newent;
58787+
58788+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58789+ if (newent == NULL)
58790+ return;
58791+ /* no bh lock needed since we are called with bh disabled */
58792+ spin_lock(&gr_conn_table_lock);
58793+ gr_del_task_from_ip_table_nolock(sig);
58794+ sig->gr_saddr = inet->inet_rcv_saddr;
58795+ sig->gr_daddr = inet->inet_daddr;
58796+ sig->gr_sport = inet->inet_sport;
58797+ sig->gr_dport = inet->inet_dport;
58798+ gr_add_to_task_ip_table_nolock(sig, newent);
58799+ spin_unlock(&gr_conn_table_lock);
58800+#endif
58801+ return;
58802+}
58803+
58804+void gr_del_task_from_ip_table(struct task_struct *task)
58805+{
58806+#ifdef CONFIG_GRKERNSEC
58807+ spin_lock_bh(&gr_conn_table_lock);
58808+ gr_del_task_from_ip_table_nolock(task->signal);
58809+ spin_unlock_bh(&gr_conn_table_lock);
58810+#endif
58811+ return;
58812+}
58813+
58814+void
58815+gr_attach_curr_ip(const struct sock *sk)
58816+{
58817+#ifdef CONFIG_GRKERNSEC
58818+ struct signal_struct *p, *set;
58819+ const struct inet_sock *inet = inet_sk(sk);
58820+
58821+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
58822+ return;
58823+
58824+ set = current->signal;
58825+
58826+ spin_lock_bh(&gr_conn_table_lock);
58827+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
58828+ inet->inet_dport, inet->inet_sport);
58829+ if (unlikely(p != NULL)) {
58830+ set->curr_ip = p->curr_ip;
58831+ set->used_accept = 1;
58832+ gr_del_task_from_ip_table_nolock(p);
58833+ spin_unlock_bh(&gr_conn_table_lock);
58834+ return;
58835+ }
58836+ spin_unlock_bh(&gr_conn_table_lock);
58837+
58838+ set->curr_ip = inet->inet_daddr;
58839+ set->used_accept = 1;
58840+#endif
58841+ return;
58842+}
58843+
58844+int
58845+gr_handle_sock_all(const int family, const int type, const int protocol)
58846+{
58847+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58848+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
58849+ (family != AF_UNIX)) {
58850+ if (family == AF_INET)
58851+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
58852+ else
58853+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
58854+ return -EACCES;
58855+ }
58856+#endif
58857+ return 0;
58858+}
58859+
58860+int
58861+gr_handle_sock_server(const struct sockaddr *sck)
58862+{
58863+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58864+ if (grsec_enable_socket_server &&
58865+ in_group_p(grsec_socket_server_gid) &&
58866+ sck && (sck->sa_family != AF_UNIX) &&
58867+ (sck->sa_family != AF_LOCAL)) {
58868+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58869+ return -EACCES;
58870+ }
58871+#endif
58872+ return 0;
58873+}
58874+
58875+int
58876+gr_handle_sock_server_other(const struct sock *sck)
58877+{
58878+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58879+ if (grsec_enable_socket_server &&
58880+ in_group_p(grsec_socket_server_gid) &&
58881+ sck && (sck->sk_family != AF_UNIX) &&
58882+ (sck->sk_family != AF_LOCAL)) {
58883+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58884+ return -EACCES;
58885+ }
58886+#endif
58887+ return 0;
58888+}
58889+
58890+int
58891+gr_handle_sock_client(const struct sockaddr *sck)
58892+{
58893+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58894+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
58895+ sck && (sck->sa_family != AF_UNIX) &&
58896+ (sck->sa_family != AF_LOCAL)) {
58897+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
58898+ return -EACCES;
58899+ }
58900+#endif
58901+ return 0;
58902+}
58903diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
58904new file mode 100644
58905index 0000000..a1aedd7
58906--- /dev/null
58907+++ b/grsecurity/grsec_sysctl.c
58908@@ -0,0 +1,451 @@
58909+#include <linux/kernel.h>
58910+#include <linux/sched.h>
58911+#include <linux/sysctl.h>
58912+#include <linux/grsecurity.h>
58913+#include <linux/grinternal.h>
58914+
58915+int
58916+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
58917+{
58918+#ifdef CONFIG_GRKERNSEC_SYSCTL
58919+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
58920+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
58921+ return -EACCES;
58922+ }
58923+#endif
58924+ return 0;
58925+}
58926+
58927+#ifdef CONFIG_GRKERNSEC_ROFS
58928+static int __maybe_unused one = 1;
58929+#endif
58930+
58931+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
58932+struct ctl_table grsecurity_table[] = {
58933+#ifdef CONFIG_GRKERNSEC_SYSCTL
58934+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
58935+#ifdef CONFIG_GRKERNSEC_IO
58936+ {
58937+ .procname = "disable_priv_io",
58938+ .data = &grsec_disable_privio,
58939+ .maxlen = sizeof(int),
58940+ .mode = 0600,
58941+ .proc_handler = &proc_dointvec,
58942+ },
58943+#endif
58944+#endif
58945+#ifdef CONFIG_GRKERNSEC_LINK
58946+ {
58947+ .procname = "linking_restrictions",
58948+ .data = &grsec_enable_link,
58949+ .maxlen = sizeof(int),
58950+ .mode = 0600,
58951+ .proc_handler = &proc_dointvec,
58952+ },
58953+#endif
58954+#ifdef CONFIG_GRKERNSEC_BRUTE
58955+ {
58956+ .procname = "deter_bruteforce",
58957+ .data = &grsec_enable_brute,
58958+ .maxlen = sizeof(int),
58959+ .mode = 0600,
58960+ .proc_handler = &proc_dointvec,
58961+ },
58962+#endif
58963+#ifdef CONFIG_GRKERNSEC_FIFO
58964+ {
58965+ .procname = "fifo_restrictions",
58966+ .data = &grsec_enable_fifo,
58967+ .maxlen = sizeof(int),
58968+ .mode = 0600,
58969+ .proc_handler = &proc_dointvec,
58970+ },
58971+#endif
58972+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58973+ {
58974+ .procname = "ptrace_readexec",
58975+ .data = &grsec_enable_ptrace_readexec,
58976+ .maxlen = sizeof(int),
58977+ .mode = 0600,
58978+ .proc_handler = &proc_dointvec,
58979+ },
58980+#endif
58981+#ifdef CONFIG_GRKERNSEC_SETXID
58982+ {
58983+ .procname = "consistent_setxid",
58984+ .data = &grsec_enable_setxid,
58985+ .maxlen = sizeof(int),
58986+ .mode = 0600,
58987+ .proc_handler = &proc_dointvec,
58988+ },
58989+#endif
58990+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58991+ {
58992+ .procname = "ip_blackhole",
58993+ .data = &grsec_enable_blackhole,
58994+ .maxlen = sizeof(int),
58995+ .mode = 0600,
58996+ .proc_handler = &proc_dointvec,
58997+ },
58998+ {
58999+ .procname = "lastack_retries",
59000+ .data = &grsec_lastack_retries,
59001+ .maxlen = sizeof(int),
59002+ .mode = 0600,
59003+ .proc_handler = &proc_dointvec,
59004+ },
59005+#endif
59006+#ifdef CONFIG_GRKERNSEC_EXECLOG
59007+ {
59008+ .procname = "exec_logging",
59009+ .data = &grsec_enable_execlog,
59010+ .maxlen = sizeof(int),
59011+ .mode = 0600,
59012+ .proc_handler = &proc_dointvec,
59013+ },
59014+#endif
59015+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59016+ {
59017+ .procname = "rwxmap_logging",
59018+ .data = &grsec_enable_log_rwxmaps,
59019+ .maxlen = sizeof(int),
59020+ .mode = 0600,
59021+ .proc_handler = &proc_dointvec,
59022+ },
59023+#endif
59024+#ifdef CONFIG_GRKERNSEC_SIGNAL
59025+ {
59026+ .procname = "signal_logging",
59027+ .data = &grsec_enable_signal,
59028+ .maxlen = sizeof(int),
59029+ .mode = 0600,
59030+ .proc_handler = &proc_dointvec,
59031+ },
59032+#endif
59033+#ifdef CONFIG_GRKERNSEC_FORKFAIL
59034+ {
59035+ .procname = "forkfail_logging",
59036+ .data = &grsec_enable_forkfail,
59037+ .maxlen = sizeof(int),
59038+ .mode = 0600,
59039+ .proc_handler = &proc_dointvec,
59040+ },
59041+#endif
59042+#ifdef CONFIG_GRKERNSEC_TIME
59043+ {
59044+ .procname = "timechange_logging",
59045+ .data = &grsec_enable_time,
59046+ .maxlen = sizeof(int),
59047+ .mode = 0600,
59048+ .proc_handler = &proc_dointvec,
59049+ },
59050+#endif
59051+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59052+ {
59053+ .procname = "chroot_deny_shmat",
59054+ .data = &grsec_enable_chroot_shmat,
59055+ .maxlen = sizeof(int),
59056+ .mode = 0600,
59057+ .proc_handler = &proc_dointvec,
59058+ },
59059+#endif
59060+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59061+ {
59062+ .procname = "chroot_deny_unix",
59063+ .data = &grsec_enable_chroot_unix,
59064+ .maxlen = sizeof(int),
59065+ .mode = 0600,
59066+ .proc_handler = &proc_dointvec,
59067+ },
59068+#endif
59069+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59070+ {
59071+ .procname = "chroot_deny_mount",
59072+ .data = &grsec_enable_chroot_mount,
59073+ .maxlen = sizeof(int),
59074+ .mode = 0600,
59075+ .proc_handler = &proc_dointvec,
59076+ },
59077+#endif
59078+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59079+ {
59080+ .procname = "chroot_deny_fchdir",
59081+ .data = &grsec_enable_chroot_fchdir,
59082+ .maxlen = sizeof(int),
59083+ .mode = 0600,
59084+ .proc_handler = &proc_dointvec,
59085+ },
59086+#endif
59087+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59088+ {
59089+ .procname = "chroot_deny_chroot",
59090+ .data = &grsec_enable_chroot_double,
59091+ .maxlen = sizeof(int),
59092+ .mode = 0600,
59093+ .proc_handler = &proc_dointvec,
59094+ },
59095+#endif
59096+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59097+ {
59098+ .procname = "chroot_deny_pivot",
59099+ .data = &grsec_enable_chroot_pivot,
59100+ .maxlen = sizeof(int),
59101+ .mode = 0600,
59102+ .proc_handler = &proc_dointvec,
59103+ },
59104+#endif
59105+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59106+ {
59107+ .procname = "chroot_enforce_chdir",
59108+ .data = &grsec_enable_chroot_chdir,
59109+ .maxlen = sizeof(int),
59110+ .mode = 0600,
59111+ .proc_handler = &proc_dointvec,
59112+ },
59113+#endif
59114+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59115+ {
59116+ .procname = "chroot_deny_chmod",
59117+ .data = &grsec_enable_chroot_chmod,
59118+ .maxlen = sizeof(int),
59119+ .mode = 0600,
59120+ .proc_handler = &proc_dointvec,
59121+ },
59122+#endif
59123+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59124+ {
59125+ .procname = "chroot_deny_mknod",
59126+ .data = &grsec_enable_chroot_mknod,
59127+ .maxlen = sizeof(int),
59128+ .mode = 0600,
59129+ .proc_handler = &proc_dointvec,
59130+ },
59131+#endif
59132+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59133+ {
59134+ .procname = "chroot_restrict_nice",
59135+ .data = &grsec_enable_chroot_nice,
59136+ .maxlen = sizeof(int),
59137+ .mode = 0600,
59138+ .proc_handler = &proc_dointvec,
59139+ },
59140+#endif
59141+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59142+ {
59143+ .procname = "chroot_execlog",
59144+ .data = &grsec_enable_chroot_execlog,
59145+ .maxlen = sizeof(int),
59146+ .mode = 0600,
59147+ .proc_handler = &proc_dointvec,
59148+ },
59149+#endif
59150+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59151+ {
59152+ .procname = "chroot_caps",
59153+ .data = &grsec_enable_chroot_caps,
59154+ .maxlen = sizeof(int),
59155+ .mode = 0600,
59156+ .proc_handler = &proc_dointvec,
59157+ },
59158+#endif
59159+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59160+ {
59161+ .procname = "chroot_deny_sysctl",
59162+ .data = &grsec_enable_chroot_sysctl,
59163+ .maxlen = sizeof(int),
59164+ .mode = 0600,
59165+ .proc_handler = &proc_dointvec,
59166+ },
59167+#endif
59168+#ifdef CONFIG_GRKERNSEC_TPE
59169+ {
59170+ .procname = "tpe",
59171+ .data = &grsec_enable_tpe,
59172+ .maxlen = sizeof(int),
59173+ .mode = 0600,
59174+ .proc_handler = &proc_dointvec,
59175+ },
59176+ {
59177+ .procname = "tpe_gid",
59178+ .data = &grsec_tpe_gid,
59179+ .maxlen = sizeof(int),
59180+ .mode = 0600,
59181+ .proc_handler = &proc_dointvec,
59182+ },
59183+#endif
59184+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59185+ {
59186+ .procname = "tpe_invert",
59187+ .data = &grsec_enable_tpe_invert,
59188+ .maxlen = sizeof(int),
59189+ .mode = 0600,
59190+ .proc_handler = &proc_dointvec,
59191+ },
59192+#endif
59193+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59194+ {
59195+ .procname = "tpe_restrict_all",
59196+ .data = &grsec_enable_tpe_all,
59197+ .maxlen = sizeof(int),
59198+ .mode = 0600,
59199+ .proc_handler = &proc_dointvec,
59200+ },
59201+#endif
59202+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59203+ {
59204+ .procname = "socket_all",
59205+ .data = &grsec_enable_socket_all,
59206+ .maxlen = sizeof(int),
59207+ .mode = 0600,
59208+ .proc_handler = &proc_dointvec,
59209+ },
59210+ {
59211+ .procname = "socket_all_gid",
59212+ .data = &grsec_socket_all_gid,
59213+ .maxlen = sizeof(int),
59214+ .mode = 0600,
59215+ .proc_handler = &proc_dointvec,
59216+ },
59217+#endif
59218+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59219+ {
59220+ .procname = "socket_client",
59221+ .data = &grsec_enable_socket_client,
59222+ .maxlen = sizeof(int),
59223+ .mode = 0600,
59224+ .proc_handler = &proc_dointvec,
59225+ },
59226+ {
59227+ .procname = "socket_client_gid",
59228+ .data = &grsec_socket_client_gid,
59229+ .maxlen = sizeof(int),
59230+ .mode = 0600,
59231+ .proc_handler = &proc_dointvec,
59232+ },
59233+#endif
59234+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59235+ {
59236+ .procname = "socket_server",
59237+ .data = &grsec_enable_socket_server,
59238+ .maxlen = sizeof(int),
59239+ .mode = 0600,
59240+ .proc_handler = &proc_dointvec,
59241+ },
59242+ {
59243+ .procname = "socket_server_gid",
59244+ .data = &grsec_socket_server_gid,
59245+ .maxlen = sizeof(int),
59246+ .mode = 0600,
59247+ .proc_handler = &proc_dointvec,
59248+ },
59249+#endif
59250+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59251+ {
59252+ .procname = "audit_group",
59253+ .data = &grsec_enable_group,
59254+ .maxlen = sizeof(int),
59255+ .mode = 0600,
59256+ .proc_handler = &proc_dointvec,
59257+ },
59258+ {
59259+ .procname = "audit_gid",
59260+ .data = &grsec_audit_gid,
59261+ .maxlen = sizeof(int),
59262+ .mode = 0600,
59263+ .proc_handler = &proc_dointvec,
59264+ },
59265+#endif
59266+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59267+ {
59268+ .procname = "audit_chdir",
59269+ .data = &grsec_enable_chdir,
59270+ .maxlen = sizeof(int),
59271+ .mode = 0600,
59272+ .proc_handler = &proc_dointvec,
59273+ },
59274+#endif
59275+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59276+ {
59277+ .procname = "audit_mount",
59278+ .data = &grsec_enable_mount,
59279+ .maxlen = sizeof(int),
59280+ .mode = 0600,
59281+ .proc_handler = &proc_dointvec,
59282+ },
59283+#endif
59284+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59285+ {
59286+ .procname = "audit_textrel",
59287+ .data = &grsec_enable_audit_textrel,
59288+ .maxlen = sizeof(int),
59289+ .mode = 0600,
59290+ .proc_handler = &proc_dointvec,
59291+ },
59292+#endif
59293+#ifdef CONFIG_GRKERNSEC_DMESG
59294+ {
59295+ .procname = "dmesg",
59296+ .data = &grsec_enable_dmesg,
59297+ .maxlen = sizeof(int),
59298+ .mode = 0600,
59299+ .proc_handler = &proc_dointvec,
59300+ },
59301+#endif
59302+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59303+ {
59304+ .procname = "chroot_findtask",
59305+ .data = &grsec_enable_chroot_findtask,
59306+ .maxlen = sizeof(int),
59307+ .mode = 0600,
59308+ .proc_handler = &proc_dointvec,
59309+ },
59310+#endif
59311+#ifdef CONFIG_GRKERNSEC_RESLOG
59312+ {
59313+ .procname = "resource_logging",
59314+ .data = &grsec_resource_logging,
59315+ .maxlen = sizeof(int),
59316+ .mode = 0600,
59317+ .proc_handler = &proc_dointvec,
59318+ },
59319+#endif
59320+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59321+ {
59322+ .procname = "audit_ptrace",
59323+ .data = &grsec_enable_audit_ptrace,
59324+ .maxlen = sizeof(int),
59325+ .mode = 0600,
59326+ .proc_handler = &proc_dointvec,
59327+ },
59328+#endif
59329+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59330+ {
59331+ .procname = "harden_ptrace",
59332+ .data = &grsec_enable_harden_ptrace,
59333+ .maxlen = sizeof(int),
59334+ .mode = 0600,
59335+ .proc_handler = &proc_dointvec,
59336+ },
59337+#endif
59338+ {
59339+ .procname = "grsec_lock",
59340+ .data = &grsec_lock,
59341+ .maxlen = sizeof(int),
59342+ .mode = 0600,
59343+ .proc_handler = &proc_dointvec,
59344+ },
59345+#endif
59346+#ifdef CONFIG_GRKERNSEC_ROFS
59347+ {
59348+ .procname = "romount_protect",
59349+ .data = &grsec_enable_rofs,
59350+ .maxlen = sizeof(int),
59351+ .mode = 0600,
59352+ .proc_handler = &proc_dointvec_minmax,
59353+ .extra1 = &one,
59354+ .extra2 = &one,
59355+ },
59356+#endif
59357+ { }
59358+};
59359+#endif
59360diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59361new file mode 100644
59362index 0000000..0dc13c3
59363--- /dev/null
59364+++ b/grsecurity/grsec_time.c
59365@@ -0,0 +1,16 @@
59366+#include <linux/kernel.h>
59367+#include <linux/sched.h>
59368+#include <linux/grinternal.h>
59369+#include <linux/module.h>
59370+
59371+void
59372+gr_log_timechange(void)
59373+{
59374+#ifdef CONFIG_GRKERNSEC_TIME
59375+ if (grsec_enable_time)
59376+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59377+#endif
59378+ return;
59379+}
59380+
59381+EXPORT_SYMBOL(gr_log_timechange);
59382diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59383new file mode 100644
59384index 0000000..07e0dc0
59385--- /dev/null
59386+++ b/grsecurity/grsec_tpe.c
59387@@ -0,0 +1,73 @@
59388+#include <linux/kernel.h>
59389+#include <linux/sched.h>
59390+#include <linux/file.h>
59391+#include <linux/fs.h>
59392+#include <linux/grinternal.h>
59393+
59394+extern int gr_acl_tpe_check(void);
59395+
59396+int
59397+gr_tpe_allow(const struct file *file)
59398+{
59399+#ifdef CONFIG_GRKERNSEC
59400+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59401+ const struct cred *cred = current_cred();
59402+ char *msg = NULL;
59403+ char *msg2 = NULL;
59404+
59405+ // never restrict root
59406+ if (!cred->uid)
59407+ return 1;
59408+
59409+ if (grsec_enable_tpe) {
59410+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59411+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59412+ msg = "not being in trusted group";
59413+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59414+ msg = "being in untrusted group";
59415+#else
59416+ if (in_group_p(grsec_tpe_gid))
59417+ msg = "being in untrusted group";
59418+#endif
59419+ }
59420+ if (!msg && gr_acl_tpe_check())
59421+ msg = "being in untrusted role";
59422+
59423+ // not in any affected group/role
59424+ if (!msg)
59425+ goto next_check;
59426+
59427+ if (inode->i_uid)
59428+ msg2 = "file in non-root-owned directory";
59429+ else if (inode->i_mode & S_IWOTH)
59430+ msg2 = "file in world-writable directory";
59431+ else if (inode->i_mode & S_IWGRP)
59432+ msg2 = "file in group-writable directory";
59433+
59434+ if (msg && msg2) {
59435+ char fullmsg[70] = {0};
59436+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59437+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59438+ return 0;
59439+ }
59440+ msg = NULL;
59441+next_check:
59442+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59443+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59444+ return 1;
59445+
59446+ if (inode->i_uid && (inode->i_uid != cred->uid))
59447+ msg = "directory not owned by user";
59448+ else if (inode->i_mode & S_IWOTH)
59449+ msg = "file in world-writable directory";
59450+ else if (inode->i_mode & S_IWGRP)
59451+ msg = "file in group-writable directory";
59452+
59453+ if (msg) {
59454+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59455+ return 0;
59456+ }
59457+#endif
59458+#endif
59459+ return 1;
59460+}
59461diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59462new file mode 100644
59463index 0000000..9f7b1ac
59464--- /dev/null
59465+++ b/grsecurity/grsum.c
59466@@ -0,0 +1,61 @@
59467+#include <linux/err.h>
59468+#include <linux/kernel.h>
59469+#include <linux/sched.h>
59470+#include <linux/mm.h>
59471+#include <linux/scatterlist.h>
59472+#include <linux/crypto.h>
59473+#include <linux/gracl.h>
59474+
59475+
59476+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59477+#error "crypto and sha256 must be built into the kernel"
59478+#endif
59479+
59480+int
59481+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59482+{
59483+ char *p;
59484+ struct crypto_hash *tfm;
59485+ struct hash_desc desc;
59486+ struct scatterlist sg;
59487+ unsigned char temp_sum[GR_SHA_LEN];
59488+ volatile int retval = 0;
59489+ volatile int dummy = 0;
59490+ unsigned int i;
59491+
59492+ sg_init_table(&sg, 1);
59493+
59494+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59495+ if (IS_ERR(tfm)) {
59496+ /* should never happen, since sha256 should be built in */
59497+ return 1;
59498+ }
59499+
59500+ desc.tfm = tfm;
59501+ desc.flags = 0;
59502+
59503+ crypto_hash_init(&desc);
59504+
59505+ p = salt;
59506+ sg_set_buf(&sg, p, GR_SALT_LEN);
59507+ crypto_hash_update(&desc, &sg, sg.length);
59508+
59509+ p = entry->pw;
59510+ sg_set_buf(&sg, p, strlen(p));
59511+
59512+ crypto_hash_update(&desc, &sg, sg.length);
59513+
59514+ crypto_hash_final(&desc, temp_sum);
59515+
59516+ memset(entry->pw, 0, GR_PW_LEN);
59517+
59518+ for (i = 0; i < GR_SHA_LEN; i++)
59519+ if (sum[i] != temp_sum[i])
59520+ retval = 1;
59521+ else
59522+ dummy = 1; // waste a cycle
59523+
59524+ crypto_free_hash(tfm);
59525+
59526+ return retval;
59527+}
59528diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59529index 6cd5b64..f620d2d 100644
59530--- a/include/acpi/acpi_bus.h
59531+++ b/include/acpi/acpi_bus.h
59532@@ -107,7 +107,7 @@ struct acpi_device_ops {
59533 acpi_op_bind bind;
59534 acpi_op_unbind unbind;
59535 acpi_op_notify notify;
59536-};
59537+} __no_const;
59538
59539 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59540
59541diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59542index b7babf0..71e4e74 100644
59543--- a/include/asm-generic/atomic-long.h
59544+++ b/include/asm-generic/atomic-long.h
59545@@ -22,6 +22,12 @@
59546
59547 typedef atomic64_t atomic_long_t;
59548
59549+#ifdef CONFIG_PAX_REFCOUNT
59550+typedef atomic64_unchecked_t atomic_long_unchecked_t;
59551+#else
59552+typedef atomic64_t atomic_long_unchecked_t;
59553+#endif
59554+
59555 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59556
59557 static inline long atomic_long_read(atomic_long_t *l)
59558@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59559 return (long)atomic64_read(v);
59560 }
59561
59562+#ifdef CONFIG_PAX_REFCOUNT
59563+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59564+{
59565+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59566+
59567+ return (long)atomic64_read_unchecked(v);
59568+}
59569+#endif
59570+
59571 static inline void atomic_long_set(atomic_long_t *l, long i)
59572 {
59573 atomic64_t *v = (atomic64_t *)l;
59574@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59575 atomic64_set(v, i);
59576 }
59577
59578+#ifdef CONFIG_PAX_REFCOUNT
59579+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59580+{
59581+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59582+
59583+ atomic64_set_unchecked(v, i);
59584+}
59585+#endif
59586+
59587 static inline void atomic_long_inc(atomic_long_t *l)
59588 {
59589 atomic64_t *v = (atomic64_t *)l;
59590@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59591 atomic64_inc(v);
59592 }
59593
59594+#ifdef CONFIG_PAX_REFCOUNT
59595+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59596+{
59597+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59598+
59599+ atomic64_inc_unchecked(v);
59600+}
59601+#endif
59602+
59603 static inline void atomic_long_dec(atomic_long_t *l)
59604 {
59605 atomic64_t *v = (atomic64_t *)l;
59606@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59607 atomic64_dec(v);
59608 }
59609
59610+#ifdef CONFIG_PAX_REFCOUNT
59611+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59612+{
59613+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59614+
59615+ atomic64_dec_unchecked(v);
59616+}
59617+#endif
59618+
59619 static inline void atomic_long_add(long i, atomic_long_t *l)
59620 {
59621 atomic64_t *v = (atomic64_t *)l;
59622@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59623 atomic64_add(i, v);
59624 }
59625
59626+#ifdef CONFIG_PAX_REFCOUNT
59627+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59628+{
59629+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59630+
59631+ atomic64_add_unchecked(i, v);
59632+}
59633+#endif
59634+
59635 static inline void atomic_long_sub(long i, atomic_long_t *l)
59636 {
59637 atomic64_t *v = (atomic64_t *)l;
59638@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59639 atomic64_sub(i, v);
59640 }
59641
59642+#ifdef CONFIG_PAX_REFCOUNT
59643+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59644+{
59645+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59646+
59647+ atomic64_sub_unchecked(i, v);
59648+}
59649+#endif
59650+
59651 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59652 {
59653 atomic64_t *v = (atomic64_t *)l;
59654@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59655 return (long)atomic64_inc_return(v);
59656 }
59657
59658+#ifdef CONFIG_PAX_REFCOUNT
59659+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59660+{
59661+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59662+
59663+ return (long)atomic64_inc_return_unchecked(v);
59664+}
59665+#endif
59666+
59667 static inline long atomic_long_dec_return(atomic_long_t *l)
59668 {
59669 atomic64_t *v = (atomic64_t *)l;
59670@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59671
59672 typedef atomic_t atomic_long_t;
59673
59674+#ifdef CONFIG_PAX_REFCOUNT
59675+typedef atomic_unchecked_t atomic_long_unchecked_t;
59676+#else
59677+typedef atomic_t atomic_long_unchecked_t;
59678+#endif
59679+
59680 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59681 static inline long atomic_long_read(atomic_long_t *l)
59682 {
59683@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59684 return (long)atomic_read(v);
59685 }
59686
59687+#ifdef CONFIG_PAX_REFCOUNT
59688+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59689+{
59690+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59691+
59692+ return (long)atomic_read_unchecked(v);
59693+}
59694+#endif
59695+
59696 static inline void atomic_long_set(atomic_long_t *l, long i)
59697 {
59698 atomic_t *v = (atomic_t *)l;
59699@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59700 atomic_set(v, i);
59701 }
59702
59703+#ifdef CONFIG_PAX_REFCOUNT
59704+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59705+{
59706+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59707+
59708+ atomic_set_unchecked(v, i);
59709+}
59710+#endif
59711+
59712 static inline void atomic_long_inc(atomic_long_t *l)
59713 {
59714 atomic_t *v = (atomic_t *)l;
59715@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59716 atomic_inc(v);
59717 }
59718
59719+#ifdef CONFIG_PAX_REFCOUNT
59720+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59721+{
59722+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59723+
59724+ atomic_inc_unchecked(v);
59725+}
59726+#endif
59727+
59728 static inline void atomic_long_dec(atomic_long_t *l)
59729 {
59730 atomic_t *v = (atomic_t *)l;
59731@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59732 atomic_dec(v);
59733 }
59734
59735+#ifdef CONFIG_PAX_REFCOUNT
59736+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59737+{
59738+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59739+
59740+ atomic_dec_unchecked(v);
59741+}
59742+#endif
59743+
59744 static inline void atomic_long_add(long i, atomic_long_t *l)
59745 {
59746 atomic_t *v = (atomic_t *)l;
59747@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59748 atomic_add(i, v);
59749 }
59750
59751+#ifdef CONFIG_PAX_REFCOUNT
59752+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59753+{
59754+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59755+
59756+ atomic_add_unchecked(i, v);
59757+}
59758+#endif
59759+
59760 static inline void atomic_long_sub(long i, atomic_long_t *l)
59761 {
59762 atomic_t *v = (atomic_t *)l;
59763@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59764 atomic_sub(i, v);
59765 }
59766
59767+#ifdef CONFIG_PAX_REFCOUNT
59768+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59769+{
59770+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59771+
59772+ atomic_sub_unchecked(i, v);
59773+}
59774+#endif
59775+
59776 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59777 {
59778 atomic_t *v = (atomic_t *)l;
59779@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59780 return (long)atomic_inc_return(v);
59781 }
59782
59783+#ifdef CONFIG_PAX_REFCOUNT
59784+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59785+{
59786+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59787+
59788+ return (long)atomic_inc_return_unchecked(v);
59789+}
59790+#endif
59791+
59792 static inline long atomic_long_dec_return(atomic_long_t *l)
59793 {
59794 atomic_t *v = (atomic_t *)l;
59795@@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59796
59797 #endif /* BITS_PER_LONG == 64 */
59798
59799+#ifdef CONFIG_PAX_REFCOUNT
59800+static inline void pax_refcount_needs_these_functions(void)
59801+{
59802+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
59803+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
59804+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
59805+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
59806+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
59807+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
59808+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
59809+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
59810+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
59811+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
59812+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
59813+
59814+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
59815+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
59816+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
59817+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
59818+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
59819+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
59820+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
59821+}
59822+#else
59823+#define atomic_read_unchecked(v) atomic_read(v)
59824+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
59825+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
59826+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
59827+#define atomic_inc_unchecked(v) atomic_inc(v)
59828+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
59829+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
59830+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
59831+#define atomic_dec_unchecked(v) atomic_dec(v)
59832+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
59833+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
59834+
59835+#define atomic_long_read_unchecked(v) atomic_long_read(v)
59836+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
59837+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
59838+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
59839+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
59840+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
59841+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
59842+#endif
59843+
59844 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
59845diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
59846index b18ce4f..2ee2843 100644
59847--- a/include/asm-generic/atomic64.h
59848+++ b/include/asm-generic/atomic64.h
59849@@ -16,6 +16,8 @@ typedef struct {
59850 long long counter;
59851 } atomic64_t;
59852
59853+typedef atomic64_t atomic64_unchecked_t;
59854+
59855 #define ATOMIC64_INIT(i) { (i) }
59856
59857 extern long long atomic64_read(const atomic64_t *v);
59858@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
59859 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
59860 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
59861
59862+#define atomic64_read_unchecked(v) atomic64_read(v)
59863+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
59864+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
59865+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
59866+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
59867+#define atomic64_inc_unchecked(v) atomic64_inc(v)
59868+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
59869+#define atomic64_dec_unchecked(v) atomic64_dec(v)
59870+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
59871+
59872 #endif /* _ASM_GENERIC_ATOMIC64_H */
59873diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
59874index 1bfcfe5..e04c5c9 100644
59875--- a/include/asm-generic/cache.h
59876+++ b/include/asm-generic/cache.h
59877@@ -6,7 +6,7 @@
59878 * cache lines need to provide their own cache.h.
59879 */
59880
59881-#define L1_CACHE_SHIFT 5
59882-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
59883+#define L1_CACHE_SHIFT 5UL
59884+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
59885
59886 #endif /* __ASM_GENERIC_CACHE_H */
59887diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
59888index 0d68a1e..b74a761 100644
59889--- a/include/asm-generic/emergency-restart.h
59890+++ b/include/asm-generic/emergency-restart.h
59891@@ -1,7 +1,7 @@
59892 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
59893 #define _ASM_GENERIC_EMERGENCY_RESTART_H
59894
59895-static inline void machine_emergency_restart(void)
59896+static inline __noreturn void machine_emergency_restart(void)
59897 {
59898 machine_restart(NULL);
59899 }
59900diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
59901index 0232ccb..13d9165 100644
59902--- a/include/asm-generic/kmap_types.h
59903+++ b/include/asm-generic/kmap_types.h
59904@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
59905 KMAP_D(17) KM_NMI,
59906 KMAP_D(18) KM_NMI_PTE,
59907 KMAP_D(19) KM_KDB,
59908+KMAP_D(20) KM_CLEARPAGE,
59909 /*
59910 * Remember to update debug_kmap_atomic() when adding new kmap types!
59911 */
59912-KMAP_D(20) KM_TYPE_NR
59913+KMAP_D(21) KM_TYPE_NR
59914 };
59915
59916 #undef KMAP_D
59917diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
59918index 9ceb03b..2efbcbd 100644
59919--- a/include/asm-generic/local.h
59920+++ b/include/asm-generic/local.h
59921@@ -39,6 +39,7 @@ typedef struct
59922 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
59923 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
59924 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
59925+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
59926
59927 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
59928 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
59929diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
59930index 725612b..9cc513a 100644
59931--- a/include/asm-generic/pgtable-nopmd.h
59932+++ b/include/asm-generic/pgtable-nopmd.h
59933@@ -1,14 +1,19 @@
59934 #ifndef _PGTABLE_NOPMD_H
59935 #define _PGTABLE_NOPMD_H
59936
59937-#ifndef __ASSEMBLY__
59938-
59939 #include <asm-generic/pgtable-nopud.h>
59940
59941-struct mm_struct;
59942-
59943 #define __PAGETABLE_PMD_FOLDED
59944
59945+#define PMD_SHIFT PUD_SHIFT
59946+#define PTRS_PER_PMD 1
59947+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
59948+#define PMD_MASK (~(PMD_SIZE-1))
59949+
59950+#ifndef __ASSEMBLY__
59951+
59952+struct mm_struct;
59953+
59954 /*
59955 * Having the pmd type consist of a pud gets the size right, and allows
59956 * us to conceptually access the pud entry that this pmd is folded into
59957@@ -16,11 +21,6 @@ struct mm_struct;
59958 */
59959 typedef struct { pud_t pud; } pmd_t;
59960
59961-#define PMD_SHIFT PUD_SHIFT
59962-#define PTRS_PER_PMD 1
59963-#define PMD_SIZE (1UL << PMD_SHIFT)
59964-#define PMD_MASK (~(PMD_SIZE-1))
59965-
59966 /*
59967 * The "pud_xxx()" functions here are trivial for a folded two-level
59968 * setup: the pmd is never bad, and a pmd always exists (as it's folded
59969diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
59970index 810431d..0ec4804f 100644
59971--- a/include/asm-generic/pgtable-nopud.h
59972+++ b/include/asm-generic/pgtable-nopud.h
59973@@ -1,10 +1,15 @@
59974 #ifndef _PGTABLE_NOPUD_H
59975 #define _PGTABLE_NOPUD_H
59976
59977-#ifndef __ASSEMBLY__
59978-
59979 #define __PAGETABLE_PUD_FOLDED
59980
59981+#define PUD_SHIFT PGDIR_SHIFT
59982+#define PTRS_PER_PUD 1
59983+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
59984+#define PUD_MASK (~(PUD_SIZE-1))
59985+
59986+#ifndef __ASSEMBLY__
59987+
59988 /*
59989 * Having the pud type consist of a pgd gets the size right, and allows
59990 * us to conceptually access the pgd entry that this pud is folded into
59991@@ -12,11 +17,6 @@
59992 */
59993 typedef struct { pgd_t pgd; } pud_t;
59994
59995-#define PUD_SHIFT PGDIR_SHIFT
59996-#define PTRS_PER_PUD 1
59997-#define PUD_SIZE (1UL << PUD_SHIFT)
59998-#define PUD_MASK (~(PUD_SIZE-1))
59999-
60000 /*
60001 * The "pgd_xxx()" functions here are trivial for a folded two-level
60002 * setup: the pud is never bad, and a pud always exists (as it's folded
60003@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60004 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60005
60006 #define pgd_populate(mm, pgd, pud) do { } while (0)
60007+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60008 /*
60009 * (puds are folded into pgds so this doesn't get actually called,
60010 * but the define is needed for a generic inline function.)
60011diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60012index a03c098..19751cf 100644
60013--- a/include/asm-generic/pgtable.h
60014+++ b/include/asm-generic/pgtable.h
60015@@ -445,6 +445,18 @@ static inline int pmd_write(pmd_t pmd)
60016 #endif /* __HAVE_ARCH_PMD_WRITE */
60017 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
60018
60019+#ifndef __HAVE_ARCH_READ_PMD_ATOMIC
60020+static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
60021+{
60022+ /*
60023+ * Depend on compiler for an atomic pmd read. NOTE: this is
60024+ * only going to work, if the pmdval_t isn't larger than
60025+ * an unsigned long.
60026+ */
60027+ return *pmdp;
60028+}
60029+#endif /* __HAVE_ARCH_READ_PMD_ATOMIC */
60030+
60031 /*
60032 * This function is meant to be used by sites walking pagetables with
60033 * the mmap_sem hold in read mode to protect against MADV_DONTNEED and
60034@@ -458,11 +470,17 @@ static inline int pmd_write(pmd_t pmd)
60035 * undefined so behaving like if the pmd was none is safe (because it
60036 * can return none anyway). The compiler level barrier() is critically
60037 * important to compute the two checks atomically on the same pmdval.
60038+ *
60039+ * For 32bit kernels with a 64bit large pmd_t this automatically takes
60040+ * care of reading the pmd atomically to avoid SMP race conditions
60041+ * against pmd_populate() when the mmap_sem is hold for reading by the
60042+ * caller (a special atomic read not done by "gcc" as in the generic
60043+ * version above, is also needed when THP is disabled because the page
60044+ * fault can populate the pmd from under us).
60045 */
60046 static inline int pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd)
60047 {
60048- /* depend on compiler for an atomic pmd read */
60049- pmd_t pmdval = *pmd;
60050+ pmd_t pmdval = read_pmd_atomic(pmd);
60051 /*
60052 * The barrier will stabilize the pmdval in a register or on
60053 * the stack so that it will stop changing under the code.
60054@@ -502,6 +520,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60055 #endif
60056 }
60057
60058+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60059+static inline unsigned long pax_open_kernel(void) { return 0; }
60060+#endif
60061+
60062+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60063+static inline unsigned long pax_close_kernel(void) { return 0; }
60064+#endif
60065+
60066 #endif /* CONFIG_MMU */
60067
60068 #endif /* !__ASSEMBLY__ */
60069diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60070index b5e2e4c..6a5373e 100644
60071--- a/include/asm-generic/vmlinux.lds.h
60072+++ b/include/asm-generic/vmlinux.lds.h
60073@@ -217,6 +217,7 @@
60074 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60075 VMLINUX_SYMBOL(__start_rodata) = .; \
60076 *(.rodata) *(.rodata.*) \
60077+ *(.data..read_only) \
60078 *(__vermagic) /* Kernel version magic */ \
60079 . = ALIGN(8); \
60080 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60081@@ -722,17 +723,18 @@
60082 * section in the linker script will go there too. @phdr should have
60083 * a leading colon.
60084 *
60085- * Note that this macros defines __per_cpu_load as an absolute symbol.
60086+ * Note that this macros defines per_cpu_load as an absolute symbol.
60087 * If there is no need to put the percpu section at a predetermined
60088 * address, use PERCPU_SECTION.
60089 */
60090 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60091- VMLINUX_SYMBOL(__per_cpu_load) = .; \
60092- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60093+ per_cpu_load = .; \
60094+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60095 - LOAD_OFFSET) { \
60096+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60097 PERCPU_INPUT(cacheline) \
60098 } phdr \
60099- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60100+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60101
60102 /**
60103 * PERCPU_SECTION - define output section for percpu area, simple version
60104diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60105index 92f0981..d44a37c 100644
60106--- a/include/drm/drmP.h
60107+++ b/include/drm/drmP.h
60108@@ -72,6 +72,7 @@
60109 #include <linux/workqueue.h>
60110 #include <linux/poll.h>
60111 #include <asm/pgalloc.h>
60112+#include <asm/local.h>
60113 #include "drm.h"
60114
60115 #include <linux/idr.h>
60116@@ -1038,7 +1039,7 @@ struct drm_device {
60117
60118 /** \name Usage Counters */
60119 /*@{ */
60120- int open_count; /**< Outstanding files open */
60121+ local_t open_count; /**< Outstanding files open */
60122 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60123 atomic_t vma_count; /**< Outstanding vma areas open */
60124 int buf_use; /**< Buffers in use -- cannot alloc */
60125@@ -1049,7 +1050,7 @@ struct drm_device {
60126 /*@{ */
60127 unsigned long counters;
60128 enum drm_stat_type types[15];
60129- atomic_t counts[15];
60130+ atomic_unchecked_t counts[15];
60131 /*@} */
60132
60133 struct list_head filelist;
60134diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60135index 37515d1..34fa8b0 100644
60136--- a/include/drm/drm_crtc_helper.h
60137+++ b/include/drm/drm_crtc_helper.h
60138@@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
60139
60140 /* disable crtc when not in use - more explicit than dpms off */
60141 void (*disable)(struct drm_crtc *crtc);
60142-};
60143+} __no_const;
60144
60145 struct drm_encoder_helper_funcs {
60146 void (*dpms)(struct drm_encoder *encoder, int mode);
60147@@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
60148 struct drm_connector *connector);
60149 /* disable encoder when not in use - more explicit than dpms off */
60150 void (*disable)(struct drm_encoder *encoder);
60151-};
60152+} __no_const;
60153
60154 struct drm_connector_helper_funcs {
60155 int (*get_modes)(struct drm_connector *connector);
60156diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60157index 26c1f78..6722682 100644
60158--- a/include/drm/ttm/ttm_memory.h
60159+++ b/include/drm/ttm/ttm_memory.h
60160@@ -47,7 +47,7 @@
60161
60162 struct ttm_mem_shrink {
60163 int (*do_shrink) (struct ttm_mem_shrink *);
60164-};
60165+} __no_const;
60166
60167 /**
60168 * struct ttm_mem_global - Global memory accounting structure.
60169diff --git a/include/linux/Kbuild b/include/linux/Kbuild
60170index c94e717..524703a 100644
60171--- a/include/linux/Kbuild
60172+++ b/include/linux/Kbuild
60173@@ -19,7 +19,7 @@ header-y += netfilter_ipv6/
60174 header-y += usb/
60175 header-y += wimax/
60176
60177-objhdr-y += version.h
60178+genhdr-y += version.h
60179
60180 ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/a.out.h \
60181 $(srctree)/include/asm-$(SRCARCH)/a.out.h \
60182diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60183index e86dfca..40cc55f 100644
60184--- a/include/linux/a.out.h
60185+++ b/include/linux/a.out.h
60186@@ -39,6 +39,14 @@ enum machine_type {
60187 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60188 };
60189
60190+/* Constants for the N_FLAGS field */
60191+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60192+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60193+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60194+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60195+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60196+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60197+
60198 #if !defined (N_MAGIC)
60199 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60200 #endif
60201diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60202index f4ff882..84b53a6 100644
60203--- a/include/linux/atmdev.h
60204+++ b/include/linux/atmdev.h
60205@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60206 #endif
60207
60208 struct k_atm_aal_stats {
60209-#define __HANDLE_ITEM(i) atomic_t i
60210+#define __HANDLE_ITEM(i) atomic_unchecked_t i
60211 __AAL_STAT_ITEMS
60212 #undef __HANDLE_ITEM
60213 };
60214diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60215index 0092102..8a801b4 100644
60216--- a/include/linux/binfmts.h
60217+++ b/include/linux/binfmts.h
60218@@ -89,6 +89,7 @@ struct linux_binfmt {
60219 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60220 int (*load_shlib)(struct file *);
60221 int (*core_dump)(struct coredump_params *cprm);
60222+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60223 unsigned long min_coredump; /* minimal dump size */
60224 };
60225
60226diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60227index 606cf33..b72c577 100644
60228--- a/include/linux/blkdev.h
60229+++ b/include/linux/blkdev.h
60230@@ -1379,7 +1379,7 @@ struct block_device_operations {
60231 /* this callback is with swap_lock and sometimes page table lock held */
60232 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60233 struct module *owner;
60234-};
60235+} __do_const;
60236
60237 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60238 unsigned long);
60239diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60240index 4d1a074..88f929a 100644
60241--- a/include/linux/blktrace_api.h
60242+++ b/include/linux/blktrace_api.h
60243@@ -162,7 +162,7 @@ struct blk_trace {
60244 struct dentry *dir;
60245 struct dentry *dropped_file;
60246 struct dentry *msg_file;
60247- atomic_t dropped;
60248+ atomic_unchecked_t dropped;
60249 };
60250
60251 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60252diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60253index 83195fb..0b0f77d 100644
60254--- a/include/linux/byteorder/little_endian.h
60255+++ b/include/linux/byteorder/little_endian.h
60256@@ -42,51 +42,51 @@
60257
60258 static inline __le64 __cpu_to_le64p(const __u64 *p)
60259 {
60260- return (__force __le64)*p;
60261+ return (__force const __le64)*p;
60262 }
60263 static inline __u64 __le64_to_cpup(const __le64 *p)
60264 {
60265- return (__force __u64)*p;
60266+ return (__force const __u64)*p;
60267 }
60268 static inline __le32 __cpu_to_le32p(const __u32 *p)
60269 {
60270- return (__force __le32)*p;
60271+ return (__force const __le32)*p;
60272 }
60273 static inline __u32 __le32_to_cpup(const __le32 *p)
60274 {
60275- return (__force __u32)*p;
60276+ return (__force const __u32)*p;
60277 }
60278 static inline __le16 __cpu_to_le16p(const __u16 *p)
60279 {
60280- return (__force __le16)*p;
60281+ return (__force const __le16)*p;
60282 }
60283 static inline __u16 __le16_to_cpup(const __le16 *p)
60284 {
60285- return (__force __u16)*p;
60286+ return (__force const __u16)*p;
60287 }
60288 static inline __be64 __cpu_to_be64p(const __u64 *p)
60289 {
60290- return (__force __be64)__swab64p(p);
60291+ return (__force const __be64)__swab64p(p);
60292 }
60293 static inline __u64 __be64_to_cpup(const __be64 *p)
60294 {
60295- return __swab64p((__u64 *)p);
60296+ return __swab64p((const __u64 *)p);
60297 }
60298 static inline __be32 __cpu_to_be32p(const __u32 *p)
60299 {
60300- return (__force __be32)__swab32p(p);
60301+ return (__force const __be32)__swab32p(p);
60302 }
60303 static inline __u32 __be32_to_cpup(const __be32 *p)
60304 {
60305- return __swab32p((__u32 *)p);
60306+ return __swab32p((const __u32 *)p);
60307 }
60308 static inline __be16 __cpu_to_be16p(const __u16 *p)
60309 {
60310- return (__force __be16)__swab16p(p);
60311+ return (__force const __be16)__swab16p(p);
60312 }
60313 static inline __u16 __be16_to_cpup(const __be16 *p)
60314 {
60315- return __swab16p((__u16 *)p);
60316+ return __swab16p((const __u16 *)p);
60317 }
60318 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60319 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60320diff --git a/include/linux/cache.h b/include/linux/cache.h
60321index 4c57065..4307975 100644
60322--- a/include/linux/cache.h
60323+++ b/include/linux/cache.h
60324@@ -16,6 +16,10 @@
60325 #define __read_mostly
60326 #endif
60327
60328+#ifndef __read_only
60329+#define __read_only __read_mostly
60330+#endif
60331+
60332 #ifndef ____cacheline_aligned
60333 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60334 #endif
60335diff --git a/include/linux/capability.h b/include/linux/capability.h
60336index 12d52de..b5f7fa7 100644
60337--- a/include/linux/capability.h
60338+++ b/include/linux/capability.h
60339@@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
60340 extern bool capable(int cap);
60341 extern bool ns_capable(struct user_namespace *ns, int cap);
60342 extern bool nsown_capable(int cap);
60343+extern bool capable_nolog(int cap);
60344+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60345
60346 /* audit system wants to get cap info from files as well */
60347 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60348diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60349index 04ffb2e..6799180 100644
60350--- a/include/linux/cleancache.h
60351+++ b/include/linux/cleancache.h
60352@@ -31,7 +31,7 @@ struct cleancache_ops {
60353 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
60354 void (*flush_inode)(int, struct cleancache_filekey);
60355 void (*flush_fs)(int);
60356-};
60357+} __no_const;
60358
60359 extern struct cleancache_ops
60360 cleancache_register_ops(struct cleancache_ops *ops);
60361diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60362index 2f40791..a62d196 100644
60363--- a/include/linux/compiler-gcc4.h
60364+++ b/include/linux/compiler-gcc4.h
60365@@ -32,6 +32,16 @@
60366 #define __linktime_error(message) __attribute__((__error__(message)))
60367
60368 #if __GNUC_MINOR__ >= 5
60369+
60370+#ifdef CONSTIFY_PLUGIN
60371+#define __no_const __attribute__((no_const))
60372+#define __do_const __attribute__((do_const))
60373+#endif
60374+
60375+#ifdef SIZE_OVERFLOW_PLUGIN
60376+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60377+#endif
60378+
60379 /*
60380 * Mark a position in code as unreachable. This can be used to
60381 * suppress control flow warnings after asm blocks that transfer
60382@@ -47,6 +57,11 @@
60383 #define __noclone __attribute__((__noclone__))
60384
60385 #endif
60386+
60387+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60388+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60389+#define __bos0(ptr) __bos((ptr), 0)
60390+#define __bos1(ptr) __bos((ptr), 1)
60391 #endif
60392
60393 #if __GNUC_MINOR__ > 0
60394diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60395index 4a24354..7149ac2 100644
60396--- a/include/linux/compiler.h
60397+++ b/include/linux/compiler.h
60398@@ -5,31 +5,62 @@
60399
60400 #ifdef __CHECKER__
60401 # define __user __attribute__((noderef, address_space(1)))
60402+# define __force_user __force __user
60403 # define __kernel __attribute__((address_space(0)))
60404+# define __force_kernel __force __kernel
60405 # define __safe __attribute__((safe))
60406 # define __force __attribute__((force))
60407 # define __nocast __attribute__((nocast))
60408 # define __iomem __attribute__((noderef, address_space(2)))
60409+# define __force_iomem __force __iomem
60410 # define __acquires(x) __attribute__((context(x,0,1)))
60411 # define __releases(x) __attribute__((context(x,1,0)))
60412 # define __acquire(x) __context__(x,1)
60413 # define __release(x) __context__(x,-1)
60414 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60415 # define __percpu __attribute__((noderef, address_space(3)))
60416+# define __force_percpu __force __percpu
60417 #ifdef CONFIG_SPARSE_RCU_POINTER
60418 # define __rcu __attribute__((noderef, address_space(4)))
60419+# define __force_rcu __force __rcu
60420 #else
60421 # define __rcu
60422+# define __force_rcu
60423 #endif
60424 extern void __chk_user_ptr(const volatile void __user *);
60425 extern void __chk_io_ptr(const volatile void __iomem *);
60426+#elif defined(CHECKER_PLUGIN)
60427+//# define __user
60428+//# define __force_user
60429+//# define __kernel
60430+//# define __force_kernel
60431+# define __safe
60432+# define __force
60433+# define __nocast
60434+# define __iomem
60435+# define __force_iomem
60436+# define __chk_user_ptr(x) (void)0
60437+# define __chk_io_ptr(x) (void)0
60438+# define __builtin_warning(x, y...) (1)
60439+# define __acquires(x)
60440+# define __releases(x)
60441+# define __acquire(x) (void)0
60442+# define __release(x) (void)0
60443+# define __cond_lock(x,c) (c)
60444+# define __percpu
60445+# define __force_percpu
60446+# define __rcu
60447+# define __force_rcu
60448 #else
60449 # define __user
60450+# define __force_user
60451 # define __kernel
60452+# define __force_kernel
60453 # define __safe
60454 # define __force
60455 # define __nocast
60456 # define __iomem
60457+# define __force_iomem
60458 # define __chk_user_ptr(x) (void)0
60459 # define __chk_io_ptr(x) (void)0
60460 # define __builtin_warning(x, y...) (1)
60461@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60462 # define __release(x) (void)0
60463 # define __cond_lock(x,c) (c)
60464 # define __percpu
60465+# define __force_percpu
60466 # define __rcu
60467+# define __force_rcu
60468 #endif
60469
60470 #ifdef __KERNEL__
60471@@ -264,6 +297,18 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60472 # define __attribute_const__ /* unimplemented */
60473 #endif
60474
60475+#ifndef __no_const
60476+# define __no_const
60477+#endif
60478+
60479+#ifndef __do_const
60480+# define __do_const
60481+#endif
60482+
60483+#ifndef __size_overflow
60484+# define __size_overflow(...)
60485+#endif
60486+
60487 /*
60488 * Tell gcc if a function is cold. The compiler will assume any path
60489 * directly leading to the call is unlikely.
60490@@ -273,6 +318,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60491 #define __cold
60492 #endif
60493
60494+#ifndef __alloc_size
60495+#define __alloc_size(...)
60496+#endif
60497+
60498+#ifndef __bos
60499+#define __bos(ptr, arg)
60500+#endif
60501+
60502+#ifndef __bos0
60503+#define __bos0(ptr)
60504+#endif
60505+
60506+#ifndef __bos1
60507+#define __bos1(ptr)
60508+#endif
60509+
60510 /* Simple shorthand for a section definition */
60511 #ifndef __section
60512 # define __section(S) __attribute__ ((__section__(#S)))
60513@@ -308,6 +369,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60514 * use is to mediate communication between process-level code and irq/NMI
60515 * handlers, all running on the same CPU.
60516 */
60517-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60518+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60519+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60520
60521 #endif /* __LINUX_COMPILER_H */
60522diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
60523index e9eaec5..bfeb9bb 100644
60524--- a/include/linux/cpuset.h
60525+++ b/include/linux/cpuset.h
60526@@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
60527 * nodemask.
60528 */
60529 smp_mb();
60530- --ACCESS_ONCE(current->mems_allowed_change_disable);
60531+ --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
60532 }
60533
60534 static inline void set_mems_allowed(nodemask_t nodemask)
60535diff --git a/include/linux/cred.h b/include/linux/cred.h
60536index adadf71..6af5560 100644
60537--- a/include/linux/cred.h
60538+++ b/include/linux/cred.h
60539@@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60540 static inline void validate_process_creds(void)
60541 {
60542 }
60543+static inline void validate_task_creds(struct task_struct *task)
60544+{
60545+}
60546 #endif
60547
60548 /**
60549diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60550index 8a94217..15d49e3 100644
60551--- a/include/linux/crypto.h
60552+++ b/include/linux/crypto.h
60553@@ -365,7 +365,7 @@ struct cipher_tfm {
60554 const u8 *key, unsigned int keylen);
60555 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60556 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60557-};
60558+} __no_const;
60559
60560 struct hash_tfm {
60561 int (*init)(struct hash_desc *desc);
60562@@ -386,13 +386,13 @@ struct compress_tfm {
60563 int (*cot_decompress)(struct crypto_tfm *tfm,
60564 const u8 *src, unsigned int slen,
60565 u8 *dst, unsigned int *dlen);
60566-};
60567+} __no_const;
60568
60569 struct rng_tfm {
60570 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60571 unsigned int dlen);
60572 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60573-};
60574+} __no_const;
60575
60576 #define crt_ablkcipher crt_u.ablkcipher
60577 #define crt_aead crt_u.aead
60578diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60579index 7925bf0..d5143d2 100644
60580--- a/include/linux/decompress/mm.h
60581+++ b/include/linux/decompress/mm.h
60582@@ -77,7 +77,7 @@ static void free(void *where)
60583 * warnings when not needed (indeed large_malloc / large_free are not
60584 * needed by inflate */
60585
60586-#define malloc(a) kmalloc(a, GFP_KERNEL)
60587+#define malloc(a) kmalloc((a), GFP_KERNEL)
60588 #define free(a) kfree(a)
60589
60590 #define large_malloc(a) vmalloc(a)
60591diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60592index e13117c..e9fc938 100644
60593--- a/include/linux/dma-mapping.h
60594+++ b/include/linux/dma-mapping.h
60595@@ -46,7 +46,7 @@ struct dma_map_ops {
60596 u64 (*get_required_mask)(struct device *dev);
60597 #endif
60598 int is_phys;
60599-};
60600+} __do_const;
60601
60602 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60603
60604diff --git a/include/linux/efi.h b/include/linux/efi.h
60605index 7cce0ea..c2085e4 100644
60606--- a/include/linux/efi.h
60607+++ b/include/linux/efi.h
60608@@ -591,7 +591,7 @@ struct efivar_operations {
60609 efi_get_variable_t *get_variable;
60610 efi_get_next_variable_t *get_next_variable;
60611 efi_set_variable_t *set_variable;
60612-};
60613+} __no_const;
60614
60615 struct efivars {
60616 /*
60617diff --git a/include/linux/elf.h b/include/linux/elf.h
60618index 999b4f5..57753b4 100644
60619--- a/include/linux/elf.h
60620+++ b/include/linux/elf.h
60621@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60622 #define PT_GNU_EH_FRAME 0x6474e550
60623
60624 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60625+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60626+
60627+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60628+
60629+/* Constants for the e_flags field */
60630+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60631+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60632+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60633+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60634+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60635+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60636
60637 /*
60638 * Extended Numbering
60639@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60640 #define DT_DEBUG 21
60641 #define DT_TEXTREL 22
60642 #define DT_JMPREL 23
60643+#define DT_FLAGS 30
60644+ #define DF_TEXTREL 0x00000004
60645 #define DT_ENCODING 32
60646 #define OLD_DT_LOOS 0x60000000
60647 #define DT_LOOS 0x6000000d
60648@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60649 #define PF_W 0x2
60650 #define PF_X 0x1
60651
60652+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60653+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60654+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60655+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60656+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60657+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60658+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60659+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60660+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60661+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60662+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60663+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60664+
60665 typedef struct elf32_phdr{
60666 Elf32_Word p_type;
60667 Elf32_Off p_offset;
60668@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60669 #define EI_OSABI 7
60670 #define EI_PAD 8
60671
60672+#define EI_PAX 14
60673+
60674 #define ELFMAG0 0x7f /* EI_MAG */
60675 #define ELFMAG1 'E'
60676 #define ELFMAG2 'L'
60677@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60678 #define elf_note elf32_note
60679 #define elf_addr_t Elf32_Off
60680 #define Elf_Half Elf32_Half
60681+#define elf_dyn Elf32_Dyn
60682
60683 #else
60684
60685@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60686 #define elf_note elf64_note
60687 #define elf_addr_t Elf64_Off
60688 #define Elf_Half Elf64_Half
60689+#define elf_dyn Elf64_Dyn
60690
60691 #endif
60692
60693diff --git a/include/linux/filter.h b/include/linux/filter.h
60694index 8eeb205..d59bfa2 100644
60695--- a/include/linux/filter.h
60696+++ b/include/linux/filter.h
60697@@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
60698
60699 struct sk_buff;
60700 struct sock;
60701+struct bpf_jit_work;
60702
60703 struct sk_filter
60704 {
60705@@ -141,6 +142,9 @@ struct sk_filter
60706 unsigned int len; /* Number of filter blocks */
60707 unsigned int (*bpf_func)(const struct sk_buff *skb,
60708 const struct sock_filter *filter);
60709+#ifdef CONFIG_BPF_JIT
60710+ struct bpf_jit_work *work;
60711+#endif
60712 struct rcu_head rcu;
60713 struct sock_filter insns[0];
60714 };
60715diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60716index 84ccf8e..2e9b14c 100644
60717--- a/include/linux/firewire.h
60718+++ b/include/linux/firewire.h
60719@@ -428,7 +428,7 @@ struct fw_iso_context {
60720 union {
60721 fw_iso_callback_t sc;
60722 fw_iso_mc_callback_t mc;
60723- } callback;
60724+ } __no_const callback;
60725 void *callback_data;
60726 };
60727
60728diff --git a/include/linux/fs.h b/include/linux/fs.h
60729index f4b6e06..d6ba573 100644
60730--- a/include/linux/fs.h
60731+++ b/include/linux/fs.h
60732@@ -1628,7 +1628,8 @@ struct file_operations {
60733 int (*setlease)(struct file *, long, struct file_lock **);
60734 long (*fallocate)(struct file *file, int mode, loff_t offset,
60735 loff_t len);
60736-};
60737+} __do_const;
60738+typedef struct file_operations __no_const file_operations_no_const;
60739
60740 struct inode_operations {
60741 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60742diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60743index 003dc0f..3c4ea97 100644
60744--- a/include/linux/fs_struct.h
60745+++ b/include/linux/fs_struct.h
60746@@ -6,7 +6,7 @@
60747 #include <linux/seqlock.h>
60748
60749 struct fs_struct {
60750- int users;
60751+ atomic_t users;
60752 spinlock_t lock;
60753 seqcount_t seq;
60754 int umask;
60755diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60756index ce31408..b1ad003 100644
60757--- a/include/linux/fscache-cache.h
60758+++ b/include/linux/fscache-cache.h
60759@@ -102,7 +102,7 @@ struct fscache_operation {
60760 fscache_operation_release_t release;
60761 };
60762
60763-extern atomic_t fscache_op_debug_id;
60764+extern atomic_unchecked_t fscache_op_debug_id;
60765 extern void fscache_op_work_func(struct work_struct *work);
60766
60767 extern void fscache_enqueue_operation(struct fscache_operation *);
60768@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60769 {
60770 INIT_WORK(&op->work, fscache_op_work_func);
60771 atomic_set(&op->usage, 1);
60772- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60773+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60774 op->processor = processor;
60775 op->release = release;
60776 INIT_LIST_HEAD(&op->pend_link);
60777diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60778index 2a53f10..0187fdf 100644
60779--- a/include/linux/fsnotify.h
60780+++ b/include/linux/fsnotify.h
60781@@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60782 */
60783 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60784 {
60785- return kstrdup(name, GFP_KERNEL);
60786+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60787 }
60788
60789 /*
60790diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60791index 91d0e0a3..035666b 100644
60792--- a/include/linux/fsnotify_backend.h
60793+++ b/include/linux/fsnotify_backend.h
60794@@ -105,6 +105,7 @@ struct fsnotify_ops {
60795 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60796 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60797 };
60798+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60799
60800 /*
60801 * A group is a "thing" that wants to receive notification about filesystem
60802diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60803index c3da42d..c70e0df 100644
60804--- a/include/linux/ftrace_event.h
60805+++ b/include/linux/ftrace_event.h
60806@@ -97,7 +97,7 @@ struct trace_event_functions {
60807 trace_print_func raw;
60808 trace_print_func hex;
60809 trace_print_func binary;
60810-};
60811+} __no_const;
60812
60813 struct trace_event {
60814 struct hlist_node node;
60815@@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60816 extern int trace_add_event_call(struct ftrace_event_call *call);
60817 extern void trace_remove_event_call(struct ftrace_event_call *call);
60818
60819-#define is_signed_type(type) (((type)(-1)) < 0)
60820+#define is_signed_type(type) (((type)(-1)) < (type)1)
60821
60822 int trace_set_clr_event(const char *system, const char *event, int set);
60823
60824diff --git a/include/linux/genhd.h b/include/linux/genhd.h
60825index e61d319..0da8505 100644
60826--- a/include/linux/genhd.h
60827+++ b/include/linux/genhd.h
60828@@ -185,7 +185,7 @@ struct gendisk {
60829 struct kobject *slave_dir;
60830
60831 struct timer_rand_state *random;
60832- atomic_t sync_io; /* RAID */
60833+ atomic_unchecked_t sync_io; /* RAID */
60834 struct disk_events *ev;
60835 #ifdef CONFIG_BLK_DEV_INTEGRITY
60836 struct blk_integrity *integrity;
60837diff --git a/include/linux/gracl.h b/include/linux/gracl.h
60838new file mode 100644
60839index 0000000..8a130b6
60840--- /dev/null
60841+++ b/include/linux/gracl.h
60842@@ -0,0 +1,319 @@
60843+#ifndef GR_ACL_H
60844+#define GR_ACL_H
60845+
60846+#include <linux/grdefs.h>
60847+#include <linux/resource.h>
60848+#include <linux/capability.h>
60849+#include <linux/dcache.h>
60850+#include <asm/resource.h>
60851+
60852+/* Major status information */
60853+
60854+#define GR_VERSION "grsecurity 2.9"
60855+#define GRSECURITY_VERSION 0x2900
60856+
60857+enum {
60858+ GR_SHUTDOWN = 0,
60859+ GR_ENABLE = 1,
60860+ GR_SPROLE = 2,
60861+ GR_RELOAD = 3,
60862+ GR_SEGVMOD = 4,
60863+ GR_STATUS = 5,
60864+ GR_UNSPROLE = 6,
60865+ GR_PASSSET = 7,
60866+ GR_SPROLEPAM = 8,
60867+};
60868+
60869+/* Password setup definitions
60870+ * kernel/grhash.c */
60871+enum {
60872+ GR_PW_LEN = 128,
60873+ GR_SALT_LEN = 16,
60874+ GR_SHA_LEN = 32,
60875+};
60876+
60877+enum {
60878+ GR_SPROLE_LEN = 64,
60879+};
60880+
60881+enum {
60882+ GR_NO_GLOB = 0,
60883+ GR_REG_GLOB,
60884+ GR_CREATE_GLOB
60885+};
60886+
60887+#define GR_NLIMITS 32
60888+
60889+/* Begin Data Structures */
60890+
60891+struct sprole_pw {
60892+ unsigned char *rolename;
60893+ unsigned char salt[GR_SALT_LEN];
60894+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
60895+};
60896+
60897+struct name_entry {
60898+ __u32 key;
60899+ ino_t inode;
60900+ dev_t device;
60901+ char *name;
60902+ __u16 len;
60903+ __u8 deleted;
60904+ struct name_entry *prev;
60905+ struct name_entry *next;
60906+};
60907+
60908+struct inodev_entry {
60909+ struct name_entry *nentry;
60910+ struct inodev_entry *prev;
60911+ struct inodev_entry *next;
60912+};
60913+
60914+struct acl_role_db {
60915+ struct acl_role_label **r_hash;
60916+ __u32 r_size;
60917+};
60918+
60919+struct inodev_db {
60920+ struct inodev_entry **i_hash;
60921+ __u32 i_size;
60922+};
60923+
60924+struct name_db {
60925+ struct name_entry **n_hash;
60926+ __u32 n_size;
60927+};
60928+
60929+struct crash_uid {
60930+ uid_t uid;
60931+ unsigned long expires;
60932+};
60933+
60934+struct gr_hash_struct {
60935+ void **table;
60936+ void **nametable;
60937+ void *first;
60938+ __u32 table_size;
60939+ __u32 used_size;
60940+ int type;
60941+};
60942+
60943+/* Userspace Grsecurity ACL data structures */
60944+
60945+struct acl_subject_label {
60946+ char *filename;
60947+ ino_t inode;
60948+ dev_t device;
60949+ __u32 mode;
60950+ kernel_cap_t cap_mask;
60951+ kernel_cap_t cap_lower;
60952+ kernel_cap_t cap_invert_audit;
60953+
60954+ struct rlimit res[GR_NLIMITS];
60955+ __u32 resmask;
60956+
60957+ __u8 user_trans_type;
60958+ __u8 group_trans_type;
60959+ uid_t *user_transitions;
60960+ gid_t *group_transitions;
60961+ __u16 user_trans_num;
60962+ __u16 group_trans_num;
60963+
60964+ __u32 sock_families[2];
60965+ __u32 ip_proto[8];
60966+ __u32 ip_type;
60967+ struct acl_ip_label **ips;
60968+ __u32 ip_num;
60969+ __u32 inaddr_any_override;
60970+
60971+ __u32 crashes;
60972+ unsigned long expires;
60973+
60974+ struct acl_subject_label *parent_subject;
60975+ struct gr_hash_struct *hash;
60976+ struct acl_subject_label *prev;
60977+ struct acl_subject_label *next;
60978+
60979+ struct acl_object_label **obj_hash;
60980+ __u32 obj_hash_size;
60981+ __u16 pax_flags;
60982+};
60983+
60984+struct role_allowed_ip {
60985+ __u32 addr;
60986+ __u32 netmask;
60987+
60988+ struct role_allowed_ip *prev;
60989+ struct role_allowed_ip *next;
60990+};
60991+
60992+struct role_transition {
60993+ char *rolename;
60994+
60995+ struct role_transition *prev;
60996+ struct role_transition *next;
60997+};
60998+
60999+struct acl_role_label {
61000+ char *rolename;
61001+ uid_t uidgid;
61002+ __u16 roletype;
61003+
61004+ __u16 auth_attempts;
61005+ unsigned long expires;
61006+
61007+ struct acl_subject_label *root_label;
61008+ struct gr_hash_struct *hash;
61009+
61010+ struct acl_role_label *prev;
61011+ struct acl_role_label *next;
61012+
61013+ struct role_transition *transitions;
61014+ struct role_allowed_ip *allowed_ips;
61015+ uid_t *domain_children;
61016+ __u16 domain_child_num;
61017+
61018+ umode_t umask;
61019+
61020+ struct acl_subject_label **subj_hash;
61021+ __u32 subj_hash_size;
61022+};
61023+
61024+struct user_acl_role_db {
61025+ struct acl_role_label **r_table;
61026+ __u32 num_pointers; /* Number of allocations to track */
61027+ __u32 num_roles; /* Number of roles */
61028+ __u32 num_domain_children; /* Number of domain children */
61029+ __u32 num_subjects; /* Number of subjects */
61030+ __u32 num_objects; /* Number of objects */
61031+};
61032+
61033+struct acl_object_label {
61034+ char *filename;
61035+ ino_t inode;
61036+ dev_t device;
61037+ __u32 mode;
61038+
61039+ struct acl_subject_label *nested;
61040+ struct acl_object_label *globbed;
61041+
61042+ /* next two structures not used */
61043+
61044+ struct acl_object_label *prev;
61045+ struct acl_object_label *next;
61046+};
61047+
61048+struct acl_ip_label {
61049+ char *iface;
61050+ __u32 addr;
61051+ __u32 netmask;
61052+ __u16 low, high;
61053+ __u8 mode;
61054+ __u32 type;
61055+ __u32 proto[8];
61056+
61057+ /* next two structures not used */
61058+
61059+ struct acl_ip_label *prev;
61060+ struct acl_ip_label *next;
61061+};
61062+
61063+struct gr_arg {
61064+ struct user_acl_role_db role_db;
61065+ unsigned char pw[GR_PW_LEN];
61066+ unsigned char salt[GR_SALT_LEN];
61067+ unsigned char sum[GR_SHA_LEN];
61068+ unsigned char sp_role[GR_SPROLE_LEN];
61069+ struct sprole_pw *sprole_pws;
61070+ dev_t segv_device;
61071+ ino_t segv_inode;
61072+ uid_t segv_uid;
61073+ __u16 num_sprole_pws;
61074+ __u16 mode;
61075+};
61076+
61077+struct gr_arg_wrapper {
61078+ struct gr_arg *arg;
61079+ __u32 version;
61080+ __u32 size;
61081+};
61082+
61083+struct subject_map {
61084+ struct acl_subject_label *user;
61085+ struct acl_subject_label *kernel;
61086+ struct subject_map *prev;
61087+ struct subject_map *next;
61088+};
61089+
61090+struct acl_subj_map_db {
61091+ struct subject_map **s_hash;
61092+ __u32 s_size;
61093+};
61094+
61095+/* End Data Structures Section */
61096+
61097+/* Hash functions generated by empirical testing by Brad Spengler
61098+ Makes good use of the low bits of the inode. Generally 0-1 times
61099+ in loop for successful match. 0-3 for unsuccessful match.
61100+ Shift/add algorithm with modulus of table size and an XOR*/
61101+
61102+static __inline__ unsigned int
61103+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61104+{
61105+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
61106+}
61107+
61108+ static __inline__ unsigned int
61109+shash(const struct acl_subject_label *userp, const unsigned int sz)
61110+{
61111+ return ((const unsigned long)userp % sz);
61112+}
61113+
61114+static __inline__ unsigned int
61115+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61116+{
61117+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61118+}
61119+
61120+static __inline__ unsigned int
61121+nhash(const char *name, const __u16 len, const unsigned int sz)
61122+{
61123+ return full_name_hash((const unsigned char *)name, len) % sz;
61124+}
61125+
61126+#define FOR_EACH_ROLE_START(role) \
61127+ role = role_list; \
61128+ while (role) {
61129+
61130+#define FOR_EACH_ROLE_END(role) \
61131+ role = role->prev; \
61132+ }
61133+
61134+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61135+ subj = NULL; \
61136+ iter = 0; \
61137+ while (iter < role->subj_hash_size) { \
61138+ if (subj == NULL) \
61139+ subj = role->subj_hash[iter]; \
61140+ if (subj == NULL) { \
61141+ iter++; \
61142+ continue; \
61143+ }
61144+
61145+#define FOR_EACH_SUBJECT_END(subj,iter) \
61146+ subj = subj->next; \
61147+ if (subj == NULL) \
61148+ iter++; \
61149+ }
61150+
61151+
61152+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61153+ subj = role->hash->first; \
61154+ while (subj != NULL) {
61155+
61156+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61157+ subj = subj->next; \
61158+ }
61159+
61160+#endif
61161+
61162diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61163new file mode 100644
61164index 0000000..323ecf2
61165--- /dev/null
61166+++ b/include/linux/gralloc.h
61167@@ -0,0 +1,9 @@
61168+#ifndef __GRALLOC_H
61169+#define __GRALLOC_H
61170+
61171+void acl_free_all(void);
61172+int acl_alloc_stack_init(unsigned long size);
61173+void *acl_alloc(unsigned long len);
61174+void *acl_alloc_num(unsigned long num, unsigned long len);
61175+
61176+#endif
61177diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61178new file mode 100644
61179index 0000000..b30e9bc
61180--- /dev/null
61181+++ b/include/linux/grdefs.h
61182@@ -0,0 +1,140 @@
61183+#ifndef GRDEFS_H
61184+#define GRDEFS_H
61185+
61186+/* Begin grsecurity status declarations */
61187+
61188+enum {
61189+ GR_READY = 0x01,
61190+ GR_STATUS_INIT = 0x00 // disabled state
61191+};
61192+
61193+/* Begin ACL declarations */
61194+
61195+/* Role flags */
61196+
61197+enum {
61198+ GR_ROLE_USER = 0x0001,
61199+ GR_ROLE_GROUP = 0x0002,
61200+ GR_ROLE_DEFAULT = 0x0004,
61201+ GR_ROLE_SPECIAL = 0x0008,
61202+ GR_ROLE_AUTH = 0x0010,
61203+ GR_ROLE_NOPW = 0x0020,
61204+ GR_ROLE_GOD = 0x0040,
61205+ GR_ROLE_LEARN = 0x0080,
61206+ GR_ROLE_TPE = 0x0100,
61207+ GR_ROLE_DOMAIN = 0x0200,
61208+ GR_ROLE_PAM = 0x0400,
61209+ GR_ROLE_PERSIST = 0x0800
61210+};
61211+
61212+/* ACL Subject and Object mode flags */
61213+enum {
61214+ GR_DELETED = 0x80000000
61215+};
61216+
61217+/* ACL Object-only mode flags */
61218+enum {
61219+ GR_READ = 0x00000001,
61220+ GR_APPEND = 0x00000002,
61221+ GR_WRITE = 0x00000004,
61222+ GR_EXEC = 0x00000008,
61223+ GR_FIND = 0x00000010,
61224+ GR_INHERIT = 0x00000020,
61225+ GR_SETID = 0x00000040,
61226+ GR_CREATE = 0x00000080,
61227+ GR_DELETE = 0x00000100,
61228+ GR_LINK = 0x00000200,
61229+ GR_AUDIT_READ = 0x00000400,
61230+ GR_AUDIT_APPEND = 0x00000800,
61231+ GR_AUDIT_WRITE = 0x00001000,
61232+ GR_AUDIT_EXEC = 0x00002000,
61233+ GR_AUDIT_FIND = 0x00004000,
61234+ GR_AUDIT_INHERIT= 0x00008000,
61235+ GR_AUDIT_SETID = 0x00010000,
61236+ GR_AUDIT_CREATE = 0x00020000,
61237+ GR_AUDIT_DELETE = 0x00040000,
61238+ GR_AUDIT_LINK = 0x00080000,
61239+ GR_PTRACERD = 0x00100000,
61240+ GR_NOPTRACE = 0x00200000,
61241+ GR_SUPPRESS = 0x00400000,
61242+ GR_NOLEARN = 0x00800000,
61243+ GR_INIT_TRANSFER= 0x01000000
61244+};
61245+
61246+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61247+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61248+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61249+
61250+/* ACL subject-only mode flags */
61251+enum {
61252+ GR_KILL = 0x00000001,
61253+ GR_VIEW = 0x00000002,
61254+ GR_PROTECTED = 0x00000004,
61255+ GR_LEARN = 0x00000008,
61256+ GR_OVERRIDE = 0x00000010,
61257+ /* just a placeholder, this mode is only used in userspace */
61258+ GR_DUMMY = 0x00000020,
61259+ GR_PROTSHM = 0x00000040,
61260+ GR_KILLPROC = 0x00000080,
61261+ GR_KILLIPPROC = 0x00000100,
61262+ /* just a placeholder, this mode is only used in userspace */
61263+ GR_NOTROJAN = 0x00000200,
61264+ GR_PROTPROCFD = 0x00000400,
61265+ GR_PROCACCT = 0x00000800,
61266+ GR_RELAXPTRACE = 0x00001000,
61267+ GR_NESTED = 0x00002000,
61268+ GR_INHERITLEARN = 0x00004000,
61269+ GR_PROCFIND = 0x00008000,
61270+ GR_POVERRIDE = 0x00010000,
61271+ GR_KERNELAUTH = 0x00020000,
61272+ GR_ATSECURE = 0x00040000,
61273+ GR_SHMEXEC = 0x00080000
61274+};
61275+
61276+enum {
61277+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61278+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61279+ GR_PAX_ENABLE_MPROTECT = 0x0004,
61280+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
61281+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61282+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61283+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61284+ GR_PAX_DISABLE_MPROTECT = 0x0400,
61285+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
61286+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61287+};
61288+
61289+enum {
61290+ GR_ID_USER = 0x01,
61291+ GR_ID_GROUP = 0x02,
61292+};
61293+
61294+enum {
61295+ GR_ID_ALLOW = 0x01,
61296+ GR_ID_DENY = 0x02,
61297+};
61298+
61299+#define GR_CRASH_RES 31
61300+#define GR_UIDTABLE_MAX 500
61301+
61302+/* begin resource learning section */
61303+enum {
61304+ GR_RLIM_CPU_BUMP = 60,
61305+ GR_RLIM_FSIZE_BUMP = 50000,
61306+ GR_RLIM_DATA_BUMP = 10000,
61307+ GR_RLIM_STACK_BUMP = 1000,
61308+ GR_RLIM_CORE_BUMP = 10000,
61309+ GR_RLIM_RSS_BUMP = 500000,
61310+ GR_RLIM_NPROC_BUMP = 1,
61311+ GR_RLIM_NOFILE_BUMP = 5,
61312+ GR_RLIM_MEMLOCK_BUMP = 50000,
61313+ GR_RLIM_AS_BUMP = 500000,
61314+ GR_RLIM_LOCKS_BUMP = 2,
61315+ GR_RLIM_SIGPENDING_BUMP = 5,
61316+ GR_RLIM_MSGQUEUE_BUMP = 10000,
61317+ GR_RLIM_NICE_BUMP = 1,
61318+ GR_RLIM_RTPRIO_BUMP = 1,
61319+ GR_RLIM_RTTIME_BUMP = 1000000
61320+};
61321+
61322+#endif
61323diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61324new file mode 100644
61325index 0000000..da390f1
61326--- /dev/null
61327+++ b/include/linux/grinternal.h
61328@@ -0,0 +1,221 @@
61329+#ifndef __GRINTERNAL_H
61330+#define __GRINTERNAL_H
61331+
61332+#ifdef CONFIG_GRKERNSEC
61333+
61334+#include <linux/fs.h>
61335+#include <linux/mnt_namespace.h>
61336+#include <linux/nsproxy.h>
61337+#include <linux/gracl.h>
61338+#include <linux/grdefs.h>
61339+#include <linux/grmsg.h>
61340+
61341+void gr_add_learn_entry(const char *fmt, ...)
61342+ __attribute__ ((format (printf, 1, 2)));
61343+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61344+ const struct vfsmount *mnt);
61345+__u32 gr_check_create(const struct dentry *new_dentry,
61346+ const struct dentry *parent,
61347+ const struct vfsmount *mnt, const __u32 mode);
61348+int gr_check_protected_task(const struct task_struct *task);
61349+__u32 to_gr_audit(const __u32 reqmode);
61350+int gr_set_acls(const int type);
61351+int gr_apply_subject_to_task(struct task_struct *task);
61352+int gr_acl_is_enabled(void);
61353+char gr_roletype_to_char(void);
61354+
61355+void gr_handle_alertkill(struct task_struct *task);
61356+char *gr_to_filename(const struct dentry *dentry,
61357+ const struct vfsmount *mnt);
61358+char *gr_to_filename1(const struct dentry *dentry,
61359+ const struct vfsmount *mnt);
61360+char *gr_to_filename2(const struct dentry *dentry,
61361+ const struct vfsmount *mnt);
61362+char *gr_to_filename3(const struct dentry *dentry,
61363+ const struct vfsmount *mnt);
61364+
61365+extern int grsec_enable_ptrace_readexec;
61366+extern int grsec_enable_harden_ptrace;
61367+extern int grsec_enable_link;
61368+extern int grsec_enable_fifo;
61369+extern int grsec_enable_execve;
61370+extern int grsec_enable_shm;
61371+extern int grsec_enable_execlog;
61372+extern int grsec_enable_signal;
61373+extern int grsec_enable_audit_ptrace;
61374+extern int grsec_enable_forkfail;
61375+extern int grsec_enable_time;
61376+extern int grsec_enable_rofs;
61377+extern int grsec_enable_chroot_shmat;
61378+extern int grsec_enable_chroot_mount;
61379+extern int grsec_enable_chroot_double;
61380+extern int grsec_enable_chroot_pivot;
61381+extern int grsec_enable_chroot_chdir;
61382+extern int grsec_enable_chroot_chmod;
61383+extern int grsec_enable_chroot_mknod;
61384+extern int grsec_enable_chroot_fchdir;
61385+extern int grsec_enable_chroot_nice;
61386+extern int grsec_enable_chroot_execlog;
61387+extern int grsec_enable_chroot_caps;
61388+extern int grsec_enable_chroot_sysctl;
61389+extern int grsec_enable_chroot_unix;
61390+extern int grsec_enable_tpe;
61391+extern int grsec_tpe_gid;
61392+extern int grsec_enable_tpe_all;
61393+extern int grsec_enable_tpe_invert;
61394+extern int grsec_enable_socket_all;
61395+extern int grsec_socket_all_gid;
61396+extern int grsec_enable_socket_client;
61397+extern int grsec_socket_client_gid;
61398+extern int grsec_enable_socket_server;
61399+extern int grsec_socket_server_gid;
61400+extern int grsec_audit_gid;
61401+extern int grsec_enable_group;
61402+extern int grsec_enable_audit_textrel;
61403+extern int grsec_enable_log_rwxmaps;
61404+extern int grsec_enable_mount;
61405+extern int grsec_enable_chdir;
61406+extern int grsec_resource_logging;
61407+extern int grsec_enable_blackhole;
61408+extern int grsec_lastack_retries;
61409+extern int grsec_enable_brute;
61410+extern int grsec_lock;
61411+
61412+extern spinlock_t grsec_alert_lock;
61413+extern unsigned long grsec_alert_wtime;
61414+extern unsigned long grsec_alert_fyet;
61415+
61416+extern spinlock_t grsec_audit_lock;
61417+
61418+extern rwlock_t grsec_exec_file_lock;
61419+
61420+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61421+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61422+ (tsk)->exec_file->f_vfsmnt) : "/")
61423+
61424+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61425+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61426+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61427+
61428+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61429+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
61430+ (tsk)->exec_file->f_vfsmnt) : "/")
61431+
61432+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61433+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61434+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61435+
61436+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61437+
61438+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61439+
61440+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61441+ (task)->pid, (cred)->uid, \
61442+ (cred)->euid, (cred)->gid, (cred)->egid, \
61443+ gr_parent_task_fullpath(task), \
61444+ (task)->real_parent->comm, (task)->real_parent->pid, \
61445+ (pcred)->uid, (pcred)->euid, \
61446+ (pcred)->gid, (pcred)->egid
61447+
61448+#define GR_CHROOT_CAPS {{ \
61449+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61450+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61451+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61452+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61453+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61454+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61455+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61456+
61457+#define security_learn(normal_msg,args...) \
61458+({ \
61459+ read_lock(&grsec_exec_file_lock); \
61460+ gr_add_learn_entry(normal_msg "\n", ## args); \
61461+ read_unlock(&grsec_exec_file_lock); \
61462+})
61463+
61464+enum {
61465+ GR_DO_AUDIT,
61466+ GR_DONT_AUDIT,
61467+ /* used for non-audit messages that we shouldn't kill the task on */
61468+ GR_DONT_AUDIT_GOOD
61469+};
61470+
61471+enum {
61472+ GR_TTYSNIFF,
61473+ GR_RBAC,
61474+ GR_RBAC_STR,
61475+ GR_STR_RBAC,
61476+ GR_RBAC_MODE2,
61477+ GR_RBAC_MODE3,
61478+ GR_FILENAME,
61479+ GR_SYSCTL_HIDDEN,
61480+ GR_NOARGS,
61481+ GR_ONE_INT,
61482+ GR_ONE_INT_TWO_STR,
61483+ GR_ONE_STR,
61484+ GR_STR_INT,
61485+ GR_TWO_STR_INT,
61486+ GR_TWO_INT,
61487+ GR_TWO_U64,
61488+ GR_THREE_INT,
61489+ GR_FIVE_INT_TWO_STR,
61490+ GR_TWO_STR,
61491+ GR_THREE_STR,
61492+ GR_FOUR_STR,
61493+ GR_STR_FILENAME,
61494+ GR_FILENAME_STR,
61495+ GR_FILENAME_TWO_INT,
61496+ GR_FILENAME_TWO_INT_STR,
61497+ GR_TEXTREL,
61498+ GR_PTRACE,
61499+ GR_RESOURCE,
61500+ GR_CAP,
61501+ GR_SIG,
61502+ GR_SIG2,
61503+ GR_CRASH1,
61504+ GR_CRASH2,
61505+ GR_PSACCT,
61506+ GR_RWXMAP
61507+};
61508+
61509+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61510+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61511+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61512+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61513+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61514+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61515+#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)
61516+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61517+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61518+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61519+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61520+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61521+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61522+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61523+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61524+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61525+#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)
61526+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61527+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61528+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61529+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61530+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61531+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61532+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61533+#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)
61534+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61535+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61536+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61537+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61538+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61539+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61540+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61541+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61542+#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)
61543+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61544+
61545+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61546+
61547+#endif
61548+
61549+#endif
61550diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61551new file mode 100644
61552index 0000000..ae576a1
61553--- /dev/null
61554+++ b/include/linux/grmsg.h
61555@@ -0,0 +1,109 @@
61556+#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"
61557+#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"
61558+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61559+#define GR_STOPMOD_MSG "denied modification of module state by "
61560+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61561+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61562+#define GR_IOPERM_MSG "denied use of ioperm() by "
61563+#define GR_IOPL_MSG "denied use of iopl() by "
61564+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61565+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61566+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61567+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61568+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61569+#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"
61570+#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"
61571+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61572+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61573+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61574+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61575+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61576+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61577+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61578+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61579+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61580+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61581+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61582+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61583+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61584+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61585+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61586+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61587+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61588+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61589+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61590+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61591+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61592+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61593+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61594+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61595+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61596+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61597+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61598+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61599+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61600+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61601+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61602+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61603+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61604+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61605+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61606+#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"
61607+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61608+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61609+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61610+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61611+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61612+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61613+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61614+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61615+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61616+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61617+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61618+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61619+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61620+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61621+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61622+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61623+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61624+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61625+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61626+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61627+#define GR_FAILFORK_MSG "failed fork with errno %s by "
61628+#define GR_NICE_CHROOT_MSG "denied priority change by "
61629+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61630+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61631+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61632+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61633+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61634+#define GR_TIME_MSG "time set by "
61635+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61636+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61637+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61638+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61639+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61640+#define GR_BIND_MSG "denied bind() by "
61641+#define GR_CONNECT_MSG "denied connect() by "
61642+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61643+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61644+#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"
61645+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61646+#define GR_CAP_ACL_MSG "use of %s denied for "
61647+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61648+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61649+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61650+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61651+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61652+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61653+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61654+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61655+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61656+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61657+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61658+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61659+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61660+#define GR_VM86_MSG "denied use of vm86 by "
61661+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61662+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61663+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61664+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61665diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61666new file mode 100644
61667index 0000000..acd05db
61668--- /dev/null
61669+++ b/include/linux/grsecurity.h
61670@@ -0,0 +1,232 @@
61671+#ifndef GR_SECURITY_H
61672+#define GR_SECURITY_H
61673+#include <linux/fs.h>
61674+#include <linux/fs_struct.h>
61675+#include <linux/binfmts.h>
61676+#include <linux/gracl.h>
61677+
61678+/* notify of brain-dead configs */
61679+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61680+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61681+#endif
61682+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61683+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61684+#endif
61685+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61686+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61687+#endif
61688+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61689+#error "CONFIG_PAX enabled, but no PaX options are enabled."
61690+#endif
61691+
61692+#include <linux/compat.h>
61693+
61694+struct user_arg_ptr {
61695+#ifdef CONFIG_COMPAT
61696+ bool is_compat;
61697+#endif
61698+ union {
61699+ const char __user *const __user *native;
61700+#ifdef CONFIG_COMPAT
61701+ compat_uptr_t __user *compat;
61702+#endif
61703+ } ptr;
61704+};
61705+
61706+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61707+void gr_handle_brute_check(void);
61708+void gr_handle_kernel_exploit(void);
61709+int gr_process_user_ban(void);
61710+
61711+char gr_roletype_to_char(void);
61712+
61713+int gr_acl_enable_at_secure(void);
61714+
61715+int gr_check_user_change(int real, int effective, int fs);
61716+int gr_check_group_change(int real, int effective, int fs);
61717+
61718+void gr_del_task_from_ip_table(struct task_struct *p);
61719+
61720+int gr_pid_is_chrooted(struct task_struct *p);
61721+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61722+int gr_handle_chroot_nice(void);
61723+int gr_handle_chroot_sysctl(const int op);
61724+int gr_handle_chroot_setpriority(struct task_struct *p,
61725+ const int niceval);
61726+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61727+int gr_handle_chroot_chroot(const struct dentry *dentry,
61728+ const struct vfsmount *mnt);
61729+void gr_handle_chroot_chdir(struct path *path);
61730+int gr_handle_chroot_chmod(const struct dentry *dentry,
61731+ const struct vfsmount *mnt, const int mode);
61732+int gr_handle_chroot_mknod(const struct dentry *dentry,
61733+ const struct vfsmount *mnt, const int mode);
61734+int gr_handle_chroot_mount(const struct dentry *dentry,
61735+ const struct vfsmount *mnt,
61736+ const char *dev_name);
61737+int gr_handle_chroot_pivot(void);
61738+int gr_handle_chroot_unix(const pid_t pid);
61739+
61740+int gr_handle_rawio(const struct inode *inode);
61741+
61742+void gr_handle_ioperm(void);
61743+void gr_handle_iopl(void);
61744+
61745+umode_t gr_acl_umask(void);
61746+
61747+int gr_tpe_allow(const struct file *file);
61748+
61749+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61750+void gr_clear_chroot_entries(struct task_struct *task);
61751+
61752+void gr_log_forkfail(const int retval);
61753+void gr_log_timechange(void);
61754+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61755+void gr_log_chdir(const struct dentry *dentry,
61756+ const struct vfsmount *mnt);
61757+void gr_log_chroot_exec(const struct dentry *dentry,
61758+ const struct vfsmount *mnt);
61759+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
61760+void gr_log_remount(const char *devname, const int retval);
61761+void gr_log_unmount(const char *devname, const int retval);
61762+void gr_log_mount(const char *from, const char *to, const int retval);
61763+void gr_log_textrel(struct vm_area_struct *vma);
61764+void gr_log_rwxmmap(struct file *file);
61765+void gr_log_rwxmprotect(struct file *file);
61766+
61767+int gr_handle_follow_link(const struct inode *parent,
61768+ const struct inode *inode,
61769+ const struct dentry *dentry,
61770+ const struct vfsmount *mnt);
61771+int gr_handle_fifo(const struct dentry *dentry,
61772+ const struct vfsmount *mnt,
61773+ const struct dentry *dir, const int flag,
61774+ const int acc_mode);
61775+int gr_handle_hardlink(const struct dentry *dentry,
61776+ const struct vfsmount *mnt,
61777+ struct inode *inode,
61778+ const int mode, const char *to);
61779+
61780+int gr_is_capable(const int cap);
61781+int gr_is_capable_nolog(const int cap);
61782+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61783+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
61784+
61785+void gr_learn_resource(const struct task_struct *task, const int limit,
61786+ const unsigned long wanted, const int gt);
61787+void gr_copy_label(struct task_struct *tsk);
61788+void gr_handle_crash(struct task_struct *task, const int sig);
61789+int gr_handle_signal(const struct task_struct *p, const int sig);
61790+int gr_check_crash_uid(const uid_t uid);
61791+int gr_check_protected_task(const struct task_struct *task);
61792+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
61793+int gr_acl_handle_mmap(const struct file *file,
61794+ const unsigned long prot);
61795+int gr_acl_handle_mprotect(const struct file *file,
61796+ const unsigned long prot);
61797+int gr_check_hidden_task(const struct task_struct *tsk);
61798+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
61799+ const struct vfsmount *mnt);
61800+__u32 gr_acl_handle_utime(const struct dentry *dentry,
61801+ const struct vfsmount *mnt);
61802+__u32 gr_acl_handle_access(const struct dentry *dentry,
61803+ const struct vfsmount *mnt, const int fmode);
61804+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
61805+ const struct vfsmount *mnt, umode_t *mode);
61806+__u32 gr_acl_handle_chown(const struct dentry *dentry,
61807+ const struct vfsmount *mnt);
61808+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
61809+ const struct vfsmount *mnt);
61810+int gr_handle_ptrace(struct task_struct *task, const long request);
61811+int gr_handle_proc_ptrace(struct task_struct *task);
61812+__u32 gr_acl_handle_execve(const struct dentry *dentry,
61813+ const struct vfsmount *mnt);
61814+int gr_check_crash_exec(const struct file *filp);
61815+int gr_acl_is_enabled(void);
61816+void gr_set_kernel_label(struct task_struct *task);
61817+void gr_set_role_label(struct task_struct *task, const uid_t uid,
61818+ const gid_t gid);
61819+int gr_set_proc_label(const struct dentry *dentry,
61820+ const struct vfsmount *mnt,
61821+ const int unsafe_flags);
61822+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
61823+ const struct vfsmount *mnt);
61824+__u32 gr_acl_handle_open(const struct dentry *dentry,
61825+ const struct vfsmount *mnt, int acc_mode);
61826+__u32 gr_acl_handle_creat(const struct dentry *dentry,
61827+ const struct dentry *p_dentry,
61828+ const struct vfsmount *p_mnt,
61829+ int open_flags, int acc_mode, const int imode);
61830+void gr_handle_create(const struct dentry *dentry,
61831+ const struct vfsmount *mnt);
61832+void gr_handle_proc_create(const struct dentry *dentry,
61833+ const struct inode *inode);
61834+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
61835+ const struct dentry *parent_dentry,
61836+ const struct vfsmount *parent_mnt,
61837+ const int mode);
61838+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
61839+ const struct dentry *parent_dentry,
61840+ const struct vfsmount *parent_mnt);
61841+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
61842+ const struct vfsmount *mnt);
61843+void gr_handle_delete(const ino_t ino, const dev_t dev);
61844+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
61845+ const struct vfsmount *mnt);
61846+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
61847+ const struct dentry *parent_dentry,
61848+ const struct vfsmount *parent_mnt,
61849+ const char *from);
61850+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
61851+ const struct dentry *parent_dentry,
61852+ const struct vfsmount *parent_mnt,
61853+ const struct dentry *old_dentry,
61854+ const struct vfsmount *old_mnt, const char *to);
61855+int gr_acl_handle_rename(struct dentry *new_dentry,
61856+ struct dentry *parent_dentry,
61857+ const struct vfsmount *parent_mnt,
61858+ struct dentry *old_dentry,
61859+ struct inode *old_parent_inode,
61860+ struct vfsmount *old_mnt, const char *newname);
61861+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61862+ struct dentry *old_dentry,
61863+ struct dentry *new_dentry,
61864+ struct vfsmount *mnt, const __u8 replace);
61865+__u32 gr_check_link(const struct dentry *new_dentry,
61866+ const struct dentry *parent_dentry,
61867+ const struct vfsmount *parent_mnt,
61868+ const struct dentry *old_dentry,
61869+ const struct vfsmount *old_mnt);
61870+int gr_acl_handle_filldir(const struct file *file, const char *name,
61871+ const unsigned int namelen, const ino_t ino);
61872+
61873+__u32 gr_acl_handle_unix(const struct dentry *dentry,
61874+ const struct vfsmount *mnt);
61875+void gr_acl_handle_exit(void);
61876+void gr_acl_handle_psacct(struct task_struct *task, const long code);
61877+int gr_acl_handle_procpidmem(const struct task_struct *task);
61878+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
61879+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
61880+void gr_audit_ptrace(struct task_struct *task);
61881+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
61882+
61883+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
61884+
61885+#ifdef CONFIG_GRKERNSEC
61886+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
61887+void gr_handle_vm86(void);
61888+void gr_handle_mem_readwrite(u64 from, u64 to);
61889+
61890+void gr_log_badprocpid(const char *entry);
61891+
61892+extern int grsec_enable_dmesg;
61893+extern int grsec_disable_privio;
61894+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61895+extern int grsec_enable_chroot_findtask;
61896+#endif
61897+#ifdef CONFIG_GRKERNSEC_SETXID
61898+extern int grsec_enable_setxid;
61899+#endif
61900+#endif
61901+
61902+#endif
61903diff --git a/include/linux/grsock.h b/include/linux/grsock.h
61904new file mode 100644
61905index 0000000..e7ffaaf
61906--- /dev/null
61907+++ b/include/linux/grsock.h
61908@@ -0,0 +1,19 @@
61909+#ifndef __GRSOCK_H
61910+#define __GRSOCK_H
61911+
61912+extern void gr_attach_curr_ip(const struct sock *sk);
61913+extern int gr_handle_sock_all(const int family, const int type,
61914+ const int protocol);
61915+extern int gr_handle_sock_server(const struct sockaddr *sck);
61916+extern int gr_handle_sock_server_other(const struct sock *sck);
61917+extern int gr_handle_sock_client(const struct sockaddr *sck);
61918+extern int gr_search_connect(struct socket * sock,
61919+ struct sockaddr_in * addr);
61920+extern int gr_search_bind(struct socket * sock,
61921+ struct sockaddr_in * addr);
61922+extern int gr_search_listen(struct socket * sock);
61923+extern int gr_search_accept(struct socket * sock);
61924+extern int gr_search_socket(const int domain, const int type,
61925+ const int protocol);
61926+
61927+#endif
61928diff --git a/include/linux/hid.h b/include/linux/hid.h
61929index 3a95da6..51986f1 100644
61930--- a/include/linux/hid.h
61931+++ b/include/linux/hid.h
61932@@ -696,7 +696,7 @@ struct hid_ll_driver {
61933 unsigned int code, int value);
61934
61935 int (*parse)(struct hid_device *hdev);
61936-};
61937+} __no_const;
61938
61939 #define PM_HINT_FULLON 1<<5
61940 #define PM_HINT_NORMAL 1<<1
61941diff --git a/include/linux/highmem.h b/include/linux/highmem.h
61942index 3a93f73..b19d0b3 100644
61943--- a/include/linux/highmem.h
61944+++ b/include/linux/highmem.h
61945@@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
61946 kunmap_atomic(kaddr, KM_USER0);
61947 }
61948
61949+static inline void sanitize_highpage(struct page *page)
61950+{
61951+ void *kaddr;
61952+ unsigned long flags;
61953+
61954+ local_irq_save(flags);
61955+ kaddr = kmap_atomic(page, KM_CLEARPAGE);
61956+ clear_page(kaddr);
61957+ kunmap_atomic(kaddr, KM_CLEARPAGE);
61958+ local_irq_restore(flags);
61959+}
61960+
61961 static inline void zero_user_segments(struct page *page,
61962 unsigned start1, unsigned end1,
61963 unsigned start2, unsigned end2)
61964diff --git a/include/linux/i2c.h b/include/linux/i2c.h
61965index 8e25a91..551b161 100644
61966--- a/include/linux/i2c.h
61967+++ b/include/linux/i2c.h
61968@@ -364,6 +364,7 @@ struct i2c_algorithm {
61969 /* To determine what the adapter supports */
61970 u32 (*functionality) (struct i2c_adapter *);
61971 };
61972+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
61973
61974 /*
61975 * i2c_adapter is the structure used to identify a physical i2c bus along
61976diff --git a/include/linux/i2o.h b/include/linux/i2o.h
61977index a6deef4..c56a7f2 100644
61978--- a/include/linux/i2o.h
61979+++ b/include/linux/i2o.h
61980@@ -564,7 +564,7 @@ struct i2o_controller {
61981 struct i2o_device *exec; /* Executive */
61982 #if BITS_PER_LONG == 64
61983 spinlock_t context_list_lock; /* lock for context_list */
61984- atomic_t context_list_counter; /* needed for unique contexts */
61985+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
61986 struct list_head context_list; /* list of context id's
61987 and pointers */
61988 #endif
61989diff --git a/include/linux/if_team.h b/include/linux/if_team.h
61990index 58404b0..439ed95 100644
61991--- a/include/linux/if_team.h
61992+++ b/include/linux/if_team.h
61993@@ -64,6 +64,7 @@ struct team_mode_ops {
61994 void (*port_leave)(struct team *team, struct team_port *port);
61995 void (*port_change_mac)(struct team *team, struct team_port *port);
61996 };
61997+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
61998
61999 enum team_option_type {
62000 TEAM_OPTION_TYPE_U32,
62001@@ -112,7 +113,7 @@ struct team {
62002 struct list_head option_list;
62003
62004 const struct team_mode *mode;
62005- struct team_mode_ops ops;
62006+ team_mode_ops_no_const ops;
62007 long mode_priv[TEAM_MODE_PRIV_LONGS];
62008 };
62009
62010diff --git a/include/linux/init.h b/include/linux/init.h
62011index 6b95109..4aca62c 100644
62012--- a/include/linux/init.h
62013+++ b/include/linux/init.h
62014@@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
62015
62016 /* Each module must use one module_init(). */
62017 #define module_init(initfn) \
62018- static inline initcall_t __inittest(void) \
62019+ static inline __used initcall_t __inittest(void) \
62020 { return initfn; } \
62021 int init_module(void) __attribute__((alias(#initfn)));
62022
62023 /* This is only required if you want to be unloadable. */
62024 #define module_exit(exitfn) \
62025- static inline exitcall_t __exittest(void) \
62026+ static inline __used exitcall_t __exittest(void) \
62027 { return exitfn; } \
62028 void cleanup_module(void) __attribute__((alias(#exitfn)));
62029
62030diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62031index 9c66b1a..a3fdded 100644
62032--- a/include/linux/init_task.h
62033+++ b/include/linux/init_task.h
62034@@ -127,6 +127,12 @@ extern struct cred init_cred;
62035
62036 #define INIT_TASK_COMM "swapper"
62037
62038+#ifdef CONFIG_X86
62039+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62040+#else
62041+#define INIT_TASK_THREAD_INFO
62042+#endif
62043+
62044 /*
62045 * INIT_TASK is used to set up the first task table, touch at
62046 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62047@@ -165,6 +171,7 @@ extern struct cred init_cred;
62048 RCU_INIT_POINTER(.cred, &init_cred), \
62049 .comm = INIT_TASK_COMM, \
62050 .thread = INIT_THREAD, \
62051+ INIT_TASK_THREAD_INFO \
62052 .fs = &init_fs, \
62053 .files = &init_files, \
62054 .signal = &init_signals, \
62055diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62056index e6ca56d..8583707 100644
62057--- a/include/linux/intel-iommu.h
62058+++ b/include/linux/intel-iommu.h
62059@@ -296,7 +296,7 @@ struct iommu_flush {
62060 u8 fm, u64 type);
62061 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62062 unsigned int size_order, u64 type);
62063-};
62064+} __no_const;
62065
62066 enum {
62067 SR_DMAR_FECTL_REG,
62068diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62069index a64b00e..464d8bc 100644
62070--- a/include/linux/interrupt.h
62071+++ b/include/linux/interrupt.h
62072@@ -441,7 +441,7 @@ enum
62073 /* map softirq index to softirq name. update 'softirq_to_name' in
62074 * kernel/softirq.c when adding a new softirq.
62075 */
62076-extern char *softirq_to_name[NR_SOFTIRQS];
62077+extern const char * const softirq_to_name[NR_SOFTIRQS];
62078
62079 /* softirq mask and active fields moved to irq_cpustat_t in
62080 * asm/hardirq.h to get better cache usage. KAO
62081@@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62082
62083 struct softirq_action
62084 {
62085- void (*action)(struct softirq_action *);
62086+ void (*action)(void);
62087 };
62088
62089 asmlinkage void do_softirq(void);
62090 asmlinkage void __do_softirq(void);
62091-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62092+extern void open_softirq(int nr, void (*action)(void));
62093 extern void softirq_init(void);
62094 static inline void __raise_softirq_irqoff(unsigned int nr)
62095 {
62096diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62097index 3875719..4cd454c 100644
62098--- a/include/linux/kallsyms.h
62099+++ b/include/linux/kallsyms.h
62100@@ -15,7 +15,8 @@
62101
62102 struct module;
62103
62104-#ifdef CONFIG_KALLSYMS
62105+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62106+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62107 /* Lookup the address for a symbol. Returns 0 if not found. */
62108 unsigned long kallsyms_lookup_name(const char *name);
62109
62110@@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62111 /* Stupid that this does nothing, but I didn't create this mess. */
62112 #define __print_symbol(fmt, addr)
62113 #endif /*CONFIG_KALLSYMS*/
62114+#else /* when included by kallsyms.c, vsnprintf.c, or
62115+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62116+extern void __print_symbol(const char *fmt, unsigned long address);
62117+extern int sprint_backtrace(char *buffer, unsigned long address);
62118+extern int sprint_symbol(char *buffer, unsigned long address);
62119+const char *kallsyms_lookup(unsigned long addr,
62120+ unsigned long *symbolsize,
62121+ unsigned long *offset,
62122+ char **modname, char *namebuf);
62123+#endif
62124
62125 /* This macro allows us to keep printk typechecking */
62126 static __printf(1, 2)
62127diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62128index c4d2fc1..5df9c19 100644
62129--- a/include/linux/kgdb.h
62130+++ b/include/linux/kgdb.h
62131@@ -53,7 +53,7 @@ extern int kgdb_connected;
62132 extern int kgdb_io_module_registered;
62133
62134 extern atomic_t kgdb_setting_breakpoint;
62135-extern atomic_t kgdb_cpu_doing_single_step;
62136+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62137
62138 extern struct task_struct *kgdb_usethread;
62139 extern struct task_struct *kgdb_contthread;
62140@@ -252,7 +252,7 @@ struct kgdb_arch {
62141 void (*disable_hw_break)(struct pt_regs *regs);
62142 void (*remove_all_hw_break)(void);
62143 void (*correct_hw_break)(void);
62144-};
62145+} __do_const;
62146
62147 /**
62148 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62149@@ -277,7 +277,7 @@ struct kgdb_io {
62150 void (*pre_exception) (void);
62151 void (*post_exception) (void);
62152 int is_console;
62153-};
62154+} __do_const;
62155
62156 extern struct kgdb_arch arch_kgdb_ops;
62157
62158diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62159index 0fb48ef..1b680b2 100644
62160--- a/include/linux/kmod.h
62161+++ b/include/linux/kmod.h
62162@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62163 * usually useless though. */
62164 extern __printf(2, 3)
62165 int __request_module(bool wait, const char *name, ...);
62166+extern __printf(3, 4)
62167+int ___request_module(bool wait, char *param_name, const char *name, ...);
62168 #define request_module(mod...) __request_module(true, mod)
62169 #define request_module_nowait(mod...) __request_module(false, mod)
62170 #define try_then_request_module(x, mod...) \
62171diff --git a/include/linux/kref.h b/include/linux/kref.h
62172index 9c07dce..a92fa71 100644
62173--- a/include/linux/kref.h
62174+++ b/include/linux/kref.h
62175@@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62176 static inline int kref_sub(struct kref *kref, unsigned int count,
62177 void (*release)(struct kref *kref))
62178 {
62179- WARN_ON(release == NULL);
62180+ BUG_ON(release == NULL);
62181
62182 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62183 release(kref);
62184diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62185index 4c4e83d..695674f 100644
62186--- a/include/linux/kvm_host.h
62187+++ b/include/linux/kvm_host.h
62188@@ -326,7 +326,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62189 void vcpu_load(struct kvm_vcpu *vcpu);
62190 void vcpu_put(struct kvm_vcpu *vcpu);
62191
62192-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62193+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62194 struct module *module);
62195 void kvm_exit(void);
62196
62197@@ -485,7 +485,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62198 struct kvm_guest_debug *dbg);
62199 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62200
62201-int kvm_arch_init(void *opaque);
62202+int kvm_arch_init(const void *opaque);
62203 void kvm_arch_exit(void);
62204
62205 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62206diff --git a/include/linux/libata.h b/include/linux/libata.h
62207index cafc09a..d7e7829 100644
62208--- a/include/linux/libata.h
62209+++ b/include/linux/libata.h
62210@@ -909,7 +909,7 @@ struct ata_port_operations {
62211 * fields must be pointers.
62212 */
62213 const struct ata_port_operations *inherits;
62214-};
62215+} __do_const;
62216
62217 struct ata_port_info {
62218 unsigned long flags;
62219diff --git a/include/linux/mca.h b/include/linux/mca.h
62220index 3797270..7765ede 100644
62221--- a/include/linux/mca.h
62222+++ b/include/linux/mca.h
62223@@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
62224 int region);
62225 void * (*mca_transform_memory)(struct mca_device *,
62226 void *memory);
62227-};
62228+} __no_const;
62229
62230 struct mca_bus {
62231 u64 default_dma_mask;
62232diff --git a/include/linux/memory.h b/include/linux/memory.h
62233index 1ac7f6e..a5794d0 100644
62234--- a/include/linux/memory.h
62235+++ b/include/linux/memory.h
62236@@ -143,7 +143,7 @@ struct memory_accessor {
62237 size_t count);
62238 ssize_t (*write)(struct memory_accessor *, const char *buf,
62239 off_t offset, size_t count);
62240-};
62241+} __no_const;
62242
62243 /*
62244 * Kernel text modification mutex, used for code patching. Users of this lock
62245diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62246index 9970337..9444122 100644
62247--- a/include/linux/mfd/abx500.h
62248+++ b/include/linux/mfd/abx500.h
62249@@ -188,6 +188,7 @@ struct abx500_ops {
62250 int (*event_registers_startup_state_get) (struct device *, u8 *);
62251 int (*startup_irq_enabled) (struct device *, unsigned int);
62252 };
62253+typedef struct abx500_ops __no_const abx500_ops_no_const;
62254
62255 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62256 void abx500_remove_ops(struct device *dev);
62257diff --git a/include/linux/mm.h b/include/linux/mm.h
62258index 17b27cd..baea141 100644
62259--- a/include/linux/mm.h
62260+++ b/include/linux/mm.h
62261@@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
62262
62263 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62264 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62265+
62266+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62267+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62268+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62269+#else
62270 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62271+#endif
62272+
62273 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62274 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62275
62276@@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
62277 int set_page_dirty_lock(struct page *page);
62278 int clear_page_dirty_for_io(struct page *page);
62279
62280-/* Is the vma a continuation of the stack vma above it? */
62281-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62282-{
62283- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62284-}
62285-
62286-static inline int stack_guard_page_start(struct vm_area_struct *vma,
62287- unsigned long addr)
62288-{
62289- return (vma->vm_flags & VM_GROWSDOWN) &&
62290- (vma->vm_start == addr) &&
62291- !vma_growsdown(vma->vm_prev, addr);
62292-}
62293-
62294-/* Is the vma a continuation of the stack vma below it? */
62295-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62296-{
62297- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62298-}
62299-
62300-static inline int stack_guard_page_end(struct vm_area_struct *vma,
62301- unsigned long addr)
62302-{
62303- return (vma->vm_flags & VM_GROWSUP) &&
62304- (vma->vm_end == addr) &&
62305- !vma_growsup(vma->vm_next, addr);
62306-}
62307-
62308 extern unsigned long move_page_tables(struct vm_area_struct *vma,
62309 unsigned long old_addr, struct vm_area_struct *new_vma,
62310 unsigned long new_addr, unsigned long len);
62311@@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
62312 }
62313 #endif
62314
62315+#ifdef CONFIG_MMU
62316+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62317+#else
62318+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62319+{
62320+ return __pgprot(0);
62321+}
62322+#endif
62323+
62324 int vma_wants_writenotify(struct vm_area_struct *vma);
62325
62326 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62327@@ -1152,8 +1140,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
62328 {
62329 return 0;
62330 }
62331+
62332+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
62333+ unsigned long address)
62334+{
62335+ return 0;
62336+}
62337 #else
62338 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62339+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62340 #endif
62341
62342 #ifdef __PAGETABLE_PMD_FOLDED
62343@@ -1162,8 +1157,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
62344 {
62345 return 0;
62346 }
62347+
62348+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
62349+ unsigned long address)
62350+{
62351+ return 0;
62352+}
62353 #else
62354 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
62355+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
62356 #endif
62357
62358 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
62359@@ -1181,11 +1183,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
62360 NULL: pud_offset(pgd, address);
62361 }
62362
62363+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
62364+{
62365+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
62366+ NULL: pud_offset(pgd, address);
62367+}
62368+
62369 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
62370 {
62371 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
62372 NULL: pmd_offset(pud, address);
62373 }
62374+
62375+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
62376+{
62377+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
62378+ NULL: pmd_offset(pud, address);
62379+}
62380 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
62381
62382 #if USE_SPLIT_PTLOCKS
62383@@ -1409,6 +1423,7 @@ out:
62384 }
62385
62386 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62387+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62388
62389 extern unsigned long do_brk(unsigned long, unsigned long);
62390
62391@@ -1466,6 +1481,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62392 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62393 struct vm_area_struct **pprev);
62394
62395+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62396+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62397+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62398+
62399 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62400 NULL if none. Assume start_addr < end_addr. */
62401 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62402@@ -1494,15 +1513,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62403 return vma;
62404 }
62405
62406-#ifdef CONFIG_MMU
62407-pgprot_t vm_get_page_prot(unsigned long vm_flags);
62408-#else
62409-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62410-{
62411- return __pgprot(0);
62412-}
62413-#endif
62414-
62415 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62416 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62417 unsigned long pfn, unsigned long size, pgprot_t);
62418@@ -1606,7 +1616,7 @@ extern int unpoison_memory(unsigned long pfn);
62419 extern int sysctl_memory_failure_early_kill;
62420 extern int sysctl_memory_failure_recovery;
62421 extern void shake_page(struct page *p, int access);
62422-extern atomic_long_t mce_bad_pages;
62423+extern atomic_long_unchecked_t mce_bad_pages;
62424 extern int soft_offline_page(struct page *page, int flags);
62425
62426 extern void dump_page(struct page *page);
62427@@ -1637,5 +1647,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62428 static inline bool page_is_guard(struct page *page) { return false; }
62429 #endif /* CONFIG_DEBUG_PAGEALLOC */
62430
62431+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62432+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62433+#else
62434+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62435+#endif
62436+
62437 #endif /* __KERNEL__ */
62438 #endif /* _LINUX_MM_H */
62439diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62440index 3cc3062..efeaeb7 100644
62441--- a/include/linux/mm_types.h
62442+++ b/include/linux/mm_types.h
62443@@ -252,6 +252,8 @@ struct vm_area_struct {
62444 #ifdef CONFIG_NUMA
62445 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62446 #endif
62447+
62448+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62449 };
62450
62451 struct core_thread {
62452@@ -326,7 +328,7 @@ struct mm_struct {
62453 unsigned long def_flags;
62454 unsigned long nr_ptes; /* Page table pages */
62455 unsigned long start_code, end_code, start_data, end_data;
62456- unsigned long start_brk, brk, start_stack;
62457+ unsigned long brk_gap, start_brk, brk, start_stack;
62458 unsigned long arg_start, arg_end, env_start, env_end;
62459
62460 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62461@@ -388,6 +390,24 @@ struct mm_struct {
62462 #ifdef CONFIG_CPUMASK_OFFSTACK
62463 struct cpumask cpumask_allocation;
62464 #endif
62465+
62466+#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)
62467+ unsigned long pax_flags;
62468+#endif
62469+
62470+#ifdef CONFIG_PAX_DLRESOLVE
62471+ unsigned long call_dl_resolve;
62472+#endif
62473+
62474+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62475+ unsigned long call_syscall;
62476+#endif
62477+
62478+#ifdef CONFIG_PAX_ASLR
62479+ unsigned long delta_mmap; /* randomized offset */
62480+ unsigned long delta_stack; /* randomized offset */
62481+#endif
62482+
62483 };
62484
62485 static inline void mm_init_cpumask(struct mm_struct *mm)
62486diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62487index 1d1b1e1..2a13c78 100644
62488--- a/include/linux/mmu_notifier.h
62489+++ b/include/linux/mmu_notifier.h
62490@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62491 */
62492 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62493 ({ \
62494- pte_t __pte; \
62495+ pte_t ___pte; \
62496 struct vm_area_struct *___vma = __vma; \
62497 unsigned long ___address = __address; \
62498- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62499+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62500 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62501- __pte; \
62502+ ___pte; \
62503 })
62504
62505 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62506diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62507index 650ba2f..af0a58c 100644
62508--- a/include/linux/mmzone.h
62509+++ b/include/linux/mmzone.h
62510@@ -379,7 +379,7 @@ struct zone {
62511 unsigned long flags; /* zone flags, see below */
62512
62513 /* Zone statistics */
62514- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62515+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62516
62517 /*
62518 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62519diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62520index 83ac071..2656e0e 100644
62521--- a/include/linux/mod_devicetable.h
62522+++ b/include/linux/mod_devicetable.h
62523@@ -12,7 +12,7 @@
62524 typedef unsigned long kernel_ulong_t;
62525 #endif
62526
62527-#define PCI_ANY_ID (~0)
62528+#define PCI_ANY_ID ((__u16)~0)
62529
62530 struct pci_device_id {
62531 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62532@@ -131,7 +131,7 @@ struct usb_device_id {
62533 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62534 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62535
62536-#define HID_ANY_ID (~0)
62537+#define HID_ANY_ID (~0U)
62538
62539 struct hid_device_id {
62540 __u16 bus;
62541diff --git a/include/linux/module.h b/include/linux/module.h
62542index 4598bf0..e069d7f 100644
62543--- a/include/linux/module.h
62544+++ b/include/linux/module.h
62545@@ -17,6 +17,7 @@
62546 #include <linux/moduleparam.h>
62547 #include <linux/tracepoint.h>
62548 #include <linux/export.h>
62549+#include <linux/fs.h>
62550
62551 #include <linux/percpu.h>
62552 #include <asm/module.h>
62553@@ -275,19 +276,16 @@ struct module
62554 int (*init)(void);
62555
62556 /* If this is non-NULL, vfree after init() returns */
62557- void *module_init;
62558+ void *module_init_rx, *module_init_rw;
62559
62560 /* Here is the actual code + data, vfree'd on unload. */
62561- void *module_core;
62562+ void *module_core_rx, *module_core_rw;
62563
62564 /* Here are the sizes of the init and core sections */
62565- unsigned int init_size, core_size;
62566+ unsigned int init_size_rw, core_size_rw;
62567
62568 /* The size of the executable code in each section. */
62569- unsigned int init_text_size, core_text_size;
62570-
62571- /* Size of RO sections of the module (text+rodata) */
62572- unsigned int init_ro_size, core_ro_size;
62573+ unsigned int init_size_rx, core_size_rx;
62574
62575 /* Arch-specific module values */
62576 struct mod_arch_specific arch;
62577@@ -343,6 +341,10 @@ struct module
62578 #ifdef CONFIG_EVENT_TRACING
62579 struct ftrace_event_call **trace_events;
62580 unsigned int num_trace_events;
62581+ struct file_operations trace_id;
62582+ struct file_operations trace_enable;
62583+ struct file_operations trace_format;
62584+ struct file_operations trace_filter;
62585 #endif
62586 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62587 unsigned int num_ftrace_callsites;
62588@@ -390,16 +392,46 @@ bool is_module_address(unsigned long addr);
62589 bool is_module_percpu_address(unsigned long addr);
62590 bool is_module_text_address(unsigned long addr);
62591
62592+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62593+{
62594+
62595+#ifdef CONFIG_PAX_KERNEXEC
62596+ if (ktla_ktva(addr) >= (unsigned long)start &&
62597+ ktla_ktva(addr) < (unsigned long)start + size)
62598+ return 1;
62599+#endif
62600+
62601+ return ((void *)addr >= start && (void *)addr < start + size);
62602+}
62603+
62604+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62605+{
62606+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62607+}
62608+
62609+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62610+{
62611+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62612+}
62613+
62614+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62615+{
62616+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62617+}
62618+
62619+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62620+{
62621+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62622+}
62623+
62624 static inline int within_module_core(unsigned long addr, struct module *mod)
62625 {
62626- return (unsigned long)mod->module_core <= addr &&
62627- addr < (unsigned long)mod->module_core + mod->core_size;
62628+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62629 }
62630
62631 static inline int within_module_init(unsigned long addr, struct module *mod)
62632 {
62633- return (unsigned long)mod->module_init <= addr &&
62634- addr < (unsigned long)mod->module_init + mod->init_size;
62635+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62636 }
62637
62638 /* Search for module by name: must hold module_mutex. */
62639diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62640index b2be02e..0a61daa 100644
62641--- a/include/linux/moduleloader.h
62642+++ b/include/linux/moduleloader.h
62643@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62644 sections. Returns NULL on failure. */
62645 void *module_alloc(unsigned long size);
62646
62647+#ifdef CONFIG_PAX_KERNEXEC
62648+void *module_alloc_exec(unsigned long size) __size_overflow(1);
62649+#else
62650+#define module_alloc_exec(x) module_alloc(x)
62651+#endif
62652+
62653 /* Free memory returned from module_alloc. */
62654 void module_free(struct module *mod, void *module_region);
62655
62656+#ifdef CONFIG_PAX_KERNEXEC
62657+void module_free_exec(struct module *mod, void *module_region);
62658+#else
62659+#define module_free_exec(x, y) module_free((x), (y))
62660+#endif
62661+
62662 /* Apply the given relocation to the (simplified) ELF. Return -error
62663 or 0. */
62664 int apply_relocate(Elf_Shdr *sechdrs,
62665diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62666index c47f4d6..23f9bdb 100644
62667--- a/include/linux/moduleparam.h
62668+++ b/include/linux/moduleparam.h
62669@@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
62670 * @len is usually just sizeof(string).
62671 */
62672 #define module_param_string(name, string, len, perm) \
62673- static const struct kparam_string __param_string_##name \
62674+ static const struct kparam_string __param_string_##name __used \
62675 = { len, string }; \
62676 __module_param_call(MODULE_PARAM_PREFIX, name, \
62677 &param_ops_string, \
62678@@ -396,7 +396,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62679 */
62680 #define module_param_array_named(name, array, type, nump, perm) \
62681 param_check_##type(name, &(array)[0]); \
62682- static const struct kparam_array __param_arr_##name \
62683+ static const struct kparam_array __param_arr_##name __used \
62684 = { .max = ARRAY_SIZE(array), .num = nump, \
62685 .ops = &param_ops_##type, \
62686 .elemsize = sizeof(array[0]), .elem = array }; \
62687diff --git a/include/linux/namei.h b/include/linux/namei.h
62688index ffc0213..2c1f2cb 100644
62689--- a/include/linux/namei.h
62690+++ b/include/linux/namei.h
62691@@ -24,7 +24,7 @@ struct nameidata {
62692 unsigned seq;
62693 int last_type;
62694 unsigned depth;
62695- char *saved_names[MAX_NESTED_LINKS + 1];
62696+ const char *saved_names[MAX_NESTED_LINKS + 1];
62697
62698 /* Intent data */
62699 union {
62700@@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62701 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62702 extern void unlock_rename(struct dentry *, struct dentry *);
62703
62704-static inline void nd_set_link(struct nameidata *nd, char *path)
62705+static inline void nd_set_link(struct nameidata *nd, const char *path)
62706 {
62707 nd->saved_names[nd->depth] = path;
62708 }
62709
62710-static inline char *nd_get_link(struct nameidata *nd)
62711+static inline const char *nd_get_link(const struct nameidata *nd)
62712 {
62713 return nd->saved_names[nd->depth];
62714 }
62715diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62716index 7e472b7..212d381 100644
62717--- a/include/linux/netdevice.h
62718+++ b/include/linux/netdevice.h
62719@@ -1002,6 +1002,7 @@ struct net_device_ops {
62720 int (*ndo_neigh_construct)(struct neighbour *n);
62721 void (*ndo_neigh_destroy)(struct neighbour *n);
62722 };
62723+typedef struct net_device_ops __no_const net_device_ops_no_const;
62724
62725 /*
62726 * The DEVICE structure.
62727@@ -1063,7 +1064,7 @@ struct net_device {
62728 int iflink;
62729
62730 struct net_device_stats stats;
62731- atomic_long_t rx_dropped; /* dropped packets by core network
62732+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
62733 * Do not use this in drivers.
62734 */
62735
62736diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62737new file mode 100644
62738index 0000000..33f4af8
62739--- /dev/null
62740+++ b/include/linux/netfilter/xt_gradm.h
62741@@ -0,0 +1,9 @@
62742+#ifndef _LINUX_NETFILTER_XT_GRADM_H
62743+#define _LINUX_NETFILTER_XT_GRADM_H 1
62744+
62745+struct xt_gradm_mtinfo {
62746+ __u16 flags;
62747+ __u16 invflags;
62748+};
62749+
62750+#endif
62751diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
62752index c65a18a..0c05f3a 100644
62753--- a/include/linux/of_pdt.h
62754+++ b/include/linux/of_pdt.h
62755@@ -32,7 +32,7 @@ struct of_pdt_ops {
62756
62757 /* return 0 on success; fill in 'len' with number of bytes in path */
62758 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
62759-};
62760+} __no_const;
62761
62762 extern void *prom_early_alloc(unsigned long size);
62763
62764diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
62765index a4c5624..79d6d88 100644
62766--- a/include/linux/oprofile.h
62767+++ b/include/linux/oprofile.h
62768@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
62769 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
62770 char const * name, ulong * val);
62771
62772-/** Create a file for read-only access to an atomic_t. */
62773+/** Create a file for read-only access to an atomic_unchecked_t. */
62774 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
62775- char const * name, atomic_t * val);
62776+ char const * name, atomic_unchecked_t * val);
62777
62778 /** create a directory */
62779 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
62780diff --git a/include/linux/padata.h b/include/linux/padata.h
62781index 4633b2f..988bc08 100644
62782--- a/include/linux/padata.h
62783+++ b/include/linux/padata.h
62784@@ -129,7 +129,7 @@ struct parallel_data {
62785 struct padata_instance *pinst;
62786 struct padata_parallel_queue __percpu *pqueue;
62787 struct padata_serial_queue __percpu *squeue;
62788- atomic_t seq_nr;
62789+ atomic_unchecked_t seq_nr;
62790 atomic_t reorder_objects;
62791 atomic_t refcnt;
62792 unsigned int max_seq_nr;
62793diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
62794index abb2776..d8b8e15 100644
62795--- a/include/linux/perf_event.h
62796+++ b/include/linux/perf_event.h
62797@@ -750,8 +750,8 @@ struct perf_event {
62798
62799 enum perf_event_active_state state;
62800 unsigned int attach_state;
62801- local64_t count;
62802- atomic64_t child_count;
62803+ local64_t count; /* PaX: fix it one day */
62804+ atomic64_unchecked_t child_count;
62805
62806 /*
62807 * These are the total time in nanoseconds that the event
62808@@ -802,8 +802,8 @@ struct perf_event {
62809 * These accumulate total time (in nanoseconds) that children
62810 * events have been enabled and running, respectively.
62811 */
62812- atomic64_t child_total_time_enabled;
62813- atomic64_t child_total_time_running;
62814+ atomic64_unchecked_t child_total_time_enabled;
62815+ atomic64_unchecked_t child_total_time_running;
62816
62817 /*
62818 * Protect attach/detach and child_list:
62819diff --git a/include/linux/personality.h b/include/linux/personality.h
62820index 8fc7dd1a..c19d89e 100644
62821--- a/include/linux/personality.h
62822+++ b/include/linux/personality.h
62823@@ -44,6 +44,7 @@ enum {
62824 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
62825 ADDR_NO_RANDOMIZE | \
62826 ADDR_COMPAT_LAYOUT | \
62827+ ADDR_LIMIT_3GB | \
62828 MMAP_PAGE_ZERO)
62829
62830 /*
62831diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
62832index 0072a53..c5dcca5 100644
62833--- a/include/linux/pipe_fs_i.h
62834+++ b/include/linux/pipe_fs_i.h
62835@@ -47,9 +47,9 @@ struct pipe_buffer {
62836 struct pipe_inode_info {
62837 wait_queue_head_t wait;
62838 unsigned int nrbufs, curbuf, buffers;
62839- unsigned int readers;
62840- unsigned int writers;
62841- unsigned int waiting_writers;
62842+ atomic_t readers;
62843+ atomic_t writers;
62844+ atomic_t waiting_writers;
62845 unsigned int r_counter;
62846 unsigned int w_counter;
62847 struct page *tmp_page;
62848diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
62849index 609daae..5392427 100644
62850--- a/include/linux/pm_runtime.h
62851+++ b/include/linux/pm_runtime.h
62852@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
62853
62854 static inline void pm_runtime_mark_last_busy(struct device *dev)
62855 {
62856- ACCESS_ONCE(dev->power.last_busy) = jiffies;
62857+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
62858 }
62859
62860 #else /* !CONFIG_PM_RUNTIME */
62861diff --git a/include/linux/poison.h b/include/linux/poison.h
62862index 2110a81..13a11bb 100644
62863--- a/include/linux/poison.h
62864+++ b/include/linux/poison.h
62865@@ -19,8 +19,8 @@
62866 * under normal circumstances, used to verify that nobody uses
62867 * non-initialized list entries.
62868 */
62869-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
62870-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
62871+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
62872+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
62873
62874 /********** include/linux/timer.h **********/
62875 /*
62876diff --git a/include/linux/preempt.h b/include/linux/preempt.h
62877index 58969b2..ead129b 100644
62878--- a/include/linux/preempt.h
62879+++ b/include/linux/preempt.h
62880@@ -123,7 +123,7 @@ struct preempt_ops {
62881 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
62882 void (*sched_out)(struct preempt_notifier *notifier,
62883 struct task_struct *next);
62884-};
62885+} __no_const;
62886
62887 /**
62888 * preempt_notifier - key for installing preemption notifiers
62889diff --git a/include/linux/printk.h b/include/linux/printk.h
62890index f0e22f7..82dd544 100644
62891--- a/include/linux/printk.h
62892+++ b/include/linux/printk.h
62893@@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
62894 extern int printk_needs_cpu(int cpu);
62895 extern void printk_tick(void);
62896
62897+extern int kptr_restrict;
62898+
62899 #ifdef CONFIG_PRINTK
62900 asmlinkage __printf(1, 0)
62901 int vprintk(const char *fmt, va_list args);
62902@@ -112,7 +114,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
62903
62904 extern int printk_delay_msec;
62905 extern int dmesg_restrict;
62906-extern int kptr_restrict;
62907
62908 void log_buf_kexec_setup(void);
62909 void __init setup_log_buf(int early);
62910diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
62911index 85c5073..51fac8b 100644
62912--- a/include/linux/proc_fs.h
62913+++ b/include/linux/proc_fs.h
62914@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
62915 return proc_create_data(name, mode, parent, proc_fops, NULL);
62916 }
62917
62918+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
62919+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
62920+{
62921+#ifdef CONFIG_GRKERNSEC_PROC_USER
62922+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
62923+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62924+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
62925+#else
62926+ return proc_create_data(name, mode, parent, proc_fops, NULL);
62927+#endif
62928+}
62929+
62930 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
62931 umode_t mode, struct proc_dir_entry *base,
62932 read_proc_t *read_proc, void * data)
62933@@ -258,7 +270,7 @@ union proc_op {
62934 int (*proc_show)(struct seq_file *m,
62935 struct pid_namespace *ns, struct pid *pid,
62936 struct task_struct *task);
62937-};
62938+} __no_const;
62939
62940 struct ctl_table_header;
62941 struct ctl_table;
62942diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
62943index c2f1f6a..6fdb196 100644
62944--- a/include/linux/ptrace.h
62945+++ b/include/linux/ptrace.h
62946@@ -199,9 +199,10 @@ static inline void ptrace_event(int event, unsigned long message)
62947 if (unlikely(ptrace_event_enabled(current, event))) {
62948 current->ptrace_message = message;
62949 ptrace_notify((event << 8) | SIGTRAP);
62950- } else if (event == PTRACE_EVENT_EXEC && unlikely(current->ptrace)) {
62951+ } else if (event == PTRACE_EVENT_EXEC) {
62952 /* legacy EXEC report via SIGTRAP */
62953- send_sig(SIGTRAP, current, 0);
62954+ if ((current->ptrace & (PT_PTRACED|PT_SEIZED)) == PT_PTRACED)
62955+ send_sig(SIGTRAP, current, 0);
62956 }
62957 }
62958
62959diff --git a/include/linux/random.h b/include/linux/random.h
62960index 8f74538..02a1012 100644
62961--- a/include/linux/random.h
62962+++ b/include/linux/random.h
62963@@ -69,12 +69,17 @@ void srandom32(u32 seed);
62964
62965 u32 prandom32(struct rnd_state *);
62966
62967+static inline unsigned long pax_get_random_long(void)
62968+{
62969+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
62970+}
62971+
62972 /*
62973 * Handle minimum values for seeds
62974 */
62975 static inline u32 __seed(u32 x, u32 m)
62976 {
62977- return (x < m) ? x + m : x;
62978+ return (x <= m) ? x + m + 1 : x;
62979 }
62980
62981 /**
62982diff --git a/include/linux/reboot.h b/include/linux/reboot.h
62983index e0879a7..a12f962 100644
62984--- a/include/linux/reboot.h
62985+++ b/include/linux/reboot.h
62986@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
62987 * Architecture-specific implementations of sys_reboot commands.
62988 */
62989
62990-extern void machine_restart(char *cmd);
62991-extern void machine_halt(void);
62992-extern void machine_power_off(void);
62993+extern void machine_restart(char *cmd) __noreturn;
62994+extern void machine_halt(void) __noreturn;
62995+extern void machine_power_off(void) __noreturn;
62996
62997 extern void machine_shutdown(void);
62998 struct pt_regs;
62999@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63000 */
63001
63002 extern void kernel_restart_prepare(char *cmd);
63003-extern void kernel_restart(char *cmd);
63004-extern void kernel_halt(void);
63005-extern void kernel_power_off(void);
63006+extern void kernel_restart(char *cmd) __noreturn;
63007+extern void kernel_halt(void) __noreturn;
63008+extern void kernel_power_off(void) __noreturn;
63009
63010 extern int C_A_D; /* for sysctl */
63011 void ctrl_alt_del(void);
63012@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63013 * Emergency restart, callable from an interrupt handler.
63014 */
63015
63016-extern void emergency_restart(void);
63017+extern void emergency_restart(void) __noreturn;
63018 #include <asm/emergency-restart.h>
63019
63020 #endif
63021diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
63022index 2213ddc..650212a 100644
63023--- a/include/linux/reiserfs_fs.h
63024+++ b/include/linux/reiserfs_fs.h
63025@@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
63026 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
63027
63028 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
63029-#define get_generation(s) atomic_read (&fs_generation(s))
63030+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
63031 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
63032 #define __fs_changed(gen,s) (gen != get_generation (s))
63033 #define fs_changed(gen,s) \
63034diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
63035index 8c9e85c..1698e9a 100644
63036--- a/include/linux/reiserfs_fs_sb.h
63037+++ b/include/linux/reiserfs_fs_sb.h
63038@@ -386,7 +386,7 @@ struct reiserfs_sb_info {
63039 /* Comment? -Hans */
63040 wait_queue_head_t s_wait;
63041 /* To be obsoleted soon by per buffer seals.. -Hans */
63042- atomic_t s_generation_counter; // increased by one every time the
63043+ atomic_unchecked_t s_generation_counter; // increased by one every time the
63044 // tree gets re-balanced
63045 unsigned long s_properties; /* File system properties. Currently holds
63046 on-disk FS format */
63047diff --git a/include/linux/relay.h b/include/linux/relay.h
63048index a822fd7..62b70f6 100644
63049--- a/include/linux/relay.h
63050+++ b/include/linux/relay.h
63051@@ -159,7 +159,7 @@ struct rchan_callbacks
63052 * The callback should return 0 if successful, negative if not.
63053 */
63054 int (*remove_buf_file)(struct dentry *dentry);
63055-};
63056+} __no_const;
63057
63058 /*
63059 * CONFIG_RELAY kernel API, kernel/relay.c
63060diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63061index c6c6084..5bf1212 100644
63062--- a/include/linux/rfkill.h
63063+++ b/include/linux/rfkill.h
63064@@ -147,6 +147,7 @@ struct rfkill_ops {
63065 void (*query)(struct rfkill *rfkill, void *data);
63066 int (*set_block)(void *data, bool blocked);
63067 };
63068+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63069
63070 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63071 /**
63072diff --git a/include/linux/rio.h b/include/linux/rio.h
63073index 4d50611..c6858a2 100644
63074--- a/include/linux/rio.h
63075+++ b/include/linux/rio.h
63076@@ -315,7 +315,7 @@ struct rio_ops {
63077 int mbox, void *buffer, size_t len);
63078 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63079 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63080-};
63081+} __no_const;
63082
63083 #define RIO_RESOURCE_MEM 0x00000100
63084 #define RIO_RESOURCE_DOORBELL 0x00000200
63085diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63086index 1cdd62a..e399f0d 100644
63087--- a/include/linux/rmap.h
63088+++ b/include/linux/rmap.h
63089@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63090 void anon_vma_init(void); /* create anon_vma_cachep */
63091 int anon_vma_prepare(struct vm_area_struct *);
63092 void unlink_anon_vmas(struct vm_area_struct *);
63093-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63094+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63095 void anon_vma_moveto_tail(struct vm_area_struct *);
63096-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63097+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63098 void __anon_vma_link(struct vm_area_struct *);
63099
63100 static inline void anon_vma_merge(struct vm_area_struct *vma,
63101diff --git a/include/linux/sched.h b/include/linux/sched.h
63102index 0657368..765f70f 100644
63103--- a/include/linux/sched.h
63104+++ b/include/linux/sched.h
63105@@ -101,6 +101,7 @@ struct bio_list;
63106 struct fs_struct;
63107 struct perf_event_context;
63108 struct blk_plug;
63109+struct linux_binprm;
63110
63111 /*
63112 * List of flags we want to share for kernel threads,
63113@@ -382,10 +383,13 @@ struct user_namespace;
63114 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63115
63116 extern int sysctl_max_map_count;
63117+extern unsigned long sysctl_heap_stack_gap;
63118
63119 #include <linux/aio.h>
63120
63121 #ifdef CONFIG_MMU
63122+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63123+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63124 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63125 extern unsigned long
63126 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63127@@ -631,6 +635,17 @@ struct signal_struct {
63128 #ifdef CONFIG_TASKSTATS
63129 struct taskstats *stats;
63130 #endif
63131+
63132+#ifdef CONFIG_GRKERNSEC
63133+ u32 curr_ip;
63134+ u32 saved_ip;
63135+ u32 gr_saddr;
63136+ u32 gr_daddr;
63137+ u16 gr_sport;
63138+ u16 gr_dport;
63139+ u8 used_accept:1;
63140+#endif
63141+
63142 #ifdef CONFIG_AUDIT
63143 unsigned audit_tty;
63144 struct tty_audit_buf *tty_audit_buf;
63145@@ -714,6 +729,11 @@ struct user_struct {
63146 struct key *session_keyring; /* UID's default session keyring */
63147 #endif
63148
63149+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63150+ unsigned int banned;
63151+ unsigned long ban_expires;
63152+#endif
63153+
63154 /* Hash table maintenance information */
63155 struct hlist_node uidhash_node;
63156 uid_t uid;
63157@@ -1354,8 +1374,8 @@ struct task_struct {
63158 struct list_head thread_group;
63159
63160 struct completion *vfork_done; /* for vfork() */
63161- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63162- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63163+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63164+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63165
63166 cputime_t utime, stime, utimescaled, stimescaled;
63167 cputime_t gtime;
63168@@ -1371,13 +1391,6 @@ struct task_struct {
63169 struct task_cputime cputime_expires;
63170 struct list_head cpu_timers[3];
63171
63172-/* process credentials */
63173- const struct cred __rcu *real_cred; /* objective and real subjective task
63174- * credentials (COW) */
63175- const struct cred __rcu *cred; /* effective (overridable) subjective task
63176- * credentials (COW) */
63177- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63178-
63179 char comm[TASK_COMM_LEN]; /* executable name excluding path
63180 - access with [gs]et_task_comm (which lock
63181 it with task_lock())
63182@@ -1394,8 +1407,16 @@ struct task_struct {
63183 #endif
63184 /* CPU-specific state of this task */
63185 struct thread_struct thread;
63186+/* thread_info moved to task_struct */
63187+#ifdef CONFIG_X86
63188+ struct thread_info tinfo;
63189+#endif
63190 /* filesystem information */
63191 struct fs_struct *fs;
63192+
63193+ const struct cred __rcu *cred; /* effective (overridable) subjective task
63194+ * credentials (COW) */
63195+
63196 /* open file information */
63197 struct files_struct *files;
63198 /* namespaces */
63199@@ -1442,6 +1463,11 @@ struct task_struct {
63200 struct rt_mutex_waiter *pi_blocked_on;
63201 #endif
63202
63203+/* process credentials */
63204+ const struct cred __rcu *real_cred; /* objective and real subjective task
63205+ * credentials (COW) */
63206+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63207+
63208 #ifdef CONFIG_DEBUG_MUTEXES
63209 /* mutex deadlock detection */
63210 struct mutex_waiter *blocked_on;
63211@@ -1558,6 +1584,27 @@ struct task_struct {
63212 unsigned long default_timer_slack_ns;
63213
63214 struct list_head *scm_work_list;
63215+
63216+#ifdef CONFIG_GRKERNSEC
63217+ /* grsecurity */
63218+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63219+ u64 exec_id;
63220+#endif
63221+#ifdef CONFIG_GRKERNSEC_SETXID
63222+ const struct cred *delayed_cred;
63223+#endif
63224+ struct dentry *gr_chroot_dentry;
63225+ struct acl_subject_label *acl;
63226+ struct acl_role_label *role;
63227+ struct file *exec_file;
63228+ u16 acl_role_id;
63229+ /* is this the task that authenticated to the special role */
63230+ u8 acl_sp_role;
63231+ u8 is_writable;
63232+ u8 brute;
63233+ u8 gr_is_chrooted;
63234+#endif
63235+
63236 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63237 /* Index of current stored address in ret_stack */
63238 int curr_ret_stack;
63239@@ -1592,6 +1639,51 @@ struct task_struct {
63240 #endif
63241 };
63242
63243+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63244+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63245+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63246+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63247+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63248+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63249+
63250+#ifdef CONFIG_PAX_SOFTMODE
63251+extern int pax_softmode;
63252+#endif
63253+
63254+extern int pax_check_flags(unsigned long *);
63255+
63256+/* if tsk != current then task_lock must be held on it */
63257+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63258+static inline unsigned long pax_get_flags(struct task_struct *tsk)
63259+{
63260+ if (likely(tsk->mm))
63261+ return tsk->mm->pax_flags;
63262+ else
63263+ return 0UL;
63264+}
63265+
63266+/* if tsk != current then task_lock must be held on it */
63267+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63268+{
63269+ if (likely(tsk->mm)) {
63270+ tsk->mm->pax_flags = flags;
63271+ return 0;
63272+ }
63273+ return -EINVAL;
63274+}
63275+#endif
63276+
63277+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63278+extern void pax_set_initial_flags(struct linux_binprm *bprm);
63279+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63280+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63281+#endif
63282+
63283+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63284+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63285+extern void pax_report_refcount_overflow(struct pt_regs *regs);
63286+extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
63287+
63288 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63289 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63290
63291@@ -2104,7 +2196,9 @@ void yield(void);
63292 extern struct exec_domain default_exec_domain;
63293
63294 union thread_union {
63295+#ifndef CONFIG_X86
63296 struct thread_info thread_info;
63297+#endif
63298 unsigned long stack[THREAD_SIZE/sizeof(long)];
63299 };
63300
63301@@ -2137,6 +2231,7 @@ extern struct pid_namespace init_pid_ns;
63302 */
63303
63304 extern struct task_struct *find_task_by_vpid(pid_t nr);
63305+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63306 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63307 struct pid_namespace *ns);
63308
63309@@ -2280,7 +2375,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63310 extern void exit_itimers(struct signal_struct *);
63311 extern void flush_itimer_signals(void);
63312
63313-extern void do_group_exit(int);
63314+extern __noreturn void do_group_exit(int);
63315
63316 extern void daemonize(const char *, ...);
63317 extern int allow_signal(int);
63318@@ -2478,13 +2573,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63319
63320 #endif
63321
63322-static inline int object_is_on_stack(void *obj)
63323+static inline int object_starts_on_stack(void *obj)
63324 {
63325- void *stack = task_stack_page(current);
63326+ const void *stack = task_stack_page(current);
63327
63328 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63329 }
63330
63331+#ifdef CONFIG_PAX_USERCOPY
63332+extern int object_is_on_stack(const void *obj, unsigned long len);
63333+#endif
63334+
63335 extern void thread_info_cache_init(void);
63336
63337 #ifdef CONFIG_DEBUG_STACK_USAGE
63338diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63339index 899fbb4..1cb4138 100644
63340--- a/include/linux/screen_info.h
63341+++ b/include/linux/screen_info.h
63342@@ -43,7 +43,8 @@ struct screen_info {
63343 __u16 pages; /* 0x32 */
63344 __u16 vesa_attributes; /* 0x34 */
63345 __u32 capabilities; /* 0x36 */
63346- __u8 _reserved[6]; /* 0x3a */
63347+ __u16 vesapm_size; /* 0x3a */
63348+ __u8 _reserved[4]; /* 0x3c */
63349 } __attribute__((packed));
63350
63351 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63352diff --git a/include/linux/security.h b/include/linux/security.h
63353index 83c18e8..2d98860 100644
63354--- a/include/linux/security.h
63355+++ b/include/linux/security.h
63356@@ -37,6 +37,7 @@
63357 #include <linux/xfrm.h>
63358 #include <linux/slab.h>
63359 #include <linux/xattr.h>
63360+#include <linux/grsecurity.h>
63361 #include <net/flow.h>
63362
63363 /* Maximum number of letters for an LSM name string */
63364diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63365index 44f1514..2bbf6c1 100644
63366--- a/include/linux/seq_file.h
63367+++ b/include/linux/seq_file.h
63368@@ -24,6 +24,9 @@ struct seq_file {
63369 struct mutex lock;
63370 const struct seq_operations *op;
63371 int poll_event;
63372+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63373+ u64 exec_id;
63374+#endif
63375 void *private;
63376 };
63377
63378@@ -33,6 +36,7 @@ struct seq_operations {
63379 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63380 int (*show) (struct seq_file *m, void *v);
63381 };
63382+typedef struct seq_operations __no_const seq_operations_no_const;
63383
63384 #define SEQ_SKIP 1
63385
63386diff --git a/include/linux/shm.h b/include/linux/shm.h
63387index 92808b8..c28cac4 100644
63388--- a/include/linux/shm.h
63389+++ b/include/linux/shm.h
63390@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63391
63392 /* The task created the shm object. NULL if the task is dead. */
63393 struct task_struct *shm_creator;
63394+#ifdef CONFIG_GRKERNSEC
63395+ time_t shm_createtime;
63396+ pid_t shm_lapid;
63397+#endif
63398 };
63399
63400 /* shm_mode upper byte flags */
63401diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63402index 42854ce..3b7d3c8 100644
63403--- a/include/linux/skbuff.h
63404+++ b/include/linux/skbuff.h
63405@@ -655,7 +655,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63406 */
63407 static inline int skb_queue_empty(const struct sk_buff_head *list)
63408 {
63409- return list->next == (struct sk_buff *)list;
63410+ return list->next == (const struct sk_buff *)list;
63411 }
63412
63413 /**
63414@@ -668,7 +668,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63415 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63416 const struct sk_buff *skb)
63417 {
63418- return skb->next == (struct sk_buff *)list;
63419+ return skb->next == (const struct sk_buff *)list;
63420 }
63421
63422 /**
63423@@ -681,7 +681,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63424 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63425 const struct sk_buff *skb)
63426 {
63427- return skb->prev == (struct sk_buff *)list;
63428+ return skb->prev == (const struct sk_buff *)list;
63429 }
63430
63431 /**
63432@@ -1558,7 +1558,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63433 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63434 */
63435 #ifndef NET_SKB_PAD
63436-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63437+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63438 #endif
63439
63440 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63441diff --git a/include/linux/slab.h b/include/linux/slab.h
63442index 573c809..eaaf6ea 100644
63443--- a/include/linux/slab.h
63444+++ b/include/linux/slab.h
63445@@ -11,12 +11,20 @@
63446
63447 #include <linux/gfp.h>
63448 #include <linux/types.h>
63449+#include <linux/err.h>
63450
63451 /*
63452 * Flags to pass to kmem_cache_create().
63453 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63454 */
63455 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63456+
63457+#ifdef CONFIG_PAX_USERCOPY
63458+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63459+#else
63460+#define SLAB_USERCOPY 0x00000000UL
63461+#endif
63462+
63463 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63464 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63465 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63466@@ -87,10 +95,13 @@
63467 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63468 * Both make kfree a no-op.
63469 */
63470-#define ZERO_SIZE_PTR ((void *)16)
63471+#define ZERO_SIZE_PTR \
63472+({ \
63473+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63474+ (void *)(-MAX_ERRNO-1L); \
63475+})
63476
63477-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63478- (unsigned long)ZERO_SIZE_PTR)
63479+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63480
63481 /*
63482 * struct kmem_cache related prototypes
63483@@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
63484 void kfree(const void *);
63485 void kzfree(const void *);
63486 size_t ksize(const void *);
63487+void check_object_size(const void *ptr, unsigned long n, bool to);
63488
63489 /*
63490 * Allocator specific definitions. These are mainly used to establish optimized
63491@@ -287,7 +299,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63492 */
63493 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63494 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63495-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63496+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63497 #define kmalloc_track_caller(size, flags) \
63498 __kmalloc_track_caller(size, flags, _RET_IP_)
63499 #else
63500@@ -306,7 +318,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63501 */
63502 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63503 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63504-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63505+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63506 #define kmalloc_node_track_caller(size, flags, node) \
63507 __kmalloc_node_track_caller(size, flags, node, \
63508 _RET_IP_)
63509diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63510index fbd1117..d4d8ef8 100644
63511--- a/include/linux/slab_def.h
63512+++ b/include/linux/slab_def.h
63513@@ -66,10 +66,10 @@ struct kmem_cache {
63514 unsigned long node_allocs;
63515 unsigned long node_frees;
63516 unsigned long node_overflow;
63517- atomic_t allochit;
63518- atomic_t allocmiss;
63519- atomic_t freehit;
63520- atomic_t freemiss;
63521+ atomic_unchecked_t allochit;
63522+ atomic_unchecked_t allocmiss;
63523+ atomic_unchecked_t freehit;
63524+ atomic_unchecked_t freemiss;
63525
63526 /*
63527 * If debugging is enabled, then the allocator can add additional
63528@@ -107,7 +107,7 @@ struct cache_sizes {
63529 extern struct cache_sizes malloc_sizes[];
63530
63531 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63532-void *__kmalloc(size_t size, gfp_t flags);
63533+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63534
63535 #ifdef CONFIG_TRACING
63536 extern void *kmem_cache_alloc_trace(size_t size,
63537@@ -160,7 +160,7 @@ found:
63538 }
63539
63540 #ifdef CONFIG_NUMA
63541-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63542+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63543 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63544
63545 #ifdef CONFIG_TRACING
63546diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63547index 0ec00b3..39cb7fc 100644
63548--- a/include/linux/slob_def.h
63549+++ b/include/linux/slob_def.h
63550@@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63551 return kmem_cache_alloc_node(cachep, flags, -1);
63552 }
63553
63554-void *__kmalloc_node(size_t size, gfp_t flags, int node);
63555+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63556
63557 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63558 {
63559@@ -29,6 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63560 return __kmalloc_node(size, flags, -1);
63561 }
63562
63563+static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63564 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63565 {
63566 return kmalloc(size, flags);
63567diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63568index a32bcfd..a80ed70 100644
63569--- a/include/linux/slub_def.h
63570+++ b/include/linux/slub_def.h
63571@@ -89,7 +89,7 @@ struct kmem_cache {
63572 struct kmem_cache_order_objects max;
63573 struct kmem_cache_order_objects min;
63574 gfp_t allocflags; /* gfp flags to use on each alloc */
63575- int refcount; /* Refcount for slab cache destroy */
63576+ atomic_t refcount; /* Refcount for slab cache destroy */
63577 void (*ctor)(void *);
63578 int inuse; /* Offset to metadata */
63579 int align; /* Alignment */
63580@@ -150,6 +150,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
63581 * Sorry that the following has to be that ugly but some versions of GCC
63582 * have trouble with constant propagation and loops.
63583 */
63584+static __always_inline int kmalloc_index(size_t size) __size_overflow(1);
63585 static __always_inline int kmalloc_index(size_t size)
63586 {
63587 if (!size)
63588@@ -215,7 +216,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63589 }
63590
63591 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63592-void *__kmalloc(size_t size, gfp_t flags);
63593+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
63594
63595 static __always_inline void *
63596 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63597@@ -256,6 +257,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
63598 }
63599 #endif
63600
63601+static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
63602 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
63603 {
63604 unsigned int order = get_order(size);
63605@@ -281,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63606 }
63607
63608 #ifdef CONFIG_NUMA
63609-void *__kmalloc_node(size_t size, gfp_t flags, int node);
63610+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63611 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63612
63613 #ifdef CONFIG_TRACING
63614diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63615index de8832d..0147b46 100644
63616--- a/include/linux/sonet.h
63617+++ b/include/linux/sonet.h
63618@@ -61,7 +61,7 @@ struct sonet_stats {
63619 #include <linux/atomic.h>
63620
63621 struct k_sonet_stats {
63622-#define __HANDLE_ITEM(i) atomic_t i
63623+#define __HANDLE_ITEM(i) atomic_unchecked_t i
63624 __SONET_ITEMS
63625 #undef __HANDLE_ITEM
63626 };
63627diff --git a/include/linux/stddef.h b/include/linux/stddef.h
63628index 6a40c76..1747b67 100644
63629--- a/include/linux/stddef.h
63630+++ b/include/linux/stddef.h
63631@@ -3,14 +3,10 @@
63632
63633 #include <linux/compiler.h>
63634
63635+#ifdef __KERNEL__
63636+
63637 #undef NULL
63638-#if defined(__cplusplus)
63639-#define NULL 0
63640-#else
63641 #define NULL ((void *)0)
63642-#endif
63643-
63644-#ifdef __KERNEL__
63645
63646 enum {
63647 false = 0,
63648diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63649index 2c5993a..b0e79f0 100644
63650--- a/include/linux/sunrpc/clnt.h
63651+++ b/include/linux/sunrpc/clnt.h
63652@@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63653 {
63654 switch (sap->sa_family) {
63655 case AF_INET:
63656- return ntohs(((struct sockaddr_in *)sap)->sin_port);
63657+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63658 case AF_INET6:
63659- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63660+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63661 }
63662 return 0;
63663 }
63664@@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63665 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63666 const struct sockaddr *src)
63667 {
63668- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63669+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63670 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63671
63672 dsin->sin_family = ssin->sin_family;
63673@@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63674 if (sa->sa_family != AF_INET6)
63675 return 0;
63676
63677- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63678+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63679 }
63680
63681 #endif /* __KERNEL__ */
63682diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63683index e775689..9e206d9 100644
63684--- a/include/linux/sunrpc/sched.h
63685+++ b/include/linux/sunrpc/sched.h
63686@@ -105,6 +105,7 @@ struct rpc_call_ops {
63687 void (*rpc_call_done)(struct rpc_task *, void *);
63688 void (*rpc_release)(void *);
63689 };
63690+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63691
63692 struct rpc_task_setup {
63693 struct rpc_task *task;
63694diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63695index c14fe86..393245e 100644
63696--- a/include/linux/sunrpc/svc_rdma.h
63697+++ b/include/linux/sunrpc/svc_rdma.h
63698@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63699 extern unsigned int svcrdma_max_requests;
63700 extern unsigned int svcrdma_max_req_size;
63701
63702-extern atomic_t rdma_stat_recv;
63703-extern atomic_t rdma_stat_read;
63704-extern atomic_t rdma_stat_write;
63705-extern atomic_t rdma_stat_sq_starve;
63706-extern atomic_t rdma_stat_rq_starve;
63707-extern atomic_t rdma_stat_rq_poll;
63708-extern atomic_t rdma_stat_rq_prod;
63709-extern atomic_t rdma_stat_sq_poll;
63710-extern atomic_t rdma_stat_sq_prod;
63711+extern atomic_unchecked_t rdma_stat_recv;
63712+extern atomic_unchecked_t rdma_stat_read;
63713+extern atomic_unchecked_t rdma_stat_write;
63714+extern atomic_unchecked_t rdma_stat_sq_starve;
63715+extern atomic_unchecked_t rdma_stat_rq_starve;
63716+extern atomic_unchecked_t rdma_stat_rq_poll;
63717+extern atomic_unchecked_t rdma_stat_rq_prod;
63718+extern atomic_unchecked_t rdma_stat_sq_poll;
63719+extern atomic_unchecked_t rdma_stat_sq_prod;
63720
63721 #define RPCRDMA_VERSION 1
63722
63723diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63724index bb9127d..34ab358 100644
63725--- a/include/linux/sysctl.h
63726+++ b/include/linux/sysctl.h
63727@@ -155,7 +155,11 @@ enum
63728 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63729 };
63730
63731-
63732+#ifdef CONFIG_PAX_SOFTMODE
63733+enum {
63734+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63735+};
63736+#endif
63737
63738 /* CTL_VM names: */
63739 enum
63740@@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63741
63742 extern int proc_dostring(struct ctl_table *, int,
63743 void __user *, size_t *, loff_t *);
63744+extern int proc_dostring_modpriv(struct ctl_table *, int,
63745+ void __user *, size_t *, loff_t *);
63746 extern int proc_dointvec(struct ctl_table *, int,
63747 void __user *, size_t *, loff_t *);
63748 extern int proc_dointvec_minmax(struct ctl_table *, int,
63749diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
63750index a71a292..51bd91d 100644
63751--- a/include/linux/tracehook.h
63752+++ b/include/linux/tracehook.h
63753@@ -54,12 +54,12 @@ struct linux_binprm;
63754 /*
63755 * ptrace report for syscall entry and exit looks identical.
63756 */
63757-static inline void ptrace_report_syscall(struct pt_regs *regs)
63758+static inline int ptrace_report_syscall(struct pt_regs *regs)
63759 {
63760 int ptrace = current->ptrace;
63761
63762 if (!(ptrace & PT_PTRACED))
63763- return;
63764+ return 0;
63765
63766 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
63767
63768@@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
63769 send_sig(current->exit_code, current, 1);
63770 current->exit_code = 0;
63771 }
63772+
63773+ return fatal_signal_pending(current);
63774 }
63775
63776 /**
63777@@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
63778 static inline __must_check int tracehook_report_syscall_entry(
63779 struct pt_regs *regs)
63780 {
63781- ptrace_report_syscall(regs);
63782- return 0;
63783+ return ptrace_report_syscall(regs);
63784 }
63785
63786 /**
63787diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
63788index ff7dc08..893e1bd 100644
63789--- a/include/linux/tty_ldisc.h
63790+++ b/include/linux/tty_ldisc.h
63791@@ -148,7 +148,7 @@ struct tty_ldisc_ops {
63792
63793 struct module *owner;
63794
63795- int refcount;
63796+ atomic_t refcount;
63797 };
63798
63799 struct tty_ldisc {
63800diff --git a/include/linux/types.h b/include/linux/types.h
63801index e5fa503..df6e8a4 100644
63802--- a/include/linux/types.h
63803+++ b/include/linux/types.h
63804@@ -214,10 +214,26 @@ typedef struct {
63805 int counter;
63806 } atomic_t;
63807
63808+#ifdef CONFIG_PAX_REFCOUNT
63809+typedef struct {
63810+ int counter;
63811+} atomic_unchecked_t;
63812+#else
63813+typedef atomic_t atomic_unchecked_t;
63814+#endif
63815+
63816 #ifdef CONFIG_64BIT
63817 typedef struct {
63818 long counter;
63819 } atomic64_t;
63820+
63821+#ifdef CONFIG_PAX_REFCOUNT
63822+typedef struct {
63823+ long counter;
63824+} atomic64_unchecked_t;
63825+#else
63826+typedef atomic64_t atomic64_unchecked_t;
63827+#endif
63828 #endif
63829
63830 struct list_head {
63831diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
63832index 5ca0951..ab496a5 100644
63833--- a/include/linux/uaccess.h
63834+++ b/include/linux/uaccess.h
63835@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
63836 long ret; \
63837 mm_segment_t old_fs = get_fs(); \
63838 \
63839- set_fs(KERNEL_DS); \
63840 pagefault_disable(); \
63841- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
63842- pagefault_enable(); \
63843+ set_fs(KERNEL_DS); \
63844+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
63845 set_fs(old_fs); \
63846+ pagefault_enable(); \
63847 ret; \
63848 })
63849
63850diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
63851index 99c1b4d..bb94261 100644
63852--- a/include/linux/unaligned/access_ok.h
63853+++ b/include/linux/unaligned/access_ok.h
63854@@ -6,32 +6,32 @@
63855
63856 static inline u16 get_unaligned_le16(const void *p)
63857 {
63858- return le16_to_cpup((__le16 *)p);
63859+ return le16_to_cpup((const __le16 *)p);
63860 }
63861
63862 static inline u32 get_unaligned_le32(const void *p)
63863 {
63864- return le32_to_cpup((__le32 *)p);
63865+ return le32_to_cpup((const __le32 *)p);
63866 }
63867
63868 static inline u64 get_unaligned_le64(const void *p)
63869 {
63870- return le64_to_cpup((__le64 *)p);
63871+ return le64_to_cpup((const __le64 *)p);
63872 }
63873
63874 static inline u16 get_unaligned_be16(const void *p)
63875 {
63876- return be16_to_cpup((__be16 *)p);
63877+ return be16_to_cpup((const __be16 *)p);
63878 }
63879
63880 static inline u32 get_unaligned_be32(const void *p)
63881 {
63882- return be32_to_cpup((__be32 *)p);
63883+ return be32_to_cpup((const __be32 *)p);
63884 }
63885
63886 static inline u64 get_unaligned_be64(const void *p)
63887 {
63888- return be64_to_cpup((__be64 *)p);
63889+ return be64_to_cpup((const __be64 *)p);
63890 }
63891
63892 static inline void put_unaligned_le16(u16 val, void *p)
63893diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
63894index 0d3f988..000f101 100644
63895--- a/include/linux/usb/renesas_usbhs.h
63896+++ b/include/linux/usb/renesas_usbhs.h
63897@@ -39,7 +39,7 @@ enum {
63898 */
63899 struct renesas_usbhs_driver_callback {
63900 int (*notify_hotplug)(struct platform_device *pdev);
63901-};
63902+} __no_const;
63903
63904 /*
63905 * callback functions for platform
63906@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
63907 * VBUS control is needed for Host
63908 */
63909 int (*set_vbus)(struct platform_device *pdev, int enable);
63910-};
63911+} __no_const;
63912
63913 /*
63914 * parameters for renesas usbhs
63915diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
63916index 6f8fbcf..8259001 100644
63917--- a/include/linux/vermagic.h
63918+++ b/include/linux/vermagic.h
63919@@ -25,9 +25,35 @@
63920 #define MODULE_ARCH_VERMAGIC ""
63921 #endif
63922
63923+#ifdef CONFIG_PAX_REFCOUNT
63924+#define MODULE_PAX_REFCOUNT "REFCOUNT "
63925+#else
63926+#define MODULE_PAX_REFCOUNT ""
63927+#endif
63928+
63929+#ifdef CONSTIFY_PLUGIN
63930+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
63931+#else
63932+#define MODULE_CONSTIFY_PLUGIN ""
63933+#endif
63934+
63935+#ifdef STACKLEAK_PLUGIN
63936+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
63937+#else
63938+#define MODULE_STACKLEAK_PLUGIN ""
63939+#endif
63940+
63941+#ifdef CONFIG_GRKERNSEC
63942+#define MODULE_GRSEC "GRSEC "
63943+#else
63944+#define MODULE_GRSEC ""
63945+#endif
63946+
63947 #define VERMAGIC_STRING \
63948 UTS_RELEASE " " \
63949 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
63950 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
63951- MODULE_ARCH_VERMAGIC
63952+ MODULE_ARCH_VERMAGIC \
63953+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
63954+ MODULE_GRSEC
63955
63956diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
63957index dcdfc2b..ec79ab5 100644
63958--- a/include/linux/vmalloc.h
63959+++ b/include/linux/vmalloc.h
63960@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
63961 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
63962 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
63963 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
63964+
63965+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
63966+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
63967+#endif
63968+
63969 /* bits [20..32] reserved for arch specific ioremap internals */
63970
63971 /*
63972@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
63973 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
63974 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
63975 unsigned long start, unsigned long end, gfp_t gfp_mask,
63976- pgprot_t prot, int node, void *caller);
63977+ pgprot_t prot, int node, void *caller) __size_overflow(1);
63978 extern void vfree(const void *addr);
63979
63980 extern void *vmap(struct page **pages, unsigned int count,
63981@@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
63982 extern void free_vm_area(struct vm_struct *area);
63983
63984 /* for /dev/kmem */
63985-extern long vread(char *buf, char *addr, unsigned long count);
63986-extern long vwrite(char *buf, char *addr, unsigned long count);
63987+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
63988+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
63989
63990 /*
63991 * Internals. Dont't use..
63992diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
63993index 65efb92..137adbb 100644
63994--- a/include/linux/vmstat.h
63995+++ b/include/linux/vmstat.h
63996@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
63997 /*
63998 * Zone based page accounting with per cpu differentials.
63999 */
64000-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64001+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64002
64003 static inline void zone_page_state_add(long x, struct zone *zone,
64004 enum zone_stat_item item)
64005 {
64006- atomic_long_add(x, &zone->vm_stat[item]);
64007- atomic_long_add(x, &vm_stat[item]);
64008+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64009+ atomic_long_add_unchecked(x, &vm_stat[item]);
64010 }
64011
64012 static inline unsigned long global_page_state(enum zone_stat_item item)
64013 {
64014- long x = atomic_long_read(&vm_stat[item]);
64015+ long x = atomic_long_read_unchecked(&vm_stat[item]);
64016 #ifdef CONFIG_SMP
64017 if (x < 0)
64018 x = 0;
64019@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64020 static inline unsigned long zone_page_state(struct zone *zone,
64021 enum zone_stat_item item)
64022 {
64023- long x = atomic_long_read(&zone->vm_stat[item]);
64024+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64025 #ifdef CONFIG_SMP
64026 if (x < 0)
64027 x = 0;
64028@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64029 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64030 enum zone_stat_item item)
64031 {
64032- long x = atomic_long_read(&zone->vm_stat[item]);
64033+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64034
64035 #ifdef CONFIG_SMP
64036 int cpu;
64037@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64038
64039 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64040 {
64041- atomic_long_inc(&zone->vm_stat[item]);
64042- atomic_long_inc(&vm_stat[item]);
64043+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
64044+ atomic_long_inc_unchecked(&vm_stat[item]);
64045 }
64046
64047 static inline void __inc_zone_page_state(struct page *page,
64048@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64049
64050 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64051 {
64052- atomic_long_dec(&zone->vm_stat[item]);
64053- atomic_long_dec(&vm_stat[item]);
64054+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
64055+ atomic_long_dec_unchecked(&vm_stat[item]);
64056 }
64057
64058 static inline void __dec_zone_page_state(struct page *page,
64059diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64060index e5d1220..ef6e406 100644
64061--- a/include/linux/xattr.h
64062+++ b/include/linux/xattr.h
64063@@ -57,6 +57,11 @@
64064 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64065 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64066
64067+/* User namespace */
64068+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64069+#define XATTR_PAX_FLAGS_SUFFIX "flags"
64070+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64071+
64072 #ifdef __KERNEL__
64073
64074 #include <linux/types.h>
64075diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64076index 4aeff96..b378cdc 100644
64077--- a/include/media/saa7146_vv.h
64078+++ b/include/media/saa7146_vv.h
64079@@ -163,7 +163,7 @@ struct saa7146_ext_vv
64080 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64081
64082 /* the extension can override this */
64083- struct v4l2_ioctl_ops ops;
64084+ v4l2_ioctl_ops_no_const ops;
64085 /* pointer to the saa7146 core ops */
64086 const struct v4l2_ioctl_ops *core_ops;
64087
64088diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64089index c7c40f1..4f01585 100644
64090--- a/include/media/v4l2-dev.h
64091+++ b/include/media/v4l2-dev.h
64092@@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
64093
64094
64095 struct v4l2_file_operations {
64096- struct module *owner;
64097+ struct module * const owner;
64098 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
64099 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
64100 unsigned int (*poll) (struct file *, struct poll_table_struct *);
64101@@ -68,6 +68,7 @@ struct v4l2_file_operations {
64102 int (*open) (struct file *);
64103 int (*release) (struct file *);
64104 };
64105+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64106
64107 /*
64108 * Newer version of video_device, handled by videodev2.c
64109diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64110index 3f5d60f..44210ed 100644
64111--- a/include/media/v4l2-ioctl.h
64112+++ b/include/media/v4l2-ioctl.h
64113@@ -278,7 +278,7 @@ struct v4l2_ioctl_ops {
64114 long (*vidioc_default) (struct file *file, void *fh,
64115 bool valid_prio, int cmd, void *arg);
64116 };
64117-
64118+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64119
64120 /* v4l debugging and diagnostics */
64121
64122diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64123index 8d55251..dfe5b0a 100644
64124--- a/include/net/caif/caif_hsi.h
64125+++ b/include/net/caif/caif_hsi.h
64126@@ -98,7 +98,7 @@ struct cfhsi_drv {
64127 void (*rx_done_cb) (struct cfhsi_drv *drv);
64128 void (*wake_up_cb) (struct cfhsi_drv *drv);
64129 void (*wake_down_cb) (struct cfhsi_drv *drv);
64130-};
64131+} __no_const;
64132
64133 /* Structure implemented by HSI device. */
64134 struct cfhsi_dev {
64135diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64136index 9e5425b..8136ffc 100644
64137--- a/include/net/caif/cfctrl.h
64138+++ b/include/net/caif/cfctrl.h
64139@@ -52,7 +52,7 @@ struct cfctrl_rsp {
64140 void (*radioset_rsp)(void);
64141 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64142 struct cflayer *client_layer);
64143-};
64144+} __no_const;
64145
64146 /* Link Setup Parameters for CAIF-Links. */
64147 struct cfctrl_link_param {
64148@@ -101,8 +101,8 @@ struct cfctrl_request_info {
64149 struct cfctrl {
64150 struct cfsrvl serv;
64151 struct cfctrl_rsp res;
64152- atomic_t req_seq_no;
64153- atomic_t rsp_seq_no;
64154+ atomic_unchecked_t req_seq_no;
64155+ atomic_unchecked_t rsp_seq_no;
64156 struct list_head list;
64157 /* Protects from simultaneous access to first_req list */
64158 spinlock_t info_list_lock;
64159diff --git a/include/net/flow.h b/include/net/flow.h
64160index 6c469db..7743b8e 100644
64161--- a/include/net/flow.h
64162+++ b/include/net/flow.h
64163@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64164
64165 extern void flow_cache_flush(void);
64166 extern void flow_cache_flush_deferred(void);
64167-extern atomic_t flow_cache_genid;
64168+extern atomic_unchecked_t flow_cache_genid;
64169
64170 #endif
64171diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64172index b94765e..053f68b 100644
64173--- a/include/net/inetpeer.h
64174+++ b/include/net/inetpeer.h
64175@@ -48,8 +48,8 @@ struct inet_peer {
64176 */
64177 union {
64178 struct {
64179- atomic_t rid; /* Frag reception counter */
64180- atomic_t ip_id_count; /* IP ID for the next packet */
64181+ atomic_unchecked_t rid; /* Frag reception counter */
64182+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64183 __u32 tcp_ts;
64184 __u32 tcp_ts_stamp;
64185 };
64186@@ -115,11 +115,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64187 more++;
64188 inet_peer_refcheck(p);
64189 do {
64190- old = atomic_read(&p->ip_id_count);
64191+ old = atomic_read_unchecked(&p->ip_id_count);
64192 new = old + more;
64193 if (!new)
64194 new = 1;
64195- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64196+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64197 return new;
64198 }
64199
64200diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64201index 10422ef..662570f 100644
64202--- a/include/net/ip_fib.h
64203+++ b/include/net/ip_fib.h
64204@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64205
64206 #define FIB_RES_SADDR(net, res) \
64207 ((FIB_RES_NH(res).nh_saddr_genid == \
64208- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64209+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64210 FIB_RES_NH(res).nh_saddr : \
64211 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64212 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64213diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64214index ebe517f..1bd286b 100644
64215--- a/include/net/ip_vs.h
64216+++ b/include/net/ip_vs.h
64217@@ -509,7 +509,7 @@ struct ip_vs_conn {
64218 struct ip_vs_conn *control; /* Master control connection */
64219 atomic_t n_control; /* Number of controlled ones */
64220 struct ip_vs_dest *dest; /* real server */
64221- atomic_t in_pkts; /* incoming packet counter */
64222+ atomic_unchecked_t in_pkts; /* incoming packet counter */
64223
64224 /* packet transmitter for different forwarding methods. If it
64225 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64226@@ -647,7 +647,7 @@ struct ip_vs_dest {
64227 __be16 port; /* port number of the server */
64228 union nf_inet_addr addr; /* IP address of the server */
64229 volatile unsigned flags; /* dest status flags */
64230- atomic_t conn_flags; /* flags to copy to conn */
64231+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
64232 atomic_t weight; /* server weight */
64233
64234 atomic_t refcnt; /* reference counter */
64235diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64236index 69b610a..fe3962c 100644
64237--- a/include/net/irda/ircomm_core.h
64238+++ b/include/net/irda/ircomm_core.h
64239@@ -51,7 +51,7 @@ typedef struct {
64240 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64241 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64242 struct ircomm_info *);
64243-} call_t;
64244+} __no_const call_t;
64245
64246 struct ircomm_cb {
64247 irda_queue_t queue;
64248diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64249index 59ba38bc..d515662 100644
64250--- a/include/net/irda/ircomm_tty.h
64251+++ b/include/net/irda/ircomm_tty.h
64252@@ -35,6 +35,7 @@
64253 #include <linux/termios.h>
64254 #include <linux/timer.h>
64255 #include <linux/tty.h> /* struct tty_struct */
64256+#include <asm/local.h>
64257
64258 #include <net/irda/irias_object.h>
64259 #include <net/irda/ircomm_core.h>
64260@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64261 unsigned short close_delay;
64262 unsigned short closing_wait; /* time to wait before closing */
64263
64264- int open_count;
64265- int blocked_open; /* # of blocked opens */
64266+ local_t open_count;
64267+ local_t blocked_open; /* # of blocked opens */
64268
64269 /* Protect concurent access to :
64270 * o self->open_count
64271diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64272index 0954ec9..7413562 100644
64273--- a/include/net/iucv/af_iucv.h
64274+++ b/include/net/iucv/af_iucv.h
64275@@ -138,7 +138,7 @@ struct iucv_sock {
64276 struct iucv_sock_list {
64277 struct hlist_head head;
64278 rwlock_t lock;
64279- atomic_t autobind_name;
64280+ atomic_unchecked_t autobind_name;
64281 };
64282
64283 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64284diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64285index 34c996f..bb3b4d4 100644
64286--- a/include/net/neighbour.h
64287+++ b/include/net/neighbour.h
64288@@ -123,7 +123,7 @@ struct neigh_ops {
64289 void (*error_report)(struct neighbour *, struct sk_buff *);
64290 int (*output)(struct neighbour *, struct sk_buff *);
64291 int (*connected_output)(struct neighbour *, struct sk_buff *);
64292-};
64293+} __do_const;
64294
64295 struct pneigh_entry {
64296 struct pneigh_entry *next;
64297diff --git a/include/net/netlink.h b/include/net/netlink.h
64298index cb1f350..3279d2c 100644
64299--- a/include/net/netlink.h
64300+++ b/include/net/netlink.h
64301@@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64302 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64303 {
64304 if (mark)
64305- skb_trim(skb, (unsigned char *) mark - skb->data);
64306+ skb_trim(skb, (const unsigned char *) mark - skb->data);
64307 }
64308
64309 /**
64310diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64311index bbd023a..97c6d0d 100644
64312--- a/include/net/netns/ipv4.h
64313+++ b/include/net/netns/ipv4.h
64314@@ -57,8 +57,8 @@ struct netns_ipv4 {
64315 unsigned int sysctl_ping_group_range[2];
64316 long sysctl_tcp_mem[3];
64317
64318- atomic_t rt_genid;
64319- atomic_t dev_addr_genid;
64320+ atomic_unchecked_t rt_genid;
64321+ atomic_unchecked_t dev_addr_genid;
64322
64323 #ifdef CONFIG_IP_MROUTE
64324 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64325diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64326index d368561..96aaa17 100644
64327--- a/include/net/sctp/sctp.h
64328+++ b/include/net/sctp/sctp.h
64329@@ -318,9 +318,9 @@ do { \
64330
64331 #else /* SCTP_DEBUG */
64332
64333-#define SCTP_DEBUG_PRINTK(whatever...)
64334-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64335-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64336+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64337+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64338+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64339 #define SCTP_ENABLE_DEBUG
64340 #define SCTP_DISABLE_DEBUG
64341 #define SCTP_ASSERT(expr, str, func)
64342diff --git a/include/net/sock.h b/include/net/sock.h
64343index 91c1c8b..15ae923 100644
64344--- a/include/net/sock.h
64345+++ b/include/net/sock.h
64346@@ -299,7 +299,7 @@ struct sock {
64347 #ifdef CONFIG_RPS
64348 __u32 sk_rxhash;
64349 #endif
64350- atomic_t sk_drops;
64351+ atomic_unchecked_t sk_drops;
64352 int sk_rcvbuf;
64353
64354 struct sk_filter __rcu *sk_filter;
64355@@ -1660,7 +1660,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64356 }
64357
64358 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64359- char __user *from, char *to,
64360+ char __user *from, unsigned char *to,
64361 int copy, int offset)
64362 {
64363 if (skb->ip_summed == CHECKSUM_NONE) {
64364diff --git a/include/net/tcp.h b/include/net/tcp.h
64365index 2d80c29..aa07caf 100644
64366--- a/include/net/tcp.h
64367+++ b/include/net/tcp.h
64368@@ -1426,7 +1426,7 @@ struct tcp_seq_afinfo {
64369 char *name;
64370 sa_family_t family;
64371 const struct file_operations *seq_fops;
64372- struct seq_operations seq_ops;
64373+ seq_operations_no_const seq_ops;
64374 };
64375
64376 struct tcp_iter_state {
64377diff --git a/include/net/udp.h b/include/net/udp.h
64378index e39592f..fef9680 100644
64379--- a/include/net/udp.h
64380+++ b/include/net/udp.h
64381@@ -243,7 +243,7 @@ struct udp_seq_afinfo {
64382 sa_family_t family;
64383 struct udp_table *udp_table;
64384 const struct file_operations *seq_fops;
64385- struct seq_operations seq_ops;
64386+ seq_operations_no_const seq_ops;
64387 };
64388
64389 struct udp_iter_state {
64390diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64391index 89174e2..1f82598 100644
64392--- a/include/net/xfrm.h
64393+++ b/include/net/xfrm.h
64394@@ -505,7 +505,7 @@ struct xfrm_policy {
64395 struct timer_list timer;
64396
64397 struct flow_cache_object flo;
64398- atomic_t genid;
64399+ atomic_unchecked_t genid;
64400 u32 priority;
64401 u32 index;
64402 struct xfrm_mark mark;
64403diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64404index 1a046b1..ee0bef0 100644
64405--- a/include/rdma/iw_cm.h
64406+++ b/include/rdma/iw_cm.h
64407@@ -122,7 +122,7 @@ struct iw_cm_verbs {
64408 int backlog);
64409
64410 int (*destroy_listen)(struct iw_cm_id *cm_id);
64411-};
64412+} __no_const;
64413
64414 /**
64415 * iw_create_cm_id - Create an IW CM identifier.
64416diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64417index 6a3922f..0b73022 100644
64418--- a/include/scsi/libfc.h
64419+++ b/include/scsi/libfc.h
64420@@ -748,6 +748,7 @@ struct libfc_function_template {
64421 */
64422 void (*disc_stop_final) (struct fc_lport *);
64423 };
64424+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64425
64426 /**
64427 * struct fc_disc - Discovery context
64428@@ -851,7 +852,7 @@ struct fc_lport {
64429 struct fc_vport *vport;
64430
64431 /* Operational Information */
64432- struct libfc_function_template tt;
64433+ libfc_function_template_no_const tt;
64434 u8 link_up;
64435 u8 qfull;
64436 enum fc_lport_state state;
64437diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64438index 77273f2..dd4031f 100644
64439--- a/include/scsi/scsi_device.h
64440+++ b/include/scsi/scsi_device.h
64441@@ -161,9 +161,9 @@ struct scsi_device {
64442 unsigned int max_device_blocked; /* what device_blocked counts down from */
64443 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64444
64445- atomic_t iorequest_cnt;
64446- atomic_t iodone_cnt;
64447- atomic_t ioerr_cnt;
64448+ atomic_unchecked_t iorequest_cnt;
64449+ atomic_unchecked_t iodone_cnt;
64450+ atomic_unchecked_t ioerr_cnt;
64451
64452 struct device sdev_gendev,
64453 sdev_dev;
64454diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64455index 2a65167..91e01f8 100644
64456--- a/include/scsi/scsi_transport_fc.h
64457+++ b/include/scsi/scsi_transport_fc.h
64458@@ -711,7 +711,7 @@ struct fc_function_template {
64459 unsigned long show_host_system_hostname:1;
64460
64461 unsigned long disable_target_scan:1;
64462-};
64463+} __do_const;
64464
64465
64466 /**
64467diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64468index 030b87c..98a6954 100644
64469--- a/include/sound/ak4xxx-adda.h
64470+++ b/include/sound/ak4xxx-adda.h
64471@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64472 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64473 unsigned char val);
64474 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64475-};
64476+} __no_const;
64477
64478 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64479
64480diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64481index 8c05e47..2b5df97 100644
64482--- a/include/sound/hwdep.h
64483+++ b/include/sound/hwdep.h
64484@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64485 struct snd_hwdep_dsp_status *status);
64486 int (*dsp_load)(struct snd_hwdep *hw,
64487 struct snd_hwdep_dsp_image *image);
64488-};
64489+} __no_const;
64490
64491 struct snd_hwdep {
64492 struct snd_card *card;
64493diff --git a/include/sound/info.h b/include/sound/info.h
64494index 9ca1a49..aba1728 100644
64495--- a/include/sound/info.h
64496+++ b/include/sound/info.h
64497@@ -44,7 +44,7 @@ struct snd_info_entry_text {
64498 struct snd_info_buffer *buffer);
64499 void (*write)(struct snd_info_entry *entry,
64500 struct snd_info_buffer *buffer);
64501-};
64502+} __no_const;
64503
64504 struct snd_info_entry_ops {
64505 int (*open)(struct snd_info_entry *entry,
64506diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64507index 0cf91b2..b70cae4 100644
64508--- a/include/sound/pcm.h
64509+++ b/include/sound/pcm.h
64510@@ -81,6 +81,7 @@ struct snd_pcm_ops {
64511 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64512 int (*ack)(struct snd_pcm_substream *substream);
64513 };
64514+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64515
64516 /*
64517 *
64518diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64519index af1b49e..a5d55a5 100644
64520--- a/include/sound/sb16_csp.h
64521+++ b/include/sound/sb16_csp.h
64522@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64523 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64524 int (*csp_stop) (struct snd_sb_csp * p);
64525 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64526-};
64527+} __no_const;
64528
64529 /*
64530 * CSP private data
64531diff --git a/include/sound/soc.h b/include/sound/soc.h
64532index 0992dff..bb366fe 100644
64533--- a/include/sound/soc.h
64534+++ b/include/sound/soc.h
64535@@ -682,7 +682,7 @@ struct snd_soc_platform_driver {
64536 /* platform IO - used for platform DAPM */
64537 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64538 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64539-};
64540+} __do_const;
64541
64542 struct snd_soc_platform {
64543 const char *name;
64544@@ -852,7 +852,7 @@ struct snd_soc_pcm_runtime {
64545 struct snd_soc_dai_link *dai_link;
64546 struct mutex pcm_mutex;
64547 enum snd_soc_pcm_subclass pcm_subclass;
64548- struct snd_pcm_ops ops;
64549+ snd_pcm_ops_no_const ops;
64550
64551 unsigned int complete:1;
64552 unsigned int dev_registered:1;
64553diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64554index 444cd6b..3327cc5 100644
64555--- a/include/sound/ymfpci.h
64556+++ b/include/sound/ymfpci.h
64557@@ -358,7 +358,7 @@ struct snd_ymfpci {
64558 spinlock_t reg_lock;
64559 spinlock_t voice_lock;
64560 wait_queue_head_t interrupt_sleep;
64561- atomic_t interrupt_sleep_count;
64562+ atomic_unchecked_t interrupt_sleep_count;
64563 struct snd_info_entry *proc_entry;
64564 const struct firmware *dsp_microcode;
64565 const struct firmware *controller_microcode;
64566diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64567index fe73eb8..56388b1 100644
64568--- a/include/target/target_core_base.h
64569+++ b/include/target/target_core_base.h
64570@@ -443,7 +443,7 @@ struct t10_reservation_ops {
64571 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64572 int (*t10_pr_register)(struct se_cmd *);
64573 int (*t10_pr_clear)(struct se_cmd *);
64574-};
64575+} __no_const;
64576
64577 struct t10_reservation {
64578 /* Reservation effects all target ports */
64579@@ -561,8 +561,8 @@ struct se_cmd {
64580 atomic_t t_se_count;
64581 atomic_t t_task_cdbs_left;
64582 atomic_t t_task_cdbs_ex_left;
64583- atomic_t t_task_cdbs_sent;
64584- atomic_t t_transport_aborted;
64585+ atomic_unchecked_t t_task_cdbs_sent;
64586+ atomic_unchecked_t t_transport_aborted;
64587 atomic_t t_transport_active;
64588 atomic_t t_transport_complete;
64589 atomic_t t_transport_queue_active;
64590@@ -799,7 +799,7 @@ struct se_device {
64591 spinlock_t stats_lock;
64592 /* Active commands on this virtual SE device */
64593 atomic_t simple_cmds;
64594- atomic_t dev_ordered_id;
64595+ atomic_unchecked_t dev_ordered_id;
64596 atomic_t execute_tasks;
64597 atomic_t dev_ordered_sync;
64598 atomic_t dev_qf_count;
64599diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64600index 1c09820..7f5ec79 100644
64601--- a/include/trace/events/irq.h
64602+++ b/include/trace/events/irq.h
64603@@ -36,7 +36,7 @@ struct softirq_action;
64604 */
64605 TRACE_EVENT(irq_handler_entry,
64606
64607- TP_PROTO(int irq, struct irqaction *action),
64608+ TP_PROTO(int irq, const struct irqaction *action),
64609
64610 TP_ARGS(irq, action),
64611
64612@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64613 */
64614 TRACE_EVENT(irq_handler_exit,
64615
64616- TP_PROTO(int irq, struct irqaction *action, int ret),
64617+ TP_PROTO(int irq, const struct irqaction *action, int ret),
64618
64619 TP_ARGS(irq, action, ret),
64620
64621diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64622index c41f308..6918de3 100644
64623--- a/include/video/udlfb.h
64624+++ b/include/video/udlfb.h
64625@@ -52,10 +52,10 @@ struct dlfb_data {
64626 u32 pseudo_palette[256];
64627 int blank_mode; /*one of FB_BLANK_ */
64628 /* blit-only rendering path metrics, exposed through sysfs */
64629- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64630- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64631- atomic_t bytes_sent; /* to usb, after compression including overhead */
64632- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64633+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64634+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64635+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64636+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64637 };
64638
64639 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64640diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64641index 0993a22..32ba2fe 100644
64642--- a/include/video/uvesafb.h
64643+++ b/include/video/uvesafb.h
64644@@ -177,6 +177,7 @@ struct uvesafb_par {
64645 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64646 u8 pmi_setpal; /* PMI for palette changes */
64647 u16 *pmi_base; /* protected mode interface location */
64648+ u8 *pmi_code; /* protected mode code location */
64649 void *pmi_start;
64650 void *pmi_pal;
64651 u8 *vbe_state_orig; /*
64652diff --git a/init/Kconfig b/init/Kconfig
64653index 3f42cd6..613f41d 100644
64654--- a/init/Kconfig
64655+++ b/init/Kconfig
64656@@ -799,6 +799,7 @@ endif # CGROUPS
64657
64658 config CHECKPOINT_RESTORE
64659 bool "Checkpoint/restore support" if EXPERT
64660+ depends on !GRKERNSEC
64661 default n
64662 help
64663 Enables additional kernel features in a sake of checkpoint/restore.
64664@@ -1249,7 +1250,7 @@ config SLUB_DEBUG
64665
64666 config COMPAT_BRK
64667 bool "Disable heap randomization"
64668- default y
64669+ default n
64670 help
64671 Randomizing heap placement makes heap exploits harder, but it
64672 also breaks ancient binaries (including anything libc5 based).
64673diff --git a/init/do_mounts.c b/init/do_mounts.c
64674index bf6edbf..4e5809c 100644
64675--- a/init/do_mounts.c
64676+++ b/init/do_mounts.c
64677@@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
64678 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64679 {
64680 struct super_block *s;
64681- int err = sys_mount(name, "/root", fs, flags, data);
64682+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64683 if (err)
64684 return err;
64685
64686- sys_chdir((const char __user __force *)"/root");
64687+ sys_chdir((const char __force_user *)"/root");
64688 s = current->fs->pwd.dentry->d_sb;
64689 ROOT_DEV = s->s_dev;
64690 printk(KERN_INFO
64691@@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
64692 va_start(args, fmt);
64693 vsprintf(buf, fmt, args);
64694 va_end(args);
64695- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
64696+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
64697 if (fd >= 0) {
64698 sys_ioctl(fd, FDEJECT, 0);
64699 sys_close(fd);
64700 }
64701 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
64702- fd = sys_open("/dev/console", O_RDWR, 0);
64703+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
64704 if (fd >= 0) {
64705 sys_ioctl(fd, TCGETS, (long)&termios);
64706 termios.c_lflag &= ~ICANON;
64707 sys_ioctl(fd, TCSETSF, (long)&termios);
64708- sys_read(fd, &c, 1);
64709+ sys_read(fd, (char __user *)&c, 1);
64710 termios.c_lflag |= ICANON;
64711 sys_ioctl(fd, TCSETSF, (long)&termios);
64712 sys_close(fd);
64713@@ -555,6 +555,6 @@ void __init prepare_namespace(void)
64714 mount_root();
64715 out:
64716 devtmpfs_mount("dev");
64717- sys_mount(".", "/", NULL, MS_MOVE, NULL);
64718- sys_chroot((const char __user __force *)".");
64719+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64720+ sys_chroot((const char __force_user *)".");
64721 }
64722diff --git a/init/do_mounts.h b/init/do_mounts.h
64723index f5b978a..69dbfe8 100644
64724--- a/init/do_mounts.h
64725+++ b/init/do_mounts.h
64726@@ -15,15 +15,15 @@ extern int root_mountflags;
64727
64728 static inline int create_dev(char *name, dev_t dev)
64729 {
64730- sys_unlink(name);
64731- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64732+ sys_unlink((char __force_user *)name);
64733+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64734 }
64735
64736 #if BITS_PER_LONG == 32
64737 static inline u32 bstat(char *name)
64738 {
64739 struct stat64 stat;
64740- if (sys_stat64(name, &stat) != 0)
64741+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64742 return 0;
64743 if (!S_ISBLK(stat.st_mode))
64744 return 0;
64745@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
64746 static inline u32 bstat(char *name)
64747 {
64748 struct stat stat;
64749- if (sys_newstat(name, &stat) != 0)
64750+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
64751 return 0;
64752 if (!S_ISBLK(stat.st_mode))
64753 return 0;
64754diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
64755index 3098a38..253064e 100644
64756--- a/init/do_mounts_initrd.c
64757+++ b/init/do_mounts_initrd.c
64758@@ -44,13 +44,13 @@ static void __init handle_initrd(void)
64759 create_dev("/dev/root.old", Root_RAM0);
64760 /* mount initrd on rootfs' /root */
64761 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
64762- sys_mkdir("/old", 0700);
64763- root_fd = sys_open("/", 0, 0);
64764- old_fd = sys_open("/old", 0, 0);
64765+ sys_mkdir((const char __force_user *)"/old", 0700);
64766+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
64767+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
64768 /* move initrd over / and chdir/chroot in initrd root */
64769- sys_chdir("/root");
64770- sys_mount(".", "/", NULL, MS_MOVE, NULL);
64771- sys_chroot(".");
64772+ sys_chdir((const char __force_user *)"/root");
64773+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64774+ sys_chroot((const char __force_user *)".");
64775
64776 /*
64777 * In case that a resume from disk is carried out by linuxrc or one of
64778@@ -67,15 +67,15 @@ static void __init handle_initrd(void)
64779
64780 /* move initrd to rootfs' /old */
64781 sys_fchdir(old_fd);
64782- sys_mount("/", ".", NULL, MS_MOVE, NULL);
64783+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
64784 /* switch root and cwd back to / of rootfs */
64785 sys_fchdir(root_fd);
64786- sys_chroot(".");
64787+ sys_chroot((const char __force_user *)".");
64788 sys_close(old_fd);
64789 sys_close(root_fd);
64790
64791 if (new_decode_dev(real_root_dev) == Root_RAM0) {
64792- sys_chdir("/old");
64793+ sys_chdir((const char __force_user *)"/old");
64794 return;
64795 }
64796
64797@@ -83,17 +83,17 @@ static void __init handle_initrd(void)
64798 mount_root();
64799
64800 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
64801- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
64802+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
64803 if (!error)
64804 printk("okay\n");
64805 else {
64806- int fd = sys_open("/dev/root.old", O_RDWR, 0);
64807+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
64808 if (error == -ENOENT)
64809 printk("/initrd does not exist. Ignored.\n");
64810 else
64811 printk("failed\n");
64812 printk(KERN_NOTICE "Unmounting old root\n");
64813- sys_umount("/old", MNT_DETACH);
64814+ sys_umount((char __force_user *)"/old", MNT_DETACH);
64815 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
64816 if (fd < 0) {
64817 error = fd;
64818@@ -116,11 +116,11 @@ int __init initrd_load(void)
64819 * mounted in the normal path.
64820 */
64821 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
64822- sys_unlink("/initrd.image");
64823+ sys_unlink((const char __force_user *)"/initrd.image");
64824 handle_initrd();
64825 return 1;
64826 }
64827 }
64828- sys_unlink("/initrd.image");
64829+ sys_unlink((const char __force_user *)"/initrd.image");
64830 return 0;
64831 }
64832diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
64833index 32c4799..c27ee74 100644
64834--- a/init/do_mounts_md.c
64835+++ b/init/do_mounts_md.c
64836@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
64837 partitioned ? "_d" : "", minor,
64838 md_setup_args[ent].device_names);
64839
64840- fd = sys_open(name, 0, 0);
64841+ fd = sys_open((char __force_user *)name, 0, 0);
64842 if (fd < 0) {
64843 printk(KERN_ERR "md: open failed - cannot start "
64844 "array %s\n", name);
64845@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
64846 * array without it
64847 */
64848 sys_close(fd);
64849- fd = sys_open(name, 0, 0);
64850+ fd = sys_open((char __force_user *)name, 0, 0);
64851 sys_ioctl(fd, BLKRRPART, 0);
64852 }
64853 sys_close(fd);
64854@@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
64855
64856 wait_for_device_probe();
64857
64858- fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
64859+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
64860 if (fd >= 0) {
64861 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
64862 sys_close(fd);
64863diff --git a/init/initramfs.c b/init/initramfs.c
64864index 8216c30..25e8e32 100644
64865--- a/init/initramfs.c
64866+++ b/init/initramfs.c
64867@@ -74,7 +74,7 @@ static void __init free_hash(void)
64868 }
64869 }
64870
64871-static long __init do_utime(char __user *filename, time_t mtime)
64872+static long __init do_utime(__force char __user *filename, time_t mtime)
64873 {
64874 struct timespec t[2];
64875
64876@@ -109,7 +109,7 @@ static void __init dir_utime(void)
64877 struct dir_entry *de, *tmp;
64878 list_for_each_entry_safe(de, tmp, &dir_list, list) {
64879 list_del(&de->list);
64880- do_utime(de->name, de->mtime);
64881+ do_utime((char __force_user *)de->name, de->mtime);
64882 kfree(de->name);
64883 kfree(de);
64884 }
64885@@ -271,7 +271,7 @@ static int __init maybe_link(void)
64886 if (nlink >= 2) {
64887 char *old = find_link(major, minor, ino, mode, collected);
64888 if (old)
64889- return (sys_link(old, collected) < 0) ? -1 : 1;
64890+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
64891 }
64892 return 0;
64893 }
64894@@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
64895 {
64896 struct stat st;
64897
64898- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
64899+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
64900 if (S_ISDIR(st.st_mode))
64901- sys_rmdir(path);
64902+ sys_rmdir((char __force_user *)path);
64903 else
64904- sys_unlink(path);
64905+ sys_unlink((char __force_user *)path);
64906 }
64907 }
64908
64909@@ -305,7 +305,7 @@ static int __init do_name(void)
64910 int openflags = O_WRONLY|O_CREAT;
64911 if (ml != 1)
64912 openflags |= O_TRUNC;
64913- wfd = sys_open(collected, openflags, mode);
64914+ wfd = sys_open((char __force_user *)collected, openflags, mode);
64915
64916 if (wfd >= 0) {
64917 sys_fchown(wfd, uid, gid);
64918@@ -317,17 +317,17 @@ static int __init do_name(void)
64919 }
64920 }
64921 } else if (S_ISDIR(mode)) {
64922- sys_mkdir(collected, mode);
64923- sys_chown(collected, uid, gid);
64924- sys_chmod(collected, mode);
64925+ sys_mkdir((char __force_user *)collected, mode);
64926+ sys_chown((char __force_user *)collected, uid, gid);
64927+ sys_chmod((char __force_user *)collected, mode);
64928 dir_add(collected, mtime);
64929 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
64930 S_ISFIFO(mode) || S_ISSOCK(mode)) {
64931 if (maybe_link() == 0) {
64932- sys_mknod(collected, mode, rdev);
64933- sys_chown(collected, uid, gid);
64934- sys_chmod(collected, mode);
64935- do_utime(collected, mtime);
64936+ sys_mknod((char __force_user *)collected, mode, rdev);
64937+ sys_chown((char __force_user *)collected, uid, gid);
64938+ sys_chmod((char __force_user *)collected, mode);
64939+ do_utime((char __force_user *)collected, mtime);
64940 }
64941 }
64942 return 0;
64943@@ -336,15 +336,15 @@ static int __init do_name(void)
64944 static int __init do_copy(void)
64945 {
64946 if (count >= body_len) {
64947- sys_write(wfd, victim, body_len);
64948+ sys_write(wfd, (char __force_user *)victim, body_len);
64949 sys_close(wfd);
64950- do_utime(vcollected, mtime);
64951+ do_utime((char __force_user *)vcollected, mtime);
64952 kfree(vcollected);
64953 eat(body_len);
64954 state = SkipIt;
64955 return 0;
64956 } else {
64957- sys_write(wfd, victim, count);
64958+ sys_write(wfd, (char __force_user *)victim, count);
64959 body_len -= count;
64960 eat(count);
64961 return 1;
64962@@ -355,9 +355,9 @@ static int __init do_symlink(void)
64963 {
64964 collected[N_ALIGN(name_len) + body_len] = '\0';
64965 clean_path(collected, 0);
64966- sys_symlink(collected + N_ALIGN(name_len), collected);
64967- sys_lchown(collected, uid, gid);
64968- do_utime(collected, mtime);
64969+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
64970+ sys_lchown((char __force_user *)collected, uid, gid);
64971+ do_utime((char __force_user *)collected, mtime);
64972 state = SkipIt;
64973 next_state = Reset;
64974 return 0;
64975diff --git a/init/main.c b/init/main.c
64976index ff49a6d..5fa0429 100644
64977--- a/init/main.c
64978+++ b/init/main.c
64979@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
64980 extern void tc_init(void);
64981 #endif
64982
64983+extern void grsecurity_init(void);
64984+
64985 /*
64986 * Debug helper: via this flag we know that we are in 'early bootup code'
64987 * where only the boot processor is running with IRQ disabled. This means
64988@@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
64989
64990 __setup("reset_devices", set_reset_devices);
64991
64992+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
64993+extern char pax_enter_kernel_user[];
64994+extern char pax_exit_kernel_user[];
64995+extern pgdval_t clone_pgd_mask;
64996+#endif
64997+
64998+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
64999+static int __init setup_pax_nouderef(char *str)
65000+{
65001+#ifdef CONFIG_X86_32
65002+ unsigned int cpu;
65003+ struct desc_struct *gdt;
65004+
65005+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65006+ gdt = get_cpu_gdt_table(cpu);
65007+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65008+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65009+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65010+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65011+ }
65012+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65013+#else
65014+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65015+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65016+ clone_pgd_mask = ~(pgdval_t)0UL;
65017+#endif
65018+
65019+ return 0;
65020+}
65021+early_param("pax_nouderef", setup_pax_nouderef);
65022+#endif
65023+
65024+#ifdef CONFIG_PAX_SOFTMODE
65025+int pax_softmode;
65026+
65027+static int __init setup_pax_softmode(char *str)
65028+{
65029+ get_option(&str, &pax_softmode);
65030+ return 1;
65031+}
65032+__setup("pax_softmode=", setup_pax_softmode);
65033+#endif
65034+
65035 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65036 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65037 static const char *panic_later, *panic_param;
65038@@ -675,6 +720,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65039 {
65040 int count = preempt_count();
65041 int ret;
65042+ const char *msg1 = "", *msg2 = "";
65043
65044 if (initcall_debug)
65045 ret = do_one_initcall_debug(fn);
65046@@ -687,15 +733,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65047 sprintf(msgbuf, "error code %d ", ret);
65048
65049 if (preempt_count() != count) {
65050- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65051+ msg1 = " preemption imbalance";
65052 preempt_count() = count;
65053 }
65054 if (irqs_disabled()) {
65055- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65056+ msg2 = " disabled interrupts";
65057 local_irq_enable();
65058 }
65059- if (msgbuf[0]) {
65060- printk("initcall %pF returned with %s\n", fn, msgbuf);
65061+ if (msgbuf[0] || *msg1 || *msg2) {
65062+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65063 }
65064
65065 return ret;
65066@@ -814,7 +860,7 @@ static int __init kernel_init(void * unused)
65067 do_basic_setup();
65068
65069 /* Open the /dev/console on the rootfs, this should never fail */
65070- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65071+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65072 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65073
65074 (void) sys_dup(0);
65075@@ -827,11 +873,13 @@ static int __init kernel_init(void * unused)
65076 if (!ramdisk_execute_command)
65077 ramdisk_execute_command = "/init";
65078
65079- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65080+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65081 ramdisk_execute_command = NULL;
65082 prepare_namespace();
65083 }
65084
65085+ grsecurity_init();
65086+
65087 /*
65088 * Ok, we have completed the initial bootup, and
65089 * we're essentially up and running. Get rid of the
65090diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65091index 86ee272..773d937 100644
65092--- a/ipc/mqueue.c
65093+++ b/ipc/mqueue.c
65094@@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65095 mq_bytes = (mq_msg_tblsz +
65096 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
65097
65098+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65099 spin_lock(&mq_lock);
65100 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65101 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65102diff --git a/ipc/msg.c b/ipc/msg.c
65103index 7385de2..a8180e08 100644
65104--- a/ipc/msg.c
65105+++ b/ipc/msg.c
65106@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65107 return security_msg_queue_associate(msq, msgflg);
65108 }
65109
65110+static struct ipc_ops msg_ops = {
65111+ .getnew = newque,
65112+ .associate = msg_security,
65113+ .more_checks = NULL
65114+};
65115+
65116 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65117 {
65118 struct ipc_namespace *ns;
65119- struct ipc_ops msg_ops;
65120 struct ipc_params msg_params;
65121
65122 ns = current->nsproxy->ipc_ns;
65123
65124- msg_ops.getnew = newque;
65125- msg_ops.associate = msg_security;
65126- msg_ops.more_checks = NULL;
65127-
65128 msg_params.key = key;
65129 msg_params.flg = msgflg;
65130
65131diff --git a/ipc/sem.c b/ipc/sem.c
65132index 5215a81..cfc0cac 100644
65133--- a/ipc/sem.c
65134+++ b/ipc/sem.c
65135@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65136 return 0;
65137 }
65138
65139+static struct ipc_ops sem_ops = {
65140+ .getnew = newary,
65141+ .associate = sem_security,
65142+ .more_checks = sem_more_checks
65143+};
65144+
65145 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65146 {
65147 struct ipc_namespace *ns;
65148- struct ipc_ops sem_ops;
65149 struct ipc_params sem_params;
65150
65151 ns = current->nsproxy->ipc_ns;
65152@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65153 if (nsems < 0 || nsems > ns->sc_semmsl)
65154 return -EINVAL;
65155
65156- sem_ops.getnew = newary;
65157- sem_ops.associate = sem_security;
65158- sem_ops.more_checks = sem_more_checks;
65159-
65160 sem_params.key = key;
65161 sem_params.flg = semflg;
65162 sem_params.u.nsems = nsems;
65163diff --git a/ipc/shm.c b/ipc/shm.c
65164index b76be5b..859e750 100644
65165--- a/ipc/shm.c
65166+++ b/ipc/shm.c
65167@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65168 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65169 #endif
65170
65171+#ifdef CONFIG_GRKERNSEC
65172+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65173+ const time_t shm_createtime, const uid_t cuid,
65174+ const int shmid);
65175+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65176+ const time_t shm_createtime);
65177+#endif
65178+
65179 void shm_init_ns(struct ipc_namespace *ns)
65180 {
65181 ns->shm_ctlmax = SHMMAX;
65182@@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65183 shp->shm_lprid = 0;
65184 shp->shm_atim = shp->shm_dtim = 0;
65185 shp->shm_ctim = get_seconds();
65186+#ifdef CONFIG_GRKERNSEC
65187+ {
65188+ struct timespec timeval;
65189+ do_posix_clock_monotonic_gettime(&timeval);
65190+
65191+ shp->shm_createtime = timeval.tv_sec;
65192+ }
65193+#endif
65194 shp->shm_segsz = size;
65195 shp->shm_nattch = 0;
65196 shp->shm_file = file;
65197@@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65198 return 0;
65199 }
65200
65201+static struct ipc_ops shm_ops = {
65202+ .getnew = newseg,
65203+ .associate = shm_security,
65204+ .more_checks = shm_more_checks
65205+};
65206+
65207 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65208 {
65209 struct ipc_namespace *ns;
65210- struct ipc_ops shm_ops;
65211 struct ipc_params shm_params;
65212
65213 ns = current->nsproxy->ipc_ns;
65214
65215- shm_ops.getnew = newseg;
65216- shm_ops.associate = shm_security;
65217- shm_ops.more_checks = shm_more_checks;
65218-
65219 shm_params.key = key;
65220 shm_params.flg = shmflg;
65221 shm_params.u.size = size;
65222@@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65223 f_mode = FMODE_READ | FMODE_WRITE;
65224 }
65225 if (shmflg & SHM_EXEC) {
65226+
65227+#ifdef CONFIG_PAX_MPROTECT
65228+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
65229+ goto out;
65230+#endif
65231+
65232 prot |= PROT_EXEC;
65233 acc_mode |= S_IXUGO;
65234 }
65235@@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65236 if (err)
65237 goto out_unlock;
65238
65239+#ifdef CONFIG_GRKERNSEC
65240+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65241+ shp->shm_perm.cuid, shmid) ||
65242+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65243+ err = -EACCES;
65244+ goto out_unlock;
65245+ }
65246+#endif
65247+
65248 path = shp->shm_file->f_path;
65249 path_get(&path);
65250 shp->shm_nattch++;
65251+#ifdef CONFIG_GRKERNSEC
65252+ shp->shm_lapid = current->pid;
65253+#endif
65254 size = i_size_read(path.dentry->d_inode);
65255 shm_unlock(shp);
65256
65257diff --git a/kernel/acct.c b/kernel/acct.c
65258index 02e6167..54824f7 100644
65259--- a/kernel/acct.c
65260+++ b/kernel/acct.c
65261@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65262 */
65263 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65264 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65265- file->f_op->write(file, (char *)&ac,
65266+ file->f_op->write(file, (char __force_user *)&ac,
65267 sizeof(acct_t), &file->f_pos);
65268 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65269 set_fs(fs);
65270diff --git a/kernel/audit.c b/kernel/audit.c
65271index bb0eb5b..cf2a03a 100644
65272--- a/kernel/audit.c
65273+++ b/kernel/audit.c
65274@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65275 3) suppressed due to audit_rate_limit
65276 4) suppressed due to audit_backlog_limit
65277 */
65278-static atomic_t audit_lost = ATOMIC_INIT(0);
65279+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65280
65281 /* The netlink socket. */
65282 static struct sock *audit_sock;
65283@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65284 unsigned long now;
65285 int print;
65286
65287- atomic_inc(&audit_lost);
65288+ atomic_inc_unchecked(&audit_lost);
65289
65290 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65291
65292@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65293 printk(KERN_WARNING
65294 "audit: audit_lost=%d audit_rate_limit=%d "
65295 "audit_backlog_limit=%d\n",
65296- atomic_read(&audit_lost),
65297+ atomic_read_unchecked(&audit_lost),
65298 audit_rate_limit,
65299 audit_backlog_limit);
65300 audit_panic(message);
65301@@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65302 status_set.pid = audit_pid;
65303 status_set.rate_limit = audit_rate_limit;
65304 status_set.backlog_limit = audit_backlog_limit;
65305- status_set.lost = atomic_read(&audit_lost);
65306+ status_set.lost = atomic_read_unchecked(&audit_lost);
65307 status_set.backlog = skb_queue_len(&audit_skb_queue);
65308 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65309 &status_set, sizeof(status_set));
65310diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65311index af1de0f..06dfe57 100644
65312--- a/kernel/auditsc.c
65313+++ b/kernel/auditsc.c
65314@@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65315 }
65316
65317 /* global counter which is incremented every time something logs in */
65318-static atomic_t session_id = ATOMIC_INIT(0);
65319+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65320
65321 /**
65322 * audit_set_loginuid - set current task's audit_context loginuid
65323@@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
65324 return -EPERM;
65325 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65326
65327- sessionid = atomic_inc_return(&session_id);
65328+ sessionid = atomic_inc_return_unchecked(&session_id);
65329 if (context && context->in_syscall) {
65330 struct audit_buffer *ab;
65331
65332diff --git a/kernel/capability.c b/kernel/capability.c
65333index 3f1adb6..c564db0 100644
65334--- a/kernel/capability.c
65335+++ b/kernel/capability.c
65336@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65337 * before modification is attempted and the application
65338 * fails.
65339 */
65340+ if (tocopy > ARRAY_SIZE(kdata))
65341+ return -EFAULT;
65342+
65343 if (copy_to_user(dataptr, kdata, tocopy
65344 * sizeof(struct __user_cap_data_struct))) {
65345 return -EFAULT;
65346@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65347 int ret;
65348
65349 rcu_read_lock();
65350- ret = security_capable(__task_cred(t), ns, cap);
65351+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65352+ gr_task_is_capable(t, __task_cred(t), cap);
65353 rcu_read_unlock();
65354
65355- return (ret == 0);
65356+ return ret;
65357 }
65358
65359 /**
65360@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65361 int ret;
65362
65363 rcu_read_lock();
65364- ret = security_capable_noaudit(__task_cred(t), ns, cap);
65365+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65366 rcu_read_unlock();
65367
65368- return (ret == 0);
65369+ return ret;
65370 }
65371
65372 /**
65373@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65374 BUG();
65375 }
65376
65377- if (security_capable(current_cred(), ns, cap) == 0) {
65378+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65379 current->flags |= PF_SUPERPRIV;
65380 return true;
65381 }
65382@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65383 }
65384 EXPORT_SYMBOL(ns_capable);
65385
65386+bool ns_capable_nolog(struct user_namespace *ns, int cap)
65387+{
65388+ if (unlikely(!cap_valid(cap))) {
65389+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65390+ BUG();
65391+ }
65392+
65393+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65394+ current->flags |= PF_SUPERPRIV;
65395+ return true;
65396+ }
65397+ return false;
65398+}
65399+EXPORT_SYMBOL(ns_capable_nolog);
65400+
65401 /**
65402 * capable - Determine if the current task has a superior capability in effect
65403 * @cap: The capability to be tested for
65404@@ -408,6 +427,12 @@ bool capable(int cap)
65405 }
65406 EXPORT_SYMBOL(capable);
65407
65408+bool capable_nolog(int cap)
65409+{
65410+ return ns_capable_nolog(&init_user_ns, cap);
65411+}
65412+EXPORT_SYMBOL(capable_nolog);
65413+
65414 /**
65415 * nsown_capable - Check superior capability to one's own user_ns
65416 * @cap: The capability in question
65417diff --git a/kernel/compat.c b/kernel/compat.c
65418index a6d0649..f44fb27 100644
65419--- a/kernel/compat.c
65420+++ b/kernel/compat.c
65421@@ -13,6 +13,7 @@
65422
65423 #include <linux/linkage.h>
65424 #include <linux/compat.h>
65425+#include <linux/module.h>
65426 #include <linux/errno.h>
65427 #include <linux/time.h>
65428 #include <linux/signal.h>
65429@@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65430 mm_segment_t oldfs;
65431 long ret;
65432
65433- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65434+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65435 oldfs = get_fs();
65436 set_fs(KERNEL_DS);
65437 ret = hrtimer_nanosleep_restart(restart);
65438@@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65439 oldfs = get_fs();
65440 set_fs(KERNEL_DS);
65441 ret = hrtimer_nanosleep(&tu,
65442- rmtp ? (struct timespec __user *)&rmt : NULL,
65443+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
65444 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65445 set_fs(oldfs);
65446
65447@@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65448 mm_segment_t old_fs = get_fs();
65449
65450 set_fs(KERNEL_DS);
65451- ret = sys_sigpending((old_sigset_t __user *) &s);
65452+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
65453 set_fs(old_fs);
65454 if (ret == 0)
65455 ret = put_user(s, set);
65456@@ -399,7 +400,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65457 mm_segment_t old_fs = get_fs();
65458
65459 set_fs(KERNEL_DS);
65460- ret = sys_old_getrlimit(resource, &r);
65461+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65462 set_fs(old_fs);
65463
65464 if (!ret) {
65465@@ -471,7 +472,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65466 mm_segment_t old_fs = get_fs();
65467
65468 set_fs(KERNEL_DS);
65469- ret = sys_getrusage(who, (struct rusage __user *) &r);
65470+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65471 set_fs(old_fs);
65472
65473 if (ret)
65474@@ -498,8 +499,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65475 set_fs (KERNEL_DS);
65476 ret = sys_wait4(pid,
65477 (stat_addr ?
65478- (unsigned int __user *) &status : NULL),
65479- options, (struct rusage __user *) &r);
65480+ (unsigned int __force_user *) &status : NULL),
65481+ options, (struct rusage __force_user *) &r);
65482 set_fs (old_fs);
65483
65484 if (ret > 0) {
65485@@ -524,8 +525,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65486 memset(&info, 0, sizeof(info));
65487
65488 set_fs(KERNEL_DS);
65489- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65490- uru ? (struct rusage __user *)&ru : NULL);
65491+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65492+ uru ? (struct rusage __force_user *)&ru : NULL);
65493 set_fs(old_fs);
65494
65495 if ((ret < 0) || (info.si_signo == 0))
65496@@ -655,8 +656,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65497 oldfs = get_fs();
65498 set_fs(KERNEL_DS);
65499 err = sys_timer_settime(timer_id, flags,
65500- (struct itimerspec __user *) &newts,
65501- (struct itimerspec __user *) &oldts);
65502+ (struct itimerspec __force_user *) &newts,
65503+ (struct itimerspec __force_user *) &oldts);
65504 set_fs(oldfs);
65505 if (!err && old && put_compat_itimerspec(old, &oldts))
65506 return -EFAULT;
65507@@ -673,7 +674,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65508 oldfs = get_fs();
65509 set_fs(KERNEL_DS);
65510 err = sys_timer_gettime(timer_id,
65511- (struct itimerspec __user *) &ts);
65512+ (struct itimerspec __force_user *) &ts);
65513 set_fs(oldfs);
65514 if (!err && put_compat_itimerspec(setting, &ts))
65515 return -EFAULT;
65516@@ -692,7 +693,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65517 oldfs = get_fs();
65518 set_fs(KERNEL_DS);
65519 err = sys_clock_settime(which_clock,
65520- (struct timespec __user *) &ts);
65521+ (struct timespec __force_user *) &ts);
65522 set_fs(oldfs);
65523 return err;
65524 }
65525@@ -707,7 +708,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65526 oldfs = get_fs();
65527 set_fs(KERNEL_DS);
65528 err = sys_clock_gettime(which_clock,
65529- (struct timespec __user *) &ts);
65530+ (struct timespec __force_user *) &ts);
65531 set_fs(oldfs);
65532 if (!err && put_compat_timespec(&ts, tp))
65533 return -EFAULT;
65534@@ -727,7 +728,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65535
65536 oldfs = get_fs();
65537 set_fs(KERNEL_DS);
65538- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65539+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65540 set_fs(oldfs);
65541
65542 err = compat_put_timex(utp, &txc);
65543@@ -747,7 +748,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65544 oldfs = get_fs();
65545 set_fs(KERNEL_DS);
65546 err = sys_clock_getres(which_clock,
65547- (struct timespec __user *) &ts);
65548+ (struct timespec __force_user *) &ts);
65549 set_fs(oldfs);
65550 if (!err && tp && put_compat_timespec(&ts, tp))
65551 return -EFAULT;
65552@@ -759,9 +760,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65553 long err;
65554 mm_segment_t oldfs;
65555 struct timespec tu;
65556- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65557+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65558
65559- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65560+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65561 oldfs = get_fs();
65562 set_fs(KERNEL_DS);
65563 err = clock_nanosleep_restart(restart);
65564@@ -793,8 +794,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
65565 oldfs = get_fs();
65566 set_fs(KERNEL_DS);
65567 err = sys_clock_nanosleep(which_clock, flags,
65568- (struct timespec __user *) &in,
65569- (struct timespec __user *) &out);
65570+ (struct timespec __force_user *) &in,
65571+ (struct timespec __force_user *) &out);
65572 set_fs(oldfs);
65573
65574 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
65575diff --git a/kernel/configs.c b/kernel/configs.c
65576index 42e8fa0..9e7406b 100644
65577--- a/kernel/configs.c
65578+++ b/kernel/configs.c
65579@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
65580 struct proc_dir_entry *entry;
65581
65582 /* create the current config file */
65583+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
65584+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
65585+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
65586+ &ikconfig_file_ops);
65587+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65588+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
65589+ &ikconfig_file_ops);
65590+#endif
65591+#else
65592 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
65593 &ikconfig_file_ops);
65594+#endif
65595+
65596 if (!entry)
65597 return -ENOMEM;
65598
65599diff --git a/kernel/cred.c b/kernel/cred.c
65600index 48c6fd3..8398912 100644
65601--- a/kernel/cred.c
65602+++ b/kernel/cred.c
65603@@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
65604 validate_creds(cred);
65605 put_cred(cred);
65606 }
65607+
65608+#ifdef CONFIG_GRKERNSEC_SETXID
65609+ cred = (struct cred *) tsk->delayed_cred;
65610+ if (cred) {
65611+ tsk->delayed_cred = NULL;
65612+ validate_creds(cred);
65613+ put_cred(cred);
65614+ }
65615+#endif
65616 }
65617
65618 /**
65619@@ -472,7 +481,7 @@ error_put:
65620 * Always returns 0 thus allowing this function to be tail-called at the end
65621 * of, say, sys_setgid().
65622 */
65623-int commit_creds(struct cred *new)
65624+static int __commit_creds(struct cred *new)
65625 {
65626 struct task_struct *task = current;
65627 const struct cred *old = task->real_cred;
65628@@ -491,6 +500,8 @@ int commit_creds(struct cred *new)
65629
65630 get_cred(new); /* we will require a ref for the subj creds too */
65631
65632+ gr_set_role_label(task, new->uid, new->gid);
65633+
65634 /* dumpability changes */
65635 if (old->euid != new->euid ||
65636 old->egid != new->egid ||
65637@@ -540,6 +551,101 @@ int commit_creds(struct cred *new)
65638 put_cred(old);
65639 return 0;
65640 }
65641+#ifdef CONFIG_GRKERNSEC_SETXID
65642+extern int set_user(struct cred *new);
65643+
65644+void gr_delayed_cred_worker(void)
65645+{
65646+ const struct cred *new = current->delayed_cred;
65647+ struct cred *ncred;
65648+
65649+ current->delayed_cred = NULL;
65650+
65651+ if (current_uid() && new != NULL) {
65652+ // from doing get_cred on it when queueing this
65653+ put_cred(new);
65654+ return;
65655+ } else if (new == NULL)
65656+ return;
65657+
65658+ ncred = prepare_creds();
65659+ if (!ncred)
65660+ goto die;
65661+ // uids
65662+ ncred->uid = new->uid;
65663+ ncred->euid = new->euid;
65664+ ncred->suid = new->suid;
65665+ ncred->fsuid = new->fsuid;
65666+ // gids
65667+ ncred->gid = new->gid;
65668+ ncred->egid = new->egid;
65669+ ncred->sgid = new->sgid;
65670+ ncred->fsgid = new->fsgid;
65671+ // groups
65672+ if (set_groups(ncred, new->group_info) < 0) {
65673+ abort_creds(ncred);
65674+ goto die;
65675+ }
65676+ // caps
65677+ ncred->securebits = new->securebits;
65678+ ncred->cap_inheritable = new->cap_inheritable;
65679+ ncred->cap_permitted = new->cap_permitted;
65680+ ncred->cap_effective = new->cap_effective;
65681+ ncred->cap_bset = new->cap_bset;
65682+
65683+ if (set_user(ncred)) {
65684+ abort_creds(ncred);
65685+ goto die;
65686+ }
65687+
65688+ // from doing get_cred on it when queueing this
65689+ put_cred(new);
65690+
65691+ __commit_creds(ncred);
65692+ return;
65693+die:
65694+ // from doing get_cred on it when queueing this
65695+ put_cred(new);
65696+ do_group_exit(SIGKILL);
65697+}
65698+#endif
65699+
65700+int commit_creds(struct cred *new)
65701+{
65702+#ifdef CONFIG_GRKERNSEC_SETXID
65703+ int ret;
65704+ int schedule_it = 0;
65705+ struct task_struct *t;
65706+
65707+ /* we won't get called with tasklist_lock held for writing
65708+ and interrupts disabled as the cred struct in that case is
65709+ init_cred
65710+ */
65711+ if (grsec_enable_setxid && !current_is_single_threaded() &&
65712+ !current_uid() && new->uid) {
65713+ schedule_it = 1;
65714+ }
65715+ ret = __commit_creds(new);
65716+ if (schedule_it) {
65717+ rcu_read_lock();
65718+ read_lock(&tasklist_lock);
65719+ for (t = next_thread(current); t != current;
65720+ t = next_thread(t)) {
65721+ if (t->delayed_cred == NULL) {
65722+ t->delayed_cred = get_cred(new);
65723+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
65724+ set_tsk_need_resched(t);
65725+ }
65726+ }
65727+ read_unlock(&tasklist_lock);
65728+ rcu_read_unlock();
65729+ }
65730+ return ret;
65731+#else
65732+ return __commit_creds(new);
65733+#endif
65734+}
65735+
65736 EXPORT_SYMBOL(commit_creds);
65737
65738 /**
65739diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
65740index 7fda904..59f620c 100644
65741--- a/kernel/debug/debug_core.c
65742+++ b/kernel/debug/debug_core.c
65743@@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
65744 */
65745 static atomic_t masters_in_kgdb;
65746 static atomic_t slaves_in_kgdb;
65747-static atomic_t kgdb_break_tasklet_var;
65748+static atomic_unchecked_t kgdb_break_tasklet_var;
65749 atomic_t kgdb_setting_breakpoint;
65750
65751 struct task_struct *kgdb_usethread;
65752@@ -129,7 +129,7 @@ int kgdb_single_step;
65753 static pid_t kgdb_sstep_pid;
65754
65755 /* to keep track of the CPU which is doing the single stepping*/
65756-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65757+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65758
65759 /*
65760 * If you are debugging a problem where roundup (the collection of
65761@@ -537,7 +537,7 @@ return_normal:
65762 * kernel will only try for the value of sstep_tries before
65763 * giving up and continuing on.
65764 */
65765- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
65766+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
65767 (kgdb_info[cpu].task &&
65768 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
65769 atomic_set(&kgdb_active, -1);
65770@@ -631,8 +631,8 @@ cpu_master_loop:
65771 }
65772
65773 kgdb_restore:
65774- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
65775- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
65776+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
65777+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
65778 if (kgdb_info[sstep_cpu].task)
65779 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
65780 else
65781@@ -829,18 +829,18 @@ static void kgdb_unregister_callbacks(void)
65782 static void kgdb_tasklet_bpt(unsigned long ing)
65783 {
65784 kgdb_breakpoint();
65785- atomic_set(&kgdb_break_tasklet_var, 0);
65786+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
65787 }
65788
65789 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
65790
65791 void kgdb_schedule_breakpoint(void)
65792 {
65793- if (atomic_read(&kgdb_break_tasklet_var) ||
65794+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
65795 atomic_read(&kgdb_active) != -1 ||
65796 atomic_read(&kgdb_setting_breakpoint))
65797 return;
65798- atomic_inc(&kgdb_break_tasklet_var);
65799+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
65800 tasklet_schedule(&kgdb_tasklet_breakpoint);
65801 }
65802 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
65803diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
65804index e2ae734..08a4c5c 100644
65805--- a/kernel/debug/kdb/kdb_main.c
65806+++ b/kernel/debug/kdb/kdb_main.c
65807@@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
65808 list_for_each_entry(mod, kdb_modules, list) {
65809
65810 kdb_printf("%-20s%8u 0x%p ", mod->name,
65811- mod->core_size, (void *)mod);
65812+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
65813 #ifdef CONFIG_MODULE_UNLOAD
65814 kdb_printf("%4ld ", module_refcount(mod));
65815 #endif
65816@@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
65817 kdb_printf(" (Loading)");
65818 else
65819 kdb_printf(" (Live)");
65820- kdb_printf(" 0x%p", mod->module_core);
65821+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
65822
65823 #ifdef CONFIG_MODULE_UNLOAD
65824 {
65825diff --git a/kernel/events/core.c b/kernel/events/core.c
65826index 1b5c081..c375f83 100644
65827--- a/kernel/events/core.c
65828+++ b/kernel/events/core.c
65829@@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
65830 return 0;
65831 }
65832
65833-static atomic64_t perf_event_id;
65834+static atomic64_unchecked_t perf_event_id;
65835
65836 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
65837 enum event_type_t event_type);
65838@@ -2581,7 +2581,7 @@ static void __perf_event_read(void *info)
65839
65840 static inline u64 perf_event_count(struct perf_event *event)
65841 {
65842- return local64_read(&event->count) + atomic64_read(&event->child_count);
65843+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
65844 }
65845
65846 static u64 perf_event_read(struct perf_event *event)
65847@@ -2897,9 +2897,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
65848 mutex_lock(&event->child_mutex);
65849 total += perf_event_read(event);
65850 *enabled += event->total_time_enabled +
65851- atomic64_read(&event->child_total_time_enabled);
65852+ atomic64_read_unchecked(&event->child_total_time_enabled);
65853 *running += event->total_time_running +
65854- atomic64_read(&event->child_total_time_running);
65855+ atomic64_read_unchecked(&event->child_total_time_running);
65856
65857 list_for_each_entry(child, &event->child_list, child_list) {
65858 total += perf_event_read(child);
65859@@ -3306,10 +3306,10 @@ void perf_event_update_userpage(struct perf_event *event)
65860 userpg->offset -= local64_read(&event->hw.prev_count);
65861
65862 userpg->time_enabled = enabled +
65863- atomic64_read(&event->child_total_time_enabled);
65864+ atomic64_read_unchecked(&event->child_total_time_enabled);
65865
65866 userpg->time_running = running +
65867- atomic64_read(&event->child_total_time_running);
65868+ atomic64_read_unchecked(&event->child_total_time_running);
65869
65870 barrier();
65871 ++userpg->lock;
65872@@ -3738,11 +3738,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
65873 values[n++] = perf_event_count(event);
65874 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
65875 values[n++] = enabled +
65876- atomic64_read(&event->child_total_time_enabled);
65877+ atomic64_read_unchecked(&event->child_total_time_enabled);
65878 }
65879 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
65880 values[n++] = running +
65881- atomic64_read(&event->child_total_time_running);
65882+ atomic64_read_unchecked(&event->child_total_time_running);
65883 }
65884 if (read_format & PERF_FORMAT_ID)
65885 values[n++] = primary_event_id(event);
65886@@ -4393,12 +4393,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
65887 * need to add enough zero bytes after the string to handle
65888 * the 64bit alignment we do later.
65889 */
65890- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
65891+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
65892 if (!buf) {
65893 name = strncpy(tmp, "//enomem", sizeof(tmp));
65894 goto got_name;
65895 }
65896- name = d_path(&file->f_path, buf, PATH_MAX);
65897+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
65898 if (IS_ERR(name)) {
65899 name = strncpy(tmp, "//toolong", sizeof(tmp));
65900 goto got_name;
65901@@ -5765,7 +5765,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
65902 event->parent = parent_event;
65903
65904 event->ns = get_pid_ns(current->nsproxy->pid_ns);
65905- event->id = atomic64_inc_return(&perf_event_id);
65906+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
65907
65908 event->state = PERF_EVENT_STATE_INACTIVE;
65909
65910@@ -6287,10 +6287,10 @@ static void sync_child_event(struct perf_event *child_event,
65911 /*
65912 * Add back the child's count to the parent's count:
65913 */
65914- atomic64_add(child_val, &parent_event->child_count);
65915- atomic64_add(child_event->total_time_enabled,
65916+ atomic64_add_unchecked(child_val, &parent_event->child_count);
65917+ atomic64_add_unchecked(child_event->total_time_enabled,
65918 &parent_event->child_total_time_enabled);
65919- atomic64_add(child_event->total_time_running,
65920+ atomic64_add_unchecked(child_event->total_time_running,
65921 &parent_event->child_total_time_running);
65922
65923 /*
65924diff --git a/kernel/exit.c b/kernel/exit.c
65925index 46c8b14..d868958 100644
65926--- a/kernel/exit.c
65927+++ b/kernel/exit.c
65928@@ -58,6 +58,10 @@
65929 #include <asm/pgtable.h>
65930 #include <asm/mmu_context.h>
65931
65932+#ifdef CONFIG_GRKERNSEC
65933+extern rwlock_t grsec_exec_file_lock;
65934+#endif
65935+
65936 static void exit_mm(struct task_struct * tsk);
65937
65938 static void __unhash_process(struct task_struct *p, bool group_dead)
65939@@ -169,6 +173,10 @@ void release_task(struct task_struct * p)
65940 struct task_struct *leader;
65941 int zap_leader;
65942 repeat:
65943+#ifdef CONFIG_NET
65944+ gr_del_task_from_ip_table(p);
65945+#endif
65946+
65947 /* don't need to get the RCU readlock here - the process is dead and
65948 * can't be modifying its own credentials. But shut RCU-lockdep up */
65949 rcu_read_lock();
65950@@ -381,7 +389,7 @@ int allow_signal(int sig)
65951 * know it'll be handled, so that they don't get converted to
65952 * SIGKILL or just silently dropped.
65953 */
65954- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
65955+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
65956 recalc_sigpending();
65957 spin_unlock_irq(&current->sighand->siglock);
65958 return 0;
65959@@ -417,6 +425,17 @@ void daemonize(const char *name, ...)
65960 vsnprintf(current->comm, sizeof(current->comm), name, args);
65961 va_end(args);
65962
65963+#ifdef CONFIG_GRKERNSEC
65964+ write_lock(&grsec_exec_file_lock);
65965+ if (current->exec_file) {
65966+ fput(current->exec_file);
65967+ current->exec_file = NULL;
65968+ }
65969+ write_unlock(&grsec_exec_file_lock);
65970+#endif
65971+
65972+ gr_set_kernel_label(current);
65973+
65974 /*
65975 * If we were started as result of loading a module, close all of the
65976 * user space pages. We don't need them, and if we didn't close them
65977@@ -873,6 +892,8 @@ void do_exit(long code)
65978 struct task_struct *tsk = current;
65979 int group_dead;
65980
65981+ set_fs(USER_DS);
65982+
65983 profile_task_exit(tsk);
65984
65985 WARN_ON(blk_needs_flush_plug(tsk));
65986@@ -889,7 +910,6 @@ void do_exit(long code)
65987 * mm_release()->clear_child_tid() from writing to a user-controlled
65988 * kernel address.
65989 */
65990- set_fs(USER_DS);
65991
65992 ptrace_event(PTRACE_EVENT_EXIT, code);
65993
65994@@ -950,6 +970,9 @@ void do_exit(long code)
65995 tsk->exit_code = code;
65996 taskstats_exit(tsk, group_dead);
65997
65998+ gr_acl_handle_psacct(tsk, code);
65999+ gr_acl_handle_exit();
66000+
66001 exit_mm(tsk);
66002
66003 if (group_dead)
66004@@ -1066,7 +1089,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66005 * Take down every thread in the group. This is called by fatal signals
66006 * as well as by sys_exit_group (below).
66007 */
66008-void
66009+__noreturn void
66010 do_group_exit(int exit_code)
66011 {
66012 struct signal_struct *sig = current->signal;
66013diff --git a/kernel/fork.c b/kernel/fork.c
66014index 423d5a4..881923e 100644
66015--- a/kernel/fork.c
66016+++ b/kernel/fork.c
66017@@ -285,7 +285,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66018 *stackend = STACK_END_MAGIC; /* for overflow detection */
66019
66020 #ifdef CONFIG_CC_STACKPROTECTOR
66021- tsk->stack_canary = get_random_int();
66022+ tsk->stack_canary = pax_get_random_long();
66023 #endif
66024
66025 /*
66026@@ -309,13 +309,77 @@ out:
66027 }
66028
66029 #ifdef CONFIG_MMU
66030+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
66031+{
66032+ struct vm_area_struct *tmp;
66033+ unsigned long charge;
66034+ struct mempolicy *pol;
66035+ struct file *file;
66036+
66037+ charge = 0;
66038+ if (mpnt->vm_flags & VM_ACCOUNT) {
66039+ unsigned long len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66040+ if (security_vm_enough_memory(len))
66041+ goto fail_nomem;
66042+ charge = len;
66043+ }
66044+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66045+ if (!tmp)
66046+ goto fail_nomem;
66047+ *tmp = *mpnt;
66048+ tmp->vm_mm = mm;
66049+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
66050+ pol = mpol_dup(vma_policy(mpnt));
66051+ if (IS_ERR(pol))
66052+ goto fail_nomem_policy;
66053+ vma_set_policy(tmp, pol);
66054+ if (anon_vma_fork(tmp, mpnt))
66055+ goto fail_nomem_anon_vma_fork;
66056+ tmp->vm_flags &= ~VM_LOCKED;
66057+ tmp->vm_next = tmp->vm_prev = NULL;
66058+ tmp->vm_mirror = NULL;
66059+ file = tmp->vm_file;
66060+ if (file) {
66061+ struct inode *inode = file->f_path.dentry->d_inode;
66062+ struct address_space *mapping = file->f_mapping;
66063+
66064+ get_file(file);
66065+ if (tmp->vm_flags & VM_DENYWRITE)
66066+ atomic_dec(&inode->i_writecount);
66067+ mutex_lock(&mapping->i_mmap_mutex);
66068+ if (tmp->vm_flags & VM_SHARED)
66069+ mapping->i_mmap_writable++;
66070+ flush_dcache_mmap_lock(mapping);
66071+ /* insert tmp into the share list, just after mpnt */
66072+ vma_prio_tree_add(tmp, mpnt);
66073+ flush_dcache_mmap_unlock(mapping);
66074+ mutex_unlock(&mapping->i_mmap_mutex);
66075+ }
66076+
66077+ /*
66078+ * Clear hugetlb-related page reserves for children. This only
66079+ * affects MAP_PRIVATE mappings. Faults generated by the child
66080+ * are not guaranteed to succeed, even if read-only
66081+ */
66082+ if (is_vm_hugetlb_page(tmp))
66083+ reset_vma_resv_huge_pages(tmp);
66084+
66085+ return tmp;
66086+
66087+fail_nomem_anon_vma_fork:
66088+ mpol_put(pol);
66089+fail_nomem_policy:
66090+ kmem_cache_free(vm_area_cachep, tmp);
66091+fail_nomem:
66092+ vm_unacct_memory(charge);
66093+ return NULL;
66094+}
66095+
66096 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66097 {
66098 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66099 struct rb_node **rb_link, *rb_parent;
66100 int retval;
66101- unsigned long charge;
66102- struct mempolicy *pol;
66103
66104 down_write(&oldmm->mmap_sem);
66105 flush_cache_dup_mm(oldmm);
66106@@ -327,8 +391,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66107 mm->locked_vm = 0;
66108 mm->mmap = NULL;
66109 mm->mmap_cache = NULL;
66110- mm->free_area_cache = oldmm->mmap_base;
66111- mm->cached_hole_size = ~0UL;
66112+ mm->free_area_cache = oldmm->free_area_cache;
66113+ mm->cached_hole_size = oldmm->cached_hole_size;
66114 mm->map_count = 0;
66115 cpumask_clear(mm_cpumask(mm));
66116 mm->mm_rb = RB_ROOT;
66117@@ -344,8 +408,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66118
66119 prev = NULL;
66120 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66121- struct file *file;
66122-
66123 if (mpnt->vm_flags & VM_DONTCOPY) {
66124 long pages = vma_pages(mpnt);
66125 mm->total_vm -= pages;
66126@@ -353,53 +415,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66127 -pages);
66128 continue;
66129 }
66130- charge = 0;
66131- if (mpnt->vm_flags & VM_ACCOUNT) {
66132- unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66133- if (security_vm_enough_memory(len))
66134- goto fail_nomem;
66135- charge = len;
66136+ tmp = dup_vma(mm, mpnt);
66137+ if (!tmp) {
66138+ retval = -ENOMEM;
66139+ goto out;
66140 }
66141- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66142- if (!tmp)
66143- goto fail_nomem;
66144- *tmp = *mpnt;
66145- INIT_LIST_HEAD(&tmp->anon_vma_chain);
66146- pol = mpol_dup(vma_policy(mpnt));
66147- retval = PTR_ERR(pol);
66148- if (IS_ERR(pol))
66149- goto fail_nomem_policy;
66150- vma_set_policy(tmp, pol);
66151- tmp->vm_mm = mm;
66152- if (anon_vma_fork(tmp, mpnt))
66153- goto fail_nomem_anon_vma_fork;
66154- tmp->vm_flags &= ~VM_LOCKED;
66155- tmp->vm_next = tmp->vm_prev = NULL;
66156- file = tmp->vm_file;
66157- if (file) {
66158- struct inode *inode = file->f_path.dentry->d_inode;
66159- struct address_space *mapping = file->f_mapping;
66160-
66161- get_file(file);
66162- if (tmp->vm_flags & VM_DENYWRITE)
66163- atomic_dec(&inode->i_writecount);
66164- mutex_lock(&mapping->i_mmap_mutex);
66165- if (tmp->vm_flags & VM_SHARED)
66166- mapping->i_mmap_writable++;
66167- flush_dcache_mmap_lock(mapping);
66168- /* insert tmp into the share list, just after mpnt */
66169- vma_prio_tree_add(tmp, mpnt);
66170- flush_dcache_mmap_unlock(mapping);
66171- mutex_unlock(&mapping->i_mmap_mutex);
66172- }
66173-
66174- /*
66175- * Clear hugetlb-related page reserves for children. This only
66176- * affects MAP_PRIVATE mappings. Faults generated by the child
66177- * are not guaranteed to succeed, even if read-only
66178- */
66179- if (is_vm_hugetlb_page(tmp))
66180- reset_vma_resv_huge_pages(tmp);
66181
66182 /*
66183 * Link in the new vma and copy the page table entries.
66184@@ -422,6 +442,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66185 if (retval)
66186 goto out;
66187 }
66188+
66189+#ifdef CONFIG_PAX_SEGMEXEC
66190+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66191+ struct vm_area_struct *mpnt_m;
66192+
66193+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66194+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66195+
66196+ if (!mpnt->vm_mirror)
66197+ continue;
66198+
66199+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66200+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66201+ mpnt->vm_mirror = mpnt_m;
66202+ } else {
66203+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66204+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66205+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66206+ mpnt->vm_mirror->vm_mirror = mpnt;
66207+ }
66208+ }
66209+ BUG_ON(mpnt_m);
66210+ }
66211+#endif
66212+
66213 /* a new mm has just been created */
66214 arch_dup_mmap(oldmm, mm);
66215 retval = 0;
66216@@ -430,14 +475,6 @@ out:
66217 flush_tlb_mm(oldmm);
66218 up_write(&oldmm->mmap_sem);
66219 return retval;
66220-fail_nomem_anon_vma_fork:
66221- mpol_put(pol);
66222-fail_nomem_policy:
66223- kmem_cache_free(vm_area_cachep, tmp);
66224-fail_nomem:
66225- retval = -ENOMEM;
66226- vm_unacct_memory(charge);
66227- goto out;
66228 }
66229
66230 static inline int mm_alloc_pgd(struct mm_struct *mm)
66231@@ -659,8 +696,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66232 return ERR_PTR(err);
66233
66234 mm = get_task_mm(task);
66235- if (mm && mm != current->mm &&
66236- !ptrace_may_access(task, mode)) {
66237+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66238+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66239 mmput(mm);
66240 mm = ERR_PTR(-EACCES);
66241 }
66242@@ -882,13 +919,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66243 spin_unlock(&fs->lock);
66244 return -EAGAIN;
66245 }
66246- fs->users++;
66247+ atomic_inc(&fs->users);
66248 spin_unlock(&fs->lock);
66249 return 0;
66250 }
66251 tsk->fs = copy_fs_struct(fs);
66252 if (!tsk->fs)
66253 return -ENOMEM;
66254+ gr_set_chroot_entries(tsk, &tsk->fs->root);
66255 return 0;
66256 }
66257
66258@@ -1152,6 +1190,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66259 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66260 #endif
66261 retval = -EAGAIN;
66262+
66263+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66264+
66265 if (atomic_read(&p->real_cred->user->processes) >=
66266 task_rlimit(p, RLIMIT_NPROC)) {
66267 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66268@@ -1307,6 +1348,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66269 if (clone_flags & CLONE_THREAD)
66270 p->tgid = current->tgid;
66271
66272+ gr_copy_label(p);
66273+
66274 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
66275 /*
66276 * Clear TID on mm_release()?
66277@@ -1475,6 +1518,8 @@ bad_fork_cleanup_count:
66278 bad_fork_free:
66279 free_task(p);
66280 fork_out:
66281+ gr_log_forkfail(retval);
66282+
66283 return ERR_PTR(retval);
66284 }
66285
66286@@ -1575,6 +1620,8 @@ long do_fork(unsigned long clone_flags,
66287 if (clone_flags & CLONE_PARENT_SETTID)
66288 put_user(nr, parent_tidptr);
66289
66290+ gr_handle_brute_check();
66291+
66292 if (clone_flags & CLONE_VFORK) {
66293 p->vfork_done = &vfork;
66294 init_completion(&vfork);
66295@@ -1673,7 +1720,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66296 return 0;
66297
66298 /* don't need lock here; in the worst case we'll do useless copy */
66299- if (fs->users == 1)
66300+ if (atomic_read(&fs->users) == 1)
66301 return 0;
66302
66303 *new_fsp = copy_fs_struct(fs);
66304@@ -1762,7 +1809,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66305 fs = current->fs;
66306 spin_lock(&fs->lock);
66307 current->fs = new_fs;
66308- if (--fs->users)
66309+ gr_set_chroot_entries(current, &current->fs->root);
66310+ if (atomic_dec_return(&fs->users))
66311 new_fs = NULL;
66312 else
66313 new_fs = fs;
66314diff --git a/kernel/futex.c b/kernel/futex.c
66315index 866c9d5..5c5f828 100644
66316--- a/kernel/futex.c
66317+++ b/kernel/futex.c
66318@@ -54,6 +54,7 @@
66319 #include <linux/mount.h>
66320 #include <linux/pagemap.h>
66321 #include <linux/syscalls.h>
66322+#include <linux/ptrace.h>
66323 #include <linux/signal.h>
66324 #include <linux/export.h>
66325 #include <linux/magic.h>
66326@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66327 struct page *page, *page_head;
66328 int err, ro = 0;
66329
66330+#ifdef CONFIG_PAX_SEGMEXEC
66331+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66332+ return -EFAULT;
66333+#endif
66334+
66335 /*
66336 * The futex address must be "naturally" aligned.
66337 */
66338@@ -2721,6 +2727,7 @@ static int __init futex_init(void)
66339 {
66340 u32 curval;
66341 int i;
66342+ mm_segment_t oldfs;
66343
66344 /*
66345 * This will fail and we want it. Some arch implementations do
66346@@ -2732,8 +2739,11 @@ static int __init futex_init(void)
66347 * implementation, the non-functional ones will return
66348 * -ENOSYS.
66349 */
66350+ oldfs = get_fs();
66351+ set_fs(USER_DS);
66352 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66353 futex_cmpxchg_enabled = 1;
66354+ set_fs(oldfs);
66355
66356 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66357 plist_head_init(&futex_queues[i].chain);
66358diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66359index 9b22d03..6295b62 100644
66360--- a/kernel/gcov/base.c
66361+++ b/kernel/gcov/base.c
66362@@ -102,11 +102,6 @@ void gcov_enable_events(void)
66363 }
66364
66365 #ifdef CONFIG_MODULES
66366-static inline int within(void *addr, void *start, unsigned long size)
66367-{
66368- return ((addr >= start) && (addr < start + size));
66369-}
66370-
66371 /* Update list and generate events when modules are unloaded. */
66372 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66373 void *data)
66374@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66375 prev = NULL;
66376 /* Remove entries located in module from linked list. */
66377 for (info = gcov_info_head; info; info = info->next) {
66378- if (within(info, mod->module_core, mod->core_size)) {
66379+ if (within_module_core_rw((unsigned long)info, mod)) {
66380 if (prev)
66381 prev->next = info->next;
66382 else
66383diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66384index ae34bf5..4e2f3d0 100644
66385--- a/kernel/hrtimer.c
66386+++ b/kernel/hrtimer.c
66387@@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
66388 local_irq_restore(flags);
66389 }
66390
66391-static void run_hrtimer_softirq(struct softirq_action *h)
66392+static void run_hrtimer_softirq(void)
66393 {
66394 hrtimer_peek_ahead_timers();
66395 }
66396diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66397index 01d3b70..9e4d098 100644
66398--- a/kernel/jump_label.c
66399+++ b/kernel/jump_label.c
66400@@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66401
66402 size = (((unsigned long)stop - (unsigned long)start)
66403 / sizeof(struct jump_entry));
66404+ pax_open_kernel();
66405 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66406+ pax_close_kernel();
66407 }
66408
66409 static void jump_label_update(struct jump_label_key *key, int enable);
66410@@ -340,10 +342,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66411 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66412 struct jump_entry *iter;
66413
66414+ pax_open_kernel();
66415 for (iter = iter_start; iter < iter_stop; iter++) {
66416 if (within_module_init(iter->code, mod))
66417 iter->code = 0;
66418 }
66419+ pax_close_kernel();
66420 }
66421
66422 static int
66423diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66424index 079f1d3..a407562 100644
66425--- a/kernel/kallsyms.c
66426+++ b/kernel/kallsyms.c
66427@@ -11,6 +11,9 @@
66428 * Changed the compression method from stem compression to "table lookup"
66429 * compression (see scripts/kallsyms.c for a more complete description)
66430 */
66431+#ifdef CONFIG_GRKERNSEC_HIDESYM
66432+#define __INCLUDED_BY_HIDESYM 1
66433+#endif
66434 #include <linux/kallsyms.h>
66435 #include <linux/module.h>
66436 #include <linux/init.h>
66437@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66438
66439 static inline int is_kernel_inittext(unsigned long addr)
66440 {
66441+ if (system_state != SYSTEM_BOOTING)
66442+ return 0;
66443+
66444 if (addr >= (unsigned long)_sinittext
66445 && addr <= (unsigned long)_einittext)
66446 return 1;
66447 return 0;
66448 }
66449
66450+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66451+#ifdef CONFIG_MODULES
66452+static inline int is_module_text(unsigned long addr)
66453+{
66454+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66455+ return 1;
66456+
66457+ addr = ktla_ktva(addr);
66458+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66459+}
66460+#else
66461+static inline int is_module_text(unsigned long addr)
66462+{
66463+ return 0;
66464+}
66465+#endif
66466+#endif
66467+
66468 static inline int is_kernel_text(unsigned long addr)
66469 {
66470 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66471@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66472
66473 static inline int is_kernel(unsigned long addr)
66474 {
66475+
66476+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66477+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
66478+ return 1;
66479+
66480+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66481+#else
66482 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66483+#endif
66484+
66485 return 1;
66486 return in_gate_area_no_mm(addr);
66487 }
66488
66489 static int is_ksym_addr(unsigned long addr)
66490 {
66491+
66492+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66493+ if (is_module_text(addr))
66494+ return 0;
66495+#endif
66496+
66497 if (all_var)
66498 return is_kernel(addr);
66499
66500@@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66501
66502 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66503 {
66504- iter->name[0] = '\0';
66505 iter->nameoff = get_symbol_offset(new_pos);
66506 iter->pos = new_pos;
66507 }
66508@@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
66509 {
66510 struct kallsym_iter *iter = m->private;
66511
66512+#ifdef CONFIG_GRKERNSEC_HIDESYM
66513+ if (current_uid())
66514+ return 0;
66515+#endif
66516+
66517 /* Some debugging symbols have no name. Ignore them. */
66518 if (!iter->name[0])
66519 return 0;
66520@@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66521 struct kallsym_iter *iter;
66522 int ret;
66523
66524- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66525+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
66526 if (!iter)
66527 return -ENOMEM;
66528 reset_iter(iter, 0);
66529diff --git a/kernel/kexec.c b/kernel/kexec.c
66530index 7b08867..3bac516 100644
66531--- a/kernel/kexec.c
66532+++ b/kernel/kexec.c
66533@@ -1047,7 +1047,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
66534 unsigned long flags)
66535 {
66536 struct compat_kexec_segment in;
66537- struct kexec_segment out, __user *ksegments;
66538+ struct kexec_segment out;
66539+ struct kexec_segment __user *ksegments;
66540 unsigned long i, result;
66541
66542 /* Don't allow clients that don't understand the native
66543diff --git a/kernel/kmod.c b/kernel/kmod.c
66544index a3a46cb..f2e42f8 100644
66545--- a/kernel/kmod.c
66546+++ b/kernel/kmod.c
66547@@ -75,13 +75,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
66548 * If module auto-loading support is disabled then this function
66549 * becomes a no-operation.
66550 */
66551-int __request_module(bool wait, const char *fmt, ...)
66552+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
66553 {
66554- va_list args;
66555 char module_name[MODULE_NAME_LEN];
66556 unsigned int max_modprobes;
66557 int ret;
66558- char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
66559+ char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
66560 static char *envp[] = { "HOME=/",
66561 "TERM=linux",
66562 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
66563@@ -90,9 +89,7 @@ int __request_module(bool wait, const char *fmt, ...)
66564 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
66565 static int kmod_loop_msg;
66566
66567- va_start(args, fmt);
66568- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
66569- va_end(args);
66570+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
66571 if (ret >= MODULE_NAME_LEN)
66572 return -ENAMETOOLONG;
66573
66574@@ -100,6 +97,20 @@ int __request_module(bool wait, const char *fmt, ...)
66575 if (ret)
66576 return ret;
66577
66578+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66579+ if (!current_uid()) {
66580+ /* hack to workaround consolekit/udisks stupidity */
66581+ read_lock(&tasklist_lock);
66582+ if (!strcmp(current->comm, "mount") &&
66583+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
66584+ read_unlock(&tasklist_lock);
66585+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
66586+ return -EPERM;
66587+ }
66588+ read_unlock(&tasklist_lock);
66589+ }
66590+#endif
66591+
66592 /* If modprobe needs a service that is in a module, we get a recursive
66593 * loop. Limit the number of running kmod threads to max_threads/2 or
66594 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
66595@@ -135,6 +146,47 @@ int __request_module(bool wait, const char *fmt, ...)
66596 atomic_dec(&kmod_concurrent);
66597 return ret;
66598 }
66599+
66600+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
66601+{
66602+ va_list args;
66603+ int ret;
66604+
66605+ va_start(args, fmt);
66606+ ret = ____request_module(wait, module_param, fmt, args);
66607+ va_end(args);
66608+
66609+ return ret;
66610+}
66611+
66612+int __request_module(bool wait, const char *fmt, ...)
66613+{
66614+ va_list args;
66615+ int ret;
66616+
66617+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66618+ if (current_uid()) {
66619+ char module_param[MODULE_NAME_LEN];
66620+
66621+ memset(module_param, 0, sizeof(module_param));
66622+
66623+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
66624+
66625+ va_start(args, fmt);
66626+ ret = ____request_module(wait, module_param, fmt, args);
66627+ va_end(args);
66628+
66629+ return ret;
66630+ }
66631+#endif
66632+
66633+ va_start(args, fmt);
66634+ ret = ____request_module(wait, NULL, fmt, args);
66635+ va_end(args);
66636+
66637+ return ret;
66638+}
66639+
66640 EXPORT_SYMBOL(__request_module);
66641 #endif /* CONFIG_MODULES */
66642
66643@@ -224,7 +276,7 @@ static int wait_for_helper(void *data)
66644 *
66645 * Thus the __user pointer cast is valid here.
66646 */
66647- sys_wait4(pid, (int __user *)&ret, 0, NULL);
66648+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
66649
66650 /*
66651 * If ret is 0, either ____call_usermodehelper failed and the
66652diff --git a/kernel/kprobes.c b/kernel/kprobes.c
66653index c62b854..cb67968 100644
66654--- a/kernel/kprobes.c
66655+++ b/kernel/kprobes.c
66656@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
66657 * kernel image and loaded module images reside. This is required
66658 * so x86_64 can correctly handle the %rip-relative fixups.
66659 */
66660- kip->insns = module_alloc(PAGE_SIZE);
66661+ kip->insns = module_alloc_exec(PAGE_SIZE);
66662 if (!kip->insns) {
66663 kfree(kip);
66664 return NULL;
66665@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
66666 */
66667 if (!list_is_singular(&kip->list)) {
66668 list_del(&kip->list);
66669- module_free(NULL, kip->insns);
66670+ module_free_exec(NULL, kip->insns);
66671 kfree(kip);
66672 }
66673 return 1;
66674@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
66675 {
66676 int i, err = 0;
66677 unsigned long offset = 0, size = 0;
66678- char *modname, namebuf[128];
66679+ char *modname, namebuf[KSYM_NAME_LEN];
66680 const char *symbol_name;
66681 void *addr;
66682 struct kprobe_blackpoint *kb;
66683@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
66684 const char *sym = NULL;
66685 unsigned int i = *(loff_t *) v;
66686 unsigned long offset = 0;
66687- char *modname, namebuf[128];
66688+ char *modname, namebuf[KSYM_NAME_LEN];
66689
66690 head = &kprobe_table[i];
66691 preempt_disable();
66692diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
66693index 4e316e1..5501eef 100644
66694--- a/kernel/ksysfs.c
66695+++ b/kernel/ksysfs.c
66696@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
66697 {
66698 if (count+1 > UEVENT_HELPER_PATH_LEN)
66699 return -ENOENT;
66700+ if (!capable(CAP_SYS_ADMIN))
66701+ return -EPERM;
66702 memcpy(uevent_helper, buf, count);
66703 uevent_helper[count] = '\0';
66704 if (count && uevent_helper[count-1] == '\n')
66705diff --git a/kernel/lockdep.c b/kernel/lockdep.c
66706index 8889f7d..95319b7 100644
66707--- a/kernel/lockdep.c
66708+++ b/kernel/lockdep.c
66709@@ -590,6 +590,10 @@ static int static_obj(void *obj)
66710 end = (unsigned long) &_end,
66711 addr = (unsigned long) obj;
66712
66713+#ifdef CONFIG_PAX_KERNEXEC
66714+ start = ktla_ktva(start);
66715+#endif
66716+
66717 /*
66718 * static variable?
66719 */
66720@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
66721 if (!static_obj(lock->key)) {
66722 debug_locks_off();
66723 printk("INFO: trying to register non-static key.\n");
66724+ printk("lock:%pS key:%pS.\n", lock, lock->key);
66725 printk("the code is fine but needs lockdep annotation.\n");
66726 printk("turning off the locking correctness validator.\n");
66727 dump_stack();
66728@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
66729 if (!class)
66730 return 0;
66731 }
66732- atomic_inc((atomic_t *)&class->ops);
66733+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
66734 if (very_verbose(class)) {
66735 printk("\nacquire class [%p] %s", class->key, class->name);
66736 if (class->name_version > 1)
66737diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
66738index 91c32a0..b2c71c5 100644
66739--- a/kernel/lockdep_proc.c
66740+++ b/kernel/lockdep_proc.c
66741@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
66742
66743 static void print_name(struct seq_file *m, struct lock_class *class)
66744 {
66745- char str[128];
66746+ char str[KSYM_NAME_LEN];
66747 const char *name = class->name;
66748
66749 if (!name) {
66750diff --git a/kernel/module.c b/kernel/module.c
66751index 3d56b6f..2a22bd0 100644
66752--- a/kernel/module.c
66753+++ b/kernel/module.c
66754@@ -58,6 +58,7 @@
66755 #include <linux/jump_label.h>
66756 #include <linux/pfn.h>
66757 #include <linux/bsearch.h>
66758+#include <linux/grsecurity.h>
66759
66760 #define CREATE_TRACE_POINTS
66761 #include <trace/events/module.h>
66762@@ -113,7 +114,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
66763
66764 /* Bounds of module allocation, for speeding __module_address.
66765 * Protected by module_mutex. */
66766-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
66767+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
66768+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
66769
66770 int register_module_notifier(struct notifier_block * nb)
66771 {
66772@@ -277,7 +279,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66773 return true;
66774
66775 list_for_each_entry_rcu(mod, &modules, list) {
66776- struct symsearch arr[] = {
66777+ struct symsearch modarr[] = {
66778 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
66779 NOT_GPL_ONLY, false },
66780 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
66781@@ -299,7 +301,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66782 #endif
66783 };
66784
66785- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
66786+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
66787 return true;
66788 }
66789 return false;
66790@@ -431,7 +433,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
66791 static int percpu_modalloc(struct module *mod,
66792 unsigned long size, unsigned long align)
66793 {
66794- if (align > PAGE_SIZE) {
66795+ if (align-1 >= PAGE_SIZE) {
66796 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
66797 mod->name, align, PAGE_SIZE);
66798 align = PAGE_SIZE;
66799@@ -1001,7 +1003,7 @@ struct module_attribute module_uevent =
66800 static ssize_t show_coresize(struct module_attribute *mattr,
66801 struct module_kobject *mk, char *buffer)
66802 {
66803- return sprintf(buffer, "%u\n", mk->mod->core_size);
66804+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
66805 }
66806
66807 static struct module_attribute modinfo_coresize =
66808@@ -1010,7 +1012,7 @@ static struct module_attribute modinfo_coresize =
66809 static ssize_t show_initsize(struct module_attribute *mattr,
66810 struct module_kobject *mk, char *buffer)
66811 {
66812- return sprintf(buffer, "%u\n", mk->mod->init_size);
66813+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
66814 }
66815
66816 static struct module_attribute modinfo_initsize =
66817@@ -1224,7 +1226,7 @@ resolve_symbol_wait(struct module *mod,
66818 */
66819 #ifdef CONFIG_SYSFS
66820
66821-#ifdef CONFIG_KALLSYMS
66822+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66823 static inline bool sect_empty(const Elf_Shdr *sect)
66824 {
66825 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
66826@@ -1690,21 +1692,21 @@ static void set_section_ro_nx(void *base,
66827
66828 static void unset_module_core_ro_nx(struct module *mod)
66829 {
66830- set_page_attributes(mod->module_core + mod->core_text_size,
66831- mod->module_core + mod->core_size,
66832+ set_page_attributes(mod->module_core_rw,
66833+ mod->module_core_rw + mod->core_size_rw,
66834 set_memory_x);
66835- set_page_attributes(mod->module_core,
66836- mod->module_core + mod->core_ro_size,
66837+ set_page_attributes(mod->module_core_rx,
66838+ mod->module_core_rx + mod->core_size_rx,
66839 set_memory_rw);
66840 }
66841
66842 static void unset_module_init_ro_nx(struct module *mod)
66843 {
66844- set_page_attributes(mod->module_init + mod->init_text_size,
66845- mod->module_init + mod->init_size,
66846+ set_page_attributes(mod->module_init_rw,
66847+ mod->module_init_rw + mod->init_size_rw,
66848 set_memory_x);
66849- set_page_attributes(mod->module_init,
66850- mod->module_init + mod->init_ro_size,
66851+ set_page_attributes(mod->module_init_rx,
66852+ mod->module_init_rx + mod->init_size_rx,
66853 set_memory_rw);
66854 }
66855
66856@@ -1715,14 +1717,14 @@ void set_all_modules_text_rw(void)
66857
66858 mutex_lock(&module_mutex);
66859 list_for_each_entry_rcu(mod, &modules, list) {
66860- if ((mod->module_core) && (mod->core_text_size)) {
66861- set_page_attributes(mod->module_core,
66862- mod->module_core + mod->core_text_size,
66863+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
66864+ set_page_attributes(mod->module_core_rx,
66865+ mod->module_core_rx + mod->core_size_rx,
66866 set_memory_rw);
66867 }
66868- if ((mod->module_init) && (mod->init_text_size)) {
66869- set_page_attributes(mod->module_init,
66870- mod->module_init + mod->init_text_size,
66871+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
66872+ set_page_attributes(mod->module_init_rx,
66873+ mod->module_init_rx + mod->init_size_rx,
66874 set_memory_rw);
66875 }
66876 }
66877@@ -1736,14 +1738,14 @@ void set_all_modules_text_ro(void)
66878
66879 mutex_lock(&module_mutex);
66880 list_for_each_entry_rcu(mod, &modules, list) {
66881- if ((mod->module_core) && (mod->core_text_size)) {
66882- set_page_attributes(mod->module_core,
66883- mod->module_core + mod->core_text_size,
66884+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
66885+ set_page_attributes(mod->module_core_rx,
66886+ mod->module_core_rx + mod->core_size_rx,
66887 set_memory_ro);
66888 }
66889- if ((mod->module_init) && (mod->init_text_size)) {
66890- set_page_attributes(mod->module_init,
66891- mod->module_init + mod->init_text_size,
66892+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
66893+ set_page_attributes(mod->module_init_rx,
66894+ mod->module_init_rx + mod->init_size_rx,
66895 set_memory_ro);
66896 }
66897 }
66898@@ -1789,16 +1791,19 @@ static void free_module(struct module *mod)
66899
66900 /* This may be NULL, but that's OK */
66901 unset_module_init_ro_nx(mod);
66902- module_free(mod, mod->module_init);
66903+ module_free(mod, mod->module_init_rw);
66904+ module_free_exec(mod, mod->module_init_rx);
66905 kfree(mod->args);
66906 percpu_modfree(mod);
66907
66908 /* Free lock-classes: */
66909- lockdep_free_key_range(mod->module_core, mod->core_size);
66910+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
66911+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
66912
66913 /* Finally, free the core (containing the module structure) */
66914 unset_module_core_ro_nx(mod);
66915- module_free(mod, mod->module_core);
66916+ module_free_exec(mod, mod->module_core_rx);
66917+ module_free(mod, mod->module_core_rw);
66918
66919 #ifdef CONFIG_MPU
66920 update_protections(current->mm);
66921@@ -1867,10 +1872,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66922 unsigned int i;
66923 int ret = 0;
66924 const struct kernel_symbol *ksym;
66925+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66926+ int is_fs_load = 0;
66927+ int register_filesystem_found = 0;
66928+ char *p;
66929+
66930+ p = strstr(mod->args, "grsec_modharden_fs");
66931+ if (p) {
66932+ char *endptr = p + strlen("grsec_modharden_fs");
66933+ /* copy \0 as well */
66934+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
66935+ is_fs_load = 1;
66936+ }
66937+#endif
66938
66939 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
66940 const char *name = info->strtab + sym[i].st_name;
66941
66942+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66943+ /* it's a real shame this will never get ripped and copied
66944+ upstream! ;(
66945+ */
66946+ if (is_fs_load && !strcmp(name, "register_filesystem"))
66947+ register_filesystem_found = 1;
66948+#endif
66949+
66950 switch (sym[i].st_shndx) {
66951 case SHN_COMMON:
66952 /* We compiled with -fno-common. These are not
66953@@ -1891,7 +1917,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66954 ksym = resolve_symbol_wait(mod, info, name);
66955 /* Ok if resolved. */
66956 if (ksym && !IS_ERR(ksym)) {
66957+ pax_open_kernel();
66958 sym[i].st_value = ksym->value;
66959+ pax_close_kernel();
66960 break;
66961 }
66962
66963@@ -1910,11 +1938,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66964 secbase = (unsigned long)mod_percpu(mod);
66965 else
66966 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
66967+ pax_open_kernel();
66968 sym[i].st_value += secbase;
66969+ pax_close_kernel();
66970 break;
66971 }
66972 }
66973
66974+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66975+ if (is_fs_load && !register_filesystem_found) {
66976+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
66977+ ret = -EPERM;
66978+ }
66979+#endif
66980+
66981 return ret;
66982 }
66983
66984@@ -2018,22 +2055,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
66985 || s->sh_entsize != ~0UL
66986 || strstarts(sname, ".init"))
66987 continue;
66988- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
66989+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66990+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
66991+ else
66992+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
66993 pr_debug("\t%s\n", sname);
66994 }
66995- switch (m) {
66996- case 0: /* executable */
66997- mod->core_size = debug_align(mod->core_size);
66998- mod->core_text_size = mod->core_size;
66999- break;
67000- case 1: /* RO: text and ro-data */
67001- mod->core_size = debug_align(mod->core_size);
67002- mod->core_ro_size = mod->core_size;
67003- break;
67004- case 3: /* whole core */
67005- mod->core_size = debug_align(mod->core_size);
67006- break;
67007- }
67008 }
67009
67010 pr_debug("Init section allocation order:\n");
67011@@ -2047,23 +2074,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67012 || s->sh_entsize != ~0UL
67013 || !strstarts(sname, ".init"))
67014 continue;
67015- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67016- | INIT_OFFSET_MASK);
67017+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67018+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67019+ else
67020+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67021+ s->sh_entsize |= INIT_OFFSET_MASK;
67022 pr_debug("\t%s\n", sname);
67023 }
67024- switch (m) {
67025- case 0: /* executable */
67026- mod->init_size = debug_align(mod->init_size);
67027- mod->init_text_size = mod->init_size;
67028- break;
67029- case 1: /* RO: text and ro-data */
67030- mod->init_size = debug_align(mod->init_size);
67031- mod->init_ro_size = mod->init_size;
67032- break;
67033- case 3: /* whole init */
67034- mod->init_size = debug_align(mod->init_size);
67035- break;
67036- }
67037 }
67038 }
67039
67040@@ -2235,7 +2252,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67041
67042 /* Put symbol section at end of init part of module. */
67043 symsect->sh_flags |= SHF_ALLOC;
67044- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67045+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67046 info->index.sym) | INIT_OFFSET_MASK;
67047 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67048
67049@@ -2250,13 +2267,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67050 }
67051
67052 /* Append room for core symbols at end of core part. */
67053- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67054- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67055- mod->core_size += strtab_size;
67056+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67057+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67058+ mod->core_size_rx += strtab_size;
67059
67060 /* Put string table section at end of init part of module. */
67061 strsect->sh_flags |= SHF_ALLOC;
67062- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67063+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67064 info->index.str) | INIT_OFFSET_MASK;
67065 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67066 }
67067@@ -2274,12 +2291,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67068 /* Make sure we get permanent strtab: don't use info->strtab. */
67069 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67070
67071+ pax_open_kernel();
67072+
67073 /* Set types up while we still have access to sections. */
67074 for (i = 0; i < mod->num_symtab; i++)
67075 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67076
67077- mod->core_symtab = dst = mod->module_core + info->symoffs;
67078- mod->core_strtab = s = mod->module_core + info->stroffs;
67079+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67080+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67081 src = mod->symtab;
67082 *dst = *src;
67083 *s++ = 0;
67084@@ -2292,6 +2311,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67085 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67086 }
67087 mod->core_num_syms = ndst;
67088+
67089+ pax_close_kernel();
67090 }
67091 #else
67092 static inline void layout_symtab(struct module *mod, struct load_info *info)
67093@@ -2325,17 +2346,33 @@ void * __weak module_alloc(unsigned long size)
67094 return size == 0 ? NULL : vmalloc_exec(size);
67095 }
67096
67097-static void *module_alloc_update_bounds(unsigned long size)
67098+static void *module_alloc_update_bounds_rw(unsigned long size)
67099 {
67100 void *ret = module_alloc(size);
67101
67102 if (ret) {
67103 mutex_lock(&module_mutex);
67104 /* Update module bounds. */
67105- if ((unsigned long)ret < module_addr_min)
67106- module_addr_min = (unsigned long)ret;
67107- if ((unsigned long)ret + size > module_addr_max)
67108- module_addr_max = (unsigned long)ret + size;
67109+ if ((unsigned long)ret < module_addr_min_rw)
67110+ module_addr_min_rw = (unsigned long)ret;
67111+ if ((unsigned long)ret + size > module_addr_max_rw)
67112+ module_addr_max_rw = (unsigned long)ret + size;
67113+ mutex_unlock(&module_mutex);
67114+ }
67115+ return ret;
67116+}
67117+
67118+static void *module_alloc_update_bounds_rx(unsigned long size)
67119+{
67120+ void *ret = module_alloc_exec(size);
67121+
67122+ if (ret) {
67123+ mutex_lock(&module_mutex);
67124+ /* Update module bounds. */
67125+ if ((unsigned long)ret < module_addr_min_rx)
67126+ module_addr_min_rx = (unsigned long)ret;
67127+ if ((unsigned long)ret + size > module_addr_max_rx)
67128+ module_addr_max_rx = (unsigned long)ret + size;
67129 mutex_unlock(&module_mutex);
67130 }
67131 return ret;
67132@@ -2512,8 +2549,14 @@ static struct module *setup_load_info(struct load_info *info)
67133 static int check_modinfo(struct module *mod, struct load_info *info)
67134 {
67135 const char *modmagic = get_modinfo(info, "vermagic");
67136+ const char *license = get_modinfo(info, "license");
67137 int err;
67138
67139+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67140+ if (!license || !license_is_gpl_compatible(license))
67141+ return -ENOEXEC;
67142+#endif
67143+
67144 /* This is allowed: modprobe --force will invalidate it. */
67145 if (!modmagic) {
67146 err = try_to_force_load(mod, "bad vermagic");
67147@@ -2536,7 +2579,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67148 }
67149
67150 /* Set up license info based on the info section */
67151- set_license(mod, get_modinfo(info, "license"));
67152+ set_license(mod, license);
67153
67154 return 0;
67155 }
67156@@ -2630,7 +2673,7 @@ static int move_module(struct module *mod, struct load_info *info)
67157 void *ptr;
67158
67159 /* Do the allocs. */
67160- ptr = module_alloc_update_bounds(mod->core_size);
67161+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67162 /*
67163 * The pointer to this block is stored in the module structure
67164 * which is inside the block. Just mark it as not being a
67165@@ -2640,23 +2683,50 @@ static int move_module(struct module *mod, struct load_info *info)
67166 if (!ptr)
67167 return -ENOMEM;
67168
67169- memset(ptr, 0, mod->core_size);
67170- mod->module_core = ptr;
67171+ memset(ptr, 0, mod->core_size_rw);
67172+ mod->module_core_rw = ptr;
67173
67174- ptr = module_alloc_update_bounds(mod->init_size);
67175+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67176 /*
67177 * The pointer to this block is stored in the module structure
67178 * which is inside the block. This block doesn't need to be
67179 * scanned as it contains data and code that will be freed
67180 * after the module is initialized.
67181 */
67182- kmemleak_ignore(ptr);
67183- if (!ptr && mod->init_size) {
67184- module_free(mod, mod->module_core);
67185+ kmemleak_not_leak(ptr);
67186+ if (!ptr && mod->init_size_rw) {
67187+ module_free(mod, mod->module_core_rw);
67188 return -ENOMEM;
67189 }
67190- memset(ptr, 0, mod->init_size);
67191- mod->module_init = ptr;
67192+ memset(ptr, 0, mod->init_size_rw);
67193+ mod->module_init_rw = ptr;
67194+
67195+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67196+ kmemleak_not_leak(ptr);
67197+ if (!ptr) {
67198+ module_free(mod, mod->module_init_rw);
67199+ module_free(mod, mod->module_core_rw);
67200+ return -ENOMEM;
67201+ }
67202+
67203+ pax_open_kernel();
67204+ memset(ptr, 0, mod->core_size_rx);
67205+ pax_close_kernel();
67206+ mod->module_core_rx = ptr;
67207+
67208+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67209+ kmemleak_not_leak(ptr);
67210+ if (!ptr && mod->init_size_rx) {
67211+ module_free_exec(mod, mod->module_core_rx);
67212+ module_free(mod, mod->module_init_rw);
67213+ module_free(mod, mod->module_core_rw);
67214+ return -ENOMEM;
67215+ }
67216+
67217+ pax_open_kernel();
67218+ memset(ptr, 0, mod->init_size_rx);
67219+ pax_close_kernel();
67220+ mod->module_init_rx = ptr;
67221
67222 /* Transfer each section which specifies SHF_ALLOC */
67223 pr_debug("final section addresses:\n");
67224@@ -2667,16 +2737,45 @@ static int move_module(struct module *mod, struct load_info *info)
67225 if (!(shdr->sh_flags & SHF_ALLOC))
67226 continue;
67227
67228- if (shdr->sh_entsize & INIT_OFFSET_MASK)
67229- dest = mod->module_init
67230- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67231- else
67232- dest = mod->module_core + shdr->sh_entsize;
67233+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67234+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67235+ dest = mod->module_init_rw
67236+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67237+ else
67238+ dest = mod->module_init_rx
67239+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67240+ } else {
67241+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67242+ dest = mod->module_core_rw + shdr->sh_entsize;
67243+ else
67244+ dest = mod->module_core_rx + shdr->sh_entsize;
67245+ }
67246+
67247+ if (shdr->sh_type != SHT_NOBITS) {
67248+
67249+#ifdef CONFIG_PAX_KERNEXEC
67250+#ifdef CONFIG_X86_64
67251+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67252+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67253+#endif
67254+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67255+ pax_open_kernel();
67256+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67257+ pax_close_kernel();
67258+ } else
67259+#endif
67260
67261- if (shdr->sh_type != SHT_NOBITS)
67262 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67263+ }
67264 /* Update sh_addr to point to copy in image. */
67265- shdr->sh_addr = (unsigned long)dest;
67266+
67267+#ifdef CONFIG_PAX_KERNEXEC
67268+ if (shdr->sh_flags & SHF_EXECINSTR)
67269+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
67270+ else
67271+#endif
67272+
67273+ shdr->sh_addr = (unsigned long)dest;
67274 pr_debug("\t0x%lx %s\n",
67275 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67276 }
67277@@ -2727,12 +2826,12 @@ static void flush_module_icache(const struct module *mod)
67278 * Do it before processing of module parameters, so the module
67279 * can provide parameter accessor functions of its own.
67280 */
67281- if (mod->module_init)
67282- flush_icache_range((unsigned long)mod->module_init,
67283- (unsigned long)mod->module_init
67284- + mod->init_size);
67285- flush_icache_range((unsigned long)mod->module_core,
67286- (unsigned long)mod->module_core + mod->core_size);
67287+ if (mod->module_init_rx)
67288+ flush_icache_range((unsigned long)mod->module_init_rx,
67289+ (unsigned long)mod->module_init_rx
67290+ + mod->init_size_rx);
67291+ flush_icache_range((unsigned long)mod->module_core_rx,
67292+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
67293
67294 set_fs(old_fs);
67295 }
67296@@ -2802,8 +2901,10 @@ out:
67297 static void module_deallocate(struct module *mod, struct load_info *info)
67298 {
67299 percpu_modfree(mod);
67300- module_free(mod, mod->module_init);
67301- module_free(mod, mod->module_core);
67302+ module_free_exec(mod, mod->module_init_rx);
67303+ module_free_exec(mod, mod->module_core_rx);
67304+ module_free(mod, mod->module_init_rw);
67305+ module_free(mod, mod->module_core_rw);
67306 }
67307
67308 int __weak module_finalize(const Elf_Ehdr *hdr,
67309@@ -2867,9 +2968,38 @@ static struct module *load_module(void __user *umod,
67310 if (err)
67311 goto free_unload;
67312
67313+ /* Now copy in args */
67314+ mod->args = strndup_user(uargs, ~0UL >> 1);
67315+ if (IS_ERR(mod->args)) {
67316+ err = PTR_ERR(mod->args);
67317+ goto free_unload;
67318+ }
67319+
67320 /* Set up MODINFO_ATTR fields */
67321 setup_modinfo(mod, &info);
67322
67323+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67324+ {
67325+ char *p, *p2;
67326+
67327+ if (strstr(mod->args, "grsec_modharden_netdev")) {
67328+ 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);
67329+ err = -EPERM;
67330+ goto free_modinfo;
67331+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67332+ p += strlen("grsec_modharden_normal");
67333+ p2 = strstr(p, "_");
67334+ if (p2) {
67335+ *p2 = '\0';
67336+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67337+ *p2 = '_';
67338+ }
67339+ err = -EPERM;
67340+ goto free_modinfo;
67341+ }
67342+ }
67343+#endif
67344+
67345 /* Fix up syms, so that st_value is a pointer to location. */
67346 err = simplify_symbols(mod, &info);
67347 if (err < 0)
67348@@ -2885,13 +3015,6 @@ static struct module *load_module(void __user *umod,
67349
67350 flush_module_icache(mod);
67351
67352- /* Now copy in args */
67353- mod->args = strndup_user(uargs, ~0UL >> 1);
67354- if (IS_ERR(mod->args)) {
67355- err = PTR_ERR(mod->args);
67356- goto free_arch_cleanup;
67357- }
67358-
67359 /* Mark state as coming so strong_try_module_get() ignores us. */
67360 mod->state = MODULE_STATE_COMING;
67361
67362@@ -2948,11 +3071,10 @@ static struct module *load_module(void __user *umod,
67363 unlock:
67364 mutex_unlock(&module_mutex);
67365 synchronize_sched();
67366- kfree(mod->args);
67367- free_arch_cleanup:
67368 module_arch_cleanup(mod);
67369 free_modinfo:
67370 free_modinfo(mod);
67371+ kfree(mod->args);
67372 free_unload:
67373 module_unload_free(mod);
67374 free_module:
67375@@ -2993,16 +3115,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67376 MODULE_STATE_COMING, mod);
67377
67378 /* Set RO and NX regions for core */
67379- set_section_ro_nx(mod->module_core,
67380- mod->core_text_size,
67381- mod->core_ro_size,
67382- mod->core_size);
67383+ set_section_ro_nx(mod->module_core_rx,
67384+ mod->core_size_rx,
67385+ mod->core_size_rx,
67386+ mod->core_size_rx);
67387
67388 /* Set RO and NX regions for init */
67389- set_section_ro_nx(mod->module_init,
67390- mod->init_text_size,
67391- mod->init_ro_size,
67392- mod->init_size);
67393+ set_section_ro_nx(mod->module_init_rx,
67394+ mod->init_size_rx,
67395+ mod->init_size_rx,
67396+ mod->init_size_rx);
67397
67398 do_mod_ctors(mod);
67399 /* Start the module */
67400@@ -3048,11 +3170,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67401 mod->strtab = mod->core_strtab;
67402 #endif
67403 unset_module_init_ro_nx(mod);
67404- module_free(mod, mod->module_init);
67405- mod->module_init = NULL;
67406- mod->init_size = 0;
67407- mod->init_ro_size = 0;
67408- mod->init_text_size = 0;
67409+ module_free(mod, mod->module_init_rw);
67410+ module_free_exec(mod, mod->module_init_rx);
67411+ mod->module_init_rw = NULL;
67412+ mod->module_init_rx = NULL;
67413+ mod->init_size_rw = 0;
67414+ mod->init_size_rx = 0;
67415 mutex_unlock(&module_mutex);
67416
67417 return 0;
67418@@ -3083,10 +3206,16 @@ static const char *get_ksymbol(struct module *mod,
67419 unsigned long nextval;
67420
67421 /* At worse, next value is at end of module */
67422- if (within_module_init(addr, mod))
67423- nextval = (unsigned long)mod->module_init+mod->init_text_size;
67424+ if (within_module_init_rx(addr, mod))
67425+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67426+ else if (within_module_init_rw(addr, mod))
67427+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67428+ else if (within_module_core_rx(addr, mod))
67429+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67430+ else if (within_module_core_rw(addr, mod))
67431+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67432 else
67433- nextval = (unsigned long)mod->module_core+mod->core_text_size;
67434+ return NULL;
67435
67436 /* Scan for closest preceding symbol, and next symbol. (ELF
67437 starts real symbols at 1). */
67438@@ -3321,7 +3450,7 @@ static int m_show(struct seq_file *m, void *p)
67439 char buf[8];
67440
67441 seq_printf(m, "%s %u",
67442- mod->name, mod->init_size + mod->core_size);
67443+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67444 print_unload_info(m, mod);
67445
67446 /* Informative for users. */
67447@@ -3330,7 +3459,7 @@ static int m_show(struct seq_file *m, void *p)
67448 mod->state == MODULE_STATE_COMING ? "Loading":
67449 "Live");
67450 /* Used by oprofile and other similar tools. */
67451- seq_printf(m, " 0x%pK", mod->module_core);
67452+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67453
67454 /* Taints info */
67455 if (mod->taints)
67456@@ -3366,7 +3495,17 @@ static const struct file_operations proc_modules_operations = {
67457
67458 static int __init proc_modules_init(void)
67459 {
67460+#ifndef CONFIG_GRKERNSEC_HIDESYM
67461+#ifdef CONFIG_GRKERNSEC_PROC_USER
67462+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67463+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67464+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67465+#else
67466 proc_create("modules", 0, NULL, &proc_modules_operations);
67467+#endif
67468+#else
67469+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67470+#endif
67471 return 0;
67472 }
67473 module_init(proc_modules_init);
67474@@ -3425,12 +3564,12 @@ struct module *__module_address(unsigned long addr)
67475 {
67476 struct module *mod;
67477
67478- if (addr < module_addr_min || addr > module_addr_max)
67479+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67480+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
67481 return NULL;
67482
67483 list_for_each_entry_rcu(mod, &modules, list)
67484- if (within_module_core(addr, mod)
67485- || within_module_init(addr, mod))
67486+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
67487 return mod;
67488 return NULL;
67489 }
67490@@ -3464,11 +3603,20 @@ bool is_module_text_address(unsigned long addr)
67491 */
67492 struct module *__module_text_address(unsigned long addr)
67493 {
67494- struct module *mod = __module_address(addr);
67495+ struct module *mod;
67496+
67497+#ifdef CONFIG_X86_32
67498+ addr = ktla_ktva(addr);
67499+#endif
67500+
67501+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67502+ return NULL;
67503+
67504+ mod = __module_address(addr);
67505+
67506 if (mod) {
67507 /* Make sure it's within the text section. */
67508- if (!within(addr, mod->module_init, mod->init_text_size)
67509- && !within(addr, mod->module_core, mod->core_text_size))
67510+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
67511 mod = NULL;
67512 }
67513 return mod;
67514diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
67515index 7e3443f..b2a1e6b 100644
67516--- a/kernel/mutex-debug.c
67517+++ b/kernel/mutex-debug.c
67518@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
67519 }
67520
67521 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67522- struct thread_info *ti)
67523+ struct task_struct *task)
67524 {
67525 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
67526
67527 /* Mark the current thread as blocked on the lock: */
67528- ti->task->blocked_on = waiter;
67529+ task->blocked_on = waiter;
67530 }
67531
67532 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67533- struct thread_info *ti)
67534+ struct task_struct *task)
67535 {
67536 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
67537- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
67538- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
67539- ti->task->blocked_on = NULL;
67540+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
67541+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
67542+ task->blocked_on = NULL;
67543
67544 list_del_init(&waiter->list);
67545 waiter->task = NULL;
67546diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
67547index 0799fd3..d06ae3b 100644
67548--- a/kernel/mutex-debug.h
67549+++ b/kernel/mutex-debug.h
67550@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
67551 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
67552 extern void debug_mutex_add_waiter(struct mutex *lock,
67553 struct mutex_waiter *waiter,
67554- struct thread_info *ti);
67555+ struct task_struct *task);
67556 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67557- struct thread_info *ti);
67558+ struct task_struct *task);
67559 extern void debug_mutex_unlock(struct mutex *lock);
67560 extern void debug_mutex_init(struct mutex *lock, const char *name,
67561 struct lock_class_key *key);
67562diff --git a/kernel/mutex.c b/kernel/mutex.c
67563index 89096dd..f91ebc5 100644
67564--- a/kernel/mutex.c
67565+++ b/kernel/mutex.c
67566@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67567 spin_lock_mutex(&lock->wait_lock, flags);
67568
67569 debug_mutex_lock_common(lock, &waiter);
67570- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
67571+ debug_mutex_add_waiter(lock, &waiter, task);
67572
67573 /* add waiting tasks to the end of the waitqueue (FIFO): */
67574 list_add_tail(&waiter.list, &lock->wait_list);
67575@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67576 * TASK_UNINTERRUPTIBLE case.)
67577 */
67578 if (unlikely(signal_pending_state(state, task))) {
67579- mutex_remove_waiter(lock, &waiter,
67580- task_thread_info(task));
67581+ mutex_remove_waiter(lock, &waiter, task);
67582 mutex_release(&lock->dep_map, 1, ip);
67583 spin_unlock_mutex(&lock->wait_lock, flags);
67584
67585@@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67586 done:
67587 lock_acquired(&lock->dep_map, ip);
67588 /* got the lock - rejoice! */
67589- mutex_remove_waiter(lock, &waiter, current_thread_info());
67590+ mutex_remove_waiter(lock, &waiter, task);
67591 mutex_set_owner(lock);
67592
67593 /* set it to 0 if there are no waiters left: */
67594diff --git a/kernel/padata.c b/kernel/padata.c
67595index b452599..5d68f4e 100644
67596--- a/kernel/padata.c
67597+++ b/kernel/padata.c
67598@@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
67599 padata->pd = pd;
67600 padata->cb_cpu = cb_cpu;
67601
67602- if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
67603- atomic_set(&pd->seq_nr, -1);
67604+ if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
67605+ atomic_set_unchecked(&pd->seq_nr, -1);
67606
67607- padata->seq_nr = atomic_inc_return(&pd->seq_nr);
67608+ padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
67609
67610 target_cpu = padata_cpu_hash(padata);
67611 queue = per_cpu_ptr(pd->pqueue, target_cpu);
67612@@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
67613 padata_init_pqueues(pd);
67614 padata_init_squeues(pd);
67615 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
67616- atomic_set(&pd->seq_nr, -1);
67617+ atomic_set_unchecked(&pd->seq_nr, -1);
67618 atomic_set(&pd->reorder_objects, 0);
67619 atomic_set(&pd->refcnt, 0);
67620 pd->pinst = pinst;
67621diff --git a/kernel/panic.c b/kernel/panic.c
67622index 8ed89a1..e83856a 100644
67623--- a/kernel/panic.c
67624+++ b/kernel/panic.c
67625@@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
67626 const char *board;
67627
67628 printk(KERN_WARNING "------------[ cut here ]------------\n");
67629- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
67630+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
67631 board = dmi_get_system_info(DMI_PRODUCT_NAME);
67632 if (board)
67633 printk(KERN_WARNING "Hardware name: %s\n", board);
67634@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
67635 */
67636 void __stack_chk_fail(void)
67637 {
67638- panic("stack-protector: Kernel stack is corrupted in: %p\n",
67639+ dump_stack();
67640+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
67641 __builtin_return_address(0));
67642 }
67643 EXPORT_SYMBOL(__stack_chk_fail);
67644diff --git a/kernel/pid.c b/kernel/pid.c
67645index 9f08dfa..6765c40 100644
67646--- a/kernel/pid.c
67647+++ b/kernel/pid.c
67648@@ -33,6 +33,7 @@
67649 #include <linux/rculist.h>
67650 #include <linux/bootmem.h>
67651 #include <linux/hash.h>
67652+#include <linux/security.h>
67653 #include <linux/pid_namespace.h>
67654 #include <linux/init_task.h>
67655 #include <linux/syscalls.h>
67656@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
67657
67658 int pid_max = PID_MAX_DEFAULT;
67659
67660-#define RESERVED_PIDS 300
67661+#define RESERVED_PIDS 500
67662
67663 int pid_max_min = RESERVED_PIDS + 1;
67664 int pid_max_max = PID_MAX_LIMIT;
67665@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
67666 */
67667 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
67668 {
67669+ struct task_struct *task;
67670+
67671 rcu_lockdep_assert(rcu_read_lock_held(),
67672 "find_task_by_pid_ns() needs rcu_read_lock()"
67673 " protection");
67674- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67675+
67676+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67677+
67678+ if (gr_pid_is_chrooted(task))
67679+ return NULL;
67680+
67681+ return task;
67682 }
67683
67684 struct task_struct *find_task_by_vpid(pid_t vnr)
67685@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
67686 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
67687 }
67688
67689+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
67690+{
67691+ rcu_lockdep_assert(rcu_read_lock_held(),
67692+ "find_task_by_pid_ns() needs rcu_read_lock()"
67693+ " protection");
67694+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
67695+}
67696+
67697 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
67698 {
67699 struct pid *pid;
67700diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
67701index 125cb67..a4d1c30 100644
67702--- a/kernel/posix-cpu-timers.c
67703+++ b/kernel/posix-cpu-timers.c
67704@@ -6,6 +6,7 @@
67705 #include <linux/posix-timers.h>
67706 #include <linux/errno.h>
67707 #include <linux/math64.h>
67708+#include <linux/security.h>
67709 #include <asm/uaccess.h>
67710 #include <linux/kernel_stat.h>
67711 #include <trace/events/timer.h>
67712@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
67713
67714 static __init int init_posix_cpu_timers(void)
67715 {
67716- struct k_clock process = {
67717+ static struct k_clock process = {
67718 .clock_getres = process_cpu_clock_getres,
67719 .clock_get = process_cpu_clock_get,
67720 .timer_create = process_cpu_timer_create,
67721 .nsleep = process_cpu_nsleep,
67722 .nsleep_restart = process_cpu_nsleep_restart,
67723 };
67724- struct k_clock thread = {
67725+ static struct k_clock thread = {
67726 .clock_getres = thread_cpu_clock_getres,
67727 .clock_get = thread_cpu_clock_get,
67728 .timer_create = thread_cpu_timer_create,
67729diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
67730index 69185ae..cc2847a 100644
67731--- a/kernel/posix-timers.c
67732+++ b/kernel/posix-timers.c
67733@@ -43,6 +43,7 @@
67734 #include <linux/idr.h>
67735 #include <linux/posix-clock.h>
67736 #include <linux/posix-timers.h>
67737+#include <linux/grsecurity.h>
67738 #include <linux/syscalls.h>
67739 #include <linux/wait.h>
67740 #include <linux/workqueue.h>
67741@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
67742 * which we beg off on and pass to do_sys_settimeofday().
67743 */
67744
67745-static struct k_clock posix_clocks[MAX_CLOCKS];
67746+static struct k_clock *posix_clocks[MAX_CLOCKS];
67747
67748 /*
67749 * These ones are defined below.
67750@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
67751 */
67752 static __init int init_posix_timers(void)
67753 {
67754- struct k_clock clock_realtime = {
67755+ static struct k_clock clock_realtime = {
67756 .clock_getres = hrtimer_get_res,
67757 .clock_get = posix_clock_realtime_get,
67758 .clock_set = posix_clock_realtime_set,
67759@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
67760 .timer_get = common_timer_get,
67761 .timer_del = common_timer_del,
67762 };
67763- struct k_clock clock_monotonic = {
67764+ static struct k_clock clock_monotonic = {
67765 .clock_getres = hrtimer_get_res,
67766 .clock_get = posix_ktime_get_ts,
67767 .nsleep = common_nsleep,
67768@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
67769 .timer_get = common_timer_get,
67770 .timer_del = common_timer_del,
67771 };
67772- struct k_clock clock_monotonic_raw = {
67773+ static struct k_clock clock_monotonic_raw = {
67774 .clock_getres = hrtimer_get_res,
67775 .clock_get = posix_get_monotonic_raw,
67776 };
67777- struct k_clock clock_realtime_coarse = {
67778+ static struct k_clock clock_realtime_coarse = {
67779 .clock_getres = posix_get_coarse_res,
67780 .clock_get = posix_get_realtime_coarse,
67781 };
67782- struct k_clock clock_monotonic_coarse = {
67783+ static struct k_clock clock_monotonic_coarse = {
67784 .clock_getres = posix_get_coarse_res,
67785 .clock_get = posix_get_monotonic_coarse,
67786 };
67787- struct k_clock clock_boottime = {
67788+ static struct k_clock clock_boottime = {
67789 .clock_getres = hrtimer_get_res,
67790 .clock_get = posix_get_boottime,
67791 .nsleep = common_nsleep,
67792@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
67793 return;
67794 }
67795
67796- posix_clocks[clock_id] = *new_clock;
67797+ posix_clocks[clock_id] = new_clock;
67798 }
67799 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
67800
67801@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
67802 return (id & CLOCKFD_MASK) == CLOCKFD ?
67803 &clock_posix_dynamic : &clock_posix_cpu;
67804
67805- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
67806+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
67807 return NULL;
67808- return &posix_clocks[id];
67809+ return posix_clocks[id];
67810 }
67811
67812 static int common_timer_create(struct k_itimer *new_timer)
67813@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
67814 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
67815 return -EFAULT;
67816
67817+ /* only the CLOCK_REALTIME clock can be set, all other clocks
67818+ have their clock_set fptr set to a nosettime dummy function
67819+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
67820+ call common_clock_set, which calls do_sys_settimeofday, which
67821+ we hook
67822+ */
67823+
67824 return kc->clock_set(which_clock, &new_tp);
67825 }
67826
67827diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
67828index d523593..68197a4 100644
67829--- a/kernel/power/poweroff.c
67830+++ b/kernel/power/poweroff.c
67831@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
67832 .enable_mask = SYSRQ_ENABLE_BOOT,
67833 };
67834
67835-static int pm_sysrq_init(void)
67836+static int __init pm_sysrq_init(void)
67837 {
67838 register_sysrq_key('o', &sysrq_poweroff_op);
67839 return 0;
67840diff --git a/kernel/power/process.c b/kernel/power/process.c
67841index 7aac07a..2d3c6dc 100644
67842--- a/kernel/power/process.c
67843+++ b/kernel/power/process.c
67844@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
67845 u64 elapsed_csecs64;
67846 unsigned int elapsed_csecs;
67847 bool wakeup = false;
67848+ bool timedout = false;
67849
67850 do_gettimeofday(&start);
67851
67852@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
67853
67854 while (true) {
67855 todo = 0;
67856+ if (time_after(jiffies, end_time))
67857+ timedout = true;
67858 read_lock(&tasklist_lock);
67859 do_each_thread(g, p) {
67860 if (p == current || !freeze_task(p))
67861@@ -60,9 +63,13 @@ static int try_to_freeze_tasks(bool user_only)
67862 * try_to_stop() after schedule() in ptrace/signal
67863 * stop sees TIF_FREEZE.
67864 */
67865- if (!task_is_stopped_or_traced(p) &&
67866- !freezer_should_skip(p))
67867+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
67868 todo++;
67869+ if (timedout) {
67870+ printk(KERN_ERR "Task refusing to freeze:\n");
67871+ sched_show_task(p);
67872+ }
67873+ }
67874 } while_each_thread(g, p);
67875 read_unlock(&tasklist_lock);
67876
67877@@ -71,7 +78,7 @@ static int try_to_freeze_tasks(bool user_only)
67878 todo += wq_busy;
67879 }
67880
67881- if (!todo || time_after(jiffies, end_time))
67882+ if (!todo || timedout)
67883 break;
67884
67885 if (pm_wakeup_pending()) {
67886diff --git a/kernel/printk.c b/kernel/printk.c
67887index 32690a0..cd7c798 100644
67888--- a/kernel/printk.c
67889+++ b/kernel/printk.c
67890@@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
67891 if (from_file && type != SYSLOG_ACTION_OPEN)
67892 return 0;
67893
67894+#ifdef CONFIG_GRKERNSEC_DMESG
67895+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
67896+ return -EPERM;
67897+#endif
67898+
67899 if (syslog_action_restricted(type)) {
67900 if (capable(CAP_SYSLOG))
67901 return 0;
67902diff --git a/kernel/profile.c b/kernel/profile.c
67903index 76b8e77..a2930e8 100644
67904--- a/kernel/profile.c
67905+++ b/kernel/profile.c
67906@@ -39,7 +39,7 @@ struct profile_hit {
67907 /* Oprofile timer tick hook */
67908 static int (*timer_hook)(struct pt_regs *) __read_mostly;
67909
67910-static atomic_t *prof_buffer;
67911+static atomic_unchecked_t *prof_buffer;
67912 static unsigned long prof_len, prof_shift;
67913
67914 int prof_on __read_mostly;
67915@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
67916 hits[i].pc = 0;
67917 continue;
67918 }
67919- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67920+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67921 hits[i].hits = hits[i].pc = 0;
67922 }
67923 }
67924@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67925 * Add the current hit(s) and flush the write-queue out
67926 * to the global buffer:
67927 */
67928- atomic_add(nr_hits, &prof_buffer[pc]);
67929+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
67930 for (i = 0; i < NR_PROFILE_HIT; ++i) {
67931- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67932+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67933 hits[i].pc = hits[i].hits = 0;
67934 }
67935 out:
67936@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67937 {
67938 unsigned long pc;
67939 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
67940- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67941+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67942 }
67943 #endif /* !CONFIG_SMP */
67944
67945@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
67946 return -EFAULT;
67947 buf++; p++; count--; read++;
67948 }
67949- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
67950+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
67951 if (copy_to_user(buf, (void *)pnt, count))
67952 return -EFAULT;
67953 read += count;
67954@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
67955 }
67956 #endif
67957 profile_discard_flip_buffers();
67958- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
67959+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
67960 return count;
67961 }
67962
67963diff --git a/kernel/ptrace.c b/kernel/ptrace.c
67964index 00ab2ca..d237f61 100644
67965--- a/kernel/ptrace.c
67966+++ b/kernel/ptrace.c
67967@@ -285,7 +285,7 @@ static int ptrace_attach(struct task_struct *task, long request,
67968 task->ptrace = PT_PTRACED;
67969 if (seize)
67970 task->ptrace |= PT_SEIZED;
67971- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
67972+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
67973 task->ptrace |= PT_PTRACE_CAP;
67974
67975 __ptrace_link(task, current);
67976@@ -491,7 +491,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
67977 break;
67978 return -EIO;
67979 }
67980- if (copy_to_user(dst, buf, retval))
67981+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
67982 return -EFAULT;
67983 copied += retval;
67984 src += retval;
67985@@ -688,7 +688,7 @@ int ptrace_request(struct task_struct *child, long request,
67986 bool seized = child->ptrace & PT_SEIZED;
67987 int ret = -EIO;
67988 siginfo_t siginfo, *si;
67989- void __user *datavp = (void __user *) data;
67990+ void __user *datavp = (__force void __user *) data;
67991 unsigned long __user *datalp = datavp;
67992 unsigned long flags;
67993
67994@@ -890,14 +890,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
67995 goto out;
67996 }
67997
67998+ if (gr_handle_ptrace(child, request)) {
67999+ ret = -EPERM;
68000+ goto out_put_task_struct;
68001+ }
68002+
68003 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68004 ret = ptrace_attach(child, request, data);
68005 /*
68006 * Some architectures need to do book-keeping after
68007 * a ptrace attach.
68008 */
68009- if (!ret)
68010+ if (!ret) {
68011 arch_ptrace_attach(child);
68012+ gr_audit_ptrace(child);
68013+ }
68014 goto out_put_task_struct;
68015 }
68016
68017@@ -923,7 +930,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68018 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68019 if (copied != sizeof(tmp))
68020 return -EIO;
68021- return put_user(tmp, (unsigned long __user *)data);
68022+ return put_user(tmp, (__force unsigned long __user *)data);
68023 }
68024
68025 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68026@@ -1033,14 +1040,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68027 goto out;
68028 }
68029
68030+ if (gr_handle_ptrace(child, request)) {
68031+ ret = -EPERM;
68032+ goto out_put_task_struct;
68033+ }
68034+
68035 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68036 ret = ptrace_attach(child, request, data);
68037 /*
68038 * Some architectures need to do book-keeping after
68039 * a ptrace attach.
68040 */
68041- if (!ret)
68042+ if (!ret) {
68043 arch_ptrace_attach(child);
68044+ gr_audit_ptrace(child);
68045+ }
68046 goto out_put_task_struct;
68047 }
68048
68049diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68050index 977296d..c4744dc 100644
68051--- a/kernel/rcutiny.c
68052+++ b/kernel/rcutiny.c
68053@@ -46,7 +46,7 @@
68054 struct rcu_ctrlblk;
68055 static void invoke_rcu_callbacks(void);
68056 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68057-static void rcu_process_callbacks(struct softirq_action *unused);
68058+static void rcu_process_callbacks(void);
68059 static void __call_rcu(struct rcu_head *head,
68060 void (*func)(struct rcu_head *rcu),
68061 struct rcu_ctrlblk *rcp);
68062@@ -297,7 +297,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68063 rcu_is_callbacks_kthread()));
68064 }
68065
68066-static void rcu_process_callbacks(struct softirq_action *unused)
68067+static void rcu_process_callbacks(void)
68068 {
68069 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68070 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68071diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68072index 9cb1ae4..aac7d3e 100644
68073--- a/kernel/rcutiny_plugin.h
68074+++ b/kernel/rcutiny_plugin.h
68075@@ -920,7 +920,7 @@ static int rcu_kthread(void *arg)
68076 have_rcu_kthread_work = morework;
68077 local_irq_restore(flags);
68078 if (work)
68079- rcu_process_callbacks(NULL);
68080+ rcu_process_callbacks();
68081 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68082 }
68083
68084diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68085index a58ac28..196a3d8 100644
68086--- a/kernel/rcutorture.c
68087+++ b/kernel/rcutorture.c
68088@@ -148,12 +148,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68089 { 0 };
68090 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68091 { 0 };
68092-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68093-static atomic_t n_rcu_torture_alloc;
68094-static atomic_t n_rcu_torture_alloc_fail;
68095-static atomic_t n_rcu_torture_free;
68096-static atomic_t n_rcu_torture_mberror;
68097-static atomic_t n_rcu_torture_error;
68098+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68099+static atomic_unchecked_t n_rcu_torture_alloc;
68100+static atomic_unchecked_t n_rcu_torture_alloc_fail;
68101+static atomic_unchecked_t n_rcu_torture_free;
68102+static atomic_unchecked_t n_rcu_torture_mberror;
68103+static atomic_unchecked_t n_rcu_torture_error;
68104 static long n_rcu_torture_boost_ktrerror;
68105 static long n_rcu_torture_boost_rterror;
68106 static long n_rcu_torture_boost_failure;
68107@@ -243,11 +243,11 @@ rcu_torture_alloc(void)
68108
68109 spin_lock_bh(&rcu_torture_lock);
68110 if (list_empty(&rcu_torture_freelist)) {
68111- atomic_inc(&n_rcu_torture_alloc_fail);
68112+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68113 spin_unlock_bh(&rcu_torture_lock);
68114 return NULL;
68115 }
68116- atomic_inc(&n_rcu_torture_alloc);
68117+ atomic_inc_unchecked(&n_rcu_torture_alloc);
68118 p = rcu_torture_freelist.next;
68119 list_del_init(p);
68120 spin_unlock_bh(&rcu_torture_lock);
68121@@ -260,7 +260,7 @@ rcu_torture_alloc(void)
68122 static void
68123 rcu_torture_free(struct rcu_torture *p)
68124 {
68125- atomic_inc(&n_rcu_torture_free);
68126+ atomic_inc_unchecked(&n_rcu_torture_free);
68127 spin_lock_bh(&rcu_torture_lock);
68128 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68129 spin_unlock_bh(&rcu_torture_lock);
68130@@ -380,7 +380,7 @@ rcu_torture_cb(struct rcu_head *p)
68131 i = rp->rtort_pipe_count;
68132 if (i > RCU_TORTURE_PIPE_LEN)
68133 i = RCU_TORTURE_PIPE_LEN;
68134- atomic_inc(&rcu_torture_wcount[i]);
68135+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68136 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68137 rp->rtort_mbtest = 0;
68138 rcu_torture_free(rp);
68139@@ -427,7 +427,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68140 i = rp->rtort_pipe_count;
68141 if (i > RCU_TORTURE_PIPE_LEN)
68142 i = RCU_TORTURE_PIPE_LEN;
68143- atomic_inc(&rcu_torture_wcount[i]);
68144+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68145 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68146 rp->rtort_mbtest = 0;
68147 list_del(&rp->rtort_free);
68148@@ -916,7 +916,7 @@ rcu_torture_writer(void *arg)
68149 i = old_rp->rtort_pipe_count;
68150 if (i > RCU_TORTURE_PIPE_LEN)
68151 i = RCU_TORTURE_PIPE_LEN;
68152- atomic_inc(&rcu_torture_wcount[i]);
68153+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68154 old_rp->rtort_pipe_count++;
68155 cur_ops->deferred_free(old_rp);
68156 }
68157@@ -997,7 +997,7 @@ static void rcu_torture_timer(unsigned long unused)
68158 return;
68159 }
68160 if (p->rtort_mbtest == 0)
68161- atomic_inc(&n_rcu_torture_mberror);
68162+ atomic_inc_unchecked(&n_rcu_torture_mberror);
68163 spin_lock(&rand_lock);
68164 cur_ops->read_delay(&rand);
68165 n_rcu_torture_timers++;
68166@@ -1061,7 +1061,7 @@ rcu_torture_reader(void *arg)
68167 continue;
68168 }
68169 if (p->rtort_mbtest == 0)
68170- atomic_inc(&n_rcu_torture_mberror);
68171+ atomic_inc_unchecked(&n_rcu_torture_mberror);
68172 cur_ops->read_delay(&rand);
68173 preempt_disable();
68174 pipe_count = p->rtort_pipe_count;
68175@@ -1123,10 +1123,10 @@ rcu_torture_printk(char *page)
68176 rcu_torture_current,
68177 rcu_torture_current_version,
68178 list_empty(&rcu_torture_freelist),
68179- atomic_read(&n_rcu_torture_alloc),
68180- atomic_read(&n_rcu_torture_alloc_fail),
68181- atomic_read(&n_rcu_torture_free),
68182- atomic_read(&n_rcu_torture_mberror),
68183+ atomic_read_unchecked(&n_rcu_torture_alloc),
68184+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68185+ atomic_read_unchecked(&n_rcu_torture_free),
68186+ atomic_read_unchecked(&n_rcu_torture_mberror),
68187 n_rcu_torture_boost_ktrerror,
68188 n_rcu_torture_boost_rterror,
68189 n_rcu_torture_boost_failure,
68190@@ -1136,7 +1136,7 @@ rcu_torture_printk(char *page)
68191 n_online_attempts,
68192 n_offline_successes,
68193 n_offline_attempts);
68194- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68195+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68196 n_rcu_torture_boost_ktrerror != 0 ||
68197 n_rcu_torture_boost_rterror != 0 ||
68198 n_rcu_torture_boost_failure != 0)
68199@@ -1144,7 +1144,7 @@ rcu_torture_printk(char *page)
68200 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68201 if (i > 1) {
68202 cnt += sprintf(&page[cnt], "!!! ");
68203- atomic_inc(&n_rcu_torture_error);
68204+ atomic_inc_unchecked(&n_rcu_torture_error);
68205 WARN_ON_ONCE(1);
68206 }
68207 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68208@@ -1158,7 +1158,7 @@ rcu_torture_printk(char *page)
68209 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68210 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68211 cnt += sprintf(&page[cnt], " %d",
68212- atomic_read(&rcu_torture_wcount[i]));
68213+ atomic_read_unchecked(&rcu_torture_wcount[i]));
68214 }
68215 cnt += sprintf(&page[cnt], "\n");
68216 if (cur_ops->stats)
68217@@ -1600,7 +1600,7 @@ rcu_torture_cleanup(void)
68218
68219 if (cur_ops->cleanup)
68220 cur_ops->cleanup();
68221- if (atomic_read(&n_rcu_torture_error))
68222+ if (atomic_read_unchecked(&n_rcu_torture_error))
68223 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68224 else
68225 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
68226@@ -1664,17 +1664,17 @@ rcu_torture_init(void)
68227
68228 rcu_torture_current = NULL;
68229 rcu_torture_current_version = 0;
68230- atomic_set(&n_rcu_torture_alloc, 0);
68231- atomic_set(&n_rcu_torture_alloc_fail, 0);
68232- atomic_set(&n_rcu_torture_free, 0);
68233- atomic_set(&n_rcu_torture_mberror, 0);
68234- atomic_set(&n_rcu_torture_error, 0);
68235+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68236+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68237+ atomic_set_unchecked(&n_rcu_torture_free, 0);
68238+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68239+ atomic_set_unchecked(&n_rcu_torture_error, 0);
68240 n_rcu_torture_boost_ktrerror = 0;
68241 n_rcu_torture_boost_rterror = 0;
68242 n_rcu_torture_boost_failure = 0;
68243 n_rcu_torture_boosts = 0;
68244 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68245- atomic_set(&rcu_torture_wcount[i], 0);
68246+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68247 for_each_possible_cpu(cpu) {
68248 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68249 per_cpu(rcu_torture_count, cpu)[i] = 0;
68250diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68251index 6c4a672..70f3202 100644
68252--- a/kernel/rcutree.c
68253+++ b/kernel/rcutree.c
68254@@ -363,9 +363,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68255 rcu_prepare_for_idle(smp_processor_id());
68256 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68257 smp_mb__before_atomic_inc(); /* See above. */
68258- atomic_inc(&rdtp->dynticks);
68259+ atomic_inc_unchecked(&rdtp->dynticks);
68260 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68261- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68262+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68263 }
68264
68265 /**
68266@@ -438,10 +438,10 @@ void rcu_irq_exit(void)
68267 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68268 {
68269 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68270- atomic_inc(&rdtp->dynticks);
68271+ atomic_inc_unchecked(&rdtp->dynticks);
68272 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68273 smp_mb__after_atomic_inc(); /* See above. */
68274- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68275+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68276 rcu_cleanup_after_idle(smp_processor_id());
68277 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68278 if (!is_idle_task(current)) {
68279@@ -531,14 +531,14 @@ void rcu_nmi_enter(void)
68280 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68281
68282 if (rdtp->dynticks_nmi_nesting == 0 &&
68283- (atomic_read(&rdtp->dynticks) & 0x1))
68284+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68285 return;
68286 rdtp->dynticks_nmi_nesting++;
68287 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68288- atomic_inc(&rdtp->dynticks);
68289+ atomic_inc_unchecked(&rdtp->dynticks);
68290 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68291 smp_mb__after_atomic_inc(); /* See above. */
68292- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68293+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68294 }
68295
68296 /**
68297@@ -557,9 +557,9 @@ void rcu_nmi_exit(void)
68298 return;
68299 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68300 smp_mb__before_atomic_inc(); /* See above. */
68301- atomic_inc(&rdtp->dynticks);
68302+ atomic_inc_unchecked(&rdtp->dynticks);
68303 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68304- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68305+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68306 }
68307
68308 #ifdef CONFIG_PROVE_RCU
68309@@ -575,7 +575,7 @@ int rcu_is_cpu_idle(void)
68310 int ret;
68311
68312 preempt_disable();
68313- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68314+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68315 preempt_enable();
68316 return ret;
68317 }
68318@@ -604,7 +604,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68319 */
68320 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68321 {
68322- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68323+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68324 return (rdp->dynticks_snap & 0x1) == 0;
68325 }
68326
68327@@ -619,7 +619,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68328 unsigned int curr;
68329 unsigned int snap;
68330
68331- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68332+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68333 snap = (unsigned int)rdp->dynticks_snap;
68334
68335 /*
68336@@ -1667,7 +1667,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68337 /*
68338 * Do RCU core processing for the current CPU.
68339 */
68340-static void rcu_process_callbacks(struct softirq_action *unused)
68341+static void rcu_process_callbacks(void)
68342 {
68343 trace_rcu_utilization("Start RCU core");
68344 __rcu_process_callbacks(&rcu_sched_state,
68345@@ -2030,7 +2030,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
68346 rdp->qlen = 0;
68347 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
68348 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_NESTING);
68349- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
68350+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
68351 rdp->cpu = cpu;
68352 rdp->rsp = rsp;
68353 raw_spin_unlock_irqrestore(&rnp->lock, flags);
68354@@ -2058,8 +2058,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
68355 rdp->n_force_qs_snap = rsp->n_force_qs;
68356 rdp->blimit = blimit;
68357 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_NESTING;
68358- atomic_set(&rdp->dynticks->dynticks,
68359- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
68360+ atomic_set_unchecked(&rdp->dynticks->dynticks,
68361+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
68362 rcu_prepare_for_idle_init(cpu);
68363 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
68364
68365diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68366index fddff92..2c08359 100644
68367--- a/kernel/rcutree.h
68368+++ b/kernel/rcutree.h
68369@@ -87,7 +87,7 @@ struct rcu_dynticks {
68370 long long dynticks_nesting; /* Track irq/process nesting level. */
68371 /* Process level is worth LLONG_MAX/2. */
68372 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68373- atomic_t dynticks; /* Even value for idle, else odd. */
68374+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
68375 };
68376
68377 /* RCU's kthread states for tracing. */
68378diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68379index 8bb35d7..6ea0a463 100644
68380--- a/kernel/rcutree_plugin.h
68381+++ b/kernel/rcutree_plugin.h
68382@@ -850,7 +850,7 @@ void synchronize_rcu_expedited(void)
68383
68384 /* Clean up and exit. */
68385 smp_mb(); /* ensure expedited GP seen before counter increment. */
68386- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68387+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68388 unlock_mb_ret:
68389 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68390 mb_ret:
68391@@ -1833,8 +1833,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
68392
68393 #else /* #ifndef CONFIG_SMP */
68394
68395-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68396-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68397+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68398+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68399
68400 static int synchronize_sched_expedited_cpu_stop(void *data)
68401 {
68402@@ -1889,7 +1889,7 @@ void synchronize_sched_expedited(void)
68403 int firstsnap, s, snap, trycount = 0;
68404
68405 /* Note that atomic_inc_return() implies full memory barrier. */
68406- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68407+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68408 get_online_cpus();
68409
68410 /*
68411@@ -1910,7 +1910,7 @@ void synchronize_sched_expedited(void)
68412 }
68413
68414 /* Check to see if someone else did our work for us. */
68415- s = atomic_read(&sync_sched_expedited_done);
68416+ s = atomic_read_unchecked(&sync_sched_expedited_done);
68417 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68418 smp_mb(); /* ensure test happens before caller kfree */
68419 return;
68420@@ -1925,7 +1925,7 @@ void synchronize_sched_expedited(void)
68421 * grace period works for us.
68422 */
68423 get_online_cpus();
68424- snap = atomic_read(&sync_sched_expedited_started);
68425+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
68426 smp_mb(); /* ensure read is before try_stop_cpus(). */
68427 }
68428
68429@@ -1936,12 +1936,12 @@ void synchronize_sched_expedited(void)
68430 * than we did beat us to the punch.
68431 */
68432 do {
68433- s = atomic_read(&sync_sched_expedited_done);
68434+ s = atomic_read_unchecked(&sync_sched_expedited_done);
68435 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68436 smp_mb(); /* ensure test happens before caller kfree */
68437 break;
68438 }
68439- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68440+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68441
68442 put_online_cpus();
68443 }
68444diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68445index 654cfe6..c0b28e2 100644
68446--- a/kernel/rcutree_trace.c
68447+++ b/kernel/rcutree_trace.c
68448@@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68449 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68450 rdp->qs_pending);
68451 seq_printf(m, " dt=%d/%llx/%d df=%lu",
68452- atomic_read(&rdp->dynticks->dynticks),
68453+ atomic_read_unchecked(&rdp->dynticks->dynticks),
68454 rdp->dynticks->dynticks_nesting,
68455 rdp->dynticks->dynticks_nmi_nesting,
68456 rdp->dynticks_fqs);
68457@@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68458 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68459 rdp->qs_pending);
68460 seq_printf(m, ",%d,%llx,%d,%lu",
68461- atomic_read(&rdp->dynticks->dynticks),
68462+ atomic_read_unchecked(&rdp->dynticks->dynticks),
68463 rdp->dynticks->dynticks_nesting,
68464 rdp->dynticks->dynticks_nmi_nesting,
68465 rdp->dynticks_fqs);
68466diff --git a/kernel/resource.c b/kernel/resource.c
68467index 7640b3a..5879283 100644
68468--- a/kernel/resource.c
68469+++ b/kernel/resource.c
68470@@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68471
68472 static int __init ioresources_init(void)
68473 {
68474+#ifdef CONFIG_GRKERNSEC_PROC_ADD
68475+#ifdef CONFIG_GRKERNSEC_PROC_USER
68476+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68477+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68478+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68479+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68480+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68481+#endif
68482+#else
68483 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68484 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68485+#endif
68486 return 0;
68487 }
68488 __initcall(ioresources_init);
68489diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68490index 98ec494..4241d6d 100644
68491--- a/kernel/rtmutex-tester.c
68492+++ b/kernel/rtmutex-tester.c
68493@@ -20,7 +20,7 @@
68494 #define MAX_RT_TEST_MUTEXES 8
68495
68496 static spinlock_t rttest_lock;
68497-static atomic_t rttest_event;
68498+static atomic_unchecked_t rttest_event;
68499
68500 struct test_thread_data {
68501 int opcode;
68502@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68503
68504 case RTTEST_LOCKCONT:
68505 td->mutexes[td->opdata] = 1;
68506- td->event = atomic_add_return(1, &rttest_event);
68507+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68508 return 0;
68509
68510 case RTTEST_RESET:
68511@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68512 return 0;
68513
68514 case RTTEST_RESETEVENT:
68515- atomic_set(&rttest_event, 0);
68516+ atomic_set_unchecked(&rttest_event, 0);
68517 return 0;
68518
68519 default:
68520@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68521 return ret;
68522
68523 td->mutexes[id] = 1;
68524- td->event = atomic_add_return(1, &rttest_event);
68525+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68526 rt_mutex_lock(&mutexes[id]);
68527- td->event = atomic_add_return(1, &rttest_event);
68528+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68529 td->mutexes[id] = 4;
68530 return 0;
68531
68532@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68533 return ret;
68534
68535 td->mutexes[id] = 1;
68536- td->event = atomic_add_return(1, &rttest_event);
68537+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68538 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
68539- td->event = atomic_add_return(1, &rttest_event);
68540+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68541 td->mutexes[id] = ret ? 0 : 4;
68542 return ret ? -EINTR : 0;
68543
68544@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68545 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
68546 return ret;
68547
68548- td->event = atomic_add_return(1, &rttest_event);
68549+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68550 rt_mutex_unlock(&mutexes[id]);
68551- td->event = atomic_add_return(1, &rttest_event);
68552+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68553 td->mutexes[id] = 0;
68554 return 0;
68555
68556@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68557 break;
68558
68559 td->mutexes[dat] = 2;
68560- td->event = atomic_add_return(1, &rttest_event);
68561+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68562 break;
68563
68564 default:
68565@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68566 return;
68567
68568 td->mutexes[dat] = 3;
68569- td->event = atomic_add_return(1, &rttest_event);
68570+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68571 break;
68572
68573 case RTTEST_LOCKNOWAIT:
68574@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68575 return;
68576
68577 td->mutexes[dat] = 1;
68578- td->event = atomic_add_return(1, &rttest_event);
68579+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68580 return;
68581
68582 default:
68583diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
68584index e8a1f83..363d17d 100644
68585--- a/kernel/sched/auto_group.c
68586+++ b/kernel/sched/auto_group.c
68587@@ -11,7 +11,7 @@
68588
68589 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
68590 static struct autogroup autogroup_default;
68591-static atomic_t autogroup_seq_nr;
68592+static atomic_unchecked_t autogroup_seq_nr;
68593
68594 void __init autogroup_init(struct task_struct *init_task)
68595 {
68596@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
68597
68598 kref_init(&ag->kref);
68599 init_rwsem(&ag->lock);
68600- ag->id = atomic_inc_return(&autogroup_seq_nr);
68601+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
68602 ag->tg = tg;
68603 #ifdef CONFIG_RT_GROUP_SCHED
68604 /*
68605diff --git a/kernel/sched/core.c b/kernel/sched/core.c
68606index 478a04c..e16339a 100644
68607--- a/kernel/sched/core.c
68608+++ b/kernel/sched/core.c
68609@@ -3851,6 +3851,8 @@ int can_nice(const struct task_struct *p, const int nice)
68610 /* convert nice value [19,-20] to rlimit style value [1,40] */
68611 int nice_rlim = 20 - nice;
68612
68613+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
68614+
68615 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
68616 capable(CAP_SYS_NICE));
68617 }
68618@@ -3884,7 +3886,8 @@ SYSCALL_DEFINE1(nice, int, increment)
68619 if (nice > 19)
68620 nice = 19;
68621
68622- if (increment < 0 && !can_nice(current, nice))
68623+ if (increment < 0 && (!can_nice(current, nice) ||
68624+ gr_handle_chroot_nice()))
68625 return -EPERM;
68626
68627 retval = security_task_setnice(current, nice);
68628@@ -4041,6 +4044,7 @@ recheck:
68629 unsigned long rlim_rtprio =
68630 task_rlimit(p, RLIMIT_RTPRIO);
68631
68632+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
68633 /* can't set/change the rt policy */
68634 if (policy != p->policy && !rlim_rtprio)
68635 return -EPERM;
68636diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
68637index aca16b8..8e3acc4 100644
68638--- a/kernel/sched/fair.c
68639+++ b/kernel/sched/fair.c
68640@@ -5147,7 +5147,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
68641 * run_rebalance_domains is triggered when needed from the scheduler tick.
68642 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
68643 */
68644-static void run_rebalance_domains(struct softirq_action *h)
68645+static void run_rebalance_domains(void)
68646 {
68647 int this_cpu = smp_processor_id();
68648 struct rq *this_rq = cpu_rq(this_cpu);
68649diff --git a/kernel/signal.c b/kernel/signal.c
68650index b09cf3b..b291c66 100644
68651--- a/kernel/signal.c
68652+++ b/kernel/signal.c
68653@@ -46,12 +46,12 @@ static struct kmem_cache *sigqueue_cachep;
68654
68655 int print_fatal_signals __read_mostly;
68656
68657-static void __user *sig_handler(struct task_struct *t, int sig)
68658+static __sighandler_t sig_handler(struct task_struct *t, int sig)
68659 {
68660 return t->sighand->action[sig - 1].sa.sa_handler;
68661 }
68662
68663-static int sig_handler_ignored(void __user *handler, int sig)
68664+static int sig_handler_ignored(__sighandler_t handler, int sig)
68665 {
68666 /* Is it explicitly or implicitly ignored? */
68667 return handler == SIG_IGN ||
68668@@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
68669 static int sig_task_ignored(struct task_struct *t, int sig,
68670 int from_ancestor_ns)
68671 {
68672- void __user *handler;
68673+ __sighandler_t handler;
68674
68675 handler = sig_handler(t, sig);
68676
68677@@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
68678 atomic_inc(&user->sigpending);
68679 rcu_read_unlock();
68680
68681+ if (!override_rlimit)
68682+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
68683+
68684 if (override_rlimit ||
68685 atomic_read(&user->sigpending) <=
68686 task_rlimit(t, RLIMIT_SIGPENDING)) {
68687@@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
68688
68689 int unhandled_signal(struct task_struct *tsk, int sig)
68690 {
68691- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
68692+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
68693 if (is_global_init(tsk))
68694 return 1;
68695 if (handler != SIG_IGN && handler != SIG_DFL)
68696@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
68697 }
68698 }
68699
68700+ /* allow glibc communication via tgkill to other threads in our
68701+ thread group */
68702+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
68703+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
68704+ && gr_handle_signal(t, sig))
68705+ return -EPERM;
68706+
68707 return security_task_kill(t, info, sig, 0);
68708 }
68709
68710@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68711 return send_signal(sig, info, p, 1);
68712 }
68713
68714-static int
68715+int
68716 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68717 {
68718 return send_signal(sig, info, t, 0);
68719@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68720 unsigned long int flags;
68721 int ret, blocked, ignored;
68722 struct k_sigaction *action;
68723+ int is_unhandled = 0;
68724
68725 spin_lock_irqsave(&t->sighand->siglock, flags);
68726 action = &t->sighand->action[sig-1];
68727@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68728 }
68729 if (action->sa.sa_handler == SIG_DFL)
68730 t->signal->flags &= ~SIGNAL_UNKILLABLE;
68731+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
68732+ is_unhandled = 1;
68733 ret = specific_send_sig_info(sig, info, t);
68734 spin_unlock_irqrestore(&t->sighand->siglock, flags);
68735
68736+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
68737+ normal operation */
68738+ if (is_unhandled) {
68739+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
68740+ gr_handle_crash(t, sig);
68741+ }
68742+
68743 return ret;
68744 }
68745
68746@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68747 ret = check_kill_permission(sig, info, p);
68748 rcu_read_unlock();
68749
68750- if (!ret && sig)
68751+ if (!ret && sig) {
68752 ret = do_send_sig_info(sig, info, p, true);
68753+ if (!ret)
68754+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
68755+ }
68756
68757 return ret;
68758 }
68759@@ -2829,7 +2852,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
68760 int error = -ESRCH;
68761
68762 rcu_read_lock();
68763- p = find_task_by_vpid(pid);
68764+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68765+ /* allow glibc communication via tgkill to other threads in our
68766+ thread group */
68767+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
68768+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
68769+ p = find_task_by_vpid_unrestricted(pid);
68770+ else
68771+#endif
68772+ p = find_task_by_vpid(pid);
68773 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
68774 error = check_kill_permission(sig, info, p);
68775 /*
68776diff --git a/kernel/smp.c b/kernel/smp.c
68777index db197d6..17aef0b 100644
68778--- a/kernel/smp.c
68779+++ b/kernel/smp.c
68780@@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
68781 }
68782 EXPORT_SYMBOL(smp_call_function);
68783
68784-void ipi_call_lock(void)
68785+void ipi_call_lock(void) __acquires(call_function.lock)
68786 {
68787 raw_spin_lock(&call_function.lock);
68788 }
68789
68790-void ipi_call_unlock(void)
68791+void ipi_call_unlock(void) __releases(call_function.lock)
68792 {
68793 raw_spin_unlock(&call_function.lock);
68794 }
68795
68796-void ipi_call_lock_irq(void)
68797+void ipi_call_lock_irq(void) __acquires(call_function.lock)
68798 {
68799 raw_spin_lock_irq(&call_function.lock);
68800 }
68801
68802-void ipi_call_unlock_irq(void)
68803+void ipi_call_unlock_irq(void) __releases(call_function.lock)
68804 {
68805 raw_spin_unlock_irq(&call_function.lock);
68806 }
68807diff --git a/kernel/softirq.c b/kernel/softirq.c
68808index 4eb3a0f..6f1fa81 100644
68809--- a/kernel/softirq.c
68810+++ b/kernel/softirq.c
68811@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
68812
68813 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
68814
68815-char *softirq_to_name[NR_SOFTIRQS] = {
68816+const char * const softirq_to_name[NR_SOFTIRQS] = {
68817 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
68818 "TASKLET", "SCHED", "HRTIMER", "RCU"
68819 };
68820@@ -235,7 +235,7 @@ restart:
68821 kstat_incr_softirqs_this_cpu(vec_nr);
68822
68823 trace_softirq_entry(vec_nr);
68824- h->action(h);
68825+ h->action();
68826 trace_softirq_exit(vec_nr);
68827 if (unlikely(prev_count != preempt_count())) {
68828 printk(KERN_ERR "huh, entered softirq %u %s %p"
68829@@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
68830 local_irq_restore(flags);
68831 }
68832
68833-void open_softirq(int nr, void (*action)(struct softirq_action *))
68834+void open_softirq(int nr, void (*action)(void))
68835 {
68836- softirq_vec[nr].action = action;
68837+ pax_open_kernel();
68838+ *(void **)&softirq_vec[nr].action = action;
68839+ pax_close_kernel();
68840 }
68841
68842 /*
68843@@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
68844
68845 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
68846
68847-static void tasklet_action(struct softirq_action *a)
68848+static void tasklet_action(void)
68849 {
68850 struct tasklet_struct *list;
68851
68852@@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
68853 }
68854 }
68855
68856-static void tasklet_hi_action(struct softirq_action *a)
68857+static void tasklet_hi_action(void)
68858 {
68859 struct tasklet_struct *list;
68860
68861diff --git a/kernel/sys.c b/kernel/sys.c
68862index 888d227..f04b318 100644
68863--- a/kernel/sys.c
68864+++ b/kernel/sys.c
68865@@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
68866 error = -EACCES;
68867 goto out;
68868 }
68869+
68870+ if (gr_handle_chroot_setpriority(p, niceval)) {
68871+ error = -EACCES;
68872+ goto out;
68873+ }
68874+
68875 no_nice = security_task_setnice(p, niceval);
68876 if (no_nice) {
68877 error = no_nice;
68878@@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
68879 goto error;
68880 }
68881
68882+ if (gr_check_group_change(new->gid, new->egid, -1))
68883+ goto error;
68884+
68885 if (rgid != (gid_t) -1 ||
68886 (egid != (gid_t) -1 && egid != old->gid))
68887 new->sgid = new->egid;
68888@@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
68889 old = current_cred();
68890
68891 retval = -EPERM;
68892+
68893+ if (gr_check_group_change(gid, gid, gid))
68894+ goto error;
68895+
68896 if (nsown_capable(CAP_SETGID))
68897 new->gid = new->egid = new->sgid = new->fsgid = gid;
68898 else if (gid == old->gid || gid == old->sgid)
68899@@ -618,7 +631,7 @@ error:
68900 /*
68901 * change the user struct in a credentials set to match the new UID
68902 */
68903-static int set_user(struct cred *new)
68904+int set_user(struct cred *new)
68905 {
68906 struct user_struct *new_user;
68907
68908@@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
68909 goto error;
68910 }
68911
68912+ if (gr_check_user_change(new->uid, new->euid, -1))
68913+ goto error;
68914+
68915 if (new->uid != old->uid) {
68916 retval = set_user(new);
68917 if (retval < 0)
68918@@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
68919 old = current_cred();
68920
68921 retval = -EPERM;
68922+
68923+ if (gr_check_crash_uid(uid))
68924+ goto error;
68925+ if (gr_check_user_change(uid, uid, uid))
68926+ goto error;
68927+
68928 if (nsown_capable(CAP_SETUID)) {
68929 new->suid = new->uid = uid;
68930 if (uid != old->uid) {
68931@@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
68932 goto error;
68933 }
68934
68935+ if (gr_check_user_change(ruid, euid, -1))
68936+ goto error;
68937+
68938 if (ruid != (uid_t) -1) {
68939 new->uid = ruid;
68940 if (ruid != old->uid) {
68941@@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
68942 goto error;
68943 }
68944
68945+ if (gr_check_group_change(rgid, egid, -1))
68946+ goto error;
68947+
68948 if (rgid != (gid_t) -1)
68949 new->gid = rgid;
68950 if (egid != (gid_t) -1)
68951@@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68952 old = current_cred();
68953 old_fsuid = old->fsuid;
68954
68955+ if (gr_check_user_change(-1, -1, uid))
68956+ goto error;
68957+
68958 if (uid == old->uid || uid == old->euid ||
68959 uid == old->suid || uid == old->fsuid ||
68960 nsown_capable(CAP_SETUID)) {
68961@@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68962 }
68963 }
68964
68965+error:
68966 abort_creds(new);
68967 return old_fsuid;
68968
68969@@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
68970 if (gid == old->gid || gid == old->egid ||
68971 gid == old->sgid || gid == old->fsgid ||
68972 nsown_capable(CAP_SETGID)) {
68973+ if (gr_check_group_change(-1, -1, gid))
68974+ goto error;
68975+
68976 if (gid != old_fsgid) {
68977 new->fsgid = gid;
68978 goto change_okay;
68979 }
68980 }
68981
68982+error:
68983 abort_creds(new);
68984 return old_fsgid;
68985
68986@@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
68987 }
68988 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
68989 snprintf(buf, len, "2.6.%u%s", v, rest);
68990- ret = copy_to_user(release, buf, len);
68991+ if (len > sizeof(buf))
68992+ ret = -EFAULT;
68993+ else
68994+ ret = copy_to_user(release, buf, len);
68995 }
68996 return ret;
68997 }
68998@@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
68999 return -EFAULT;
69000
69001 down_read(&uts_sem);
69002- error = __copy_to_user(&name->sysname, &utsname()->sysname,
69003+ error = __copy_to_user(name->sysname, &utsname()->sysname,
69004 __OLD_UTS_LEN);
69005 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69006- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69007+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
69008 __OLD_UTS_LEN);
69009 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69010- error |= __copy_to_user(&name->release, &utsname()->release,
69011+ error |= __copy_to_user(name->release, &utsname()->release,
69012 __OLD_UTS_LEN);
69013 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69014- error |= __copy_to_user(&name->version, &utsname()->version,
69015+ error |= __copy_to_user(name->version, &utsname()->version,
69016 __OLD_UTS_LEN);
69017 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69018- error |= __copy_to_user(&name->machine, &utsname()->machine,
69019+ error |= __copy_to_user(name->machine, &utsname()->machine,
69020 __OLD_UTS_LEN);
69021 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69022 up_read(&uts_sem);
69023@@ -1838,7 +1877,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69024 error = get_dumpable(me->mm);
69025 break;
69026 case PR_SET_DUMPABLE:
69027- if (arg2 < 0 || arg2 > 1) {
69028+ if (arg2 > 1) {
69029 error = -EINVAL;
69030 break;
69031 }
69032diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69033index f03a6ef..735d95c 100644
69034--- a/kernel/sysctl.c
69035+++ b/kernel/sysctl.c
69036@@ -86,6 +86,13 @@
69037
69038
69039 #if defined(CONFIG_SYSCTL)
69040+#include <linux/grsecurity.h>
69041+#include <linux/grinternal.h>
69042+
69043+extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
69044+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
69045+ const int op);
69046+extern int gr_handle_chroot_sysctl(const int op);
69047
69048 /* External variables not in a header file. */
69049 extern int sysctl_overcommit_memory;
69050@@ -165,10 +172,8 @@ static int proc_taint(struct ctl_table *table, int write,
69051 void __user *buffer, size_t *lenp, loff_t *ppos);
69052 #endif
69053
69054-#ifdef CONFIG_PRINTK
69055 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69056 void __user *buffer, size_t *lenp, loff_t *ppos);
69057-#endif
69058
69059 #ifdef CONFIG_MAGIC_SYSRQ
69060 /* Note: sysrq code uses it's own private copy */
69061@@ -191,6 +196,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69062 }
69063
69064 #endif
69065+extern struct ctl_table grsecurity_table[];
69066
69067 static struct ctl_table root_table[];
69068 static struct ctl_table_root sysctl_table_root;
69069@@ -220,6 +226,20 @@ extern struct ctl_table epoll_table[];
69070 int sysctl_legacy_va_layout;
69071 #endif
69072
69073+#ifdef CONFIG_PAX_SOFTMODE
69074+static ctl_table pax_table[] = {
69075+ {
69076+ .procname = "softmode",
69077+ .data = &pax_softmode,
69078+ .maxlen = sizeof(unsigned int),
69079+ .mode = 0600,
69080+ .proc_handler = &proc_dointvec,
69081+ },
69082+
69083+ { }
69084+};
69085+#endif
69086+
69087 /* The default sysctl tables: */
69088
69089 static struct ctl_table root_table[] = {
69090@@ -266,6 +286,22 @@ static int max_extfrag_threshold = 1000;
69091 #endif
69092
69093 static struct ctl_table kern_table[] = {
69094+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69095+ {
69096+ .procname = "grsecurity",
69097+ .mode = 0500,
69098+ .child = grsecurity_table,
69099+ },
69100+#endif
69101+
69102+#ifdef CONFIG_PAX_SOFTMODE
69103+ {
69104+ .procname = "pax",
69105+ .mode = 0500,
69106+ .child = pax_table,
69107+ },
69108+#endif
69109+
69110 {
69111 .procname = "sched_child_runs_first",
69112 .data = &sysctl_sched_child_runs_first,
69113@@ -550,7 +586,7 @@ static struct ctl_table kern_table[] = {
69114 .data = &modprobe_path,
69115 .maxlen = KMOD_PATH_LEN,
69116 .mode = 0644,
69117- .proc_handler = proc_dostring,
69118+ .proc_handler = proc_dostring_modpriv,
69119 },
69120 {
69121 .procname = "modules_disabled",
69122@@ -717,16 +753,20 @@ static struct ctl_table kern_table[] = {
69123 .extra1 = &zero,
69124 .extra2 = &one,
69125 },
69126+#endif
69127 {
69128 .procname = "kptr_restrict",
69129 .data = &kptr_restrict,
69130 .maxlen = sizeof(int),
69131 .mode = 0644,
69132 .proc_handler = proc_dointvec_minmax_sysadmin,
69133+#ifdef CONFIG_GRKERNSEC_HIDESYM
69134+ .extra1 = &two,
69135+#else
69136 .extra1 = &zero,
69137+#endif
69138 .extra2 = &two,
69139 },
69140-#endif
69141 {
69142 .procname = "ngroups_max",
69143 .data = &ngroups_max,
69144@@ -1225,6 +1265,13 @@ static struct ctl_table vm_table[] = {
69145 .proc_handler = proc_dointvec_minmax,
69146 .extra1 = &zero,
69147 },
69148+ {
69149+ .procname = "heap_stack_gap",
69150+ .data = &sysctl_heap_stack_gap,
69151+ .maxlen = sizeof(sysctl_heap_stack_gap),
69152+ .mode = 0644,
69153+ .proc_handler = proc_doulongvec_minmax,
69154+ },
69155 #else
69156 {
69157 .procname = "nr_trim_pages",
69158@@ -1729,6 +1776,17 @@ static int test_perm(int mode, int op)
69159 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
69160 {
69161 int mode;
69162+ int error;
69163+
69164+ if (table->parent != NULL && table->parent->procname != NULL &&
69165+ table->procname != NULL &&
69166+ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
69167+ return -EACCES;
69168+ if (gr_handle_chroot_sysctl(op))
69169+ return -EACCES;
69170+ error = gr_handle_sysctl(table, op);
69171+ if (error)
69172+ return error;
69173
69174 if (root->permissions)
69175 mode = root->permissions(root, current->nsproxy, table);
69176@@ -2133,6 +2191,16 @@ int proc_dostring(struct ctl_table *table, int write,
69177 buffer, lenp, ppos);
69178 }
69179
69180+int proc_dostring_modpriv(struct ctl_table *table, int write,
69181+ void __user *buffer, size_t *lenp, loff_t *ppos)
69182+{
69183+ if (write && !capable(CAP_SYS_MODULE))
69184+ return -EPERM;
69185+
69186+ return _proc_do_string(table->data, table->maxlen, write,
69187+ buffer, lenp, ppos);
69188+}
69189+
69190 static size_t proc_skip_spaces(char **buf)
69191 {
69192 size_t ret;
69193@@ -2238,6 +2306,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69194 len = strlen(tmp);
69195 if (len > *size)
69196 len = *size;
69197+ if (len > sizeof(tmp))
69198+ len = sizeof(tmp);
69199 if (copy_to_user(*buf, tmp, len))
69200 return -EFAULT;
69201 *size -= len;
69202@@ -2430,7 +2500,6 @@ static int proc_taint(struct ctl_table *table, int write,
69203 return err;
69204 }
69205
69206-#ifdef CONFIG_PRINTK
69207 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69208 void __user *buffer, size_t *lenp, loff_t *ppos)
69209 {
69210@@ -2439,7 +2508,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69211
69212 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69213 }
69214-#endif
69215
69216 struct do_proc_dointvec_minmax_conv_param {
69217 int *min;
69218@@ -2554,8 +2622,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69219 *i = val;
69220 } else {
69221 val = convdiv * (*i) / convmul;
69222- if (!first)
69223+ if (!first) {
69224 err = proc_put_char(&buffer, &left, '\t');
69225+ if (err)
69226+ break;
69227+ }
69228 err = proc_put_long(&buffer, &left, val, false);
69229 if (err)
69230 break;
69231@@ -2950,6 +3021,12 @@ int proc_dostring(struct ctl_table *table, int write,
69232 return -ENOSYS;
69233 }
69234
69235+int proc_dostring_modpriv(struct ctl_table *table, int write,
69236+ void __user *buffer, size_t *lenp, loff_t *ppos)
69237+{
69238+ return -ENOSYS;
69239+}
69240+
69241 int proc_dointvec(struct ctl_table *table, int write,
69242 void __user *buffer, size_t *lenp, loff_t *ppos)
69243 {
69244@@ -3006,6 +3083,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69245 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69246 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69247 EXPORT_SYMBOL(proc_dostring);
69248+EXPORT_SYMBOL(proc_dostring_modpriv);
69249 EXPORT_SYMBOL(proc_doulongvec_minmax);
69250 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69251 EXPORT_SYMBOL(register_sysctl_table);
69252diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69253index a650694..aaeeb20 100644
69254--- a/kernel/sysctl_binary.c
69255+++ b/kernel/sysctl_binary.c
69256@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69257 int i;
69258
69259 set_fs(KERNEL_DS);
69260- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69261+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69262 set_fs(old_fs);
69263 if (result < 0)
69264 goto out_kfree;
69265@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69266 }
69267
69268 set_fs(KERNEL_DS);
69269- result = vfs_write(file, buffer, str - buffer, &pos);
69270+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69271 set_fs(old_fs);
69272 if (result < 0)
69273 goto out_kfree;
69274@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69275 int i;
69276
69277 set_fs(KERNEL_DS);
69278- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69279+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69280 set_fs(old_fs);
69281 if (result < 0)
69282 goto out_kfree;
69283@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69284 }
69285
69286 set_fs(KERNEL_DS);
69287- result = vfs_write(file, buffer, str - buffer, &pos);
69288+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69289 set_fs(old_fs);
69290 if (result < 0)
69291 goto out_kfree;
69292@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69293 int i;
69294
69295 set_fs(KERNEL_DS);
69296- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69297+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69298 set_fs(old_fs);
69299 if (result < 0)
69300 goto out;
69301@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69302 __le16 dnaddr;
69303
69304 set_fs(KERNEL_DS);
69305- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69306+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69307 set_fs(old_fs);
69308 if (result < 0)
69309 goto out;
69310@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69311 le16_to_cpu(dnaddr) & 0x3ff);
69312
69313 set_fs(KERNEL_DS);
69314- result = vfs_write(file, buf, len, &pos);
69315+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69316 set_fs(old_fs);
69317 if (result < 0)
69318 goto out;
69319diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
69320index 362da65..ab8ef8c 100644
69321--- a/kernel/sysctl_check.c
69322+++ b/kernel/sysctl_check.c
69323@@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
69324 set_fail(&fail, table, "Directory with extra2");
69325 } else {
69326 if ((table->proc_handler == proc_dostring) ||
69327+ (table->proc_handler == proc_dostring_modpriv) ||
69328 (table->proc_handler == proc_dointvec) ||
69329 (table->proc_handler == proc_dointvec_minmax) ||
69330 (table->proc_handler == proc_dointvec_jiffies) ||
69331diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69332index e660464..c8b9e67 100644
69333--- a/kernel/taskstats.c
69334+++ b/kernel/taskstats.c
69335@@ -27,9 +27,12 @@
69336 #include <linux/cgroup.h>
69337 #include <linux/fs.h>
69338 #include <linux/file.h>
69339+#include <linux/grsecurity.h>
69340 #include <net/genetlink.h>
69341 #include <linux/atomic.h>
69342
69343+extern int gr_is_taskstats_denied(int pid);
69344+
69345 /*
69346 * Maximum length of a cpumask that can be specified in
69347 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69348@@ -556,6 +559,9 @@ err:
69349
69350 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69351 {
69352+ if (gr_is_taskstats_denied(current->pid))
69353+ return -EACCES;
69354+
69355 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69356 return cmd_attr_register_cpumask(info);
69357 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69358diff --git a/kernel/time.c b/kernel/time.c
69359index 73e416d..cfc6f69 100644
69360--- a/kernel/time.c
69361+++ b/kernel/time.c
69362@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69363 return error;
69364
69365 if (tz) {
69366+ /* we log in do_settimeofday called below, so don't log twice
69367+ */
69368+ if (!tv)
69369+ gr_log_timechange();
69370+
69371 /* SMP safe, global irq locking makes it work. */
69372 sys_tz = *tz;
69373 update_vsyscall_tz();
69374diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69375index 8a46f5d..bbe6f9c 100644
69376--- a/kernel/time/alarmtimer.c
69377+++ b/kernel/time/alarmtimer.c
69378@@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
69379 struct platform_device *pdev;
69380 int error = 0;
69381 int i;
69382- struct k_clock alarm_clock = {
69383+ static struct k_clock alarm_clock = {
69384 .clock_getres = alarm_clock_getres,
69385 .clock_get = alarm_clock_get,
69386 .timer_create = alarm_timer_create,
69387diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69388index fd4a7b1..fae5c2a 100644
69389--- a/kernel/time/tick-broadcast.c
69390+++ b/kernel/time/tick-broadcast.c
69391@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69392 * then clear the broadcast bit.
69393 */
69394 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69395- int cpu = smp_processor_id();
69396+ cpu = smp_processor_id();
69397
69398 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69399 tick_broadcast_clear_oneshot(cpu);
69400diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69401index 0c63581..e25dcb6 100644
69402--- a/kernel/time/timekeeping.c
69403+++ b/kernel/time/timekeeping.c
69404@@ -14,6 +14,7 @@
69405 #include <linux/init.h>
69406 #include <linux/mm.h>
69407 #include <linux/sched.h>
69408+#include <linux/grsecurity.h>
69409 #include <linux/syscore_ops.h>
69410 #include <linux/clocksource.h>
69411 #include <linux/jiffies.h>
69412@@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
69413 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69414 return -EINVAL;
69415
69416+ gr_log_timechange();
69417+
69418 write_seqlock_irqsave(&xtime_lock, flags);
69419
69420 timekeeping_forward_now();
69421diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69422index 3258455..f35227d 100644
69423--- a/kernel/time/timer_list.c
69424+++ b/kernel/time/timer_list.c
69425@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69426
69427 static void print_name_offset(struct seq_file *m, void *sym)
69428 {
69429+#ifdef CONFIG_GRKERNSEC_HIDESYM
69430+ SEQ_printf(m, "<%p>", NULL);
69431+#else
69432 char symname[KSYM_NAME_LEN];
69433
69434 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
69435 SEQ_printf(m, "<%pK>", sym);
69436 else
69437 SEQ_printf(m, "%s", symname);
69438+#endif
69439 }
69440
69441 static void
69442@@ -112,7 +116,11 @@ next_one:
69443 static void
69444 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
69445 {
69446+#ifdef CONFIG_GRKERNSEC_HIDESYM
69447+ SEQ_printf(m, " .base: %p\n", NULL);
69448+#else
69449 SEQ_printf(m, " .base: %pK\n", base);
69450+#endif
69451 SEQ_printf(m, " .index: %d\n",
69452 base->index);
69453 SEQ_printf(m, " .resolution: %Lu nsecs\n",
69454@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
69455 {
69456 struct proc_dir_entry *pe;
69457
69458+#ifdef CONFIG_GRKERNSEC_PROC_ADD
69459+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
69460+#else
69461 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
69462+#endif
69463 if (!pe)
69464 return -ENOMEM;
69465 return 0;
69466diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
69467index 0b537f2..9e71eca 100644
69468--- a/kernel/time/timer_stats.c
69469+++ b/kernel/time/timer_stats.c
69470@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
69471 static unsigned long nr_entries;
69472 static struct entry entries[MAX_ENTRIES];
69473
69474-static atomic_t overflow_count;
69475+static atomic_unchecked_t overflow_count;
69476
69477 /*
69478 * The entries are in a hash-table, for fast lookup:
69479@@ -140,7 +140,7 @@ static void reset_entries(void)
69480 nr_entries = 0;
69481 memset(entries, 0, sizeof(entries));
69482 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
69483- atomic_set(&overflow_count, 0);
69484+ atomic_set_unchecked(&overflow_count, 0);
69485 }
69486
69487 static struct entry *alloc_entry(void)
69488@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69489 if (likely(entry))
69490 entry->count++;
69491 else
69492- atomic_inc(&overflow_count);
69493+ atomic_inc_unchecked(&overflow_count);
69494
69495 out_unlock:
69496 raw_spin_unlock_irqrestore(lock, flags);
69497@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69498
69499 static void print_name_offset(struct seq_file *m, unsigned long addr)
69500 {
69501+#ifdef CONFIG_GRKERNSEC_HIDESYM
69502+ seq_printf(m, "<%p>", NULL);
69503+#else
69504 char symname[KSYM_NAME_LEN];
69505
69506 if (lookup_symbol_name(addr, symname) < 0)
69507 seq_printf(m, "<%p>", (void *)addr);
69508 else
69509 seq_printf(m, "%s", symname);
69510+#endif
69511 }
69512
69513 static int tstats_show(struct seq_file *m, void *v)
69514@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
69515
69516 seq_puts(m, "Timer Stats Version: v0.2\n");
69517 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
69518- if (atomic_read(&overflow_count))
69519+ if (atomic_read_unchecked(&overflow_count))
69520 seq_printf(m, "Overflow: %d entries\n",
69521- atomic_read(&overflow_count));
69522+ atomic_read_unchecked(&overflow_count));
69523
69524 for (i = 0; i < nr_entries; i++) {
69525 entry = entries + i;
69526@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
69527 {
69528 struct proc_dir_entry *pe;
69529
69530+#ifdef CONFIG_GRKERNSEC_PROC_ADD
69531+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
69532+#else
69533 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
69534+#endif
69535 if (!pe)
69536 return -ENOMEM;
69537 return 0;
69538diff --git a/kernel/timer.c b/kernel/timer.c
69539index a297ffc..5e16b0b 100644
69540--- a/kernel/timer.c
69541+++ b/kernel/timer.c
69542@@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
69543 /*
69544 * This function runs timers and the timer-tq in bottom half context.
69545 */
69546-static void run_timer_softirq(struct softirq_action *h)
69547+static void run_timer_softirq(void)
69548 {
69549 struct tvec_base *base = __this_cpu_read(tvec_bases);
69550
69551diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
69552index cdea7b5..9b820d4 100644
69553--- a/kernel/trace/blktrace.c
69554+++ b/kernel/trace/blktrace.c
69555@@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
69556 struct blk_trace *bt = filp->private_data;
69557 char buf[16];
69558
69559- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
69560+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
69561
69562 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
69563 }
69564@@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
69565 return 1;
69566
69567 bt = buf->chan->private_data;
69568- atomic_inc(&bt->dropped);
69569+ atomic_inc_unchecked(&bt->dropped);
69570 return 0;
69571 }
69572
69573@@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
69574
69575 bt->dir = dir;
69576 bt->dev = dev;
69577- atomic_set(&bt->dropped, 0);
69578+ atomic_set_unchecked(&bt->dropped, 0);
69579
69580 ret = -EIO;
69581 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
69582diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
69583index 683d559..d70d914 100644
69584--- a/kernel/trace/ftrace.c
69585+++ b/kernel/trace/ftrace.c
69586@@ -1726,12 +1726,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
69587 if (unlikely(ftrace_disabled))
69588 return 0;
69589
69590+ ret = ftrace_arch_code_modify_prepare();
69591+ FTRACE_WARN_ON(ret);
69592+ if (ret)
69593+ return 0;
69594+
69595 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
69596+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
69597 if (ret) {
69598 ftrace_bug(ret, ip);
69599- return 0;
69600 }
69601- return 1;
69602+ return ret ? 0 : 1;
69603 }
69604
69605 /*
69606@@ -2843,7 +2848,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
69607
69608 int
69609 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
69610- void *data)
69611+ void *data)
69612 {
69613 struct ftrace_func_probe *entry;
69614 struct ftrace_page *pg;
69615diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
69616index c4579f1..6a439da 100644
69617--- a/kernel/trace/trace.c
69618+++ b/kernel/trace/trace.c
69619@@ -4258,10 +4258,9 @@ static const struct file_operations tracing_dyn_info_fops = {
69620 };
69621 #endif
69622
69623-static struct dentry *d_tracer;
69624-
69625 struct dentry *tracing_init_dentry(void)
69626 {
69627+ static struct dentry *d_tracer;
69628 static int once;
69629
69630 if (d_tracer)
69631@@ -4281,10 +4280,9 @@ struct dentry *tracing_init_dentry(void)
69632 return d_tracer;
69633 }
69634
69635-static struct dentry *d_percpu;
69636-
69637 struct dentry *tracing_dentry_percpu(void)
69638 {
69639+ static struct dentry *d_percpu;
69640 static int once;
69641 struct dentry *d_tracer;
69642
69643diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
69644index c212a7f..7b02394 100644
69645--- a/kernel/trace/trace_events.c
69646+++ b/kernel/trace/trace_events.c
69647@@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
69648 struct ftrace_module_file_ops {
69649 struct list_head list;
69650 struct module *mod;
69651- struct file_operations id;
69652- struct file_operations enable;
69653- struct file_operations format;
69654- struct file_operations filter;
69655 };
69656
69657 static struct ftrace_module_file_ops *
69658@@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
69659
69660 file_ops->mod = mod;
69661
69662- file_ops->id = ftrace_event_id_fops;
69663- file_ops->id.owner = mod;
69664-
69665- file_ops->enable = ftrace_enable_fops;
69666- file_ops->enable.owner = mod;
69667-
69668- file_ops->filter = ftrace_event_filter_fops;
69669- file_ops->filter.owner = mod;
69670-
69671- file_ops->format = ftrace_event_format_fops;
69672- file_ops->format.owner = mod;
69673+ pax_open_kernel();
69674+ *(void **)&mod->trace_id.owner = mod;
69675+ *(void **)&mod->trace_enable.owner = mod;
69676+ *(void **)&mod->trace_filter.owner = mod;
69677+ *(void **)&mod->trace_format.owner = mod;
69678+ pax_close_kernel();
69679
69680 list_add(&file_ops->list, &ftrace_module_file_list);
69681
69682@@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
69683
69684 for_each_event(call, start, end) {
69685 __trace_add_event_call(*call, mod,
69686- &file_ops->id, &file_ops->enable,
69687- &file_ops->filter, &file_ops->format);
69688+ &mod->trace_id, &mod->trace_enable,
69689+ &mod->trace_filter, &mod->trace_format);
69690 }
69691 }
69692
69693diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
69694index 00d527c..7c5b1a3 100644
69695--- a/kernel/trace/trace_kprobe.c
69696+++ b/kernel/trace/trace_kprobe.c
69697@@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69698 long ret;
69699 int maxlen = get_rloc_len(*(u32 *)dest);
69700 u8 *dst = get_rloc_data(dest);
69701- u8 *src = addr;
69702+ const u8 __user *src = (const u8 __force_user *)addr;
69703 mm_segment_t old_fs = get_fs();
69704 if (!maxlen)
69705 return;
69706@@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69707 pagefault_disable();
69708 do
69709 ret = __copy_from_user_inatomic(dst++, src++, 1);
69710- while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
69711+ while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
69712 dst[-1] = '\0';
69713 pagefault_enable();
69714 set_fs(old_fs);
69715@@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69716 ((u8 *)get_rloc_data(dest))[0] = '\0';
69717 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
69718 } else
69719- *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
69720+ *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
69721 get_rloc_offs(*(u32 *)dest));
69722 }
69723 /* Return the length of string -- including null terminal byte */
69724@@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
69725 set_fs(KERNEL_DS);
69726 pagefault_disable();
69727 do {
69728- ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
69729+ ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
69730 len++;
69731 } while (c && ret == 0 && len < MAX_STRING_SIZE);
69732 pagefault_enable();
69733diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
69734index fd3c8aa..5f324a6 100644
69735--- a/kernel/trace/trace_mmiotrace.c
69736+++ b/kernel/trace/trace_mmiotrace.c
69737@@ -24,7 +24,7 @@ struct header_iter {
69738 static struct trace_array *mmio_trace_array;
69739 static bool overrun_detected;
69740 static unsigned long prev_overruns;
69741-static atomic_t dropped_count;
69742+static atomic_unchecked_t dropped_count;
69743
69744 static void mmio_reset_data(struct trace_array *tr)
69745 {
69746@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
69747
69748 static unsigned long count_overruns(struct trace_iterator *iter)
69749 {
69750- unsigned long cnt = atomic_xchg(&dropped_count, 0);
69751+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
69752 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
69753
69754 if (over > prev_overruns)
69755@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
69756 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
69757 sizeof(*entry), 0, pc);
69758 if (!event) {
69759- atomic_inc(&dropped_count);
69760+ atomic_inc_unchecked(&dropped_count);
69761 return;
69762 }
69763 entry = ring_buffer_event_data(event);
69764@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
69765 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
69766 sizeof(*entry), 0, pc);
69767 if (!event) {
69768- atomic_inc(&dropped_count);
69769+ atomic_inc_unchecked(&dropped_count);
69770 return;
69771 }
69772 entry = ring_buffer_event_data(event);
69773diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
69774index d9c07f0..c1eeceb 100644
69775--- a/kernel/trace/trace_output.c
69776+++ b/kernel/trace/trace_output.c
69777@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
69778
69779 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
69780 if (!IS_ERR(p)) {
69781- p = mangle_path(s->buffer + s->len, p, "\n");
69782+ p = mangle_path(s->buffer + s->len, p, "\n\\");
69783 if (p) {
69784 s->len = p - s->buffer;
69785 return 1;
69786diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
69787index d4545f4..a9010a1 100644
69788--- a/kernel/trace/trace_stack.c
69789+++ b/kernel/trace/trace_stack.c
69790@@ -53,7 +53,7 @@ static inline void check_stack(void)
69791 return;
69792
69793 /* we do not handle interrupt stacks yet */
69794- if (!object_is_on_stack(&this_size))
69795+ if (!object_starts_on_stack(&this_size))
69796 return;
69797
69798 local_irq_save(flags);
69799diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
69800index 209b379..7f76423 100644
69801--- a/kernel/trace/trace_workqueue.c
69802+++ b/kernel/trace/trace_workqueue.c
69803@@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
69804 int cpu;
69805 pid_t pid;
69806 /* Can be inserted from interrupt or user context, need to be atomic */
69807- atomic_t inserted;
69808+ atomic_unchecked_t inserted;
69809 /*
69810 * Don't need to be atomic, works are serialized in a single workqueue thread
69811 * on a single CPU.
69812@@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
69813 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
69814 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
69815 if (node->pid == wq_thread->pid) {
69816- atomic_inc(&node->inserted);
69817+ atomic_inc_unchecked(&node->inserted);
69818 goto found;
69819 }
69820 }
69821@@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
69822 tsk = get_pid_task(pid, PIDTYPE_PID);
69823 if (tsk) {
69824 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
69825- atomic_read(&cws->inserted), cws->executed,
69826+ atomic_read_unchecked(&cws->inserted), cws->executed,
69827 tsk->comm);
69828 put_task_struct(tsk);
69829 }
69830diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
69831index 8745ac7..d144e37 100644
69832--- a/lib/Kconfig.debug
69833+++ b/lib/Kconfig.debug
69834@@ -1103,6 +1103,7 @@ config LATENCYTOP
69835 depends on DEBUG_KERNEL
69836 depends on STACKTRACE_SUPPORT
69837 depends on PROC_FS
69838+ depends on !GRKERNSEC_HIDESYM
69839 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
69840 select KALLSYMS
69841 select KALLSYMS_ALL
69842diff --git a/lib/bitmap.c b/lib/bitmap.c
69843index 0d4a127..33a06c7 100644
69844--- a/lib/bitmap.c
69845+++ b/lib/bitmap.c
69846@@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
69847 {
69848 int c, old_c, totaldigits, ndigits, nchunks, nbits;
69849 u32 chunk;
69850- const char __user __force *ubuf = (const char __user __force *)buf;
69851+ const char __user *ubuf = (const char __force_user *)buf;
69852
69853 bitmap_zero(maskp, nmaskbits);
69854
69855@@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
69856 {
69857 if (!access_ok(VERIFY_READ, ubuf, ulen))
69858 return -EFAULT;
69859- return __bitmap_parse((const char __force *)ubuf,
69860+ return __bitmap_parse((const char __force_kernel *)ubuf,
69861 ulen, 1, maskp, nmaskbits);
69862
69863 }
69864@@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
69865 {
69866 unsigned a, b;
69867 int c, old_c, totaldigits;
69868- const char __user __force *ubuf = (const char __user __force *)buf;
69869+ const char __user *ubuf = (const char __force_user *)buf;
69870 int exp_digit, in_range;
69871
69872 totaldigits = c = 0;
69873@@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
69874 {
69875 if (!access_ok(VERIFY_READ, ubuf, ulen))
69876 return -EFAULT;
69877- return __bitmap_parselist((const char __force *)ubuf,
69878+ return __bitmap_parselist((const char __force_kernel *)ubuf,
69879 ulen, 1, maskp, nmaskbits);
69880 }
69881 EXPORT_SYMBOL(bitmap_parselist_user);
69882diff --git a/lib/bug.c b/lib/bug.c
69883index a28c141..2bd3d95 100644
69884--- a/lib/bug.c
69885+++ b/lib/bug.c
69886@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
69887 return BUG_TRAP_TYPE_NONE;
69888
69889 bug = find_bug(bugaddr);
69890+ if (!bug)
69891+ return BUG_TRAP_TYPE_NONE;
69892
69893 file = NULL;
69894 line = 0;
69895diff --git a/lib/debugobjects.c b/lib/debugobjects.c
69896index 0ab9ae8..f01ceca 100644
69897--- a/lib/debugobjects.c
69898+++ b/lib/debugobjects.c
69899@@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
69900 if (limit > 4)
69901 return;
69902
69903- is_on_stack = object_is_on_stack(addr);
69904+ is_on_stack = object_starts_on_stack(addr);
69905 if (is_on_stack == onstack)
69906 return;
69907
69908diff --git a/lib/devres.c b/lib/devres.c
69909index 9676617..5149e15 100644
69910--- a/lib/devres.c
69911+++ b/lib/devres.c
69912@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
69913 void devm_iounmap(struct device *dev, void __iomem *addr)
69914 {
69915 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
69916- (void *)addr));
69917+ (void __force *)addr));
69918 iounmap(addr);
69919 }
69920 EXPORT_SYMBOL(devm_iounmap);
69921@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
69922 {
69923 ioport_unmap(addr);
69924 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
69925- devm_ioport_map_match, (void *)addr));
69926+ devm_ioport_map_match, (void __force *)addr));
69927 }
69928 EXPORT_SYMBOL(devm_ioport_unmap);
69929
69930diff --git a/lib/dma-debug.c b/lib/dma-debug.c
69931index fea790a..ebb0e82 100644
69932--- a/lib/dma-debug.c
69933+++ b/lib/dma-debug.c
69934@@ -925,7 +925,7 @@ out:
69935
69936 static void check_for_stack(struct device *dev, void *addr)
69937 {
69938- if (object_is_on_stack(addr))
69939+ if (object_starts_on_stack(addr))
69940 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
69941 "stack [addr=%p]\n", addr);
69942 }
69943diff --git a/lib/extable.c b/lib/extable.c
69944index 4cac81e..63e9b8f 100644
69945--- a/lib/extable.c
69946+++ b/lib/extable.c
69947@@ -13,6 +13,7 @@
69948 #include <linux/init.h>
69949 #include <linux/sort.h>
69950 #include <asm/uaccess.h>
69951+#include <asm/pgtable.h>
69952
69953 #ifndef ARCH_HAS_SORT_EXTABLE
69954 /*
69955@@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
69956 void sort_extable(struct exception_table_entry *start,
69957 struct exception_table_entry *finish)
69958 {
69959+ pax_open_kernel();
69960 sort(start, finish - start, sizeof(struct exception_table_entry),
69961 cmp_ex, NULL);
69962+ pax_close_kernel();
69963 }
69964
69965 #ifdef CONFIG_MODULES
69966diff --git a/lib/inflate.c b/lib/inflate.c
69967index 013a761..c28f3fc 100644
69968--- a/lib/inflate.c
69969+++ b/lib/inflate.c
69970@@ -269,7 +269,7 @@ static void free(void *where)
69971 malloc_ptr = free_mem_ptr;
69972 }
69973 #else
69974-#define malloc(a) kmalloc(a, GFP_KERNEL)
69975+#define malloc(a) kmalloc((a), GFP_KERNEL)
69976 #define free(a) kfree(a)
69977 #endif
69978
69979diff --git a/lib/ioremap.c b/lib/ioremap.c
69980index da4e2ad..6373b5f 100644
69981--- a/lib/ioremap.c
69982+++ b/lib/ioremap.c
69983@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
69984 unsigned long next;
69985
69986 phys_addr -= addr;
69987- pmd = pmd_alloc(&init_mm, pud, addr);
69988+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
69989 if (!pmd)
69990 return -ENOMEM;
69991 do {
69992@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
69993 unsigned long next;
69994
69995 phys_addr -= addr;
69996- pud = pud_alloc(&init_mm, pgd, addr);
69997+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
69998 if (!pud)
69999 return -ENOMEM;
70000 do {
70001diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70002index bd2bea9..6b3c95e 100644
70003--- a/lib/is_single_threaded.c
70004+++ b/lib/is_single_threaded.c
70005@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70006 struct task_struct *p, *t;
70007 bool ret;
70008
70009+ if (!mm)
70010+ return true;
70011+
70012 if (atomic_read(&task->signal->live) != 1)
70013 return false;
70014
70015diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70016index dc63d08..95ae14a 100644
70017--- a/lib/radix-tree.c
70018+++ b/lib/radix-tree.c
70019@@ -78,7 +78,7 @@ struct radix_tree_preload {
70020 int nr;
70021 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
70022 };
70023-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70024+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70025
70026 static inline void *ptr_to_indirect(void *ptr)
70027 {
70028diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70029index 38e612e..4fb99a8 100644
70030--- a/lib/vsprintf.c
70031+++ b/lib/vsprintf.c
70032@@ -16,6 +16,9 @@
70033 * - scnprintf and vscnprintf
70034 */
70035
70036+#ifdef CONFIG_GRKERNSEC_HIDESYM
70037+#define __INCLUDED_BY_HIDESYM 1
70038+#endif
70039 #include <stdarg.h>
70040 #include <linux/module.h>
70041 #include <linux/types.h>
70042@@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70043 char sym[KSYM_SYMBOL_LEN];
70044 if (ext == 'B')
70045 sprint_backtrace(sym, value);
70046- else if (ext != 'f' && ext != 's')
70047+ else if (ext != 'f' && ext != 's' && ext != 'a')
70048 sprint_symbol(sym, value);
70049 else
70050 kallsyms_lookup(value, NULL, NULL, NULL, sym);
70051@@ -789,7 +792,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70052 return number(buf, end, *(const netdev_features_t *)addr, spec);
70053 }
70054
70055+#ifdef CONFIG_GRKERNSEC_HIDESYM
70056+int kptr_restrict __read_mostly = 2;
70057+#else
70058 int kptr_restrict __read_mostly;
70059+#endif
70060
70061 /*
70062 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70063@@ -803,6 +810,8 @@ int kptr_restrict __read_mostly;
70064 * - 'S' For symbolic direct pointers with offset
70065 * - 's' For symbolic direct pointers without offset
70066 * - 'B' For backtraced symbolic direct pointers with offset
70067+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70068+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70069 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70070 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70071 * - 'M' For a 6-byte MAC address, it prints the address in the
70072@@ -848,12 +857,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70073 {
70074 if (!ptr && *fmt != 'K') {
70075 /*
70076- * Print (null) with the same width as a pointer so it makes
70077+ * Print (nil) with the same width as a pointer so it makes
70078 * tabular output look nice.
70079 */
70080 if (spec.field_width == -1)
70081 spec.field_width = 2 * sizeof(void *);
70082- return string(buf, end, "(null)", spec);
70083+ return string(buf, end, "(nil)", spec);
70084 }
70085
70086 switch (*fmt) {
70087@@ -863,6 +872,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70088 /* Fallthrough */
70089 case 'S':
70090 case 's':
70091+#ifdef CONFIG_GRKERNSEC_HIDESYM
70092+ break;
70093+#else
70094+ return symbol_string(buf, end, ptr, spec, *fmt);
70095+#endif
70096+ case 'A':
70097+ case 'a':
70098 case 'B':
70099 return symbol_string(buf, end, ptr, spec, *fmt);
70100 case 'R':
70101@@ -1633,11 +1649,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70102 typeof(type) value; \
70103 if (sizeof(type) == 8) { \
70104 args = PTR_ALIGN(args, sizeof(u32)); \
70105- *(u32 *)&value = *(u32 *)args; \
70106- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70107+ *(u32 *)&value = *(const u32 *)args; \
70108+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70109 } else { \
70110 args = PTR_ALIGN(args, sizeof(type)); \
70111- value = *(typeof(type) *)args; \
70112+ value = *(const typeof(type) *)args; \
70113 } \
70114 args += sizeof(type); \
70115 value; \
70116@@ -1700,7 +1716,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70117 case FORMAT_TYPE_STR: {
70118 const char *str_arg = args;
70119 args += strlen(str_arg) + 1;
70120- str = string(str, end, (char *)str_arg, spec);
70121+ str = string(str, end, str_arg, spec);
70122 break;
70123 }
70124
70125diff --git a/localversion-grsec b/localversion-grsec
70126new file mode 100644
70127index 0000000..7cd6065
70128--- /dev/null
70129+++ b/localversion-grsec
70130@@ -0,0 +1 @@
70131+-grsec
70132diff --git a/mm/Kconfig b/mm/Kconfig
70133index e338407..4210331 100644
70134--- a/mm/Kconfig
70135+++ b/mm/Kconfig
70136@@ -247,10 +247,10 @@ config KSM
70137 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70138
70139 config DEFAULT_MMAP_MIN_ADDR
70140- int "Low address space to protect from user allocation"
70141+ int "Low address space to protect from user allocation"
70142 depends on MMU
70143- default 4096
70144- help
70145+ default 65536
70146+ help
70147 This is the portion of low virtual memory which should be protected
70148 from userspace allocation. Keeping a user from writing to low pages
70149 can help reduce the impact of kernel NULL pointer bugs.
70150@@ -280,7 +280,7 @@ config MEMORY_FAILURE
70151
70152 config HWPOISON_INJECT
70153 tristate "HWPoison pages injector"
70154- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
70155+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
70156 select PROC_PAGE_MONITOR
70157
70158 config NOMMU_INITIAL_TRIM_EXCESS
70159diff --git a/mm/filemap.c b/mm/filemap.c
70160index b662757..3081ddd 100644
70161--- a/mm/filemap.c
70162+++ b/mm/filemap.c
70163@@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70164 struct address_space *mapping = file->f_mapping;
70165
70166 if (!mapping->a_ops->readpage)
70167- return -ENOEXEC;
70168+ return -ENODEV;
70169 file_accessed(file);
70170 vma->vm_ops = &generic_file_vm_ops;
70171 vma->vm_flags |= VM_CAN_NONLINEAR;
70172@@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70173 *pos = i_size_read(inode);
70174
70175 if (limit != RLIM_INFINITY) {
70176+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70177 if (*pos >= limit) {
70178 send_sig(SIGXFSZ, current, 0);
70179 return -EFBIG;
70180diff --git a/mm/fremap.c b/mm/fremap.c
70181index 9ed4fd4..c42648d 100644
70182--- a/mm/fremap.c
70183+++ b/mm/fremap.c
70184@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70185 retry:
70186 vma = find_vma(mm, start);
70187
70188+#ifdef CONFIG_PAX_SEGMEXEC
70189+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70190+ goto out;
70191+#endif
70192+
70193 /*
70194 * Make sure the vma is shared, that it supports prefaulting,
70195 * and that the remapped range is valid and fully within
70196diff --git a/mm/highmem.c b/mm/highmem.c
70197index 57d82c6..e9e0552 100644
70198--- a/mm/highmem.c
70199+++ b/mm/highmem.c
70200@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70201 * So no dangers, even with speculative execution.
70202 */
70203 page = pte_page(pkmap_page_table[i]);
70204+ pax_open_kernel();
70205 pte_clear(&init_mm, (unsigned long)page_address(page),
70206 &pkmap_page_table[i]);
70207-
70208+ pax_close_kernel();
70209 set_page_address(page, NULL);
70210 need_flush = 1;
70211 }
70212@@ -186,9 +187,11 @@ start:
70213 }
70214 }
70215 vaddr = PKMAP_ADDR(last_pkmap_nr);
70216+
70217+ pax_open_kernel();
70218 set_pte_at(&init_mm, vaddr,
70219 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70220-
70221+ pax_close_kernel();
70222 pkmap_count[last_pkmap_nr] = 1;
70223 set_page_address(page, (void *)vaddr);
70224
70225diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70226index 8f7fc39..69bf1e9 100644
70227--- a/mm/huge_memory.c
70228+++ b/mm/huge_memory.c
70229@@ -733,7 +733,7 @@ out:
70230 * run pte_offset_map on the pmd, if an huge pmd could
70231 * materialize from under us from a different thread.
70232 */
70233- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70234+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70235 return VM_FAULT_OOM;
70236 /* if an huge pmd materialized from under us just retry later */
70237 if (unlikely(pmd_trans_huge(*pmd)))
70238diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70239index fece520..e10da7f 100644
70240--- a/mm/hugetlb.c
70241+++ b/mm/hugetlb.c
70242@@ -2146,6 +2146,15 @@ static void hugetlb_vm_op_open(struct vm_area_struct *vma)
70243 kref_get(&reservations->refs);
70244 }
70245
70246+static void resv_map_put(struct vm_area_struct *vma)
70247+{
70248+ struct resv_map *reservations = vma_resv_map(vma);
70249+
70250+ if (!reservations)
70251+ return;
70252+ kref_put(&reservations->refs, resv_map_release);
70253+}
70254+
70255 static void hugetlb_vm_op_close(struct vm_area_struct *vma)
70256 {
70257 struct hstate *h = hstate_vma(vma);
70258@@ -2162,7 +2171,7 @@ static void hugetlb_vm_op_close(struct vm_area_struct *vma)
70259 reserve = (end - start) -
70260 region_count(&reservations->regions, start, end);
70261
70262- kref_put(&reservations->refs, resv_map_release);
70263+ resv_map_put(vma);
70264
70265 if (reserve) {
70266 hugetlb_acct_memory(h, -reserve);
70267@@ -2425,6 +2434,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70268 return 1;
70269 }
70270
70271+#ifdef CONFIG_PAX_SEGMEXEC
70272+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70273+{
70274+ struct mm_struct *mm = vma->vm_mm;
70275+ struct vm_area_struct *vma_m;
70276+ unsigned long address_m;
70277+ pte_t *ptep_m;
70278+
70279+ vma_m = pax_find_mirror_vma(vma);
70280+ if (!vma_m)
70281+ return;
70282+
70283+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70284+ address_m = address + SEGMEXEC_TASK_SIZE;
70285+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70286+ get_page(page_m);
70287+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
70288+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70289+}
70290+#endif
70291+
70292 /*
70293 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70294 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70295@@ -2537,6 +2567,11 @@ retry_avoidcopy:
70296 make_huge_pte(vma, new_page, 1));
70297 page_remove_rmap(old_page);
70298 hugepage_add_new_anon_rmap(new_page, vma, address);
70299+
70300+#ifdef CONFIG_PAX_SEGMEXEC
70301+ pax_mirror_huge_pte(vma, address, new_page);
70302+#endif
70303+
70304 /* Make the old page be freed below */
70305 new_page = old_page;
70306 mmu_notifier_invalidate_range_end(mm,
70307@@ -2691,6 +2726,10 @@ retry:
70308 && (vma->vm_flags & VM_SHARED)));
70309 set_huge_pte_at(mm, address, ptep, new_pte);
70310
70311+#ifdef CONFIG_PAX_SEGMEXEC
70312+ pax_mirror_huge_pte(vma, address, page);
70313+#endif
70314+
70315 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70316 /* Optimization, do the COW without a second fault */
70317 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70318@@ -2720,6 +2759,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70319 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70320 struct hstate *h = hstate_vma(vma);
70321
70322+#ifdef CONFIG_PAX_SEGMEXEC
70323+ struct vm_area_struct *vma_m;
70324+#endif
70325+
70326 address &= huge_page_mask(h);
70327
70328 ptep = huge_pte_offset(mm, address);
70329@@ -2733,6 +2776,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70330 VM_FAULT_SET_HINDEX(h - hstates);
70331 }
70332
70333+#ifdef CONFIG_PAX_SEGMEXEC
70334+ vma_m = pax_find_mirror_vma(vma);
70335+ if (vma_m) {
70336+ unsigned long address_m;
70337+
70338+ if (vma->vm_start > vma_m->vm_start) {
70339+ address_m = address;
70340+ address -= SEGMEXEC_TASK_SIZE;
70341+ vma = vma_m;
70342+ h = hstate_vma(vma);
70343+ } else
70344+ address_m = address + SEGMEXEC_TASK_SIZE;
70345+
70346+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70347+ return VM_FAULT_OOM;
70348+ address_m &= HPAGE_MASK;
70349+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70350+ }
70351+#endif
70352+
70353 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70354 if (!ptep)
70355 return VM_FAULT_OOM;
70356@@ -2978,12 +3041,16 @@ int hugetlb_reserve_pages(struct inode *inode,
70357 set_vma_resv_flags(vma, HPAGE_RESV_OWNER);
70358 }
70359
70360- if (chg < 0)
70361- return chg;
70362+ if (chg < 0) {
70363+ ret = chg;
70364+ goto out_err;
70365+ }
70366
70367 /* There must be enough pages in the subpool for the mapping */
70368- if (hugepage_subpool_get_pages(spool, chg))
70369- return -ENOSPC;
70370+ if (hugepage_subpool_get_pages(spool, chg)) {
70371+ ret = -ENOSPC;
70372+ goto out_err;
70373+ }
70374
70375 /*
70376 * Check enough hugepages are available for the reservation.
70377@@ -2992,7 +3059,7 @@ int hugetlb_reserve_pages(struct inode *inode,
70378 ret = hugetlb_acct_memory(h, chg);
70379 if (ret < 0) {
70380 hugepage_subpool_put_pages(spool, chg);
70381- return ret;
70382+ goto out_err;
70383 }
70384
70385 /*
70386@@ -3009,6 +3076,10 @@ int hugetlb_reserve_pages(struct inode *inode,
70387 if (!vma || vma->vm_flags & VM_MAYSHARE)
70388 region_add(&inode->i_mapping->private_list, from, to);
70389 return 0;
70390+out_err:
70391+ if (vma)
70392+ resv_map_put(vma);
70393+ return ret;
70394 }
70395
70396 void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed)
70397diff --git a/mm/internal.h b/mm/internal.h
70398index 2189af4..f2ca332 100644
70399--- a/mm/internal.h
70400+++ b/mm/internal.h
70401@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70402 * in mm/page_alloc.c
70403 */
70404 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70405+extern void free_compound_page(struct page *page);
70406 extern void prep_compound_page(struct page *page, unsigned long order);
70407 #ifdef CONFIG_MEMORY_FAILURE
70408 extern bool is_free_buddy_page(struct page *page);
70409diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70410index 45eb621..6ccd8ea 100644
70411--- a/mm/kmemleak.c
70412+++ b/mm/kmemleak.c
70413@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70414
70415 for (i = 0; i < object->trace_len; i++) {
70416 void *ptr = (void *)object->trace[i];
70417- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70418+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70419 }
70420 }
70421
70422diff --git a/mm/maccess.c b/mm/maccess.c
70423index d53adf9..03a24bf 100644
70424--- a/mm/maccess.c
70425+++ b/mm/maccess.c
70426@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70427 set_fs(KERNEL_DS);
70428 pagefault_disable();
70429 ret = __copy_from_user_inatomic(dst,
70430- (__force const void __user *)src, size);
70431+ (const void __force_user *)src, size);
70432 pagefault_enable();
70433 set_fs(old_fs);
70434
70435@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70436
70437 set_fs(KERNEL_DS);
70438 pagefault_disable();
70439- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70440+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70441 pagefault_enable();
70442 set_fs(old_fs);
70443
70444diff --git a/mm/madvise.c b/mm/madvise.c
70445index 74bf193..feb6fd3 100644
70446--- a/mm/madvise.c
70447+++ b/mm/madvise.c
70448@@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70449 pgoff_t pgoff;
70450 unsigned long new_flags = vma->vm_flags;
70451
70452+#ifdef CONFIG_PAX_SEGMEXEC
70453+ struct vm_area_struct *vma_m;
70454+#endif
70455+
70456 switch (behavior) {
70457 case MADV_NORMAL:
70458 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70459@@ -110,6 +114,13 @@ success:
70460 /*
70461 * vm_flags is protected by the mmap_sem held in write mode.
70462 */
70463+
70464+#ifdef CONFIG_PAX_SEGMEXEC
70465+ vma_m = pax_find_mirror_vma(vma);
70466+ if (vma_m)
70467+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70468+#endif
70469+
70470 vma->vm_flags = new_flags;
70471
70472 out:
70473@@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70474 struct vm_area_struct ** prev,
70475 unsigned long start, unsigned long end)
70476 {
70477+
70478+#ifdef CONFIG_PAX_SEGMEXEC
70479+ struct vm_area_struct *vma_m;
70480+#endif
70481+
70482 *prev = vma;
70483 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70484 return -EINVAL;
70485@@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70486 zap_page_range(vma, start, end - start, &details);
70487 } else
70488 zap_page_range(vma, start, end - start, NULL);
70489+
70490+#ifdef CONFIG_PAX_SEGMEXEC
70491+ vma_m = pax_find_mirror_vma(vma);
70492+ if (vma_m) {
70493+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70494+ struct zap_details details = {
70495+ .nonlinear_vma = vma_m,
70496+ .last_index = ULONG_MAX,
70497+ };
70498+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70499+ } else
70500+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70501+ }
70502+#endif
70503+
70504 return 0;
70505 }
70506
70507@@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70508 if (end < start)
70509 goto out;
70510
70511+#ifdef CONFIG_PAX_SEGMEXEC
70512+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70513+ if (end > SEGMEXEC_TASK_SIZE)
70514+ goto out;
70515+ } else
70516+#endif
70517+
70518+ if (end > TASK_SIZE)
70519+ goto out;
70520+
70521 error = 0;
70522 if (end == start)
70523 goto out;
70524diff --git a/mm/memory-failure.c b/mm/memory-failure.c
70525index 56080ea..115071e 100644
70526--- a/mm/memory-failure.c
70527+++ b/mm/memory-failure.c
70528@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
70529
70530 int sysctl_memory_failure_recovery __read_mostly = 1;
70531
70532-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70533+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70534
70535 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
70536
70537@@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
70538 si.si_signo = SIGBUS;
70539 si.si_errno = 0;
70540 si.si_code = BUS_MCEERR_AO;
70541- si.si_addr = (void *)addr;
70542+ si.si_addr = (void __user *)addr;
70543 #ifdef __ARCH_SI_TRAPNO
70544 si.si_trapno = trapno;
70545 #endif
70546@@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70547 }
70548
70549 nr_pages = 1 << compound_trans_order(hpage);
70550- atomic_long_add(nr_pages, &mce_bad_pages);
70551+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
70552
70553 /*
70554 * We need/can do nothing about count=0 pages.
70555@@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70556 if (!PageHWPoison(hpage)
70557 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
70558 || (p != hpage && TestSetPageHWPoison(hpage))) {
70559- atomic_long_sub(nr_pages, &mce_bad_pages);
70560+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70561 return 0;
70562 }
70563 set_page_hwpoison_huge_page(hpage);
70564@@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70565 }
70566 if (hwpoison_filter(p)) {
70567 if (TestClearPageHWPoison(p))
70568- atomic_long_sub(nr_pages, &mce_bad_pages);
70569+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70570 unlock_page(hpage);
70571 put_page(hpage);
70572 return 0;
70573@@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
70574 return 0;
70575 }
70576 if (TestClearPageHWPoison(p))
70577- atomic_long_sub(nr_pages, &mce_bad_pages);
70578+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70579 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
70580 return 0;
70581 }
70582@@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
70583 */
70584 if (TestClearPageHWPoison(page)) {
70585 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
70586- atomic_long_sub(nr_pages, &mce_bad_pages);
70587+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70588 freeit = 1;
70589 if (PageHuge(page))
70590 clear_page_hwpoison_huge_page(page);
70591@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
70592 }
70593 done:
70594 if (!PageHWPoison(hpage))
70595- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
70596+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
70597 set_page_hwpoison_huge_page(hpage);
70598 dequeue_hwpoisoned_huge_page(hpage);
70599 /* keep elevated page count for bad page */
70600@@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
70601 return ret;
70602
70603 done:
70604- atomic_long_add(1, &mce_bad_pages);
70605+ atomic_long_add_unchecked(1, &mce_bad_pages);
70606 SetPageHWPoison(page);
70607 /* keep elevated page count for bad page */
70608 return ret;
70609diff --git a/mm/memory.c b/mm/memory.c
70610index 10b4dda..06857f3 100644
70611--- a/mm/memory.c
70612+++ b/mm/memory.c
70613@@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
70614 return;
70615
70616 pmd = pmd_offset(pud, start);
70617+
70618+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
70619 pud_clear(pud);
70620 pmd_free_tlb(tlb, pmd, start);
70621+#endif
70622+
70623 }
70624
70625 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70626@@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70627 if (end - 1 > ceiling - 1)
70628 return;
70629
70630+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
70631 pud = pud_offset(pgd, start);
70632 pgd_clear(pgd);
70633 pud_free_tlb(tlb, pud, start);
70634+#endif
70635+
70636 }
70637
70638 /*
70639@@ -1593,12 +1600,6 @@ no_page_table:
70640 return page;
70641 }
70642
70643-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
70644-{
70645- return stack_guard_page_start(vma, addr) ||
70646- stack_guard_page_end(vma, addr+PAGE_SIZE);
70647-}
70648-
70649 /**
70650 * __get_user_pages() - pin user pages in memory
70651 * @tsk: task_struct of target task
70652@@ -1671,10 +1672,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70653 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
70654 i = 0;
70655
70656- do {
70657+ while (nr_pages) {
70658 struct vm_area_struct *vma;
70659
70660- vma = find_extend_vma(mm, start);
70661+ vma = find_vma(mm, start);
70662 if (!vma && in_gate_area(mm, start)) {
70663 unsigned long pg = start & PAGE_MASK;
70664 pgd_t *pgd;
70665@@ -1722,7 +1723,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70666 goto next_page;
70667 }
70668
70669- if (!vma ||
70670+ if (!vma || start < vma->vm_start ||
70671 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
70672 !(vm_flags & vma->vm_flags))
70673 return i ? : -EFAULT;
70674@@ -1749,11 +1750,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70675 int ret;
70676 unsigned int fault_flags = 0;
70677
70678- /* For mlock, just skip the stack guard page. */
70679- if (foll_flags & FOLL_MLOCK) {
70680- if (stack_guard_page(vma, start))
70681- goto next_page;
70682- }
70683 if (foll_flags & FOLL_WRITE)
70684 fault_flags |= FAULT_FLAG_WRITE;
70685 if (nonblocking)
70686@@ -1827,7 +1823,7 @@ next_page:
70687 start += PAGE_SIZE;
70688 nr_pages--;
70689 } while (nr_pages && start < vma->vm_end);
70690- } while (nr_pages);
70691+ }
70692 return i;
70693 }
70694 EXPORT_SYMBOL(__get_user_pages);
70695@@ -2034,6 +2030,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
70696 page_add_file_rmap(page);
70697 set_pte_at(mm, addr, pte, mk_pte(page, prot));
70698
70699+#ifdef CONFIG_PAX_SEGMEXEC
70700+ pax_mirror_file_pte(vma, addr, page, ptl);
70701+#endif
70702+
70703 retval = 0;
70704 pte_unmap_unlock(pte, ptl);
70705 return retval;
70706@@ -2068,10 +2068,22 @@ out:
70707 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
70708 struct page *page)
70709 {
70710+
70711+#ifdef CONFIG_PAX_SEGMEXEC
70712+ struct vm_area_struct *vma_m;
70713+#endif
70714+
70715 if (addr < vma->vm_start || addr >= vma->vm_end)
70716 return -EFAULT;
70717 if (!page_count(page))
70718 return -EINVAL;
70719+
70720+#ifdef CONFIG_PAX_SEGMEXEC
70721+ vma_m = pax_find_mirror_vma(vma);
70722+ if (vma_m)
70723+ vma_m->vm_flags |= VM_INSERTPAGE;
70724+#endif
70725+
70726 vma->vm_flags |= VM_INSERTPAGE;
70727 return insert_page(vma, addr, page, vma->vm_page_prot);
70728 }
70729@@ -2157,6 +2169,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
70730 unsigned long pfn)
70731 {
70732 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
70733+ BUG_ON(vma->vm_mirror);
70734
70735 if (addr < vma->vm_start || addr >= vma->vm_end)
70736 return -EFAULT;
70737@@ -2364,7 +2377,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
70738
70739 BUG_ON(pud_huge(*pud));
70740
70741- pmd = pmd_alloc(mm, pud, addr);
70742+ pmd = (mm == &init_mm) ?
70743+ pmd_alloc_kernel(mm, pud, addr) :
70744+ pmd_alloc(mm, pud, addr);
70745 if (!pmd)
70746 return -ENOMEM;
70747 do {
70748@@ -2384,7 +2399,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
70749 unsigned long next;
70750 int err;
70751
70752- pud = pud_alloc(mm, pgd, addr);
70753+ pud = (mm == &init_mm) ?
70754+ pud_alloc_kernel(mm, pgd, addr) :
70755+ pud_alloc(mm, pgd, addr);
70756 if (!pud)
70757 return -ENOMEM;
70758 do {
70759@@ -2472,6 +2489,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
70760 copy_user_highpage(dst, src, va, vma);
70761 }
70762
70763+#ifdef CONFIG_PAX_SEGMEXEC
70764+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
70765+{
70766+ struct mm_struct *mm = vma->vm_mm;
70767+ spinlock_t *ptl;
70768+ pte_t *pte, entry;
70769+
70770+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
70771+ entry = *pte;
70772+ if (!pte_present(entry)) {
70773+ if (!pte_none(entry)) {
70774+ BUG_ON(pte_file(entry));
70775+ free_swap_and_cache(pte_to_swp_entry(entry));
70776+ pte_clear_not_present_full(mm, address, pte, 0);
70777+ }
70778+ } else {
70779+ struct page *page;
70780+
70781+ flush_cache_page(vma, address, pte_pfn(entry));
70782+ entry = ptep_clear_flush(vma, address, pte);
70783+ BUG_ON(pte_dirty(entry));
70784+ page = vm_normal_page(vma, address, entry);
70785+ if (page) {
70786+ update_hiwater_rss(mm);
70787+ if (PageAnon(page))
70788+ dec_mm_counter_fast(mm, MM_ANONPAGES);
70789+ else
70790+ dec_mm_counter_fast(mm, MM_FILEPAGES);
70791+ page_remove_rmap(page);
70792+ page_cache_release(page);
70793+ }
70794+ }
70795+ pte_unmap_unlock(pte, ptl);
70796+}
70797+
70798+/* PaX: if vma is mirrored, synchronize the mirror's PTE
70799+ *
70800+ * the ptl of the lower mapped page is held on entry and is not released on exit
70801+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
70802+ */
70803+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70804+{
70805+ struct mm_struct *mm = vma->vm_mm;
70806+ unsigned long address_m;
70807+ spinlock_t *ptl_m;
70808+ struct vm_area_struct *vma_m;
70809+ pmd_t *pmd_m;
70810+ pte_t *pte_m, entry_m;
70811+
70812+ BUG_ON(!page_m || !PageAnon(page_m));
70813+
70814+ vma_m = pax_find_mirror_vma(vma);
70815+ if (!vma_m)
70816+ return;
70817+
70818+ BUG_ON(!PageLocked(page_m));
70819+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70820+ address_m = address + SEGMEXEC_TASK_SIZE;
70821+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70822+ pte_m = pte_offset_map(pmd_m, address_m);
70823+ ptl_m = pte_lockptr(mm, pmd_m);
70824+ if (ptl != ptl_m) {
70825+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70826+ if (!pte_none(*pte_m))
70827+ goto out;
70828+ }
70829+
70830+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70831+ page_cache_get(page_m);
70832+ page_add_anon_rmap(page_m, vma_m, address_m);
70833+ inc_mm_counter_fast(mm, MM_ANONPAGES);
70834+ set_pte_at(mm, address_m, pte_m, entry_m);
70835+ update_mmu_cache(vma_m, address_m, entry_m);
70836+out:
70837+ if (ptl != ptl_m)
70838+ spin_unlock(ptl_m);
70839+ pte_unmap(pte_m);
70840+ unlock_page(page_m);
70841+}
70842+
70843+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70844+{
70845+ struct mm_struct *mm = vma->vm_mm;
70846+ unsigned long address_m;
70847+ spinlock_t *ptl_m;
70848+ struct vm_area_struct *vma_m;
70849+ pmd_t *pmd_m;
70850+ pte_t *pte_m, entry_m;
70851+
70852+ BUG_ON(!page_m || PageAnon(page_m));
70853+
70854+ vma_m = pax_find_mirror_vma(vma);
70855+ if (!vma_m)
70856+ return;
70857+
70858+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70859+ address_m = address + SEGMEXEC_TASK_SIZE;
70860+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70861+ pte_m = pte_offset_map(pmd_m, address_m);
70862+ ptl_m = pte_lockptr(mm, pmd_m);
70863+ if (ptl != ptl_m) {
70864+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70865+ if (!pte_none(*pte_m))
70866+ goto out;
70867+ }
70868+
70869+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70870+ page_cache_get(page_m);
70871+ page_add_file_rmap(page_m);
70872+ inc_mm_counter_fast(mm, MM_FILEPAGES);
70873+ set_pte_at(mm, address_m, pte_m, entry_m);
70874+ update_mmu_cache(vma_m, address_m, entry_m);
70875+out:
70876+ if (ptl != ptl_m)
70877+ spin_unlock(ptl_m);
70878+ pte_unmap(pte_m);
70879+}
70880+
70881+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
70882+{
70883+ struct mm_struct *mm = vma->vm_mm;
70884+ unsigned long address_m;
70885+ spinlock_t *ptl_m;
70886+ struct vm_area_struct *vma_m;
70887+ pmd_t *pmd_m;
70888+ pte_t *pte_m, entry_m;
70889+
70890+ vma_m = pax_find_mirror_vma(vma);
70891+ if (!vma_m)
70892+ return;
70893+
70894+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70895+ address_m = address + SEGMEXEC_TASK_SIZE;
70896+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70897+ pte_m = pte_offset_map(pmd_m, address_m);
70898+ ptl_m = pte_lockptr(mm, pmd_m);
70899+ if (ptl != ptl_m) {
70900+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70901+ if (!pte_none(*pte_m))
70902+ goto out;
70903+ }
70904+
70905+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
70906+ set_pte_at(mm, address_m, pte_m, entry_m);
70907+out:
70908+ if (ptl != ptl_m)
70909+ spin_unlock(ptl_m);
70910+ pte_unmap(pte_m);
70911+}
70912+
70913+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
70914+{
70915+ struct page *page_m;
70916+ pte_t entry;
70917+
70918+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
70919+ goto out;
70920+
70921+ entry = *pte;
70922+ page_m = vm_normal_page(vma, address, entry);
70923+ if (!page_m)
70924+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
70925+ else if (PageAnon(page_m)) {
70926+ if (pax_find_mirror_vma(vma)) {
70927+ pte_unmap_unlock(pte, ptl);
70928+ lock_page(page_m);
70929+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
70930+ if (pte_same(entry, *pte))
70931+ pax_mirror_anon_pte(vma, address, page_m, ptl);
70932+ else
70933+ unlock_page(page_m);
70934+ }
70935+ } else
70936+ pax_mirror_file_pte(vma, address, page_m, ptl);
70937+
70938+out:
70939+ pte_unmap_unlock(pte, ptl);
70940+}
70941+#endif
70942+
70943 /*
70944 * This routine handles present pages, when users try to write
70945 * to a shared page. It is done by copying the page to a new address
70946@@ -2683,6 +2880,12 @@ gotten:
70947 */
70948 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70949 if (likely(pte_same(*page_table, orig_pte))) {
70950+
70951+#ifdef CONFIG_PAX_SEGMEXEC
70952+ if (pax_find_mirror_vma(vma))
70953+ BUG_ON(!trylock_page(new_page));
70954+#endif
70955+
70956 if (old_page) {
70957 if (!PageAnon(old_page)) {
70958 dec_mm_counter_fast(mm, MM_FILEPAGES);
70959@@ -2734,6 +2937,10 @@ gotten:
70960 page_remove_rmap(old_page);
70961 }
70962
70963+#ifdef CONFIG_PAX_SEGMEXEC
70964+ pax_mirror_anon_pte(vma, address, new_page, ptl);
70965+#endif
70966+
70967 /* Free the old page.. */
70968 new_page = old_page;
70969 ret |= VM_FAULT_WRITE;
70970@@ -3013,6 +3220,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70971 swap_free(entry);
70972 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
70973 try_to_free_swap(page);
70974+
70975+#ifdef CONFIG_PAX_SEGMEXEC
70976+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
70977+#endif
70978+
70979 unlock_page(page);
70980 if (swapcache) {
70981 /*
70982@@ -3036,6 +3248,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70983
70984 /* No need to invalidate - it was non-present before */
70985 update_mmu_cache(vma, address, page_table);
70986+
70987+#ifdef CONFIG_PAX_SEGMEXEC
70988+ pax_mirror_anon_pte(vma, address, page, ptl);
70989+#endif
70990+
70991 unlock:
70992 pte_unmap_unlock(page_table, ptl);
70993 out:
70994@@ -3055,40 +3272,6 @@ out_release:
70995 }
70996
70997 /*
70998- * This is like a special single-page "expand_{down|up}wards()",
70999- * except we must first make sure that 'address{-|+}PAGE_SIZE'
71000- * doesn't hit another vma.
71001- */
71002-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71003-{
71004- address &= PAGE_MASK;
71005- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71006- struct vm_area_struct *prev = vma->vm_prev;
71007-
71008- /*
71009- * Is there a mapping abutting this one below?
71010- *
71011- * That's only ok if it's the same stack mapping
71012- * that has gotten split..
71013- */
71014- if (prev && prev->vm_end == address)
71015- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71016-
71017- expand_downwards(vma, address - PAGE_SIZE);
71018- }
71019- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71020- struct vm_area_struct *next = vma->vm_next;
71021-
71022- /* As VM_GROWSDOWN but s/below/above/ */
71023- if (next && next->vm_start == address + PAGE_SIZE)
71024- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71025-
71026- expand_upwards(vma, address + PAGE_SIZE);
71027- }
71028- return 0;
71029-}
71030-
71031-/*
71032 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71033 * but allow concurrent faults), and pte mapped but not yet locked.
71034 * We return with mmap_sem still held, but pte unmapped and unlocked.
71035@@ -3097,27 +3280,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71036 unsigned long address, pte_t *page_table, pmd_t *pmd,
71037 unsigned int flags)
71038 {
71039- struct page *page;
71040+ struct page *page = NULL;
71041 spinlock_t *ptl;
71042 pte_t entry;
71043
71044- pte_unmap(page_table);
71045-
71046- /* Check if we need to add a guard page to the stack */
71047- if (check_stack_guard_page(vma, address) < 0)
71048- return VM_FAULT_SIGBUS;
71049-
71050- /* Use the zero-page for reads */
71051 if (!(flags & FAULT_FLAG_WRITE)) {
71052 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71053 vma->vm_page_prot));
71054- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71055+ ptl = pte_lockptr(mm, pmd);
71056+ spin_lock(ptl);
71057 if (!pte_none(*page_table))
71058 goto unlock;
71059 goto setpte;
71060 }
71061
71062 /* Allocate our own private page. */
71063+ pte_unmap(page_table);
71064+
71065 if (unlikely(anon_vma_prepare(vma)))
71066 goto oom;
71067 page = alloc_zeroed_user_highpage_movable(vma, address);
71068@@ -3136,6 +3315,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71069 if (!pte_none(*page_table))
71070 goto release;
71071
71072+#ifdef CONFIG_PAX_SEGMEXEC
71073+ if (pax_find_mirror_vma(vma))
71074+ BUG_ON(!trylock_page(page));
71075+#endif
71076+
71077 inc_mm_counter_fast(mm, MM_ANONPAGES);
71078 page_add_new_anon_rmap(page, vma, address);
71079 setpte:
71080@@ -3143,6 +3327,12 @@ setpte:
71081
71082 /* No need to invalidate - it was non-present before */
71083 update_mmu_cache(vma, address, page_table);
71084+
71085+#ifdef CONFIG_PAX_SEGMEXEC
71086+ if (page)
71087+ pax_mirror_anon_pte(vma, address, page, ptl);
71088+#endif
71089+
71090 unlock:
71091 pte_unmap_unlock(page_table, ptl);
71092 return 0;
71093@@ -3286,6 +3476,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71094 */
71095 /* Only go through if we didn't race with anybody else... */
71096 if (likely(pte_same(*page_table, orig_pte))) {
71097+
71098+#ifdef CONFIG_PAX_SEGMEXEC
71099+ if (anon && pax_find_mirror_vma(vma))
71100+ BUG_ON(!trylock_page(page));
71101+#endif
71102+
71103 flush_icache_page(vma, page);
71104 entry = mk_pte(page, vma->vm_page_prot);
71105 if (flags & FAULT_FLAG_WRITE)
71106@@ -3305,6 +3501,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71107
71108 /* no need to invalidate: a not-present page won't be cached */
71109 update_mmu_cache(vma, address, page_table);
71110+
71111+#ifdef CONFIG_PAX_SEGMEXEC
71112+ if (anon)
71113+ pax_mirror_anon_pte(vma, address, page, ptl);
71114+ else
71115+ pax_mirror_file_pte(vma, address, page, ptl);
71116+#endif
71117+
71118 } else {
71119 if (cow_page)
71120 mem_cgroup_uncharge_page(cow_page);
71121@@ -3458,6 +3662,12 @@ int handle_pte_fault(struct mm_struct *mm,
71122 if (flags & FAULT_FLAG_WRITE)
71123 flush_tlb_fix_spurious_fault(vma, address);
71124 }
71125+
71126+#ifdef CONFIG_PAX_SEGMEXEC
71127+ pax_mirror_pte(vma, address, pte, pmd, ptl);
71128+ return 0;
71129+#endif
71130+
71131 unlock:
71132 pte_unmap_unlock(pte, ptl);
71133 return 0;
71134@@ -3474,6 +3684,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71135 pmd_t *pmd;
71136 pte_t *pte;
71137
71138+#ifdef CONFIG_PAX_SEGMEXEC
71139+ struct vm_area_struct *vma_m;
71140+#endif
71141+
71142 __set_current_state(TASK_RUNNING);
71143
71144 count_vm_event(PGFAULT);
71145@@ -3485,6 +3699,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71146 if (unlikely(is_vm_hugetlb_page(vma)))
71147 return hugetlb_fault(mm, vma, address, flags);
71148
71149+#ifdef CONFIG_PAX_SEGMEXEC
71150+ vma_m = pax_find_mirror_vma(vma);
71151+ if (vma_m) {
71152+ unsigned long address_m;
71153+ pgd_t *pgd_m;
71154+ pud_t *pud_m;
71155+ pmd_t *pmd_m;
71156+
71157+ if (vma->vm_start > vma_m->vm_start) {
71158+ address_m = address;
71159+ address -= SEGMEXEC_TASK_SIZE;
71160+ vma = vma_m;
71161+ } else
71162+ address_m = address + SEGMEXEC_TASK_SIZE;
71163+
71164+ pgd_m = pgd_offset(mm, address_m);
71165+ pud_m = pud_alloc(mm, pgd_m, address_m);
71166+ if (!pud_m)
71167+ return VM_FAULT_OOM;
71168+ pmd_m = pmd_alloc(mm, pud_m, address_m);
71169+ if (!pmd_m)
71170+ return VM_FAULT_OOM;
71171+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71172+ return VM_FAULT_OOM;
71173+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71174+ }
71175+#endif
71176+
71177 pgd = pgd_offset(mm, address);
71178 pud = pud_alloc(mm, pgd, address);
71179 if (!pud)
71180@@ -3514,7 +3756,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71181 * run pte_offset_map on the pmd, if an huge pmd could
71182 * materialize from under us from a different thread.
71183 */
71184- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71185+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71186 return VM_FAULT_OOM;
71187 /* if an huge pmd materialized from under us just retry later */
71188 if (unlikely(pmd_trans_huge(*pmd)))
71189@@ -3551,6 +3793,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71190 spin_unlock(&mm->page_table_lock);
71191 return 0;
71192 }
71193+
71194+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71195+{
71196+ pud_t *new = pud_alloc_one(mm, address);
71197+ if (!new)
71198+ return -ENOMEM;
71199+
71200+ smp_wmb(); /* See comment in __pte_alloc */
71201+
71202+ spin_lock(&mm->page_table_lock);
71203+ if (pgd_present(*pgd)) /* Another has populated it */
71204+ pud_free(mm, new);
71205+ else
71206+ pgd_populate_kernel(mm, pgd, new);
71207+ spin_unlock(&mm->page_table_lock);
71208+ return 0;
71209+}
71210 #endif /* __PAGETABLE_PUD_FOLDED */
71211
71212 #ifndef __PAGETABLE_PMD_FOLDED
71213@@ -3581,6 +3840,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71214 spin_unlock(&mm->page_table_lock);
71215 return 0;
71216 }
71217+
71218+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71219+{
71220+ pmd_t *new = pmd_alloc_one(mm, address);
71221+ if (!new)
71222+ return -ENOMEM;
71223+
71224+ smp_wmb(); /* See comment in __pte_alloc */
71225+
71226+ spin_lock(&mm->page_table_lock);
71227+#ifndef __ARCH_HAS_4LEVEL_HACK
71228+ if (pud_present(*pud)) /* Another has populated it */
71229+ pmd_free(mm, new);
71230+ else
71231+ pud_populate_kernel(mm, pud, new);
71232+#else
71233+ if (pgd_present(*pud)) /* Another has populated it */
71234+ pmd_free(mm, new);
71235+ else
71236+ pgd_populate_kernel(mm, pud, new);
71237+#endif /* __ARCH_HAS_4LEVEL_HACK */
71238+ spin_unlock(&mm->page_table_lock);
71239+ return 0;
71240+}
71241 #endif /* __PAGETABLE_PMD_FOLDED */
71242
71243 int make_pages_present(unsigned long addr, unsigned long end)
71244@@ -3618,7 +3901,7 @@ static int __init gate_vma_init(void)
71245 gate_vma.vm_start = FIXADDR_USER_START;
71246 gate_vma.vm_end = FIXADDR_USER_END;
71247 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71248- gate_vma.vm_page_prot = __P101;
71249+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71250 /*
71251 * Make sure the vDSO gets into every core dump.
71252 * Dumping its contents makes post-mortem fully interpretable later
71253diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71254index 0a37570..2048346 100644
71255--- a/mm/mempolicy.c
71256+++ b/mm/mempolicy.c
71257@@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71258 unsigned long vmstart;
71259 unsigned long vmend;
71260
71261+#ifdef CONFIG_PAX_SEGMEXEC
71262+ struct vm_area_struct *vma_m;
71263+#endif
71264+
71265 vma = find_vma(mm, start);
71266 if (!vma || vma->vm_start > start)
71267 return -EFAULT;
71268@@ -679,6 +683,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71269 err = policy_vma(vma, new_pol);
71270 if (err)
71271 goto out;
71272+
71273+#ifdef CONFIG_PAX_SEGMEXEC
71274+ vma_m = pax_find_mirror_vma(vma);
71275+ if (vma_m) {
71276+ err = policy_vma(vma_m, new_pol);
71277+ if (err)
71278+ goto out;
71279+ }
71280+#endif
71281+
71282 }
71283
71284 out:
71285@@ -1112,6 +1126,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71286
71287 if (end < start)
71288 return -EINVAL;
71289+
71290+#ifdef CONFIG_PAX_SEGMEXEC
71291+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71292+ if (end > SEGMEXEC_TASK_SIZE)
71293+ return -EINVAL;
71294+ } else
71295+#endif
71296+
71297+ if (end > TASK_SIZE)
71298+ return -EINVAL;
71299+
71300 if (end == start)
71301 return 0;
71302
71303@@ -1330,6 +1355,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71304 if (!mm)
71305 goto out;
71306
71307+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71308+ if (mm != current->mm &&
71309+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71310+ err = -EPERM;
71311+ goto out;
71312+ }
71313+#endif
71314+
71315 /*
71316 * Check if this process has the right to modify the specified
71317 * process. The right exists if the process has administrative
71318@@ -1339,8 +1372,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71319 rcu_read_lock();
71320 tcred = __task_cred(task);
71321 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71322- cred->uid != tcred->suid && cred->uid != tcred->uid &&
71323- !capable(CAP_SYS_NICE)) {
71324+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71325 rcu_read_unlock();
71326 err = -EPERM;
71327 goto out;
71328diff --git a/mm/migrate.c b/mm/migrate.c
71329index 1503b6b..156c672 100644
71330--- a/mm/migrate.c
71331+++ b/mm/migrate.c
71332@@ -1370,6 +1370,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71333 if (!mm)
71334 return -EINVAL;
71335
71336+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71337+ if (mm != current->mm &&
71338+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71339+ err = -EPERM;
71340+ goto out;
71341+ }
71342+#endif
71343+
71344 /*
71345 * Check if this process has the right to modify the specified
71346 * process. The right exists if the process has administrative
71347@@ -1379,8 +1387,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71348 rcu_read_lock();
71349 tcred = __task_cred(task);
71350 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71351- cred->uid != tcred->suid && cred->uid != tcred->uid &&
71352- !capable(CAP_SYS_NICE)) {
71353+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71354 rcu_read_unlock();
71355 err = -EPERM;
71356 goto out;
71357diff --git a/mm/mlock.c b/mm/mlock.c
71358index ef726e8..13e0901 100644
71359--- a/mm/mlock.c
71360+++ b/mm/mlock.c
71361@@ -13,6 +13,7 @@
71362 #include <linux/pagemap.h>
71363 #include <linux/mempolicy.h>
71364 #include <linux/syscalls.h>
71365+#include <linux/security.h>
71366 #include <linux/sched.h>
71367 #include <linux/export.h>
71368 #include <linux/rmap.h>
71369@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71370 return -EINVAL;
71371 if (end == start)
71372 return 0;
71373+ if (end > TASK_SIZE)
71374+ return -EINVAL;
71375+
71376 vma = find_vma(current->mm, start);
71377 if (!vma || vma->vm_start > start)
71378 return -ENOMEM;
71379@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71380 for (nstart = start ; ; ) {
71381 vm_flags_t newflags;
71382
71383+#ifdef CONFIG_PAX_SEGMEXEC
71384+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71385+ break;
71386+#endif
71387+
71388 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71389
71390 newflags = vma->vm_flags | VM_LOCKED;
71391@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71392 lock_limit >>= PAGE_SHIFT;
71393
71394 /* check against resource limits */
71395+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71396 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71397 error = do_mlock(start, len, 1);
71398 up_write(&current->mm->mmap_sem);
71399@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71400 static int do_mlockall(int flags)
71401 {
71402 struct vm_area_struct * vma, * prev = NULL;
71403- unsigned int def_flags = 0;
71404
71405 if (flags & MCL_FUTURE)
71406- def_flags = VM_LOCKED;
71407- current->mm->def_flags = def_flags;
71408+ current->mm->def_flags |= VM_LOCKED;
71409+ else
71410+ current->mm->def_flags &= ~VM_LOCKED;
71411 if (flags == MCL_FUTURE)
71412 goto out;
71413
71414 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71415 vm_flags_t newflags;
71416
71417+#ifdef CONFIG_PAX_SEGMEXEC
71418+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71419+ break;
71420+#endif
71421+
71422+ BUG_ON(vma->vm_end > TASK_SIZE);
71423 newflags = vma->vm_flags | VM_LOCKED;
71424 if (!(flags & MCL_CURRENT))
71425 newflags &= ~VM_LOCKED;
71426@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71427 lock_limit >>= PAGE_SHIFT;
71428
71429 ret = -ENOMEM;
71430+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71431 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71432 capable(CAP_IPC_LOCK))
71433 ret = do_mlockall(flags);
71434diff --git a/mm/mmap.c b/mm/mmap.c
71435index da15a79..314aef3 100644
71436--- a/mm/mmap.c
71437+++ b/mm/mmap.c
71438@@ -46,6 +46,16 @@
71439 #define arch_rebalance_pgtables(addr, len) (addr)
71440 #endif
71441
71442+static inline void verify_mm_writelocked(struct mm_struct *mm)
71443+{
71444+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71445+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71446+ up_read(&mm->mmap_sem);
71447+ BUG();
71448+ }
71449+#endif
71450+}
71451+
71452 static void unmap_region(struct mm_struct *mm,
71453 struct vm_area_struct *vma, struct vm_area_struct *prev,
71454 unsigned long start, unsigned long end);
71455@@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
71456 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71457 *
71458 */
71459-pgprot_t protection_map[16] = {
71460+pgprot_t protection_map[16] __read_only = {
71461 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71462 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71463 };
71464
71465-pgprot_t vm_get_page_prot(unsigned long vm_flags)
71466+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71467 {
71468- return __pgprot(pgprot_val(protection_map[vm_flags &
71469+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71470 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71471 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71472+
71473+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71474+ if (!(__supported_pte_mask & _PAGE_NX) &&
71475+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71476+ (vm_flags & (VM_READ | VM_WRITE)))
71477+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71478+#endif
71479+
71480+ return prot;
71481 }
71482 EXPORT_SYMBOL(vm_get_page_prot);
71483
71484 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71485 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71486 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71487+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71488 /*
71489 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71490 * other variables. It can be updated by several CPUs frequently.
71491@@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71492 struct vm_area_struct *next = vma->vm_next;
71493
71494 might_sleep();
71495+ BUG_ON(vma->vm_mirror);
71496 if (vma->vm_ops && vma->vm_ops->close)
71497 vma->vm_ops->close(vma);
71498 if (vma->vm_file) {
71499@@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71500 * not page aligned -Ram Gupta
71501 */
71502 rlim = rlimit(RLIMIT_DATA);
71503+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71504 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71505 (mm->end_data - mm->start_data) > rlim)
71506 goto out;
71507@@ -689,6 +711,12 @@ static int
71508 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71509 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71510 {
71511+
71512+#ifdef CONFIG_PAX_SEGMEXEC
71513+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71514+ return 0;
71515+#endif
71516+
71517 if (is_mergeable_vma(vma, file, vm_flags) &&
71518 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71519 if (vma->vm_pgoff == vm_pgoff)
71520@@ -708,6 +736,12 @@ static int
71521 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71522 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71523 {
71524+
71525+#ifdef CONFIG_PAX_SEGMEXEC
71526+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71527+ return 0;
71528+#endif
71529+
71530 if (is_mergeable_vma(vma, file, vm_flags) &&
71531 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71532 pgoff_t vm_pglen;
71533@@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71534 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71535 struct vm_area_struct *prev, unsigned long addr,
71536 unsigned long end, unsigned long vm_flags,
71537- struct anon_vma *anon_vma, struct file *file,
71538+ struct anon_vma *anon_vma, struct file *file,
71539 pgoff_t pgoff, struct mempolicy *policy)
71540 {
71541 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71542 struct vm_area_struct *area, *next;
71543 int err;
71544
71545+#ifdef CONFIG_PAX_SEGMEXEC
71546+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
71547+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
71548+
71549+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
71550+#endif
71551+
71552 /*
71553 * We later require that vma->vm_flags == vm_flags,
71554 * so this tests vma->vm_flags & VM_SPECIAL, too.
71555@@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71556 if (next && next->vm_end == end) /* cases 6, 7, 8 */
71557 next = next->vm_next;
71558
71559+#ifdef CONFIG_PAX_SEGMEXEC
71560+ if (prev)
71561+ prev_m = pax_find_mirror_vma(prev);
71562+ if (area)
71563+ area_m = pax_find_mirror_vma(area);
71564+ if (next)
71565+ next_m = pax_find_mirror_vma(next);
71566+#endif
71567+
71568 /*
71569 * Can it merge with the predecessor?
71570 */
71571@@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71572 /* cases 1, 6 */
71573 err = vma_adjust(prev, prev->vm_start,
71574 next->vm_end, prev->vm_pgoff, NULL);
71575- } else /* cases 2, 5, 7 */
71576+
71577+#ifdef CONFIG_PAX_SEGMEXEC
71578+ if (!err && prev_m)
71579+ err = vma_adjust(prev_m, prev_m->vm_start,
71580+ next_m->vm_end, prev_m->vm_pgoff, NULL);
71581+#endif
71582+
71583+ } else { /* cases 2, 5, 7 */
71584 err = vma_adjust(prev, prev->vm_start,
71585 end, prev->vm_pgoff, NULL);
71586+
71587+#ifdef CONFIG_PAX_SEGMEXEC
71588+ if (!err && prev_m)
71589+ err = vma_adjust(prev_m, prev_m->vm_start,
71590+ end_m, prev_m->vm_pgoff, NULL);
71591+#endif
71592+
71593+ }
71594 if (err)
71595 return NULL;
71596 khugepaged_enter_vma_merge(prev);
71597@@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71598 mpol_equal(policy, vma_policy(next)) &&
71599 can_vma_merge_before(next, vm_flags,
71600 anon_vma, file, pgoff+pglen)) {
71601- if (prev && addr < prev->vm_end) /* case 4 */
71602+ if (prev && addr < prev->vm_end) { /* case 4 */
71603 err = vma_adjust(prev, prev->vm_start,
71604 addr, prev->vm_pgoff, NULL);
71605- else /* cases 3, 8 */
71606+
71607+#ifdef CONFIG_PAX_SEGMEXEC
71608+ if (!err && prev_m)
71609+ err = vma_adjust(prev_m, prev_m->vm_start,
71610+ addr_m, prev_m->vm_pgoff, NULL);
71611+#endif
71612+
71613+ } else { /* cases 3, 8 */
71614 err = vma_adjust(area, addr, next->vm_end,
71615 next->vm_pgoff - pglen, NULL);
71616+
71617+#ifdef CONFIG_PAX_SEGMEXEC
71618+ if (!err && area_m)
71619+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
71620+ next_m->vm_pgoff - pglen, NULL);
71621+#endif
71622+
71623+ }
71624 if (err)
71625 return NULL;
71626 khugepaged_enter_vma_merge(area);
71627@@ -921,14 +1001,11 @@ none:
71628 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
71629 struct file *file, long pages)
71630 {
71631- const unsigned long stack_flags
71632- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
71633-
71634 if (file) {
71635 mm->shared_vm += pages;
71636 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
71637 mm->exec_vm += pages;
71638- } else if (flags & stack_flags)
71639+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
71640 mm->stack_vm += pages;
71641 if (flags & (VM_RESERVED|VM_IO))
71642 mm->reserved_vm += pages;
71643@@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71644 * (the exception is when the underlying filesystem is noexec
71645 * mounted, in which case we dont add PROT_EXEC.)
71646 */
71647- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
71648+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
71649 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
71650 prot |= PROT_EXEC;
71651
71652@@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71653 /* Obtain the address to map to. we verify (or select) it and ensure
71654 * that it represents a valid section of the address space.
71655 */
71656- addr = get_unmapped_area(file, addr, len, pgoff, flags);
71657+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
71658 if (addr & ~PAGE_MASK)
71659 return addr;
71660
71661@@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71662 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
71663 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
71664
71665+#ifdef CONFIG_PAX_MPROTECT
71666+ if (mm->pax_flags & MF_PAX_MPROTECT) {
71667+#ifndef CONFIG_PAX_MPROTECT_COMPAT
71668+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
71669+ gr_log_rwxmmap(file);
71670+
71671+#ifdef CONFIG_PAX_EMUPLT
71672+ vm_flags &= ~VM_EXEC;
71673+#else
71674+ return -EPERM;
71675+#endif
71676+
71677+ }
71678+
71679+ if (!(vm_flags & VM_EXEC))
71680+ vm_flags &= ~VM_MAYEXEC;
71681+#else
71682+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71683+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71684+#endif
71685+ else
71686+ vm_flags &= ~VM_MAYWRITE;
71687+ }
71688+#endif
71689+
71690+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71691+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
71692+ vm_flags &= ~VM_PAGEEXEC;
71693+#endif
71694+
71695 if (flags & MAP_LOCKED)
71696 if (!can_do_mlock())
71697 return -EPERM;
71698@@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71699 locked += mm->locked_vm;
71700 lock_limit = rlimit(RLIMIT_MEMLOCK);
71701 lock_limit >>= PAGE_SHIFT;
71702+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71703 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
71704 return -EAGAIN;
71705 }
71706@@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71707 if (error)
71708 return error;
71709
71710+ if (!gr_acl_handle_mmap(file, prot))
71711+ return -EACCES;
71712+
71713 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
71714 }
71715 EXPORT_SYMBOL(do_mmap_pgoff);
71716@@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
71717 vm_flags_t vm_flags = vma->vm_flags;
71718
71719 /* If it was private or non-writable, the write bit is already clear */
71720- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
71721+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
71722 return 0;
71723
71724 /* The backer wishes to know when pages are first written to? */
71725@@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
71726 unsigned long charged = 0;
71727 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
71728
71729+#ifdef CONFIG_PAX_SEGMEXEC
71730+ struct vm_area_struct *vma_m = NULL;
71731+#endif
71732+
71733+ /*
71734+ * mm->mmap_sem is required to protect against another thread
71735+ * changing the mappings in case we sleep.
71736+ */
71737+ verify_mm_writelocked(mm);
71738+
71739 /* Clear old maps */
71740 error = -ENOMEM;
71741-munmap_back:
71742 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71743 if (vma && vma->vm_start < addr + len) {
71744 if (do_munmap(mm, addr, len))
71745 return -ENOMEM;
71746- goto munmap_back;
71747+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71748+ BUG_ON(vma && vma->vm_start < addr + len);
71749 }
71750
71751 /* Check against address space limit. */
71752@@ -1258,6 +1379,16 @@ munmap_back:
71753 goto unacct_error;
71754 }
71755
71756+#ifdef CONFIG_PAX_SEGMEXEC
71757+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
71758+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71759+ if (!vma_m) {
71760+ error = -ENOMEM;
71761+ goto free_vma;
71762+ }
71763+ }
71764+#endif
71765+
71766 vma->vm_mm = mm;
71767 vma->vm_start = addr;
71768 vma->vm_end = addr + len;
71769@@ -1282,6 +1413,19 @@ munmap_back:
71770 error = file->f_op->mmap(file, vma);
71771 if (error)
71772 goto unmap_and_free_vma;
71773+
71774+#ifdef CONFIG_PAX_SEGMEXEC
71775+ if (vma_m && (vm_flags & VM_EXECUTABLE))
71776+ added_exe_file_vma(mm);
71777+#endif
71778+
71779+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71780+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
71781+ vma->vm_flags |= VM_PAGEEXEC;
71782+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71783+ }
71784+#endif
71785+
71786 if (vm_flags & VM_EXECUTABLE)
71787 added_exe_file_vma(mm);
71788
71789@@ -1319,6 +1463,11 @@ munmap_back:
71790 vma_link(mm, vma, prev, rb_link, rb_parent);
71791 file = vma->vm_file;
71792
71793+#ifdef CONFIG_PAX_SEGMEXEC
71794+ if (vma_m)
71795+ BUG_ON(pax_mirror_vma(vma_m, vma));
71796+#endif
71797+
71798 /* Once vma denies write, undo our temporary denial count */
71799 if (correct_wcount)
71800 atomic_inc(&inode->i_writecount);
71801@@ -1327,6 +1476,7 @@ out:
71802
71803 mm->total_vm += len >> PAGE_SHIFT;
71804 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
71805+ track_exec_limit(mm, addr, addr + len, vm_flags);
71806 if (vm_flags & VM_LOCKED) {
71807 if (!mlock_vma_pages_range(vma, addr, addr + len))
71808 mm->locked_vm += (len >> PAGE_SHIFT);
71809@@ -1344,6 +1494,12 @@ unmap_and_free_vma:
71810 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
71811 charged = 0;
71812 free_vma:
71813+
71814+#ifdef CONFIG_PAX_SEGMEXEC
71815+ if (vma_m)
71816+ kmem_cache_free(vm_area_cachep, vma_m);
71817+#endif
71818+
71819 kmem_cache_free(vm_area_cachep, vma);
71820 unacct_error:
71821 if (charged)
71822@@ -1351,6 +1507,44 @@ unacct_error:
71823 return error;
71824 }
71825
71826+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
71827+{
71828+ if (!vma) {
71829+#ifdef CONFIG_STACK_GROWSUP
71830+ if (addr > sysctl_heap_stack_gap)
71831+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
71832+ else
71833+ vma = find_vma(current->mm, 0);
71834+ if (vma && (vma->vm_flags & VM_GROWSUP))
71835+ return false;
71836+#endif
71837+ return true;
71838+ }
71839+
71840+ if (addr + len > vma->vm_start)
71841+ return false;
71842+
71843+ if (vma->vm_flags & VM_GROWSDOWN)
71844+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
71845+#ifdef CONFIG_STACK_GROWSUP
71846+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
71847+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
71848+#endif
71849+
71850+ return true;
71851+}
71852+
71853+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
71854+{
71855+ if (vma->vm_start < len)
71856+ return -ENOMEM;
71857+ if (!(vma->vm_flags & VM_GROWSDOWN))
71858+ return vma->vm_start - len;
71859+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
71860+ return vma->vm_start - len - sysctl_heap_stack_gap;
71861+ return -ENOMEM;
71862+}
71863+
71864 /* Get an address range which is currently unmapped.
71865 * For shmat() with addr=0.
71866 *
71867@@ -1377,18 +1571,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
71868 if (flags & MAP_FIXED)
71869 return addr;
71870
71871+#ifdef CONFIG_PAX_RANDMMAP
71872+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71873+#endif
71874+
71875 if (addr) {
71876 addr = PAGE_ALIGN(addr);
71877- vma = find_vma(mm, addr);
71878- if (TASK_SIZE - len >= addr &&
71879- (!vma || addr + len <= vma->vm_start))
71880- return addr;
71881+ if (TASK_SIZE - len >= addr) {
71882+ vma = find_vma(mm, addr);
71883+ if (check_heap_stack_gap(vma, addr, len))
71884+ return addr;
71885+ }
71886 }
71887 if (len > mm->cached_hole_size) {
71888- start_addr = addr = mm->free_area_cache;
71889+ start_addr = addr = mm->free_area_cache;
71890 } else {
71891- start_addr = addr = TASK_UNMAPPED_BASE;
71892- mm->cached_hole_size = 0;
71893+ start_addr = addr = mm->mmap_base;
71894+ mm->cached_hole_size = 0;
71895 }
71896
71897 full_search:
71898@@ -1399,34 +1598,40 @@ full_search:
71899 * Start a new search - just in case we missed
71900 * some holes.
71901 */
71902- if (start_addr != TASK_UNMAPPED_BASE) {
71903- addr = TASK_UNMAPPED_BASE;
71904- start_addr = addr;
71905+ if (start_addr != mm->mmap_base) {
71906+ start_addr = addr = mm->mmap_base;
71907 mm->cached_hole_size = 0;
71908 goto full_search;
71909 }
71910 return -ENOMEM;
71911 }
71912- if (!vma || addr + len <= vma->vm_start) {
71913- /*
71914- * Remember the place where we stopped the search:
71915- */
71916- mm->free_area_cache = addr + len;
71917- return addr;
71918- }
71919+ if (check_heap_stack_gap(vma, addr, len))
71920+ break;
71921 if (addr + mm->cached_hole_size < vma->vm_start)
71922 mm->cached_hole_size = vma->vm_start - addr;
71923 addr = vma->vm_end;
71924 }
71925+
71926+ /*
71927+ * Remember the place where we stopped the search:
71928+ */
71929+ mm->free_area_cache = addr + len;
71930+ return addr;
71931 }
71932 #endif
71933
71934 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
71935 {
71936+
71937+#ifdef CONFIG_PAX_SEGMEXEC
71938+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71939+ return;
71940+#endif
71941+
71942 /*
71943 * Is this a new hole at the lowest possible address?
71944 */
71945- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
71946+ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
71947 mm->free_area_cache = addr;
71948 mm->cached_hole_size = ~0UL;
71949 }
71950@@ -1444,7 +1649,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71951 {
71952 struct vm_area_struct *vma;
71953 struct mm_struct *mm = current->mm;
71954- unsigned long addr = addr0;
71955+ unsigned long base = mm->mmap_base, addr = addr0;
71956
71957 /* requested length too big for entire address space */
71958 if (len > TASK_SIZE)
71959@@ -1453,13 +1658,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71960 if (flags & MAP_FIXED)
71961 return addr;
71962
71963+#ifdef CONFIG_PAX_RANDMMAP
71964+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71965+#endif
71966+
71967 /* requesting a specific address */
71968 if (addr) {
71969 addr = PAGE_ALIGN(addr);
71970- vma = find_vma(mm, addr);
71971- if (TASK_SIZE - len >= addr &&
71972- (!vma || addr + len <= vma->vm_start))
71973- return addr;
71974+ if (TASK_SIZE - len >= addr) {
71975+ vma = find_vma(mm, addr);
71976+ if (check_heap_stack_gap(vma, addr, len))
71977+ return addr;
71978+ }
71979 }
71980
71981 /* check if free_area_cache is useful for us */
71982@@ -1474,7 +1684,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71983 /* make sure it can fit in the remaining address space */
71984 if (addr > len) {
71985 vma = find_vma(mm, addr-len);
71986- if (!vma || addr <= vma->vm_start)
71987+ if (check_heap_stack_gap(vma, addr - len, len))
71988 /* remember the address as a hint for next time */
71989 return (mm->free_area_cache = addr-len);
71990 }
71991@@ -1491,7 +1701,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71992 * return with success:
71993 */
71994 vma = find_vma(mm, addr);
71995- if (!vma || addr+len <= vma->vm_start)
71996+ if (check_heap_stack_gap(vma, addr, len))
71997 /* remember the address as a hint for next time */
71998 return (mm->free_area_cache = addr);
71999
72000@@ -1500,8 +1710,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72001 mm->cached_hole_size = vma->vm_start - addr;
72002
72003 /* try just below the current vma->vm_start */
72004- addr = vma->vm_start-len;
72005- } while (len < vma->vm_start);
72006+ addr = skip_heap_stack_gap(vma, len);
72007+ } while (!IS_ERR_VALUE(addr));
72008
72009 bottomup:
72010 /*
72011@@ -1510,13 +1720,21 @@ bottomup:
72012 * can happen with large stack limits and large mmap()
72013 * allocations.
72014 */
72015+ mm->mmap_base = TASK_UNMAPPED_BASE;
72016+
72017+#ifdef CONFIG_PAX_RANDMMAP
72018+ if (mm->pax_flags & MF_PAX_RANDMMAP)
72019+ mm->mmap_base += mm->delta_mmap;
72020+#endif
72021+
72022+ mm->free_area_cache = mm->mmap_base;
72023 mm->cached_hole_size = ~0UL;
72024- mm->free_area_cache = TASK_UNMAPPED_BASE;
72025 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72026 /*
72027 * Restore the topdown base:
72028 */
72029- mm->free_area_cache = mm->mmap_base;
72030+ mm->mmap_base = base;
72031+ mm->free_area_cache = base;
72032 mm->cached_hole_size = ~0UL;
72033
72034 return addr;
72035@@ -1525,6 +1743,12 @@ bottomup:
72036
72037 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72038 {
72039+
72040+#ifdef CONFIG_PAX_SEGMEXEC
72041+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72042+ return;
72043+#endif
72044+
72045 /*
72046 * Is this a new hole at the highest possible address?
72047 */
72048@@ -1532,8 +1756,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72049 mm->free_area_cache = addr;
72050
72051 /* dont allow allocations above current base */
72052- if (mm->free_area_cache > mm->mmap_base)
72053+ if (mm->free_area_cache > mm->mmap_base) {
72054 mm->free_area_cache = mm->mmap_base;
72055+ mm->cached_hole_size = ~0UL;
72056+ }
72057 }
72058
72059 unsigned long
72060@@ -1629,6 +1855,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
72061 return vma;
72062 }
72063
72064+#ifdef CONFIG_PAX_SEGMEXEC
72065+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72066+{
72067+ struct vm_area_struct *vma_m;
72068+
72069+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72070+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72071+ BUG_ON(vma->vm_mirror);
72072+ return NULL;
72073+ }
72074+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72075+ vma_m = vma->vm_mirror;
72076+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72077+ BUG_ON(vma->vm_file != vma_m->vm_file);
72078+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72079+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72080+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72081+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72082+ return vma_m;
72083+}
72084+#endif
72085+
72086 /*
72087 * Verify that the stack growth is acceptable and
72088 * update accounting. This is shared with both the
72089@@ -1645,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72090 return -ENOMEM;
72091
72092 /* Stack limit test */
72093+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
72094 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72095 return -ENOMEM;
72096
72097@@ -1655,6 +1904,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72098 locked = mm->locked_vm + grow;
72099 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72100 limit >>= PAGE_SHIFT;
72101+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72102 if (locked > limit && !capable(CAP_IPC_LOCK))
72103 return -ENOMEM;
72104 }
72105@@ -1685,37 +1935,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72106 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72107 * vma is the last one with address > vma->vm_end. Have to extend vma.
72108 */
72109+#ifndef CONFIG_IA64
72110+static
72111+#endif
72112 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72113 {
72114 int error;
72115+ bool locknext;
72116
72117 if (!(vma->vm_flags & VM_GROWSUP))
72118 return -EFAULT;
72119
72120+ /* Also guard against wrapping around to address 0. */
72121+ if (address < PAGE_ALIGN(address+1))
72122+ address = PAGE_ALIGN(address+1);
72123+ else
72124+ return -ENOMEM;
72125+
72126 /*
72127 * We must make sure the anon_vma is allocated
72128 * so that the anon_vma locking is not a noop.
72129 */
72130 if (unlikely(anon_vma_prepare(vma)))
72131 return -ENOMEM;
72132+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72133+ if (locknext && anon_vma_prepare(vma->vm_next))
72134+ return -ENOMEM;
72135 vma_lock_anon_vma(vma);
72136+ if (locknext)
72137+ vma_lock_anon_vma(vma->vm_next);
72138
72139 /*
72140 * vma->vm_start/vm_end cannot change under us because the caller
72141 * is required to hold the mmap_sem in read mode. We need the
72142- * anon_vma lock to serialize against concurrent expand_stacks.
72143- * Also guard against wrapping around to address 0.
72144+ * anon_vma locks to serialize against concurrent expand_stacks
72145+ * and expand_upwards.
72146 */
72147- if (address < PAGE_ALIGN(address+4))
72148- address = PAGE_ALIGN(address+4);
72149- else {
72150- vma_unlock_anon_vma(vma);
72151- return -ENOMEM;
72152- }
72153 error = 0;
72154
72155 /* Somebody else might have raced and expanded it already */
72156- if (address > vma->vm_end) {
72157+ 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)
72158+ error = -ENOMEM;
72159+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72160 unsigned long size, grow;
72161
72162 size = address - vma->vm_start;
72163@@ -1730,6 +1991,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72164 }
72165 }
72166 }
72167+ if (locknext)
72168+ vma_unlock_anon_vma(vma->vm_next);
72169 vma_unlock_anon_vma(vma);
72170 khugepaged_enter_vma_merge(vma);
72171 return error;
72172@@ -1743,6 +2006,8 @@ int expand_downwards(struct vm_area_struct *vma,
72173 unsigned long address)
72174 {
72175 int error;
72176+ bool lockprev = false;
72177+ struct vm_area_struct *prev;
72178
72179 /*
72180 * We must make sure the anon_vma is allocated
72181@@ -1756,6 +2021,15 @@ int expand_downwards(struct vm_area_struct *vma,
72182 if (error)
72183 return error;
72184
72185+ prev = vma->vm_prev;
72186+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72187+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72188+#endif
72189+ if (lockprev && anon_vma_prepare(prev))
72190+ return -ENOMEM;
72191+ if (lockprev)
72192+ vma_lock_anon_vma(prev);
72193+
72194 vma_lock_anon_vma(vma);
72195
72196 /*
72197@@ -1765,9 +2039,17 @@ int expand_downwards(struct vm_area_struct *vma,
72198 */
72199
72200 /* Somebody else might have raced and expanded it already */
72201- if (address < vma->vm_start) {
72202+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72203+ error = -ENOMEM;
72204+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72205 unsigned long size, grow;
72206
72207+#ifdef CONFIG_PAX_SEGMEXEC
72208+ struct vm_area_struct *vma_m;
72209+
72210+ vma_m = pax_find_mirror_vma(vma);
72211+#endif
72212+
72213 size = vma->vm_end - address;
72214 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72215
72216@@ -1777,11 +2059,22 @@ int expand_downwards(struct vm_area_struct *vma,
72217 if (!error) {
72218 vma->vm_start = address;
72219 vma->vm_pgoff -= grow;
72220+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72221+
72222+#ifdef CONFIG_PAX_SEGMEXEC
72223+ if (vma_m) {
72224+ vma_m->vm_start -= grow << PAGE_SHIFT;
72225+ vma_m->vm_pgoff -= grow;
72226+ }
72227+#endif
72228+
72229 perf_event_mmap(vma);
72230 }
72231 }
72232 }
72233 vma_unlock_anon_vma(vma);
72234+ if (lockprev)
72235+ vma_unlock_anon_vma(prev);
72236 khugepaged_enter_vma_merge(vma);
72237 return error;
72238 }
72239@@ -1851,6 +2144,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72240 do {
72241 long nrpages = vma_pages(vma);
72242
72243+#ifdef CONFIG_PAX_SEGMEXEC
72244+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72245+ vma = remove_vma(vma);
72246+ continue;
72247+ }
72248+#endif
72249+
72250 mm->total_vm -= nrpages;
72251 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
72252 vma = remove_vma(vma);
72253@@ -1896,6 +2196,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72254 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72255 vma->vm_prev = NULL;
72256 do {
72257+
72258+#ifdef CONFIG_PAX_SEGMEXEC
72259+ if (vma->vm_mirror) {
72260+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72261+ vma->vm_mirror->vm_mirror = NULL;
72262+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
72263+ vma->vm_mirror = NULL;
72264+ }
72265+#endif
72266+
72267 rb_erase(&vma->vm_rb, &mm->mm_rb);
72268 mm->map_count--;
72269 tail_vma = vma;
72270@@ -1924,14 +2234,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72271 struct vm_area_struct *new;
72272 int err = -ENOMEM;
72273
72274+#ifdef CONFIG_PAX_SEGMEXEC
72275+ struct vm_area_struct *vma_m, *new_m = NULL;
72276+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72277+#endif
72278+
72279 if (is_vm_hugetlb_page(vma) && (addr &
72280 ~(huge_page_mask(hstate_vma(vma)))))
72281 return -EINVAL;
72282
72283+#ifdef CONFIG_PAX_SEGMEXEC
72284+ vma_m = pax_find_mirror_vma(vma);
72285+#endif
72286+
72287 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72288 if (!new)
72289 goto out_err;
72290
72291+#ifdef CONFIG_PAX_SEGMEXEC
72292+ if (vma_m) {
72293+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72294+ if (!new_m) {
72295+ kmem_cache_free(vm_area_cachep, new);
72296+ goto out_err;
72297+ }
72298+ }
72299+#endif
72300+
72301 /* most fields are the same, copy all, and then fixup */
72302 *new = *vma;
72303
72304@@ -1944,6 +2273,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72305 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72306 }
72307
72308+#ifdef CONFIG_PAX_SEGMEXEC
72309+ if (vma_m) {
72310+ *new_m = *vma_m;
72311+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
72312+ new_m->vm_mirror = new;
72313+ new->vm_mirror = new_m;
72314+
72315+ if (new_below)
72316+ new_m->vm_end = addr_m;
72317+ else {
72318+ new_m->vm_start = addr_m;
72319+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72320+ }
72321+ }
72322+#endif
72323+
72324 pol = mpol_dup(vma_policy(vma));
72325 if (IS_ERR(pol)) {
72326 err = PTR_ERR(pol);
72327@@ -1969,6 +2314,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72328 else
72329 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72330
72331+#ifdef CONFIG_PAX_SEGMEXEC
72332+ if (!err && vma_m) {
72333+ if (anon_vma_clone(new_m, vma_m))
72334+ goto out_free_mpol;
72335+
72336+ mpol_get(pol);
72337+ vma_set_policy(new_m, pol);
72338+
72339+ if (new_m->vm_file) {
72340+ get_file(new_m->vm_file);
72341+ if (vma_m->vm_flags & VM_EXECUTABLE)
72342+ added_exe_file_vma(mm);
72343+ }
72344+
72345+ if (new_m->vm_ops && new_m->vm_ops->open)
72346+ new_m->vm_ops->open(new_m);
72347+
72348+ if (new_below)
72349+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72350+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72351+ else
72352+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72353+
72354+ if (err) {
72355+ if (new_m->vm_ops && new_m->vm_ops->close)
72356+ new_m->vm_ops->close(new_m);
72357+ if (new_m->vm_file) {
72358+ if (vma_m->vm_flags & VM_EXECUTABLE)
72359+ removed_exe_file_vma(mm);
72360+ fput(new_m->vm_file);
72361+ }
72362+ mpol_put(pol);
72363+ }
72364+ }
72365+#endif
72366+
72367 /* Success. */
72368 if (!err)
72369 return 0;
72370@@ -1981,10 +2362,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72371 removed_exe_file_vma(mm);
72372 fput(new->vm_file);
72373 }
72374- unlink_anon_vmas(new);
72375 out_free_mpol:
72376 mpol_put(pol);
72377 out_free_vma:
72378+
72379+#ifdef CONFIG_PAX_SEGMEXEC
72380+ if (new_m) {
72381+ unlink_anon_vmas(new_m);
72382+ kmem_cache_free(vm_area_cachep, new_m);
72383+ }
72384+#endif
72385+
72386+ unlink_anon_vmas(new);
72387 kmem_cache_free(vm_area_cachep, new);
72388 out_err:
72389 return err;
72390@@ -1997,6 +2386,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72391 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72392 unsigned long addr, int new_below)
72393 {
72394+
72395+#ifdef CONFIG_PAX_SEGMEXEC
72396+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72397+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72398+ if (mm->map_count >= sysctl_max_map_count-1)
72399+ return -ENOMEM;
72400+ } else
72401+#endif
72402+
72403 if (mm->map_count >= sysctl_max_map_count)
72404 return -ENOMEM;
72405
72406@@ -2008,11 +2406,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72407 * work. This now handles partial unmappings.
72408 * Jeremy Fitzhardinge <jeremy@goop.org>
72409 */
72410+#ifdef CONFIG_PAX_SEGMEXEC
72411 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72412 {
72413+ int ret = __do_munmap(mm, start, len);
72414+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72415+ return ret;
72416+
72417+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72418+}
72419+
72420+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72421+#else
72422+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72423+#endif
72424+{
72425 unsigned long end;
72426 struct vm_area_struct *vma, *prev, *last;
72427
72428+ /*
72429+ * mm->mmap_sem is required to protect against another thread
72430+ * changing the mappings in case we sleep.
72431+ */
72432+ verify_mm_writelocked(mm);
72433+
72434 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72435 return -EINVAL;
72436
72437@@ -2087,6 +2504,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72438 /* Fix up all other VM information */
72439 remove_vma_list(mm, vma);
72440
72441+ track_exec_limit(mm, start, end, 0UL);
72442+
72443 return 0;
72444 }
72445
72446@@ -2099,22 +2518,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72447
72448 profile_munmap(addr);
72449
72450+#ifdef CONFIG_PAX_SEGMEXEC
72451+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72452+ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
72453+ return -EINVAL;
72454+#endif
72455+
72456 down_write(&mm->mmap_sem);
72457 ret = do_munmap(mm, addr, len);
72458 up_write(&mm->mmap_sem);
72459 return ret;
72460 }
72461
72462-static inline void verify_mm_writelocked(struct mm_struct *mm)
72463-{
72464-#ifdef CONFIG_DEBUG_VM
72465- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72466- WARN_ON(1);
72467- up_read(&mm->mmap_sem);
72468- }
72469-#endif
72470-}
72471-
72472 /*
72473 * this is really a simplified "do_mmap". it only handles
72474 * anonymous maps. eventually we may be able to do some
72475@@ -2128,6 +2543,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72476 struct rb_node ** rb_link, * rb_parent;
72477 pgoff_t pgoff = addr >> PAGE_SHIFT;
72478 int error;
72479+ unsigned long charged;
72480
72481 len = PAGE_ALIGN(len);
72482 if (!len)
72483@@ -2139,16 +2555,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72484
72485 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72486
72487+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72488+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72489+ flags &= ~VM_EXEC;
72490+
72491+#ifdef CONFIG_PAX_MPROTECT
72492+ if (mm->pax_flags & MF_PAX_MPROTECT)
72493+ flags &= ~VM_MAYEXEC;
72494+#endif
72495+
72496+ }
72497+#endif
72498+
72499 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72500 if (error & ~PAGE_MASK)
72501 return error;
72502
72503+ charged = len >> PAGE_SHIFT;
72504+
72505 /*
72506 * mlock MCL_FUTURE?
72507 */
72508 if (mm->def_flags & VM_LOCKED) {
72509 unsigned long locked, lock_limit;
72510- locked = len >> PAGE_SHIFT;
72511+ locked = charged;
72512 locked += mm->locked_vm;
72513 lock_limit = rlimit(RLIMIT_MEMLOCK);
72514 lock_limit >>= PAGE_SHIFT;
72515@@ -2165,22 +2595,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72516 /*
72517 * Clear old maps. this also does some error checking for us
72518 */
72519- munmap_back:
72520 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72521 if (vma && vma->vm_start < addr + len) {
72522 if (do_munmap(mm, addr, len))
72523 return -ENOMEM;
72524- goto munmap_back;
72525+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72526+ BUG_ON(vma && vma->vm_start < addr + len);
72527 }
72528
72529 /* Check against address space limits *after* clearing old maps... */
72530- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72531+ if (!may_expand_vm(mm, charged))
72532 return -ENOMEM;
72533
72534 if (mm->map_count > sysctl_max_map_count)
72535 return -ENOMEM;
72536
72537- if (security_vm_enough_memory(len >> PAGE_SHIFT))
72538+ if (security_vm_enough_memory(charged))
72539 return -ENOMEM;
72540
72541 /* Can we just expand an old private anonymous mapping? */
72542@@ -2194,7 +2624,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72543 */
72544 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72545 if (!vma) {
72546- vm_unacct_memory(len >> PAGE_SHIFT);
72547+ vm_unacct_memory(charged);
72548 return -ENOMEM;
72549 }
72550
72551@@ -2208,11 +2638,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72552 vma_link(mm, vma, prev, rb_link, rb_parent);
72553 out:
72554 perf_event_mmap(vma);
72555- mm->total_vm += len >> PAGE_SHIFT;
72556+ mm->total_vm += charged;
72557 if (flags & VM_LOCKED) {
72558 if (!mlock_vma_pages_range(vma, addr, addr + len))
72559- mm->locked_vm += (len >> PAGE_SHIFT);
72560+ mm->locked_vm += charged;
72561 }
72562+ track_exec_limit(mm, addr, addr + len, flags);
72563 return addr;
72564 }
72565
72566@@ -2259,8 +2690,10 @@ void exit_mmap(struct mm_struct *mm)
72567 * Walk the list again, actually closing and freeing it,
72568 * with preemption enabled, without holding any MM locks.
72569 */
72570- while (vma)
72571+ while (vma) {
72572+ vma->vm_mirror = NULL;
72573 vma = remove_vma(vma);
72574+ }
72575
72576 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
72577 }
72578@@ -2274,6 +2707,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72579 struct vm_area_struct * __vma, * prev;
72580 struct rb_node ** rb_link, * rb_parent;
72581
72582+#ifdef CONFIG_PAX_SEGMEXEC
72583+ struct vm_area_struct *vma_m = NULL;
72584+#endif
72585+
72586+ if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
72587+ return -EPERM;
72588+
72589 /*
72590 * The vm_pgoff of a purely anonymous vma should be irrelevant
72591 * until its first write fault, when page's anon_vma and index
72592@@ -2296,7 +2736,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72593 if ((vma->vm_flags & VM_ACCOUNT) &&
72594 security_vm_enough_memory_mm(mm, vma_pages(vma)))
72595 return -ENOMEM;
72596+
72597+#ifdef CONFIG_PAX_SEGMEXEC
72598+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
72599+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72600+ if (!vma_m)
72601+ return -ENOMEM;
72602+ }
72603+#endif
72604+
72605 vma_link(mm, vma, prev, rb_link, rb_parent);
72606+
72607+#ifdef CONFIG_PAX_SEGMEXEC
72608+ if (vma_m)
72609+ BUG_ON(pax_mirror_vma(vma_m, vma));
72610+#endif
72611+
72612 return 0;
72613 }
72614
72615@@ -2315,6 +2770,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72616 struct mempolicy *pol;
72617 bool faulted_in_anon_vma = true;
72618
72619+ BUG_ON(vma->vm_mirror);
72620+
72621 /*
72622 * If anonymous vma has not yet been faulted, update new pgoff
72623 * to match new location, to increase its chance of merging.
72624@@ -2382,6 +2839,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72625 return NULL;
72626 }
72627
72628+#ifdef CONFIG_PAX_SEGMEXEC
72629+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
72630+{
72631+ struct vm_area_struct *prev_m;
72632+ struct rb_node **rb_link_m, *rb_parent_m;
72633+ struct mempolicy *pol_m;
72634+
72635+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
72636+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
72637+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
72638+ *vma_m = *vma;
72639+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
72640+ if (anon_vma_clone(vma_m, vma))
72641+ return -ENOMEM;
72642+ pol_m = vma_policy(vma_m);
72643+ mpol_get(pol_m);
72644+ vma_set_policy(vma_m, pol_m);
72645+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
72646+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
72647+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
72648+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
72649+ if (vma_m->vm_file)
72650+ get_file(vma_m->vm_file);
72651+ if (vma_m->vm_ops && vma_m->vm_ops->open)
72652+ vma_m->vm_ops->open(vma_m);
72653+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
72654+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
72655+ vma_m->vm_mirror = vma;
72656+ vma->vm_mirror = vma_m;
72657+ return 0;
72658+}
72659+#endif
72660+
72661 /*
72662 * Return true if the calling process may expand its vm space by the passed
72663 * number of pages
72664@@ -2393,6 +2883,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
72665
72666 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
72667
72668+#ifdef CONFIG_PAX_RANDMMAP
72669+ if (mm->pax_flags & MF_PAX_RANDMMAP)
72670+ cur -= mm->brk_gap;
72671+#endif
72672+
72673+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
72674 if (cur + npages > lim)
72675 return 0;
72676 return 1;
72677@@ -2463,6 +2959,22 @@ int install_special_mapping(struct mm_struct *mm,
72678 vma->vm_start = addr;
72679 vma->vm_end = addr + len;
72680
72681+#ifdef CONFIG_PAX_MPROTECT
72682+ if (mm->pax_flags & MF_PAX_MPROTECT) {
72683+#ifndef CONFIG_PAX_MPROTECT_COMPAT
72684+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
72685+ return -EPERM;
72686+ if (!(vm_flags & VM_EXEC))
72687+ vm_flags &= ~VM_MAYEXEC;
72688+#else
72689+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72690+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72691+#endif
72692+ else
72693+ vm_flags &= ~VM_MAYWRITE;
72694+ }
72695+#endif
72696+
72697 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
72698 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72699
72700diff --git a/mm/mprotect.c b/mm/mprotect.c
72701index f437d05..e3763f6 100644
72702--- a/mm/mprotect.c
72703+++ b/mm/mprotect.c
72704@@ -23,10 +23,16 @@
72705 #include <linux/mmu_notifier.h>
72706 #include <linux/migrate.h>
72707 #include <linux/perf_event.h>
72708+
72709+#ifdef CONFIG_PAX_MPROTECT
72710+#include <linux/elf.h>
72711+#endif
72712+
72713 #include <asm/uaccess.h>
72714 #include <asm/pgtable.h>
72715 #include <asm/cacheflush.h>
72716 #include <asm/tlbflush.h>
72717+#include <asm/mmu_context.h>
72718
72719 #ifndef pgprot_modify
72720 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
72721@@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
72722 flush_tlb_range(vma, start, end);
72723 }
72724
72725+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72726+/* called while holding the mmap semaphor for writing except stack expansion */
72727+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
72728+{
72729+ unsigned long oldlimit, newlimit = 0UL;
72730+
72731+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
72732+ return;
72733+
72734+ spin_lock(&mm->page_table_lock);
72735+ oldlimit = mm->context.user_cs_limit;
72736+ if ((prot & VM_EXEC) && oldlimit < end)
72737+ /* USER_CS limit moved up */
72738+ newlimit = end;
72739+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
72740+ /* USER_CS limit moved down */
72741+ newlimit = start;
72742+
72743+ if (newlimit) {
72744+ mm->context.user_cs_limit = newlimit;
72745+
72746+#ifdef CONFIG_SMP
72747+ wmb();
72748+ cpus_clear(mm->context.cpu_user_cs_mask);
72749+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
72750+#endif
72751+
72752+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
72753+ }
72754+ spin_unlock(&mm->page_table_lock);
72755+ if (newlimit == end) {
72756+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
72757+
72758+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
72759+ if (is_vm_hugetlb_page(vma))
72760+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
72761+ else
72762+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
72763+ }
72764+}
72765+#endif
72766+
72767 int
72768 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72769 unsigned long start, unsigned long end, unsigned long newflags)
72770@@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72771 int error;
72772 int dirty_accountable = 0;
72773
72774+#ifdef CONFIG_PAX_SEGMEXEC
72775+ struct vm_area_struct *vma_m = NULL;
72776+ unsigned long start_m, end_m;
72777+
72778+ start_m = start + SEGMEXEC_TASK_SIZE;
72779+ end_m = end + SEGMEXEC_TASK_SIZE;
72780+#endif
72781+
72782 if (newflags == oldflags) {
72783 *pprev = vma;
72784 return 0;
72785 }
72786
72787+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
72788+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
72789+
72790+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
72791+ return -ENOMEM;
72792+
72793+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
72794+ return -ENOMEM;
72795+ }
72796+
72797 /*
72798 * If we make a private mapping writable we increase our commit;
72799 * but (without finer accounting) cannot reduce our commit if we
72800@@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72801 }
72802 }
72803
72804+#ifdef CONFIG_PAX_SEGMEXEC
72805+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
72806+ if (start != vma->vm_start) {
72807+ error = split_vma(mm, vma, start, 1);
72808+ if (error)
72809+ goto fail;
72810+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
72811+ *pprev = (*pprev)->vm_next;
72812+ }
72813+
72814+ if (end != vma->vm_end) {
72815+ error = split_vma(mm, vma, end, 0);
72816+ if (error)
72817+ goto fail;
72818+ }
72819+
72820+ if (pax_find_mirror_vma(vma)) {
72821+ error = __do_munmap(mm, start_m, end_m - start_m);
72822+ if (error)
72823+ goto fail;
72824+ } else {
72825+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72826+ if (!vma_m) {
72827+ error = -ENOMEM;
72828+ goto fail;
72829+ }
72830+ vma->vm_flags = newflags;
72831+ error = pax_mirror_vma(vma_m, vma);
72832+ if (error) {
72833+ vma->vm_flags = oldflags;
72834+ goto fail;
72835+ }
72836+ }
72837+ }
72838+#endif
72839+
72840 /*
72841 * First try to merge with previous and/or next vma.
72842 */
72843@@ -204,9 +306,21 @@ success:
72844 * vm_flags and vm_page_prot are protected by the mmap_sem
72845 * held in write mode.
72846 */
72847+
72848+#ifdef CONFIG_PAX_SEGMEXEC
72849+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
72850+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
72851+#endif
72852+
72853 vma->vm_flags = newflags;
72854+
72855+#ifdef CONFIG_PAX_MPROTECT
72856+ if (mm->binfmt && mm->binfmt->handle_mprotect)
72857+ mm->binfmt->handle_mprotect(vma, newflags);
72858+#endif
72859+
72860 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
72861- vm_get_page_prot(newflags));
72862+ vm_get_page_prot(vma->vm_flags));
72863
72864 if (vma_wants_writenotify(vma)) {
72865 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
72866@@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72867 end = start + len;
72868 if (end <= start)
72869 return -ENOMEM;
72870+
72871+#ifdef CONFIG_PAX_SEGMEXEC
72872+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72873+ if (end > SEGMEXEC_TASK_SIZE)
72874+ return -EINVAL;
72875+ } else
72876+#endif
72877+
72878+ if (end > TASK_SIZE)
72879+ return -EINVAL;
72880+
72881 if (!arch_validate_prot(prot))
72882 return -EINVAL;
72883
72884@@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72885 /*
72886 * Does the application expect PROT_READ to imply PROT_EXEC:
72887 */
72888- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72889+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72890 prot |= PROT_EXEC;
72891
72892 vm_flags = calc_vm_prot_bits(prot);
72893@@ -288,6 +413,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72894 if (start > vma->vm_start)
72895 prev = vma;
72896
72897+#ifdef CONFIG_PAX_MPROTECT
72898+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
72899+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
72900+#endif
72901+
72902 for (nstart = start ; ; ) {
72903 unsigned long newflags;
72904
72905@@ -297,6 +427,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72906
72907 /* newflags >> 4 shift VM_MAY% in place of VM_% */
72908 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
72909+ if (prot & (PROT_WRITE | PROT_EXEC))
72910+ gr_log_rwxmprotect(vma->vm_file);
72911+
72912+ error = -EACCES;
72913+ goto out;
72914+ }
72915+
72916+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
72917 error = -EACCES;
72918 goto out;
72919 }
72920@@ -311,6 +449,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72921 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
72922 if (error)
72923 goto out;
72924+
72925+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
72926+
72927 nstart = tmp;
72928
72929 if (nstart < prev->vm_end)
72930diff --git a/mm/mremap.c b/mm/mremap.c
72931index 87bb839..c3bfadb 100644
72932--- a/mm/mremap.c
72933+++ b/mm/mremap.c
72934@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
72935 continue;
72936 pte = ptep_get_and_clear(mm, old_addr, old_pte);
72937 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
72938+
72939+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72940+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
72941+ pte = pte_exprotect(pte);
72942+#endif
72943+
72944 set_pte_at(mm, new_addr, new_pte, pte);
72945 }
72946
72947@@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
72948 if (is_vm_hugetlb_page(vma))
72949 goto Einval;
72950
72951+#ifdef CONFIG_PAX_SEGMEXEC
72952+ if (pax_find_mirror_vma(vma))
72953+ goto Einval;
72954+#endif
72955+
72956 /* We can't remap across vm area boundaries */
72957 if (old_len > vma->vm_end - addr)
72958 goto Efault;
72959@@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
72960 unsigned long ret = -EINVAL;
72961 unsigned long charged = 0;
72962 unsigned long map_flags;
72963+ unsigned long pax_task_size = TASK_SIZE;
72964
72965 if (new_addr & ~PAGE_MASK)
72966 goto out;
72967
72968- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
72969+#ifdef CONFIG_PAX_SEGMEXEC
72970+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
72971+ pax_task_size = SEGMEXEC_TASK_SIZE;
72972+#endif
72973+
72974+ pax_task_size -= PAGE_SIZE;
72975+
72976+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
72977 goto out;
72978
72979 /* Check if the location we're moving into overlaps the
72980 * old location at all, and fail if it does.
72981 */
72982- if ((new_addr <= addr) && (new_addr+new_len) > addr)
72983- goto out;
72984-
72985- if ((addr <= new_addr) && (addr+old_len) > new_addr)
72986+ if (addr + old_len > new_addr && new_addr + new_len > addr)
72987 goto out;
72988
72989 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72990@@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
72991 struct vm_area_struct *vma;
72992 unsigned long ret = -EINVAL;
72993 unsigned long charged = 0;
72994+ unsigned long pax_task_size = TASK_SIZE;
72995
72996 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
72997 goto out;
72998@@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
72999 if (!new_len)
73000 goto out;
73001
73002+#ifdef CONFIG_PAX_SEGMEXEC
73003+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
73004+ pax_task_size = SEGMEXEC_TASK_SIZE;
73005+#endif
73006+
73007+ pax_task_size -= PAGE_SIZE;
73008+
73009+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73010+ old_len > pax_task_size || addr > pax_task_size-old_len)
73011+ goto out;
73012+
73013 if (flags & MREMAP_FIXED) {
73014 if (flags & MREMAP_MAYMOVE)
73015 ret = mremap_to(addr, old_len, new_addr, new_len);
73016@@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
73017 addr + new_len);
73018 }
73019 ret = addr;
73020+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73021 goto out;
73022 }
73023 }
73024@@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
73025 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
73026 if (ret)
73027 goto out;
73028+
73029+ map_flags = vma->vm_flags;
73030 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73031+ if (!(ret & ~PAGE_MASK)) {
73032+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73033+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73034+ }
73035 }
73036 out:
73037 if (ret & ~PAGE_MASK)
73038diff --git a/mm/nommu.c b/mm/nommu.c
73039index f59e170..34e2a2b 100644
73040--- a/mm/nommu.c
73041+++ b/mm/nommu.c
73042@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73043 int sysctl_overcommit_ratio = 50; /* default is 50% */
73044 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73045 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73046-int heap_stack_gap = 0;
73047
73048 atomic_long_t mmap_pages_allocated;
73049
73050@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73051 EXPORT_SYMBOL(find_vma);
73052
73053 /*
73054- * find a VMA
73055- * - we don't extend stack VMAs under NOMMU conditions
73056- */
73057-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73058-{
73059- return find_vma(mm, addr);
73060-}
73061-
73062-/*
73063 * expand a stack to a given address
73064 * - not supported under NOMMU conditions
73065 */
73066@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73067
73068 /* most fields are the same, copy all, and then fixup */
73069 *new = *vma;
73070+ INIT_LIST_HEAD(&new->anon_vma_chain);
73071 *region = *vma->vm_region;
73072 new->vm_region = region;
73073
73074diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73075index a13ded1..b949d15 100644
73076--- a/mm/page_alloc.c
73077+++ b/mm/page_alloc.c
73078@@ -335,7 +335,7 @@ out:
73079 * This usage means that zero-order pages may not be compound.
73080 */
73081
73082-static void free_compound_page(struct page *page)
73083+void free_compound_page(struct page *page)
73084 {
73085 __free_pages_ok(page, compound_order(page));
73086 }
73087@@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73088 int i;
73089 int bad = 0;
73090
73091+#ifdef CONFIG_PAX_MEMORY_SANITIZE
73092+ unsigned long index = 1UL << order;
73093+#endif
73094+
73095 trace_mm_page_free(page, order);
73096 kmemcheck_free_shadow(page, order);
73097
73098@@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73099 debug_check_no_obj_freed(page_address(page),
73100 PAGE_SIZE << order);
73101 }
73102+
73103+#ifdef CONFIG_PAX_MEMORY_SANITIZE
73104+ for (; index; --index)
73105+ sanitize_highpage(page + index - 1);
73106+#endif
73107+
73108 arch_free_page(page, order);
73109 kernel_map_pages(page, 1 << order, 0);
73110
73111@@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73112 arch_alloc_page(page, order);
73113 kernel_map_pages(page, 1 << order, 1);
73114
73115+#ifndef CONFIG_PAX_MEMORY_SANITIZE
73116 if (gfp_flags & __GFP_ZERO)
73117 prep_zero_page(page, order, gfp_flags);
73118+#endif
73119
73120 if (order && (gfp_flags & __GFP_COMP))
73121 prep_compound_page(page, order);
73122@@ -3468,7 +3480,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73123 unsigned long pfn;
73124
73125 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73126+#ifdef CONFIG_X86_32
73127+ /* boot failures in VMware 8 on 32bit vanilla since
73128+ this change */
73129+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73130+#else
73131 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73132+#endif
73133 return 1;
73134 }
73135 return 0;
73136diff --git a/mm/percpu.c b/mm/percpu.c
73137index 317de23..1ba7776 100644
73138--- a/mm/percpu.c
73139+++ b/mm/percpu.c
73140@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73141 static unsigned int pcpu_high_unit_cpu __read_mostly;
73142
73143 /* the address of the first chunk which starts with the kernel static area */
73144-void *pcpu_base_addr __read_mostly;
73145+void *pcpu_base_addr __read_only;
73146 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73147
73148 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73149diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73150index c20ff48..137702a 100644
73151--- a/mm/process_vm_access.c
73152+++ b/mm/process_vm_access.c
73153@@ -13,6 +13,7 @@
73154 #include <linux/uio.h>
73155 #include <linux/sched.h>
73156 #include <linux/highmem.h>
73157+#include <linux/security.h>
73158 #include <linux/ptrace.h>
73159 #include <linux/slab.h>
73160 #include <linux/syscalls.h>
73161@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73162 size_t iov_l_curr_offset = 0;
73163 ssize_t iov_len;
73164
73165+ return -ENOSYS; // PaX: until properly audited
73166+
73167 /*
73168 * Work out how many pages of struct pages we're going to need
73169 * when eventually calling get_user_pages
73170 */
73171 for (i = 0; i < riovcnt; i++) {
73172 iov_len = rvec[i].iov_len;
73173- if (iov_len > 0) {
73174- nr_pages_iov = ((unsigned long)rvec[i].iov_base
73175- + iov_len)
73176- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73177- / PAGE_SIZE + 1;
73178- nr_pages = max(nr_pages, nr_pages_iov);
73179- }
73180+ if (iov_len <= 0)
73181+ continue;
73182+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73183+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73184+ nr_pages = max(nr_pages, nr_pages_iov);
73185 }
73186
73187 if (nr_pages == 0)
73188@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73189 goto free_proc_pages;
73190 }
73191
73192+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73193+ rc = -EPERM;
73194+ goto put_task_struct;
73195+ }
73196+
73197 mm = mm_access(task, PTRACE_MODE_ATTACH);
73198 if (!mm || IS_ERR(mm)) {
73199 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73200diff --git a/mm/rmap.c b/mm/rmap.c
73201index c8454e0..b04f3a2 100644
73202--- a/mm/rmap.c
73203+++ b/mm/rmap.c
73204@@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73205 struct anon_vma *anon_vma = vma->anon_vma;
73206 struct anon_vma_chain *avc;
73207
73208+#ifdef CONFIG_PAX_SEGMEXEC
73209+ struct anon_vma_chain *avc_m = NULL;
73210+#endif
73211+
73212 might_sleep();
73213 if (unlikely(!anon_vma)) {
73214 struct mm_struct *mm = vma->vm_mm;
73215@@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73216 if (!avc)
73217 goto out_enomem;
73218
73219+#ifdef CONFIG_PAX_SEGMEXEC
73220+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73221+ if (!avc_m)
73222+ goto out_enomem_free_avc;
73223+#endif
73224+
73225 anon_vma = find_mergeable_anon_vma(vma);
73226 allocated = NULL;
73227 if (!anon_vma) {
73228@@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73229 /* page_table_lock to protect against threads */
73230 spin_lock(&mm->page_table_lock);
73231 if (likely(!vma->anon_vma)) {
73232+
73233+#ifdef CONFIG_PAX_SEGMEXEC
73234+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73235+
73236+ if (vma_m) {
73237+ BUG_ON(vma_m->anon_vma);
73238+ vma_m->anon_vma = anon_vma;
73239+ avc_m->anon_vma = anon_vma;
73240+ avc_m->vma = vma;
73241+ list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
73242+ list_add(&avc_m->same_anon_vma, &anon_vma->head);
73243+ avc_m = NULL;
73244+ }
73245+#endif
73246+
73247 vma->anon_vma = anon_vma;
73248 avc->anon_vma = anon_vma;
73249 avc->vma = vma;
73250@@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73251
73252 if (unlikely(allocated))
73253 put_anon_vma(allocated);
73254+
73255+#ifdef CONFIG_PAX_SEGMEXEC
73256+ if (unlikely(avc_m))
73257+ anon_vma_chain_free(avc_m);
73258+#endif
73259+
73260 if (unlikely(avc))
73261 anon_vma_chain_free(avc);
73262 }
73263 return 0;
73264
73265 out_enomem_free_avc:
73266+
73267+#ifdef CONFIG_PAX_SEGMEXEC
73268+ if (avc_m)
73269+ anon_vma_chain_free(avc_m);
73270+#endif
73271+
73272 anon_vma_chain_free(avc);
73273 out_enomem:
73274 return -ENOMEM;
73275@@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
73276 * Attach the anon_vmas from src to dst.
73277 * Returns 0 on success, -ENOMEM on failure.
73278 */
73279-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73280+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73281 {
73282 struct anon_vma_chain *avc, *pavc;
73283 struct anon_vma *root = NULL;
73284@@ -321,7 +358,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73285 * the corresponding VMA in the parent process is attached to.
73286 * Returns 0 on success, non-zero on failure.
73287 */
73288-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73289+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73290 {
73291 struct anon_vma_chain *avc;
73292 struct anon_vma *anon_vma;
73293diff --git a/mm/shmem.c b/mm/shmem.c
73294index 269d049..a9d2b50 100644
73295--- a/mm/shmem.c
73296+++ b/mm/shmem.c
73297@@ -31,7 +31,7 @@
73298 #include <linux/export.h>
73299 #include <linux/swap.h>
73300
73301-static struct vfsmount *shm_mnt;
73302+struct vfsmount *shm_mnt;
73303
73304 #ifdef CONFIG_SHMEM
73305 /*
73306@@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
73307 #define BOGO_DIRENT_SIZE 20
73308
73309 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73310-#define SHORT_SYMLINK_LEN 128
73311+#define SHORT_SYMLINK_LEN 64
73312
73313 struct shmem_xattr {
73314 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73315@@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73316 int err = -ENOMEM;
73317
73318 /* Round up to L1_CACHE_BYTES to resist false sharing */
73319- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73320- L1_CACHE_BYTES), GFP_KERNEL);
73321+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73322 if (!sbinfo)
73323 return -ENOMEM;
73324
73325diff --git a/mm/slab.c b/mm/slab.c
73326index f0bd785..348b96a 100644
73327--- a/mm/slab.c
73328+++ b/mm/slab.c
73329@@ -153,7 +153,7 @@
73330
73331 /* Legal flag mask for kmem_cache_create(). */
73332 #if DEBUG
73333-# define CREATE_MASK (SLAB_RED_ZONE | \
73334+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73335 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73336 SLAB_CACHE_DMA | \
73337 SLAB_STORE_USER | \
73338@@ -161,7 +161,7 @@
73339 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73340 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73341 #else
73342-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73343+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73344 SLAB_CACHE_DMA | \
73345 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73346 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73347@@ -290,7 +290,7 @@ struct kmem_list3 {
73348 * Need this for bootstrapping a per node allocator.
73349 */
73350 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73351-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73352+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73353 #define CACHE_CACHE 0
73354 #define SIZE_AC MAX_NUMNODES
73355 #define SIZE_L3 (2 * MAX_NUMNODES)
73356@@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73357 if ((x)->max_freeable < i) \
73358 (x)->max_freeable = i; \
73359 } while (0)
73360-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73361-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73362-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73363-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73364+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73365+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73366+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73367+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73368 #else
73369 #define STATS_INC_ACTIVE(x) do { } while (0)
73370 #define STATS_DEC_ACTIVE(x) do { } while (0)
73371@@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73372 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73373 */
73374 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73375- const struct slab *slab, void *obj)
73376+ const struct slab *slab, const void *obj)
73377 {
73378 u32 offset = (obj - slab->s_mem);
73379 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73380@@ -568,7 +568,7 @@ struct cache_names {
73381 static struct cache_names __initdata cache_names[] = {
73382 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73383 #include <linux/kmalloc_sizes.h>
73384- {NULL,}
73385+ {NULL}
73386 #undef CACHE
73387 };
73388
73389@@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
73390 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73391 sizes[INDEX_AC].cs_size,
73392 ARCH_KMALLOC_MINALIGN,
73393- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73394+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73395 NULL);
73396
73397 if (INDEX_AC != INDEX_L3) {
73398@@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
73399 kmem_cache_create(names[INDEX_L3].name,
73400 sizes[INDEX_L3].cs_size,
73401 ARCH_KMALLOC_MINALIGN,
73402- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73403+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73404 NULL);
73405 }
73406
73407@@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
73408 sizes->cs_cachep = kmem_cache_create(names->name,
73409 sizes->cs_size,
73410 ARCH_KMALLOC_MINALIGN,
73411- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73412+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73413 NULL);
73414 }
73415 #ifdef CONFIG_ZONE_DMA
73416@@ -4339,10 +4339,10 @@ static int s_show(struct seq_file *m, void *p)
73417 }
73418 /* cpu stats */
73419 {
73420- unsigned long allochit = atomic_read(&cachep->allochit);
73421- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73422- unsigned long freehit = atomic_read(&cachep->freehit);
73423- unsigned long freemiss = atomic_read(&cachep->freemiss);
73424+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73425+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73426+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73427+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73428
73429 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73430 allochit, allocmiss, freehit, freemiss);
73431@@ -4601,13 +4601,62 @@ static int __init slab_proc_init(void)
73432 {
73433 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73434 #ifdef CONFIG_DEBUG_SLAB_LEAK
73435- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73436+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73437 #endif
73438 return 0;
73439 }
73440 module_init(slab_proc_init);
73441 #endif
73442
73443+void check_object_size(const void *ptr, unsigned long n, bool to)
73444+{
73445+
73446+#ifdef CONFIG_PAX_USERCOPY
73447+ struct page *page;
73448+ struct kmem_cache *cachep = NULL;
73449+ struct slab *slabp;
73450+ unsigned int objnr;
73451+ unsigned long offset;
73452+ const char *type;
73453+
73454+ if (!n)
73455+ return;
73456+
73457+ type = "<null>";
73458+ if (ZERO_OR_NULL_PTR(ptr))
73459+ goto report;
73460+
73461+ if (!virt_addr_valid(ptr))
73462+ return;
73463+
73464+ page = virt_to_head_page(ptr);
73465+
73466+ type = "<process stack>";
73467+ if (!PageSlab(page)) {
73468+ if (object_is_on_stack(ptr, n) == -1)
73469+ goto report;
73470+ return;
73471+ }
73472+
73473+ cachep = page_get_cache(page);
73474+ type = cachep->name;
73475+ if (!(cachep->flags & SLAB_USERCOPY))
73476+ goto report;
73477+
73478+ slabp = page_get_slab(page);
73479+ objnr = obj_to_index(cachep, slabp, ptr);
73480+ BUG_ON(objnr >= cachep->num);
73481+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73482+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73483+ return;
73484+
73485+report:
73486+ pax_report_usercopy(ptr, n, to, type);
73487+#endif
73488+
73489+}
73490+EXPORT_SYMBOL(check_object_size);
73491+
73492 /**
73493 * ksize - get the actual amount of memory allocated for a given object
73494 * @objp: Pointer to the object
73495diff --git a/mm/slob.c b/mm/slob.c
73496index 8105be4..e045f96 100644
73497--- a/mm/slob.c
73498+++ b/mm/slob.c
73499@@ -29,7 +29,7 @@
73500 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73501 * alloc_pages() directly, allocating compound pages so the page order
73502 * does not have to be separately tracked, and also stores the exact
73503- * allocation size in page->private so that it can be used to accurately
73504+ * allocation size in slob_page->size so that it can be used to accurately
73505 * provide ksize(). These objects are detected in kfree() because slob_page()
73506 * is false for them.
73507 *
73508@@ -58,6 +58,7 @@
73509 */
73510
73511 #include <linux/kernel.h>
73512+#include <linux/sched.h>
73513 #include <linux/slab.h>
73514 #include <linux/mm.h>
73515 #include <linux/swap.h> /* struct reclaim_state */
73516@@ -102,7 +103,8 @@ struct slob_page {
73517 unsigned long flags; /* mandatory */
73518 atomic_t _count; /* mandatory */
73519 slobidx_t units; /* free units left in page */
73520- unsigned long pad[2];
73521+ unsigned long pad[1];
73522+ unsigned long size; /* size when >=PAGE_SIZE */
73523 slob_t *free; /* first free slob_t in page */
73524 struct list_head list; /* linked list of free pages */
73525 };
73526@@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
73527 */
73528 static inline int is_slob_page(struct slob_page *sp)
73529 {
73530- return PageSlab((struct page *)sp);
73531+ return PageSlab((struct page *)sp) && !sp->size;
73532 }
73533
73534 static inline void set_slob_page(struct slob_page *sp)
73535@@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
73536
73537 static inline struct slob_page *slob_page(const void *addr)
73538 {
73539- return (struct slob_page *)virt_to_page(addr);
73540+ return (struct slob_page *)virt_to_head_page(addr);
73541 }
73542
73543 /*
73544@@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
73545 /*
73546 * Return the size of a slob block.
73547 */
73548-static slobidx_t slob_units(slob_t *s)
73549+static slobidx_t slob_units(const slob_t *s)
73550 {
73551 if (s->units > 0)
73552 return s->units;
73553@@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
73554 /*
73555 * Return the next free slob block pointer after this one.
73556 */
73557-static slob_t *slob_next(slob_t *s)
73558+static slob_t *slob_next(const slob_t *s)
73559 {
73560 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
73561 slobidx_t next;
73562@@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
73563 /*
73564 * Returns true if s is the last free block in its page.
73565 */
73566-static int slob_last(slob_t *s)
73567+static int slob_last(const slob_t *s)
73568 {
73569 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
73570 }
73571@@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
73572 if (!page)
73573 return NULL;
73574
73575+ set_slob_page(page);
73576 return page_address(page);
73577 }
73578
73579@@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
73580 if (!b)
73581 return NULL;
73582 sp = slob_page(b);
73583- set_slob_page(sp);
73584
73585 spin_lock_irqsave(&slob_lock, flags);
73586 sp->units = SLOB_UNITS(PAGE_SIZE);
73587 sp->free = b;
73588+ sp->size = 0;
73589 INIT_LIST_HEAD(&sp->list);
73590 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
73591 set_slob_page_free(sp, slob_list);
73592@@ -476,10 +479,9 @@ out:
73593 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
73594 */
73595
73596-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73597+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
73598 {
73599- unsigned int *m;
73600- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73601+ slob_t *m;
73602 void *ret;
73603
73604 gfp &= gfp_allowed_mask;
73605@@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73606
73607 if (!m)
73608 return NULL;
73609- *m = size;
73610+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
73611+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
73612+ m[0].units = size;
73613+ m[1].units = align;
73614 ret = (void *)m + align;
73615
73616 trace_kmalloc_node(_RET_IP_, ret,
73617@@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73618 gfp |= __GFP_COMP;
73619 ret = slob_new_pages(gfp, order, node);
73620 if (ret) {
73621- struct page *page;
73622- page = virt_to_page(ret);
73623- page->private = size;
73624+ struct slob_page *sp;
73625+ sp = slob_page(ret);
73626+ sp->size = size;
73627 }
73628
73629 trace_kmalloc_node(_RET_IP_, ret,
73630 size, PAGE_SIZE << order, gfp, node);
73631 }
73632
73633- kmemleak_alloc(ret, size, 1, gfp);
73634+ return ret;
73635+}
73636+
73637+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73638+{
73639+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73640+ void *ret = __kmalloc_node_align(size, gfp, node, align);
73641+
73642+ if (!ZERO_OR_NULL_PTR(ret))
73643+ kmemleak_alloc(ret, size, 1, gfp);
73644 return ret;
73645 }
73646 EXPORT_SYMBOL(__kmalloc_node);
73647@@ -533,13 +547,92 @@ void kfree(const void *block)
73648 sp = slob_page(block);
73649 if (is_slob_page(sp)) {
73650 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73651- unsigned int *m = (unsigned int *)(block - align);
73652- slob_free(m, *m + align);
73653- } else
73654+ slob_t *m = (slob_t *)(block - align);
73655+ slob_free(m, m[0].units + align);
73656+ } else {
73657+ clear_slob_page(sp);
73658+ free_slob_page(sp);
73659+ sp->size = 0;
73660 put_page(&sp->page);
73661+ }
73662 }
73663 EXPORT_SYMBOL(kfree);
73664
73665+void check_object_size(const void *ptr, unsigned long n, bool to)
73666+{
73667+
73668+#ifdef CONFIG_PAX_USERCOPY
73669+ struct slob_page *sp;
73670+ const slob_t *free;
73671+ const void *base;
73672+ unsigned long flags;
73673+ const char *type;
73674+
73675+ if (!n)
73676+ return;
73677+
73678+ type = "<null>";
73679+ if (ZERO_OR_NULL_PTR(ptr))
73680+ goto report;
73681+
73682+ if (!virt_addr_valid(ptr))
73683+ return;
73684+
73685+ type = "<process stack>";
73686+ sp = slob_page(ptr);
73687+ if (!PageSlab((struct page *)sp)) {
73688+ if (object_is_on_stack(ptr, n) == -1)
73689+ goto report;
73690+ return;
73691+ }
73692+
73693+ type = "<slob>";
73694+ if (sp->size) {
73695+ base = page_address(&sp->page);
73696+ if (base <= ptr && n <= sp->size - (ptr - base))
73697+ return;
73698+ goto report;
73699+ }
73700+
73701+ /* some tricky double walking to find the chunk */
73702+ spin_lock_irqsave(&slob_lock, flags);
73703+ base = (void *)((unsigned long)ptr & PAGE_MASK);
73704+ free = sp->free;
73705+
73706+ while (!slob_last(free) && (void *)free <= ptr) {
73707+ base = free + slob_units(free);
73708+ free = slob_next(free);
73709+ }
73710+
73711+ while (base < (void *)free) {
73712+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
73713+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
73714+ int offset;
73715+
73716+ if (ptr < base + align)
73717+ break;
73718+
73719+ offset = ptr - base - align;
73720+ if (offset >= m) {
73721+ base += size;
73722+ continue;
73723+ }
73724+
73725+ if (n > m - offset)
73726+ break;
73727+
73728+ spin_unlock_irqrestore(&slob_lock, flags);
73729+ return;
73730+ }
73731+
73732+ spin_unlock_irqrestore(&slob_lock, flags);
73733+report:
73734+ pax_report_usercopy(ptr, n, to, type);
73735+#endif
73736+
73737+}
73738+EXPORT_SYMBOL(check_object_size);
73739+
73740 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
73741 size_t ksize(const void *block)
73742 {
73743@@ -552,10 +645,10 @@ size_t ksize(const void *block)
73744 sp = slob_page(block);
73745 if (is_slob_page(sp)) {
73746 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73747- unsigned int *m = (unsigned int *)(block - align);
73748- return SLOB_UNITS(*m) * SLOB_UNIT;
73749+ slob_t *m = (slob_t *)(block - align);
73750+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
73751 } else
73752- return sp->page.private;
73753+ return sp->size;
73754 }
73755 EXPORT_SYMBOL(ksize);
73756
73757@@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73758 {
73759 struct kmem_cache *c;
73760
73761+#ifdef CONFIG_PAX_USERCOPY
73762+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
73763+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
73764+#else
73765 c = slob_alloc(sizeof(struct kmem_cache),
73766 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
73767+#endif
73768
73769 if (c) {
73770 c->name = name;
73771@@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
73772
73773 lockdep_trace_alloc(flags);
73774
73775+#ifdef CONFIG_PAX_USERCOPY
73776+ b = __kmalloc_node_align(c->size, flags, node, c->align);
73777+#else
73778 if (c->size < PAGE_SIZE) {
73779 b = slob_alloc(c->size, flags, c->align, node);
73780 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73781 SLOB_UNITS(c->size) * SLOB_UNIT,
73782 flags, node);
73783 } else {
73784+ struct slob_page *sp;
73785+
73786 b = slob_new_pages(flags, get_order(c->size), node);
73787+ sp = slob_page(b);
73788+ sp->size = c->size;
73789 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73790 PAGE_SIZE << get_order(c->size),
73791 flags, node);
73792 }
73793+#endif
73794
73795 if (c->ctor)
73796 c->ctor(b);
73797@@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
73798
73799 static void __kmem_cache_free(void *b, int size)
73800 {
73801- if (size < PAGE_SIZE)
73802+ struct slob_page *sp = slob_page(b);
73803+
73804+ if (is_slob_page(sp))
73805 slob_free(b, size);
73806- else
73807+ else {
73808+ clear_slob_page(sp);
73809+ free_slob_page(sp);
73810+ sp->size = 0;
73811 slob_free_pages(b, get_order(size));
73812+ }
73813 }
73814
73815 static void kmem_rcu_free(struct rcu_head *head)
73816@@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
73817
73818 void kmem_cache_free(struct kmem_cache *c, void *b)
73819 {
73820+ int size = c->size;
73821+
73822+#ifdef CONFIG_PAX_USERCOPY
73823+ if (size + c->align < PAGE_SIZE) {
73824+ size += c->align;
73825+ b -= c->align;
73826+ }
73827+#endif
73828+
73829 kmemleak_free_recursive(b, c->flags);
73830 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
73831 struct slob_rcu *slob_rcu;
73832- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
73833- slob_rcu->size = c->size;
73834+ slob_rcu = b + (size - sizeof(struct slob_rcu));
73835+ slob_rcu->size = size;
73836 call_rcu(&slob_rcu->head, kmem_rcu_free);
73837 } else {
73838- __kmem_cache_free(b, c->size);
73839+ __kmem_cache_free(b, size);
73840 }
73841
73842+#ifdef CONFIG_PAX_USERCOPY
73843+ trace_kfree(_RET_IP_, b);
73844+#else
73845 trace_kmem_cache_free(_RET_IP_, b);
73846+#endif
73847+
73848 }
73849 EXPORT_SYMBOL(kmem_cache_free);
73850
73851diff --git a/mm/slub.c b/mm/slub.c
73852index 0342a5d..8180ae9 100644
73853--- a/mm/slub.c
73854+++ b/mm/slub.c
73855@@ -208,7 +208,7 @@ struct track {
73856
73857 enum track_item { TRACK_ALLOC, TRACK_FREE };
73858
73859-#ifdef CONFIG_SYSFS
73860+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73861 static int sysfs_slab_add(struct kmem_cache *);
73862 static int sysfs_slab_alias(struct kmem_cache *, const char *);
73863 static void sysfs_slab_remove(struct kmem_cache *);
73864@@ -532,7 +532,7 @@ static void print_track(const char *s, struct track *t)
73865 if (!t->addr)
73866 return;
73867
73868- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
73869+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
73870 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
73871 #ifdef CONFIG_STACKTRACE
73872 {
73873@@ -2571,6 +2571,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
73874
73875 page = virt_to_head_page(x);
73876
73877+ BUG_ON(!PageSlab(page));
73878+
73879 slab_free(s, page, x, _RET_IP_);
73880
73881 trace_kmem_cache_free(_RET_IP_, x);
73882@@ -2604,7 +2606,7 @@ static int slub_min_objects;
73883 * Merge control. If this is set then no merging of slab caches will occur.
73884 * (Could be removed. This was introduced to pacify the merge skeptics.)
73885 */
73886-static int slub_nomerge;
73887+static int slub_nomerge = 1;
73888
73889 /*
73890 * Calculate the order of allocation given an slab object size.
73891@@ -3057,7 +3059,7 @@ static int kmem_cache_open(struct kmem_cache *s,
73892 else
73893 s->cpu_partial = 30;
73894
73895- s->refcount = 1;
73896+ atomic_set(&s->refcount, 1);
73897 #ifdef CONFIG_NUMA
73898 s->remote_node_defrag_ratio = 1000;
73899 #endif
73900@@ -3161,8 +3163,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
73901 void kmem_cache_destroy(struct kmem_cache *s)
73902 {
73903 down_write(&slub_lock);
73904- s->refcount--;
73905- if (!s->refcount) {
73906+ if (atomic_dec_and_test(&s->refcount)) {
73907 list_del(&s->list);
73908 up_write(&slub_lock);
73909 if (kmem_cache_close(s)) {
73910@@ -3373,6 +3374,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
73911 EXPORT_SYMBOL(__kmalloc_node);
73912 #endif
73913
73914+void check_object_size(const void *ptr, unsigned long n, bool to)
73915+{
73916+
73917+#ifdef CONFIG_PAX_USERCOPY
73918+ struct page *page;
73919+ struct kmem_cache *s = NULL;
73920+ unsigned long offset;
73921+ const char *type;
73922+
73923+ if (!n)
73924+ return;
73925+
73926+ type = "<null>";
73927+ if (ZERO_OR_NULL_PTR(ptr))
73928+ goto report;
73929+
73930+ if (!virt_addr_valid(ptr))
73931+ return;
73932+
73933+ page = virt_to_head_page(ptr);
73934+
73935+ type = "<process stack>";
73936+ if (!PageSlab(page)) {
73937+ if (object_is_on_stack(ptr, n) == -1)
73938+ goto report;
73939+ return;
73940+ }
73941+
73942+ s = page->slab;
73943+ type = s->name;
73944+ if (!(s->flags & SLAB_USERCOPY))
73945+ goto report;
73946+
73947+ offset = (ptr - page_address(page)) % s->size;
73948+ if (offset <= s->objsize && n <= s->objsize - offset)
73949+ return;
73950+
73951+report:
73952+ pax_report_usercopy(ptr, n, to, type);
73953+#endif
73954+
73955+}
73956+EXPORT_SYMBOL(check_object_size);
73957+
73958 size_t ksize(const void *object)
73959 {
73960 struct page *page;
73961@@ -3647,7 +3692,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
73962 int node;
73963
73964 list_add(&s->list, &slab_caches);
73965- s->refcount = -1;
73966+ atomic_set(&s->refcount, -1);
73967
73968 for_each_node_state(node, N_NORMAL_MEMORY) {
73969 struct kmem_cache_node *n = get_node(s, node);
73970@@ -3767,17 +3812,17 @@ void __init kmem_cache_init(void)
73971
73972 /* Caches that are not of the two-to-the-power-of size */
73973 if (KMALLOC_MIN_SIZE <= 32) {
73974- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
73975+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
73976 caches++;
73977 }
73978
73979 if (KMALLOC_MIN_SIZE <= 64) {
73980- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
73981+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
73982 caches++;
73983 }
73984
73985 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
73986- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
73987+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
73988 caches++;
73989 }
73990
73991@@ -3845,7 +3890,7 @@ static int slab_unmergeable(struct kmem_cache *s)
73992 /*
73993 * We may have set a slab to be unmergeable during bootstrap.
73994 */
73995- if (s->refcount < 0)
73996+ if (atomic_read(&s->refcount) < 0)
73997 return 1;
73998
73999 return 0;
74000@@ -3904,7 +3949,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74001 down_write(&slub_lock);
74002 s = find_mergeable(size, align, flags, name, ctor);
74003 if (s) {
74004- s->refcount++;
74005+ atomic_inc(&s->refcount);
74006 /*
74007 * Adjust the object sizes so that we clear
74008 * the complete object on kzalloc.
74009@@ -3913,7 +3958,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74010 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74011
74012 if (sysfs_slab_alias(s, name)) {
74013- s->refcount--;
74014+ atomic_dec(&s->refcount);
74015 goto err;
74016 }
74017 up_write(&slub_lock);
74018@@ -4042,7 +4087,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74019 }
74020 #endif
74021
74022-#ifdef CONFIG_SYSFS
74023+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74024 static int count_inuse(struct page *page)
74025 {
74026 return page->inuse;
74027@@ -4429,12 +4474,12 @@ static void resiliency_test(void)
74028 validate_slab_cache(kmalloc_caches[9]);
74029 }
74030 #else
74031-#ifdef CONFIG_SYSFS
74032+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74033 static void resiliency_test(void) {};
74034 #endif
74035 #endif
74036
74037-#ifdef CONFIG_SYSFS
74038+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74039 enum slab_stat_type {
74040 SL_ALL, /* All slabs */
74041 SL_PARTIAL, /* Only partially allocated slabs */
74042@@ -4677,7 +4722,7 @@ SLAB_ATTR_RO(ctor);
74043
74044 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74045 {
74046- return sprintf(buf, "%d\n", s->refcount - 1);
74047+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74048 }
74049 SLAB_ATTR_RO(aliases);
74050
74051@@ -5244,6 +5289,7 @@ static char *create_unique_id(struct kmem_cache *s)
74052 return name;
74053 }
74054
74055+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74056 static int sysfs_slab_add(struct kmem_cache *s)
74057 {
74058 int err;
74059@@ -5306,6 +5352,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74060 kobject_del(&s->kobj);
74061 kobject_put(&s->kobj);
74062 }
74063+#endif
74064
74065 /*
74066 * Need to buffer aliases during bootup until sysfs becomes
74067@@ -5319,6 +5366,7 @@ struct saved_alias {
74068
74069 static struct saved_alias *alias_list;
74070
74071+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74072 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74073 {
74074 struct saved_alias *al;
74075@@ -5341,6 +5389,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74076 alias_list = al;
74077 return 0;
74078 }
74079+#endif
74080
74081 static int __init slab_sysfs_init(void)
74082 {
74083diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
74084index 1b7e22a..3fcd4f3 100644
74085--- a/mm/sparse-vmemmap.c
74086+++ b/mm/sparse-vmemmap.c
74087@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
74088 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74089 if (!p)
74090 return NULL;
74091- pud_populate(&init_mm, pud, p);
74092+ pud_populate_kernel(&init_mm, pud, p);
74093 }
74094 return pud;
74095 }
74096@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
74097 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74098 if (!p)
74099 return NULL;
74100- pgd_populate(&init_mm, pgd, p);
74101+ pgd_populate_kernel(&init_mm, pgd, p);
74102 }
74103 return pgd;
74104 }
74105diff --git a/mm/swap.c b/mm/swap.c
74106index 14380e9..e244704 100644
74107--- a/mm/swap.c
74108+++ b/mm/swap.c
74109@@ -30,6 +30,7 @@
74110 #include <linux/backing-dev.h>
74111 #include <linux/memcontrol.h>
74112 #include <linux/gfp.h>
74113+#include <linux/hugetlb.h>
74114
74115 #include "internal.h"
74116
74117@@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
74118
74119 __page_cache_release(page);
74120 dtor = get_compound_page_dtor(page);
74121+ if (!PageHuge(page))
74122+ BUG_ON(dtor != free_compound_page);
74123 (*dtor)(page);
74124 }
74125
74126diff --git a/mm/swapfile.c b/mm/swapfile.c
74127index f31b29d..8bdcae2 100644
74128--- a/mm/swapfile.c
74129+++ b/mm/swapfile.c
74130@@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
74131
74132 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74133 /* Activity counter to indicate that a swapon or swapoff has occurred */
74134-static atomic_t proc_poll_event = ATOMIC_INIT(0);
74135+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74136
74137 static inline unsigned char swap_count(unsigned char ent)
74138 {
74139@@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74140 }
74141 filp_close(swap_file, NULL);
74142 err = 0;
74143- atomic_inc(&proc_poll_event);
74144+ atomic_inc_unchecked(&proc_poll_event);
74145 wake_up_interruptible(&proc_poll_wait);
74146
74147 out_dput:
74148@@ -1685,8 +1685,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74149
74150 poll_wait(file, &proc_poll_wait, wait);
74151
74152- if (seq->poll_event != atomic_read(&proc_poll_event)) {
74153- seq->poll_event = atomic_read(&proc_poll_event);
74154+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74155+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74156 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74157 }
74158
74159@@ -1784,7 +1784,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74160 return ret;
74161
74162 seq = file->private_data;
74163- seq->poll_event = atomic_read(&proc_poll_event);
74164+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74165 return 0;
74166 }
74167
74168@@ -2122,7 +2122,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74169 (p->flags & SWP_DISCARDABLE) ? "D" : "");
74170
74171 mutex_unlock(&swapon_mutex);
74172- atomic_inc(&proc_poll_event);
74173+ atomic_inc_unchecked(&proc_poll_event);
74174 wake_up_interruptible(&proc_poll_wait);
74175
74176 if (S_ISREG(inode->i_mode))
74177diff --git a/mm/util.c b/mm/util.c
74178index 136ac4f..f917fa9 100644
74179--- a/mm/util.c
74180+++ b/mm/util.c
74181@@ -243,6 +243,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
74182 void arch_pick_mmap_layout(struct mm_struct *mm)
74183 {
74184 mm->mmap_base = TASK_UNMAPPED_BASE;
74185+
74186+#ifdef CONFIG_PAX_RANDMMAP
74187+ if (mm->pax_flags & MF_PAX_RANDMMAP)
74188+ mm->mmap_base += mm->delta_mmap;
74189+#endif
74190+
74191 mm->get_unmapped_area = arch_get_unmapped_area;
74192 mm->unmap_area = arch_unmap_area;
74193 }
74194diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74195index 86ce9a5..550d03c 100644
74196--- a/mm/vmalloc.c
74197+++ b/mm/vmalloc.c
74198@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74199
74200 pte = pte_offset_kernel(pmd, addr);
74201 do {
74202- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74203- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74204+
74205+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74206+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74207+ BUG_ON(!pte_exec(*pte));
74208+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74209+ continue;
74210+ }
74211+#endif
74212+
74213+ {
74214+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74215+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74216+ }
74217 } while (pte++, addr += PAGE_SIZE, addr != end);
74218 }
74219
74220@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74221 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74222 {
74223 pte_t *pte;
74224+ int ret = -ENOMEM;
74225
74226 /*
74227 * nr is a running index into the array which helps higher level
74228@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74229 pte = pte_alloc_kernel(pmd, addr);
74230 if (!pte)
74231 return -ENOMEM;
74232+
74233+ pax_open_kernel();
74234 do {
74235 struct page *page = pages[*nr];
74236
74237- if (WARN_ON(!pte_none(*pte)))
74238- return -EBUSY;
74239- if (WARN_ON(!page))
74240- return -ENOMEM;
74241+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74242+ if (pgprot_val(prot) & _PAGE_NX)
74243+#endif
74244+
74245+ if (WARN_ON(!pte_none(*pte))) {
74246+ ret = -EBUSY;
74247+ goto out;
74248+ }
74249+ if (WARN_ON(!page)) {
74250+ ret = -ENOMEM;
74251+ goto out;
74252+ }
74253 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74254 (*nr)++;
74255 } while (pte++, addr += PAGE_SIZE, addr != end);
74256- return 0;
74257+ ret = 0;
74258+out:
74259+ pax_close_kernel();
74260+ return ret;
74261 }
74262
74263 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74264@@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74265 pmd_t *pmd;
74266 unsigned long next;
74267
74268- pmd = pmd_alloc(&init_mm, pud, addr);
74269+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74270 if (!pmd)
74271 return -ENOMEM;
74272 do {
74273@@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
74274 pud_t *pud;
74275 unsigned long next;
74276
74277- pud = pud_alloc(&init_mm, pgd, addr);
74278+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
74279 if (!pud)
74280 return -ENOMEM;
74281 do {
74282@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74283 * and fall back on vmalloc() if that fails. Others
74284 * just put it in the vmalloc space.
74285 */
74286-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74287+#ifdef CONFIG_MODULES
74288+#ifdef MODULES_VADDR
74289 unsigned long addr = (unsigned long)x;
74290 if (addr >= MODULES_VADDR && addr < MODULES_END)
74291 return 1;
74292 #endif
74293+
74294+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74295+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74296+ return 1;
74297+#endif
74298+
74299+#endif
74300+
74301 return is_vmalloc_addr(x);
74302 }
74303
74304@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74305
74306 if (!pgd_none(*pgd)) {
74307 pud_t *pud = pud_offset(pgd, addr);
74308+#ifdef CONFIG_X86
74309+ if (!pud_large(*pud))
74310+#endif
74311 if (!pud_none(*pud)) {
74312 pmd_t *pmd = pmd_offset(pud, addr);
74313+#ifdef CONFIG_X86
74314+ if (!pmd_large(*pmd))
74315+#endif
74316 if (!pmd_none(*pmd)) {
74317 pte_t *ptep, pte;
74318
74319@@ -332,6 +372,10 @@ static void purge_vmap_area_lazy(void);
74320 static struct vmap_area *alloc_vmap_area(unsigned long size,
74321 unsigned long align,
74322 unsigned long vstart, unsigned long vend,
74323+ int node, gfp_t gfp_mask) __size_overflow(1);
74324+static struct vmap_area *alloc_vmap_area(unsigned long size,
74325+ unsigned long align,
74326+ unsigned long vstart, unsigned long vend,
74327 int node, gfp_t gfp_mask)
74328 {
74329 struct vmap_area *va;
74330@@ -1319,6 +1363,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74331 struct vm_struct *area;
74332
74333 BUG_ON(in_interrupt());
74334+
74335+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74336+ if (flags & VM_KERNEXEC) {
74337+ if (start != VMALLOC_START || end != VMALLOC_END)
74338+ return NULL;
74339+ start = (unsigned long)MODULES_EXEC_VADDR;
74340+ end = (unsigned long)MODULES_EXEC_END;
74341+ }
74342+#endif
74343+
74344 if (flags & VM_IOREMAP) {
74345 int bit = fls(size);
74346
74347@@ -1551,6 +1605,11 @@ void *vmap(struct page **pages, unsigned int count,
74348 if (count > totalram_pages)
74349 return NULL;
74350
74351+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74352+ if (!(pgprot_val(prot) & _PAGE_NX))
74353+ flags |= VM_KERNEXEC;
74354+#endif
74355+
74356 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74357 __builtin_return_address(0));
74358 if (!area)
74359@@ -1652,6 +1711,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74360 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74361 goto fail;
74362
74363+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74364+ if (!(pgprot_val(prot) & _PAGE_NX))
74365+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74366+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74367+ else
74368+#endif
74369+
74370 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74371 start, end, node, gfp_mask, caller);
74372 if (!area)
74373@@ -1825,10 +1891,9 @@ EXPORT_SYMBOL(vzalloc_node);
74374 * For tight control over page level allocator and protection flags
74375 * use __vmalloc() instead.
74376 */
74377-
74378 void *vmalloc_exec(unsigned long size)
74379 {
74380- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74381+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74382 -1, __builtin_return_address(0));
74383 }
74384
74385@@ -2123,6 +2188,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74386 unsigned long uaddr = vma->vm_start;
74387 unsigned long usize = vma->vm_end - vma->vm_start;
74388
74389+ BUG_ON(vma->vm_mirror);
74390+
74391 if ((PAGE_SIZE-1) & (unsigned long)addr)
74392 return -EINVAL;
74393
74394@@ -2375,8 +2442,8 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
74395 return NULL;
74396 }
74397
74398- vms = kzalloc(sizeof(vms[0]) * nr_vms, GFP_KERNEL);
74399- vas = kzalloc(sizeof(vas[0]) * nr_vms, GFP_KERNEL);
74400+ vms = kcalloc(nr_vms, sizeof(vms[0]), GFP_KERNEL);
74401+ vas = kcalloc(nr_vms, sizeof(vas[0]), GFP_KERNEL);
74402 if (!vas || !vms)
74403 goto err_free2;
74404
74405diff --git a/mm/vmstat.c b/mm/vmstat.c
74406index f600557..1459fc8 100644
74407--- a/mm/vmstat.c
74408+++ b/mm/vmstat.c
74409@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74410 *
74411 * vm_stat contains the global counters
74412 */
74413-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74414+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74415 EXPORT_SYMBOL(vm_stat);
74416
74417 #ifdef CONFIG_SMP
74418@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74419 v = p->vm_stat_diff[i];
74420 p->vm_stat_diff[i] = 0;
74421 local_irq_restore(flags);
74422- atomic_long_add(v, &zone->vm_stat[i]);
74423+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74424 global_diff[i] += v;
74425 #ifdef CONFIG_NUMA
74426 /* 3 seconds idle till flush */
74427@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74428
74429 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74430 if (global_diff[i])
74431- atomic_long_add(global_diff[i], &vm_stat[i]);
74432+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74433 }
74434
74435 #endif
74436@@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
74437 start_cpu_timer(cpu);
74438 #endif
74439 #ifdef CONFIG_PROC_FS
74440- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74441- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74442- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74443- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74444+ {
74445+ mode_t gr_mode = S_IRUGO;
74446+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74447+ gr_mode = S_IRUSR;
74448+#endif
74449+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74450+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74451+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74452+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74453+#else
74454+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74455+#endif
74456+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74457+ }
74458 #endif
74459 return 0;
74460 }
74461diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74462index efea35b..9c8dd0b 100644
74463--- a/net/8021q/vlan.c
74464+++ b/net/8021q/vlan.c
74465@@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74466 err = -EPERM;
74467 if (!capable(CAP_NET_ADMIN))
74468 break;
74469- if ((args.u.name_type >= 0) &&
74470- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74471+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74472 struct vlan_net *vn;
74473
74474 vn = net_generic(net, vlan_net_id);
74475diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74476index fccae26..e7ece2f 100644
74477--- a/net/9p/trans_fd.c
74478+++ b/net/9p/trans_fd.c
74479@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74480 oldfs = get_fs();
74481 set_fs(get_ds());
74482 /* The cast to a user pointer is valid due to the set_fs() */
74483- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
74484+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
74485 set_fs(oldfs);
74486
74487 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
74488diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
74489index 876fbe8..8bbea9f 100644
74490--- a/net/atm/atm_misc.c
74491+++ b/net/atm/atm_misc.c
74492@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
74493 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
74494 return 1;
74495 atm_return(vcc, truesize);
74496- atomic_inc(&vcc->stats->rx_drop);
74497+ atomic_inc_unchecked(&vcc->stats->rx_drop);
74498 return 0;
74499 }
74500 EXPORT_SYMBOL(atm_charge);
74501@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
74502 }
74503 }
74504 atm_return(vcc, guess);
74505- atomic_inc(&vcc->stats->rx_drop);
74506+ atomic_inc_unchecked(&vcc->stats->rx_drop);
74507 return NULL;
74508 }
74509 EXPORT_SYMBOL(atm_alloc_charge);
74510@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
74511
74512 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74513 {
74514-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74515+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74516 __SONET_ITEMS
74517 #undef __HANDLE_ITEM
74518 }
74519@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
74520
74521 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74522 {
74523-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74524+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
74525 __SONET_ITEMS
74526 #undef __HANDLE_ITEM
74527 }
74528diff --git a/net/atm/lec.h b/net/atm/lec.h
74529index dfc0719..47c5322 100644
74530--- a/net/atm/lec.h
74531+++ b/net/atm/lec.h
74532@@ -48,7 +48,7 @@ struct lane2_ops {
74533 const u8 *tlvs, u32 sizeoftlvs);
74534 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
74535 const u8 *tlvs, u32 sizeoftlvs);
74536-};
74537+} __no_const;
74538
74539 /*
74540 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
74541diff --git a/net/atm/mpc.h b/net/atm/mpc.h
74542index 0919a88..a23d54e 100644
74543--- a/net/atm/mpc.h
74544+++ b/net/atm/mpc.h
74545@@ -33,7 +33,7 @@ struct mpoa_client {
74546 struct mpc_parameters parameters; /* parameters for this client */
74547
74548 const struct net_device_ops *old_ops;
74549- struct net_device_ops new_ops;
74550+ net_device_ops_no_const new_ops;
74551 };
74552
74553
74554diff --git a/net/atm/proc.c b/net/atm/proc.c
74555index 0d020de..011c7bb 100644
74556--- a/net/atm/proc.c
74557+++ b/net/atm/proc.c
74558@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
74559 const struct k_atm_aal_stats *stats)
74560 {
74561 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
74562- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
74563- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
74564- atomic_read(&stats->rx_drop));
74565+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
74566+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
74567+ atomic_read_unchecked(&stats->rx_drop));
74568 }
74569
74570 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
74571diff --git a/net/atm/resources.c b/net/atm/resources.c
74572index 23f45ce..c748f1a 100644
74573--- a/net/atm/resources.c
74574+++ b/net/atm/resources.c
74575@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
74576 static void copy_aal_stats(struct k_atm_aal_stats *from,
74577 struct atm_aal_stats *to)
74578 {
74579-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74580+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74581 __AAL_STAT_ITEMS
74582 #undef __HANDLE_ITEM
74583 }
74584@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
74585 static void subtract_aal_stats(struct k_atm_aal_stats *from,
74586 struct atm_aal_stats *to)
74587 {
74588-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74589+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
74590 __AAL_STAT_ITEMS
74591 #undef __HANDLE_ITEM
74592 }
74593diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
74594index 3512e25..2b33401 100644
74595--- a/net/batman-adv/bat_iv_ogm.c
74596+++ b/net/batman-adv/bat_iv_ogm.c
74597@@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74598
74599 /* change sequence number to network order */
74600 batman_ogm_packet->seqno =
74601- htonl((uint32_t)atomic_read(&hard_iface->seqno));
74602+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
74603
74604 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
74605 batman_ogm_packet->tt_crc = htons((uint16_t)
74606@@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74607 else
74608 batman_ogm_packet->gw_flags = NO_FLAGS;
74609
74610- atomic_inc(&hard_iface->seqno);
74611+ atomic_inc_unchecked(&hard_iface->seqno);
74612
74613 slide_own_bcast_window(hard_iface);
74614 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
74615@@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
74616 return;
74617
74618 /* could be changed by schedule_own_packet() */
74619- if_incoming_seqno = atomic_read(&if_incoming->seqno);
74620+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
74621
74622 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
74623
74624diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
74625index 7704df4..beb4e16 100644
74626--- a/net/batman-adv/hard-interface.c
74627+++ b/net/batman-adv/hard-interface.c
74628@@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
74629 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
74630 dev_add_pack(&hard_iface->batman_adv_ptype);
74631
74632- atomic_set(&hard_iface->seqno, 1);
74633- atomic_set(&hard_iface->frag_seqno, 1);
74634+ atomic_set_unchecked(&hard_iface->seqno, 1);
74635+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
74636 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
74637 hard_iface->net_dev->name);
74638
74639diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
74640index 987c75a..20d6f36 100644
74641--- a/net/batman-adv/soft-interface.c
74642+++ b/net/batman-adv/soft-interface.c
74643@@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
74644
74645 /* set broadcast sequence number */
74646 bcast_packet->seqno =
74647- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
74648+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
74649
74650 add_bcast_packet_to_list(bat_priv, skb, 1);
74651
74652@@ -843,7 +843,7 @@ struct net_device *softif_create(const char *name)
74653 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
74654
74655 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
74656- atomic_set(&bat_priv->bcast_seqno, 1);
74657+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
74658 atomic_set(&bat_priv->ttvn, 0);
74659 atomic_set(&bat_priv->tt_local_changes, 0);
74660 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
74661diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
74662index e9eb043..d174eeb 100644
74663--- a/net/batman-adv/types.h
74664+++ b/net/batman-adv/types.h
74665@@ -38,8 +38,8 @@ struct hard_iface {
74666 int16_t if_num;
74667 char if_status;
74668 struct net_device *net_dev;
74669- atomic_t seqno;
74670- atomic_t frag_seqno;
74671+ atomic_unchecked_t seqno;
74672+ atomic_unchecked_t frag_seqno;
74673 unsigned char *packet_buff;
74674 int packet_len;
74675 struct kobject *hardif_obj;
74676@@ -154,7 +154,7 @@ struct bat_priv {
74677 atomic_t orig_interval; /* uint */
74678 atomic_t hop_penalty; /* uint */
74679 atomic_t log_level; /* uint */
74680- atomic_t bcast_seqno;
74681+ atomic_unchecked_t bcast_seqno;
74682 atomic_t bcast_queue_left;
74683 atomic_t batman_queue_left;
74684 atomic_t ttvn; /* translation table version number */
74685diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
74686index 07d1c1d..7e9bea9 100644
74687--- a/net/batman-adv/unicast.c
74688+++ b/net/batman-adv/unicast.c
74689@@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
74690 frag1->flags = UNI_FRAG_HEAD | large_tail;
74691 frag2->flags = large_tail;
74692
74693- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
74694+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
74695 frag1->seqno = htons(seqno - 1);
74696 frag2->seqno = htons(seqno);
74697
74698diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
74699index 280953b..cd219bb 100644
74700--- a/net/bluetooth/hci_conn.c
74701+++ b/net/bluetooth/hci_conn.c
74702@@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
74703 memset(&cp, 0, sizeof(cp));
74704
74705 cp.handle = cpu_to_le16(conn->handle);
74706- memcpy(cp.ltk, ltk, sizeof(ltk));
74707+ memcpy(cp.ltk, ltk, sizeof(cp.ltk));
74708
74709 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
74710 }
74711diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
74712index 32d338c..d24bcdb 100644
74713--- a/net/bluetooth/l2cap_core.c
74714+++ b/net/bluetooth/l2cap_core.c
74715@@ -2418,8 +2418,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
74716 break;
74717
74718 case L2CAP_CONF_RFC:
74719- if (olen == sizeof(rfc))
74720- memcpy(&rfc, (void *)val, olen);
74721+ if (olen != sizeof(rfc))
74722+ break;
74723+
74724+ memcpy(&rfc, (void *)val, olen);
74725
74726 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
74727 rfc.mode != chan->mode)
74728@@ -2537,8 +2539,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
74729
74730 switch (type) {
74731 case L2CAP_CONF_RFC:
74732- if (olen == sizeof(rfc))
74733- memcpy(&rfc, (void *)val, olen);
74734+ if (olen != sizeof(rfc))
74735+ break;
74736+
74737+ memcpy(&rfc, (void *)val, olen);
74738 goto done;
74739 }
74740 }
74741diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
74742index 5fe2ff3..10968b5 100644
74743--- a/net/bridge/netfilter/ebtables.c
74744+++ b/net/bridge/netfilter/ebtables.c
74745@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
74746 tmp.valid_hooks = t->table->valid_hooks;
74747 }
74748 mutex_unlock(&ebt_mutex);
74749- if (copy_to_user(user, &tmp, *len) != 0){
74750+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
74751 BUGPRINT("c2u Didn't work\n");
74752 ret = -EFAULT;
74753 break;
74754diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
74755index a97d97a..6f679ed 100644
74756--- a/net/caif/caif_socket.c
74757+++ b/net/caif/caif_socket.c
74758@@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
74759 #ifdef CONFIG_DEBUG_FS
74760 struct debug_fs_counter {
74761 atomic_t caif_nr_socks;
74762- atomic_t caif_sock_create;
74763- atomic_t num_connect_req;
74764- atomic_t num_connect_resp;
74765- atomic_t num_connect_fail_resp;
74766- atomic_t num_disconnect;
74767- atomic_t num_remote_shutdown_ind;
74768- atomic_t num_tx_flow_off_ind;
74769- atomic_t num_tx_flow_on_ind;
74770- atomic_t num_rx_flow_off;
74771- atomic_t num_rx_flow_on;
74772+ atomic_unchecked_t caif_sock_create;
74773+ atomic_unchecked_t num_connect_req;
74774+ atomic_unchecked_t num_connect_resp;
74775+ atomic_unchecked_t num_connect_fail_resp;
74776+ atomic_unchecked_t num_disconnect;
74777+ atomic_unchecked_t num_remote_shutdown_ind;
74778+ atomic_unchecked_t num_tx_flow_off_ind;
74779+ atomic_unchecked_t num_tx_flow_on_ind;
74780+ atomic_unchecked_t num_rx_flow_off;
74781+ atomic_unchecked_t num_rx_flow_on;
74782 };
74783 static struct debug_fs_counter cnt;
74784 #define dbfs_atomic_inc(v) atomic_inc_return(v)
74785+#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
74786 #define dbfs_atomic_dec(v) atomic_dec_return(v)
74787 #else
74788 #define dbfs_atomic_inc(v) 0
74789@@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74790 atomic_read(&cf_sk->sk.sk_rmem_alloc),
74791 sk_rcvbuf_lowwater(cf_sk));
74792 set_rx_flow_off(cf_sk);
74793- dbfs_atomic_inc(&cnt.num_rx_flow_off);
74794+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74795 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74796 }
74797
74798@@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74799 set_rx_flow_off(cf_sk);
74800 if (net_ratelimit())
74801 pr_debug("sending flow OFF due to rmem_schedule\n");
74802- dbfs_atomic_inc(&cnt.num_rx_flow_off);
74803+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74804 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74805 }
74806 skb->dev = NULL;
74807@@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
74808 switch (flow) {
74809 case CAIF_CTRLCMD_FLOW_ON_IND:
74810 /* OK from modem to start sending again */
74811- dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
74812+ dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
74813 set_tx_flow_on(cf_sk);
74814 cf_sk->sk.sk_state_change(&cf_sk->sk);
74815 break;
74816
74817 case CAIF_CTRLCMD_FLOW_OFF_IND:
74818 /* Modem asks us to shut up */
74819- dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
74820+ dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
74821 set_tx_flow_off(cf_sk);
74822 cf_sk->sk.sk_state_change(&cf_sk->sk);
74823 break;
74824@@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74825 /* We're now connected */
74826 caif_client_register_refcnt(&cf_sk->layer,
74827 cfsk_hold, cfsk_put);
74828- dbfs_atomic_inc(&cnt.num_connect_resp);
74829+ dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
74830 cf_sk->sk.sk_state = CAIF_CONNECTED;
74831 set_tx_flow_on(cf_sk);
74832 cf_sk->sk.sk_state_change(&cf_sk->sk);
74833@@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74834
74835 case CAIF_CTRLCMD_INIT_FAIL_RSP:
74836 /* Connect request failed */
74837- dbfs_atomic_inc(&cnt.num_connect_fail_resp);
74838+ dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
74839 cf_sk->sk.sk_err = ECONNREFUSED;
74840 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
74841 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74842@@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74843
74844 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
74845 /* Modem has closed this connection, or device is down. */
74846- dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
74847+ dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
74848 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74849 cf_sk->sk.sk_err = ECONNRESET;
74850 set_rx_flow_on(cf_sk);
74851@@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
74852 return;
74853
74854 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
74855- dbfs_atomic_inc(&cnt.num_rx_flow_on);
74856+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
74857 set_rx_flow_on(cf_sk);
74858 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
74859 }
74860@@ -856,7 +857,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
74861 /*ifindex = id of the interface.*/
74862 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
74863
74864- dbfs_atomic_inc(&cnt.num_connect_req);
74865+ dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
74866 cf_sk->layer.receive = caif_sktrecv_cb;
74867
74868 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
74869@@ -945,7 +946,7 @@ static int caif_release(struct socket *sock)
74870 spin_unlock_bh(&sk->sk_receive_queue.lock);
74871 sock->sk = NULL;
74872
74873- dbfs_atomic_inc(&cnt.num_disconnect);
74874+ dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
74875
74876 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
74877 if (cf_sk->debugfs_socket_dir != NULL)
74878@@ -1124,7 +1125,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
74879 cf_sk->conn_req.protocol = protocol;
74880 /* Increase the number of sockets created. */
74881 dbfs_atomic_inc(&cnt.caif_nr_socks);
74882- num = dbfs_atomic_inc(&cnt.caif_sock_create);
74883+ num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
74884 #ifdef CONFIG_DEBUG_FS
74885 if (!IS_ERR(debugfsdir)) {
74886
74887diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
74888index 5cf5222..6f704ad 100644
74889--- a/net/caif/cfctrl.c
74890+++ b/net/caif/cfctrl.c
74891@@ -9,6 +9,7 @@
74892 #include <linux/stddef.h>
74893 #include <linux/spinlock.h>
74894 #include <linux/slab.h>
74895+#include <linux/sched.h>
74896 #include <net/caif/caif_layer.h>
74897 #include <net/caif/cfpkt.h>
74898 #include <net/caif/cfctrl.h>
74899@@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
74900 memset(&dev_info, 0, sizeof(dev_info));
74901 dev_info.id = 0xff;
74902 cfsrvl_init(&this->serv, 0, &dev_info, false);
74903- atomic_set(&this->req_seq_no, 1);
74904- atomic_set(&this->rsp_seq_no, 1);
74905+ atomic_set_unchecked(&this->req_seq_no, 1);
74906+ atomic_set_unchecked(&this->rsp_seq_no, 1);
74907 this->serv.layer.receive = cfctrl_recv;
74908 sprintf(this->serv.layer.name, "ctrl");
74909 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
74910@@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
74911 struct cfctrl_request_info *req)
74912 {
74913 spin_lock_bh(&ctrl->info_list_lock);
74914- atomic_inc(&ctrl->req_seq_no);
74915- req->sequence_no = atomic_read(&ctrl->req_seq_no);
74916+ atomic_inc_unchecked(&ctrl->req_seq_no);
74917+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
74918 list_add_tail(&req->list, &ctrl->list);
74919 spin_unlock_bh(&ctrl->info_list_lock);
74920 }
74921@@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
74922 if (p != first)
74923 pr_warn("Requests are not received in order\n");
74924
74925- atomic_set(&ctrl->rsp_seq_no,
74926+ atomic_set_unchecked(&ctrl->rsp_seq_no,
74927 p->sequence_no);
74928 list_del(&p->list);
74929 goto out;
74930diff --git a/net/can/gw.c b/net/can/gw.c
74931index 3d79b12..8de85fa 100644
74932--- a/net/can/gw.c
74933+++ b/net/can/gw.c
74934@@ -96,7 +96,7 @@ struct cf_mod {
74935 struct {
74936 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
74937 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
74938- } csumfunc;
74939+ } __no_const csumfunc;
74940 };
74941
74942
74943diff --git a/net/compat.c b/net/compat.c
74944index 6def90e..c6992fa 100644
74945--- a/net/compat.c
74946+++ b/net/compat.c
74947@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
74948 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
74949 __get_user(kmsg->msg_flags, &umsg->msg_flags))
74950 return -EFAULT;
74951- kmsg->msg_name = compat_ptr(tmp1);
74952- kmsg->msg_iov = compat_ptr(tmp2);
74953- kmsg->msg_control = compat_ptr(tmp3);
74954+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
74955+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
74956+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
74957 return 0;
74958 }
74959
74960@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74961
74962 if (kern_msg->msg_namelen) {
74963 if (mode == VERIFY_READ) {
74964- int err = move_addr_to_kernel(kern_msg->msg_name,
74965+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
74966 kern_msg->msg_namelen,
74967 kern_address);
74968 if (err < 0)
74969@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74970 kern_msg->msg_name = NULL;
74971
74972 tot_len = iov_from_user_compat_to_kern(kern_iov,
74973- (struct compat_iovec __user *)kern_msg->msg_iov,
74974+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
74975 kern_msg->msg_iovlen);
74976 if (tot_len >= 0)
74977 kern_msg->msg_iov = kern_iov;
74978@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74979
74980 #define CMSG_COMPAT_FIRSTHDR(msg) \
74981 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
74982- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
74983+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
74984 (struct compat_cmsghdr __user *)NULL)
74985
74986 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
74987 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
74988 (ucmlen) <= (unsigned long) \
74989 ((mhdr)->msg_controllen - \
74990- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
74991+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
74992
74993 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
74994 struct compat_cmsghdr __user *cmsg, int cmsg_len)
74995 {
74996 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
74997- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
74998+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
74999 msg->msg_controllen)
75000 return NULL;
75001 return (struct compat_cmsghdr __user *)ptr;
75002@@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75003 {
75004 struct compat_timeval ctv;
75005 struct compat_timespec cts[3];
75006- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75007+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75008 struct compat_cmsghdr cmhdr;
75009 int cmlen;
75010
75011@@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75012
75013 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75014 {
75015- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75016+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75017 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75018 int fdnum = scm->fp->count;
75019 struct file **fp = scm->fp->fp;
75020@@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
75021 return -EFAULT;
75022 old_fs = get_fs();
75023 set_fs(KERNEL_DS);
75024- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75025+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75026 set_fs(old_fs);
75027
75028 return err;
75029@@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75030 len = sizeof(ktime);
75031 old_fs = get_fs();
75032 set_fs(KERNEL_DS);
75033- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75034+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75035 set_fs(old_fs);
75036
75037 if (!err) {
75038@@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75039 case MCAST_JOIN_GROUP:
75040 case MCAST_LEAVE_GROUP:
75041 {
75042- struct compat_group_req __user *gr32 = (void *)optval;
75043+ struct compat_group_req __user *gr32 = (void __user *)optval;
75044 struct group_req __user *kgr =
75045 compat_alloc_user_space(sizeof(struct group_req));
75046 u32 interface;
75047@@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75048 case MCAST_BLOCK_SOURCE:
75049 case MCAST_UNBLOCK_SOURCE:
75050 {
75051- struct compat_group_source_req __user *gsr32 = (void *)optval;
75052+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75053 struct group_source_req __user *kgsr = compat_alloc_user_space(
75054 sizeof(struct group_source_req));
75055 u32 interface;
75056@@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75057 }
75058 case MCAST_MSFILTER:
75059 {
75060- struct compat_group_filter __user *gf32 = (void *)optval;
75061+ struct compat_group_filter __user *gf32 = (void __user *)optval;
75062 struct group_filter __user *kgf;
75063 u32 interface, fmode, numsrc;
75064
75065@@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75066 char __user *optval, int __user *optlen,
75067 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75068 {
75069- struct compat_group_filter __user *gf32 = (void *)optval;
75070+ struct compat_group_filter __user *gf32 = (void __user *)optval;
75071 struct group_filter __user *kgf;
75072 int __user *koptlen;
75073 u32 interface, fmode, numsrc;
75074diff --git a/net/core/datagram.c b/net/core/datagram.c
75075index 68bbf9f..5ef0d12 100644
75076--- a/net/core/datagram.c
75077+++ b/net/core/datagram.c
75078@@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75079 }
75080
75081 kfree_skb(skb);
75082- atomic_inc(&sk->sk_drops);
75083+ atomic_inc_unchecked(&sk->sk_drops);
75084 sk_mem_reclaim_partial(sk);
75085
75086 return err;
75087diff --git a/net/core/dev.c b/net/core/dev.c
75088index 0336374..659088a 100644
75089--- a/net/core/dev.c
75090+++ b/net/core/dev.c
75091@@ -1138,10 +1138,14 @@ void dev_load(struct net *net, const char *name)
75092 if (no_module && capable(CAP_NET_ADMIN))
75093 no_module = request_module("netdev-%s", name);
75094 if (no_module && capable(CAP_SYS_MODULE)) {
75095+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75096+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
75097+#else
75098 if (!request_module("%s", name))
75099 pr_err("Loading kernel module for a network device "
75100 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
75101 "instead\n", name);
75102+#endif
75103 }
75104 }
75105 EXPORT_SYMBOL(dev_load);
75106@@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75107 {
75108 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75109 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75110- atomic_long_inc(&dev->rx_dropped);
75111+ atomic_long_inc_unchecked(&dev->rx_dropped);
75112 kfree_skb(skb);
75113 return NET_RX_DROP;
75114 }
75115@@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75116 nf_reset(skb);
75117
75118 if (unlikely(!is_skb_forwardable(dev, skb))) {
75119- atomic_long_inc(&dev->rx_dropped);
75120+ atomic_long_inc_unchecked(&dev->rx_dropped);
75121 kfree_skb(skb);
75122 return NET_RX_DROP;
75123 }
75124@@ -2077,7 +2081,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75125
75126 struct dev_gso_cb {
75127 void (*destructor)(struct sk_buff *skb);
75128-};
75129+} __no_const;
75130
75131 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75132
75133@@ -2933,7 +2937,7 @@ enqueue:
75134
75135 local_irq_restore(flags);
75136
75137- atomic_long_inc(&skb->dev->rx_dropped);
75138+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75139 kfree_skb(skb);
75140 return NET_RX_DROP;
75141 }
75142@@ -3005,7 +3009,7 @@ int netif_rx_ni(struct sk_buff *skb)
75143 }
75144 EXPORT_SYMBOL(netif_rx_ni);
75145
75146-static void net_tx_action(struct softirq_action *h)
75147+static void net_tx_action(void)
75148 {
75149 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75150
75151@@ -3293,7 +3297,7 @@ ncls:
75152 if (pt_prev) {
75153 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75154 } else {
75155- atomic_long_inc(&skb->dev->rx_dropped);
75156+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75157 kfree_skb(skb);
75158 /* Jamal, now you will not able to escape explaining
75159 * me how you were going to use this. :-)
75160@@ -3853,7 +3857,7 @@ void netif_napi_del(struct napi_struct *napi)
75161 }
75162 EXPORT_SYMBOL(netif_napi_del);
75163
75164-static void net_rx_action(struct softirq_action *h)
75165+static void net_rx_action(void)
75166 {
75167 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75168 unsigned long time_limit = jiffies + 2;
75169@@ -5878,7 +5882,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75170 } else {
75171 netdev_stats_to_stats64(storage, &dev->stats);
75172 }
75173- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75174+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75175 return storage;
75176 }
75177 EXPORT_SYMBOL(dev_get_stats);
75178diff --git a/net/core/flow.c b/net/core/flow.c
75179index e318c7e..168b1d0 100644
75180--- a/net/core/flow.c
75181+++ b/net/core/flow.c
75182@@ -61,7 +61,7 @@ struct flow_cache {
75183 struct timer_list rnd_timer;
75184 };
75185
75186-atomic_t flow_cache_genid = ATOMIC_INIT(0);
75187+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75188 EXPORT_SYMBOL(flow_cache_genid);
75189 static struct flow_cache flow_cache_global;
75190 static struct kmem_cache *flow_cachep __read_mostly;
75191@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75192
75193 static int flow_entry_valid(struct flow_cache_entry *fle)
75194 {
75195- if (atomic_read(&flow_cache_genid) != fle->genid)
75196+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75197 return 0;
75198 if (fle->object && !fle->object->ops->check(fle->object))
75199 return 0;
75200@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75201 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75202 fcp->hash_count++;
75203 }
75204- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75205+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75206 flo = fle->object;
75207 if (!flo)
75208 goto ret_object;
75209@@ -280,7 +280,7 @@ nocache:
75210 }
75211 flo = resolver(net, key, family, dir, flo, ctx);
75212 if (fle) {
75213- fle->genid = atomic_read(&flow_cache_genid);
75214+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
75215 if (!IS_ERR(flo))
75216 fle->object = flo;
75217 else
75218diff --git a/net/core/iovec.c b/net/core/iovec.c
75219index c40f27e..7f49254 100644
75220--- a/net/core/iovec.c
75221+++ b/net/core/iovec.c
75222@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75223 if (m->msg_namelen) {
75224 if (mode == VERIFY_READ) {
75225 void __user *namep;
75226- namep = (void __user __force *) m->msg_name;
75227+ namep = (void __force_user *) m->msg_name;
75228 err = move_addr_to_kernel(namep, m->msg_namelen,
75229 address);
75230 if (err < 0)
75231@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75232 }
75233
75234 size = m->msg_iovlen * sizeof(struct iovec);
75235- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75236+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75237 return -EFAULT;
75238
75239 m->msg_iov = iov;
75240diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75241index 5c30296..ebe7b61 100644
75242--- a/net/core/rtnetlink.c
75243+++ b/net/core/rtnetlink.c
75244@@ -57,7 +57,7 @@ struct rtnl_link {
75245 rtnl_doit_func doit;
75246 rtnl_dumpit_func dumpit;
75247 rtnl_calcit_func calcit;
75248-};
75249+} __no_const;
75250
75251 static DEFINE_MUTEX(rtnl_mutex);
75252
75253diff --git a/net/core/scm.c b/net/core/scm.c
75254index ff52ad0..aff1c0f 100644
75255--- a/net/core/scm.c
75256+++ b/net/core/scm.c
75257@@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
75258 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75259 {
75260 struct cmsghdr __user *cm
75261- = (__force struct cmsghdr __user *)msg->msg_control;
75262+ = (struct cmsghdr __force_user *)msg->msg_control;
75263 struct cmsghdr cmhdr;
75264 int cmlen = CMSG_LEN(len);
75265 int err;
75266@@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75267 err = -EFAULT;
75268 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75269 goto out;
75270- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75271+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75272 goto out;
75273 cmlen = CMSG_SPACE(len);
75274 if (msg->msg_controllen < cmlen)
75275@@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
75276 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75277 {
75278 struct cmsghdr __user *cm
75279- = (__force struct cmsghdr __user*)msg->msg_control;
75280+ = (struct cmsghdr __force_user *)msg->msg_control;
75281
75282 int fdmax = 0;
75283 int fdnum = scm->fp->count;
75284@@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75285 if (fdnum < fdmax)
75286 fdmax = fdnum;
75287
75288- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75289+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75290 i++, cmfptr++)
75291 {
75292 int new_fd;
75293diff --git a/net/core/sock.c b/net/core/sock.c
75294index 02f8dfe..86dfd4a 100644
75295--- a/net/core/sock.c
75296+++ b/net/core/sock.c
75297@@ -341,7 +341,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75298 struct sk_buff_head *list = &sk->sk_receive_queue;
75299
75300 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75301- atomic_inc(&sk->sk_drops);
75302+ atomic_inc_unchecked(&sk->sk_drops);
75303 trace_sock_rcvqueue_full(sk, skb);
75304 return -ENOMEM;
75305 }
75306@@ -351,7 +351,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75307 return err;
75308
75309 if (!sk_rmem_schedule(sk, skb->truesize)) {
75310- atomic_inc(&sk->sk_drops);
75311+ atomic_inc_unchecked(&sk->sk_drops);
75312 return -ENOBUFS;
75313 }
75314
75315@@ -371,7 +371,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75316 skb_dst_force(skb);
75317
75318 spin_lock_irqsave(&list->lock, flags);
75319- skb->dropcount = atomic_read(&sk->sk_drops);
75320+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75321 __skb_queue_tail(list, skb);
75322 spin_unlock_irqrestore(&list->lock, flags);
75323
75324@@ -391,7 +391,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75325 skb->dev = NULL;
75326
75327 if (sk_rcvqueues_full(sk, skb)) {
75328- atomic_inc(&sk->sk_drops);
75329+ atomic_inc_unchecked(&sk->sk_drops);
75330 goto discard_and_relse;
75331 }
75332 if (nested)
75333@@ -409,7 +409,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75334 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75335 } else if (sk_add_backlog(sk, skb)) {
75336 bh_unlock_sock(sk);
75337- atomic_inc(&sk->sk_drops);
75338+ atomic_inc_unchecked(&sk->sk_drops);
75339 goto discard_and_relse;
75340 }
75341
75342@@ -974,7 +974,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75343 if (len > sizeof(peercred))
75344 len = sizeof(peercred);
75345 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75346- if (copy_to_user(optval, &peercred, len))
75347+ if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75348 return -EFAULT;
75349 goto lenout;
75350 }
75351@@ -987,7 +987,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75352 return -ENOTCONN;
75353 if (lv < len)
75354 return -EINVAL;
75355- if (copy_to_user(optval, address, len))
75356+ if (len > sizeof(address) || copy_to_user(optval, address, len))
75357 return -EFAULT;
75358 goto lenout;
75359 }
75360@@ -1024,7 +1024,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75361
75362 if (len > lv)
75363 len = lv;
75364- if (copy_to_user(optval, &v, len))
75365+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
75366 return -EFAULT;
75367 lenout:
75368 if (put_user(len, optlen))
75369@@ -2108,7 +2108,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75370 */
75371 smp_wmb();
75372 atomic_set(&sk->sk_refcnt, 1);
75373- atomic_set(&sk->sk_drops, 0);
75374+ atomic_set_unchecked(&sk->sk_drops, 0);
75375 }
75376 EXPORT_SYMBOL(sock_init_data);
75377
75378diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
75379index b9868e1..849f809 100644
75380--- a/net/core/sock_diag.c
75381+++ b/net/core/sock_diag.c
75382@@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
75383
75384 int sock_diag_check_cookie(void *sk, __u32 *cookie)
75385 {
75386+#ifndef CONFIG_GRKERNSEC_HIDESYM
75387 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
75388 cookie[1] != INET_DIAG_NOCOOKIE) &&
75389 ((u32)(unsigned long)sk != cookie[0] ||
75390 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
75391 return -ESTALE;
75392 else
75393+#endif
75394 return 0;
75395 }
75396 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
75397
75398 void sock_diag_save_cookie(void *sk, __u32 *cookie)
75399 {
75400+#ifdef CONFIG_GRKERNSEC_HIDESYM
75401+ cookie[0] = 0;
75402+ cookie[1] = 0;
75403+#else
75404 cookie[0] = (u32)(unsigned long)sk;
75405 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75406+#endif
75407 }
75408 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
75409
75410diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75411index 02e75d1..9a57a7c 100644
75412--- a/net/decnet/sysctl_net_decnet.c
75413+++ b/net/decnet/sysctl_net_decnet.c
75414@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75415
75416 if (len > *lenp) len = *lenp;
75417
75418- if (copy_to_user(buffer, addr, len))
75419+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
75420 return -EFAULT;
75421
75422 *lenp = len;
75423@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75424
75425 if (len > *lenp) len = *lenp;
75426
75427- if (copy_to_user(buffer, devname, len))
75428+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
75429 return -EFAULT;
75430
75431 *lenp = len;
75432diff --git a/net/econet/Kconfig b/net/econet/Kconfig
75433index 39a2d29..f39c0fe 100644
75434--- a/net/econet/Kconfig
75435+++ b/net/econet/Kconfig
75436@@ -4,7 +4,7 @@
75437
75438 config ECONET
75439 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
75440- depends on EXPERIMENTAL && INET
75441+ depends on EXPERIMENTAL && INET && BROKEN
75442 ---help---
75443 Econet is a fairly old and slow networking protocol mainly used by
75444 Acorn computers to access file and print servers. It uses native
75445diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75446index 92fc5f6..b790d91 100644
75447--- a/net/ipv4/fib_frontend.c
75448+++ b/net/ipv4/fib_frontend.c
75449@@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75450 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75451 fib_sync_up(dev);
75452 #endif
75453- atomic_inc(&net->ipv4.dev_addr_genid);
75454+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75455 rt_cache_flush(dev_net(dev), -1);
75456 break;
75457 case NETDEV_DOWN:
75458 fib_del_ifaddr(ifa, NULL);
75459- atomic_inc(&net->ipv4.dev_addr_genid);
75460+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75461 if (ifa->ifa_dev->ifa_list == NULL) {
75462 /* Last address was deleted from this interface.
75463 * Disable IP.
75464@@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75465 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75466 fib_sync_up(dev);
75467 #endif
75468- atomic_inc(&net->ipv4.dev_addr_genid);
75469+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75470 rt_cache_flush(dev_net(dev), -1);
75471 break;
75472 case NETDEV_DOWN:
75473diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75474index 80106d8..232e898 100644
75475--- a/net/ipv4/fib_semantics.c
75476+++ b/net/ipv4/fib_semantics.c
75477@@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75478 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75479 nh->nh_gw,
75480 nh->nh_parent->fib_scope);
75481- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75482+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75483
75484 return nh->nh_saddr;
75485 }
75486diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75487index 984ec65..97ac518 100644
75488--- a/net/ipv4/inet_hashtables.c
75489+++ b/net/ipv4/inet_hashtables.c
75490@@ -18,12 +18,15 @@
75491 #include <linux/sched.h>
75492 #include <linux/slab.h>
75493 #include <linux/wait.h>
75494+#include <linux/security.h>
75495
75496 #include <net/inet_connection_sock.h>
75497 #include <net/inet_hashtables.h>
75498 #include <net/secure_seq.h>
75499 #include <net/ip.h>
75500
75501+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75502+
75503 /*
75504 * Allocate and initialize a new local port bind bucket.
75505 * The bindhash mutex for snum's hash chain must be held here.
75506@@ -530,6 +533,8 @@ ok:
75507 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75508 spin_unlock(&head->lock);
75509
75510+ gr_update_task_in_ip_table(current, inet_sk(sk));
75511+
75512 if (tw) {
75513 inet_twsk_deschedule(tw, death_row);
75514 while (twrefcnt) {
75515diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75516index d4d61b6..b81aec8 100644
75517--- a/net/ipv4/inetpeer.c
75518+++ b/net/ipv4/inetpeer.c
75519@@ -487,8 +487,8 @@ relookup:
75520 if (p) {
75521 p->daddr = *daddr;
75522 atomic_set(&p->refcnt, 1);
75523- atomic_set(&p->rid, 0);
75524- atomic_set(&p->ip_id_count,
75525+ atomic_set_unchecked(&p->rid, 0);
75526+ atomic_set_unchecked(&p->ip_id_count,
75527 (daddr->family == AF_INET) ?
75528 secure_ip_id(daddr->addr.a4) :
75529 secure_ipv6_id(daddr->addr.a6));
75530diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75531index 1f23a57..7180dfe 100644
75532--- a/net/ipv4/ip_fragment.c
75533+++ b/net/ipv4/ip_fragment.c
75534@@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75535 return 0;
75536
75537 start = qp->rid;
75538- end = atomic_inc_return(&peer->rid);
75539+ end = atomic_inc_return_unchecked(&peer->rid);
75540 qp->rid = end;
75541
75542 rc = qp->q.fragments && (end - start) > max;
75543diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75544index 8aa87c1..35c3248 100644
75545--- a/net/ipv4/ip_sockglue.c
75546+++ b/net/ipv4/ip_sockglue.c
75547@@ -1112,7 +1112,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75548 len = min_t(unsigned int, len, opt->optlen);
75549 if (put_user(len, optlen))
75550 return -EFAULT;
75551- if (copy_to_user(optval, opt->__data, len))
75552+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75553+ copy_to_user(optval, opt->__data, len))
75554 return -EFAULT;
75555 return 0;
75556 }
75557@@ -1240,7 +1241,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75558 if (sk->sk_type != SOCK_STREAM)
75559 return -ENOPROTOOPT;
75560
75561- msg.msg_control = optval;
75562+ msg.msg_control = (void __force_kernel *)optval;
75563 msg.msg_controllen = len;
75564 msg.msg_flags = flags;
75565
75566diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75567index 6e412a6..6640538 100644
75568--- a/net/ipv4/ipconfig.c
75569+++ b/net/ipv4/ipconfig.c
75570@@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75571
75572 mm_segment_t oldfs = get_fs();
75573 set_fs(get_ds());
75574- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75575+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75576 set_fs(oldfs);
75577 return res;
75578 }
75579@@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
75580
75581 mm_segment_t oldfs = get_fs();
75582 set_fs(get_ds());
75583- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75584+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75585 set_fs(oldfs);
75586 return res;
75587 }
75588@@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
75589
75590 mm_segment_t oldfs = get_fs();
75591 set_fs(get_ds());
75592- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
75593+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
75594 set_fs(oldfs);
75595 return res;
75596 }
75597diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
75598index b072386..abdebcf 100644
75599--- a/net/ipv4/ping.c
75600+++ b/net/ipv4/ping.c
75601@@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
75602 sk_rmem_alloc_get(sp),
75603 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75604 atomic_read(&sp->sk_refcnt), sp,
75605- atomic_read(&sp->sk_drops), len);
75606+ atomic_read_unchecked(&sp->sk_drops), len);
75607 }
75608
75609 static int ping_seq_show(struct seq_file *seq, void *v)
75610diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
75611index 3ccda5a..3c1e61d 100644
75612--- a/net/ipv4/raw.c
75613+++ b/net/ipv4/raw.c
75614@@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
75615 int raw_rcv(struct sock *sk, struct sk_buff *skb)
75616 {
75617 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
75618- atomic_inc(&sk->sk_drops);
75619+ atomic_inc_unchecked(&sk->sk_drops);
75620 kfree_skb(skb);
75621 return NET_RX_DROP;
75622 }
75623@@ -742,16 +742,20 @@ static int raw_init(struct sock *sk)
75624
75625 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
75626 {
75627+ struct icmp_filter filter;
75628+
75629 if (optlen > sizeof(struct icmp_filter))
75630 optlen = sizeof(struct icmp_filter);
75631- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
75632+ if (copy_from_user(&filter, optval, optlen))
75633 return -EFAULT;
75634+ raw_sk(sk)->filter = filter;
75635 return 0;
75636 }
75637
75638 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
75639 {
75640 int len, ret = -EFAULT;
75641+ struct icmp_filter filter;
75642
75643 if (get_user(len, optlen))
75644 goto out;
75645@@ -761,8 +765,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
75646 if (len > sizeof(struct icmp_filter))
75647 len = sizeof(struct icmp_filter);
75648 ret = -EFAULT;
75649- if (put_user(len, optlen) ||
75650- copy_to_user(optval, &raw_sk(sk)->filter, len))
75651+ filter = raw_sk(sk)->filter;
75652+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
75653 goto out;
75654 ret = 0;
75655 out: return ret;
75656@@ -990,7 +994,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75657 sk_wmem_alloc_get(sp),
75658 sk_rmem_alloc_get(sp),
75659 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75660- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75661+ atomic_read(&sp->sk_refcnt),
75662+#ifdef CONFIG_GRKERNSEC_HIDESYM
75663+ NULL,
75664+#else
75665+ sp,
75666+#endif
75667+ atomic_read_unchecked(&sp->sk_drops));
75668 }
75669
75670 static int raw_seq_show(struct seq_file *seq, void *v)
75671diff --git a/net/ipv4/route.c b/net/ipv4/route.c
75672index 0197747..7adb0dc 100644
75673--- a/net/ipv4/route.c
75674+++ b/net/ipv4/route.c
75675@@ -311,7 +311,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
75676
75677 static inline int rt_genid(struct net *net)
75678 {
75679- return atomic_read(&net->ipv4.rt_genid);
75680+ return atomic_read_unchecked(&net->ipv4.rt_genid);
75681 }
75682
75683 #ifdef CONFIG_PROC_FS
75684@@ -935,7 +935,7 @@ static void rt_cache_invalidate(struct net *net)
75685 unsigned char shuffle;
75686
75687 get_random_bytes(&shuffle, sizeof(shuffle));
75688- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
75689+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
75690 inetpeer_invalidate_tree(AF_INET);
75691 }
75692
75693@@ -3010,7 +3010,7 @@ static int rt_fill_info(struct net *net,
75694 error = rt->dst.error;
75695 if (peer) {
75696 inet_peer_refcheck(rt->peer);
75697- id = atomic_read(&peer->ip_id_count) & 0xffff;
75698+ id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
75699 if (peer->tcp_ts_stamp) {
75700 ts = peer->tcp_ts;
75701 tsage = get_seconds() - peer->tcp_ts_stamp;
75702diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
75703index fd54c5f..96d6407 100644
75704--- a/net/ipv4/tcp_ipv4.c
75705+++ b/net/ipv4/tcp_ipv4.c
75706@@ -88,6 +88,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
75707 int sysctl_tcp_low_latency __read_mostly;
75708 EXPORT_SYMBOL(sysctl_tcp_low_latency);
75709
75710+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75711+extern int grsec_enable_blackhole;
75712+#endif
75713
75714 #ifdef CONFIG_TCP_MD5SIG
75715 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
75716@@ -1638,6 +1641,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
75717 return 0;
75718
75719 reset:
75720+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75721+ if (!grsec_enable_blackhole)
75722+#endif
75723 tcp_v4_send_reset(rsk, skb);
75724 discard:
75725 kfree_skb(skb);
75726@@ -1700,12 +1706,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
75727 TCP_SKB_CB(skb)->sacked = 0;
75728
75729 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75730- if (!sk)
75731+ if (!sk) {
75732+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75733+ ret = 1;
75734+#endif
75735 goto no_tcp_socket;
75736-
75737+ }
75738 process:
75739- if (sk->sk_state == TCP_TIME_WAIT)
75740+ if (sk->sk_state == TCP_TIME_WAIT) {
75741+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75742+ ret = 2;
75743+#endif
75744 goto do_time_wait;
75745+ }
75746
75747 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
75748 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75749@@ -1755,6 +1768,10 @@ no_tcp_socket:
75750 bad_packet:
75751 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75752 } else {
75753+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75754+ if (!grsec_enable_blackhole || (ret == 1 &&
75755+ (skb->dev->flags & IFF_LOOPBACK)))
75756+#endif
75757 tcp_v4_send_reset(NULL, skb);
75758 }
75759
75760@@ -2417,7 +2434,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
75761 0, /* non standard timer */
75762 0, /* open_requests have no inode */
75763 atomic_read(&sk->sk_refcnt),
75764+#ifdef CONFIG_GRKERNSEC_HIDESYM
75765+ NULL,
75766+#else
75767 req,
75768+#endif
75769 len);
75770 }
75771
75772@@ -2467,7 +2488,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
75773 sock_i_uid(sk),
75774 icsk->icsk_probes_out,
75775 sock_i_ino(sk),
75776- atomic_read(&sk->sk_refcnt), sk,
75777+ atomic_read(&sk->sk_refcnt),
75778+#ifdef CONFIG_GRKERNSEC_HIDESYM
75779+ NULL,
75780+#else
75781+ sk,
75782+#endif
75783 jiffies_to_clock_t(icsk->icsk_rto),
75784 jiffies_to_clock_t(icsk->icsk_ack.ato),
75785 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
75786@@ -2495,7 +2521,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
75787 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
75788 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
75789 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75790- atomic_read(&tw->tw_refcnt), tw, len);
75791+ atomic_read(&tw->tw_refcnt),
75792+#ifdef CONFIG_GRKERNSEC_HIDESYM
75793+ NULL,
75794+#else
75795+ tw,
75796+#endif
75797+ len);
75798 }
75799
75800 #define TMPSZ 150
75801diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
75802index 550e755..25721b3 100644
75803--- a/net/ipv4/tcp_minisocks.c
75804+++ b/net/ipv4/tcp_minisocks.c
75805@@ -27,6 +27,10 @@
75806 #include <net/inet_common.h>
75807 #include <net/xfrm.h>
75808
75809+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75810+extern int grsec_enable_blackhole;
75811+#endif
75812+
75813 int sysctl_tcp_syncookies __read_mostly = 1;
75814 EXPORT_SYMBOL(sysctl_tcp_syncookies);
75815
75816@@ -753,6 +757,10 @@ listen_overflow:
75817
75818 embryonic_reset:
75819 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
75820+
75821+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75822+ if (!grsec_enable_blackhole)
75823+#endif
75824 if (!(flg & TCP_FLAG_RST))
75825 req->rsk_ops->send_reset(sk, skb);
75826
75827diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
75828index 85ee7eb..53277ab 100644
75829--- a/net/ipv4/tcp_probe.c
75830+++ b/net/ipv4/tcp_probe.c
75831@@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
75832 if (cnt + width >= len)
75833 break;
75834
75835- if (copy_to_user(buf + cnt, tbuf, width))
75836+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
75837 return -EFAULT;
75838 cnt += width;
75839 }
75840diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
75841index cd2e072..1fffee2 100644
75842--- a/net/ipv4/tcp_timer.c
75843+++ b/net/ipv4/tcp_timer.c
75844@@ -22,6 +22,10 @@
75845 #include <linux/gfp.h>
75846 #include <net/tcp.h>
75847
75848+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75849+extern int grsec_lastack_retries;
75850+#endif
75851+
75852 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
75853 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
75854 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
75855@@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
75856 }
75857 }
75858
75859+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75860+ if ((sk->sk_state == TCP_LAST_ACK) &&
75861+ (grsec_lastack_retries > 0) &&
75862+ (grsec_lastack_retries < retry_until))
75863+ retry_until = grsec_lastack_retries;
75864+#endif
75865+
75866 if (retransmits_timed_out(sk, retry_until,
75867 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
75868 /* Has it gone just too far? */
75869diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
75870index 5d075b5..d907d5f 100644
75871--- a/net/ipv4/udp.c
75872+++ b/net/ipv4/udp.c
75873@@ -86,6 +86,7 @@
75874 #include <linux/types.h>
75875 #include <linux/fcntl.h>
75876 #include <linux/module.h>
75877+#include <linux/security.h>
75878 #include <linux/socket.h>
75879 #include <linux/sockios.h>
75880 #include <linux/igmp.h>
75881@@ -108,6 +109,10 @@
75882 #include <trace/events/udp.h>
75883 #include "udp_impl.h"
75884
75885+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75886+extern int grsec_enable_blackhole;
75887+#endif
75888+
75889 struct udp_table udp_table __read_mostly;
75890 EXPORT_SYMBOL(udp_table);
75891
75892@@ -566,6 +571,9 @@ found:
75893 return s;
75894 }
75895
75896+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
75897+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
75898+
75899 /*
75900 * This routine is called by the ICMP module when it gets some
75901 * sort of error condition. If err < 0 then the socket should
75902@@ -857,9 +865,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
75903 dport = usin->sin_port;
75904 if (dport == 0)
75905 return -EINVAL;
75906+
75907+ err = gr_search_udp_sendmsg(sk, usin);
75908+ if (err)
75909+ return err;
75910 } else {
75911 if (sk->sk_state != TCP_ESTABLISHED)
75912 return -EDESTADDRREQ;
75913+
75914+ err = gr_search_udp_sendmsg(sk, NULL);
75915+ if (err)
75916+ return err;
75917+
75918 daddr = inet->inet_daddr;
75919 dport = inet->inet_dport;
75920 /* Open fast path for connected socket.
75921@@ -1100,7 +1117,7 @@ static unsigned int first_packet_length(struct sock *sk)
75922 udp_lib_checksum_complete(skb)) {
75923 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75924 IS_UDPLITE(sk));
75925- atomic_inc(&sk->sk_drops);
75926+ atomic_inc_unchecked(&sk->sk_drops);
75927 __skb_unlink(skb, rcvq);
75928 __skb_queue_tail(&list_kill, skb);
75929 }
75930@@ -1186,6 +1203,10 @@ try_again:
75931 if (!skb)
75932 goto out;
75933
75934+ err = gr_search_udp_recvmsg(sk, skb);
75935+ if (err)
75936+ goto out_free;
75937+
75938 ulen = skb->len - sizeof(struct udphdr);
75939 copied = len;
75940 if (copied > ulen)
75941@@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75942
75943 drop:
75944 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75945- atomic_inc(&sk->sk_drops);
75946+ atomic_inc_unchecked(&sk->sk_drops);
75947 kfree_skb(skb);
75948 return -1;
75949 }
75950@@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75951 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
75952
75953 if (!skb1) {
75954- atomic_inc(&sk->sk_drops);
75955+ atomic_inc_unchecked(&sk->sk_drops);
75956 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
75957 IS_UDPLITE(sk));
75958 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75959@@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75960 goto csum_error;
75961
75962 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
75963+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75964+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75965+#endif
75966 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
75967
75968 /*
75969@@ -2100,8 +2124,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
75970 sk_wmem_alloc_get(sp),
75971 sk_rmem_alloc_get(sp),
75972 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75973- atomic_read(&sp->sk_refcnt), sp,
75974- atomic_read(&sp->sk_drops), len);
75975+ atomic_read(&sp->sk_refcnt),
75976+#ifdef CONFIG_GRKERNSEC_HIDESYM
75977+ NULL,
75978+#else
75979+ sp,
75980+#endif
75981+ atomic_read_unchecked(&sp->sk_drops), len);
75982 }
75983
75984 int udp4_seq_show(struct seq_file *seq, void *v)
75985diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
75986index 6b8ebc5..1d624f4 100644
75987--- a/net/ipv6/addrconf.c
75988+++ b/net/ipv6/addrconf.c
75989@@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
75990 p.iph.ihl = 5;
75991 p.iph.protocol = IPPROTO_IPV6;
75992 p.iph.ttl = 64;
75993- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
75994+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
75995
75996 if (ops->ndo_do_ioctl) {
75997 mm_segment_t oldfs = get_fs();
75998diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
75999index 02dd203..e03fcc9 100644
76000--- a/net/ipv6/inet6_connection_sock.c
76001+++ b/net/ipv6/inet6_connection_sock.c
76002@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76003 #ifdef CONFIG_XFRM
76004 {
76005 struct rt6_info *rt = (struct rt6_info *)dst;
76006- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76007+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76008 }
76009 #endif
76010 }
76011@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76012 #ifdef CONFIG_XFRM
76013 if (dst) {
76014 struct rt6_info *rt = (struct rt6_info *)dst;
76015- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76016+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76017 __sk_dst_reset(sk);
76018 dst = NULL;
76019 }
76020diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76021index 18a2719..779f36a 100644
76022--- a/net/ipv6/ipv6_sockglue.c
76023+++ b/net/ipv6/ipv6_sockglue.c
76024@@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76025 if (sk->sk_type != SOCK_STREAM)
76026 return -ENOPROTOOPT;
76027
76028- msg.msg_control = optval;
76029+ msg.msg_control = (void __force_kernel *)optval;
76030 msg.msg_controllen = len;
76031 msg.msg_flags = flags;
76032
76033diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76034index d02f7e4..2d2a0f1 100644
76035--- a/net/ipv6/raw.c
76036+++ b/net/ipv6/raw.c
76037@@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76038 {
76039 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76040 skb_checksum_complete(skb)) {
76041- atomic_inc(&sk->sk_drops);
76042+ atomic_inc_unchecked(&sk->sk_drops);
76043 kfree_skb(skb);
76044 return NET_RX_DROP;
76045 }
76046@@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76047 struct raw6_sock *rp = raw6_sk(sk);
76048
76049 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76050- atomic_inc(&sk->sk_drops);
76051+ atomic_inc_unchecked(&sk->sk_drops);
76052 kfree_skb(skb);
76053 return NET_RX_DROP;
76054 }
76055@@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76056
76057 if (inet->hdrincl) {
76058 if (skb_checksum_complete(skb)) {
76059- atomic_inc(&sk->sk_drops);
76060+ atomic_inc_unchecked(&sk->sk_drops);
76061 kfree_skb(skb);
76062 return NET_RX_DROP;
76063 }
76064@@ -602,7 +602,7 @@ out:
76065 return err;
76066 }
76067
76068-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76069+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76070 struct flowi6 *fl6, struct dst_entry **dstp,
76071 unsigned int flags)
76072 {
76073@@ -912,12 +912,15 @@ do_confirm:
76074 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76075 char __user *optval, int optlen)
76076 {
76077+ struct icmp6_filter filter;
76078+
76079 switch (optname) {
76080 case ICMPV6_FILTER:
76081 if (optlen > sizeof(struct icmp6_filter))
76082 optlen = sizeof(struct icmp6_filter);
76083- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76084+ if (copy_from_user(&filter, optval, optlen))
76085 return -EFAULT;
76086+ raw6_sk(sk)->filter = filter;
76087 return 0;
76088 default:
76089 return -ENOPROTOOPT;
76090@@ -930,6 +933,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76091 char __user *optval, int __user *optlen)
76092 {
76093 int len;
76094+ struct icmp6_filter filter;
76095
76096 switch (optname) {
76097 case ICMPV6_FILTER:
76098@@ -941,7 +945,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76099 len = sizeof(struct icmp6_filter);
76100 if (put_user(len, optlen))
76101 return -EFAULT;
76102- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76103+ filter = raw6_sk(sk)->filter;
76104+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
76105 return -EFAULT;
76106 return 0;
76107 default:
76108@@ -1248,7 +1253,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76109 0, 0L, 0,
76110 sock_i_uid(sp), 0,
76111 sock_i_ino(sp),
76112- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76113+ atomic_read(&sp->sk_refcnt),
76114+#ifdef CONFIG_GRKERNSEC_HIDESYM
76115+ NULL,
76116+#else
76117+ sp,
76118+#endif
76119+ atomic_read_unchecked(&sp->sk_drops));
76120 }
76121
76122 static int raw6_seq_show(struct seq_file *seq, void *v)
76123diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76124index a89ca8d..12e66b0 100644
76125--- a/net/ipv6/tcp_ipv6.c
76126+++ b/net/ipv6/tcp_ipv6.c
76127@@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76128 }
76129 #endif
76130
76131+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76132+extern int grsec_enable_blackhole;
76133+#endif
76134+
76135 static void tcp_v6_hash(struct sock *sk)
76136 {
76137 if (sk->sk_state != TCP_CLOSE) {
76138@@ -1654,6 +1658,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76139 return 0;
76140
76141 reset:
76142+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76143+ if (!grsec_enable_blackhole)
76144+#endif
76145 tcp_v6_send_reset(sk, skb);
76146 discard:
76147 if (opt_skb)
76148@@ -1733,12 +1740,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76149 TCP_SKB_CB(skb)->sacked = 0;
76150
76151 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76152- if (!sk)
76153+ if (!sk) {
76154+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76155+ ret = 1;
76156+#endif
76157 goto no_tcp_socket;
76158+ }
76159
76160 process:
76161- if (sk->sk_state == TCP_TIME_WAIT)
76162+ if (sk->sk_state == TCP_TIME_WAIT) {
76163+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76164+ ret = 2;
76165+#endif
76166 goto do_time_wait;
76167+ }
76168
76169 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76170 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76171@@ -1786,6 +1801,10 @@ no_tcp_socket:
76172 bad_packet:
76173 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76174 } else {
76175+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76176+ if (!grsec_enable_blackhole || (ret == 1 &&
76177+ (skb->dev->flags & IFF_LOOPBACK)))
76178+#endif
76179 tcp_v6_send_reset(NULL, skb);
76180 }
76181
76182@@ -2047,7 +2066,13 @@ static void get_openreq6(struct seq_file *seq,
76183 uid,
76184 0, /* non standard timer */
76185 0, /* open_requests have no inode */
76186- 0, req);
76187+ 0,
76188+#ifdef CONFIG_GRKERNSEC_HIDESYM
76189+ NULL
76190+#else
76191+ req
76192+#endif
76193+ );
76194 }
76195
76196 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76197@@ -2097,7 +2122,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76198 sock_i_uid(sp),
76199 icsk->icsk_probes_out,
76200 sock_i_ino(sp),
76201- atomic_read(&sp->sk_refcnt), sp,
76202+ atomic_read(&sp->sk_refcnt),
76203+#ifdef CONFIG_GRKERNSEC_HIDESYM
76204+ NULL,
76205+#else
76206+ sp,
76207+#endif
76208 jiffies_to_clock_t(icsk->icsk_rto),
76209 jiffies_to_clock_t(icsk->icsk_ack.ato),
76210 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76211@@ -2132,7 +2162,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76212 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76213 tw->tw_substate, 0, 0,
76214 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76215- atomic_read(&tw->tw_refcnt), tw);
76216+ atomic_read(&tw->tw_refcnt),
76217+#ifdef CONFIG_GRKERNSEC_HIDESYM
76218+ NULL
76219+#else
76220+ tw
76221+#endif
76222+ );
76223 }
76224
76225 static int tcp6_seq_show(struct seq_file *seq, void *v)
76226diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76227index 4f96b5c..75543d7 100644
76228--- a/net/ipv6/udp.c
76229+++ b/net/ipv6/udp.c
76230@@ -50,6 +50,10 @@
76231 #include <linux/seq_file.h>
76232 #include "udp_impl.h"
76233
76234+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76235+extern int grsec_enable_blackhole;
76236+#endif
76237+
76238 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76239 {
76240 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76241@@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
76242
76243 return 0;
76244 drop:
76245- atomic_inc(&sk->sk_drops);
76246+ atomic_inc_unchecked(&sk->sk_drops);
76247 drop_no_sk_drops_inc:
76248 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76249 kfree_skb(skb);
76250@@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76251 continue;
76252 }
76253 drop:
76254- atomic_inc(&sk->sk_drops);
76255+ atomic_inc_unchecked(&sk->sk_drops);
76256 UDP6_INC_STATS_BH(sock_net(sk),
76257 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
76258 UDP6_INC_STATS_BH(sock_net(sk),
76259@@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76260 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76261 proto == IPPROTO_UDPLITE);
76262
76263+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76264+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76265+#endif
76266 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76267
76268 kfree_skb(skb);
76269@@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76270 if (!sock_owned_by_user(sk))
76271 udpv6_queue_rcv_skb(sk, skb);
76272 else if (sk_add_backlog(sk, skb)) {
76273- atomic_inc(&sk->sk_drops);
76274+ atomic_inc_unchecked(&sk->sk_drops);
76275 bh_unlock_sock(sk);
76276 sock_put(sk);
76277 goto discard;
76278@@ -1410,8 +1417,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76279 0, 0L, 0,
76280 sock_i_uid(sp), 0,
76281 sock_i_ino(sp),
76282- atomic_read(&sp->sk_refcnt), sp,
76283- atomic_read(&sp->sk_drops));
76284+ atomic_read(&sp->sk_refcnt),
76285+#ifdef CONFIG_GRKERNSEC_HIDESYM
76286+ NULL,
76287+#else
76288+ sp,
76289+#endif
76290+ atomic_read_unchecked(&sp->sk_drops));
76291 }
76292
76293 int udp6_seq_show(struct seq_file *seq, void *v)
76294diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76295index 253695d..9481ce8 100644
76296--- a/net/irda/ircomm/ircomm_tty.c
76297+++ b/net/irda/ircomm/ircomm_tty.c
76298@@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76299 add_wait_queue(&self->open_wait, &wait);
76300
76301 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76302- __FILE__,__LINE__, tty->driver->name, self->open_count );
76303+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76304
76305 /* As far as I can see, we protect open_count - Jean II */
76306 spin_lock_irqsave(&self->spinlock, flags);
76307 if (!tty_hung_up_p(filp)) {
76308 extra_count = 1;
76309- self->open_count--;
76310+ local_dec(&self->open_count);
76311 }
76312 spin_unlock_irqrestore(&self->spinlock, flags);
76313- self->blocked_open++;
76314+ local_inc(&self->blocked_open);
76315
76316 while (1) {
76317 if (tty->termios->c_cflag & CBAUD) {
76318@@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76319 }
76320
76321 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76322- __FILE__,__LINE__, tty->driver->name, self->open_count );
76323+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76324
76325 schedule();
76326 }
76327@@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76328 if (extra_count) {
76329 /* ++ is not atomic, so this should be protected - Jean II */
76330 spin_lock_irqsave(&self->spinlock, flags);
76331- self->open_count++;
76332+ local_inc(&self->open_count);
76333 spin_unlock_irqrestore(&self->spinlock, flags);
76334 }
76335- self->blocked_open--;
76336+ local_dec(&self->blocked_open);
76337
76338 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76339- __FILE__,__LINE__, tty->driver->name, self->open_count);
76340+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76341
76342 if (!retval)
76343 self->flags |= ASYNC_NORMAL_ACTIVE;
76344@@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76345 }
76346 /* ++ is not atomic, so this should be protected - Jean II */
76347 spin_lock_irqsave(&self->spinlock, flags);
76348- self->open_count++;
76349+ local_inc(&self->open_count);
76350
76351 tty->driver_data = self;
76352 self->tty = tty;
76353 spin_unlock_irqrestore(&self->spinlock, flags);
76354
76355 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76356- self->line, self->open_count);
76357+ self->line, local_read(&self->open_count));
76358
76359 /* Not really used by us, but lets do it anyway */
76360 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76361@@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76362 return;
76363 }
76364
76365- if ((tty->count == 1) && (self->open_count != 1)) {
76366+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76367 /*
76368 * Uh, oh. tty->count is 1, which means that the tty
76369 * structure will be freed. state->count should always
76370@@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76371 */
76372 IRDA_DEBUG(0, "%s(), bad serial port count; "
76373 "tty->count is 1, state->count is %d\n", __func__ ,
76374- self->open_count);
76375- self->open_count = 1;
76376+ local_read(&self->open_count));
76377+ local_set(&self->open_count, 1);
76378 }
76379
76380- if (--self->open_count < 0) {
76381+ if (local_dec_return(&self->open_count) < 0) {
76382 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76383- __func__, self->line, self->open_count);
76384- self->open_count = 0;
76385+ __func__, self->line, local_read(&self->open_count));
76386+ local_set(&self->open_count, 0);
76387 }
76388- if (self->open_count) {
76389+ if (local_read(&self->open_count)) {
76390 spin_unlock_irqrestore(&self->spinlock, flags);
76391
76392 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76393@@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76394 tty->closing = 0;
76395 self->tty = NULL;
76396
76397- if (self->blocked_open) {
76398+ if (local_read(&self->blocked_open)) {
76399 if (self->close_delay)
76400 schedule_timeout_interruptible(self->close_delay);
76401 wake_up_interruptible(&self->open_wait);
76402@@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76403 spin_lock_irqsave(&self->spinlock, flags);
76404 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76405 self->tty = NULL;
76406- self->open_count = 0;
76407+ local_set(&self->open_count, 0);
76408 spin_unlock_irqrestore(&self->spinlock, flags);
76409
76410 wake_up_interruptible(&self->open_wait);
76411@@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76412 seq_putc(m, '\n');
76413
76414 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76415- seq_printf(m, "Open count: %d\n", self->open_count);
76416+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76417 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76418 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76419
76420diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76421index d5c5b8f..33beff0 100644
76422--- a/net/iucv/af_iucv.c
76423+++ b/net/iucv/af_iucv.c
76424@@ -764,10 +764,10 @@ static int iucv_sock_autobind(struct sock *sk)
76425
76426 write_lock_bh(&iucv_sk_list.lock);
76427
76428- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76429+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76430 while (__iucv_get_sock_by_name(name)) {
76431 sprintf(name, "%08x",
76432- atomic_inc_return(&iucv_sk_list.autobind_name));
76433+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76434 }
76435
76436 write_unlock_bh(&iucv_sk_list.lock);
76437diff --git a/net/key/af_key.c b/net/key/af_key.c
76438index 11dbb22..c20f667 100644
76439--- a/net/key/af_key.c
76440+++ b/net/key/af_key.c
76441@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76442 static u32 get_acqseq(void)
76443 {
76444 u32 res;
76445- static atomic_t acqseq;
76446+ static atomic_unchecked_t acqseq;
76447
76448 do {
76449- res = atomic_inc_return(&acqseq);
76450+ res = atomic_inc_return_unchecked(&acqseq);
76451 } while (!res);
76452 return res;
76453 }
76454diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
76455index 2f0642d..e5c6fba 100644
76456--- a/net/mac80211/ieee80211_i.h
76457+++ b/net/mac80211/ieee80211_i.h
76458@@ -28,6 +28,7 @@
76459 #include <net/ieee80211_radiotap.h>
76460 #include <net/cfg80211.h>
76461 #include <net/mac80211.h>
76462+#include <asm/local.h>
76463 #include "key.h"
76464 #include "sta_info.h"
76465
76466@@ -781,7 +782,7 @@ struct ieee80211_local {
76467 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
76468 spinlock_t queue_stop_reason_lock;
76469
76470- int open_count;
76471+ local_t open_count;
76472 int monitors, cooked_mntrs;
76473 /* number of interfaces with corresponding FIF_ flags */
76474 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
76475diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
76476index 8e2137b..2974283 100644
76477--- a/net/mac80211/iface.c
76478+++ b/net/mac80211/iface.c
76479@@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76480 break;
76481 }
76482
76483- if (local->open_count == 0) {
76484+ if (local_read(&local->open_count) == 0) {
76485 res = drv_start(local);
76486 if (res)
76487 goto err_del_bss;
76488@@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76489 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
76490
76491 if (!is_valid_ether_addr(dev->dev_addr)) {
76492- if (!local->open_count)
76493+ if (!local_read(&local->open_count))
76494 drv_stop(local);
76495 return -EADDRNOTAVAIL;
76496 }
76497@@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76498 mutex_unlock(&local->mtx);
76499
76500 if (coming_up)
76501- local->open_count++;
76502+ local_inc(&local->open_count);
76503
76504 if (hw_reconf_flags)
76505 ieee80211_hw_config(local, hw_reconf_flags);
76506@@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76507 err_del_interface:
76508 drv_remove_interface(local, sdata);
76509 err_stop:
76510- if (!local->open_count)
76511+ if (!local_read(&local->open_count))
76512 drv_stop(local);
76513 err_del_bss:
76514 sdata->bss = NULL;
76515@@ -489,7 +489,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76516 }
76517
76518 if (going_down)
76519- local->open_count--;
76520+ local_dec(&local->open_count);
76521
76522 switch (sdata->vif.type) {
76523 case NL80211_IFTYPE_AP_VLAN:
76524@@ -548,7 +548,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76525
76526 ieee80211_recalc_ps(local, -1);
76527
76528- if (local->open_count == 0) {
76529+ if (local_read(&local->open_count) == 0) {
76530 if (local->ops->napi_poll)
76531 napi_disable(&local->napi);
76532 ieee80211_clear_tx_pending(local);
76533diff --git a/net/mac80211/main.c b/net/mac80211/main.c
76534index b142bd4..a651749 100644
76535--- a/net/mac80211/main.c
76536+++ b/net/mac80211/main.c
76537@@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
76538 local->hw.conf.power_level = power;
76539 }
76540
76541- if (changed && local->open_count) {
76542+ if (changed && local_read(&local->open_count)) {
76543 ret = drv_config(local, changed);
76544 /*
76545 * Goal:
76546diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
76547index 596efaf..8f1911f 100644
76548--- a/net/mac80211/pm.c
76549+++ b/net/mac80211/pm.c
76550@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76551 struct ieee80211_sub_if_data *sdata;
76552 struct sta_info *sta;
76553
76554- if (!local->open_count)
76555+ if (!local_read(&local->open_count))
76556 goto suspend;
76557
76558 ieee80211_scan_cancel(local);
76559@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76560 cancel_work_sync(&local->dynamic_ps_enable_work);
76561 del_timer_sync(&local->dynamic_ps_timer);
76562
76563- local->wowlan = wowlan && local->open_count;
76564+ local->wowlan = wowlan && local_read(&local->open_count);
76565 if (local->wowlan) {
76566 int err = drv_suspend(local, wowlan);
76567 if (err < 0) {
76568@@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76569 }
76570
76571 /* stop hardware - this must stop RX */
76572- if (local->open_count)
76573+ if (local_read(&local->open_count))
76574 ieee80211_stop_device(local);
76575
76576 suspend:
76577diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
76578index f9b8e81..bb89b46 100644
76579--- a/net/mac80211/rate.c
76580+++ b/net/mac80211/rate.c
76581@@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
76582
76583 ASSERT_RTNL();
76584
76585- if (local->open_count)
76586+ if (local_read(&local->open_count))
76587 return -EBUSY;
76588
76589 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
76590diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
76591index c97a065..ff61928 100644
76592--- a/net/mac80211/rc80211_pid_debugfs.c
76593+++ b/net/mac80211/rc80211_pid_debugfs.c
76594@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
76595
76596 spin_unlock_irqrestore(&events->lock, status);
76597
76598- if (copy_to_user(buf, pb, p))
76599+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
76600 return -EFAULT;
76601
76602 return p;
76603diff --git a/net/mac80211/util.c b/net/mac80211/util.c
76604index 9919892..8c49803 100644
76605--- a/net/mac80211/util.c
76606+++ b/net/mac80211/util.c
76607@@ -1143,7 +1143,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
76608 }
76609 #endif
76610 /* everything else happens only if HW was up & running */
76611- if (!local->open_count)
76612+ if (!local_read(&local->open_count))
76613 goto wake_up;
76614
76615 /*
76616diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
76617index f8ac4ef..b02560b 100644
76618--- a/net/netfilter/Kconfig
76619+++ b/net/netfilter/Kconfig
76620@@ -806,6 +806,16 @@ config NETFILTER_XT_MATCH_ESP
76621
76622 To compile it as a module, choose M here. If unsure, say N.
76623
76624+config NETFILTER_XT_MATCH_GRADM
76625+ tristate '"gradm" match support'
76626+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
76627+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
76628+ ---help---
76629+ The gradm match allows to match on grsecurity RBAC being enabled.
76630+ It is useful when iptables rules are applied early on bootup to
76631+ prevent connections to the machine (except from a trusted host)
76632+ while the RBAC system is disabled.
76633+
76634 config NETFILTER_XT_MATCH_HASHLIMIT
76635 tristate '"hashlimit" match support'
76636 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
76637diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
76638index 40f4c3d..0d5dd6b 100644
76639--- a/net/netfilter/Makefile
76640+++ b/net/netfilter/Makefile
76641@@ -83,6 +83,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
76642 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
76643 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
76644 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
76645+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
76646 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
76647 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
76648 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
76649diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
76650index 29fa5ba..8debc79 100644
76651--- a/net/netfilter/ipvs/ip_vs_conn.c
76652+++ b/net/netfilter/ipvs/ip_vs_conn.c
76653@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
76654 /* Increase the refcnt counter of the dest */
76655 atomic_inc(&dest->refcnt);
76656
76657- conn_flags = atomic_read(&dest->conn_flags);
76658+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
76659 if (cp->protocol != IPPROTO_UDP)
76660 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
76661 /* Bind with the destination and its corresponding transmitter */
76662@@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
76663 atomic_set(&cp->refcnt, 1);
76664
76665 atomic_set(&cp->n_control, 0);
76666- atomic_set(&cp->in_pkts, 0);
76667+ atomic_set_unchecked(&cp->in_pkts, 0);
76668
76669 atomic_inc(&ipvs->conn_count);
76670 if (flags & IP_VS_CONN_F_NO_CPORT)
76671@@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
76672
76673 /* Don't drop the entry if its number of incoming packets is not
76674 located in [0, 8] */
76675- i = atomic_read(&cp->in_pkts);
76676+ i = atomic_read_unchecked(&cp->in_pkts);
76677 if (i > 8 || i < 0) return 0;
76678
76679 if (!todrop_rate[i]) return 0;
76680diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
76681index 2555816..31492d9 100644
76682--- a/net/netfilter/ipvs/ip_vs_core.c
76683+++ b/net/netfilter/ipvs/ip_vs_core.c
76684@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
76685 ret = cp->packet_xmit(skb, cp, pd->pp);
76686 /* do not touch skb anymore */
76687
76688- atomic_inc(&cp->in_pkts);
76689+ atomic_inc_unchecked(&cp->in_pkts);
76690 ip_vs_conn_put(cp);
76691 return ret;
76692 }
76693@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
76694 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
76695 pkts = sysctl_sync_threshold(ipvs);
76696 else
76697- pkts = atomic_add_return(1, &cp->in_pkts);
76698+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76699
76700 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
76701 cp->protocol == IPPROTO_SCTP) {
76702diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
76703index b3afe18..08ec940 100644
76704--- a/net/netfilter/ipvs/ip_vs_ctl.c
76705+++ b/net/netfilter/ipvs/ip_vs_ctl.c
76706@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
76707 ip_vs_rs_hash(ipvs, dest);
76708 write_unlock_bh(&ipvs->rs_lock);
76709 }
76710- atomic_set(&dest->conn_flags, conn_flags);
76711+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
76712
76713 /* bind the service */
76714 if (!dest->svc) {
76715@@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76716 " %-7s %-6d %-10d %-10d\n",
76717 &dest->addr.in6,
76718 ntohs(dest->port),
76719- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76720+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76721 atomic_read(&dest->weight),
76722 atomic_read(&dest->activeconns),
76723 atomic_read(&dest->inactconns));
76724@@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76725 "%-7s %-6d %-10d %-10d\n",
76726 ntohl(dest->addr.ip),
76727 ntohs(dest->port),
76728- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76729+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76730 atomic_read(&dest->weight),
76731 atomic_read(&dest->activeconns),
76732 atomic_read(&dest->inactconns));
76733@@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
76734
76735 entry.addr = dest->addr.ip;
76736 entry.port = dest->port;
76737- entry.conn_flags = atomic_read(&dest->conn_flags);
76738+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
76739 entry.weight = atomic_read(&dest->weight);
76740 entry.u_threshold = dest->u_threshold;
76741 entry.l_threshold = dest->l_threshold;
76742@@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
76743 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
76744
76745 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
76746- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76747+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76748 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
76749 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
76750 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
76751diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
76752index 8a0d6d6..90ec197 100644
76753--- a/net/netfilter/ipvs/ip_vs_sync.c
76754+++ b/net/netfilter/ipvs/ip_vs_sync.c
76755@@ -649,7 +649,7 @@ control:
76756 * i.e only increment in_pkts for Templates.
76757 */
76758 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
76759- int pkts = atomic_add_return(1, &cp->in_pkts);
76760+ int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76761
76762 if (pkts % sysctl_sync_period(ipvs) != 1)
76763 return;
76764@@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
76765
76766 if (opt)
76767 memcpy(&cp->in_seq, opt, sizeof(*opt));
76768- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76769+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76770 cp->state = state;
76771 cp->old_state = cp->state;
76772 /*
76773diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
76774index 7fd66de..e6fb361 100644
76775--- a/net/netfilter/ipvs/ip_vs_xmit.c
76776+++ b/net/netfilter/ipvs/ip_vs_xmit.c
76777@@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
76778 else
76779 rc = NF_ACCEPT;
76780 /* do not touch skb anymore */
76781- atomic_inc(&cp->in_pkts);
76782+ atomic_inc_unchecked(&cp->in_pkts);
76783 goto out;
76784 }
76785
76786@@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
76787 else
76788 rc = NF_ACCEPT;
76789 /* do not touch skb anymore */
76790- atomic_inc(&cp->in_pkts);
76791+ atomic_inc_unchecked(&cp->in_pkts);
76792 goto out;
76793 }
76794
76795diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
76796index 66b2c54..c7884e3 100644
76797--- a/net/netfilter/nfnetlink_log.c
76798+++ b/net/netfilter/nfnetlink_log.c
76799@@ -70,7 +70,7 @@ struct nfulnl_instance {
76800 };
76801
76802 static DEFINE_SPINLOCK(instances_lock);
76803-static atomic_t global_seq;
76804+static atomic_unchecked_t global_seq;
76805
76806 #define INSTANCE_BUCKETS 16
76807 static struct hlist_head instance_table[INSTANCE_BUCKETS];
76808@@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
76809 /* global sequence number */
76810 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
76811 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
76812- htonl(atomic_inc_return(&global_seq)));
76813+ htonl(atomic_inc_return_unchecked(&global_seq)));
76814
76815 if (data_len) {
76816 struct nlattr *nla;
76817diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
76818new file mode 100644
76819index 0000000..6905327
76820--- /dev/null
76821+++ b/net/netfilter/xt_gradm.c
76822@@ -0,0 +1,51 @@
76823+/*
76824+ * gradm match for netfilter
76825