]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.5.0-201208061715.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.5.0-201208061715.patch
CommitLineData
c25f0751
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b4a898f..cd023f2 100644
3--- a/Documentation/dontdiff
4+++ b/Documentation/dontdiff
5@@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9+*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13+*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17@@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21+*.gmo
22 *.grep
23 *.grp
24 *.gz
25@@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29+*.vim
30 *.xml
31 *.xz
32 *_MODULES
33+*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38-.*
39+.[^g]*
40+.gen*
41 .*.d
42 .mm
43 53c700_d.h
44@@ -69,6 +75,7 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48+PERF*
49 SCCS
50 System.map*
51 TAGS
52@@ -80,6 +87,7 @@ aic7*seq.h*
53 aicasm
54 aicdb.h*
55 altivec*.c
56+ashldi3.S
57 asm-offsets.h
58 asm_offsets.h
59 autoconf.h*
60@@ -92,19 +100,24 @@ bounds.h
61 bsetup
62 btfixupprep
63 build
64+builtin-policy.h
65 bvmlinux
66 bzImage*
67 capability_names.h
68 capflags.c
69 classlist.h*
70+clut_vga16.c
71+common-cmds.h
72 comp*.log
73 compile.h*
74 conf
75 config
76 config-*
77 config_data.h*
78+config.c
79 config.mak
80 config.mak.autogen
81+config.tmp
82 conmakehash
83 consolemap_deftbl.c*
84 cpustr.h
85@@ -115,9 +128,11 @@ devlist.h*
86 dnotify_test
87 docproc
88 dslm
89+dtc-lexer.lex.c
90 elf2ecoff
91 elfconfig.h*
92 evergreen_reg_safe.h
93+exception_policy.conf
94 fixdep
95 flask.h
96 fore200e_mkfirm
97@@ -125,12 +140,15 @@ fore200e_pca_fw.c*
98 gconf
99 gconf.glade.h
100 gen-devlist
101+gen-kdb_cmds.c
102 gen_crc32table
103 gen_init_cpio
104 generated
105 genheaders
106 genksyms
107 *_gray256.c
108+hash
109+hid-example
110 hpet_example
111 hugepage-mmap
112 hugepage-shm
113@@ -145,7 +163,7 @@ int32.c
114 int4.c
115 int8.c
116 kallsyms
117-kconfig
118+kern_constants.h
119 keywords.c
120 ksym.c*
121 ksym.h*
122@@ -153,7 +171,7 @@ kxgettext
123 lkc_defs.h
124 lex.c
125 lex.*.c
126-linux
127+lib1funcs.S
128 logo_*.c
129 logo_*_clut224.c
130 logo_*_mono.c
131@@ -164,14 +182,15 @@ machtypes.h
132 map
133 map_hugetlb
134 maui_boot.h
135-media
136 mconf
137+mdp
138 miboot*
139 mk_elfconfig
140 mkboot
141 mkbugboot
142 mkcpustr
143 mkdep
144+mkpiggy
145 mkprep
146 mkregtable
147 mktables
148@@ -188,6 +207,8 @@ oui.c*
149 page-types
150 parse.c
151 parse.h
152+parse-events*
153+pasyms.h
154 patches*
155 pca200e.bin
156 pca200e_ecd.bin2
157@@ -197,6 +218,7 @@ perf-archive
158 piggyback
159 piggy.gzip
160 piggy.S
161+pmu-*
162 pnmtologo
163 ppc_defs.h*
164 pss_boot.h
165@@ -206,7 +228,10 @@ r200_reg_safe.h
166 r300_reg_safe.h
167 r420_reg_safe.h
168 r600_reg_safe.h
169+realmode.lds
170+realmode.relocs
171 recordmcount
172+regdb.c
173 relocs
174 rlim_names.h
175 rn50_reg_safe.h
176@@ -216,8 +241,11 @@ series
177 setup
178 setup.bin
179 setup.elf
180+size_overflow_hash.h
181 sImage
182+slabinfo
183 sm_tbl*
184+sortextable
185 split-include
186 syscalltab.h
187 tables.c
188@@ -227,6 +255,7 @@ tftpboot.img
189 timeconst.h
190 times.h*
191 trix_boot.h
192+user_constants.h
193 utsrelease.h*
194 vdso-syms.lds
195 vdso.lds
196@@ -238,13 +267,17 @@ vdso32.lds
197 vdso32.so.dbg
198 vdso64.lds
199 vdso64.so.dbg
200+vdsox32.lds
201+vdsox32-syms.lds
202 version.h*
203 vmImage
204 vmlinux
205 vmlinux-*
206 vmlinux.aout
207 vmlinux.bin.all
208+vmlinux.bin.bz2
209 vmlinux.lds
210+vmlinux.relocs
211 vmlinuz
212 voffset.h
213 vsyscall.lds
214@@ -252,9 +285,11 @@ vsyscall_32.lds
215 wanxlfw.inc
216 uImage
217 unifdef
218+utsrelease.h
219 wakeup.bin
220 wakeup.elf
221 wakeup.lds
222 zImage*
223 zconf.hash.c
224+zconf.lex.c
225 zoffset.h
226diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
227index a92c5eb..7530459 100644
228--- a/Documentation/kernel-parameters.txt
229+++ b/Documentation/kernel-parameters.txt
230@@ -2051,6 +2051,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
231 the specified number of seconds. This is to be used if
232 your oopses keep scrolling off the screen.
233
234+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
235+ virtualization environments that don't cope well with the
236+ expand down segment used by UDEREF on X86-32 or the frequent
237+ page table updates on X86-64.
238+
239+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
240+
241 pcbit= [HW,ISDN]
242
243 pcd. [PARIDE]
244diff --git a/Documentation/sysctl/fs.txt b/Documentation/sysctl/fs.txt
245index 13d6166..8c235b6 100644
246--- a/Documentation/sysctl/fs.txt
247+++ b/Documentation/sysctl/fs.txt
248@@ -163,16 +163,22 @@ This value can be used to query and set the core dump mode for setuid
249 or otherwise protected/tainted binaries. The modes are
250
251 0 - (default) - traditional behaviour. Any process which has changed
252- privilege levels or is execute only will not be dumped
253+ privilege levels or is execute only will not be dumped.
254 1 - (debug) - all processes dump core when possible. The core dump is
255 owned by the current user and no security is applied. This is
256 intended for system debugging situations only. Ptrace is unchecked.
257+ This is insecure as it allows regular users to examine the memory
258+ contents of privileged processes.
259 2 - (suidsafe) - any binary which normally would not be dumped is dumped
260- readable by root only. This allows the end user to remove
261- such a dump but not access it directly. For security reasons
262- core dumps in this mode will not overwrite one another or
263- other files. This mode is appropriate when administrators are
264- attempting to debug problems in a normal environment.
265+ anyway, but only if the "core_pattern" kernel sysctl is set to
266+ either a pipe handler or a fully qualified path. (For more details
267+ on this limitation, see CVE-2006-2451.) This mode is appropriate
268+ when administrators are attempting to debug problems in a normal
269+ environment, and either have a core dump pipe handler that knows
270+ to treat privileged core dumps with care, or specific directory
271+ defined for catching core dumps. If a core dump happens without
272+ a pipe handler or fully qualifid path, a message will be emitted
273+ to syslog warning about the lack of a correct setting.
274
275 ==============================================================
276
277diff --git a/Makefile b/Makefile
278index 4bb09e1..d2e3cb6 100644
279--- a/Makefile
280+++ b/Makefile
281@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
282
283 HOSTCC = gcc
284 HOSTCXX = g++
285-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
286-HOSTCXXFLAGS = -O2
287+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
288+HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
289+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
290
291 # Decide whether to build built-in, modular, or both.
292 # Normally, just do built-in.
293@@ -404,8 +405,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
294 # Rules shared between *config targets and build targets
295
296 # Basic helpers built in scripts/
297-PHONY += scripts_basic
298-scripts_basic:
299+PHONY += scripts_basic gcc-plugins
300+scripts_basic: gcc-plugins
301 $(Q)$(MAKE) $(build)=scripts/basic
302 $(Q)rm -f .tmp_quiet_recordmcount
303
304@@ -561,6 +562,60 @@ else
305 KBUILD_CFLAGS += -O2
306 endif
307
308+ifndef DISABLE_PAX_PLUGINS
309+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
310+ifneq ($(PLUGINCC),)
311+ifndef DISABLE_PAX_CONSTIFY_PLUGIN
312+ifndef CONFIG_UML
313+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
314+endif
315+endif
316+ifdef CONFIG_PAX_MEMORY_STACKLEAK
317+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
318+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
319+endif
320+ifdef CONFIG_KALLOCSTAT_PLUGIN
321+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
322+endif
323+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
324+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
325+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
326+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
327+endif
328+ifdef CONFIG_CHECKER_PLUGIN
329+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
330+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
331+endif
332+endif
333+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
334+ifdef CONFIG_PAX_SIZE_OVERFLOW
335+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
336+endif
337+ifdef CONFIG_PAX_LATENT_ENTROPY
338+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
339+endif
340+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
341+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
342+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
343+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
344+export PLUGINCC CONSTIFY_PLUGIN
345+ifeq ($(KBUILD_EXTMOD),)
346+gcc-plugins:
347+ $(Q)$(MAKE) $(build)=tools/gcc
348+else
349+gcc-plugins: ;
350+endif
351+else
352+gcc-plugins:
353+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
354+ $(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.))
355+else
356+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
357+endif
358+ $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
359+endif
360+endif
361+
362 include $(srctree)/arch/$(SRCARCH)/Makefile
363
364 ifdef CONFIG_READABLE_ASM
365@@ -715,7 +770,7 @@ export mod_strip_cmd
366
367
368 ifeq ($(KBUILD_EXTMOD),)
369-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
370+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
371
372 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
373 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
374@@ -762,6 +817,8 @@ endif
375
376 # The actual objects are generated when descending,
377 # make sure no implicit rule kicks in
378+$(sort $(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
379+$(sort $(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
380 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
381
382 # Handle descending into subdirectories listed in $(vmlinux-dirs)
383@@ -771,7 +828,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
384 # Error messages still appears in the original language
385
386 PHONY += $(vmlinux-dirs)
387-$(vmlinux-dirs): prepare scripts
388+$(vmlinux-dirs): gcc-plugins prepare scripts
389 $(Q)$(MAKE) $(build)=$@
390
391 # Store (new) KERNELRELASE string in include/config/kernel.release
392@@ -815,6 +872,7 @@ prepare0: archprepare FORCE
393 $(Q)$(MAKE) $(build)=.
394
395 # All the preparing..
396+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
397 prepare: prepare0
398
399 # Generate some files
400@@ -922,6 +980,8 @@ all: modules
401 # using awk while concatenating to the final file.
402
403 PHONY += modules
404+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
405+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
406 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
407 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
408 @$(kecho) ' Building modules, stage 2.';
409@@ -937,7 +997,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
410
411 # Target to prepare building external modules
412 PHONY += modules_prepare
413-modules_prepare: prepare scripts
414+modules_prepare: gcc-plugins prepare scripts
415
416 # Target to install modules
417 PHONY += modules_install
418@@ -994,7 +1054,7 @@ CLEAN_DIRS += $(MODVERDIR)
419 MRPROPER_DIRS += include/config usr/include include/generated \
420 arch/*/include/generated
421 MRPROPER_FILES += .config .config.old .version .old_version \
422- include/linux/version.h \
423+ include/linux/version.h tools/gcc/size_overflow_hash.h\
424 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
425
426 # clean - Delete most, but leave enough to build external modules
427@@ -1032,6 +1092,7 @@ distclean: mrproper
428 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
429 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
430 -o -name '.*.rej' \
431+ -o -name '.*.rej' -o -name '*.so' \
432 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
433 -type f -print | xargs rm -f
434
435@@ -1192,6 +1253,8 @@ PHONY += $(module-dirs) modules
436 $(module-dirs): crmodverdir $(objtree)/Module.symvers
437 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
438
439+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
440+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
441 modules: $(module-dirs)
442 @$(kecho) ' Building modules, stage 2.';
443 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
444@@ -1326,17 +1389,21 @@ else
445 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
446 endif
447
448-%.s: %.c prepare scripts FORCE
449+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
450+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
451+%.s: %.c gcc-plugins prepare scripts FORCE
452 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
453 %.i: %.c prepare scripts FORCE
454 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
455-%.o: %.c prepare scripts FORCE
456+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
457+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
458+%.o: %.c gcc-plugins prepare scripts FORCE
459 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
460 %.lst: %.c prepare scripts FORCE
461 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
462-%.s: %.S prepare scripts FORCE
463+%.s: %.S gcc-plugins prepare scripts FORCE
464 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
465-%.o: %.S prepare scripts FORCE
466+%.o: %.S gcc-plugins prepare scripts FORCE
467 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
468 %.symtypes: %.c prepare scripts FORCE
469 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
470@@ -1346,11 +1413,15 @@ endif
471 $(cmd_crmodverdir)
472 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
473 $(build)=$(build-dir)
474-%/: prepare scripts FORCE
475+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
476+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
477+%/: gcc-plugins prepare scripts FORCE
478 $(cmd_crmodverdir)
479 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
480 $(build)=$(build-dir)
481-%.ko: prepare scripts FORCE
482+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
483+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
484+%.ko: gcc-plugins prepare scripts FORCE
485 $(cmd_crmodverdir)
486 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
487 $(build)=$(build-dir) $(@:.ko=.o)
488diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
489index 3bb7ffe..347a54c 100644
490--- a/arch/alpha/include/asm/atomic.h
491+++ b/arch/alpha/include/asm/atomic.h
492@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
493 #define atomic_dec(v) atomic_sub(1,(v))
494 #define atomic64_dec(v) atomic64_sub(1,(v))
495
496+#define atomic64_read_unchecked(v) atomic64_read(v)
497+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
498+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
499+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
500+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
501+#define atomic64_inc_unchecked(v) atomic64_inc(v)
502+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
503+#define atomic64_dec_unchecked(v) atomic64_dec(v)
504+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
505+
506 #define smp_mb__before_atomic_dec() smp_mb()
507 #define smp_mb__after_atomic_dec() smp_mb()
508 #define smp_mb__before_atomic_inc() smp_mb()
509diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
510index ad368a9..fbe0f25 100644
511--- a/arch/alpha/include/asm/cache.h
512+++ b/arch/alpha/include/asm/cache.h
513@@ -4,19 +4,19 @@
514 #ifndef __ARCH_ALPHA_CACHE_H
515 #define __ARCH_ALPHA_CACHE_H
516
517+#include <linux/const.h>
518
519 /* Bytes per L1 (data) cache line. */
520 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
521-# define L1_CACHE_BYTES 64
522 # define L1_CACHE_SHIFT 6
523 #else
524 /* Both EV4 and EV5 are write-through, read-allocate,
525 direct-mapped, physical.
526 */
527-# define L1_CACHE_BYTES 32
528 # define L1_CACHE_SHIFT 5
529 #endif
530
531+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
532 #define SMP_CACHE_BYTES L1_CACHE_BYTES
533
534 #endif
535diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
536index 968d999..d36b2df 100644
537--- a/arch/alpha/include/asm/elf.h
538+++ b/arch/alpha/include/asm/elf.h
539@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
540
541 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
542
543+#ifdef CONFIG_PAX_ASLR
544+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
545+
546+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
547+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
548+#endif
549+
550 /* $0 is set by ld.so to a pointer to a function which might be
551 registered using atexit. This provides a mean for the dynamic
552 linker to call DT_FINI functions for shared libraries that have
553diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
554index bc2a0da..8ad11ee 100644
555--- a/arch/alpha/include/asm/pgalloc.h
556+++ b/arch/alpha/include/asm/pgalloc.h
557@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
558 pgd_set(pgd, pmd);
559 }
560
561+static inline void
562+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
563+{
564+ pgd_populate(mm, pgd, pmd);
565+}
566+
567 extern pgd_t *pgd_alloc(struct mm_struct *mm);
568
569 static inline void
570diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
571index 81a4342..348b927 100644
572--- a/arch/alpha/include/asm/pgtable.h
573+++ b/arch/alpha/include/asm/pgtable.h
574@@ -102,6 +102,17 @@ struct vm_area_struct;
575 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
576 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
577 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
578+
579+#ifdef CONFIG_PAX_PAGEEXEC
580+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
581+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
582+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
583+#else
584+# define PAGE_SHARED_NOEXEC PAGE_SHARED
585+# define PAGE_COPY_NOEXEC PAGE_COPY
586+# define PAGE_READONLY_NOEXEC PAGE_READONLY
587+#endif
588+
589 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
590
591 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
592diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
593index 2fd00b7..cfd5069 100644
594--- a/arch/alpha/kernel/module.c
595+++ b/arch/alpha/kernel/module.c
596@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
597
598 /* The small sections were sorted to the end of the segment.
599 The following should definitely cover them. */
600- gp = (u64)me->module_core + me->core_size - 0x8000;
601+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
602 got = sechdrs[me->arch.gotsecindex].sh_addr;
603
604 for (i = 0; i < n; i++) {
605diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
606index 98a1036..fb54ccf 100644
607--- a/arch/alpha/kernel/osf_sys.c
608+++ b/arch/alpha/kernel/osf_sys.c
609@@ -1312,7 +1312,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
610 /* At this point: (!vma || addr < vma->vm_end). */
611 if (limit - len < addr)
612 return -ENOMEM;
613- if (!vma || addr + len <= vma->vm_start)
614+ if (check_heap_stack_gap(vma, addr, len))
615 return addr;
616 addr = vma->vm_end;
617 vma = vma->vm_next;
618@@ -1348,6 +1348,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
619 merely specific addresses, but regions of memory -- perhaps
620 this feature should be incorporated into all ports? */
621
622+#ifdef CONFIG_PAX_RANDMMAP
623+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
624+#endif
625+
626 if (addr) {
627 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
628 if (addr != (unsigned long) -ENOMEM)
629@@ -1355,8 +1359,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
630 }
631
632 /* Next, try allocating at TASK_UNMAPPED_BASE. */
633- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
634- len, limit);
635+ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
636+
637 if (addr != (unsigned long) -ENOMEM)
638 return addr;
639
640diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
641index 5eecab1..609abc0 100644
642--- a/arch/alpha/mm/fault.c
643+++ b/arch/alpha/mm/fault.c
644@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
645 __reload_thread(pcb);
646 }
647
648+#ifdef CONFIG_PAX_PAGEEXEC
649+/*
650+ * PaX: decide what to do with offenders (regs->pc = fault address)
651+ *
652+ * returns 1 when task should be killed
653+ * 2 when patched PLT trampoline was detected
654+ * 3 when unpatched PLT trampoline was detected
655+ */
656+static int pax_handle_fetch_fault(struct pt_regs *regs)
657+{
658+
659+#ifdef CONFIG_PAX_EMUPLT
660+ int err;
661+
662+ do { /* PaX: patched PLT emulation #1 */
663+ unsigned int ldah, ldq, jmp;
664+
665+ err = get_user(ldah, (unsigned int *)regs->pc);
666+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
667+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
668+
669+ if (err)
670+ break;
671+
672+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
673+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
674+ jmp == 0x6BFB0000U)
675+ {
676+ unsigned long r27, addr;
677+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
678+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
679+
680+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
681+ err = get_user(r27, (unsigned long *)addr);
682+ if (err)
683+ break;
684+
685+ regs->r27 = r27;
686+ regs->pc = r27;
687+ return 2;
688+ }
689+ } while (0);
690+
691+ do { /* PaX: patched PLT emulation #2 */
692+ unsigned int ldah, lda, br;
693+
694+ err = get_user(ldah, (unsigned int *)regs->pc);
695+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
696+ err |= get_user(br, (unsigned int *)(regs->pc+8));
697+
698+ if (err)
699+ break;
700+
701+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
702+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
703+ (br & 0xFFE00000U) == 0xC3E00000U)
704+ {
705+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
706+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
707+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
708+
709+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
710+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
711+ return 2;
712+ }
713+ } while (0);
714+
715+ do { /* PaX: unpatched PLT emulation */
716+ unsigned int br;
717+
718+ err = get_user(br, (unsigned int *)regs->pc);
719+
720+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
721+ unsigned int br2, ldq, nop, jmp;
722+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
723+
724+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
725+ err = get_user(br2, (unsigned int *)addr);
726+ err |= get_user(ldq, (unsigned int *)(addr+4));
727+ err |= get_user(nop, (unsigned int *)(addr+8));
728+ err |= get_user(jmp, (unsigned int *)(addr+12));
729+ err |= get_user(resolver, (unsigned long *)(addr+16));
730+
731+ if (err)
732+ break;
733+
734+ if (br2 == 0xC3600000U &&
735+ ldq == 0xA77B000CU &&
736+ nop == 0x47FF041FU &&
737+ jmp == 0x6B7B0000U)
738+ {
739+ regs->r28 = regs->pc+4;
740+ regs->r27 = addr+16;
741+ regs->pc = resolver;
742+ return 3;
743+ }
744+ }
745+ } while (0);
746+#endif
747+
748+ return 1;
749+}
750+
751+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
752+{
753+ unsigned long i;
754+
755+ printk(KERN_ERR "PAX: bytes at PC: ");
756+ for (i = 0; i < 5; i++) {
757+ unsigned int c;
758+ if (get_user(c, (unsigned int *)pc+i))
759+ printk(KERN_CONT "???????? ");
760+ else
761+ printk(KERN_CONT "%08x ", c);
762+ }
763+ printk("\n");
764+}
765+#endif
766
767 /*
768 * This routine handles page faults. It determines the address,
769@@ -130,8 +248,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
770 good_area:
771 si_code = SEGV_ACCERR;
772 if (cause < 0) {
773- if (!(vma->vm_flags & VM_EXEC))
774+ if (!(vma->vm_flags & VM_EXEC)) {
775+
776+#ifdef CONFIG_PAX_PAGEEXEC
777+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
778+ goto bad_area;
779+
780+ up_read(&mm->mmap_sem);
781+ switch (pax_handle_fetch_fault(regs)) {
782+
783+#ifdef CONFIG_PAX_EMUPLT
784+ case 2:
785+ case 3:
786+ return;
787+#endif
788+
789+ }
790+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
791+ do_group_exit(SIGKILL);
792+#else
793 goto bad_area;
794+#endif
795+
796+ }
797 } else if (!cause) {
798 /* Allow reads even for write-only mappings */
799 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
800diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
801index c79f61f..9269ea1 100644
802--- a/arch/arm/include/asm/atomic.h
803+++ b/arch/arm/include/asm/atomic.h
804@@ -17,17 +17,35 @@
805 #include <asm/barrier.h>
806 #include <asm/cmpxchg.h>
807
808+#ifdef CONFIG_GENERIC_ATOMIC64
809+#include <asm-generic/atomic64.h>
810+#endif
811+
812 #define ATOMIC_INIT(i) { (i) }
813
814 #ifdef __KERNEL__
815
816+#define _ASM_EXTABLE(from, to) \
817+" .pushsection __ex_table,\"a\"\n"\
818+" .align 3\n" \
819+" .long " #from ", " #to"\n" \
820+" .popsection"
821+
822 /*
823 * On ARM, ordinary assignment (str instruction) doesn't clear the local
824 * strex/ldrex monitor on some implementations. The reason we can use it for
825 * atomic_set() is the clrex or dummy strex done on every exception return.
826 */
827 #define atomic_read(v) (*(volatile int *)&(v)->counter)
828+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
829+{
830+ return v->counter;
831+}
832 #define atomic_set(v,i) (((v)->counter) = (i))
833+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
834+{
835+ v->counter = i;
836+}
837
838 #if __LINUX_ARM_ARCH__ >= 6
839
840@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
841 int result;
842
843 __asm__ __volatile__("@ atomic_add\n"
844+"1: ldrex %1, [%3]\n"
845+" adds %0, %1, %4\n"
846+
847+#ifdef CONFIG_PAX_REFCOUNT
848+" bvc 3f\n"
849+"2: bkpt 0xf103\n"
850+"3:\n"
851+#endif
852+
853+" strex %1, %0, [%3]\n"
854+" teq %1, #0\n"
855+" bne 1b"
856+
857+#ifdef CONFIG_PAX_REFCOUNT
858+"\n4:\n"
859+ _ASM_EXTABLE(2b, 4b)
860+#endif
861+
862+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
863+ : "r" (&v->counter), "Ir" (i)
864+ : "cc");
865+}
866+
867+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
868+{
869+ unsigned long tmp;
870+ int result;
871+
872+ __asm__ __volatile__("@ atomic_add_unchecked\n"
873 "1: ldrex %0, [%3]\n"
874 " add %0, %0, %4\n"
875 " strex %1, %0, [%3]\n"
876@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
877 smp_mb();
878
879 __asm__ __volatile__("@ atomic_add_return\n"
880+"1: ldrex %1, [%3]\n"
881+" adds %0, %1, %4\n"
882+
883+#ifdef CONFIG_PAX_REFCOUNT
884+" bvc 3f\n"
885+" mov %0, %1\n"
886+"2: bkpt 0xf103\n"
887+"3:\n"
888+#endif
889+
890+" strex %1, %0, [%3]\n"
891+" teq %1, #0\n"
892+" bne 1b"
893+
894+#ifdef CONFIG_PAX_REFCOUNT
895+"\n4:\n"
896+ _ASM_EXTABLE(2b, 4b)
897+#endif
898+
899+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
900+ : "r" (&v->counter), "Ir" (i)
901+ : "cc");
902+
903+ smp_mb();
904+
905+ return result;
906+}
907+
908+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
909+{
910+ unsigned long tmp;
911+ int result;
912+
913+ smp_mb();
914+
915+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
916 "1: ldrex %0, [%3]\n"
917 " add %0, %0, %4\n"
918 " strex %1, %0, [%3]\n"
919@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
920 int result;
921
922 __asm__ __volatile__("@ atomic_sub\n"
923+"1: ldrex %1, [%3]\n"
924+" subs %0, %1, %4\n"
925+
926+#ifdef CONFIG_PAX_REFCOUNT
927+" bvc 3f\n"
928+"2: bkpt 0xf103\n"
929+"3:\n"
930+#endif
931+
932+" strex %1, %0, [%3]\n"
933+" teq %1, #0\n"
934+" bne 1b"
935+
936+#ifdef CONFIG_PAX_REFCOUNT
937+"\n4:\n"
938+ _ASM_EXTABLE(2b, 4b)
939+#endif
940+
941+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
942+ : "r" (&v->counter), "Ir" (i)
943+ : "cc");
944+}
945+
946+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
947+{
948+ unsigned long tmp;
949+ int result;
950+
951+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
952 "1: ldrex %0, [%3]\n"
953 " sub %0, %0, %4\n"
954 " strex %1, %0, [%3]\n"
955@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
956 smp_mb();
957
958 __asm__ __volatile__("@ atomic_sub_return\n"
959-"1: ldrex %0, [%3]\n"
960-" sub %0, %0, %4\n"
961+"1: ldrex %1, [%3]\n"
962+" sub %0, %1, %4\n"
963+
964+#ifdef CONFIG_PAX_REFCOUNT
965+" bvc 3f\n"
966+" mov %0, %1\n"
967+"2: bkpt 0xf103\n"
968+"3:\n"
969+#endif
970+
971 " strex %1, %0, [%3]\n"
972 " teq %1, #0\n"
973 " bne 1b"
974+
975+#ifdef CONFIG_PAX_REFCOUNT
976+"\n4:\n"
977+ _ASM_EXTABLE(2b, 4b)
978+#endif
979+
980 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
981 : "r" (&v->counter), "Ir" (i)
982 : "cc");
983@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
984 return oldval;
985 }
986
987+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
988+{
989+ unsigned long oldval, res;
990+
991+ smp_mb();
992+
993+ do {
994+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
995+ "ldrex %1, [%3]\n"
996+ "mov %0, #0\n"
997+ "teq %1, %4\n"
998+ "strexeq %0, %5, [%3]\n"
999+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1000+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1001+ : "cc");
1002+ } while (res);
1003+
1004+ smp_mb();
1005+
1006+ return oldval;
1007+}
1008+
1009 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1010 {
1011 unsigned long tmp, tmp2;
1012@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1013
1014 return val;
1015 }
1016+
1017+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1018+{
1019+ return atomic_add_return(i, v);
1020+}
1021+
1022 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1023+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1024+{
1025+ (void) atomic_add_return(i, v);
1026+}
1027
1028 static inline int atomic_sub_return(int i, atomic_t *v)
1029 {
1030@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1031 return val;
1032 }
1033 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1034+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1035+{
1036+ (void) atomic_sub_return(i, v);
1037+}
1038
1039 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1040 {
1041@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1042 return ret;
1043 }
1044
1045+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1046+{
1047+ return atomic_cmpxchg(v, old, new);
1048+}
1049+
1050 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1051 {
1052 unsigned long flags;
1053@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1054 #endif /* __LINUX_ARM_ARCH__ */
1055
1056 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1057+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1058+{
1059+ return xchg(&v->counter, new);
1060+}
1061
1062 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1063 {
1064@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1065 }
1066
1067 #define atomic_inc(v) atomic_add(1, v)
1068+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1069+{
1070+ atomic_add_unchecked(1, v);
1071+}
1072 #define atomic_dec(v) atomic_sub(1, v)
1073+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1074+{
1075+ atomic_sub_unchecked(1, v);
1076+}
1077
1078 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1079+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1080+{
1081+ return atomic_add_return_unchecked(1, v) == 0;
1082+}
1083 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1084 #define atomic_inc_return(v) (atomic_add_return(1, v))
1085+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1086+{
1087+ return atomic_add_return_unchecked(1, v);
1088+}
1089 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1090 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1091
1092@@ -241,6 +428,14 @@ typedef struct {
1093 u64 __aligned(8) counter;
1094 } atomic64_t;
1095
1096+#ifdef CONFIG_PAX_REFCOUNT
1097+typedef struct {
1098+ u64 __aligned(8) counter;
1099+} atomic64_unchecked_t;
1100+#else
1101+typedef atomic64_t atomic64_unchecked_t;
1102+#endif
1103+
1104 #define ATOMIC64_INIT(i) { (i) }
1105
1106 static inline u64 atomic64_read(const atomic64_t *v)
1107@@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1108 return result;
1109 }
1110
1111+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1112+{
1113+ u64 result;
1114+
1115+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1116+" ldrexd %0, %H0, [%1]"
1117+ : "=&r" (result)
1118+ : "r" (&v->counter), "Qo" (v->counter)
1119+ );
1120+
1121+ return result;
1122+}
1123+
1124 static inline void atomic64_set(atomic64_t *v, u64 i)
1125 {
1126 u64 tmp;
1127@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1128 : "cc");
1129 }
1130
1131+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1132+{
1133+ u64 tmp;
1134+
1135+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1136+"1: ldrexd %0, %H0, [%2]\n"
1137+" strexd %0, %3, %H3, [%2]\n"
1138+" teq %0, #0\n"
1139+" bne 1b"
1140+ : "=&r" (tmp), "=Qo" (v->counter)
1141+ : "r" (&v->counter), "r" (i)
1142+ : "cc");
1143+}
1144+
1145 static inline void atomic64_add(u64 i, atomic64_t *v)
1146 {
1147 u64 result;
1148@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1149 __asm__ __volatile__("@ atomic64_add\n"
1150 "1: ldrexd %0, %H0, [%3]\n"
1151 " adds %0, %0, %4\n"
1152+" adcs %H0, %H0, %H4\n"
1153+
1154+#ifdef CONFIG_PAX_REFCOUNT
1155+" bvc 3f\n"
1156+"2: bkpt 0xf103\n"
1157+"3:\n"
1158+#endif
1159+
1160+" strexd %1, %0, %H0, [%3]\n"
1161+" teq %1, #0\n"
1162+" bne 1b"
1163+
1164+#ifdef CONFIG_PAX_REFCOUNT
1165+"\n4:\n"
1166+ _ASM_EXTABLE(2b, 4b)
1167+#endif
1168+
1169+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1170+ : "r" (&v->counter), "r" (i)
1171+ : "cc");
1172+}
1173+
1174+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1175+{
1176+ u64 result;
1177+ unsigned long tmp;
1178+
1179+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1180+"1: ldrexd %0, %H0, [%3]\n"
1181+" adds %0, %0, %4\n"
1182 " adc %H0, %H0, %H4\n"
1183 " strexd %1, %0, %H0, [%3]\n"
1184 " teq %1, #0\n"
1185@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1186
1187 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1188 {
1189- u64 result;
1190- unsigned long tmp;
1191+ u64 result, tmp;
1192
1193 smp_mb();
1194
1195 __asm__ __volatile__("@ atomic64_add_return\n"
1196+"1: ldrexd %1, %H1, [%3]\n"
1197+" adds %0, %1, %4\n"
1198+" adcs %H0, %H1, %H4\n"
1199+
1200+#ifdef CONFIG_PAX_REFCOUNT
1201+" bvc 3f\n"
1202+" mov %0, %1\n"
1203+" mov %H0, %H1\n"
1204+"2: bkpt 0xf103\n"
1205+"3:\n"
1206+#endif
1207+
1208+" strexd %1, %0, %H0, [%3]\n"
1209+" teq %1, #0\n"
1210+" bne 1b"
1211+
1212+#ifdef CONFIG_PAX_REFCOUNT
1213+"\n4:\n"
1214+ _ASM_EXTABLE(2b, 4b)
1215+#endif
1216+
1217+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1218+ : "r" (&v->counter), "r" (i)
1219+ : "cc");
1220+
1221+ smp_mb();
1222+
1223+ return result;
1224+}
1225+
1226+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1227+{
1228+ u64 result;
1229+ unsigned long tmp;
1230+
1231+ smp_mb();
1232+
1233+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1234 "1: ldrexd %0, %H0, [%3]\n"
1235 " adds %0, %0, %4\n"
1236 " adc %H0, %H0, %H4\n"
1237@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1238 __asm__ __volatile__("@ atomic64_sub\n"
1239 "1: ldrexd %0, %H0, [%3]\n"
1240 " subs %0, %0, %4\n"
1241+" sbcs %H0, %H0, %H4\n"
1242+
1243+#ifdef CONFIG_PAX_REFCOUNT
1244+" bvc 3f\n"
1245+"2: bkpt 0xf103\n"
1246+"3:\n"
1247+#endif
1248+
1249+" strexd %1, %0, %H0, [%3]\n"
1250+" teq %1, #0\n"
1251+" bne 1b"
1252+
1253+#ifdef CONFIG_PAX_REFCOUNT
1254+"\n4:\n"
1255+ _ASM_EXTABLE(2b, 4b)
1256+#endif
1257+
1258+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1259+ : "r" (&v->counter), "r" (i)
1260+ : "cc");
1261+}
1262+
1263+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1264+{
1265+ u64 result;
1266+ unsigned long tmp;
1267+
1268+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1269+"1: ldrexd %0, %H0, [%3]\n"
1270+" subs %0, %0, %4\n"
1271 " sbc %H0, %H0, %H4\n"
1272 " strexd %1, %0, %H0, [%3]\n"
1273 " teq %1, #0\n"
1274@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1275
1276 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1277 {
1278- u64 result;
1279- unsigned long tmp;
1280+ u64 result, tmp;
1281
1282 smp_mb();
1283
1284 __asm__ __volatile__("@ atomic64_sub_return\n"
1285-"1: ldrexd %0, %H0, [%3]\n"
1286-" subs %0, %0, %4\n"
1287-" sbc %H0, %H0, %H4\n"
1288+"1: ldrexd %1, %H1, [%3]\n"
1289+" subs %0, %1, %4\n"
1290+" sbc %H0, %H1, %H4\n"
1291+
1292+#ifdef CONFIG_PAX_REFCOUNT
1293+" bvc 3f\n"
1294+" mov %0, %1\n"
1295+" mov %H0, %H1\n"
1296+"2: bkpt 0xf103\n"
1297+"3:\n"
1298+#endif
1299+
1300 " strexd %1, %0, %H0, [%3]\n"
1301 " teq %1, #0\n"
1302 " bne 1b"
1303+
1304+#ifdef CONFIG_PAX_REFCOUNT
1305+"\n4:\n"
1306+ _ASM_EXTABLE(2b, 4b)
1307+#endif
1308+
1309 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1310 : "r" (&v->counter), "r" (i)
1311 : "cc");
1312@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1313 return oldval;
1314 }
1315
1316+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1317+{
1318+ u64 oldval;
1319+ unsigned long res;
1320+
1321+ smp_mb();
1322+
1323+ do {
1324+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1325+ "ldrexd %1, %H1, [%3]\n"
1326+ "mov %0, #0\n"
1327+ "teq %1, %4\n"
1328+ "teqeq %H1, %H4\n"
1329+ "strexdeq %0, %5, %H5, [%3]"
1330+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1331+ : "r" (&ptr->counter), "r" (old), "r" (new)
1332+ : "cc");
1333+ } while (res);
1334+
1335+ smp_mb();
1336+
1337+ return oldval;
1338+}
1339+
1340 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1341 {
1342 u64 result;
1343@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1344
1345 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1346 {
1347- u64 result;
1348- unsigned long tmp;
1349+ u64 result, tmp;
1350
1351 smp_mb();
1352
1353 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1354-"1: ldrexd %0, %H0, [%3]\n"
1355-" subs %0, %0, #1\n"
1356-" sbc %H0, %H0, #0\n"
1357+"1: ldrexd %1, %H1, [%3]\n"
1358+" subs %0, %1, #1\n"
1359+" sbc %H0, %H1, #0\n"
1360+
1361+#ifdef CONFIG_PAX_REFCOUNT
1362+" bvc 3f\n"
1363+" mov %0, %1\n"
1364+" mov %H0, %H1\n"
1365+"2: bkpt 0xf103\n"
1366+"3:\n"
1367+#endif
1368+
1369 " teq %H0, #0\n"
1370-" bmi 2f\n"
1371+" bmi 4f\n"
1372 " strexd %1, %0, %H0, [%3]\n"
1373 " teq %1, #0\n"
1374 " bne 1b\n"
1375-"2:"
1376+"4:\n"
1377+
1378+#ifdef CONFIG_PAX_REFCOUNT
1379+ _ASM_EXTABLE(2b, 4b)
1380+#endif
1381+
1382 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1383 : "r" (&v->counter)
1384 : "cc");
1385@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1386 " teq %0, %5\n"
1387 " teqeq %H0, %H5\n"
1388 " moveq %1, #0\n"
1389-" beq 2f\n"
1390+" beq 4f\n"
1391 " adds %0, %0, %6\n"
1392 " adc %H0, %H0, %H6\n"
1393+
1394+#ifdef CONFIG_PAX_REFCOUNT
1395+" bvc 3f\n"
1396+"2: bkpt 0xf103\n"
1397+"3:\n"
1398+#endif
1399+
1400 " strexd %2, %0, %H0, [%4]\n"
1401 " teq %2, #0\n"
1402 " bne 1b\n"
1403-"2:"
1404+"4:\n"
1405+
1406+#ifdef CONFIG_PAX_REFCOUNT
1407+ _ASM_EXTABLE(2b, 4b)
1408+#endif
1409+
1410 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1411 : "r" (&v->counter), "r" (u), "r" (a)
1412 : "cc");
1413@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1414
1415 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1416 #define atomic64_inc(v) atomic64_add(1LL, (v))
1417+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1418 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1419+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1420 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1421 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1422 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1423+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1424 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1425 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1426 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1427diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1428index 75fe66b..2255c86 100644
1429--- a/arch/arm/include/asm/cache.h
1430+++ b/arch/arm/include/asm/cache.h
1431@@ -4,8 +4,10 @@
1432 #ifndef __ASMARM_CACHE_H
1433 #define __ASMARM_CACHE_H
1434
1435+#include <linux/const.h>
1436+
1437 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1438-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1439+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1440
1441 /*
1442 * Memory returned by kmalloc() may be used for DMA, so we must make
1443diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1444index 004c1bc..d9d6d91 100644
1445--- a/arch/arm/include/asm/cacheflush.h
1446+++ b/arch/arm/include/asm/cacheflush.h
1447@@ -108,7 +108,7 @@ struct cpu_cache_fns {
1448 void (*dma_unmap_area)(const void *, size_t, int);
1449
1450 void (*dma_flush_range)(const void *, const void *);
1451-};
1452+} __no_const;
1453
1454 /*
1455 * Select the calling method
1456diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1457index 7eb18c1..e38b6d2 100644
1458--- a/arch/arm/include/asm/cmpxchg.h
1459+++ b/arch/arm/include/asm/cmpxchg.h
1460@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1461
1462 #define xchg(ptr,x) \
1463 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1464+#define xchg_unchecked(ptr,x) \
1465+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1466
1467 #include <asm-generic/cmpxchg-local.h>
1468
1469diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1470index 38050b1..9d90e8b 100644
1471--- a/arch/arm/include/asm/elf.h
1472+++ b/arch/arm/include/asm/elf.h
1473@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1474 the loader. We need to make sure that it is out of the way of the program
1475 that it will "exec", and that there is sufficient room for the brk. */
1476
1477-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1478+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1479+
1480+#ifdef CONFIG_PAX_ASLR
1481+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1482+
1483+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1484+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1485+#endif
1486
1487 /* When the program starts, a1 contains a pointer to a function to be
1488 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1489@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1490 extern void elf_set_personality(const struct elf32_hdr *);
1491 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1492
1493-struct mm_struct;
1494-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1495-#define arch_randomize_brk arch_randomize_brk
1496-
1497 #endif
1498diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1499index e51b1e8..32a3113 100644
1500--- a/arch/arm/include/asm/kmap_types.h
1501+++ b/arch/arm/include/asm/kmap_types.h
1502@@ -21,6 +21,7 @@ enum km_type {
1503 KM_L1_CACHE,
1504 KM_L2_CACHE,
1505 KM_KDB,
1506+ KM_CLEARPAGE,
1507 KM_TYPE_NR
1508 };
1509
1510diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1511index 53426c6..c7baff3 100644
1512--- a/arch/arm/include/asm/outercache.h
1513+++ b/arch/arm/include/asm/outercache.h
1514@@ -35,7 +35,7 @@ struct outer_cache_fns {
1515 #endif
1516 void (*set_debug)(unsigned long);
1517 void (*resume)(void);
1518-};
1519+} __no_const;
1520
1521 #ifdef CONFIG_OUTER_CACHE
1522
1523diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1524index ecf9019..b71d9a1 100644
1525--- a/arch/arm/include/asm/page.h
1526+++ b/arch/arm/include/asm/page.h
1527@@ -114,7 +114,7 @@ struct cpu_user_fns {
1528 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1529 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1530 unsigned long vaddr, struct vm_area_struct *vma);
1531-};
1532+} __no_const;
1533
1534 #ifdef MULTI_USER
1535 extern struct cpu_user_fns cpu_user;
1536diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1537index 943504f..bf8d667 100644
1538--- a/arch/arm/include/asm/pgalloc.h
1539+++ b/arch/arm/include/asm/pgalloc.h
1540@@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1541 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1542 }
1543
1544+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1545+{
1546+ pud_populate(mm, pud, pmd);
1547+}
1548+
1549 #else /* !CONFIG_ARM_LPAE */
1550
1551 /*
1552@@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1553 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1554 #define pmd_free(mm, pmd) do { } while (0)
1555 #define pud_populate(mm,pmd,pte) BUG()
1556+#define pud_populate_kernel(mm,pmd,pte) BUG()
1557
1558 #endif /* CONFIG_ARM_LPAE */
1559
1560diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1561index af7b0bd..6750a8c 100644
1562--- a/arch/arm/include/asm/thread_info.h
1563+++ b/arch/arm/include/asm/thread_info.h
1564@@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1565 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1566 #define TIF_SYSCALL_TRACE 8
1567 #define TIF_SYSCALL_AUDIT 9
1568+
1569+/* within 8 bits of TIF_SYSCALL_TRACE
1570+ to meet flexible second operand requirements
1571+*/
1572+#define TIF_GRSEC_SETXID 10
1573+
1574 #define TIF_POLLING_NRFLAG 16
1575 #define TIF_USING_IWMMXT 17
1576 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1577@@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1578 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
1579 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1580 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1581+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1582
1583 /* Checks for any syscall work in entry-common.S */
1584-#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1585+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1586+ _TIF_GRSEC_SETXID)
1587
1588 /*
1589 * Change these and you break ASM code in entry-common.S
1590diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1591index 71f6536..602f279 100644
1592--- a/arch/arm/include/asm/uaccess.h
1593+++ b/arch/arm/include/asm/uaccess.h
1594@@ -22,6 +22,8 @@
1595 #define VERIFY_READ 0
1596 #define VERIFY_WRITE 1
1597
1598+extern void check_object_size(const void *ptr, unsigned long n, bool to);
1599+
1600 /*
1601 * The exception table consists of pairs of addresses: the first is the
1602 * address of an instruction that is allowed to fault, and the second is
1603@@ -387,8 +389,23 @@ do { \
1604
1605
1606 #ifdef CONFIG_MMU
1607-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1608-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1609+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1610+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1611+
1612+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1613+{
1614+ if (!__builtin_constant_p(n))
1615+ check_object_size(to, n, false);
1616+ return ___copy_from_user(to, from, n);
1617+}
1618+
1619+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1620+{
1621+ if (!__builtin_constant_p(n))
1622+ check_object_size(from, n, true);
1623+ return ___copy_to_user(to, from, n);
1624+}
1625+
1626 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1627 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1628 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1629@@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1630
1631 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1632 {
1633+ if ((long)n < 0)
1634+ return n;
1635+
1636 if (access_ok(VERIFY_READ, from, n))
1637 n = __copy_from_user(to, from, n);
1638 else /* security hole - plug it */
1639@@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1640
1641 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1642 {
1643+ if ((long)n < 0)
1644+ return n;
1645+
1646 if (access_ok(VERIFY_WRITE, to, n))
1647 n = __copy_to_user(to, from, n);
1648 return n;
1649diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1650index b57c75e..ed2d6b2 100644
1651--- a/arch/arm/kernel/armksyms.c
1652+++ b/arch/arm/kernel/armksyms.c
1653@@ -94,8 +94,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1654 #ifdef CONFIG_MMU
1655 EXPORT_SYMBOL(copy_page);
1656
1657-EXPORT_SYMBOL(__copy_from_user);
1658-EXPORT_SYMBOL(__copy_to_user);
1659+EXPORT_SYMBOL(___copy_from_user);
1660+EXPORT_SYMBOL(___copy_to_user);
1661 EXPORT_SYMBOL(__clear_user);
1662
1663 EXPORT_SYMBOL(__get_user_1);
1664diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1665index 19c95ea..7160f7c 100644
1666--- a/arch/arm/kernel/process.c
1667+++ b/arch/arm/kernel/process.c
1668@@ -28,7 +28,6 @@
1669 #include <linux/tick.h>
1670 #include <linux/utsname.h>
1671 #include <linux/uaccess.h>
1672-#include <linux/random.h>
1673 #include <linux/hw_breakpoint.h>
1674 #include <linux/cpuidle.h>
1675
1676@@ -255,9 +254,10 @@ void machine_power_off(void)
1677 machine_shutdown();
1678 if (pm_power_off)
1679 pm_power_off();
1680+ BUG();
1681 }
1682
1683-void machine_restart(char *cmd)
1684+__noreturn void machine_restart(char *cmd)
1685 {
1686 machine_shutdown();
1687
1688@@ -499,12 +499,6 @@ unsigned long get_wchan(struct task_struct *p)
1689 return 0;
1690 }
1691
1692-unsigned long arch_randomize_brk(struct mm_struct *mm)
1693-{
1694- unsigned long range_end = mm->brk + 0x02000000;
1695- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1696-}
1697-
1698 #ifdef CONFIG_MMU
1699 /*
1700 * The vectors page is always readable from user space for the
1701diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1702index 14e3826..d832d89 100644
1703--- a/arch/arm/kernel/ptrace.c
1704+++ b/arch/arm/kernel/ptrace.c
1705@@ -907,10 +907,19 @@ long arch_ptrace(struct task_struct *child, long request,
1706 return ret;
1707 }
1708
1709+#ifdef CONFIG_GRKERNSEC_SETXID
1710+extern void gr_delayed_cred_worker(void);
1711+#endif
1712+
1713 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1714 {
1715 unsigned long ip;
1716
1717+#ifdef CONFIG_GRKERNSEC_SETXID
1718+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1719+ gr_delayed_cred_worker();
1720+#endif
1721+
1722 if (why)
1723 audit_syscall_exit(regs);
1724 else
1725diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1726index e15d83b..8c466dd 100644
1727--- a/arch/arm/kernel/setup.c
1728+++ b/arch/arm/kernel/setup.c
1729@@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1730 struct cpu_tlb_fns cpu_tlb __read_mostly;
1731 #endif
1732 #ifdef MULTI_USER
1733-struct cpu_user_fns cpu_user __read_mostly;
1734+struct cpu_user_fns cpu_user __read_only;
1735 #endif
1736 #ifdef MULTI_CACHE
1737-struct cpu_cache_fns cpu_cache __read_mostly;
1738+struct cpu_cache_fns cpu_cache __read_only;
1739 #endif
1740 #ifdef CONFIG_OUTER_CACHE
1741-struct outer_cache_fns outer_cache __read_mostly;
1742+struct outer_cache_fns outer_cache __read_only;
1743 EXPORT_SYMBOL(outer_cache);
1744 #endif
1745
1746diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1747index 3647170..065e1cd 100644
1748--- a/arch/arm/kernel/traps.c
1749+++ b/arch/arm/kernel/traps.c
1750@@ -264,6 +264,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1751
1752 static DEFINE_RAW_SPINLOCK(die_lock);
1753
1754+extern void gr_handle_kernel_exploit(void);
1755+
1756 /*
1757 * This function is protected against re-entrancy.
1758 */
1759@@ -296,6 +298,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1760 panic("Fatal exception in interrupt");
1761 if (panic_on_oops)
1762 panic("Fatal exception");
1763+
1764+ gr_handle_kernel_exploit();
1765+
1766 if (ret != NOTIFY_STOP)
1767 do_exit(SIGSEGV);
1768 }
1769diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1770index 66a477a..bee61d3 100644
1771--- a/arch/arm/lib/copy_from_user.S
1772+++ b/arch/arm/lib/copy_from_user.S
1773@@ -16,7 +16,7 @@
1774 /*
1775 * Prototype:
1776 *
1777- * size_t __copy_from_user(void *to, const void *from, size_t n)
1778+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
1779 *
1780 * Purpose:
1781 *
1782@@ -84,11 +84,11 @@
1783
1784 .text
1785
1786-ENTRY(__copy_from_user)
1787+ENTRY(___copy_from_user)
1788
1789 #include "copy_template.S"
1790
1791-ENDPROC(__copy_from_user)
1792+ENDPROC(___copy_from_user)
1793
1794 .pushsection .fixup,"ax"
1795 .align 0
1796diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1797index 6ee2f67..d1cce76 100644
1798--- a/arch/arm/lib/copy_page.S
1799+++ b/arch/arm/lib/copy_page.S
1800@@ -10,6 +10,7 @@
1801 * ASM optimised string functions
1802 */
1803 #include <linux/linkage.h>
1804+#include <linux/const.h>
1805 #include <asm/assembler.h>
1806 #include <asm/asm-offsets.h>
1807 #include <asm/cache.h>
1808diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1809index d066df6..df28194 100644
1810--- a/arch/arm/lib/copy_to_user.S
1811+++ b/arch/arm/lib/copy_to_user.S
1812@@ -16,7 +16,7 @@
1813 /*
1814 * Prototype:
1815 *
1816- * size_t __copy_to_user(void *to, const void *from, size_t n)
1817+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
1818 *
1819 * Purpose:
1820 *
1821@@ -88,11 +88,11 @@
1822 .text
1823
1824 ENTRY(__copy_to_user_std)
1825-WEAK(__copy_to_user)
1826+WEAK(___copy_to_user)
1827
1828 #include "copy_template.S"
1829
1830-ENDPROC(__copy_to_user)
1831+ENDPROC(___copy_to_user)
1832 ENDPROC(__copy_to_user_std)
1833
1834 .pushsection .fixup,"ax"
1835diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1836index 025f742..8432b08 100644
1837--- a/arch/arm/lib/uaccess_with_memcpy.c
1838+++ b/arch/arm/lib/uaccess_with_memcpy.c
1839@@ -104,7 +104,7 @@ out:
1840 }
1841
1842 unsigned long
1843-__copy_to_user(void __user *to, const void *from, unsigned long n)
1844+___copy_to_user(void __user *to, const void *from, unsigned long n)
1845 {
1846 /*
1847 * This test is stubbed out of the main function above to keep
1848diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1849index 2c5d0ed..7d9099c 100644
1850--- a/arch/arm/mach-omap2/board-n8x0.c
1851+++ b/arch/arm/mach-omap2/board-n8x0.c
1852@@ -594,7 +594,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1853 }
1854 #endif
1855
1856-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1857+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1858 .late_init = n8x0_menelaus_late_init,
1859 };
1860
1861diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1862index c3bd834..e81ef02 100644
1863--- a/arch/arm/mm/fault.c
1864+++ b/arch/arm/mm/fault.c
1865@@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1866 }
1867 #endif
1868
1869+#ifdef CONFIG_PAX_PAGEEXEC
1870+ if (fsr & FSR_LNX_PF) {
1871+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1872+ do_group_exit(SIGKILL);
1873+ }
1874+#endif
1875+
1876 tsk->thread.address = addr;
1877 tsk->thread.error_code = fsr;
1878 tsk->thread.trap_no = 14;
1879@@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1880 }
1881 #endif /* CONFIG_MMU */
1882
1883+#ifdef CONFIG_PAX_PAGEEXEC
1884+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1885+{
1886+ long i;
1887+
1888+ printk(KERN_ERR "PAX: bytes at PC: ");
1889+ for (i = 0; i < 20; i++) {
1890+ unsigned char c;
1891+ if (get_user(c, (__force unsigned char __user *)pc+i))
1892+ printk(KERN_CONT "?? ");
1893+ else
1894+ printk(KERN_CONT "%02x ", c);
1895+ }
1896+ printk("\n");
1897+
1898+ printk(KERN_ERR "PAX: bytes at SP-4: ");
1899+ for (i = -1; i < 20; i++) {
1900+ unsigned long c;
1901+ if (get_user(c, (__force unsigned long __user *)sp+i))
1902+ printk(KERN_CONT "???????? ");
1903+ else
1904+ printk(KERN_CONT "%08lx ", c);
1905+ }
1906+ printk("\n");
1907+}
1908+#endif
1909+
1910 /*
1911 * First Level Translation Fault Handler
1912 *
1913@@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1914 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1915 struct siginfo info;
1916
1917+#ifdef CONFIG_PAX_REFCOUNT
1918+ if (fsr_fs(ifsr) == 2) {
1919+ unsigned int bkpt;
1920+
1921+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1922+ current->thread.error_code = ifsr;
1923+ current->thread.trap_no = 0;
1924+ pax_report_refcount_overflow(regs);
1925+ fixup_exception(regs);
1926+ return;
1927+ }
1928+ }
1929+#endif
1930+
1931 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1932 return;
1933
1934diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1935index ce8cb19..3ec539d 100644
1936--- a/arch/arm/mm/mmap.c
1937+++ b/arch/arm/mm/mmap.c
1938@@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1939 if (len > TASK_SIZE)
1940 return -ENOMEM;
1941
1942+#ifdef CONFIG_PAX_RANDMMAP
1943+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1944+#endif
1945+
1946 if (addr) {
1947 if (do_align)
1948 addr = COLOUR_ALIGN(addr, pgoff);
1949@@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1950 addr = PAGE_ALIGN(addr);
1951
1952 vma = find_vma(mm, addr);
1953- if (TASK_SIZE - len >= addr &&
1954- (!vma || addr + len <= vma->vm_start))
1955+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1956 return addr;
1957 }
1958 if (len > mm->cached_hole_size) {
1959- start_addr = addr = mm->free_area_cache;
1960+ start_addr = addr = mm->free_area_cache;
1961 } else {
1962- start_addr = addr = mm->mmap_base;
1963- mm->cached_hole_size = 0;
1964+ start_addr = addr = mm->mmap_base;
1965+ mm->cached_hole_size = 0;
1966 }
1967
1968 full_search:
1969@@ -124,14 +127,14 @@ full_search:
1970 * Start a new search - just in case we missed
1971 * some holes.
1972 */
1973- if (start_addr != TASK_UNMAPPED_BASE) {
1974- start_addr = addr = TASK_UNMAPPED_BASE;
1975+ if (start_addr != mm->mmap_base) {
1976+ start_addr = addr = mm->mmap_base;
1977 mm->cached_hole_size = 0;
1978 goto full_search;
1979 }
1980 return -ENOMEM;
1981 }
1982- if (!vma || addr + len <= vma->vm_start) {
1983+ if (check_heap_stack_gap(vma, addr, len)) {
1984 /*
1985 * Remember the place where we stopped the search:
1986 */
1987@@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1988
1989 if (mmap_is_legacy()) {
1990 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1991+
1992+#ifdef CONFIG_PAX_RANDMMAP
1993+ if (mm->pax_flags & MF_PAX_RANDMMAP)
1994+ mm->mmap_base += mm->delta_mmap;
1995+#endif
1996+
1997 mm->get_unmapped_area = arch_get_unmapped_area;
1998 mm->unmap_area = arch_unmap_area;
1999 } else {
2000 mm->mmap_base = mmap_base(random_factor);
2001+
2002+#ifdef CONFIG_PAX_RANDMMAP
2003+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2004+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2005+#endif
2006+
2007 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2008 mm->unmap_area = arch_unmap_area_topdown;
2009 }
2010diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2011index fd556f7..af2e7d2 100644
2012--- a/arch/arm/plat-orion/include/plat/addr-map.h
2013+++ b/arch/arm/plat-orion/include/plat/addr-map.h
2014@@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2015 value in bridge_virt_base */
2016 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2017 const int win);
2018-};
2019+} __no_const;
2020
2021 /*
2022 * Information needed to setup one address mapping.
2023diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2024index 71a6827..e7fbc23 100644
2025--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2026+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2027@@ -43,7 +43,7 @@ struct samsung_dma_ops {
2028 int (*started)(unsigned ch);
2029 int (*flush)(unsigned ch);
2030 int (*stop)(unsigned ch);
2031-};
2032+} __no_const;
2033
2034 extern void *samsung_dmadev_get_ops(void);
2035 extern void *s3c_dma_get_ops(void);
2036diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2037index 5f28cae..3d23723 100644
2038--- a/arch/arm/plat-samsung/include/plat/ehci.h
2039+++ b/arch/arm/plat-samsung/include/plat/ehci.h
2040@@ -14,7 +14,7 @@
2041 struct s5p_ehci_platdata {
2042 int (*phy_init)(struct platform_device *pdev, int type);
2043 int (*phy_exit)(struct platform_device *pdev, int type);
2044-};
2045+} __no_const;
2046
2047 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2048
2049diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2050index c3a58a1..78fbf54 100644
2051--- a/arch/avr32/include/asm/cache.h
2052+++ b/arch/avr32/include/asm/cache.h
2053@@ -1,8 +1,10 @@
2054 #ifndef __ASM_AVR32_CACHE_H
2055 #define __ASM_AVR32_CACHE_H
2056
2057+#include <linux/const.h>
2058+
2059 #define L1_CACHE_SHIFT 5
2060-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2061+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2062
2063 /*
2064 * Memory returned by kmalloc() may be used for DMA, so we must make
2065diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2066index 3b3159b..425ea94 100644
2067--- a/arch/avr32/include/asm/elf.h
2068+++ b/arch/avr32/include/asm/elf.h
2069@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2070 the loader. We need to make sure that it is out of the way of the program
2071 that it will "exec", and that there is sufficient room for the brk. */
2072
2073-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2074+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2075
2076+#ifdef CONFIG_PAX_ASLR
2077+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2078+
2079+#define PAX_DELTA_MMAP_LEN 15
2080+#define PAX_DELTA_STACK_LEN 15
2081+#endif
2082
2083 /* This yields a mask that user programs can use to figure out what
2084 instruction set this CPU supports. This could be done in user space,
2085diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2086index b7f5c68..556135c 100644
2087--- a/arch/avr32/include/asm/kmap_types.h
2088+++ b/arch/avr32/include/asm/kmap_types.h
2089@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2090 D(11) KM_IRQ1,
2091 D(12) KM_SOFTIRQ0,
2092 D(13) KM_SOFTIRQ1,
2093-D(14) KM_TYPE_NR
2094+D(14) KM_CLEARPAGE,
2095+D(15) KM_TYPE_NR
2096 };
2097
2098 #undef D
2099diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2100index f7040a1..db9f300 100644
2101--- a/arch/avr32/mm/fault.c
2102+++ b/arch/avr32/mm/fault.c
2103@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2104
2105 int exception_trace = 1;
2106
2107+#ifdef CONFIG_PAX_PAGEEXEC
2108+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2109+{
2110+ unsigned long i;
2111+
2112+ printk(KERN_ERR "PAX: bytes at PC: ");
2113+ for (i = 0; i < 20; i++) {
2114+ unsigned char c;
2115+ if (get_user(c, (unsigned char *)pc+i))
2116+ printk(KERN_CONT "???????? ");
2117+ else
2118+ printk(KERN_CONT "%02x ", c);
2119+ }
2120+ printk("\n");
2121+}
2122+#endif
2123+
2124 /*
2125 * This routine handles page faults. It determines the address and the
2126 * problem, and then passes it off to one of the appropriate routines.
2127@@ -156,6 +173,16 @@ bad_area:
2128 up_read(&mm->mmap_sem);
2129
2130 if (user_mode(regs)) {
2131+
2132+#ifdef CONFIG_PAX_PAGEEXEC
2133+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2134+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2135+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2136+ do_group_exit(SIGKILL);
2137+ }
2138+ }
2139+#endif
2140+
2141 if (exception_trace && printk_ratelimit())
2142 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2143 "sp %08lx ecr %lu\n",
2144diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2145index 568885a..f8008df 100644
2146--- a/arch/blackfin/include/asm/cache.h
2147+++ b/arch/blackfin/include/asm/cache.h
2148@@ -7,6 +7,7 @@
2149 #ifndef __ARCH_BLACKFIN_CACHE_H
2150 #define __ARCH_BLACKFIN_CACHE_H
2151
2152+#include <linux/const.h>
2153 #include <linux/linkage.h> /* for asmlinkage */
2154
2155 /*
2156@@ -14,7 +15,7 @@
2157 * Blackfin loads 32 bytes for cache
2158 */
2159 #define L1_CACHE_SHIFT 5
2160-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2161+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2162 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2163
2164 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2165diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2166index aea2718..3639a60 100644
2167--- a/arch/cris/include/arch-v10/arch/cache.h
2168+++ b/arch/cris/include/arch-v10/arch/cache.h
2169@@ -1,8 +1,9 @@
2170 #ifndef _ASM_ARCH_CACHE_H
2171 #define _ASM_ARCH_CACHE_H
2172
2173+#include <linux/const.h>
2174 /* Etrax 100LX have 32-byte cache-lines. */
2175-#define L1_CACHE_BYTES 32
2176 #define L1_CACHE_SHIFT 5
2177+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2178
2179 #endif /* _ASM_ARCH_CACHE_H */
2180diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2181index 7caf25d..ee65ac5 100644
2182--- a/arch/cris/include/arch-v32/arch/cache.h
2183+++ b/arch/cris/include/arch-v32/arch/cache.h
2184@@ -1,11 +1,12 @@
2185 #ifndef _ASM_CRIS_ARCH_CACHE_H
2186 #define _ASM_CRIS_ARCH_CACHE_H
2187
2188+#include <linux/const.h>
2189 #include <arch/hwregs/dma.h>
2190
2191 /* A cache-line is 32 bytes. */
2192-#define L1_CACHE_BYTES 32
2193 #define L1_CACHE_SHIFT 5
2194+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2195
2196 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2197
2198diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2199index b86329d..6709906 100644
2200--- a/arch/frv/include/asm/atomic.h
2201+++ b/arch/frv/include/asm/atomic.h
2202@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2203 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2204 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2205
2206+#define atomic64_read_unchecked(v) atomic64_read(v)
2207+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2208+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2209+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2210+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2211+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2212+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2213+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2214+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2215+
2216 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2217 {
2218 int c, old;
2219diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2220index 2797163..c2a401d 100644
2221--- a/arch/frv/include/asm/cache.h
2222+++ b/arch/frv/include/asm/cache.h
2223@@ -12,10 +12,11 @@
2224 #ifndef __ASM_CACHE_H
2225 #define __ASM_CACHE_H
2226
2227+#include <linux/const.h>
2228
2229 /* bytes per L1 cache line */
2230 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2231-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2232+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2233
2234 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2235 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2236diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2237index f8e16b2..c73ff79 100644
2238--- a/arch/frv/include/asm/kmap_types.h
2239+++ b/arch/frv/include/asm/kmap_types.h
2240@@ -23,6 +23,7 @@ enum km_type {
2241 KM_IRQ1,
2242 KM_SOFTIRQ0,
2243 KM_SOFTIRQ1,
2244+ KM_CLEARPAGE,
2245 KM_TYPE_NR
2246 };
2247
2248diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2249index 385fd30..6c3d97e 100644
2250--- a/arch/frv/mm/elf-fdpic.c
2251+++ b/arch/frv/mm/elf-fdpic.c
2252@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2253 if (addr) {
2254 addr = PAGE_ALIGN(addr);
2255 vma = find_vma(current->mm, addr);
2256- if (TASK_SIZE - len >= addr &&
2257- (!vma || addr + len <= vma->vm_start))
2258+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2259 goto success;
2260 }
2261
2262@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2263 for (; vma; vma = vma->vm_next) {
2264 if (addr > limit)
2265 break;
2266- if (addr + len <= vma->vm_start)
2267+ if (check_heap_stack_gap(vma, addr, len))
2268 goto success;
2269 addr = vma->vm_end;
2270 }
2271@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2272 for (; vma; vma = vma->vm_next) {
2273 if (addr > limit)
2274 break;
2275- if (addr + len <= vma->vm_start)
2276+ if (check_heap_stack_gap(vma, addr, len))
2277 goto success;
2278 addr = vma->vm_end;
2279 }
2280diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2281index c635028..6d9445a 100644
2282--- a/arch/h8300/include/asm/cache.h
2283+++ b/arch/h8300/include/asm/cache.h
2284@@ -1,8 +1,10 @@
2285 #ifndef __ARCH_H8300_CACHE_H
2286 #define __ARCH_H8300_CACHE_H
2287
2288+#include <linux/const.h>
2289+
2290 /* bytes per L1 cache line */
2291-#define L1_CACHE_BYTES 4
2292+#define L1_CACHE_BYTES _AC(4,UL)
2293
2294 /* m68k-elf-gcc 2.95.2 doesn't like these */
2295
2296diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2297index 0f01de2..d37d309 100644
2298--- a/arch/hexagon/include/asm/cache.h
2299+++ b/arch/hexagon/include/asm/cache.h
2300@@ -21,9 +21,11 @@
2301 #ifndef __ASM_CACHE_H
2302 #define __ASM_CACHE_H
2303
2304+#include <linux/const.h>
2305+
2306 /* Bytes per L1 cache line */
2307-#define L1_CACHE_SHIFT (5)
2308-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2309+#define L1_CACHE_SHIFT 5
2310+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2311
2312 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2313 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2314diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2315index 7d91166..88ab87e 100644
2316--- a/arch/ia64/include/asm/atomic.h
2317+++ b/arch/ia64/include/asm/atomic.h
2318@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2319 #define atomic64_inc(v) atomic64_add(1, (v))
2320 #define atomic64_dec(v) atomic64_sub(1, (v))
2321
2322+#define atomic64_read_unchecked(v) atomic64_read(v)
2323+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2324+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2325+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2326+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2327+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2328+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2329+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2330+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2331+
2332 /* Atomic operations are already serializing */
2333 #define smp_mb__before_atomic_dec() barrier()
2334 #define smp_mb__after_atomic_dec() barrier()
2335diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2336index 988254a..e1ee885 100644
2337--- a/arch/ia64/include/asm/cache.h
2338+++ b/arch/ia64/include/asm/cache.h
2339@@ -1,6 +1,7 @@
2340 #ifndef _ASM_IA64_CACHE_H
2341 #define _ASM_IA64_CACHE_H
2342
2343+#include <linux/const.h>
2344
2345 /*
2346 * Copyright (C) 1998-2000 Hewlett-Packard Co
2347@@ -9,7 +10,7 @@
2348
2349 /* Bytes per L1 (data) cache line. */
2350 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2351-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2352+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2353
2354 #ifdef CONFIG_SMP
2355 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2356diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2357index b5298eb..67c6e62 100644
2358--- a/arch/ia64/include/asm/elf.h
2359+++ b/arch/ia64/include/asm/elf.h
2360@@ -42,6 +42,13 @@
2361 */
2362 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2363
2364+#ifdef CONFIG_PAX_ASLR
2365+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2366+
2367+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2368+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2369+#endif
2370+
2371 #define PT_IA_64_UNWIND 0x70000001
2372
2373 /* IA-64 relocations: */
2374diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2375index 96a8d92..617a1cf 100644
2376--- a/arch/ia64/include/asm/pgalloc.h
2377+++ b/arch/ia64/include/asm/pgalloc.h
2378@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2379 pgd_val(*pgd_entry) = __pa(pud);
2380 }
2381
2382+static inline void
2383+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2384+{
2385+ pgd_populate(mm, pgd_entry, pud);
2386+}
2387+
2388 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2389 {
2390 return quicklist_alloc(0, GFP_KERNEL, NULL);
2391@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2392 pud_val(*pud_entry) = __pa(pmd);
2393 }
2394
2395+static inline void
2396+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2397+{
2398+ pud_populate(mm, pud_entry, pmd);
2399+}
2400+
2401 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2402 {
2403 return quicklist_alloc(0, GFP_KERNEL, NULL);
2404diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2405index 815810c..d60bd4c 100644
2406--- a/arch/ia64/include/asm/pgtable.h
2407+++ b/arch/ia64/include/asm/pgtable.h
2408@@ -12,7 +12,7 @@
2409 * David Mosberger-Tang <davidm@hpl.hp.com>
2410 */
2411
2412-
2413+#include <linux/const.h>
2414 #include <asm/mman.h>
2415 #include <asm/page.h>
2416 #include <asm/processor.h>
2417@@ -142,6 +142,17 @@
2418 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2419 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2420 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2421+
2422+#ifdef CONFIG_PAX_PAGEEXEC
2423+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2424+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2425+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2426+#else
2427+# define PAGE_SHARED_NOEXEC PAGE_SHARED
2428+# define PAGE_READONLY_NOEXEC PAGE_READONLY
2429+# define PAGE_COPY_NOEXEC PAGE_COPY
2430+#endif
2431+
2432 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2433 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2434 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2435diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2436index 54ff557..70c88b7 100644
2437--- a/arch/ia64/include/asm/spinlock.h
2438+++ b/arch/ia64/include/asm/spinlock.h
2439@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2440 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2441
2442 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2443- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2444+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2445 }
2446
2447 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2448diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2449index 449c8c0..432a3d2 100644
2450--- a/arch/ia64/include/asm/uaccess.h
2451+++ b/arch/ia64/include/asm/uaccess.h
2452@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2453 const void *__cu_from = (from); \
2454 long __cu_len = (n); \
2455 \
2456- if (__access_ok(__cu_to, __cu_len, get_fs())) \
2457+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2458 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2459 __cu_len; \
2460 })
2461@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2462 long __cu_len = (n); \
2463 \
2464 __chk_user_ptr(__cu_from); \
2465- if (__access_ok(__cu_from, __cu_len, get_fs())) \
2466+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2467 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2468 __cu_len; \
2469 })
2470diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2471index 24603be..948052d 100644
2472--- a/arch/ia64/kernel/module.c
2473+++ b/arch/ia64/kernel/module.c
2474@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2475 void
2476 module_free (struct module *mod, void *module_region)
2477 {
2478- if (mod && mod->arch.init_unw_table &&
2479- module_region == mod->module_init) {
2480+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2481 unw_remove_unwind_table(mod->arch.init_unw_table);
2482 mod->arch.init_unw_table = NULL;
2483 }
2484@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2485 }
2486
2487 static inline int
2488+in_init_rx (const struct module *mod, uint64_t addr)
2489+{
2490+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2491+}
2492+
2493+static inline int
2494+in_init_rw (const struct module *mod, uint64_t addr)
2495+{
2496+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2497+}
2498+
2499+static inline int
2500 in_init (const struct module *mod, uint64_t addr)
2501 {
2502- return addr - (uint64_t) mod->module_init < mod->init_size;
2503+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2504+}
2505+
2506+static inline int
2507+in_core_rx (const struct module *mod, uint64_t addr)
2508+{
2509+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2510+}
2511+
2512+static inline int
2513+in_core_rw (const struct module *mod, uint64_t addr)
2514+{
2515+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2516 }
2517
2518 static inline int
2519 in_core (const struct module *mod, uint64_t addr)
2520 {
2521- return addr - (uint64_t) mod->module_core < mod->core_size;
2522+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2523 }
2524
2525 static inline int
2526@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2527 break;
2528
2529 case RV_BDREL:
2530- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2531+ if (in_init_rx(mod, val))
2532+ val -= (uint64_t) mod->module_init_rx;
2533+ else if (in_init_rw(mod, val))
2534+ val -= (uint64_t) mod->module_init_rw;
2535+ else if (in_core_rx(mod, val))
2536+ val -= (uint64_t) mod->module_core_rx;
2537+ else if (in_core_rw(mod, val))
2538+ val -= (uint64_t) mod->module_core_rw;
2539 break;
2540
2541 case RV_LTV:
2542@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2543 * addresses have been selected...
2544 */
2545 uint64_t gp;
2546- if (mod->core_size > MAX_LTOFF)
2547+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2548 /*
2549 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2550 * at the end of the module.
2551 */
2552- gp = mod->core_size - MAX_LTOFF / 2;
2553+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2554 else
2555- gp = mod->core_size / 2;
2556- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2557+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2558+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2559 mod->arch.gp = gp;
2560 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2561 }
2562diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2563index d9439ef..b9a4303 100644
2564--- a/arch/ia64/kernel/sys_ia64.c
2565+++ b/arch/ia64/kernel/sys_ia64.c
2566@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2567 if (REGION_NUMBER(addr) == RGN_HPAGE)
2568 addr = 0;
2569 #endif
2570+
2571+#ifdef CONFIG_PAX_RANDMMAP
2572+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2573+ addr = mm->free_area_cache;
2574+ else
2575+#endif
2576+
2577 if (!addr)
2578 addr = mm->free_area_cache;
2579
2580@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2581 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2582 /* At this point: (!vma || addr < vma->vm_end). */
2583 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2584- if (start_addr != TASK_UNMAPPED_BASE) {
2585+ if (start_addr != mm->mmap_base) {
2586 /* Start a new search --- just in case we missed some holes. */
2587- addr = TASK_UNMAPPED_BASE;
2588+ addr = mm->mmap_base;
2589 goto full_search;
2590 }
2591 return -ENOMEM;
2592 }
2593- if (!vma || addr + len <= vma->vm_start) {
2594+ if (check_heap_stack_gap(vma, addr, len)) {
2595 /* Remember the address where we stopped this search: */
2596 mm->free_area_cache = addr + len;
2597 return addr;
2598diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2599index 0ccb28f..8992469 100644
2600--- a/arch/ia64/kernel/vmlinux.lds.S
2601+++ b/arch/ia64/kernel/vmlinux.lds.S
2602@@ -198,7 +198,7 @@ SECTIONS {
2603 /* Per-cpu data: */
2604 . = ALIGN(PERCPU_PAGE_SIZE);
2605 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2606- __phys_per_cpu_start = __per_cpu_load;
2607+ __phys_per_cpu_start = per_cpu_load;
2608 /*
2609 * ensure percpu data fits
2610 * into percpu page size
2611diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2612index 02d29c2..ea893df 100644
2613--- a/arch/ia64/mm/fault.c
2614+++ b/arch/ia64/mm/fault.c
2615@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2616 return pte_present(pte);
2617 }
2618
2619+#ifdef CONFIG_PAX_PAGEEXEC
2620+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2621+{
2622+ unsigned long i;
2623+
2624+ printk(KERN_ERR "PAX: bytes at PC: ");
2625+ for (i = 0; i < 8; i++) {
2626+ unsigned int c;
2627+ if (get_user(c, (unsigned int *)pc+i))
2628+ printk(KERN_CONT "???????? ");
2629+ else
2630+ printk(KERN_CONT "%08x ", c);
2631+ }
2632+ printk("\n");
2633+}
2634+#endif
2635+
2636 void __kprobes
2637 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2638 {
2639@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2640 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2641 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2642
2643- if ((vma->vm_flags & mask) != mask)
2644+ if ((vma->vm_flags & mask) != mask) {
2645+
2646+#ifdef CONFIG_PAX_PAGEEXEC
2647+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2648+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2649+ goto bad_area;
2650+
2651+ up_read(&mm->mmap_sem);
2652+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2653+ do_group_exit(SIGKILL);
2654+ }
2655+#endif
2656+
2657 goto bad_area;
2658
2659+ }
2660+
2661 /*
2662 * If for any reason at all we couldn't handle the fault, make
2663 * sure we exit gracefully rather than endlessly redo the
2664diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2665index 5ca674b..e0e1b70 100644
2666--- a/arch/ia64/mm/hugetlbpage.c
2667+++ b/arch/ia64/mm/hugetlbpage.c
2668@@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2669 /* At this point: (!vmm || addr < vmm->vm_end). */
2670 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2671 return -ENOMEM;
2672- if (!vmm || (addr + len) <= vmm->vm_start)
2673+ if (check_heap_stack_gap(vmm, addr, len))
2674 return addr;
2675 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2676 }
2677diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2678index 0eab454..bd794f2 100644
2679--- a/arch/ia64/mm/init.c
2680+++ b/arch/ia64/mm/init.c
2681@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2682 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2683 vma->vm_end = vma->vm_start + PAGE_SIZE;
2684 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2685+
2686+#ifdef CONFIG_PAX_PAGEEXEC
2687+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2688+ vma->vm_flags &= ~VM_EXEC;
2689+
2690+#ifdef CONFIG_PAX_MPROTECT
2691+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
2692+ vma->vm_flags &= ~VM_MAYEXEC;
2693+#endif
2694+
2695+ }
2696+#endif
2697+
2698 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2699 down_write(&current->mm->mmap_sem);
2700 if (insert_vm_struct(current->mm, vma)) {
2701diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2702index 40b3ee9..8c2c112 100644
2703--- a/arch/m32r/include/asm/cache.h
2704+++ b/arch/m32r/include/asm/cache.h
2705@@ -1,8 +1,10 @@
2706 #ifndef _ASM_M32R_CACHE_H
2707 #define _ASM_M32R_CACHE_H
2708
2709+#include <linux/const.h>
2710+
2711 /* L1 cache line size */
2712 #define L1_CACHE_SHIFT 4
2713-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2714+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2715
2716 #endif /* _ASM_M32R_CACHE_H */
2717diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2718index 82abd15..d95ae5d 100644
2719--- a/arch/m32r/lib/usercopy.c
2720+++ b/arch/m32r/lib/usercopy.c
2721@@ -14,6 +14,9 @@
2722 unsigned long
2723 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2724 {
2725+ if ((long)n < 0)
2726+ return n;
2727+
2728 prefetch(from);
2729 if (access_ok(VERIFY_WRITE, to, n))
2730 __copy_user(to,from,n);
2731@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2732 unsigned long
2733 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2734 {
2735+ if ((long)n < 0)
2736+ return n;
2737+
2738 prefetchw(to);
2739 if (access_ok(VERIFY_READ, from, n))
2740 __copy_user_zeroing(to,from,n);
2741diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2742index 0395c51..5f26031 100644
2743--- a/arch/m68k/include/asm/cache.h
2744+++ b/arch/m68k/include/asm/cache.h
2745@@ -4,9 +4,11 @@
2746 #ifndef __ARCH_M68K_CACHE_H
2747 #define __ARCH_M68K_CACHE_H
2748
2749+#include <linux/const.h>
2750+
2751 /* bytes per L1 cache line */
2752 #define L1_CACHE_SHIFT 4
2753-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2754+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2755
2756 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2757
2758diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2759index 4efe96a..60e8699 100644
2760--- a/arch/microblaze/include/asm/cache.h
2761+++ b/arch/microblaze/include/asm/cache.h
2762@@ -13,11 +13,12 @@
2763 #ifndef _ASM_MICROBLAZE_CACHE_H
2764 #define _ASM_MICROBLAZE_CACHE_H
2765
2766+#include <linux/const.h>
2767 #include <asm/registers.h>
2768
2769 #define L1_CACHE_SHIFT 5
2770 /* word-granular cache in microblaze */
2771-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2772+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2773
2774 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2775
2776diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2777index 3f4c5cb..3439c6e 100644
2778--- a/arch/mips/include/asm/atomic.h
2779+++ b/arch/mips/include/asm/atomic.h
2780@@ -21,6 +21,10 @@
2781 #include <asm/cmpxchg.h>
2782 #include <asm/war.h>
2783
2784+#ifdef CONFIG_GENERIC_ATOMIC64
2785+#include <asm-generic/atomic64.h>
2786+#endif
2787+
2788 #define ATOMIC_INIT(i) { (i) }
2789
2790 /*
2791@@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2792 */
2793 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2794
2795+#define atomic64_read_unchecked(v) atomic64_read(v)
2796+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2797+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2798+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2799+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2800+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2801+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2802+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2803+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2804+
2805 #endif /* CONFIG_64BIT */
2806
2807 /*
2808diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2809index b4db69f..8f3b093 100644
2810--- a/arch/mips/include/asm/cache.h
2811+++ b/arch/mips/include/asm/cache.h
2812@@ -9,10 +9,11 @@
2813 #ifndef _ASM_CACHE_H
2814 #define _ASM_CACHE_H
2815
2816+#include <linux/const.h>
2817 #include <kmalloc.h>
2818
2819 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2820-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2821+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2822
2823 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2824 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2825diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2826index 455c0ac..ad65fbe 100644
2827--- a/arch/mips/include/asm/elf.h
2828+++ b/arch/mips/include/asm/elf.h
2829@@ -372,13 +372,16 @@ extern const char *__elf_platform;
2830 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2831 #endif
2832
2833+#ifdef CONFIG_PAX_ASLR
2834+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2835+
2836+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2837+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2838+#endif
2839+
2840 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2841 struct linux_binprm;
2842 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2843 int uses_interp);
2844
2845-struct mm_struct;
2846-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2847-#define arch_randomize_brk arch_randomize_brk
2848-
2849 #endif /* _ASM_ELF_H */
2850diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2851index c1f6afa..38cc6e9 100644
2852--- a/arch/mips/include/asm/exec.h
2853+++ b/arch/mips/include/asm/exec.h
2854@@ -12,6 +12,6 @@
2855 #ifndef _ASM_EXEC_H
2856 #define _ASM_EXEC_H
2857
2858-extern unsigned long arch_align_stack(unsigned long sp);
2859+#define arch_align_stack(x) ((x) & ~0xfUL)
2860
2861 #endif /* _ASM_EXEC_H */
2862diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2863index da9bd7d..91aa7ab 100644
2864--- a/arch/mips/include/asm/page.h
2865+++ b/arch/mips/include/asm/page.h
2866@@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2867 #ifdef CONFIG_CPU_MIPS32
2868 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2869 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2870- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2871+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2872 #else
2873 typedef struct { unsigned long long pte; } pte_t;
2874 #define pte_val(x) ((x).pte)
2875diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2876index 881d18b..cea38bc 100644
2877--- a/arch/mips/include/asm/pgalloc.h
2878+++ b/arch/mips/include/asm/pgalloc.h
2879@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2880 {
2881 set_pud(pud, __pud((unsigned long)pmd));
2882 }
2883+
2884+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2885+{
2886+ pud_populate(mm, pud, pmd);
2887+}
2888 #endif
2889
2890 /*
2891diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2892index ca97e0e..cd08920 100644
2893--- a/arch/mips/include/asm/thread_info.h
2894+++ b/arch/mips/include/asm/thread_info.h
2895@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2896 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2897 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2898 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2899+/* li takes a 32bit immediate */
2900+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2901 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2902
2903 #ifdef CONFIG_MIPS32_O32
2904@@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2905 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2906 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2907 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2908+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2909+
2910+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2911
2912 /* work to do in syscall_trace_leave() */
2913-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2914+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2915
2916 /* work to do on interrupt/exception return */
2917 #define _TIF_WORK_MASK (0x0000ffef & \
2918 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2919 /* work to do on any return to u-space */
2920-#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2921+#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2922
2923 #endif /* __KERNEL__ */
2924
2925diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2926index 9fdd8bc..4bd7f1a 100644
2927--- a/arch/mips/kernel/binfmt_elfn32.c
2928+++ b/arch/mips/kernel/binfmt_elfn32.c
2929@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2930 #undef ELF_ET_DYN_BASE
2931 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2932
2933+#ifdef CONFIG_PAX_ASLR
2934+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2935+
2936+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2937+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2938+#endif
2939+
2940 #include <asm/processor.h>
2941 #include <linux/module.h>
2942 #include <linux/elfcore.h>
2943diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2944index ff44823..97f8906 100644
2945--- a/arch/mips/kernel/binfmt_elfo32.c
2946+++ b/arch/mips/kernel/binfmt_elfo32.c
2947@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2948 #undef ELF_ET_DYN_BASE
2949 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2950
2951+#ifdef CONFIG_PAX_ASLR
2952+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2953+
2954+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2955+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2956+#endif
2957+
2958 #include <asm/processor.h>
2959
2960 /*
2961diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2962index e9a5fd7..378809a 100644
2963--- a/arch/mips/kernel/process.c
2964+++ b/arch/mips/kernel/process.c
2965@@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2966 out:
2967 return pc;
2968 }
2969-
2970-/*
2971- * Don't forget that the stack pointer must be aligned on a 8 bytes
2972- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2973- */
2974-unsigned long arch_align_stack(unsigned long sp)
2975-{
2976- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2977- sp -= get_random_int() & ~PAGE_MASK;
2978-
2979- return sp & ALMASK;
2980-}
2981diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2982index 4812c6d..2069554 100644
2983--- a/arch/mips/kernel/ptrace.c
2984+++ b/arch/mips/kernel/ptrace.c
2985@@ -528,6 +528,10 @@ static inline int audit_arch(void)
2986 return arch;
2987 }
2988
2989+#ifdef CONFIG_GRKERNSEC_SETXID
2990+extern void gr_delayed_cred_worker(void);
2991+#endif
2992+
2993 /*
2994 * Notification of system call entry/exit
2995 * - triggered by current->work.syscall_trace
2996@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
2997 /* do the secure computing check first */
2998 secure_computing_strict(regs->regs[2]);
2999
3000+#ifdef CONFIG_GRKERNSEC_SETXID
3001+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3002+ gr_delayed_cred_worker();
3003+#endif
3004+
3005 if (!(current->ptrace & PT_PTRACED))
3006 goto out;
3007
3008diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3009index a632bc1..0b77c7c 100644
3010--- a/arch/mips/kernel/scall32-o32.S
3011+++ b/arch/mips/kernel/scall32-o32.S
3012@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3013
3014 stack_done:
3015 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3016- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3017+ li t1, _TIF_SYSCALL_WORK
3018 and t0, t1
3019 bnez t0, syscall_trace_entry # -> yes
3020
3021diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3022index 3b5a5e9..e1ee86d 100644
3023--- a/arch/mips/kernel/scall64-64.S
3024+++ b/arch/mips/kernel/scall64-64.S
3025@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3026
3027 sd a3, PT_R26(sp) # save a3 for syscall restarting
3028
3029- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3030+ li t1, _TIF_SYSCALL_WORK
3031 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3032 and t0, t1, t0
3033 bnez t0, syscall_trace_entry
3034diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3035index 6be6f70..1859577 100644
3036--- a/arch/mips/kernel/scall64-n32.S
3037+++ b/arch/mips/kernel/scall64-n32.S
3038@@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3039
3040 sd a3, PT_R26(sp) # save a3 for syscall restarting
3041
3042- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3043+ li t1, _TIF_SYSCALL_WORK
3044 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3045 and t0, t1, t0
3046 bnez t0, n32_syscall_trace_entry
3047diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3048index 5422855..74e63a3 100644
3049--- a/arch/mips/kernel/scall64-o32.S
3050+++ b/arch/mips/kernel/scall64-o32.S
3051@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3052 PTR 4b, bad_stack
3053 .previous
3054
3055- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3056+ li t1, _TIF_SYSCALL_WORK
3057 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3058 and t0, t1, t0
3059 bnez t0, trace_a_syscall
3060diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3061index c14f6df..537e729 100644
3062--- a/arch/mips/mm/fault.c
3063+++ b/arch/mips/mm/fault.c
3064@@ -27,6 +27,23 @@
3065 #include <asm/highmem.h> /* For VMALLOC_END */
3066 #include <linux/kdebug.h>
3067
3068+#ifdef CONFIG_PAX_PAGEEXEC
3069+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3070+{
3071+ unsigned long i;
3072+
3073+ printk(KERN_ERR "PAX: bytes at PC: ");
3074+ for (i = 0; i < 5; i++) {
3075+ unsigned int c;
3076+ if (get_user(c, (unsigned int *)pc+i))
3077+ printk(KERN_CONT "???????? ");
3078+ else
3079+ printk(KERN_CONT "%08x ", c);
3080+ }
3081+ printk("\n");
3082+}
3083+#endif
3084+
3085 /*
3086 * This routine handles page faults. It determines the address,
3087 * and the problem, and then passes it off to one of the appropriate
3088diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3089index 302d779..7d35bf8 100644
3090--- a/arch/mips/mm/mmap.c
3091+++ b/arch/mips/mm/mmap.c
3092@@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3093 do_color_align = 1;
3094
3095 /* requesting a specific address */
3096+
3097+#ifdef CONFIG_PAX_RANDMMAP
3098+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3099+#endif
3100+
3101 if (addr) {
3102 if (do_color_align)
3103 addr = COLOUR_ALIGN(addr, pgoff);
3104@@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3105 addr = PAGE_ALIGN(addr);
3106
3107 vma = find_vma(mm, addr);
3108- if (TASK_SIZE - len >= addr &&
3109- (!vma || addr + len <= vma->vm_start))
3110+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3111 return addr;
3112 }
3113
3114@@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3115 /* At this point: (!vma || addr < vma->vm_end). */
3116 if (TASK_SIZE - len < addr)
3117 return -ENOMEM;
3118- if (!vma || addr + len <= vma->vm_start)
3119+ if (check_heap_stack_gap(vmm, addr, len))
3120 return addr;
3121 addr = vma->vm_end;
3122 if (do_color_align)
3123@@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3124 /* make sure it can fit in the remaining address space */
3125 if (likely(addr > len)) {
3126 vma = find_vma(mm, addr - len);
3127- if (!vma || addr <= vma->vm_start) {
3128+ if (check_heap_stack_gap(vmm, addr - len, len))
3129 /* cache the address as a hint for next time */
3130 return mm->free_area_cache = addr - len;
3131 }
3132@@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3133 * return with success:
3134 */
3135 vma = find_vma(mm, addr);
3136- if (likely(!vma || addr + len <= vma->vm_start)) {
3137+ if (check_heap_stack_gap(vmm, addr, len)) {
3138 /* cache the address as a hint for next time */
3139 return mm->free_area_cache = addr;
3140 }
3141@@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3142 mm->unmap_area = arch_unmap_area_topdown;
3143 }
3144 }
3145-
3146-static inline unsigned long brk_rnd(void)
3147-{
3148- unsigned long rnd = get_random_int();
3149-
3150- rnd = rnd << PAGE_SHIFT;
3151- /* 8MB for 32bit, 256MB for 64bit */
3152- if (TASK_IS_32BIT_ADDR)
3153- rnd = rnd & 0x7ffffful;
3154- else
3155- rnd = rnd & 0xffffffful;
3156-
3157- return rnd;
3158-}
3159-
3160-unsigned long arch_randomize_brk(struct mm_struct *mm)
3161-{
3162- unsigned long base = mm->brk;
3163- unsigned long ret;
3164-
3165- ret = PAGE_ALIGN(base + brk_rnd());
3166-
3167- if (ret < mm->brk)
3168- return mm->brk;
3169-
3170- return ret;
3171-}
3172diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3173index 967d144..db12197 100644
3174--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3175+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3176@@ -11,12 +11,14 @@
3177 #ifndef _ASM_PROC_CACHE_H
3178 #define _ASM_PROC_CACHE_H
3179
3180+#include <linux/const.h>
3181+
3182 /* L1 cache */
3183
3184 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3185 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3186-#define L1_CACHE_BYTES 16 /* bytes per entry */
3187 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3188+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3189 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3190
3191 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3192diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3193index bcb5df2..84fabd2 100644
3194--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3195+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3196@@ -16,13 +16,15 @@
3197 #ifndef _ASM_PROC_CACHE_H
3198 #define _ASM_PROC_CACHE_H
3199
3200+#include <linux/const.h>
3201+
3202 /*
3203 * L1 cache
3204 */
3205 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3206 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3207-#define L1_CACHE_BYTES 32 /* bytes per entry */
3208 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3209+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3210 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3211
3212 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3213diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3214index 4ce7a01..449202a 100644
3215--- a/arch/openrisc/include/asm/cache.h
3216+++ b/arch/openrisc/include/asm/cache.h
3217@@ -19,11 +19,13 @@
3218 #ifndef __ASM_OPENRISC_CACHE_H
3219 #define __ASM_OPENRISC_CACHE_H
3220
3221+#include <linux/const.h>
3222+
3223 /* FIXME: How can we replace these with values from the CPU...
3224 * they shouldn't be hard-coded!
3225 */
3226
3227-#define L1_CACHE_BYTES 16
3228 #define L1_CACHE_SHIFT 4
3229+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3230
3231 #endif /* __ASM_OPENRISC_CACHE_H */
3232diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3233index 6c6defc..d30653d 100644
3234--- a/arch/parisc/include/asm/atomic.h
3235+++ b/arch/parisc/include/asm/atomic.h
3236@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3237
3238 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3239
3240+#define atomic64_read_unchecked(v) atomic64_read(v)
3241+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3242+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3243+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3244+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3245+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3246+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3247+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3248+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3249+
3250 #endif /* !CONFIG_64BIT */
3251
3252
3253diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3254index 47f11c7..3420df2 100644
3255--- a/arch/parisc/include/asm/cache.h
3256+++ b/arch/parisc/include/asm/cache.h
3257@@ -5,6 +5,7 @@
3258 #ifndef __ARCH_PARISC_CACHE_H
3259 #define __ARCH_PARISC_CACHE_H
3260
3261+#include <linux/const.h>
3262
3263 /*
3264 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3265@@ -15,13 +16,13 @@
3266 * just ruin performance.
3267 */
3268 #ifdef CONFIG_PA20
3269-#define L1_CACHE_BYTES 64
3270 #define L1_CACHE_SHIFT 6
3271 #else
3272-#define L1_CACHE_BYTES 32
3273 #define L1_CACHE_SHIFT 5
3274 #endif
3275
3276+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3277+
3278 #ifndef __ASSEMBLY__
3279
3280 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3281diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3282index 19f6cb1..6c78cf2 100644
3283--- a/arch/parisc/include/asm/elf.h
3284+++ b/arch/parisc/include/asm/elf.h
3285@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3286
3287 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3288
3289+#ifdef CONFIG_PAX_ASLR
3290+#define PAX_ELF_ET_DYN_BASE 0x10000UL
3291+
3292+#define PAX_DELTA_MMAP_LEN 16
3293+#define PAX_DELTA_STACK_LEN 16
3294+#endif
3295+
3296 /* This yields a mask that user programs can use to figure out what
3297 instruction set this CPU supports. This could be done in user space,
3298 but it's not easy, and we've already done it here. */
3299diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3300index fc987a1..6e068ef 100644
3301--- a/arch/parisc/include/asm/pgalloc.h
3302+++ b/arch/parisc/include/asm/pgalloc.h
3303@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3304 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3305 }
3306
3307+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3308+{
3309+ pgd_populate(mm, pgd, pmd);
3310+}
3311+
3312 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3313 {
3314 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3315@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3316 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3317 #define pmd_free(mm, x) do { } while (0)
3318 #define pgd_populate(mm, pmd, pte) BUG()
3319+#define pgd_populate_kernel(mm, pmd, pte) BUG()
3320
3321 #endif
3322
3323diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3324index ee99f23..802b0a1 100644
3325--- a/arch/parisc/include/asm/pgtable.h
3326+++ b/arch/parisc/include/asm/pgtable.h
3327@@ -212,6 +212,17 @@ struct vm_area_struct;
3328 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3329 #define PAGE_COPY PAGE_EXECREAD
3330 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3331+
3332+#ifdef CONFIG_PAX_PAGEEXEC
3333+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3334+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3335+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3336+#else
3337+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3338+# define PAGE_COPY_NOEXEC PAGE_COPY
3339+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3340+#endif
3341+
3342 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3343 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3344 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3345diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3346index 4ba2c93..f5e3974 100644
3347--- a/arch/parisc/include/asm/uaccess.h
3348+++ b/arch/parisc/include/asm/uaccess.h
3349@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3350 const void __user *from,
3351 unsigned long n)
3352 {
3353- int sz = __compiletime_object_size(to);
3354+ size_t sz = __compiletime_object_size(to);
3355 int ret = -EFAULT;
3356
3357- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3358+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3359 ret = __copy_from_user(to, from, n);
3360 else
3361 copy_from_user_overflow();
3362diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3363index 5e34ccf..672bc9c 100644
3364--- a/arch/parisc/kernel/module.c
3365+++ b/arch/parisc/kernel/module.c
3366@@ -98,16 +98,38 @@
3367
3368 /* three functions to determine where in the module core
3369 * or init pieces the location is */
3370+static inline int in_init_rx(struct module *me, void *loc)
3371+{
3372+ return (loc >= me->module_init_rx &&
3373+ loc < (me->module_init_rx + me->init_size_rx));
3374+}
3375+
3376+static inline int in_init_rw(struct module *me, void *loc)
3377+{
3378+ return (loc >= me->module_init_rw &&
3379+ loc < (me->module_init_rw + me->init_size_rw));
3380+}
3381+
3382 static inline int in_init(struct module *me, void *loc)
3383 {
3384- return (loc >= me->module_init &&
3385- loc <= (me->module_init + me->init_size));
3386+ return in_init_rx(me, loc) || in_init_rw(me, loc);
3387+}
3388+
3389+static inline int in_core_rx(struct module *me, void *loc)
3390+{
3391+ return (loc >= me->module_core_rx &&
3392+ loc < (me->module_core_rx + me->core_size_rx));
3393+}
3394+
3395+static inline int in_core_rw(struct module *me, void *loc)
3396+{
3397+ return (loc >= me->module_core_rw &&
3398+ loc < (me->module_core_rw + me->core_size_rw));
3399 }
3400
3401 static inline int in_core(struct module *me, void *loc)
3402 {
3403- return (loc >= me->module_core &&
3404- loc <= (me->module_core + me->core_size));
3405+ return in_core_rx(me, loc) || in_core_rw(me, loc);
3406 }
3407
3408 static inline int in_local(struct module *me, void *loc)
3409@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3410 }
3411
3412 /* align things a bit */
3413- me->core_size = ALIGN(me->core_size, 16);
3414- me->arch.got_offset = me->core_size;
3415- me->core_size += gots * sizeof(struct got_entry);
3416+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3417+ me->arch.got_offset = me->core_size_rw;
3418+ me->core_size_rw += gots * sizeof(struct got_entry);
3419
3420- me->core_size = ALIGN(me->core_size, 16);
3421- me->arch.fdesc_offset = me->core_size;
3422- me->core_size += fdescs * sizeof(Elf_Fdesc);
3423+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3424+ me->arch.fdesc_offset = me->core_size_rw;
3425+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3426
3427 me->arch.got_max = gots;
3428 me->arch.fdesc_max = fdescs;
3429@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3430
3431 BUG_ON(value == 0);
3432
3433- got = me->module_core + me->arch.got_offset;
3434+ got = me->module_core_rw + me->arch.got_offset;
3435 for (i = 0; got[i].addr; i++)
3436 if (got[i].addr == value)
3437 goto out;
3438@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3439 #ifdef CONFIG_64BIT
3440 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3441 {
3442- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3443+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3444
3445 if (!value) {
3446 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3447@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3448
3449 /* Create new one */
3450 fdesc->addr = value;
3451- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3452+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3453 return (Elf_Addr)fdesc;
3454 }
3455 #endif /* CONFIG_64BIT */
3456@@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3457
3458 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3459 end = table + sechdrs[me->arch.unwind_section].sh_size;
3460- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3461+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3462
3463 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3464 me->arch.unwind_section, table, end, gp);
3465diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3466index c9b9322..02d8940 100644
3467--- a/arch/parisc/kernel/sys_parisc.c
3468+++ b/arch/parisc/kernel/sys_parisc.c
3469@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3470 /* At this point: (!vma || addr < vma->vm_end). */
3471 if (TASK_SIZE - len < addr)
3472 return -ENOMEM;
3473- if (!vma || addr + len <= vma->vm_start)
3474+ if (check_heap_stack_gap(vma, addr, len))
3475 return addr;
3476 addr = vma->vm_end;
3477 }
3478@@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3479 /* At this point: (!vma || addr < vma->vm_end). */
3480 if (TASK_SIZE - len < addr)
3481 return -ENOMEM;
3482- if (!vma || addr + len <= vma->vm_start)
3483+ if (check_heap_stack_gap(vma, addr, len))
3484 return addr;
3485 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3486 if (addr < vma->vm_end) /* handle wraparound */
3487@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3488 if (flags & MAP_FIXED)
3489 return addr;
3490 if (!addr)
3491- addr = TASK_UNMAPPED_BASE;
3492+ addr = current->mm->mmap_base;
3493
3494 if (filp) {
3495 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3496diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3497index 45ba99f..8e22c33 100644
3498--- a/arch/parisc/kernel/traps.c
3499+++ b/arch/parisc/kernel/traps.c
3500@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3501
3502 down_read(&current->mm->mmap_sem);
3503 vma = find_vma(current->mm,regs->iaoq[0]);
3504- if (vma && (regs->iaoq[0] >= vma->vm_start)
3505- && (vma->vm_flags & VM_EXEC)) {
3506-
3507+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3508 fault_address = regs->iaoq[0];
3509 fault_space = regs->iasq[0];
3510
3511diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3512index 18162ce..94de376 100644
3513--- a/arch/parisc/mm/fault.c
3514+++ b/arch/parisc/mm/fault.c
3515@@ -15,6 +15,7 @@
3516 #include <linux/sched.h>
3517 #include <linux/interrupt.h>
3518 #include <linux/module.h>
3519+#include <linux/unistd.h>
3520
3521 #include <asm/uaccess.h>
3522 #include <asm/traps.h>
3523@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3524 static unsigned long
3525 parisc_acctyp(unsigned long code, unsigned int inst)
3526 {
3527- if (code == 6 || code == 16)
3528+ if (code == 6 || code == 7 || code == 16)
3529 return VM_EXEC;
3530
3531 switch (inst & 0xf0000000) {
3532@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3533 }
3534 #endif
3535
3536+#ifdef CONFIG_PAX_PAGEEXEC
3537+/*
3538+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3539+ *
3540+ * returns 1 when task should be killed
3541+ * 2 when rt_sigreturn trampoline was detected
3542+ * 3 when unpatched PLT trampoline was detected
3543+ */
3544+static int pax_handle_fetch_fault(struct pt_regs *regs)
3545+{
3546+
3547+#ifdef CONFIG_PAX_EMUPLT
3548+ int err;
3549+
3550+ do { /* PaX: unpatched PLT emulation */
3551+ unsigned int bl, depwi;
3552+
3553+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3554+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3555+
3556+ if (err)
3557+ break;
3558+
3559+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3560+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3561+
3562+ err = get_user(ldw, (unsigned int *)addr);
3563+ err |= get_user(bv, (unsigned int *)(addr+4));
3564+ err |= get_user(ldw2, (unsigned int *)(addr+8));
3565+
3566+ if (err)
3567+ break;
3568+
3569+ if (ldw == 0x0E801096U &&
3570+ bv == 0xEAC0C000U &&
3571+ ldw2 == 0x0E881095U)
3572+ {
3573+ unsigned int resolver, map;
3574+
3575+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3576+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3577+ if (err)
3578+ break;
3579+
3580+ regs->gr[20] = instruction_pointer(regs)+8;
3581+ regs->gr[21] = map;
3582+ regs->gr[22] = resolver;
3583+ regs->iaoq[0] = resolver | 3UL;
3584+ regs->iaoq[1] = regs->iaoq[0] + 4;
3585+ return 3;
3586+ }
3587+ }
3588+ } while (0);
3589+#endif
3590+
3591+#ifdef CONFIG_PAX_EMUTRAMP
3592+
3593+#ifndef CONFIG_PAX_EMUSIGRT
3594+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3595+ return 1;
3596+#endif
3597+
3598+ do { /* PaX: rt_sigreturn emulation */
3599+ unsigned int ldi1, ldi2, bel, nop;
3600+
3601+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3602+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3603+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3604+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3605+
3606+ if (err)
3607+ break;
3608+
3609+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3610+ ldi2 == 0x3414015AU &&
3611+ bel == 0xE4008200U &&
3612+ nop == 0x08000240U)
3613+ {
3614+ regs->gr[25] = (ldi1 & 2) >> 1;
3615+ regs->gr[20] = __NR_rt_sigreturn;
3616+ regs->gr[31] = regs->iaoq[1] + 16;
3617+ regs->sr[0] = regs->iasq[1];
3618+ regs->iaoq[0] = 0x100UL;
3619+ regs->iaoq[1] = regs->iaoq[0] + 4;
3620+ regs->iasq[0] = regs->sr[2];
3621+ regs->iasq[1] = regs->sr[2];
3622+ return 2;
3623+ }
3624+ } while (0);
3625+#endif
3626+
3627+ return 1;
3628+}
3629+
3630+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3631+{
3632+ unsigned long i;
3633+
3634+ printk(KERN_ERR "PAX: bytes at PC: ");
3635+ for (i = 0; i < 5; i++) {
3636+ unsigned int c;
3637+ if (get_user(c, (unsigned int *)pc+i))
3638+ printk(KERN_CONT "???????? ");
3639+ else
3640+ printk(KERN_CONT "%08x ", c);
3641+ }
3642+ printk("\n");
3643+}
3644+#endif
3645+
3646 int fixup_exception(struct pt_regs *regs)
3647 {
3648 const struct exception_table_entry *fix;
3649@@ -192,8 +303,33 @@ good_area:
3650
3651 acc_type = parisc_acctyp(code,regs->iir);
3652
3653- if ((vma->vm_flags & acc_type) != acc_type)
3654+ if ((vma->vm_flags & acc_type) != acc_type) {
3655+
3656+#ifdef CONFIG_PAX_PAGEEXEC
3657+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3658+ (address & ~3UL) == instruction_pointer(regs))
3659+ {
3660+ up_read(&mm->mmap_sem);
3661+ switch (pax_handle_fetch_fault(regs)) {
3662+
3663+#ifdef CONFIG_PAX_EMUPLT
3664+ case 3:
3665+ return;
3666+#endif
3667+
3668+#ifdef CONFIG_PAX_EMUTRAMP
3669+ case 2:
3670+ return;
3671+#endif
3672+
3673+ }
3674+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3675+ do_group_exit(SIGKILL);
3676+ }
3677+#endif
3678+
3679 goto bad_area;
3680+ }
3681
3682 /*
3683 * If for any reason at all we couldn't handle the fault, make
3684diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3685index da29032..f76c24c 100644
3686--- a/arch/powerpc/include/asm/atomic.h
3687+++ b/arch/powerpc/include/asm/atomic.h
3688@@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3689 return t1;
3690 }
3691
3692+#define atomic64_read_unchecked(v) atomic64_read(v)
3693+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3694+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3695+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3696+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3697+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3698+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3699+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3700+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3701+
3702 #endif /* __powerpc64__ */
3703
3704 #endif /* __KERNEL__ */
3705diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3706index 9e495c9..b6878e5 100644
3707--- a/arch/powerpc/include/asm/cache.h
3708+++ b/arch/powerpc/include/asm/cache.h
3709@@ -3,6 +3,7 @@
3710
3711 #ifdef __KERNEL__
3712
3713+#include <linux/const.h>
3714
3715 /* bytes per L1 cache line */
3716 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3717@@ -22,7 +23,7 @@
3718 #define L1_CACHE_SHIFT 7
3719 #endif
3720
3721-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3722+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3723
3724 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3725
3726diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3727index 3bf9cca..e7457d0 100644
3728--- a/arch/powerpc/include/asm/elf.h
3729+++ b/arch/powerpc/include/asm/elf.h
3730@@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3731 the loader. We need to make sure that it is out of the way of the program
3732 that it will "exec", and that there is sufficient room for the brk. */
3733
3734-extern unsigned long randomize_et_dyn(unsigned long base);
3735-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3736+#define ELF_ET_DYN_BASE (0x20000000)
3737+
3738+#ifdef CONFIG_PAX_ASLR
3739+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3740+
3741+#ifdef __powerpc64__
3742+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3743+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3744+#else
3745+#define PAX_DELTA_MMAP_LEN 15
3746+#define PAX_DELTA_STACK_LEN 15
3747+#endif
3748+#endif
3749
3750 /*
3751 * Our registers are always unsigned longs, whether we're a 32 bit
3752@@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3753 (0x7ff >> (PAGE_SHIFT - 12)) : \
3754 (0x3ffff >> (PAGE_SHIFT - 12)))
3755
3756-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3757-#define arch_randomize_brk arch_randomize_brk
3758-
3759 #endif /* __KERNEL__ */
3760
3761 /*
3762diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3763index 8196e9c..d83a9f3 100644
3764--- a/arch/powerpc/include/asm/exec.h
3765+++ b/arch/powerpc/include/asm/exec.h
3766@@ -4,6 +4,6 @@
3767 #ifndef _ASM_POWERPC_EXEC_H
3768 #define _ASM_POWERPC_EXEC_H
3769
3770-extern unsigned long arch_align_stack(unsigned long sp);
3771+#define arch_align_stack(x) ((x) & ~0xfUL)
3772
3773 #endif /* _ASM_POWERPC_EXEC_H */
3774diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3775index bca8fdc..61e9580 100644
3776--- a/arch/powerpc/include/asm/kmap_types.h
3777+++ b/arch/powerpc/include/asm/kmap_types.h
3778@@ -27,6 +27,7 @@ enum km_type {
3779 KM_PPC_SYNC_PAGE,
3780 KM_PPC_SYNC_ICACHE,
3781 KM_KDB,
3782+ KM_CLEARPAGE,
3783 KM_TYPE_NR
3784 };
3785
3786diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3787index d4a7f64..451de1c 100644
3788--- a/arch/powerpc/include/asm/mman.h
3789+++ b/arch/powerpc/include/asm/mman.h
3790@@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3791 }
3792 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3793
3794-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3795+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3796 {
3797 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3798 }
3799diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3800index f072e97..b436dee 100644
3801--- a/arch/powerpc/include/asm/page.h
3802+++ b/arch/powerpc/include/asm/page.h
3803@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3804 * and needs to be executable. This means the whole heap ends
3805 * up being executable.
3806 */
3807-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3808- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3809+#define VM_DATA_DEFAULT_FLAGS32 \
3810+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3811+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3812
3813 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3814 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3815@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3816 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3817 #endif
3818
3819+#define ktla_ktva(addr) (addr)
3820+#define ktva_ktla(addr) (addr)
3821+
3822 /*
3823 * Use the top bit of the higher-level page table entries to indicate whether
3824 * the entries we point to contain hugepages. This works because we know that
3825diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3826index fed85e6..da5c71b 100644
3827--- a/arch/powerpc/include/asm/page_64.h
3828+++ b/arch/powerpc/include/asm/page_64.h
3829@@ -146,15 +146,18 @@ do { \
3830 * stack by default, so in the absence of a PT_GNU_STACK program header
3831 * we turn execute permission off.
3832 */
3833-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3834- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3835+#define VM_STACK_DEFAULT_FLAGS32 \
3836+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3837+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3838
3839 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3840 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3841
3842+#ifndef CONFIG_PAX_PAGEEXEC
3843 #define VM_STACK_DEFAULT_FLAGS \
3844 (is_32bit_task() ? \
3845 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3846+#endif
3847
3848 #include <asm-generic/getorder.h>
3849
3850diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3851index 292725c..f87ae14 100644
3852--- a/arch/powerpc/include/asm/pgalloc-64.h
3853+++ b/arch/powerpc/include/asm/pgalloc-64.h
3854@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3855 #ifndef CONFIG_PPC_64K_PAGES
3856
3857 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3858+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3859
3860 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3861 {
3862@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3863 pud_set(pud, (unsigned long)pmd);
3864 }
3865
3866+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3867+{
3868+ pud_populate(mm, pud, pmd);
3869+}
3870+
3871 #define pmd_populate(mm, pmd, pte_page) \
3872 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3873 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3874@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3875 #else /* CONFIG_PPC_64K_PAGES */
3876
3877 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3878+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3879
3880 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3881 pte_t *pte)
3882diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3883index 2e0e411..7899c68 100644
3884--- a/arch/powerpc/include/asm/pgtable.h
3885+++ b/arch/powerpc/include/asm/pgtable.h
3886@@ -2,6 +2,7 @@
3887 #define _ASM_POWERPC_PGTABLE_H
3888 #ifdef __KERNEL__
3889
3890+#include <linux/const.h>
3891 #ifndef __ASSEMBLY__
3892 #include <asm/processor.h> /* For TASK_SIZE */
3893 #include <asm/mmu.h>
3894diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3895index 4aad413..85d86bf 100644
3896--- a/arch/powerpc/include/asm/pte-hash32.h
3897+++ b/arch/powerpc/include/asm/pte-hash32.h
3898@@ -21,6 +21,7 @@
3899 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3900 #define _PAGE_USER 0x004 /* usermode access allowed */
3901 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3902+#define _PAGE_EXEC _PAGE_GUARDED
3903 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3904 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3905 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3906diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3907index f0cb7f4..d1296c4 100644
3908--- a/arch/powerpc/include/asm/reg.h
3909+++ b/arch/powerpc/include/asm/reg.h
3910@@ -212,6 +212,7 @@
3911 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3912 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3913 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3914+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3915 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3916 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3917 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3918diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3919index 68831e9..379c695 100644
3920--- a/arch/powerpc/include/asm/thread_info.h
3921+++ b/arch/powerpc/include/asm/thread_info.h
3922@@ -91,12 +91,14 @@ static inline struct thread_info *current_thread_info(void)
3923 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3924 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3925 #define TIF_SINGLESTEP 8 /* singlestepping active */
3926-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3927 #define TIF_SECCOMP 10 /* secure computing */
3928 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3929 #define TIF_NOERROR 12 /* Force successful syscall return */
3930 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3931 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3932+#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3933+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3934+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3935
3936 /* as above, but as bit values */
3937 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3938@@ -113,8 +115,10 @@ static inline struct thread_info *current_thread_info(void)
3939 #define _TIF_NOERROR (1<<TIF_NOERROR)
3940 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3941 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3942+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3943 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3944- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3945+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3946+ _TIF_GRSEC_SETXID)
3947
3948 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3949 _TIF_NOTIFY_RESUME)
3950diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3951index 17bb40c..353c98b 100644
3952--- a/arch/powerpc/include/asm/uaccess.h
3953+++ b/arch/powerpc/include/asm/uaccess.h
3954@@ -13,6 +13,8 @@
3955 #define VERIFY_READ 0
3956 #define VERIFY_WRITE 1
3957
3958+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3959+
3960 /*
3961 * The fs value determines whether argument validity checking should be
3962 * performed or not. If get_fs() == USER_DS, checking is performed, with
3963@@ -329,52 +331,6 @@ do { \
3964 extern unsigned long __copy_tofrom_user(void __user *to,
3965 const void __user *from, unsigned long size);
3966
3967-#ifndef __powerpc64__
3968-
3969-static inline unsigned long copy_from_user(void *to,
3970- const void __user *from, unsigned long n)
3971-{
3972- unsigned long over;
3973-
3974- if (access_ok(VERIFY_READ, from, n))
3975- return __copy_tofrom_user((__force void __user *)to, from, n);
3976- if ((unsigned long)from < TASK_SIZE) {
3977- over = (unsigned long)from + n - TASK_SIZE;
3978- return __copy_tofrom_user((__force void __user *)to, from,
3979- n - over) + over;
3980- }
3981- return n;
3982-}
3983-
3984-static inline unsigned long copy_to_user(void __user *to,
3985- const void *from, unsigned long n)
3986-{
3987- unsigned long over;
3988-
3989- if (access_ok(VERIFY_WRITE, to, n))
3990- return __copy_tofrom_user(to, (__force void __user *)from, n);
3991- if ((unsigned long)to < TASK_SIZE) {
3992- over = (unsigned long)to + n - TASK_SIZE;
3993- return __copy_tofrom_user(to, (__force void __user *)from,
3994- n - over) + over;
3995- }
3996- return n;
3997-}
3998-
3999-#else /* __powerpc64__ */
4000-
4001-#define __copy_in_user(to, from, size) \
4002- __copy_tofrom_user((to), (from), (size))
4003-
4004-extern unsigned long copy_from_user(void *to, const void __user *from,
4005- unsigned long n);
4006-extern unsigned long copy_to_user(void __user *to, const void *from,
4007- unsigned long n);
4008-extern unsigned long copy_in_user(void __user *to, const void __user *from,
4009- unsigned long n);
4010-
4011-#endif /* __powerpc64__ */
4012-
4013 static inline unsigned long __copy_from_user_inatomic(void *to,
4014 const void __user *from, unsigned long n)
4015 {
4016@@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4017 if (ret == 0)
4018 return 0;
4019 }
4020+
4021+ if (!__builtin_constant_p(n))
4022+ check_object_size(to, n, false);
4023+
4024 return __copy_tofrom_user((__force void __user *)to, from, n);
4025 }
4026
4027@@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4028 if (ret == 0)
4029 return 0;
4030 }
4031+
4032+ if (!__builtin_constant_p(n))
4033+ check_object_size(from, n, true);
4034+
4035 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4036 }
4037
4038@@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4039 return __copy_to_user_inatomic(to, from, size);
4040 }
4041
4042+#ifndef __powerpc64__
4043+
4044+static inline unsigned long __must_check copy_from_user(void *to,
4045+ const void __user *from, unsigned long n)
4046+{
4047+ unsigned long over;
4048+
4049+ if ((long)n < 0)
4050+ return n;
4051+
4052+ if (access_ok(VERIFY_READ, from, n)) {
4053+ if (!__builtin_constant_p(n))
4054+ check_object_size(to, n, false);
4055+ return __copy_tofrom_user((__force void __user *)to, from, n);
4056+ }
4057+ if ((unsigned long)from < TASK_SIZE) {
4058+ over = (unsigned long)from + n - TASK_SIZE;
4059+ if (!__builtin_constant_p(n - over))
4060+ check_object_size(to, n - over, false);
4061+ return __copy_tofrom_user((__force void __user *)to, from,
4062+ n - over) + over;
4063+ }
4064+ return n;
4065+}
4066+
4067+static inline unsigned long __must_check copy_to_user(void __user *to,
4068+ const void *from, unsigned long n)
4069+{
4070+ unsigned long over;
4071+
4072+ if ((long)n < 0)
4073+ return n;
4074+
4075+ if (access_ok(VERIFY_WRITE, to, n)) {
4076+ if (!__builtin_constant_p(n))
4077+ check_object_size(from, n, true);
4078+ return __copy_tofrom_user(to, (__force void __user *)from, n);
4079+ }
4080+ if ((unsigned long)to < TASK_SIZE) {
4081+ over = (unsigned long)to + n - TASK_SIZE;
4082+ if (!__builtin_constant_p(n))
4083+ check_object_size(from, n - over, true);
4084+ return __copy_tofrom_user(to, (__force void __user *)from,
4085+ n - over) + over;
4086+ }
4087+ return n;
4088+}
4089+
4090+#else /* __powerpc64__ */
4091+
4092+#define __copy_in_user(to, from, size) \
4093+ __copy_tofrom_user((to), (from), (size))
4094+
4095+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4096+{
4097+ if ((long)n < 0 || n > INT_MAX)
4098+ return n;
4099+
4100+ if (!__builtin_constant_p(n))
4101+ check_object_size(to, n, false);
4102+
4103+ if (likely(access_ok(VERIFY_READ, from, n)))
4104+ n = __copy_from_user(to, from, n);
4105+ else
4106+ memset(to, 0, n);
4107+ return n;
4108+}
4109+
4110+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4111+{
4112+ if ((long)n < 0 || n > INT_MAX)
4113+ return n;
4114+
4115+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
4116+ if (!__builtin_constant_p(n))
4117+ check_object_size(from, n, true);
4118+ n = __copy_to_user(to, from, n);
4119+ }
4120+ return n;
4121+}
4122+
4123+extern unsigned long copy_in_user(void __user *to, const void __user *from,
4124+ unsigned long n);
4125+
4126+#endif /* __powerpc64__ */
4127+
4128 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4129
4130 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4131diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4132index 7215cc2..a9730c1 100644
4133--- a/arch/powerpc/kernel/exceptions-64e.S
4134+++ b/arch/powerpc/kernel/exceptions-64e.S
4135@@ -661,6 +661,7 @@ storage_fault_common:
4136 std r14,_DAR(r1)
4137 std r15,_DSISR(r1)
4138 addi r3,r1,STACK_FRAME_OVERHEAD
4139+ bl .save_nvgprs
4140 mr r4,r14
4141 mr r5,r15
4142 ld r14,PACA_EXGEN+EX_R14(r13)
4143@@ -669,8 +670,7 @@ storage_fault_common:
4144 cmpdi r3,0
4145 bne- 1f
4146 b .ret_from_except_lite
4147-1: bl .save_nvgprs
4148- mr r5,r3
4149+1: mr r5,r3
4150 addi r3,r1,STACK_FRAME_OVERHEAD
4151 ld r4,_DAR(r1)
4152 bl .bad_page_fault
4153diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4154index 1c06d29..c2a339b 100644
4155--- a/arch/powerpc/kernel/exceptions-64s.S
4156+++ b/arch/powerpc/kernel/exceptions-64s.S
4157@@ -888,10 +888,10 @@ handle_page_fault:
4158 11: ld r4,_DAR(r1)
4159 ld r5,_DSISR(r1)
4160 addi r3,r1,STACK_FRAME_OVERHEAD
4161+ bl .save_nvgprs
4162 bl .do_page_fault
4163 cmpdi r3,0
4164 beq+ 12f
4165- bl .save_nvgprs
4166 mr r5,r3
4167 addi r3,r1,STACK_FRAME_OVERHEAD
4168 lwz r4,_DAR(r1)
4169diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4170index 2e3200c..72095ce 100644
4171--- a/arch/powerpc/kernel/module_32.c
4172+++ b/arch/powerpc/kernel/module_32.c
4173@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4174 me->arch.core_plt_section = i;
4175 }
4176 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4177- printk("Module doesn't contain .plt or .init.plt sections.\n");
4178+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4179 return -ENOEXEC;
4180 }
4181
4182@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4183
4184 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4185 /* Init, or core PLT? */
4186- if (location >= mod->module_core
4187- && location < mod->module_core + mod->core_size)
4188+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4189+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4190 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4191- else
4192+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4193+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4194 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4195+ else {
4196+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4197+ return ~0UL;
4198+ }
4199
4200 /* Find this entry, or if that fails, the next avail. entry */
4201 while (entry->jump[0]) {
4202diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4203index 710f400..d00ebe6 100644
4204--- a/arch/powerpc/kernel/process.c
4205+++ b/arch/powerpc/kernel/process.c
4206@@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4207 * Lookup NIP late so we have the best change of getting the
4208 * above info out without failing
4209 */
4210- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4211- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4212+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4213+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4214 #endif
4215 show_stack(current, (unsigned long *) regs->gpr[1]);
4216 if (!user_mode(regs))
4217@@ -1189,10 +1189,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4218 newsp = stack[0];
4219 ip = stack[STACK_FRAME_LR_SAVE];
4220 if (!firstframe || ip != lr) {
4221- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4222+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4223 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4224 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4225- printk(" (%pS)",
4226+ printk(" (%pA)",
4227 (void *)current->ret_stack[curr_frame].ret);
4228 curr_frame--;
4229 }
4230@@ -1212,7 +1212,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4231 struct pt_regs *regs = (struct pt_regs *)
4232 (sp + STACK_FRAME_OVERHEAD);
4233 lr = regs->link;
4234- printk("--- Exception: %lx at %pS\n LR = %pS\n",
4235+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
4236 regs->trap, (void *)regs->nip, (void *)lr);
4237 firstframe = 1;
4238 }
4239@@ -1254,58 +1254,3 @@ void __ppc64_runlatch_off(void)
4240 mtspr(SPRN_CTRLT, ctrl);
4241 }
4242 #endif /* CONFIG_PPC64 */
4243-
4244-unsigned long arch_align_stack(unsigned long sp)
4245-{
4246- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4247- sp -= get_random_int() & ~PAGE_MASK;
4248- return sp & ~0xf;
4249-}
4250-
4251-static inline unsigned long brk_rnd(void)
4252-{
4253- unsigned long rnd = 0;
4254-
4255- /* 8MB for 32bit, 1GB for 64bit */
4256- if (is_32bit_task())
4257- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4258- else
4259- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4260-
4261- return rnd << PAGE_SHIFT;
4262-}
4263-
4264-unsigned long arch_randomize_brk(struct mm_struct *mm)
4265-{
4266- unsigned long base = mm->brk;
4267- unsigned long ret;
4268-
4269-#ifdef CONFIG_PPC_STD_MMU_64
4270- /*
4271- * If we are using 1TB segments and we are allowed to randomise
4272- * the heap, we can put it above 1TB so it is backed by a 1TB
4273- * segment. Otherwise the heap will be in the bottom 1TB
4274- * which always uses 256MB segments and this may result in a
4275- * performance penalty.
4276- */
4277- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4278- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4279-#endif
4280-
4281- ret = PAGE_ALIGN(base + brk_rnd());
4282-
4283- if (ret < mm->brk)
4284- return mm->brk;
4285-
4286- return ret;
4287-}
4288-
4289-unsigned long randomize_et_dyn(unsigned long base)
4290-{
4291- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4292-
4293- if (ret < base)
4294- return base;
4295-
4296- return ret;
4297-}
4298diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4299index c10fc28..c4ef063 100644
4300--- a/arch/powerpc/kernel/ptrace.c
4301+++ b/arch/powerpc/kernel/ptrace.c
4302@@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4303 return ret;
4304 }
4305
4306+#ifdef CONFIG_GRKERNSEC_SETXID
4307+extern void gr_delayed_cred_worker(void);
4308+#endif
4309+
4310 /*
4311 * We must return the syscall number to actually look up in the table.
4312 * This can be -1L to skip running any syscall at all.
4313@@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4314
4315 secure_computing_strict(regs->gpr[0]);
4316
4317+#ifdef CONFIG_GRKERNSEC_SETXID
4318+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4319+ gr_delayed_cred_worker();
4320+#endif
4321+
4322 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4323 tracehook_report_syscall_entry(regs))
4324 /*
4325@@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4326 {
4327 int step;
4328
4329+#ifdef CONFIG_GRKERNSEC_SETXID
4330+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4331+ gr_delayed_cred_worker();
4332+#endif
4333+
4334 audit_syscall_exit(regs);
4335
4336 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4337diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4338index 8b4c049..dcd6ef3 100644
4339--- a/arch/powerpc/kernel/signal_32.c
4340+++ b/arch/powerpc/kernel/signal_32.c
4341@@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4342 /* Save user registers on the stack */
4343 frame = &rt_sf->uc.uc_mcontext;
4344 addr = frame;
4345- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4346+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4347 if (save_user_regs(regs, frame, 0, 1))
4348 goto badframe;
4349 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4350diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4351index d183f87..1867f1a 100644
4352--- a/arch/powerpc/kernel/signal_64.c
4353+++ b/arch/powerpc/kernel/signal_64.c
4354@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4355 current->thread.fpscr.val = 0;
4356
4357 /* Set up to return from userspace. */
4358- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4359+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4360 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4361 } else {
4362 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4363diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4364index 1589723..cefe690 100644
4365--- a/arch/powerpc/kernel/traps.c
4366+++ b/arch/powerpc/kernel/traps.c
4367@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4368 return flags;
4369 }
4370
4371+extern void gr_handle_kernel_exploit(void);
4372+
4373 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4374 int signr)
4375 {
4376@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4377 panic("Fatal exception in interrupt");
4378 if (panic_on_oops)
4379 panic("Fatal exception");
4380+
4381+ gr_handle_kernel_exploit();
4382+
4383 do_exit(signr);
4384 }
4385
4386diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4387index 9eb5b9b..e45498a 100644
4388--- a/arch/powerpc/kernel/vdso.c
4389+++ b/arch/powerpc/kernel/vdso.c
4390@@ -34,6 +34,7 @@
4391 #include <asm/firmware.h>
4392 #include <asm/vdso.h>
4393 #include <asm/vdso_datapage.h>
4394+#include <asm/mman.h>
4395
4396 #include "setup.h"
4397
4398@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4399 vdso_base = VDSO32_MBASE;
4400 #endif
4401
4402- current->mm->context.vdso_base = 0;
4403+ current->mm->context.vdso_base = ~0UL;
4404
4405 /* vDSO has a problem and was disabled, just don't "enable" it for the
4406 * process
4407@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4408 vdso_base = get_unmapped_area(NULL, vdso_base,
4409 (vdso_pages << PAGE_SHIFT) +
4410 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4411- 0, 0);
4412+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
4413 if (IS_ERR_VALUE(vdso_base)) {
4414 rc = vdso_base;
4415 goto fail_mmapsem;
4416diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4417index 5eea6f3..5d10396 100644
4418--- a/arch/powerpc/lib/usercopy_64.c
4419+++ b/arch/powerpc/lib/usercopy_64.c
4420@@ -9,22 +9,6 @@
4421 #include <linux/module.h>
4422 #include <asm/uaccess.h>
4423
4424-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4425-{
4426- if (likely(access_ok(VERIFY_READ, from, n)))
4427- n = __copy_from_user(to, from, n);
4428- else
4429- memset(to, 0, n);
4430- return n;
4431-}
4432-
4433-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4434-{
4435- if (likely(access_ok(VERIFY_WRITE, to, n)))
4436- n = __copy_to_user(to, from, n);
4437- return n;
4438-}
4439-
4440 unsigned long copy_in_user(void __user *to, const void __user *from,
4441 unsigned long n)
4442 {
4443@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4444 return n;
4445 }
4446
4447-EXPORT_SYMBOL(copy_from_user);
4448-EXPORT_SYMBOL(copy_to_user);
4449 EXPORT_SYMBOL(copy_in_user);
4450
4451diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4452index 08ffcf5..a0ab912 100644
4453--- a/arch/powerpc/mm/fault.c
4454+++ b/arch/powerpc/mm/fault.c
4455@@ -32,6 +32,10 @@
4456 #include <linux/perf_event.h>
4457 #include <linux/magic.h>
4458 #include <linux/ratelimit.h>
4459+#include <linux/slab.h>
4460+#include <linux/pagemap.h>
4461+#include <linux/compiler.h>
4462+#include <linux/unistd.h>
4463
4464 #include <asm/firmware.h>
4465 #include <asm/page.h>
4466@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4467 }
4468 #endif
4469
4470+#ifdef CONFIG_PAX_PAGEEXEC
4471+/*
4472+ * PaX: decide what to do with offenders (regs->nip = fault address)
4473+ *
4474+ * returns 1 when task should be killed
4475+ */
4476+static int pax_handle_fetch_fault(struct pt_regs *regs)
4477+{
4478+ return 1;
4479+}
4480+
4481+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4482+{
4483+ unsigned long i;
4484+
4485+ printk(KERN_ERR "PAX: bytes at PC: ");
4486+ for (i = 0; i < 5; i++) {
4487+ unsigned int c;
4488+ if (get_user(c, (unsigned int __user *)pc+i))
4489+ printk(KERN_CONT "???????? ");
4490+ else
4491+ printk(KERN_CONT "%08x ", c);
4492+ }
4493+ printk("\n");
4494+}
4495+#endif
4496+
4497 /*
4498 * Check whether the instruction at regs->nip is a store using
4499 * an update addressing form which will update r1.
4500@@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4501 * indicate errors in DSISR but can validly be set in SRR1.
4502 */
4503 if (trap == 0x400)
4504- error_code &= 0x48200000;
4505+ error_code &= 0x58200000;
4506 else
4507 is_write = error_code & DSISR_ISSTORE;
4508 #else
4509@@ -366,7 +397,7 @@ good_area:
4510 * "undefined". Of those that can be set, this is the only
4511 * one which seems bad.
4512 */
4513- if (error_code & 0x10000000)
4514+ if (error_code & DSISR_GUARDED)
4515 /* Guarded storage error. */
4516 goto bad_area;
4517 #endif /* CONFIG_8xx */
4518@@ -381,7 +412,7 @@ good_area:
4519 * processors use the same I/D cache coherency mechanism
4520 * as embedded.
4521 */
4522- if (error_code & DSISR_PROTFAULT)
4523+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4524 goto bad_area;
4525 #endif /* CONFIG_PPC_STD_MMU */
4526
4527@@ -463,6 +494,23 @@ bad_area:
4528 bad_area_nosemaphore:
4529 /* User mode accesses cause a SIGSEGV */
4530 if (user_mode(regs)) {
4531+
4532+#ifdef CONFIG_PAX_PAGEEXEC
4533+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4534+#ifdef CONFIG_PPC_STD_MMU
4535+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4536+#else
4537+ if (is_exec && regs->nip == address) {
4538+#endif
4539+ switch (pax_handle_fetch_fault(regs)) {
4540+ }
4541+
4542+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4543+ do_group_exit(SIGKILL);
4544+ }
4545+ }
4546+#endif
4547+
4548 _exception(SIGSEGV, regs, code, address);
4549 return 0;
4550 }
4551diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4552index 67a42ed..1c7210c 100644
4553--- a/arch/powerpc/mm/mmap_64.c
4554+++ b/arch/powerpc/mm/mmap_64.c
4555@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4556 */
4557 if (mmap_is_legacy()) {
4558 mm->mmap_base = TASK_UNMAPPED_BASE;
4559+
4560+#ifdef CONFIG_PAX_RANDMMAP
4561+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4562+ mm->mmap_base += mm->delta_mmap;
4563+#endif
4564+
4565 mm->get_unmapped_area = arch_get_unmapped_area;
4566 mm->unmap_area = arch_unmap_area;
4567 } else {
4568 mm->mmap_base = mmap_base();
4569+
4570+#ifdef CONFIG_PAX_RANDMMAP
4571+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4572+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4573+#endif
4574+
4575 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4576 mm->unmap_area = arch_unmap_area_topdown;
4577 }
4578diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4579index 73709f7..6b90313 100644
4580--- a/arch/powerpc/mm/slice.c
4581+++ b/arch/powerpc/mm/slice.c
4582@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4583 if ((mm->task_size - len) < addr)
4584 return 0;
4585 vma = find_vma(mm, addr);
4586- return (!vma || (addr + len) <= vma->vm_start);
4587+ return check_heap_stack_gap(vma, addr, len);
4588 }
4589
4590 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4591@@ -256,7 +256,7 @@ full_search:
4592 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4593 continue;
4594 }
4595- if (!vma || addr + len <= vma->vm_start) {
4596+ if (check_heap_stack_gap(vma, addr, len)) {
4597 /*
4598 * Remember the place where we stopped the search:
4599 */
4600@@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4601 }
4602 }
4603
4604- addr = mm->mmap_base;
4605- while (addr > len) {
4606+ if (mm->mmap_base < len)
4607+ addr = -ENOMEM;
4608+ else
4609+ addr = mm->mmap_base - len;
4610+
4611+ while (!IS_ERR_VALUE(addr)) {
4612 /* Go down by chunk size */
4613- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4614+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
4615
4616 /* Check for hit with different page size */
4617 mask = slice_range_to_mask(addr, len);
4618@@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4619 * return with success:
4620 */
4621 vma = find_vma(mm, addr);
4622- if (!vma || (addr + len) <= vma->vm_start) {
4623+ if (check_heap_stack_gap(vma, addr, len)) {
4624 /* remember the address as a hint for next time */
4625 if (use_cache)
4626 mm->free_area_cache = addr;
4627@@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4628 mm->cached_hole_size = vma->vm_start - addr;
4629
4630 /* try just below the current vma->vm_start */
4631- addr = vma->vm_start;
4632+ addr = skip_heap_stack_gap(vma, len);
4633 }
4634
4635 /*
4636@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4637 if (fixed && addr > (mm->task_size - len))
4638 return -EINVAL;
4639
4640+#ifdef CONFIG_PAX_RANDMMAP
4641+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4642+ addr = 0;
4643+#endif
4644+
4645 /* If hint, make sure it matches our alignment restrictions */
4646 if (!fixed && addr) {
4647 addr = _ALIGN_UP(addr, 1ul << pshift);
4648diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4649index 748347b..81bc6c7 100644
4650--- a/arch/s390/include/asm/atomic.h
4651+++ b/arch/s390/include/asm/atomic.h
4652@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4653 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4654 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4655
4656+#define atomic64_read_unchecked(v) atomic64_read(v)
4657+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4658+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4659+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4660+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4661+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4662+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4663+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4664+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4665+
4666 #define smp_mb__before_atomic_dec() smp_mb()
4667 #define smp_mb__after_atomic_dec() smp_mb()
4668 #define smp_mb__before_atomic_inc() smp_mb()
4669diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4670index 2a30d5a..5e5586f 100644
4671--- a/arch/s390/include/asm/cache.h
4672+++ b/arch/s390/include/asm/cache.h
4673@@ -11,8 +11,10 @@
4674 #ifndef __ARCH_S390_CACHE_H
4675 #define __ARCH_S390_CACHE_H
4676
4677-#define L1_CACHE_BYTES 256
4678+#include <linux/const.h>
4679+
4680 #define L1_CACHE_SHIFT 8
4681+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4682 #define NET_SKB_PAD 32
4683
4684 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4685diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4686index 06151e6..c08cb52 100644
4687--- a/arch/s390/include/asm/elf.h
4688+++ b/arch/s390/include/asm/elf.h
4689@@ -161,8 +161,14 @@ extern unsigned int vdso_enabled;
4690 the loader. We need to make sure that it is out of the way of the program
4691 that it will "exec", and that there is sufficient room for the brk. */
4692
4693-extern unsigned long randomize_et_dyn(unsigned long base);
4694-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4695+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4696+
4697+#ifdef CONFIG_PAX_ASLR
4698+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4699+
4700+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4701+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4702+#endif
4703
4704 /* This yields a mask that user programs can use to figure out what
4705 instruction set this CPU supports. */
4706@@ -210,7 +216,4 @@ struct linux_binprm;
4707 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4708 int arch_setup_additional_pages(struct linux_binprm *, int);
4709
4710-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4711-#define arch_randomize_brk arch_randomize_brk
4712-
4713 #endif
4714diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4715index c4a93d6..4d2a9b4 100644
4716--- a/arch/s390/include/asm/exec.h
4717+++ b/arch/s390/include/asm/exec.h
4718@@ -7,6 +7,6 @@
4719 #ifndef __ASM_EXEC_H
4720 #define __ASM_EXEC_H
4721
4722-extern unsigned long arch_align_stack(unsigned long sp);
4723+#define arch_align_stack(x) ((x) & ~0xfUL)
4724
4725 #endif /* __ASM_EXEC_H */
4726diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4727index 1f3a79b..44d7f9c 100644
4728--- a/arch/s390/include/asm/uaccess.h
4729+++ b/arch/s390/include/asm/uaccess.h
4730@@ -241,6 +241,10 @@ static inline unsigned long __must_check
4731 copy_to_user(void __user *to, const void *from, unsigned long n)
4732 {
4733 might_fault();
4734+
4735+ if ((long)n < 0)
4736+ return n;
4737+
4738 if (access_ok(VERIFY_WRITE, to, n))
4739 n = __copy_to_user(to, from, n);
4740 return n;
4741@@ -266,6 +270,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4742 static inline unsigned long __must_check
4743 __copy_from_user(void *to, const void __user *from, unsigned long n)
4744 {
4745+ if ((long)n < 0)
4746+ return n;
4747+
4748 if (__builtin_constant_p(n) && (n <= 256))
4749 return uaccess.copy_from_user_small(n, from, to);
4750 else
4751@@ -297,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4752 static inline unsigned long __must_check
4753 copy_from_user(void *to, const void __user *from, unsigned long n)
4754 {
4755- unsigned int sz = __compiletime_object_size(to);
4756+ size_t sz = __compiletime_object_size(to);
4757
4758 might_fault();
4759- if (unlikely(sz != -1 && sz < n)) {
4760+
4761+ if ((long)n < 0)
4762+ return n;
4763+
4764+ if (unlikely(sz != (size_t)-1 && sz < n)) {
4765 copy_from_user_overflow();
4766 return n;
4767 }
4768diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4769index dfcb343..eda788a 100644
4770--- a/arch/s390/kernel/module.c
4771+++ b/arch/s390/kernel/module.c
4772@@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4773
4774 /* Increase core size by size of got & plt and set start
4775 offsets for got and plt. */
4776- me->core_size = ALIGN(me->core_size, 4);
4777- me->arch.got_offset = me->core_size;
4778- me->core_size += me->arch.got_size;
4779- me->arch.plt_offset = me->core_size;
4780- me->core_size += me->arch.plt_size;
4781+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
4782+ me->arch.got_offset = me->core_size_rw;
4783+ me->core_size_rw += me->arch.got_size;
4784+ me->arch.plt_offset = me->core_size_rx;
4785+ me->core_size_rx += me->arch.plt_size;
4786 return 0;
4787 }
4788
4789@@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4790 if (info->got_initialized == 0) {
4791 Elf_Addr *gotent;
4792
4793- gotent = me->module_core + me->arch.got_offset +
4794+ gotent = me->module_core_rw + me->arch.got_offset +
4795 info->got_offset;
4796 *gotent = val;
4797 info->got_initialized = 1;
4798@@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4799 else if (r_type == R_390_GOTENT ||
4800 r_type == R_390_GOTPLTENT)
4801 *(unsigned int *) loc =
4802- (val + (Elf_Addr) me->module_core - loc) >> 1;
4803+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4804 else if (r_type == R_390_GOT64 ||
4805 r_type == R_390_GOTPLT64)
4806 *(unsigned long *) loc = val;
4807@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4808 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4809 if (info->plt_initialized == 0) {
4810 unsigned int *ip;
4811- ip = me->module_core + me->arch.plt_offset +
4812+ ip = me->module_core_rx + me->arch.plt_offset +
4813 info->plt_offset;
4814 #ifndef CONFIG_64BIT
4815 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4816@@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4817 val - loc + 0xffffUL < 0x1ffffeUL) ||
4818 (r_type == R_390_PLT32DBL &&
4819 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4820- val = (Elf_Addr) me->module_core +
4821+ val = (Elf_Addr) me->module_core_rx +
4822 me->arch.plt_offset +
4823 info->plt_offset;
4824 val += rela->r_addend - loc;
4825@@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4826 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4827 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4828 val = val + rela->r_addend -
4829- ((Elf_Addr) me->module_core + me->arch.got_offset);
4830+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4831 if (r_type == R_390_GOTOFF16)
4832 *(unsigned short *) loc = val;
4833 else if (r_type == R_390_GOTOFF32)
4834@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4835 break;
4836 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4837 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4838- val = (Elf_Addr) me->module_core + me->arch.got_offset +
4839+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4840 rela->r_addend - loc;
4841 if (r_type == R_390_GOTPC)
4842 *(unsigned int *) loc = val;
4843diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4844index 60055ce..ee4b252 100644
4845--- a/arch/s390/kernel/process.c
4846+++ b/arch/s390/kernel/process.c
4847@@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4848 }
4849 return 0;
4850 }
4851-
4852-unsigned long arch_align_stack(unsigned long sp)
4853-{
4854- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4855- sp -= get_random_int() & ~PAGE_MASK;
4856- return sp & ~0xf;
4857-}
4858-
4859-static inline unsigned long brk_rnd(void)
4860-{
4861- /* 8MB for 32bit, 1GB for 64bit */
4862- if (is_32bit_task())
4863- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4864- else
4865- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4866-}
4867-
4868-unsigned long arch_randomize_brk(struct mm_struct *mm)
4869-{
4870- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4871-
4872- if (ret < mm->brk)
4873- return mm->brk;
4874- return ret;
4875-}
4876-
4877-unsigned long randomize_et_dyn(unsigned long base)
4878-{
4879- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4880-
4881- if (!(current->flags & PF_RANDOMIZE))
4882- return base;
4883- if (ret < base)
4884- return base;
4885- return ret;
4886-}
4887diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4888index 2857c48..d047481 100644
4889--- a/arch/s390/mm/mmap.c
4890+++ b/arch/s390/mm/mmap.c
4891@@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4892 */
4893 if (mmap_is_legacy()) {
4894 mm->mmap_base = TASK_UNMAPPED_BASE;
4895+
4896+#ifdef CONFIG_PAX_RANDMMAP
4897+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4898+ mm->mmap_base += mm->delta_mmap;
4899+#endif
4900+
4901 mm->get_unmapped_area = arch_get_unmapped_area;
4902 mm->unmap_area = arch_unmap_area;
4903 } else {
4904 mm->mmap_base = mmap_base();
4905+
4906+#ifdef CONFIG_PAX_RANDMMAP
4907+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4908+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4909+#endif
4910+
4911 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4912 mm->unmap_area = arch_unmap_area_topdown;
4913 }
4914@@ -166,10 +178,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4915 */
4916 if (mmap_is_legacy()) {
4917 mm->mmap_base = TASK_UNMAPPED_BASE;
4918+
4919+#ifdef CONFIG_PAX_RANDMMAP
4920+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4921+ mm->mmap_base += mm->delta_mmap;
4922+#endif
4923+
4924 mm->get_unmapped_area = s390_get_unmapped_area;
4925 mm->unmap_area = arch_unmap_area;
4926 } else {
4927 mm->mmap_base = mmap_base();
4928+
4929+#ifdef CONFIG_PAX_RANDMMAP
4930+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4931+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4932+#endif
4933+
4934 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4935 mm->unmap_area = arch_unmap_area_topdown;
4936 }
4937diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4938index ae3d59f..f65f075 100644
4939--- a/arch/score/include/asm/cache.h
4940+++ b/arch/score/include/asm/cache.h
4941@@ -1,7 +1,9 @@
4942 #ifndef _ASM_SCORE_CACHE_H
4943 #define _ASM_SCORE_CACHE_H
4944
4945+#include <linux/const.h>
4946+
4947 #define L1_CACHE_SHIFT 4
4948-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4949+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4950
4951 #endif /* _ASM_SCORE_CACHE_H */
4952diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4953index f9f3cd5..58ff438 100644
4954--- a/arch/score/include/asm/exec.h
4955+++ b/arch/score/include/asm/exec.h
4956@@ -1,6 +1,6 @@
4957 #ifndef _ASM_SCORE_EXEC_H
4958 #define _ASM_SCORE_EXEC_H
4959
4960-extern unsigned long arch_align_stack(unsigned long sp);
4961+#define arch_align_stack(x) (x)
4962
4963 #endif /* _ASM_SCORE_EXEC_H */
4964diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4965index 2707023..1c2a3b7 100644
4966--- a/arch/score/kernel/process.c
4967+++ b/arch/score/kernel/process.c
4968@@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
4969
4970 return task_pt_regs(task)->cp0_epc;
4971 }
4972-
4973-unsigned long arch_align_stack(unsigned long sp)
4974-{
4975- return sp;
4976-}
4977diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4978index ef9e555..331bd29 100644
4979--- a/arch/sh/include/asm/cache.h
4980+++ b/arch/sh/include/asm/cache.h
4981@@ -9,10 +9,11 @@
4982 #define __ASM_SH_CACHE_H
4983 #ifdef __KERNEL__
4984
4985+#include <linux/const.h>
4986 #include <linux/init.h>
4987 #include <cpu/cache.h>
4988
4989-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4990+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4991
4992 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4993
4994diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4995index afeb710..d1d1289 100644
4996--- a/arch/sh/mm/mmap.c
4997+++ b/arch/sh/mm/mmap.c
4998@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4999 addr = PAGE_ALIGN(addr);
5000
5001 vma = find_vma(mm, addr);
5002- if (TASK_SIZE - len >= addr &&
5003- (!vma || addr + len <= vma->vm_start))
5004+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5005 return addr;
5006 }
5007
5008@@ -106,7 +105,7 @@ full_search:
5009 }
5010 return -ENOMEM;
5011 }
5012- if (likely(!vma || addr + len <= vma->vm_start)) {
5013+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5014 /*
5015 * Remember the place where we stopped the search:
5016 */
5017@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5018 addr = PAGE_ALIGN(addr);
5019
5020 vma = find_vma(mm, addr);
5021- if (TASK_SIZE - len >= addr &&
5022- (!vma || addr + len <= vma->vm_start))
5023+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5024 return addr;
5025 }
5026
5027@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5028 /* make sure it can fit in the remaining address space */
5029 if (likely(addr > len)) {
5030 vma = find_vma(mm, addr-len);
5031- if (!vma || addr <= vma->vm_start) {
5032+ if (check_heap_stack_gap(vma, addr - len, len)) {
5033 /* remember the address as a hint for next time */
5034 return (mm->free_area_cache = addr-len);
5035 }
5036@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5037 if (unlikely(mm->mmap_base < len))
5038 goto bottomup;
5039
5040- addr = mm->mmap_base-len;
5041- if (do_colour_align)
5042- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5043+ addr = mm->mmap_base - len;
5044
5045 do {
5046+ if (do_colour_align)
5047+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5048 /*
5049 * Lookup failure means no vma is above this address,
5050 * else if new region fits below vma->vm_start,
5051 * return with success:
5052 */
5053 vma = find_vma(mm, addr);
5054- if (likely(!vma || addr+len <= vma->vm_start)) {
5055+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5056 /* remember the address as a hint for next time */
5057 return (mm->free_area_cache = addr);
5058 }
5059@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5060 mm->cached_hole_size = vma->vm_start - addr;
5061
5062 /* try just below the current vma->vm_start */
5063- addr = vma->vm_start-len;
5064- if (do_colour_align)
5065- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5066- } while (likely(len < vma->vm_start));
5067+ addr = skip_heap_stack_gap(vma, len);
5068+ } while (!IS_ERR_VALUE(addr));
5069
5070 bottomup:
5071 /*
5072diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5073index ce35a1c..2e7b8f9 100644
5074--- a/arch/sparc/include/asm/atomic_64.h
5075+++ b/arch/sparc/include/asm/atomic_64.h
5076@@ -14,18 +14,40 @@
5077 #define ATOMIC64_INIT(i) { (i) }
5078
5079 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5080+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5081+{
5082+ return v->counter;
5083+}
5084 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5085+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5086+{
5087+ return v->counter;
5088+}
5089
5090 #define atomic_set(v, i) (((v)->counter) = i)
5091+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5092+{
5093+ v->counter = i;
5094+}
5095 #define atomic64_set(v, i) (((v)->counter) = i)
5096+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5097+{
5098+ v->counter = i;
5099+}
5100
5101 extern void atomic_add(int, atomic_t *);
5102+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5103 extern void atomic64_add(long, atomic64_t *);
5104+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5105 extern void atomic_sub(int, atomic_t *);
5106+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5107 extern void atomic64_sub(long, atomic64_t *);
5108+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5109
5110 extern int atomic_add_ret(int, atomic_t *);
5111+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5112 extern long atomic64_add_ret(long, atomic64_t *);
5113+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5114 extern int atomic_sub_ret(int, atomic_t *);
5115 extern long atomic64_sub_ret(long, atomic64_t *);
5116
5117@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5118 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5119
5120 #define atomic_inc_return(v) atomic_add_ret(1, v)
5121+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5122+{
5123+ return atomic_add_ret_unchecked(1, v);
5124+}
5125 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5126+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5127+{
5128+ return atomic64_add_ret_unchecked(1, v);
5129+}
5130
5131 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5132 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5133
5134 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5135+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5136+{
5137+ return atomic_add_ret_unchecked(i, v);
5138+}
5139 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5140+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5141+{
5142+ return atomic64_add_ret_unchecked(i, v);
5143+}
5144
5145 /*
5146 * atomic_inc_and_test - increment and test
5147@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5148 * other cases.
5149 */
5150 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5151+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5152+{
5153+ return atomic_inc_return_unchecked(v) == 0;
5154+}
5155 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5156
5157 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5158@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5159 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5160
5161 #define atomic_inc(v) atomic_add(1, v)
5162+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5163+{
5164+ atomic_add_unchecked(1, v);
5165+}
5166 #define atomic64_inc(v) atomic64_add(1, v)
5167+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5168+{
5169+ atomic64_add_unchecked(1, v);
5170+}
5171
5172 #define atomic_dec(v) atomic_sub(1, v)
5173+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5174+{
5175+ atomic_sub_unchecked(1, v);
5176+}
5177 #define atomic64_dec(v) atomic64_sub(1, v)
5178+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5179+{
5180+ atomic64_sub_unchecked(1, v);
5181+}
5182
5183 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5184 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5185
5186 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5187+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5188+{
5189+ return cmpxchg(&v->counter, old, new);
5190+}
5191 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5192+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5193+{
5194+ return xchg(&v->counter, new);
5195+}
5196
5197 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5198 {
5199- int c, old;
5200+ int c, old, new;
5201 c = atomic_read(v);
5202 for (;;) {
5203- if (unlikely(c == (u)))
5204+ if (unlikely(c == u))
5205 break;
5206- old = atomic_cmpxchg((v), c, c + (a));
5207+
5208+ asm volatile("addcc %2, %0, %0\n"
5209+
5210+#ifdef CONFIG_PAX_REFCOUNT
5211+ "tvs %%icc, 6\n"
5212+#endif
5213+
5214+ : "=r" (new)
5215+ : "0" (c), "ir" (a)
5216+ : "cc");
5217+
5218+ old = atomic_cmpxchg(v, c, new);
5219 if (likely(old == c))
5220 break;
5221 c = old;
5222@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5223 #define atomic64_cmpxchg(v, o, n) \
5224 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5225 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5226+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5227+{
5228+ return xchg(&v->counter, new);
5229+}
5230
5231 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5232 {
5233- long c, old;
5234+ long c, old, new;
5235 c = atomic64_read(v);
5236 for (;;) {
5237- if (unlikely(c == (u)))
5238+ if (unlikely(c == u))
5239 break;
5240- old = atomic64_cmpxchg((v), c, c + (a));
5241+
5242+ asm volatile("addcc %2, %0, %0\n"
5243+
5244+#ifdef CONFIG_PAX_REFCOUNT
5245+ "tvs %%xcc, 6\n"
5246+#endif
5247+
5248+ : "=r" (new)
5249+ : "0" (c), "ir" (a)
5250+ : "cc");
5251+
5252+ old = atomic64_cmpxchg(v, c, new);
5253 if (likely(old == c))
5254 break;
5255 c = old;
5256 }
5257- return c != (u);
5258+ return c != u;
5259 }
5260
5261 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5262diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5263index 5bb6991..5c2132e 100644
5264--- a/arch/sparc/include/asm/cache.h
5265+++ b/arch/sparc/include/asm/cache.h
5266@@ -7,10 +7,12 @@
5267 #ifndef _SPARC_CACHE_H
5268 #define _SPARC_CACHE_H
5269
5270+#include <linux/const.h>
5271+
5272 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5273
5274 #define L1_CACHE_SHIFT 5
5275-#define L1_CACHE_BYTES 32
5276+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5277
5278 #ifdef CONFIG_SPARC32
5279 #define SMP_CACHE_BYTES_SHIFT 5
5280diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5281index 2d4d755..81b6662 100644
5282--- a/arch/sparc/include/asm/elf_32.h
5283+++ b/arch/sparc/include/asm/elf_32.h
5284@@ -114,6 +114,13 @@ typedef struct {
5285
5286 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5287
5288+#ifdef CONFIG_PAX_ASLR
5289+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5290+
5291+#define PAX_DELTA_MMAP_LEN 16
5292+#define PAX_DELTA_STACK_LEN 16
5293+#endif
5294+
5295 /* This yields a mask that user programs can use to figure out what
5296 instruction set this cpu supports. This can NOT be done in userspace
5297 on Sparc. */
5298diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5299index 7df8b7f..4946269 100644
5300--- a/arch/sparc/include/asm/elf_64.h
5301+++ b/arch/sparc/include/asm/elf_64.h
5302@@ -180,6 +180,13 @@ typedef struct {
5303 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5304 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5305
5306+#ifdef CONFIG_PAX_ASLR
5307+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5308+
5309+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5310+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5311+#endif
5312+
5313 extern unsigned long sparc64_elf_hwcap;
5314 #define ELF_HWCAP sparc64_elf_hwcap
5315
5316diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5317index e5b169b46..e90b4fa 100644
5318--- a/arch/sparc/include/asm/pgalloc_32.h
5319+++ b/arch/sparc/include/asm/pgalloc_32.h
5320@@ -46,6 +46,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5321 }
5322
5323 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5324+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5325
5326 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5327 unsigned long address)
5328diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5329index 40b2d7a..22a665b 100644
5330--- a/arch/sparc/include/asm/pgalloc_64.h
5331+++ b/arch/sparc/include/asm/pgalloc_64.h
5332@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5333 }
5334
5335 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5336+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5337
5338 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5339 {
5340diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5341index cbbbed5..0983069 100644
5342--- a/arch/sparc/include/asm/pgtable_32.h
5343+++ b/arch/sparc/include/asm/pgtable_32.h
5344@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5345 #define PAGE_SHARED SRMMU_PAGE_SHARED
5346 #define PAGE_COPY SRMMU_PAGE_COPY
5347 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5348+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5349+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5350+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5351 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5352
5353 /* Top-level page directory */
5354@@ -61,18 +64,18 @@ extern unsigned long ptr_in_current_pgd;
5355
5356 /* xwr */
5357 #define __P000 PAGE_NONE
5358-#define __P001 PAGE_READONLY
5359-#define __P010 PAGE_COPY
5360-#define __P011 PAGE_COPY
5361+#define __P001 PAGE_READONLY_NOEXEC
5362+#define __P010 PAGE_COPY_NOEXEC
5363+#define __P011 PAGE_COPY_NOEXEC
5364 #define __P100 PAGE_READONLY
5365 #define __P101 PAGE_READONLY
5366 #define __P110 PAGE_COPY
5367 #define __P111 PAGE_COPY
5368
5369 #define __S000 PAGE_NONE
5370-#define __S001 PAGE_READONLY
5371-#define __S010 PAGE_SHARED
5372-#define __S011 PAGE_SHARED
5373+#define __S001 PAGE_READONLY_NOEXEC
5374+#define __S010 PAGE_SHARE_NOEXEC
5375+#define __S011 PAGE_SHARE_NOEXEC
5376 #define __S100 PAGE_READONLY
5377 #define __S101 PAGE_READONLY
5378 #define __S110 PAGE_SHARED
5379diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5380index 79da178..c2eede8 100644
5381--- a/arch/sparc/include/asm/pgtsrmmu.h
5382+++ b/arch/sparc/include/asm/pgtsrmmu.h
5383@@ -115,6 +115,11 @@
5384 SRMMU_EXEC | SRMMU_REF)
5385 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5386 SRMMU_EXEC | SRMMU_REF)
5387+
5388+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5389+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5390+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5391+
5392 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5393 SRMMU_DIRTY | SRMMU_REF)
5394
5395diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5396index 9689176..63c18ea 100644
5397--- a/arch/sparc/include/asm/spinlock_64.h
5398+++ b/arch/sparc/include/asm/spinlock_64.h
5399@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5400
5401 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5402
5403-static void inline arch_read_lock(arch_rwlock_t *lock)
5404+static inline void arch_read_lock(arch_rwlock_t *lock)
5405 {
5406 unsigned long tmp1, tmp2;
5407
5408 __asm__ __volatile__ (
5409 "1: ldsw [%2], %0\n"
5410 " brlz,pn %0, 2f\n"
5411-"4: add %0, 1, %1\n"
5412+"4: addcc %0, 1, %1\n"
5413+
5414+#ifdef CONFIG_PAX_REFCOUNT
5415+" tvs %%icc, 6\n"
5416+#endif
5417+
5418 " cas [%2], %0, %1\n"
5419 " cmp %0, %1\n"
5420 " bne,pn %%icc, 1b\n"
5421@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5422 " .previous"
5423 : "=&r" (tmp1), "=&r" (tmp2)
5424 : "r" (lock)
5425- : "memory");
5426+ : "memory", "cc");
5427 }
5428
5429-static int inline arch_read_trylock(arch_rwlock_t *lock)
5430+static inline int arch_read_trylock(arch_rwlock_t *lock)
5431 {
5432 int tmp1, tmp2;
5433
5434@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5435 "1: ldsw [%2], %0\n"
5436 " brlz,a,pn %0, 2f\n"
5437 " mov 0, %0\n"
5438-" add %0, 1, %1\n"
5439+" addcc %0, 1, %1\n"
5440+
5441+#ifdef CONFIG_PAX_REFCOUNT
5442+" tvs %%icc, 6\n"
5443+#endif
5444+
5445 " cas [%2], %0, %1\n"
5446 " cmp %0, %1\n"
5447 " bne,pn %%icc, 1b\n"
5448@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5449 return tmp1;
5450 }
5451
5452-static void inline arch_read_unlock(arch_rwlock_t *lock)
5453+static inline void arch_read_unlock(arch_rwlock_t *lock)
5454 {
5455 unsigned long tmp1, tmp2;
5456
5457 __asm__ __volatile__(
5458 "1: lduw [%2], %0\n"
5459-" sub %0, 1, %1\n"
5460+" subcc %0, 1, %1\n"
5461+
5462+#ifdef CONFIG_PAX_REFCOUNT
5463+" tvs %%icc, 6\n"
5464+#endif
5465+
5466 " cas [%2], %0, %1\n"
5467 " cmp %0, %1\n"
5468 " bne,pn %%xcc, 1b\n"
5469@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5470 : "memory");
5471 }
5472
5473-static void inline arch_write_lock(arch_rwlock_t *lock)
5474+static inline void arch_write_lock(arch_rwlock_t *lock)
5475 {
5476 unsigned long mask, tmp1, tmp2;
5477
5478@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5479 : "memory");
5480 }
5481
5482-static void inline arch_write_unlock(arch_rwlock_t *lock)
5483+static inline void arch_write_unlock(arch_rwlock_t *lock)
5484 {
5485 __asm__ __volatile__(
5486 " stw %%g0, [%0]"
5487@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5488 : "memory");
5489 }
5490
5491-static int inline arch_write_trylock(arch_rwlock_t *lock)
5492+static inline int arch_write_trylock(arch_rwlock_t *lock)
5493 {
5494 unsigned long mask, tmp1, tmp2, result;
5495
5496diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5497index e6cd224..3a71793 100644
5498--- a/arch/sparc/include/asm/thread_info_32.h
5499+++ b/arch/sparc/include/asm/thread_info_32.h
5500@@ -49,6 +49,8 @@ struct thread_info {
5501 unsigned long w_saved;
5502
5503 struct restart_block restart_block;
5504+
5505+ unsigned long lowest_stack;
5506 };
5507
5508 /*
5509diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5510index cfa8c38..13f30d3 100644
5511--- a/arch/sparc/include/asm/thread_info_64.h
5512+++ b/arch/sparc/include/asm/thread_info_64.h
5513@@ -63,6 +63,8 @@ struct thread_info {
5514 struct pt_regs *kern_una_regs;
5515 unsigned int kern_una_insn;
5516
5517+ unsigned long lowest_stack;
5518+
5519 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5520 };
5521
5522@@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5523 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5524 /* flag bit 6 is available */
5525 #define TIF_32BIT 7 /* 32-bit binary */
5526-/* flag bit 8 is available */
5527+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5528 #define TIF_SECCOMP 9 /* secure computing */
5529 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5530 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5531+
5532 /* NOTE: Thread flags >= 12 should be ones we have no interest
5533 * in using in assembly, else we can't use the mask as
5534 * an immediate value in instructions such as andcc.
5535@@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5536 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5537 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5538 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5539+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5540
5541 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5542 _TIF_DO_NOTIFY_RESUME_MASK | \
5543 _TIF_NEED_RESCHED)
5544 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5545
5546+#define _TIF_WORK_SYSCALL \
5547+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5548+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5549+
5550+
5551 /*
5552 * Thread-synchronous status.
5553 *
5554diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5555index 0167d26..9acd8ed 100644
5556--- a/arch/sparc/include/asm/uaccess.h
5557+++ b/arch/sparc/include/asm/uaccess.h
5558@@ -1,5 +1,13 @@
5559 #ifndef ___ASM_SPARC_UACCESS_H
5560 #define ___ASM_SPARC_UACCESS_H
5561+
5562+#ifdef __KERNEL__
5563+#ifndef __ASSEMBLY__
5564+#include <linux/types.h>
5565+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5566+#endif
5567+#endif
5568+
5569 #if defined(__sparc__) && defined(__arch64__)
5570 #include <asm/uaccess_64.h>
5571 #else
5572diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5573index 53a28dd..50c38c3 100644
5574--- a/arch/sparc/include/asm/uaccess_32.h
5575+++ b/arch/sparc/include/asm/uaccess_32.h
5576@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5577
5578 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5579 {
5580- if (n && __access_ok((unsigned long) to, n))
5581+ if ((long)n < 0)
5582+ return n;
5583+
5584+ if (n && __access_ok((unsigned long) to, n)) {
5585+ if (!__builtin_constant_p(n))
5586+ check_object_size(from, n, true);
5587 return __copy_user(to, (__force void __user *) from, n);
5588- else
5589+ } else
5590 return n;
5591 }
5592
5593 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5594 {
5595+ if ((long)n < 0)
5596+ return n;
5597+
5598+ if (!__builtin_constant_p(n))
5599+ check_object_size(from, n, true);
5600+
5601 return __copy_user(to, (__force void __user *) from, n);
5602 }
5603
5604 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5605 {
5606- if (n && __access_ok((unsigned long) from, n))
5607+ if ((long)n < 0)
5608+ return n;
5609+
5610+ if (n && __access_ok((unsigned long) from, n)) {
5611+ if (!__builtin_constant_p(n))
5612+ check_object_size(to, n, false);
5613 return __copy_user((__force void __user *) to, from, n);
5614- else
5615+ } else
5616 return n;
5617 }
5618
5619 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5620 {
5621+ if ((long)n < 0)
5622+ return n;
5623+
5624 return __copy_user((__force void __user *) to, from, n);
5625 }
5626
5627diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5628index 7c831d8..d440ca7 100644
5629--- a/arch/sparc/include/asm/uaccess_64.h
5630+++ b/arch/sparc/include/asm/uaccess_64.h
5631@@ -10,6 +10,7 @@
5632 #include <linux/compiler.h>
5633 #include <linux/string.h>
5634 #include <linux/thread_info.h>
5635+#include <linux/kernel.h>
5636 #include <asm/asi.h>
5637 #include <asm/spitfire.h>
5638 #include <asm-generic/uaccess-unaligned.h>
5639@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5640 static inline unsigned long __must_check
5641 copy_from_user(void *to, const void __user *from, unsigned long size)
5642 {
5643- unsigned long ret = ___copy_from_user(to, from, size);
5644+ unsigned long ret;
5645
5646+ if ((long)size < 0 || size > INT_MAX)
5647+ return size;
5648+
5649+ if (!__builtin_constant_p(size))
5650+ check_object_size(to, size, false);
5651+
5652+ ret = ___copy_from_user(to, from, size);
5653 if (unlikely(ret))
5654 ret = copy_from_user_fixup(to, from, size);
5655
5656@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5657 static inline unsigned long __must_check
5658 copy_to_user(void __user *to, const void *from, unsigned long size)
5659 {
5660- unsigned long ret = ___copy_to_user(to, from, size);
5661+ unsigned long ret;
5662
5663+ if ((long)size < 0 || size > INT_MAX)
5664+ return size;
5665+
5666+ if (!__builtin_constant_p(size))
5667+ check_object_size(from, size, true);
5668+
5669+ ret = ___copy_to_user(to, from, size);
5670 if (unlikely(ret))
5671 ret = copy_to_user_fixup(to, from, size);
5672 return ret;
5673diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5674index 6cf591b..b49e65a 100644
5675--- a/arch/sparc/kernel/Makefile
5676+++ b/arch/sparc/kernel/Makefile
5677@@ -3,7 +3,7 @@
5678 #
5679
5680 asflags-y := -ansi
5681-ccflags-y := -Werror
5682+#ccflags-y := -Werror
5683
5684 extra-y := head_$(BITS).o
5685
5686diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5687index cb36e82..1c1462f 100644
5688--- a/arch/sparc/kernel/process_32.c
5689+++ b/arch/sparc/kernel/process_32.c
5690@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5691
5692 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5693 r->psr, r->pc, r->npc, r->y, print_tainted());
5694- printk("PC: <%pS>\n", (void *) r->pc);
5695+ printk("PC: <%pA>\n", (void *) r->pc);
5696 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5697 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5698 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5699 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5700 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5701 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5702- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5703+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5704
5705 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5706 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5707@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5708 rw = (struct reg_window32 *) fp;
5709 pc = rw->ins[7];
5710 printk("[%08lx : ", pc);
5711- printk("%pS ] ", (void *) pc);
5712+ printk("%pA ] ", (void *) pc);
5713 fp = rw->ins[6];
5714 } while (++count < 16);
5715 printk("\n");
5716diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5717index aff0c72..9067b39 100644
5718--- a/arch/sparc/kernel/process_64.c
5719+++ b/arch/sparc/kernel/process_64.c
5720@@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5721 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5722 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5723 if (regs->tstate & TSTATE_PRIV)
5724- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5725+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5726 }
5727
5728 void show_regs(struct pt_regs *regs)
5729 {
5730 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5731 regs->tpc, regs->tnpc, regs->y, print_tainted());
5732- printk("TPC: <%pS>\n", (void *) regs->tpc);
5733+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5734 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5735 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5736 regs->u_regs[3]);
5737@@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5738 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5739 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5740 regs->u_regs[15]);
5741- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5742+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5743 show_regwindow(regs);
5744 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5745 }
5746@@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5747 ((tp && tp->task) ? tp->task->pid : -1));
5748
5749 if (gp->tstate & TSTATE_PRIV) {
5750- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5751+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5752 (void *) gp->tpc,
5753 (void *) gp->o7,
5754 (void *) gp->i7,
5755diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5756index 484daba..0674139 100644
5757--- a/arch/sparc/kernel/ptrace_64.c
5758+++ b/arch/sparc/kernel/ptrace_64.c
5759@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5760 return ret;
5761 }
5762
5763+#ifdef CONFIG_GRKERNSEC_SETXID
5764+extern void gr_delayed_cred_worker(void);
5765+#endif
5766+
5767 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5768 {
5769 int ret = 0;
5770@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5771 /* do the secure computing check first */
5772 secure_computing_strict(regs->u_regs[UREG_G1]);
5773
5774+#ifdef CONFIG_GRKERNSEC_SETXID
5775+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5776+ gr_delayed_cred_worker();
5777+#endif
5778+
5779 if (test_thread_flag(TIF_SYSCALL_TRACE))
5780 ret = tracehook_report_syscall_entry(regs);
5781
5782@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5783
5784 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5785 {
5786+#ifdef CONFIG_GRKERNSEC_SETXID
5787+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5788+ gr_delayed_cred_worker();
5789+#endif
5790+
5791 audit_syscall_exit(regs);
5792
5793 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5794diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5795index 0c9b31b..7cb7aee 100644
5796--- a/arch/sparc/kernel/sys_sparc_32.c
5797+++ b/arch/sparc/kernel/sys_sparc_32.c
5798@@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5799 if (len > TASK_SIZE - PAGE_SIZE)
5800 return -ENOMEM;
5801 if (!addr)
5802- addr = TASK_UNMAPPED_BASE;
5803+ addr = current->mm->mmap_base;
5804
5805 if (flags & MAP_SHARED)
5806 addr = COLOUR_ALIGN(addr);
5807@@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5808 /* At this point: (!vmm || addr < vmm->vm_end). */
5809 if (TASK_SIZE - PAGE_SIZE - len < addr)
5810 return -ENOMEM;
5811- if (!vmm || addr + len <= vmm->vm_start)
5812+ if (check_heap_stack_gap(vmm, addr, len))
5813 return addr;
5814 addr = vmm->vm_end;
5815 if (flags & MAP_SHARED)
5816diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5817index 275f74f..81bf5b8 100644
5818--- a/arch/sparc/kernel/sys_sparc_64.c
5819+++ b/arch/sparc/kernel/sys_sparc_64.c
5820@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5821 /* We do not accept a shared mapping if it would violate
5822 * cache aliasing constraints.
5823 */
5824- if ((flags & MAP_SHARED) &&
5825+ if ((filp || (flags & MAP_SHARED)) &&
5826 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5827 return -EINVAL;
5828 return addr;
5829@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5830 if (filp || (flags & MAP_SHARED))
5831 do_color_align = 1;
5832
5833+#ifdef CONFIG_PAX_RANDMMAP
5834+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5835+#endif
5836+
5837 if (addr) {
5838 if (do_color_align)
5839 addr = COLOUR_ALIGN(addr, pgoff);
5840@@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5841 addr = PAGE_ALIGN(addr);
5842
5843 vma = find_vma(mm, addr);
5844- if (task_size - len >= addr &&
5845- (!vma || addr + len <= vma->vm_start))
5846+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5847 return addr;
5848 }
5849
5850 if (len > mm->cached_hole_size) {
5851- start_addr = addr = mm->free_area_cache;
5852+ start_addr = addr = mm->free_area_cache;
5853 } else {
5854- start_addr = addr = TASK_UNMAPPED_BASE;
5855+ start_addr = addr = mm->mmap_base;
5856 mm->cached_hole_size = 0;
5857 }
5858
5859@@ -174,14 +177,14 @@ full_search:
5860 vma = find_vma(mm, VA_EXCLUDE_END);
5861 }
5862 if (unlikely(task_size < addr)) {
5863- if (start_addr != TASK_UNMAPPED_BASE) {
5864- start_addr = addr = TASK_UNMAPPED_BASE;
5865+ if (start_addr != mm->mmap_base) {
5866+ start_addr = addr = mm->mmap_base;
5867 mm->cached_hole_size = 0;
5868 goto full_search;
5869 }
5870 return -ENOMEM;
5871 }
5872- if (likely(!vma || addr + len <= vma->vm_start)) {
5873+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5874 /*
5875 * Remember the place where we stopped the search:
5876 */
5877@@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5878 /* We do not accept a shared mapping if it would violate
5879 * cache aliasing constraints.
5880 */
5881- if ((flags & MAP_SHARED) &&
5882+ if ((filp || (flags & MAP_SHARED)) &&
5883 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5884 return -EINVAL;
5885 return addr;
5886@@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5887 addr = PAGE_ALIGN(addr);
5888
5889 vma = find_vma(mm, addr);
5890- if (task_size - len >= addr &&
5891- (!vma || addr + len <= vma->vm_start))
5892+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5893 return addr;
5894 }
5895
5896@@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5897 /* make sure it can fit in the remaining address space */
5898 if (likely(addr > len)) {
5899 vma = find_vma(mm, addr-len);
5900- if (!vma || addr <= vma->vm_start) {
5901+ if (check_heap_stack_gap(vma, addr - len, len)) {
5902 /* remember the address as a hint for next time */
5903 return (mm->free_area_cache = addr-len);
5904 }
5905@@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5906 if (unlikely(mm->mmap_base < len))
5907 goto bottomup;
5908
5909- addr = mm->mmap_base-len;
5910- if (do_color_align)
5911- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5912+ addr = mm->mmap_base - len;
5913
5914 do {
5915+ if (do_color_align)
5916+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5917 /*
5918 * Lookup failure means no vma is above this address,
5919 * else if new region fits below vma->vm_start,
5920 * return with success:
5921 */
5922 vma = find_vma(mm, addr);
5923- if (likely(!vma || addr+len <= vma->vm_start)) {
5924+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5925 /* remember the address as a hint for next time */
5926 return (mm->free_area_cache = addr);
5927 }
5928@@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5929 mm->cached_hole_size = vma->vm_start - addr;
5930
5931 /* try just below the current vma->vm_start */
5932- addr = vma->vm_start-len;
5933- if (do_color_align)
5934- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5935- } while (likely(len < vma->vm_start));
5936+ addr = skip_heap_stack_gap(vma, len);
5937+ } while (!IS_ERR_VALUE(addr));
5938
5939 bottomup:
5940 /*
5941@@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5942 gap == RLIM_INFINITY ||
5943 sysctl_legacy_va_layout) {
5944 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5945+
5946+#ifdef CONFIG_PAX_RANDMMAP
5947+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5948+ mm->mmap_base += mm->delta_mmap;
5949+#endif
5950+
5951 mm->get_unmapped_area = arch_get_unmapped_area;
5952 mm->unmap_area = arch_unmap_area;
5953 } else {
5954@@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5955 gap = (task_size / 6 * 5);
5956
5957 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5958+
5959+#ifdef CONFIG_PAX_RANDMMAP
5960+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5961+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5962+#endif
5963+
5964 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5965 mm->unmap_area = arch_unmap_area_topdown;
5966 }
5967diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5968index 1d7e274..b39c527 100644
5969--- a/arch/sparc/kernel/syscalls.S
5970+++ b/arch/sparc/kernel/syscalls.S
5971@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
5972 #endif
5973 .align 32
5974 1: ldx [%g6 + TI_FLAGS], %l5
5975- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5976+ andcc %l5, _TIF_WORK_SYSCALL, %g0
5977 be,pt %icc, rtrap
5978 nop
5979 call syscall_trace_leave
5980@@ -179,7 +179,7 @@ linux_sparc_syscall32:
5981
5982 srl %i5, 0, %o5 ! IEU1
5983 srl %i2, 0, %o2 ! IEU0 Group
5984- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5985+ andcc %l0, _TIF_WORK_SYSCALL, %g0
5986 bne,pn %icc, linux_syscall_trace32 ! CTI
5987 mov %i0, %l5 ! IEU1
5988 call %l7 ! CTI Group brk forced
5989@@ -202,7 +202,7 @@ linux_sparc_syscall:
5990
5991 mov %i3, %o3 ! IEU1
5992 mov %i4, %o4 ! IEU0 Group
5993- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5994+ andcc %l0, _TIF_WORK_SYSCALL, %g0
5995 bne,pn %icc, linux_syscall_trace ! CTI Group
5996 mov %i0, %l5 ! IEU0
5997 2: call %l7 ! CTI Group brk forced
5998@@ -226,7 +226,7 @@ ret_sys_call:
5999
6000 cmp %o0, -ERESTART_RESTARTBLOCK
6001 bgeu,pn %xcc, 1f
6002- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6003+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6004 80:
6005 /* System call success, clear Carry condition code. */
6006 andn %g3, %g2, %g3
6007@@ -241,7 +241,7 @@ ret_sys_call:
6008 /* System call failure, set Carry condition code.
6009 * Also, get abs(errno) to return to the process.
6010 */
6011- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6012+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6013 sub %g0, %o0, %o0
6014 or %g3, %g2, %g3
6015 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6016diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6017index a5785ea..405c5f7 100644
6018--- a/arch/sparc/kernel/traps_32.c
6019+++ b/arch/sparc/kernel/traps_32.c
6020@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6021 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6022 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6023
6024+extern void gr_handle_kernel_exploit(void);
6025+
6026 void die_if_kernel(char *str, struct pt_regs *regs)
6027 {
6028 static int die_counter;
6029@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6030 count++ < 30 &&
6031 (((unsigned long) rw) >= PAGE_OFFSET) &&
6032 !(((unsigned long) rw) & 0x7)) {
6033- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6034+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6035 (void *) rw->ins[7]);
6036 rw = (struct reg_window32 *)rw->ins[6];
6037 }
6038 }
6039 printk("Instruction DUMP:");
6040 instruction_dump ((unsigned long *) regs->pc);
6041- if(regs->psr & PSR_PS)
6042+ if(regs->psr & PSR_PS) {
6043+ gr_handle_kernel_exploit();
6044 do_exit(SIGKILL);
6045+ }
6046 do_exit(SIGSEGV);
6047 }
6048
6049diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6050index 3b05e66..6ea2917 100644
6051--- a/arch/sparc/kernel/traps_64.c
6052+++ b/arch/sparc/kernel/traps_64.c
6053@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6054 i + 1,
6055 p->trapstack[i].tstate, p->trapstack[i].tpc,
6056 p->trapstack[i].tnpc, p->trapstack[i].tt);
6057- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6058+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6059 }
6060 }
6061
6062@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6063
6064 lvl -= 0x100;
6065 if (regs->tstate & TSTATE_PRIV) {
6066+
6067+#ifdef CONFIG_PAX_REFCOUNT
6068+ if (lvl == 6)
6069+ pax_report_refcount_overflow(regs);
6070+#endif
6071+
6072 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6073 die_if_kernel(buffer, regs);
6074 }
6075@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6076 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6077 {
6078 char buffer[32];
6079-
6080+
6081 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6082 0, lvl, SIGTRAP) == NOTIFY_STOP)
6083 return;
6084
6085+#ifdef CONFIG_PAX_REFCOUNT
6086+ if (lvl == 6)
6087+ pax_report_refcount_overflow(regs);
6088+#endif
6089+
6090 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6091
6092 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6093@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6094 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6095 printk("%s" "ERROR(%d): ",
6096 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6097- printk("TPC<%pS>\n", (void *) regs->tpc);
6098+ printk("TPC<%pA>\n", (void *) regs->tpc);
6099 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6100 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6101 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6102@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6103 smp_processor_id(),
6104 (type & 0x1) ? 'I' : 'D',
6105 regs->tpc);
6106- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6107+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6108 panic("Irrecoverable Cheetah+ parity error.");
6109 }
6110
6111@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6112 smp_processor_id(),
6113 (type & 0x1) ? 'I' : 'D',
6114 regs->tpc);
6115- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6116+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6117 }
6118
6119 struct sun4v_error_entry {
6120@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6121
6122 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6123 regs->tpc, tl);
6124- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6125+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6126 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6127- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6128+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6129 (void *) regs->u_regs[UREG_I7]);
6130 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6131 "pte[%lx] error[%lx]\n",
6132@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6133
6134 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6135 regs->tpc, tl);
6136- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6137+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6138 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6139- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6140+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6141 (void *) regs->u_regs[UREG_I7]);
6142 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6143 "pte[%lx] error[%lx]\n",
6144@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6145 fp = (unsigned long)sf->fp + STACK_BIAS;
6146 }
6147
6148- printk(" [%016lx] %pS\n", pc, (void *) pc);
6149+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6150 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6151 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6152 int index = tsk->curr_ret_stack;
6153 if (tsk->ret_stack && index >= graph) {
6154 pc = tsk->ret_stack[index - graph].ret;
6155- printk(" [%016lx] %pS\n", pc, (void *) pc);
6156+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6157 graph++;
6158 }
6159 }
6160@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6161 return (struct reg_window *) (fp + STACK_BIAS);
6162 }
6163
6164+extern void gr_handle_kernel_exploit(void);
6165+
6166 void die_if_kernel(char *str, struct pt_regs *regs)
6167 {
6168 static int die_counter;
6169@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6170 while (rw &&
6171 count++ < 30 &&
6172 kstack_valid(tp, (unsigned long) rw)) {
6173- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6174+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6175 (void *) rw->ins[7]);
6176
6177 rw = kernel_stack_up(rw);
6178@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6179 }
6180 user_instruction_dump ((unsigned int __user *) regs->tpc);
6181 }
6182- if (regs->tstate & TSTATE_PRIV)
6183+ if (regs->tstate & TSTATE_PRIV) {
6184+ gr_handle_kernel_exploit();
6185 do_exit(SIGKILL);
6186+ }
6187 do_exit(SIGSEGV);
6188 }
6189 EXPORT_SYMBOL(die_if_kernel);
6190diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6191index f81d038..e7a4680 100644
6192--- a/arch/sparc/kernel/unaligned_64.c
6193+++ b/arch/sparc/kernel/unaligned_64.c
6194@@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6195 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6196
6197 if (__ratelimit(&ratelimit)) {
6198- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6199+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6200 regs->tpc, (void *) regs->tpc);
6201 }
6202 }
6203diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6204index dff4096..bd9a388 100644
6205--- a/arch/sparc/lib/Makefile
6206+++ b/arch/sparc/lib/Makefile
6207@@ -2,7 +2,7 @@
6208 #
6209
6210 asflags-y := -ansi -DST_DIV0=0x02
6211-ccflags-y := -Werror
6212+#ccflags-y := -Werror
6213
6214 lib-$(CONFIG_SPARC32) += ashrdi3.o
6215 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6216diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6217index 4d502da..527c48d 100644
6218--- a/arch/sparc/lib/atomic_64.S
6219+++ b/arch/sparc/lib/atomic_64.S
6220@@ -17,7 +17,12 @@
6221 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6222 BACKOFF_SETUP(%o2)
6223 1: lduw [%o1], %g1
6224- add %g1, %o0, %g7
6225+ addcc %g1, %o0, %g7
6226+
6227+#ifdef CONFIG_PAX_REFCOUNT
6228+ tvs %icc, 6
6229+#endif
6230+
6231 cas [%o1], %g1, %g7
6232 cmp %g1, %g7
6233 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6234@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6235 2: BACKOFF_SPIN(%o2, %o3, 1b)
6236 ENDPROC(atomic_add)
6237
6238+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6239+ BACKOFF_SETUP(%o2)
6240+1: lduw [%o1], %g1
6241+ add %g1, %o0, %g7
6242+ cas [%o1], %g1, %g7
6243+ cmp %g1, %g7
6244+ bne,pn %icc, 2f
6245+ nop
6246+ retl
6247+ nop
6248+2: BACKOFF_SPIN(%o2, %o3, 1b)
6249+ENDPROC(atomic_add_unchecked)
6250+
6251 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6252 BACKOFF_SETUP(%o2)
6253 1: lduw [%o1], %g1
6254- sub %g1, %o0, %g7
6255+ subcc %g1, %o0, %g7
6256+
6257+#ifdef CONFIG_PAX_REFCOUNT
6258+ tvs %icc, 6
6259+#endif
6260+
6261 cas [%o1], %g1, %g7
6262 cmp %g1, %g7
6263 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6264@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6265 2: BACKOFF_SPIN(%o2, %o3, 1b)
6266 ENDPROC(atomic_sub)
6267
6268+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6269+ BACKOFF_SETUP(%o2)
6270+1: lduw [%o1], %g1
6271+ sub %g1, %o0, %g7
6272+ cas [%o1], %g1, %g7
6273+ cmp %g1, %g7
6274+ bne,pn %icc, 2f
6275+ nop
6276+ retl
6277+ nop
6278+2: BACKOFF_SPIN(%o2, %o3, 1b)
6279+ENDPROC(atomic_sub_unchecked)
6280+
6281 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6282 BACKOFF_SETUP(%o2)
6283 1: lduw [%o1], %g1
6284- add %g1, %o0, %g7
6285+ addcc %g1, %o0, %g7
6286+
6287+#ifdef CONFIG_PAX_REFCOUNT
6288+ tvs %icc, 6
6289+#endif
6290+
6291 cas [%o1], %g1, %g7
6292 cmp %g1, %g7
6293 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6294@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6295 2: BACKOFF_SPIN(%o2, %o3, 1b)
6296 ENDPROC(atomic_add_ret)
6297
6298+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6299+ BACKOFF_SETUP(%o2)
6300+1: lduw [%o1], %g1
6301+ addcc %g1, %o0, %g7
6302+ cas [%o1], %g1, %g7
6303+ cmp %g1, %g7
6304+ bne,pn %icc, 2f
6305+ add %g7, %o0, %g7
6306+ sra %g7, 0, %o0
6307+ retl
6308+ nop
6309+2: BACKOFF_SPIN(%o2, %o3, 1b)
6310+ENDPROC(atomic_add_ret_unchecked)
6311+
6312 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6313 BACKOFF_SETUP(%o2)
6314 1: lduw [%o1], %g1
6315- sub %g1, %o0, %g7
6316+ subcc %g1, %o0, %g7
6317+
6318+#ifdef CONFIG_PAX_REFCOUNT
6319+ tvs %icc, 6
6320+#endif
6321+
6322 cas [%o1], %g1, %g7
6323 cmp %g1, %g7
6324 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6325@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6326 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6327 BACKOFF_SETUP(%o2)
6328 1: ldx [%o1], %g1
6329- add %g1, %o0, %g7
6330+ addcc %g1, %o0, %g7
6331+
6332+#ifdef CONFIG_PAX_REFCOUNT
6333+ tvs %xcc, 6
6334+#endif
6335+
6336 casx [%o1], %g1, %g7
6337 cmp %g1, %g7
6338 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6339@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6340 2: BACKOFF_SPIN(%o2, %o3, 1b)
6341 ENDPROC(atomic64_add)
6342
6343+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6344+ BACKOFF_SETUP(%o2)
6345+1: ldx [%o1], %g1
6346+ addcc %g1, %o0, %g7
6347+ casx [%o1], %g1, %g7
6348+ cmp %g1, %g7
6349+ bne,pn %xcc, 2f
6350+ nop
6351+ retl
6352+ nop
6353+2: BACKOFF_SPIN(%o2, %o3, 1b)
6354+ENDPROC(atomic64_add_unchecked)
6355+
6356 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6357 BACKOFF_SETUP(%o2)
6358 1: ldx [%o1], %g1
6359- sub %g1, %o0, %g7
6360+ subcc %g1, %o0, %g7
6361+
6362+#ifdef CONFIG_PAX_REFCOUNT
6363+ tvs %xcc, 6
6364+#endif
6365+
6366 casx [%o1], %g1, %g7
6367 cmp %g1, %g7
6368 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6369@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6370 2: BACKOFF_SPIN(%o2, %o3, 1b)
6371 ENDPROC(atomic64_sub)
6372
6373+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6374+ BACKOFF_SETUP(%o2)
6375+1: ldx [%o1], %g1
6376+ subcc %g1, %o0, %g7
6377+ casx [%o1], %g1, %g7
6378+ cmp %g1, %g7
6379+ bne,pn %xcc, 2f
6380+ nop
6381+ retl
6382+ nop
6383+2: BACKOFF_SPIN(%o2, %o3, 1b)
6384+ENDPROC(atomic64_sub_unchecked)
6385+
6386 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6387 BACKOFF_SETUP(%o2)
6388 1: ldx [%o1], %g1
6389- add %g1, %o0, %g7
6390+ addcc %g1, %o0, %g7
6391+
6392+#ifdef CONFIG_PAX_REFCOUNT
6393+ tvs %xcc, 6
6394+#endif
6395+
6396 casx [%o1], %g1, %g7
6397 cmp %g1, %g7
6398 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6399@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6400 2: BACKOFF_SPIN(%o2, %o3, 1b)
6401 ENDPROC(atomic64_add_ret)
6402
6403+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6404+ BACKOFF_SETUP(%o2)
6405+1: ldx [%o1], %g1
6406+ addcc %g1, %o0, %g7
6407+ casx [%o1], %g1, %g7
6408+ cmp %g1, %g7
6409+ bne,pn %xcc, 2f
6410+ add %g7, %o0, %g7
6411+ mov %g7, %o0
6412+ retl
6413+ nop
6414+2: BACKOFF_SPIN(%o2, %o3, 1b)
6415+ENDPROC(atomic64_add_ret_unchecked)
6416+
6417 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6418 BACKOFF_SETUP(%o2)
6419 1: ldx [%o1], %g1
6420- sub %g1, %o0, %g7
6421+ subcc %g1, %o0, %g7
6422+
6423+#ifdef CONFIG_PAX_REFCOUNT
6424+ tvs %xcc, 6
6425+#endif
6426+
6427 casx [%o1], %g1, %g7
6428 cmp %g1, %g7
6429 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6430diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6431index 3b31218..345c609 100644
6432--- a/arch/sparc/lib/ksyms.c
6433+++ b/arch/sparc/lib/ksyms.c
6434@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6435
6436 /* Atomic counter implementation. */
6437 EXPORT_SYMBOL(atomic_add);
6438+EXPORT_SYMBOL(atomic_add_unchecked);
6439 EXPORT_SYMBOL(atomic_add_ret);
6440+EXPORT_SYMBOL(atomic_add_ret_unchecked);
6441 EXPORT_SYMBOL(atomic_sub);
6442+EXPORT_SYMBOL(atomic_sub_unchecked);
6443 EXPORT_SYMBOL(atomic_sub_ret);
6444 EXPORT_SYMBOL(atomic64_add);
6445+EXPORT_SYMBOL(atomic64_add_unchecked);
6446 EXPORT_SYMBOL(atomic64_add_ret);
6447+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6448 EXPORT_SYMBOL(atomic64_sub);
6449+EXPORT_SYMBOL(atomic64_sub_unchecked);
6450 EXPORT_SYMBOL(atomic64_sub_ret);
6451
6452 /* Atomic bit operations. */
6453diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6454index 30c3ecc..736f015 100644
6455--- a/arch/sparc/mm/Makefile
6456+++ b/arch/sparc/mm/Makefile
6457@@ -2,7 +2,7 @@
6458 #
6459
6460 asflags-y := -ansi
6461-ccflags-y := -Werror
6462+#ccflags-y := -Werror
6463
6464 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6465 obj-y += fault_$(BITS).o
6466diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6467index f46cf6b..cc0666bae 100644
6468--- a/arch/sparc/mm/fault_32.c
6469+++ b/arch/sparc/mm/fault_32.c
6470@@ -21,6 +21,9 @@
6471 #include <linux/perf_event.h>
6472 #include <linux/interrupt.h>
6473 #include <linux/kdebug.h>
6474+#include <linux/slab.h>
6475+#include <linux/pagemap.h>
6476+#include <linux/compiler.h>
6477
6478 #include <asm/page.h>
6479 #include <asm/pgtable.h>
6480@@ -177,6 +180,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6481 return safe_compute_effective_address(regs, insn);
6482 }
6483
6484+#ifdef CONFIG_PAX_PAGEEXEC
6485+#ifdef CONFIG_PAX_DLRESOLVE
6486+static void pax_emuplt_close(struct vm_area_struct *vma)
6487+{
6488+ vma->vm_mm->call_dl_resolve = 0UL;
6489+}
6490+
6491+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6492+{
6493+ unsigned int *kaddr;
6494+
6495+ vmf->page = alloc_page(GFP_HIGHUSER);
6496+ if (!vmf->page)
6497+ return VM_FAULT_OOM;
6498+
6499+ kaddr = kmap(vmf->page);
6500+ memset(kaddr, 0, PAGE_SIZE);
6501+ kaddr[0] = 0x9DE3BFA8U; /* save */
6502+ flush_dcache_page(vmf->page);
6503+ kunmap(vmf->page);
6504+ return VM_FAULT_MAJOR;
6505+}
6506+
6507+static const struct vm_operations_struct pax_vm_ops = {
6508+ .close = pax_emuplt_close,
6509+ .fault = pax_emuplt_fault
6510+};
6511+
6512+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6513+{
6514+ int ret;
6515+
6516+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6517+ vma->vm_mm = current->mm;
6518+ vma->vm_start = addr;
6519+ vma->vm_end = addr + PAGE_SIZE;
6520+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6521+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6522+ vma->vm_ops = &pax_vm_ops;
6523+
6524+ ret = insert_vm_struct(current->mm, vma);
6525+ if (ret)
6526+ return ret;
6527+
6528+ ++current->mm->total_vm;
6529+ return 0;
6530+}
6531+#endif
6532+
6533+/*
6534+ * PaX: decide what to do with offenders (regs->pc = fault address)
6535+ *
6536+ * returns 1 when task should be killed
6537+ * 2 when patched PLT trampoline was detected
6538+ * 3 when unpatched PLT trampoline was detected
6539+ */
6540+static int pax_handle_fetch_fault(struct pt_regs *regs)
6541+{
6542+
6543+#ifdef CONFIG_PAX_EMUPLT
6544+ int err;
6545+
6546+ do { /* PaX: patched PLT emulation #1 */
6547+ unsigned int sethi1, sethi2, jmpl;
6548+
6549+ err = get_user(sethi1, (unsigned int *)regs->pc);
6550+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6551+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6552+
6553+ if (err)
6554+ break;
6555+
6556+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6557+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6558+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6559+ {
6560+ unsigned int addr;
6561+
6562+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6563+ addr = regs->u_regs[UREG_G1];
6564+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6565+ regs->pc = addr;
6566+ regs->npc = addr+4;
6567+ return 2;
6568+ }
6569+ } while (0);
6570+
6571+ do { /* PaX: patched PLT emulation #2 */
6572+ unsigned int ba;
6573+
6574+ err = get_user(ba, (unsigned int *)regs->pc);
6575+
6576+ if (err)
6577+ break;
6578+
6579+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6580+ unsigned int addr;
6581+
6582+ if ((ba & 0xFFC00000U) == 0x30800000U)
6583+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6584+ else
6585+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6586+ regs->pc = addr;
6587+ regs->npc = addr+4;
6588+ return 2;
6589+ }
6590+ } while (0);
6591+
6592+ do { /* PaX: patched PLT emulation #3 */
6593+ unsigned int sethi, bajmpl, nop;
6594+
6595+ err = get_user(sethi, (unsigned int *)regs->pc);
6596+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6597+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6598+
6599+ if (err)
6600+ break;
6601+
6602+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6603+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6604+ nop == 0x01000000U)
6605+ {
6606+ unsigned int addr;
6607+
6608+ addr = (sethi & 0x003FFFFFU) << 10;
6609+ regs->u_regs[UREG_G1] = addr;
6610+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6611+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6612+ else
6613+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6614+ regs->pc = addr;
6615+ regs->npc = addr+4;
6616+ return 2;
6617+ }
6618+ } while (0);
6619+
6620+ do { /* PaX: unpatched PLT emulation step 1 */
6621+ unsigned int sethi, ba, nop;
6622+
6623+ err = get_user(sethi, (unsigned int *)regs->pc);
6624+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6625+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6626+
6627+ if (err)
6628+ break;
6629+
6630+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6631+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6632+ nop == 0x01000000U)
6633+ {
6634+ unsigned int addr, save, call;
6635+
6636+ if ((ba & 0xFFC00000U) == 0x30800000U)
6637+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6638+ else
6639+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6640+
6641+ err = get_user(save, (unsigned int *)addr);
6642+ err |= get_user(call, (unsigned int *)(addr+4));
6643+ err |= get_user(nop, (unsigned int *)(addr+8));
6644+ if (err)
6645+ break;
6646+
6647+#ifdef CONFIG_PAX_DLRESOLVE
6648+ if (save == 0x9DE3BFA8U &&
6649+ (call & 0xC0000000U) == 0x40000000U &&
6650+ nop == 0x01000000U)
6651+ {
6652+ struct vm_area_struct *vma;
6653+ unsigned long call_dl_resolve;
6654+
6655+ down_read(&current->mm->mmap_sem);
6656+ call_dl_resolve = current->mm->call_dl_resolve;
6657+ up_read(&current->mm->mmap_sem);
6658+ if (likely(call_dl_resolve))
6659+ goto emulate;
6660+
6661+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6662+
6663+ down_write(&current->mm->mmap_sem);
6664+ if (current->mm->call_dl_resolve) {
6665+ call_dl_resolve = current->mm->call_dl_resolve;
6666+ up_write(&current->mm->mmap_sem);
6667+ if (vma)
6668+ kmem_cache_free(vm_area_cachep, vma);
6669+ goto emulate;
6670+ }
6671+
6672+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6673+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6674+ up_write(&current->mm->mmap_sem);
6675+ if (vma)
6676+ kmem_cache_free(vm_area_cachep, vma);
6677+ return 1;
6678+ }
6679+
6680+ if (pax_insert_vma(vma, call_dl_resolve)) {
6681+ up_write(&current->mm->mmap_sem);
6682+ kmem_cache_free(vm_area_cachep, vma);
6683+ return 1;
6684+ }
6685+
6686+ current->mm->call_dl_resolve = call_dl_resolve;
6687+ up_write(&current->mm->mmap_sem);
6688+
6689+emulate:
6690+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6691+ regs->pc = call_dl_resolve;
6692+ regs->npc = addr+4;
6693+ return 3;
6694+ }
6695+#endif
6696+
6697+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6698+ if ((save & 0xFFC00000U) == 0x05000000U &&
6699+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6700+ nop == 0x01000000U)
6701+ {
6702+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6703+ regs->u_regs[UREG_G2] = addr + 4;
6704+ addr = (save & 0x003FFFFFU) << 10;
6705+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6706+ regs->pc = addr;
6707+ regs->npc = addr+4;
6708+ return 3;
6709+ }
6710+ }
6711+ } while (0);
6712+
6713+ do { /* PaX: unpatched PLT emulation step 2 */
6714+ unsigned int save, call, nop;
6715+
6716+ err = get_user(save, (unsigned int *)(regs->pc-4));
6717+ err |= get_user(call, (unsigned int *)regs->pc);
6718+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6719+ if (err)
6720+ break;
6721+
6722+ if (save == 0x9DE3BFA8U &&
6723+ (call & 0xC0000000U) == 0x40000000U &&
6724+ nop == 0x01000000U)
6725+ {
6726+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6727+
6728+ regs->u_regs[UREG_RETPC] = regs->pc;
6729+ regs->pc = dl_resolve;
6730+ regs->npc = dl_resolve+4;
6731+ return 3;
6732+ }
6733+ } while (0);
6734+#endif
6735+
6736+ return 1;
6737+}
6738+
6739+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6740+{
6741+ unsigned long i;
6742+
6743+ printk(KERN_ERR "PAX: bytes at PC: ");
6744+ for (i = 0; i < 8; i++) {
6745+ unsigned int c;
6746+ if (get_user(c, (unsigned int *)pc+i))
6747+ printk(KERN_CONT "???????? ");
6748+ else
6749+ printk(KERN_CONT "%08x ", c);
6750+ }
6751+ printk("\n");
6752+}
6753+#endif
6754+
6755 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6756 int text_fault)
6757 {
6758@@ -248,6 +522,24 @@ good_area:
6759 if (!(vma->vm_flags & VM_WRITE))
6760 goto bad_area;
6761 } else {
6762+
6763+#ifdef CONFIG_PAX_PAGEEXEC
6764+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6765+ up_read(&mm->mmap_sem);
6766+ switch (pax_handle_fetch_fault(regs)) {
6767+
6768+#ifdef CONFIG_PAX_EMUPLT
6769+ case 2:
6770+ case 3:
6771+ return;
6772+#endif
6773+
6774+ }
6775+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6776+ do_group_exit(SIGKILL);
6777+ }
6778+#endif
6779+
6780 /* Allow reads even for write-only mappings */
6781 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6782 goto bad_area;
6783diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6784index 1fe0429..8dd5dd5 100644
6785--- a/arch/sparc/mm/fault_64.c
6786+++ b/arch/sparc/mm/fault_64.c
6787@@ -21,6 +21,9 @@
6788 #include <linux/kprobes.h>
6789 #include <linux/kdebug.h>
6790 #include <linux/percpu.h>
6791+#include <linux/slab.h>
6792+#include <linux/pagemap.h>
6793+#include <linux/compiler.h>
6794
6795 #include <asm/page.h>
6796 #include <asm/pgtable.h>
6797@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6798 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6799 regs->tpc);
6800 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6801- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6802+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6803 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6804 dump_stack();
6805 unhandled_fault(regs->tpc, current, regs);
6806@@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6807 show_regs(regs);
6808 }
6809
6810+#ifdef CONFIG_PAX_PAGEEXEC
6811+#ifdef CONFIG_PAX_DLRESOLVE
6812+static void pax_emuplt_close(struct vm_area_struct *vma)
6813+{
6814+ vma->vm_mm->call_dl_resolve = 0UL;
6815+}
6816+
6817+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6818+{
6819+ unsigned int *kaddr;
6820+
6821+ vmf->page = alloc_page(GFP_HIGHUSER);
6822+ if (!vmf->page)
6823+ return VM_FAULT_OOM;
6824+
6825+ kaddr = kmap(vmf->page);
6826+ memset(kaddr, 0, PAGE_SIZE);
6827+ kaddr[0] = 0x9DE3BFA8U; /* save */
6828+ flush_dcache_page(vmf->page);
6829+ kunmap(vmf->page);
6830+ return VM_FAULT_MAJOR;
6831+}
6832+
6833+static const struct vm_operations_struct pax_vm_ops = {
6834+ .close = pax_emuplt_close,
6835+ .fault = pax_emuplt_fault
6836+};
6837+
6838+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6839+{
6840+ int ret;
6841+
6842+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6843+ vma->vm_mm = current->mm;
6844+ vma->vm_start = addr;
6845+ vma->vm_end = addr + PAGE_SIZE;
6846+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6847+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6848+ vma->vm_ops = &pax_vm_ops;
6849+
6850+ ret = insert_vm_struct(current->mm, vma);
6851+ if (ret)
6852+ return ret;
6853+
6854+ ++current->mm->total_vm;
6855+ return 0;
6856+}
6857+#endif
6858+
6859+/*
6860+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6861+ *
6862+ * returns 1 when task should be killed
6863+ * 2 when patched PLT trampoline was detected
6864+ * 3 when unpatched PLT trampoline was detected
6865+ */
6866+static int pax_handle_fetch_fault(struct pt_regs *regs)
6867+{
6868+
6869+#ifdef CONFIG_PAX_EMUPLT
6870+ int err;
6871+
6872+ do { /* PaX: patched PLT emulation #1 */
6873+ unsigned int sethi1, sethi2, jmpl;
6874+
6875+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6876+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6877+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6878+
6879+ if (err)
6880+ break;
6881+
6882+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6883+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6884+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6885+ {
6886+ unsigned long addr;
6887+
6888+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6889+ addr = regs->u_regs[UREG_G1];
6890+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6891+
6892+ if (test_thread_flag(TIF_32BIT))
6893+ addr &= 0xFFFFFFFFUL;
6894+
6895+ regs->tpc = addr;
6896+ regs->tnpc = addr+4;
6897+ return 2;
6898+ }
6899+ } while (0);
6900+
6901+ do { /* PaX: patched PLT emulation #2 */
6902+ unsigned int ba;
6903+
6904+ err = get_user(ba, (unsigned int *)regs->tpc);
6905+
6906+ if (err)
6907+ break;
6908+
6909+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6910+ unsigned long addr;
6911+
6912+ if ((ba & 0xFFC00000U) == 0x30800000U)
6913+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6914+ else
6915+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6916+
6917+ if (test_thread_flag(TIF_32BIT))
6918+ addr &= 0xFFFFFFFFUL;
6919+
6920+ regs->tpc = addr;
6921+ regs->tnpc = addr+4;
6922+ return 2;
6923+ }
6924+ } while (0);
6925+
6926+ do { /* PaX: patched PLT emulation #3 */
6927+ unsigned int sethi, bajmpl, nop;
6928+
6929+ err = get_user(sethi, (unsigned int *)regs->tpc);
6930+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6931+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6932+
6933+ if (err)
6934+ break;
6935+
6936+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6937+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6938+ nop == 0x01000000U)
6939+ {
6940+ unsigned long addr;
6941+
6942+ addr = (sethi & 0x003FFFFFU) << 10;
6943+ regs->u_regs[UREG_G1] = addr;
6944+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6945+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6946+ else
6947+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6948+
6949+ if (test_thread_flag(TIF_32BIT))
6950+ addr &= 0xFFFFFFFFUL;
6951+
6952+ regs->tpc = addr;
6953+ regs->tnpc = addr+4;
6954+ return 2;
6955+ }
6956+ } while (0);
6957+
6958+ do { /* PaX: patched PLT emulation #4 */
6959+ unsigned int sethi, mov1, call, mov2;
6960+
6961+ err = get_user(sethi, (unsigned int *)regs->tpc);
6962+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6963+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
6964+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6965+
6966+ if (err)
6967+ break;
6968+
6969+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6970+ mov1 == 0x8210000FU &&
6971+ (call & 0xC0000000U) == 0x40000000U &&
6972+ mov2 == 0x9E100001U)
6973+ {
6974+ unsigned long addr;
6975+
6976+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6977+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6978+
6979+ if (test_thread_flag(TIF_32BIT))
6980+ addr &= 0xFFFFFFFFUL;
6981+
6982+ regs->tpc = addr;
6983+ regs->tnpc = addr+4;
6984+ return 2;
6985+ }
6986+ } while (0);
6987+
6988+ do { /* PaX: patched PLT emulation #5 */
6989+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6990+
6991+ err = get_user(sethi, (unsigned int *)regs->tpc);
6992+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6993+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6994+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6995+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6996+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6997+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6998+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6999+
7000+ if (err)
7001+ break;
7002+
7003+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7004+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7005+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7006+ (or1 & 0xFFFFE000U) == 0x82106000U &&
7007+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7008+ sllx == 0x83287020U &&
7009+ jmpl == 0x81C04005U &&
7010+ nop == 0x01000000U)
7011+ {
7012+ unsigned long addr;
7013+
7014+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7015+ regs->u_regs[UREG_G1] <<= 32;
7016+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7017+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7018+ regs->tpc = addr;
7019+ regs->tnpc = addr+4;
7020+ return 2;
7021+ }
7022+ } while (0);
7023+
7024+ do { /* PaX: patched PLT emulation #6 */
7025+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7026+
7027+ err = get_user(sethi, (unsigned int *)regs->tpc);
7028+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7029+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7030+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7031+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
7032+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7033+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7034+
7035+ if (err)
7036+ break;
7037+
7038+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7039+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7040+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7041+ sllx == 0x83287020U &&
7042+ (or & 0xFFFFE000U) == 0x8A116000U &&
7043+ jmpl == 0x81C04005U &&
7044+ nop == 0x01000000U)
7045+ {
7046+ unsigned long addr;
7047+
7048+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7049+ regs->u_regs[UREG_G1] <<= 32;
7050+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7051+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7052+ regs->tpc = addr;
7053+ regs->tnpc = addr+4;
7054+ return 2;
7055+ }
7056+ } while (0);
7057+
7058+ do { /* PaX: unpatched PLT emulation step 1 */
7059+ unsigned int sethi, ba, nop;
7060+
7061+ err = get_user(sethi, (unsigned int *)regs->tpc);
7062+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7063+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7064+
7065+ if (err)
7066+ break;
7067+
7068+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7069+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7070+ nop == 0x01000000U)
7071+ {
7072+ unsigned long addr;
7073+ unsigned int save, call;
7074+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7075+
7076+ if ((ba & 0xFFC00000U) == 0x30800000U)
7077+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7078+ else
7079+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7080+
7081+ if (test_thread_flag(TIF_32BIT))
7082+ addr &= 0xFFFFFFFFUL;
7083+
7084+ err = get_user(save, (unsigned int *)addr);
7085+ err |= get_user(call, (unsigned int *)(addr+4));
7086+ err |= get_user(nop, (unsigned int *)(addr+8));
7087+ if (err)
7088+ break;
7089+
7090+#ifdef CONFIG_PAX_DLRESOLVE
7091+ if (save == 0x9DE3BFA8U &&
7092+ (call & 0xC0000000U) == 0x40000000U &&
7093+ nop == 0x01000000U)
7094+ {
7095+ struct vm_area_struct *vma;
7096+ unsigned long call_dl_resolve;
7097+
7098+ down_read(&current->mm->mmap_sem);
7099+ call_dl_resolve = current->mm->call_dl_resolve;
7100+ up_read(&current->mm->mmap_sem);
7101+ if (likely(call_dl_resolve))
7102+ goto emulate;
7103+
7104+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7105+
7106+ down_write(&current->mm->mmap_sem);
7107+ if (current->mm->call_dl_resolve) {
7108+ call_dl_resolve = current->mm->call_dl_resolve;
7109+ up_write(&current->mm->mmap_sem);
7110+ if (vma)
7111+ kmem_cache_free(vm_area_cachep, vma);
7112+ goto emulate;
7113+ }
7114+
7115+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7116+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7117+ up_write(&current->mm->mmap_sem);
7118+ if (vma)
7119+ kmem_cache_free(vm_area_cachep, vma);
7120+ return 1;
7121+ }
7122+
7123+ if (pax_insert_vma(vma, call_dl_resolve)) {
7124+ up_write(&current->mm->mmap_sem);
7125+ kmem_cache_free(vm_area_cachep, vma);
7126+ return 1;
7127+ }
7128+
7129+ current->mm->call_dl_resolve = call_dl_resolve;
7130+ up_write(&current->mm->mmap_sem);
7131+
7132+emulate:
7133+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7134+ regs->tpc = call_dl_resolve;
7135+ regs->tnpc = addr+4;
7136+ return 3;
7137+ }
7138+#endif
7139+
7140+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7141+ if ((save & 0xFFC00000U) == 0x05000000U &&
7142+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7143+ nop == 0x01000000U)
7144+ {
7145+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7146+ regs->u_regs[UREG_G2] = addr + 4;
7147+ addr = (save & 0x003FFFFFU) << 10;
7148+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7149+
7150+ if (test_thread_flag(TIF_32BIT))
7151+ addr &= 0xFFFFFFFFUL;
7152+
7153+ regs->tpc = addr;
7154+ regs->tnpc = addr+4;
7155+ return 3;
7156+ }
7157+
7158+ /* PaX: 64-bit PLT stub */
7159+ err = get_user(sethi1, (unsigned int *)addr);
7160+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7161+ err |= get_user(or1, (unsigned int *)(addr+8));
7162+ err |= get_user(or2, (unsigned int *)(addr+12));
7163+ err |= get_user(sllx, (unsigned int *)(addr+16));
7164+ err |= get_user(add, (unsigned int *)(addr+20));
7165+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7166+ err |= get_user(nop, (unsigned int *)(addr+28));
7167+ if (err)
7168+ break;
7169+
7170+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7171+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7172+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7173+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7174+ sllx == 0x89293020U &&
7175+ add == 0x8A010005U &&
7176+ jmpl == 0x89C14000U &&
7177+ nop == 0x01000000U)
7178+ {
7179+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7180+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7181+ regs->u_regs[UREG_G4] <<= 32;
7182+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7183+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7184+ regs->u_regs[UREG_G4] = addr + 24;
7185+ addr = regs->u_regs[UREG_G5];
7186+ regs->tpc = addr;
7187+ regs->tnpc = addr+4;
7188+ return 3;
7189+ }
7190+ }
7191+ } while (0);
7192+
7193+#ifdef CONFIG_PAX_DLRESOLVE
7194+ do { /* PaX: unpatched PLT emulation step 2 */
7195+ unsigned int save, call, nop;
7196+
7197+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7198+ err |= get_user(call, (unsigned int *)regs->tpc);
7199+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7200+ if (err)
7201+ break;
7202+
7203+ if (save == 0x9DE3BFA8U &&
7204+ (call & 0xC0000000U) == 0x40000000U &&
7205+ nop == 0x01000000U)
7206+ {
7207+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7208+
7209+ if (test_thread_flag(TIF_32BIT))
7210+ dl_resolve &= 0xFFFFFFFFUL;
7211+
7212+ regs->u_regs[UREG_RETPC] = regs->tpc;
7213+ regs->tpc = dl_resolve;
7214+ regs->tnpc = dl_resolve+4;
7215+ return 3;
7216+ }
7217+ } while (0);
7218+#endif
7219+
7220+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7221+ unsigned int sethi, ba, nop;
7222+
7223+ err = get_user(sethi, (unsigned int *)regs->tpc);
7224+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7225+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7226+
7227+ if (err)
7228+ break;
7229+
7230+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7231+ (ba & 0xFFF00000U) == 0x30600000U &&
7232+ nop == 0x01000000U)
7233+ {
7234+ unsigned long addr;
7235+
7236+ addr = (sethi & 0x003FFFFFU) << 10;
7237+ regs->u_regs[UREG_G1] = addr;
7238+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7239+
7240+ if (test_thread_flag(TIF_32BIT))
7241+ addr &= 0xFFFFFFFFUL;
7242+
7243+ regs->tpc = addr;
7244+ regs->tnpc = addr+4;
7245+ return 2;
7246+ }
7247+ } while (0);
7248+
7249+#endif
7250+
7251+ return 1;
7252+}
7253+
7254+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7255+{
7256+ unsigned long i;
7257+
7258+ printk(KERN_ERR "PAX: bytes at PC: ");
7259+ for (i = 0; i < 8; i++) {
7260+ unsigned int c;
7261+ if (get_user(c, (unsigned int *)pc+i))
7262+ printk(KERN_CONT "???????? ");
7263+ else
7264+ printk(KERN_CONT "%08x ", c);
7265+ }
7266+ printk("\n");
7267+}
7268+#endif
7269+
7270 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7271 {
7272 struct mm_struct *mm = current->mm;
7273@@ -343,6 +806,29 @@ retry:
7274 if (!vma)
7275 goto bad_area;
7276
7277+#ifdef CONFIG_PAX_PAGEEXEC
7278+ /* PaX: detect ITLB misses on non-exec pages */
7279+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7280+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7281+ {
7282+ if (address != regs->tpc)
7283+ goto good_area;
7284+
7285+ up_read(&mm->mmap_sem);
7286+ switch (pax_handle_fetch_fault(regs)) {
7287+
7288+#ifdef CONFIG_PAX_EMUPLT
7289+ case 2:
7290+ case 3:
7291+ return;
7292+#endif
7293+
7294+ }
7295+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7296+ do_group_exit(SIGKILL);
7297+ }
7298+#endif
7299+
7300 /* Pure DTLB misses do not tell us whether the fault causing
7301 * load/store/atomic was a write or not, it only says that there
7302 * was no match. So in such a case we (carefully) read the
7303diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7304index 07e1453..0a7d9e9 100644
7305--- a/arch/sparc/mm/hugetlbpage.c
7306+++ b/arch/sparc/mm/hugetlbpage.c
7307@@ -67,7 +67,7 @@ full_search:
7308 }
7309 return -ENOMEM;
7310 }
7311- if (likely(!vma || addr + len <= vma->vm_start)) {
7312+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7313 /*
7314 * Remember the place where we stopped the search:
7315 */
7316@@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7317 /* make sure it can fit in the remaining address space */
7318 if (likely(addr > len)) {
7319 vma = find_vma(mm, addr-len);
7320- if (!vma || addr <= vma->vm_start) {
7321+ if (check_heap_stack_gap(vma, addr - len, len)) {
7322 /* remember the address as a hint for next time */
7323 return (mm->free_area_cache = addr-len);
7324 }
7325@@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7326 if (unlikely(mm->mmap_base < len))
7327 goto bottomup;
7328
7329- addr = (mm->mmap_base-len) & HPAGE_MASK;
7330+ addr = mm->mmap_base - len;
7331
7332 do {
7333+ addr &= HPAGE_MASK;
7334 /*
7335 * Lookup failure means no vma is above this address,
7336 * else if new region fits below vma->vm_start,
7337 * return with success:
7338 */
7339 vma = find_vma(mm, addr);
7340- if (likely(!vma || addr+len <= vma->vm_start)) {
7341+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7342 /* remember the address as a hint for next time */
7343 return (mm->free_area_cache = addr);
7344 }
7345@@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7346 mm->cached_hole_size = vma->vm_start - addr;
7347
7348 /* try just below the current vma->vm_start */
7349- addr = (vma->vm_start-len) & HPAGE_MASK;
7350- } while (likely(len < vma->vm_start));
7351+ addr = skip_heap_stack_gap(vma, len);
7352+ } while (!IS_ERR_VALUE(addr));
7353
7354 bottomup:
7355 /*
7356@@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7357 if (addr) {
7358 addr = ALIGN(addr, HPAGE_SIZE);
7359 vma = find_vma(mm, addr);
7360- if (task_size - len >= addr &&
7361- (!vma || addr + len <= vma->vm_start))
7362+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7363 return addr;
7364 }
7365 if (mm->get_unmapped_area == arch_get_unmapped_area)
7366diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7367index f4500c6..889656c 100644
7368--- a/arch/tile/include/asm/atomic_64.h
7369+++ b/arch/tile/include/asm/atomic_64.h
7370@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7371
7372 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7373
7374+#define atomic64_read_unchecked(v) atomic64_read(v)
7375+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7376+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7377+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7378+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7379+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7380+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7381+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7382+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7383+
7384 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7385 #define smp_mb__before_atomic_dec() smp_mb()
7386 #define smp_mb__after_atomic_dec() smp_mb()
7387diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7388index 392e533..536b092 100644
7389--- a/arch/tile/include/asm/cache.h
7390+++ b/arch/tile/include/asm/cache.h
7391@@ -15,11 +15,12 @@
7392 #ifndef _ASM_TILE_CACHE_H
7393 #define _ASM_TILE_CACHE_H
7394
7395+#include <linux/const.h>
7396 #include <arch/chip.h>
7397
7398 /* bytes per L1 data cache line */
7399 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7400-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7401+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7402
7403 /* bytes per L2 cache line */
7404 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7405diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7406index 9ab078a..d6635c2 100644
7407--- a/arch/tile/include/asm/uaccess.h
7408+++ b/arch/tile/include/asm/uaccess.h
7409@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7410 const void __user *from,
7411 unsigned long n)
7412 {
7413- int sz = __compiletime_object_size(to);
7414+ size_t sz = __compiletime_object_size(to);
7415
7416- if (likely(sz == -1 || sz >= n))
7417+ if (likely(sz == (size_t)-1 || sz >= n))
7418 n = _copy_from_user(to, from, n);
7419 else
7420 copy_from_user_overflow();
7421diff --git a/arch/um/Makefile b/arch/um/Makefile
7422index 0970910..13adb57a 100644
7423--- a/arch/um/Makefile
7424+++ b/arch/um/Makefile
7425@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7426 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7427 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7428
7429+ifdef CONSTIFY_PLUGIN
7430+USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7431+endif
7432+
7433 #This will adjust *FLAGS accordingly to the platform.
7434 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7435
7436diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7437index 19e1bdd..3665b77 100644
7438--- a/arch/um/include/asm/cache.h
7439+++ b/arch/um/include/asm/cache.h
7440@@ -1,6 +1,7 @@
7441 #ifndef __UM_CACHE_H
7442 #define __UM_CACHE_H
7443
7444+#include <linux/const.h>
7445
7446 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7447 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7448@@ -12,6 +13,6 @@
7449 # define L1_CACHE_SHIFT 5
7450 #endif
7451
7452-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7453+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7454
7455 #endif
7456diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7457index 6c03acd..a5e0215 100644
7458--- a/arch/um/include/asm/kmap_types.h
7459+++ b/arch/um/include/asm/kmap_types.h
7460@@ -23,6 +23,7 @@ enum km_type {
7461 KM_IRQ1,
7462 KM_SOFTIRQ0,
7463 KM_SOFTIRQ1,
7464+ KM_CLEARPAGE,
7465 KM_TYPE_NR
7466 };
7467
7468diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7469index 7cfc3ce..cbd1a58 100644
7470--- a/arch/um/include/asm/page.h
7471+++ b/arch/um/include/asm/page.h
7472@@ -14,6 +14,9 @@
7473 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7474 #define PAGE_MASK (~(PAGE_SIZE-1))
7475
7476+#define ktla_ktva(addr) (addr)
7477+#define ktva_ktla(addr) (addr)
7478+
7479 #ifndef __ASSEMBLY__
7480
7481 struct page;
7482diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7483index 0032f92..cd151e0 100644
7484--- a/arch/um/include/asm/pgtable-3level.h
7485+++ b/arch/um/include/asm/pgtable-3level.h
7486@@ -58,6 +58,7 @@
7487 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7488 #define pud_populate(mm, pud, pmd) \
7489 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7490+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7491
7492 #ifdef CONFIG_64BIT
7493 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7494diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7495index ccb9a9d..cc425bb 100644
7496--- a/arch/um/kernel/process.c
7497+++ b/arch/um/kernel/process.c
7498@@ -407,22 +407,6 @@ int singlestepping(void * t)
7499 return 2;
7500 }
7501
7502-/*
7503- * Only x86 and x86_64 have an arch_align_stack().
7504- * All other arches have "#define arch_align_stack(x) (x)"
7505- * in their asm/system.h
7506- * As this is included in UML from asm-um/system-generic.h,
7507- * we can use it to behave as the subarch does.
7508- */
7509-#ifndef arch_align_stack
7510-unsigned long arch_align_stack(unsigned long sp)
7511-{
7512- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7513- sp -= get_random_int() % 8192;
7514- return sp & ~0xf;
7515-}
7516-#endif
7517-
7518 unsigned long get_wchan(struct task_struct *p)
7519 {
7520 unsigned long stack_page, sp, ip;
7521diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7522index ad8f795..2c7eec6 100644
7523--- a/arch/unicore32/include/asm/cache.h
7524+++ b/arch/unicore32/include/asm/cache.h
7525@@ -12,8 +12,10 @@
7526 #ifndef __UNICORE_CACHE_H__
7527 #define __UNICORE_CACHE_H__
7528
7529-#define L1_CACHE_SHIFT (5)
7530-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7531+#include <linux/const.h>
7532+
7533+#define L1_CACHE_SHIFT 5
7534+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7535
7536 /*
7537 * Memory returned by kmalloc() may be used for DMA, so we must make
7538diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7539index c70684f..698fa4b 100644
7540--- a/arch/x86/Kconfig
7541+++ b/arch/x86/Kconfig
7542@@ -218,7 +218,7 @@ config X86_HT
7543
7544 config X86_32_LAZY_GS
7545 def_bool y
7546- depends on X86_32 && !CC_STACKPROTECTOR
7547+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7548
7549 config ARCH_HWEIGHT_CFLAGS
7550 string
7551@@ -1047,7 +1047,7 @@ choice
7552
7553 config NOHIGHMEM
7554 bool "off"
7555- depends on !X86_NUMAQ
7556+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7557 ---help---
7558 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7559 However, the address space of 32-bit x86 processors is only 4
7560@@ -1084,7 +1084,7 @@ config NOHIGHMEM
7561
7562 config HIGHMEM4G
7563 bool "4GB"
7564- depends on !X86_NUMAQ
7565+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7566 ---help---
7567 Select this if you have a 32-bit processor and between 1 and 4
7568 gigabytes of physical RAM.
7569@@ -1138,7 +1138,7 @@ config PAGE_OFFSET
7570 hex
7571 default 0xB0000000 if VMSPLIT_3G_OPT
7572 default 0x80000000 if VMSPLIT_2G
7573- default 0x78000000 if VMSPLIT_2G_OPT
7574+ default 0x70000000 if VMSPLIT_2G_OPT
7575 default 0x40000000 if VMSPLIT_1G
7576 default 0xC0000000
7577 depends on X86_32
7578@@ -1526,6 +1526,7 @@ config SECCOMP
7579
7580 config CC_STACKPROTECTOR
7581 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7582+ depends on X86_64 || !PAX_MEMORY_UDEREF
7583 ---help---
7584 This option turns on the -fstack-protector GCC feature. This
7585 feature puts, at the beginning of functions, a canary value on
7586@@ -1583,6 +1584,7 @@ config KEXEC_JUMP
7587 config PHYSICAL_START
7588 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7589 default "0x1000000"
7590+ range 0x400000 0x40000000
7591 ---help---
7592 This gives the physical address where the kernel is loaded.
7593
7594@@ -1646,6 +1648,7 @@ config X86_NEED_RELOCS
7595 config PHYSICAL_ALIGN
7596 hex "Alignment value to which kernel should be aligned" if X86_32
7597 default "0x1000000"
7598+ range 0x400000 0x1000000 if PAX_KERNEXEC
7599 range 0x2000 0x1000000
7600 ---help---
7601 This value puts the alignment restrictions on physical address
7602@@ -1677,9 +1680,10 @@ config HOTPLUG_CPU
7603 Say N if you want to disable CPU hotplug.
7604
7605 config COMPAT_VDSO
7606- def_bool y
7607+ def_bool n
7608 prompt "Compat VDSO support"
7609 depends on X86_32 || IA32_EMULATION
7610+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7611 ---help---
7612 Map the 32-bit VDSO to the predictable old-style address too.
7613
7614diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7615index 706e12e..62e4feb 100644
7616--- a/arch/x86/Kconfig.cpu
7617+++ b/arch/x86/Kconfig.cpu
7618@@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7619
7620 config X86_F00F_BUG
7621 def_bool y
7622- depends on M586MMX || M586TSC || M586 || M486 || M386
7623+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7624
7625 config X86_INVD_BUG
7626 def_bool y
7627@@ -358,7 +358,7 @@ config X86_POPAD_OK
7628
7629 config X86_ALIGNMENT_16
7630 def_bool y
7631- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7632+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7633
7634 config X86_INTEL_USERCOPY
7635 def_bool y
7636@@ -404,7 +404,7 @@ config X86_CMPXCHG64
7637 # generates cmov.
7638 config X86_CMOV
7639 def_bool y
7640- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7641+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7642
7643 config X86_MINIMUM_CPU_FAMILY
7644 int
7645diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7646index e46c214..ab62fd1 100644
7647--- a/arch/x86/Kconfig.debug
7648+++ b/arch/x86/Kconfig.debug
7649@@ -84,7 +84,7 @@ config X86_PTDUMP
7650 config DEBUG_RODATA
7651 bool "Write protect kernel read-only data structures"
7652 default y
7653- depends on DEBUG_KERNEL
7654+ depends on DEBUG_KERNEL && BROKEN
7655 ---help---
7656 Mark the kernel read-only data as write-protected in the pagetables,
7657 in order to catch accidental (and incorrect) writes to such const
7658@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7659
7660 config DEBUG_SET_MODULE_RONX
7661 bool "Set loadable kernel module data as NX and text as RO"
7662- depends on MODULES
7663+ depends on MODULES && BROKEN
7664 ---help---
7665 This option helps catch unintended modifications to loadable
7666 kernel module's text and read-only data. It also prevents execution
7667@@ -275,7 +275,7 @@ config OPTIMIZE_INLINING
7668
7669 config DEBUG_STRICT_USER_COPY_CHECKS
7670 bool "Strict copy size checks"
7671- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7672+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7673 ---help---
7674 Enabling this option turns a certain set of sanity checks for user
7675 copy operations into compile time failures.
7676diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7677index 1f25214..39422b3 100644
7678--- a/arch/x86/Makefile
7679+++ b/arch/x86/Makefile
7680@@ -46,6 +46,7 @@ else
7681 UTS_MACHINE := x86_64
7682 CHECKFLAGS += -D__x86_64__ -m64
7683
7684+ biarch := $(call cc-option,-m64)
7685 KBUILD_AFLAGS += -m64
7686 KBUILD_CFLAGS += -m64
7687
7688@@ -222,3 +223,12 @@ define archhelp
7689 echo ' FDARGS="..." arguments for the booted kernel'
7690 echo ' FDINITRD=file initrd for the booted kernel'
7691 endef
7692+
7693+define OLD_LD
7694+
7695+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7696+*** Please upgrade your binutils to 2.18 or newer
7697+endef
7698+
7699+archprepare:
7700+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7701diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7702index 5a747dd..ff7b12c 100644
7703--- a/arch/x86/boot/Makefile
7704+++ b/arch/x86/boot/Makefile
7705@@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7706 $(call cc-option, -fno-stack-protector) \
7707 $(call cc-option, -mpreferred-stack-boundary=2)
7708 KBUILD_CFLAGS += $(call cc-option, -m32)
7709+ifdef CONSTIFY_PLUGIN
7710+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7711+endif
7712 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7713 GCOV_PROFILE := n
7714
7715diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7716index 878e4b9..20537ab 100644
7717--- a/arch/x86/boot/bitops.h
7718+++ b/arch/x86/boot/bitops.h
7719@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7720 u8 v;
7721 const u32 *p = (const u32 *)addr;
7722
7723- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7724+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7725 return v;
7726 }
7727
7728@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7729
7730 static inline void set_bit(int nr, void *addr)
7731 {
7732- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7733+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7734 }
7735
7736 #endif /* BOOT_BITOPS_H */
7737diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7738index 18997e5..83d9c67 100644
7739--- a/arch/x86/boot/boot.h
7740+++ b/arch/x86/boot/boot.h
7741@@ -85,7 +85,7 @@ static inline void io_delay(void)
7742 static inline u16 ds(void)
7743 {
7744 u16 seg;
7745- asm("movw %%ds,%0" : "=rm" (seg));
7746+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7747 return seg;
7748 }
7749
7750@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7751 static inline int memcmp(const void *s1, const void *s2, size_t len)
7752 {
7753 u8 diff;
7754- asm("repe; cmpsb; setnz %0"
7755+ asm volatile("repe; cmpsb; setnz %0"
7756 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7757 return diff;
7758 }
7759diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7760index e398bb5..3a382ca 100644
7761--- a/arch/x86/boot/compressed/Makefile
7762+++ b/arch/x86/boot/compressed/Makefile
7763@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7764 KBUILD_CFLAGS += $(cflags-y)
7765 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7766 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7767+ifdef CONSTIFY_PLUGIN
7768+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7769+endif
7770
7771 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7772 GCOV_PROFILE := n
7773diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7774index 4e85f5f..39fa641 100644
7775--- a/arch/x86/boot/compressed/eboot.c
7776+++ b/arch/x86/boot/compressed/eboot.c
7777@@ -142,7 +142,6 @@ again:
7778 *addr = max_addr;
7779 }
7780
7781-free_pool:
7782 efi_call_phys1(sys_table->boottime->free_pool, map);
7783
7784 fail:
7785@@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7786 if (i == map_size / desc_size)
7787 status = EFI_NOT_FOUND;
7788
7789-free_pool:
7790 efi_call_phys1(sys_table->boottime->free_pool, map);
7791 fail:
7792 return status;
7793diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7794index c85e3ac..6f5aa80 100644
7795--- a/arch/x86/boot/compressed/head_32.S
7796+++ b/arch/x86/boot/compressed/head_32.S
7797@@ -106,7 +106,7 @@ preferred_addr:
7798 notl %eax
7799 andl %eax, %ebx
7800 #else
7801- movl $LOAD_PHYSICAL_ADDR, %ebx
7802+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7803 #endif
7804
7805 /* Target address to relocate to for decompression */
7806@@ -192,7 +192,7 @@ relocated:
7807 * and where it was actually loaded.
7808 */
7809 movl %ebp, %ebx
7810- subl $LOAD_PHYSICAL_ADDR, %ebx
7811+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7812 jz 2f /* Nothing to be done if loaded at compiled addr. */
7813 /*
7814 * Process relocations.
7815@@ -200,8 +200,7 @@ relocated:
7816
7817 1: subl $4, %edi
7818 movl (%edi), %ecx
7819- testl %ecx, %ecx
7820- jz 2f
7821+ jecxz 2f
7822 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7823 jmp 1b
7824 2:
7825diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7826index 87e03a1..0d94c76 100644
7827--- a/arch/x86/boot/compressed/head_64.S
7828+++ b/arch/x86/boot/compressed/head_64.S
7829@@ -91,7 +91,7 @@ ENTRY(startup_32)
7830 notl %eax
7831 andl %eax, %ebx
7832 #else
7833- movl $LOAD_PHYSICAL_ADDR, %ebx
7834+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7835 #endif
7836
7837 /* Target address to relocate to for decompression */
7838@@ -263,7 +263,7 @@ preferred_addr:
7839 notq %rax
7840 andq %rax, %rbp
7841 #else
7842- movq $LOAD_PHYSICAL_ADDR, %rbp
7843+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7844 #endif
7845
7846 /* Target address to relocate to for decompression */
7847diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7848index 7116dcb..d9ae1d7 100644
7849--- a/arch/x86/boot/compressed/misc.c
7850+++ b/arch/x86/boot/compressed/misc.c
7851@@ -310,7 +310,7 @@ static void parse_elf(void *output)
7852 case PT_LOAD:
7853 #ifdef CONFIG_RELOCATABLE
7854 dest = output;
7855- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7856+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7857 #else
7858 dest = (void *)(phdr->p_paddr);
7859 #endif
7860@@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7861 error("Destination address too large");
7862 #endif
7863 #ifndef CONFIG_RELOCATABLE
7864- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7865+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7866 error("Wrong destination address");
7867 #endif
7868
7869diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7870index 4d3ff03..e4972ff 100644
7871--- a/arch/x86/boot/cpucheck.c
7872+++ b/arch/x86/boot/cpucheck.c
7873@@ -74,7 +74,7 @@ static int has_fpu(void)
7874 u16 fcw = -1, fsw = -1;
7875 u32 cr0;
7876
7877- asm("movl %%cr0,%0" : "=r" (cr0));
7878+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
7879 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7880 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7881 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7882@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7883 {
7884 u32 f0, f1;
7885
7886- asm("pushfl ; "
7887+ asm volatile("pushfl ; "
7888 "pushfl ; "
7889 "popl %0 ; "
7890 "movl %0,%1 ; "
7891@@ -115,7 +115,7 @@ static void get_flags(void)
7892 set_bit(X86_FEATURE_FPU, cpu.flags);
7893
7894 if (has_eflag(X86_EFLAGS_ID)) {
7895- asm("cpuid"
7896+ asm volatile("cpuid"
7897 : "=a" (max_intel_level),
7898 "=b" (cpu_vendor[0]),
7899 "=d" (cpu_vendor[1]),
7900@@ -124,7 +124,7 @@ static void get_flags(void)
7901
7902 if (max_intel_level >= 0x00000001 &&
7903 max_intel_level <= 0x0000ffff) {
7904- asm("cpuid"
7905+ asm volatile("cpuid"
7906 : "=a" (tfms),
7907 "=c" (cpu.flags[4]),
7908 "=d" (cpu.flags[0])
7909@@ -136,7 +136,7 @@ static void get_flags(void)
7910 cpu.model += ((tfms >> 16) & 0xf) << 4;
7911 }
7912
7913- asm("cpuid"
7914+ asm volatile("cpuid"
7915 : "=a" (max_amd_level)
7916 : "a" (0x80000000)
7917 : "ebx", "ecx", "edx");
7918@@ -144,7 +144,7 @@ static void get_flags(void)
7919 if (max_amd_level >= 0x80000001 &&
7920 max_amd_level <= 0x8000ffff) {
7921 u32 eax = 0x80000001;
7922- asm("cpuid"
7923+ asm volatile("cpuid"
7924 : "+a" (eax),
7925 "=c" (cpu.flags[6]),
7926 "=d" (cpu.flags[1])
7927@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7928 u32 ecx = MSR_K7_HWCR;
7929 u32 eax, edx;
7930
7931- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7932+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7933 eax &= ~(1 << 15);
7934- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7935+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7936
7937 get_flags(); /* Make sure it really did something */
7938 err = check_flags();
7939@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7940 u32 ecx = MSR_VIA_FCR;
7941 u32 eax, edx;
7942
7943- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7944+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7945 eax |= (1<<1)|(1<<7);
7946- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7947+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7948
7949 set_bit(X86_FEATURE_CX8, cpu.flags);
7950 err = check_flags();
7951@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7952 u32 eax, edx;
7953 u32 level = 1;
7954
7955- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7956- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7957- asm("cpuid"
7958+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7959+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7960+ asm volatile("cpuid"
7961 : "+a" (level), "=d" (cpu.flags[0])
7962 : : "ecx", "ebx");
7963- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7964+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7965
7966 err = check_flags();
7967 }
7968diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7969index efe5acf..22a3784 100644
7970--- a/arch/x86/boot/header.S
7971+++ b/arch/x86/boot/header.S
7972@@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7973 # single linked list of
7974 # struct setup_data
7975
7976-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7977+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7978
7979 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7980+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
7981+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
7982+#else
7983 #define VO_INIT_SIZE (VO__end - VO__text)
7984+#endif
7985 #if ZO_INIT_SIZE > VO_INIT_SIZE
7986 #define INIT_SIZE ZO_INIT_SIZE
7987 #else
7988diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7989index db75d07..8e6d0af 100644
7990--- a/arch/x86/boot/memory.c
7991+++ b/arch/x86/boot/memory.c
7992@@ -19,7 +19,7 @@
7993
7994 static int detect_memory_e820(void)
7995 {
7996- int count = 0;
7997+ unsigned int count = 0;
7998 struct biosregs ireg, oreg;
7999 struct e820entry *desc = boot_params.e820_map;
8000 static struct e820entry buf; /* static so it is zeroed */
8001diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8002index 11e8c6e..fdbb1ed 100644
8003--- a/arch/x86/boot/video-vesa.c
8004+++ b/arch/x86/boot/video-vesa.c
8005@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8006
8007 boot_params.screen_info.vesapm_seg = oreg.es;
8008 boot_params.screen_info.vesapm_off = oreg.di;
8009+ boot_params.screen_info.vesapm_size = oreg.cx;
8010 }
8011
8012 /*
8013diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8014index 43eda28..5ab5fdb 100644
8015--- a/arch/x86/boot/video.c
8016+++ b/arch/x86/boot/video.c
8017@@ -96,7 +96,7 @@ static void store_mode_params(void)
8018 static unsigned int get_entry(void)
8019 {
8020 char entry_buf[4];
8021- int i, len = 0;
8022+ unsigned int i, len = 0;
8023 int key;
8024 unsigned int v;
8025
8026diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8027index 5b577d5..3c1fed4 100644
8028--- a/arch/x86/crypto/aes-x86_64-asm_64.S
8029+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8030@@ -8,6 +8,8 @@
8031 * including this sentence is retained in full.
8032 */
8033
8034+#include <asm/alternative-asm.h>
8035+
8036 .extern crypto_ft_tab
8037 .extern crypto_it_tab
8038 .extern crypto_fl_tab
8039@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8040 je B192; \
8041 leaq 32(r9),r9;
8042
8043+#define ret pax_force_retaddr 0, 1; ret
8044+
8045 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8046 movq r1,r2; \
8047 movq r3,r4; \
8048diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8049index 3470624..201259d 100644
8050--- a/arch/x86/crypto/aesni-intel_asm.S
8051+++ b/arch/x86/crypto/aesni-intel_asm.S
8052@@ -31,6 +31,7 @@
8053
8054 #include <linux/linkage.h>
8055 #include <asm/inst.h>
8056+#include <asm/alternative-asm.h>
8057
8058 #ifdef __x86_64__
8059 .data
8060@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8061 pop %r14
8062 pop %r13
8063 pop %r12
8064+ pax_force_retaddr 0, 1
8065 ret
8066+ENDPROC(aesni_gcm_dec)
8067
8068
8069 /*****************************************************************************
8070@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8071 pop %r14
8072 pop %r13
8073 pop %r12
8074+ pax_force_retaddr 0, 1
8075 ret
8076+ENDPROC(aesni_gcm_enc)
8077
8078 #endif
8079
8080@@ -1714,6 +1719,7 @@ _key_expansion_256a:
8081 pxor %xmm1, %xmm0
8082 movaps %xmm0, (TKEYP)
8083 add $0x10, TKEYP
8084+ pax_force_retaddr_bts
8085 ret
8086
8087 .align 4
8088@@ -1738,6 +1744,7 @@ _key_expansion_192a:
8089 shufps $0b01001110, %xmm2, %xmm1
8090 movaps %xmm1, 0x10(TKEYP)
8091 add $0x20, TKEYP
8092+ pax_force_retaddr_bts
8093 ret
8094
8095 .align 4
8096@@ -1757,6 +1764,7 @@ _key_expansion_192b:
8097
8098 movaps %xmm0, (TKEYP)
8099 add $0x10, TKEYP
8100+ pax_force_retaddr_bts
8101 ret
8102
8103 .align 4
8104@@ -1769,6 +1777,7 @@ _key_expansion_256b:
8105 pxor %xmm1, %xmm2
8106 movaps %xmm2, (TKEYP)
8107 add $0x10, TKEYP
8108+ pax_force_retaddr_bts
8109 ret
8110
8111 /*
8112@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8113 #ifndef __x86_64__
8114 popl KEYP
8115 #endif
8116+ pax_force_retaddr 0, 1
8117 ret
8118+ENDPROC(aesni_set_key)
8119
8120 /*
8121 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8122@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8123 popl KLEN
8124 popl KEYP
8125 #endif
8126+ pax_force_retaddr 0, 1
8127 ret
8128+ENDPROC(aesni_enc)
8129
8130 /*
8131 * _aesni_enc1: internal ABI
8132@@ -1959,6 +1972,7 @@ _aesni_enc1:
8133 AESENC KEY STATE
8134 movaps 0x70(TKEYP), KEY
8135 AESENCLAST KEY STATE
8136+ pax_force_retaddr_bts
8137 ret
8138
8139 /*
8140@@ -2067,6 +2081,7 @@ _aesni_enc4:
8141 AESENCLAST KEY STATE2
8142 AESENCLAST KEY STATE3
8143 AESENCLAST KEY STATE4
8144+ pax_force_retaddr_bts
8145 ret
8146
8147 /*
8148@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8149 popl KLEN
8150 popl KEYP
8151 #endif
8152+ pax_force_retaddr 0, 1
8153 ret
8154+ENDPROC(aesni_dec)
8155
8156 /*
8157 * _aesni_dec1: internal ABI
8158@@ -2146,6 +2163,7 @@ _aesni_dec1:
8159 AESDEC KEY STATE
8160 movaps 0x70(TKEYP), KEY
8161 AESDECLAST KEY STATE
8162+ pax_force_retaddr_bts
8163 ret
8164
8165 /*
8166@@ -2254,6 +2272,7 @@ _aesni_dec4:
8167 AESDECLAST KEY STATE2
8168 AESDECLAST KEY STATE3
8169 AESDECLAST KEY STATE4
8170+ pax_force_retaddr_bts
8171 ret
8172
8173 /*
8174@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8175 popl KEYP
8176 popl LEN
8177 #endif
8178+ pax_force_retaddr 0, 1
8179 ret
8180+ENDPROC(aesni_ecb_enc)
8181
8182 /*
8183 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8184@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8185 popl KEYP
8186 popl LEN
8187 #endif
8188+ pax_force_retaddr 0, 1
8189 ret
8190+ENDPROC(aesni_ecb_dec)
8191
8192 /*
8193 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8194@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8195 popl LEN
8196 popl IVP
8197 #endif
8198+ pax_force_retaddr 0, 1
8199 ret
8200+ENDPROC(aesni_cbc_enc)
8201
8202 /*
8203 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8204@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8205 popl LEN
8206 popl IVP
8207 #endif
8208+ pax_force_retaddr 0, 1
8209 ret
8210+ENDPROC(aesni_cbc_dec)
8211
8212 #ifdef __x86_64__
8213 .align 16
8214@@ -2526,6 +2553,7 @@ _aesni_inc_init:
8215 mov $1, TCTR_LOW
8216 MOVQ_R64_XMM TCTR_LOW INC
8217 MOVQ_R64_XMM CTR TCTR_LOW
8218+ pax_force_retaddr_bts
8219 ret
8220
8221 /*
8222@@ -2554,6 +2582,7 @@ _aesni_inc:
8223 .Linc_low:
8224 movaps CTR, IV
8225 PSHUFB_XMM BSWAP_MASK IV
8226+ pax_force_retaddr_bts
8227 ret
8228
8229 /*
8230@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8231 .Lctr_enc_ret:
8232 movups IV, (IVP)
8233 .Lctr_enc_just_ret:
8234+ pax_force_retaddr 0, 1
8235 ret
8236+ENDPROC(aesni_ctr_enc)
8237 #endif
8238diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8239index 391d245..67f35c2 100644
8240--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8241+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8242@@ -20,6 +20,8 @@
8243 *
8244 */
8245
8246+#include <asm/alternative-asm.h>
8247+
8248 .file "blowfish-x86_64-asm.S"
8249 .text
8250
8251@@ -151,9 +153,11 @@ __blowfish_enc_blk:
8252 jnz __enc_xor;
8253
8254 write_block();
8255+ pax_force_retaddr 0, 1
8256 ret;
8257 __enc_xor:
8258 xor_block();
8259+ pax_force_retaddr 0, 1
8260 ret;
8261
8262 .align 8
8263@@ -188,6 +192,7 @@ blowfish_dec_blk:
8264
8265 movq %r11, %rbp;
8266
8267+ pax_force_retaddr 0, 1
8268 ret;
8269
8270 /**********************************************************************
8271@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8272
8273 popq %rbx;
8274 popq %rbp;
8275+ pax_force_retaddr 0, 1
8276 ret;
8277
8278 __enc_xor4:
8279@@ -349,6 +355,7 @@ __enc_xor4:
8280
8281 popq %rbx;
8282 popq %rbp;
8283+ pax_force_retaddr 0, 1
8284 ret;
8285
8286 .align 8
8287@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8288 popq %rbx;
8289 popq %rbp;
8290
8291+ pax_force_retaddr 0, 1
8292 ret;
8293
8294diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8295index 0b33743..7a56206 100644
8296--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8297+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8298@@ -20,6 +20,8 @@
8299 *
8300 */
8301
8302+#include <asm/alternative-asm.h>
8303+
8304 .file "camellia-x86_64-asm_64.S"
8305 .text
8306
8307@@ -229,12 +231,14 @@ __enc_done:
8308 enc_outunpack(mov, RT1);
8309
8310 movq RRBP, %rbp;
8311+ pax_force_retaddr 0, 1
8312 ret;
8313
8314 __enc_xor:
8315 enc_outunpack(xor, RT1);
8316
8317 movq RRBP, %rbp;
8318+ pax_force_retaddr 0, 1
8319 ret;
8320
8321 .global camellia_dec_blk;
8322@@ -275,6 +279,7 @@ __dec_rounds16:
8323 dec_outunpack();
8324
8325 movq RRBP, %rbp;
8326+ pax_force_retaddr 0, 1
8327 ret;
8328
8329 /**********************************************************************
8330@@ -468,6 +473,7 @@ __enc2_done:
8331
8332 movq RRBP, %rbp;
8333 popq %rbx;
8334+ pax_force_retaddr 0, 1
8335 ret;
8336
8337 __enc2_xor:
8338@@ -475,6 +481,7 @@ __enc2_xor:
8339
8340 movq RRBP, %rbp;
8341 popq %rbx;
8342+ pax_force_retaddr 0, 1
8343 ret;
8344
8345 .global camellia_dec_blk_2way;
8346@@ -517,4 +524,5 @@ __dec2_rounds16:
8347
8348 movq RRBP, %rbp;
8349 movq RXOR, %rbx;
8350+ pax_force_retaddr 0, 1
8351 ret;
8352diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8353index 6214a9b..1f4fc9a 100644
8354--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8355+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8356@@ -1,3 +1,5 @@
8357+#include <asm/alternative-asm.h>
8358+
8359 # enter ECRYPT_encrypt_bytes
8360 .text
8361 .p2align 5
8362@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8363 add %r11,%rsp
8364 mov %rdi,%rax
8365 mov %rsi,%rdx
8366+ pax_force_retaddr 0, 1
8367 ret
8368 # bytesatleast65:
8369 ._bytesatleast65:
8370@@ -891,6 +894,7 @@ ECRYPT_keysetup:
8371 add %r11,%rsp
8372 mov %rdi,%rax
8373 mov %rsi,%rdx
8374+ pax_force_retaddr
8375 ret
8376 # enter ECRYPT_ivsetup
8377 .text
8378@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8379 add %r11,%rsp
8380 mov %rdi,%rax
8381 mov %rsi,%rdx
8382+ pax_force_retaddr
8383 ret
8384diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8385index 3ee1ff0..cbc568b 100644
8386--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8387+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8388@@ -24,6 +24,8 @@
8389 *
8390 */
8391
8392+#include <asm/alternative-asm.h>
8393+
8394 .file "serpent-sse2-x86_64-asm_64.S"
8395 .text
8396
8397@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8398 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8399 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8400
8401+ pax_force_retaddr
8402 ret;
8403
8404 __enc_xor8:
8405 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8406 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8407
8408+ pax_force_retaddr
8409 ret;
8410
8411 .align 8
8412@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8413 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8414 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8415
8416+ pax_force_retaddr
8417 ret;
8418diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8419index b2c2f57..8470cab 100644
8420--- a/arch/x86/crypto/sha1_ssse3_asm.S
8421+++ b/arch/x86/crypto/sha1_ssse3_asm.S
8422@@ -28,6 +28,8 @@
8423 * (at your option) any later version.
8424 */
8425
8426+#include <asm/alternative-asm.h>
8427+
8428 #define CTX %rdi // arg1
8429 #define BUF %rsi // arg2
8430 #define CNT %rdx // arg3
8431@@ -104,6 +106,7 @@
8432 pop %r12
8433 pop %rbp
8434 pop %rbx
8435+ pax_force_retaddr 0, 1
8436 ret
8437
8438 .size \name, .-\name
8439diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8440index 5b012a2..36d5364 100644
8441--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8442+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8443@@ -20,6 +20,8 @@
8444 *
8445 */
8446
8447+#include <asm/alternative-asm.h>
8448+
8449 .file "twofish-x86_64-asm-3way.S"
8450 .text
8451
8452@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8453 popq %r13;
8454 popq %r14;
8455 popq %r15;
8456+ pax_force_retaddr 0, 1
8457 ret;
8458
8459 __enc_xor3:
8460@@ -271,6 +274,7 @@ __enc_xor3:
8461 popq %r13;
8462 popq %r14;
8463 popq %r15;
8464+ pax_force_retaddr 0, 1
8465 ret;
8466
8467 .global twofish_dec_blk_3way
8468@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8469 popq %r13;
8470 popq %r14;
8471 popq %r15;
8472+ pax_force_retaddr 0, 1
8473 ret;
8474
8475diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8476index 7bcf3fc..f53832f 100644
8477--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8478+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8479@@ -21,6 +21,7 @@
8480 .text
8481
8482 #include <asm/asm-offsets.h>
8483+#include <asm/alternative-asm.h>
8484
8485 #define a_offset 0
8486 #define b_offset 4
8487@@ -268,6 +269,7 @@ twofish_enc_blk:
8488
8489 popq R1
8490 movq $1,%rax
8491+ pax_force_retaddr 0, 1
8492 ret
8493
8494 twofish_dec_blk:
8495@@ -319,4 +321,5 @@ twofish_dec_blk:
8496
8497 popq R1
8498 movq $1,%rax
8499+ pax_force_retaddr 0, 1
8500 ret
8501diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8502index 07b3a68..bd2a388 100644
8503--- a/arch/x86/ia32/ia32_aout.c
8504+++ b/arch/x86/ia32/ia32_aout.c
8505@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8506 unsigned long dump_start, dump_size;
8507 struct user32 dump;
8508
8509+ memset(&dump, 0, sizeof(dump));
8510+
8511 fs = get_fs();
8512 set_fs(KERNEL_DS);
8513 has_dumped = 1;
8514diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8515index 673ac9b..7a8c5df 100644
8516--- a/arch/x86/ia32/ia32_signal.c
8517+++ b/arch/x86/ia32/ia32_signal.c
8518@@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8519 }
8520 seg = get_fs();
8521 set_fs(KERNEL_DS);
8522- ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8523+ ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8524 set_fs(seg);
8525 if (ret >= 0 && uoss_ptr) {
8526 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8527@@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8528 */
8529 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8530 size_t frame_size,
8531- void **fpstate)
8532+ void __user **fpstate)
8533 {
8534 unsigned long sp;
8535
8536@@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8537
8538 if (used_math()) {
8539 sp = sp - sig_xstate_ia32_size;
8540- *fpstate = (struct _fpstate_ia32 *) sp;
8541+ *fpstate = (struct _fpstate_ia32 __user *) sp;
8542 if (save_i387_xstate_ia32(*fpstate) < 0)
8543 return (void __user *) -1L;
8544 }
8545@@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8546 sp -= frame_size;
8547 /* Align the stack pointer according to the i386 ABI,
8548 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8549- sp = ((sp + 4) & -16ul) - 4;
8550+ sp = ((sp - 12) & -16ul) - 4;
8551 return (void __user *) sp;
8552 }
8553
8554@@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8555 * These are actually not used anymore, but left because some
8556 * gdb versions depend on them as a marker.
8557 */
8558- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8559+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8560 } put_user_catch(err);
8561
8562 if (err)
8563@@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8564 0xb8,
8565 __NR_ia32_rt_sigreturn,
8566 0x80cd,
8567- 0,
8568+ 0
8569 };
8570
8571 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8572@@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8573
8574 if (ka->sa.sa_flags & SA_RESTORER)
8575 restorer = ka->sa.sa_restorer;
8576+ else if (current->mm->context.vdso)
8577+ /* Return stub is in 32bit vsyscall page */
8578+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8579 else
8580- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8581- rt_sigreturn);
8582+ restorer = &frame->retcode;
8583 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8584
8585 /*
8586 * Not actually used anymore, but left because some gdb
8587 * versions need it.
8588 */
8589- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8590+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8591 } put_user_catch(err);
8592
8593 if (err)
8594diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8595index 20e5f7b..eab8751 100644
8596--- a/arch/x86/ia32/ia32entry.S
8597+++ b/arch/x86/ia32/ia32entry.S
8598@@ -14,8 +14,10 @@
8599 #include <asm/segment.h>
8600 #include <asm/irqflags.h>
8601 #include <asm/asm.h>
8602+#include <asm/pgtable.h>
8603 #include <linux/linkage.h>
8604 #include <linux/err.h>
8605+#include <asm/alternative-asm.h>
8606
8607 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8608 #include <linux/elf-em.h>
8609@@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8610 ENDPROC(native_irq_enable_sysexit)
8611 #endif
8612
8613+ .macro pax_enter_kernel_user
8614+ pax_set_fptr_mask
8615+#ifdef CONFIG_PAX_MEMORY_UDEREF
8616+ call pax_enter_kernel_user
8617+#endif
8618+ .endm
8619+
8620+ .macro pax_exit_kernel_user
8621+#ifdef CONFIG_PAX_MEMORY_UDEREF
8622+ call pax_exit_kernel_user
8623+#endif
8624+#ifdef CONFIG_PAX_RANDKSTACK
8625+ pushq %rax
8626+ pushq %r11
8627+ call pax_randomize_kstack
8628+ popq %r11
8629+ popq %rax
8630+#endif
8631+ .endm
8632+
8633+.macro pax_erase_kstack
8634+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8635+ call pax_erase_kstack
8636+#endif
8637+.endm
8638+
8639 /*
8640 * 32bit SYSENTER instruction entry.
8641 *
8642@@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8643 CFI_REGISTER rsp,rbp
8644 SWAPGS_UNSAFE_STACK
8645 movq PER_CPU_VAR(kernel_stack), %rsp
8646- addq $(KERNEL_STACK_OFFSET),%rsp
8647- /*
8648- * No need to follow this irqs on/off section: the syscall
8649- * disabled irqs, here we enable it straight after entry:
8650- */
8651- ENABLE_INTERRUPTS(CLBR_NONE)
8652 movl %ebp,%ebp /* zero extension */
8653 pushq_cfi $__USER32_DS
8654 /*CFI_REL_OFFSET ss,0*/
8655@@ -134,22 +156,37 @@ ENTRY(ia32_sysenter_target)
8656 CFI_REL_OFFSET rsp,0
8657 pushfq_cfi
8658 /*CFI_REL_OFFSET rflags,0*/
8659- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8660- CFI_REGISTER rip,r10
8661+ orl $X86_EFLAGS_IF,(%rsp)
8662+ GET_THREAD_INFO(%r11)
8663+ movl TI_sysenter_return(%r11), %r11d
8664+ CFI_REGISTER rip,r11
8665 pushq_cfi $__USER32_CS
8666 /*CFI_REL_OFFSET cs,0*/
8667 movl %eax, %eax
8668- pushq_cfi %r10
8669+ pushq_cfi %r11
8670 CFI_REL_OFFSET rip,0
8671 pushq_cfi %rax
8672 cld
8673 SAVE_ARGS 0,1,0
8674+ pax_enter_kernel_user
8675+ /*
8676+ * No need to follow this irqs on/off section: the syscall
8677+ * disabled irqs, here we enable it straight after entry:
8678+ */
8679+ ENABLE_INTERRUPTS(CLBR_NONE)
8680 /* no need to do an access_ok check here because rbp has been
8681 32bit zero extended */
8682+
8683+#ifdef CONFIG_PAX_MEMORY_UDEREF
8684+ mov $PAX_USER_SHADOW_BASE,%r11
8685+ add %r11,%rbp
8686+#endif
8687+
8688 1: movl (%rbp),%ebp
8689 _ASM_EXTABLE(1b,ia32_badarg)
8690- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8691- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8692+ GET_THREAD_INFO(%r11)
8693+ orl $TS_COMPAT,TI_status(%r11)
8694+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8695 CFI_REMEMBER_STATE
8696 jnz sysenter_tracesys
8697 cmpq $(IA32_NR_syscalls-1),%rax
8698@@ -159,12 +196,15 @@ sysenter_do_call:
8699 sysenter_dispatch:
8700 call *ia32_sys_call_table(,%rax,8)
8701 movq %rax,RAX-ARGOFFSET(%rsp)
8702+ GET_THREAD_INFO(%r11)
8703 DISABLE_INTERRUPTS(CLBR_NONE)
8704 TRACE_IRQS_OFF
8705- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8706+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8707 jnz sysexit_audit
8708 sysexit_from_sys_call:
8709- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8710+ pax_exit_kernel_user
8711+ pax_erase_kstack
8712+ andl $~TS_COMPAT,TI_status(%r11)
8713 /* clear IF, that popfq doesn't enable interrupts early */
8714 andl $~0x200,EFLAGS-R11(%rsp)
8715 movl RIP-R11(%rsp),%edx /* User %eip */
8716@@ -190,6 +230,9 @@ sysexit_from_sys_call:
8717 movl %eax,%esi /* 2nd arg: syscall number */
8718 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8719 call __audit_syscall_entry
8720+
8721+ pax_erase_kstack
8722+
8723 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8724 cmpq $(IA32_NR_syscalls-1),%rax
8725 ja ia32_badsys
8726@@ -201,7 +244,7 @@ sysexit_from_sys_call:
8727 .endm
8728
8729 .macro auditsys_exit exit
8730- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8731+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8732 jnz ia32_ret_from_sys_call
8733 TRACE_IRQS_ON
8734 sti
8735@@ -212,11 +255,12 @@ sysexit_from_sys_call:
8736 1: setbe %al /* 1 if error, 0 if not */
8737 movzbl %al,%edi /* zero-extend that into %edi */
8738 call __audit_syscall_exit
8739+ GET_THREAD_INFO(%r11)
8740 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8741 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8742 cli
8743 TRACE_IRQS_OFF
8744- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8745+ testl %edi,TI_flags(%r11)
8746 jz \exit
8747 CLEAR_RREGS -ARGOFFSET
8748 jmp int_with_check
8749@@ -234,7 +278,7 @@ sysexit_audit:
8750
8751 sysenter_tracesys:
8752 #ifdef CONFIG_AUDITSYSCALL
8753- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8754+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8755 jz sysenter_auditsys
8756 #endif
8757 SAVE_REST
8758@@ -242,6 +286,9 @@ sysenter_tracesys:
8759 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8760 movq %rsp,%rdi /* &pt_regs -> arg1 */
8761 call syscall_trace_enter
8762+
8763+ pax_erase_kstack
8764+
8765 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8766 RESTORE_REST
8767 cmpq $(IA32_NR_syscalls-1),%rax
8768@@ -273,19 +320,20 @@ ENDPROC(ia32_sysenter_target)
8769 ENTRY(ia32_cstar_target)
8770 CFI_STARTPROC32 simple
8771 CFI_SIGNAL_FRAME
8772- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8773+ CFI_DEF_CFA rsp,0
8774 CFI_REGISTER rip,rcx
8775 /*CFI_REGISTER rflags,r11*/
8776 SWAPGS_UNSAFE_STACK
8777 movl %esp,%r8d
8778 CFI_REGISTER rsp,r8
8779 movq PER_CPU_VAR(kernel_stack),%rsp
8780+ SAVE_ARGS 8*6,0,0
8781+ pax_enter_kernel_user
8782 /*
8783 * No need to follow this irqs on/off section: the syscall
8784 * disabled irqs and here we enable it straight after entry:
8785 */
8786 ENABLE_INTERRUPTS(CLBR_NONE)
8787- SAVE_ARGS 8,0,0
8788 movl %eax,%eax /* zero extension */
8789 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8790 movq %rcx,RIP-ARGOFFSET(%rsp)
8791@@ -301,10 +349,17 @@ ENTRY(ia32_cstar_target)
8792 /* no need to do an access_ok check here because r8 has been
8793 32bit zero extended */
8794 /* hardware stack frame is complete now */
8795+
8796+#ifdef CONFIG_PAX_MEMORY_UDEREF
8797+ mov $PAX_USER_SHADOW_BASE,%r11
8798+ add %r11,%r8
8799+#endif
8800+
8801 1: movl (%r8),%r9d
8802 _ASM_EXTABLE(1b,ia32_badarg)
8803- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8804- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8805+ GET_THREAD_INFO(%r11)
8806+ orl $TS_COMPAT,TI_status(%r11)
8807+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8808 CFI_REMEMBER_STATE
8809 jnz cstar_tracesys
8810 cmpq $IA32_NR_syscalls-1,%rax
8811@@ -314,12 +369,15 @@ cstar_do_call:
8812 cstar_dispatch:
8813 call *ia32_sys_call_table(,%rax,8)
8814 movq %rax,RAX-ARGOFFSET(%rsp)
8815+ GET_THREAD_INFO(%r11)
8816 DISABLE_INTERRUPTS(CLBR_NONE)
8817 TRACE_IRQS_OFF
8818- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8819+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8820 jnz sysretl_audit
8821 sysretl_from_sys_call:
8822- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8823+ pax_exit_kernel_user
8824+ pax_erase_kstack
8825+ andl $~TS_COMPAT,TI_status(%r11)
8826 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8827 movl RIP-ARGOFFSET(%rsp),%ecx
8828 CFI_REGISTER rip,rcx
8829@@ -347,7 +405,7 @@ sysretl_audit:
8830
8831 cstar_tracesys:
8832 #ifdef CONFIG_AUDITSYSCALL
8833- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8834+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8835 jz cstar_auditsys
8836 #endif
8837 xchgl %r9d,%ebp
8838@@ -356,6 +414,9 @@ cstar_tracesys:
8839 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8840 movq %rsp,%rdi /* &pt_regs -> arg1 */
8841 call syscall_trace_enter
8842+
8843+ pax_erase_kstack
8844+
8845 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8846 RESTORE_REST
8847 xchgl %ebp,%r9d
8848@@ -401,19 +462,21 @@ ENTRY(ia32_syscall)
8849 CFI_REL_OFFSET rip,RIP-RIP
8850 PARAVIRT_ADJUST_EXCEPTION_FRAME
8851 SWAPGS
8852- /*
8853- * No need to follow this irqs on/off section: the syscall
8854- * disabled irqs and here we enable it straight after entry:
8855- */
8856- ENABLE_INTERRUPTS(CLBR_NONE)
8857 movl %eax,%eax
8858 pushq_cfi %rax
8859 cld
8860 /* note the registers are not zero extended to the sf.
8861 this could be a problem. */
8862 SAVE_ARGS 0,1,0
8863- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8864- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8865+ pax_enter_kernel_user
8866+ /*
8867+ * No need to follow this irqs on/off section: the syscall
8868+ * disabled irqs and here we enable it straight after entry:
8869+ */
8870+ ENABLE_INTERRUPTS(CLBR_NONE)
8871+ GET_THREAD_INFO(%r11)
8872+ orl $TS_COMPAT,TI_status(%r11)
8873+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8874 jnz ia32_tracesys
8875 cmpq $(IA32_NR_syscalls-1),%rax
8876 ja ia32_badsys
8877@@ -432,6 +495,9 @@ ia32_tracesys:
8878 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8879 movq %rsp,%rdi /* &pt_regs -> arg1 */
8880 call syscall_trace_enter
8881+
8882+ pax_erase_kstack
8883+
8884 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8885 RESTORE_REST
8886 cmpq $(IA32_NR_syscalls-1),%rax
8887diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8888index 4540bec..714d913 100644
8889--- a/arch/x86/ia32/sys_ia32.c
8890+++ b/arch/x86/ia32/sys_ia32.c
8891@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8892 */
8893 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8894 {
8895- typeof(ubuf->st_uid) uid = 0;
8896- typeof(ubuf->st_gid) gid = 0;
8897+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
8898+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
8899 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8900 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8901 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8902@@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8903 return ret;
8904 }
8905
8906-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8907+asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8908 int options)
8909 {
8910 return compat_sys_wait4(pid, stat_addr, options, NULL);
8911@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8912 mm_segment_t old_fs = get_fs();
8913
8914 set_fs(KERNEL_DS);
8915- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8916+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8917 set_fs(old_fs);
8918 if (put_compat_timespec(&t, interval))
8919 return -EFAULT;
8920@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8921 mm_segment_t old_fs = get_fs();
8922
8923 set_fs(KERNEL_DS);
8924- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8925+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8926 set_fs(old_fs);
8927 if (!ret) {
8928 switch (_NSIG_WORDS) {
8929@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8930 if (copy_siginfo_from_user32(&info, uinfo))
8931 return -EFAULT;
8932 set_fs(KERNEL_DS);
8933- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8934+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8935 set_fs(old_fs);
8936 return ret;
8937 }
8938@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8939 return -EFAULT;
8940
8941 set_fs(KERNEL_DS);
8942- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8943+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8944 count);
8945 set_fs(old_fs);
8946
8947diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8948index 952bd01..7692c6f 100644
8949--- a/arch/x86/include/asm/alternative-asm.h
8950+++ b/arch/x86/include/asm/alternative-asm.h
8951@@ -15,6 +15,45 @@
8952 .endm
8953 #endif
8954
8955+#ifdef KERNEXEC_PLUGIN
8956+ .macro pax_force_retaddr_bts rip=0
8957+ btsq $63,\rip(%rsp)
8958+ .endm
8959+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8960+ .macro pax_force_retaddr rip=0, reload=0
8961+ btsq $63,\rip(%rsp)
8962+ .endm
8963+ .macro pax_force_fptr ptr
8964+ btsq $63,\ptr
8965+ .endm
8966+ .macro pax_set_fptr_mask
8967+ .endm
8968+#endif
8969+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8970+ .macro pax_force_retaddr rip=0, reload=0
8971+ .if \reload
8972+ pax_set_fptr_mask
8973+ .endif
8974+ orq %r10,\rip(%rsp)
8975+ .endm
8976+ .macro pax_force_fptr ptr
8977+ orq %r10,\ptr
8978+ .endm
8979+ .macro pax_set_fptr_mask
8980+ movabs $0x8000000000000000,%r10
8981+ .endm
8982+#endif
8983+#else
8984+ .macro pax_force_retaddr rip=0, reload=0
8985+ .endm
8986+ .macro pax_force_fptr ptr
8987+ .endm
8988+ .macro pax_force_retaddr_bts rip=0
8989+ .endm
8990+ .macro pax_set_fptr_mask
8991+ .endm
8992+#endif
8993+
8994 .macro altinstruction_entry orig alt feature orig_len alt_len
8995 .long \orig - .
8996 .long \alt - .
8997diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
8998index 49331be..9706065 100644
8999--- a/arch/x86/include/asm/alternative.h
9000+++ b/arch/x86/include/asm/alternative.h
9001@@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9002 ".section .discard,\"aw\",@progbits\n" \
9003 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9004 ".previous\n" \
9005- ".section .altinstr_replacement, \"ax\"\n" \
9006+ ".section .altinstr_replacement, \"a\"\n" \
9007 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9008 ".previous"
9009
9010diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9011index eaff479..3025a63 100644
9012--- a/arch/x86/include/asm/apic.h
9013+++ b/arch/x86/include/asm/apic.h
9014@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9015
9016 #ifdef CONFIG_X86_LOCAL_APIC
9017
9018-extern unsigned int apic_verbosity;
9019+extern int apic_verbosity;
9020 extern int local_apic_timer_c2_ok;
9021
9022 extern int disable_apic;
9023diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9024index 20370c6..a2eb9b0 100644
9025--- a/arch/x86/include/asm/apm.h
9026+++ b/arch/x86/include/asm/apm.h
9027@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9028 __asm__ __volatile__(APM_DO_ZERO_SEGS
9029 "pushl %%edi\n\t"
9030 "pushl %%ebp\n\t"
9031- "lcall *%%cs:apm_bios_entry\n\t"
9032+ "lcall *%%ss:apm_bios_entry\n\t"
9033 "setc %%al\n\t"
9034 "popl %%ebp\n\t"
9035 "popl %%edi\n\t"
9036@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9037 __asm__ __volatile__(APM_DO_ZERO_SEGS
9038 "pushl %%edi\n\t"
9039 "pushl %%ebp\n\t"
9040- "lcall *%%cs:apm_bios_entry\n\t"
9041+ "lcall *%%ss:apm_bios_entry\n\t"
9042 "setc %%bl\n\t"
9043 "popl %%ebp\n\t"
9044 "popl %%edi\n\t"
9045diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9046index 58cb6d4..a4b806c 100644
9047--- a/arch/x86/include/asm/atomic.h
9048+++ b/arch/x86/include/asm/atomic.h
9049@@ -22,7 +22,18 @@
9050 */
9051 static inline int atomic_read(const atomic_t *v)
9052 {
9053- return (*(volatile int *)&(v)->counter);
9054+ return (*(volatile const int *)&(v)->counter);
9055+}
9056+
9057+/**
9058+ * atomic_read_unchecked - read atomic variable
9059+ * @v: pointer of type atomic_unchecked_t
9060+ *
9061+ * Atomically reads the value of @v.
9062+ */
9063+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9064+{
9065+ return (*(volatile const int *)&(v)->counter);
9066 }
9067
9068 /**
9069@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9070 }
9071
9072 /**
9073+ * atomic_set_unchecked - set atomic variable
9074+ * @v: pointer of type atomic_unchecked_t
9075+ * @i: required value
9076+ *
9077+ * Atomically sets the value of @v to @i.
9078+ */
9079+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9080+{
9081+ v->counter = i;
9082+}
9083+
9084+/**
9085 * atomic_add - add integer to atomic variable
9086 * @i: integer value to add
9087 * @v: pointer of type atomic_t
9088@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9089 */
9090 static inline void atomic_add(int i, atomic_t *v)
9091 {
9092- asm volatile(LOCK_PREFIX "addl %1,%0"
9093+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9094+
9095+#ifdef CONFIG_PAX_REFCOUNT
9096+ "jno 0f\n"
9097+ LOCK_PREFIX "subl %1,%0\n"
9098+ "int $4\n0:\n"
9099+ _ASM_EXTABLE(0b, 0b)
9100+#endif
9101+
9102+ : "+m" (v->counter)
9103+ : "ir" (i));
9104+}
9105+
9106+/**
9107+ * atomic_add_unchecked - add integer to atomic variable
9108+ * @i: integer value to add
9109+ * @v: pointer of type atomic_unchecked_t
9110+ *
9111+ * Atomically adds @i to @v.
9112+ */
9113+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9114+{
9115+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9116 : "+m" (v->counter)
9117 : "ir" (i));
9118 }
9119@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9120 */
9121 static inline void atomic_sub(int i, atomic_t *v)
9122 {
9123- asm volatile(LOCK_PREFIX "subl %1,%0"
9124+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9125+
9126+#ifdef CONFIG_PAX_REFCOUNT
9127+ "jno 0f\n"
9128+ LOCK_PREFIX "addl %1,%0\n"
9129+ "int $4\n0:\n"
9130+ _ASM_EXTABLE(0b, 0b)
9131+#endif
9132+
9133+ : "+m" (v->counter)
9134+ : "ir" (i));
9135+}
9136+
9137+/**
9138+ * atomic_sub_unchecked - subtract integer from atomic variable
9139+ * @i: integer value to subtract
9140+ * @v: pointer of type atomic_unchecked_t
9141+ *
9142+ * Atomically subtracts @i from @v.
9143+ */
9144+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9145+{
9146+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9147 : "+m" (v->counter)
9148 : "ir" (i));
9149 }
9150@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9151 {
9152 unsigned char c;
9153
9154- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9155+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
9156+
9157+#ifdef CONFIG_PAX_REFCOUNT
9158+ "jno 0f\n"
9159+ LOCK_PREFIX "addl %2,%0\n"
9160+ "int $4\n0:\n"
9161+ _ASM_EXTABLE(0b, 0b)
9162+#endif
9163+
9164+ "sete %1\n"
9165 : "+m" (v->counter), "=qm" (c)
9166 : "ir" (i) : "memory");
9167 return c;
9168@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9169 */
9170 static inline void atomic_inc(atomic_t *v)
9171 {
9172- asm volatile(LOCK_PREFIX "incl %0"
9173+ asm volatile(LOCK_PREFIX "incl %0\n"
9174+
9175+#ifdef CONFIG_PAX_REFCOUNT
9176+ "jno 0f\n"
9177+ LOCK_PREFIX "decl %0\n"
9178+ "int $4\n0:\n"
9179+ _ASM_EXTABLE(0b, 0b)
9180+#endif
9181+
9182+ : "+m" (v->counter));
9183+}
9184+
9185+/**
9186+ * atomic_inc_unchecked - increment atomic variable
9187+ * @v: pointer of type atomic_unchecked_t
9188+ *
9189+ * Atomically increments @v by 1.
9190+ */
9191+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9192+{
9193+ asm volatile(LOCK_PREFIX "incl %0\n"
9194 : "+m" (v->counter));
9195 }
9196
9197@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9198 */
9199 static inline void atomic_dec(atomic_t *v)
9200 {
9201- asm volatile(LOCK_PREFIX "decl %0"
9202+ asm volatile(LOCK_PREFIX "decl %0\n"
9203+
9204+#ifdef CONFIG_PAX_REFCOUNT
9205+ "jno 0f\n"
9206+ LOCK_PREFIX "incl %0\n"
9207+ "int $4\n0:\n"
9208+ _ASM_EXTABLE(0b, 0b)
9209+#endif
9210+
9211+ : "+m" (v->counter));
9212+}
9213+
9214+/**
9215+ * atomic_dec_unchecked - decrement atomic variable
9216+ * @v: pointer of type atomic_unchecked_t
9217+ *
9218+ * Atomically decrements @v by 1.
9219+ */
9220+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9221+{
9222+ asm volatile(LOCK_PREFIX "decl %0\n"
9223 : "+m" (v->counter));
9224 }
9225
9226@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9227 {
9228 unsigned char c;
9229
9230- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9231+ asm volatile(LOCK_PREFIX "decl %0\n"
9232+
9233+#ifdef CONFIG_PAX_REFCOUNT
9234+ "jno 0f\n"
9235+ LOCK_PREFIX "incl %0\n"
9236+ "int $4\n0:\n"
9237+ _ASM_EXTABLE(0b, 0b)
9238+#endif
9239+
9240+ "sete %1\n"
9241 : "+m" (v->counter), "=qm" (c)
9242 : : "memory");
9243 return c != 0;
9244@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9245 {
9246 unsigned char c;
9247
9248- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9249+ asm volatile(LOCK_PREFIX "incl %0\n"
9250+
9251+#ifdef CONFIG_PAX_REFCOUNT
9252+ "jno 0f\n"
9253+ LOCK_PREFIX "decl %0\n"
9254+ "int $4\n0:\n"
9255+ _ASM_EXTABLE(0b, 0b)
9256+#endif
9257+
9258+ "sete %1\n"
9259+ : "+m" (v->counter), "=qm" (c)
9260+ : : "memory");
9261+ return c != 0;
9262+}
9263+
9264+/**
9265+ * atomic_inc_and_test_unchecked - increment and test
9266+ * @v: pointer of type atomic_unchecked_t
9267+ *
9268+ * Atomically increments @v by 1
9269+ * and returns true if the result is zero, or false for all
9270+ * other cases.
9271+ */
9272+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9273+{
9274+ unsigned char c;
9275+
9276+ asm volatile(LOCK_PREFIX "incl %0\n"
9277+ "sete %1\n"
9278 : "+m" (v->counter), "=qm" (c)
9279 : : "memory");
9280 return c != 0;
9281@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9282 {
9283 unsigned char c;
9284
9285- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9286+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9287+
9288+#ifdef CONFIG_PAX_REFCOUNT
9289+ "jno 0f\n"
9290+ LOCK_PREFIX "subl %2,%0\n"
9291+ "int $4\n0:\n"
9292+ _ASM_EXTABLE(0b, 0b)
9293+#endif
9294+
9295+ "sets %1\n"
9296 : "+m" (v->counter), "=qm" (c)
9297 : "ir" (i) : "memory");
9298 return c;
9299@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9300 goto no_xadd;
9301 #endif
9302 /* Modern 486+ processor */
9303- return i + xadd(&v->counter, i);
9304+ return i + xadd_check_overflow(&v->counter, i);
9305
9306 #ifdef CONFIG_M386
9307 no_xadd: /* Legacy 386 processor */
9308@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9309 }
9310
9311 /**
9312+ * atomic_add_return_unchecked - add integer and return
9313+ * @i: integer value to add
9314+ * @v: pointer of type atomic_unchecked_t
9315+ *
9316+ * Atomically adds @i to @v and returns @i + @v
9317+ */
9318+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9319+{
9320+#ifdef CONFIG_M386
9321+ int __i;
9322+ unsigned long flags;
9323+ if (unlikely(boot_cpu_data.x86 <= 3))
9324+ goto no_xadd;
9325+#endif
9326+ /* Modern 486+ processor */
9327+ return i + xadd(&v->counter, i);
9328+
9329+#ifdef CONFIG_M386
9330+no_xadd: /* Legacy 386 processor */
9331+ raw_local_irq_save(flags);
9332+ __i = atomic_read_unchecked(v);
9333+ atomic_set_unchecked(v, i + __i);
9334+ raw_local_irq_restore(flags);
9335+ return i + __i;
9336+#endif
9337+}
9338+
9339+/**
9340 * atomic_sub_return - subtract integer and return
9341 * @v: pointer of type atomic_t
9342 * @i: integer value to subtract
9343@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9344 }
9345
9346 #define atomic_inc_return(v) (atomic_add_return(1, v))
9347+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9348+{
9349+ return atomic_add_return_unchecked(1, v);
9350+}
9351 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9352
9353 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9354@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9355 return cmpxchg(&v->counter, old, new);
9356 }
9357
9358+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9359+{
9360+ return cmpxchg(&v->counter, old, new);
9361+}
9362+
9363 static inline int atomic_xchg(atomic_t *v, int new)
9364 {
9365 return xchg(&v->counter, new);
9366 }
9367
9368+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9369+{
9370+ return xchg(&v->counter, new);
9371+}
9372+
9373 /**
9374 * __atomic_add_unless - add unless the number is already a given value
9375 * @v: pointer of type atomic_t
9376@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9377 */
9378 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9379 {
9380- int c, old;
9381+ int c, old, new;
9382 c = atomic_read(v);
9383 for (;;) {
9384- if (unlikely(c == (u)))
9385+ if (unlikely(c == u))
9386 break;
9387- old = atomic_cmpxchg((v), c, c + (a));
9388+
9389+ asm volatile("addl %2,%0\n"
9390+
9391+#ifdef CONFIG_PAX_REFCOUNT
9392+ "jno 0f\n"
9393+ "subl %2,%0\n"
9394+ "int $4\n0:\n"
9395+ _ASM_EXTABLE(0b, 0b)
9396+#endif
9397+
9398+ : "=r" (new)
9399+ : "0" (c), "ir" (a));
9400+
9401+ old = atomic_cmpxchg(v, c, new);
9402 if (likely(old == c))
9403 break;
9404 c = old;
9405@@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9406 return c;
9407 }
9408
9409+/**
9410+ * atomic_inc_not_zero_hint - increment if not null
9411+ * @v: pointer of type atomic_t
9412+ * @hint: probable value of the atomic before the increment
9413+ *
9414+ * This version of atomic_inc_not_zero() gives a hint of probable
9415+ * value of the atomic. This helps processor to not read the memory
9416+ * before doing the atomic read/modify/write cycle, lowering
9417+ * number of bus transactions on some arches.
9418+ *
9419+ * Returns: 0 if increment was not done, 1 otherwise.
9420+ */
9421+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9422+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9423+{
9424+ int val, c = hint, new;
9425+
9426+ /* sanity test, should be removed by compiler if hint is a constant */
9427+ if (!hint)
9428+ return __atomic_add_unless(v, 1, 0);
9429+
9430+ do {
9431+ asm volatile("incl %0\n"
9432+
9433+#ifdef CONFIG_PAX_REFCOUNT
9434+ "jno 0f\n"
9435+ "decl %0\n"
9436+ "int $4\n0:\n"
9437+ _ASM_EXTABLE(0b, 0b)
9438+#endif
9439+
9440+ : "=r" (new)
9441+ : "0" (c));
9442+
9443+ val = atomic_cmpxchg(v, c, new);
9444+ if (val == c)
9445+ return 1;
9446+ c = val;
9447+ } while (c);
9448+
9449+ return 0;
9450+}
9451
9452 /*
9453 * atomic_dec_if_positive - decrement by 1 if old value positive
9454@@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9455 #endif
9456
9457 /* These are x86-specific, used by some header files */
9458-#define atomic_clear_mask(mask, addr) \
9459- asm volatile(LOCK_PREFIX "andl %0,%1" \
9460- : : "r" (~(mask)), "m" (*(addr)) : "memory")
9461+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9462+{
9463+ asm volatile(LOCK_PREFIX "andl %1,%0"
9464+ : "+m" (v->counter)
9465+ : "r" (~(mask))
9466+ : "memory");
9467+}
9468
9469-#define atomic_set_mask(mask, addr) \
9470- asm volatile(LOCK_PREFIX "orl %0,%1" \
9471- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9472- : "memory")
9473+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9474+{
9475+ asm volatile(LOCK_PREFIX "andl %1,%0"
9476+ : "+m" (v->counter)
9477+ : "r" (~(mask))
9478+ : "memory");
9479+}
9480+
9481+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9482+{
9483+ asm volatile(LOCK_PREFIX "orl %1,%0"
9484+ : "+m" (v->counter)
9485+ : "r" (mask)
9486+ : "memory");
9487+}
9488+
9489+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9490+{
9491+ asm volatile(LOCK_PREFIX "orl %1,%0"
9492+ : "+m" (v->counter)
9493+ : "r" (mask)
9494+ : "memory");
9495+}
9496
9497 /* Atomic operations are already serializing on x86 */
9498 #define smp_mb__before_atomic_dec() barrier()
9499diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9500index b154de7..aadebd8 100644
9501--- a/arch/x86/include/asm/atomic64_32.h
9502+++ b/arch/x86/include/asm/atomic64_32.h
9503@@ -12,6 +12,14 @@ typedef struct {
9504 u64 __aligned(8) counter;
9505 } atomic64_t;
9506
9507+#ifdef CONFIG_PAX_REFCOUNT
9508+typedef struct {
9509+ u64 __aligned(8) counter;
9510+} atomic64_unchecked_t;
9511+#else
9512+typedef atomic64_t atomic64_unchecked_t;
9513+#endif
9514+
9515 #define ATOMIC64_INIT(val) { (val) }
9516
9517 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9518@@ -37,21 +45,31 @@ typedef struct {
9519 ATOMIC64_DECL_ONE(sym##_386)
9520
9521 ATOMIC64_DECL_ONE(add_386);
9522+ATOMIC64_DECL_ONE(add_unchecked_386);
9523 ATOMIC64_DECL_ONE(sub_386);
9524+ATOMIC64_DECL_ONE(sub_unchecked_386);
9525 ATOMIC64_DECL_ONE(inc_386);
9526+ATOMIC64_DECL_ONE(inc_unchecked_386);
9527 ATOMIC64_DECL_ONE(dec_386);
9528+ATOMIC64_DECL_ONE(dec_unchecked_386);
9529 #endif
9530
9531 #define alternative_atomic64(f, out, in...) \
9532 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9533
9534 ATOMIC64_DECL(read);
9535+ATOMIC64_DECL(read_unchecked);
9536 ATOMIC64_DECL(set);
9537+ATOMIC64_DECL(set_unchecked);
9538 ATOMIC64_DECL(xchg);
9539 ATOMIC64_DECL(add_return);
9540+ATOMIC64_DECL(add_return_unchecked);
9541 ATOMIC64_DECL(sub_return);
9542+ATOMIC64_DECL(sub_return_unchecked);
9543 ATOMIC64_DECL(inc_return);
9544+ATOMIC64_DECL(inc_return_unchecked);
9545 ATOMIC64_DECL(dec_return);
9546+ATOMIC64_DECL(dec_return_unchecked);
9547 ATOMIC64_DECL(dec_if_positive);
9548 ATOMIC64_DECL(inc_not_zero);
9549 ATOMIC64_DECL(add_unless);
9550@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9551 }
9552
9553 /**
9554+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9555+ * @p: pointer to type atomic64_unchecked_t
9556+ * @o: expected value
9557+ * @n: new value
9558+ *
9559+ * Atomically sets @v to @n if it was equal to @o and returns
9560+ * the old value.
9561+ */
9562+
9563+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9564+{
9565+ return cmpxchg64(&v->counter, o, n);
9566+}
9567+
9568+/**
9569 * atomic64_xchg - xchg atomic64 variable
9570 * @v: pointer to type atomic64_t
9571 * @n: value to assign
9572@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9573 }
9574
9575 /**
9576+ * atomic64_set_unchecked - set atomic64 variable
9577+ * @v: pointer to type atomic64_unchecked_t
9578+ * @n: value to assign
9579+ *
9580+ * Atomically sets the value of @v to @n.
9581+ */
9582+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9583+{
9584+ unsigned high = (unsigned)(i >> 32);
9585+ unsigned low = (unsigned)i;
9586+ alternative_atomic64(set, /* no output */,
9587+ "S" (v), "b" (low), "c" (high)
9588+ : "eax", "edx", "memory");
9589+}
9590+
9591+/**
9592 * atomic64_read - read atomic64 variable
9593 * @v: pointer to type atomic64_t
9594 *
9595@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9596 }
9597
9598 /**
9599+ * atomic64_read_unchecked - read atomic64 variable
9600+ * @v: pointer to type atomic64_unchecked_t
9601+ *
9602+ * Atomically reads the value of @v and returns it.
9603+ */
9604+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9605+{
9606+ long long r;
9607+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9608+ return r;
9609+ }
9610+
9611+/**
9612 * atomic64_add_return - add and return
9613 * @i: integer value to add
9614 * @v: pointer to type atomic64_t
9615@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9616 return i;
9617 }
9618
9619+/**
9620+ * atomic64_add_return_unchecked - add and return
9621+ * @i: integer value to add
9622+ * @v: pointer to type atomic64_unchecked_t
9623+ *
9624+ * Atomically adds @i to @v and returns @i + *@v
9625+ */
9626+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9627+{
9628+ alternative_atomic64(add_return_unchecked,
9629+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9630+ ASM_NO_INPUT_CLOBBER("memory"));
9631+ return i;
9632+}
9633+
9634 /*
9635 * Other variants with different arithmetic operators:
9636 */
9637@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9638 return a;
9639 }
9640
9641+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9642+{
9643+ long long a;
9644+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
9645+ "S" (v) : "memory", "ecx");
9646+ return a;
9647+}
9648+
9649 static inline long long atomic64_dec_return(atomic64_t *v)
9650 {
9651 long long a;
9652@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9653 }
9654
9655 /**
9656+ * atomic64_add_unchecked - add integer to atomic64 variable
9657+ * @i: integer value to add
9658+ * @v: pointer to type atomic64_unchecked_t
9659+ *
9660+ * Atomically adds @i to @v.
9661+ */
9662+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9663+{
9664+ __alternative_atomic64(add_unchecked, add_return_unchecked,
9665+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9666+ ASM_NO_INPUT_CLOBBER("memory"));
9667+ return i;
9668+}
9669+
9670+/**
9671 * atomic64_sub - subtract the atomic64 variable
9672 * @i: integer value to subtract
9673 * @v: pointer to type atomic64_t
9674diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9675index 0e1cbfc..5623683 100644
9676--- a/arch/x86/include/asm/atomic64_64.h
9677+++ b/arch/x86/include/asm/atomic64_64.h
9678@@ -18,7 +18,19 @@
9679 */
9680 static inline long atomic64_read(const atomic64_t *v)
9681 {
9682- return (*(volatile long *)&(v)->counter);
9683+ return (*(volatile const long *)&(v)->counter);
9684+}
9685+
9686+/**
9687+ * atomic64_read_unchecked - read atomic64 variable
9688+ * @v: pointer of type atomic64_unchecked_t
9689+ *
9690+ * Atomically reads the value of @v.
9691+ * Doesn't imply a read memory barrier.
9692+ */
9693+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9694+{
9695+ return (*(volatile const long *)&(v)->counter);
9696 }
9697
9698 /**
9699@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9700 }
9701
9702 /**
9703+ * atomic64_set_unchecked - set atomic64 variable
9704+ * @v: pointer to type atomic64_unchecked_t
9705+ * @i: required value
9706+ *
9707+ * Atomically sets the value of @v to @i.
9708+ */
9709+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9710+{
9711+ v->counter = i;
9712+}
9713+
9714+/**
9715 * atomic64_add - add integer to atomic64 variable
9716 * @i: integer value to add
9717 * @v: pointer to type atomic64_t
9718@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9719 */
9720 static inline void atomic64_add(long i, atomic64_t *v)
9721 {
9722+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9723+
9724+#ifdef CONFIG_PAX_REFCOUNT
9725+ "jno 0f\n"
9726+ LOCK_PREFIX "subq %1,%0\n"
9727+ "int $4\n0:\n"
9728+ _ASM_EXTABLE(0b, 0b)
9729+#endif
9730+
9731+ : "=m" (v->counter)
9732+ : "er" (i), "m" (v->counter));
9733+}
9734+
9735+/**
9736+ * atomic64_add_unchecked - add integer to atomic64 variable
9737+ * @i: integer value to add
9738+ * @v: pointer to type atomic64_unchecked_t
9739+ *
9740+ * Atomically adds @i to @v.
9741+ */
9742+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9743+{
9744 asm volatile(LOCK_PREFIX "addq %1,%0"
9745 : "=m" (v->counter)
9746 : "er" (i), "m" (v->counter));
9747@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9748 */
9749 static inline void atomic64_sub(long i, atomic64_t *v)
9750 {
9751- asm volatile(LOCK_PREFIX "subq %1,%0"
9752+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9753+
9754+#ifdef CONFIG_PAX_REFCOUNT
9755+ "jno 0f\n"
9756+ LOCK_PREFIX "addq %1,%0\n"
9757+ "int $4\n0:\n"
9758+ _ASM_EXTABLE(0b, 0b)
9759+#endif
9760+
9761+ : "=m" (v->counter)
9762+ : "er" (i), "m" (v->counter));
9763+}
9764+
9765+/**
9766+ * atomic64_sub_unchecked - subtract the atomic64 variable
9767+ * @i: integer value to subtract
9768+ * @v: pointer to type atomic64_unchecked_t
9769+ *
9770+ * Atomically subtracts @i from @v.
9771+ */
9772+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9773+{
9774+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9775 : "=m" (v->counter)
9776 : "er" (i), "m" (v->counter));
9777 }
9778@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9779 {
9780 unsigned char c;
9781
9782- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9783+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9784+
9785+#ifdef CONFIG_PAX_REFCOUNT
9786+ "jno 0f\n"
9787+ LOCK_PREFIX "addq %2,%0\n"
9788+ "int $4\n0:\n"
9789+ _ASM_EXTABLE(0b, 0b)
9790+#endif
9791+
9792+ "sete %1\n"
9793 : "=m" (v->counter), "=qm" (c)
9794 : "er" (i), "m" (v->counter) : "memory");
9795 return c;
9796@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9797 */
9798 static inline void atomic64_inc(atomic64_t *v)
9799 {
9800+ asm volatile(LOCK_PREFIX "incq %0\n"
9801+
9802+#ifdef CONFIG_PAX_REFCOUNT
9803+ "jno 0f\n"
9804+ LOCK_PREFIX "decq %0\n"
9805+ "int $4\n0:\n"
9806+ _ASM_EXTABLE(0b, 0b)
9807+#endif
9808+
9809+ : "=m" (v->counter)
9810+ : "m" (v->counter));
9811+}
9812+
9813+/**
9814+ * atomic64_inc_unchecked - increment atomic64 variable
9815+ * @v: pointer to type atomic64_unchecked_t
9816+ *
9817+ * Atomically increments @v by 1.
9818+ */
9819+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9820+{
9821 asm volatile(LOCK_PREFIX "incq %0"
9822 : "=m" (v->counter)
9823 : "m" (v->counter));
9824@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9825 */
9826 static inline void atomic64_dec(atomic64_t *v)
9827 {
9828- asm volatile(LOCK_PREFIX "decq %0"
9829+ asm volatile(LOCK_PREFIX "decq %0\n"
9830+
9831+#ifdef CONFIG_PAX_REFCOUNT
9832+ "jno 0f\n"
9833+ LOCK_PREFIX "incq %0\n"
9834+ "int $4\n0:\n"
9835+ _ASM_EXTABLE(0b, 0b)
9836+#endif
9837+
9838+ : "=m" (v->counter)
9839+ : "m" (v->counter));
9840+}
9841+
9842+/**
9843+ * atomic64_dec_unchecked - decrement atomic64 variable
9844+ * @v: pointer to type atomic64_t
9845+ *
9846+ * Atomically decrements @v by 1.
9847+ */
9848+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9849+{
9850+ asm volatile(LOCK_PREFIX "decq %0\n"
9851 : "=m" (v->counter)
9852 : "m" (v->counter));
9853 }
9854@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9855 {
9856 unsigned char c;
9857
9858- asm volatile(LOCK_PREFIX "decq %0; sete %1"
9859+ asm volatile(LOCK_PREFIX "decq %0\n"
9860+
9861+#ifdef CONFIG_PAX_REFCOUNT
9862+ "jno 0f\n"
9863+ LOCK_PREFIX "incq %0\n"
9864+ "int $4\n0:\n"
9865+ _ASM_EXTABLE(0b, 0b)
9866+#endif
9867+
9868+ "sete %1\n"
9869 : "=m" (v->counter), "=qm" (c)
9870 : "m" (v->counter) : "memory");
9871 return c != 0;
9872@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9873 {
9874 unsigned char c;
9875
9876- asm volatile(LOCK_PREFIX "incq %0; sete %1"
9877+ asm volatile(LOCK_PREFIX "incq %0\n"
9878+
9879+#ifdef CONFIG_PAX_REFCOUNT
9880+ "jno 0f\n"
9881+ LOCK_PREFIX "decq %0\n"
9882+ "int $4\n0:\n"
9883+ _ASM_EXTABLE(0b, 0b)
9884+#endif
9885+
9886+ "sete %1\n"
9887 : "=m" (v->counter), "=qm" (c)
9888 : "m" (v->counter) : "memory");
9889 return c != 0;
9890@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9891 {
9892 unsigned char c;
9893
9894- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9895+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
9896+
9897+#ifdef CONFIG_PAX_REFCOUNT
9898+ "jno 0f\n"
9899+ LOCK_PREFIX "subq %2,%0\n"
9900+ "int $4\n0:\n"
9901+ _ASM_EXTABLE(0b, 0b)
9902+#endif
9903+
9904+ "sets %1\n"
9905 : "=m" (v->counter), "=qm" (c)
9906 : "er" (i), "m" (v->counter) : "memory");
9907 return c;
9908@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9909 */
9910 static inline long atomic64_add_return(long i, atomic64_t *v)
9911 {
9912+ return i + xadd_check_overflow(&v->counter, i);
9913+}
9914+
9915+/**
9916+ * atomic64_add_return_unchecked - add and return
9917+ * @i: integer value to add
9918+ * @v: pointer to type atomic64_unchecked_t
9919+ *
9920+ * Atomically adds @i to @v and returns @i + @v
9921+ */
9922+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9923+{
9924 return i + xadd(&v->counter, i);
9925 }
9926
9927@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9928 }
9929
9930 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9931+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9932+{
9933+ return atomic64_add_return_unchecked(1, v);
9934+}
9935 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9936
9937 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9938@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9939 return cmpxchg(&v->counter, old, new);
9940 }
9941
9942+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9943+{
9944+ return cmpxchg(&v->counter, old, new);
9945+}
9946+
9947 static inline long atomic64_xchg(atomic64_t *v, long new)
9948 {
9949 return xchg(&v->counter, new);
9950@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9951 */
9952 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9953 {
9954- long c, old;
9955+ long c, old, new;
9956 c = atomic64_read(v);
9957 for (;;) {
9958- if (unlikely(c == (u)))
9959+ if (unlikely(c == u))
9960 break;
9961- old = atomic64_cmpxchg((v), c, c + (a));
9962+
9963+ asm volatile("add %2,%0\n"
9964+
9965+#ifdef CONFIG_PAX_REFCOUNT
9966+ "jno 0f\n"
9967+ "sub %2,%0\n"
9968+ "int $4\n0:\n"
9969+ _ASM_EXTABLE(0b, 0b)
9970+#endif
9971+
9972+ : "=r" (new)
9973+ : "0" (c), "ir" (a));
9974+
9975+ old = atomic64_cmpxchg(v, c, new);
9976 if (likely(old == c))
9977 break;
9978 c = old;
9979 }
9980- return c != (u);
9981+ return c != u;
9982 }
9983
9984 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9985diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9986index a6983b2..63f48a2 100644
9987--- a/arch/x86/include/asm/bitops.h
9988+++ b/arch/x86/include/asm/bitops.h
9989@@ -40,7 +40,7 @@
9990 * a mask operation on a byte.
9991 */
9992 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9993-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9994+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9995 #define CONST_MASK(nr) (1 << ((nr) & 7))
9996
9997 /**
9998diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
9999index b13fe63..0dab13a 100644
10000--- a/arch/x86/include/asm/boot.h
10001+++ b/arch/x86/include/asm/boot.h
10002@@ -11,10 +11,15 @@
10003 #include <asm/pgtable_types.h>
10004
10005 /* Physical address where kernel should be loaded. */
10006-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10007+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10008 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10009 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10010
10011+#ifndef __ASSEMBLY__
10012+extern unsigned char __LOAD_PHYSICAL_ADDR[];
10013+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10014+#endif
10015+
10016 /* Minimum kernel alignment, as a power of two */
10017 #ifdef CONFIG_X86_64
10018 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10019diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10020index 48f99f1..d78ebf9 100644
10021--- a/arch/x86/include/asm/cache.h
10022+++ b/arch/x86/include/asm/cache.h
10023@@ -5,12 +5,13 @@
10024
10025 /* L1 cache line size */
10026 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10027-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10028+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10029
10030 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10031+#define __read_only __attribute__((__section__(".data..read_only")))
10032
10033 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10034-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10035+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10036
10037 #ifdef CONFIG_X86_VSMP
10038 #ifdef CONFIG_SMP
10039diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10040index 9863ee3..4a1f8e1 100644
10041--- a/arch/x86/include/asm/cacheflush.h
10042+++ b/arch/x86/include/asm/cacheflush.h
10043@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10044 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10045
10046 if (pg_flags == _PGMT_DEFAULT)
10047- return -1;
10048+ return ~0UL;
10049 else if (pg_flags == _PGMT_WC)
10050 return _PAGE_CACHE_WC;
10051 else if (pg_flags == _PGMT_UC_MINUS)
10052diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10053index 46fc474..b02b0f9 100644
10054--- a/arch/x86/include/asm/checksum_32.h
10055+++ b/arch/x86/include/asm/checksum_32.h
10056@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10057 int len, __wsum sum,
10058 int *src_err_ptr, int *dst_err_ptr);
10059
10060+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10061+ int len, __wsum sum,
10062+ int *src_err_ptr, int *dst_err_ptr);
10063+
10064+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10065+ int len, __wsum sum,
10066+ int *src_err_ptr, int *dst_err_ptr);
10067+
10068 /*
10069 * Note: when you get a NULL pointer exception here this means someone
10070 * passed in an incorrect kernel address to one of these functions.
10071@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10072 int *err_ptr)
10073 {
10074 might_sleep();
10075- return csum_partial_copy_generic((__force void *)src, dst,
10076+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
10077 len, sum, err_ptr, NULL);
10078 }
10079
10080@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10081 {
10082 might_sleep();
10083 if (access_ok(VERIFY_WRITE, dst, len))
10084- return csum_partial_copy_generic(src, (__force void *)dst,
10085+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10086 len, sum, NULL, err_ptr);
10087
10088 if (len)
10089diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10090index 99480e5..d81165b 100644
10091--- a/arch/x86/include/asm/cmpxchg.h
10092+++ b/arch/x86/include/asm/cmpxchg.h
10093@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10094 __compiletime_error("Bad argument size for cmpxchg");
10095 extern void __xadd_wrong_size(void)
10096 __compiletime_error("Bad argument size for xadd");
10097+extern void __xadd_check_overflow_wrong_size(void)
10098+ __compiletime_error("Bad argument size for xadd_check_overflow");
10099 extern void __add_wrong_size(void)
10100 __compiletime_error("Bad argument size for add");
10101+extern void __add_check_overflow_wrong_size(void)
10102+ __compiletime_error("Bad argument size for add_check_overflow");
10103
10104 /*
10105 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10106@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10107 __ret; \
10108 })
10109
10110+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10111+ ({ \
10112+ __typeof__ (*(ptr)) __ret = (arg); \
10113+ switch (sizeof(*(ptr))) { \
10114+ case __X86_CASE_L: \
10115+ asm volatile (lock #op "l %0, %1\n" \
10116+ "jno 0f\n" \
10117+ "mov %0,%1\n" \
10118+ "int $4\n0:\n" \
10119+ _ASM_EXTABLE(0b, 0b) \
10120+ : "+r" (__ret), "+m" (*(ptr)) \
10121+ : : "memory", "cc"); \
10122+ break; \
10123+ case __X86_CASE_Q: \
10124+ asm volatile (lock #op "q %q0, %1\n" \
10125+ "jno 0f\n" \
10126+ "mov %0,%1\n" \
10127+ "int $4\n0:\n" \
10128+ _ASM_EXTABLE(0b, 0b) \
10129+ : "+r" (__ret), "+m" (*(ptr)) \
10130+ : : "memory", "cc"); \
10131+ break; \
10132+ default: \
10133+ __ ## op ## _check_overflow_wrong_size(); \
10134+ } \
10135+ __ret; \
10136+ })
10137+
10138 /*
10139 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10140 * Since this is generally used to protect other memory information, we
10141@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10142 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10143 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10144
10145+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10146+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10147+
10148 #define __add(ptr, inc, lock) \
10149 ({ \
10150 __typeof__ (*(ptr)) __ret = (inc); \
10151diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10152index f91e80f..7f9bd27 100644
10153--- a/arch/x86/include/asm/cpufeature.h
10154+++ b/arch/x86/include/asm/cpufeature.h
10155@@ -371,7 +371,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10156 ".section .discard,\"aw\",@progbits\n"
10157 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10158 ".previous\n"
10159- ".section .altinstr_replacement,\"ax\"\n"
10160+ ".section .altinstr_replacement,\"a\"\n"
10161 "3: movb $1,%0\n"
10162 "4:\n"
10163 ".previous\n"
10164diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10165index 8bf1c06..f723dfd 100644
10166--- a/arch/x86/include/asm/desc.h
10167+++ b/arch/x86/include/asm/desc.h
10168@@ -4,6 +4,7 @@
10169 #include <asm/desc_defs.h>
10170 #include <asm/ldt.h>
10171 #include <asm/mmu.h>
10172+#include <asm/pgtable.h>
10173
10174 #include <linux/smp.h>
10175 #include <linux/percpu.h>
10176@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10177
10178 desc->type = (info->read_exec_only ^ 1) << 1;
10179 desc->type |= info->contents << 2;
10180+ desc->type |= info->seg_not_present ^ 1;
10181
10182 desc->s = 1;
10183 desc->dpl = 0x3;
10184@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10185 }
10186
10187 extern struct desc_ptr idt_descr;
10188-extern gate_desc idt_table[];
10189 extern struct desc_ptr nmi_idt_descr;
10190-extern gate_desc nmi_idt_table[];
10191-
10192-struct gdt_page {
10193- struct desc_struct gdt[GDT_ENTRIES];
10194-} __attribute__((aligned(PAGE_SIZE)));
10195-
10196-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10197+extern gate_desc idt_table[256];
10198+extern gate_desc nmi_idt_table[256];
10199
10200+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10201 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10202 {
10203- return per_cpu(gdt_page, cpu).gdt;
10204+ return cpu_gdt_table[cpu];
10205 }
10206
10207 #ifdef CONFIG_X86_64
10208@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10209 unsigned long base, unsigned dpl, unsigned flags,
10210 unsigned short seg)
10211 {
10212- gate->a = (seg << 16) | (base & 0xffff);
10213- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10214+ gate->gate.offset_low = base;
10215+ gate->gate.seg = seg;
10216+ gate->gate.reserved = 0;
10217+ gate->gate.type = type;
10218+ gate->gate.s = 0;
10219+ gate->gate.dpl = dpl;
10220+ gate->gate.p = 1;
10221+ gate->gate.offset_high = base >> 16;
10222 }
10223
10224 #endif
10225@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10226
10227 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10228 {
10229+ pax_open_kernel();
10230 memcpy(&idt[entry], gate, sizeof(*gate));
10231+ pax_close_kernel();
10232 }
10233
10234 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10235 {
10236+ pax_open_kernel();
10237 memcpy(&ldt[entry], desc, 8);
10238+ pax_close_kernel();
10239 }
10240
10241 static inline void
10242@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10243 default: size = sizeof(*gdt); break;
10244 }
10245
10246+ pax_open_kernel();
10247 memcpy(&gdt[entry], desc, size);
10248+ pax_close_kernel();
10249 }
10250
10251 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10252@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10253
10254 static inline void native_load_tr_desc(void)
10255 {
10256+ pax_open_kernel();
10257 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10258+ pax_close_kernel();
10259 }
10260
10261 static inline void native_load_gdt(const struct desc_ptr *dtr)
10262@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10263 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10264 unsigned int i;
10265
10266+ pax_open_kernel();
10267 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10268 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10269+ pax_close_kernel();
10270 }
10271
10272 #define _LDT_empty(info) \
10273@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10274 }
10275
10276 #ifdef CONFIG_X86_64
10277-static inline void set_nmi_gate(int gate, void *addr)
10278+static inline void set_nmi_gate(int gate, const void *addr)
10279 {
10280 gate_desc s;
10281
10282@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10283 }
10284 #endif
10285
10286-static inline void _set_gate(int gate, unsigned type, void *addr,
10287+static inline void _set_gate(int gate, unsigned type, const void *addr,
10288 unsigned dpl, unsigned ist, unsigned seg)
10289 {
10290 gate_desc s;
10291@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10292 * Pentium F0 0F bugfix can have resulted in the mapped
10293 * IDT being write-protected.
10294 */
10295-static inline void set_intr_gate(unsigned int n, void *addr)
10296+static inline void set_intr_gate(unsigned int n, const void *addr)
10297 {
10298 BUG_ON((unsigned)n > 0xFF);
10299 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10300@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10301 /*
10302 * This routine sets up an interrupt gate at directory privilege level 3.
10303 */
10304-static inline void set_system_intr_gate(unsigned int n, void *addr)
10305+static inline void set_system_intr_gate(unsigned int n, const void *addr)
10306 {
10307 BUG_ON((unsigned)n > 0xFF);
10308 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10309 }
10310
10311-static inline void set_system_trap_gate(unsigned int n, void *addr)
10312+static inline void set_system_trap_gate(unsigned int n, const void *addr)
10313 {
10314 BUG_ON((unsigned)n > 0xFF);
10315 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10316 }
10317
10318-static inline void set_trap_gate(unsigned int n, void *addr)
10319+static inline void set_trap_gate(unsigned int n, const void *addr)
10320 {
10321 BUG_ON((unsigned)n > 0xFF);
10322 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10323@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10324 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10325 {
10326 BUG_ON((unsigned)n > 0xFF);
10327- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10328+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10329 }
10330
10331-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10332+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10333 {
10334 BUG_ON((unsigned)n > 0xFF);
10335 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10336 }
10337
10338-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10339+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10340 {
10341 BUG_ON((unsigned)n > 0xFF);
10342 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10343 }
10344
10345+#ifdef CONFIG_X86_32
10346+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10347+{
10348+ struct desc_struct d;
10349+
10350+ if (likely(limit))
10351+ limit = (limit - 1UL) >> PAGE_SHIFT;
10352+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
10353+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10354+}
10355+#endif
10356+
10357 #endif /* _ASM_X86_DESC_H */
10358diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10359index 278441f..b95a174 100644
10360--- a/arch/x86/include/asm/desc_defs.h
10361+++ b/arch/x86/include/asm/desc_defs.h
10362@@ -31,6 +31,12 @@ struct desc_struct {
10363 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10364 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10365 };
10366+ struct {
10367+ u16 offset_low;
10368+ u16 seg;
10369+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10370+ unsigned offset_high: 16;
10371+ } gate;
10372 };
10373 } __attribute__((packed));
10374
10375diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10376index 3778256..c5d4fce 100644
10377--- a/arch/x86/include/asm/e820.h
10378+++ b/arch/x86/include/asm/e820.h
10379@@ -69,7 +69,7 @@ struct e820map {
10380 #define ISA_START_ADDRESS 0xa0000
10381 #define ISA_END_ADDRESS 0x100000
10382
10383-#define BIOS_BEGIN 0x000a0000
10384+#define BIOS_BEGIN 0x000c0000
10385 #define BIOS_END 0x00100000
10386
10387 #define BIOS_ROM_BASE 0xffe00000
10388diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10389index 5939f44..f8845f6 100644
10390--- a/arch/x86/include/asm/elf.h
10391+++ b/arch/x86/include/asm/elf.h
10392@@ -243,7 +243,25 @@ extern int force_personality32;
10393 the loader. We need to make sure that it is out of the way of the program
10394 that it will "exec", and that there is sufficient room for the brk. */
10395
10396+#ifdef CONFIG_PAX_SEGMEXEC
10397+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10398+#else
10399 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10400+#endif
10401+
10402+#ifdef CONFIG_PAX_ASLR
10403+#ifdef CONFIG_X86_32
10404+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10405+
10406+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10407+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10408+#else
10409+#define PAX_ELF_ET_DYN_BASE 0x400000UL
10410+
10411+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10412+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10413+#endif
10414+#endif
10415
10416 /* This yields a mask that user programs can use to figure out what
10417 instruction set this CPU supports. This could be done in user space,
10418@@ -296,16 +314,12 @@ do { \
10419
10420 #define ARCH_DLINFO \
10421 do { \
10422- if (vdso_enabled) \
10423- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10424- (unsigned long)current->mm->context.vdso); \
10425+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10426 } while (0)
10427
10428 #define ARCH_DLINFO_X32 \
10429 do { \
10430- if (vdso_enabled) \
10431- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10432- (unsigned long)current->mm->context.vdso); \
10433+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10434 } while (0)
10435
10436 #define AT_SYSINFO 32
10437@@ -320,7 +334,7 @@ else \
10438
10439 #endif /* !CONFIG_X86_32 */
10440
10441-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10442+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10443
10444 #define VDSO_ENTRY \
10445 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10446@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10447 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10448 #define compat_arch_setup_additional_pages syscall32_setup_pages
10449
10450-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10451-#define arch_randomize_brk arch_randomize_brk
10452-
10453 /*
10454 * True on X86_32 or when emulating IA32 on X86_64
10455 */
10456diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10457index cc70c1c..d96d011 100644
10458--- a/arch/x86/include/asm/emergency-restart.h
10459+++ b/arch/x86/include/asm/emergency-restart.h
10460@@ -15,6 +15,6 @@ enum reboot_type {
10461
10462 extern enum reboot_type reboot_type;
10463
10464-extern void machine_emergency_restart(void);
10465+extern void machine_emergency_restart(void) __noreturn;
10466
10467 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10468diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10469index 75f4c6d..ee3eb8f 100644
10470--- a/arch/x86/include/asm/fpu-internal.h
10471+++ b/arch/x86/include/asm/fpu-internal.h
10472@@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10473 {
10474 int err;
10475
10476+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10477+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10478+ fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10479+#endif
10480+
10481 /* See comment in fxsave() below. */
10482 #ifdef CONFIG_AS_FXSAVEQ
10483 asm volatile("1: fxrstorq %[fx]\n\t"
10484@@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10485 {
10486 int err;
10487
10488+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10489+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10490+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10491+#endif
10492+
10493 /*
10494 * Clear the bytes not touched by the fxsave and reserved
10495 * for the SW usage.
10496@@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10497 "emms\n\t" /* clear stack tags */
10498 "fildl %P[addr]", /* set F?P to defined value */
10499 X86_FEATURE_FXSAVE_LEAK,
10500- [addr] "m" (tsk->thread.fpu.has_fpu));
10501+ [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10502
10503 return fpu_restore_checking(&tsk->thread.fpu);
10504 }
10505diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10506index 71ecbcb..bac10b7 100644
10507--- a/arch/x86/include/asm/futex.h
10508+++ b/arch/x86/include/asm/futex.h
10509@@ -11,16 +11,18 @@
10510 #include <asm/processor.h>
10511
10512 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10513+ typecheck(u32 __user *, uaddr); \
10514 asm volatile("1:\t" insn "\n" \
10515 "2:\t.section .fixup,\"ax\"\n" \
10516 "3:\tmov\t%3, %1\n" \
10517 "\tjmp\t2b\n" \
10518 "\t.previous\n" \
10519 _ASM_EXTABLE(1b, 3b) \
10520- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10521+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10522 : "i" (-EFAULT), "0" (oparg), "1" (0))
10523
10524 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10525+ typecheck(u32 __user *, uaddr); \
10526 asm volatile("1:\tmovl %2, %0\n" \
10527 "\tmovl\t%0, %3\n" \
10528 "\t" insn "\n" \
10529@@ -33,7 +35,7 @@
10530 _ASM_EXTABLE(1b, 4b) \
10531 _ASM_EXTABLE(2b, 4b) \
10532 : "=&a" (oldval), "=&r" (ret), \
10533- "+m" (*uaddr), "=&r" (tem) \
10534+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10535 : "r" (oparg), "i" (-EFAULT), "1" (0))
10536
10537 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10538@@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10539
10540 switch (op) {
10541 case FUTEX_OP_SET:
10542- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10543+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10544 break;
10545 case FUTEX_OP_ADD:
10546- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10547+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10548 uaddr, oparg);
10549 break;
10550 case FUTEX_OP_OR:
10551@@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10552 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10553 return -EFAULT;
10554
10555- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10556+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10557 "2:\t.section .fixup, \"ax\"\n"
10558 "3:\tmov %3, %0\n"
10559 "\tjmp 2b\n"
10560 "\t.previous\n"
10561 _ASM_EXTABLE(1b, 3b)
10562- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10563+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10564 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10565 : "memory"
10566 );
10567diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10568index eb92a6e..b98b2f4 100644
10569--- a/arch/x86/include/asm/hw_irq.h
10570+++ b/arch/x86/include/asm/hw_irq.h
10571@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10572 extern void enable_IO_APIC(void);
10573
10574 /* Statistics */
10575-extern atomic_t irq_err_count;
10576-extern atomic_t irq_mis_count;
10577+extern atomic_unchecked_t irq_err_count;
10578+extern atomic_unchecked_t irq_mis_count;
10579
10580 /* EISA */
10581 extern void eisa_set_level_irq(unsigned int irq);
10582diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10583index d8e8eef..99f81ae 100644
10584--- a/arch/x86/include/asm/io.h
10585+++ b/arch/x86/include/asm/io.h
10586@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10587
10588 #include <linux/vmalloc.h>
10589
10590+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10591+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10592+{
10593+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10594+}
10595+
10596+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10597+{
10598+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10599+}
10600+
10601 /*
10602 * Convert a virtual cached pointer to an uncached pointer
10603 */
10604diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10605index bba3cf8..06bc8da 100644
10606--- a/arch/x86/include/asm/irqflags.h
10607+++ b/arch/x86/include/asm/irqflags.h
10608@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10609 sti; \
10610 sysexit
10611
10612+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10613+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10614+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10615+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10616+
10617 #else
10618 #define INTERRUPT_RETURN iret
10619 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10620diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10621index 5478825..839e88c 100644
10622--- a/arch/x86/include/asm/kprobes.h
10623+++ b/arch/x86/include/asm/kprobes.h
10624@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10625 #define RELATIVEJUMP_SIZE 5
10626 #define RELATIVECALL_OPCODE 0xe8
10627 #define RELATIVE_ADDR_SIZE 4
10628-#define MAX_STACK_SIZE 64
10629-#define MIN_STACK_SIZE(ADDR) \
10630- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10631- THREAD_SIZE - (unsigned long)(ADDR))) \
10632- ? (MAX_STACK_SIZE) \
10633- : (((unsigned long)current_thread_info()) + \
10634- THREAD_SIZE - (unsigned long)(ADDR)))
10635+#define MAX_STACK_SIZE 64UL
10636+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10637
10638 #define flush_insn_slot(p) do { } while (0)
10639
10640diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10641index db7c1f2..92f130a 100644
10642--- a/arch/x86/include/asm/kvm_host.h
10643+++ b/arch/x86/include/asm/kvm_host.h
10644@@ -680,7 +680,7 @@ struct kvm_x86_ops {
10645 int (*check_intercept)(struct kvm_vcpu *vcpu,
10646 struct x86_instruction_info *info,
10647 enum x86_intercept_stage stage);
10648-};
10649+} __do_const;
10650
10651 struct kvm_arch_async_pf {
10652 u32 token;
10653diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10654index c8bed0d..e5721fa 100644
10655--- a/arch/x86/include/asm/local.h
10656+++ b/arch/x86/include/asm/local.h
10657@@ -17,26 +17,58 @@ typedef struct {
10658
10659 static inline void local_inc(local_t *l)
10660 {
10661- asm volatile(_ASM_INC "%0"
10662+ asm volatile(_ASM_INC "%0\n"
10663+
10664+#ifdef CONFIG_PAX_REFCOUNT
10665+ "jno 0f\n"
10666+ _ASM_DEC "%0\n"
10667+ "int $4\n0:\n"
10668+ _ASM_EXTABLE(0b, 0b)
10669+#endif
10670+
10671 : "+m" (l->a.counter));
10672 }
10673
10674 static inline void local_dec(local_t *l)
10675 {
10676- asm volatile(_ASM_DEC "%0"
10677+ asm volatile(_ASM_DEC "%0\n"
10678+
10679+#ifdef CONFIG_PAX_REFCOUNT
10680+ "jno 0f\n"
10681+ _ASM_INC "%0\n"
10682+ "int $4\n0:\n"
10683+ _ASM_EXTABLE(0b, 0b)
10684+#endif
10685+
10686 : "+m" (l->a.counter));
10687 }
10688
10689 static inline void local_add(long i, local_t *l)
10690 {
10691- asm volatile(_ASM_ADD "%1,%0"
10692+ asm volatile(_ASM_ADD "%1,%0\n"
10693+
10694+#ifdef CONFIG_PAX_REFCOUNT
10695+ "jno 0f\n"
10696+ _ASM_SUB "%1,%0\n"
10697+ "int $4\n0:\n"
10698+ _ASM_EXTABLE(0b, 0b)
10699+#endif
10700+
10701 : "+m" (l->a.counter)
10702 : "ir" (i));
10703 }
10704
10705 static inline void local_sub(long i, local_t *l)
10706 {
10707- asm volatile(_ASM_SUB "%1,%0"
10708+ asm volatile(_ASM_SUB "%1,%0\n"
10709+
10710+#ifdef CONFIG_PAX_REFCOUNT
10711+ "jno 0f\n"
10712+ _ASM_ADD "%1,%0\n"
10713+ "int $4\n0:\n"
10714+ _ASM_EXTABLE(0b, 0b)
10715+#endif
10716+
10717 : "+m" (l->a.counter)
10718 : "ir" (i));
10719 }
10720@@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10721 {
10722 unsigned char c;
10723
10724- asm volatile(_ASM_SUB "%2,%0; sete %1"
10725+ asm volatile(_ASM_SUB "%2,%0\n"
10726+
10727+#ifdef CONFIG_PAX_REFCOUNT
10728+ "jno 0f\n"
10729+ _ASM_ADD "%2,%0\n"
10730+ "int $4\n0:\n"
10731+ _ASM_EXTABLE(0b, 0b)
10732+#endif
10733+
10734+ "sete %1\n"
10735 : "+m" (l->a.counter), "=qm" (c)
10736 : "ir" (i) : "memory");
10737 return c;
10738@@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10739 {
10740 unsigned char c;
10741
10742- asm volatile(_ASM_DEC "%0; sete %1"
10743+ asm volatile(_ASM_DEC "%0\n"
10744+
10745+#ifdef CONFIG_PAX_REFCOUNT
10746+ "jno 0f\n"
10747+ _ASM_INC "%0\n"
10748+ "int $4\n0:\n"
10749+ _ASM_EXTABLE(0b, 0b)
10750+#endif
10751+
10752+ "sete %1\n"
10753 : "+m" (l->a.counter), "=qm" (c)
10754 : : "memory");
10755 return c != 0;
10756@@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10757 {
10758 unsigned char c;
10759
10760- asm volatile(_ASM_INC "%0; sete %1"
10761+ asm volatile(_ASM_INC "%0\n"
10762+
10763+#ifdef CONFIG_PAX_REFCOUNT
10764+ "jno 0f\n"
10765+ _ASM_DEC "%0\n"
10766+ "int $4\n0:\n"
10767+ _ASM_EXTABLE(0b, 0b)
10768+#endif
10769+
10770+ "sete %1\n"
10771 : "+m" (l->a.counter), "=qm" (c)
10772 : : "memory");
10773 return c != 0;
10774@@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10775 {
10776 unsigned char c;
10777
10778- asm volatile(_ASM_ADD "%2,%0; sets %1"
10779+ asm volatile(_ASM_ADD "%2,%0\n"
10780+
10781+#ifdef CONFIG_PAX_REFCOUNT
10782+ "jno 0f\n"
10783+ _ASM_SUB "%2,%0\n"
10784+ "int $4\n0:\n"
10785+ _ASM_EXTABLE(0b, 0b)
10786+#endif
10787+
10788+ "sets %1\n"
10789 : "+m" (l->a.counter), "=qm" (c)
10790 : "ir" (i) : "memory");
10791 return c;
10792@@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10793 #endif
10794 /* Modern 486+ processor */
10795 __i = i;
10796- asm volatile(_ASM_XADD "%0, %1;"
10797+ asm volatile(_ASM_XADD "%0, %1\n"
10798+
10799+#ifdef CONFIG_PAX_REFCOUNT
10800+ "jno 0f\n"
10801+ _ASM_MOV "%0,%1\n"
10802+ "int $4\n0:\n"
10803+ _ASM_EXTABLE(0b, 0b)
10804+#endif
10805+
10806 : "+r" (i), "+m" (l->a.counter)
10807 : : "memory");
10808 return i + __i;
10809diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10810index 593e51d..fa69c9a 100644
10811--- a/arch/x86/include/asm/mman.h
10812+++ b/arch/x86/include/asm/mman.h
10813@@ -5,4 +5,14 @@
10814
10815 #include <asm-generic/mman.h>
10816
10817+#ifdef __KERNEL__
10818+#ifndef __ASSEMBLY__
10819+#ifdef CONFIG_X86_32
10820+#define arch_mmap_check i386_mmap_check
10821+int i386_mmap_check(unsigned long addr, unsigned long len,
10822+ unsigned long flags);
10823+#endif
10824+#endif
10825+#endif
10826+
10827 #endif /* _ASM_X86_MMAN_H */
10828diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10829index 5f55e69..e20bfb1 100644
10830--- a/arch/x86/include/asm/mmu.h
10831+++ b/arch/x86/include/asm/mmu.h
10832@@ -9,7 +9,7 @@
10833 * we put the segment information here.
10834 */
10835 typedef struct {
10836- void *ldt;
10837+ struct desc_struct *ldt;
10838 int size;
10839
10840 #ifdef CONFIG_X86_64
10841@@ -18,7 +18,19 @@ typedef struct {
10842 #endif
10843
10844 struct mutex lock;
10845- void *vdso;
10846+ unsigned long vdso;
10847+
10848+#ifdef CONFIG_X86_32
10849+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10850+ unsigned long user_cs_base;
10851+ unsigned long user_cs_limit;
10852+
10853+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10854+ cpumask_t cpu_user_cs_mask;
10855+#endif
10856+
10857+#endif
10858+#endif
10859 } mm_context_t;
10860
10861 #ifdef CONFIG_SMP
10862diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10863index cdbf367..adb37ac 100644
10864--- a/arch/x86/include/asm/mmu_context.h
10865+++ b/arch/x86/include/asm/mmu_context.h
10866@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10867
10868 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10869 {
10870+
10871+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10872+ unsigned int i;
10873+ pgd_t *pgd;
10874+
10875+ pax_open_kernel();
10876+ pgd = get_cpu_pgd(smp_processor_id());
10877+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10878+ set_pgd_batched(pgd+i, native_make_pgd(0));
10879+ pax_close_kernel();
10880+#endif
10881+
10882 #ifdef CONFIG_SMP
10883 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10884 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10885@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10886 struct task_struct *tsk)
10887 {
10888 unsigned cpu = smp_processor_id();
10889+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10890+ int tlbstate = TLBSTATE_OK;
10891+#endif
10892
10893 if (likely(prev != next)) {
10894 #ifdef CONFIG_SMP
10895+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10896+ tlbstate = this_cpu_read(cpu_tlbstate.state);
10897+#endif
10898 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10899 this_cpu_write(cpu_tlbstate.active_mm, next);
10900 #endif
10901 cpumask_set_cpu(cpu, mm_cpumask(next));
10902
10903 /* Re-load page tables */
10904+#ifdef CONFIG_PAX_PER_CPU_PGD
10905+ pax_open_kernel();
10906+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10907+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10908+ pax_close_kernel();
10909+ load_cr3(get_cpu_pgd(cpu));
10910+#else
10911 load_cr3(next->pgd);
10912+#endif
10913
10914 /* stop flush ipis for the previous mm */
10915 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10916@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10917 */
10918 if (unlikely(prev->context.ldt != next->context.ldt))
10919 load_LDT_nolock(&next->context);
10920- }
10921+
10922+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10923+ if (!(__supported_pte_mask & _PAGE_NX)) {
10924+ smp_mb__before_clear_bit();
10925+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10926+ smp_mb__after_clear_bit();
10927+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10928+ }
10929+#endif
10930+
10931+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10932+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10933+ prev->context.user_cs_limit != next->context.user_cs_limit))
10934+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10935 #ifdef CONFIG_SMP
10936+ else if (unlikely(tlbstate != TLBSTATE_OK))
10937+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10938+#endif
10939+#endif
10940+
10941+ }
10942 else {
10943+
10944+#ifdef CONFIG_PAX_PER_CPU_PGD
10945+ pax_open_kernel();
10946+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10947+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10948+ pax_close_kernel();
10949+ load_cr3(get_cpu_pgd(cpu));
10950+#endif
10951+
10952+#ifdef CONFIG_SMP
10953 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10954 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
10955
10956@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10957 * tlb flush IPI delivery. We must reload CR3
10958 * to make sure to use no freed page tables.
10959 */
10960+
10961+#ifndef CONFIG_PAX_PER_CPU_PGD
10962 load_cr3(next->pgd);
10963+#endif
10964+
10965 load_LDT_nolock(&next->context);
10966+
10967+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10968+ if (!(__supported_pte_mask & _PAGE_NX))
10969+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10970+#endif
10971+
10972+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10973+#ifdef CONFIG_PAX_PAGEEXEC
10974+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10975+#endif
10976+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10977+#endif
10978+
10979 }
10980+#endif
10981 }
10982-#endif
10983 }
10984
10985 #define activate_mm(prev, next) \
10986diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10987index 9eae775..c914fea 100644
10988--- a/arch/x86/include/asm/module.h
10989+++ b/arch/x86/include/asm/module.h
10990@@ -5,6 +5,7 @@
10991
10992 #ifdef CONFIG_X86_64
10993 /* X86_64 does not define MODULE_PROC_FAMILY */
10994+#define MODULE_PROC_FAMILY ""
10995 #elif defined CONFIG_M386
10996 #define MODULE_PROC_FAMILY "386 "
10997 #elif defined CONFIG_M486
10998@@ -59,8 +60,20 @@
10999 #error unknown processor family
11000 #endif
11001
11002-#ifdef CONFIG_X86_32
11003-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11004+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11005+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11006+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11007+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11008+#else
11009+#define MODULE_PAX_KERNEXEC ""
11010 #endif
11011
11012+#ifdef CONFIG_PAX_MEMORY_UDEREF
11013+#define MODULE_PAX_UDEREF "UDEREF "
11014+#else
11015+#define MODULE_PAX_UDEREF ""
11016+#endif
11017+
11018+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11019+
11020 #endif /* _ASM_X86_MODULE_H */
11021diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11022index 320f7bb..e89f8f8 100644
11023--- a/arch/x86/include/asm/page_64_types.h
11024+++ b/arch/x86/include/asm/page_64_types.h
11025@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11026
11027 /* duplicated to the one in bootmem.h */
11028 extern unsigned long max_pfn;
11029-extern unsigned long phys_base;
11030+extern const unsigned long phys_base;
11031
11032 extern unsigned long __phys_addr(unsigned long);
11033 #define __phys_reloc_hide(x) (x)
11034diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11035index 6cbbabf..11b3aed 100644
11036--- a/arch/x86/include/asm/paravirt.h
11037+++ b/arch/x86/include/asm/paravirt.h
11038@@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11039 val);
11040 }
11041
11042+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11043+{
11044+ pgdval_t val = native_pgd_val(pgd);
11045+
11046+ if (sizeof(pgdval_t) > sizeof(long))
11047+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11048+ val, (u64)val >> 32);
11049+ else
11050+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11051+ val);
11052+}
11053+
11054 static inline void pgd_clear(pgd_t *pgdp)
11055 {
11056 set_pgd(pgdp, __pgd(0));
11057@@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11058 pv_mmu_ops.set_fixmap(idx, phys, flags);
11059 }
11060
11061+#ifdef CONFIG_PAX_KERNEXEC
11062+static inline unsigned long pax_open_kernel(void)
11063+{
11064+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11065+}
11066+
11067+static inline unsigned long pax_close_kernel(void)
11068+{
11069+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11070+}
11071+#else
11072+static inline unsigned long pax_open_kernel(void) { return 0; }
11073+static inline unsigned long pax_close_kernel(void) { return 0; }
11074+#endif
11075+
11076 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11077
11078 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11079@@ -965,7 +992,7 @@ extern void default_banner(void);
11080
11081 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11082 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11083-#define PARA_INDIRECT(addr) *%cs:addr
11084+#define PARA_INDIRECT(addr) *%ss:addr
11085 #endif
11086
11087 #define INTERRUPT_RETURN \
11088@@ -1040,6 +1067,21 @@ extern void default_banner(void);
11089 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11090 CLBR_NONE, \
11091 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11092+
11093+#define GET_CR0_INTO_RDI \
11094+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11095+ mov %rax,%rdi
11096+
11097+#define SET_RDI_INTO_CR0 \
11098+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11099+
11100+#define GET_CR3_INTO_RDI \
11101+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11102+ mov %rax,%rdi
11103+
11104+#define SET_RDI_INTO_CR3 \
11105+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11106+
11107 #endif /* CONFIG_X86_32 */
11108
11109 #endif /* __ASSEMBLY__ */
11110diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11111index 8e8b9a4..f07d725 100644
11112--- a/arch/x86/include/asm/paravirt_types.h
11113+++ b/arch/x86/include/asm/paravirt_types.h
11114@@ -84,20 +84,20 @@ struct pv_init_ops {
11115 */
11116 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11117 unsigned long addr, unsigned len);
11118-};
11119+} __no_const;
11120
11121
11122 struct pv_lazy_ops {
11123 /* Set deferred update mode, used for batching operations. */
11124 void (*enter)(void);
11125 void (*leave)(void);
11126-};
11127+} __no_const;
11128
11129 struct pv_time_ops {
11130 unsigned long long (*sched_clock)(void);
11131 unsigned long long (*steal_clock)(int cpu);
11132 unsigned long (*get_tsc_khz)(void);
11133-};
11134+} __no_const;
11135
11136 struct pv_cpu_ops {
11137 /* hooks for various privileged instructions */
11138@@ -193,7 +193,7 @@ struct pv_cpu_ops {
11139
11140 void (*start_context_switch)(struct task_struct *prev);
11141 void (*end_context_switch)(struct task_struct *next);
11142-};
11143+} __no_const;
11144
11145 struct pv_irq_ops {
11146 /*
11147@@ -224,7 +224,7 @@ struct pv_apic_ops {
11148 unsigned long start_eip,
11149 unsigned long start_esp);
11150 #endif
11151-};
11152+} __no_const;
11153
11154 struct pv_mmu_ops {
11155 unsigned long (*read_cr2)(void);
11156@@ -313,6 +313,7 @@ struct pv_mmu_ops {
11157 struct paravirt_callee_save make_pud;
11158
11159 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11160+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11161 #endif /* PAGETABLE_LEVELS == 4 */
11162 #endif /* PAGETABLE_LEVELS >= 3 */
11163
11164@@ -324,6 +325,12 @@ struct pv_mmu_ops {
11165 an mfn. We can tell which is which from the index. */
11166 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11167 phys_addr_t phys, pgprot_t flags);
11168+
11169+#ifdef CONFIG_PAX_KERNEXEC
11170+ unsigned long (*pax_open_kernel)(void);
11171+ unsigned long (*pax_close_kernel)(void);
11172+#endif
11173+
11174 };
11175
11176 struct arch_spinlock;
11177@@ -334,7 +341,7 @@ struct pv_lock_ops {
11178 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11179 int (*spin_trylock)(struct arch_spinlock *lock);
11180 void (*spin_unlock)(struct arch_spinlock *lock);
11181-};
11182+} __no_const;
11183
11184 /* This contains all the paravirt structures: we get a convenient
11185 * number for each function using the offset which we use to indicate
11186diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11187index b4389a4..7024269 100644
11188--- a/arch/x86/include/asm/pgalloc.h
11189+++ b/arch/x86/include/asm/pgalloc.h
11190@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11191 pmd_t *pmd, pte_t *pte)
11192 {
11193 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11194+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11195+}
11196+
11197+static inline void pmd_populate_user(struct mm_struct *mm,
11198+ pmd_t *pmd, pte_t *pte)
11199+{
11200+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11201 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11202 }
11203
11204@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11205
11206 #ifdef CONFIG_X86_PAE
11207 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11208+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11209+{
11210+ pud_populate(mm, pudp, pmd);
11211+}
11212 #else /* !CONFIG_X86_PAE */
11213 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11214 {
11215 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11216 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11217 }
11218+
11219+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11220+{
11221+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11222+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11223+}
11224 #endif /* CONFIG_X86_PAE */
11225
11226 #if PAGETABLE_LEVELS > 3
11227@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11228 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11229 }
11230
11231+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11232+{
11233+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11234+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11235+}
11236+
11237 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11238 {
11239 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11240diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11241index 98391db..8f6984e 100644
11242--- a/arch/x86/include/asm/pgtable-2level.h
11243+++ b/arch/x86/include/asm/pgtable-2level.h
11244@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11245
11246 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11247 {
11248+ pax_open_kernel();
11249 *pmdp = pmd;
11250+ pax_close_kernel();
11251 }
11252
11253 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11254diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11255index cb00ccc..17e9054 100644
11256--- a/arch/x86/include/asm/pgtable-3level.h
11257+++ b/arch/x86/include/asm/pgtable-3level.h
11258@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11259
11260 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11261 {
11262+ pax_open_kernel();
11263 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11264+ pax_close_kernel();
11265 }
11266
11267 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11268 {
11269+ pax_open_kernel();
11270 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11271+ pax_close_kernel();
11272 }
11273
11274 /*
11275diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11276index 49afb3f..91a8c63 100644
11277--- a/arch/x86/include/asm/pgtable.h
11278+++ b/arch/x86/include/asm/pgtable.h
11279@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11280
11281 #ifndef __PAGETABLE_PUD_FOLDED
11282 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11283+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11284 #define pgd_clear(pgd) native_pgd_clear(pgd)
11285 #endif
11286
11287@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11288
11289 #define arch_end_context_switch(prev) do {} while(0)
11290
11291+#define pax_open_kernel() native_pax_open_kernel()
11292+#define pax_close_kernel() native_pax_close_kernel()
11293 #endif /* CONFIG_PARAVIRT */
11294
11295+#define __HAVE_ARCH_PAX_OPEN_KERNEL
11296+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11297+
11298+#ifdef CONFIG_PAX_KERNEXEC
11299+static inline unsigned long native_pax_open_kernel(void)
11300+{
11301+ unsigned long cr0;
11302+
11303+ preempt_disable();
11304+ barrier();
11305+ cr0 = read_cr0() ^ X86_CR0_WP;
11306+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11307+ write_cr0(cr0);
11308+ return cr0 ^ X86_CR0_WP;
11309+}
11310+
11311+static inline unsigned long native_pax_close_kernel(void)
11312+{
11313+ unsigned long cr0;
11314+
11315+ cr0 = read_cr0() ^ X86_CR0_WP;
11316+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11317+ write_cr0(cr0);
11318+ barrier();
11319+ preempt_enable_no_resched();
11320+ return cr0 ^ X86_CR0_WP;
11321+}
11322+#else
11323+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11324+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11325+#endif
11326+
11327 /*
11328 * The following only work if pte_present() is true.
11329 * Undefined behaviour if not..
11330 */
11331+static inline int pte_user(pte_t pte)
11332+{
11333+ return pte_val(pte) & _PAGE_USER;
11334+}
11335+
11336 static inline int pte_dirty(pte_t pte)
11337 {
11338 return pte_flags(pte) & _PAGE_DIRTY;
11339@@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11340 return pte_clear_flags(pte, _PAGE_RW);
11341 }
11342
11343+static inline pte_t pte_mkread(pte_t pte)
11344+{
11345+ return __pte(pte_val(pte) | _PAGE_USER);
11346+}
11347+
11348 static inline pte_t pte_mkexec(pte_t pte)
11349 {
11350- return pte_clear_flags(pte, _PAGE_NX);
11351+#ifdef CONFIG_X86_PAE
11352+ if (__supported_pte_mask & _PAGE_NX)
11353+ return pte_clear_flags(pte, _PAGE_NX);
11354+ else
11355+#endif
11356+ return pte_set_flags(pte, _PAGE_USER);
11357+}
11358+
11359+static inline pte_t pte_exprotect(pte_t pte)
11360+{
11361+#ifdef CONFIG_X86_PAE
11362+ if (__supported_pte_mask & _PAGE_NX)
11363+ return pte_set_flags(pte, _PAGE_NX);
11364+ else
11365+#endif
11366+ return pte_clear_flags(pte, _PAGE_USER);
11367 }
11368
11369 static inline pte_t pte_mkdirty(pte_t pte)
11370@@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11371 #endif
11372
11373 #ifndef __ASSEMBLY__
11374+
11375+#ifdef CONFIG_PAX_PER_CPU_PGD
11376+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11377+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11378+{
11379+ return cpu_pgd[cpu];
11380+}
11381+#endif
11382+
11383 #include <linux/mm_types.h>
11384
11385 static inline int pte_none(pte_t pte)
11386@@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11387
11388 static inline int pgd_bad(pgd_t pgd)
11389 {
11390- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11391+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11392 }
11393
11394 static inline int pgd_none(pgd_t pgd)
11395@@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11396 * pgd_offset() returns a (pgd_t *)
11397 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11398 */
11399-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11400+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11401+
11402+#ifdef CONFIG_PAX_PER_CPU_PGD
11403+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11404+#endif
11405+
11406 /*
11407 * a shortcut which implies the use of the kernel's pgd, instead
11408 * of a process's
11409@@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11410 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11411 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11412
11413+#ifdef CONFIG_X86_32
11414+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11415+#else
11416+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11417+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11418+
11419+#ifdef CONFIG_PAX_MEMORY_UDEREF
11420+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11421+#else
11422+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11423+#endif
11424+
11425+#endif
11426+
11427 #ifndef __ASSEMBLY__
11428
11429 extern int direct_gbpages;
11430@@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11431 * dst and src can be on the same page, but the range must not overlap,
11432 * and must not cross a page boundary.
11433 */
11434-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11435+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11436 {
11437- memcpy(dst, src, count * sizeof(pgd_t));
11438+ pax_open_kernel();
11439+ while (count--)
11440+ *dst++ = *src++;
11441+ pax_close_kernel();
11442 }
11443
11444+#ifdef CONFIG_PAX_PER_CPU_PGD
11445+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11446+#endif
11447+
11448+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11449+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11450+#else
11451+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11452+#endif
11453
11454 #include <asm-generic/pgtable.h>
11455 #endif /* __ASSEMBLY__ */
11456diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11457index 0c92113..34a77c6 100644
11458--- a/arch/x86/include/asm/pgtable_32.h
11459+++ b/arch/x86/include/asm/pgtable_32.h
11460@@ -25,9 +25,6 @@
11461 struct mm_struct;
11462 struct vm_area_struct;
11463
11464-extern pgd_t swapper_pg_dir[1024];
11465-extern pgd_t initial_page_table[1024];
11466-
11467 static inline void pgtable_cache_init(void) { }
11468 static inline void check_pgt_cache(void) { }
11469 void paging_init(void);
11470@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11471 # include <asm/pgtable-2level.h>
11472 #endif
11473
11474+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11475+extern pgd_t initial_page_table[PTRS_PER_PGD];
11476+#ifdef CONFIG_X86_PAE
11477+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11478+#endif
11479+
11480 #if defined(CONFIG_HIGHPTE)
11481 #define pte_offset_map(dir, address) \
11482 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11483@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11484 /* Clear a kernel PTE and flush it from the TLB */
11485 #define kpte_clear_flush(ptep, vaddr) \
11486 do { \
11487+ pax_open_kernel(); \
11488 pte_clear(&init_mm, (vaddr), (ptep)); \
11489+ pax_close_kernel(); \
11490 __flush_tlb_one((vaddr)); \
11491 } while (0)
11492
11493@@ -74,6 +79,9 @@ do { \
11494
11495 #endif /* !__ASSEMBLY__ */
11496
11497+#define HAVE_ARCH_UNMAPPED_AREA
11498+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11499+
11500 /*
11501 * kern_addr_valid() is (1) for FLATMEM and (0) for
11502 * SPARSEMEM and DISCONTIGMEM
11503diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11504index ed5903b..c7fe163 100644
11505--- a/arch/x86/include/asm/pgtable_32_types.h
11506+++ b/arch/x86/include/asm/pgtable_32_types.h
11507@@ -8,7 +8,7 @@
11508 */
11509 #ifdef CONFIG_X86_PAE
11510 # include <asm/pgtable-3level_types.h>
11511-# define PMD_SIZE (1UL << PMD_SHIFT)
11512+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11513 # define PMD_MASK (~(PMD_SIZE - 1))
11514 #else
11515 # include <asm/pgtable-2level_types.h>
11516@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11517 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11518 #endif
11519
11520+#ifdef CONFIG_PAX_KERNEXEC
11521+#ifndef __ASSEMBLY__
11522+extern unsigned char MODULES_EXEC_VADDR[];
11523+extern unsigned char MODULES_EXEC_END[];
11524+#endif
11525+#include <asm/boot.h>
11526+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11527+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11528+#else
11529+#define ktla_ktva(addr) (addr)
11530+#define ktva_ktla(addr) (addr)
11531+#endif
11532+
11533 #define MODULES_VADDR VMALLOC_START
11534 #define MODULES_END VMALLOC_END
11535 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11536diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11537index 975f709..9f779c9 100644
11538--- a/arch/x86/include/asm/pgtable_64.h
11539+++ b/arch/x86/include/asm/pgtable_64.h
11540@@ -16,10 +16,14 @@
11541
11542 extern pud_t level3_kernel_pgt[512];
11543 extern pud_t level3_ident_pgt[512];
11544+extern pud_t level3_vmalloc_start_pgt[512];
11545+extern pud_t level3_vmalloc_end_pgt[512];
11546+extern pud_t level3_vmemmap_pgt[512];
11547+extern pud_t level2_vmemmap_pgt[512];
11548 extern pmd_t level2_kernel_pgt[512];
11549 extern pmd_t level2_fixmap_pgt[512];
11550-extern pmd_t level2_ident_pgt[512];
11551-extern pgd_t init_level4_pgt[];
11552+extern pmd_t level2_ident_pgt[512*2];
11553+extern pgd_t init_level4_pgt[512];
11554
11555 #define swapper_pg_dir init_level4_pgt
11556
11557@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11558
11559 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11560 {
11561+ pax_open_kernel();
11562 *pmdp = pmd;
11563+ pax_close_kernel();
11564 }
11565
11566 static inline void native_pmd_clear(pmd_t *pmd)
11567@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11568
11569 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11570 {
11571+ pax_open_kernel();
11572 *pudp = pud;
11573+ pax_close_kernel();
11574 }
11575
11576 static inline void native_pud_clear(pud_t *pud)
11577@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11578
11579 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11580 {
11581+ pax_open_kernel();
11582+ *pgdp = pgd;
11583+ pax_close_kernel();
11584+}
11585+
11586+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11587+{
11588 *pgdp = pgd;
11589 }
11590
11591diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11592index 766ea16..5b96cb3 100644
11593--- a/arch/x86/include/asm/pgtable_64_types.h
11594+++ b/arch/x86/include/asm/pgtable_64_types.h
11595@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11596 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11597 #define MODULES_END _AC(0xffffffffff000000, UL)
11598 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11599+#define MODULES_EXEC_VADDR MODULES_VADDR
11600+#define MODULES_EXEC_END MODULES_END
11601+
11602+#define ktla_ktva(addr) (addr)
11603+#define ktva_ktla(addr) (addr)
11604
11605 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11606diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11607index 013286a..8b42f4f 100644
11608--- a/arch/x86/include/asm/pgtable_types.h
11609+++ b/arch/x86/include/asm/pgtable_types.h
11610@@ -16,13 +16,12 @@
11611 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11612 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11613 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11614-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11615+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11616 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11617 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11618 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11619-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11620-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11621-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11622+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11623+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11624 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11625
11626 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11627@@ -40,7 +39,6 @@
11628 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11629 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11630 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11631-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11632 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11633 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11634 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11635@@ -57,8 +55,10 @@
11636
11637 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11638 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11639-#else
11640+#elif defined(CONFIG_KMEMCHECK)
11641 #define _PAGE_NX (_AT(pteval_t, 0))
11642+#else
11643+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11644 #endif
11645
11646 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11647@@ -96,6 +96,9 @@
11648 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11649 _PAGE_ACCESSED)
11650
11651+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11652+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11653+
11654 #define __PAGE_KERNEL_EXEC \
11655 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11656 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11657@@ -106,7 +109,7 @@
11658 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11659 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11660 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11661-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11662+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11663 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11664 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11665 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11666@@ -168,8 +171,8 @@
11667 * bits are combined, this will alow user to access the high address mapped
11668 * VDSO in the presence of CONFIG_COMPAT_VDSO
11669 */
11670-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11671-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11672+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11673+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11674 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11675 #endif
11676
11677@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11678 {
11679 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11680 }
11681+#endif
11682
11683+#if PAGETABLE_LEVELS == 3
11684+#include <asm-generic/pgtable-nopud.h>
11685+#endif
11686+
11687+#if PAGETABLE_LEVELS == 2
11688+#include <asm-generic/pgtable-nopmd.h>
11689+#endif
11690+
11691+#ifndef __ASSEMBLY__
11692 #if PAGETABLE_LEVELS > 3
11693 typedef struct { pudval_t pud; } pud_t;
11694
11695@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11696 return pud.pud;
11697 }
11698 #else
11699-#include <asm-generic/pgtable-nopud.h>
11700-
11701 static inline pudval_t native_pud_val(pud_t pud)
11702 {
11703 return native_pgd_val(pud.pgd);
11704@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11705 return pmd.pmd;
11706 }
11707 #else
11708-#include <asm-generic/pgtable-nopmd.h>
11709-
11710 static inline pmdval_t native_pmd_val(pmd_t pmd)
11711 {
11712 return native_pgd_val(pmd.pud.pgd);
11713@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11714
11715 extern pteval_t __supported_pte_mask;
11716 extern void set_nx(void);
11717-extern int nx_enabled;
11718
11719 #define pgprot_writecombine pgprot_writecombine
11720 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11721diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11722index 39bc577..538233f 100644
11723--- a/arch/x86/include/asm/processor.h
11724+++ b/arch/x86/include/asm/processor.h
11725@@ -276,7 +276,7 @@ struct tss_struct {
11726
11727 } ____cacheline_aligned;
11728
11729-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11730+extern struct tss_struct init_tss[NR_CPUS];
11731
11732 /*
11733 * Save the original ist values for checking stack pointers during debugging
11734@@ -809,11 +809,18 @@ static inline void spin_lock_prefetch(const void *x)
11735 */
11736 #define TASK_SIZE PAGE_OFFSET
11737 #define TASK_SIZE_MAX TASK_SIZE
11738+
11739+#ifdef CONFIG_PAX_SEGMEXEC
11740+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11741+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11742+#else
11743 #define STACK_TOP TASK_SIZE
11744-#define STACK_TOP_MAX STACK_TOP
11745+#endif
11746+
11747+#define STACK_TOP_MAX TASK_SIZE
11748
11749 #define INIT_THREAD { \
11750- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11751+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11752 .vm86_info = NULL, \
11753 .sysenter_cs = __KERNEL_CS, \
11754 .io_bitmap_ptr = NULL, \
11755@@ -827,7 +834,7 @@ static inline void spin_lock_prefetch(const void *x)
11756 */
11757 #define INIT_TSS { \
11758 .x86_tss = { \
11759- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11760+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11761 .ss0 = __KERNEL_DS, \
11762 .ss1 = __KERNEL_CS, \
11763 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11764@@ -838,11 +845,7 @@ static inline void spin_lock_prefetch(const void *x)
11765 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11766
11767 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11768-#define KSTK_TOP(info) \
11769-({ \
11770- unsigned long *__ptr = (unsigned long *)(info); \
11771- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11772-})
11773+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11774
11775 /*
11776 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11777@@ -857,7 +860,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11778 #define task_pt_regs(task) \
11779 ({ \
11780 struct pt_regs *__regs__; \
11781- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11782+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11783 __regs__ - 1; \
11784 })
11785
11786@@ -867,13 +870,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11787 /*
11788 * User space process size. 47bits minus one guard page.
11789 */
11790-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11791+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11792
11793 /* This decides where the kernel will search for a free chunk of vm
11794 * space during mmap's.
11795 */
11796 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11797- 0xc0000000 : 0xFFFFe000)
11798+ 0xc0000000 : 0xFFFFf000)
11799
11800 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11801 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11802@@ -884,11 +887,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11803 #define STACK_TOP_MAX TASK_SIZE_MAX
11804
11805 #define INIT_THREAD { \
11806- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11807+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11808 }
11809
11810 #define INIT_TSS { \
11811- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11812+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11813 }
11814
11815 /*
11816@@ -916,6 +919,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11817 */
11818 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11819
11820+#ifdef CONFIG_PAX_SEGMEXEC
11821+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11822+#endif
11823+
11824 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11825
11826 /* Get/set a process' ability to use the timestamp counter instruction */
11827@@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11828 #define cpu_has_amd_erratum(x) (false)
11829 #endif /* CONFIG_CPU_SUP_AMD */
11830
11831-extern unsigned long arch_align_stack(unsigned long sp);
11832+#define arch_align_stack(x) ((x) & ~0xfUL)
11833 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11834
11835 void default_idle(void);
11836 bool set_pm_idle_to_default(void);
11837
11838-void stop_this_cpu(void *dummy);
11839+void stop_this_cpu(void *dummy) __noreturn;
11840
11841 #endif /* _ASM_X86_PROCESSOR_H */
11842diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11843index dcfde52..dbfea06 100644
11844--- a/arch/x86/include/asm/ptrace.h
11845+++ b/arch/x86/include/asm/ptrace.h
11846@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11847 }
11848
11849 /*
11850- * user_mode_vm(regs) determines whether a register set came from user mode.
11851+ * user_mode(regs) determines whether a register set came from user mode.
11852 * This is true if V8086 mode was enabled OR if the register set was from
11853 * protected mode with RPL-3 CS value. This tricky test checks that with
11854 * one comparison. Many places in the kernel can bypass this full check
11855- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11856+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11857+ * be used.
11858 */
11859-static inline int user_mode(struct pt_regs *regs)
11860+static inline int user_mode_novm(struct pt_regs *regs)
11861 {
11862 #ifdef CONFIG_X86_32
11863 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11864 #else
11865- return !!(regs->cs & 3);
11866+ return !!(regs->cs & SEGMENT_RPL_MASK);
11867 #endif
11868 }
11869
11870-static inline int user_mode_vm(struct pt_regs *regs)
11871+static inline int user_mode(struct pt_regs *regs)
11872 {
11873 #ifdef CONFIG_X86_32
11874 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11875 USER_RPL;
11876 #else
11877- return user_mode(regs);
11878+ return user_mode_novm(regs);
11879 #endif
11880 }
11881
11882@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11883 #ifdef CONFIG_X86_64
11884 static inline bool user_64bit_mode(struct pt_regs *regs)
11885 {
11886+ unsigned long cs = regs->cs & 0xffff;
11887 #ifndef CONFIG_PARAVIRT
11888 /*
11889 * On non-paravirt systems, this is the only long mode CPL 3
11890 * selector. We do not allow long mode selectors in the LDT.
11891 */
11892- return regs->cs == __USER_CS;
11893+ return cs == __USER_CS;
11894 #else
11895 /* Headers are too twisted for this to go in paravirt.h. */
11896- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11897+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11898 #endif
11899 }
11900 #endif
11901diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
11902index fce3f4a..3f69f2a 100644
11903--- a/arch/x86/include/asm/realmode.h
11904+++ b/arch/x86/include/asm/realmode.h
11905@@ -30,7 +30,7 @@ struct real_mode_header {
11906 struct trampoline_header {
11907 #ifdef CONFIG_X86_32
11908 u32 start;
11909- u16 gdt_pad;
11910+ u16 boot_cs;
11911 u16 gdt_limit;
11912 u32 gdt_base;
11913 #else
11914diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11915index 92f29706..a79cbbb 100644
11916--- a/arch/x86/include/asm/reboot.h
11917+++ b/arch/x86/include/asm/reboot.h
11918@@ -6,19 +6,19 @@
11919 struct pt_regs;
11920
11921 struct machine_ops {
11922- void (*restart)(char *cmd);
11923- void (*halt)(void);
11924- void (*power_off)(void);
11925+ void (* __noreturn restart)(char *cmd);
11926+ void (* __noreturn halt)(void);
11927+ void (* __noreturn power_off)(void);
11928 void (*shutdown)(void);
11929 void (*crash_shutdown)(struct pt_regs *);
11930- void (*emergency_restart)(void);
11931-};
11932+ void (* __noreturn emergency_restart)(void);
11933+} __no_const;
11934
11935 extern struct machine_ops machine_ops;
11936
11937 void native_machine_crash_shutdown(struct pt_regs *regs);
11938 void native_machine_shutdown(void);
11939-void machine_real_restart(unsigned int type);
11940+void machine_real_restart(unsigned int type) __noreturn;
11941 /* These must match dispatch_table in reboot_32.S */
11942 #define MRR_BIOS 0
11943 #define MRR_APM 1
11944diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11945index 2dbe4a7..ce1db00 100644
11946--- a/arch/x86/include/asm/rwsem.h
11947+++ b/arch/x86/include/asm/rwsem.h
11948@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11949 {
11950 asm volatile("# beginning down_read\n\t"
11951 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11952+
11953+#ifdef CONFIG_PAX_REFCOUNT
11954+ "jno 0f\n"
11955+ LOCK_PREFIX _ASM_DEC "(%1)\n"
11956+ "int $4\n0:\n"
11957+ _ASM_EXTABLE(0b, 0b)
11958+#endif
11959+
11960 /* adds 0x00000001 */
11961 " jns 1f\n"
11962 " call call_rwsem_down_read_failed\n"
11963@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11964 "1:\n\t"
11965 " mov %1,%2\n\t"
11966 " add %3,%2\n\t"
11967+
11968+#ifdef CONFIG_PAX_REFCOUNT
11969+ "jno 0f\n"
11970+ "sub %3,%2\n"
11971+ "int $4\n0:\n"
11972+ _ASM_EXTABLE(0b, 0b)
11973+#endif
11974+
11975 " jle 2f\n\t"
11976 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11977 " jnz 1b\n\t"
11978@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11979 long tmp;
11980 asm volatile("# beginning down_write\n\t"
11981 LOCK_PREFIX " xadd %1,(%2)\n\t"
11982+
11983+#ifdef CONFIG_PAX_REFCOUNT
11984+ "jno 0f\n"
11985+ "mov %1,(%2)\n"
11986+ "int $4\n0:\n"
11987+ _ASM_EXTABLE(0b, 0b)
11988+#endif
11989+
11990 /* adds 0xffff0001, returns the old value */
11991 " test %1,%1\n\t"
11992 /* was the count 0 before? */
11993@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11994 long tmp;
11995 asm volatile("# beginning __up_read\n\t"
11996 LOCK_PREFIX " xadd %1,(%2)\n\t"
11997+
11998+#ifdef CONFIG_PAX_REFCOUNT
11999+ "jno 0f\n"
12000+ "mov %1,(%2)\n"
12001+ "int $4\n0:\n"
12002+ _ASM_EXTABLE(0b, 0b)
12003+#endif
12004+
12005 /* subtracts 1, returns the old value */
12006 " jns 1f\n\t"
12007 " call call_rwsem_wake\n" /* expects old value in %edx */
12008@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12009 long tmp;
12010 asm volatile("# beginning __up_write\n\t"
12011 LOCK_PREFIX " xadd %1,(%2)\n\t"
12012+
12013+#ifdef CONFIG_PAX_REFCOUNT
12014+ "jno 0f\n"
12015+ "mov %1,(%2)\n"
12016+ "int $4\n0:\n"
12017+ _ASM_EXTABLE(0b, 0b)
12018+#endif
12019+
12020 /* subtracts 0xffff0001, returns the old value */
12021 " jns 1f\n\t"
12022 " call call_rwsem_wake\n" /* expects old value in %edx */
12023@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12024 {
12025 asm volatile("# beginning __downgrade_write\n\t"
12026 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12027+
12028+#ifdef CONFIG_PAX_REFCOUNT
12029+ "jno 0f\n"
12030+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12031+ "int $4\n0:\n"
12032+ _ASM_EXTABLE(0b, 0b)
12033+#endif
12034+
12035 /*
12036 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12037 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12038@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12039 */
12040 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12041 {
12042- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12043+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12044+
12045+#ifdef CONFIG_PAX_REFCOUNT
12046+ "jno 0f\n"
12047+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
12048+ "int $4\n0:\n"
12049+ _ASM_EXTABLE(0b, 0b)
12050+#endif
12051+
12052 : "+m" (sem->count)
12053 : "er" (delta));
12054 }
12055@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12056 */
12057 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12058 {
12059- return delta + xadd(&sem->count, delta);
12060+ return delta + xadd_check_overflow(&sem->count, delta);
12061 }
12062
12063 #endif /* __KERNEL__ */
12064diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12065index c48a950..c6d7468 100644
12066--- a/arch/x86/include/asm/segment.h
12067+++ b/arch/x86/include/asm/segment.h
12068@@ -64,10 +64,15 @@
12069 * 26 - ESPFIX small SS
12070 * 27 - per-cpu [ offset to per-cpu data area ]
12071 * 28 - stack_canary-20 [ for stack protector ]
12072- * 29 - unused
12073- * 30 - unused
12074+ * 29 - PCI BIOS CS
12075+ * 30 - PCI BIOS DS
12076 * 31 - TSS for double fault handler
12077 */
12078+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12079+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12080+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12081+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12082+
12083 #define GDT_ENTRY_TLS_MIN 6
12084 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12085
12086@@ -79,6 +84,8 @@
12087
12088 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12089
12090+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12091+
12092 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12093
12094 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12095@@ -104,6 +111,12 @@
12096 #define __KERNEL_STACK_CANARY 0
12097 #endif
12098
12099+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12100+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12101+
12102+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12103+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12104+
12105 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12106
12107 /*
12108@@ -141,7 +154,7 @@
12109 */
12110
12111 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12112-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12113+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12114
12115
12116 #else
12117@@ -165,6 +178,8 @@
12118 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12119 #define __USER32_DS __USER_DS
12120
12121+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12122+
12123 #define GDT_ENTRY_TSS 8 /* needs two entries */
12124 #define GDT_ENTRY_LDT 10 /* needs two entries */
12125 #define GDT_ENTRY_TLS_MIN 12
12126@@ -185,6 +200,7 @@
12127 #endif
12128
12129 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12130+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12131 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12132 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12133 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12134@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12135 {
12136 unsigned long __limit;
12137 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12138- return __limit + 1;
12139+ return __limit;
12140 }
12141
12142 #endif /* !__ASSEMBLY__ */
12143diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12144index f483945..64a7851 100644
12145--- a/arch/x86/include/asm/smp.h
12146+++ b/arch/x86/include/asm/smp.h
12147@@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12148 /* cpus sharing the last level cache: */
12149 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12150 DECLARE_PER_CPU(u16, cpu_llc_id);
12151-DECLARE_PER_CPU(int, cpu_number);
12152+DECLARE_PER_CPU(unsigned int, cpu_number);
12153
12154 static inline struct cpumask *cpu_sibling_mask(int cpu)
12155 {
12156@@ -79,7 +79,7 @@ struct smp_ops {
12157
12158 void (*send_call_func_ipi)(const struct cpumask *mask);
12159 void (*send_call_func_single_ipi)(int cpu);
12160-};
12161+} __no_const;
12162
12163 /* Globals due to paravirt */
12164 extern void set_cpu_sibling_map(int cpu);
12165@@ -195,14 +195,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12166 extern int safe_smp_processor_id(void);
12167
12168 #elif defined(CONFIG_X86_64_SMP)
12169-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12170-
12171-#define stack_smp_processor_id() \
12172-({ \
12173- struct thread_info *ti; \
12174- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12175- ti->cpu; \
12176-})
12177+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12178+#define stack_smp_processor_id() raw_smp_processor_id()
12179 #define safe_smp_processor_id() smp_processor_id()
12180
12181 #endif
12182diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12183index b315a33..8849ab0 100644
12184--- a/arch/x86/include/asm/spinlock.h
12185+++ b/arch/x86/include/asm/spinlock.h
12186@@ -173,6 +173,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12187 static inline void arch_read_lock(arch_rwlock_t *rw)
12188 {
12189 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12190+
12191+#ifdef CONFIG_PAX_REFCOUNT
12192+ "jno 0f\n"
12193+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12194+ "int $4\n0:\n"
12195+ _ASM_EXTABLE(0b, 0b)
12196+#endif
12197+
12198 "jns 1f\n"
12199 "call __read_lock_failed\n\t"
12200 "1:\n"
12201@@ -182,6 +190,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12202 static inline void arch_write_lock(arch_rwlock_t *rw)
12203 {
12204 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12205+
12206+#ifdef CONFIG_PAX_REFCOUNT
12207+ "jno 0f\n"
12208+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12209+ "int $4\n0:\n"
12210+ _ASM_EXTABLE(0b, 0b)
12211+#endif
12212+
12213 "jz 1f\n"
12214 "call __write_lock_failed\n\t"
12215 "1:\n"
12216@@ -211,13 +227,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12217
12218 static inline void arch_read_unlock(arch_rwlock_t *rw)
12219 {
12220- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12221+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12222+
12223+#ifdef CONFIG_PAX_REFCOUNT
12224+ "jno 0f\n"
12225+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12226+ "int $4\n0:\n"
12227+ _ASM_EXTABLE(0b, 0b)
12228+#endif
12229+
12230 :"+m" (rw->lock) : : "memory");
12231 }
12232
12233 static inline void arch_write_unlock(arch_rwlock_t *rw)
12234 {
12235- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12236+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12237+
12238+#ifdef CONFIG_PAX_REFCOUNT
12239+ "jno 0f\n"
12240+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12241+ "int $4\n0:\n"
12242+ _ASM_EXTABLE(0b, 0b)
12243+#endif
12244+
12245 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12246 }
12247
12248diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12249index 6a99859..03cb807 100644
12250--- a/arch/x86/include/asm/stackprotector.h
12251+++ b/arch/x86/include/asm/stackprotector.h
12252@@ -47,7 +47,7 @@
12253 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12254 */
12255 #define GDT_STACK_CANARY_INIT \
12256- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12257+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12258
12259 /*
12260 * Initialize the stackprotector canary value.
12261@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12262
12263 static inline void load_stack_canary_segment(void)
12264 {
12265-#ifdef CONFIG_X86_32
12266+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12267 asm volatile ("mov %0, %%gs" : : "r" (0));
12268 #endif
12269 }
12270diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12271index 70bbe39..4ae2bd4 100644
12272--- a/arch/x86/include/asm/stacktrace.h
12273+++ b/arch/x86/include/asm/stacktrace.h
12274@@ -11,28 +11,20 @@
12275
12276 extern int kstack_depth_to_print;
12277
12278-struct thread_info;
12279+struct task_struct;
12280 struct stacktrace_ops;
12281
12282-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12283- unsigned long *stack,
12284- unsigned long bp,
12285- const struct stacktrace_ops *ops,
12286- void *data,
12287- unsigned long *end,
12288- int *graph);
12289+typedef unsigned long walk_stack_t(struct task_struct *task,
12290+ void *stack_start,
12291+ unsigned long *stack,
12292+ unsigned long bp,
12293+ const struct stacktrace_ops *ops,
12294+ void *data,
12295+ unsigned long *end,
12296+ int *graph);
12297
12298-extern unsigned long
12299-print_context_stack(struct thread_info *tinfo,
12300- unsigned long *stack, unsigned long bp,
12301- const struct stacktrace_ops *ops, void *data,
12302- unsigned long *end, int *graph);
12303-
12304-extern unsigned long
12305-print_context_stack_bp(struct thread_info *tinfo,
12306- unsigned long *stack, unsigned long bp,
12307- const struct stacktrace_ops *ops, void *data,
12308- unsigned long *end, int *graph);
12309+extern walk_stack_t print_context_stack;
12310+extern walk_stack_t print_context_stack_bp;
12311
12312 /* Generic stack tracer with callbacks */
12313
12314@@ -40,7 +32,7 @@ struct stacktrace_ops {
12315 void (*address)(void *data, unsigned long address, int reliable);
12316 /* On negative return stop dumping */
12317 int (*stack)(void *data, char *name);
12318- walk_stack_t walk_stack;
12319+ walk_stack_t *walk_stack;
12320 };
12321
12322 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12323diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12324index 4ec45b3..a4f0a8a 100644
12325--- a/arch/x86/include/asm/switch_to.h
12326+++ b/arch/x86/include/asm/switch_to.h
12327@@ -108,7 +108,7 @@ do { \
12328 "call __switch_to\n\t" \
12329 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12330 __switch_canary \
12331- "movq %P[thread_info](%%rsi),%%r8\n\t" \
12332+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12333 "movq %%rax,%%rdi\n\t" \
12334 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12335 "jnz ret_from_fork\n\t" \
12336@@ -119,7 +119,7 @@ do { \
12337 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12338 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12339 [_tif_fork] "i" (_TIF_FORK), \
12340- [thread_info] "i" (offsetof(struct task_struct, stack)), \
12341+ [thread_info] "m" (current_tinfo), \
12342 [current_task] "m" (current_task) \
12343 __switch_canary_iparam \
12344 : "memory", "cc" __EXTRA_CLOBBER)
12345diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12346index 3fda9db4..4ca1c61 100644
12347--- a/arch/x86/include/asm/sys_ia32.h
12348+++ b/arch/x86/include/asm/sys_ia32.h
12349@@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12350 struct old_sigaction32 __user *);
12351 asmlinkage long sys32_alarm(unsigned int);
12352
12353-asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12354+asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12355 asmlinkage long sys32_sysfs(int, u32, u32);
12356
12357 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12358diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12359index 89f794f..1422765 100644
12360--- a/arch/x86/include/asm/thread_info.h
12361+++ b/arch/x86/include/asm/thread_info.h
12362@@ -10,6 +10,7 @@
12363 #include <linux/compiler.h>
12364 #include <asm/page.h>
12365 #include <asm/types.h>
12366+#include <asm/percpu.h>
12367
12368 /*
12369 * low level task data that entry.S needs immediate access to
12370@@ -24,7 +25,6 @@ struct exec_domain;
12371 #include <linux/atomic.h>
12372
12373 struct thread_info {
12374- struct task_struct *task; /* main task structure */
12375 struct exec_domain *exec_domain; /* execution domain */
12376 __u32 flags; /* low level flags */
12377 __u32 status; /* thread synchronous flags */
12378@@ -34,19 +34,13 @@ struct thread_info {
12379 mm_segment_t addr_limit;
12380 struct restart_block restart_block;
12381 void __user *sysenter_return;
12382-#ifdef CONFIG_X86_32
12383- unsigned long previous_esp; /* ESP of the previous stack in
12384- case of nested (IRQ) stacks
12385- */
12386- __u8 supervisor_stack[0];
12387-#endif
12388+ unsigned long lowest_stack;
12389 unsigned int sig_on_uaccess_error:1;
12390 unsigned int uaccess_err:1; /* uaccess failed */
12391 };
12392
12393-#define INIT_THREAD_INFO(tsk) \
12394+#define INIT_THREAD_INFO \
12395 { \
12396- .task = &tsk, \
12397 .exec_domain = &default_exec_domain, \
12398 .flags = 0, \
12399 .cpu = 0, \
12400@@ -57,7 +51,7 @@ struct thread_info {
12401 }, \
12402 }
12403
12404-#define init_thread_info (init_thread_union.thread_info)
12405+#define init_thread_info (init_thread_union.stack)
12406 #define init_stack (init_thread_union.stack)
12407
12408 #else /* !__ASSEMBLY__ */
12409@@ -98,6 +92,7 @@ struct thread_info {
12410 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12411 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12412 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12413+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12414
12415 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12416 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12417@@ -122,16 +117,18 @@ struct thread_info {
12418 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12419 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12420 #define _TIF_X32 (1 << TIF_X32)
12421+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12422
12423 /* work to do in syscall_trace_enter() */
12424 #define _TIF_WORK_SYSCALL_ENTRY \
12425 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12426- _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12427+ _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12428+ _TIF_GRSEC_SETXID)
12429
12430 /* work to do in syscall_trace_leave() */
12431 #define _TIF_WORK_SYSCALL_EXIT \
12432 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12433- _TIF_SYSCALL_TRACEPOINT)
12434+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12435
12436 /* work to do on interrupt/exception return */
12437 #define _TIF_WORK_MASK \
12438@@ -141,7 +138,8 @@ struct thread_info {
12439
12440 /* work to do on any return to user space */
12441 #define _TIF_ALLWORK_MASK \
12442- ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12443+ ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12444+ _TIF_GRSEC_SETXID)
12445
12446 /* Only used for 64 bit */
12447 #define _TIF_DO_NOTIFY_MASK \
12448@@ -157,45 +155,40 @@ struct thread_info {
12449
12450 #define PREEMPT_ACTIVE 0x10000000
12451
12452-#ifdef CONFIG_X86_32
12453-
12454-#define STACK_WARN (THREAD_SIZE/8)
12455-/*
12456- * macros/functions for gaining access to the thread information structure
12457- *
12458- * preempt_count needs to be 1 initially, until the scheduler is functional.
12459- */
12460-#ifndef __ASSEMBLY__
12461-
12462-
12463-/* how to get the current stack pointer from C */
12464-register unsigned long current_stack_pointer asm("esp") __used;
12465-
12466-/* how to get the thread information struct from C */
12467-static inline struct thread_info *current_thread_info(void)
12468-{
12469- return (struct thread_info *)
12470- (current_stack_pointer & ~(THREAD_SIZE - 1));
12471-}
12472-
12473-#else /* !__ASSEMBLY__ */
12474-
12475+#ifdef __ASSEMBLY__
12476 /* how to get the thread information struct from ASM */
12477 #define GET_THREAD_INFO(reg) \
12478- movl $-THREAD_SIZE, reg; \
12479- andl %esp, reg
12480+ mov PER_CPU_VAR(current_tinfo), reg
12481
12482 /* use this one if reg already contains %esp */
12483-#define GET_THREAD_INFO_WITH_ESP(reg) \
12484- andl $-THREAD_SIZE, reg
12485+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12486+#else
12487+/* how to get the thread information struct from C */
12488+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12489+
12490+static __always_inline struct thread_info *current_thread_info(void)
12491+{
12492+ return this_cpu_read_stable(current_tinfo);
12493+}
12494+#endif
12495+
12496+#ifdef CONFIG_X86_32
12497+
12498+#define STACK_WARN (THREAD_SIZE/8)
12499+/*
12500+ * macros/functions for gaining access to the thread information structure
12501+ *
12502+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12503+ */
12504+#ifndef __ASSEMBLY__
12505+
12506+/* how to get the current stack pointer from C */
12507+register unsigned long current_stack_pointer asm("esp") __used;
12508
12509 #endif
12510
12511 #else /* X86_32 */
12512
12513-#include <asm/percpu.h>
12514-#define KERNEL_STACK_OFFSET (5*8)
12515-
12516 /*
12517 * macros/functions for gaining access to the thread information structure
12518 * preempt_count needs to be 1 initially, until the scheduler is functional.
12519@@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12520 #ifndef __ASSEMBLY__
12521 DECLARE_PER_CPU(unsigned long, kernel_stack);
12522
12523-static inline struct thread_info *current_thread_info(void)
12524-{
12525- struct thread_info *ti;
12526- ti = (void *)(this_cpu_read_stable(kernel_stack) +
12527- KERNEL_STACK_OFFSET - THREAD_SIZE);
12528- return ti;
12529-}
12530-
12531-#else /* !__ASSEMBLY__ */
12532-
12533-/* how to get the thread information struct from ASM */
12534-#define GET_THREAD_INFO(reg) \
12535- movq PER_CPU_VAR(kernel_stack),reg ; \
12536- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12537-
12538-/*
12539- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12540- * a certain register (to be used in assembler memory operands).
12541- */
12542-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12543-
12544+/* how to get the current stack pointer from C */
12545+register unsigned long current_stack_pointer asm("rsp") __used;
12546 #endif
12547
12548 #endif /* !X86_32 */
12549@@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12550 extern void arch_task_cache_init(void);
12551 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12552 extern void arch_release_task_struct(struct task_struct *tsk);
12553+
12554+#define __HAVE_THREAD_FUNCTIONS
12555+#define task_thread_info(task) (&(task)->tinfo)
12556+#define task_stack_page(task) ((task)->stack)
12557+#define setup_thread_stack(p, org) do {} while (0)
12558+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12559+
12560 #endif
12561 #endif /* _ASM_X86_THREAD_INFO_H */
12562diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12563index e1f3a17..1ab364d 100644
12564--- a/arch/x86/include/asm/uaccess.h
12565+++ b/arch/x86/include/asm/uaccess.h
12566@@ -7,12 +7,15 @@
12567 #include <linux/compiler.h>
12568 #include <linux/thread_info.h>
12569 #include <linux/string.h>
12570+#include <linux/sched.h>
12571 #include <asm/asm.h>
12572 #include <asm/page.h>
12573
12574 #define VERIFY_READ 0
12575 #define VERIFY_WRITE 1
12576
12577+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12578+
12579 /*
12580 * The fs value determines whether argument validity checking should be
12581 * performed or not. If get_fs() == USER_DS, checking is performed, with
12582@@ -28,7 +31,12 @@
12583
12584 #define get_ds() (KERNEL_DS)
12585 #define get_fs() (current_thread_info()->addr_limit)
12586+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12587+void __set_fs(mm_segment_t x);
12588+void set_fs(mm_segment_t x);
12589+#else
12590 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12591+#endif
12592
12593 #define segment_eq(a, b) ((a).seg == (b).seg)
12594
12595@@ -76,8 +84,33 @@
12596 * checks that the pointer is in the user space range - after calling
12597 * this function, memory access functions may still return -EFAULT.
12598 */
12599-#define access_ok(type, addr, size) \
12600- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12601+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12602+#define access_ok(type, addr, size) \
12603+({ \
12604+ long __size = size; \
12605+ unsigned long __addr = (unsigned long)addr; \
12606+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12607+ unsigned long __end_ao = __addr + __size - 1; \
12608+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12609+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12610+ while(__addr_ao <= __end_ao) { \
12611+ char __c_ao; \
12612+ __addr_ao += PAGE_SIZE; \
12613+ if (__size > PAGE_SIZE) \
12614+ cond_resched(); \
12615+ if (__get_user(__c_ao, (char __user *)__addr)) \
12616+ break; \
12617+ if (type != VERIFY_WRITE) { \
12618+ __addr = __addr_ao; \
12619+ continue; \
12620+ } \
12621+ if (__put_user(__c_ao, (char __user *)__addr)) \
12622+ break; \
12623+ __addr = __addr_ao; \
12624+ } \
12625+ } \
12626+ __ret_ao; \
12627+})
12628
12629 /*
12630 * The exception table consists of pairs of addresses relative to the
12631@@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12632 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12633 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12634
12635-
12636+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12637+#define __copyuser_seg "gs;"
12638+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12639+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12640+#else
12641+#define __copyuser_seg
12642+#define __COPYUSER_SET_ES
12643+#define __COPYUSER_RESTORE_ES
12644+#endif
12645
12646 #ifdef CONFIG_X86_32
12647 #define __put_user_asm_u64(x, addr, err, errret) \
12648- asm volatile("1: movl %%eax,0(%2)\n" \
12649- "2: movl %%edx,4(%2)\n" \
12650+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12651+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12652 "3:\n" \
12653 ".section .fixup,\"ax\"\n" \
12654 "4: movl %3,%0\n" \
12655@@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12656 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12657
12658 #define __put_user_asm_ex_u64(x, addr) \
12659- asm volatile("1: movl %%eax,0(%1)\n" \
12660- "2: movl %%edx,4(%1)\n" \
12661+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12662+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12663 "3:\n" \
12664 _ASM_EXTABLE_EX(1b, 2b) \
12665 _ASM_EXTABLE_EX(2b, 3b) \
12666@@ -258,7 +299,7 @@ extern void __put_user_8(void);
12667 __typeof__(*(ptr)) __pu_val; \
12668 __chk_user_ptr(ptr); \
12669 might_fault(); \
12670- __pu_val = x; \
12671+ __pu_val = (x); \
12672 switch (sizeof(*(ptr))) { \
12673 case 1: \
12674 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12675@@ -379,7 +420,7 @@ do { \
12676 } while (0)
12677
12678 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12679- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12680+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12681 "2:\n" \
12682 ".section .fixup,\"ax\"\n" \
12683 "3: mov %3,%0\n" \
12684@@ -387,7 +428,7 @@ do { \
12685 " jmp 2b\n" \
12686 ".previous\n" \
12687 _ASM_EXTABLE(1b, 3b) \
12688- : "=r" (err), ltype(x) \
12689+ : "=r" (err), ltype (x) \
12690 : "m" (__m(addr)), "i" (errret), "0" (err))
12691
12692 #define __get_user_size_ex(x, ptr, size) \
12693@@ -412,7 +453,7 @@ do { \
12694 } while (0)
12695
12696 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12697- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12698+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12699 "2:\n" \
12700 _ASM_EXTABLE_EX(1b, 2b) \
12701 : ltype(x) : "m" (__m(addr)))
12702@@ -429,13 +470,24 @@ do { \
12703 int __gu_err; \
12704 unsigned long __gu_val; \
12705 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12706- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12707+ (x) = (__typeof__(*(ptr)))__gu_val; \
12708 __gu_err; \
12709 })
12710
12711 /* FIXME: this hack is definitely wrong -AK */
12712 struct __large_struct { unsigned long buf[100]; };
12713-#define __m(x) (*(struct __large_struct __user *)(x))
12714+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12715+#define ____m(x) \
12716+({ \
12717+ unsigned long ____x = (unsigned long)(x); \
12718+ if (____x < PAX_USER_SHADOW_BASE) \
12719+ ____x += PAX_USER_SHADOW_BASE; \
12720+ (void __user *)____x; \
12721+})
12722+#else
12723+#define ____m(x) (x)
12724+#endif
12725+#define __m(x) (*(struct __large_struct __user *)____m(x))
12726
12727 /*
12728 * Tell gcc we read from memory instead of writing: this is because
12729@@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12730 * aliasing issues.
12731 */
12732 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12733- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12734+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12735 "2:\n" \
12736 ".section .fixup,\"ax\"\n" \
12737 "3: mov %3,%0\n" \
12738@@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12739 ".previous\n" \
12740 _ASM_EXTABLE(1b, 3b) \
12741 : "=r"(err) \
12742- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12743+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12744
12745 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12746- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12747+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12748 "2:\n" \
12749 _ASM_EXTABLE_EX(1b, 2b) \
12750 : : ltype(x), "m" (__m(addr)))
12751@@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12752 * On error, the variable @x is set to zero.
12753 */
12754
12755+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12756+#define __get_user(x, ptr) get_user((x), (ptr))
12757+#else
12758 #define __get_user(x, ptr) \
12759 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12760+#endif
12761
12762 /**
12763 * __put_user: - Write a simple value into user space, with less checking.
12764@@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12765 * Returns zero on success, or -EFAULT on error.
12766 */
12767
12768+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12769+#define __put_user(x, ptr) put_user((x), (ptr))
12770+#else
12771 #define __put_user(x, ptr) \
12772 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12773+#endif
12774
12775 #define __get_user_unaligned __get_user
12776 #define __put_user_unaligned __put_user
12777@@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12778 #define get_user_ex(x, ptr) do { \
12779 unsigned long __gue_val; \
12780 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12781- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12782+ (x) = (__typeof__(*(ptr)))__gue_val; \
12783 } while (0)
12784
12785 #ifdef CONFIG_X86_WP_WORKS_OK
12786diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12787index 576e39b..ccd0a39 100644
12788--- a/arch/x86/include/asm/uaccess_32.h
12789+++ b/arch/x86/include/asm/uaccess_32.h
12790@@ -11,15 +11,15 @@
12791 #include <asm/page.h>
12792
12793 unsigned long __must_check __copy_to_user_ll
12794- (void __user *to, const void *from, unsigned long n);
12795+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12796 unsigned long __must_check __copy_from_user_ll
12797- (void *to, const void __user *from, unsigned long n);
12798+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12799 unsigned long __must_check __copy_from_user_ll_nozero
12800- (void *to, const void __user *from, unsigned long n);
12801+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12802 unsigned long __must_check __copy_from_user_ll_nocache
12803- (void *to, const void __user *from, unsigned long n);
12804+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12805 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12806- (void *to, const void __user *from, unsigned long n);
12807+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12808
12809 /**
12810 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12811@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12812 static __always_inline unsigned long __must_check
12813 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12814 {
12815+ if ((long)n < 0)
12816+ return n;
12817+
12818 if (__builtin_constant_p(n)) {
12819 unsigned long ret;
12820
12821@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12822 return ret;
12823 }
12824 }
12825+ if (!__builtin_constant_p(n))
12826+ check_object_size(from, n, true);
12827 return __copy_to_user_ll(to, from, n);
12828 }
12829
12830@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12831 __copy_to_user(void __user *to, const void *from, unsigned long n)
12832 {
12833 might_fault();
12834+
12835 return __copy_to_user_inatomic(to, from, n);
12836 }
12837
12838 static __always_inline unsigned long
12839 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12840 {
12841+ if ((long)n < 0)
12842+ return n;
12843+
12844 /* Avoid zeroing the tail if the copy fails..
12845 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12846 * but as the zeroing behaviour is only significant when n is not
12847@@ -137,6 +146,10 @@ static __always_inline unsigned long
12848 __copy_from_user(void *to, const void __user *from, unsigned long n)
12849 {
12850 might_fault();
12851+
12852+ if ((long)n < 0)
12853+ return n;
12854+
12855 if (__builtin_constant_p(n)) {
12856 unsigned long ret;
12857
12858@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12859 return ret;
12860 }
12861 }
12862+ if (!__builtin_constant_p(n))
12863+ check_object_size(to, n, false);
12864 return __copy_from_user_ll(to, from, n);
12865 }
12866
12867@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12868 const void __user *from, unsigned long n)
12869 {
12870 might_fault();
12871+
12872+ if ((long)n < 0)
12873+ return n;
12874+
12875 if (__builtin_constant_p(n)) {
12876 unsigned long ret;
12877
12878@@ -181,15 +200,19 @@ static __always_inline unsigned long
12879 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12880 unsigned long n)
12881 {
12882- return __copy_from_user_ll_nocache_nozero(to, from, n);
12883+ if ((long)n < 0)
12884+ return n;
12885+
12886+ return __copy_from_user_ll_nocache_nozero(to, from, n);
12887 }
12888
12889-unsigned long __must_check copy_to_user(void __user *to,
12890- const void *from, unsigned long n);
12891-unsigned long __must_check _copy_from_user(void *to,
12892- const void __user *from,
12893- unsigned long n);
12894-
12895+extern void copy_to_user_overflow(void)
12896+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12897+ __compiletime_error("copy_to_user() buffer size is not provably correct")
12898+#else
12899+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
12900+#endif
12901+;
12902
12903 extern void copy_from_user_overflow(void)
12904 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12905@@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
12906 #endif
12907 ;
12908
12909-static inline unsigned long __must_check copy_from_user(void *to,
12910- const void __user *from,
12911- unsigned long n)
12912+/**
12913+ * copy_to_user: - Copy a block of data into user space.
12914+ * @to: Destination address, in user space.
12915+ * @from: Source address, in kernel space.
12916+ * @n: Number of bytes to copy.
12917+ *
12918+ * Context: User context only. This function may sleep.
12919+ *
12920+ * Copy data from kernel space to user space.
12921+ *
12922+ * Returns number of bytes that could not be copied.
12923+ * On success, this will be zero.
12924+ */
12925+static inline unsigned long __must_check
12926+copy_to_user(void __user *to, const void *from, unsigned long n)
12927 {
12928- int sz = __compiletime_object_size(to);
12929+ size_t sz = __compiletime_object_size(from);
12930
12931- if (likely(sz == -1 || sz >= n))
12932- n = _copy_from_user(to, from, n);
12933- else
12934+ if (unlikely(sz != (size_t)-1 && sz < n))
12935+ copy_to_user_overflow();
12936+ else if (access_ok(VERIFY_WRITE, to, n))
12937+ n = __copy_to_user(to, from, n);
12938+ return n;
12939+}
12940+
12941+/**
12942+ * copy_from_user: - Copy a block of data from user space.
12943+ * @to: Destination address, in kernel space.
12944+ * @from: Source address, in user space.
12945+ * @n: Number of bytes to copy.
12946+ *
12947+ * Context: User context only. This function may sleep.
12948+ *
12949+ * Copy data from user space to kernel space.
12950+ *
12951+ * Returns number of bytes that could not be copied.
12952+ * On success, this will be zero.
12953+ *
12954+ * If some data could not be copied, this function will pad the copied
12955+ * data to the requested size using zero bytes.
12956+ */
12957+static inline unsigned long __must_check
12958+copy_from_user(void *to, const void __user *from, unsigned long n)
12959+{
12960+ size_t sz = __compiletime_object_size(to);
12961+
12962+ if (unlikely(sz != (size_t)-1 && sz < n))
12963 copy_from_user_overflow();
12964-
12965+ else if (access_ok(VERIFY_READ, from, n))
12966+ n = __copy_from_user(to, from, n);
12967+ else if ((long)n > 0) {
12968+ if (!__builtin_constant_p(n))
12969+ check_object_size(to, n, false);
12970+ memset(to, 0, n);
12971+ }
12972 return n;
12973 }
12974
12975-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
12976-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
12977+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12978+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12979
12980 #endif /* _ASM_X86_UACCESS_32_H */
12981diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12982index 8e796fb..72fd934 100644
12983--- a/arch/x86/include/asm/uaccess_64.h
12984+++ b/arch/x86/include/asm/uaccess_64.h
12985@@ -10,6 +10,9 @@
12986 #include <asm/alternative.h>
12987 #include <asm/cpufeature.h>
12988 #include <asm/page.h>
12989+#include <asm/pgtable.h>
12990+
12991+#define set_fs(x) (current_thread_info()->addr_limit = (x))
12992
12993 /*
12994 * Copy To/From Userspace
12995@@ -17,12 +20,14 @@
12996
12997 /* Handles exceptions in both to and from, but doesn't do access_ok */
12998 __must_check unsigned long
12999-copy_user_generic_string(void *to, const void *from, unsigned len);
13000+copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13001 __must_check unsigned long
13002-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13003+copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13004
13005 static __always_inline __must_check unsigned long
13006-copy_user_generic(void *to, const void *from, unsigned len)
13007+copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13008+static __always_inline __must_check unsigned long
13009+copy_user_generic(void *to, const void *from, unsigned long len)
13010 {
13011 unsigned ret;
13012
13013@@ -32,142 +37,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13014 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13015 "=d" (len)),
13016 "1" (to), "2" (from), "3" (len)
13017- : "memory", "rcx", "r8", "r9", "r10", "r11");
13018+ : "memory", "rcx", "r8", "r9", "r11");
13019 return ret;
13020 }
13021
13022+static __always_inline __must_check unsigned long
13023+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13024+static __always_inline __must_check unsigned long
13025+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13026 __must_check unsigned long
13027-_copy_to_user(void __user *to, const void *from, unsigned len);
13028-__must_check unsigned long
13029-_copy_from_user(void *to, const void __user *from, unsigned len);
13030-__must_check unsigned long
13031-copy_in_user(void __user *to, const void __user *from, unsigned len);
13032+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13033+
13034+extern void copy_to_user_overflow(void)
13035+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13036+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13037+#else
13038+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13039+#endif
13040+;
13041+
13042+extern void copy_from_user_overflow(void)
13043+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13044+ __compiletime_error("copy_from_user() buffer size is not provably correct")
13045+#else
13046+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
13047+#endif
13048+;
13049
13050 static inline unsigned long __must_check copy_from_user(void *to,
13051 const void __user *from,
13052 unsigned long n)
13053 {
13054- int sz = __compiletime_object_size(to);
13055-
13056 might_fault();
13057- if (likely(sz == -1 || sz >= n))
13058- n = _copy_from_user(to, from, n);
13059-#ifdef CONFIG_DEBUG_VM
13060- else
13061- WARN(1, "Buffer overflow detected!\n");
13062-#endif
13063+
13064+ if (access_ok(VERIFY_READ, from, n))
13065+ n = __copy_from_user(to, from, n);
13066+ else if (n < INT_MAX) {
13067+ if (!__builtin_constant_p(n))
13068+ check_object_size(to, n, false);
13069+ memset(to, 0, n);
13070+ }
13071 return n;
13072 }
13073
13074 static __always_inline __must_check
13075-int copy_to_user(void __user *dst, const void *src, unsigned size)
13076+int copy_to_user(void __user *dst, const void *src, unsigned long size)
13077 {
13078 might_fault();
13079
13080- return _copy_to_user(dst, src, size);
13081+ if (access_ok(VERIFY_WRITE, dst, size))
13082+ size = __copy_to_user(dst, src, size);
13083+ return size;
13084 }
13085
13086 static __always_inline __must_check
13087-int __copy_from_user(void *dst, const void __user *src, unsigned size)
13088+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13089 {
13090- int ret = 0;
13091+ size_t sz = __compiletime_object_size(dst);
13092+ unsigned ret = 0;
13093
13094 might_fault();
13095- if (!__builtin_constant_p(size))
13096- return copy_user_generic(dst, (__force void *)src, size);
13097+
13098+ if (size > INT_MAX)
13099+ return size;
13100+
13101+#ifdef CONFIG_PAX_MEMORY_UDEREF
13102+ if (!__access_ok(VERIFY_READ, src, size))
13103+ return size;
13104+#endif
13105+
13106+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13107+ copy_from_user_overflow();
13108+ return size;
13109+ }
13110+
13111+ if (!__builtin_constant_p(size)) {
13112+ check_object_size(dst, size, false);
13113+
13114+#ifdef CONFIG_PAX_MEMORY_UDEREF
13115+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13116+ src += PAX_USER_SHADOW_BASE;
13117+#endif
13118+
13119+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13120+ }
13121 switch (size) {
13122- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13123+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13124 ret, "b", "b", "=q", 1);
13125 return ret;
13126- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13127+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13128 ret, "w", "w", "=r", 2);
13129 return ret;
13130- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13131+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13132 ret, "l", "k", "=r", 4);
13133 return ret;
13134- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13135+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13136 ret, "q", "", "=r", 8);
13137 return ret;
13138 case 10:
13139- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13140+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13141 ret, "q", "", "=r", 10);
13142 if (unlikely(ret))
13143 return ret;
13144 __get_user_asm(*(u16 *)(8 + (char *)dst),
13145- (u16 __user *)(8 + (char __user *)src),
13146+ (const u16 __user *)(8 + (const char __user *)src),
13147 ret, "w", "w", "=r", 2);
13148 return ret;
13149 case 16:
13150- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13151+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13152 ret, "q", "", "=r", 16);
13153 if (unlikely(ret))
13154 return ret;
13155 __get_user_asm(*(u64 *)(8 + (char *)dst),
13156- (u64 __user *)(8 + (char __user *)src),
13157+ (const u64 __user *)(8 + (const char __user *)src),
13158 ret, "q", "", "=r", 8);
13159 return ret;
13160 default:
13161- return copy_user_generic(dst, (__force void *)src, size);
13162+
13163+#ifdef CONFIG_PAX_MEMORY_UDEREF
13164+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13165+ src += PAX_USER_SHADOW_BASE;
13166+#endif
13167+
13168+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13169 }
13170 }
13171
13172 static __always_inline __must_check
13173-int __copy_to_user(void __user *dst, const void *src, unsigned size)
13174+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13175 {
13176- int ret = 0;
13177+ size_t sz = __compiletime_object_size(src);
13178+ unsigned ret = 0;
13179
13180 might_fault();
13181- if (!__builtin_constant_p(size))
13182- return copy_user_generic((__force void *)dst, src, size);
13183+
13184+ if (size > INT_MAX)
13185+ return size;
13186+
13187+#ifdef CONFIG_PAX_MEMORY_UDEREF
13188+ if (!__access_ok(VERIFY_WRITE, dst, size))
13189+ return size;
13190+#endif
13191+
13192+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13193+ copy_to_user_overflow();
13194+ return size;
13195+ }
13196+
13197+ if (!__builtin_constant_p(size)) {
13198+ check_object_size(src, size, true);
13199+
13200+#ifdef CONFIG_PAX_MEMORY_UDEREF
13201+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13202+ dst += PAX_USER_SHADOW_BASE;
13203+#endif
13204+
13205+ return copy_user_generic((__force_kernel void *)dst, src, size);
13206+ }
13207 switch (size) {
13208- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13209+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13210 ret, "b", "b", "iq", 1);
13211 return ret;
13212- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13213+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13214 ret, "w", "w", "ir", 2);
13215 return ret;
13216- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13217+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13218 ret, "l", "k", "ir", 4);
13219 return ret;
13220- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13221+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13222 ret, "q", "", "er", 8);
13223 return ret;
13224 case 10:
13225- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13226+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13227 ret, "q", "", "er", 10);
13228 if (unlikely(ret))
13229 return ret;
13230 asm("":::"memory");
13231- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13232+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13233 ret, "w", "w", "ir", 2);
13234 return ret;
13235 case 16:
13236- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13237+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13238 ret, "q", "", "er", 16);
13239 if (unlikely(ret))
13240 return ret;
13241 asm("":::"memory");
13242- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13243+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13244 ret, "q", "", "er", 8);
13245 return ret;
13246 default:
13247- return copy_user_generic((__force void *)dst, src, size);
13248+
13249+#ifdef CONFIG_PAX_MEMORY_UDEREF
13250+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13251+ dst += PAX_USER_SHADOW_BASE;
13252+#endif
13253+
13254+ return copy_user_generic((__force_kernel void *)dst, src, size);
13255 }
13256 }
13257
13258 static __always_inline __must_check
13259-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13260+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13261 {
13262- int ret = 0;
13263+ unsigned ret = 0;
13264
13265 might_fault();
13266- if (!__builtin_constant_p(size))
13267- return copy_user_generic((__force void *)dst,
13268- (__force void *)src, size);
13269+
13270+ if (size > INT_MAX)
13271+ return size;
13272+
13273+#ifdef CONFIG_PAX_MEMORY_UDEREF
13274+ if (!__access_ok(VERIFY_READ, src, size))
13275+ return size;
13276+ if (!__access_ok(VERIFY_WRITE, dst, size))
13277+ return size;
13278+#endif
13279+
13280+ if (!__builtin_constant_p(size)) {
13281+
13282+#ifdef CONFIG_PAX_MEMORY_UDEREF
13283+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13284+ src += PAX_USER_SHADOW_BASE;
13285+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13286+ dst += PAX_USER_SHADOW_BASE;
13287+#endif
13288+
13289+ return copy_user_generic((__force_kernel void *)dst,
13290+ (__force_kernel const void *)src, size);
13291+ }
13292 switch (size) {
13293 case 1: {
13294 u8 tmp;
13295- __get_user_asm(tmp, (u8 __user *)src,
13296+ __get_user_asm(tmp, (const u8 __user *)src,
13297 ret, "b", "b", "=q", 1);
13298 if (likely(!ret))
13299 __put_user_asm(tmp, (u8 __user *)dst,
13300@@ -176,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13301 }
13302 case 2: {
13303 u16 tmp;
13304- __get_user_asm(tmp, (u16 __user *)src,
13305+ __get_user_asm(tmp, (const u16 __user *)src,
13306 ret, "w", "w", "=r", 2);
13307 if (likely(!ret))
13308 __put_user_asm(tmp, (u16 __user *)dst,
13309@@ -186,7 +287,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13310
13311 case 4: {
13312 u32 tmp;
13313- __get_user_asm(tmp, (u32 __user *)src,
13314+ __get_user_asm(tmp, (const u32 __user *)src,
13315 ret, "l", "k", "=r", 4);
13316 if (likely(!ret))
13317 __put_user_asm(tmp, (u32 __user *)dst,
13318@@ -195,7 +296,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13319 }
13320 case 8: {
13321 u64 tmp;
13322- __get_user_asm(tmp, (u64 __user *)src,
13323+ __get_user_asm(tmp, (const u64 __user *)src,
13324 ret, "q", "", "=r", 8);
13325 if (likely(!ret))
13326 __put_user_asm(tmp, (u64 __user *)dst,
13327@@ -203,44 +304,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13328 return ret;
13329 }
13330 default:
13331- return copy_user_generic((__force void *)dst,
13332- (__force void *)src, size);
13333+
13334+#ifdef CONFIG_PAX_MEMORY_UDEREF
13335+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13336+ src += PAX_USER_SHADOW_BASE;
13337+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13338+ dst += PAX_USER_SHADOW_BASE;
13339+#endif
13340+
13341+ return copy_user_generic((__force_kernel void *)dst,
13342+ (__force_kernel const void *)src, size);
13343 }
13344 }
13345
13346-__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13347-__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13348+__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13349+__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13350
13351 static __must_check __always_inline int
13352-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13353+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13354 {
13355- return copy_user_generic(dst, (__force const void *)src, size);
13356+ if (size > INT_MAX)
13357+ return size;
13358+
13359+#ifdef CONFIG_PAX_MEMORY_UDEREF
13360+ if (!__access_ok(VERIFY_READ, src, size))
13361+ return size;
13362+
13363+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13364+ src += PAX_USER_SHADOW_BASE;
13365+#endif
13366+
13367+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13368 }
13369
13370-static __must_check __always_inline int
13371-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13372+static __must_check __always_inline unsigned long
13373+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13374 {
13375- return copy_user_generic((__force void *)dst, src, size);
13376+ if (size > INT_MAX)
13377+ return size;
13378+
13379+#ifdef CONFIG_PAX_MEMORY_UDEREF
13380+ if (!__access_ok(VERIFY_WRITE, dst, size))
13381+ return size;
13382+
13383+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13384+ dst += PAX_USER_SHADOW_BASE;
13385+#endif
13386+
13387+ return copy_user_generic((__force_kernel void *)dst, src, size);
13388 }
13389
13390-extern long __copy_user_nocache(void *dst, const void __user *src,
13391- unsigned size, int zerorest);
13392+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13393+ unsigned long size, int zerorest) __size_overflow(3);
13394
13395-static inline int
13396-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13397+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13398 {
13399 might_sleep();
13400+
13401+ if (size > INT_MAX)
13402+ return size;
13403+
13404+#ifdef CONFIG_PAX_MEMORY_UDEREF
13405+ if (!__access_ok(VERIFY_READ, src, size))
13406+ return size;
13407+#endif
13408+
13409 return __copy_user_nocache(dst, src, size, 1);
13410 }
13411
13412-static inline int
13413-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13414- unsigned size)
13415+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13416+ unsigned long size)
13417 {
13418+ if (size > INT_MAX)
13419+ return size;
13420+
13421+#ifdef CONFIG_PAX_MEMORY_UDEREF
13422+ if (!__access_ok(VERIFY_READ, src, size))
13423+ return size;
13424+#endif
13425+
13426 return __copy_user_nocache(dst, src, size, 0);
13427 }
13428
13429-unsigned long
13430-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13431+extern unsigned long
13432+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13433
13434 #endif /* _ASM_X86_UACCESS_64_H */
13435diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13436index bb05228..d763d5b 100644
13437--- a/arch/x86/include/asm/vdso.h
13438+++ b/arch/x86/include/asm/vdso.h
13439@@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13440 #define VDSO32_SYMBOL(base, name) \
13441 ({ \
13442 extern const char VDSO32_##name[]; \
13443- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13444+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13445 })
13446 #endif
13447
13448diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13449index 5b238981..77fdd78 100644
13450--- a/arch/x86/include/asm/word-at-a-time.h
13451+++ b/arch/x86/include/asm/word-at-a-time.h
13452@@ -11,7 +11,7 @@
13453 * and shift, for example.
13454 */
13455 struct word_at_a_time {
13456- const unsigned long one_bits, high_bits;
13457+ unsigned long one_bits, high_bits;
13458 };
13459
13460 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13461diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13462index c090af1..7e7bf16 100644
13463--- a/arch/x86/include/asm/x86_init.h
13464+++ b/arch/x86/include/asm/x86_init.h
13465@@ -29,7 +29,7 @@ struct x86_init_mpparse {
13466 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13467 void (*find_smp_config)(void);
13468 void (*get_smp_config)(unsigned int early);
13469-};
13470+} __no_const;
13471
13472 /**
13473 * struct x86_init_resources - platform specific resource related ops
13474@@ -43,7 +43,7 @@ struct x86_init_resources {
13475 void (*probe_roms)(void);
13476 void (*reserve_resources)(void);
13477 char *(*memory_setup)(void);
13478-};
13479+} __no_const;
13480
13481 /**
13482 * struct x86_init_irqs - platform specific interrupt setup
13483@@ -56,7 +56,7 @@ struct x86_init_irqs {
13484 void (*pre_vector_init)(void);
13485 void (*intr_init)(void);
13486 void (*trap_init)(void);
13487-};
13488+} __no_const;
13489
13490 /**
13491 * struct x86_init_oem - oem platform specific customizing functions
13492@@ -66,7 +66,7 @@ struct x86_init_irqs {
13493 struct x86_init_oem {
13494 void (*arch_setup)(void);
13495 void (*banner)(void);
13496-};
13497+} __no_const;
13498
13499 /**
13500 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13501@@ -77,7 +77,7 @@ struct x86_init_oem {
13502 */
13503 struct x86_init_mapping {
13504 void (*pagetable_reserve)(u64 start, u64 end);
13505-};
13506+} __no_const;
13507
13508 /**
13509 * struct x86_init_paging - platform specific paging functions
13510@@ -87,7 +87,7 @@ struct x86_init_mapping {
13511 struct x86_init_paging {
13512 void (*pagetable_setup_start)(pgd_t *base);
13513 void (*pagetable_setup_done)(pgd_t *base);
13514-};
13515+} __no_const;
13516
13517 /**
13518 * struct x86_init_timers - platform specific timer setup
13519@@ -102,7 +102,7 @@ struct x86_init_timers {
13520 void (*tsc_pre_init)(void);
13521 void (*timer_init)(void);
13522 void (*wallclock_init)(void);
13523-};
13524+} __no_const;
13525
13526 /**
13527 * struct x86_init_iommu - platform specific iommu setup
13528@@ -110,7 +110,7 @@ struct x86_init_timers {
13529 */
13530 struct x86_init_iommu {
13531 int (*iommu_init)(void);
13532-};
13533+} __no_const;
13534
13535 /**
13536 * struct x86_init_pci - platform specific pci init functions
13537@@ -124,7 +124,7 @@ struct x86_init_pci {
13538 int (*init)(void);
13539 void (*init_irq)(void);
13540 void (*fixup_irqs)(void);
13541-};
13542+} __no_const;
13543
13544 /**
13545 * struct x86_init_ops - functions for platform specific setup
13546@@ -140,7 +140,7 @@ struct x86_init_ops {
13547 struct x86_init_timers timers;
13548 struct x86_init_iommu iommu;
13549 struct x86_init_pci pci;
13550-};
13551+} __no_const;
13552
13553 /**
13554 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13555@@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13556 void (*setup_percpu_clockev)(void);
13557 void (*early_percpu_clock_init)(void);
13558 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13559-};
13560+} __no_const;
13561
13562 /**
13563 * struct x86_platform_ops - platform specific runtime functions
13564@@ -177,7 +177,7 @@ struct x86_platform_ops {
13565 int (*i8042_detect)(void);
13566 void (*save_sched_clock_state)(void);
13567 void (*restore_sched_clock_state)(void);
13568-};
13569+} __no_const;
13570
13571 struct pci_dev;
13572
13573@@ -186,14 +186,14 @@ struct x86_msi_ops {
13574 void (*teardown_msi_irq)(unsigned int irq);
13575 void (*teardown_msi_irqs)(struct pci_dev *dev);
13576 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13577-};
13578+} __no_const;
13579
13580 struct x86_io_apic_ops {
13581 void (*init) (void);
13582 unsigned int (*read) (unsigned int apic, unsigned int reg);
13583 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13584 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13585-};
13586+} __no_const;
13587
13588 extern struct x86_init_ops x86_init;
13589 extern struct x86_cpuinit_ops x86_cpuinit;
13590diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13591index 8a1b6f9..a29c4e4 100644
13592--- a/arch/x86/include/asm/xsave.h
13593+++ b/arch/x86/include/asm/xsave.h
13594@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13595 {
13596 int err;
13597
13598+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13599+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13600+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13601+#endif
13602+
13603 /*
13604 * Clear the xsave header first, so that reserved fields are
13605 * initialized to zero.
13606@@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13607 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13608 {
13609 int err;
13610- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13611+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13612 u32 lmask = mask;
13613 u32 hmask = mask >> 32;
13614
13615+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13616+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13617+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13618+#endif
13619+
13620 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13621 "2:\n"
13622 ".section .fixup,\"ax\"\n"
13623diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13624index 95bf99de..de9235c 100644
13625--- a/arch/x86/kernel/acpi/sleep.c
13626+++ b/arch/x86/kernel/acpi/sleep.c
13627@@ -73,8 +73,12 @@ int acpi_suspend_lowlevel(void)
13628 #else /* CONFIG_64BIT */
13629 #ifdef CONFIG_SMP
13630 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13631+
13632+ pax_open_kernel();
13633 early_gdt_descr.address =
13634 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13635+ pax_close_kernel();
13636+
13637 initial_gs = per_cpu_offset(smp_processor_id());
13638 #endif
13639 initial_code = (unsigned long)wakeup_long64;
13640diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13641index 7261083..5c12053 100644
13642--- a/arch/x86/kernel/acpi/wakeup_32.S
13643+++ b/arch/x86/kernel/acpi/wakeup_32.S
13644@@ -30,13 +30,11 @@ wakeup_pmode_return:
13645 # and restore the stack ... but you need gdt for this to work
13646 movl saved_context_esp, %esp
13647
13648- movl %cs:saved_magic, %eax
13649- cmpl $0x12345678, %eax
13650+ cmpl $0x12345678, saved_magic
13651 jne bogus_magic
13652
13653 # jump to place where we left off
13654- movl saved_eip, %eax
13655- jmp *%eax
13656+ jmp *(saved_eip)
13657
13658 bogus_magic:
13659 jmp bogus_magic
13660diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13661index 1f84794..e23f862 100644
13662--- a/arch/x86/kernel/alternative.c
13663+++ b/arch/x86/kernel/alternative.c
13664@@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13665 */
13666 for (a = start; a < end; a++) {
13667 instr = (u8 *)&a->instr_offset + a->instr_offset;
13668+
13669+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13670+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13671+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13672+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13673+#endif
13674+
13675 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13676 BUG_ON(a->replacementlen > a->instrlen);
13677 BUG_ON(a->instrlen > sizeof(insnbuf));
13678@@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13679 for (poff = start; poff < end; poff++) {
13680 u8 *ptr = (u8 *)poff + *poff;
13681
13682+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13683+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13684+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13685+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13686+#endif
13687+
13688 if (!*poff || ptr < text || ptr >= text_end)
13689 continue;
13690 /* turn DS segment override prefix into lock prefix */
13691- if (*ptr == 0x3e)
13692+ if (*ktla_ktva(ptr) == 0x3e)
13693 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13694 };
13695 mutex_unlock(&text_mutex);
13696@@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13697 for (poff = start; poff < end; poff++) {
13698 u8 *ptr = (u8 *)poff + *poff;
13699
13700+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13701+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13702+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13703+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13704+#endif
13705+
13706 if (!*poff || ptr < text || ptr >= text_end)
13707 continue;
13708 /* turn lock prefix into DS segment override prefix */
13709- if (*ptr == 0xf0)
13710+ if (*ktla_ktva(ptr) == 0xf0)
13711 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13712 };
13713 mutex_unlock(&text_mutex);
13714@@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13715
13716 BUG_ON(p->len > MAX_PATCH_LEN);
13717 /* prep the buffer with the original instructions */
13718- memcpy(insnbuf, p->instr, p->len);
13719+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13720 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13721 (unsigned long)p->instr, p->len);
13722
13723@@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13724 if (smp_alt_once)
13725 free_init_pages("SMP alternatives",
13726 (unsigned long)__smp_locks,
13727- (unsigned long)__smp_locks_end);
13728+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13729
13730 restart_nmi();
13731 }
13732@@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13733 * instructions. And on the local CPU you need to be protected again NMI or MCE
13734 * handlers seeing an inconsistent instruction while you patch.
13735 */
13736-void *__init_or_module text_poke_early(void *addr, const void *opcode,
13737+void *__kprobes text_poke_early(void *addr, const void *opcode,
13738 size_t len)
13739 {
13740 unsigned long flags;
13741 local_irq_save(flags);
13742- memcpy(addr, opcode, len);
13743+
13744+ pax_open_kernel();
13745+ memcpy(ktla_ktva(addr), opcode, len);
13746 sync_core();
13747+ pax_close_kernel();
13748+
13749 local_irq_restore(flags);
13750 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13751 that causes hangs on some VIA CPUs. */
13752@@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13753 */
13754 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13755 {
13756- unsigned long flags;
13757- char *vaddr;
13758+ unsigned char *vaddr = ktla_ktva(addr);
13759 struct page *pages[2];
13760- int i;
13761+ size_t i;
13762
13763 if (!core_kernel_text((unsigned long)addr)) {
13764- pages[0] = vmalloc_to_page(addr);
13765- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13766+ pages[0] = vmalloc_to_page(vaddr);
13767+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13768 } else {
13769- pages[0] = virt_to_page(addr);
13770+ pages[0] = virt_to_page(vaddr);
13771 WARN_ON(!PageReserved(pages[0]));
13772- pages[1] = virt_to_page(addr + PAGE_SIZE);
13773+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13774 }
13775 BUG_ON(!pages[0]);
13776- local_irq_save(flags);
13777- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13778- if (pages[1])
13779- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13780- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13781- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13782- clear_fixmap(FIX_TEXT_POKE0);
13783- if (pages[1])
13784- clear_fixmap(FIX_TEXT_POKE1);
13785- local_flush_tlb();
13786- sync_core();
13787- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13788- that causes hangs on some VIA CPUs. */
13789+ text_poke_early(addr, opcode, len);
13790 for (i = 0; i < len; i++)
13791- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13792- local_irq_restore(flags);
13793+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13794 return addr;
13795 }
13796
13797diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13798index 39a222e..85a7767 100644
13799--- a/arch/x86/kernel/apic/apic.c
13800+++ b/arch/x86/kernel/apic/apic.c
13801@@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13802 /*
13803 * Debug level, exported for io_apic.c
13804 */
13805-unsigned int apic_verbosity;
13806+int apic_verbosity;
13807
13808 int pic_mode;
13809
13810@@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13811 apic_write(APIC_ESR, 0);
13812 v1 = apic_read(APIC_ESR);
13813 ack_APIC_irq();
13814- atomic_inc(&irq_err_count);
13815+ atomic_inc_unchecked(&irq_err_count);
13816
13817 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13818 smp_processor_id(), v0 , v1);
13819diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13820index 5f0ff59..f9e01bc 100644
13821--- a/arch/x86/kernel/apic/io_apic.c
13822+++ b/arch/x86/kernel/apic/io_apic.c
13823@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13824 }
13825 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13826
13827-void lock_vector_lock(void)
13828+void lock_vector_lock(void) __acquires(vector_lock)
13829 {
13830 /* Used to the online set of cpus does not change
13831 * during assign_irq_vector.
13832@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13833 raw_spin_lock(&vector_lock);
13834 }
13835
13836-void unlock_vector_lock(void)
13837+void unlock_vector_lock(void) __releases(vector_lock)
13838 {
13839 raw_spin_unlock(&vector_lock);
13840 }
13841@@ -2369,7 +2369,7 @@ static void ack_apic_edge(struct irq_data *data)
13842 ack_APIC_irq();
13843 }
13844
13845-atomic_t irq_mis_count;
13846+atomic_unchecked_t irq_mis_count;
13847
13848 #ifdef CONFIG_GENERIC_PENDING_IRQ
13849 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13850@@ -2510,7 +2510,7 @@ static void ack_apic_level(struct irq_data *data)
13851 * at the cpu.
13852 */
13853 if (!(v & (1 << (i & 0x1f)))) {
13854- atomic_inc(&irq_mis_count);
13855+ atomic_inc_unchecked(&irq_mis_count);
13856
13857 eoi_ioapic_irq(irq, cfg);
13858 }
13859diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13860index 07b0c0d..1df6f42 100644
13861--- a/arch/x86/kernel/apm_32.c
13862+++ b/arch/x86/kernel/apm_32.c
13863@@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13864 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13865 * even though they are called in protected mode.
13866 */
13867-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13868+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13869 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13870
13871 static const char driver_version[] = "1.16ac"; /* no spaces */
13872@@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13873 BUG_ON(cpu != 0);
13874 gdt = get_cpu_gdt_table(cpu);
13875 save_desc_40 = gdt[0x40 / 8];
13876+
13877+ pax_open_kernel();
13878 gdt[0x40 / 8] = bad_bios_desc;
13879+ pax_close_kernel();
13880
13881 apm_irq_save(flags);
13882 APM_DO_SAVE_SEGS;
13883@@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13884 &call->esi);
13885 APM_DO_RESTORE_SEGS;
13886 apm_irq_restore(flags);
13887+
13888+ pax_open_kernel();
13889 gdt[0x40 / 8] = save_desc_40;
13890+ pax_close_kernel();
13891+
13892 put_cpu();
13893
13894 return call->eax & 0xff;
13895@@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
13896 BUG_ON(cpu != 0);
13897 gdt = get_cpu_gdt_table(cpu);
13898 save_desc_40 = gdt[0x40 / 8];
13899+
13900+ pax_open_kernel();
13901 gdt[0x40 / 8] = bad_bios_desc;
13902+ pax_close_kernel();
13903
13904 apm_irq_save(flags);
13905 APM_DO_SAVE_SEGS;
13906@@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
13907 &call->eax);
13908 APM_DO_RESTORE_SEGS;
13909 apm_irq_restore(flags);
13910+
13911+ pax_open_kernel();
13912 gdt[0x40 / 8] = save_desc_40;
13913+ pax_close_kernel();
13914+
13915 put_cpu();
13916 return error;
13917 }
13918@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
13919 * code to that CPU.
13920 */
13921 gdt = get_cpu_gdt_table(0);
13922+
13923+ pax_open_kernel();
13924 set_desc_base(&gdt[APM_CS >> 3],
13925 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13926 set_desc_base(&gdt[APM_CS_16 >> 3],
13927 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13928 set_desc_base(&gdt[APM_DS >> 3],
13929 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13930+ pax_close_kernel();
13931
13932 proc_create("apm", 0, NULL, &apm_file_ops);
13933
13934diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13935index 68de2dc..1f3c720 100644
13936--- a/arch/x86/kernel/asm-offsets.c
13937+++ b/arch/x86/kernel/asm-offsets.c
13938@@ -33,6 +33,8 @@ void common(void) {
13939 OFFSET(TI_status, thread_info, status);
13940 OFFSET(TI_addr_limit, thread_info, addr_limit);
13941 OFFSET(TI_preempt_count, thread_info, preempt_count);
13942+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13943+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13944
13945 BLANK();
13946 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13947@@ -53,8 +55,26 @@ void common(void) {
13948 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13949 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13950 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13951+
13952+#ifdef CONFIG_PAX_KERNEXEC
13953+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13954 #endif
13955
13956+#ifdef CONFIG_PAX_MEMORY_UDEREF
13957+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13958+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13959+#ifdef CONFIG_X86_64
13960+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13961+#endif
13962+#endif
13963+
13964+#endif
13965+
13966+ BLANK();
13967+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13968+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13969+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13970+
13971 #ifdef CONFIG_XEN
13972 BLANK();
13973 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13974diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13975index 1b4754f..fbb4227 100644
13976--- a/arch/x86/kernel/asm-offsets_64.c
13977+++ b/arch/x86/kernel/asm-offsets_64.c
13978@@ -76,6 +76,7 @@ int main(void)
13979 BLANK();
13980 #undef ENTRY
13981
13982+ DEFINE(TSS_size, sizeof(struct tss_struct));
13983 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13984 BLANK();
13985
13986diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13987index 6ab6aa2..8f71507 100644
13988--- a/arch/x86/kernel/cpu/Makefile
13989+++ b/arch/x86/kernel/cpu/Makefile
13990@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13991 CFLAGS_REMOVE_perf_event.o = -pg
13992 endif
13993
13994-# Make sure load_percpu_segment has no stackprotector
13995-nostackp := $(call cc-option, -fno-stack-protector)
13996-CFLAGS_common.o := $(nostackp)
13997-
13998 obj-y := intel_cacheinfo.o scattered.o topology.o
13999 obj-y += proc.o capflags.o powerflags.o common.o
14000 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14001diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14002index 146bb62..ac9c74a 100644
14003--- a/arch/x86/kernel/cpu/amd.c
14004+++ b/arch/x86/kernel/cpu/amd.c
14005@@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14006 unsigned int size)
14007 {
14008 /* AMD errata T13 (order #21922) */
14009- if ((c->x86 == 6)) {
14010+ if (c->x86 == 6) {
14011 /* Duron Rev A0 */
14012 if (c->x86_model == 3 && c->x86_mask == 0)
14013 size = 64;
14014diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14015index 6b9333b..4c3083a 100644
14016--- a/arch/x86/kernel/cpu/common.c
14017+++ b/arch/x86/kernel/cpu/common.c
14018@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14019
14020 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14021
14022-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14023-#ifdef CONFIG_X86_64
14024- /*
14025- * We need valid kernel segments for data and code in long mode too
14026- * IRET will check the segment types kkeil 2000/10/28
14027- * Also sysret mandates a special GDT layout
14028- *
14029- * TLS descriptors are currently at a different place compared to i386.
14030- * Hopefully nobody expects them at a fixed place (Wine?)
14031- */
14032- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14033- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14034- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14035- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14036- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14037- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14038-#else
14039- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14040- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14041- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14042- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14043- /*
14044- * Segments used for calling PnP BIOS have byte granularity.
14045- * They code segments and data segments have fixed 64k limits,
14046- * the transfer segment sizes are set at run time.
14047- */
14048- /* 32-bit code */
14049- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14050- /* 16-bit code */
14051- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14052- /* 16-bit data */
14053- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14054- /* 16-bit data */
14055- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14056- /* 16-bit data */
14057- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14058- /*
14059- * The APM segments have byte granularity and their bases
14060- * are set at run time. All have 64k limits.
14061- */
14062- /* 32-bit code */
14063- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14064- /* 16-bit code */
14065- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14066- /* data */
14067- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14068-
14069- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14070- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14071- GDT_STACK_CANARY_INIT
14072-#endif
14073-} };
14074-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14075-
14076 static int __init x86_xsave_setup(char *s)
14077 {
14078 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14079@@ -374,7 +320,7 @@ void switch_to_new_gdt(int cpu)
14080 {
14081 struct desc_ptr gdt_descr;
14082
14083- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14084+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14085 gdt_descr.size = GDT_SIZE - 1;
14086 load_gdt(&gdt_descr);
14087 /* Reload the per-cpu base */
14088@@ -841,6 +787,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14089 /* Filter out anything that depends on CPUID levels we don't have */
14090 filter_cpuid_features(c, true);
14091
14092+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14093+ setup_clear_cpu_cap(X86_FEATURE_SEP);
14094+#endif
14095+
14096 /* If the model name is still unset, do table lookup. */
14097 if (!c->x86_model_id[0]) {
14098 const char *p;
14099@@ -1021,10 +971,12 @@ static __init int setup_disablecpuid(char *arg)
14100 }
14101 __setup("clearcpuid=", setup_disablecpuid);
14102
14103+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14104+EXPORT_PER_CPU_SYMBOL(current_tinfo);
14105+
14106 #ifdef CONFIG_X86_64
14107 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14108-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14109- (unsigned long) nmi_idt_table };
14110+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14111
14112 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14113 irq_stack_union) __aligned(PAGE_SIZE);
14114@@ -1038,7 +990,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14115 EXPORT_PER_CPU_SYMBOL(current_task);
14116
14117 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14118- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14119+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14120 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14121
14122 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14123@@ -1132,7 +1084,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14124 {
14125 memset(regs, 0, sizeof(struct pt_regs));
14126 regs->fs = __KERNEL_PERCPU;
14127- regs->gs = __KERNEL_STACK_CANARY;
14128+ savesegment(gs, regs->gs);
14129
14130 return regs;
14131 }
14132@@ -1187,7 +1139,7 @@ void __cpuinit cpu_init(void)
14133 int i;
14134
14135 cpu = stack_smp_processor_id();
14136- t = &per_cpu(init_tss, cpu);
14137+ t = init_tss + cpu;
14138 oist = &per_cpu(orig_ist, cpu);
14139
14140 #ifdef CONFIG_NUMA
14141@@ -1213,7 +1165,7 @@ void __cpuinit cpu_init(void)
14142 switch_to_new_gdt(cpu);
14143 loadsegment(fs, 0);
14144
14145- load_idt((const struct desc_ptr *)&idt_descr);
14146+ load_idt(&idt_descr);
14147
14148 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14149 syscall_init();
14150@@ -1222,7 +1174,6 @@ void __cpuinit cpu_init(void)
14151 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14152 barrier();
14153
14154- x86_configure_nx();
14155 if (cpu != 0)
14156 enable_x2apic();
14157
14158@@ -1278,7 +1229,7 @@ void __cpuinit cpu_init(void)
14159 {
14160 int cpu = smp_processor_id();
14161 struct task_struct *curr = current;
14162- struct tss_struct *t = &per_cpu(init_tss, cpu);
14163+ struct tss_struct *t = init_tss + cpu;
14164 struct thread_struct *thread = &curr->thread;
14165
14166 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14167diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14168index 3e6ff6c..54b4992 100644
14169--- a/arch/x86/kernel/cpu/intel.c
14170+++ b/arch/x86/kernel/cpu/intel.c
14171@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14172 * Update the IDT descriptor and reload the IDT so that
14173 * it uses the read-only mapped virtual address.
14174 */
14175- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14176+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14177 load_idt(&idt_descr);
14178 }
14179 #endif
14180diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14181index da27c5d..569e359 100644
14182--- a/arch/x86/kernel/cpu/mcheck/mce.c
14183+++ b/arch/x86/kernel/cpu/mcheck/mce.c
14184@@ -42,6 +42,7 @@
14185 #include <asm/processor.h>
14186 #include <asm/mce.h>
14187 #include <asm/msr.h>
14188+#include <asm/local.h>
14189
14190 #include "mce-internal.h"
14191
14192@@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14193 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14194 m->cs, m->ip);
14195
14196- if (m->cs == __KERNEL_CS)
14197+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14198 print_symbol("{%s}", m->ip);
14199 pr_cont("\n");
14200 }
14201@@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14202
14203 #define PANIC_TIMEOUT 5 /* 5 seconds */
14204
14205-static atomic_t mce_paniced;
14206+static atomic_unchecked_t mce_paniced;
14207
14208 static int fake_panic;
14209-static atomic_t mce_fake_paniced;
14210+static atomic_unchecked_t mce_fake_paniced;
14211
14212 /* Panic in progress. Enable interrupts and wait for final IPI */
14213 static void wait_for_panic(void)
14214@@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14215 /*
14216 * Make sure only one CPU runs in machine check panic
14217 */
14218- if (atomic_inc_return(&mce_paniced) > 1)
14219+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14220 wait_for_panic();
14221 barrier();
14222
14223@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14224 console_verbose();
14225 } else {
14226 /* Don't log too much for fake panic */
14227- if (atomic_inc_return(&mce_fake_paniced) > 1)
14228+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14229 return;
14230 }
14231 /* First print corrected ones that are still unlogged */
14232@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
14233 * might have been modified by someone else.
14234 */
14235 rmb();
14236- if (atomic_read(&mce_paniced))
14237+ if (atomic_read_unchecked(&mce_paniced))
14238 wait_for_panic();
14239 if (!monarch_timeout)
14240 goto out;
14241@@ -1579,7 +1580,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14242 }
14243
14244 /* Call the installed machine check handler for this CPU setup. */
14245-void (*machine_check_vector)(struct pt_regs *, long error_code) =
14246+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14247 unexpected_machine_check;
14248
14249 /*
14250@@ -1602,7 +1603,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14251 return;
14252 }
14253
14254+ pax_open_kernel();
14255 machine_check_vector = do_machine_check;
14256+ pax_close_kernel();
14257
14258 __mcheck_cpu_init_generic();
14259 __mcheck_cpu_init_vendor(c);
14260@@ -1616,7 +1619,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14261 */
14262
14263 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14264-static int mce_chrdev_open_count; /* #times opened */
14265+static local_t mce_chrdev_open_count; /* #times opened */
14266 static int mce_chrdev_open_exclu; /* already open exclusive? */
14267
14268 static int mce_chrdev_open(struct inode *inode, struct file *file)
14269@@ -1624,7 +1627,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14270 spin_lock(&mce_chrdev_state_lock);
14271
14272 if (mce_chrdev_open_exclu ||
14273- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14274+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14275 spin_unlock(&mce_chrdev_state_lock);
14276
14277 return -EBUSY;
14278@@ -1632,7 +1635,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14279
14280 if (file->f_flags & O_EXCL)
14281 mce_chrdev_open_exclu = 1;
14282- mce_chrdev_open_count++;
14283+ local_inc(&mce_chrdev_open_count);
14284
14285 spin_unlock(&mce_chrdev_state_lock);
14286
14287@@ -1643,7 +1646,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14288 {
14289 spin_lock(&mce_chrdev_state_lock);
14290
14291- mce_chrdev_open_count--;
14292+ local_dec(&mce_chrdev_open_count);
14293 mce_chrdev_open_exclu = 0;
14294
14295 spin_unlock(&mce_chrdev_state_lock);
14296@@ -2368,7 +2371,7 @@ struct dentry *mce_get_debugfs_dir(void)
14297 static void mce_reset(void)
14298 {
14299 cpu_missing = 0;
14300- atomic_set(&mce_fake_paniced, 0);
14301+ atomic_set_unchecked(&mce_fake_paniced, 0);
14302 atomic_set(&mce_executing, 0);
14303 atomic_set(&mce_callin, 0);
14304 atomic_set(&global_nwo, 0);
14305diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14306index 2d5454c..51987eb 100644
14307--- a/arch/x86/kernel/cpu/mcheck/p5.c
14308+++ b/arch/x86/kernel/cpu/mcheck/p5.c
14309@@ -11,6 +11,7 @@
14310 #include <asm/processor.h>
14311 #include <asm/mce.h>
14312 #include <asm/msr.h>
14313+#include <asm/pgtable.h>
14314
14315 /* By default disabled */
14316 int mce_p5_enabled __read_mostly;
14317@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14318 if (!cpu_has(c, X86_FEATURE_MCE))
14319 return;
14320
14321+ pax_open_kernel();
14322 machine_check_vector = pentium_machine_check;
14323+ pax_close_kernel();
14324 /* Make sure the vector pointer is visible before we enable MCEs: */
14325 wmb();
14326
14327diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14328index 2d7998f..17c9de1 100644
14329--- a/arch/x86/kernel/cpu/mcheck/winchip.c
14330+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14331@@ -10,6 +10,7 @@
14332 #include <asm/processor.h>
14333 #include <asm/mce.h>
14334 #include <asm/msr.h>
14335+#include <asm/pgtable.h>
14336
14337 /* Machine check handler for WinChip C6: */
14338 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14339@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14340 {
14341 u32 lo, hi;
14342
14343+ pax_open_kernel();
14344 machine_check_vector = winchip_machine_check;
14345+ pax_close_kernel();
14346 /* Make sure the vector pointer is visible before we enable MCEs: */
14347 wmb();
14348
14349diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14350index 6b96110..0da73eb 100644
14351--- a/arch/x86/kernel/cpu/mtrr/main.c
14352+++ b/arch/x86/kernel/cpu/mtrr/main.c
14353@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14354 u64 size_or_mask, size_and_mask;
14355 static bool mtrr_aps_delayed_init;
14356
14357-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14358+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14359
14360 const struct mtrr_ops *mtrr_if;
14361
14362diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14363index df5e41f..816c719 100644
14364--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14365+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14366@@ -25,7 +25,7 @@ struct mtrr_ops {
14367 int (*validate_add_page)(unsigned long base, unsigned long size,
14368 unsigned int type);
14369 int (*have_wrcomb)(void);
14370-};
14371+} __do_const;
14372
14373 extern int generic_get_free_region(unsigned long base, unsigned long size,
14374 int replace_reg);
14375diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14376index c4706cf..264b0f7 100644
14377--- a/arch/x86/kernel/cpu/perf_event.c
14378+++ b/arch/x86/kernel/cpu/perf_event.c
14379@@ -1837,7 +1837,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14380 break;
14381
14382 perf_callchain_store(entry, frame.return_address);
14383- fp = frame.next_frame;
14384+ fp = (const void __force_user *)frame.next_frame;
14385 }
14386 }
14387
14388diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14389index 13ad899..f642b9a 100644
14390--- a/arch/x86/kernel/crash.c
14391+++ b/arch/x86/kernel/crash.c
14392@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14393 {
14394 #ifdef CONFIG_X86_32
14395 struct pt_regs fixed_regs;
14396-#endif
14397
14398-#ifdef CONFIG_X86_32
14399- if (!user_mode_vm(regs)) {
14400+ if (!user_mode(regs)) {
14401 crash_fixup_ss_esp(&fixed_regs, regs);
14402 regs = &fixed_regs;
14403 }
14404diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14405index 37250fe..bf2ec74 100644
14406--- a/arch/x86/kernel/doublefault_32.c
14407+++ b/arch/x86/kernel/doublefault_32.c
14408@@ -11,7 +11,7 @@
14409
14410 #define DOUBLEFAULT_STACKSIZE (1024)
14411 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14412-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14413+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14414
14415 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14416
14417@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14418 unsigned long gdt, tss;
14419
14420 store_gdt(&gdt_desc);
14421- gdt = gdt_desc.address;
14422+ gdt = (unsigned long)gdt_desc.address;
14423
14424 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14425
14426@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14427 /* 0x2 bit is always set */
14428 .flags = X86_EFLAGS_SF | 0x2,
14429 .sp = STACK_START,
14430- .es = __USER_DS,
14431+ .es = __KERNEL_DS,
14432 .cs = __KERNEL_CS,
14433 .ss = __KERNEL_DS,
14434- .ds = __USER_DS,
14435+ .ds = __KERNEL_DS,
14436 .fs = __KERNEL_PERCPU,
14437
14438 .__cr3 = __pa_nodebug(swapper_pg_dir),
14439diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14440index 571246d..81f335c 100644
14441--- a/arch/x86/kernel/dumpstack.c
14442+++ b/arch/x86/kernel/dumpstack.c
14443@@ -2,6 +2,9 @@
14444 * Copyright (C) 1991, 1992 Linus Torvalds
14445 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14446 */
14447+#ifdef CONFIG_GRKERNSEC_HIDESYM
14448+#define __INCLUDED_BY_HIDESYM 1
14449+#endif
14450 #include <linux/kallsyms.h>
14451 #include <linux/kprobes.h>
14452 #include <linux/uaccess.h>
14453@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14454 static void
14455 print_ftrace_graph_addr(unsigned long addr, void *data,
14456 const struct stacktrace_ops *ops,
14457- struct thread_info *tinfo, int *graph)
14458+ struct task_struct *task, int *graph)
14459 {
14460- struct task_struct *task;
14461 unsigned long ret_addr;
14462 int index;
14463
14464 if (addr != (unsigned long)return_to_handler)
14465 return;
14466
14467- task = tinfo->task;
14468 index = task->curr_ret_stack;
14469
14470 if (!task->ret_stack || index < *graph)
14471@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14472 static inline void
14473 print_ftrace_graph_addr(unsigned long addr, void *data,
14474 const struct stacktrace_ops *ops,
14475- struct thread_info *tinfo, int *graph)
14476+ struct task_struct *task, int *graph)
14477 { }
14478 #endif
14479
14480@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14481 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14482 */
14483
14484-static inline int valid_stack_ptr(struct thread_info *tinfo,
14485- void *p, unsigned int size, void *end)
14486+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14487 {
14488- void *t = tinfo;
14489 if (end) {
14490 if (p < end && p >= (end-THREAD_SIZE))
14491 return 1;
14492@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14493 }
14494
14495 unsigned long
14496-print_context_stack(struct thread_info *tinfo,
14497+print_context_stack(struct task_struct *task, void *stack_start,
14498 unsigned long *stack, unsigned long bp,
14499 const struct stacktrace_ops *ops, void *data,
14500 unsigned long *end, int *graph)
14501 {
14502 struct stack_frame *frame = (struct stack_frame *)bp;
14503
14504- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14505+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14506 unsigned long addr;
14507
14508 addr = *stack;
14509@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14510 } else {
14511 ops->address(data, addr, 0);
14512 }
14513- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14514+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14515 }
14516 stack++;
14517 }
14518@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14519 EXPORT_SYMBOL_GPL(print_context_stack);
14520
14521 unsigned long
14522-print_context_stack_bp(struct thread_info *tinfo,
14523+print_context_stack_bp(struct task_struct *task, void *stack_start,
14524 unsigned long *stack, unsigned long bp,
14525 const struct stacktrace_ops *ops, void *data,
14526 unsigned long *end, int *graph)
14527@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14528 struct stack_frame *frame = (struct stack_frame *)bp;
14529 unsigned long *ret_addr = &frame->return_address;
14530
14531- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14532+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14533 unsigned long addr = *ret_addr;
14534
14535 if (!__kernel_text_address(addr))
14536@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14537 ops->address(data, addr, 1);
14538 frame = frame->next_frame;
14539 ret_addr = &frame->return_address;
14540- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14541+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14542 }
14543
14544 return (unsigned long)frame;
14545@@ -189,7 +188,7 @@ void dump_stack(void)
14546
14547 bp = stack_frame(current, NULL);
14548 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14549- current->pid, current->comm, print_tainted(),
14550+ task_pid_nr(current), current->comm, print_tainted(),
14551 init_utsname()->release,
14552 (int)strcspn(init_utsname()->version, " "),
14553 init_utsname()->version);
14554@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14555 }
14556 EXPORT_SYMBOL_GPL(oops_begin);
14557
14558+extern void gr_handle_kernel_exploit(void);
14559+
14560 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14561 {
14562 if (regs && kexec_should_crash(current))
14563@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14564 panic("Fatal exception in interrupt");
14565 if (panic_on_oops)
14566 panic("Fatal exception");
14567- do_exit(signr);
14568+
14569+ gr_handle_kernel_exploit();
14570+
14571+ do_group_exit(signr);
14572 }
14573
14574 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14575@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14576
14577 show_regs(regs);
14578 #ifdef CONFIG_X86_32
14579- if (user_mode_vm(regs)) {
14580+ if (user_mode(regs)) {
14581 sp = regs->sp;
14582 ss = regs->ss & 0xffff;
14583 } else {
14584@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14585 unsigned long flags = oops_begin();
14586 int sig = SIGSEGV;
14587
14588- if (!user_mode_vm(regs))
14589+ if (!user_mode(regs))
14590 report_bug(regs->ip, regs);
14591
14592 if (__die(str, regs, err))
14593diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14594index e0b1d78..a8ade5e 100644
14595--- a/arch/x86/kernel/dumpstack_32.c
14596+++ b/arch/x86/kernel/dumpstack_32.c
14597@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14598 bp = stack_frame(task, regs);
14599
14600 for (;;) {
14601- struct thread_info *context;
14602+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14603
14604- context = (struct thread_info *)
14605- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14606- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14607+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14608
14609- stack = (unsigned long *)context->previous_esp;
14610- if (!stack)
14611+ if (stack_start == task_stack_page(task))
14612 break;
14613+ stack = *(unsigned long **)stack_start;
14614 if (ops->stack(data, "IRQ") < 0)
14615 break;
14616 touch_nmi_watchdog();
14617@@ -87,7 +85,7 @@ void show_regs(struct pt_regs *regs)
14618 int i;
14619
14620 print_modules();
14621- __show_regs(regs, !user_mode_vm(regs));
14622+ __show_regs(regs, !user_mode(regs));
14623
14624 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14625 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14626@@ -96,21 +94,22 @@ void show_regs(struct pt_regs *regs)
14627 * When in-kernel, we also print out the stack and code at the
14628 * time of the fault..
14629 */
14630- if (!user_mode_vm(regs)) {
14631+ if (!user_mode(regs)) {
14632 unsigned int code_prologue = code_bytes * 43 / 64;
14633 unsigned int code_len = code_bytes;
14634 unsigned char c;
14635 u8 *ip;
14636+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14637
14638 printk(KERN_EMERG "Stack:\n");
14639 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14640
14641 printk(KERN_EMERG "Code: ");
14642
14643- ip = (u8 *)regs->ip - code_prologue;
14644+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14645 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14646 /* try starting at IP */
14647- ip = (u8 *)regs->ip;
14648+ ip = (u8 *)regs->ip + cs_base;
14649 code_len = code_len - code_prologue + 1;
14650 }
14651 for (i = 0; i < code_len; i++, ip++) {
14652@@ -119,7 +118,7 @@ void show_regs(struct pt_regs *regs)
14653 printk(KERN_CONT " Bad EIP value.");
14654 break;
14655 }
14656- if (ip == (u8 *)regs->ip)
14657+ if (ip == (u8 *)regs->ip + cs_base)
14658 printk(KERN_CONT "<%02x> ", c);
14659 else
14660 printk(KERN_CONT "%02x ", c);
14661@@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14662 {
14663 unsigned short ud2;
14664
14665+ ip = ktla_ktva(ip);
14666 if (ip < PAGE_OFFSET)
14667 return 0;
14668 if (probe_kernel_address((unsigned short *)ip, ud2))
14669@@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14670
14671 return ud2 == 0x0b0f;
14672 }
14673+
14674+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14675+void pax_check_alloca(unsigned long size)
14676+{
14677+ unsigned long sp = (unsigned long)&sp, stack_left;
14678+
14679+ /* all kernel stacks are of the same size */
14680+ stack_left = sp & (THREAD_SIZE - 1);
14681+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14682+}
14683+EXPORT_SYMBOL(pax_check_alloca);
14684+#endif
14685diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14686index 791b761..2ab6e33 100644
14687--- a/arch/x86/kernel/dumpstack_64.c
14688+++ b/arch/x86/kernel/dumpstack_64.c
14689@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14690 unsigned long *irq_stack_end =
14691 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14692 unsigned used = 0;
14693- struct thread_info *tinfo;
14694 int graph = 0;
14695 unsigned long dummy;
14696+ void *stack_start;
14697
14698 if (!task)
14699 task = current;
14700@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14701 * current stack address. If the stacks consist of nested
14702 * exceptions
14703 */
14704- tinfo = task_thread_info(task);
14705 for (;;) {
14706 char *id;
14707 unsigned long *estack_end;
14708+
14709 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14710 &used, &id);
14711
14712@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14713 if (ops->stack(data, id) < 0)
14714 break;
14715
14716- bp = ops->walk_stack(tinfo, stack, bp, ops,
14717+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14718 data, estack_end, &graph);
14719 ops->stack(data, "<EOE>");
14720 /*
14721@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14722 * second-to-last pointer (index -2 to end) in the
14723 * exception stack:
14724 */
14725+ if ((u16)estack_end[-1] != __KERNEL_DS)
14726+ goto out;
14727 stack = (unsigned long *) estack_end[-2];
14728 continue;
14729 }
14730@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14731 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14732 if (ops->stack(data, "IRQ") < 0)
14733 break;
14734- bp = ops->walk_stack(tinfo, stack, bp,
14735+ bp = ops->walk_stack(task, irq_stack, stack, bp,
14736 ops, data, irq_stack_end, &graph);
14737 /*
14738 * We link to the next stack (which would be
14739@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14740 /*
14741 * This handles the process stack:
14742 */
14743- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14744+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14745+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14746+out:
14747 put_cpu();
14748 }
14749 EXPORT_SYMBOL(dump_trace);
14750@@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14751
14752 return ud2 == 0x0b0f;
14753 }
14754+
14755+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14756+void pax_check_alloca(unsigned long size)
14757+{
14758+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14759+ unsigned cpu, used;
14760+ char *id;
14761+
14762+ /* check the process stack first */
14763+ stack_start = (unsigned long)task_stack_page(current);
14764+ stack_end = stack_start + THREAD_SIZE;
14765+ if (likely(stack_start <= sp && sp < stack_end)) {
14766+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14767+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14768+ return;
14769+ }
14770+
14771+ cpu = get_cpu();
14772+
14773+ /* check the irq stacks */
14774+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14775+ stack_start = stack_end - IRQ_STACK_SIZE;
14776+ if (stack_start <= sp && sp < stack_end) {
14777+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14778+ put_cpu();
14779+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14780+ return;
14781+ }
14782+
14783+ /* check the exception stacks */
14784+ used = 0;
14785+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14786+ stack_start = stack_end - EXCEPTION_STKSZ;
14787+ if (stack_end && stack_start <= sp && sp < stack_end) {
14788+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14789+ put_cpu();
14790+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14791+ return;
14792+ }
14793+
14794+ put_cpu();
14795+
14796+ /* unknown stack */
14797+ BUG();
14798+}
14799+EXPORT_SYMBOL(pax_check_alloca);
14800+#endif
14801diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14802index 9b9f18b..9fcaa04 100644
14803--- a/arch/x86/kernel/early_printk.c
14804+++ b/arch/x86/kernel/early_printk.c
14805@@ -7,6 +7,7 @@
14806 #include <linux/pci_regs.h>
14807 #include <linux/pci_ids.h>
14808 #include <linux/errno.h>
14809+#include <linux/sched.h>
14810 #include <asm/io.h>
14811 #include <asm/processor.h>
14812 #include <asm/fcntl.h>
14813diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14814index 623f288..0683156 100644
14815--- a/arch/x86/kernel/entry_32.S
14816+++ b/arch/x86/kernel/entry_32.S
14817@@ -176,13 +176,146 @@
14818 /*CFI_REL_OFFSET gs, PT_GS*/
14819 .endm
14820 .macro SET_KERNEL_GS reg
14821+
14822+#ifdef CONFIG_CC_STACKPROTECTOR
14823 movl $(__KERNEL_STACK_CANARY), \reg
14824+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14825+ movl $(__USER_DS), \reg
14826+#else
14827+ xorl \reg, \reg
14828+#endif
14829+
14830 movl \reg, %gs
14831 .endm
14832
14833 #endif /* CONFIG_X86_32_LAZY_GS */
14834
14835-.macro SAVE_ALL
14836+.macro pax_enter_kernel
14837+#ifdef CONFIG_PAX_KERNEXEC
14838+ call pax_enter_kernel
14839+#endif
14840+.endm
14841+
14842+.macro pax_exit_kernel
14843+#ifdef CONFIG_PAX_KERNEXEC
14844+ call pax_exit_kernel
14845+#endif
14846+.endm
14847+
14848+#ifdef CONFIG_PAX_KERNEXEC
14849+ENTRY(pax_enter_kernel)
14850+#ifdef CONFIG_PARAVIRT
14851+ pushl %eax
14852+ pushl %ecx
14853+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14854+ mov %eax, %esi
14855+#else
14856+ mov %cr0, %esi
14857+#endif
14858+ bts $16, %esi
14859+ jnc 1f
14860+ mov %cs, %esi
14861+ cmp $__KERNEL_CS, %esi
14862+ jz 3f
14863+ ljmp $__KERNEL_CS, $3f
14864+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14865+2:
14866+#ifdef CONFIG_PARAVIRT
14867+ mov %esi, %eax
14868+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14869+#else
14870+ mov %esi, %cr0
14871+#endif
14872+3:
14873+#ifdef CONFIG_PARAVIRT
14874+ popl %ecx
14875+ popl %eax
14876+#endif
14877+ ret
14878+ENDPROC(pax_enter_kernel)
14879+
14880+ENTRY(pax_exit_kernel)
14881+#ifdef CONFIG_PARAVIRT
14882+ pushl %eax
14883+ pushl %ecx
14884+#endif
14885+ mov %cs, %esi
14886+ cmp $__KERNEXEC_KERNEL_CS, %esi
14887+ jnz 2f
14888+#ifdef CONFIG_PARAVIRT
14889+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14890+ mov %eax, %esi
14891+#else
14892+ mov %cr0, %esi
14893+#endif
14894+ btr $16, %esi
14895+ ljmp $__KERNEL_CS, $1f
14896+1:
14897+#ifdef CONFIG_PARAVIRT
14898+ mov %esi, %eax
14899+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14900+#else
14901+ mov %esi, %cr0
14902+#endif
14903+2:
14904+#ifdef CONFIG_PARAVIRT
14905+ popl %ecx
14906+ popl %eax
14907+#endif
14908+ ret
14909+ENDPROC(pax_exit_kernel)
14910+#endif
14911+
14912+.macro pax_erase_kstack
14913+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14914+ call pax_erase_kstack
14915+#endif
14916+.endm
14917+
14918+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14919+/*
14920+ * ebp: thread_info
14921+ * ecx, edx: can be clobbered
14922+ */
14923+ENTRY(pax_erase_kstack)
14924+ pushl %edi
14925+ pushl %eax
14926+
14927+ mov TI_lowest_stack(%ebp), %edi
14928+ mov $-0xBEEF, %eax
14929+ std
14930+
14931+1: mov %edi, %ecx
14932+ and $THREAD_SIZE_asm - 1, %ecx
14933+ shr $2, %ecx
14934+ repne scasl
14935+ jecxz 2f
14936+
14937+ cmp $2*16, %ecx
14938+ jc 2f
14939+
14940+ mov $2*16, %ecx
14941+ repe scasl
14942+ jecxz 2f
14943+ jne 1b
14944+
14945+2: cld
14946+ mov %esp, %ecx
14947+ sub %edi, %ecx
14948+ shr $2, %ecx
14949+ rep stosl
14950+
14951+ mov TI_task_thread_sp0(%ebp), %edi
14952+ sub $128, %edi
14953+ mov %edi, TI_lowest_stack(%ebp)
14954+
14955+ popl %eax
14956+ popl %edi
14957+ ret
14958+ENDPROC(pax_erase_kstack)
14959+#endif
14960+
14961+.macro __SAVE_ALL _DS
14962 cld
14963 PUSH_GS
14964 pushl_cfi %fs
14965@@ -205,7 +338,7 @@
14966 CFI_REL_OFFSET ecx, 0
14967 pushl_cfi %ebx
14968 CFI_REL_OFFSET ebx, 0
14969- movl $(__USER_DS), %edx
14970+ movl $\_DS, %edx
14971 movl %edx, %ds
14972 movl %edx, %es
14973 movl $(__KERNEL_PERCPU), %edx
14974@@ -213,6 +346,15 @@
14975 SET_KERNEL_GS %edx
14976 .endm
14977
14978+.macro SAVE_ALL
14979+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14980+ __SAVE_ALL __KERNEL_DS
14981+ pax_enter_kernel
14982+#else
14983+ __SAVE_ALL __USER_DS
14984+#endif
14985+.endm
14986+
14987 .macro RESTORE_INT_REGS
14988 popl_cfi %ebx
14989 CFI_RESTORE ebx
14990@@ -296,7 +438,7 @@ ENTRY(ret_from_fork)
14991 popfl_cfi
14992 jmp syscall_exit
14993 CFI_ENDPROC
14994-END(ret_from_fork)
14995+ENDPROC(ret_from_fork)
14996
14997 /*
14998 * Interrupt exit functions should be protected against kprobes
14999@@ -329,7 +471,15 @@ ret_from_intr:
15000 andl $SEGMENT_RPL_MASK, %eax
15001 #endif
15002 cmpl $USER_RPL, %eax
15003+
15004+#ifdef CONFIG_PAX_KERNEXEC
15005+ jae resume_userspace
15006+
15007+ pax_exit_kernel
15008+ jmp resume_kernel
15009+#else
15010 jb resume_kernel # not returning to v8086 or userspace
15011+#endif
15012
15013 ENTRY(resume_userspace)
15014 LOCKDEP_SYS_EXIT
15015@@ -341,8 +491,8 @@ ENTRY(resume_userspace)
15016 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15017 # int/exception return?
15018 jne work_pending
15019- jmp restore_all
15020-END(ret_from_exception)
15021+ jmp restore_all_pax
15022+ENDPROC(ret_from_exception)
15023
15024 #ifdef CONFIG_PREEMPT
15025 ENTRY(resume_kernel)
15026@@ -357,7 +507,7 @@ need_resched:
15027 jz restore_all
15028 call preempt_schedule_irq
15029 jmp need_resched
15030-END(resume_kernel)
15031+ENDPROC(resume_kernel)
15032 #endif
15033 CFI_ENDPROC
15034 /*
15035@@ -391,23 +541,34 @@ sysenter_past_esp:
15036 /*CFI_REL_OFFSET cs, 0*/
15037 /*
15038 * Push current_thread_info()->sysenter_return to the stack.
15039- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15040- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15041 */
15042- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15043+ pushl_cfi $0
15044 CFI_REL_OFFSET eip, 0
15045
15046 pushl_cfi %eax
15047 SAVE_ALL
15048+ GET_THREAD_INFO(%ebp)
15049+ movl TI_sysenter_return(%ebp),%ebp
15050+ movl %ebp,PT_EIP(%esp)
15051 ENABLE_INTERRUPTS(CLBR_NONE)
15052
15053 /*
15054 * Load the potential sixth argument from user stack.
15055 * Careful about security.
15056 */
15057+ movl PT_OLDESP(%esp),%ebp
15058+
15059+#ifdef CONFIG_PAX_MEMORY_UDEREF
15060+ mov PT_OLDSS(%esp),%ds
15061+1: movl %ds:(%ebp),%ebp
15062+ push %ss
15063+ pop %ds
15064+#else
15065 cmpl $__PAGE_OFFSET-3,%ebp
15066 jae syscall_fault
15067 1: movl (%ebp),%ebp
15068+#endif
15069+
15070 movl %ebp,PT_EBP(%esp)
15071 _ASM_EXTABLE(1b,syscall_fault)
15072
15073@@ -427,12 +588,24 @@ sysenter_do_call:
15074 testl $_TIF_ALLWORK_MASK, %ecx
15075 jne sysexit_audit
15076 sysenter_exit:
15077+
15078+#ifdef CONFIG_PAX_RANDKSTACK
15079+ pushl_cfi %eax
15080+ movl %esp, %eax
15081+ call pax_randomize_kstack
15082+ popl_cfi %eax
15083+#endif
15084+
15085+ pax_erase_kstack
15086+
15087 /* if something modifies registers it must also disable sysexit */
15088 movl PT_EIP(%esp), %edx
15089 movl PT_OLDESP(%esp), %ecx
15090 xorl %ebp,%ebp
15091 TRACE_IRQS_ON
15092 1: mov PT_FS(%esp), %fs
15093+2: mov PT_DS(%esp), %ds
15094+3: mov PT_ES(%esp), %es
15095 PTGS_TO_GS
15096 ENABLE_INTERRUPTS_SYSEXIT
15097
15098@@ -449,6 +622,9 @@ sysenter_audit:
15099 movl %eax,%edx /* 2nd arg: syscall number */
15100 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15101 call __audit_syscall_entry
15102+
15103+ pax_erase_kstack
15104+
15105 pushl_cfi %ebx
15106 movl PT_EAX(%esp),%eax /* reload syscall number */
15107 jmp sysenter_do_call
15108@@ -474,10 +650,16 @@ sysexit_audit:
15109
15110 CFI_ENDPROC
15111 .pushsection .fixup,"ax"
15112-2: movl $0,PT_FS(%esp)
15113+4: movl $0,PT_FS(%esp)
15114+ jmp 1b
15115+5: movl $0,PT_DS(%esp)
15116+ jmp 1b
15117+6: movl $0,PT_ES(%esp)
15118 jmp 1b
15119 .popsection
15120- _ASM_EXTABLE(1b,2b)
15121+ _ASM_EXTABLE(1b,4b)
15122+ _ASM_EXTABLE(2b,5b)
15123+ _ASM_EXTABLE(3b,6b)
15124 PTGS_TO_GS_EX
15125 ENDPROC(ia32_sysenter_target)
15126
15127@@ -509,6 +691,15 @@ syscall_exit:
15128 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15129 jne syscall_exit_work
15130
15131+restore_all_pax:
15132+
15133+#ifdef CONFIG_PAX_RANDKSTACK
15134+ movl %esp, %eax
15135+ call pax_randomize_kstack
15136+#endif
15137+
15138+ pax_erase_kstack
15139+
15140 restore_all:
15141 TRACE_IRQS_IRET
15142 restore_all_notrace:
15143@@ -565,14 +756,34 @@ ldt_ss:
15144 * compensating for the offset by changing to the ESPFIX segment with
15145 * a base address that matches for the difference.
15146 */
15147-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15148+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15149 mov %esp, %edx /* load kernel esp */
15150 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15151 mov %dx, %ax /* eax: new kernel esp */
15152 sub %eax, %edx /* offset (low word is 0) */
15153+#ifdef CONFIG_SMP
15154+ movl PER_CPU_VAR(cpu_number), %ebx
15155+ shll $PAGE_SHIFT_asm, %ebx
15156+ addl $cpu_gdt_table, %ebx
15157+#else
15158+ movl $cpu_gdt_table, %ebx
15159+#endif
15160 shr $16, %edx
15161- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15162- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15163+
15164+#ifdef CONFIG_PAX_KERNEXEC
15165+ mov %cr0, %esi
15166+ btr $16, %esi
15167+ mov %esi, %cr0
15168+#endif
15169+
15170+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15171+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15172+
15173+#ifdef CONFIG_PAX_KERNEXEC
15174+ bts $16, %esi
15175+ mov %esi, %cr0
15176+#endif
15177+
15178 pushl_cfi $__ESPFIX_SS
15179 pushl_cfi %eax /* new kernel esp */
15180 /* Disable interrupts, but do not irqtrace this section: we
15181@@ -601,35 +812,23 @@ work_resched:
15182 movl TI_flags(%ebp), %ecx
15183 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15184 # than syscall tracing?
15185- jz restore_all
15186+ jz restore_all_pax
15187 testb $_TIF_NEED_RESCHED, %cl
15188 jnz work_resched
15189
15190 work_notifysig: # deal with pending signals and
15191 # notify-resume requests
15192+ movl %esp, %eax
15193 #ifdef CONFIG_VM86
15194 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15195- movl %esp, %eax
15196- jne work_notifysig_v86 # returning to kernel-space or
15197+ jz 1f # returning to kernel-space or
15198 # vm86-space
15199- TRACE_IRQS_ON
15200- ENABLE_INTERRUPTS(CLBR_NONE)
15201- movb PT_CS(%esp), %bl
15202- andb $SEGMENT_RPL_MASK, %bl
15203- cmpb $USER_RPL, %bl
15204- jb resume_kernel
15205- xorl %edx, %edx
15206- call do_notify_resume
15207- jmp resume_userspace
15208
15209- ALIGN
15210-work_notifysig_v86:
15211 pushl_cfi %ecx # save ti_flags for do_notify_resume
15212 call save_v86_state # %eax contains pt_regs pointer
15213 popl_cfi %ecx
15214 movl %eax, %esp
15215-#else
15216- movl %esp, %eax
15217+1:
15218 #endif
15219 TRACE_IRQS_ON
15220 ENABLE_INTERRUPTS(CLBR_NONE)
15221@@ -640,7 +839,7 @@ work_notifysig_v86:
15222 xorl %edx, %edx
15223 call do_notify_resume
15224 jmp resume_userspace
15225-END(work_pending)
15226+ENDPROC(work_pending)
15227
15228 # perform syscall exit tracing
15229 ALIGN
15230@@ -648,11 +847,14 @@ syscall_trace_entry:
15231 movl $-ENOSYS,PT_EAX(%esp)
15232 movl %esp, %eax
15233 call syscall_trace_enter
15234+
15235+ pax_erase_kstack
15236+
15237 /* What it returned is what we'll actually use. */
15238 cmpl $(NR_syscalls), %eax
15239 jnae syscall_call
15240 jmp syscall_exit
15241-END(syscall_trace_entry)
15242+ENDPROC(syscall_trace_entry)
15243
15244 # perform syscall exit tracing
15245 ALIGN
15246@@ -665,20 +867,24 @@ syscall_exit_work:
15247 movl %esp, %eax
15248 call syscall_trace_leave
15249 jmp resume_userspace
15250-END(syscall_exit_work)
15251+ENDPROC(syscall_exit_work)
15252 CFI_ENDPROC
15253
15254 RING0_INT_FRAME # can't unwind into user space anyway
15255 syscall_fault:
15256+#ifdef CONFIG_PAX_MEMORY_UDEREF
15257+ push %ss
15258+ pop %ds
15259+#endif
15260 GET_THREAD_INFO(%ebp)
15261 movl $-EFAULT,PT_EAX(%esp)
15262 jmp resume_userspace
15263-END(syscall_fault)
15264+ENDPROC(syscall_fault)
15265
15266 syscall_badsys:
15267 movl $-ENOSYS,PT_EAX(%esp)
15268 jmp resume_userspace
15269-END(syscall_badsys)
15270+ENDPROC(syscall_badsys)
15271 CFI_ENDPROC
15272 /*
15273 * End of kprobes section
15274@@ -750,6 +956,36 @@ ENTRY(ptregs_clone)
15275 CFI_ENDPROC
15276 ENDPROC(ptregs_clone)
15277
15278+ ALIGN;
15279+ENTRY(kernel_execve)
15280+ CFI_STARTPROC
15281+ pushl_cfi %ebp
15282+ sub $PT_OLDSS+4,%esp
15283+ pushl_cfi %edi
15284+ pushl_cfi %ecx
15285+ pushl_cfi %eax
15286+ lea 3*4(%esp),%edi
15287+ mov $PT_OLDSS/4+1,%ecx
15288+ xorl %eax,%eax
15289+ rep stosl
15290+ popl_cfi %eax
15291+ popl_cfi %ecx
15292+ popl_cfi %edi
15293+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15294+ pushl_cfi %esp
15295+ call sys_execve
15296+ add $4,%esp
15297+ CFI_ADJUST_CFA_OFFSET -4
15298+ GET_THREAD_INFO(%ebp)
15299+ test %eax,%eax
15300+ jz syscall_exit
15301+ add $PT_OLDSS+4,%esp
15302+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15303+ popl_cfi %ebp
15304+ ret
15305+ CFI_ENDPROC
15306+ENDPROC(kernel_execve)
15307+
15308 .macro FIXUP_ESPFIX_STACK
15309 /*
15310 * Switch back for ESPFIX stack to the normal zerobased stack
15311@@ -759,8 +995,15 @@ ENDPROC(ptregs_clone)
15312 * normal stack and adjusts ESP with the matching offset.
15313 */
15314 /* fixup the stack */
15315- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15316- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15317+#ifdef CONFIG_SMP
15318+ movl PER_CPU_VAR(cpu_number), %ebx
15319+ shll $PAGE_SHIFT_asm, %ebx
15320+ addl $cpu_gdt_table, %ebx
15321+#else
15322+ movl $cpu_gdt_table, %ebx
15323+#endif
15324+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15325+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15326 shl $16, %eax
15327 addl %esp, %eax /* the adjusted stack pointer */
15328 pushl_cfi $__KERNEL_DS
15329@@ -813,7 +1056,7 @@ vector=vector+1
15330 .endr
15331 2: jmp common_interrupt
15332 .endr
15333-END(irq_entries_start)
15334+ENDPROC(irq_entries_start)
15335
15336 .previous
15337 END(interrupt)
15338@@ -861,7 +1104,7 @@ ENTRY(coprocessor_error)
15339 pushl_cfi $do_coprocessor_error
15340 jmp error_code
15341 CFI_ENDPROC
15342-END(coprocessor_error)
15343+ENDPROC(coprocessor_error)
15344
15345 ENTRY(simd_coprocessor_error)
15346 RING0_INT_FRAME
15347@@ -882,7 +1125,7 @@ ENTRY(simd_coprocessor_error)
15348 #endif
15349 jmp error_code
15350 CFI_ENDPROC
15351-END(simd_coprocessor_error)
15352+ENDPROC(simd_coprocessor_error)
15353
15354 ENTRY(device_not_available)
15355 RING0_INT_FRAME
15356@@ -890,18 +1133,18 @@ ENTRY(device_not_available)
15357 pushl_cfi $do_device_not_available
15358 jmp error_code
15359 CFI_ENDPROC
15360-END(device_not_available)
15361+ENDPROC(device_not_available)
15362
15363 #ifdef CONFIG_PARAVIRT
15364 ENTRY(native_iret)
15365 iret
15366 _ASM_EXTABLE(native_iret, iret_exc)
15367-END(native_iret)
15368+ENDPROC(native_iret)
15369
15370 ENTRY(native_irq_enable_sysexit)
15371 sti
15372 sysexit
15373-END(native_irq_enable_sysexit)
15374+ENDPROC(native_irq_enable_sysexit)
15375 #endif
15376
15377 ENTRY(overflow)
15378@@ -910,7 +1153,7 @@ ENTRY(overflow)
15379 pushl_cfi $do_overflow
15380 jmp error_code
15381 CFI_ENDPROC
15382-END(overflow)
15383+ENDPROC(overflow)
15384
15385 ENTRY(bounds)
15386 RING0_INT_FRAME
15387@@ -918,7 +1161,7 @@ ENTRY(bounds)
15388 pushl_cfi $do_bounds
15389 jmp error_code
15390 CFI_ENDPROC
15391-END(bounds)
15392+ENDPROC(bounds)
15393
15394 ENTRY(invalid_op)
15395 RING0_INT_FRAME
15396@@ -926,7 +1169,7 @@ ENTRY(invalid_op)
15397 pushl_cfi $do_invalid_op
15398 jmp error_code
15399 CFI_ENDPROC
15400-END(invalid_op)
15401+ENDPROC(invalid_op)
15402
15403 ENTRY(coprocessor_segment_overrun)
15404 RING0_INT_FRAME
15405@@ -934,35 +1177,35 @@ ENTRY(coprocessor_segment_overrun)
15406 pushl_cfi $do_coprocessor_segment_overrun
15407 jmp error_code
15408 CFI_ENDPROC
15409-END(coprocessor_segment_overrun)
15410+ENDPROC(coprocessor_segment_overrun)
15411
15412 ENTRY(invalid_TSS)
15413 RING0_EC_FRAME
15414 pushl_cfi $do_invalid_TSS
15415 jmp error_code
15416 CFI_ENDPROC
15417-END(invalid_TSS)
15418+ENDPROC(invalid_TSS)
15419
15420 ENTRY(segment_not_present)
15421 RING0_EC_FRAME
15422 pushl_cfi $do_segment_not_present
15423 jmp error_code
15424 CFI_ENDPROC
15425-END(segment_not_present)
15426+ENDPROC(segment_not_present)
15427
15428 ENTRY(stack_segment)
15429 RING0_EC_FRAME
15430 pushl_cfi $do_stack_segment
15431 jmp error_code
15432 CFI_ENDPROC
15433-END(stack_segment)
15434+ENDPROC(stack_segment)
15435
15436 ENTRY(alignment_check)
15437 RING0_EC_FRAME
15438 pushl_cfi $do_alignment_check
15439 jmp error_code
15440 CFI_ENDPROC
15441-END(alignment_check)
15442+ENDPROC(alignment_check)
15443
15444 ENTRY(divide_error)
15445 RING0_INT_FRAME
15446@@ -970,7 +1213,7 @@ ENTRY(divide_error)
15447 pushl_cfi $do_divide_error
15448 jmp error_code
15449 CFI_ENDPROC
15450-END(divide_error)
15451+ENDPROC(divide_error)
15452
15453 #ifdef CONFIG_X86_MCE
15454 ENTRY(machine_check)
15455@@ -979,7 +1222,7 @@ ENTRY(machine_check)
15456 pushl_cfi machine_check_vector
15457 jmp error_code
15458 CFI_ENDPROC
15459-END(machine_check)
15460+ENDPROC(machine_check)
15461 #endif
15462
15463 ENTRY(spurious_interrupt_bug)
15464@@ -988,7 +1231,7 @@ ENTRY(spurious_interrupt_bug)
15465 pushl_cfi $do_spurious_interrupt_bug
15466 jmp error_code
15467 CFI_ENDPROC
15468-END(spurious_interrupt_bug)
15469+ENDPROC(spurious_interrupt_bug)
15470 /*
15471 * End of kprobes section
15472 */
15473@@ -1100,7 +1343,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15474
15475 ENTRY(mcount)
15476 ret
15477-END(mcount)
15478+ENDPROC(mcount)
15479
15480 ENTRY(ftrace_caller)
15481 cmpl $0, function_trace_stop
15482@@ -1129,7 +1372,7 @@ ftrace_graph_call:
15483 .globl ftrace_stub
15484 ftrace_stub:
15485 ret
15486-END(ftrace_caller)
15487+ENDPROC(ftrace_caller)
15488
15489 #else /* ! CONFIG_DYNAMIC_FTRACE */
15490
15491@@ -1165,7 +1408,7 @@ trace:
15492 popl %ecx
15493 popl %eax
15494 jmp ftrace_stub
15495-END(mcount)
15496+ENDPROC(mcount)
15497 #endif /* CONFIG_DYNAMIC_FTRACE */
15498 #endif /* CONFIG_FUNCTION_TRACER */
15499
15500@@ -1186,7 +1429,7 @@ ENTRY(ftrace_graph_caller)
15501 popl %ecx
15502 popl %eax
15503 ret
15504-END(ftrace_graph_caller)
15505+ENDPROC(ftrace_graph_caller)
15506
15507 .globl return_to_handler
15508 return_to_handler:
15509@@ -1241,15 +1484,18 @@ error_code:
15510 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15511 REG_TO_PTGS %ecx
15512 SET_KERNEL_GS %ecx
15513- movl $(__USER_DS), %ecx
15514+ movl $(__KERNEL_DS), %ecx
15515 movl %ecx, %ds
15516 movl %ecx, %es
15517+
15518+ pax_enter_kernel
15519+
15520 TRACE_IRQS_OFF
15521 movl %esp,%eax # pt_regs pointer
15522 call *%edi
15523 jmp ret_from_exception
15524 CFI_ENDPROC
15525-END(page_fault)
15526+ENDPROC(page_fault)
15527
15528 /*
15529 * Debug traps and NMI can happen at the one SYSENTER instruction
15530@@ -1291,7 +1537,7 @@ debug_stack_correct:
15531 call do_debug
15532 jmp ret_from_exception
15533 CFI_ENDPROC
15534-END(debug)
15535+ENDPROC(debug)
15536
15537 /*
15538 * NMI is doubly nasty. It can happen _while_ we're handling
15539@@ -1328,6 +1574,9 @@ nmi_stack_correct:
15540 xorl %edx,%edx # zero error code
15541 movl %esp,%eax # pt_regs pointer
15542 call do_nmi
15543+
15544+ pax_exit_kernel
15545+
15546 jmp restore_all_notrace
15547 CFI_ENDPROC
15548
15549@@ -1364,12 +1613,15 @@ nmi_espfix_stack:
15550 FIXUP_ESPFIX_STACK # %eax == %esp
15551 xorl %edx,%edx # zero error code
15552 call do_nmi
15553+
15554+ pax_exit_kernel
15555+
15556 RESTORE_REGS
15557 lss 12+4(%esp), %esp # back to espfix stack
15558 CFI_ADJUST_CFA_OFFSET -24
15559 jmp irq_return
15560 CFI_ENDPROC
15561-END(nmi)
15562+ENDPROC(nmi)
15563
15564 ENTRY(int3)
15565 RING0_INT_FRAME
15566@@ -1381,14 +1633,14 @@ ENTRY(int3)
15567 call do_int3
15568 jmp ret_from_exception
15569 CFI_ENDPROC
15570-END(int3)
15571+ENDPROC(int3)
15572
15573 ENTRY(general_protection)
15574 RING0_EC_FRAME
15575 pushl_cfi $do_general_protection
15576 jmp error_code
15577 CFI_ENDPROC
15578-END(general_protection)
15579+ENDPROC(general_protection)
15580
15581 #ifdef CONFIG_KVM_GUEST
15582 ENTRY(async_page_fault)
15583@@ -1396,7 +1648,7 @@ ENTRY(async_page_fault)
15584 pushl_cfi $do_async_page_fault
15585 jmp error_code
15586 CFI_ENDPROC
15587-END(async_page_fault)
15588+ENDPROC(async_page_fault)
15589 #endif
15590
15591 /*
15592diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15593index 7d65133..27bce5b 100644
15594--- a/arch/x86/kernel/entry_64.S
15595+++ b/arch/x86/kernel/entry_64.S
15596@@ -57,6 +57,8 @@
15597 #include <asm/percpu.h>
15598 #include <asm/asm.h>
15599 #include <linux/err.h>
15600+#include <asm/pgtable.h>
15601+#include <asm/alternative-asm.h>
15602
15603 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15604 #include <linux/elf-em.h>
15605@@ -70,8 +72,9 @@
15606 #ifdef CONFIG_FUNCTION_TRACER
15607 #ifdef CONFIG_DYNAMIC_FTRACE
15608 ENTRY(mcount)
15609+ pax_force_retaddr
15610 retq
15611-END(mcount)
15612+ENDPROC(mcount)
15613
15614 ENTRY(ftrace_caller)
15615 cmpl $0, function_trace_stop
15616@@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15617 #endif
15618
15619 GLOBAL(ftrace_stub)
15620+ pax_force_retaddr
15621 retq
15622-END(ftrace_caller)
15623+ENDPROC(ftrace_caller)
15624
15625 #else /* ! CONFIG_DYNAMIC_FTRACE */
15626 ENTRY(mcount)
15627@@ -114,6 +118,7 @@ ENTRY(mcount)
15628 #endif
15629
15630 GLOBAL(ftrace_stub)
15631+ pax_force_retaddr
15632 retq
15633
15634 trace:
15635@@ -123,12 +128,13 @@ trace:
15636 movq 8(%rbp), %rsi
15637 subq $MCOUNT_INSN_SIZE, %rdi
15638
15639+ pax_force_fptr ftrace_trace_function
15640 call *ftrace_trace_function
15641
15642 MCOUNT_RESTORE_FRAME
15643
15644 jmp ftrace_stub
15645-END(mcount)
15646+ENDPROC(mcount)
15647 #endif /* CONFIG_DYNAMIC_FTRACE */
15648 #endif /* CONFIG_FUNCTION_TRACER */
15649
15650@@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15651
15652 MCOUNT_RESTORE_FRAME
15653
15654+ pax_force_retaddr
15655 retq
15656-END(ftrace_graph_caller)
15657+ENDPROC(ftrace_graph_caller)
15658
15659 GLOBAL(return_to_handler)
15660 subq $24, %rsp
15661@@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15662 movq 8(%rsp), %rdx
15663 movq (%rsp), %rax
15664 addq $24, %rsp
15665+ pax_force_fptr %rdi
15666 jmp *%rdi
15667 #endif
15668
15669@@ -180,6 +188,282 @@ ENTRY(native_usergs_sysret64)
15670 ENDPROC(native_usergs_sysret64)
15671 #endif /* CONFIG_PARAVIRT */
15672
15673+ .macro ljmpq sel, off
15674+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15675+ .byte 0x48; ljmp *1234f(%rip)
15676+ .pushsection .rodata
15677+ .align 16
15678+ 1234: .quad \off; .word \sel
15679+ .popsection
15680+#else
15681+ pushq $\sel
15682+ pushq $\off
15683+ lretq
15684+#endif
15685+ .endm
15686+
15687+ .macro pax_enter_kernel
15688+ pax_set_fptr_mask
15689+#ifdef CONFIG_PAX_KERNEXEC
15690+ call pax_enter_kernel
15691+#endif
15692+ .endm
15693+
15694+ .macro pax_exit_kernel
15695+#ifdef CONFIG_PAX_KERNEXEC
15696+ call pax_exit_kernel
15697+#endif
15698+ .endm
15699+
15700+#ifdef CONFIG_PAX_KERNEXEC
15701+ENTRY(pax_enter_kernel)
15702+ pushq %rdi
15703+
15704+#ifdef CONFIG_PARAVIRT
15705+ PV_SAVE_REGS(CLBR_RDI)
15706+#endif
15707+
15708+ GET_CR0_INTO_RDI
15709+ bts $16,%rdi
15710+ jnc 3f
15711+ mov %cs,%edi
15712+ cmp $__KERNEL_CS,%edi
15713+ jnz 2f
15714+1:
15715+
15716+#ifdef CONFIG_PARAVIRT
15717+ PV_RESTORE_REGS(CLBR_RDI)
15718+#endif
15719+
15720+ popq %rdi
15721+ pax_force_retaddr
15722+ retq
15723+
15724+2: ljmpq __KERNEL_CS,1f
15725+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15726+4: SET_RDI_INTO_CR0
15727+ jmp 1b
15728+ENDPROC(pax_enter_kernel)
15729+
15730+ENTRY(pax_exit_kernel)
15731+ pushq %rdi
15732+
15733+#ifdef CONFIG_PARAVIRT
15734+ PV_SAVE_REGS(CLBR_RDI)
15735+#endif
15736+
15737+ mov %cs,%rdi
15738+ cmp $__KERNEXEC_KERNEL_CS,%edi
15739+ jz 2f
15740+1:
15741+
15742+#ifdef CONFIG_PARAVIRT
15743+ PV_RESTORE_REGS(CLBR_RDI);
15744+#endif
15745+
15746+ popq %rdi
15747+ pax_force_retaddr
15748+ retq
15749+
15750+2: GET_CR0_INTO_RDI
15751+ btr $16,%rdi
15752+ ljmpq __KERNEL_CS,3f
15753+3: SET_RDI_INTO_CR0
15754+ jmp 1b
15755+#ifdef CONFIG_PARAVIRT
15756+ PV_RESTORE_REGS(CLBR_RDI);
15757+#endif
15758+
15759+ popq %rdi
15760+ pax_force_retaddr
15761+ retq
15762+ENDPROC(pax_exit_kernel)
15763+#endif
15764+
15765+ .macro pax_enter_kernel_user
15766+ pax_set_fptr_mask
15767+#ifdef CONFIG_PAX_MEMORY_UDEREF
15768+ call pax_enter_kernel_user
15769+#endif
15770+ .endm
15771+
15772+ .macro pax_exit_kernel_user
15773+#ifdef CONFIG_PAX_MEMORY_UDEREF
15774+ call pax_exit_kernel_user
15775+#endif
15776+#ifdef CONFIG_PAX_RANDKSTACK
15777+ pushq %rax
15778+ call pax_randomize_kstack
15779+ popq %rax
15780+#endif
15781+ .endm
15782+
15783+#ifdef CONFIG_PAX_MEMORY_UDEREF
15784+ENTRY(pax_enter_kernel_user)
15785+ pushq %rdi
15786+ pushq %rbx
15787+
15788+#ifdef CONFIG_PARAVIRT
15789+ PV_SAVE_REGS(CLBR_RDI)
15790+#endif
15791+
15792+ GET_CR3_INTO_RDI
15793+ mov %rdi,%rbx
15794+ add $__START_KERNEL_map,%rbx
15795+ sub phys_base(%rip),%rbx
15796+
15797+#ifdef CONFIG_PARAVIRT
15798+ pushq %rdi
15799+ cmpl $0, pv_info+PARAVIRT_enabled
15800+ jz 1f
15801+ i = 0
15802+ .rept USER_PGD_PTRS
15803+ mov i*8(%rbx),%rsi
15804+ mov $0,%sil
15805+ lea i*8(%rbx),%rdi
15806+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15807+ i = i + 1
15808+ .endr
15809+ jmp 2f
15810+1:
15811+#endif
15812+
15813+ i = 0
15814+ .rept USER_PGD_PTRS
15815+ movb $0,i*8(%rbx)
15816+ i = i + 1
15817+ .endr
15818+
15819+#ifdef CONFIG_PARAVIRT
15820+2: popq %rdi
15821+#endif
15822+ SET_RDI_INTO_CR3
15823+
15824+#ifdef CONFIG_PAX_KERNEXEC
15825+ GET_CR0_INTO_RDI
15826+ bts $16,%rdi
15827+ SET_RDI_INTO_CR0
15828+#endif
15829+
15830+#ifdef CONFIG_PARAVIRT
15831+ PV_RESTORE_REGS(CLBR_RDI)
15832+#endif
15833+
15834+ popq %rbx
15835+ popq %rdi
15836+ pax_force_retaddr
15837+ retq
15838+ENDPROC(pax_enter_kernel_user)
15839+
15840+ENTRY(pax_exit_kernel_user)
15841+ push %rdi
15842+
15843+#ifdef CONFIG_PARAVIRT
15844+ pushq %rbx
15845+ PV_SAVE_REGS(CLBR_RDI)
15846+#endif
15847+
15848+#ifdef CONFIG_PAX_KERNEXEC
15849+ GET_CR0_INTO_RDI
15850+ btr $16,%rdi
15851+ SET_RDI_INTO_CR0
15852+#endif
15853+
15854+ GET_CR3_INTO_RDI
15855+ add $__START_KERNEL_map,%rdi
15856+ sub phys_base(%rip),%rdi
15857+
15858+#ifdef CONFIG_PARAVIRT
15859+ cmpl $0, pv_info+PARAVIRT_enabled
15860+ jz 1f
15861+ mov %rdi,%rbx
15862+ i = 0
15863+ .rept USER_PGD_PTRS
15864+ mov i*8(%rbx),%rsi
15865+ mov $0x67,%sil
15866+ lea i*8(%rbx),%rdi
15867+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15868+ i = i + 1
15869+ .endr
15870+ jmp 2f
15871+1:
15872+#endif
15873+
15874+ i = 0
15875+ .rept USER_PGD_PTRS
15876+ movb $0x67,i*8(%rdi)
15877+ i = i + 1
15878+ .endr
15879+
15880+#ifdef CONFIG_PARAVIRT
15881+2: PV_RESTORE_REGS(CLBR_RDI)
15882+ popq %rbx
15883+#endif
15884+
15885+ popq %rdi
15886+ pax_force_retaddr
15887+ retq
15888+ENDPROC(pax_exit_kernel_user)
15889+#endif
15890+
15891+.macro pax_erase_kstack
15892+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15893+ call pax_erase_kstack
15894+#endif
15895+.endm
15896+
15897+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15898+/*
15899+ * r11: thread_info
15900+ * rcx, rdx: can be clobbered
15901+ */
15902+ENTRY(pax_erase_kstack)
15903+ pushq %rdi
15904+ pushq %rax
15905+ pushq %r11
15906+
15907+ GET_THREAD_INFO(%r11)
15908+ mov TI_lowest_stack(%r11), %rdi
15909+ mov $-0xBEEF, %rax
15910+ std
15911+
15912+1: mov %edi, %ecx
15913+ and $THREAD_SIZE_asm - 1, %ecx
15914+ shr $3, %ecx
15915+ repne scasq
15916+ jecxz 2f
15917+
15918+ cmp $2*8, %ecx
15919+ jc 2f
15920+
15921+ mov $2*8, %ecx
15922+ repe scasq
15923+ jecxz 2f
15924+ jne 1b
15925+
15926+2: cld
15927+ mov %esp, %ecx
15928+ sub %edi, %ecx
15929+
15930+ cmp $THREAD_SIZE_asm, %rcx
15931+ jb 3f
15932+ ud2
15933+3:
15934+
15935+ shr $3, %ecx
15936+ rep stosq
15937+
15938+ mov TI_task_thread_sp0(%r11), %rdi
15939+ sub $256, %rdi
15940+ mov %rdi, TI_lowest_stack(%r11)
15941+
15942+ popq %r11
15943+ popq %rax
15944+ popq %rdi
15945+ pax_force_retaddr
15946+ ret
15947+ENDPROC(pax_erase_kstack)
15948+#endif
15949
15950 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15951 #ifdef CONFIG_TRACE_IRQFLAGS
15952@@ -271,8 +555,8 @@ ENDPROC(native_usergs_sysret64)
15953 .endm
15954
15955 .macro UNFAKE_STACK_FRAME
15956- addq $8*6, %rsp
15957- CFI_ADJUST_CFA_OFFSET -(6*8)
15958+ addq $8*6 + ARG_SKIP, %rsp
15959+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15960 .endm
15961
15962 /*
15963@@ -359,7 +643,7 @@ ENDPROC(native_usergs_sysret64)
15964 movq %rsp, %rsi
15965
15966 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15967- testl $3, CS-RBP(%rsi)
15968+ testb $3, CS-RBP(%rsi)
15969 je 1f
15970 SWAPGS
15971 /*
15972@@ -394,9 +678,10 @@ ENTRY(save_rest)
15973 movq_cfi r15, R15+16
15974 movq %r11, 8(%rsp) /* return address */
15975 FIXUP_TOP_OF_STACK %r11, 16
15976+ pax_force_retaddr
15977 ret
15978 CFI_ENDPROC
15979-END(save_rest)
15980+ENDPROC(save_rest)
15981
15982 /* save complete stack frame */
15983 .pushsection .kprobes.text, "ax"
15984@@ -425,9 +710,10 @@ ENTRY(save_paranoid)
15985 js 1f /* negative -> in kernel */
15986 SWAPGS
15987 xorl %ebx,%ebx
15988-1: ret
15989+1: pax_force_retaddr_bts
15990+ ret
15991 CFI_ENDPROC
15992-END(save_paranoid)
15993+ENDPROC(save_paranoid)
15994 .popsection
15995
15996 /*
15997@@ -449,7 +735,7 @@ ENTRY(ret_from_fork)
15998
15999 RESTORE_REST
16000
16001- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16002+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16003 jz retint_restore_args
16004
16005 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16006@@ -459,7 +745,7 @@ ENTRY(ret_from_fork)
16007 jmp ret_from_sys_call # go to the SYSRET fastpath
16008
16009 CFI_ENDPROC
16010-END(ret_from_fork)
16011+ENDPROC(ret_from_fork)
16012
16013 /*
16014 * System call entry. Up to 6 arguments in registers are supported.
16015@@ -495,7 +781,7 @@ END(ret_from_fork)
16016 ENTRY(system_call)
16017 CFI_STARTPROC simple
16018 CFI_SIGNAL_FRAME
16019- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16020+ CFI_DEF_CFA rsp,0
16021 CFI_REGISTER rip,rcx
16022 /*CFI_REGISTER rflags,r11*/
16023 SWAPGS_UNSAFE_STACK
16024@@ -508,16 +794,18 @@ GLOBAL(system_call_after_swapgs)
16025
16026 movq %rsp,PER_CPU_VAR(old_rsp)
16027 movq PER_CPU_VAR(kernel_stack),%rsp
16028+ SAVE_ARGS 8*6,0
16029+ pax_enter_kernel_user
16030 /*
16031 * No need to follow this irqs off/on section - it's straight
16032 * and short:
16033 */
16034 ENABLE_INTERRUPTS(CLBR_NONE)
16035- SAVE_ARGS 8,0
16036 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16037 movq %rcx,RIP-ARGOFFSET(%rsp)
16038 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16039- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16040+ GET_THREAD_INFO(%rcx)
16041+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16042 jnz tracesys
16043 system_call_fastpath:
16044 #if __SYSCALL_MASK == ~0
16045@@ -527,7 +815,7 @@ system_call_fastpath:
16046 cmpl $__NR_syscall_max,%eax
16047 #endif
16048 ja badsys
16049- movq %r10,%rcx
16050+ movq R10-ARGOFFSET(%rsp),%rcx
16051 call *sys_call_table(,%rax,8) # XXX: rip relative
16052 movq %rax,RAX-ARGOFFSET(%rsp)
16053 /*
16054@@ -541,10 +829,13 @@ sysret_check:
16055 LOCKDEP_SYS_EXIT
16056 DISABLE_INTERRUPTS(CLBR_NONE)
16057 TRACE_IRQS_OFF
16058- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16059+ GET_THREAD_INFO(%rcx)
16060+ movl TI_flags(%rcx),%edx
16061 andl %edi,%edx
16062 jnz sysret_careful
16063 CFI_REMEMBER_STATE
16064+ pax_exit_kernel_user
16065+ pax_erase_kstack
16066 /*
16067 * sysretq will re-enable interrupts:
16068 */
16069@@ -596,14 +887,18 @@ badsys:
16070 * jump back to the normal fast path.
16071 */
16072 auditsys:
16073- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16074+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16075 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16076 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16077 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16078 movq %rax,%rsi /* 2nd arg: syscall number */
16079 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16080 call __audit_syscall_entry
16081+
16082+ pax_erase_kstack
16083+
16084 LOAD_ARGS 0 /* reload call-clobbered registers */
16085+ pax_set_fptr_mask
16086 jmp system_call_fastpath
16087
16088 /*
16089@@ -624,7 +919,7 @@ sysret_audit:
16090 /* Do syscall tracing */
16091 tracesys:
16092 #ifdef CONFIG_AUDITSYSCALL
16093- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16094+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16095 jz auditsys
16096 #endif
16097 SAVE_REST
16098@@ -632,12 +927,16 @@ tracesys:
16099 FIXUP_TOP_OF_STACK %rdi
16100 movq %rsp,%rdi
16101 call syscall_trace_enter
16102+
16103+ pax_erase_kstack
16104+
16105 /*
16106 * Reload arg registers from stack in case ptrace changed them.
16107 * We don't reload %rax because syscall_trace_enter() returned
16108 * the value it wants us to use in the table lookup.
16109 */
16110 LOAD_ARGS ARGOFFSET, 1
16111+ pax_set_fptr_mask
16112 RESTORE_REST
16113 #if __SYSCALL_MASK == ~0
16114 cmpq $__NR_syscall_max,%rax
16115@@ -646,7 +945,7 @@ tracesys:
16116 cmpl $__NR_syscall_max,%eax
16117 #endif
16118 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16119- movq %r10,%rcx /* fixup for C */
16120+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16121 call *sys_call_table(,%rax,8)
16122 movq %rax,RAX-ARGOFFSET(%rsp)
16123 /* Use IRET because user could have changed frame */
16124@@ -667,6 +966,7 @@ GLOBAL(int_with_check)
16125 andl %edi,%edx
16126 jnz int_careful
16127 andl $~TS_COMPAT,TI_status(%rcx)
16128+ pax_erase_kstack
16129 jmp retint_swapgs
16130
16131 /* Either reschedule or signal or syscall exit tracking needed. */
16132@@ -713,7 +1013,7 @@ int_restore_rest:
16133 TRACE_IRQS_OFF
16134 jmp int_with_check
16135 CFI_ENDPROC
16136-END(system_call)
16137+ENDPROC(system_call)
16138
16139 /*
16140 * Certain special system calls that need to save a complete full stack frame.
16141@@ -729,7 +1029,7 @@ ENTRY(\label)
16142 call \func
16143 jmp ptregscall_common
16144 CFI_ENDPROC
16145-END(\label)
16146+ENDPROC(\label)
16147 .endm
16148
16149 PTREGSCALL stub_clone, sys_clone, %r8
16150@@ -747,9 +1047,10 @@ ENTRY(ptregscall_common)
16151 movq_cfi_restore R12+8, r12
16152 movq_cfi_restore RBP+8, rbp
16153 movq_cfi_restore RBX+8, rbx
16154+ pax_force_retaddr
16155 ret $REST_SKIP /* pop extended registers */
16156 CFI_ENDPROC
16157-END(ptregscall_common)
16158+ENDPROC(ptregscall_common)
16159
16160 ENTRY(stub_execve)
16161 CFI_STARTPROC
16162@@ -764,7 +1065,7 @@ ENTRY(stub_execve)
16163 RESTORE_REST
16164 jmp int_ret_from_sys_call
16165 CFI_ENDPROC
16166-END(stub_execve)
16167+ENDPROC(stub_execve)
16168
16169 /*
16170 * sigreturn is special because it needs to restore all registers on return.
16171@@ -782,7 +1083,7 @@ ENTRY(stub_rt_sigreturn)
16172 RESTORE_REST
16173 jmp int_ret_from_sys_call
16174 CFI_ENDPROC
16175-END(stub_rt_sigreturn)
16176+ENDPROC(stub_rt_sigreturn)
16177
16178 #ifdef CONFIG_X86_X32_ABI
16179 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16180@@ -851,7 +1152,7 @@ vector=vector+1
16181 2: jmp common_interrupt
16182 .endr
16183 CFI_ENDPROC
16184-END(irq_entries_start)
16185+ENDPROC(irq_entries_start)
16186
16187 .previous
16188 END(interrupt)
16189@@ -871,6 +1172,16 @@ END(interrupt)
16190 subq $ORIG_RAX-RBP, %rsp
16191 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16192 SAVE_ARGS_IRQ
16193+#ifdef CONFIG_PAX_MEMORY_UDEREF
16194+ testb $3, CS(%rdi)
16195+ jnz 1f
16196+ pax_enter_kernel
16197+ jmp 2f
16198+1: pax_enter_kernel_user
16199+2:
16200+#else
16201+ pax_enter_kernel
16202+#endif
16203 call \func
16204 .endm
16205
16206@@ -902,7 +1213,7 @@ ret_from_intr:
16207
16208 exit_intr:
16209 GET_THREAD_INFO(%rcx)
16210- testl $3,CS-ARGOFFSET(%rsp)
16211+ testb $3,CS-ARGOFFSET(%rsp)
16212 je retint_kernel
16213
16214 /* Interrupt came from user space */
16215@@ -924,12 +1235,15 @@ retint_swapgs: /* return to user-space */
16216 * The iretq could re-enable interrupts:
16217 */
16218 DISABLE_INTERRUPTS(CLBR_ANY)
16219+ pax_exit_kernel_user
16220 TRACE_IRQS_IRETQ
16221 SWAPGS
16222 jmp restore_args
16223
16224 retint_restore_args: /* return to kernel space */
16225 DISABLE_INTERRUPTS(CLBR_ANY)
16226+ pax_exit_kernel
16227+ pax_force_retaddr RIP-ARGOFFSET
16228 /*
16229 * The iretq could re-enable interrupts:
16230 */
16231@@ -1012,7 +1326,7 @@ ENTRY(retint_kernel)
16232 #endif
16233
16234 CFI_ENDPROC
16235-END(common_interrupt)
16236+ENDPROC(common_interrupt)
16237 /*
16238 * End of kprobes section
16239 */
16240@@ -1029,7 +1343,7 @@ ENTRY(\sym)
16241 interrupt \do_sym
16242 jmp ret_from_intr
16243 CFI_ENDPROC
16244-END(\sym)
16245+ENDPROC(\sym)
16246 .endm
16247
16248 #ifdef CONFIG_SMP
16249@@ -1102,12 +1416,22 @@ ENTRY(\sym)
16250 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16251 call error_entry
16252 DEFAULT_FRAME 0
16253+#ifdef CONFIG_PAX_MEMORY_UDEREF
16254+ testb $3, CS(%rsp)
16255+ jnz 1f
16256+ pax_enter_kernel
16257+ jmp 2f
16258+1: pax_enter_kernel_user
16259+2:
16260+#else
16261+ pax_enter_kernel
16262+#endif
16263 movq %rsp,%rdi /* pt_regs pointer */
16264 xorl %esi,%esi /* no error code */
16265 call \do_sym
16266 jmp error_exit /* %ebx: no swapgs flag */
16267 CFI_ENDPROC
16268-END(\sym)
16269+ENDPROC(\sym)
16270 .endm
16271
16272 .macro paranoidzeroentry sym do_sym
16273@@ -1119,15 +1443,25 @@ ENTRY(\sym)
16274 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16275 call save_paranoid
16276 TRACE_IRQS_OFF
16277+#ifdef CONFIG_PAX_MEMORY_UDEREF
16278+ testb $3, CS(%rsp)
16279+ jnz 1f
16280+ pax_enter_kernel
16281+ jmp 2f
16282+1: pax_enter_kernel_user
16283+2:
16284+#else
16285+ pax_enter_kernel
16286+#endif
16287 movq %rsp,%rdi /* pt_regs pointer */
16288 xorl %esi,%esi /* no error code */
16289 call \do_sym
16290 jmp paranoid_exit /* %ebx: no swapgs flag */
16291 CFI_ENDPROC
16292-END(\sym)
16293+ENDPROC(\sym)
16294 .endm
16295
16296-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16297+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16298 .macro paranoidzeroentry_ist sym do_sym ist
16299 ENTRY(\sym)
16300 INTR_FRAME
16301@@ -1137,14 +1471,30 @@ ENTRY(\sym)
16302 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16303 call save_paranoid
16304 TRACE_IRQS_OFF_DEBUG
16305+#ifdef CONFIG_PAX_MEMORY_UDEREF
16306+ testb $3, CS(%rsp)
16307+ jnz 1f
16308+ pax_enter_kernel
16309+ jmp 2f
16310+1: pax_enter_kernel_user
16311+2:
16312+#else
16313+ pax_enter_kernel
16314+#endif
16315 movq %rsp,%rdi /* pt_regs pointer */
16316 xorl %esi,%esi /* no error code */
16317+#ifdef CONFIG_SMP
16318+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16319+ lea init_tss(%r12), %r12
16320+#else
16321+ lea init_tss(%rip), %r12
16322+#endif
16323 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16324 call \do_sym
16325 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16326 jmp paranoid_exit /* %ebx: no swapgs flag */
16327 CFI_ENDPROC
16328-END(\sym)
16329+ENDPROC(\sym)
16330 .endm
16331
16332 .macro errorentry sym do_sym
16333@@ -1155,13 +1505,23 @@ ENTRY(\sym)
16334 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16335 call error_entry
16336 DEFAULT_FRAME 0
16337+#ifdef CONFIG_PAX_MEMORY_UDEREF
16338+ testb $3, CS(%rsp)
16339+ jnz 1f
16340+ pax_enter_kernel
16341+ jmp 2f
16342+1: pax_enter_kernel_user
16343+2:
16344+#else
16345+ pax_enter_kernel
16346+#endif
16347 movq %rsp,%rdi /* pt_regs pointer */
16348 movq ORIG_RAX(%rsp),%rsi /* get error code */
16349 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16350 call \do_sym
16351 jmp error_exit /* %ebx: no swapgs flag */
16352 CFI_ENDPROC
16353-END(\sym)
16354+ENDPROC(\sym)
16355 .endm
16356
16357 /* error code is on the stack already */
16358@@ -1174,13 +1534,23 @@ ENTRY(\sym)
16359 call save_paranoid
16360 DEFAULT_FRAME 0
16361 TRACE_IRQS_OFF
16362+#ifdef CONFIG_PAX_MEMORY_UDEREF
16363+ testb $3, CS(%rsp)
16364+ jnz 1f
16365+ pax_enter_kernel
16366+ jmp 2f
16367+1: pax_enter_kernel_user
16368+2:
16369+#else
16370+ pax_enter_kernel
16371+#endif
16372 movq %rsp,%rdi /* pt_regs pointer */
16373 movq ORIG_RAX(%rsp),%rsi /* get error code */
16374 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16375 call \do_sym
16376 jmp paranoid_exit /* %ebx: no swapgs flag */
16377 CFI_ENDPROC
16378-END(\sym)
16379+ENDPROC(\sym)
16380 .endm
16381
16382 zeroentry divide_error do_divide_error
16383@@ -1210,9 +1580,10 @@ gs_change:
16384 2: mfence /* workaround */
16385 SWAPGS
16386 popfq_cfi
16387+ pax_force_retaddr
16388 ret
16389 CFI_ENDPROC
16390-END(native_load_gs_index)
16391+ENDPROC(native_load_gs_index)
16392
16393 _ASM_EXTABLE(gs_change,bad_gs)
16394 .section .fixup,"ax"
16395@@ -1231,13 +1602,14 @@ ENTRY(kernel_thread_helper)
16396 * Here we are in the child and the registers are set as they were
16397 * at kernel_thread() invocation in the parent.
16398 */
16399+ pax_force_fptr %rsi
16400 call *%rsi
16401 # exit
16402 mov %eax, %edi
16403 call do_exit
16404 ud2 # padding for call trace
16405 CFI_ENDPROC
16406-END(kernel_thread_helper)
16407+ENDPROC(kernel_thread_helper)
16408
16409 /*
16410 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16411@@ -1264,11 +1636,11 @@ ENTRY(kernel_execve)
16412 RESTORE_REST
16413 testq %rax,%rax
16414 je int_ret_from_sys_call
16415- RESTORE_ARGS
16416 UNFAKE_STACK_FRAME
16417+ pax_force_retaddr
16418 ret
16419 CFI_ENDPROC
16420-END(kernel_execve)
16421+ENDPROC(kernel_execve)
16422
16423 /* Call softirq on interrupt stack. Interrupts are off. */
16424 ENTRY(call_softirq)
16425@@ -1286,9 +1658,10 @@ ENTRY(call_softirq)
16426 CFI_DEF_CFA_REGISTER rsp
16427 CFI_ADJUST_CFA_OFFSET -8
16428 decl PER_CPU_VAR(irq_count)
16429+ pax_force_retaddr
16430 ret
16431 CFI_ENDPROC
16432-END(call_softirq)
16433+ENDPROC(call_softirq)
16434
16435 #ifdef CONFIG_XEN
16436 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16437@@ -1326,7 +1699,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16438 decl PER_CPU_VAR(irq_count)
16439 jmp error_exit
16440 CFI_ENDPROC
16441-END(xen_do_hypervisor_callback)
16442+ENDPROC(xen_do_hypervisor_callback)
16443
16444 /*
16445 * Hypervisor uses this for application faults while it executes.
16446@@ -1385,7 +1758,7 @@ ENTRY(xen_failsafe_callback)
16447 SAVE_ALL
16448 jmp error_exit
16449 CFI_ENDPROC
16450-END(xen_failsafe_callback)
16451+ENDPROC(xen_failsafe_callback)
16452
16453 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16454 xen_hvm_callback_vector xen_evtchn_do_upcall
16455@@ -1434,16 +1807,31 @@ ENTRY(paranoid_exit)
16456 TRACE_IRQS_OFF_DEBUG
16457 testl %ebx,%ebx /* swapgs needed? */
16458 jnz paranoid_restore
16459- testl $3,CS(%rsp)
16460+ testb $3,CS(%rsp)
16461 jnz paranoid_userspace
16462+#ifdef CONFIG_PAX_MEMORY_UDEREF
16463+ pax_exit_kernel
16464+ TRACE_IRQS_IRETQ 0
16465+ SWAPGS_UNSAFE_STACK
16466+ RESTORE_ALL 8
16467+ pax_force_retaddr_bts
16468+ jmp irq_return
16469+#endif
16470 paranoid_swapgs:
16471+#ifdef CONFIG_PAX_MEMORY_UDEREF
16472+ pax_exit_kernel_user
16473+#else
16474+ pax_exit_kernel
16475+#endif
16476 TRACE_IRQS_IRETQ 0
16477 SWAPGS_UNSAFE_STACK
16478 RESTORE_ALL 8
16479 jmp irq_return
16480 paranoid_restore:
16481+ pax_exit_kernel
16482 TRACE_IRQS_IRETQ_DEBUG 0
16483 RESTORE_ALL 8
16484+ pax_force_retaddr_bts
16485 jmp irq_return
16486 paranoid_userspace:
16487 GET_THREAD_INFO(%rcx)
16488@@ -1472,7 +1860,7 @@ paranoid_schedule:
16489 TRACE_IRQS_OFF
16490 jmp paranoid_userspace
16491 CFI_ENDPROC
16492-END(paranoid_exit)
16493+ENDPROC(paranoid_exit)
16494
16495 /*
16496 * Exception entry point. This expects an error code/orig_rax on the stack.
16497@@ -1499,12 +1887,13 @@ ENTRY(error_entry)
16498 movq_cfi r14, R14+8
16499 movq_cfi r15, R15+8
16500 xorl %ebx,%ebx
16501- testl $3,CS+8(%rsp)
16502+ testb $3,CS+8(%rsp)
16503 je error_kernelspace
16504 error_swapgs:
16505 SWAPGS
16506 error_sti:
16507 TRACE_IRQS_OFF
16508+ pax_force_retaddr_bts
16509 ret
16510
16511 /*
16512@@ -1531,7 +1920,7 @@ bstep_iret:
16513 movq %rcx,RIP+8(%rsp)
16514 jmp error_swapgs
16515 CFI_ENDPROC
16516-END(error_entry)
16517+ENDPROC(error_entry)
16518
16519
16520 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16521@@ -1551,7 +1940,7 @@ ENTRY(error_exit)
16522 jnz retint_careful
16523 jmp retint_swapgs
16524 CFI_ENDPROC
16525-END(error_exit)
16526+ENDPROC(error_exit)
16527
16528 /*
16529 * Test if a given stack is an NMI stack or not.
16530@@ -1609,9 +1998,11 @@ ENTRY(nmi)
16531 * If %cs was not the kernel segment, then the NMI triggered in user
16532 * space, which means it is definitely not nested.
16533 */
16534+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16535+ je 1f
16536 cmpl $__KERNEL_CS, 16(%rsp)
16537 jne first_nmi
16538-
16539+1:
16540 /*
16541 * Check the special variable on the stack to see if NMIs are
16542 * executing.
16543@@ -1758,6 +2149,16 @@ end_repeat_nmi:
16544 */
16545 call save_paranoid
16546 DEFAULT_FRAME 0
16547+#ifdef CONFIG_PAX_MEMORY_UDEREF
16548+ testb $3, CS(%rsp)
16549+ jnz 1f
16550+ pax_enter_kernel
16551+ jmp 2f
16552+1: pax_enter_kernel_user
16553+2:
16554+#else
16555+ pax_enter_kernel
16556+#endif
16557 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16558 movq %rsp,%rdi
16559 movq $-1,%rsi
16560@@ -1765,21 +2166,32 @@ end_repeat_nmi:
16561 testl %ebx,%ebx /* swapgs needed? */
16562 jnz nmi_restore
16563 nmi_swapgs:
16564+#ifdef CONFIG_PAX_MEMORY_UDEREF
16565+ pax_exit_kernel_user
16566+#else
16567+ pax_exit_kernel
16568+#endif
16569 SWAPGS_UNSAFE_STACK
16570+ RESTORE_ALL 8
16571+ /* Clear the NMI executing stack variable */
16572+ movq $0, 10*8(%rsp)
16573+ jmp irq_return
16574 nmi_restore:
16575+ pax_exit_kernel
16576 RESTORE_ALL 8
16577+ pax_force_retaddr_bts
16578 /* Clear the NMI executing stack variable */
16579 movq $0, 10*8(%rsp)
16580 jmp irq_return
16581 CFI_ENDPROC
16582-END(nmi)
16583+ENDPROC(nmi)
16584
16585 ENTRY(ignore_sysret)
16586 CFI_STARTPROC
16587 mov $-ENOSYS,%eax
16588 sysret
16589 CFI_ENDPROC
16590-END(ignore_sysret)
16591+ENDPROC(ignore_sysret)
16592
16593 /*
16594 * End of kprobes section
16595diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16596index c3a7cb4..3ad00dc 100644
16597--- a/arch/x86/kernel/ftrace.c
16598+++ b/arch/x86/kernel/ftrace.c
16599@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16600 {
16601 unsigned char replaced[MCOUNT_INSN_SIZE];
16602
16603+ ip = ktla_ktva(ip);
16604+
16605 /*
16606 * Note: Due to modules and __init, code can
16607 * disappear and change, we need to protect against faulting
16608@@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16609 unsigned char old[MCOUNT_INSN_SIZE], *new;
16610 int ret;
16611
16612- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16613+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16614 new = ftrace_call_replace(ip, (unsigned long)func);
16615
16616 /* See comment above by declaration of modifying_ftrace_code */
16617@@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16618 {
16619 unsigned char code[MCOUNT_INSN_SIZE];
16620
16621+ ip = ktla_ktva(ip);
16622+
16623 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16624 return -EFAULT;
16625
16626diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16627index c18f59d..9c0c9f6 100644
16628--- a/arch/x86/kernel/head32.c
16629+++ b/arch/x86/kernel/head32.c
16630@@ -18,6 +18,7 @@
16631 #include <asm/io_apic.h>
16632 #include <asm/bios_ebda.h>
16633 #include <asm/tlbflush.h>
16634+#include <asm/boot.h>
16635
16636 static void __init i386_default_early_setup(void)
16637 {
16638@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16639
16640 void __init i386_start_kernel(void)
16641 {
16642- memblock_reserve(__pa_symbol(&_text),
16643- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16644+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16645
16646 #ifdef CONFIG_BLK_DEV_INITRD
16647 /* Reserve INITRD */
16648diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16649index d42ab17..5015ea6 100644
16650--- a/arch/x86/kernel/head_32.S
16651+++ b/arch/x86/kernel/head_32.S
16652@@ -26,6 +26,12 @@
16653 /* Physical address */
16654 #define pa(X) ((X) - __PAGE_OFFSET)
16655
16656+#ifdef CONFIG_PAX_KERNEXEC
16657+#define ta(X) (X)
16658+#else
16659+#define ta(X) ((X) - __PAGE_OFFSET)
16660+#endif
16661+
16662 /*
16663 * References to members of the new_cpu_data structure.
16664 */
16665@@ -55,11 +61,7 @@
16666 * and small than max_low_pfn, otherwise will waste some page table entries
16667 */
16668
16669-#if PTRS_PER_PMD > 1
16670-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16671-#else
16672-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16673-#endif
16674+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16675
16676 /* Number of possible pages in the lowmem region */
16677 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16678@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16679 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16680
16681 /*
16682+ * Real beginning of normal "text" segment
16683+ */
16684+ENTRY(stext)
16685+ENTRY(_stext)
16686+
16687+/*
16688 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16689 * %esi points to the real-mode code as a 32-bit pointer.
16690 * CS and DS must be 4 GB flat segments, but we don't depend on
16691@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16692 * can.
16693 */
16694 __HEAD
16695+
16696+#ifdef CONFIG_PAX_KERNEXEC
16697+ jmp startup_32
16698+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16699+.fill PAGE_SIZE-5,1,0xcc
16700+#endif
16701+
16702 ENTRY(startup_32)
16703 movl pa(stack_start),%ecx
16704
16705@@ -106,6 +121,57 @@ ENTRY(startup_32)
16706 2:
16707 leal -__PAGE_OFFSET(%ecx),%esp
16708
16709+#ifdef CONFIG_SMP
16710+ movl $pa(cpu_gdt_table),%edi
16711+ movl $__per_cpu_load,%eax
16712+ movw %ax,__KERNEL_PERCPU + 2(%edi)
16713+ rorl $16,%eax
16714+ movb %al,__KERNEL_PERCPU + 4(%edi)
16715+ movb %ah,__KERNEL_PERCPU + 7(%edi)
16716+ movl $__per_cpu_end - 1,%eax
16717+ subl $__per_cpu_start,%eax
16718+ movw %ax,__KERNEL_PERCPU + 0(%edi)
16719+#endif
16720+
16721+#ifdef CONFIG_PAX_MEMORY_UDEREF
16722+ movl $NR_CPUS,%ecx
16723+ movl $pa(cpu_gdt_table),%edi
16724+1:
16725+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16726+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16727+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16728+ addl $PAGE_SIZE_asm,%edi
16729+ loop 1b
16730+#endif
16731+
16732+#ifdef CONFIG_PAX_KERNEXEC
16733+ movl $pa(boot_gdt),%edi
16734+ movl $__LOAD_PHYSICAL_ADDR,%eax
16735+ movw %ax,__BOOT_CS + 2(%edi)
16736+ rorl $16,%eax
16737+ movb %al,__BOOT_CS + 4(%edi)
16738+ movb %ah,__BOOT_CS + 7(%edi)
16739+ rorl $16,%eax
16740+
16741+ ljmp $(__BOOT_CS),$1f
16742+1:
16743+
16744+ movl $NR_CPUS,%ecx
16745+ movl $pa(cpu_gdt_table),%edi
16746+ addl $__PAGE_OFFSET,%eax
16747+1:
16748+ movw %ax,__KERNEL_CS + 2(%edi)
16749+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16750+ rorl $16,%eax
16751+ movb %al,__KERNEL_CS + 4(%edi)
16752+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16753+ movb %ah,__KERNEL_CS + 7(%edi)
16754+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16755+ rorl $16,%eax
16756+ addl $PAGE_SIZE_asm,%edi
16757+ loop 1b
16758+#endif
16759+
16760 /*
16761 * Clear BSS first so that there are no surprises...
16762 */
16763@@ -196,8 +262,11 @@ ENTRY(startup_32)
16764 movl %eax, pa(max_pfn_mapped)
16765
16766 /* Do early initialization of the fixmap area */
16767- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16768- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16769+#ifdef CONFIG_COMPAT_VDSO
16770+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16771+#else
16772+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16773+#endif
16774 #else /* Not PAE */
16775
16776 page_pde_offset = (__PAGE_OFFSET >> 20);
16777@@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16778 movl %eax, pa(max_pfn_mapped)
16779
16780 /* Do early initialization of the fixmap area */
16781- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16782- movl %eax,pa(initial_page_table+0xffc)
16783+#ifdef CONFIG_COMPAT_VDSO
16784+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16785+#else
16786+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16787+#endif
16788 #endif
16789
16790 #ifdef CONFIG_PARAVIRT
16791@@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16792 cmpl $num_subarch_entries, %eax
16793 jae bad_subarch
16794
16795- movl pa(subarch_entries)(,%eax,4), %eax
16796- subl $__PAGE_OFFSET, %eax
16797- jmp *%eax
16798+ jmp *pa(subarch_entries)(,%eax,4)
16799
16800 bad_subarch:
16801 WEAK(lguest_entry)
16802@@ -256,10 +326,10 @@ WEAK(xen_entry)
16803 __INITDATA
16804
16805 subarch_entries:
16806- .long default_entry /* normal x86/PC */
16807- .long lguest_entry /* lguest hypervisor */
16808- .long xen_entry /* Xen hypervisor */
16809- .long default_entry /* Moorestown MID */
16810+ .long ta(default_entry) /* normal x86/PC */
16811+ .long ta(lguest_entry) /* lguest hypervisor */
16812+ .long ta(xen_entry) /* Xen hypervisor */
16813+ .long ta(default_entry) /* Moorestown MID */
16814 num_subarch_entries = (. - subarch_entries) / 4
16815 .previous
16816 #else
16817@@ -310,6 +380,7 @@ default_entry:
16818 orl %edx,%eax
16819 movl %eax,%cr4
16820
16821+#ifdef CONFIG_X86_PAE
16822 testb $X86_CR4_PAE, %al # check if PAE is enabled
16823 jz 6f
16824
16825@@ -338,6 +409,9 @@ default_entry:
16826 /* Make changes effective */
16827 wrmsr
16828
16829+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16830+#endif
16831+
16832 6:
16833
16834 /*
16835@@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
16836 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16837 movl %eax,%ss # after changing gdt.
16838
16839- movl $(__USER_DS),%eax # DS/ES contains default USER segment
16840+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16841 movl %eax,%ds
16842 movl %eax,%es
16843
16844 movl $(__KERNEL_PERCPU), %eax
16845 movl %eax,%fs # set this cpu's percpu
16846
16847+#ifdef CONFIG_CC_STACKPROTECTOR
16848 movl $(__KERNEL_STACK_CANARY),%eax
16849+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16850+ movl $(__USER_DS),%eax
16851+#else
16852+ xorl %eax,%eax
16853+#endif
16854 movl %eax,%gs
16855
16856 xorl %eax,%eax # Clear LDT
16857@@ -520,8 +600,11 @@ setup_once:
16858 * relocation. Manually set base address in stack canary
16859 * segment descriptor.
16860 */
16861- movl $gdt_page,%eax
16862+ movl $cpu_gdt_table,%eax
16863 movl $stack_canary,%ecx
16864+#ifdef CONFIG_SMP
16865+ addl $__per_cpu_load,%ecx
16866+#endif
16867 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16868 shrl $16, %ecx
16869 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16870@@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
16871 /* This is global to keep gas from relaxing the jumps */
16872 ENTRY(early_idt_handler)
16873 cld
16874- cmpl $2,%ss:early_recursion_flag
16875+ cmpl $1,%ss:early_recursion_flag
16876 je hlt_loop
16877 incl %ss:early_recursion_flag
16878
16879@@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
16880 pushl (20+6*4)(%esp) /* trapno */
16881 pushl $fault_msg
16882 call printk
16883-#endif
16884 call dump_stack
16885+#endif
16886 hlt_loop:
16887 hlt
16888 jmp hlt_loop
16889@@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
16890 /* This is the default interrupt "handler" :-) */
16891 ALIGN
16892 ignore_int:
16893- cld
16894 #ifdef CONFIG_PRINTK
16895+ cmpl $2,%ss:early_recursion_flag
16896+ je hlt_loop
16897+ incl %ss:early_recursion_flag
16898+ cld
16899 pushl %eax
16900 pushl %ecx
16901 pushl %edx
16902@@ -620,9 +706,6 @@ ignore_int:
16903 movl $(__KERNEL_DS),%eax
16904 movl %eax,%ds
16905 movl %eax,%es
16906- cmpl $2,early_recursion_flag
16907- je hlt_loop
16908- incl early_recursion_flag
16909 pushl 16(%esp)
16910 pushl 24(%esp)
16911 pushl 32(%esp)
16912@@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
16913 /*
16914 * BSS section
16915 */
16916-__PAGE_ALIGNED_BSS
16917- .align PAGE_SIZE
16918 #ifdef CONFIG_X86_PAE
16919+.section .initial_pg_pmd,"a",@progbits
16920 initial_pg_pmd:
16921 .fill 1024*KPMDS,4,0
16922 #else
16923+.section .initial_page_table,"a",@progbits
16924 ENTRY(initial_page_table)
16925 .fill 1024,4,0
16926 #endif
16927+.section .initial_pg_fixmap,"a",@progbits
16928 initial_pg_fixmap:
16929 .fill 1024,4,0
16930+.section .empty_zero_page,"a",@progbits
16931 ENTRY(empty_zero_page)
16932 .fill 4096,1,0
16933+.section .swapper_pg_dir,"a",@progbits
16934 ENTRY(swapper_pg_dir)
16935+#ifdef CONFIG_X86_PAE
16936+ .fill 4,8,0
16937+#else
16938 .fill 1024,4,0
16939+#endif
16940+
16941+/*
16942+ * The IDT has to be page-aligned to simplify the Pentium
16943+ * F0 0F bug workaround.. We have a special link segment
16944+ * for this.
16945+ */
16946+.section .idt,"a",@progbits
16947+ENTRY(idt_table)
16948+ .fill 256,8,0
16949
16950 /*
16951 * This starts the data section.
16952 */
16953 #ifdef CONFIG_X86_PAE
16954-__PAGE_ALIGNED_DATA
16955- /* Page-aligned for the benefit of paravirt? */
16956- .align PAGE_SIZE
16957+.section .initial_page_table,"a",@progbits
16958 ENTRY(initial_page_table)
16959 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16960 # if KPMDS == 3
16961@@ -697,12 +794,20 @@ ENTRY(initial_page_table)
16962 # error "Kernel PMDs should be 1, 2 or 3"
16963 # endif
16964 .align PAGE_SIZE /* needs to be page-sized too */
16965+
16966+#ifdef CONFIG_PAX_PER_CPU_PGD
16967+ENTRY(cpu_pgd)
16968+ .rept NR_CPUS
16969+ .fill 4,8,0
16970+ .endr
16971+#endif
16972+
16973 #endif
16974
16975 .data
16976 .balign 4
16977 ENTRY(stack_start)
16978- .long init_thread_union+THREAD_SIZE
16979+ .long init_thread_union+THREAD_SIZE-8
16980
16981 __INITRODATA
16982 int_msg:
16983@@ -739,7 +844,7 @@ fault_msg:
16984 .word 0 # 32 bit align gdt_desc.address
16985 boot_gdt_descr:
16986 .word __BOOT_DS+7
16987- .long boot_gdt - __PAGE_OFFSET
16988+ .long pa(boot_gdt)
16989
16990 .word 0 # 32-bit align idt_desc.address
16991 idt_descr:
16992@@ -750,7 +855,7 @@ idt_descr:
16993 .word 0 # 32 bit align gdt_desc.address
16994 ENTRY(early_gdt_descr)
16995 .word GDT_ENTRIES*8-1
16996- .long gdt_page /* Overwritten for secondary CPUs */
16997+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
16998
16999 /*
17000 * The boot_gdt must mirror the equivalent in setup.S and is
17001@@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17002 .align L1_CACHE_BYTES
17003 ENTRY(boot_gdt)
17004 .fill GDT_ENTRY_BOOT_CS,8,0
17005- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17006- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17007+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17008+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17009+
17010+ .align PAGE_SIZE_asm
17011+ENTRY(cpu_gdt_table)
17012+ .rept NR_CPUS
17013+ .quad 0x0000000000000000 /* NULL descriptor */
17014+ .quad 0x0000000000000000 /* 0x0b reserved */
17015+ .quad 0x0000000000000000 /* 0x13 reserved */
17016+ .quad 0x0000000000000000 /* 0x1b reserved */
17017+
17018+#ifdef CONFIG_PAX_KERNEXEC
17019+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17020+#else
17021+ .quad 0x0000000000000000 /* 0x20 unused */
17022+#endif
17023+
17024+ .quad 0x0000000000000000 /* 0x28 unused */
17025+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17026+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17027+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17028+ .quad 0x0000000000000000 /* 0x4b reserved */
17029+ .quad 0x0000000000000000 /* 0x53 reserved */
17030+ .quad 0x0000000000000000 /* 0x5b reserved */
17031+
17032+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17033+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17034+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17035+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17036+
17037+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17038+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17039+
17040+ /*
17041+ * Segments used for calling PnP BIOS have byte granularity.
17042+ * The code segments and data segments have fixed 64k limits,
17043+ * the transfer segment sizes are set at run time.
17044+ */
17045+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17046+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17047+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17048+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17049+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17050+
17051+ /*
17052+ * The APM segments have byte granularity and their bases
17053+ * are set at run time. All have 64k limits.
17054+ */
17055+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17056+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17057+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17058+
17059+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17060+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17061+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17062+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17063+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17064+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17065+
17066+ /* Be sure this is zeroed to avoid false validations in Xen */
17067+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17068+ .endr
17069diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17070index 94bf9cc..400455a 100644
17071--- a/arch/x86/kernel/head_64.S
17072+++ b/arch/x86/kernel/head_64.S
17073@@ -20,6 +20,8 @@
17074 #include <asm/processor-flags.h>
17075 #include <asm/percpu.h>
17076 #include <asm/nops.h>
17077+#include <asm/cpufeature.h>
17078+#include <asm/alternative-asm.h>
17079
17080 #ifdef CONFIG_PARAVIRT
17081 #include <asm/asm-offsets.h>
17082@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17083 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17084 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17085 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17086+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17087+L3_VMALLOC_START = pud_index(VMALLOC_START)
17088+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17089+L3_VMALLOC_END = pud_index(VMALLOC_END)
17090+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17091+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17092
17093 .text
17094 __HEAD
17095@@ -88,35 +96,23 @@ startup_64:
17096 */
17097 addq %rbp, init_level4_pgt + 0(%rip)
17098 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17099+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17100+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17101+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17102 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17103
17104 addq %rbp, level3_ident_pgt + 0(%rip)
17105+#ifndef CONFIG_XEN
17106+ addq %rbp, level3_ident_pgt + 8(%rip)
17107+#endif
17108
17109- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17110- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17111+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17112+
17113+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17114+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17115
17116 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17117-
17118- /* Add an Identity mapping if I am above 1G */
17119- leaq _text(%rip), %rdi
17120- andq $PMD_PAGE_MASK, %rdi
17121-
17122- movq %rdi, %rax
17123- shrq $PUD_SHIFT, %rax
17124- andq $(PTRS_PER_PUD - 1), %rax
17125- jz ident_complete
17126-
17127- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17128- leaq level3_ident_pgt(%rip), %rbx
17129- movq %rdx, 0(%rbx, %rax, 8)
17130-
17131- movq %rdi, %rax
17132- shrq $PMD_SHIFT, %rax
17133- andq $(PTRS_PER_PMD - 1), %rax
17134- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17135- leaq level2_spare_pgt(%rip), %rbx
17136- movq %rdx, 0(%rbx, %rax, 8)
17137-ident_complete:
17138+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17139
17140 /*
17141 * Fixup the kernel text+data virtual addresses. Note that
17142@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17143 * after the boot processor executes this code.
17144 */
17145
17146- /* Enable PAE mode and PGE */
17147- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17148+ /* Enable PAE mode and PSE/PGE */
17149+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17150 movq %rax, %cr4
17151
17152 /* Setup early boot stage 4 level pagetables. */
17153@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17154 movl $MSR_EFER, %ecx
17155 rdmsr
17156 btsl $_EFER_SCE, %eax /* Enable System Call */
17157- btl $20,%edi /* No Execute supported? */
17158+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17159 jnc 1f
17160 btsl $_EFER_NX, %eax
17161+ leaq init_level4_pgt(%rip), %rdi
17162+#ifndef CONFIG_EFI
17163+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17164+#endif
17165+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17166+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17167+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17168+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17169 1: wrmsr /* Make changes effective */
17170
17171 /* Setup cr0 */
17172@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17173 * jump. In addition we need to ensure %cs is set so we make this
17174 * a far return.
17175 */
17176+ pax_set_fptr_mask
17177 movq initial_code(%rip),%rax
17178 pushq $0 # fake return address to stop unwinder
17179 pushq $__KERNEL_CS # set correct cs
17180@@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17181 bad_address:
17182 jmp bad_address
17183
17184- .section ".init.text","ax"
17185+ __INIT
17186 .globl early_idt_handlers
17187 early_idt_handlers:
17188 # 104(%rsp) %rflags
17189@@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17190 addq $16,%rsp # drop vector number and error code
17191 decl early_recursion_flag(%rip)
17192 INTERRUPT_RETURN
17193+ .previous
17194
17195+ __INITDATA
17196 .balign 4
17197 early_recursion_flag:
17198 .long 0
17199+ .previous
17200
17201+ .section .rodata,"a",@progbits
17202 #ifdef CONFIG_EARLY_PRINTK
17203 early_idt_msg:
17204 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17205@@ -360,6 +369,7 @@ early_idt_ripmsg:
17206 #endif /* CONFIG_EARLY_PRINTK */
17207 .previous
17208
17209+ .section .rodata,"a",@progbits
17210 #define NEXT_PAGE(name) \
17211 .balign PAGE_SIZE; \
17212 ENTRY(name)
17213@@ -372,7 +382,6 @@ ENTRY(name)
17214 i = i + 1 ; \
17215 .endr
17216
17217- .data
17218 /*
17219 * This default setting generates an ident mapping at address 0x100000
17220 * and a mapping for the kernel that precisely maps virtual address
17221@@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17222 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17223 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17224 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17225+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17226+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17227+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17228+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17229+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17230+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17231 .org init_level4_pgt + L4_START_KERNEL*8, 0
17232 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17233 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17234
17235+#ifdef CONFIG_PAX_PER_CPU_PGD
17236+NEXT_PAGE(cpu_pgd)
17237+ .rept NR_CPUS
17238+ .fill 512,8,0
17239+ .endr
17240+#endif
17241+
17242 NEXT_PAGE(level3_ident_pgt)
17243 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17244+#ifdef CONFIG_XEN
17245 .fill 511,8,0
17246+#else
17247+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17248+ .fill 510,8,0
17249+#endif
17250+
17251+NEXT_PAGE(level3_vmalloc_start_pgt)
17252+ .fill 512,8,0
17253+
17254+NEXT_PAGE(level3_vmalloc_end_pgt)
17255+ .fill 512,8,0
17256+
17257+NEXT_PAGE(level3_vmemmap_pgt)
17258+ .fill L3_VMEMMAP_START,8,0
17259+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17260
17261 NEXT_PAGE(level3_kernel_pgt)
17262 .fill L3_START_KERNEL,8,0
17263@@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17264 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17265 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17266
17267+NEXT_PAGE(level2_vmemmap_pgt)
17268+ .fill 512,8,0
17269+
17270 NEXT_PAGE(level2_fixmap_pgt)
17271- .fill 506,8,0
17272- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17273- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17274- .fill 5,8,0
17275+ .fill 507,8,0
17276+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17277+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17278+ .fill 4,8,0
17279
17280-NEXT_PAGE(level1_fixmap_pgt)
17281+NEXT_PAGE(level1_vsyscall_pgt)
17282 .fill 512,8,0
17283
17284-NEXT_PAGE(level2_ident_pgt)
17285- /* Since I easily can, map the first 1G.
17286+ /* Since I easily can, map the first 2G.
17287 * Don't set NX because code runs from these pages.
17288 */
17289- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17290+NEXT_PAGE(level2_ident_pgt)
17291+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17292
17293 NEXT_PAGE(level2_kernel_pgt)
17294 /*
17295@@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17296 * If you want to increase this then increase MODULES_VADDR
17297 * too.)
17298 */
17299- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17300- KERNEL_IMAGE_SIZE/PMD_SIZE)
17301-
17302-NEXT_PAGE(level2_spare_pgt)
17303- .fill 512, 8, 0
17304+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17305
17306 #undef PMDS
17307 #undef NEXT_PAGE
17308
17309- .data
17310+ .align PAGE_SIZE
17311+ENTRY(cpu_gdt_table)
17312+ .rept NR_CPUS
17313+ .quad 0x0000000000000000 /* NULL descriptor */
17314+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17315+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17316+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17317+ .quad 0x00cffb000000ffff /* __USER32_CS */
17318+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17319+ .quad 0x00affb000000ffff /* __USER_CS */
17320+
17321+#ifdef CONFIG_PAX_KERNEXEC
17322+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17323+#else
17324+ .quad 0x0 /* unused */
17325+#endif
17326+
17327+ .quad 0,0 /* TSS */
17328+ .quad 0,0 /* LDT */
17329+ .quad 0,0,0 /* three TLS descriptors */
17330+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17331+ /* asm/segment.h:GDT_ENTRIES must match this */
17332+
17333+ /* zero the remaining page */
17334+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17335+ .endr
17336+
17337 .align 16
17338 .globl early_gdt_descr
17339 early_gdt_descr:
17340 .word GDT_ENTRIES*8-1
17341 early_gdt_descr_base:
17342- .quad INIT_PER_CPU_VAR(gdt_page)
17343+ .quad cpu_gdt_table
17344
17345 ENTRY(phys_base)
17346 /* This must match the first entry in level2_kernel_pgt */
17347 .quad 0x0000000000000000
17348
17349 #include "../../x86/xen/xen-head.S"
17350-
17351- .section .bss, "aw", @nobits
17352+
17353+ .section .rodata,"a",@progbits
17354 .align L1_CACHE_BYTES
17355 ENTRY(idt_table)
17356- .skip IDT_ENTRIES * 16
17357+ .fill 512,8,0
17358
17359 .align L1_CACHE_BYTES
17360 ENTRY(nmi_idt_table)
17361- .skip IDT_ENTRIES * 16
17362+ .fill 512,8,0
17363
17364 __PAGE_ALIGNED_BSS
17365 .align PAGE_SIZE
17366diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17367index 9c3bd4a..e1d9b35 100644
17368--- a/arch/x86/kernel/i386_ksyms_32.c
17369+++ b/arch/x86/kernel/i386_ksyms_32.c
17370@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17371 EXPORT_SYMBOL(cmpxchg8b_emu);
17372 #endif
17373
17374+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17375+
17376 /* Networking helper routines. */
17377 EXPORT_SYMBOL(csum_partial_copy_generic);
17378+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17379+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17380
17381 EXPORT_SYMBOL(__get_user_1);
17382 EXPORT_SYMBOL(__get_user_2);
17383@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17384
17385 EXPORT_SYMBOL(csum_partial);
17386 EXPORT_SYMBOL(empty_zero_page);
17387+
17388+#ifdef CONFIG_PAX_KERNEXEC
17389+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17390+#endif
17391diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17392index f250431..54097e7 100644
17393--- a/arch/x86/kernel/i387.c
17394+++ b/arch/x86/kernel/i387.c
17395@@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17396 static inline bool interrupted_user_mode(void)
17397 {
17398 struct pt_regs *regs = get_irq_regs();
17399- return regs && user_mode_vm(regs);
17400+ return regs && user_mode(regs);
17401 }
17402
17403 /*
17404diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17405index 36d1853..bf25736 100644
17406--- a/arch/x86/kernel/i8259.c
17407+++ b/arch/x86/kernel/i8259.c
17408@@ -209,7 +209,7 @@ spurious_8259A_irq:
17409 "spurious 8259A interrupt: IRQ%d.\n", irq);
17410 spurious_irq_mask |= irqmask;
17411 }
17412- atomic_inc(&irq_err_count);
17413+ atomic_inc_unchecked(&irq_err_count);
17414 /*
17415 * Theoretically we do not have to handle this IRQ,
17416 * but in Linux this does not cause problems and is
17417diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17418index 8c96897..be66bfa 100644
17419--- a/arch/x86/kernel/ioport.c
17420+++ b/arch/x86/kernel/ioport.c
17421@@ -6,6 +6,7 @@
17422 #include <linux/sched.h>
17423 #include <linux/kernel.h>
17424 #include <linux/capability.h>
17425+#include <linux/security.h>
17426 #include <linux/errno.h>
17427 #include <linux/types.h>
17428 #include <linux/ioport.h>
17429@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17430
17431 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17432 return -EINVAL;
17433+#ifdef CONFIG_GRKERNSEC_IO
17434+ if (turn_on && grsec_disable_privio) {
17435+ gr_handle_ioperm();
17436+ return -EPERM;
17437+ }
17438+#endif
17439 if (turn_on && !capable(CAP_SYS_RAWIO))
17440 return -EPERM;
17441
17442@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17443 * because the ->io_bitmap_max value must match the bitmap
17444 * contents:
17445 */
17446- tss = &per_cpu(init_tss, get_cpu());
17447+ tss = init_tss + get_cpu();
17448
17449 if (turn_on)
17450 bitmap_clear(t->io_bitmap_ptr, from, num);
17451@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17452 return -EINVAL;
17453 /* Trying to gain more privileges? */
17454 if (level > old) {
17455+#ifdef CONFIG_GRKERNSEC_IO
17456+ if (grsec_disable_privio) {
17457+ gr_handle_iopl();
17458+ return -EPERM;
17459+ }
17460+#endif
17461 if (!capable(CAP_SYS_RAWIO))
17462 return -EPERM;
17463 }
17464diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17465index 3dafc60..aa8e9c4 100644
17466--- a/arch/x86/kernel/irq.c
17467+++ b/arch/x86/kernel/irq.c
17468@@ -18,7 +18,7 @@
17469 #include <asm/mce.h>
17470 #include <asm/hw_irq.h>
17471
17472-atomic_t irq_err_count;
17473+atomic_unchecked_t irq_err_count;
17474
17475 /* Function pointer for generic interrupt vector handling */
17476 void (*x86_platform_ipi_callback)(void) = NULL;
17477@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17478 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17479 seq_printf(p, " Machine check polls\n");
17480 #endif
17481- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17482+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17483 #if defined(CONFIG_X86_IO_APIC)
17484- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17485+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17486 #endif
17487 return 0;
17488 }
17489@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17490
17491 u64 arch_irq_stat(void)
17492 {
17493- u64 sum = atomic_read(&irq_err_count);
17494+ u64 sum = atomic_read_unchecked(&irq_err_count);
17495
17496 #ifdef CONFIG_X86_IO_APIC
17497- sum += atomic_read(&irq_mis_count);
17498+ sum += atomic_read_unchecked(&irq_mis_count);
17499 #endif
17500 return sum;
17501 }
17502diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17503index 344faf8..355f60d 100644
17504--- a/arch/x86/kernel/irq_32.c
17505+++ b/arch/x86/kernel/irq_32.c
17506@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17507 __asm__ __volatile__("andl %%esp,%0" :
17508 "=r" (sp) : "0" (THREAD_SIZE - 1));
17509
17510- return sp < (sizeof(struct thread_info) + STACK_WARN);
17511+ return sp < STACK_WARN;
17512 }
17513
17514 static void print_stack_overflow(void)
17515@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17516 * per-CPU IRQ handling contexts (thread information and stack)
17517 */
17518 union irq_ctx {
17519- struct thread_info tinfo;
17520- u32 stack[THREAD_SIZE/sizeof(u32)];
17521+ unsigned long previous_esp;
17522+ u32 stack[THREAD_SIZE/sizeof(u32)];
17523 } __attribute__((aligned(THREAD_SIZE)));
17524
17525 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17526@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17527 static inline int
17528 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17529 {
17530- union irq_ctx *curctx, *irqctx;
17531+ union irq_ctx *irqctx;
17532 u32 *isp, arg1, arg2;
17533
17534- curctx = (union irq_ctx *) current_thread_info();
17535 irqctx = __this_cpu_read(hardirq_ctx);
17536
17537 /*
17538@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17539 * handler) we can't do that and just have to keep using the
17540 * current stack (which is the irq stack already after all)
17541 */
17542- if (unlikely(curctx == irqctx))
17543+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17544 return 0;
17545
17546 /* build the stack frame on the IRQ stack */
17547- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17548- irqctx->tinfo.task = curctx->tinfo.task;
17549- irqctx->tinfo.previous_esp = current_stack_pointer;
17550+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17551+ irqctx->previous_esp = current_stack_pointer;
17552
17553- /* Copy the preempt_count so that the [soft]irq checks work. */
17554- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17555+#ifdef CONFIG_PAX_MEMORY_UDEREF
17556+ __set_fs(MAKE_MM_SEG(0));
17557+#endif
17558
17559 if (unlikely(overflow))
17560 call_on_stack(print_stack_overflow, isp);
17561@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17562 : "0" (irq), "1" (desc), "2" (isp),
17563 "D" (desc->handle_irq)
17564 : "memory", "cc", "ecx");
17565+
17566+#ifdef CONFIG_PAX_MEMORY_UDEREF
17567+ __set_fs(current_thread_info()->addr_limit);
17568+#endif
17569+
17570 return 1;
17571 }
17572
17573@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17574 */
17575 void __cpuinit irq_ctx_init(int cpu)
17576 {
17577- union irq_ctx *irqctx;
17578-
17579 if (per_cpu(hardirq_ctx, cpu))
17580 return;
17581
17582- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17583- THREADINFO_GFP,
17584- THREAD_SIZE_ORDER));
17585- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17586- irqctx->tinfo.cpu = cpu;
17587- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17588- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17589-
17590- per_cpu(hardirq_ctx, cpu) = irqctx;
17591-
17592- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17593- THREADINFO_GFP,
17594- THREAD_SIZE_ORDER));
17595- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17596- irqctx->tinfo.cpu = cpu;
17597- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17598-
17599- per_cpu(softirq_ctx, cpu) = irqctx;
17600+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17601+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17602+
17603+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17604+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17605
17606 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17607 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17608@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17609 asmlinkage void do_softirq(void)
17610 {
17611 unsigned long flags;
17612- struct thread_info *curctx;
17613 union irq_ctx *irqctx;
17614 u32 *isp;
17615
17616@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17617 local_irq_save(flags);
17618
17619 if (local_softirq_pending()) {
17620- curctx = current_thread_info();
17621 irqctx = __this_cpu_read(softirq_ctx);
17622- irqctx->tinfo.task = curctx->task;
17623- irqctx->tinfo.previous_esp = current_stack_pointer;
17624+ irqctx->previous_esp = current_stack_pointer;
17625
17626 /* build the stack frame on the softirq stack */
17627- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17628+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17629+
17630+#ifdef CONFIG_PAX_MEMORY_UDEREF
17631+ __set_fs(MAKE_MM_SEG(0));
17632+#endif
17633
17634 call_on_stack(__do_softirq, isp);
17635+
17636+#ifdef CONFIG_PAX_MEMORY_UDEREF
17637+ __set_fs(current_thread_info()->addr_limit);
17638+#endif
17639+
17640 /*
17641 * Shouldn't happen, we returned above if in_interrupt():
17642 */
17643@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17644 if (unlikely(!desc))
17645 return false;
17646
17647- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17648+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17649 if (unlikely(overflow))
17650 print_stack_overflow();
17651 desc->handle_irq(irq, desc);
17652diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17653index d04d3ec..ea4b374 100644
17654--- a/arch/x86/kernel/irq_64.c
17655+++ b/arch/x86/kernel/irq_64.c
17656@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17657 u64 estack_top, estack_bottom;
17658 u64 curbase = (u64)task_stack_page(current);
17659
17660- if (user_mode_vm(regs))
17661+ if (user_mode(regs))
17662 return;
17663
17664 if (regs->sp >= curbase + sizeof(struct thread_info) +
17665diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17666index 1d5d31e..ab846ed 100644
17667--- a/arch/x86/kernel/kdebugfs.c
17668+++ b/arch/x86/kernel/kdebugfs.c
17669@@ -28,6 +28,8 @@ struct setup_data_node {
17670 };
17671
17672 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17673+ size_t count, loff_t *ppos) __size_overflow(3);
17674+static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17675 size_t count, loff_t *ppos)
17676 {
17677 struct setup_data_node *node = file->private_data;
17678diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17679index 3f61904..873cea9 100644
17680--- a/arch/x86/kernel/kgdb.c
17681+++ b/arch/x86/kernel/kgdb.c
17682@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17683 #ifdef CONFIG_X86_32
17684 switch (regno) {
17685 case GDB_SS:
17686- if (!user_mode_vm(regs))
17687+ if (!user_mode(regs))
17688 *(unsigned long *)mem = __KERNEL_DS;
17689 break;
17690 case GDB_SP:
17691- if (!user_mode_vm(regs))
17692+ if (!user_mode(regs))
17693 *(unsigned long *)mem = kernel_stack_pointer(regs);
17694 break;
17695 case GDB_GS:
17696@@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17697 case 'k':
17698 /* clear the trace bit */
17699 linux_regs->flags &= ~X86_EFLAGS_TF;
17700- atomic_set(&kgdb_cpu_doing_single_step, -1);
17701+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17702
17703 /* set the trace bit if we're stepping */
17704 if (remcomInBuffer[0] == 's') {
17705 linux_regs->flags |= X86_EFLAGS_TF;
17706- atomic_set(&kgdb_cpu_doing_single_step,
17707+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17708 raw_smp_processor_id());
17709 }
17710
17711@@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17712
17713 switch (cmd) {
17714 case DIE_DEBUG:
17715- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17716+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17717 if (user_mode(regs))
17718 return single_step_cont(regs, args);
17719 break;
17720diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17721index c5e410e..da6aaf9 100644
17722--- a/arch/x86/kernel/kprobes-opt.c
17723+++ b/arch/x86/kernel/kprobes-opt.c
17724@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17725 * Verify if the address gap is in 2GB range, because this uses
17726 * a relative jump.
17727 */
17728- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17729+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17730 if (abs(rel) > 0x7fffffff)
17731 return -ERANGE;
17732
17733@@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17734 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17735
17736 /* Set probe function call */
17737- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17738+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17739
17740 /* Set returning jmp instruction at the tail of out-of-line buffer */
17741 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17742- (u8 *)op->kp.addr + op->optinsn.size);
17743+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17744
17745 flush_icache_range((unsigned long) buf,
17746 (unsigned long) buf + TMPL_END_IDX +
17747@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17748 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17749
17750 /* Backup instructions which will be replaced by jump address */
17751- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17752+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17753 RELATIVE_ADDR_SIZE);
17754
17755 insn_buf[0] = RELATIVEJUMP_OPCODE;
17756diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17757index e2f751e..dffa2a0 100644
17758--- a/arch/x86/kernel/kprobes.c
17759+++ b/arch/x86/kernel/kprobes.c
17760@@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17761 } __attribute__((packed)) *insn;
17762
17763 insn = (struct __arch_relative_insn *)from;
17764+
17765+ pax_open_kernel();
17766 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17767 insn->op = op;
17768+ pax_close_kernel();
17769 }
17770
17771 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17772@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17773 kprobe_opcode_t opcode;
17774 kprobe_opcode_t *orig_opcodes = opcodes;
17775
17776- if (search_exception_tables((unsigned long)opcodes))
17777+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17778 return 0; /* Page fault may occur on this address. */
17779
17780 retry:
17781@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17782 /* Another subsystem puts a breakpoint, failed to recover */
17783 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17784 return 0;
17785+ pax_open_kernel();
17786 memcpy(dest, insn.kaddr, insn.length);
17787+ pax_close_kernel();
17788
17789 #ifdef CONFIG_X86_64
17790 if (insn_rip_relative(&insn)) {
17791@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17792 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17793 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17794 disp = (u8 *) dest + insn_offset_displacement(&insn);
17795+ pax_open_kernel();
17796 *(s32 *) disp = (s32) newdisp;
17797+ pax_close_kernel();
17798 }
17799 #endif
17800 return insn.length;
17801@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17802 * nor set current_kprobe, because it doesn't use single
17803 * stepping.
17804 */
17805- regs->ip = (unsigned long)p->ainsn.insn;
17806+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17807 preempt_enable_no_resched();
17808 return;
17809 }
17810@@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17811 if (p->opcode == BREAKPOINT_INSTRUCTION)
17812 regs->ip = (unsigned long)p->addr;
17813 else
17814- regs->ip = (unsigned long)p->ainsn.insn;
17815+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17816 }
17817
17818 /*
17819@@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17820 setup_singlestep(p, regs, kcb, 0);
17821 return 1;
17822 }
17823- } else if (*addr != BREAKPOINT_INSTRUCTION) {
17824+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17825 /*
17826 * The breakpoint instruction was removed right
17827 * after we hit it. Another cpu has removed
17828@@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17829 " movq %rax, 152(%rsp)\n"
17830 RESTORE_REGS_STRING
17831 " popfq\n"
17832+#ifdef KERNEXEC_PLUGIN
17833+ " btsq $63,(%rsp)\n"
17834+#endif
17835 #else
17836 " pushf\n"
17837 SAVE_REGS_STRING
17838@@ -765,7 +775,7 @@ static void __kprobes
17839 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17840 {
17841 unsigned long *tos = stack_addr(regs);
17842- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17843+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17844 unsigned long orig_ip = (unsigned long)p->addr;
17845 kprobe_opcode_t *insn = p->ainsn.insn;
17846
17847@@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
17848 struct die_args *args = data;
17849 int ret = NOTIFY_DONE;
17850
17851- if (args->regs && user_mode_vm(args->regs))
17852+ if (args->regs && user_mode(args->regs))
17853 return ret;
17854
17855 switch (val) {
17856diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17857index ebc9873..1b9724b 100644
17858--- a/arch/x86/kernel/ldt.c
17859+++ b/arch/x86/kernel/ldt.c
17860@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17861 if (reload) {
17862 #ifdef CONFIG_SMP
17863 preempt_disable();
17864- load_LDT(pc);
17865+ load_LDT_nolock(pc);
17866 if (!cpumask_equal(mm_cpumask(current->mm),
17867 cpumask_of(smp_processor_id())))
17868 smp_call_function(flush_ldt, current->mm, 1);
17869 preempt_enable();
17870 #else
17871- load_LDT(pc);
17872+ load_LDT_nolock(pc);
17873 #endif
17874 }
17875 if (oldsize) {
17876@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17877 return err;
17878
17879 for (i = 0; i < old->size; i++)
17880- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17881+ write_ldt_entry(new->ldt, i, old->ldt + i);
17882 return 0;
17883 }
17884
17885@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17886 retval = copy_ldt(&mm->context, &old_mm->context);
17887 mutex_unlock(&old_mm->context.lock);
17888 }
17889+
17890+ if (tsk == current) {
17891+ mm->context.vdso = 0;
17892+
17893+#ifdef CONFIG_X86_32
17894+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17895+ mm->context.user_cs_base = 0UL;
17896+ mm->context.user_cs_limit = ~0UL;
17897+
17898+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17899+ cpus_clear(mm->context.cpu_user_cs_mask);
17900+#endif
17901+
17902+#endif
17903+#endif
17904+
17905+ }
17906+
17907 return retval;
17908 }
17909
17910@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17911 }
17912 }
17913
17914+#ifdef CONFIG_PAX_SEGMEXEC
17915+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17916+ error = -EINVAL;
17917+ goto out_unlock;
17918+ }
17919+#endif
17920+
17921 fill_ldt(&ldt, &ldt_info);
17922 if (oldmode)
17923 ldt.avl = 0;
17924diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17925index 5b19e4d..6476a76 100644
17926--- a/arch/x86/kernel/machine_kexec_32.c
17927+++ b/arch/x86/kernel/machine_kexec_32.c
17928@@ -26,7 +26,7 @@
17929 #include <asm/cacheflush.h>
17930 #include <asm/debugreg.h>
17931
17932-static void set_idt(void *newidt, __u16 limit)
17933+static void set_idt(struct desc_struct *newidt, __u16 limit)
17934 {
17935 struct desc_ptr curidt;
17936
17937@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
17938 }
17939
17940
17941-static void set_gdt(void *newgdt, __u16 limit)
17942+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17943 {
17944 struct desc_ptr curgdt;
17945
17946@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
17947 }
17948
17949 control_page = page_address(image->control_code_page);
17950- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17951+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17952
17953 relocate_kernel_ptr = control_page;
17954 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17955diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17956index 0327e2b..e43737b 100644
17957--- a/arch/x86/kernel/microcode_intel.c
17958+++ b/arch/x86/kernel/microcode_intel.c
17959@@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17960
17961 static int get_ucode_user(void *to, const void *from, size_t n)
17962 {
17963- return copy_from_user(to, from, n);
17964+ return copy_from_user(to, (const void __force_user *)from, n);
17965 }
17966
17967 static enum ucode_state
17968 request_microcode_user(int cpu, const void __user *buf, size_t size)
17969 {
17970- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17971+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17972 }
17973
17974 static void microcode_fini_cpu(int cpu)
17975diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17976index f21fd94..61565cd 100644
17977--- a/arch/x86/kernel/module.c
17978+++ b/arch/x86/kernel/module.c
17979@@ -35,15 +35,60 @@
17980 #define DEBUGP(fmt...)
17981 #endif
17982
17983-void *module_alloc(unsigned long size)
17984+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
17985 {
17986- if (PAGE_ALIGN(size) > MODULES_LEN)
17987+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
17988 return NULL;
17989 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
17990- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
17991+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
17992 -1, __builtin_return_address(0));
17993 }
17994
17995+void *module_alloc(unsigned long size)
17996+{
17997+
17998+#ifdef CONFIG_PAX_KERNEXEC
17999+ return __module_alloc(size, PAGE_KERNEL);
18000+#else
18001+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18002+#endif
18003+
18004+}
18005+
18006+#ifdef CONFIG_PAX_KERNEXEC
18007+#ifdef CONFIG_X86_32
18008+void *module_alloc_exec(unsigned long size)
18009+{
18010+ struct vm_struct *area;
18011+
18012+ if (size == 0)
18013+ return NULL;
18014+
18015+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18016+ return area ? area->addr : NULL;
18017+}
18018+EXPORT_SYMBOL(module_alloc_exec);
18019+
18020+void module_free_exec(struct module *mod, void *module_region)
18021+{
18022+ vunmap(module_region);
18023+}
18024+EXPORT_SYMBOL(module_free_exec);
18025+#else
18026+void module_free_exec(struct module *mod, void *module_region)
18027+{
18028+ module_free(mod, module_region);
18029+}
18030+EXPORT_SYMBOL(module_free_exec);
18031+
18032+void *module_alloc_exec(unsigned long size)
18033+{
18034+ return __module_alloc(size, PAGE_KERNEL_RX);
18035+}
18036+EXPORT_SYMBOL(module_alloc_exec);
18037+#endif
18038+#endif
18039+
18040 #ifdef CONFIG_X86_32
18041 int apply_relocate(Elf32_Shdr *sechdrs,
18042 const char *strtab,
18043@@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18044 unsigned int i;
18045 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18046 Elf32_Sym *sym;
18047- uint32_t *location;
18048+ uint32_t *plocation, location;
18049
18050 DEBUGP("Applying relocate section %u to %u\n", relsec,
18051 sechdrs[relsec].sh_info);
18052 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18053 /* This is where to make the change */
18054- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18055- + rel[i].r_offset;
18056+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18057+ location = (uint32_t)plocation;
18058+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18059+ plocation = ktla_ktva((void *)plocation);
18060 /* This is the symbol it is referring to. Note that all
18061 undefined symbols have been resolved. */
18062 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18063@@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18064 switch (ELF32_R_TYPE(rel[i].r_info)) {
18065 case R_386_32:
18066 /* We add the value into the location given */
18067- *location += sym->st_value;
18068+ pax_open_kernel();
18069+ *plocation += sym->st_value;
18070+ pax_close_kernel();
18071 break;
18072 case R_386_PC32:
18073 /* Add the value, subtract its postition */
18074- *location += sym->st_value - (uint32_t)location;
18075+ pax_open_kernel();
18076+ *plocation += sym->st_value - location;
18077+ pax_close_kernel();
18078 break;
18079 default:
18080 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18081@@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18082 case R_X86_64_NONE:
18083 break;
18084 case R_X86_64_64:
18085+ pax_open_kernel();
18086 *(u64 *)loc = val;
18087+ pax_close_kernel();
18088 break;
18089 case R_X86_64_32:
18090+ pax_open_kernel();
18091 *(u32 *)loc = val;
18092+ pax_close_kernel();
18093 if (val != *(u32 *)loc)
18094 goto overflow;
18095 break;
18096 case R_X86_64_32S:
18097+ pax_open_kernel();
18098 *(s32 *)loc = val;
18099+ pax_close_kernel();
18100 if ((s64)val != *(s32 *)loc)
18101 goto overflow;
18102 break;
18103 case R_X86_64_PC32:
18104 val -= (u64)loc;
18105+ pax_open_kernel();
18106 *(u32 *)loc = val;
18107+ pax_close_kernel();
18108+
18109 #if 0
18110 if ((s64)val != *(s32 *)loc)
18111 goto overflow;
18112diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18113index a0b2f84..875ab81 100644
18114--- a/arch/x86/kernel/nmi.c
18115+++ b/arch/x86/kernel/nmi.c
18116@@ -460,6 +460,17 @@ static inline void nmi_nesting_postprocess(void)
18117 dotraplinkage notrace __kprobes void
18118 do_nmi(struct pt_regs *regs, long error_code)
18119 {
18120+
18121+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18122+ if (!user_mode(regs)) {
18123+ unsigned long cs = regs->cs & 0xFFFF;
18124+ unsigned long ip = ktva_ktla(regs->ip);
18125+
18126+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18127+ regs->ip = ip;
18128+ }
18129+#endif
18130+
18131 nmi_nesting_preprocess(regs);
18132
18133 nmi_enter();
18134diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18135index 676b8c7..870ba04 100644
18136--- a/arch/x86/kernel/paravirt-spinlocks.c
18137+++ b/arch/x86/kernel/paravirt-spinlocks.c
18138@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18139 arch_spin_lock(lock);
18140 }
18141
18142-struct pv_lock_ops pv_lock_ops = {
18143+struct pv_lock_ops pv_lock_ops __read_only = {
18144 #ifdef CONFIG_SMP
18145 .spin_is_locked = __ticket_spin_is_locked,
18146 .spin_is_contended = __ticket_spin_is_contended,
18147diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18148index 9ce8859..b49bf51 100644
18149--- a/arch/x86/kernel/paravirt.c
18150+++ b/arch/x86/kernel/paravirt.c
18151@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18152 {
18153 return x;
18154 }
18155+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18156+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18157+#endif
18158
18159 void __init default_banner(void)
18160 {
18161@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18162 if (opfunc == NULL)
18163 /* If there's no function, patch it with a ud2a (BUG) */
18164 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18165- else if (opfunc == _paravirt_nop)
18166+ else if (opfunc == (void *)_paravirt_nop)
18167 /* If the operation is a nop, then nop the callsite */
18168 ret = paravirt_patch_nop();
18169
18170 /* identity functions just return their single argument */
18171- else if (opfunc == _paravirt_ident_32)
18172+ else if (opfunc == (void *)_paravirt_ident_32)
18173 ret = paravirt_patch_ident_32(insnbuf, len);
18174- else if (opfunc == _paravirt_ident_64)
18175+ else if (opfunc == (void *)_paravirt_ident_64)
18176 ret = paravirt_patch_ident_64(insnbuf, len);
18177+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18178+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18179+ ret = paravirt_patch_ident_64(insnbuf, len);
18180+#endif
18181
18182 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18183 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18184@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18185 if (insn_len > len || start == NULL)
18186 insn_len = len;
18187 else
18188- memcpy(insnbuf, start, insn_len);
18189+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18190
18191 return insn_len;
18192 }
18193@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18194 preempt_enable();
18195 }
18196
18197-struct pv_info pv_info = {
18198+struct pv_info pv_info __read_only = {
18199 .name = "bare hardware",
18200 .paravirt_enabled = 0,
18201 .kernel_rpl = 0,
18202@@ -315,16 +322,16 @@ struct pv_info pv_info = {
18203 #endif
18204 };
18205
18206-struct pv_init_ops pv_init_ops = {
18207+struct pv_init_ops pv_init_ops __read_only = {
18208 .patch = native_patch,
18209 };
18210
18211-struct pv_time_ops pv_time_ops = {
18212+struct pv_time_ops pv_time_ops __read_only = {
18213 .sched_clock = native_sched_clock,
18214 .steal_clock = native_steal_clock,
18215 };
18216
18217-struct pv_irq_ops pv_irq_ops = {
18218+struct pv_irq_ops pv_irq_ops __read_only = {
18219 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18220 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18221 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18222@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18223 #endif
18224 };
18225
18226-struct pv_cpu_ops pv_cpu_ops = {
18227+struct pv_cpu_ops pv_cpu_ops __read_only = {
18228 .cpuid = native_cpuid,
18229 .get_debugreg = native_get_debugreg,
18230 .set_debugreg = native_set_debugreg,
18231@@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18232 .end_context_switch = paravirt_nop,
18233 };
18234
18235-struct pv_apic_ops pv_apic_ops = {
18236+struct pv_apic_ops pv_apic_ops __read_only = {
18237 #ifdef CONFIG_X86_LOCAL_APIC
18238 .startup_ipi_hook = paravirt_nop,
18239 #endif
18240 };
18241
18242-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18243+#ifdef CONFIG_X86_32
18244+#ifdef CONFIG_X86_PAE
18245+/* 64-bit pagetable entries */
18246+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18247+#else
18248 /* 32-bit pagetable entries */
18249 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18250+#endif
18251 #else
18252 /* 64-bit pagetable entries */
18253 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18254 #endif
18255
18256-struct pv_mmu_ops pv_mmu_ops = {
18257+struct pv_mmu_ops pv_mmu_ops __read_only = {
18258
18259 .read_cr2 = native_read_cr2,
18260 .write_cr2 = native_write_cr2,
18261@@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18262 .make_pud = PTE_IDENT,
18263
18264 .set_pgd = native_set_pgd,
18265+ .set_pgd_batched = native_set_pgd_batched,
18266 #endif
18267 #endif /* PAGETABLE_LEVELS >= 3 */
18268
18269@@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18270 },
18271
18272 .set_fixmap = native_set_fixmap,
18273+
18274+#ifdef CONFIG_PAX_KERNEXEC
18275+ .pax_open_kernel = native_pax_open_kernel,
18276+ .pax_close_kernel = native_pax_close_kernel,
18277+#endif
18278+
18279 };
18280
18281 EXPORT_SYMBOL_GPL(pv_time_ops);
18282diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18283index 35ccf75..7a15747 100644
18284--- a/arch/x86/kernel/pci-iommu_table.c
18285+++ b/arch/x86/kernel/pci-iommu_table.c
18286@@ -2,7 +2,7 @@
18287 #include <asm/iommu_table.h>
18288 #include <linux/string.h>
18289 #include <linux/kallsyms.h>
18290-
18291+#include <linux/sched.h>
18292
18293 #define DEBUG 1
18294
18295diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18296index 735279e..5008677 100644
18297--- a/arch/x86/kernel/process.c
18298+++ b/arch/x86/kernel/process.c
18299@@ -34,7 +34,8 @@
18300 * section. Since TSS's are completely CPU-local, we want them
18301 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18302 */
18303-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18304+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18305+EXPORT_SYMBOL(init_tss);
18306
18307 #ifdef CONFIG_X86_64
18308 static DEFINE_PER_CPU(unsigned char, is_idle);
18309@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
18310 task_xstate_cachep =
18311 kmem_cache_create("task_xstate", xstate_size,
18312 __alignof__(union thread_xstate),
18313- SLAB_PANIC | SLAB_NOTRACK, NULL);
18314+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18315 }
18316
18317 static inline void drop_fpu(struct task_struct *tsk)
18318@@ -115,7 +116,7 @@ void exit_thread(void)
18319 unsigned long *bp = t->io_bitmap_ptr;
18320
18321 if (bp) {
18322- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18323+ struct tss_struct *tss = init_tss + get_cpu();
18324
18325 t->io_bitmap_ptr = NULL;
18326 clear_thread_flag(TIF_IO_BITMAP);
18327@@ -147,7 +148,7 @@ void show_regs_common(void)
18328
18329 printk(KERN_CONT "\n");
18330 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18331- current->pid, current->comm, print_tainted(),
18332+ task_pid_nr(current), current->comm, print_tainted(),
18333 init_utsname()->release,
18334 (int)strcspn(init_utsname()->version, " "),
18335 init_utsname()->version);
18336@@ -161,6 +162,9 @@ void flush_thread(void)
18337 {
18338 struct task_struct *tsk = current;
18339
18340+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18341+ loadsegment(gs, 0);
18342+#endif
18343 flush_ptrace_hw_breakpoint(tsk);
18344 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18345 drop_fpu(tsk);
18346@@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18347 regs.di = (unsigned long) arg;
18348
18349 #ifdef CONFIG_X86_32
18350- regs.ds = __USER_DS;
18351- regs.es = __USER_DS;
18352+ regs.ds = __KERNEL_DS;
18353+ regs.es = __KERNEL_DS;
18354 regs.fs = __KERNEL_PERCPU;
18355- regs.gs = __KERNEL_STACK_CANARY;
18356+ savesegment(gs, regs.gs);
18357 #else
18358 regs.ss = __KERNEL_DS;
18359 #endif
18360@@ -407,7 +411,7 @@ static void __exit_idle(void)
18361 void exit_idle(void)
18362 {
18363 /* idle loop has pid 0 */
18364- if (current->pid)
18365+ if (task_pid_nr(current))
18366 return;
18367 __exit_idle();
18368 }
18369@@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18370
18371 return ret;
18372 }
18373-void stop_this_cpu(void *dummy)
18374+__noreturn void stop_this_cpu(void *dummy)
18375 {
18376 local_irq_disable();
18377 /*
18378@@ -746,16 +750,37 @@ static int __init idle_setup(char *str)
18379 }
18380 early_param("idle", idle_setup);
18381
18382-unsigned long arch_align_stack(unsigned long sp)
18383+#ifdef CONFIG_PAX_RANDKSTACK
18384+void pax_randomize_kstack(struct pt_regs *regs)
18385 {
18386- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18387- sp -= get_random_int() % 8192;
18388- return sp & ~0xf;
18389-}
18390+ struct thread_struct *thread = &current->thread;
18391+ unsigned long time;
18392
18393-unsigned long arch_randomize_brk(struct mm_struct *mm)
18394-{
18395- unsigned long range_end = mm->brk + 0x02000000;
18396- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18397-}
18398+ if (!randomize_va_space)
18399+ return;
18400+
18401+ if (v8086_mode(regs))
18402+ return;
18403
18404+ rdtscl(time);
18405+
18406+ /* P4 seems to return a 0 LSB, ignore it */
18407+#ifdef CONFIG_MPENTIUM4
18408+ time &= 0x3EUL;
18409+ time <<= 2;
18410+#elif defined(CONFIG_X86_64)
18411+ time &= 0xFUL;
18412+ time <<= 4;
18413+#else
18414+ time &= 0x1FUL;
18415+ time <<= 3;
18416+#endif
18417+
18418+ thread->sp0 ^= time;
18419+ load_sp0(init_tss + smp_processor_id(), thread);
18420+
18421+#ifdef CONFIG_X86_64
18422+ this_cpu_write(kernel_stack, thread->sp0);
18423+#endif
18424+}
18425+#endif
18426diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18427index 516fa18..80bd9e6 100644
18428--- a/arch/x86/kernel/process_32.c
18429+++ b/arch/x86/kernel/process_32.c
18430@@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18431 unsigned long thread_saved_pc(struct task_struct *tsk)
18432 {
18433 return ((unsigned long *)tsk->thread.sp)[3];
18434+//XXX return tsk->thread.eip;
18435 }
18436
18437 void __show_regs(struct pt_regs *regs, int all)
18438@@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18439 unsigned long sp;
18440 unsigned short ss, gs;
18441
18442- if (user_mode_vm(regs)) {
18443+ if (user_mode(regs)) {
18444 sp = regs->sp;
18445 ss = regs->ss & 0xffff;
18446- gs = get_user_gs(regs);
18447 } else {
18448 sp = kernel_stack_pointer(regs);
18449 savesegment(ss, ss);
18450- savesegment(gs, gs);
18451 }
18452+ gs = get_user_gs(regs);
18453
18454 show_regs_common();
18455
18456@@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18457 struct task_struct *tsk;
18458 int err;
18459
18460- childregs = task_pt_regs(p);
18461+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18462 *childregs = *regs;
18463 childregs->ax = 0;
18464 childregs->sp = sp;
18465
18466 p->thread.sp = (unsigned long) childregs;
18467 p->thread.sp0 = (unsigned long) (childregs+1);
18468+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18469
18470 p->thread.ip = (unsigned long) ret_from_fork;
18471
18472@@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18473 struct thread_struct *prev = &prev_p->thread,
18474 *next = &next_p->thread;
18475 int cpu = smp_processor_id();
18476- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18477+ struct tss_struct *tss = init_tss + cpu;
18478 fpu_switch_t fpu;
18479
18480 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18481@@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18482 */
18483 lazy_save_gs(prev->gs);
18484
18485+#ifdef CONFIG_PAX_MEMORY_UDEREF
18486+ __set_fs(task_thread_info(next_p)->addr_limit);
18487+#endif
18488+
18489 /*
18490 * Load the per-thread Thread-Local Storage descriptor.
18491 */
18492@@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18493 */
18494 arch_end_context_switch(next_p);
18495
18496+ this_cpu_write(current_task, next_p);
18497+ this_cpu_write(current_tinfo, &next_p->tinfo);
18498+
18499 /*
18500 * Restore %gs if needed (which is common)
18501 */
18502@@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18503
18504 switch_fpu_finish(next_p, fpu);
18505
18506- this_cpu_write(current_task, next_p);
18507-
18508 return prev_p;
18509 }
18510
18511@@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18512 } while (count++ < 16);
18513 return 0;
18514 }
18515-
18516diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18517index 61cdf7f..797f06a 100644
18518--- a/arch/x86/kernel/process_64.c
18519+++ b/arch/x86/kernel/process_64.c
18520@@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18521 struct pt_regs *childregs;
18522 struct task_struct *me = current;
18523
18524- childregs = ((struct pt_regs *)
18525- (THREAD_SIZE + task_stack_page(p))) - 1;
18526+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18527 *childregs = *regs;
18528
18529 childregs->ax = 0;
18530@@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18531 p->thread.sp = (unsigned long) childregs;
18532 p->thread.sp0 = (unsigned long) (childregs+1);
18533 p->thread.usersp = me->thread.usersp;
18534+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18535
18536 set_tsk_thread_flag(p, TIF_FORK);
18537
18538@@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18539 struct thread_struct *prev = &prev_p->thread;
18540 struct thread_struct *next = &next_p->thread;
18541 int cpu = smp_processor_id();
18542- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18543+ struct tss_struct *tss = init_tss + cpu;
18544 unsigned fsindex, gsindex;
18545 fpu_switch_t fpu;
18546
18547@@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18548 prev->usersp = this_cpu_read(old_rsp);
18549 this_cpu_write(old_rsp, next->usersp);
18550 this_cpu_write(current_task, next_p);
18551+ this_cpu_write(current_tinfo, &next_p->tinfo);
18552
18553- this_cpu_write(kernel_stack,
18554- (unsigned long)task_stack_page(next_p) +
18555- THREAD_SIZE - KERNEL_STACK_OFFSET);
18556+ this_cpu_write(kernel_stack, next->sp0);
18557
18558 /*
18559 * Now maybe reload the debug registers and handle I/O bitmaps
18560@@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18561 if (!p || p == current || p->state == TASK_RUNNING)
18562 return 0;
18563 stack = (unsigned long)task_stack_page(p);
18564- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18565+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18566 return 0;
18567 fp = *(u64 *)(p->thread.sp);
18568 do {
18569- if (fp < (unsigned long)stack ||
18570- fp >= (unsigned long)stack+THREAD_SIZE)
18571+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18572 return 0;
18573 ip = *(u64 *)(fp+8);
18574 if (!in_sched_functions(ip))
18575diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18576index c4c6a5c..905f440 100644
18577--- a/arch/x86/kernel/ptrace.c
18578+++ b/arch/x86/kernel/ptrace.c
18579@@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18580 unsigned long addr, unsigned long data)
18581 {
18582 int ret;
18583- unsigned long __user *datap = (unsigned long __user *)data;
18584+ unsigned long __user *datap = (__force unsigned long __user *)data;
18585
18586 switch (request) {
18587 /* read the word at location addr in the USER area. */
18588@@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18589 if ((int) addr < 0)
18590 return -EIO;
18591 ret = do_get_thread_area(child, addr,
18592- (struct user_desc __user *)data);
18593+ (__force struct user_desc __user *) data);
18594 break;
18595
18596 case PTRACE_SET_THREAD_AREA:
18597 if ((int) addr < 0)
18598 return -EIO;
18599 ret = do_set_thread_area(child, addr,
18600- (struct user_desc __user *)data, 0);
18601+ (__force struct user_desc __user *) data, 0);
18602 break;
18603 #endif
18604
18605@@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18606 memset(info, 0, sizeof(*info));
18607 info->si_signo = SIGTRAP;
18608 info->si_code = si_code;
18609- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18610+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18611 }
18612
18613 void user_single_step_siginfo(struct task_struct *tsk,
18614@@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18615 # define IS_IA32 0
18616 #endif
18617
18618+#ifdef CONFIG_GRKERNSEC_SETXID
18619+extern void gr_delayed_cred_worker(void);
18620+#endif
18621+
18622 /*
18623 * We must return the syscall number to actually look up in the table.
18624 * This can be -1L to skip running any syscall at all.
18625@@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18626 {
18627 long ret = 0;
18628
18629+#ifdef CONFIG_GRKERNSEC_SETXID
18630+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18631+ gr_delayed_cred_worker();
18632+#endif
18633+
18634 /*
18635 * If we stepped into a sysenter/syscall insn, it trapped in
18636 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18637@@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18638 {
18639 bool step;
18640
18641+#ifdef CONFIG_GRKERNSEC_SETXID
18642+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18643+ gr_delayed_cred_worker();
18644+#endif
18645+
18646 audit_syscall_exit(regs);
18647
18648 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18649diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18650index 42eb330..139955c 100644
18651--- a/arch/x86/kernel/pvclock.c
18652+++ b/arch/x86/kernel/pvclock.c
18653@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18654 return pv_tsc_khz;
18655 }
18656
18657-static atomic64_t last_value = ATOMIC64_INIT(0);
18658+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18659
18660 void pvclock_resume(void)
18661 {
18662- atomic64_set(&last_value, 0);
18663+ atomic64_set_unchecked(&last_value, 0);
18664 }
18665
18666 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18667@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18668 * updating at the same time, and one of them could be slightly behind,
18669 * making the assumption that last_value always go forward fail to hold.
18670 */
18671- last = atomic64_read(&last_value);
18672+ last = atomic64_read_unchecked(&last_value);
18673 do {
18674 if (ret < last)
18675 return last;
18676- last = atomic64_cmpxchg(&last_value, last, ret);
18677+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18678 } while (unlikely(last != ret));
18679
18680 return ret;
18681diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18682index 5de92f1..2732385 100644
18683--- a/arch/x86/kernel/reboot.c
18684+++ b/arch/x86/kernel/reboot.c
18685@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18686 EXPORT_SYMBOL(pm_power_off);
18687
18688 static const struct desc_ptr no_idt = {};
18689-static int reboot_mode;
18690+static unsigned short reboot_mode;
18691 enum reboot_type reboot_type = BOOT_ACPI;
18692 int reboot_force;
18693
18694@@ -157,11 +157,15 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18695 return 0;
18696 }
18697
18698-void machine_real_restart(unsigned int type)
18699+__noreturn void machine_real_restart(unsigned int type)
18700 {
18701- void (*restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18702+ void (* restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18703 real_mode_header->machine_real_restart_asm;
18704
18705+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18706+ struct desc_struct *gdt;
18707+#endif
18708+
18709 local_irq_disable();
18710
18711 /*
18712@@ -189,10 +193,36 @@ void machine_real_restart(unsigned int type)
18713 * boot)". This seems like a fairly standard thing that gets set by
18714 * REBOOT.COM programs, and the previous reset routine did this
18715 * too. */
18716- *((unsigned short *)0x472) = reboot_mode;
18717+ *(unsigned short *)(__va(0x472)) = reboot_mode;
18718
18719 /* Jump to the identity-mapped low memory code */
18720+
18721+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18722+ gdt = get_cpu_gdt_table(smp_processor_id());
18723+ pax_open_kernel();
18724+#ifdef CONFIG_PAX_MEMORY_UDEREF
18725+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18726+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18727+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18728+#endif
18729+#ifdef CONFIG_PAX_KERNEXEC
18730+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18731+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18732+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18733+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18734+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18735+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18736+#endif
18737+ pax_close_kernel();
18738+#endif
18739+
18740+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18741+ asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18742+ unreachable();
18743+#else
18744 restart_lowmem(type);
18745+#endif
18746+
18747 }
18748 #ifdef CONFIG_APM_MODULE
18749 EXPORT_SYMBOL(machine_real_restart);
18750@@ -543,7 +573,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18751 * try to force a triple fault and then cycle between hitting the keyboard
18752 * controller and doing that
18753 */
18754-static void native_machine_emergency_restart(void)
18755+__noreturn static void native_machine_emergency_restart(void)
18756 {
18757 int i;
18758 int attempt = 0;
18759@@ -670,13 +700,13 @@ void native_machine_shutdown(void)
18760 #endif
18761 }
18762
18763-static void __machine_emergency_restart(int emergency)
18764+static __noreturn void __machine_emergency_restart(int emergency)
18765 {
18766 reboot_emergency = emergency;
18767 machine_ops.emergency_restart();
18768 }
18769
18770-static void native_machine_restart(char *__unused)
18771+static __noreturn void native_machine_restart(char *__unused)
18772 {
18773 printk("machine restart\n");
18774
18775@@ -685,7 +715,7 @@ static void native_machine_restart(char *__unused)
18776 __machine_emergency_restart(0);
18777 }
18778
18779-static void native_machine_halt(void)
18780+static __noreturn void native_machine_halt(void)
18781 {
18782 /* Stop other cpus and apics */
18783 machine_shutdown();
18784@@ -695,7 +725,7 @@ static void native_machine_halt(void)
18785 stop_this_cpu(NULL);
18786 }
18787
18788-static void native_machine_power_off(void)
18789+__noreturn static void native_machine_power_off(void)
18790 {
18791 if (pm_power_off) {
18792 if (!reboot_force)
18793@@ -704,6 +734,7 @@ static void native_machine_power_off(void)
18794 }
18795 /* A fallback in case there is no PM info available */
18796 tboot_shutdown(TB_SHUTDOWN_HALT);
18797+ unreachable();
18798 }
18799
18800 struct machine_ops machine_ops = {
18801diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18802index 7a6f3b3..bed145d7 100644
18803--- a/arch/x86/kernel/relocate_kernel_64.S
18804+++ b/arch/x86/kernel/relocate_kernel_64.S
18805@@ -11,6 +11,7 @@
18806 #include <asm/kexec.h>
18807 #include <asm/processor-flags.h>
18808 #include <asm/pgtable_types.h>
18809+#include <asm/alternative-asm.h>
18810
18811 /*
18812 * Must be relocatable PIC code callable as a C function
18813@@ -160,13 +161,14 @@ identity_mapped:
18814 xorq %rbp, %rbp
18815 xorq %r8, %r8
18816 xorq %r9, %r9
18817- xorq %r10, %r9
18818+ xorq %r10, %r10
18819 xorq %r11, %r11
18820 xorq %r12, %r12
18821 xorq %r13, %r13
18822 xorq %r14, %r14
18823 xorq %r15, %r15
18824
18825+ pax_force_retaddr 0, 1
18826 ret
18827
18828 1:
18829diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18830index 16be6dc..4686132 100644
18831--- a/arch/x86/kernel/setup.c
18832+++ b/arch/x86/kernel/setup.c
18833@@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
18834
18835 switch (data->type) {
18836 case SETUP_E820_EXT:
18837- parse_e820_ext(data);
18838+ parse_e820_ext((struct setup_data __force_kernel *)data);
18839 break;
18840 case SETUP_DTB:
18841 add_dtb(pa_data);
18842@@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
18843 * area (640->1Mb) as ram even though it is not.
18844 * take them out.
18845 */
18846- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18847+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18848 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18849 }
18850
18851@@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
18852
18853 if (!boot_params.hdr.root_flags)
18854 root_mountflags &= ~MS_RDONLY;
18855- init_mm.start_code = (unsigned long) _text;
18856- init_mm.end_code = (unsigned long) _etext;
18857+ init_mm.start_code = ktla_ktva((unsigned long) _text);
18858+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
18859 init_mm.end_data = (unsigned long) _edata;
18860 init_mm.brk = _brk_end;
18861
18862- code_resource.start = virt_to_phys(_text);
18863- code_resource.end = virt_to_phys(_etext)-1;
18864- data_resource.start = virt_to_phys(_etext);
18865+ code_resource.start = virt_to_phys(ktla_ktva(_text));
18866+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18867+ data_resource.start = virt_to_phys(_sdata);
18868 data_resource.end = virt_to_phys(_edata)-1;
18869 bss_resource.start = virt_to_phys(&__bss_start);
18870 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18871diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18872index 5a98aa2..2f9288d 100644
18873--- a/arch/x86/kernel/setup_percpu.c
18874+++ b/arch/x86/kernel/setup_percpu.c
18875@@ -21,19 +21,17 @@
18876 #include <asm/cpu.h>
18877 #include <asm/stackprotector.h>
18878
18879-DEFINE_PER_CPU(int, cpu_number);
18880+#ifdef CONFIG_SMP
18881+DEFINE_PER_CPU(unsigned int, cpu_number);
18882 EXPORT_PER_CPU_SYMBOL(cpu_number);
18883+#endif
18884
18885-#ifdef CONFIG_X86_64
18886 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18887-#else
18888-#define BOOT_PERCPU_OFFSET 0
18889-#endif
18890
18891 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18892 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18893
18894-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18895+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18896 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18897 };
18898 EXPORT_SYMBOL(__per_cpu_offset);
18899@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
18900 {
18901 #ifdef CONFIG_X86_32
18902 struct desc_struct gdt;
18903+ unsigned long base = per_cpu_offset(cpu);
18904
18905- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18906- 0x2 | DESCTYPE_S, 0x8);
18907- gdt.s = 1;
18908+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18909+ 0x83 | DESCTYPE_S, 0xC);
18910 write_gdt_entry(get_cpu_gdt_table(cpu),
18911 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18912 #endif
18913@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
18914 /* alrighty, percpu areas up and running */
18915 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18916 for_each_possible_cpu(cpu) {
18917+#ifdef CONFIG_CC_STACKPROTECTOR
18918+#ifdef CONFIG_X86_32
18919+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
18920+#endif
18921+#endif
18922 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18923 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18924 per_cpu(cpu_number, cpu) = cpu;
18925@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
18926 */
18927 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18928 #endif
18929+#ifdef CONFIG_CC_STACKPROTECTOR
18930+#ifdef CONFIG_X86_32
18931+ if (!cpu)
18932+ per_cpu(stack_canary.canary, cpu) = canary;
18933+#endif
18934+#endif
18935 /*
18936 * Up to this point, the boot CPU has been using .init.data
18937 * area. Reload any changed state for the boot CPU.
18938diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18939index 21af737..fb45e22 100644
18940--- a/arch/x86/kernel/signal.c
18941+++ b/arch/x86/kernel/signal.c
18942@@ -191,7 +191,7 @@ static unsigned long align_sigframe(unsigned long sp)
18943 * Align the stack pointer according to the i386 ABI,
18944 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18945 */
18946- sp = ((sp + 4) & -16ul) - 4;
18947+ sp = ((sp - 12) & -16ul) - 4;
18948 #else /* !CONFIG_X86_32 */
18949 sp = round_down(sp, 16) - 8;
18950 #endif
18951@@ -242,11 +242,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18952 * Return an always-bogus address instead so we will die with SIGSEGV.
18953 */
18954 if (onsigstack && !likely(on_sig_stack(sp)))
18955- return (void __user *)-1L;
18956+ return (__force void __user *)-1L;
18957
18958 /* save i387 state */
18959 if (used_math() && save_i387_xstate(*fpstate) < 0)
18960- return (void __user *)-1L;
18961+ return (__force void __user *)-1L;
18962
18963 return (void __user *)sp;
18964 }
18965@@ -301,9 +301,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18966 }
18967
18968 if (current->mm->context.vdso)
18969- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18970+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18971 else
18972- restorer = &frame->retcode;
18973+ restorer = (void __user *)&frame->retcode;
18974 if (ka->sa.sa_flags & SA_RESTORER)
18975 restorer = ka->sa.sa_restorer;
18976
18977@@ -317,7 +317,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18978 * reasons and because gdb uses it as a signature to notice
18979 * signal handler stack frames.
18980 */
18981- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
18982+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
18983
18984 if (err)
18985 return -EFAULT;
18986@@ -371,7 +371,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18987 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
18988
18989 /* Set up to return from userspace. */
18990- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18991+ if (current->mm->context.vdso)
18992+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18993+ else
18994+ restorer = (void __user *)&frame->retcode;
18995 if (ka->sa.sa_flags & SA_RESTORER)
18996 restorer = ka->sa.sa_restorer;
18997 put_user_ex(restorer, &frame->pretcode);
18998@@ -383,7 +386,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18999 * reasons and because gdb uses it as a signature to notice
19000 * signal handler stack frames.
19001 */
19002- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19003+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19004 } put_user_catch(err);
19005
19006 if (err)
19007diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19008index 7bd8a08..2659b5b 100644
19009--- a/arch/x86/kernel/smpboot.c
19010+++ b/arch/x86/kernel/smpboot.c
19011@@ -679,6 +679,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19012 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19013 (THREAD_SIZE + task_stack_page(idle))) - 1);
19014 per_cpu(current_task, cpu) = idle;
19015+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
19016
19017 #ifdef CONFIG_X86_32
19018 /* Stack for startup_32 can be just as for start_secondary onwards */
19019@@ -686,11 +687,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19020 #else
19021 clear_tsk_thread_flag(idle, TIF_FORK);
19022 initial_gs = per_cpu_offset(cpu);
19023- per_cpu(kernel_stack, cpu) =
19024- (unsigned long)task_stack_page(idle) -
19025- KERNEL_STACK_OFFSET + THREAD_SIZE;
19026+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19027 #endif
19028+
19029+ pax_open_kernel();
19030 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19031+ pax_close_kernel();
19032+
19033 initial_code = (unsigned long)start_secondary;
19034 stack_start = idle->thread.sp;
19035
19036@@ -826,6 +829,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19037
19038 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19039
19040+#ifdef CONFIG_PAX_PER_CPU_PGD
19041+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19042+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19043+ KERNEL_PGD_PTRS);
19044+#endif
19045+
19046 err = do_boot_cpu(apicid, cpu, tidle);
19047 if (err) {
19048 pr_debug("do_boot_cpu failed %d\n", err);
19049diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19050index c346d11..d43b163 100644
19051--- a/arch/x86/kernel/step.c
19052+++ b/arch/x86/kernel/step.c
19053@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19054 struct desc_struct *desc;
19055 unsigned long base;
19056
19057- seg &= ~7UL;
19058+ seg >>= 3;
19059
19060 mutex_lock(&child->mm->context.lock);
19061- if (unlikely((seg >> 3) >= child->mm->context.size))
19062+ if (unlikely(seg >= child->mm->context.size))
19063 addr = -1L; /* bogus selector, access would fault */
19064 else {
19065 desc = child->mm->context.ldt + seg;
19066@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19067 addr += base;
19068 }
19069 mutex_unlock(&child->mm->context.lock);
19070- }
19071+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19072+ addr = ktla_ktva(addr);
19073
19074 return addr;
19075 }
19076@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19077 unsigned char opcode[15];
19078 unsigned long addr = convert_ip_to_linear(child, regs);
19079
19080+ if (addr == -EINVAL)
19081+ return 0;
19082+
19083 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19084 for (i = 0; i < copied; i++) {
19085 switch (opcode[i]) {
19086diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19087index 0b0cb5f..db6b9ed 100644
19088--- a/arch/x86/kernel/sys_i386_32.c
19089+++ b/arch/x86/kernel/sys_i386_32.c
19090@@ -24,17 +24,224 @@
19091
19092 #include <asm/syscalls.h>
19093
19094-/*
19095- * Do a system call from kernel instead of calling sys_execve so we
19096- * end up with proper pt_regs.
19097- */
19098-int kernel_execve(const char *filename,
19099- const char *const argv[],
19100- const char *const envp[])
19101+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19102 {
19103- long __res;
19104- asm volatile ("int $0x80"
19105- : "=a" (__res)
19106- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19107- return __res;
19108+ unsigned long pax_task_size = TASK_SIZE;
19109+
19110+#ifdef CONFIG_PAX_SEGMEXEC
19111+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19112+ pax_task_size = SEGMEXEC_TASK_SIZE;
19113+#endif
19114+
19115+ if (len > pax_task_size || addr > pax_task_size - len)
19116+ return -EINVAL;
19117+
19118+ return 0;
19119+}
19120+
19121+unsigned long
19122+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19123+ unsigned long len, unsigned long pgoff, unsigned long flags)
19124+{
19125+ struct mm_struct *mm = current->mm;
19126+ struct vm_area_struct *vma;
19127+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19128+
19129+#ifdef CONFIG_PAX_SEGMEXEC
19130+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19131+ pax_task_size = SEGMEXEC_TASK_SIZE;
19132+#endif
19133+
19134+ pax_task_size -= PAGE_SIZE;
19135+
19136+ if (len > pax_task_size)
19137+ return -ENOMEM;
19138+
19139+ if (flags & MAP_FIXED)
19140+ return addr;
19141+
19142+#ifdef CONFIG_PAX_RANDMMAP
19143+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19144+#endif
19145+
19146+ if (addr) {
19147+ addr = PAGE_ALIGN(addr);
19148+ if (pax_task_size - len >= addr) {
19149+ vma = find_vma(mm, addr);
19150+ if (check_heap_stack_gap(vma, addr, len))
19151+ return addr;
19152+ }
19153+ }
19154+ if (len > mm->cached_hole_size) {
19155+ start_addr = addr = mm->free_area_cache;
19156+ } else {
19157+ start_addr = addr = mm->mmap_base;
19158+ mm->cached_hole_size = 0;
19159+ }
19160+
19161+#ifdef CONFIG_PAX_PAGEEXEC
19162+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19163+ start_addr = 0x00110000UL;
19164+
19165+#ifdef CONFIG_PAX_RANDMMAP
19166+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19167+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19168+#endif
19169+
19170+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19171+ start_addr = addr = mm->mmap_base;
19172+ else
19173+ addr = start_addr;
19174+ }
19175+#endif
19176+
19177+full_search:
19178+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19179+ /* At this point: (!vma || addr < vma->vm_end). */
19180+ if (pax_task_size - len < addr) {
19181+ /*
19182+ * Start a new search - just in case we missed
19183+ * some holes.
19184+ */
19185+ if (start_addr != mm->mmap_base) {
19186+ start_addr = addr = mm->mmap_base;
19187+ mm->cached_hole_size = 0;
19188+ goto full_search;
19189+ }
19190+ return -ENOMEM;
19191+ }
19192+ if (check_heap_stack_gap(vma, addr, len))
19193+ break;
19194+ if (addr + mm->cached_hole_size < vma->vm_start)
19195+ mm->cached_hole_size = vma->vm_start - addr;
19196+ addr = vma->vm_end;
19197+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19198+ start_addr = addr = mm->mmap_base;
19199+ mm->cached_hole_size = 0;
19200+ goto full_search;
19201+ }
19202+ }
19203+
19204+ /*
19205+ * Remember the place where we stopped the search:
19206+ */
19207+ mm->free_area_cache = addr + len;
19208+ return addr;
19209+}
19210+
19211+unsigned long
19212+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19213+ const unsigned long len, const unsigned long pgoff,
19214+ const unsigned long flags)
19215+{
19216+ struct vm_area_struct *vma;
19217+ struct mm_struct *mm = current->mm;
19218+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19219+
19220+#ifdef CONFIG_PAX_SEGMEXEC
19221+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19222+ pax_task_size = SEGMEXEC_TASK_SIZE;
19223+#endif
19224+
19225+ pax_task_size -= PAGE_SIZE;
19226+
19227+ /* requested length too big for entire address space */
19228+ if (len > pax_task_size)
19229+ return -ENOMEM;
19230+
19231+ if (flags & MAP_FIXED)
19232+ return addr;
19233+
19234+#ifdef CONFIG_PAX_PAGEEXEC
19235+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19236+ goto bottomup;
19237+#endif
19238+
19239+#ifdef CONFIG_PAX_RANDMMAP
19240+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19241+#endif
19242+
19243+ /* requesting a specific address */
19244+ if (addr) {
19245+ addr = PAGE_ALIGN(addr);
19246+ if (pax_task_size - len >= addr) {
19247+ vma = find_vma(mm, addr);
19248+ if (check_heap_stack_gap(vma, addr, len))
19249+ return addr;
19250+ }
19251+ }
19252+
19253+ /* check if free_area_cache is useful for us */
19254+ if (len <= mm->cached_hole_size) {
19255+ mm->cached_hole_size = 0;
19256+ mm->free_area_cache = mm->mmap_base;
19257+ }
19258+
19259+ /* either no address requested or can't fit in requested address hole */
19260+ addr = mm->free_area_cache;
19261+
19262+ /* make sure it can fit in the remaining address space */
19263+ if (addr > len) {
19264+ vma = find_vma(mm, addr-len);
19265+ if (check_heap_stack_gap(vma, addr - len, len))
19266+ /* remember the address as a hint for next time */
19267+ return (mm->free_area_cache = addr-len);
19268+ }
19269+
19270+ if (mm->mmap_base < len)
19271+ goto bottomup;
19272+
19273+ addr = mm->mmap_base-len;
19274+
19275+ do {
19276+ /*
19277+ * Lookup failure means no vma is above this address,
19278+ * else if new region fits below vma->vm_start,
19279+ * return with success:
19280+ */
19281+ vma = find_vma(mm, addr);
19282+ if (check_heap_stack_gap(vma, addr, len))
19283+ /* remember the address as a hint for next time */
19284+ return (mm->free_area_cache = addr);
19285+
19286+ /* remember the largest hole we saw so far */
19287+ if (addr + mm->cached_hole_size < vma->vm_start)
19288+ mm->cached_hole_size = vma->vm_start - addr;
19289+
19290+ /* try just below the current vma->vm_start */
19291+ addr = skip_heap_stack_gap(vma, len);
19292+ } while (!IS_ERR_VALUE(addr));
19293+
19294+bottomup:
19295+ /*
19296+ * A failed mmap() very likely causes application failure,
19297+ * so fall back to the bottom-up function here. This scenario
19298+ * can happen with large stack limits and large mmap()
19299+ * allocations.
19300+ */
19301+
19302+#ifdef CONFIG_PAX_SEGMEXEC
19303+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19304+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19305+ else
19306+#endif
19307+
19308+ mm->mmap_base = TASK_UNMAPPED_BASE;
19309+
19310+#ifdef CONFIG_PAX_RANDMMAP
19311+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19312+ mm->mmap_base += mm->delta_mmap;
19313+#endif
19314+
19315+ mm->free_area_cache = mm->mmap_base;
19316+ mm->cached_hole_size = ~0UL;
19317+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19318+ /*
19319+ * Restore the topdown base:
19320+ */
19321+ mm->mmap_base = base;
19322+ mm->free_area_cache = base;
19323+ mm->cached_hole_size = ~0UL;
19324+
19325+ return addr;
19326 }
19327diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19328index b4d3c39..82bb73b 100644
19329--- a/arch/x86/kernel/sys_x86_64.c
19330+++ b/arch/x86/kernel/sys_x86_64.c
19331@@ -95,8 +95,8 @@ out:
19332 return error;
19333 }
19334
19335-static void find_start_end(unsigned long flags, unsigned long *begin,
19336- unsigned long *end)
19337+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19338+ unsigned long *begin, unsigned long *end)
19339 {
19340 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19341 unsigned long new_begin;
19342@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19343 *begin = new_begin;
19344 }
19345 } else {
19346- *begin = TASK_UNMAPPED_BASE;
19347+ *begin = mm->mmap_base;
19348 *end = TASK_SIZE;
19349 }
19350 }
19351@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19352 if (flags & MAP_FIXED)
19353 return addr;
19354
19355- find_start_end(flags, &begin, &end);
19356+ find_start_end(mm, flags, &begin, &end);
19357
19358 if (len > end)
19359 return -ENOMEM;
19360
19361+#ifdef CONFIG_PAX_RANDMMAP
19362+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19363+#endif
19364+
19365 if (addr) {
19366 addr = PAGE_ALIGN(addr);
19367 vma = find_vma(mm, addr);
19368- if (end - len >= addr &&
19369- (!vma || addr + len <= vma->vm_start))
19370+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19371 return addr;
19372 }
19373 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19374@@ -172,7 +175,7 @@ full_search:
19375 }
19376 return -ENOMEM;
19377 }
19378- if (!vma || addr + len <= vma->vm_start) {
19379+ if (check_heap_stack_gap(vma, addr, len)) {
19380 /*
19381 * Remember the place where we stopped the search:
19382 */
19383@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19384 {
19385 struct vm_area_struct *vma;
19386 struct mm_struct *mm = current->mm;
19387- unsigned long addr = addr0, start_addr;
19388+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19389
19390 /* requested length too big for entire address space */
19391 if (len > TASK_SIZE)
19392@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19393 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19394 goto bottomup;
19395
19396+#ifdef CONFIG_PAX_RANDMMAP
19397+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19398+#endif
19399+
19400 /* requesting a specific address */
19401 if (addr) {
19402 addr = PAGE_ALIGN(addr);
19403- vma = find_vma(mm, addr);
19404- if (TASK_SIZE - len >= addr &&
19405- (!vma || addr + len <= vma->vm_start))
19406- return addr;
19407+ if (TASK_SIZE - len >= addr) {
19408+ vma = find_vma(mm, addr);
19409+ if (check_heap_stack_gap(vma, addr, len))
19410+ return addr;
19411+ }
19412 }
19413
19414 /* check if free_area_cache is useful for us */
19415@@ -240,7 +248,7 @@ try_again:
19416 * return with success:
19417 */
19418 vma = find_vma(mm, addr);
19419- if (!vma || addr+len <= vma->vm_start)
19420+ if (check_heap_stack_gap(vma, addr, len))
19421 /* remember the address as a hint for next time */
19422 return mm->free_area_cache = addr;
19423
19424@@ -249,8 +257,8 @@ try_again:
19425 mm->cached_hole_size = vma->vm_start - addr;
19426
19427 /* try just below the current vma->vm_start */
19428- addr = vma->vm_start-len;
19429- } while (len < vma->vm_start);
19430+ addr = skip_heap_stack_gap(vma, len);
19431+ } while (!IS_ERR_VALUE(addr));
19432
19433 fail:
19434 /*
19435@@ -270,13 +278,21 @@ bottomup:
19436 * can happen with large stack limits and large mmap()
19437 * allocations.
19438 */
19439+ mm->mmap_base = TASK_UNMAPPED_BASE;
19440+
19441+#ifdef CONFIG_PAX_RANDMMAP
19442+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19443+ mm->mmap_base += mm->delta_mmap;
19444+#endif
19445+
19446+ mm->free_area_cache = mm->mmap_base;
19447 mm->cached_hole_size = ~0UL;
19448- mm->free_area_cache = TASK_UNMAPPED_BASE;
19449 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19450 /*
19451 * Restore the topdown base:
19452 */
19453- mm->free_area_cache = mm->mmap_base;
19454+ mm->mmap_base = base;
19455+ mm->free_area_cache = base;
19456 mm->cached_hole_size = ~0UL;
19457
19458 return addr;
19459diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19460index f84fe00..93fe08f 100644
19461--- a/arch/x86/kernel/tboot.c
19462+++ b/arch/x86/kernel/tboot.c
19463@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19464
19465 void tboot_shutdown(u32 shutdown_type)
19466 {
19467- void (*shutdown)(void);
19468+ void (* __noreturn shutdown)(void);
19469
19470 if (!tboot_enabled())
19471 return;
19472@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19473
19474 switch_to_tboot_pt();
19475
19476- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19477+ shutdown = (void *)tboot->shutdown_entry;
19478 shutdown();
19479
19480 /* should not reach here */
19481@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19482 return 0;
19483 }
19484
19485-static atomic_t ap_wfs_count;
19486+static atomic_unchecked_t ap_wfs_count;
19487
19488 static int tboot_wait_for_aps(int num_aps)
19489 {
19490@@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19491 {
19492 switch (action) {
19493 case CPU_DYING:
19494- atomic_inc(&ap_wfs_count);
19495+ atomic_inc_unchecked(&ap_wfs_count);
19496 if (num_online_cpus() == 1)
19497- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19498+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19499 return NOTIFY_BAD;
19500 break;
19501 }
19502@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19503
19504 tboot_create_trampoline();
19505
19506- atomic_set(&ap_wfs_count, 0);
19507+ atomic_set_unchecked(&ap_wfs_count, 0);
19508 register_hotcpu_notifier(&tboot_cpu_notifier);
19509
19510 acpi_os_set_prepare_sleep(&tboot_sleep);
19511diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19512index 24d3c91..d06b473 100644
19513--- a/arch/x86/kernel/time.c
19514+++ b/arch/x86/kernel/time.c
19515@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19516 {
19517 unsigned long pc = instruction_pointer(regs);
19518
19519- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19520+ if (!user_mode(regs) && in_lock_functions(pc)) {
19521 #ifdef CONFIG_FRAME_POINTER
19522- return *(unsigned long *)(regs->bp + sizeof(long));
19523+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19524 #else
19525 unsigned long *sp =
19526 (unsigned long *)kernel_stack_pointer(regs);
19527@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19528 * or above a saved flags. Eflags has bits 22-31 zero,
19529 * kernel addresses don't.
19530 */
19531+
19532+#ifdef CONFIG_PAX_KERNEXEC
19533+ return ktla_ktva(sp[0]);
19534+#else
19535 if (sp[0] >> 22)
19536 return sp[0];
19537 if (sp[1] >> 22)
19538 return sp[1];
19539 #endif
19540+
19541+#endif
19542 }
19543 return pc;
19544 }
19545diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19546index 9d9d2f9..ed344e4 100644
19547--- a/arch/x86/kernel/tls.c
19548+++ b/arch/x86/kernel/tls.c
19549@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19550 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19551 return -EINVAL;
19552
19553+#ifdef CONFIG_PAX_SEGMEXEC
19554+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19555+ return -EINVAL;
19556+#endif
19557+
19558 set_tls_desc(p, idx, &info, 1);
19559
19560 return 0;
19561diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19562index 05b31d9..501d3ba 100644
19563--- a/arch/x86/kernel/traps.c
19564+++ b/arch/x86/kernel/traps.c
19565@@ -67,12 +67,6 @@ asmlinkage int system_call(void);
19566
19567 /* Do we ignore FPU interrupts ? */
19568 char ignore_fpu_irq;
19569-
19570-/*
19571- * The IDT has to be page-aligned to simplify the Pentium
19572- * F0 0F bug workaround.
19573- */
19574-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19575 #endif
19576
19577 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19578@@ -105,13 +99,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19579 }
19580
19581 static void __kprobes
19582-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19583+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19584 long error_code, siginfo_t *info)
19585 {
19586 struct task_struct *tsk = current;
19587
19588 #ifdef CONFIG_X86_32
19589- if (regs->flags & X86_VM_MASK) {
19590+ if (v8086_mode(regs)) {
19591 /*
19592 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19593 * On nmi (interrupt 2), do_trap should not be called.
19594@@ -122,7 +116,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19595 }
19596 #endif
19597
19598- if (!user_mode(regs))
19599+ if (!user_mode_novm(regs))
19600 goto kernel_trap;
19601
19602 #ifdef CONFIG_X86_32
19603@@ -145,7 +139,7 @@ trap_signal:
19604 printk_ratelimit()) {
19605 printk(KERN_INFO
19606 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19607- tsk->comm, tsk->pid, str,
19608+ tsk->comm, task_pid_nr(tsk), str,
19609 regs->ip, regs->sp, error_code);
19610 print_vma_addr(" in ", regs->ip);
19611 printk("\n");
19612@@ -162,8 +156,20 @@ kernel_trap:
19613 if (!fixup_exception(regs)) {
19614 tsk->thread.error_code = error_code;
19615 tsk->thread.trap_nr = trapnr;
19616+
19617+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19618+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19619+ str = "PAX: suspicious stack segment fault";
19620+#endif
19621+
19622 die(str, regs, error_code);
19623 }
19624+
19625+#ifdef CONFIG_PAX_REFCOUNT
19626+ if (trapnr == 4)
19627+ pax_report_refcount_overflow(regs);
19628+#endif
19629+
19630 return;
19631
19632 #ifdef CONFIG_X86_32
19633@@ -256,14 +262,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19634 conditional_sti(regs);
19635
19636 #ifdef CONFIG_X86_32
19637- if (regs->flags & X86_VM_MASK)
19638+ if (v8086_mode(regs))
19639 goto gp_in_vm86;
19640 #endif
19641
19642 tsk = current;
19643- if (!user_mode(regs))
19644+ if (!user_mode_novm(regs))
19645 goto gp_in_kernel;
19646
19647+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19648+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19649+ struct mm_struct *mm = tsk->mm;
19650+ unsigned long limit;
19651+
19652+ down_write(&mm->mmap_sem);
19653+ limit = mm->context.user_cs_limit;
19654+ if (limit < TASK_SIZE) {
19655+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19656+ up_write(&mm->mmap_sem);
19657+ return;
19658+ }
19659+ up_write(&mm->mmap_sem);
19660+ }
19661+#endif
19662+
19663 tsk->thread.error_code = error_code;
19664 tsk->thread.trap_nr = X86_TRAP_GP;
19665
19666@@ -296,6 +318,13 @@ gp_in_kernel:
19667 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19668 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19669 return;
19670+
19671+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19672+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19673+ die("PAX: suspicious general protection fault", regs, error_code);
19674+ else
19675+#endif
19676+
19677 die("general protection fault", regs, error_code);
19678 }
19679
19680@@ -431,7 +460,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19681 /* It's safe to allow irq's after DR6 has been saved */
19682 preempt_conditional_sti(regs);
19683
19684- if (regs->flags & X86_VM_MASK) {
19685+ if (v8086_mode(regs)) {
19686 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19687 X86_TRAP_DB);
19688 preempt_conditional_cli(regs);
19689@@ -446,7 +475,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19690 * We already checked v86 mode above, so we can check for kernel mode
19691 * by just checking the CPL of CS.
19692 */
19693- if ((dr6 & DR_STEP) && !user_mode(regs)) {
19694+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19695 tsk->thread.debugreg6 &= ~DR_STEP;
19696 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19697 regs->flags &= ~X86_EFLAGS_TF;
19698@@ -477,7 +506,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19699 return;
19700 conditional_sti(regs);
19701
19702- if (!user_mode_vm(regs))
19703+ if (!user_mode(regs))
19704 {
19705 if (!fixup_exception(regs)) {
19706 task->thread.error_code = error_code;
19707diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19708index dc4e910..c9dedab 100644
19709--- a/arch/x86/kernel/uprobes.c
19710+++ b/arch/x86/kernel/uprobes.c
19711@@ -606,7 +606,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19712 int ret = NOTIFY_DONE;
19713
19714 /* We are only interested in userspace traps */
19715- if (regs && !user_mode_vm(regs))
19716+ if (regs && !user_mode(regs))
19717 return NOTIFY_DONE;
19718
19719 switch (val) {
19720diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19721index b9242ba..50c5edd 100644
19722--- a/arch/x86/kernel/verify_cpu.S
19723+++ b/arch/x86/kernel/verify_cpu.S
19724@@ -20,6 +20,7 @@
19725 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19726 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19727 * arch/x86/kernel/head_32.S: processor startup
19728+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19729 *
19730 * verify_cpu, returns the status of longmode and SSE in register %eax.
19731 * 0: Success 1: Failure
19732diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19733index 255f58a..5e91150 100644
19734--- a/arch/x86/kernel/vm86_32.c
19735+++ b/arch/x86/kernel/vm86_32.c
19736@@ -41,6 +41,7 @@
19737 #include <linux/ptrace.h>
19738 #include <linux/audit.h>
19739 #include <linux/stddef.h>
19740+#include <linux/grsecurity.h>
19741
19742 #include <asm/uaccess.h>
19743 #include <asm/io.h>
19744@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19745 do_exit(SIGSEGV);
19746 }
19747
19748- tss = &per_cpu(init_tss, get_cpu());
19749+ tss = init_tss + get_cpu();
19750 current->thread.sp0 = current->thread.saved_sp0;
19751 current->thread.sysenter_cs = __KERNEL_CS;
19752 load_sp0(tss, &current->thread);
19753@@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19754 struct task_struct *tsk;
19755 int tmp, ret = -EPERM;
19756
19757+#ifdef CONFIG_GRKERNSEC_VM86
19758+ if (!capable(CAP_SYS_RAWIO)) {
19759+ gr_handle_vm86();
19760+ goto out;
19761+ }
19762+#endif
19763+
19764 tsk = current;
19765 if (tsk->thread.saved_sp0)
19766 goto out;
19767@@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19768 int tmp, ret;
19769 struct vm86plus_struct __user *v86;
19770
19771+#ifdef CONFIG_GRKERNSEC_VM86
19772+ if (!capable(CAP_SYS_RAWIO)) {
19773+ gr_handle_vm86();
19774+ ret = -EPERM;
19775+ goto out;
19776+ }
19777+#endif
19778+
19779 tsk = current;
19780 switch (cmd) {
19781 case VM86_REQUEST_IRQ:
19782@@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19783 tsk->thread.saved_fs = info->regs32->fs;
19784 tsk->thread.saved_gs = get_user_gs(info->regs32);
19785
19786- tss = &per_cpu(init_tss, get_cpu());
19787+ tss = init_tss + get_cpu();
19788 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19789 if (cpu_has_sep)
19790 tsk->thread.sysenter_cs = 0;
19791@@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19792 goto cannot_handle;
19793 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19794 goto cannot_handle;
19795- intr_ptr = (unsigned long __user *) (i << 2);
19796+ intr_ptr = (__force unsigned long __user *) (i << 2);
19797 if (get_user(segoffs, intr_ptr))
19798 goto cannot_handle;
19799 if ((segoffs >> 16) == BIOSSEG)
19800diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19801index 22a1530..8fbaaad 100644
19802--- a/arch/x86/kernel/vmlinux.lds.S
19803+++ b/arch/x86/kernel/vmlinux.lds.S
19804@@ -26,6 +26,13 @@
19805 #include <asm/page_types.h>
19806 #include <asm/cache.h>
19807 #include <asm/boot.h>
19808+#include <asm/segment.h>
19809+
19810+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19811+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19812+#else
19813+#define __KERNEL_TEXT_OFFSET 0
19814+#endif
19815
19816 #undef i386 /* in case the preprocessor is a 32bit one */
19817
19818@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19819
19820 PHDRS {
19821 text PT_LOAD FLAGS(5); /* R_E */
19822+#ifdef CONFIG_X86_32
19823+ module PT_LOAD FLAGS(5); /* R_E */
19824+#endif
19825+#ifdef CONFIG_XEN
19826+ rodata PT_LOAD FLAGS(5); /* R_E */
19827+#else
19828+ rodata PT_LOAD FLAGS(4); /* R__ */
19829+#endif
19830 data PT_LOAD FLAGS(6); /* RW_ */
19831-#ifdef CONFIG_X86_64
19832+ init.begin PT_LOAD FLAGS(6); /* RW_ */
19833 #ifdef CONFIG_SMP
19834 percpu PT_LOAD FLAGS(6); /* RW_ */
19835 #endif
19836+ text.init PT_LOAD FLAGS(5); /* R_E */
19837+ text.exit PT_LOAD FLAGS(5); /* R_E */
19838 init PT_LOAD FLAGS(7); /* RWE */
19839-#endif
19840 note PT_NOTE FLAGS(0); /* ___ */
19841 }
19842
19843 SECTIONS
19844 {
19845 #ifdef CONFIG_X86_32
19846- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19847- phys_startup_32 = startup_32 - LOAD_OFFSET;
19848+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19849 #else
19850- . = __START_KERNEL;
19851- phys_startup_64 = startup_64 - LOAD_OFFSET;
19852+ . = __START_KERNEL;
19853 #endif
19854
19855 /* Text and read-only data */
19856- .text : AT(ADDR(.text) - LOAD_OFFSET) {
19857- _text = .;
19858+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19859 /* bootstrapping code */
19860+#ifdef CONFIG_X86_32
19861+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19862+#else
19863+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19864+#endif
19865+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19866+ _text = .;
19867 HEAD_TEXT
19868 #ifdef CONFIG_X86_32
19869 . = ALIGN(PAGE_SIZE);
19870@@ -108,13 +128,48 @@ SECTIONS
19871 IRQENTRY_TEXT
19872 *(.fixup)
19873 *(.gnu.warning)
19874- /* End of text section */
19875- _etext = .;
19876 } :text = 0x9090
19877
19878- NOTES :text :note
19879+ . += __KERNEL_TEXT_OFFSET;
19880
19881- EXCEPTION_TABLE(16) :text = 0x9090
19882+#ifdef CONFIG_X86_32
19883+ . = ALIGN(PAGE_SIZE);
19884+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19885+
19886+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19887+ MODULES_EXEC_VADDR = .;
19888+ BYTE(0)
19889+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19890+ . = ALIGN(HPAGE_SIZE) - 1;
19891+ MODULES_EXEC_END = .;
19892+#endif
19893+
19894+ } :module
19895+#endif
19896+
19897+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19898+ /* End of text section */
19899+ BYTE(0)
19900+ _etext = . - __KERNEL_TEXT_OFFSET;
19901+ }
19902+
19903+#ifdef CONFIG_X86_32
19904+ . = ALIGN(PAGE_SIZE);
19905+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19906+ *(.idt)
19907+ . = ALIGN(PAGE_SIZE);
19908+ *(.empty_zero_page)
19909+ *(.initial_pg_fixmap)
19910+ *(.initial_pg_pmd)
19911+ *(.initial_page_table)
19912+ *(.swapper_pg_dir)
19913+ } :rodata
19914+#endif
19915+
19916+ . = ALIGN(PAGE_SIZE);
19917+ NOTES :rodata :note
19918+
19919+ EXCEPTION_TABLE(16) :rodata
19920
19921 #if defined(CONFIG_DEBUG_RODATA)
19922 /* .text should occupy whole number of pages */
19923@@ -126,16 +181,20 @@ SECTIONS
19924
19925 /* Data */
19926 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19927+
19928+#ifdef CONFIG_PAX_KERNEXEC
19929+ . = ALIGN(HPAGE_SIZE);
19930+#else
19931+ . = ALIGN(PAGE_SIZE);
19932+#endif
19933+
19934 /* Start of data section */
19935 _sdata = .;
19936
19937 /* init_task */
19938 INIT_TASK_DATA(THREAD_SIZE)
19939
19940-#ifdef CONFIG_X86_32
19941- /* 32 bit has nosave before _edata */
19942 NOSAVE_DATA
19943-#endif
19944
19945 PAGE_ALIGNED_DATA(PAGE_SIZE)
19946
19947@@ -176,12 +235,19 @@ SECTIONS
19948 #endif /* CONFIG_X86_64 */
19949
19950 /* Init code and data - will be freed after init */
19951- . = ALIGN(PAGE_SIZE);
19952 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19953+ BYTE(0)
19954+
19955+#ifdef CONFIG_PAX_KERNEXEC
19956+ . = ALIGN(HPAGE_SIZE);
19957+#else
19958+ . = ALIGN(PAGE_SIZE);
19959+#endif
19960+
19961 __init_begin = .; /* paired with __init_end */
19962- }
19963+ } :init.begin
19964
19965-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19966+#ifdef CONFIG_SMP
19967 /*
19968 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19969 * output PHDR, so the next output section - .init.text - should
19970@@ -190,12 +256,27 @@ SECTIONS
19971 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
19972 #endif
19973
19974- INIT_TEXT_SECTION(PAGE_SIZE)
19975-#ifdef CONFIG_X86_64
19976- :init
19977-#endif
19978+ . = ALIGN(PAGE_SIZE);
19979+ init_begin = .;
19980+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
19981+ VMLINUX_SYMBOL(_sinittext) = .;
19982+ INIT_TEXT
19983+ VMLINUX_SYMBOL(_einittext) = .;
19984+ . = ALIGN(PAGE_SIZE);
19985+ } :text.init
19986
19987- INIT_DATA_SECTION(16)
19988+ /*
19989+ * .exit.text is discard at runtime, not link time, to deal with
19990+ * references from .altinstructions and .eh_frame
19991+ */
19992+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19993+ EXIT_TEXT
19994+ . = ALIGN(16);
19995+ } :text.exit
19996+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
19997+
19998+ . = ALIGN(PAGE_SIZE);
19999+ INIT_DATA_SECTION(16) :init
20000
20001 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20002 __x86_cpu_dev_start = .;
20003@@ -257,19 +338,12 @@ SECTIONS
20004 }
20005
20006 . = ALIGN(8);
20007- /*
20008- * .exit.text is discard at runtime, not link time, to deal with
20009- * references from .altinstructions and .eh_frame
20010- */
20011- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20012- EXIT_TEXT
20013- }
20014
20015 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20016 EXIT_DATA
20017 }
20018
20019-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20020+#ifndef CONFIG_SMP
20021 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20022 #endif
20023
20024@@ -288,16 +362,10 @@ SECTIONS
20025 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20026 __smp_locks = .;
20027 *(.smp_locks)
20028- . = ALIGN(PAGE_SIZE);
20029 __smp_locks_end = .;
20030+ . = ALIGN(PAGE_SIZE);
20031 }
20032
20033-#ifdef CONFIG_X86_64
20034- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20035- NOSAVE_DATA
20036- }
20037-#endif
20038-
20039 /* BSS */
20040 . = ALIGN(PAGE_SIZE);
20041 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20042@@ -313,6 +381,7 @@ SECTIONS
20043 __brk_base = .;
20044 . += 64 * 1024; /* 64k alignment slop space */
20045 *(.brk_reservation) /* areas brk users have reserved */
20046+ . = ALIGN(HPAGE_SIZE);
20047 __brk_limit = .;
20048 }
20049
20050@@ -339,13 +408,12 @@ SECTIONS
20051 * for the boot processor.
20052 */
20053 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20054-INIT_PER_CPU(gdt_page);
20055 INIT_PER_CPU(irq_stack_union);
20056
20057 /*
20058 * Build-time check on the image size:
20059 */
20060-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20061+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20062 "kernel image bigger than KERNEL_IMAGE_SIZE");
20063
20064 #ifdef CONFIG_SMP
20065diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20066index 5db36ca..2938af9 100644
20067--- a/arch/x86/kernel/vsyscall_64.c
20068+++ b/arch/x86/kernel/vsyscall_64.c
20069@@ -54,15 +54,13 @@
20070 DEFINE_VVAR(int, vgetcpu_mode);
20071 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20072
20073-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20074+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20075
20076 static int __init vsyscall_setup(char *str)
20077 {
20078 if (str) {
20079 if (!strcmp("emulate", str))
20080 vsyscall_mode = EMULATE;
20081- else if (!strcmp("native", str))
20082- vsyscall_mode = NATIVE;
20083 else if (!strcmp("none", str))
20084 vsyscall_mode = NONE;
20085 else
20086@@ -309,8 +307,7 @@ done:
20087 return true;
20088
20089 sigsegv:
20090- force_sig(SIGSEGV, current);
20091- return true;
20092+ do_group_exit(SIGKILL);
20093 }
20094
20095 /*
20096@@ -363,10 +360,7 @@ void __init map_vsyscall(void)
20097 extern char __vvar_page;
20098 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20099
20100- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20101- vsyscall_mode == NATIVE
20102- ? PAGE_KERNEL_VSYSCALL
20103- : PAGE_KERNEL_VVAR);
20104+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20105 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20106 (unsigned long)VSYSCALL_START);
20107
20108diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20109index 9796c2f..f686fbf 100644
20110--- a/arch/x86/kernel/x8664_ksyms_64.c
20111+++ b/arch/x86/kernel/x8664_ksyms_64.c
20112@@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20113 EXPORT_SYMBOL(copy_user_generic_string);
20114 EXPORT_SYMBOL(copy_user_generic_unrolled);
20115 EXPORT_SYMBOL(__copy_user_nocache);
20116-EXPORT_SYMBOL(_copy_from_user);
20117-EXPORT_SYMBOL(_copy_to_user);
20118
20119 EXPORT_SYMBOL(copy_page);
20120 EXPORT_SYMBOL(clear_page);
20121diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20122index bd18149..2ea0183 100644
20123--- a/arch/x86/kernel/xsave.c
20124+++ b/arch/x86/kernel/xsave.c
20125@@ -129,7 +129,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20126 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20127 return -EINVAL;
20128
20129- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20130+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20131 fx_sw_user->extended_size -
20132 FP_XSTATE_MAGIC2_SIZE));
20133 if (err)
20134@@ -265,7 +265,7 @@ fx_only:
20135 * the other extended state.
20136 */
20137 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20138- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20139+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20140 }
20141
20142 /*
20143@@ -294,7 +294,7 @@ int restore_i387_xstate(void __user *buf)
20144 if (use_xsave())
20145 err = restore_user_xstate(buf);
20146 else
20147- err = fxrstor_checking((__force struct i387_fxsave_struct *)
20148+ err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20149 buf);
20150 if (unlikely(err)) {
20151 /*
20152diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20153index 7df1c6d..9ea7c79 100644
20154--- a/arch/x86/kvm/cpuid.c
20155+++ b/arch/x86/kvm/cpuid.c
20156@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20157 struct kvm_cpuid2 *cpuid,
20158 struct kvm_cpuid_entry2 __user *entries)
20159 {
20160- int r;
20161+ int r, i;
20162
20163 r = -E2BIG;
20164 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20165 goto out;
20166 r = -EFAULT;
20167- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20168- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20169+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20170 goto out;
20171+ for (i = 0; i < cpuid->nent; ++i) {
20172+ struct kvm_cpuid_entry2 cpuid_entry;
20173+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20174+ goto out;
20175+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
20176+ }
20177 vcpu->arch.cpuid_nent = cpuid->nent;
20178 kvm_apic_set_version(vcpu);
20179 kvm_x86_ops->cpuid_update(vcpu);
20180@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20181 struct kvm_cpuid2 *cpuid,
20182 struct kvm_cpuid_entry2 __user *entries)
20183 {
20184- int r;
20185+ int r, i;
20186
20187 r = -E2BIG;
20188 if (cpuid->nent < vcpu->arch.cpuid_nent)
20189 goto out;
20190 r = -EFAULT;
20191- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20192- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20193+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20194 goto out;
20195+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20196+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20197+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20198+ goto out;
20199+ }
20200 return 0;
20201
20202 out:
20203diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20204index f95d242..3b49a90 100644
20205--- a/arch/x86/kvm/emulate.c
20206+++ b/arch/x86/kvm/emulate.c
20207@@ -256,6 +256,7 @@ struct gprefix {
20208
20209 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20210 do { \
20211+ unsigned long _tmp; \
20212 __asm__ __volatile__ ( \
20213 _PRE_EFLAGS("0", "4", "2") \
20214 _op _suffix " %"_x"3,%1; " \
20215@@ -270,8 +271,6 @@ struct gprefix {
20216 /* Raw emulation: instruction has two explicit operands. */
20217 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20218 do { \
20219- unsigned long _tmp; \
20220- \
20221 switch ((ctxt)->dst.bytes) { \
20222 case 2: \
20223 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20224@@ -287,7 +286,6 @@ struct gprefix {
20225
20226 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20227 do { \
20228- unsigned long _tmp; \
20229 switch ((ctxt)->dst.bytes) { \
20230 case 1: \
20231 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20232diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20233index 93c1574..d6097dc 100644
20234--- a/arch/x86/kvm/lapic.c
20235+++ b/arch/x86/kvm/lapic.c
20236@@ -54,7 +54,7 @@
20237 #define APIC_BUS_CYCLE_NS 1
20238
20239 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20240-#define apic_debug(fmt, arg...)
20241+#define apic_debug(fmt, arg...) do {} while (0)
20242
20243 #define APIC_LVT_NUM 6
20244 /* 14 is the version for Xeon and Pentium 8.4.8*/
20245diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20246index 34f9709..8eca2d5 100644
20247--- a/arch/x86/kvm/paging_tmpl.h
20248+++ b/arch/x86/kvm/paging_tmpl.h
20249@@ -197,7 +197,7 @@ retry_walk:
20250 if (unlikely(kvm_is_error_hva(host_addr)))
20251 goto error;
20252
20253- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20254+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20255 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20256 goto error;
20257
20258diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20259index f75af40..285b18f 100644
20260--- a/arch/x86/kvm/svm.c
20261+++ b/arch/x86/kvm/svm.c
20262@@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20263 int cpu = raw_smp_processor_id();
20264
20265 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20266+
20267+ pax_open_kernel();
20268 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20269+ pax_close_kernel();
20270+
20271 load_TR_desc();
20272 }
20273
20274@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20275 #endif
20276 #endif
20277
20278+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20279+ __set_fs(current_thread_info()->addr_limit);
20280+#endif
20281+
20282 reload_tss(vcpu);
20283
20284 local_irq_disable();
20285diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20286index 32eb588..19c4fe3 100644
20287--- a/arch/x86/kvm/vmx.c
20288+++ b/arch/x86/kvm/vmx.c
20289@@ -1313,7 +1313,11 @@ static void reload_tss(void)
20290 struct desc_struct *descs;
20291
20292 descs = (void *)gdt->address;
20293+
20294+ pax_open_kernel();
20295 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20296+ pax_close_kernel();
20297+
20298 load_TR_desc();
20299 }
20300
20301@@ -1475,8 +1479,8 @@ static void __vmx_load_host_state(struct vcpu_vmx *vmx)
20302 * The sysexit path does not restore ds/es, so we must set them to
20303 * a reasonable value ourselves.
20304 */
20305- loadsegment(ds, __USER_DS);
20306- loadsegment(es, __USER_DS);
20307+ loadsegment(ds, __KERNEL_DS);
20308+ loadsegment(es, __KERNEL_DS);
20309 #endif
20310 reload_tss();
20311 #ifdef CONFIG_X86_64
20312@@ -2653,8 +2657,11 @@ static __init int hardware_setup(void)
20313 if (!cpu_has_vmx_flexpriority())
20314 flexpriority_enabled = 0;
20315
20316- if (!cpu_has_vmx_tpr_shadow())
20317- kvm_x86_ops->update_cr8_intercept = NULL;
20318+ if (!cpu_has_vmx_tpr_shadow()) {
20319+ pax_open_kernel();
20320+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20321+ pax_close_kernel();
20322+ }
20323
20324 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20325 kvm_disable_largepages();
20326@@ -3680,7 +3687,7 @@ static void vmx_set_constant_host_state(void)
20327 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20328
20329 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20330- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20331+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20332
20333 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20334 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20335@@ -6218,6 +6225,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20336 "jmp .Lkvm_vmx_return \n\t"
20337 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20338 ".Lkvm_vmx_return: "
20339+
20340+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20341+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20342+ ".Lkvm_vmx_return2: "
20343+#endif
20344+
20345 /* Save guest registers, load host registers, keep flags */
20346 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20347 "pop %0 \n\t"
20348@@ -6266,6 +6279,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20349 #endif
20350 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20351 [wordsize]"i"(sizeof(ulong))
20352+
20353+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20354+ ,[cs]"i"(__KERNEL_CS)
20355+#endif
20356+
20357 : "cc", "memory"
20358 , R"ax", R"bx", R"di", R"si"
20359 #ifdef CONFIG_X86_64
20360@@ -6294,6 +6312,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20361 }
20362 }
20363
20364+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20365+
20366+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20367+ loadsegment(fs, __KERNEL_PERCPU);
20368+#endif
20369+
20370+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20371+ __set_fs(current_thread_info()->addr_limit);
20372+#endif
20373+
20374 vmx->loaded_vmcs->launched = 1;
20375
20376 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20377diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20378index be6d549..b0ba2bf 100644
20379--- a/arch/x86/kvm/x86.c
20380+++ b/arch/x86/kvm/x86.c
20381@@ -1357,8 +1357,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20382 {
20383 struct kvm *kvm = vcpu->kvm;
20384 int lm = is_long_mode(vcpu);
20385- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20386- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20387+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20388+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20389 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20390 : kvm->arch.xen_hvm_config.blob_size_32;
20391 u32 page_num = data & ~PAGE_MASK;
20392@@ -2214,6 +2214,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20393 if (n < msr_list.nmsrs)
20394 goto out;
20395 r = -EFAULT;
20396+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20397+ goto out;
20398 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20399 num_msrs_to_save * sizeof(u32)))
20400 goto out;
20401@@ -2339,7 +2341,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20402 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20403 struct kvm_interrupt *irq)
20404 {
20405- if (irq->irq < 0 || irq->irq >= 256)
20406+ if (irq->irq >= 256)
20407 return -EINVAL;
20408 if (irqchip_in_kernel(vcpu->kvm))
20409 return -ENXIO;
20410@@ -4876,7 +4878,7 @@ static void kvm_set_mmio_spte_mask(void)
20411 kvm_mmu_set_mmio_spte_mask(mask);
20412 }
20413
20414-int kvm_arch_init(void *opaque)
20415+int kvm_arch_init(const void *opaque)
20416 {
20417 int r;
20418 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20419diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20420index 642d880..44e0f3f 100644
20421--- a/arch/x86/lguest/boot.c
20422+++ b/arch/x86/lguest/boot.c
20423@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20424 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20425 * Launcher to reboot us.
20426 */
20427-static void lguest_restart(char *reason)
20428+static __noreturn void lguest_restart(char *reason)
20429 {
20430 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20431+ BUG();
20432 }
20433
20434 /*G:050
20435diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20436index 00933d5..3a64af9 100644
20437--- a/arch/x86/lib/atomic64_386_32.S
20438+++ b/arch/x86/lib/atomic64_386_32.S
20439@@ -48,6 +48,10 @@ BEGIN(read)
20440 movl (v), %eax
20441 movl 4(v), %edx
20442 RET_ENDP
20443+BEGIN(read_unchecked)
20444+ movl (v), %eax
20445+ movl 4(v), %edx
20446+RET_ENDP
20447 #undef v
20448
20449 #define v %esi
20450@@ -55,6 +59,10 @@ BEGIN(set)
20451 movl %ebx, (v)
20452 movl %ecx, 4(v)
20453 RET_ENDP
20454+BEGIN(set_unchecked)
20455+ movl %ebx, (v)
20456+ movl %ecx, 4(v)
20457+RET_ENDP
20458 #undef v
20459
20460 #define v %esi
20461@@ -70,6 +78,20 @@ RET_ENDP
20462 BEGIN(add)
20463 addl %eax, (v)
20464 adcl %edx, 4(v)
20465+
20466+#ifdef CONFIG_PAX_REFCOUNT
20467+ jno 0f
20468+ subl %eax, (v)
20469+ sbbl %edx, 4(v)
20470+ int $4
20471+0:
20472+ _ASM_EXTABLE(0b, 0b)
20473+#endif
20474+
20475+RET_ENDP
20476+BEGIN(add_unchecked)
20477+ addl %eax, (v)
20478+ adcl %edx, 4(v)
20479 RET_ENDP
20480 #undef v
20481
20482@@ -77,6 +99,24 @@ RET_ENDP
20483 BEGIN(add_return)
20484 addl (v), %eax
20485 adcl 4(v), %edx
20486+
20487+#ifdef CONFIG_PAX_REFCOUNT
20488+ into
20489+1234:
20490+ _ASM_EXTABLE(1234b, 2f)
20491+#endif
20492+
20493+ movl %eax, (v)
20494+ movl %edx, 4(v)
20495+
20496+#ifdef CONFIG_PAX_REFCOUNT
20497+2:
20498+#endif
20499+
20500+RET_ENDP
20501+BEGIN(add_return_unchecked)
20502+ addl (v), %eax
20503+ adcl 4(v), %edx
20504 movl %eax, (v)
20505 movl %edx, 4(v)
20506 RET_ENDP
20507@@ -86,6 +126,20 @@ RET_ENDP
20508 BEGIN(sub)
20509 subl %eax, (v)
20510 sbbl %edx, 4(v)
20511+
20512+#ifdef CONFIG_PAX_REFCOUNT
20513+ jno 0f
20514+ addl %eax, (v)
20515+ adcl %edx, 4(v)
20516+ int $4
20517+0:
20518+ _ASM_EXTABLE(0b, 0b)
20519+#endif
20520+
20521+RET_ENDP
20522+BEGIN(sub_unchecked)
20523+ subl %eax, (v)
20524+ sbbl %edx, 4(v)
20525 RET_ENDP
20526 #undef v
20527
20528@@ -96,6 +150,27 @@ BEGIN(sub_return)
20529 sbbl $0, %edx
20530 addl (v), %eax
20531 adcl 4(v), %edx
20532+
20533+#ifdef CONFIG_PAX_REFCOUNT
20534+ into
20535+1234:
20536+ _ASM_EXTABLE(1234b, 2f)
20537+#endif
20538+
20539+ movl %eax, (v)
20540+ movl %edx, 4(v)
20541+
20542+#ifdef CONFIG_PAX_REFCOUNT
20543+2:
20544+#endif
20545+
20546+RET_ENDP
20547+BEGIN(sub_return_unchecked)
20548+ negl %edx
20549+ negl %eax
20550+ sbbl $0, %edx
20551+ addl (v), %eax
20552+ adcl 4(v), %edx
20553 movl %eax, (v)
20554 movl %edx, 4(v)
20555 RET_ENDP
20556@@ -105,6 +180,20 @@ RET_ENDP
20557 BEGIN(inc)
20558 addl $1, (v)
20559 adcl $0, 4(v)
20560+
20561+#ifdef CONFIG_PAX_REFCOUNT
20562+ jno 0f
20563+ subl $1, (v)
20564+ sbbl $0, 4(v)
20565+ int $4
20566+0:
20567+ _ASM_EXTABLE(0b, 0b)
20568+#endif
20569+
20570+RET_ENDP
20571+BEGIN(inc_unchecked)
20572+ addl $1, (v)
20573+ adcl $0, 4(v)
20574 RET_ENDP
20575 #undef v
20576
20577@@ -114,6 +203,26 @@ BEGIN(inc_return)
20578 movl 4(v), %edx
20579 addl $1, %eax
20580 adcl $0, %edx
20581+
20582+#ifdef CONFIG_PAX_REFCOUNT
20583+ into
20584+1234:
20585+ _ASM_EXTABLE(1234b, 2f)
20586+#endif
20587+
20588+ movl %eax, (v)
20589+ movl %edx, 4(v)
20590+
20591+#ifdef CONFIG_PAX_REFCOUNT
20592+2:
20593+#endif
20594+
20595+RET_ENDP
20596+BEGIN(inc_return_unchecked)
20597+ movl (v), %eax
20598+ movl 4(v), %edx
20599+ addl $1, %eax
20600+ adcl $0, %edx
20601 movl %eax, (v)
20602 movl %edx, 4(v)
20603 RET_ENDP
20604@@ -123,6 +232,20 @@ RET_ENDP
20605 BEGIN(dec)
20606 subl $1, (v)
20607 sbbl $0, 4(v)
20608+
20609+#ifdef CONFIG_PAX_REFCOUNT
20610+ jno 0f
20611+ addl $1, (v)
20612+ adcl $0, 4(v)
20613+ int $4
20614+0:
20615+ _ASM_EXTABLE(0b, 0b)
20616+#endif
20617+
20618+RET_ENDP
20619+BEGIN(dec_unchecked)
20620+ subl $1, (v)
20621+ sbbl $0, 4(v)
20622 RET_ENDP
20623 #undef v
20624
20625@@ -132,6 +255,26 @@ BEGIN(dec_return)
20626 movl 4(v), %edx
20627 subl $1, %eax
20628 sbbl $0, %edx
20629+
20630+#ifdef CONFIG_PAX_REFCOUNT
20631+ into
20632+1234:
20633+ _ASM_EXTABLE(1234b, 2f)
20634+#endif
20635+
20636+ movl %eax, (v)
20637+ movl %edx, 4(v)
20638+
20639+#ifdef CONFIG_PAX_REFCOUNT
20640+2:
20641+#endif
20642+
20643+RET_ENDP
20644+BEGIN(dec_return_unchecked)
20645+ movl (v), %eax
20646+ movl 4(v), %edx
20647+ subl $1, %eax
20648+ sbbl $0, %edx
20649 movl %eax, (v)
20650 movl %edx, 4(v)
20651 RET_ENDP
20652@@ -143,6 +286,13 @@ BEGIN(add_unless)
20653 adcl %edx, %edi
20654 addl (v), %eax
20655 adcl 4(v), %edx
20656+
20657+#ifdef CONFIG_PAX_REFCOUNT
20658+ into
20659+1234:
20660+ _ASM_EXTABLE(1234b, 2f)
20661+#endif
20662+
20663 cmpl %eax, %ecx
20664 je 3f
20665 1:
20666@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20667 1:
20668 addl $1, %eax
20669 adcl $0, %edx
20670+
20671+#ifdef CONFIG_PAX_REFCOUNT
20672+ into
20673+1234:
20674+ _ASM_EXTABLE(1234b, 2f)
20675+#endif
20676+
20677 movl %eax, (v)
20678 movl %edx, 4(v)
20679 movl $1, %eax
20680@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20681 movl 4(v), %edx
20682 subl $1, %eax
20683 sbbl $0, %edx
20684+
20685+#ifdef CONFIG_PAX_REFCOUNT
20686+ into
20687+1234:
20688+ _ASM_EXTABLE(1234b, 1f)
20689+#endif
20690+
20691 js 1f
20692 movl %eax, (v)
20693 movl %edx, 4(v)
20694diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20695index f5cc9eb..51fa319 100644
20696--- a/arch/x86/lib/atomic64_cx8_32.S
20697+++ b/arch/x86/lib/atomic64_cx8_32.S
20698@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20699 CFI_STARTPROC
20700
20701 read64 %ecx
20702+ pax_force_retaddr
20703 ret
20704 CFI_ENDPROC
20705 ENDPROC(atomic64_read_cx8)
20706
20707+ENTRY(atomic64_read_unchecked_cx8)
20708+ CFI_STARTPROC
20709+
20710+ read64 %ecx
20711+ pax_force_retaddr
20712+ ret
20713+ CFI_ENDPROC
20714+ENDPROC(atomic64_read_unchecked_cx8)
20715+
20716 ENTRY(atomic64_set_cx8)
20717 CFI_STARTPROC
20718
20719@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20720 cmpxchg8b (%esi)
20721 jne 1b
20722
20723+ pax_force_retaddr
20724 ret
20725 CFI_ENDPROC
20726 ENDPROC(atomic64_set_cx8)
20727
20728+ENTRY(atomic64_set_unchecked_cx8)
20729+ CFI_STARTPROC
20730+
20731+1:
20732+/* we don't need LOCK_PREFIX since aligned 64-bit writes
20733+ * are atomic on 586 and newer */
20734+ cmpxchg8b (%esi)
20735+ jne 1b
20736+
20737+ pax_force_retaddr
20738+ ret
20739+ CFI_ENDPROC
20740+ENDPROC(atomic64_set_unchecked_cx8)
20741+
20742 ENTRY(atomic64_xchg_cx8)
20743 CFI_STARTPROC
20744
20745@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20746 cmpxchg8b (%esi)
20747 jne 1b
20748
20749+ pax_force_retaddr
20750 ret
20751 CFI_ENDPROC
20752 ENDPROC(atomic64_xchg_cx8)
20753
20754-.macro addsub_return func ins insc
20755-ENTRY(atomic64_\func\()_return_cx8)
20756+.macro addsub_return func ins insc unchecked=""
20757+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20758 CFI_STARTPROC
20759 SAVE ebp
20760 SAVE ebx
20761@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20762 movl %edx, %ecx
20763 \ins\()l %esi, %ebx
20764 \insc\()l %edi, %ecx
20765+
20766+.ifb \unchecked
20767+#ifdef CONFIG_PAX_REFCOUNT
20768+ into
20769+2:
20770+ _ASM_EXTABLE(2b, 3f)
20771+#endif
20772+.endif
20773+
20774 LOCK_PREFIX
20775 cmpxchg8b (%ebp)
20776 jne 1b
20777-
20778-10:
20779 movl %ebx, %eax
20780 movl %ecx, %edx
20781+
20782+.ifb \unchecked
20783+#ifdef CONFIG_PAX_REFCOUNT
20784+3:
20785+#endif
20786+.endif
20787+
20788 RESTORE edi
20789 RESTORE esi
20790 RESTORE ebx
20791 RESTORE ebp
20792+ pax_force_retaddr
20793 ret
20794 CFI_ENDPROC
20795-ENDPROC(atomic64_\func\()_return_cx8)
20796+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20797 .endm
20798
20799 addsub_return add add adc
20800 addsub_return sub sub sbb
20801+addsub_return add add adc _unchecked
20802+addsub_return sub sub sbb _unchecked
20803
20804-.macro incdec_return func ins insc
20805-ENTRY(atomic64_\func\()_return_cx8)
20806+.macro incdec_return func ins insc unchecked=""
20807+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20808 CFI_STARTPROC
20809 SAVE ebx
20810
20811@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20812 movl %edx, %ecx
20813 \ins\()l $1, %ebx
20814 \insc\()l $0, %ecx
20815+
20816+.ifb \unchecked
20817+#ifdef CONFIG_PAX_REFCOUNT
20818+ into
20819+2:
20820+ _ASM_EXTABLE(2b, 3f)
20821+#endif
20822+.endif
20823+
20824 LOCK_PREFIX
20825 cmpxchg8b (%esi)
20826 jne 1b
20827
20828-10:
20829 movl %ebx, %eax
20830 movl %ecx, %edx
20831+
20832+.ifb \unchecked
20833+#ifdef CONFIG_PAX_REFCOUNT
20834+3:
20835+#endif
20836+.endif
20837+
20838 RESTORE ebx
20839+ pax_force_retaddr
20840 ret
20841 CFI_ENDPROC
20842-ENDPROC(atomic64_\func\()_return_cx8)
20843+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20844 .endm
20845
20846 incdec_return inc add adc
20847 incdec_return dec sub sbb
20848+incdec_return inc add adc _unchecked
20849+incdec_return dec sub sbb _unchecked
20850
20851 ENTRY(atomic64_dec_if_positive_cx8)
20852 CFI_STARTPROC
20853@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20854 movl %edx, %ecx
20855 subl $1, %ebx
20856 sbb $0, %ecx
20857+
20858+#ifdef CONFIG_PAX_REFCOUNT
20859+ into
20860+1234:
20861+ _ASM_EXTABLE(1234b, 2f)
20862+#endif
20863+
20864 js 2f
20865 LOCK_PREFIX
20866 cmpxchg8b (%esi)
20867@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20868 movl %ebx, %eax
20869 movl %ecx, %edx
20870 RESTORE ebx
20871+ pax_force_retaddr
20872 ret
20873 CFI_ENDPROC
20874 ENDPROC(atomic64_dec_if_positive_cx8)
20875@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
20876 movl %edx, %ecx
20877 addl %ebp, %ebx
20878 adcl %edi, %ecx
20879+
20880+#ifdef CONFIG_PAX_REFCOUNT
20881+ into
20882+1234:
20883+ _ASM_EXTABLE(1234b, 3f)
20884+#endif
20885+
20886 LOCK_PREFIX
20887 cmpxchg8b (%esi)
20888 jne 1b
20889@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
20890 CFI_ADJUST_CFA_OFFSET -8
20891 RESTORE ebx
20892 RESTORE ebp
20893+ pax_force_retaddr
20894 ret
20895 4:
20896 cmpl %edx, 4(%esp)
20897@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20898 xorl %ecx, %ecx
20899 addl $1, %ebx
20900 adcl %edx, %ecx
20901+
20902+#ifdef CONFIG_PAX_REFCOUNT
20903+ into
20904+1234:
20905+ _ASM_EXTABLE(1234b, 3f)
20906+#endif
20907+
20908 LOCK_PREFIX
20909 cmpxchg8b (%esi)
20910 jne 1b
20911@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
20912 movl $1, %eax
20913 3:
20914 RESTORE ebx
20915+ pax_force_retaddr
20916 ret
20917 CFI_ENDPROC
20918 ENDPROC(atomic64_inc_not_zero_cx8)
20919diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
20920index 2af5df3..62b1a5a 100644
20921--- a/arch/x86/lib/checksum_32.S
20922+++ b/arch/x86/lib/checksum_32.S
20923@@ -29,7 +29,8 @@
20924 #include <asm/dwarf2.h>
20925 #include <asm/errno.h>
20926 #include <asm/asm.h>
20927-
20928+#include <asm/segment.h>
20929+
20930 /*
20931 * computes a partial checksum, e.g. for TCP/UDP fragments
20932 */
20933@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
20934
20935 #define ARGBASE 16
20936 #define FP 12
20937-
20938-ENTRY(csum_partial_copy_generic)
20939+
20940+ENTRY(csum_partial_copy_generic_to_user)
20941 CFI_STARTPROC
20942+
20943+#ifdef CONFIG_PAX_MEMORY_UDEREF
20944+ pushl_cfi %gs
20945+ popl_cfi %es
20946+ jmp csum_partial_copy_generic
20947+#endif
20948+
20949+ENTRY(csum_partial_copy_generic_from_user)
20950+
20951+#ifdef CONFIG_PAX_MEMORY_UDEREF
20952+ pushl_cfi %gs
20953+ popl_cfi %ds
20954+#endif
20955+
20956+ENTRY(csum_partial_copy_generic)
20957 subl $4,%esp
20958 CFI_ADJUST_CFA_OFFSET 4
20959 pushl_cfi %edi
20960@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
20961 jmp 4f
20962 SRC(1: movw (%esi), %bx )
20963 addl $2, %esi
20964-DST( movw %bx, (%edi) )
20965+DST( movw %bx, %es:(%edi) )
20966 addl $2, %edi
20967 addw %bx, %ax
20968 adcl $0, %eax
20969@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
20970 SRC(1: movl (%esi), %ebx )
20971 SRC( movl 4(%esi), %edx )
20972 adcl %ebx, %eax
20973-DST( movl %ebx, (%edi) )
20974+DST( movl %ebx, %es:(%edi) )
20975 adcl %edx, %eax
20976-DST( movl %edx, 4(%edi) )
20977+DST( movl %edx, %es:4(%edi) )
20978
20979 SRC( movl 8(%esi), %ebx )
20980 SRC( movl 12(%esi), %edx )
20981 adcl %ebx, %eax
20982-DST( movl %ebx, 8(%edi) )
20983+DST( movl %ebx, %es:8(%edi) )
20984 adcl %edx, %eax
20985-DST( movl %edx, 12(%edi) )
20986+DST( movl %edx, %es:12(%edi) )
20987
20988 SRC( movl 16(%esi), %ebx )
20989 SRC( movl 20(%esi), %edx )
20990 adcl %ebx, %eax
20991-DST( movl %ebx, 16(%edi) )
20992+DST( movl %ebx, %es:16(%edi) )
20993 adcl %edx, %eax
20994-DST( movl %edx, 20(%edi) )
20995+DST( movl %edx, %es:20(%edi) )
20996
20997 SRC( movl 24(%esi), %ebx )
20998 SRC( movl 28(%esi), %edx )
20999 adcl %ebx, %eax
21000-DST( movl %ebx, 24(%edi) )
21001+DST( movl %ebx, %es:24(%edi) )
21002 adcl %edx, %eax
21003-DST( movl %edx, 28(%edi) )
21004+DST( movl %edx, %es:28(%edi) )
21005
21006 lea 32(%esi), %esi
21007 lea 32(%edi), %edi
21008@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21009 shrl $2, %edx # This clears CF
21010 SRC(3: movl (%esi), %ebx )
21011 adcl %ebx, %eax
21012-DST( movl %ebx, (%edi) )
21013+DST( movl %ebx, %es:(%edi) )
21014 lea 4(%esi), %esi
21015 lea 4(%edi), %edi
21016 dec %edx
21017@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21018 jb 5f
21019 SRC( movw (%esi), %cx )
21020 leal 2(%esi), %esi
21021-DST( movw %cx, (%edi) )
21022+DST( movw %cx, %es:(%edi) )
21023 leal 2(%edi), %edi
21024 je 6f
21025 shll $16,%ecx
21026 SRC(5: movb (%esi), %cl )
21027-DST( movb %cl, (%edi) )
21028+DST( movb %cl, %es:(%edi) )
21029 6: addl %ecx, %eax
21030 adcl $0, %eax
21031 7:
21032@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21033
21034 6001:
21035 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21036- movl $-EFAULT, (%ebx)
21037+ movl $-EFAULT, %ss:(%ebx)
21038
21039 # zero the complete destination - computing the rest
21040 # is too much work
21041@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21042
21043 6002:
21044 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21045- movl $-EFAULT,(%ebx)
21046+ movl $-EFAULT,%ss:(%ebx)
21047 jmp 5000b
21048
21049 .previous
21050
21051+ pushl_cfi %ss
21052+ popl_cfi %ds
21053+ pushl_cfi %ss
21054+ popl_cfi %es
21055 popl_cfi %ebx
21056 CFI_RESTORE ebx
21057 popl_cfi %esi
21058@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21059 popl_cfi %ecx # equivalent to addl $4,%esp
21060 ret
21061 CFI_ENDPROC
21062-ENDPROC(csum_partial_copy_generic)
21063+ENDPROC(csum_partial_copy_generic_to_user)
21064
21065 #else
21066
21067 /* Version for PentiumII/PPro */
21068
21069 #define ROUND1(x) \
21070+ nop; nop; nop; \
21071 SRC(movl x(%esi), %ebx ) ; \
21072 addl %ebx, %eax ; \
21073- DST(movl %ebx, x(%edi) ) ;
21074+ DST(movl %ebx, %es:x(%edi)) ;
21075
21076 #define ROUND(x) \
21077+ nop; nop; nop; \
21078 SRC(movl x(%esi), %ebx ) ; \
21079 adcl %ebx, %eax ; \
21080- DST(movl %ebx, x(%edi) ) ;
21081+ DST(movl %ebx, %es:x(%edi)) ;
21082
21083 #define ARGBASE 12
21084-
21085-ENTRY(csum_partial_copy_generic)
21086+
21087+ENTRY(csum_partial_copy_generic_to_user)
21088 CFI_STARTPROC
21089+
21090+#ifdef CONFIG_PAX_MEMORY_UDEREF
21091+ pushl_cfi %gs
21092+ popl_cfi %es
21093+ jmp csum_partial_copy_generic
21094+#endif
21095+
21096+ENTRY(csum_partial_copy_generic_from_user)
21097+
21098+#ifdef CONFIG_PAX_MEMORY_UDEREF
21099+ pushl_cfi %gs
21100+ popl_cfi %ds
21101+#endif
21102+
21103+ENTRY(csum_partial_copy_generic)
21104 pushl_cfi %ebx
21105 CFI_REL_OFFSET ebx, 0
21106 pushl_cfi %edi
21107@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21108 subl %ebx, %edi
21109 lea -1(%esi),%edx
21110 andl $-32,%edx
21111- lea 3f(%ebx,%ebx), %ebx
21112+ lea 3f(%ebx,%ebx,2), %ebx
21113 testl %esi, %esi
21114 jmp *%ebx
21115 1: addl $64,%esi
21116@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21117 jb 5f
21118 SRC( movw (%esi), %dx )
21119 leal 2(%esi), %esi
21120-DST( movw %dx, (%edi) )
21121+DST( movw %dx, %es:(%edi) )
21122 leal 2(%edi), %edi
21123 je 6f
21124 shll $16,%edx
21125 5:
21126 SRC( movb (%esi), %dl )
21127-DST( movb %dl, (%edi) )
21128+DST( movb %dl, %es:(%edi) )
21129 6: addl %edx, %eax
21130 adcl $0, %eax
21131 7:
21132 .section .fixup, "ax"
21133 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21134- movl $-EFAULT, (%ebx)
21135+ movl $-EFAULT, %ss:(%ebx)
21136 # zero the complete destination (computing the rest is too much work)
21137 movl ARGBASE+8(%esp),%edi # dst
21138 movl ARGBASE+12(%esp),%ecx # len
21139@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21140 rep; stosb
21141 jmp 7b
21142 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21143- movl $-EFAULT, (%ebx)
21144+ movl $-EFAULT, %ss:(%ebx)
21145 jmp 7b
21146 .previous
21147
21148+#ifdef CONFIG_PAX_MEMORY_UDEREF
21149+ pushl_cfi %ss
21150+ popl_cfi %ds
21151+ pushl_cfi %ss
21152+ popl_cfi %es
21153+#endif
21154+
21155 popl_cfi %esi
21156 CFI_RESTORE esi
21157 popl_cfi %edi
21158@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21159 CFI_RESTORE ebx
21160 ret
21161 CFI_ENDPROC
21162-ENDPROC(csum_partial_copy_generic)
21163+ENDPROC(csum_partial_copy_generic_to_user)
21164
21165 #undef ROUND
21166 #undef ROUND1
21167diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21168index f2145cf..cea889d 100644
21169--- a/arch/x86/lib/clear_page_64.S
21170+++ b/arch/x86/lib/clear_page_64.S
21171@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21172 movl $4096/8,%ecx
21173 xorl %eax,%eax
21174 rep stosq
21175+ pax_force_retaddr
21176 ret
21177 CFI_ENDPROC
21178 ENDPROC(clear_page_c)
21179@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21180 movl $4096,%ecx
21181 xorl %eax,%eax
21182 rep stosb
21183+ pax_force_retaddr
21184 ret
21185 CFI_ENDPROC
21186 ENDPROC(clear_page_c_e)
21187@@ -43,6 +45,7 @@ ENTRY(clear_page)
21188 leaq 64(%rdi),%rdi
21189 jnz .Lloop
21190 nop
21191+ pax_force_retaddr
21192 ret
21193 CFI_ENDPROC
21194 .Lclear_page_end:
21195@@ -58,7 +61,7 @@ ENDPROC(clear_page)
21196
21197 #include <asm/cpufeature.h>
21198
21199- .section .altinstr_replacement,"ax"
21200+ .section .altinstr_replacement,"a"
21201 1: .byte 0xeb /* jmp <disp8> */
21202 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21203 2: .byte 0xeb /* jmp <disp8> */
21204diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21205index 1e572c5..2a162cd 100644
21206--- a/arch/x86/lib/cmpxchg16b_emu.S
21207+++ b/arch/x86/lib/cmpxchg16b_emu.S
21208@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21209
21210 popf
21211 mov $1, %al
21212+ pax_force_retaddr
21213 ret
21214
21215 not_same:
21216 popf
21217 xor %al,%al
21218+ pax_force_retaddr
21219 ret
21220
21221 CFI_ENDPROC
21222diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21223index 6b34d04..dccb07f 100644
21224--- a/arch/x86/lib/copy_page_64.S
21225+++ b/arch/x86/lib/copy_page_64.S
21226@@ -9,6 +9,7 @@ copy_page_c:
21227 CFI_STARTPROC
21228 movl $4096/8,%ecx
21229 rep movsq
21230+ pax_force_retaddr
21231 ret
21232 CFI_ENDPROC
21233 ENDPROC(copy_page_c)
21234@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21235
21236 ENTRY(copy_page)
21237 CFI_STARTPROC
21238- subq $2*8,%rsp
21239- CFI_ADJUST_CFA_OFFSET 2*8
21240+ subq $3*8,%rsp
21241+ CFI_ADJUST_CFA_OFFSET 3*8
21242 movq %rbx,(%rsp)
21243 CFI_REL_OFFSET rbx, 0
21244 movq %r12,1*8(%rsp)
21245 CFI_REL_OFFSET r12, 1*8
21246+ movq %r13,2*8(%rsp)
21247+ CFI_REL_OFFSET r13, 2*8
21248
21249 movl $(4096/64)-5,%ecx
21250 .p2align 4
21251@@ -37,7 +40,7 @@ ENTRY(copy_page)
21252 movq 16 (%rsi), %rdx
21253 movq 24 (%rsi), %r8
21254 movq 32 (%rsi), %r9
21255- movq 40 (%rsi), %r10
21256+ movq 40 (%rsi), %r13
21257 movq 48 (%rsi), %r11
21258 movq 56 (%rsi), %r12
21259
21260@@ -48,7 +51,7 @@ ENTRY(copy_page)
21261 movq %rdx, 16 (%rdi)
21262 movq %r8, 24 (%rdi)
21263 movq %r9, 32 (%rdi)
21264- movq %r10, 40 (%rdi)
21265+ movq %r13, 40 (%rdi)
21266 movq %r11, 48 (%rdi)
21267 movq %r12, 56 (%rdi)
21268
21269@@ -67,7 +70,7 @@ ENTRY(copy_page)
21270 movq 16 (%rsi), %rdx
21271 movq 24 (%rsi), %r8
21272 movq 32 (%rsi), %r9
21273- movq 40 (%rsi), %r10
21274+ movq 40 (%rsi), %r13
21275 movq 48 (%rsi), %r11
21276 movq 56 (%rsi), %r12
21277
21278@@ -76,7 +79,7 @@ ENTRY(copy_page)
21279 movq %rdx, 16 (%rdi)
21280 movq %r8, 24 (%rdi)
21281 movq %r9, 32 (%rdi)
21282- movq %r10, 40 (%rdi)
21283+ movq %r13, 40 (%rdi)
21284 movq %r11, 48 (%rdi)
21285 movq %r12, 56 (%rdi)
21286
21287@@ -89,8 +92,11 @@ ENTRY(copy_page)
21288 CFI_RESTORE rbx
21289 movq 1*8(%rsp),%r12
21290 CFI_RESTORE r12
21291- addq $2*8,%rsp
21292- CFI_ADJUST_CFA_OFFSET -2*8
21293+ movq 2*8(%rsp),%r13
21294+ CFI_RESTORE r13
21295+ addq $3*8,%rsp
21296+ CFI_ADJUST_CFA_OFFSET -3*8
21297+ pax_force_retaddr
21298 ret
21299 .Lcopy_page_end:
21300 CFI_ENDPROC
21301@@ -101,7 +107,7 @@ ENDPROC(copy_page)
21302
21303 #include <asm/cpufeature.h>
21304
21305- .section .altinstr_replacement,"ax"
21306+ .section .altinstr_replacement,"a"
21307 1: .byte 0xeb /* jmp <disp8> */
21308 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21309 2:
21310diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21311index 5b2995f..78e7644 100644
21312--- a/arch/x86/lib/copy_user_64.S
21313+++ b/arch/x86/lib/copy_user_64.S
21314@@ -17,6 +17,7 @@
21315 #include <asm/cpufeature.h>
21316 #include <asm/alternative-asm.h>
21317 #include <asm/asm.h>
21318+#include <asm/pgtable.h>
21319
21320 /*
21321 * By placing feature2 after feature1 in altinstructions section, we logically
21322@@ -30,7 +31,7 @@
21323 .byte 0xe9 /* 32bit jump */
21324 .long \orig-1f /* by default jump to orig */
21325 1:
21326- .section .altinstr_replacement,"ax"
21327+ .section .altinstr_replacement,"a"
21328 2: .byte 0xe9 /* near jump with 32bit immediate */
21329 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21330 3: .byte 0xe9 /* near jump with 32bit immediate */
21331@@ -69,47 +70,20 @@
21332 #endif
21333 .endm
21334
21335-/* Standard copy_to_user with segment limit checking */
21336-ENTRY(_copy_to_user)
21337- CFI_STARTPROC
21338- GET_THREAD_INFO(%rax)
21339- movq %rdi,%rcx
21340- addq %rdx,%rcx
21341- jc bad_to_user
21342- cmpq TI_addr_limit(%rax),%rcx
21343- ja bad_to_user
21344- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21345- copy_user_generic_unrolled,copy_user_generic_string, \
21346- copy_user_enhanced_fast_string
21347- CFI_ENDPROC
21348-ENDPROC(_copy_to_user)
21349-
21350-/* Standard copy_from_user with segment limit checking */
21351-ENTRY(_copy_from_user)
21352- CFI_STARTPROC
21353- GET_THREAD_INFO(%rax)
21354- movq %rsi,%rcx
21355- addq %rdx,%rcx
21356- jc bad_from_user
21357- cmpq TI_addr_limit(%rax),%rcx
21358- ja bad_from_user
21359- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21360- copy_user_generic_unrolled,copy_user_generic_string, \
21361- copy_user_enhanced_fast_string
21362- CFI_ENDPROC
21363-ENDPROC(_copy_from_user)
21364-
21365 .section .fixup,"ax"
21366 /* must zero dest */
21367 ENTRY(bad_from_user)
21368 bad_from_user:
21369 CFI_STARTPROC
21370+ testl %edx,%edx
21371+ js bad_to_user
21372 movl %edx,%ecx
21373 xorl %eax,%eax
21374 rep
21375 stosb
21376 bad_to_user:
21377 movl %edx,%eax
21378+ pax_force_retaddr
21379 ret
21380 CFI_ENDPROC
21381 ENDPROC(bad_from_user)
21382@@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21383 jz 17f
21384 1: movq (%rsi),%r8
21385 2: movq 1*8(%rsi),%r9
21386-3: movq 2*8(%rsi),%r10
21387+3: movq 2*8(%rsi),%rax
21388 4: movq 3*8(%rsi),%r11
21389 5: movq %r8,(%rdi)
21390 6: movq %r9,1*8(%rdi)
21391-7: movq %r10,2*8(%rdi)
21392+7: movq %rax,2*8(%rdi)
21393 8: movq %r11,3*8(%rdi)
21394 9: movq 4*8(%rsi),%r8
21395 10: movq 5*8(%rsi),%r9
21396-11: movq 6*8(%rsi),%r10
21397+11: movq 6*8(%rsi),%rax
21398 12: movq 7*8(%rsi),%r11
21399 13: movq %r8,4*8(%rdi)
21400 14: movq %r9,5*8(%rdi)
21401-15: movq %r10,6*8(%rdi)
21402+15: movq %rax,6*8(%rdi)
21403 16: movq %r11,7*8(%rdi)
21404 leaq 64(%rsi),%rsi
21405 leaq 64(%rdi),%rdi
21406@@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21407 decl %ecx
21408 jnz 21b
21409 23: xor %eax,%eax
21410+ pax_force_retaddr
21411 ret
21412
21413 .section .fixup,"ax"
21414@@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21415 3: rep
21416 movsb
21417 4: xorl %eax,%eax
21418+ pax_force_retaddr
21419 ret
21420
21421 .section .fixup,"ax"
21422@@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21423 1: rep
21424 movsb
21425 2: xorl %eax,%eax
21426+ pax_force_retaddr
21427 ret
21428
21429 .section .fixup,"ax"
21430diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21431index cacddc7..09d49e4 100644
21432--- a/arch/x86/lib/copy_user_nocache_64.S
21433+++ b/arch/x86/lib/copy_user_nocache_64.S
21434@@ -8,6 +8,7 @@
21435
21436 #include <linux/linkage.h>
21437 #include <asm/dwarf2.h>
21438+#include <asm/alternative-asm.h>
21439
21440 #define FIX_ALIGNMENT 1
21441
21442@@ -15,6 +16,7 @@
21443 #include <asm/asm-offsets.h>
21444 #include <asm/thread_info.h>
21445 #include <asm/asm.h>
21446+#include <asm/pgtable.h>
21447
21448 .macro ALIGN_DESTINATION
21449 #ifdef FIX_ALIGNMENT
21450@@ -48,6 +50,15 @@
21451 */
21452 ENTRY(__copy_user_nocache)
21453 CFI_STARTPROC
21454+
21455+#ifdef CONFIG_PAX_MEMORY_UDEREF
21456+ mov $PAX_USER_SHADOW_BASE,%rcx
21457+ cmp %rcx,%rsi
21458+ jae 1f
21459+ add %rcx,%rsi
21460+1:
21461+#endif
21462+
21463 cmpl $8,%edx
21464 jb 20f /* less then 8 bytes, go to byte copy loop */
21465 ALIGN_DESTINATION
21466@@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21467 jz 17f
21468 1: movq (%rsi),%r8
21469 2: movq 1*8(%rsi),%r9
21470-3: movq 2*8(%rsi),%r10
21471+3: movq 2*8(%rsi),%rax
21472 4: movq 3*8(%rsi),%r11
21473 5: movnti %r8,(%rdi)
21474 6: movnti %r9,1*8(%rdi)
21475-7: movnti %r10,2*8(%rdi)
21476+7: movnti %rax,2*8(%rdi)
21477 8: movnti %r11,3*8(%rdi)
21478 9: movq 4*8(%rsi),%r8
21479 10: movq 5*8(%rsi),%r9
21480-11: movq 6*8(%rsi),%r10
21481+11: movq 6*8(%rsi),%rax
21482 12: movq 7*8(%rsi),%r11
21483 13: movnti %r8,4*8(%rdi)
21484 14: movnti %r9,5*8(%rdi)
21485-15: movnti %r10,6*8(%rdi)
21486+15: movnti %rax,6*8(%rdi)
21487 16: movnti %r11,7*8(%rdi)
21488 leaq 64(%rsi),%rsi
21489 leaq 64(%rdi),%rdi
21490@@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21491 jnz 21b
21492 23: xorl %eax,%eax
21493 sfence
21494+ pax_force_retaddr
21495 ret
21496
21497 .section .fixup,"ax"
21498diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21499index 2419d5f..953ee51 100644
21500--- a/arch/x86/lib/csum-copy_64.S
21501+++ b/arch/x86/lib/csum-copy_64.S
21502@@ -9,6 +9,7 @@
21503 #include <asm/dwarf2.h>
21504 #include <asm/errno.h>
21505 #include <asm/asm.h>
21506+#include <asm/alternative-asm.h>
21507
21508 /*
21509 * Checksum copy with exception handling.
21510@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21511 CFI_RESTORE rbp
21512 addq $7*8, %rsp
21513 CFI_ADJUST_CFA_OFFSET -7*8
21514+ pax_force_retaddr 0, 1
21515 ret
21516 CFI_RESTORE_STATE
21517
21518diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21519index 25b7ae8..3b52ccd 100644
21520--- a/arch/x86/lib/csum-wrappers_64.c
21521+++ b/arch/x86/lib/csum-wrappers_64.c
21522@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21523 len -= 2;
21524 }
21525 }
21526- isum = csum_partial_copy_generic((__force const void *)src,
21527+
21528+#ifdef CONFIG_PAX_MEMORY_UDEREF
21529+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21530+ src += PAX_USER_SHADOW_BASE;
21531+#endif
21532+
21533+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
21534 dst, len, isum, errp, NULL);
21535 if (unlikely(*errp))
21536 goto out_err;
21537@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21538 }
21539
21540 *errp = 0;
21541- return csum_partial_copy_generic(src, (void __force *)dst,
21542+
21543+#ifdef CONFIG_PAX_MEMORY_UDEREF
21544+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21545+ dst += PAX_USER_SHADOW_BASE;
21546+#endif
21547+
21548+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21549 len, isum, NULL, errp);
21550 }
21551 EXPORT_SYMBOL(csum_partial_copy_to_user);
21552diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21553index b33b1fb..219f389 100644
21554--- a/arch/x86/lib/getuser.S
21555+++ b/arch/x86/lib/getuser.S
21556@@ -33,15 +33,38 @@
21557 #include <asm/asm-offsets.h>
21558 #include <asm/thread_info.h>
21559 #include <asm/asm.h>
21560+#include <asm/segment.h>
21561+#include <asm/pgtable.h>
21562+#include <asm/alternative-asm.h>
21563+
21564+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21565+#define __copyuser_seg gs;
21566+#else
21567+#define __copyuser_seg
21568+#endif
21569
21570 .text
21571 ENTRY(__get_user_1)
21572 CFI_STARTPROC
21573+
21574+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21575 GET_THREAD_INFO(%_ASM_DX)
21576 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21577 jae bad_get_user
21578-1: movzb (%_ASM_AX),%edx
21579+
21580+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21581+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21582+ cmp %_ASM_DX,%_ASM_AX
21583+ jae 1234f
21584+ add %_ASM_DX,%_ASM_AX
21585+1234:
21586+#endif
21587+
21588+#endif
21589+
21590+1: __copyuser_seg movzb (%_ASM_AX),%edx
21591 xor %eax,%eax
21592+ pax_force_retaddr
21593 ret
21594 CFI_ENDPROC
21595 ENDPROC(__get_user_1)
21596@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21597 ENTRY(__get_user_2)
21598 CFI_STARTPROC
21599 add $1,%_ASM_AX
21600+
21601+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21602 jc bad_get_user
21603 GET_THREAD_INFO(%_ASM_DX)
21604 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21605 jae bad_get_user
21606-2: movzwl -1(%_ASM_AX),%edx
21607+
21608+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21609+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21610+ cmp %_ASM_DX,%_ASM_AX
21611+ jae 1234f
21612+ add %_ASM_DX,%_ASM_AX
21613+1234:
21614+#endif
21615+
21616+#endif
21617+
21618+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21619 xor %eax,%eax
21620+ pax_force_retaddr
21621 ret
21622 CFI_ENDPROC
21623 ENDPROC(__get_user_2)
21624@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21625 ENTRY(__get_user_4)
21626 CFI_STARTPROC
21627 add $3,%_ASM_AX
21628+
21629+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21630 jc bad_get_user
21631 GET_THREAD_INFO(%_ASM_DX)
21632 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21633 jae bad_get_user
21634-3: mov -3(%_ASM_AX),%edx
21635+
21636+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21637+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21638+ cmp %_ASM_DX,%_ASM_AX
21639+ jae 1234f
21640+ add %_ASM_DX,%_ASM_AX
21641+1234:
21642+#endif
21643+
21644+#endif
21645+
21646+3: __copyuser_seg mov -3(%_ASM_AX),%edx
21647 xor %eax,%eax
21648+ pax_force_retaddr
21649 ret
21650 CFI_ENDPROC
21651 ENDPROC(__get_user_4)
21652@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21653 GET_THREAD_INFO(%_ASM_DX)
21654 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21655 jae bad_get_user
21656+
21657+#ifdef CONFIG_PAX_MEMORY_UDEREF
21658+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21659+ cmp %_ASM_DX,%_ASM_AX
21660+ jae 1234f
21661+ add %_ASM_DX,%_ASM_AX
21662+1234:
21663+#endif
21664+
21665 4: movq -7(%_ASM_AX),%_ASM_DX
21666 xor %eax,%eax
21667+ pax_force_retaddr
21668 ret
21669 CFI_ENDPROC
21670 ENDPROC(__get_user_8)
21671@@ -91,6 +152,7 @@ bad_get_user:
21672 CFI_STARTPROC
21673 xor %edx,%edx
21674 mov $(-EFAULT),%_ASM_AX
21675+ pax_force_retaddr
21676 ret
21677 CFI_ENDPROC
21678 END(bad_get_user)
21679diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21680index b1e6c4b..21ae8fc 100644
21681--- a/arch/x86/lib/insn.c
21682+++ b/arch/x86/lib/insn.c
21683@@ -21,6 +21,11 @@
21684 #include <linux/string.h>
21685 #include <asm/inat.h>
21686 #include <asm/insn.h>
21687+#ifdef __KERNEL__
21688+#include <asm/pgtable_types.h>
21689+#else
21690+#define ktla_ktva(addr) addr
21691+#endif
21692
21693 /* Verify next sizeof(t) bytes can be on the same instruction */
21694 #define validate_next(t, insn, n) \
21695@@ -49,8 +54,8 @@
21696 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21697 {
21698 memset(insn, 0, sizeof(*insn));
21699- insn->kaddr = kaddr;
21700- insn->next_byte = kaddr;
21701+ insn->kaddr = ktla_ktva(kaddr);
21702+ insn->next_byte = ktla_ktva(kaddr);
21703 insn->x86_64 = x86_64 ? 1 : 0;
21704 insn->opnd_bytes = 4;
21705 if (x86_64)
21706diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21707index 05a95e7..326f2fa 100644
21708--- a/arch/x86/lib/iomap_copy_64.S
21709+++ b/arch/x86/lib/iomap_copy_64.S
21710@@ -17,6 +17,7 @@
21711
21712 #include <linux/linkage.h>
21713 #include <asm/dwarf2.h>
21714+#include <asm/alternative-asm.h>
21715
21716 /*
21717 * override generic version in lib/iomap_copy.c
21718@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21719 CFI_STARTPROC
21720 movl %edx,%ecx
21721 rep movsd
21722+ pax_force_retaddr
21723 ret
21724 CFI_ENDPROC
21725 ENDPROC(__iowrite32_copy)
21726diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21727index 1c273be..da9cc0e 100644
21728--- a/arch/x86/lib/memcpy_64.S
21729+++ b/arch/x86/lib/memcpy_64.S
21730@@ -33,6 +33,7 @@
21731 rep movsq
21732 movl %edx, %ecx
21733 rep movsb
21734+ pax_force_retaddr
21735 ret
21736 .Lmemcpy_e:
21737 .previous
21738@@ -49,6 +50,7 @@
21739 movq %rdi, %rax
21740 movq %rdx, %rcx
21741 rep movsb
21742+ pax_force_retaddr
21743 ret
21744 .Lmemcpy_e_e:
21745 .previous
21746@@ -76,13 +78,13 @@ ENTRY(memcpy)
21747 */
21748 movq 0*8(%rsi), %r8
21749 movq 1*8(%rsi), %r9
21750- movq 2*8(%rsi), %r10
21751+ movq 2*8(%rsi), %rcx
21752 movq 3*8(%rsi), %r11
21753 leaq 4*8(%rsi), %rsi
21754
21755 movq %r8, 0*8(%rdi)
21756 movq %r9, 1*8(%rdi)
21757- movq %r10, 2*8(%rdi)
21758+ movq %rcx, 2*8(%rdi)
21759 movq %r11, 3*8(%rdi)
21760 leaq 4*8(%rdi), %rdi
21761 jae .Lcopy_forward_loop
21762@@ -105,12 +107,12 @@ ENTRY(memcpy)
21763 subq $0x20, %rdx
21764 movq -1*8(%rsi), %r8
21765 movq -2*8(%rsi), %r9
21766- movq -3*8(%rsi), %r10
21767+ movq -3*8(%rsi), %rcx
21768 movq -4*8(%rsi), %r11
21769 leaq -4*8(%rsi), %rsi
21770 movq %r8, -1*8(%rdi)
21771 movq %r9, -2*8(%rdi)
21772- movq %r10, -3*8(%rdi)
21773+ movq %rcx, -3*8(%rdi)
21774 movq %r11, -4*8(%rdi)
21775 leaq -4*8(%rdi), %rdi
21776 jae .Lcopy_backward_loop
21777@@ -130,12 +132,13 @@ ENTRY(memcpy)
21778 */
21779 movq 0*8(%rsi), %r8
21780 movq 1*8(%rsi), %r9
21781- movq -2*8(%rsi, %rdx), %r10
21782+ movq -2*8(%rsi, %rdx), %rcx
21783 movq -1*8(%rsi, %rdx), %r11
21784 movq %r8, 0*8(%rdi)
21785 movq %r9, 1*8(%rdi)
21786- movq %r10, -2*8(%rdi, %rdx)
21787+ movq %rcx, -2*8(%rdi, %rdx)
21788 movq %r11, -1*8(%rdi, %rdx)
21789+ pax_force_retaddr
21790 retq
21791 .p2align 4
21792 .Lless_16bytes:
21793@@ -148,6 +151,7 @@ ENTRY(memcpy)
21794 movq -1*8(%rsi, %rdx), %r9
21795 movq %r8, 0*8(%rdi)
21796 movq %r9, -1*8(%rdi, %rdx)
21797+ pax_force_retaddr
21798 retq
21799 .p2align 4
21800 .Lless_8bytes:
21801@@ -161,6 +165,7 @@ ENTRY(memcpy)
21802 movl -4(%rsi, %rdx), %r8d
21803 movl %ecx, (%rdi)
21804 movl %r8d, -4(%rdi, %rdx)
21805+ pax_force_retaddr
21806 retq
21807 .p2align 4
21808 .Lless_3bytes:
21809@@ -179,6 +184,7 @@ ENTRY(memcpy)
21810 movb %cl, (%rdi)
21811
21812 .Lend:
21813+ pax_force_retaddr
21814 retq
21815 CFI_ENDPROC
21816 ENDPROC(memcpy)
21817diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21818index ee16461..c39c199 100644
21819--- a/arch/x86/lib/memmove_64.S
21820+++ b/arch/x86/lib/memmove_64.S
21821@@ -61,13 +61,13 @@ ENTRY(memmove)
21822 5:
21823 sub $0x20, %rdx
21824 movq 0*8(%rsi), %r11
21825- movq 1*8(%rsi), %r10
21826+ movq 1*8(%rsi), %rcx
21827 movq 2*8(%rsi), %r9
21828 movq 3*8(%rsi), %r8
21829 leaq 4*8(%rsi), %rsi
21830
21831 movq %r11, 0*8(%rdi)
21832- movq %r10, 1*8(%rdi)
21833+ movq %rcx, 1*8(%rdi)
21834 movq %r9, 2*8(%rdi)
21835 movq %r8, 3*8(%rdi)
21836 leaq 4*8(%rdi), %rdi
21837@@ -81,10 +81,10 @@ ENTRY(memmove)
21838 4:
21839 movq %rdx, %rcx
21840 movq -8(%rsi, %rdx), %r11
21841- lea -8(%rdi, %rdx), %r10
21842+ lea -8(%rdi, %rdx), %r9
21843 shrq $3, %rcx
21844 rep movsq
21845- movq %r11, (%r10)
21846+ movq %r11, (%r9)
21847 jmp 13f
21848 .Lmemmove_end_forward:
21849
21850@@ -95,14 +95,14 @@ ENTRY(memmove)
21851 7:
21852 movq %rdx, %rcx
21853 movq (%rsi), %r11
21854- movq %rdi, %r10
21855+ movq %rdi, %r9
21856 leaq -8(%rsi, %rdx), %rsi
21857 leaq -8(%rdi, %rdx), %rdi
21858 shrq $3, %rcx
21859 std
21860 rep movsq
21861 cld
21862- movq %r11, (%r10)
21863+ movq %r11, (%r9)
21864 jmp 13f
21865
21866 /*
21867@@ -127,13 +127,13 @@ ENTRY(memmove)
21868 8:
21869 subq $0x20, %rdx
21870 movq -1*8(%rsi), %r11
21871- movq -2*8(%rsi), %r10
21872+ movq -2*8(%rsi), %rcx
21873 movq -3*8(%rsi), %r9
21874 movq -4*8(%rsi), %r8
21875 leaq -4*8(%rsi), %rsi
21876
21877 movq %r11, -1*8(%rdi)
21878- movq %r10, -2*8(%rdi)
21879+ movq %rcx, -2*8(%rdi)
21880 movq %r9, -3*8(%rdi)
21881 movq %r8, -4*8(%rdi)
21882 leaq -4*8(%rdi), %rdi
21883@@ -151,11 +151,11 @@ ENTRY(memmove)
21884 * Move data from 16 bytes to 31 bytes.
21885 */
21886 movq 0*8(%rsi), %r11
21887- movq 1*8(%rsi), %r10
21888+ movq 1*8(%rsi), %rcx
21889 movq -2*8(%rsi, %rdx), %r9
21890 movq -1*8(%rsi, %rdx), %r8
21891 movq %r11, 0*8(%rdi)
21892- movq %r10, 1*8(%rdi)
21893+ movq %rcx, 1*8(%rdi)
21894 movq %r9, -2*8(%rdi, %rdx)
21895 movq %r8, -1*8(%rdi, %rdx)
21896 jmp 13f
21897@@ -167,9 +167,9 @@ ENTRY(memmove)
21898 * Move data from 8 bytes to 15 bytes.
21899 */
21900 movq 0*8(%rsi), %r11
21901- movq -1*8(%rsi, %rdx), %r10
21902+ movq -1*8(%rsi, %rdx), %r9
21903 movq %r11, 0*8(%rdi)
21904- movq %r10, -1*8(%rdi, %rdx)
21905+ movq %r9, -1*8(%rdi, %rdx)
21906 jmp 13f
21907 10:
21908 cmpq $4, %rdx
21909@@ -178,9 +178,9 @@ ENTRY(memmove)
21910 * Move data from 4 bytes to 7 bytes.
21911 */
21912 movl (%rsi), %r11d
21913- movl -4(%rsi, %rdx), %r10d
21914+ movl -4(%rsi, %rdx), %r9d
21915 movl %r11d, (%rdi)
21916- movl %r10d, -4(%rdi, %rdx)
21917+ movl %r9d, -4(%rdi, %rdx)
21918 jmp 13f
21919 11:
21920 cmp $2, %rdx
21921@@ -189,9 +189,9 @@ ENTRY(memmove)
21922 * Move data from 2 bytes to 3 bytes.
21923 */
21924 movw (%rsi), %r11w
21925- movw -2(%rsi, %rdx), %r10w
21926+ movw -2(%rsi, %rdx), %r9w
21927 movw %r11w, (%rdi)
21928- movw %r10w, -2(%rdi, %rdx)
21929+ movw %r9w, -2(%rdi, %rdx)
21930 jmp 13f
21931 12:
21932 cmp $1, %rdx
21933@@ -202,6 +202,7 @@ ENTRY(memmove)
21934 movb (%rsi), %r11b
21935 movb %r11b, (%rdi)
21936 13:
21937+ pax_force_retaddr
21938 retq
21939 CFI_ENDPROC
21940
21941@@ -210,6 +211,7 @@ ENTRY(memmove)
21942 /* Forward moving data. */
21943 movq %rdx, %rcx
21944 rep movsb
21945+ pax_force_retaddr
21946 retq
21947 .Lmemmove_end_forward_efs:
21948 .previous
21949diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
21950index 2dcb380..963660a 100644
21951--- a/arch/x86/lib/memset_64.S
21952+++ b/arch/x86/lib/memset_64.S
21953@@ -30,6 +30,7 @@
21954 movl %edx,%ecx
21955 rep stosb
21956 movq %r9,%rax
21957+ pax_force_retaddr
21958 ret
21959 .Lmemset_e:
21960 .previous
21961@@ -52,6 +53,7 @@
21962 movq %rdx,%rcx
21963 rep stosb
21964 movq %r9,%rax
21965+ pax_force_retaddr
21966 ret
21967 .Lmemset_e_e:
21968 .previous
21969@@ -59,7 +61,7 @@
21970 ENTRY(memset)
21971 ENTRY(__memset)
21972 CFI_STARTPROC
21973- movq %rdi,%r10
21974+ movq %rdi,%r11
21975
21976 /* expand byte value */
21977 movzbl %sil,%ecx
21978@@ -117,7 +119,8 @@ ENTRY(__memset)
21979 jnz .Lloop_1
21980
21981 .Lende:
21982- movq %r10,%rax
21983+ movq %r11,%rax
21984+ pax_force_retaddr
21985 ret
21986
21987 CFI_RESTORE_STATE
21988diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
21989index c9f2d9b..e7fd2c0 100644
21990--- a/arch/x86/lib/mmx_32.c
21991+++ b/arch/x86/lib/mmx_32.c
21992@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
21993 {
21994 void *p;
21995 int i;
21996+ unsigned long cr0;
21997
21998 if (unlikely(in_interrupt()))
21999 return __memcpy(to, from, len);
22000@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22001 kernel_fpu_begin();
22002
22003 __asm__ __volatile__ (
22004- "1: prefetch (%0)\n" /* This set is 28 bytes */
22005- " prefetch 64(%0)\n"
22006- " prefetch 128(%0)\n"
22007- " prefetch 192(%0)\n"
22008- " prefetch 256(%0)\n"
22009+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22010+ " prefetch 64(%1)\n"
22011+ " prefetch 128(%1)\n"
22012+ " prefetch 192(%1)\n"
22013+ " prefetch 256(%1)\n"
22014 "2: \n"
22015 ".section .fixup, \"ax\"\n"
22016- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22017+ "3: \n"
22018+
22019+#ifdef CONFIG_PAX_KERNEXEC
22020+ " movl %%cr0, %0\n"
22021+ " movl %0, %%eax\n"
22022+ " andl $0xFFFEFFFF, %%eax\n"
22023+ " movl %%eax, %%cr0\n"
22024+#endif
22025+
22026+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22027+
22028+#ifdef CONFIG_PAX_KERNEXEC
22029+ " movl %0, %%cr0\n"
22030+#endif
22031+
22032 " jmp 2b\n"
22033 ".previous\n"
22034 _ASM_EXTABLE(1b, 3b)
22035- : : "r" (from));
22036+ : "=&r" (cr0) : "r" (from) : "ax");
22037
22038 for ( ; i > 5; i--) {
22039 __asm__ __volatile__ (
22040- "1: prefetch 320(%0)\n"
22041- "2: movq (%0), %%mm0\n"
22042- " movq 8(%0), %%mm1\n"
22043- " movq 16(%0), %%mm2\n"
22044- " movq 24(%0), %%mm3\n"
22045- " movq %%mm0, (%1)\n"
22046- " movq %%mm1, 8(%1)\n"
22047- " movq %%mm2, 16(%1)\n"
22048- " movq %%mm3, 24(%1)\n"
22049- " movq 32(%0), %%mm0\n"
22050- " movq 40(%0), %%mm1\n"
22051- " movq 48(%0), %%mm2\n"
22052- " movq 56(%0), %%mm3\n"
22053- " movq %%mm0, 32(%1)\n"
22054- " movq %%mm1, 40(%1)\n"
22055- " movq %%mm2, 48(%1)\n"
22056- " movq %%mm3, 56(%1)\n"
22057+ "1: prefetch 320(%1)\n"
22058+ "2: movq (%1), %%mm0\n"
22059+ " movq 8(%1), %%mm1\n"
22060+ " movq 16(%1), %%mm2\n"
22061+ " movq 24(%1), %%mm3\n"
22062+ " movq %%mm0, (%2)\n"
22063+ " movq %%mm1, 8(%2)\n"
22064+ " movq %%mm2, 16(%2)\n"
22065+ " movq %%mm3, 24(%2)\n"
22066+ " movq 32(%1), %%mm0\n"
22067+ " movq 40(%1), %%mm1\n"
22068+ " movq 48(%1), %%mm2\n"
22069+ " movq 56(%1), %%mm3\n"
22070+ " movq %%mm0, 32(%2)\n"
22071+ " movq %%mm1, 40(%2)\n"
22072+ " movq %%mm2, 48(%2)\n"
22073+ " movq %%mm3, 56(%2)\n"
22074 ".section .fixup, \"ax\"\n"
22075- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22076+ "3:\n"
22077+
22078+#ifdef CONFIG_PAX_KERNEXEC
22079+ " movl %%cr0, %0\n"
22080+ " movl %0, %%eax\n"
22081+ " andl $0xFFFEFFFF, %%eax\n"
22082+ " movl %%eax, %%cr0\n"
22083+#endif
22084+
22085+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22086+
22087+#ifdef CONFIG_PAX_KERNEXEC
22088+ " movl %0, %%cr0\n"
22089+#endif
22090+
22091 " jmp 2b\n"
22092 ".previous\n"
22093 _ASM_EXTABLE(1b, 3b)
22094- : : "r" (from), "r" (to) : "memory");
22095+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22096
22097 from += 64;
22098 to += 64;
22099@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22100 static void fast_copy_page(void *to, void *from)
22101 {
22102 int i;
22103+ unsigned long cr0;
22104
22105 kernel_fpu_begin();
22106
22107@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22108 * but that is for later. -AV
22109 */
22110 __asm__ __volatile__(
22111- "1: prefetch (%0)\n"
22112- " prefetch 64(%0)\n"
22113- " prefetch 128(%0)\n"
22114- " prefetch 192(%0)\n"
22115- " prefetch 256(%0)\n"
22116+ "1: prefetch (%1)\n"
22117+ " prefetch 64(%1)\n"
22118+ " prefetch 128(%1)\n"
22119+ " prefetch 192(%1)\n"
22120+ " prefetch 256(%1)\n"
22121 "2: \n"
22122 ".section .fixup, \"ax\"\n"
22123- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22124+ "3: \n"
22125+
22126+#ifdef CONFIG_PAX_KERNEXEC
22127+ " movl %%cr0, %0\n"
22128+ " movl %0, %%eax\n"
22129+ " andl $0xFFFEFFFF, %%eax\n"
22130+ " movl %%eax, %%cr0\n"
22131+#endif
22132+
22133+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22134+
22135+#ifdef CONFIG_PAX_KERNEXEC
22136+ " movl %0, %%cr0\n"
22137+#endif
22138+
22139 " jmp 2b\n"
22140 ".previous\n"
22141- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22142+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22143
22144 for (i = 0; i < (4096-320)/64; i++) {
22145 __asm__ __volatile__ (
22146- "1: prefetch 320(%0)\n"
22147- "2: movq (%0), %%mm0\n"
22148- " movntq %%mm0, (%1)\n"
22149- " movq 8(%0), %%mm1\n"
22150- " movntq %%mm1, 8(%1)\n"
22151- " movq 16(%0), %%mm2\n"
22152- " movntq %%mm2, 16(%1)\n"
22153- " movq 24(%0), %%mm3\n"
22154- " movntq %%mm3, 24(%1)\n"
22155- " movq 32(%0), %%mm4\n"
22156- " movntq %%mm4, 32(%1)\n"
22157- " movq 40(%0), %%mm5\n"
22158- " movntq %%mm5, 40(%1)\n"
22159- " movq 48(%0), %%mm6\n"
22160- " movntq %%mm6, 48(%1)\n"
22161- " movq 56(%0), %%mm7\n"
22162- " movntq %%mm7, 56(%1)\n"
22163+ "1: prefetch 320(%1)\n"
22164+ "2: movq (%1), %%mm0\n"
22165+ " movntq %%mm0, (%2)\n"
22166+ " movq 8(%1), %%mm1\n"
22167+ " movntq %%mm1, 8(%2)\n"
22168+ " movq 16(%1), %%mm2\n"
22169+ " movntq %%mm2, 16(%2)\n"
22170+ " movq 24(%1), %%mm3\n"
22171+ " movntq %%mm3, 24(%2)\n"
22172+ " movq 32(%1), %%mm4\n"
22173+ " movntq %%mm4, 32(%2)\n"
22174+ " movq 40(%1), %%mm5\n"
22175+ " movntq %%mm5, 40(%2)\n"
22176+ " movq 48(%1), %%mm6\n"
22177+ " movntq %%mm6, 48(%2)\n"
22178+ " movq 56(%1), %%mm7\n"
22179+ " movntq %%mm7, 56(%2)\n"
22180 ".section .fixup, \"ax\"\n"
22181- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22182+ "3:\n"
22183+
22184+#ifdef CONFIG_PAX_KERNEXEC
22185+ " movl %%cr0, %0\n"
22186+ " movl %0, %%eax\n"
22187+ " andl $0xFFFEFFFF, %%eax\n"
22188+ " movl %%eax, %%cr0\n"
22189+#endif
22190+
22191+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22192+
22193+#ifdef CONFIG_PAX_KERNEXEC
22194+ " movl %0, %%cr0\n"
22195+#endif
22196+
22197 " jmp 2b\n"
22198 ".previous\n"
22199- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22200+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22201
22202 from += 64;
22203 to += 64;
22204@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22205 static void fast_copy_page(void *to, void *from)
22206 {
22207 int i;
22208+ unsigned long cr0;
22209
22210 kernel_fpu_begin();
22211
22212 __asm__ __volatile__ (
22213- "1: prefetch (%0)\n"
22214- " prefetch 64(%0)\n"
22215- " prefetch 128(%0)\n"
22216- " prefetch 192(%0)\n"
22217- " prefetch 256(%0)\n"
22218+ "1: prefetch (%1)\n"
22219+ " prefetch 64(%1)\n"
22220+ " prefetch 128(%1)\n"
22221+ " prefetch 192(%1)\n"
22222+ " prefetch 256(%1)\n"
22223 "2: \n"
22224 ".section .fixup, \"ax\"\n"
22225- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22226+ "3: \n"
22227+
22228+#ifdef CONFIG_PAX_KERNEXEC
22229+ " movl %%cr0, %0\n"
22230+ " movl %0, %%eax\n"
22231+ " andl $0xFFFEFFFF, %%eax\n"
22232+ " movl %%eax, %%cr0\n"
22233+#endif
22234+
22235+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22236+
22237+#ifdef CONFIG_PAX_KERNEXEC
22238+ " movl %0, %%cr0\n"
22239+#endif
22240+
22241 " jmp 2b\n"
22242 ".previous\n"
22243- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22244+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22245
22246 for (i = 0; i < 4096/64; i++) {
22247 __asm__ __volatile__ (
22248- "1: prefetch 320(%0)\n"
22249- "2: movq (%0), %%mm0\n"
22250- " movq 8(%0), %%mm1\n"
22251- " movq 16(%0), %%mm2\n"
22252- " movq 24(%0), %%mm3\n"
22253- " movq %%mm0, (%1)\n"
22254- " movq %%mm1, 8(%1)\n"
22255- " movq %%mm2, 16(%1)\n"
22256- " movq %%mm3, 24(%1)\n"
22257- " movq 32(%0), %%mm0\n"
22258- " movq 40(%0), %%mm1\n"
22259- " movq 48(%0), %%mm2\n"
22260- " movq 56(%0), %%mm3\n"
22261- " movq %%mm0, 32(%1)\n"
22262- " movq %%mm1, 40(%1)\n"
22263- " movq %%mm2, 48(%1)\n"
22264- " movq %%mm3, 56(%1)\n"
22265+ "1: prefetch 320(%1)\n"
22266+ "2: movq (%1), %%mm0\n"
22267+ " movq 8(%1), %%mm1\n"
22268+ " movq 16(%1), %%mm2\n"
22269+ " movq 24(%1), %%mm3\n"
22270+ " movq %%mm0, (%2)\n"
22271+ " movq %%mm1, 8(%2)\n"
22272+ " movq %%mm2, 16(%2)\n"
22273+ " movq %%mm3, 24(%2)\n"
22274+ " movq 32(%1), %%mm0\n"
22275+ " movq 40(%1), %%mm1\n"
22276+ " movq 48(%1), %%mm2\n"
22277+ " movq 56(%1), %%mm3\n"
22278+ " movq %%mm0, 32(%2)\n"
22279+ " movq %%mm1, 40(%2)\n"
22280+ " movq %%mm2, 48(%2)\n"
22281+ " movq %%mm3, 56(%2)\n"
22282 ".section .fixup, \"ax\"\n"
22283- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22284+ "3:\n"
22285+
22286+#ifdef CONFIG_PAX_KERNEXEC
22287+ " movl %%cr0, %0\n"
22288+ " movl %0, %%eax\n"
22289+ " andl $0xFFFEFFFF, %%eax\n"
22290+ " movl %%eax, %%cr0\n"
22291+#endif
22292+
22293+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22294+
22295+#ifdef CONFIG_PAX_KERNEXEC
22296+ " movl %0, %%cr0\n"
22297+#endif
22298+
22299 " jmp 2b\n"
22300 ".previous\n"
22301 _ASM_EXTABLE(1b, 3b)
22302- : : "r" (from), "r" (to) : "memory");
22303+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22304
22305 from += 64;
22306 to += 64;
22307diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22308index 69fa106..adda88b 100644
22309--- a/arch/x86/lib/msr-reg.S
22310+++ b/arch/x86/lib/msr-reg.S
22311@@ -3,6 +3,7 @@
22312 #include <asm/dwarf2.h>
22313 #include <asm/asm.h>
22314 #include <asm/msr.h>
22315+#include <asm/alternative-asm.h>
22316
22317 #ifdef CONFIG_X86_64
22318 /*
22319@@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22320 CFI_STARTPROC
22321 pushq_cfi %rbx
22322 pushq_cfi %rbp
22323- movq %rdi, %r10 /* Save pointer */
22324+ movq %rdi, %r9 /* Save pointer */
22325 xorl %r11d, %r11d /* Return value */
22326 movl (%rdi), %eax
22327 movl 4(%rdi), %ecx
22328@@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22329 movl 28(%rdi), %edi
22330 CFI_REMEMBER_STATE
22331 1: \op
22332-2: movl %eax, (%r10)
22333+2: movl %eax, (%r9)
22334 movl %r11d, %eax /* Return value */
22335- movl %ecx, 4(%r10)
22336- movl %edx, 8(%r10)
22337- movl %ebx, 12(%r10)
22338- movl %ebp, 20(%r10)
22339- movl %esi, 24(%r10)
22340- movl %edi, 28(%r10)
22341+ movl %ecx, 4(%r9)
22342+ movl %edx, 8(%r9)
22343+ movl %ebx, 12(%r9)
22344+ movl %ebp, 20(%r9)
22345+ movl %esi, 24(%r9)
22346+ movl %edi, 28(%r9)
22347 popq_cfi %rbp
22348 popq_cfi %rbx
22349+ pax_force_retaddr
22350 ret
22351 3:
22352 CFI_RESTORE_STATE
22353diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22354index 7f951c8..ebd573a 100644
22355--- a/arch/x86/lib/putuser.S
22356+++ b/arch/x86/lib/putuser.S
22357@@ -15,7 +15,9 @@
22358 #include <asm/thread_info.h>
22359 #include <asm/errno.h>
22360 #include <asm/asm.h>
22361-
22362+#include <asm/segment.h>
22363+#include <asm/pgtable.h>
22364+#include <asm/alternative-asm.h>
22365
22366 /*
22367 * __put_user_X
22368@@ -29,52 +31,119 @@
22369 * as they get called from within inline assembly.
22370 */
22371
22372-#define ENTER CFI_STARTPROC ; \
22373- GET_THREAD_INFO(%_ASM_BX)
22374-#define EXIT ret ; \
22375+#define ENTER CFI_STARTPROC
22376+#define EXIT pax_force_retaddr; ret ; \
22377 CFI_ENDPROC
22378
22379+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22380+#define _DEST %_ASM_CX,%_ASM_BX
22381+#else
22382+#define _DEST %_ASM_CX
22383+#endif
22384+
22385+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22386+#define __copyuser_seg gs;
22387+#else
22388+#define __copyuser_seg
22389+#endif
22390+
22391 .text
22392 ENTRY(__put_user_1)
22393 ENTER
22394+
22395+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22396+ GET_THREAD_INFO(%_ASM_BX)
22397 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22398 jae bad_put_user
22399-1: movb %al,(%_ASM_CX)
22400+
22401+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22402+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22403+ cmp %_ASM_BX,%_ASM_CX
22404+ jb 1234f
22405+ xor %ebx,%ebx
22406+1234:
22407+#endif
22408+
22409+#endif
22410+
22411+1: __copyuser_seg movb %al,(_DEST)
22412 xor %eax,%eax
22413 EXIT
22414 ENDPROC(__put_user_1)
22415
22416 ENTRY(__put_user_2)
22417 ENTER
22418+
22419+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22420+ GET_THREAD_INFO(%_ASM_BX)
22421 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22422 sub $1,%_ASM_BX
22423 cmp %_ASM_BX,%_ASM_CX
22424 jae bad_put_user
22425-2: movw %ax,(%_ASM_CX)
22426+
22427+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22428+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22429+ cmp %_ASM_BX,%_ASM_CX
22430+ jb 1234f
22431+ xor %ebx,%ebx
22432+1234:
22433+#endif
22434+
22435+#endif
22436+
22437+2: __copyuser_seg movw %ax,(_DEST)
22438 xor %eax,%eax
22439 EXIT
22440 ENDPROC(__put_user_2)
22441
22442 ENTRY(__put_user_4)
22443 ENTER
22444+
22445+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22446+ GET_THREAD_INFO(%_ASM_BX)
22447 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22448 sub $3,%_ASM_BX
22449 cmp %_ASM_BX,%_ASM_CX
22450 jae bad_put_user
22451-3: movl %eax,(%_ASM_CX)
22452+
22453+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22454+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22455+ cmp %_ASM_BX,%_ASM_CX
22456+ jb 1234f
22457+ xor %ebx,%ebx
22458+1234:
22459+#endif
22460+
22461+#endif
22462+
22463+3: __copyuser_seg movl %eax,(_DEST)
22464 xor %eax,%eax
22465 EXIT
22466 ENDPROC(__put_user_4)
22467
22468 ENTRY(__put_user_8)
22469 ENTER
22470+
22471+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22472+ GET_THREAD_INFO(%_ASM_BX)
22473 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22474 sub $7,%_ASM_BX
22475 cmp %_ASM_BX,%_ASM_CX
22476 jae bad_put_user
22477-4: mov %_ASM_AX,(%_ASM_CX)
22478+
22479+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22480+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22481+ cmp %_ASM_BX,%_ASM_CX
22482+ jb 1234f
22483+ xor %ebx,%ebx
22484+1234:
22485+#endif
22486+
22487+#endif
22488+
22489+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22490 #ifdef CONFIG_X86_32
22491-5: movl %edx,4(%_ASM_CX)
22492+5: __copyuser_seg movl %edx,4(_DEST)
22493 #endif
22494 xor %eax,%eax
22495 EXIT
22496diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22497index 1cad221..de671ee 100644
22498--- a/arch/x86/lib/rwlock.S
22499+++ b/arch/x86/lib/rwlock.S
22500@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22501 FRAME
22502 0: LOCK_PREFIX
22503 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22504+
22505+#ifdef CONFIG_PAX_REFCOUNT
22506+ jno 1234f
22507+ LOCK_PREFIX
22508+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22509+ int $4
22510+1234:
22511+ _ASM_EXTABLE(1234b, 1234b)
22512+#endif
22513+
22514 1: rep; nop
22515 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22516 jne 1b
22517 LOCK_PREFIX
22518 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22519+
22520+#ifdef CONFIG_PAX_REFCOUNT
22521+ jno 1234f
22522+ LOCK_PREFIX
22523+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22524+ int $4
22525+1234:
22526+ _ASM_EXTABLE(1234b, 1234b)
22527+#endif
22528+
22529 jnz 0b
22530 ENDFRAME
22531+ pax_force_retaddr
22532 ret
22533 CFI_ENDPROC
22534 END(__write_lock_failed)
22535@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22536 FRAME
22537 0: LOCK_PREFIX
22538 READ_LOCK_SIZE(inc) (%__lock_ptr)
22539+
22540+#ifdef CONFIG_PAX_REFCOUNT
22541+ jno 1234f
22542+ LOCK_PREFIX
22543+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22544+ int $4
22545+1234:
22546+ _ASM_EXTABLE(1234b, 1234b)
22547+#endif
22548+
22549 1: rep; nop
22550 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22551 js 1b
22552 LOCK_PREFIX
22553 READ_LOCK_SIZE(dec) (%__lock_ptr)
22554+
22555+#ifdef CONFIG_PAX_REFCOUNT
22556+ jno 1234f
22557+ LOCK_PREFIX
22558+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22559+ int $4
22560+1234:
22561+ _ASM_EXTABLE(1234b, 1234b)
22562+#endif
22563+
22564 js 0b
22565 ENDFRAME
22566+ pax_force_retaddr
22567 ret
22568 CFI_ENDPROC
22569 END(__read_lock_failed)
22570diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22571index 5dff5f0..cadebf4 100644
22572--- a/arch/x86/lib/rwsem.S
22573+++ b/arch/x86/lib/rwsem.S
22574@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22575 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22576 CFI_RESTORE __ASM_REG(dx)
22577 restore_common_regs
22578+ pax_force_retaddr
22579 ret
22580 CFI_ENDPROC
22581 ENDPROC(call_rwsem_down_read_failed)
22582@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22583 movq %rax,%rdi
22584 call rwsem_down_write_failed
22585 restore_common_regs
22586+ pax_force_retaddr
22587 ret
22588 CFI_ENDPROC
22589 ENDPROC(call_rwsem_down_write_failed)
22590@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22591 movq %rax,%rdi
22592 call rwsem_wake
22593 restore_common_regs
22594-1: ret
22595+1: pax_force_retaddr
22596+ ret
22597 CFI_ENDPROC
22598 ENDPROC(call_rwsem_wake)
22599
22600@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22601 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22602 CFI_RESTORE __ASM_REG(dx)
22603 restore_common_regs
22604+ pax_force_retaddr
22605 ret
22606 CFI_ENDPROC
22607 ENDPROC(call_rwsem_downgrade_wake)
22608diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22609index a63efd6..ccecad8 100644
22610--- a/arch/x86/lib/thunk_64.S
22611+++ b/arch/x86/lib/thunk_64.S
22612@@ -8,6 +8,7 @@
22613 #include <linux/linkage.h>
22614 #include <asm/dwarf2.h>
22615 #include <asm/calling.h>
22616+#include <asm/alternative-asm.h>
22617
22618 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22619 .macro THUNK name, func, put_ret_addr_in_rdi=0
22620@@ -41,5 +42,6 @@
22621 SAVE_ARGS
22622 restore:
22623 RESTORE_ARGS
22624+ pax_force_retaddr
22625 ret
22626 CFI_ENDPROC
22627diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22628index 1781b2f..18e3040 100644
22629--- a/arch/x86/lib/usercopy_32.c
22630+++ b/arch/x86/lib/usercopy_32.c
22631@@ -42,10 +42,12 @@ do { \
22632 int __d0; \
22633 might_fault(); \
22634 __asm__ __volatile__( \
22635+ __COPYUSER_SET_ES \
22636 "0: rep; stosl\n" \
22637 " movl %2,%0\n" \
22638 "1: rep; stosb\n" \
22639 "2:\n" \
22640+ __COPYUSER_RESTORE_ES \
22641 ".section .fixup,\"ax\"\n" \
22642 "3: lea 0(%2,%0,4),%0\n" \
22643 " jmp 2b\n" \
22644@@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22645
22646 #ifdef CONFIG_X86_INTEL_USERCOPY
22647 static unsigned long
22648-__copy_user_intel(void __user *to, const void *from, unsigned long size)
22649+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22650 {
22651 int d0, d1;
22652 __asm__ __volatile__(
22653@@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22654 " .align 2,0x90\n"
22655 "3: movl 0(%4), %%eax\n"
22656 "4: movl 4(%4), %%edx\n"
22657- "5: movl %%eax, 0(%3)\n"
22658- "6: movl %%edx, 4(%3)\n"
22659+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22660+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22661 "7: movl 8(%4), %%eax\n"
22662 "8: movl 12(%4),%%edx\n"
22663- "9: movl %%eax, 8(%3)\n"
22664- "10: movl %%edx, 12(%3)\n"
22665+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22666+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22667 "11: movl 16(%4), %%eax\n"
22668 "12: movl 20(%4), %%edx\n"
22669- "13: movl %%eax, 16(%3)\n"
22670- "14: movl %%edx, 20(%3)\n"
22671+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22672+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22673 "15: movl 24(%4), %%eax\n"
22674 "16: movl 28(%4), %%edx\n"
22675- "17: movl %%eax, 24(%3)\n"
22676- "18: movl %%edx, 28(%3)\n"
22677+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22678+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22679 "19: movl 32(%4), %%eax\n"
22680 "20: movl 36(%4), %%edx\n"
22681- "21: movl %%eax, 32(%3)\n"
22682- "22: movl %%edx, 36(%3)\n"
22683+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22684+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22685 "23: movl 40(%4), %%eax\n"
22686 "24: movl 44(%4), %%edx\n"
22687- "25: movl %%eax, 40(%3)\n"
22688- "26: movl %%edx, 44(%3)\n"
22689+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22690+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22691 "27: movl 48(%4), %%eax\n"
22692 "28: movl 52(%4), %%edx\n"
22693- "29: movl %%eax, 48(%3)\n"
22694- "30: movl %%edx, 52(%3)\n"
22695+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22696+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22697 "31: movl 56(%4), %%eax\n"
22698 "32: movl 60(%4), %%edx\n"
22699- "33: movl %%eax, 56(%3)\n"
22700- "34: movl %%edx, 60(%3)\n"
22701+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22702+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22703 " addl $-64, %0\n"
22704 " addl $64, %4\n"
22705 " addl $64, %3\n"
22706@@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22707 " shrl $2, %0\n"
22708 " andl $3, %%eax\n"
22709 " cld\n"
22710+ __COPYUSER_SET_ES
22711 "99: rep; movsl\n"
22712 "36: movl %%eax, %0\n"
22713 "37: rep; movsb\n"
22714 "100:\n"
22715+ __COPYUSER_RESTORE_ES
22716 ".section .fixup,\"ax\"\n"
22717 "101: lea 0(%%eax,%0,4),%0\n"
22718 " jmp 100b\n"
22719@@ -201,46 +205,152 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22720 }
22721
22722 static unsigned long
22723+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22724+{
22725+ int d0, d1;
22726+ __asm__ __volatile__(
22727+ " .align 2,0x90\n"
22728+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22729+ " cmpl $67, %0\n"
22730+ " jbe 3f\n"
22731+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22732+ " .align 2,0x90\n"
22733+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22734+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22735+ "5: movl %%eax, 0(%3)\n"
22736+ "6: movl %%edx, 4(%3)\n"
22737+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22738+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22739+ "9: movl %%eax, 8(%3)\n"
22740+ "10: movl %%edx, 12(%3)\n"
22741+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22742+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22743+ "13: movl %%eax, 16(%3)\n"
22744+ "14: movl %%edx, 20(%3)\n"
22745+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22746+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22747+ "17: movl %%eax, 24(%3)\n"
22748+ "18: movl %%edx, 28(%3)\n"
22749+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22750+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22751+ "21: movl %%eax, 32(%3)\n"
22752+ "22: movl %%edx, 36(%3)\n"
22753+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22754+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22755+ "25: movl %%eax, 40(%3)\n"
22756+ "26: movl %%edx, 44(%3)\n"
22757+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22758+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22759+ "29: movl %%eax, 48(%3)\n"
22760+ "30: movl %%edx, 52(%3)\n"
22761+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22762+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22763+ "33: movl %%eax, 56(%3)\n"
22764+ "34: movl %%edx, 60(%3)\n"
22765+ " addl $-64, %0\n"
22766+ " addl $64, %4\n"
22767+ " addl $64, %3\n"
22768+ " cmpl $63, %0\n"
22769+ " ja 1b\n"
22770+ "35: movl %0, %%eax\n"
22771+ " shrl $2, %0\n"
22772+ " andl $3, %%eax\n"
22773+ " cld\n"
22774+ "99: rep; "__copyuser_seg" movsl\n"
22775+ "36: movl %%eax, %0\n"
22776+ "37: rep; "__copyuser_seg" movsb\n"
22777+ "100:\n"
22778+ ".section .fixup,\"ax\"\n"
22779+ "101: lea 0(%%eax,%0,4),%0\n"
22780+ " jmp 100b\n"
22781+ ".previous\n"
22782+ _ASM_EXTABLE(1b,100b)
22783+ _ASM_EXTABLE(2b,100b)
22784+ _ASM_EXTABLE(3b,100b)
22785+ _ASM_EXTABLE(4b,100b)
22786+ _ASM_EXTABLE(5b,100b)
22787+ _ASM_EXTABLE(6b,100b)
22788+ _ASM_EXTABLE(7b,100b)
22789+ _ASM_EXTABLE(8b,100b)
22790+ _ASM_EXTABLE(9b,100b)
22791+ _ASM_EXTABLE(10b,100b)
22792+ _ASM_EXTABLE(11b,100b)
22793+ _ASM_EXTABLE(12b,100b)
22794+ _ASM_EXTABLE(13b,100b)
22795+ _ASM_EXTABLE(14b,100b)
22796+ _ASM_EXTABLE(15b,100b)
22797+ _ASM_EXTABLE(16b,100b)
22798+ _ASM_EXTABLE(17b,100b)
22799+ _ASM_EXTABLE(18b,100b)
22800+ _ASM_EXTABLE(19b,100b)
22801+ _ASM_EXTABLE(20b,100b)
22802+ _ASM_EXTABLE(21b,100b)
22803+ _ASM_EXTABLE(22b,100b)
22804+ _ASM_EXTABLE(23b,100b)
22805+ _ASM_EXTABLE(24b,100b)
22806+ _ASM_EXTABLE(25b,100b)
22807+ _ASM_EXTABLE(26b,100b)
22808+ _ASM_EXTABLE(27b,100b)
22809+ _ASM_EXTABLE(28b,100b)
22810+ _ASM_EXTABLE(29b,100b)
22811+ _ASM_EXTABLE(30b,100b)
22812+ _ASM_EXTABLE(31b,100b)
22813+ _ASM_EXTABLE(32b,100b)
22814+ _ASM_EXTABLE(33b,100b)
22815+ _ASM_EXTABLE(34b,100b)
22816+ _ASM_EXTABLE(35b,100b)
22817+ _ASM_EXTABLE(36b,100b)
22818+ _ASM_EXTABLE(37b,100b)
22819+ _ASM_EXTABLE(99b,101b)
22820+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
22821+ : "1"(to), "2"(from), "0"(size)
22822+ : "eax", "edx", "memory");
22823+ return size;
22824+}
22825+
22826+static unsigned long
22827+__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
22828+static unsigned long
22829 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22830 {
22831 int d0, d1;
22832 __asm__ __volatile__(
22833 " .align 2,0x90\n"
22834- "0: movl 32(%4), %%eax\n"
22835+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22836 " cmpl $67, %0\n"
22837 " jbe 2f\n"
22838- "1: movl 64(%4), %%eax\n"
22839+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22840 " .align 2,0x90\n"
22841- "2: movl 0(%4), %%eax\n"
22842- "21: movl 4(%4), %%edx\n"
22843+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22844+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22845 " movl %%eax, 0(%3)\n"
22846 " movl %%edx, 4(%3)\n"
22847- "3: movl 8(%4), %%eax\n"
22848- "31: movl 12(%4),%%edx\n"
22849+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22850+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22851 " movl %%eax, 8(%3)\n"
22852 " movl %%edx, 12(%3)\n"
22853- "4: movl 16(%4), %%eax\n"
22854- "41: movl 20(%4), %%edx\n"
22855+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22856+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22857 " movl %%eax, 16(%3)\n"
22858 " movl %%edx, 20(%3)\n"
22859- "10: movl 24(%4), %%eax\n"
22860- "51: movl 28(%4), %%edx\n"
22861+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22862+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22863 " movl %%eax, 24(%3)\n"
22864 " movl %%edx, 28(%3)\n"
22865- "11: movl 32(%4), %%eax\n"
22866- "61: movl 36(%4), %%edx\n"
22867+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22868+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22869 " movl %%eax, 32(%3)\n"
22870 " movl %%edx, 36(%3)\n"
22871- "12: movl 40(%4), %%eax\n"
22872- "71: movl 44(%4), %%edx\n"
22873+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22874+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22875 " movl %%eax, 40(%3)\n"
22876 " movl %%edx, 44(%3)\n"
22877- "13: movl 48(%4), %%eax\n"
22878- "81: movl 52(%4), %%edx\n"
22879+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22880+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22881 " movl %%eax, 48(%3)\n"
22882 " movl %%edx, 52(%3)\n"
22883- "14: movl 56(%4), %%eax\n"
22884- "91: movl 60(%4), %%edx\n"
22885+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22886+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22887 " movl %%eax, 56(%3)\n"
22888 " movl %%edx, 60(%3)\n"
22889 " addl $-64, %0\n"
22890@@ -252,9 +362,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22891 " shrl $2, %0\n"
22892 " andl $3, %%eax\n"
22893 " cld\n"
22894- "6: rep; movsl\n"
22895+ "6: rep; "__copyuser_seg" movsl\n"
22896 " movl %%eax,%0\n"
22897- "7: rep; movsb\n"
22898+ "7: rep; "__copyuser_seg" movsb\n"
22899 "8:\n"
22900 ".section .fixup,\"ax\"\n"
22901 "9: lea 0(%%eax,%0,4),%0\n"
22902@@ -298,47 +408,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22903 */
22904
22905 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22906+ const void __user *from, unsigned long size) __size_overflow(3);
22907+static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22908 const void __user *from, unsigned long size)
22909 {
22910 int d0, d1;
22911
22912 __asm__ __volatile__(
22913 " .align 2,0x90\n"
22914- "0: movl 32(%4), %%eax\n"
22915+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22916 " cmpl $67, %0\n"
22917 " jbe 2f\n"
22918- "1: movl 64(%4), %%eax\n"
22919+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22920 " .align 2,0x90\n"
22921- "2: movl 0(%4), %%eax\n"
22922- "21: movl 4(%4), %%edx\n"
22923+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22924+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22925 " movnti %%eax, 0(%3)\n"
22926 " movnti %%edx, 4(%3)\n"
22927- "3: movl 8(%4), %%eax\n"
22928- "31: movl 12(%4),%%edx\n"
22929+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22930+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22931 " movnti %%eax, 8(%3)\n"
22932 " movnti %%edx, 12(%3)\n"
22933- "4: movl 16(%4), %%eax\n"
22934- "41: movl 20(%4), %%edx\n"
22935+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22936+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22937 " movnti %%eax, 16(%3)\n"
22938 " movnti %%edx, 20(%3)\n"
22939- "10: movl 24(%4), %%eax\n"
22940- "51: movl 28(%4), %%edx\n"
22941+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22942+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22943 " movnti %%eax, 24(%3)\n"
22944 " movnti %%edx, 28(%3)\n"
22945- "11: movl 32(%4), %%eax\n"
22946- "61: movl 36(%4), %%edx\n"
22947+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22948+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22949 " movnti %%eax, 32(%3)\n"
22950 " movnti %%edx, 36(%3)\n"
22951- "12: movl 40(%4), %%eax\n"
22952- "71: movl 44(%4), %%edx\n"
22953+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22954+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22955 " movnti %%eax, 40(%3)\n"
22956 " movnti %%edx, 44(%3)\n"
22957- "13: movl 48(%4), %%eax\n"
22958- "81: movl 52(%4), %%edx\n"
22959+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22960+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22961 " movnti %%eax, 48(%3)\n"
22962 " movnti %%edx, 52(%3)\n"
22963- "14: movl 56(%4), %%eax\n"
22964- "91: movl 60(%4), %%edx\n"
22965+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22966+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22967 " movnti %%eax, 56(%3)\n"
22968 " movnti %%edx, 60(%3)\n"
22969 " addl $-64, %0\n"
22970@@ -351,9 +463,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22971 " shrl $2, %0\n"
22972 " andl $3, %%eax\n"
22973 " cld\n"
22974- "6: rep; movsl\n"
22975+ "6: rep; "__copyuser_seg" movsl\n"
22976 " movl %%eax,%0\n"
22977- "7: rep; movsb\n"
22978+ "7: rep; "__copyuser_seg" movsb\n"
22979 "8:\n"
22980 ".section .fixup,\"ax\"\n"
22981 "9: lea 0(%%eax,%0,4),%0\n"
22982@@ -392,47 +504,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22983 }
22984
22985 static unsigned long __copy_user_intel_nocache(void *to,
22986+ const void __user *from, unsigned long size) __size_overflow(3);
22987+static unsigned long __copy_user_intel_nocache(void *to,
22988 const void __user *from, unsigned long size)
22989 {
22990 int d0, d1;
22991
22992 __asm__ __volatile__(
22993 " .align 2,0x90\n"
22994- "0: movl 32(%4), %%eax\n"
22995+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22996 " cmpl $67, %0\n"
22997 " jbe 2f\n"
22998- "1: movl 64(%4), %%eax\n"
22999+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23000 " .align 2,0x90\n"
23001- "2: movl 0(%4), %%eax\n"
23002- "21: movl 4(%4), %%edx\n"
23003+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23004+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23005 " movnti %%eax, 0(%3)\n"
23006 " movnti %%edx, 4(%3)\n"
23007- "3: movl 8(%4), %%eax\n"
23008- "31: movl 12(%4),%%edx\n"
23009+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23010+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23011 " movnti %%eax, 8(%3)\n"
23012 " movnti %%edx, 12(%3)\n"
23013- "4: movl 16(%4), %%eax\n"
23014- "41: movl 20(%4), %%edx\n"
23015+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23016+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23017 " movnti %%eax, 16(%3)\n"
23018 " movnti %%edx, 20(%3)\n"
23019- "10: movl 24(%4), %%eax\n"
23020- "51: movl 28(%4), %%edx\n"
23021+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23022+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23023 " movnti %%eax, 24(%3)\n"
23024 " movnti %%edx, 28(%3)\n"
23025- "11: movl 32(%4), %%eax\n"
23026- "61: movl 36(%4), %%edx\n"
23027+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23028+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23029 " movnti %%eax, 32(%3)\n"
23030 " movnti %%edx, 36(%3)\n"
23031- "12: movl 40(%4), %%eax\n"
23032- "71: movl 44(%4), %%edx\n"
23033+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23034+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23035 " movnti %%eax, 40(%3)\n"
23036 " movnti %%edx, 44(%3)\n"
23037- "13: movl 48(%4), %%eax\n"
23038- "81: movl 52(%4), %%edx\n"
23039+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23040+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23041 " movnti %%eax, 48(%3)\n"
23042 " movnti %%edx, 52(%3)\n"
23043- "14: movl 56(%4), %%eax\n"
23044- "91: movl 60(%4), %%edx\n"
23045+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23046+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23047 " movnti %%eax, 56(%3)\n"
23048 " movnti %%edx, 60(%3)\n"
23049 " addl $-64, %0\n"
23050@@ -445,9 +559,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23051 " shrl $2, %0\n"
23052 " andl $3, %%eax\n"
23053 " cld\n"
23054- "6: rep; movsl\n"
23055+ "6: rep; "__copyuser_seg" movsl\n"
23056 " movl %%eax,%0\n"
23057- "7: rep; movsb\n"
23058+ "7: rep; "__copyuser_seg" movsb\n"
23059 "8:\n"
23060 ".section .fixup,\"ax\"\n"
23061 "9: lea 0(%%eax,%0,4),%0\n"
23062@@ -487,32 +601,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23063 */
23064 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23065 unsigned long size);
23066-unsigned long __copy_user_intel(void __user *to, const void *from,
23067+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23068+ unsigned long size);
23069+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23070 unsigned long size);
23071 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23072 const void __user *from, unsigned long size);
23073 #endif /* CONFIG_X86_INTEL_USERCOPY */
23074
23075 /* Generic arbitrary sized copy. */
23076-#define __copy_user(to, from, size) \
23077+#define __copy_user(to, from, size, prefix, set, restore) \
23078 do { \
23079 int __d0, __d1, __d2; \
23080 __asm__ __volatile__( \
23081+ set \
23082 " cmp $7,%0\n" \
23083 " jbe 1f\n" \
23084 " movl %1,%0\n" \
23085 " negl %0\n" \
23086 " andl $7,%0\n" \
23087 " subl %0,%3\n" \
23088- "4: rep; movsb\n" \
23089+ "4: rep; "prefix"movsb\n" \
23090 " movl %3,%0\n" \
23091 " shrl $2,%0\n" \
23092 " andl $3,%3\n" \
23093 " .align 2,0x90\n" \
23094- "0: rep; movsl\n" \
23095+ "0: rep; "prefix"movsl\n" \
23096 " movl %3,%0\n" \
23097- "1: rep; movsb\n" \
23098+ "1: rep; "prefix"movsb\n" \
23099 "2:\n" \
23100+ restore \
23101 ".section .fixup,\"ax\"\n" \
23102 "5: addl %3,%0\n" \
23103 " jmp 2b\n" \
23104@@ -537,14 +655,14 @@ do { \
23105 " negl %0\n" \
23106 " andl $7,%0\n" \
23107 " subl %0,%3\n" \
23108- "4: rep; movsb\n" \
23109+ "4: rep; "__copyuser_seg"movsb\n" \
23110 " movl %3,%0\n" \
23111 " shrl $2,%0\n" \
23112 " andl $3,%3\n" \
23113 " .align 2,0x90\n" \
23114- "0: rep; movsl\n" \
23115+ "0: rep; "__copyuser_seg"movsl\n" \
23116 " movl %3,%0\n" \
23117- "1: rep; movsb\n" \
23118+ "1: rep; "__copyuser_seg"movsb\n" \
23119 "2:\n" \
23120 ".section .fixup,\"ax\"\n" \
23121 "5: addl %3,%0\n" \
23122@@ -627,9 +745,9 @@ survive:
23123 }
23124 #endif
23125 if (movsl_is_ok(to, from, n))
23126- __copy_user(to, from, n);
23127+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23128 else
23129- n = __copy_user_intel(to, from, n);
23130+ n = __generic_copy_to_user_intel(to, from, n);
23131 return n;
23132 }
23133 EXPORT_SYMBOL(__copy_to_user_ll);
23134@@ -649,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23135 unsigned long n)
23136 {
23137 if (movsl_is_ok(to, from, n))
23138- __copy_user(to, from, n);
23139+ __copy_user(to, from, n, __copyuser_seg, "", "");
23140 else
23141- n = __copy_user_intel((void __user *)to,
23142- (const void *)from, n);
23143+ n = __generic_copy_from_user_intel(to, from, n);
23144 return n;
23145 }
23146 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23147@@ -679,65 +796,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23148 if (n > 64 && cpu_has_xmm2)
23149 n = __copy_user_intel_nocache(to, from, n);
23150 else
23151- __copy_user(to, from, n);
23152+ __copy_user(to, from, n, __copyuser_seg, "", "");
23153 #else
23154- __copy_user(to, from, n);
23155+ __copy_user(to, from, n, __copyuser_seg, "", "");
23156 #endif
23157 return n;
23158 }
23159 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23160
23161-/**
23162- * copy_to_user: - Copy a block of data into user space.
23163- * @to: Destination address, in user space.
23164- * @from: Source address, in kernel space.
23165- * @n: Number of bytes to copy.
23166- *
23167- * Context: User context only. This function may sleep.
23168- *
23169- * Copy data from kernel space to user space.
23170- *
23171- * Returns number of bytes that could not be copied.
23172- * On success, this will be zero.
23173- */
23174-unsigned long
23175-copy_to_user(void __user *to, const void *from, unsigned long n)
23176-{
23177- if (access_ok(VERIFY_WRITE, to, n))
23178- n = __copy_to_user(to, from, n);
23179- return n;
23180-}
23181-EXPORT_SYMBOL(copy_to_user);
23182-
23183-/**
23184- * copy_from_user: - Copy a block of data from user space.
23185- * @to: Destination address, in kernel space.
23186- * @from: Source address, in user space.
23187- * @n: Number of bytes to copy.
23188- *
23189- * Context: User context only. This function may sleep.
23190- *
23191- * Copy data from user space to kernel space.
23192- *
23193- * Returns number of bytes that could not be copied.
23194- * On success, this will be zero.
23195- *
23196- * If some data could not be copied, this function will pad the copied
23197- * data to the requested size using zero bytes.
23198- */
23199-unsigned long
23200-_copy_from_user(void *to, const void __user *from, unsigned long n)
23201-{
23202- if (access_ok(VERIFY_READ, from, n))
23203- n = __copy_from_user(to, from, n);
23204- else
23205- memset(to, 0, n);
23206- return n;
23207-}
23208-EXPORT_SYMBOL(_copy_from_user);
23209-
23210 void copy_from_user_overflow(void)
23211 {
23212 WARN(1, "Buffer overflow detected!\n");
23213 }
23214 EXPORT_SYMBOL(copy_from_user_overflow);
23215+
23216+void copy_to_user_overflow(void)
23217+{
23218+ WARN(1, "Buffer overflow detected!\n");
23219+}
23220+EXPORT_SYMBOL(copy_to_user_overflow);
23221+
23222+#ifdef CONFIG_PAX_MEMORY_UDEREF
23223+void __set_fs(mm_segment_t x)
23224+{
23225+ switch (x.seg) {
23226+ case 0:
23227+ loadsegment(gs, 0);
23228+ break;
23229+ case TASK_SIZE_MAX:
23230+ loadsegment(gs, __USER_DS);
23231+ break;
23232+ case -1UL:
23233+ loadsegment(gs, __KERNEL_DS);
23234+ break;
23235+ default:
23236+ BUG();
23237+ }
23238+ return;
23239+}
23240+EXPORT_SYMBOL(__set_fs);
23241+
23242+void set_fs(mm_segment_t x)
23243+{
23244+ current_thread_info()->addr_limit = x;
23245+ __set_fs(x);
23246+}
23247+EXPORT_SYMBOL(set_fs);
23248+#endif
23249diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23250index e5b130b..6690d31 100644
23251--- a/arch/x86/lib/usercopy_64.c
23252+++ b/arch/x86/lib/usercopy_64.c
23253@@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23254 {
23255 long __d0;
23256 might_fault();
23257+
23258+#ifdef CONFIG_PAX_MEMORY_UDEREF
23259+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23260+ addr += PAX_USER_SHADOW_BASE;
23261+#endif
23262+
23263 /* no memory constraint because it doesn't change any memory gcc knows
23264 about */
23265 asm volatile(
23266@@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23267 }
23268 EXPORT_SYMBOL(clear_user);
23269
23270-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23271+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23272 {
23273- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23274- return copy_user_generic((__force void *)to, (__force void *)from, len);
23275- }
23276- return len;
23277+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23278+
23279+#ifdef CONFIG_PAX_MEMORY_UDEREF
23280+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23281+ to += PAX_USER_SHADOW_BASE;
23282+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23283+ from += PAX_USER_SHADOW_BASE;
23284+#endif
23285+
23286+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23287+ }
23288+ return len;
23289 }
23290 EXPORT_SYMBOL(copy_in_user);
23291
23292@@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23293 * it is not necessary to optimize tail handling.
23294 */
23295 unsigned long
23296-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23297+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23298 {
23299 char c;
23300 unsigned zero_len;
23301@@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23302 break;
23303 return len;
23304 }
23305+
23306+void copy_from_user_overflow(void)
23307+{
23308+ WARN(1, "Buffer overflow detected!\n");
23309+}
23310+EXPORT_SYMBOL(copy_from_user_overflow);
23311+
23312+void copy_to_user_overflow(void)
23313+{
23314+ WARN(1, "Buffer overflow detected!\n");
23315+}
23316+EXPORT_SYMBOL(copy_to_user_overflow);
23317diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23318index 903ec1e..833f340 100644
23319--- a/arch/x86/mm/extable.c
23320+++ b/arch/x86/mm/extable.c
23321@@ -6,12 +6,25 @@
23322 static inline unsigned long
23323 ex_insn_addr(const struct exception_table_entry *x)
23324 {
23325- return (unsigned long)&x->insn + x->insn;
23326+//printk(KERN_ERR "fixup %p insn:%x fixup:%x\n", x, x->insn, x->fixup);
23327+ unsigned long reloc = 0;
23328+
23329+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23330+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23331+#endif
23332+
23333+ return (unsigned long)&x->insn + x->insn + reloc;
23334 }
23335 static inline unsigned long
23336 ex_fixup_addr(const struct exception_table_entry *x)
23337 {
23338- return (unsigned long)&x->fixup + x->fixup;
23339+ unsigned long reloc = 0;
23340+
23341+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23342+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23343+#endif
23344+
23345+ return (unsigned long)&x->fixup + x->fixup + reloc;
23346 }
23347
23348 int fixup_exception(struct pt_regs *regs)
23349@@ -20,7 +33,7 @@ int fixup_exception(struct pt_regs *regs)
23350 unsigned long new_ip;
23351
23352 #ifdef CONFIG_PNPBIOS
23353- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23354+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23355 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23356 extern u32 pnp_bios_is_utter_crap;
23357 pnp_bios_is_utter_crap = 1;
23358@@ -34,6 +47,7 @@ int fixup_exception(struct pt_regs *regs)
23359 #endif
23360
23361 fixup = search_exception_tables(regs->ip);
23362+//printk(KERN_ERR "fixup %p %lx\n", fixup, regs->ip);
23363 if (fixup) {
23364 new_ip = ex_fixup_addr(fixup);
23365
23366diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23367index 76dcd9d..e9dffde 100644
23368--- a/arch/x86/mm/fault.c
23369+++ b/arch/x86/mm/fault.c
23370@@ -13,11 +13,18 @@
23371 #include <linux/perf_event.h> /* perf_sw_event */
23372 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23373 #include <linux/prefetch.h> /* prefetchw */
23374+#include <linux/unistd.h>
23375+#include <linux/compiler.h>
23376
23377 #include <asm/traps.h> /* dotraplinkage, ... */
23378 #include <asm/pgalloc.h> /* pgd_*(), ... */
23379 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23380 #include <asm/fixmap.h> /* VSYSCALL_START */
23381+#include <asm/tlbflush.h>
23382+
23383+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23384+#include <asm/stacktrace.h>
23385+#endif
23386
23387 /*
23388 * Page fault error code bits:
23389@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23390 int ret = 0;
23391
23392 /* kprobe_running() needs smp_processor_id() */
23393- if (kprobes_built_in() && !user_mode_vm(regs)) {
23394+ if (kprobes_built_in() && !user_mode(regs)) {
23395 preempt_disable();
23396 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23397 ret = 1;
23398@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23399 return !instr_lo || (instr_lo>>1) == 1;
23400 case 0x00:
23401 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23402- if (probe_kernel_address(instr, opcode))
23403+ if (user_mode(regs)) {
23404+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23405+ return 0;
23406+ } else if (probe_kernel_address(instr, opcode))
23407 return 0;
23408
23409 *prefetch = (instr_lo == 0xF) &&
23410@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23411 while (instr < max_instr) {
23412 unsigned char opcode;
23413
23414- if (probe_kernel_address(instr, opcode))
23415+ if (user_mode(regs)) {
23416+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23417+ break;
23418+ } else if (probe_kernel_address(instr, opcode))
23419 break;
23420
23421 instr++;
23422@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23423 force_sig_info(si_signo, &info, tsk);
23424 }
23425
23426+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23427+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23428+#endif
23429+
23430+#ifdef CONFIG_PAX_EMUTRAMP
23431+static int pax_handle_fetch_fault(struct pt_regs *regs);
23432+#endif
23433+
23434+#ifdef CONFIG_PAX_PAGEEXEC
23435+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23436+{
23437+ pgd_t *pgd;
23438+ pud_t *pud;
23439+ pmd_t *pmd;
23440+
23441+ pgd = pgd_offset(mm, address);
23442+ if (!pgd_present(*pgd))
23443+ return NULL;
23444+ pud = pud_offset(pgd, address);
23445+ if (!pud_present(*pud))
23446+ return NULL;
23447+ pmd = pmd_offset(pud, address);
23448+ if (!pmd_present(*pmd))
23449+ return NULL;
23450+ return pmd;
23451+}
23452+#endif
23453+
23454 DEFINE_SPINLOCK(pgd_lock);
23455 LIST_HEAD(pgd_list);
23456
23457@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23458 for (address = VMALLOC_START & PMD_MASK;
23459 address >= TASK_SIZE && address < FIXADDR_TOP;
23460 address += PMD_SIZE) {
23461+
23462+#ifdef CONFIG_PAX_PER_CPU_PGD
23463+ unsigned long cpu;
23464+#else
23465 struct page *page;
23466+#endif
23467
23468 spin_lock(&pgd_lock);
23469+
23470+#ifdef CONFIG_PAX_PER_CPU_PGD
23471+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23472+ pgd_t *pgd = get_cpu_pgd(cpu);
23473+ pmd_t *ret;
23474+#else
23475 list_for_each_entry(page, &pgd_list, lru) {
23476+ pgd_t *pgd = page_address(page);
23477 spinlock_t *pgt_lock;
23478 pmd_t *ret;
23479
23480@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23481 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23482
23483 spin_lock(pgt_lock);
23484- ret = vmalloc_sync_one(page_address(page), address);
23485+#endif
23486+
23487+ ret = vmalloc_sync_one(pgd, address);
23488+
23489+#ifndef CONFIG_PAX_PER_CPU_PGD
23490 spin_unlock(pgt_lock);
23491+#endif
23492
23493 if (!ret)
23494 break;
23495@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23496 * an interrupt in the middle of a task switch..
23497 */
23498 pgd_paddr = read_cr3();
23499+
23500+#ifdef CONFIG_PAX_PER_CPU_PGD
23501+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23502+#endif
23503+
23504 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23505 if (!pmd_k)
23506 return -1;
23507@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23508 * happen within a race in page table update. In the later
23509 * case just flush:
23510 */
23511+
23512+#ifdef CONFIG_PAX_PER_CPU_PGD
23513+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23514+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23515+#else
23516 pgd = pgd_offset(current->active_mm, address);
23517+#endif
23518+
23519 pgd_ref = pgd_offset_k(address);
23520 if (pgd_none(*pgd_ref))
23521 return -1;
23522@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23523 static int is_errata100(struct pt_regs *regs, unsigned long address)
23524 {
23525 #ifdef CONFIG_X86_64
23526- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23527+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23528 return 1;
23529 #endif
23530 return 0;
23531@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23532 }
23533
23534 static const char nx_warning[] = KERN_CRIT
23535-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23536+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23537
23538 static void
23539 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23540@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23541 if (!oops_may_print())
23542 return;
23543
23544- if (error_code & PF_INSTR) {
23545+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23546 unsigned int level;
23547
23548 pte_t *pte = lookup_address(address, &level);
23549
23550 if (pte && pte_present(*pte) && !pte_exec(*pte))
23551- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23552+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23553 }
23554
23555+#ifdef CONFIG_PAX_KERNEXEC
23556+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23557+ if (current->signal->curr_ip)
23558+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23559+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23560+ else
23561+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23562+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23563+ }
23564+#endif
23565+
23566 printk(KERN_ALERT "BUG: unable to handle kernel ");
23567 if (address < PAGE_SIZE)
23568 printk(KERN_CONT "NULL pointer dereference");
23569@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23570 }
23571 #endif
23572
23573+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23574+ if (pax_is_fetch_fault(regs, error_code, address)) {
23575+
23576+#ifdef CONFIG_PAX_EMUTRAMP
23577+ switch (pax_handle_fetch_fault(regs)) {
23578+ case 2:
23579+ return;
23580+ }
23581+#endif
23582+
23583+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23584+ do_group_exit(SIGKILL);
23585+ }
23586+#endif
23587+
23588 if (unlikely(show_unhandled_signals))
23589 show_signal_msg(regs, error_code, address, tsk);
23590
23591@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23592 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23593 printk(KERN_ERR
23594 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23595- tsk->comm, tsk->pid, address);
23596+ tsk->comm, task_pid_nr(tsk), address);
23597 code = BUS_MCEERR_AR;
23598 }
23599 #endif
23600@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23601 return 1;
23602 }
23603
23604+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23605+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23606+{
23607+ pte_t *pte;
23608+ pmd_t *pmd;
23609+ spinlock_t *ptl;
23610+ unsigned char pte_mask;
23611+
23612+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23613+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
23614+ return 0;
23615+
23616+ /* PaX: it's our fault, let's handle it if we can */
23617+
23618+ /* PaX: take a look at read faults before acquiring any locks */
23619+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23620+ /* instruction fetch attempt from a protected page in user mode */
23621+ up_read(&mm->mmap_sem);
23622+
23623+#ifdef CONFIG_PAX_EMUTRAMP
23624+ switch (pax_handle_fetch_fault(regs)) {
23625+ case 2:
23626+ return 1;
23627+ }
23628+#endif
23629+
23630+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23631+ do_group_exit(SIGKILL);
23632+ }
23633+
23634+ pmd = pax_get_pmd(mm, address);
23635+ if (unlikely(!pmd))
23636+ return 0;
23637+
23638+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23639+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23640+ pte_unmap_unlock(pte, ptl);
23641+ return 0;
23642+ }
23643+
23644+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23645+ /* write attempt to a protected page in user mode */
23646+ pte_unmap_unlock(pte, ptl);
23647+ return 0;
23648+ }
23649+
23650+#ifdef CONFIG_SMP
23651+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23652+#else
23653+ if (likely(address > get_limit(regs->cs)))
23654+#endif
23655+ {
23656+ set_pte(pte, pte_mkread(*pte));
23657+ __flush_tlb_one(address);
23658+ pte_unmap_unlock(pte, ptl);
23659+ up_read(&mm->mmap_sem);
23660+ return 1;
23661+ }
23662+
23663+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23664+
23665+ /*
23666+ * PaX: fill DTLB with user rights and retry
23667+ */
23668+ __asm__ __volatile__ (
23669+ "orb %2,(%1)\n"
23670+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23671+/*
23672+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23673+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23674+ * page fault when examined during a TLB load attempt. this is true not only
23675+ * for PTEs holding a non-present entry but also present entries that will
23676+ * raise a page fault (such as those set up by PaX, or the copy-on-write
23677+ * mechanism). in effect it means that we do *not* need to flush the TLBs
23678+ * for our target pages since their PTEs are simply not in the TLBs at all.
23679+
23680+ * the best thing in omitting it is that we gain around 15-20% speed in the
23681+ * fast path of the page fault handler and can get rid of tracing since we
23682+ * can no longer flush unintended entries.
23683+ */
23684+ "invlpg (%0)\n"
23685+#endif
23686+ __copyuser_seg"testb $0,(%0)\n"
23687+ "xorb %3,(%1)\n"
23688+ :
23689+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23690+ : "memory", "cc");
23691+ pte_unmap_unlock(pte, ptl);
23692+ up_read(&mm->mmap_sem);
23693+ return 1;
23694+}
23695+#endif
23696+
23697 /*
23698 * Handle a spurious fault caused by a stale TLB entry.
23699 *
23700@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23701 static inline int
23702 access_error(unsigned long error_code, struct vm_area_struct *vma)
23703 {
23704+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23705+ return 1;
23706+
23707 if (error_code & PF_WRITE) {
23708 /* write, present and write, not present: */
23709 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23710@@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23711 {
23712 struct vm_area_struct *vma;
23713 struct task_struct *tsk;
23714- unsigned long address;
23715 struct mm_struct *mm;
23716 int fault;
23717 int write = error_code & PF_WRITE;
23718 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23719 (write ? FAULT_FLAG_WRITE : 0);
23720
23721- tsk = current;
23722- mm = tsk->mm;
23723-
23724 /* Get the faulting address: */
23725- address = read_cr2();
23726+ unsigned long address = read_cr2();
23727+
23728+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23729+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23730+ if (!search_exception_tables(regs->ip)) {
23731+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23732+ bad_area_nosemaphore(regs, error_code, address);
23733+ return;
23734+ }
23735+ if (address < PAX_USER_SHADOW_BASE) {
23736+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23737+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23738+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23739+ } else
23740+ address -= PAX_USER_SHADOW_BASE;
23741+ }
23742+#endif
23743+
23744+ tsk = current;
23745+ mm = tsk->mm;
23746
23747 /*
23748 * Detect and handle instructions that would cause a page fault for
23749@@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23750 * User-mode registers count as a user access even for any
23751 * potential system fault or CPU buglet:
23752 */
23753- if (user_mode_vm(regs)) {
23754+ if (user_mode(regs)) {
23755 local_irq_enable();
23756 error_code |= PF_USER;
23757 } else {
23758@@ -1132,6 +1339,11 @@ retry:
23759 might_sleep();
23760 }
23761
23762+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23763+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23764+ return;
23765+#endif
23766+
23767 vma = find_vma(mm, address);
23768 if (unlikely(!vma)) {
23769 bad_area(regs, error_code, address);
23770@@ -1143,18 +1355,24 @@ retry:
23771 bad_area(regs, error_code, address);
23772 return;
23773 }
23774- if (error_code & PF_USER) {
23775- /*
23776- * Accessing the stack below %sp is always a bug.
23777- * The large cushion allows instructions like enter
23778- * and pusha to work. ("enter $65535, $31" pushes
23779- * 32 pointers and then decrements %sp by 65535.)
23780- */
23781- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23782- bad_area(regs, error_code, address);
23783- return;
23784- }
23785+ /*
23786+ * Accessing the stack below %sp is always a bug.
23787+ * The large cushion allows instructions like enter
23788+ * and pusha to work. ("enter $65535, $31" pushes
23789+ * 32 pointers and then decrements %sp by 65535.)
23790+ */
23791+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23792+ bad_area(regs, error_code, address);
23793+ return;
23794 }
23795+
23796+#ifdef CONFIG_PAX_SEGMEXEC
23797+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23798+ bad_area(regs, error_code, address);
23799+ return;
23800+ }
23801+#endif
23802+
23803 if (unlikely(expand_stack(vma, address))) {
23804 bad_area(regs, error_code, address);
23805 return;
23806@@ -1209,3 +1427,292 @@ good_area:
23807
23808 up_read(&mm->mmap_sem);
23809 }
23810+
23811+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23812+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23813+{
23814+ struct mm_struct *mm = current->mm;
23815+ unsigned long ip = regs->ip;
23816+
23817+ if (v8086_mode(regs))
23818+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23819+
23820+#ifdef CONFIG_PAX_PAGEEXEC
23821+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23822+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23823+ return true;
23824+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23825+ return true;
23826+ return false;
23827+ }
23828+#endif
23829+
23830+#ifdef CONFIG_PAX_SEGMEXEC
23831+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23832+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23833+ return true;
23834+ return false;
23835+ }
23836+#endif
23837+
23838+ return false;
23839+}
23840+#endif
23841+
23842+#ifdef CONFIG_PAX_EMUTRAMP
23843+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23844+{
23845+ int err;
23846+
23847+ do { /* PaX: libffi trampoline emulation */
23848+ unsigned char mov, jmp;
23849+ unsigned int addr1, addr2;
23850+
23851+#ifdef CONFIG_X86_64
23852+ if ((regs->ip + 9) >> 32)
23853+ break;
23854+#endif
23855+
23856+ err = get_user(mov, (unsigned char __user *)regs->ip);
23857+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23858+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23859+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23860+
23861+ if (err)
23862+ break;
23863+
23864+ if (mov == 0xB8 && jmp == 0xE9) {
23865+ regs->ax = addr1;
23866+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23867+ return 2;
23868+ }
23869+ } while (0);
23870+
23871+ do { /* PaX: gcc trampoline emulation #1 */
23872+ unsigned char mov1, mov2;
23873+ unsigned short jmp;
23874+ unsigned int addr1, addr2;
23875+
23876+#ifdef CONFIG_X86_64
23877+ if ((regs->ip + 11) >> 32)
23878+ break;
23879+#endif
23880+
23881+ err = get_user(mov1, (unsigned char __user *)regs->ip);
23882+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23883+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23884+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23885+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23886+
23887+ if (err)
23888+ break;
23889+
23890+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23891+ regs->cx = addr1;
23892+ regs->ax = addr2;
23893+ regs->ip = addr2;
23894+ return 2;
23895+ }
23896+ } while (0);
23897+
23898+ do { /* PaX: gcc trampoline emulation #2 */
23899+ unsigned char mov, jmp;
23900+ unsigned int addr1, addr2;
23901+
23902+#ifdef CONFIG_X86_64
23903+ if ((regs->ip + 9) >> 32)
23904+ break;
23905+#endif
23906+
23907+ err = get_user(mov, (unsigned char __user *)regs->ip);
23908+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23909+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23910+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23911+
23912+ if (err)
23913+ break;
23914+
23915+ if (mov == 0xB9 && jmp == 0xE9) {
23916+ regs->cx = addr1;
23917+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23918+ return 2;
23919+ }
23920+ } while (0);
23921+
23922+ return 1; /* PaX in action */
23923+}
23924+
23925+#ifdef CONFIG_X86_64
23926+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
23927+{
23928+ int err;
23929+
23930+ do { /* PaX: libffi trampoline emulation */
23931+ unsigned short mov1, mov2, jmp1;
23932+ unsigned char stcclc, jmp2;
23933+ unsigned long addr1, addr2;
23934+
23935+ err = get_user(mov1, (unsigned short __user *)regs->ip);
23936+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23937+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23938+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23939+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
23940+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
23941+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
23942+
23943+ if (err)
23944+ break;
23945+
23946+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23947+ regs->r11 = addr1;
23948+ regs->r10 = addr2;
23949+ if (stcclc == 0xF8)
23950+ regs->flags &= ~X86_EFLAGS_CF;
23951+ else
23952+ regs->flags |= X86_EFLAGS_CF;
23953+ regs->ip = addr1;
23954+ return 2;
23955+ }
23956+ } while (0);
23957+
23958+ do { /* PaX: gcc trampoline emulation #1 */
23959+ unsigned short mov1, mov2, jmp1;
23960+ unsigned char jmp2;
23961+ unsigned int addr1;
23962+ unsigned long addr2;
23963+
23964+ err = get_user(mov1, (unsigned short __user *)regs->ip);
23965+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
23966+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
23967+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
23968+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
23969+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
23970+
23971+ if (err)
23972+ break;
23973+
23974+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23975+ regs->r11 = addr1;
23976+ regs->r10 = addr2;
23977+ regs->ip = addr1;
23978+ return 2;
23979+ }
23980+ } while (0);
23981+
23982+ do { /* PaX: gcc trampoline emulation #2 */
23983+ unsigned short mov1, mov2, jmp1;
23984+ unsigned char jmp2;
23985+ unsigned long addr1, addr2;
23986+
23987+ err = get_user(mov1, (unsigned short __user *)regs->ip);
23988+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23989+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23990+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23991+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
23992+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
23993+
23994+ if (err)
23995+ break;
23996+
23997+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23998+ regs->r11 = addr1;
23999+ regs->r10 = addr2;
24000+ regs->ip = addr1;
24001+ return 2;
24002+ }
24003+ } while (0);
24004+
24005+ return 1; /* PaX in action */
24006+}
24007+#endif
24008+
24009+/*
24010+ * PaX: decide what to do with offenders (regs->ip = fault address)
24011+ *
24012+ * returns 1 when task should be killed
24013+ * 2 when gcc trampoline was detected
24014+ */
24015+static int pax_handle_fetch_fault(struct pt_regs *regs)
24016+{
24017+ if (v8086_mode(regs))
24018+ return 1;
24019+
24020+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24021+ return 1;
24022+
24023+#ifdef CONFIG_X86_32
24024+ return pax_handle_fetch_fault_32(regs);
24025+#else
24026+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24027+ return pax_handle_fetch_fault_32(regs);
24028+ else
24029+ return pax_handle_fetch_fault_64(regs);
24030+#endif
24031+}
24032+#endif
24033+
24034+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24035+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24036+{
24037+ long i;
24038+
24039+ printk(KERN_ERR "PAX: bytes at PC: ");
24040+ for (i = 0; i < 20; i++) {
24041+ unsigned char c;
24042+ if (get_user(c, (unsigned char __force_user *)pc+i))
24043+ printk(KERN_CONT "?? ");
24044+ else
24045+ printk(KERN_CONT "%02x ", c);
24046+ }
24047+ printk("\n");
24048+
24049+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24050+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24051+ unsigned long c;
24052+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24053+#ifdef CONFIG_X86_32
24054+ printk(KERN_CONT "???????? ");
24055+#else
24056+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24057+ printk(KERN_CONT "???????? ???????? ");
24058+ else
24059+ printk(KERN_CONT "???????????????? ");
24060+#endif
24061+ } else {
24062+#ifdef CONFIG_X86_64
24063+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24064+ printk(KERN_CONT "%08x ", (unsigned int)c);
24065+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24066+ } else
24067+#endif
24068+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24069+ }
24070+ }
24071+ printk("\n");
24072+}
24073+#endif
24074+
24075+/**
24076+ * probe_kernel_write(): safely attempt to write to a location
24077+ * @dst: address to write to
24078+ * @src: pointer to the data that shall be written
24079+ * @size: size of the data chunk
24080+ *
24081+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24082+ * happens, handle that and return -EFAULT.
24083+ */
24084+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24085+{
24086+ long ret;
24087+ mm_segment_t old_fs = get_fs();
24088+
24089+ set_fs(KERNEL_DS);
24090+ pagefault_disable();
24091+ pax_open_kernel();
24092+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24093+ pax_close_kernel();
24094+ pagefault_enable();
24095+ set_fs(old_fs);
24096+
24097+ return ret ? -EFAULT : 0;
24098+}
24099diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24100index dd74e46..7d26398 100644
24101--- a/arch/x86/mm/gup.c
24102+++ b/arch/x86/mm/gup.c
24103@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24104 addr = start;
24105 len = (unsigned long) nr_pages << PAGE_SHIFT;
24106 end = start + len;
24107- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24108+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24109 (void __user *)start, len)))
24110 return 0;
24111
24112diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24113index 6f31ee5..8ee4164 100644
24114--- a/arch/x86/mm/highmem_32.c
24115+++ b/arch/x86/mm/highmem_32.c
24116@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24117 idx = type + KM_TYPE_NR*smp_processor_id();
24118 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24119 BUG_ON(!pte_none(*(kmap_pte-idx)));
24120+
24121+ pax_open_kernel();
24122 set_pte(kmap_pte-idx, mk_pte(page, prot));
24123+ pax_close_kernel();
24124+
24125 arch_flush_lazy_mmu_mode();
24126
24127 return (void *)vaddr;
24128diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24129index f6679a7..8f795a3 100644
24130--- a/arch/x86/mm/hugetlbpage.c
24131+++ b/arch/x86/mm/hugetlbpage.c
24132@@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24133 struct hstate *h = hstate_file(file);
24134 struct mm_struct *mm = current->mm;
24135 struct vm_area_struct *vma;
24136- unsigned long start_addr;
24137+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24138+
24139+#ifdef CONFIG_PAX_SEGMEXEC
24140+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24141+ pax_task_size = SEGMEXEC_TASK_SIZE;
24142+#endif
24143+
24144+ pax_task_size -= PAGE_SIZE;
24145
24146 if (len > mm->cached_hole_size) {
24147- start_addr = mm->free_area_cache;
24148+ start_addr = mm->free_area_cache;
24149 } else {
24150- start_addr = TASK_UNMAPPED_BASE;
24151- mm->cached_hole_size = 0;
24152+ start_addr = mm->mmap_base;
24153+ mm->cached_hole_size = 0;
24154 }
24155
24156 full_search:
24157@@ -280,26 +287,27 @@ full_search:
24158
24159 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24160 /* At this point: (!vma || addr < vma->vm_end). */
24161- if (TASK_SIZE - len < addr) {
24162+ if (pax_task_size - len < addr) {
24163 /*
24164 * Start a new search - just in case we missed
24165 * some holes.
24166 */
24167- if (start_addr != TASK_UNMAPPED_BASE) {
24168- start_addr = TASK_UNMAPPED_BASE;
24169+ if (start_addr != mm->mmap_base) {
24170+ start_addr = mm->mmap_base;
24171 mm->cached_hole_size = 0;
24172 goto full_search;
24173 }
24174 return -ENOMEM;
24175 }
24176- if (!vma || addr + len <= vma->vm_start) {
24177- mm->free_area_cache = addr + len;
24178- return addr;
24179- }
24180+ if (check_heap_stack_gap(vma, addr, len))
24181+ break;
24182 if (addr + mm->cached_hole_size < vma->vm_start)
24183 mm->cached_hole_size = vma->vm_start - addr;
24184 addr = ALIGN(vma->vm_end, huge_page_size(h));
24185 }
24186+
24187+ mm->free_area_cache = addr + len;
24188+ return addr;
24189 }
24190
24191 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24192@@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24193 struct mm_struct *mm = current->mm;
24194 struct vm_area_struct *vma;
24195 unsigned long base = mm->mmap_base;
24196- unsigned long addr = addr0;
24197+ unsigned long addr;
24198 unsigned long largest_hole = mm->cached_hole_size;
24199- unsigned long start_addr;
24200
24201 /* don't allow allocations above current base */
24202 if (mm->free_area_cache > base)
24203@@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24204 largest_hole = 0;
24205 mm->free_area_cache = base;
24206 }
24207-try_again:
24208- start_addr = mm->free_area_cache;
24209
24210 /* make sure it can fit in the remaining address space */
24211 if (mm->free_area_cache < len)
24212 goto fail;
24213
24214 /* either no address requested or can't fit in requested address hole */
24215- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24216+ addr = mm->free_area_cache - len;
24217 do {
24218+ addr &= huge_page_mask(h);
24219 /*
24220 * Lookup failure means no vma is above this address,
24221 * i.e. return with success:
24222@@ -340,10 +346,10 @@ try_again:
24223 if (!vma)
24224 return addr;
24225
24226- if (addr + len <= vma->vm_start) {
24227+ if (check_heap_stack_gap(vma, addr, len)) {
24228 /* remember the address as a hint for next time */
24229- mm->cached_hole_size = largest_hole;
24230- return (mm->free_area_cache = addr);
24231+ mm->cached_hole_size = largest_hole;
24232+ return (mm->free_area_cache = addr);
24233 } else if (mm->free_area_cache == vma->vm_end) {
24234 /* pull free_area_cache down to the first hole */
24235 mm->free_area_cache = vma->vm_start;
24236@@ -352,29 +358,34 @@ try_again:
24237
24238 /* remember the largest hole we saw so far */
24239 if (addr + largest_hole < vma->vm_start)
24240- largest_hole = vma->vm_start - addr;
24241+ largest_hole = vma->vm_start - addr;
24242
24243 /* try just below the current vma->vm_start */
24244- addr = (vma->vm_start - len) & huge_page_mask(h);
24245- } while (len <= vma->vm_start);
24246+ addr = skip_heap_stack_gap(vma, len);
24247+ } while (!IS_ERR_VALUE(addr));
24248
24249 fail:
24250 /*
24251- * if hint left us with no space for the requested
24252- * mapping then try again:
24253- */
24254- if (start_addr != base) {
24255- mm->free_area_cache = base;
24256- largest_hole = 0;
24257- goto try_again;
24258- }
24259- /*
24260 * A failed mmap() very likely causes application failure,
24261 * so fall back to the bottom-up function here. This scenario
24262 * can happen with large stack limits and large mmap()
24263 * allocations.
24264 */
24265- mm->free_area_cache = TASK_UNMAPPED_BASE;
24266+
24267+#ifdef CONFIG_PAX_SEGMEXEC
24268+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24269+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24270+ else
24271+#endif
24272+
24273+ mm->mmap_base = TASK_UNMAPPED_BASE;
24274+
24275+#ifdef CONFIG_PAX_RANDMMAP
24276+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24277+ mm->mmap_base += mm->delta_mmap;
24278+#endif
24279+
24280+ mm->free_area_cache = mm->mmap_base;
24281 mm->cached_hole_size = ~0UL;
24282 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24283 len, pgoff, flags);
24284@@ -382,6 +393,7 @@ fail:
24285 /*
24286 * Restore the topdown base:
24287 */
24288+ mm->mmap_base = base;
24289 mm->free_area_cache = base;
24290 mm->cached_hole_size = ~0UL;
24291
24292@@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24293 struct hstate *h = hstate_file(file);
24294 struct mm_struct *mm = current->mm;
24295 struct vm_area_struct *vma;
24296+ unsigned long pax_task_size = TASK_SIZE;
24297
24298 if (len & ~huge_page_mask(h))
24299 return -EINVAL;
24300- if (len > TASK_SIZE)
24301+
24302+#ifdef CONFIG_PAX_SEGMEXEC
24303+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24304+ pax_task_size = SEGMEXEC_TASK_SIZE;
24305+#endif
24306+
24307+ pax_task_size -= PAGE_SIZE;
24308+
24309+ if (len > pax_task_size)
24310 return -ENOMEM;
24311
24312 if (flags & MAP_FIXED) {
24313@@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24314 if (addr) {
24315 addr = ALIGN(addr, huge_page_size(h));
24316 vma = find_vma(mm, addr);
24317- if (TASK_SIZE - len >= addr &&
24318- (!vma || addr + len <= vma->vm_start))
24319+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24320 return addr;
24321 }
24322 if (mm->get_unmapped_area == arch_get_unmapped_area)
24323diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24324index bc4e9d8..ca4c14b 100644
24325--- a/arch/x86/mm/init.c
24326+++ b/arch/x86/mm/init.c
24327@@ -16,6 +16,8 @@
24328 #include <asm/tlb.h>
24329 #include <asm/proto.h>
24330 #include <asm/dma.h> /* for MAX_DMA_PFN */
24331+#include <asm/desc.h>
24332+#include <asm/bios_ebda.h>
24333
24334 unsigned long __initdata pgt_buf_start;
24335 unsigned long __meminitdata pgt_buf_end;
24336@@ -38,7 +40,7 @@ struct map_range {
24337 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24338 int use_pse, int use_gbpages)
24339 {
24340- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24341+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24342 phys_addr_t base;
24343
24344 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24345@@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24346 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24347 * mmio resources as well as potential bios/acpi data regions.
24348 */
24349+
24350+#ifdef CONFIG_GRKERNSEC_KMEM
24351+static unsigned int ebda_start __read_only;
24352+static unsigned int ebda_end __read_only;
24353+#endif
24354+
24355 int devmem_is_allowed(unsigned long pagenr)
24356 {
24357+#ifdef CONFIG_GRKERNSEC_KMEM
24358+ /* allow BDA */
24359+ if (!pagenr)
24360+ return 1;
24361+ /* allow EBDA */
24362+ if (pagenr >= ebda_start && pagenr < ebda_end)
24363+ return 1;
24364+#else
24365+ if (!pagenr)
24366+ return 1;
24367+#ifdef CONFIG_VM86
24368+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24369+ return 1;
24370+#endif
24371+#endif
24372+
24373+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24374+ return 1;
24375+#ifdef CONFIG_GRKERNSEC_KMEM
24376+ /* throw out everything else below 1MB */
24377 if (pagenr <= 256)
24378- return 1;
24379+ return 0;
24380+#endif
24381 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24382 return 0;
24383 if (!page_is_ram(pagenr))
24384@@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24385 #endif
24386 }
24387
24388+#ifdef CONFIG_GRKERNSEC_KMEM
24389+static inline void gr_init_ebda(void)
24390+{
24391+ unsigned int ebda_addr;
24392+ unsigned int ebda_size = 0;
24393+
24394+ ebda_addr = get_bios_ebda();
24395+ if (ebda_addr) {
24396+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24397+ ebda_size <<= 10;
24398+ }
24399+ if (ebda_addr && ebda_size) {
24400+ ebda_start = ebda_addr >> PAGE_SHIFT;
24401+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24402+ } else {
24403+ ebda_start = 0x9f000 >> PAGE_SHIFT;
24404+ ebda_end = 0xa0000 >> PAGE_SHIFT;
24405+ }
24406+}
24407+#else
24408+static inline void gr_init_ebda(void) { }
24409+#endif
24410+
24411 void free_initmem(void)
24412 {
24413+#ifdef CONFIG_PAX_KERNEXEC
24414+#ifdef CONFIG_X86_32
24415+ /* PaX: limit KERNEL_CS to actual size */
24416+ unsigned long addr, limit;
24417+ struct desc_struct d;
24418+ int cpu;
24419+#else
24420+ pgd_t *pgd;
24421+ pud_t *pud;
24422+ pmd_t *pmd;
24423+ unsigned long addr, end;
24424+#endif
24425+#endif
24426+
24427+ gr_init_ebda();
24428+
24429+#ifdef CONFIG_PAX_KERNEXEC
24430+#ifdef CONFIG_X86_32
24431+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24432+ limit = (limit - 1UL) >> PAGE_SHIFT;
24433+
24434+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24435+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24436+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24437+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24438+ }
24439+
24440+ /* PaX: make KERNEL_CS read-only */
24441+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24442+ if (!paravirt_enabled())
24443+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24444+/*
24445+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24446+ pgd = pgd_offset_k(addr);
24447+ pud = pud_offset(pgd, addr);
24448+ pmd = pmd_offset(pud, addr);
24449+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24450+ }
24451+*/
24452+#ifdef CONFIG_X86_PAE
24453+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24454+/*
24455+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24456+ pgd = pgd_offset_k(addr);
24457+ pud = pud_offset(pgd, addr);
24458+ pmd = pmd_offset(pud, addr);
24459+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24460+ }
24461+*/
24462+#endif
24463+
24464+#ifdef CONFIG_MODULES
24465+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24466+#endif
24467+
24468+#else
24469+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24470+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24471+ pgd = pgd_offset_k(addr);
24472+ pud = pud_offset(pgd, addr);
24473+ pmd = pmd_offset(pud, addr);
24474+ if (!pmd_present(*pmd))
24475+ continue;
24476+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24477+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24478+ else
24479+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24480+ }
24481+
24482+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24483+ end = addr + KERNEL_IMAGE_SIZE;
24484+ for (; addr < end; addr += PMD_SIZE) {
24485+ pgd = pgd_offset_k(addr);
24486+ pud = pud_offset(pgd, addr);
24487+ pmd = pmd_offset(pud, addr);
24488+ if (!pmd_present(*pmd))
24489+ continue;
24490+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24491+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24492+ }
24493+#endif
24494+
24495+ flush_tlb_all();
24496+#endif
24497+
24498 free_init_pages("unused kernel memory",
24499 (unsigned long)(&__init_begin),
24500 (unsigned long)(&__init_end));
24501diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24502index 575d86f..4987469 100644
24503--- a/arch/x86/mm/init_32.c
24504+++ b/arch/x86/mm/init_32.c
24505@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24506 }
24507
24508 /*
24509- * Creates a middle page table and puts a pointer to it in the
24510- * given global directory entry. This only returns the gd entry
24511- * in non-PAE compilation mode, since the middle layer is folded.
24512- */
24513-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24514-{
24515- pud_t *pud;
24516- pmd_t *pmd_table;
24517-
24518-#ifdef CONFIG_X86_PAE
24519- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24520- if (after_bootmem)
24521- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24522- else
24523- pmd_table = (pmd_t *)alloc_low_page();
24524- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24525- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24526- pud = pud_offset(pgd, 0);
24527- BUG_ON(pmd_table != pmd_offset(pud, 0));
24528-
24529- return pmd_table;
24530- }
24531-#endif
24532- pud = pud_offset(pgd, 0);
24533- pmd_table = pmd_offset(pud, 0);
24534-
24535- return pmd_table;
24536-}
24537-
24538-/*
24539 * Create a page table and place a pointer to it in a middle page
24540 * directory entry:
24541 */
24542@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24543 page_table = (pte_t *)alloc_low_page();
24544
24545 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24546+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24547+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24548+#else
24549 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24550+#endif
24551 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24552 }
24553
24554 return pte_offset_kernel(pmd, 0);
24555 }
24556
24557+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24558+{
24559+ pud_t *pud;
24560+ pmd_t *pmd_table;
24561+
24562+ pud = pud_offset(pgd, 0);
24563+ pmd_table = pmd_offset(pud, 0);
24564+
24565+ return pmd_table;
24566+}
24567+
24568 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24569 {
24570 int pgd_idx = pgd_index(vaddr);
24571@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24572 int pgd_idx, pmd_idx;
24573 unsigned long vaddr;
24574 pgd_t *pgd;
24575+ pud_t *pud;
24576 pmd_t *pmd;
24577 pte_t *pte = NULL;
24578
24579@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24580 pgd = pgd_base + pgd_idx;
24581
24582 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24583- pmd = one_md_table_init(pgd);
24584- pmd = pmd + pmd_index(vaddr);
24585+ pud = pud_offset(pgd, vaddr);
24586+ pmd = pmd_offset(pud, vaddr);
24587+
24588+#ifdef CONFIG_X86_PAE
24589+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24590+#endif
24591+
24592 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24593 pmd++, pmd_idx++) {
24594 pte = page_table_kmap_check(one_page_table_init(pmd),
24595@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24596 }
24597 }
24598
24599-static inline int is_kernel_text(unsigned long addr)
24600+static inline int is_kernel_text(unsigned long start, unsigned long end)
24601 {
24602- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24603- return 1;
24604- return 0;
24605+ if ((start > ktla_ktva((unsigned long)_etext) ||
24606+ end <= ktla_ktva((unsigned long)_stext)) &&
24607+ (start > ktla_ktva((unsigned long)_einittext) ||
24608+ end <= ktla_ktva((unsigned long)_sinittext)) &&
24609+
24610+#ifdef CONFIG_ACPI_SLEEP
24611+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24612+#endif
24613+
24614+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24615+ return 0;
24616+ return 1;
24617 }
24618
24619 /*
24620@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24621 unsigned long last_map_addr = end;
24622 unsigned long start_pfn, end_pfn;
24623 pgd_t *pgd_base = swapper_pg_dir;
24624- int pgd_idx, pmd_idx, pte_ofs;
24625+ unsigned int pgd_idx, pmd_idx, pte_ofs;
24626 unsigned long pfn;
24627 pgd_t *pgd;
24628+ pud_t *pud;
24629 pmd_t *pmd;
24630 pte_t *pte;
24631 unsigned pages_2m, pages_4k;
24632@@ -280,8 +281,13 @@ repeat:
24633 pfn = start_pfn;
24634 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24635 pgd = pgd_base + pgd_idx;
24636- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24637- pmd = one_md_table_init(pgd);
24638+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24639+ pud = pud_offset(pgd, 0);
24640+ pmd = pmd_offset(pud, 0);
24641+
24642+#ifdef CONFIG_X86_PAE
24643+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24644+#endif
24645
24646 if (pfn >= end_pfn)
24647 continue;
24648@@ -293,14 +299,13 @@ repeat:
24649 #endif
24650 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24651 pmd++, pmd_idx++) {
24652- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24653+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24654
24655 /*
24656 * Map with big pages if possible, otherwise
24657 * create normal page tables:
24658 */
24659 if (use_pse) {
24660- unsigned int addr2;
24661 pgprot_t prot = PAGE_KERNEL_LARGE;
24662 /*
24663 * first pass will use the same initial
24664@@ -310,11 +315,7 @@ repeat:
24665 __pgprot(PTE_IDENT_ATTR |
24666 _PAGE_PSE);
24667
24668- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24669- PAGE_OFFSET + PAGE_SIZE-1;
24670-
24671- if (is_kernel_text(addr) ||
24672- is_kernel_text(addr2))
24673+ if (is_kernel_text(address, address + PMD_SIZE))
24674 prot = PAGE_KERNEL_LARGE_EXEC;
24675
24676 pages_2m++;
24677@@ -331,7 +332,7 @@ repeat:
24678 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24679 pte += pte_ofs;
24680 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24681- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24682+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24683 pgprot_t prot = PAGE_KERNEL;
24684 /*
24685 * first pass will use the same initial
24686@@ -339,7 +340,7 @@ repeat:
24687 */
24688 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24689
24690- if (is_kernel_text(addr))
24691+ if (is_kernel_text(address, address + PAGE_SIZE))
24692 prot = PAGE_KERNEL_EXEC;
24693
24694 pages_4k++;
24695@@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24696
24697 pud = pud_offset(pgd, va);
24698 pmd = pmd_offset(pud, va);
24699- if (!pmd_present(*pmd))
24700+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
24701 break;
24702
24703 pte = pte_offset_kernel(pmd, va);
24704@@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24705
24706 static void __init pagetable_init(void)
24707 {
24708- pgd_t *pgd_base = swapper_pg_dir;
24709-
24710- permanent_kmaps_init(pgd_base);
24711+ permanent_kmaps_init(swapper_pg_dir);
24712 }
24713
24714-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24715+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24716 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24717
24718 /* user-defined highmem size */
24719@@ -734,6 +733,12 @@ void __init mem_init(void)
24720
24721 pci_iommu_alloc();
24722
24723+#ifdef CONFIG_PAX_PER_CPU_PGD
24724+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24725+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24726+ KERNEL_PGD_PTRS);
24727+#endif
24728+
24729 #ifdef CONFIG_FLATMEM
24730 BUG_ON(!mem_map);
24731 #endif
24732@@ -760,7 +765,7 @@ void __init mem_init(void)
24733 reservedpages++;
24734
24735 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24736- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24737+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24738 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24739
24740 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24741@@ -801,10 +806,10 @@ void __init mem_init(void)
24742 ((unsigned long)&__init_end -
24743 (unsigned long)&__init_begin) >> 10,
24744
24745- (unsigned long)&_etext, (unsigned long)&_edata,
24746- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24747+ (unsigned long)&_sdata, (unsigned long)&_edata,
24748+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24749
24750- (unsigned long)&_text, (unsigned long)&_etext,
24751+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24752 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24753
24754 /*
24755@@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24756 if (!kernel_set_to_readonly)
24757 return;
24758
24759+ start = ktla_ktva(start);
24760 pr_debug("Set kernel text: %lx - %lx for read write\n",
24761 start, start+size);
24762
24763@@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24764 if (!kernel_set_to_readonly)
24765 return;
24766
24767+ start = ktla_ktva(start);
24768 pr_debug("Set kernel text: %lx - %lx for read only\n",
24769 start, start+size);
24770
24771@@ -924,6 +931,7 @@ void mark_rodata_ro(void)
24772 unsigned long start = PFN_ALIGN(_text);
24773 unsigned long size = PFN_ALIGN(_etext) - start;
24774
24775+ start = ktla_ktva(start);
24776 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24777 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24778 size >> 10);
24779diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24780index 2b6b4a3..c17210d 100644
24781--- a/arch/x86/mm/init_64.c
24782+++ b/arch/x86/mm/init_64.c
24783@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24784 * around without checking the pgd every time.
24785 */
24786
24787-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24788+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24789 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24790
24791 int force_personality32;
24792@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24793
24794 for (address = start; address <= end; address += PGDIR_SIZE) {
24795 const pgd_t *pgd_ref = pgd_offset_k(address);
24796+
24797+#ifdef CONFIG_PAX_PER_CPU_PGD
24798+ unsigned long cpu;
24799+#else
24800 struct page *page;
24801+#endif
24802
24803 if (pgd_none(*pgd_ref))
24804 continue;
24805
24806 spin_lock(&pgd_lock);
24807+
24808+#ifdef CONFIG_PAX_PER_CPU_PGD
24809+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24810+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
24811+#else
24812 list_for_each_entry(page, &pgd_list, lru) {
24813 pgd_t *pgd;
24814 spinlock_t *pgt_lock;
24815@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24816 /* the pgt_lock only for Xen */
24817 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24818 spin_lock(pgt_lock);
24819+#endif
24820
24821 if (pgd_none(*pgd))
24822 set_pgd(pgd, *pgd_ref);
24823@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24824 BUG_ON(pgd_page_vaddr(*pgd)
24825 != pgd_page_vaddr(*pgd_ref));
24826
24827+#ifndef CONFIG_PAX_PER_CPU_PGD
24828 spin_unlock(pgt_lock);
24829+#endif
24830+
24831 }
24832 spin_unlock(&pgd_lock);
24833 }
24834@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
24835 {
24836 if (pgd_none(*pgd)) {
24837 pud_t *pud = (pud_t *)spp_getpage();
24838- pgd_populate(&init_mm, pgd, pud);
24839+ pgd_populate_kernel(&init_mm, pgd, pud);
24840 if (pud != pud_offset(pgd, 0))
24841 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
24842 pud, pud_offset(pgd, 0));
24843@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
24844 {
24845 if (pud_none(*pud)) {
24846 pmd_t *pmd = (pmd_t *) spp_getpage();
24847- pud_populate(&init_mm, pud, pmd);
24848+ pud_populate_kernel(&init_mm, pud, pmd);
24849 if (pmd != pmd_offset(pud, 0))
24850 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
24851 pmd, pmd_offset(pud, 0));
24852@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24853 pmd = fill_pmd(pud, vaddr);
24854 pte = fill_pte(pmd, vaddr);
24855
24856+ pax_open_kernel();
24857 set_pte(pte, new_pte);
24858+ pax_close_kernel();
24859
24860 /*
24861 * It's enough to flush this one mapping.
24862@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24863 pgd = pgd_offset_k((unsigned long)__va(phys));
24864 if (pgd_none(*pgd)) {
24865 pud = (pud_t *) spp_getpage();
24866- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24867- _PAGE_USER));
24868+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24869 }
24870 pud = pud_offset(pgd, (unsigned long)__va(phys));
24871 if (pud_none(*pud)) {
24872 pmd = (pmd_t *) spp_getpage();
24873- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24874- _PAGE_USER));
24875+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24876 }
24877 pmd = pmd_offset(pud, phys);
24878 BUG_ON(!pmd_none(*pmd));
24879@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24880 if (pfn >= pgt_buf_top)
24881 panic("alloc_low_page: ran out of memory");
24882
24883- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24884+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24885 clear_page(adr);
24886 *phys = pfn * PAGE_SIZE;
24887 return adr;
24888@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
24889
24890 phys = __pa(virt);
24891 left = phys & (PAGE_SIZE - 1);
24892- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24893+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24894 adr = (void *)(((unsigned long)adr) | left);
24895
24896 return adr;
24897@@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
24898 unmap_low_page(pmd);
24899
24900 spin_lock(&init_mm.page_table_lock);
24901- pud_populate(&init_mm, pud, __va(pmd_phys));
24902+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
24903 spin_unlock(&init_mm.page_table_lock);
24904 }
24905 __flush_tlb_all();
24906@@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
24907 unmap_low_page(pud);
24908
24909 spin_lock(&init_mm.page_table_lock);
24910- pgd_populate(&init_mm, pgd, __va(pud_phys));
24911+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
24912 spin_unlock(&init_mm.page_table_lock);
24913 pgd_changed = true;
24914 }
24915@@ -686,6 +700,12 @@ void __init mem_init(void)
24916
24917 pci_iommu_alloc();
24918
24919+#ifdef CONFIG_PAX_PER_CPU_PGD
24920+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24921+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24922+ KERNEL_PGD_PTRS);
24923+#endif
24924+
24925 /* clear_bss() already clear the empty_zero_page */
24926
24927 reservedpages = 0;
24928@@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
24929 static struct vm_area_struct gate_vma = {
24930 .vm_start = VSYSCALL_START,
24931 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
24932- .vm_page_prot = PAGE_READONLY_EXEC,
24933- .vm_flags = VM_READ | VM_EXEC
24934+ .vm_page_prot = PAGE_READONLY,
24935+ .vm_flags = VM_READ
24936 };
24937
24938 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24939@@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
24940
24941 const char *arch_vma_name(struct vm_area_struct *vma)
24942 {
24943- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24944+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24945 return "[vdso]";
24946 if (vma == &gate_vma)
24947 return "[vsyscall]";
24948diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
24949index 7b179b4..6bd1777 100644
24950--- a/arch/x86/mm/iomap_32.c
24951+++ b/arch/x86/mm/iomap_32.c
24952@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
24953 type = kmap_atomic_idx_push();
24954 idx = type + KM_TYPE_NR * smp_processor_id();
24955 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24956+
24957+ pax_open_kernel();
24958 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
24959+ pax_close_kernel();
24960+
24961 arch_flush_lazy_mmu_mode();
24962
24963 return (void *)vaddr;
24964diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
24965index 78fe3f1..8293b6f 100644
24966--- a/arch/x86/mm/ioremap.c
24967+++ b/arch/x86/mm/ioremap.c
24968@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
24969 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
24970 int is_ram = page_is_ram(pfn);
24971
24972- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
24973+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
24974 return NULL;
24975 WARN_ON_ONCE(is_ram);
24976 }
24977@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
24978
24979 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
24980 if (page_is_ram(start >> PAGE_SHIFT))
24981+#ifdef CONFIG_HIGHMEM
24982+ if ((start >> PAGE_SHIFT) < max_low_pfn)
24983+#endif
24984 return __va(phys);
24985
24986 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
24987@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
24988 early_param("early_ioremap_debug", early_ioremap_debug_setup);
24989
24990 static __initdata int after_paging_init;
24991-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
24992+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
24993
24994 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
24995 {
24996@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
24997 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
24998
24999 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25000- memset(bm_pte, 0, sizeof(bm_pte));
25001- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25002+ pmd_populate_user(&init_mm, pmd, bm_pte);
25003
25004 /*
25005 * The boot-ioremap range spans multiple pmds, for which
25006diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25007index d87dd6d..bf3fa66 100644
25008--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25009+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25010@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25011 * memory (e.g. tracked pages)? For now, we need this to avoid
25012 * invoking kmemcheck for PnP BIOS calls.
25013 */
25014- if (regs->flags & X86_VM_MASK)
25015+ if (v8086_mode(regs))
25016 return false;
25017- if (regs->cs != __KERNEL_CS)
25018+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25019 return false;
25020
25021 pte = kmemcheck_pte_lookup(address);
25022diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25023index 845df68..1d8d29f 100644
25024--- a/arch/x86/mm/mmap.c
25025+++ b/arch/x86/mm/mmap.c
25026@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25027 * Leave an at least ~128 MB hole with possible stack randomization.
25028 */
25029 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25030-#define MAX_GAP (TASK_SIZE/6*5)
25031+#define MAX_GAP (pax_task_size/6*5)
25032
25033 static int mmap_is_legacy(void)
25034 {
25035@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25036 return rnd << PAGE_SHIFT;
25037 }
25038
25039-static unsigned long mmap_base(void)
25040+static unsigned long mmap_base(struct mm_struct *mm)
25041 {
25042 unsigned long gap = rlimit(RLIMIT_STACK);
25043+ unsigned long pax_task_size = TASK_SIZE;
25044+
25045+#ifdef CONFIG_PAX_SEGMEXEC
25046+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25047+ pax_task_size = SEGMEXEC_TASK_SIZE;
25048+#endif
25049
25050 if (gap < MIN_GAP)
25051 gap = MIN_GAP;
25052 else if (gap > MAX_GAP)
25053 gap = MAX_GAP;
25054
25055- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25056+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25057 }
25058
25059 /*
25060 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25061 * does, but not when emulating X86_32
25062 */
25063-static unsigned long mmap_legacy_base(void)
25064+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25065 {
25066- if (mmap_is_ia32())
25067+ if (mmap_is_ia32()) {
25068+
25069+#ifdef CONFIG_PAX_SEGMEXEC
25070+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25071+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25072+ else
25073+#endif
25074+
25075 return TASK_UNMAPPED_BASE;
25076- else
25077+ } else
25078 return TASK_UNMAPPED_BASE + mmap_rnd();
25079 }
25080
25081@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25082 void arch_pick_mmap_layout(struct mm_struct *mm)
25083 {
25084 if (mmap_is_legacy()) {
25085- mm->mmap_base = mmap_legacy_base();
25086+ mm->mmap_base = mmap_legacy_base(mm);
25087+
25088+#ifdef CONFIG_PAX_RANDMMAP
25089+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25090+ mm->mmap_base += mm->delta_mmap;
25091+#endif
25092+
25093 mm->get_unmapped_area = arch_get_unmapped_area;
25094 mm->unmap_area = arch_unmap_area;
25095 } else {
25096- mm->mmap_base = mmap_base();
25097+ mm->mmap_base = mmap_base(mm);
25098+
25099+#ifdef CONFIG_PAX_RANDMMAP
25100+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25101+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25102+#endif
25103+
25104 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25105 mm->unmap_area = arch_unmap_area_topdown;
25106 }
25107diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25108index dc0b727..dc9d71a 100644
25109--- a/arch/x86/mm/mmio-mod.c
25110+++ b/arch/x86/mm/mmio-mod.c
25111@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25112 break;
25113 default:
25114 {
25115- unsigned char *ip = (unsigned char *)instptr;
25116+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25117 my_trace->opcode = MMIO_UNKNOWN_OP;
25118 my_trace->width = 0;
25119 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25120@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25121 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25122 void __iomem *addr)
25123 {
25124- static atomic_t next_id;
25125+ static atomic_unchecked_t next_id;
25126 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25127 /* These are page-unaligned. */
25128 struct mmiotrace_map map = {
25129@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25130 .private = trace
25131 },
25132 .phys = offset,
25133- .id = atomic_inc_return(&next_id)
25134+ .id = atomic_inc_return_unchecked(&next_id)
25135 };
25136 map.map_id = trace->id;
25137
25138diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25139index b008656..773eac2 100644
25140--- a/arch/x86/mm/pageattr-test.c
25141+++ b/arch/x86/mm/pageattr-test.c
25142@@ -36,7 +36,7 @@ enum {
25143
25144 static int pte_testbit(pte_t pte)
25145 {
25146- return pte_flags(pte) & _PAGE_UNUSED1;
25147+ return pte_flags(pte) & _PAGE_CPA_TEST;
25148 }
25149
25150 struct split_state {
25151diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25152index a718e0d..45efc32 100644
25153--- a/arch/x86/mm/pageattr.c
25154+++ b/arch/x86/mm/pageattr.c
25155@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25156 */
25157 #ifdef CONFIG_PCI_BIOS
25158 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25159- pgprot_val(forbidden) |= _PAGE_NX;
25160+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25161 #endif
25162
25163 /*
25164@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25165 * Does not cover __inittext since that is gone later on. On
25166 * 64bit we do not enforce !NX on the low mapping
25167 */
25168- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25169- pgprot_val(forbidden) |= _PAGE_NX;
25170+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25171+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25172
25173+#ifdef CONFIG_DEBUG_RODATA
25174 /*
25175 * The .rodata section needs to be read-only. Using the pfn
25176 * catches all aliases.
25177@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25178 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25179 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25180 pgprot_val(forbidden) |= _PAGE_RW;
25181+#endif
25182
25183 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25184 /*
25185@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25186 }
25187 #endif
25188
25189+#ifdef CONFIG_PAX_KERNEXEC
25190+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25191+ pgprot_val(forbidden) |= _PAGE_RW;
25192+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25193+ }
25194+#endif
25195+
25196 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25197
25198 return prot;
25199@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25200 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25201 {
25202 /* change init_mm */
25203+ pax_open_kernel();
25204 set_pte_atomic(kpte, pte);
25205+
25206 #ifdef CONFIG_X86_32
25207 if (!SHARED_KERNEL_PMD) {
25208+
25209+#ifdef CONFIG_PAX_PER_CPU_PGD
25210+ unsigned long cpu;
25211+#else
25212 struct page *page;
25213+#endif
25214
25215+#ifdef CONFIG_PAX_PER_CPU_PGD
25216+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25217+ pgd_t *pgd = get_cpu_pgd(cpu);
25218+#else
25219 list_for_each_entry(page, &pgd_list, lru) {
25220- pgd_t *pgd;
25221+ pgd_t *pgd = (pgd_t *)page_address(page);
25222+#endif
25223+
25224 pud_t *pud;
25225 pmd_t *pmd;
25226
25227- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25228+ pgd += pgd_index(address);
25229 pud = pud_offset(pgd, address);
25230 pmd = pmd_offset(pud, address);
25231 set_pte_atomic((pte_t *)pmd, pte);
25232 }
25233 }
25234 #endif
25235+ pax_close_kernel();
25236 }
25237
25238 static int
25239diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25240index 3d68ef6..7f69136 100644
25241--- a/arch/x86/mm/pat.c
25242+++ b/arch/x86/mm/pat.c
25243@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25244
25245 if (!entry) {
25246 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25247- current->comm, current->pid, start, end - 1);
25248+ current->comm, task_pid_nr(current), start, end - 1);
25249 return -EINVAL;
25250 }
25251
25252@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25253
25254 while (cursor < to) {
25255 if (!devmem_is_allowed(pfn)) {
25256- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25257- current->comm, from, to - 1);
25258+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25259+ current->comm, from, to - 1, cursor);
25260 return 0;
25261 }
25262 cursor += PAGE_SIZE;
25263@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25264 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25265 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25266 "for [mem %#010Lx-%#010Lx]\n",
25267- current->comm, current->pid,
25268+ current->comm, task_pid_nr(current),
25269 cattr_name(flags),
25270 base, (unsigned long long)(base + size-1));
25271 return -EINVAL;
25272@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25273 flags = lookup_memtype(paddr);
25274 if (want_flags != flags) {
25275 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25276- current->comm, current->pid,
25277+ current->comm, task_pid_nr(current),
25278 cattr_name(want_flags),
25279 (unsigned long long)paddr,
25280 (unsigned long long)(paddr + size - 1),
25281@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25282 free_memtype(paddr, paddr + size);
25283 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25284 " for [mem %#010Lx-%#010Lx], got %s\n",
25285- current->comm, current->pid,
25286+ current->comm, task_pid_nr(current),
25287 cattr_name(want_flags),
25288 (unsigned long long)paddr,
25289 (unsigned long long)(paddr + size - 1),
25290diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25291index 9f0614d..92ae64a 100644
25292--- a/arch/x86/mm/pf_in.c
25293+++ b/arch/x86/mm/pf_in.c
25294@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25295 int i;
25296 enum reason_type rv = OTHERS;
25297
25298- p = (unsigned char *)ins_addr;
25299+ p = (unsigned char *)ktla_ktva(ins_addr);
25300 p += skip_prefix(p, &prf);
25301 p += get_opcode(p, &opcode);
25302
25303@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25304 struct prefix_bits prf;
25305 int i;
25306
25307- p = (unsigned char *)ins_addr;
25308+ p = (unsigned char *)ktla_ktva(ins_addr);
25309 p += skip_prefix(p, &prf);
25310 p += get_opcode(p, &opcode);
25311
25312@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25313 struct prefix_bits prf;
25314 int i;
25315
25316- p = (unsigned char *)ins_addr;
25317+ p = (unsigned char *)ktla_ktva(ins_addr);
25318 p += skip_prefix(p, &prf);
25319 p += get_opcode(p, &opcode);
25320
25321@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25322 struct prefix_bits prf;
25323 int i;
25324
25325- p = (unsigned char *)ins_addr;
25326+ p = (unsigned char *)ktla_ktva(ins_addr);
25327 p += skip_prefix(p, &prf);
25328 p += get_opcode(p, &opcode);
25329 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25330@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25331 struct prefix_bits prf;
25332 int i;
25333
25334- p = (unsigned char *)ins_addr;
25335+ p = (unsigned char *)ktla_ktva(ins_addr);
25336 p += skip_prefix(p, &prf);
25337 p += get_opcode(p, &opcode);
25338 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25339diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25340index 8573b83..4f3ed7e 100644
25341--- a/arch/x86/mm/pgtable.c
25342+++ b/arch/x86/mm/pgtable.c
25343@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25344 list_del(&page->lru);
25345 }
25346
25347-#define UNSHARED_PTRS_PER_PGD \
25348- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25349+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25350+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25351
25352+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25353+{
25354+ unsigned int count = USER_PGD_PTRS;
25355
25356+ while (count--)
25357+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25358+}
25359+#endif
25360+
25361+#ifdef CONFIG_PAX_PER_CPU_PGD
25362+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25363+{
25364+ unsigned int count = USER_PGD_PTRS;
25365+
25366+ while (count--) {
25367+ pgd_t pgd;
25368+
25369+#ifdef CONFIG_X86_64
25370+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25371+#else
25372+ pgd = *src++;
25373+#endif
25374+
25375+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25376+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25377+#endif
25378+
25379+ *dst++ = pgd;
25380+ }
25381+
25382+}
25383+#endif
25384+
25385+#ifdef CONFIG_X86_64
25386+#define pxd_t pud_t
25387+#define pyd_t pgd_t
25388+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25389+#define pxd_free(mm, pud) pud_free((mm), (pud))
25390+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25391+#define pyd_offset(mm, address) pgd_offset((mm), (address))
25392+#define PYD_SIZE PGDIR_SIZE
25393+#else
25394+#define pxd_t pmd_t
25395+#define pyd_t pud_t
25396+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25397+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25398+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25399+#define pyd_offset(mm, address) pud_offset((mm), (address))
25400+#define PYD_SIZE PUD_SIZE
25401+#endif
25402+
25403+#ifdef CONFIG_PAX_PER_CPU_PGD
25404+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25405+static inline void pgd_dtor(pgd_t *pgd) {}
25406+#else
25407 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25408 {
25409 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25410@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25411 pgd_list_del(pgd);
25412 spin_unlock(&pgd_lock);
25413 }
25414+#endif
25415
25416 /*
25417 * List of all pgd's needed for non-PAE so it can invalidate entries
25418@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25419 * -- wli
25420 */
25421
25422-#ifdef CONFIG_X86_PAE
25423+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25424 /*
25425 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25426 * updating the top-level pagetable entries to guarantee the
25427@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25428 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25429 * and initialize the kernel pmds here.
25430 */
25431-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25432+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25433
25434 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25435 {
25436@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25437 */
25438 flush_tlb_mm(mm);
25439 }
25440+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25441+#define PREALLOCATED_PXDS USER_PGD_PTRS
25442 #else /* !CONFIG_X86_PAE */
25443
25444 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25445-#define PREALLOCATED_PMDS 0
25446+#define PREALLOCATED_PXDS 0
25447
25448 #endif /* CONFIG_X86_PAE */
25449
25450-static void free_pmds(pmd_t *pmds[])
25451+static void free_pxds(pxd_t *pxds[])
25452 {
25453 int i;
25454
25455- for(i = 0; i < PREALLOCATED_PMDS; i++)
25456- if (pmds[i])
25457- free_page((unsigned long)pmds[i]);
25458+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25459+ if (pxds[i])
25460+ free_page((unsigned long)pxds[i]);
25461 }
25462
25463-static int preallocate_pmds(pmd_t *pmds[])
25464+static int preallocate_pxds(pxd_t *pxds[])
25465 {
25466 int i;
25467 bool failed = false;
25468
25469- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25470- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25471- if (pmd == NULL)
25472+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25473+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25474+ if (pxd == NULL)
25475 failed = true;
25476- pmds[i] = pmd;
25477+ pxds[i] = pxd;
25478 }
25479
25480 if (failed) {
25481- free_pmds(pmds);
25482+ free_pxds(pxds);
25483 return -ENOMEM;
25484 }
25485
25486@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25487 * preallocate which never got a corresponding vma will need to be
25488 * freed manually.
25489 */
25490-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25491+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25492 {
25493 int i;
25494
25495- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25496+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25497 pgd_t pgd = pgdp[i];
25498
25499 if (pgd_val(pgd) != 0) {
25500- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25501+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25502
25503- pgdp[i] = native_make_pgd(0);
25504+ set_pgd(pgdp + i, native_make_pgd(0));
25505
25506- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25507- pmd_free(mm, pmd);
25508+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25509+ pxd_free(mm, pxd);
25510 }
25511 }
25512 }
25513
25514-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25515+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25516 {
25517- pud_t *pud;
25518+ pyd_t *pyd;
25519 unsigned long addr;
25520 int i;
25521
25522- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25523+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25524 return;
25525
25526- pud = pud_offset(pgd, 0);
25527+#ifdef CONFIG_X86_64
25528+ pyd = pyd_offset(mm, 0L);
25529+#else
25530+ pyd = pyd_offset(pgd, 0L);
25531+#endif
25532
25533- for (addr = i = 0; i < PREALLOCATED_PMDS;
25534- i++, pud++, addr += PUD_SIZE) {
25535- pmd_t *pmd = pmds[i];
25536+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25537+ i++, pyd++, addr += PYD_SIZE) {
25538+ pxd_t *pxd = pxds[i];
25539
25540 if (i >= KERNEL_PGD_BOUNDARY)
25541- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25542- sizeof(pmd_t) * PTRS_PER_PMD);
25543+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25544+ sizeof(pxd_t) * PTRS_PER_PMD);
25545
25546- pud_populate(mm, pud, pmd);
25547+ pyd_populate(mm, pyd, pxd);
25548 }
25549 }
25550
25551 pgd_t *pgd_alloc(struct mm_struct *mm)
25552 {
25553 pgd_t *pgd;
25554- pmd_t *pmds[PREALLOCATED_PMDS];
25555+ pxd_t *pxds[PREALLOCATED_PXDS];
25556
25557 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25558
25559@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25560
25561 mm->pgd = pgd;
25562
25563- if (preallocate_pmds(pmds) != 0)
25564+ if (preallocate_pxds(pxds) != 0)
25565 goto out_free_pgd;
25566
25567 if (paravirt_pgd_alloc(mm) != 0)
25568- goto out_free_pmds;
25569+ goto out_free_pxds;
25570
25571 /*
25572 * Make sure that pre-populating the pmds is atomic with
25573@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25574 spin_lock(&pgd_lock);
25575
25576 pgd_ctor(mm, pgd);
25577- pgd_prepopulate_pmd(mm, pgd, pmds);
25578+ pgd_prepopulate_pxd(mm, pgd, pxds);
25579
25580 spin_unlock(&pgd_lock);
25581
25582 return pgd;
25583
25584-out_free_pmds:
25585- free_pmds(pmds);
25586+out_free_pxds:
25587+ free_pxds(pxds);
25588 out_free_pgd:
25589 free_page((unsigned long)pgd);
25590 out:
25591@@ -295,7 +356,7 @@ out:
25592
25593 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25594 {
25595- pgd_mop_up_pmds(mm, pgd);
25596+ pgd_mop_up_pxds(mm, pgd);
25597 pgd_dtor(pgd);
25598 paravirt_pgd_free(mm, pgd);
25599 free_page((unsigned long)pgd);
25600diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25601index a69bcb8..19068ab 100644
25602--- a/arch/x86/mm/pgtable_32.c
25603+++ b/arch/x86/mm/pgtable_32.c
25604@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25605 return;
25606 }
25607 pte = pte_offset_kernel(pmd, vaddr);
25608+
25609+ pax_open_kernel();
25610 if (pte_val(pteval))
25611 set_pte_at(&init_mm, vaddr, pte, pteval);
25612 else
25613 pte_clear(&init_mm, vaddr, pte);
25614+ pax_close_kernel();
25615
25616 /*
25617 * It's enough to flush this one mapping.
25618diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25619index 410531d..0f16030 100644
25620--- a/arch/x86/mm/setup_nx.c
25621+++ b/arch/x86/mm/setup_nx.c
25622@@ -5,8 +5,10 @@
25623 #include <asm/pgtable.h>
25624 #include <asm/proto.h>
25625
25626+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25627 static int disable_nx __cpuinitdata;
25628
25629+#ifndef CONFIG_PAX_PAGEEXEC
25630 /*
25631 * noexec = on|off
25632 *
25633@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25634 return 0;
25635 }
25636 early_param("noexec", noexec_setup);
25637+#endif
25638+
25639+#endif
25640
25641 void __cpuinit x86_configure_nx(void)
25642 {
25643+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25644 if (cpu_has_nx && !disable_nx)
25645 __supported_pte_mask |= _PAGE_NX;
25646 else
25647+#endif
25648 __supported_pte_mask &= ~_PAGE_NX;
25649 }
25650
25651diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25652index 5e57e11..64874249 100644
25653--- a/arch/x86/mm/tlb.c
25654+++ b/arch/x86/mm/tlb.c
25655@@ -66,7 +66,11 @@ void leave_mm(int cpu)
25656 BUG();
25657 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25658 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25659+
25660+#ifndef CONFIG_PAX_PER_CPU_PGD
25661 load_cr3(swapper_pg_dir);
25662+#endif
25663+
25664 }
25665 }
25666 EXPORT_SYMBOL_GPL(leave_mm);
25667diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25668index 877b9a1..a8ecf42 100644
25669--- a/arch/x86/net/bpf_jit.S
25670+++ b/arch/x86/net/bpf_jit.S
25671@@ -9,6 +9,7 @@
25672 */
25673 #include <linux/linkage.h>
25674 #include <asm/dwarf2.h>
25675+#include <asm/alternative-asm.h>
25676
25677 /*
25678 * Calling convention :
25679@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25680 jle bpf_slow_path_word
25681 mov (SKBDATA,%rsi),%eax
25682 bswap %eax /* ntohl() */
25683+ pax_force_retaddr
25684 ret
25685
25686 sk_load_half:
25687@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25688 jle bpf_slow_path_half
25689 movzwl (SKBDATA,%rsi),%eax
25690 rol $8,%ax # ntohs()
25691+ pax_force_retaddr
25692 ret
25693
25694 sk_load_byte:
25695@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25696 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25697 jle bpf_slow_path_byte
25698 movzbl (SKBDATA,%rsi),%eax
25699+ pax_force_retaddr
25700 ret
25701
25702 /**
25703@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25704 movzbl (SKBDATA,%rsi),%ebx
25705 and $15,%bl
25706 shl $2,%bl
25707+ pax_force_retaddr
25708 ret
25709
25710 /* rsi contains offset and can be scratched */
25711@@ -109,6 +114,7 @@ bpf_slow_path_word:
25712 js bpf_error
25713 mov -12(%rbp),%eax
25714 bswap %eax
25715+ pax_force_retaddr
25716 ret
25717
25718 bpf_slow_path_half:
25719@@ -117,12 +123,14 @@ bpf_slow_path_half:
25720 mov -12(%rbp),%ax
25721 rol $8,%ax
25722 movzwl %ax,%eax
25723+ pax_force_retaddr
25724 ret
25725
25726 bpf_slow_path_byte:
25727 bpf_slow_path_common(1)
25728 js bpf_error
25729 movzbl -12(%rbp),%eax
25730+ pax_force_retaddr
25731 ret
25732
25733 bpf_slow_path_byte_msh:
25734@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25735 and $15,%al
25736 shl $2,%al
25737 xchg %eax,%ebx
25738+ pax_force_retaddr
25739 ret
25740
25741 #define sk_negative_common(SIZE) \
25742@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25743 sk_negative_common(4)
25744 mov (%rax), %eax
25745 bswap %eax
25746+ pax_force_retaddr
25747 ret
25748
25749 bpf_slow_path_half_neg:
25750@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25751 mov (%rax),%ax
25752 rol $8,%ax
25753 movzwl %ax,%eax
25754+ pax_force_retaddr
25755 ret
25756
25757 bpf_slow_path_byte_neg:
25758@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25759 .globl sk_load_byte_negative_offset
25760 sk_negative_common(1)
25761 movzbl (%rax), %eax
25762+ pax_force_retaddr
25763 ret
25764
25765 bpf_slow_path_byte_msh_neg:
25766@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
25767 and $15,%al
25768 shl $2,%al
25769 xchg %eax,%ebx
25770+ pax_force_retaddr
25771 ret
25772
25773 bpf_error:
25774@@ -197,4 +210,5 @@ bpf_error:
25775 xor %eax,%eax
25776 mov -8(%rbp),%rbx
25777 leaveq
25778+ pax_force_retaddr
25779 ret
25780diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25781index 0597f95..a12c36e 100644
25782--- a/arch/x86/net/bpf_jit_comp.c
25783+++ b/arch/x86/net/bpf_jit_comp.c
25784@@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
25785 set_fs(old_fs);
25786 }
25787
25788+struct bpf_jit_work {
25789+ struct work_struct work;
25790+ void *image;
25791+};
25792+
25793 #define CHOOSE_LOAD_FUNC(K, func) \
25794 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
25795
25796@@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25797 if (addrs == NULL)
25798 return;
25799
25800+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25801+ if (!fp->work)
25802+ goto out;
25803+
25804 /* Before first pass, make a rough estimation of addrs[]
25805 * each bpf instruction is translated to less than 64 bytes
25806 */
25807@@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25808 break;
25809 default:
25810 /* hmm, too complex filter, give up with jit compiler */
25811- goto out;
25812+ goto error;
25813 }
25814 ilen = prog - temp;
25815 if (image) {
25816 if (unlikely(proglen + ilen > oldproglen)) {
25817 pr_err("bpb_jit_compile fatal error\n");
25818- kfree(addrs);
25819- module_free(NULL, image);
25820- return;
25821+ module_free_exec(NULL, image);
25822+ goto error;
25823 }
25824+ pax_open_kernel();
25825 memcpy(image + proglen, temp, ilen);
25826+ pax_close_kernel();
25827 }
25828 proglen += ilen;
25829 addrs[i] = proglen;
25830@@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25831 break;
25832 }
25833 if (proglen == oldproglen) {
25834- image = module_alloc(max_t(unsigned int,
25835- proglen,
25836- sizeof(struct work_struct)));
25837+ image = module_alloc_exec(proglen);
25838 if (!image)
25839- goto out;
25840+ goto error;
25841 }
25842 oldproglen = proglen;
25843 }
25844@@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25845 bpf_flush_icache(image, image + proglen);
25846
25847 fp->bpf_func = (void *)image;
25848- }
25849+ } else
25850+error:
25851+ kfree(fp->work);
25852+
25853 out:
25854 kfree(addrs);
25855 return;
25856@@ -648,18 +659,20 @@ out:
25857
25858 static void jit_free_defer(struct work_struct *arg)
25859 {
25860- module_free(NULL, arg);
25861+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25862+ kfree(arg);
25863 }
25864
25865 /* run from softirq, we must use a work_struct to call
25866- * module_free() from process context
25867+ * module_free_exec() from process context
25868 */
25869 void bpf_jit_free(struct sk_filter *fp)
25870 {
25871 if (fp->bpf_func != sk_run_filter) {
25872- struct work_struct *work = (struct work_struct *)fp->bpf_func;
25873+ struct work_struct *work = &fp->work->work;
25874
25875 INIT_WORK(work, jit_free_defer);
25876+ fp->work->image = fp->bpf_func;
25877 schedule_work(work);
25878 }
25879 }
25880diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25881index d6aa6e8..266395a 100644
25882--- a/arch/x86/oprofile/backtrace.c
25883+++ b/arch/x86/oprofile/backtrace.c
25884@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25885 struct stack_frame_ia32 *fp;
25886 unsigned long bytes;
25887
25888- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25889+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25890 if (bytes != sizeof(bufhead))
25891 return NULL;
25892
25893- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25894+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25895
25896 oprofile_add_trace(bufhead[0].return_address);
25897
25898@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25899 struct stack_frame bufhead[2];
25900 unsigned long bytes;
25901
25902- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25903+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25904 if (bytes != sizeof(bufhead))
25905 return NULL;
25906
25907@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25908 {
25909 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25910
25911- if (!user_mode_vm(regs)) {
25912+ if (!user_mode(regs)) {
25913 unsigned long stack = kernel_stack_pointer(regs);
25914 if (depth)
25915 dump_trace(NULL, regs, (unsigned long *)stack, 0,
25916diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
25917index 140942f..8a5cc55 100644
25918--- a/arch/x86/pci/mrst.c
25919+++ b/arch/x86/pci/mrst.c
25920@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
25921 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
25922 pci_mmcfg_late_init();
25923 pcibios_enable_irq = mrst_pci_irq_enable;
25924- pci_root_ops = pci_mrst_ops;
25925+ pax_open_kernel();
25926+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
25927+ pax_close_kernel();
25928 pci_soc_mode = 1;
25929 /* Continue with standard init */
25930 return 1;
25931diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
25932index da8fe05..7ee6704 100644
25933--- a/arch/x86/pci/pcbios.c
25934+++ b/arch/x86/pci/pcbios.c
25935@@ -79,50 +79,93 @@ union bios32 {
25936 static struct {
25937 unsigned long address;
25938 unsigned short segment;
25939-} bios32_indirect = { 0, __KERNEL_CS };
25940+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
25941
25942 /*
25943 * Returns the entry point for the given service, NULL on error
25944 */
25945
25946-static unsigned long bios32_service(unsigned long service)
25947+static unsigned long __devinit bios32_service(unsigned long service)
25948 {
25949 unsigned char return_code; /* %al */
25950 unsigned long address; /* %ebx */
25951 unsigned long length; /* %ecx */
25952 unsigned long entry; /* %edx */
25953 unsigned long flags;
25954+ struct desc_struct d, *gdt;
25955
25956 local_irq_save(flags);
25957- __asm__("lcall *(%%edi); cld"
25958+
25959+ gdt = get_cpu_gdt_table(smp_processor_id());
25960+
25961+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
25962+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25963+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
25964+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25965+
25966+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
25967 : "=a" (return_code),
25968 "=b" (address),
25969 "=c" (length),
25970 "=d" (entry)
25971 : "0" (service),
25972 "1" (0),
25973- "D" (&bios32_indirect));
25974+ "D" (&bios32_indirect),
25975+ "r"(__PCIBIOS_DS)
25976+ : "memory");
25977+
25978+ pax_open_kernel();
25979+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
25980+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
25981+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
25982+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
25983+ pax_close_kernel();
25984+
25985 local_irq_restore(flags);
25986
25987 switch (return_code) {
25988- case 0:
25989- return address + entry;
25990- case 0x80: /* Not present */
25991- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25992- return 0;
25993- default: /* Shouldn't happen */
25994- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25995- service, return_code);
25996+ case 0: {
25997+ int cpu;
25998+ unsigned char flags;
25999+
26000+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26001+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26002+ printk(KERN_WARNING "bios32_service: not valid\n");
26003 return 0;
26004+ }
26005+ address = address + PAGE_OFFSET;
26006+ length += 16UL; /* some BIOSs underreport this... */
26007+ flags = 4;
26008+ if (length >= 64*1024*1024) {
26009+ length >>= PAGE_SHIFT;
26010+ flags |= 8;
26011+ }
26012+
26013+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26014+ gdt = get_cpu_gdt_table(cpu);
26015+ pack_descriptor(&d, address, length, 0x9b, flags);
26016+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26017+ pack_descriptor(&d, address, length, 0x93, flags);
26018+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26019+ }
26020+ return entry;
26021+ }
26022+ case 0x80: /* Not present */
26023+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26024+ return 0;
26025+ default: /* Shouldn't happen */
26026+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26027+ service, return_code);
26028+ return 0;
26029 }
26030 }
26031
26032 static struct {
26033 unsigned long address;
26034 unsigned short segment;
26035-} pci_indirect = { 0, __KERNEL_CS };
26036+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26037
26038-static int pci_bios_present;
26039+static int pci_bios_present __read_only;
26040
26041 static int __devinit check_pcibios(void)
26042 {
26043@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26044 unsigned long flags, pcibios_entry;
26045
26046 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26047- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26048+ pci_indirect.address = pcibios_entry;
26049
26050 local_irq_save(flags);
26051- __asm__(
26052- "lcall *(%%edi); cld\n\t"
26053+ __asm__("movw %w6, %%ds\n\t"
26054+ "lcall *%%ss:(%%edi); cld\n\t"
26055+ "push %%ss\n\t"
26056+ "pop %%ds\n\t"
26057 "jc 1f\n\t"
26058 "xor %%ah, %%ah\n"
26059 "1:"
26060@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26061 "=b" (ebx),
26062 "=c" (ecx)
26063 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26064- "D" (&pci_indirect)
26065+ "D" (&pci_indirect),
26066+ "r" (__PCIBIOS_DS)
26067 : "memory");
26068 local_irq_restore(flags);
26069
26070@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26071
26072 switch (len) {
26073 case 1:
26074- __asm__("lcall *(%%esi); cld\n\t"
26075+ __asm__("movw %w6, %%ds\n\t"
26076+ "lcall *%%ss:(%%esi); cld\n\t"
26077+ "push %%ss\n\t"
26078+ "pop %%ds\n\t"
26079 "jc 1f\n\t"
26080 "xor %%ah, %%ah\n"
26081 "1:"
26082@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26083 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26084 "b" (bx),
26085 "D" ((long)reg),
26086- "S" (&pci_indirect));
26087+ "S" (&pci_indirect),
26088+ "r" (__PCIBIOS_DS));
26089 /*
26090 * Zero-extend the result beyond 8 bits, do not trust the
26091 * BIOS having done it:
26092@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26093 *value &= 0xff;
26094 break;
26095 case 2:
26096- __asm__("lcall *(%%esi); cld\n\t"
26097+ __asm__("movw %w6, %%ds\n\t"
26098+ "lcall *%%ss:(%%esi); cld\n\t"
26099+ "push %%ss\n\t"
26100+ "pop %%ds\n\t"
26101 "jc 1f\n\t"
26102 "xor %%ah, %%ah\n"
26103 "1:"
26104@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26105 : "1" (PCIBIOS_READ_CONFIG_WORD),
26106 "b" (bx),
26107 "D" ((long)reg),
26108- "S" (&pci_indirect));
26109+ "S" (&pci_indirect),
26110+ "r" (__PCIBIOS_DS));
26111 /*
26112 * Zero-extend the result beyond 16 bits, do not trust the
26113 * BIOS having done it:
26114@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26115 *value &= 0xffff;
26116 break;
26117 case 4:
26118- __asm__("lcall *(%%esi); cld\n\t"
26119+ __asm__("movw %w6, %%ds\n\t"
26120+ "lcall *%%ss:(%%esi); cld\n\t"
26121+ "push %%ss\n\t"
26122+ "pop %%ds\n\t"
26123 "jc 1f\n\t"
26124 "xor %%ah, %%ah\n"
26125 "1:"
26126@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26127 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26128 "b" (bx),
26129 "D" ((long)reg),
26130- "S" (&pci_indirect));
26131+ "S" (&pci_indirect),
26132+ "r" (__PCIBIOS_DS));
26133 break;
26134 }
26135
26136@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26137
26138 switch (len) {
26139 case 1:
26140- __asm__("lcall *(%%esi); cld\n\t"
26141+ __asm__("movw %w6, %%ds\n\t"
26142+ "lcall *%%ss:(%%esi); cld\n\t"
26143+ "push %%ss\n\t"
26144+ "pop %%ds\n\t"
26145 "jc 1f\n\t"
26146 "xor %%ah, %%ah\n"
26147 "1:"
26148@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26149 "c" (value),
26150 "b" (bx),
26151 "D" ((long)reg),
26152- "S" (&pci_indirect));
26153+ "S" (&pci_indirect),
26154+ "r" (__PCIBIOS_DS));
26155 break;
26156 case 2:
26157- __asm__("lcall *(%%esi); cld\n\t"
26158+ __asm__("movw %w6, %%ds\n\t"
26159+ "lcall *%%ss:(%%esi); cld\n\t"
26160+ "push %%ss\n\t"
26161+ "pop %%ds\n\t"
26162 "jc 1f\n\t"
26163 "xor %%ah, %%ah\n"
26164 "1:"
26165@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26166 "c" (value),
26167 "b" (bx),
26168 "D" ((long)reg),
26169- "S" (&pci_indirect));
26170+ "S" (&pci_indirect),
26171+ "r" (__PCIBIOS_DS));
26172 break;
26173 case 4:
26174- __asm__("lcall *(%%esi); cld\n\t"
26175+ __asm__("movw %w6, %%ds\n\t"
26176+ "lcall *%%ss:(%%esi); cld\n\t"
26177+ "push %%ss\n\t"
26178+ "pop %%ds\n\t"
26179 "jc 1f\n\t"
26180 "xor %%ah, %%ah\n"
26181 "1:"
26182@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26183 "c" (value),
26184 "b" (bx),
26185 "D" ((long)reg),
26186- "S" (&pci_indirect));
26187+ "S" (&pci_indirect),
26188+ "r" (__PCIBIOS_DS));
26189 break;
26190 }
26191
26192@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26193
26194 DBG("PCI: Fetching IRQ routing table... ");
26195 __asm__("push %%es\n\t"
26196+ "movw %w8, %%ds\n\t"
26197 "push %%ds\n\t"
26198 "pop %%es\n\t"
26199- "lcall *(%%esi); cld\n\t"
26200+ "lcall *%%ss:(%%esi); cld\n\t"
26201 "pop %%es\n\t"
26202+ "push %%ss\n\t"
26203+ "pop %%ds\n"
26204 "jc 1f\n\t"
26205 "xor %%ah, %%ah\n"
26206 "1:"
26207@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26208 "1" (0),
26209 "D" ((long) &opt),
26210 "S" (&pci_indirect),
26211- "m" (opt)
26212+ "m" (opt),
26213+ "r" (__PCIBIOS_DS)
26214 : "memory");
26215 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26216 if (ret & 0xff00)
26217@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26218 {
26219 int ret;
26220
26221- __asm__("lcall *(%%esi); cld\n\t"
26222+ __asm__("movw %w5, %%ds\n\t"
26223+ "lcall *%%ss:(%%esi); cld\n\t"
26224+ "push %%ss\n\t"
26225+ "pop %%ds\n"
26226 "jc 1f\n\t"
26227 "xor %%ah, %%ah\n"
26228 "1:"
26229@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26230 : "0" (PCIBIOS_SET_PCI_HW_INT),
26231 "b" ((dev->bus->number << 8) | dev->devfn),
26232 "c" ((irq << 8) | (pin + 10)),
26233- "S" (&pci_indirect));
26234+ "S" (&pci_indirect),
26235+ "r" (__PCIBIOS_DS));
26236 return !(ret & 0xff00);
26237 }
26238 EXPORT_SYMBOL(pcibios_set_irq_routing);
26239diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26240index 40e4469..1ab536e 100644
26241--- a/arch/x86/platform/efi/efi_32.c
26242+++ b/arch/x86/platform/efi/efi_32.c
26243@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26244 {
26245 struct desc_ptr gdt_descr;
26246
26247+#ifdef CONFIG_PAX_KERNEXEC
26248+ struct desc_struct d;
26249+#endif
26250+
26251 local_irq_save(efi_rt_eflags);
26252
26253 load_cr3(initial_page_table);
26254 __flush_tlb_all();
26255
26256+#ifdef CONFIG_PAX_KERNEXEC
26257+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26258+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26259+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26260+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26261+#endif
26262+
26263 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26264 gdt_descr.size = GDT_SIZE - 1;
26265 load_gdt(&gdt_descr);
26266@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26267 {
26268 struct desc_ptr gdt_descr;
26269
26270+#ifdef CONFIG_PAX_KERNEXEC
26271+ struct desc_struct d;
26272+
26273+ memset(&d, 0, sizeof d);
26274+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26275+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26276+#endif
26277+
26278 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26279 gdt_descr.size = GDT_SIZE - 1;
26280 load_gdt(&gdt_descr);
26281diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26282index fbe66e6..eae5e38 100644
26283--- a/arch/x86/platform/efi/efi_stub_32.S
26284+++ b/arch/x86/platform/efi/efi_stub_32.S
26285@@ -6,7 +6,9 @@
26286 */
26287
26288 #include <linux/linkage.h>
26289+#include <linux/init.h>
26290 #include <asm/page_types.h>
26291+#include <asm/segment.h>
26292
26293 /*
26294 * efi_call_phys(void *, ...) is a function with variable parameters.
26295@@ -20,7 +22,7 @@
26296 * service functions will comply with gcc calling convention, too.
26297 */
26298
26299-.text
26300+__INIT
26301 ENTRY(efi_call_phys)
26302 /*
26303 * 0. The function can only be called in Linux kernel. So CS has been
26304@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26305 * The mapping of lower virtual memory has been created in prelog and
26306 * epilog.
26307 */
26308- movl $1f, %edx
26309- subl $__PAGE_OFFSET, %edx
26310- jmp *%edx
26311+#ifdef CONFIG_PAX_KERNEXEC
26312+ movl $(__KERNEXEC_EFI_DS), %edx
26313+ mov %edx, %ds
26314+ mov %edx, %es
26315+ mov %edx, %ss
26316+ addl $2f,(1f)
26317+ ljmp *(1f)
26318+
26319+__INITDATA
26320+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26321+.previous
26322+
26323+2:
26324+ subl $2b,(1b)
26325+#else
26326+ jmp 1f-__PAGE_OFFSET
26327 1:
26328+#endif
26329
26330 /*
26331 * 2. Now on the top of stack is the return
26332@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26333 * parameter 2, ..., param n. To make things easy, we save the return
26334 * address of efi_call_phys in a global variable.
26335 */
26336- popl %edx
26337- movl %edx, saved_return_addr
26338- /* get the function pointer into ECX*/
26339- popl %ecx
26340- movl %ecx, efi_rt_function_ptr
26341- movl $2f, %edx
26342- subl $__PAGE_OFFSET, %edx
26343- pushl %edx
26344+ popl (saved_return_addr)
26345+ popl (efi_rt_function_ptr)
26346
26347 /*
26348 * 3. Clear PG bit in %CR0.
26349@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26350 /*
26351 * 5. Call the physical function.
26352 */
26353- jmp *%ecx
26354+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
26355
26356-2:
26357 /*
26358 * 6. After EFI runtime service returns, control will return to
26359 * following instruction. We'd better readjust stack pointer first.
26360@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26361 movl %cr0, %edx
26362 orl $0x80000000, %edx
26363 movl %edx, %cr0
26364- jmp 1f
26365-1:
26366+
26367 /*
26368 * 8. Now restore the virtual mode from flat mode by
26369 * adding EIP with PAGE_OFFSET.
26370 */
26371- movl $1f, %edx
26372- jmp *%edx
26373+#ifdef CONFIG_PAX_KERNEXEC
26374+ movl $(__KERNEL_DS), %edx
26375+ mov %edx, %ds
26376+ mov %edx, %es
26377+ mov %edx, %ss
26378+ ljmp $(__KERNEL_CS),$1f
26379+#else
26380+ jmp 1f+__PAGE_OFFSET
26381+#endif
26382 1:
26383
26384 /*
26385 * 9. Balance the stack. And because EAX contain the return value,
26386 * we'd better not clobber it.
26387 */
26388- leal efi_rt_function_ptr, %edx
26389- movl (%edx), %ecx
26390- pushl %ecx
26391+ pushl (efi_rt_function_ptr)
26392
26393 /*
26394- * 10. Push the saved return address onto the stack and return.
26395+ * 10. Return to the saved return address.
26396 */
26397- leal saved_return_addr, %edx
26398- movl (%edx), %ecx
26399- pushl %ecx
26400- ret
26401+ jmpl *(saved_return_addr)
26402 ENDPROC(efi_call_phys)
26403 .previous
26404
26405-.data
26406+__INITDATA
26407 saved_return_addr:
26408 .long 0
26409 efi_rt_function_ptr:
26410diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26411index 4c07cca..2c8427d 100644
26412--- a/arch/x86/platform/efi/efi_stub_64.S
26413+++ b/arch/x86/platform/efi/efi_stub_64.S
26414@@ -7,6 +7,7 @@
26415 */
26416
26417 #include <linux/linkage.h>
26418+#include <asm/alternative-asm.h>
26419
26420 #define SAVE_XMM \
26421 mov %rsp, %rax; \
26422@@ -40,6 +41,7 @@ ENTRY(efi_call0)
26423 call *%rdi
26424 addq $32, %rsp
26425 RESTORE_XMM
26426+ pax_force_retaddr 0, 1
26427 ret
26428 ENDPROC(efi_call0)
26429
26430@@ -50,6 +52,7 @@ ENTRY(efi_call1)
26431 call *%rdi
26432 addq $32, %rsp
26433 RESTORE_XMM
26434+ pax_force_retaddr 0, 1
26435 ret
26436 ENDPROC(efi_call1)
26437
26438@@ -60,6 +63,7 @@ ENTRY(efi_call2)
26439 call *%rdi
26440 addq $32, %rsp
26441 RESTORE_XMM
26442+ pax_force_retaddr 0, 1
26443 ret
26444 ENDPROC(efi_call2)
26445
26446@@ -71,6 +75,7 @@ ENTRY(efi_call3)
26447 call *%rdi
26448 addq $32, %rsp
26449 RESTORE_XMM
26450+ pax_force_retaddr 0, 1
26451 ret
26452 ENDPROC(efi_call3)
26453
26454@@ -83,6 +88,7 @@ ENTRY(efi_call4)
26455 call *%rdi
26456 addq $32, %rsp
26457 RESTORE_XMM
26458+ pax_force_retaddr 0, 1
26459 ret
26460 ENDPROC(efi_call4)
26461
26462@@ -96,6 +102,7 @@ ENTRY(efi_call5)
26463 call *%rdi
26464 addq $48, %rsp
26465 RESTORE_XMM
26466+ pax_force_retaddr 0, 1
26467 ret
26468 ENDPROC(efi_call5)
26469
26470@@ -112,5 +119,6 @@ ENTRY(efi_call6)
26471 call *%rdi
26472 addq $48, %rsp
26473 RESTORE_XMM
26474+ pax_force_retaddr 0, 1
26475 ret
26476 ENDPROC(efi_call6)
26477diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26478index fd41a92..9c33628 100644
26479--- a/arch/x86/platform/mrst/mrst.c
26480+++ b/arch/x86/platform/mrst/mrst.c
26481@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26482 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26483 int sfi_mrtc_num;
26484
26485-static void mrst_power_off(void)
26486+static __noreturn void mrst_power_off(void)
26487 {
26488+ BUG();
26489 }
26490
26491-static void mrst_reboot(void)
26492+static __noreturn void mrst_reboot(void)
26493 {
26494 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26495+ BUG();
26496 }
26497
26498 /* parse all the mtimer info to a static mtimer array */
26499diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26500index 218cdb1..fd55c08 100644
26501--- a/arch/x86/power/cpu.c
26502+++ b/arch/x86/power/cpu.c
26503@@ -132,7 +132,7 @@ static void do_fpu_end(void)
26504 static void fix_processor_context(void)
26505 {
26506 int cpu = smp_processor_id();
26507- struct tss_struct *t = &per_cpu(init_tss, cpu);
26508+ struct tss_struct *t = init_tss + cpu;
26509
26510 set_tss_desc(cpu, t); /*
26511 * This just modifies memory; should not be
26512@@ -142,7 +142,9 @@ static void fix_processor_context(void)
26513 */
26514
26515 #ifdef CONFIG_X86_64
26516+ pax_open_kernel();
26517 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26518+ pax_close_kernel();
26519
26520 syscall_init(); /* This sets MSR_*STAR and related */
26521 #endif
26522diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26523index cbca565..913a0fe 100644
26524--- a/arch/x86/realmode/init.c
26525+++ b/arch/x86/realmode/init.c
26526@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26527 __va(real_mode_header->trampoline_header);
26528
26529 #ifdef CONFIG_X86_32
26530- trampoline_header->start = __pa(startup_32_smp);
26531+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26532+
26533+#ifdef CONFIG_PAX_KERNEXEC
26534+ trampoline_header->start -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26535+#endif
26536+
26537+ trampoline_header->boot_cs = __BOOT_CS;
26538 trampoline_header->gdt_limit = __BOOT_DS + 7;
26539 trampoline_header->gdt_base = __pa(boot_gdt);
26540 #else
26541diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26542index 5b84a2d..a004393 100644
26543--- a/arch/x86/realmode/rm/Makefile
26544+++ b/arch/x86/realmode/rm/Makefile
26545@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26546 $(call cc-option, -fno-unit-at-a-time)) \
26547 $(call cc-option, -fno-stack-protector) \
26548 $(call cc-option, -mpreferred-stack-boundary=2)
26549+ifdef CONSTIFY_PLUGIN
26550+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
26551+endif
26552 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26553 GCOV_PROFILE := n
26554diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26555index c1b2791..f9e31c7 100644
26556--- a/arch/x86/realmode/rm/trampoline_32.S
26557+++ b/arch/x86/realmode/rm/trampoline_32.S
26558@@ -25,6 +25,12 @@
26559 #include <asm/page_types.h>
26560 #include "realmode.h"
26561
26562+#ifdef CONFIG_PAX_KERNEXEC
26563+#define ta(X) (X)
26564+#else
26565+#define ta(X) (pa_ ## X)
26566+#endif
26567+
26568 .text
26569 .code16
26570
26571@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26572
26573 cli # We should be safe anyway
26574
26575- movl tr_start, %eax # where we need to go
26576-
26577 movl $0xA5A5A5A5, trampoline_status
26578 # write marker for master knows we're running
26579
26580@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26581 movw $1, %dx # protected mode (PE) bit
26582 lmsw %dx # into protected mode
26583
26584- ljmpl $__BOOT_CS, $pa_startup_32
26585+ ljmpl *(trampoline_header)
26586
26587 .section ".text32","ax"
26588 .code32
26589@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26590 .balign 8
26591 GLOBAL(trampoline_header)
26592 tr_start: .space 4
26593- tr_gdt_pad: .space 2
26594+ tr_boot_cs: .space 2
26595 tr_gdt: .space 6
26596 END(trampoline_header)
26597
26598diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26599index bb360dc..3e5945f 100644
26600--- a/arch/x86/realmode/rm/trampoline_64.S
26601+++ b/arch/x86/realmode/rm/trampoline_64.S
26602@@ -107,7 +107,7 @@ ENTRY(startup_32)
26603 wrmsr
26604
26605 # Enable paging and in turn activate Long Mode
26606- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26607+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
26608 movl %eax, %cr0
26609
26610 /*
26611diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26612index 5a1847d..deccb30 100644
26613--- a/arch/x86/tools/relocs.c
26614+++ b/arch/x86/tools/relocs.c
26615@@ -12,10 +12,13 @@
26616 #include <regex.h>
26617 #include <tools/le_byteshift.h>
26618
26619+#include "../../../include/generated/autoconf.h"
26620+
26621 static void die(char *fmt, ...);
26622
26623 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26624 static Elf32_Ehdr ehdr;
26625+static Elf32_Phdr *phdr;
26626 static unsigned long reloc_count, reloc_idx;
26627 static unsigned long *relocs;
26628 static unsigned long reloc16_count, reloc16_idx;
26629@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26630 }
26631 }
26632
26633+static void read_phdrs(FILE *fp)
26634+{
26635+ unsigned int i;
26636+
26637+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26638+ if (!phdr) {
26639+ die("Unable to allocate %d program headers\n",
26640+ ehdr.e_phnum);
26641+ }
26642+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26643+ die("Seek to %d failed: %s\n",
26644+ ehdr.e_phoff, strerror(errno));
26645+ }
26646+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26647+ die("Cannot read ELF program headers: %s\n",
26648+ strerror(errno));
26649+ }
26650+ for(i = 0; i < ehdr.e_phnum; i++) {
26651+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26652+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26653+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26654+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26655+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26656+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26657+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26658+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26659+ }
26660+
26661+}
26662+
26663 static void read_shdrs(FILE *fp)
26664 {
26665- int i;
26666+ unsigned int i;
26667 Elf32_Shdr shdr;
26668
26669 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26670@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26671
26672 static void read_strtabs(FILE *fp)
26673 {
26674- int i;
26675+ unsigned int i;
26676 for (i = 0; i < ehdr.e_shnum; i++) {
26677 struct section *sec = &secs[i];
26678 if (sec->shdr.sh_type != SHT_STRTAB) {
26679@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26680
26681 static void read_symtabs(FILE *fp)
26682 {
26683- int i,j;
26684+ unsigned int i,j;
26685 for (i = 0; i < ehdr.e_shnum; i++) {
26686 struct section *sec = &secs[i];
26687 if (sec->shdr.sh_type != SHT_SYMTAB) {
26688@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26689 }
26690
26691
26692-static void read_relocs(FILE *fp)
26693+static void read_relocs(FILE *fp, int use_real_mode)
26694 {
26695- int i,j;
26696+ unsigned int i,j;
26697+ uint32_t base;
26698+
26699 for (i = 0; i < ehdr.e_shnum; i++) {
26700 struct section *sec = &secs[i];
26701 if (sec->shdr.sh_type != SHT_REL) {
26702@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26703 die("Cannot read symbol table: %s\n",
26704 strerror(errno));
26705 }
26706+ base = 0;
26707+
26708+#ifdef CONFIG_X86_32
26709+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26710+ if (phdr[j].p_type != PT_LOAD )
26711+ continue;
26712+ 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)
26713+ continue;
26714+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26715+ break;
26716+ }
26717+#endif
26718+
26719 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26720 Elf32_Rel *rel = &sec->reltab[j];
26721- rel->r_offset = elf32_to_cpu(rel->r_offset);
26722+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26723 rel->r_info = elf32_to_cpu(rel->r_info);
26724 }
26725 }
26726@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
26727
26728 static void print_absolute_symbols(void)
26729 {
26730- int i;
26731+ unsigned int i;
26732 printf("Absolute symbols\n");
26733 printf(" Num: Value Size Type Bind Visibility Name\n");
26734 for (i = 0; i < ehdr.e_shnum; i++) {
26735 struct section *sec = &secs[i];
26736 char *sym_strtab;
26737- int j;
26738+ unsigned int j;
26739
26740 if (sec->shdr.sh_type != SHT_SYMTAB) {
26741 continue;
26742@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
26743
26744 static void print_absolute_relocs(void)
26745 {
26746- int i, printed = 0;
26747+ unsigned int i, printed = 0;
26748
26749 for (i = 0; i < ehdr.e_shnum; i++) {
26750 struct section *sec = &secs[i];
26751 struct section *sec_applies, *sec_symtab;
26752 char *sym_strtab;
26753 Elf32_Sym *sh_symtab;
26754- int j;
26755+ unsigned int j;
26756 if (sec->shdr.sh_type != SHT_REL) {
26757 continue;
26758 }
26759@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
26760 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26761 int use_real_mode)
26762 {
26763- int i;
26764+ unsigned int i;
26765 /* Walk through the relocations */
26766 for (i = 0; i < ehdr.e_shnum; i++) {
26767 char *sym_strtab;
26768 Elf32_Sym *sh_symtab;
26769 struct section *sec_applies, *sec_symtab;
26770- int j;
26771+ unsigned int j;
26772 struct section *sec = &secs[i];
26773
26774 if (sec->shdr.sh_type != SHT_REL) {
26775@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26776 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26777 r_type = ELF32_R_TYPE(rel->r_info);
26778
26779+ if (!use_real_mode) {
26780+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26781+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26782+ continue;
26783+
26784+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26785+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26786+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26787+ continue;
26788+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26789+ continue;
26790+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26791+ continue;
26792+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26793+ continue;
26794+#endif
26795+ }
26796+
26797 shn_abs = sym->st_shndx == SHN_ABS;
26798
26799 switch (r_type) {
26800@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
26801
26802 static void emit_relocs(int as_text, int use_real_mode)
26803 {
26804- int i;
26805+ unsigned int i;
26806 /* Count how many relocations I have and allocate space for them. */
26807 reloc_count = 0;
26808 walk_relocs(count_reloc, use_real_mode);
26809@@ -808,10 +874,11 @@ int main(int argc, char **argv)
26810 fname, strerror(errno));
26811 }
26812 read_ehdr(fp);
26813+ read_phdrs(fp);
26814 read_shdrs(fp);
26815 read_strtabs(fp);
26816 read_symtabs(fp);
26817- read_relocs(fp);
26818+ read_relocs(fp, use_real_mode);
26819 if (show_absolute_syms) {
26820 print_absolute_symbols();
26821 return 0;
26822diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26823index fd14be1..e3c79c0 100644
26824--- a/arch/x86/vdso/Makefile
26825+++ b/arch/x86/vdso/Makefile
26826@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
26827 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26828 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26829
26830-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26831+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26832 GCOV_PROFILE := n
26833
26834 #
26835diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26836index 66e6d93..587f435 100644
26837--- a/arch/x86/vdso/vdso32-setup.c
26838+++ b/arch/x86/vdso/vdso32-setup.c
26839@@ -25,6 +25,7 @@
26840 #include <asm/tlbflush.h>
26841 #include <asm/vdso.h>
26842 #include <asm/proto.h>
26843+#include <asm/mman.h>
26844
26845 enum {
26846 VDSO_DISABLED = 0,
26847@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26848 void enable_sep_cpu(void)
26849 {
26850 int cpu = get_cpu();
26851- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26852+ struct tss_struct *tss = init_tss + cpu;
26853
26854 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26855 put_cpu();
26856@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26857 gate_vma.vm_start = FIXADDR_USER_START;
26858 gate_vma.vm_end = FIXADDR_USER_END;
26859 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26860- gate_vma.vm_page_prot = __P101;
26861+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26862
26863 return 0;
26864 }
26865@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26866 if (compat)
26867 addr = VDSO_HIGH_BASE;
26868 else {
26869- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26870+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26871 if (IS_ERR_VALUE(addr)) {
26872 ret = addr;
26873 goto up_fail;
26874 }
26875 }
26876
26877- current->mm->context.vdso = (void *)addr;
26878+ current->mm->context.vdso = addr;
26879
26880 if (compat_uses_vma || !compat) {
26881 /*
26882@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26883 }
26884
26885 current_thread_info()->sysenter_return =
26886- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26887+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26888
26889 up_fail:
26890 if (ret)
26891- current->mm->context.vdso = NULL;
26892+ current->mm->context.vdso = 0;
26893
26894 up_write(&mm->mmap_sem);
26895
26896@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
26897
26898 const char *arch_vma_name(struct vm_area_struct *vma)
26899 {
26900- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26901+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26902 return "[vdso]";
26903+
26904+#ifdef CONFIG_PAX_SEGMEXEC
26905+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26906+ return "[vdso]";
26907+#endif
26908+
26909 return NULL;
26910 }
26911
26912@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26913 * Check to see if the corresponding task was created in compat vdso
26914 * mode.
26915 */
26916- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26917+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26918 return &gate_vma;
26919 return NULL;
26920 }
26921diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26922index 00aaf04..4a26505 100644
26923--- a/arch/x86/vdso/vma.c
26924+++ b/arch/x86/vdso/vma.c
26925@@ -16,8 +16,6 @@
26926 #include <asm/vdso.h>
26927 #include <asm/page.h>
26928
26929-unsigned int __read_mostly vdso_enabled = 1;
26930-
26931 extern char vdso_start[], vdso_end[];
26932 extern unsigned short vdso_sync_cpuid;
26933
26934@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26935 * unaligned here as a result of stack start randomization.
26936 */
26937 addr = PAGE_ALIGN(addr);
26938- addr = align_addr(addr, NULL, ALIGN_VDSO);
26939
26940 return addr;
26941 }
26942@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
26943 unsigned size)
26944 {
26945 struct mm_struct *mm = current->mm;
26946- unsigned long addr;
26947+ unsigned long addr = 0;
26948 int ret;
26949
26950- if (!vdso_enabled)
26951- return 0;
26952-
26953 down_write(&mm->mmap_sem);
26954+
26955+#ifdef CONFIG_PAX_RANDMMAP
26956+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26957+#endif
26958+
26959 addr = vdso_addr(mm->start_stack, size);
26960+ addr = align_addr(addr, NULL, ALIGN_VDSO);
26961 addr = get_unmapped_area(NULL, addr, size, 0, 0);
26962 if (IS_ERR_VALUE(addr)) {
26963 ret = addr;
26964 goto up_fail;
26965 }
26966
26967- current->mm->context.vdso = (void *)addr;
26968+ mm->context.vdso = addr;
26969
26970 ret = install_special_mapping(mm, addr, size,
26971 VM_READ|VM_EXEC|
26972 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
26973 pages);
26974- if (ret) {
26975- current->mm->context.vdso = NULL;
26976- goto up_fail;
26977- }
26978+ if (ret)
26979+ mm->context.vdso = 0;
26980
26981 up_fail:
26982 up_write(&mm->mmap_sem);
26983@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26984 vdsox32_size);
26985 }
26986 #endif
26987-
26988-static __init int vdso_setup(char *s)
26989-{
26990- vdso_enabled = simple_strtoul(s, NULL, 0);
26991- return 0;
26992-}
26993-__setup("vdso=", vdso_setup);
26994diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
26995index ff962d4..2bb5e83 100644
26996--- a/arch/x86/xen/enlighten.c
26997+++ b/arch/x86/xen/enlighten.c
26998@@ -97,8 +97,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
26999
27000 struct shared_info xen_dummy_shared_info;
27001
27002-void *xen_initial_gdt;
27003-
27004 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27005 __read_mostly int xen_have_vector_callback;
27006 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27007@@ -1175,30 +1173,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27008 #endif
27009 };
27010
27011-static void xen_reboot(int reason)
27012+static __noreturn void xen_reboot(int reason)
27013 {
27014 struct sched_shutdown r = { .reason = reason };
27015
27016- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27017- BUG();
27018+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27019+ BUG();
27020 }
27021
27022-static void xen_restart(char *msg)
27023+static __noreturn void xen_restart(char *msg)
27024 {
27025 xen_reboot(SHUTDOWN_reboot);
27026 }
27027
27028-static void xen_emergency_restart(void)
27029+static __noreturn void xen_emergency_restart(void)
27030 {
27031 xen_reboot(SHUTDOWN_reboot);
27032 }
27033
27034-static void xen_machine_halt(void)
27035+static __noreturn void xen_machine_halt(void)
27036 {
27037 xen_reboot(SHUTDOWN_poweroff);
27038 }
27039
27040-static void xen_machine_power_off(void)
27041+static __noreturn void xen_machine_power_off(void)
27042 {
27043 if (pm_power_off)
27044 pm_power_off();
27045@@ -1301,7 +1299,17 @@ asmlinkage void __init xen_start_kernel(void)
27046 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27047
27048 /* Work out if we support NX */
27049- x86_configure_nx();
27050+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27051+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27052+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27053+ unsigned l, h;
27054+
27055+ __supported_pte_mask |= _PAGE_NX;
27056+ rdmsr(MSR_EFER, l, h);
27057+ l |= EFER_NX;
27058+ wrmsr(MSR_EFER, l, h);
27059+ }
27060+#endif
27061
27062 xen_setup_features();
27063
27064@@ -1332,13 +1340,6 @@ asmlinkage void __init xen_start_kernel(void)
27065
27066 machine_ops = xen_machine_ops;
27067
27068- /*
27069- * The only reliable way to retain the initial address of the
27070- * percpu gdt_page is to remember it here, so we can go and
27071- * mark it RW later, when the initial percpu area is freed.
27072- */
27073- xen_initial_gdt = &per_cpu(gdt_page, 0);
27074-
27075 xen_smp_init();
27076
27077 #ifdef CONFIG_ACPI_NUMA
27078diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27079index 3a73785..0d30df2 100644
27080--- a/arch/x86/xen/mmu.c
27081+++ b/arch/x86/xen/mmu.c
27082@@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27083 convert_pfn_mfn(init_level4_pgt);
27084 convert_pfn_mfn(level3_ident_pgt);
27085 convert_pfn_mfn(level3_kernel_pgt);
27086+ convert_pfn_mfn(level3_vmalloc_start_pgt);
27087+ convert_pfn_mfn(level3_vmalloc_end_pgt);
27088+ convert_pfn_mfn(level3_vmemmap_pgt);
27089
27090 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27091 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27092@@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27093 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27094 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27095 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27096+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27097+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27098+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27099 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27100+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27101 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27102 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27103
27104@@ -1940,6 +1947,7 @@ static void __init xen_post_allocator_init(void)
27105 pv_mmu_ops.set_pud = xen_set_pud;
27106 #if PAGETABLE_LEVELS == 4
27107 pv_mmu_ops.set_pgd = xen_set_pgd;
27108+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27109 #endif
27110
27111 /* This will work as long as patching hasn't happened yet
27112@@ -2021,6 +2029,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27113 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27114 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27115 .set_pgd = xen_set_pgd_hyper,
27116+ .set_pgd_batched = xen_set_pgd_hyper,
27117
27118 .alloc_pud = xen_alloc_pmd_init,
27119 .release_pud = xen_release_pmd_init,
27120diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27121index afb250d..627075f 100644
27122--- a/arch/x86/xen/smp.c
27123+++ b/arch/x86/xen/smp.c
27124@@ -231,11 +231,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27125 {
27126 BUG_ON(smp_processor_id() != 0);
27127 native_smp_prepare_boot_cpu();
27128-
27129- /* We've switched to the "real" per-cpu gdt, so make sure the
27130- old memory can be recycled */
27131- make_lowmem_page_readwrite(xen_initial_gdt);
27132-
27133 xen_filter_cpu_maps();
27134 xen_setup_vcpu_info_placement();
27135 }
27136@@ -302,12 +297,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27137 gdt = get_cpu_gdt_table(cpu);
27138
27139 ctxt->flags = VGCF_IN_KERNEL;
27140- ctxt->user_regs.ds = __USER_DS;
27141- ctxt->user_regs.es = __USER_DS;
27142+ ctxt->user_regs.ds = __KERNEL_DS;
27143+ ctxt->user_regs.es = __KERNEL_DS;
27144 ctxt->user_regs.ss = __KERNEL_DS;
27145 #ifdef CONFIG_X86_32
27146 ctxt->user_regs.fs = __KERNEL_PERCPU;
27147- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27148+ savesegment(gs, ctxt->user_regs.gs);
27149 #else
27150 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27151 #endif
27152@@ -357,13 +352,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27153 int rc;
27154
27155 per_cpu(current_task, cpu) = idle;
27156+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27157 #ifdef CONFIG_X86_32
27158 irq_ctx_init(cpu);
27159 #else
27160 clear_tsk_thread_flag(idle, TIF_FORK);
27161- per_cpu(kernel_stack, cpu) =
27162- (unsigned long)task_stack_page(idle) -
27163- KERNEL_STACK_OFFSET + THREAD_SIZE;
27164+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27165 #endif
27166 xen_setup_runstate_info(cpu);
27167 xen_setup_timer(cpu);
27168diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27169index f9643fc..602e8af 100644
27170--- a/arch/x86/xen/xen-asm_32.S
27171+++ b/arch/x86/xen/xen-asm_32.S
27172@@ -84,14 +84,14 @@ ENTRY(xen_iret)
27173 ESP_OFFSET=4 # bytes pushed onto stack
27174
27175 /*
27176- * Store vcpu_info pointer for easy access. Do it this way to
27177- * avoid having to reload %fs
27178+ * Store vcpu_info pointer for easy access.
27179 */
27180 #ifdef CONFIG_SMP
27181- GET_THREAD_INFO(%eax)
27182- movl TI_cpu(%eax), %eax
27183- movl __per_cpu_offset(,%eax,4), %eax
27184- mov xen_vcpu(%eax), %eax
27185+ push %fs
27186+ mov $(__KERNEL_PERCPU), %eax
27187+ mov %eax, %fs
27188+ mov PER_CPU_VAR(xen_vcpu), %eax
27189+ pop %fs
27190 #else
27191 movl xen_vcpu, %eax
27192 #endif
27193diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27194index aaa7291..3f77960 100644
27195--- a/arch/x86/xen/xen-head.S
27196+++ b/arch/x86/xen/xen-head.S
27197@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27198 #ifdef CONFIG_X86_32
27199 mov %esi,xen_start_info
27200 mov $init_thread_union+THREAD_SIZE,%esp
27201+#ifdef CONFIG_SMP
27202+ movl $cpu_gdt_table,%edi
27203+ movl $__per_cpu_load,%eax
27204+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27205+ rorl $16,%eax
27206+ movb %al,__KERNEL_PERCPU + 4(%edi)
27207+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27208+ movl $__per_cpu_end - 1,%eax
27209+ subl $__per_cpu_start,%eax
27210+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27211+#endif
27212 #else
27213 mov %rsi,xen_start_info
27214 mov $init_thread_union+THREAD_SIZE,%rsp
27215diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27216index 202d4c1..99b072a 100644
27217--- a/arch/x86/xen/xen-ops.h
27218+++ b/arch/x86/xen/xen-ops.h
27219@@ -10,8 +10,6 @@
27220 extern const char xen_hypervisor_callback[];
27221 extern const char xen_failsafe_callback[];
27222
27223-extern void *xen_initial_gdt;
27224-
27225 struct trap_info;
27226 void xen_copy_trap_info(struct trap_info *traps);
27227
27228diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27229index 525bd3d..ef888b1 100644
27230--- a/arch/xtensa/variants/dc232b/include/variant/core.h
27231+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27232@@ -119,9 +119,9 @@
27233 ----------------------------------------------------------------------*/
27234
27235 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27236-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27237 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27238 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27239+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27240
27241 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27242 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27243diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27244index 2f33760..835e50a 100644
27245--- a/arch/xtensa/variants/fsf/include/variant/core.h
27246+++ b/arch/xtensa/variants/fsf/include/variant/core.h
27247@@ -11,6 +11,7 @@
27248 #ifndef _XTENSA_CORE_H
27249 #define _XTENSA_CORE_H
27250
27251+#include <linux/const.h>
27252
27253 /****************************************************************************
27254 Parameters Useful for Any Code, USER or PRIVILEGED
27255@@ -112,9 +113,9 @@
27256 ----------------------------------------------------------------------*/
27257
27258 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27259-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27260 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27261 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27262+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27263
27264 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27265 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27266diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27267index af00795..2bb8105 100644
27268--- a/arch/xtensa/variants/s6000/include/variant/core.h
27269+++ b/arch/xtensa/variants/s6000/include/variant/core.h
27270@@ -11,6 +11,7 @@
27271 #ifndef _XTENSA_CORE_CONFIGURATION_H
27272 #define _XTENSA_CORE_CONFIGURATION_H
27273
27274+#include <linux/const.h>
27275
27276 /****************************************************************************
27277 Parameters Useful for Any Code, USER or PRIVILEGED
27278@@ -118,9 +119,9 @@
27279 ----------------------------------------------------------------------*/
27280
27281 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27282-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27283 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27284 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27285+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27286
27287 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27288 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27289diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27290index 58916af..9cb880b 100644
27291--- a/block/blk-iopoll.c
27292+++ b/block/blk-iopoll.c
27293@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27294 }
27295 EXPORT_SYMBOL(blk_iopoll_complete);
27296
27297-static void blk_iopoll_softirq(struct softirq_action *h)
27298+static void blk_iopoll_softirq(void)
27299 {
27300 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27301 int rearm = 0, budget = blk_iopoll_budget;
27302diff --git a/block/blk-map.c b/block/blk-map.c
27303index 623e1cd..ca1e109 100644
27304--- a/block/blk-map.c
27305+++ b/block/blk-map.c
27306@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27307 if (!len || !kbuf)
27308 return -EINVAL;
27309
27310- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27311+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27312 if (do_copy)
27313 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27314 else
27315diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27316index 467c8de..4bddc6d 100644
27317--- a/block/blk-softirq.c
27318+++ b/block/blk-softirq.c
27319@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27320 * Softirq action handler - move entries to local list and loop over them
27321 * while passing them to the queue registered handler.
27322 */
27323-static void blk_done_softirq(struct softirq_action *h)
27324+static void blk_done_softirq(void)
27325 {
27326 struct list_head *cpu_list, local_list;
27327
27328diff --git a/block/bsg.c b/block/bsg.c
27329index ff64ae3..593560c 100644
27330--- a/block/bsg.c
27331+++ b/block/bsg.c
27332@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27333 struct sg_io_v4 *hdr, struct bsg_device *bd,
27334 fmode_t has_write_perm)
27335 {
27336+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27337+ unsigned char *cmdptr;
27338+
27339 if (hdr->request_len > BLK_MAX_CDB) {
27340 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27341 if (!rq->cmd)
27342 return -ENOMEM;
27343- }
27344+ cmdptr = rq->cmd;
27345+ } else
27346+ cmdptr = tmpcmd;
27347
27348- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27349+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27350 hdr->request_len))
27351 return -EFAULT;
27352
27353+ if (cmdptr != rq->cmd)
27354+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27355+
27356 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27357 if (blk_verify_command(rq->cmd, has_write_perm))
27358 return -EPERM;
27359diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27360index 7c668c8..db3521c 100644
27361--- a/block/compat_ioctl.c
27362+++ b/block/compat_ioctl.c
27363@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27364 err |= __get_user(f->spec1, &uf->spec1);
27365 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27366 err |= __get_user(name, &uf->name);
27367- f->name = compat_ptr(name);
27368+ f->name = (void __force_kernel *)compat_ptr(name);
27369 if (err) {
27370 err = -EFAULT;
27371 goto out;
27372diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27373index 6296b40..417c00f 100644
27374--- a/block/partitions/efi.c
27375+++ b/block/partitions/efi.c
27376@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27377 if (!gpt)
27378 return NULL;
27379
27380+ if (!le32_to_cpu(gpt->num_partition_entries))
27381+ return NULL;
27382+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27383+ if (!pte)
27384+ return NULL;
27385+
27386 count = le32_to_cpu(gpt->num_partition_entries) *
27387 le32_to_cpu(gpt->sizeof_partition_entry);
27388- if (!count)
27389- return NULL;
27390- pte = kzalloc(count, GFP_KERNEL);
27391- if (!pte)
27392- return NULL;
27393-
27394 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27395 (u8 *) pte,
27396 count) < count) {
27397diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27398index 9a87daa..fb17486 100644
27399--- a/block/scsi_ioctl.c
27400+++ b/block/scsi_ioctl.c
27401@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27402 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27403 struct sg_io_hdr *hdr, fmode_t mode)
27404 {
27405- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27406+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27407+ unsigned char *cmdptr;
27408+
27409+ if (rq->cmd != rq->__cmd)
27410+ cmdptr = rq->cmd;
27411+ else
27412+ cmdptr = tmpcmd;
27413+
27414+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27415 return -EFAULT;
27416+
27417+ if (cmdptr != rq->cmd)
27418+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27419+
27420 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27421 return -EPERM;
27422
27423@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27424 int err;
27425 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27426 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27427+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27428+ unsigned char *cmdptr;
27429
27430 if (!sic)
27431 return -EINVAL;
27432@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27433 */
27434 err = -EFAULT;
27435 rq->cmd_len = cmdlen;
27436- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27437+
27438+ if (rq->cmd != rq->__cmd)
27439+ cmdptr = rq->cmd;
27440+ else
27441+ cmdptr = tmpcmd;
27442+
27443+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27444 goto error;
27445
27446+ if (rq->cmd != cmdptr)
27447+ memcpy(rq->cmd, cmdptr, cmdlen);
27448+
27449 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27450 goto error;
27451
27452diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27453index 671d4d6..5f24030 100644
27454--- a/crypto/cryptd.c
27455+++ b/crypto/cryptd.c
27456@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27457
27458 struct cryptd_blkcipher_request_ctx {
27459 crypto_completion_t complete;
27460-};
27461+} __no_const;
27462
27463 struct cryptd_hash_ctx {
27464 struct crypto_shash *child;
27465@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27466
27467 struct cryptd_aead_request_ctx {
27468 crypto_completion_t complete;
27469-};
27470+} __no_const;
27471
27472 static void cryptd_queue_worker(struct work_struct *work);
27473
27474diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27475index e6defd8..c26a225 100644
27476--- a/drivers/acpi/apei/cper.c
27477+++ b/drivers/acpi/apei/cper.c
27478@@ -38,12 +38,12 @@
27479 */
27480 u64 cper_next_record_id(void)
27481 {
27482- static atomic64_t seq;
27483+ static atomic64_unchecked_t seq;
27484
27485- if (!atomic64_read(&seq))
27486- atomic64_set(&seq, ((u64)get_seconds()) << 32);
27487+ if (!atomic64_read_unchecked(&seq))
27488+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27489
27490- return atomic64_inc_return(&seq);
27491+ return atomic64_inc_return_unchecked(&seq);
27492 }
27493 EXPORT_SYMBOL_GPL(cper_next_record_id);
27494
27495diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27496index 7586544..636a2f0 100644
27497--- a/drivers/acpi/ec_sys.c
27498+++ b/drivers/acpi/ec_sys.c
27499@@ -12,6 +12,7 @@
27500 #include <linux/acpi.h>
27501 #include <linux/debugfs.h>
27502 #include <linux/module.h>
27503+#include <linux/uaccess.h>
27504 #include "internal.h"
27505
27506 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27507@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27508 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27509 */
27510 unsigned int size = EC_SPACE_SIZE;
27511- u8 *data = (u8 *) buf;
27512+ u8 data;
27513 loff_t init_off = *off;
27514 int err = 0;
27515
27516@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27517 size = count;
27518
27519 while (size) {
27520- err = ec_read(*off, &data[*off - init_off]);
27521+ err = ec_read(*off, &data);
27522 if (err)
27523 return err;
27524+ if (put_user(data, &buf[*off - init_off]))
27525+ return -EFAULT;
27526 *off += 1;
27527 size--;
27528 }
27529@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27530
27531 unsigned int size = count;
27532 loff_t init_off = *off;
27533- u8 *data = (u8 *) buf;
27534 int err = 0;
27535
27536 if (*off >= EC_SPACE_SIZE)
27537@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27538 }
27539
27540 while (size) {
27541- u8 byte_write = data[*off - init_off];
27542+ u8 byte_write;
27543+ if (get_user(byte_write, &buf[*off - init_off]))
27544+ return -EFAULT;
27545 err = ec_write(*off, byte_write);
27546 if (err)
27547 return err;
27548diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27549index 251c7b62..000462d 100644
27550--- a/drivers/acpi/proc.c
27551+++ b/drivers/acpi/proc.c
27552@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27553 size_t count, loff_t * ppos)
27554 {
27555 struct list_head *node, *next;
27556- char strbuf[5];
27557- char str[5] = "";
27558- unsigned int len = count;
27559+ char strbuf[5] = {0};
27560
27561- if (len > 4)
27562- len = 4;
27563- if (len < 0)
27564+ if (count > 4)
27565+ count = 4;
27566+ if (copy_from_user(strbuf, buffer, count))
27567 return -EFAULT;
27568-
27569- if (copy_from_user(strbuf, buffer, len))
27570- return -EFAULT;
27571- strbuf[len] = '\0';
27572- sscanf(strbuf, "%s", str);
27573+ strbuf[count] = '\0';
27574
27575 mutex_lock(&acpi_device_lock);
27576 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27577@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27578 if (!dev->wakeup.flags.valid)
27579 continue;
27580
27581- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27582+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27583 if (device_can_wakeup(&dev->dev)) {
27584 bool enable = !device_may_wakeup(&dev->dev);
27585 device_set_wakeup_enable(&dev->dev, enable);
27586diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27587index 0734086..3ad3e4c 100644
27588--- a/drivers/acpi/processor_driver.c
27589+++ b/drivers/acpi/processor_driver.c
27590@@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27591 return 0;
27592 #endif
27593
27594- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27595+ BUG_ON(pr->id >= nr_cpu_ids);
27596
27597 /*
27598 * Buggy BIOS check
27599diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27600index cece3a4..0845256 100644
27601--- a/drivers/ata/libata-core.c
27602+++ b/drivers/ata/libata-core.c
27603@@ -4743,7 +4743,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27604 struct ata_port *ap;
27605 unsigned int tag;
27606
27607- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27608+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27609 ap = qc->ap;
27610
27611 qc->flags = 0;
27612@@ -4759,7 +4759,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27613 struct ata_port *ap;
27614 struct ata_link *link;
27615
27616- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27617+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27618 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27619 ap = qc->ap;
27620 link = qc->dev->link;
27621@@ -5823,6 +5823,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27622 return;
27623
27624 spin_lock(&lock);
27625+ pax_open_kernel();
27626
27627 for (cur = ops->inherits; cur; cur = cur->inherits) {
27628 void **inherit = (void **)cur;
27629@@ -5836,8 +5837,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27630 if (IS_ERR(*pp))
27631 *pp = NULL;
27632
27633- ops->inherits = NULL;
27634+ *(struct ata_port_operations **)&ops->inherits = NULL;
27635
27636+ pax_close_kernel();
27637 spin_unlock(&lock);
27638 }
27639
27640diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27641index ac6a5be..c7176b1 100644
27642--- a/drivers/ata/pata_arasan_cf.c
27643+++ b/drivers/ata/pata_arasan_cf.c
27644@@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27645 /* Handle platform specific quirks */
27646 if (pdata->quirk) {
27647 if (pdata->quirk & CF_BROKEN_PIO) {
27648- ap->ops->set_piomode = NULL;
27649+ pax_open_kernel();
27650+ *(void **)&ap->ops->set_piomode = NULL;
27651+ pax_close_kernel();
27652 ap->pio_mask = 0;
27653 }
27654 if (pdata->quirk & CF_BROKEN_MWDMA)
27655diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27656index f9b983a..887b9d8 100644
27657--- a/drivers/atm/adummy.c
27658+++ b/drivers/atm/adummy.c
27659@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27660 vcc->pop(vcc, skb);
27661 else
27662 dev_kfree_skb_any(skb);
27663- atomic_inc(&vcc->stats->tx);
27664+ atomic_inc_unchecked(&vcc->stats->tx);
27665
27666 return 0;
27667 }
27668diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27669index 89b30f3..7964211 100644
27670--- a/drivers/atm/ambassador.c
27671+++ b/drivers/atm/ambassador.c
27672@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27673 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27674
27675 // VC layer stats
27676- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27677+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27678
27679 // free the descriptor
27680 kfree (tx_descr);
27681@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27682 dump_skb ("<<<", vc, skb);
27683
27684 // VC layer stats
27685- atomic_inc(&atm_vcc->stats->rx);
27686+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27687 __net_timestamp(skb);
27688 // end of our responsibility
27689 atm_vcc->push (atm_vcc, skb);
27690@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27691 } else {
27692 PRINTK (KERN_INFO, "dropped over-size frame");
27693 // should we count this?
27694- atomic_inc(&atm_vcc->stats->rx_drop);
27695+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27696 }
27697
27698 } else {
27699@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27700 }
27701
27702 if (check_area (skb->data, skb->len)) {
27703- atomic_inc(&atm_vcc->stats->tx_err);
27704+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27705 return -ENOMEM; // ?
27706 }
27707
27708diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27709index b22d71c..d6e1049 100644
27710--- a/drivers/atm/atmtcp.c
27711+++ b/drivers/atm/atmtcp.c
27712@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27713 if (vcc->pop) vcc->pop(vcc,skb);
27714 else dev_kfree_skb(skb);
27715 if (dev_data) return 0;
27716- atomic_inc(&vcc->stats->tx_err);
27717+ atomic_inc_unchecked(&vcc->stats->tx_err);
27718 return -ENOLINK;
27719 }
27720 size = skb->len+sizeof(struct atmtcp_hdr);
27721@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27722 if (!new_skb) {
27723 if (vcc->pop) vcc->pop(vcc,skb);
27724 else dev_kfree_skb(skb);
27725- atomic_inc(&vcc->stats->tx_err);
27726+ atomic_inc_unchecked(&vcc->stats->tx_err);
27727 return -ENOBUFS;
27728 }
27729 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27730@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27731 if (vcc->pop) vcc->pop(vcc,skb);
27732 else dev_kfree_skb(skb);
27733 out_vcc->push(out_vcc,new_skb);
27734- atomic_inc(&vcc->stats->tx);
27735- atomic_inc(&out_vcc->stats->rx);
27736+ atomic_inc_unchecked(&vcc->stats->tx);
27737+ atomic_inc_unchecked(&out_vcc->stats->rx);
27738 return 0;
27739 }
27740
27741@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27742 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27743 read_unlock(&vcc_sklist_lock);
27744 if (!out_vcc) {
27745- atomic_inc(&vcc->stats->tx_err);
27746+ atomic_inc_unchecked(&vcc->stats->tx_err);
27747 goto done;
27748 }
27749 skb_pull(skb,sizeof(struct atmtcp_hdr));
27750@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27751 __net_timestamp(new_skb);
27752 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27753 out_vcc->push(out_vcc,new_skb);
27754- atomic_inc(&vcc->stats->tx);
27755- atomic_inc(&out_vcc->stats->rx);
27756+ atomic_inc_unchecked(&vcc->stats->tx);
27757+ atomic_inc_unchecked(&out_vcc->stats->rx);
27758 done:
27759 if (vcc->pop) vcc->pop(vcc,skb);
27760 else dev_kfree_skb(skb);
27761diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27762index 2059ee4..faf51c7 100644
27763--- a/drivers/atm/eni.c
27764+++ b/drivers/atm/eni.c
27765@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27766 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27767 vcc->dev->number);
27768 length = 0;
27769- atomic_inc(&vcc->stats->rx_err);
27770+ atomic_inc_unchecked(&vcc->stats->rx_err);
27771 }
27772 else {
27773 length = ATM_CELL_SIZE-1; /* no HEC */
27774@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27775 size);
27776 }
27777 eff = length = 0;
27778- atomic_inc(&vcc->stats->rx_err);
27779+ atomic_inc_unchecked(&vcc->stats->rx_err);
27780 }
27781 else {
27782 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27783@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27784 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27785 vcc->dev->number,vcc->vci,length,size << 2,descr);
27786 length = eff = 0;
27787- atomic_inc(&vcc->stats->rx_err);
27788+ atomic_inc_unchecked(&vcc->stats->rx_err);
27789 }
27790 }
27791 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27792@@ -767,7 +767,7 @@ rx_dequeued++;
27793 vcc->push(vcc,skb);
27794 pushed++;
27795 }
27796- atomic_inc(&vcc->stats->rx);
27797+ atomic_inc_unchecked(&vcc->stats->rx);
27798 }
27799 wake_up(&eni_dev->rx_wait);
27800 }
27801@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27802 PCI_DMA_TODEVICE);
27803 if (vcc->pop) vcc->pop(vcc,skb);
27804 else dev_kfree_skb_irq(skb);
27805- atomic_inc(&vcc->stats->tx);
27806+ atomic_inc_unchecked(&vcc->stats->tx);
27807 wake_up(&eni_dev->tx_wait);
27808 dma_complete++;
27809 }
27810@@ -1567,7 +1567,7 @@ tx_complete++;
27811 /*--------------------------------- entries ---------------------------------*/
27812
27813
27814-static const char *media_name[] __devinitdata = {
27815+static const char *media_name[] __devinitconst = {
27816 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27817 "UTP", "05?", "06?", "07?", /* 4- 7 */
27818 "TAXI","09?", "10?", "11?", /* 8-11 */
27819diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27820index 86fed1b..6dc4721 100644
27821--- a/drivers/atm/firestream.c
27822+++ b/drivers/atm/firestream.c
27823@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27824 }
27825 }
27826
27827- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27828+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27829
27830 fs_dprintk (FS_DEBUG_TXMEM, "i");
27831 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27832@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27833 #endif
27834 skb_put (skb, qe->p1 & 0xffff);
27835 ATM_SKB(skb)->vcc = atm_vcc;
27836- atomic_inc(&atm_vcc->stats->rx);
27837+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27838 __net_timestamp(skb);
27839 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27840 atm_vcc->push (atm_vcc, skb);
27841@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27842 kfree (pe);
27843 }
27844 if (atm_vcc)
27845- atomic_inc(&atm_vcc->stats->rx_drop);
27846+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27847 break;
27848 case 0x1f: /* Reassembly abort: no buffers. */
27849 /* Silently increment error counter. */
27850 if (atm_vcc)
27851- atomic_inc(&atm_vcc->stats->rx_drop);
27852+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27853 break;
27854 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27855 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27856diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27857index 361f5ae..7fc552d 100644
27858--- a/drivers/atm/fore200e.c
27859+++ b/drivers/atm/fore200e.c
27860@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27861 #endif
27862 /* check error condition */
27863 if (*entry->status & STATUS_ERROR)
27864- atomic_inc(&vcc->stats->tx_err);
27865+ atomic_inc_unchecked(&vcc->stats->tx_err);
27866 else
27867- atomic_inc(&vcc->stats->tx);
27868+ atomic_inc_unchecked(&vcc->stats->tx);
27869 }
27870 }
27871
27872@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27873 if (skb == NULL) {
27874 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27875
27876- atomic_inc(&vcc->stats->rx_drop);
27877+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27878 return -ENOMEM;
27879 }
27880
27881@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27882
27883 dev_kfree_skb_any(skb);
27884
27885- atomic_inc(&vcc->stats->rx_drop);
27886+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27887 return -ENOMEM;
27888 }
27889
27890 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27891
27892 vcc->push(vcc, skb);
27893- atomic_inc(&vcc->stats->rx);
27894+ atomic_inc_unchecked(&vcc->stats->rx);
27895
27896 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27897
27898@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27899 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27900 fore200e->atm_dev->number,
27901 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27902- atomic_inc(&vcc->stats->rx_err);
27903+ atomic_inc_unchecked(&vcc->stats->rx_err);
27904 }
27905 }
27906
27907@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27908 goto retry_here;
27909 }
27910
27911- atomic_inc(&vcc->stats->tx_err);
27912+ atomic_inc_unchecked(&vcc->stats->tx_err);
27913
27914 fore200e->tx_sat++;
27915 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27916diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27917index b182c2f..1c6fa8a 100644
27918--- a/drivers/atm/he.c
27919+++ b/drivers/atm/he.c
27920@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27921
27922 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27923 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27924- atomic_inc(&vcc->stats->rx_drop);
27925+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27926 goto return_host_buffers;
27927 }
27928
27929@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27930 RBRQ_LEN_ERR(he_dev->rbrq_head)
27931 ? "LEN_ERR" : "",
27932 vcc->vpi, vcc->vci);
27933- atomic_inc(&vcc->stats->rx_err);
27934+ atomic_inc_unchecked(&vcc->stats->rx_err);
27935 goto return_host_buffers;
27936 }
27937
27938@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27939 vcc->push(vcc, skb);
27940 spin_lock(&he_dev->global_lock);
27941
27942- atomic_inc(&vcc->stats->rx);
27943+ atomic_inc_unchecked(&vcc->stats->rx);
27944
27945 return_host_buffers:
27946 ++pdus_assembled;
27947@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27948 tpd->vcc->pop(tpd->vcc, tpd->skb);
27949 else
27950 dev_kfree_skb_any(tpd->skb);
27951- atomic_inc(&tpd->vcc->stats->tx_err);
27952+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27953 }
27954 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27955 return;
27956@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27957 vcc->pop(vcc, skb);
27958 else
27959 dev_kfree_skb_any(skb);
27960- atomic_inc(&vcc->stats->tx_err);
27961+ atomic_inc_unchecked(&vcc->stats->tx_err);
27962 return -EINVAL;
27963 }
27964
27965@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27966 vcc->pop(vcc, skb);
27967 else
27968 dev_kfree_skb_any(skb);
27969- atomic_inc(&vcc->stats->tx_err);
27970+ atomic_inc_unchecked(&vcc->stats->tx_err);
27971 return -EINVAL;
27972 }
27973 #endif
27974@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27975 vcc->pop(vcc, skb);
27976 else
27977 dev_kfree_skb_any(skb);
27978- atomic_inc(&vcc->stats->tx_err);
27979+ atomic_inc_unchecked(&vcc->stats->tx_err);
27980 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27981 return -ENOMEM;
27982 }
27983@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27984 vcc->pop(vcc, skb);
27985 else
27986 dev_kfree_skb_any(skb);
27987- atomic_inc(&vcc->stats->tx_err);
27988+ atomic_inc_unchecked(&vcc->stats->tx_err);
27989 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27990 return -ENOMEM;
27991 }
27992@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27993 __enqueue_tpd(he_dev, tpd, cid);
27994 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27995
27996- atomic_inc(&vcc->stats->tx);
27997+ atomic_inc_unchecked(&vcc->stats->tx);
27998
27999 return 0;
28000 }
28001diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28002index 7d01c2a..4e3ac01 100644
28003--- a/drivers/atm/horizon.c
28004+++ b/drivers/atm/horizon.c
28005@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28006 {
28007 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28008 // VC layer stats
28009- atomic_inc(&vcc->stats->rx);
28010+ atomic_inc_unchecked(&vcc->stats->rx);
28011 __net_timestamp(skb);
28012 // end of our responsibility
28013 vcc->push (vcc, skb);
28014@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28015 dev->tx_iovec = NULL;
28016
28017 // VC layer stats
28018- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28019+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28020
28021 // free the skb
28022 hrz_kfree_skb (skb);
28023diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28024index 8974bd2..b856f85 100644
28025--- a/drivers/atm/idt77252.c
28026+++ b/drivers/atm/idt77252.c
28027@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28028 else
28029 dev_kfree_skb(skb);
28030
28031- atomic_inc(&vcc->stats->tx);
28032+ atomic_inc_unchecked(&vcc->stats->tx);
28033 }
28034
28035 atomic_dec(&scq->used);
28036@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28037 if ((sb = dev_alloc_skb(64)) == NULL) {
28038 printk("%s: Can't allocate buffers for aal0.\n",
28039 card->name);
28040- atomic_add(i, &vcc->stats->rx_drop);
28041+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28042 break;
28043 }
28044 if (!atm_charge(vcc, sb->truesize)) {
28045 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28046 card->name);
28047- atomic_add(i - 1, &vcc->stats->rx_drop);
28048+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28049 dev_kfree_skb(sb);
28050 break;
28051 }
28052@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28053 ATM_SKB(sb)->vcc = vcc;
28054 __net_timestamp(sb);
28055 vcc->push(vcc, sb);
28056- atomic_inc(&vcc->stats->rx);
28057+ atomic_inc_unchecked(&vcc->stats->rx);
28058
28059 cell += ATM_CELL_PAYLOAD;
28060 }
28061@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28062 "(CDC: %08x)\n",
28063 card->name, len, rpp->len, readl(SAR_REG_CDC));
28064 recycle_rx_pool_skb(card, rpp);
28065- atomic_inc(&vcc->stats->rx_err);
28066+ atomic_inc_unchecked(&vcc->stats->rx_err);
28067 return;
28068 }
28069 if (stat & SAR_RSQE_CRC) {
28070 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28071 recycle_rx_pool_skb(card, rpp);
28072- atomic_inc(&vcc->stats->rx_err);
28073+ atomic_inc_unchecked(&vcc->stats->rx_err);
28074 return;
28075 }
28076 if (skb_queue_len(&rpp->queue) > 1) {
28077@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28078 RXPRINTK("%s: Can't alloc RX skb.\n",
28079 card->name);
28080 recycle_rx_pool_skb(card, rpp);
28081- atomic_inc(&vcc->stats->rx_err);
28082+ atomic_inc_unchecked(&vcc->stats->rx_err);
28083 return;
28084 }
28085 if (!atm_charge(vcc, skb->truesize)) {
28086@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28087 __net_timestamp(skb);
28088
28089 vcc->push(vcc, skb);
28090- atomic_inc(&vcc->stats->rx);
28091+ atomic_inc_unchecked(&vcc->stats->rx);
28092
28093 return;
28094 }
28095@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28096 __net_timestamp(skb);
28097
28098 vcc->push(vcc, skb);
28099- atomic_inc(&vcc->stats->rx);
28100+ atomic_inc_unchecked(&vcc->stats->rx);
28101
28102 if (skb->truesize > SAR_FB_SIZE_3)
28103 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28104@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28105 if (vcc->qos.aal != ATM_AAL0) {
28106 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28107 card->name, vpi, vci);
28108- atomic_inc(&vcc->stats->rx_drop);
28109+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28110 goto drop;
28111 }
28112
28113 if ((sb = dev_alloc_skb(64)) == NULL) {
28114 printk("%s: Can't allocate buffers for AAL0.\n",
28115 card->name);
28116- atomic_inc(&vcc->stats->rx_err);
28117+ atomic_inc_unchecked(&vcc->stats->rx_err);
28118 goto drop;
28119 }
28120
28121@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28122 ATM_SKB(sb)->vcc = vcc;
28123 __net_timestamp(sb);
28124 vcc->push(vcc, sb);
28125- atomic_inc(&vcc->stats->rx);
28126+ atomic_inc_unchecked(&vcc->stats->rx);
28127
28128 drop:
28129 skb_pull(queue, 64);
28130@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28131
28132 if (vc == NULL) {
28133 printk("%s: NULL connection in send().\n", card->name);
28134- atomic_inc(&vcc->stats->tx_err);
28135+ atomic_inc_unchecked(&vcc->stats->tx_err);
28136 dev_kfree_skb(skb);
28137 return -EINVAL;
28138 }
28139 if (!test_bit(VCF_TX, &vc->flags)) {
28140 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28141- atomic_inc(&vcc->stats->tx_err);
28142+ atomic_inc_unchecked(&vcc->stats->tx_err);
28143 dev_kfree_skb(skb);
28144 return -EINVAL;
28145 }
28146@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28147 break;
28148 default:
28149 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28150- atomic_inc(&vcc->stats->tx_err);
28151+ atomic_inc_unchecked(&vcc->stats->tx_err);
28152 dev_kfree_skb(skb);
28153 return -EINVAL;
28154 }
28155
28156 if (skb_shinfo(skb)->nr_frags != 0) {
28157 printk("%s: No scatter-gather yet.\n", card->name);
28158- atomic_inc(&vcc->stats->tx_err);
28159+ atomic_inc_unchecked(&vcc->stats->tx_err);
28160 dev_kfree_skb(skb);
28161 return -EINVAL;
28162 }
28163@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28164
28165 err = queue_skb(card, vc, skb, oam);
28166 if (err) {
28167- atomic_inc(&vcc->stats->tx_err);
28168+ atomic_inc_unchecked(&vcc->stats->tx_err);
28169 dev_kfree_skb(skb);
28170 return err;
28171 }
28172@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28173 skb = dev_alloc_skb(64);
28174 if (!skb) {
28175 printk("%s: Out of memory in send_oam().\n", card->name);
28176- atomic_inc(&vcc->stats->tx_err);
28177+ atomic_inc_unchecked(&vcc->stats->tx_err);
28178 return -ENOMEM;
28179 }
28180 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28181diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28182index d438601..8b98495 100644
28183--- a/drivers/atm/iphase.c
28184+++ b/drivers/atm/iphase.c
28185@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28186 status = (u_short) (buf_desc_ptr->desc_mode);
28187 if (status & (RX_CER | RX_PTE | RX_OFL))
28188 {
28189- atomic_inc(&vcc->stats->rx_err);
28190+ atomic_inc_unchecked(&vcc->stats->rx_err);
28191 IF_ERR(printk("IA: bad packet, dropping it");)
28192 if (status & RX_CER) {
28193 IF_ERR(printk(" cause: packet CRC error\n");)
28194@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28195 len = dma_addr - buf_addr;
28196 if (len > iadev->rx_buf_sz) {
28197 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28198- atomic_inc(&vcc->stats->rx_err);
28199+ atomic_inc_unchecked(&vcc->stats->rx_err);
28200 goto out_free_desc;
28201 }
28202
28203@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28204 ia_vcc = INPH_IA_VCC(vcc);
28205 if (ia_vcc == NULL)
28206 {
28207- atomic_inc(&vcc->stats->rx_err);
28208+ atomic_inc_unchecked(&vcc->stats->rx_err);
28209 atm_return(vcc, skb->truesize);
28210 dev_kfree_skb_any(skb);
28211 goto INCR_DLE;
28212@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28213 if ((length > iadev->rx_buf_sz) || (length >
28214 (skb->len - sizeof(struct cpcs_trailer))))
28215 {
28216- atomic_inc(&vcc->stats->rx_err);
28217+ atomic_inc_unchecked(&vcc->stats->rx_err);
28218 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28219 length, skb->len);)
28220 atm_return(vcc, skb->truesize);
28221@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28222
28223 IF_RX(printk("rx_dle_intr: skb push");)
28224 vcc->push(vcc,skb);
28225- atomic_inc(&vcc->stats->rx);
28226+ atomic_inc_unchecked(&vcc->stats->rx);
28227 iadev->rx_pkt_cnt++;
28228 }
28229 INCR_DLE:
28230@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28231 {
28232 struct k_sonet_stats *stats;
28233 stats = &PRIV(_ia_dev[board])->sonet_stats;
28234- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28235- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28236- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28237- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28238- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28239- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28240- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28241- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28242- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28243+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28244+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28245+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28246+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28247+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28248+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28249+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28250+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28251+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28252 }
28253 ia_cmds.status = 0;
28254 break;
28255@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28256 if ((desc == 0) || (desc > iadev->num_tx_desc))
28257 {
28258 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28259- atomic_inc(&vcc->stats->tx);
28260+ atomic_inc_unchecked(&vcc->stats->tx);
28261 if (vcc->pop)
28262 vcc->pop(vcc, skb);
28263 else
28264@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28265 ATM_DESC(skb) = vcc->vci;
28266 skb_queue_tail(&iadev->tx_dma_q, skb);
28267
28268- atomic_inc(&vcc->stats->tx);
28269+ atomic_inc_unchecked(&vcc->stats->tx);
28270 iadev->tx_pkt_cnt++;
28271 /* Increment transaction counter */
28272 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28273
28274 #if 0
28275 /* add flow control logic */
28276- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28277+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28278 if (iavcc->vc_desc_cnt > 10) {
28279 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28280 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28281diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28282index 68c7588..7036683 100644
28283--- a/drivers/atm/lanai.c
28284+++ b/drivers/atm/lanai.c
28285@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28286 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28287 lanai_endtx(lanai, lvcc);
28288 lanai_free_skb(lvcc->tx.atmvcc, skb);
28289- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28290+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28291 }
28292
28293 /* Try to fill the buffer - don't call unless there is backlog */
28294@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28295 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28296 __net_timestamp(skb);
28297 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28298- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28299+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28300 out:
28301 lvcc->rx.buf.ptr = end;
28302 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28303@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28304 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28305 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28306 lanai->stats.service_rxnotaal5++;
28307- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28308+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28309 return 0;
28310 }
28311 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28312@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28313 int bytes;
28314 read_unlock(&vcc_sklist_lock);
28315 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28316- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28317+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28318 lvcc->stats.x.aal5.service_trash++;
28319 bytes = (SERVICE_GET_END(s) * 16) -
28320 (((unsigned long) lvcc->rx.buf.ptr) -
28321@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28322 }
28323 if (s & SERVICE_STREAM) {
28324 read_unlock(&vcc_sklist_lock);
28325- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28326+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28327 lvcc->stats.x.aal5.service_stream++;
28328 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28329 "PDU on VCI %d!\n", lanai->number, vci);
28330@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28331 return 0;
28332 }
28333 DPRINTK("got rx crc error on vci %d\n", vci);
28334- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28335+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28336 lvcc->stats.x.aal5.service_rxcrc++;
28337 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28338 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28339diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28340index 1c70c45..300718d 100644
28341--- a/drivers/atm/nicstar.c
28342+++ b/drivers/atm/nicstar.c
28343@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28344 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28345 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28346 card->index);
28347- atomic_inc(&vcc->stats->tx_err);
28348+ atomic_inc_unchecked(&vcc->stats->tx_err);
28349 dev_kfree_skb_any(skb);
28350 return -EINVAL;
28351 }
28352@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28353 if (!vc->tx) {
28354 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28355 card->index);
28356- atomic_inc(&vcc->stats->tx_err);
28357+ atomic_inc_unchecked(&vcc->stats->tx_err);
28358 dev_kfree_skb_any(skb);
28359 return -EINVAL;
28360 }
28361@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28362 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28363 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28364 card->index);
28365- atomic_inc(&vcc->stats->tx_err);
28366+ atomic_inc_unchecked(&vcc->stats->tx_err);
28367 dev_kfree_skb_any(skb);
28368 return -EINVAL;
28369 }
28370
28371 if (skb_shinfo(skb)->nr_frags != 0) {
28372 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28373- atomic_inc(&vcc->stats->tx_err);
28374+ atomic_inc_unchecked(&vcc->stats->tx_err);
28375 dev_kfree_skb_any(skb);
28376 return -EINVAL;
28377 }
28378@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28379 }
28380
28381 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28382- atomic_inc(&vcc->stats->tx_err);
28383+ atomic_inc_unchecked(&vcc->stats->tx_err);
28384 dev_kfree_skb_any(skb);
28385 return -EIO;
28386 }
28387- atomic_inc(&vcc->stats->tx);
28388+ atomic_inc_unchecked(&vcc->stats->tx);
28389
28390 return 0;
28391 }
28392@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28393 printk
28394 ("nicstar%d: Can't allocate buffers for aal0.\n",
28395 card->index);
28396- atomic_add(i, &vcc->stats->rx_drop);
28397+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28398 break;
28399 }
28400 if (!atm_charge(vcc, sb->truesize)) {
28401 RXPRINTK
28402 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28403 card->index);
28404- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28405+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28406 dev_kfree_skb_any(sb);
28407 break;
28408 }
28409@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28410 ATM_SKB(sb)->vcc = vcc;
28411 __net_timestamp(sb);
28412 vcc->push(vcc, sb);
28413- atomic_inc(&vcc->stats->rx);
28414+ atomic_inc_unchecked(&vcc->stats->rx);
28415 cell += ATM_CELL_PAYLOAD;
28416 }
28417
28418@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28419 if (iovb == NULL) {
28420 printk("nicstar%d: Out of iovec buffers.\n",
28421 card->index);
28422- atomic_inc(&vcc->stats->rx_drop);
28423+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28424 recycle_rx_buf(card, skb);
28425 return;
28426 }
28427@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28428 small or large buffer itself. */
28429 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28430 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28431- atomic_inc(&vcc->stats->rx_err);
28432+ atomic_inc_unchecked(&vcc->stats->rx_err);
28433 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28434 NS_MAX_IOVECS);
28435 NS_PRV_IOVCNT(iovb) = 0;
28436@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28437 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28438 card->index);
28439 which_list(card, skb);
28440- atomic_inc(&vcc->stats->rx_err);
28441+ atomic_inc_unchecked(&vcc->stats->rx_err);
28442 recycle_rx_buf(card, skb);
28443 vc->rx_iov = NULL;
28444 recycle_iov_buf(card, iovb);
28445@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28446 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28447 card->index);
28448 which_list(card, skb);
28449- atomic_inc(&vcc->stats->rx_err);
28450+ atomic_inc_unchecked(&vcc->stats->rx_err);
28451 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28452 NS_PRV_IOVCNT(iovb));
28453 vc->rx_iov = NULL;
28454@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28455 printk(" - PDU size mismatch.\n");
28456 else
28457 printk(".\n");
28458- atomic_inc(&vcc->stats->rx_err);
28459+ atomic_inc_unchecked(&vcc->stats->rx_err);
28460 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28461 NS_PRV_IOVCNT(iovb));
28462 vc->rx_iov = NULL;
28463@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28464 /* skb points to a small buffer */
28465 if (!atm_charge(vcc, skb->truesize)) {
28466 push_rxbufs(card, skb);
28467- atomic_inc(&vcc->stats->rx_drop);
28468+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28469 } else {
28470 skb_put(skb, len);
28471 dequeue_sm_buf(card, skb);
28472@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28473 ATM_SKB(skb)->vcc = vcc;
28474 __net_timestamp(skb);
28475 vcc->push(vcc, skb);
28476- atomic_inc(&vcc->stats->rx);
28477+ atomic_inc_unchecked(&vcc->stats->rx);
28478 }
28479 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28480 struct sk_buff *sb;
28481@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28482 if (len <= NS_SMBUFSIZE) {
28483 if (!atm_charge(vcc, sb->truesize)) {
28484 push_rxbufs(card, sb);
28485- atomic_inc(&vcc->stats->rx_drop);
28486+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28487 } else {
28488 skb_put(sb, len);
28489 dequeue_sm_buf(card, sb);
28490@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28491 ATM_SKB(sb)->vcc = vcc;
28492 __net_timestamp(sb);
28493 vcc->push(vcc, sb);
28494- atomic_inc(&vcc->stats->rx);
28495+ atomic_inc_unchecked(&vcc->stats->rx);
28496 }
28497
28498 push_rxbufs(card, skb);
28499@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28500
28501 if (!atm_charge(vcc, skb->truesize)) {
28502 push_rxbufs(card, skb);
28503- atomic_inc(&vcc->stats->rx_drop);
28504+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28505 } else {
28506 dequeue_lg_buf(card, skb);
28507 #ifdef NS_USE_DESTRUCTORS
28508@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28509 ATM_SKB(skb)->vcc = vcc;
28510 __net_timestamp(skb);
28511 vcc->push(vcc, skb);
28512- atomic_inc(&vcc->stats->rx);
28513+ atomic_inc_unchecked(&vcc->stats->rx);
28514 }
28515
28516 push_rxbufs(card, sb);
28517@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28518 printk
28519 ("nicstar%d: Out of huge buffers.\n",
28520 card->index);
28521- atomic_inc(&vcc->stats->rx_drop);
28522+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28523 recycle_iovec_rx_bufs(card,
28524 (struct iovec *)
28525 iovb->data,
28526@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28527 card->hbpool.count++;
28528 } else
28529 dev_kfree_skb_any(hb);
28530- atomic_inc(&vcc->stats->rx_drop);
28531+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28532 } else {
28533 /* Copy the small buffer to the huge buffer */
28534 sb = (struct sk_buff *)iov->iov_base;
28535@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28536 #endif /* NS_USE_DESTRUCTORS */
28537 __net_timestamp(hb);
28538 vcc->push(vcc, hb);
28539- atomic_inc(&vcc->stats->rx);
28540+ atomic_inc_unchecked(&vcc->stats->rx);
28541 }
28542 }
28543
28544diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28545index 9851093..adb2b1e 100644
28546--- a/drivers/atm/solos-pci.c
28547+++ b/drivers/atm/solos-pci.c
28548@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28549 }
28550 atm_charge(vcc, skb->truesize);
28551 vcc->push(vcc, skb);
28552- atomic_inc(&vcc->stats->rx);
28553+ atomic_inc_unchecked(&vcc->stats->rx);
28554 break;
28555
28556 case PKT_STATUS:
28557@@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28558 vcc = SKB_CB(oldskb)->vcc;
28559
28560 if (vcc) {
28561- atomic_inc(&vcc->stats->tx);
28562+ atomic_inc_unchecked(&vcc->stats->tx);
28563 solos_pop(vcc, oldskb);
28564 } else
28565 dev_kfree_skb_irq(oldskb);
28566diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28567index 0215934..ce9f5b1 100644
28568--- a/drivers/atm/suni.c
28569+++ b/drivers/atm/suni.c
28570@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28571
28572
28573 #define ADD_LIMITED(s,v) \
28574- atomic_add((v),&stats->s); \
28575- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28576+ atomic_add_unchecked((v),&stats->s); \
28577+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28578
28579
28580 static void suni_hz(unsigned long from_timer)
28581diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28582index 5120a96..e2572bd 100644
28583--- a/drivers/atm/uPD98402.c
28584+++ b/drivers/atm/uPD98402.c
28585@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28586 struct sonet_stats tmp;
28587 int error = 0;
28588
28589- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28590+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28591 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28592 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28593 if (zero && !error) {
28594@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28595
28596
28597 #define ADD_LIMITED(s,v) \
28598- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28599- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28600- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28601+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28602+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28603+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28604
28605
28606 static void stat_event(struct atm_dev *dev)
28607@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28608 if (reason & uPD98402_INT_PFM) stat_event(dev);
28609 if (reason & uPD98402_INT_PCO) {
28610 (void) GET(PCOCR); /* clear interrupt cause */
28611- atomic_add(GET(HECCT),
28612+ atomic_add_unchecked(GET(HECCT),
28613 &PRIV(dev)->sonet_stats.uncorr_hcs);
28614 }
28615 if ((reason & uPD98402_INT_RFO) &&
28616@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28617 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28618 uPD98402_INT_LOS),PIMR); /* enable them */
28619 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28620- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28621- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28622- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28623+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28624+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28625+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28626 return 0;
28627 }
28628
28629diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28630index abe4e20..83c4727 100644
28631--- a/drivers/atm/zatm.c
28632+++ b/drivers/atm/zatm.c
28633@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28634 }
28635 if (!size) {
28636 dev_kfree_skb_irq(skb);
28637- if (vcc) atomic_inc(&vcc->stats->rx_err);
28638+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28639 continue;
28640 }
28641 if (!atm_charge(vcc,skb->truesize)) {
28642@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28643 skb->len = size;
28644 ATM_SKB(skb)->vcc = vcc;
28645 vcc->push(vcc,skb);
28646- atomic_inc(&vcc->stats->rx);
28647+ atomic_inc_unchecked(&vcc->stats->rx);
28648 }
28649 zout(pos & 0xffff,MTA(mbx));
28650 #if 0 /* probably a stupid idea */
28651@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28652 skb_queue_head(&zatm_vcc->backlog,skb);
28653 break;
28654 }
28655- atomic_inc(&vcc->stats->tx);
28656+ atomic_inc_unchecked(&vcc->stats->tx);
28657 wake_up(&zatm_vcc->tx_wait);
28658 }
28659
28660diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28661index 765c3a2..771ace6 100644
28662--- a/drivers/base/devtmpfs.c
28663+++ b/drivers/base/devtmpfs.c
28664@@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28665 if (!thread)
28666 return 0;
28667
28668- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28669+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28670 if (err)
28671 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28672 else
28673diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28674index cbb463b..babe2cf 100644
28675--- a/drivers/base/power/wakeup.c
28676+++ b/drivers/base/power/wakeup.c
28677@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28678 * They need to be modified together atomically, so it's better to use one
28679 * atomic variable to hold them both.
28680 */
28681-static atomic_t combined_event_count = ATOMIC_INIT(0);
28682+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28683
28684 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28685 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28686
28687 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28688 {
28689- unsigned int comb = atomic_read(&combined_event_count);
28690+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
28691
28692 *cnt = (comb >> IN_PROGRESS_BITS);
28693 *inpr = comb & MAX_IN_PROGRESS;
28694@@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28695 ws->start_prevent_time = ws->last_time;
28696
28697 /* Increment the counter of events in progress. */
28698- cec = atomic_inc_return(&combined_event_count);
28699+ cec = atomic_inc_return_unchecked(&combined_event_count);
28700
28701 trace_wakeup_source_activate(ws->name, cec);
28702 }
28703@@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28704 * Increment the counter of registered wakeup events and decrement the
28705 * couter of wakeup events in progress simultaneously.
28706 */
28707- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
28708+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28709 trace_wakeup_source_deactivate(ws->name, cec);
28710
28711 split_counters(&cnt, &inpr);
28712diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28713index b0f553b..77b928b 100644
28714--- a/drivers/block/cciss.c
28715+++ b/drivers/block/cciss.c
28716@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28717 int err;
28718 u32 cp;
28719
28720+ memset(&arg64, 0, sizeof(arg64));
28721+
28722 err = 0;
28723 err |=
28724 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28725@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28726 while (!list_empty(&h->reqQ)) {
28727 c = list_entry(h->reqQ.next, CommandList_struct, list);
28728 /* can't do anything if fifo is full */
28729- if ((h->access.fifo_full(h))) {
28730+ if ((h->access->fifo_full(h))) {
28731 dev_warn(&h->pdev->dev, "fifo full\n");
28732 break;
28733 }
28734@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28735 h->Qdepth--;
28736
28737 /* Tell the controller execute command */
28738- h->access.submit_command(h, c);
28739+ h->access->submit_command(h, c);
28740
28741 /* Put job onto the completed Q */
28742 addQ(&h->cmpQ, c);
28743@@ -3443,17 +3445,17 @@ startio:
28744
28745 static inline unsigned long get_next_completion(ctlr_info_t *h)
28746 {
28747- return h->access.command_completed(h);
28748+ return h->access->command_completed(h);
28749 }
28750
28751 static inline int interrupt_pending(ctlr_info_t *h)
28752 {
28753- return h->access.intr_pending(h);
28754+ return h->access->intr_pending(h);
28755 }
28756
28757 static inline long interrupt_not_for_us(ctlr_info_t *h)
28758 {
28759- return ((h->access.intr_pending(h) == 0) ||
28760+ return ((h->access->intr_pending(h) == 0) ||
28761 (h->interrupts_enabled == 0));
28762 }
28763
28764@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28765 u32 a;
28766
28767 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28768- return h->access.command_completed(h);
28769+ return h->access->command_completed(h);
28770
28771 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28772 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28773@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28774 trans_support & CFGTBL_Trans_use_short_tags);
28775
28776 /* Change the access methods to the performant access methods */
28777- h->access = SA5_performant_access;
28778+ h->access = &SA5_performant_access;
28779 h->transMethod = CFGTBL_Trans_Performant;
28780
28781 return;
28782@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28783 if (prod_index < 0)
28784 return -ENODEV;
28785 h->product_name = products[prod_index].product_name;
28786- h->access = *(products[prod_index].access);
28787+ h->access = products[prod_index].access;
28788
28789 if (cciss_board_disabled(h)) {
28790 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28791@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28792 }
28793
28794 /* make sure the board interrupts are off */
28795- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28796+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28797 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28798 if (rc)
28799 goto clean2;
28800@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28801 * fake ones to scoop up any residual completions.
28802 */
28803 spin_lock_irqsave(&h->lock, flags);
28804- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28805+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28806 spin_unlock_irqrestore(&h->lock, flags);
28807 free_irq(h->intr[h->intr_mode], h);
28808 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28809@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28810 dev_info(&h->pdev->dev, "Board READY.\n");
28811 dev_info(&h->pdev->dev,
28812 "Waiting for stale completions to drain.\n");
28813- h->access.set_intr_mask(h, CCISS_INTR_ON);
28814+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28815 msleep(10000);
28816- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28817+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28818
28819 rc = controller_reset_failed(h->cfgtable);
28820 if (rc)
28821@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28822 cciss_scsi_setup(h);
28823
28824 /* Turn the interrupts on so we can service requests */
28825- h->access.set_intr_mask(h, CCISS_INTR_ON);
28826+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28827
28828 /* Get the firmware version */
28829 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28830@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28831 kfree(flush_buf);
28832 if (return_code != IO_OK)
28833 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28834- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28835+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28836 free_irq(h->intr[h->intr_mode], h);
28837 }
28838
28839diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28840index 7fda30e..eb5dfe0 100644
28841--- a/drivers/block/cciss.h
28842+++ b/drivers/block/cciss.h
28843@@ -101,7 +101,7 @@ struct ctlr_info
28844 /* information about each logical volume */
28845 drive_info_struct *drv[CISS_MAX_LUN];
28846
28847- struct access_method access;
28848+ struct access_method *access;
28849
28850 /* queue and queue Info */
28851 struct list_head reqQ;
28852diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28853index 9125bbe..eede5c8 100644
28854--- a/drivers/block/cpqarray.c
28855+++ b/drivers/block/cpqarray.c
28856@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28857 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28858 goto Enomem4;
28859 }
28860- hba[i]->access.set_intr_mask(hba[i], 0);
28861+ hba[i]->access->set_intr_mask(hba[i], 0);
28862 if (request_irq(hba[i]->intr, do_ida_intr,
28863 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28864 {
28865@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28866 add_timer(&hba[i]->timer);
28867
28868 /* Enable IRQ now that spinlock and rate limit timer are set up */
28869- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28870+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28871
28872 for(j=0; j<NWD; j++) {
28873 struct gendisk *disk = ida_gendisk[i][j];
28874@@ -694,7 +694,7 @@ DBGINFO(
28875 for(i=0; i<NR_PRODUCTS; i++) {
28876 if (board_id == products[i].board_id) {
28877 c->product_name = products[i].product_name;
28878- c->access = *(products[i].access);
28879+ c->access = products[i].access;
28880 break;
28881 }
28882 }
28883@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28884 hba[ctlr]->intr = intr;
28885 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28886 hba[ctlr]->product_name = products[j].product_name;
28887- hba[ctlr]->access = *(products[j].access);
28888+ hba[ctlr]->access = products[j].access;
28889 hba[ctlr]->ctlr = ctlr;
28890 hba[ctlr]->board_id = board_id;
28891 hba[ctlr]->pci_dev = NULL; /* not PCI */
28892@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28893
28894 while((c = h->reqQ) != NULL) {
28895 /* Can't do anything if we're busy */
28896- if (h->access.fifo_full(h) == 0)
28897+ if (h->access->fifo_full(h) == 0)
28898 return;
28899
28900 /* Get the first entry from the request Q */
28901@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28902 h->Qdepth--;
28903
28904 /* Tell the controller to do our bidding */
28905- h->access.submit_command(h, c);
28906+ h->access->submit_command(h, c);
28907
28908 /* Get onto the completion Q */
28909 addQ(&h->cmpQ, c);
28910@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28911 unsigned long flags;
28912 __u32 a,a1;
28913
28914- istat = h->access.intr_pending(h);
28915+ istat = h->access->intr_pending(h);
28916 /* Is this interrupt for us? */
28917 if (istat == 0)
28918 return IRQ_NONE;
28919@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28920 */
28921 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28922 if (istat & FIFO_NOT_EMPTY) {
28923- while((a = h->access.command_completed(h))) {
28924+ while((a = h->access->command_completed(h))) {
28925 a1 = a; a &= ~3;
28926 if ((c = h->cmpQ) == NULL)
28927 {
28928@@ -1449,11 +1449,11 @@ static int sendcmd(
28929 /*
28930 * Disable interrupt
28931 */
28932- info_p->access.set_intr_mask(info_p, 0);
28933+ info_p->access->set_intr_mask(info_p, 0);
28934 /* Make sure there is room in the command FIFO */
28935 /* Actually it should be completely empty at this time. */
28936 for (i = 200000; i > 0; i--) {
28937- temp = info_p->access.fifo_full(info_p);
28938+ temp = info_p->access->fifo_full(info_p);
28939 if (temp != 0) {
28940 break;
28941 }
28942@@ -1466,7 +1466,7 @@ DBG(
28943 /*
28944 * Send the cmd
28945 */
28946- info_p->access.submit_command(info_p, c);
28947+ info_p->access->submit_command(info_p, c);
28948 complete = pollcomplete(ctlr);
28949
28950 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28951@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
28952 * we check the new geometry. Then turn interrupts back on when
28953 * we're done.
28954 */
28955- host->access.set_intr_mask(host, 0);
28956+ host->access->set_intr_mask(host, 0);
28957 getgeometry(ctlr);
28958- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
28959+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
28960
28961 for(i=0; i<NWD; i++) {
28962 struct gendisk *disk = ida_gendisk[ctlr][i];
28963@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
28964 /* Wait (up to 2 seconds) for a command to complete */
28965
28966 for (i = 200000; i > 0; i--) {
28967- done = hba[ctlr]->access.command_completed(hba[ctlr]);
28968+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
28969 if (done == 0) {
28970 udelay(10); /* a short fixed delay */
28971 } else
28972diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
28973index be73e9d..7fbf140 100644
28974--- a/drivers/block/cpqarray.h
28975+++ b/drivers/block/cpqarray.h
28976@@ -99,7 +99,7 @@ struct ctlr_info {
28977 drv_info_t drv[NWD];
28978 struct proc_dir_entry *proc;
28979
28980- struct access_method access;
28981+ struct access_method *access;
28982
28983 cmdlist_t *reqQ;
28984 cmdlist_t *cmpQ;
28985diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
28986index 02f013a..afeba24 100644
28987--- a/drivers/block/drbd/drbd_int.h
28988+++ b/drivers/block/drbd/drbd_int.h
28989@@ -735,7 +735,7 @@ struct drbd_request;
28990 struct drbd_epoch {
28991 struct list_head list;
28992 unsigned int barrier_nr;
28993- atomic_t epoch_size; /* increased on every request added. */
28994+ atomic_unchecked_t epoch_size; /* increased on every request added. */
28995 atomic_t active; /* increased on every req. added, and dec on every finished. */
28996 unsigned long flags;
28997 };
28998@@ -1110,7 +1110,7 @@ struct drbd_conf {
28999 void *int_dig_in;
29000 void *int_dig_vv;
29001 wait_queue_head_t seq_wait;
29002- atomic_t packet_seq;
29003+ atomic_unchecked_t packet_seq;
29004 unsigned int peer_seq;
29005 spinlock_t peer_seq_lock;
29006 unsigned int minor;
29007@@ -1651,30 +1651,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29008
29009 static inline void drbd_tcp_cork(struct socket *sock)
29010 {
29011- int __user val = 1;
29012+ int val = 1;
29013 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29014- (char __user *)&val, sizeof(val));
29015+ (char __force_user *)&val, sizeof(val));
29016 }
29017
29018 static inline void drbd_tcp_uncork(struct socket *sock)
29019 {
29020- int __user val = 0;
29021+ int val = 0;
29022 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29023- (char __user *)&val, sizeof(val));
29024+ (char __force_user *)&val, sizeof(val));
29025 }
29026
29027 static inline void drbd_tcp_nodelay(struct socket *sock)
29028 {
29029- int __user val = 1;
29030+ int val = 1;
29031 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29032- (char __user *)&val, sizeof(val));
29033+ (char __force_user *)&val, sizeof(val));
29034 }
29035
29036 static inline void drbd_tcp_quickack(struct socket *sock)
29037 {
29038- int __user val = 2;
29039+ int val = 2;
29040 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29041- (char __user *)&val, sizeof(val));
29042+ (char __force_user *)&val, sizeof(val));
29043 }
29044
29045 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29046diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29047index 920ede2..cb827ba 100644
29048--- a/drivers/block/drbd/drbd_main.c
29049+++ b/drivers/block/drbd/drbd_main.c
29050@@ -2555,7 +2555,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29051 p.sector = sector;
29052 p.block_id = block_id;
29053 p.blksize = blksize;
29054- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29055+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29056
29057 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29058 return false;
29059@@ -2853,7 +2853,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29060
29061 p.sector = cpu_to_be64(req->sector);
29062 p.block_id = (unsigned long)req;
29063- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29064+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29065
29066 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29067
29068@@ -3138,7 +3138,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29069 atomic_set(&mdev->unacked_cnt, 0);
29070 atomic_set(&mdev->local_cnt, 0);
29071 atomic_set(&mdev->net_cnt, 0);
29072- atomic_set(&mdev->packet_seq, 0);
29073+ atomic_set_unchecked(&mdev->packet_seq, 0);
29074 atomic_set(&mdev->pp_in_use, 0);
29075 atomic_set(&mdev->pp_in_use_by_net, 0);
29076 atomic_set(&mdev->rs_sect_in, 0);
29077@@ -3220,8 +3220,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29078 mdev->receiver.t_state);
29079
29080 /* no need to lock it, I'm the only thread alive */
29081- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29082- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29083+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29084+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29085 mdev->al_writ_cnt =
29086 mdev->bm_writ_cnt =
29087 mdev->read_cnt =
29088diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29089index 6d4de6a..7b7ad4b 100644
29090--- a/drivers/block/drbd/drbd_nl.c
29091+++ b/drivers/block/drbd/drbd_nl.c
29092@@ -2387,7 +2387,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29093 module_put(THIS_MODULE);
29094 }
29095
29096-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29097+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29098
29099 static unsigned short *
29100 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29101@@ -2458,7 +2458,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29102 cn_reply->id.idx = CN_IDX_DRBD;
29103 cn_reply->id.val = CN_VAL_DRBD;
29104
29105- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29106+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29107 cn_reply->ack = 0; /* not used here. */
29108 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29109 (int)((char *)tl - (char *)reply->tag_list);
29110@@ -2490,7 +2490,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29111 cn_reply->id.idx = CN_IDX_DRBD;
29112 cn_reply->id.val = CN_VAL_DRBD;
29113
29114- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29115+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29116 cn_reply->ack = 0; /* not used here. */
29117 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29118 (int)((char *)tl - (char *)reply->tag_list);
29119@@ -2568,7 +2568,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29120 cn_reply->id.idx = CN_IDX_DRBD;
29121 cn_reply->id.val = CN_VAL_DRBD;
29122
29123- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29124+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29125 cn_reply->ack = 0; // not used here.
29126 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29127 (int)((char*)tl - (char*)reply->tag_list);
29128@@ -2607,7 +2607,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29129 cn_reply->id.idx = CN_IDX_DRBD;
29130 cn_reply->id.val = CN_VAL_DRBD;
29131
29132- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29133+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29134 cn_reply->ack = 0; /* not used here. */
29135 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29136 (int)((char *)tl - (char *)reply->tag_list);
29137diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29138index ea4836e..272d72a 100644
29139--- a/drivers/block/drbd/drbd_receiver.c
29140+++ b/drivers/block/drbd/drbd_receiver.c
29141@@ -893,7 +893,7 @@ retry:
29142 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29143 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29144
29145- atomic_set(&mdev->packet_seq, 0);
29146+ atomic_set_unchecked(&mdev->packet_seq, 0);
29147 mdev->peer_seq = 0;
29148
29149 if (drbd_send_protocol(mdev) == -1)
29150@@ -994,7 +994,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29151 do {
29152 next_epoch = NULL;
29153
29154- epoch_size = atomic_read(&epoch->epoch_size);
29155+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29156
29157 switch (ev & ~EV_CLEANUP) {
29158 case EV_PUT:
29159@@ -1030,7 +1030,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29160 rv = FE_DESTROYED;
29161 } else {
29162 epoch->flags = 0;
29163- atomic_set(&epoch->epoch_size, 0);
29164+ atomic_set_unchecked(&epoch->epoch_size, 0);
29165 /* atomic_set(&epoch->active, 0); is already zero */
29166 if (rv == FE_STILL_LIVE)
29167 rv = FE_RECYCLED;
29168@@ -1205,14 +1205,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29169 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29170 drbd_flush(mdev);
29171
29172- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29173+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29174 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29175 if (epoch)
29176 break;
29177 }
29178
29179 epoch = mdev->current_epoch;
29180- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29181+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29182
29183 D_ASSERT(atomic_read(&epoch->active) == 0);
29184 D_ASSERT(epoch->flags == 0);
29185@@ -1224,11 +1224,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29186 }
29187
29188 epoch->flags = 0;
29189- atomic_set(&epoch->epoch_size, 0);
29190+ atomic_set_unchecked(&epoch->epoch_size, 0);
29191 atomic_set(&epoch->active, 0);
29192
29193 spin_lock(&mdev->epoch_lock);
29194- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29195+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29196 list_add(&epoch->list, &mdev->current_epoch->list);
29197 mdev->current_epoch = epoch;
29198 mdev->epochs++;
29199@@ -1695,7 +1695,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29200 spin_unlock(&mdev->peer_seq_lock);
29201
29202 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29203- atomic_inc(&mdev->current_epoch->epoch_size);
29204+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29205 return drbd_drain_block(mdev, data_size);
29206 }
29207
29208@@ -1721,7 +1721,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29209
29210 spin_lock(&mdev->epoch_lock);
29211 e->epoch = mdev->current_epoch;
29212- atomic_inc(&e->epoch->epoch_size);
29213+ atomic_inc_unchecked(&e->epoch->epoch_size);
29214 atomic_inc(&e->epoch->active);
29215 spin_unlock(&mdev->epoch_lock);
29216
29217@@ -3936,7 +3936,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29218 D_ASSERT(list_empty(&mdev->done_ee));
29219
29220 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29221- atomic_set(&mdev->current_epoch->epoch_size, 0);
29222+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29223 D_ASSERT(list_empty(&mdev->current_epoch->list));
29224 }
29225
29226diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29227index 3bba655..6151b66 100644
29228--- a/drivers/block/loop.c
29229+++ b/drivers/block/loop.c
29230@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29231 mm_segment_t old_fs = get_fs();
29232
29233 set_fs(get_ds());
29234- bw = file->f_op->write(file, buf, len, &pos);
29235+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29236 set_fs(old_fs);
29237 if (likely(bw == len))
29238 return 0;
29239diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29240index ea6f632..eafb192 100644
29241--- a/drivers/char/Kconfig
29242+++ b/drivers/char/Kconfig
29243@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29244
29245 config DEVKMEM
29246 bool "/dev/kmem virtual device support"
29247- default y
29248+ default n
29249+ depends on !GRKERNSEC_KMEM
29250 help
29251 Say Y here if you want to support the /dev/kmem device. The
29252 /dev/kmem device is rarely used, but can be used for certain
29253@@ -581,6 +582,7 @@ config DEVPORT
29254 bool
29255 depends on !M68K
29256 depends on ISA || PCI
29257+ depends on !GRKERNSEC_KMEM
29258 default y
29259
29260 source "drivers/s390/char/Kconfig"
29261diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29262index 2e04433..22afc64 100644
29263--- a/drivers/char/agp/frontend.c
29264+++ b/drivers/char/agp/frontend.c
29265@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29266 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29267 return -EFAULT;
29268
29269- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29270+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29271 return -EFAULT;
29272
29273 client = agp_find_client_by_pid(reserve.pid);
29274diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29275index 21cb980..f15107c 100644
29276--- a/drivers/char/genrtc.c
29277+++ b/drivers/char/genrtc.c
29278@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29279 switch (cmd) {
29280
29281 case RTC_PLL_GET:
29282+ memset(&pll, 0, sizeof(pll));
29283 if (get_rtc_pll(&pll))
29284 return -EINVAL;
29285 else
29286diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29287index dfd7876..c0b0885 100644
29288--- a/drivers/char/hpet.c
29289+++ b/drivers/char/hpet.c
29290@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29291 }
29292
29293 static int
29294-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29295+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29296 struct hpet_info *info)
29297 {
29298 struct hpet_timer __iomem *timer;
29299diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29300index 2c29942..604c5ba 100644
29301--- a/drivers/char/ipmi/ipmi_msghandler.c
29302+++ b/drivers/char/ipmi/ipmi_msghandler.c
29303@@ -420,7 +420,7 @@ struct ipmi_smi {
29304 struct proc_dir_entry *proc_dir;
29305 char proc_dir_name[10];
29306
29307- atomic_t stats[IPMI_NUM_STATS];
29308+ atomic_unchecked_t stats[IPMI_NUM_STATS];
29309
29310 /*
29311 * run_to_completion duplicate of smb_info, smi_info
29312@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29313
29314
29315 #define ipmi_inc_stat(intf, stat) \
29316- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29317+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29318 #define ipmi_get_stat(intf, stat) \
29319- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29320+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29321
29322 static int is_lan_addr(struct ipmi_addr *addr)
29323 {
29324@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29325 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29326 init_waitqueue_head(&intf->waitq);
29327 for (i = 0; i < IPMI_NUM_STATS; i++)
29328- atomic_set(&intf->stats[i], 0);
29329+ atomic_set_unchecked(&intf->stats[i], 0);
29330
29331 intf->proc_dir = NULL;
29332
29333diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29334index 1e638ff..a869ef5 100644
29335--- a/drivers/char/ipmi/ipmi_si_intf.c
29336+++ b/drivers/char/ipmi/ipmi_si_intf.c
29337@@ -275,7 +275,7 @@ struct smi_info {
29338 unsigned char slave_addr;
29339
29340 /* Counters and things for the proc filesystem. */
29341- atomic_t stats[SI_NUM_STATS];
29342+ atomic_unchecked_t stats[SI_NUM_STATS];
29343
29344 struct task_struct *thread;
29345
29346@@ -284,9 +284,9 @@ struct smi_info {
29347 };
29348
29349 #define smi_inc_stat(smi, stat) \
29350- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29351+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29352 #define smi_get_stat(smi, stat) \
29353- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29354+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29355
29356 #define SI_MAX_PARMS 4
29357
29358@@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29359 atomic_set(&new_smi->req_events, 0);
29360 new_smi->run_to_completion = 0;
29361 for (i = 0; i < SI_NUM_STATS; i++)
29362- atomic_set(&new_smi->stats[i], 0);
29363+ atomic_set_unchecked(&new_smi->stats[i], 0);
29364
29365 new_smi->interrupt_disabled = 1;
29366 atomic_set(&new_smi->stop_operation, 0);
29367diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29368index 47ff7e4..0c7d340 100644
29369--- a/drivers/char/mbcs.c
29370+++ b/drivers/char/mbcs.c
29371@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29372 return 0;
29373 }
29374
29375-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29376+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29377 {
29378 .part_num = MBCS_PART_NUM,
29379 .mfg_num = MBCS_MFG_NUM,
29380diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29381index 67c3371..ba8429d 100644
29382--- a/drivers/char/mem.c
29383+++ b/drivers/char/mem.c
29384@@ -18,6 +18,7 @@
29385 #include <linux/raw.h>
29386 #include <linux/tty.h>
29387 #include <linux/capability.h>
29388+#include <linux/security.h>
29389 #include <linux/ptrace.h>
29390 #include <linux/device.h>
29391 #include <linux/highmem.h>
29392@@ -35,6 +36,10 @@
29393 # include <linux/efi.h>
29394 #endif
29395
29396+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29397+extern const struct file_operations grsec_fops;
29398+#endif
29399+
29400 static inline unsigned long size_inside_page(unsigned long start,
29401 unsigned long size)
29402 {
29403@@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29404
29405 while (cursor < to) {
29406 if (!devmem_is_allowed(pfn)) {
29407+#ifdef CONFIG_GRKERNSEC_KMEM
29408+ gr_handle_mem_readwrite(from, to);
29409+#else
29410 printk(KERN_INFO
29411 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29412 current->comm, from, to);
29413+#endif
29414 return 0;
29415 }
29416 cursor += PAGE_SIZE;
29417@@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29418 }
29419 return 1;
29420 }
29421+#elif defined(CONFIG_GRKERNSEC_KMEM)
29422+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29423+{
29424+ return 0;
29425+}
29426 #else
29427 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29428 {
29429@@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29430
29431 while (count > 0) {
29432 unsigned long remaining;
29433+ char *temp;
29434
29435 sz = size_inside_page(p, count);
29436
29437@@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29438 if (!ptr)
29439 return -EFAULT;
29440
29441- remaining = copy_to_user(buf, ptr, sz);
29442+#ifdef CONFIG_PAX_USERCOPY
29443+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29444+ if (!temp) {
29445+ unxlate_dev_mem_ptr(p, ptr);
29446+ return -ENOMEM;
29447+ }
29448+ memcpy(temp, ptr, sz);
29449+#else
29450+ temp = ptr;
29451+#endif
29452+
29453+ remaining = copy_to_user(buf, temp, sz);
29454+
29455+#ifdef CONFIG_PAX_USERCOPY
29456+ kfree(temp);
29457+#endif
29458+
29459 unxlate_dev_mem_ptr(p, ptr);
29460 if (remaining)
29461 return -EFAULT;
29462@@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29463 size_t count, loff_t *ppos)
29464 {
29465 unsigned long p = *ppos;
29466- ssize_t low_count, read, sz;
29467+ ssize_t low_count, read, sz, err = 0;
29468 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29469- int err = 0;
29470
29471 read = 0;
29472 if (p < (unsigned long) high_memory) {
29473@@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29474 }
29475 #endif
29476 while (low_count > 0) {
29477+ char *temp;
29478+
29479 sz = size_inside_page(p, low_count);
29480
29481 /*
29482@@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29483 */
29484 kbuf = xlate_dev_kmem_ptr((char *)p);
29485
29486- if (copy_to_user(buf, kbuf, sz))
29487+#ifdef CONFIG_PAX_USERCOPY
29488+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29489+ if (!temp)
29490+ return -ENOMEM;
29491+ memcpy(temp, kbuf, sz);
29492+#else
29493+ temp = kbuf;
29494+#endif
29495+
29496+ err = copy_to_user(buf, temp, sz);
29497+
29498+#ifdef CONFIG_PAX_USERCOPY
29499+ kfree(temp);
29500+#endif
29501+
29502+ if (err)
29503 return -EFAULT;
29504 buf += sz;
29505 p += sz;
29506@@ -831,6 +878,9 @@ static const struct memdev {
29507 #ifdef CONFIG_CRASH_DUMP
29508 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29509 #endif
29510+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29511+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29512+#endif
29513 };
29514
29515 static int memory_open(struct inode *inode, struct file *filp)
29516diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29517index 9df78e2..01ba9ae 100644
29518--- a/drivers/char/nvram.c
29519+++ b/drivers/char/nvram.c
29520@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29521
29522 spin_unlock_irq(&rtc_lock);
29523
29524- if (copy_to_user(buf, contents, tmp - contents))
29525+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29526 return -EFAULT;
29527
29528 *ppos = i;
29529diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29530index 0a484b4..f48ccd1 100644
29531--- a/drivers/char/pcmcia/synclink_cs.c
29532+++ b/drivers/char/pcmcia/synclink_cs.c
29533@@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29534
29535 if (debug_level >= DEBUG_LEVEL_INFO)
29536 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29537- __FILE__,__LINE__, info->device_name, port->count);
29538+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29539
29540- WARN_ON(!port->count);
29541+ WARN_ON(!atomic_read(&port->count));
29542
29543 if (tty_port_close_start(port, tty, filp) == 0)
29544 goto cleanup;
29545@@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29546 cleanup:
29547 if (debug_level >= DEBUG_LEVEL_INFO)
29548 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29549- tty->driver->name, port->count);
29550+ tty->driver->name, atomic_read(&port->count));
29551 }
29552
29553 /* Wait until the transmitter is empty.
29554@@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29555
29556 if (debug_level >= DEBUG_LEVEL_INFO)
29557 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29558- __FILE__,__LINE__,tty->driver->name, port->count);
29559+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29560
29561 /* If port is closing, signal caller to try again */
29562 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29563@@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29564 goto cleanup;
29565 }
29566 spin_lock(&port->lock);
29567- port->count++;
29568+ atomic_inc(&port->count);
29569 spin_unlock(&port->lock);
29570 spin_unlock_irqrestore(&info->netlock, flags);
29571
29572- if (port->count == 1) {
29573+ if (atomic_read(&port->count) == 1) {
29574 /* 1st open on this device, init hardware */
29575 retval = startup(info, tty);
29576 if (retval < 0)
29577@@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29578 unsigned short new_crctype;
29579
29580 /* return error if TTY interface open */
29581- if (info->port.count)
29582+ if (atomic_read(&info->port.count))
29583 return -EBUSY;
29584
29585 switch (encoding)
29586@@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29587
29588 /* arbitrate between network and tty opens */
29589 spin_lock_irqsave(&info->netlock, flags);
29590- if (info->port.count != 0 || info->netcount != 0) {
29591+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29592 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29593 spin_unlock_irqrestore(&info->netlock, flags);
29594 return -EBUSY;
29595@@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29596 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29597
29598 /* return error if TTY interface open */
29599- if (info->port.count)
29600+ if (atomic_read(&info->port.count))
29601 return -EBUSY;
29602
29603 if (cmd != SIOCWANDEV)
29604diff --git a/drivers/char/random.c b/drivers/char/random.c
29605index 4ec04a7..9918387 100644
29606--- a/drivers/char/random.c
29607+++ b/drivers/char/random.c
29608@@ -261,8 +261,13 @@
29609 /*
29610 * Configuration information
29611 */
29612+#ifdef CONFIG_GRKERNSEC_RANDNET
29613+#define INPUT_POOL_WORDS 512
29614+#define OUTPUT_POOL_WORDS 128
29615+#else
29616 #define INPUT_POOL_WORDS 128
29617 #define OUTPUT_POOL_WORDS 32
29618+#endif
29619 #define SEC_XFER_SIZE 512
29620 #define EXTRACT_SIZE 10
29621
29622@@ -300,10 +305,17 @@ static struct poolinfo {
29623 int poolwords;
29624 int tap1, tap2, tap3, tap4, tap5;
29625 } poolinfo_table[] = {
29626+#ifdef CONFIG_GRKERNSEC_RANDNET
29627+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29628+ { 512, 411, 308, 208, 104, 1 },
29629+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29630+ { 128, 103, 76, 51, 25, 1 },
29631+#else
29632 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29633 { 128, 103, 76, 51, 25, 1 },
29634 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29635 { 32, 26, 20, 14, 7, 1 },
29636+#endif
29637 #if 0
29638 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29639 { 2048, 1638, 1231, 819, 411, 1 },
29640@@ -726,6 +738,17 @@ void add_disk_randomness(struct gendisk *disk)
29641 }
29642 #endif
29643
29644+#ifdef CONFIG_PAX_LATENT_ENTROPY
29645+u64 latent_entropy;
29646+
29647+__init void transfer_latent_entropy(void)
29648+{
29649+ mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy));
29650+ mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy));
29651+// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29652+}
29653+#endif
29654+
29655 /*********************************************************************
29656 *
29657 * Entropy extraction routines
29658@@ -913,7 +936,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29659
29660 extract_buf(r, tmp);
29661 i = min_t(int, nbytes, EXTRACT_SIZE);
29662- if (copy_to_user(buf, tmp, i)) {
29663+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29664 ret = -EFAULT;
29665 break;
29666 }
29667@@ -1238,7 +1261,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29668 #include <linux/sysctl.h>
29669
29670 static int min_read_thresh = 8, min_write_thresh;
29671-static int max_read_thresh = INPUT_POOL_WORDS * 32;
29672+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29673 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29674 static char sysctl_bootid[16];
29675
29676diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29677index 45713f0..8286d21 100644
29678--- a/drivers/char/sonypi.c
29679+++ b/drivers/char/sonypi.c
29680@@ -54,6 +54,7 @@
29681
29682 #include <asm/uaccess.h>
29683 #include <asm/io.h>
29684+#include <asm/local.h>
29685
29686 #include <linux/sonypi.h>
29687
29688@@ -490,7 +491,7 @@ static struct sonypi_device {
29689 spinlock_t fifo_lock;
29690 wait_queue_head_t fifo_proc_list;
29691 struct fasync_struct *fifo_async;
29692- int open_count;
29693+ local_t open_count;
29694 int model;
29695 struct input_dev *input_jog_dev;
29696 struct input_dev *input_key_dev;
29697@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29698 static int sonypi_misc_release(struct inode *inode, struct file *file)
29699 {
29700 mutex_lock(&sonypi_device.lock);
29701- sonypi_device.open_count--;
29702+ local_dec(&sonypi_device.open_count);
29703 mutex_unlock(&sonypi_device.lock);
29704 return 0;
29705 }
29706@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29707 {
29708 mutex_lock(&sonypi_device.lock);
29709 /* Flush input queue on first open */
29710- if (!sonypi_device.open_count)
29711+ if (!local_read(&sonypi_device.open_count))
29712 kfifo_reset(&sonypi_device.fifo);
29713- sonypi_device.open_count++;
29714+ local_inc(&sonypi_device.open_count);
29715 mutex_unlock(&sonypi_device.lock);
29716
29717 return 0;
29718diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29719index ad7c732..5aa8054 100644
29720--- a/drivers/char/tpm/tpm.c
29721+++ b/drivers/char/tpm/tpm.c
29722@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29723 chip->vendor.req_complete_val)
29724 goto out_recv;
29725
29726- if ((status == chip->vendor.req_canceled)) {
29727+ if (status == chip->vendor.req_canceled) {
29728 dev_err(chip->dev, "Operation Canceled\n");
29729 rc = -ECANCELED;
29730 goto out;
29731diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29732index 0636520..169c1d0 100644
29733--- a/drivers/char/tpm/tpm_bios.c
29734+++ b/drivers/char/tpm/tpm_bios.c
29735@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29736 event = addr;
29737
29738 if ((event->event_type == 0 && event->event_size == 0) ||
29739- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29740+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29741 return NULL;
29742
29743 return addr;
29744@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29745 return NULL;
29746
29747 if ((event->event_type == 0 && event->event_size == 0) ||
29748- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29749+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29750 return NULL;
29751
29752 (*pos)++;
29753@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29754 int i;
29755
29756 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29757- seq_putc(m, data[i]);
29758+ if (!seq_putc(m, data[i]))
29759+ return -EFAULT;
29760
29761 return 0;
29762 }
29763@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29764 log->bios_event_log_end = log->bios_event_log + len;
29765
29766 virt = acpi_os_map_memory(start, len);
29767+ if (!virt) {
29768+ kfree(log->bios_event_log);
29769+ log->bios_event_log = NULL;
29770+ return -EFAULT;
29771+ }
29772
29773- memcpy(log->bios_event_log, virt, len);
29774+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29775
29776 acpi_os_unmap_memory(virt, len);
29777 return 0;
29778diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29779index cdf2f54..e55c197 100644
29780--- a/drivers/char/virtio_console.c
29781+++ b/drivers/char/virtio_console.c
29782@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29783 if (to_user) {
29784 ssize_t ret;
29785
29786- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29787+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29788 if (ret)
29789 return -EFAULT;
29790 } else {
29791@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29792 if (!port_has_data(port) && !port->host_connected)
29793 return 0;
29794
29795- return fill_readbuf(port, ubuf, count, true);
29796+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29797 }
29798
29799 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29800diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29801index 97f5064..202b6e6 100644
29802--- a/drivers/edac/edac_pci_sysfs.c
29803+++ b/drivers/edac/edac_pci_sysfs.c
29804@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29805 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29806 static int edac_pci_poll_msec = 1000; /* one second workq period */
29807
29808-static atomic_t pci_parity_count = ATOMIC_INIT(0);
29809-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29810+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29811+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29812
29813 static struct kobject *edac_pci_top_main_kobj;
29814 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29815@@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29816 edac_printk(KERN_CRIT, EDAC_PCI,
29817 "Signaled System Error on %s\n",
29818 pci_name(dev));
29819- atomic_inc(&pci_nonparity_count);
29820+ atomic_inc_unchecked(&pci_nonparity_count);
29821 }
29822
29823 if (status & (PCI_STATUS_PARITY)) {
29824@@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29825 "Master Data Parity Error on %s\n",
29826 pci_name(dev));
29827
29828- atomic_inc(&pci_parity_count);
29829+ atomic_inc_unchecked(&pci_parity_count);
29830 }
29831
29832 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29833@@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29834 "Detected Parity Error on %s\n",
29835 pci_name(dev));
29836
29837- atomic_inc(&pci_parity_count);
29838+ atomic_inc_unchecked(&pci_parity_count);
29839 }
29840 }
29841
29842@@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29843 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29844 "Signaled System Error on %s\n",
29845 pci_name(dev));
29846- atomic_inc(&pci_nonparity_count);
29847+ atomic_inc_unchecked(&pci_nonparity_count);
29848 }
29849
29850 if (status & (PCI_STATUS_PARITY)) {
29851@@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29852 "Master Data Parity Error on "
29853 "%s\n", pci_name(dev));
29854
29855- atomic_inc(&pci_parity_count);
29856+ atomic_inc_unchecked(&pci_parity_count);
29857 }
29858
29859 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29860@@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29861 "Detected Parity Error on %s\n",
29862 pci_name(dev));
29863
29864- atomic_inc(&pci_parity_count);
29865+ atomic_inc_unchecked(&pci_parity_count);
29866 }
29867 }
29868 }
29869@@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29870 if (!check_pci_errors)
29871 return;
29872
29873- before_count = atomic_read(&pci_parity_count);
29874+ before_count = atomic_read_unchecked(&pci_parity_count);
29875
29876 /* scan all PCI devices looking for a Parity Error on devices and
29877 * bridges.
29878@@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29879 /* Only if operator has selected panic on PCI Error */
29880 if (edac_pci_get_panic_on_pe()) {
29881 /* If the count is different 'after' from 'before' */
29882- if (before_count != atomic_read(&pci_parity_count))
29883+ if (before_count != atomic_read_unchecked(&pci_parity_count))
29884 panic("EDAC: PCI Parity Error");
29885 }
29886 }
29887diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29888index 8c87a5e..a19cbd7 100644
29889--- a/drivers/edac/mce_amd.h
29890+++ b/drivers/edac/mce_amd.h
29891@@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
29892 struct amd_decoder_ops {
29893 bool (*dc_mce)(u16, u8);
29894 bool (*ic_mce)(u16, u8);
29895-};
29896+} __no_const;
29897
29898 void amd_report_gart_errors(bool);
29899 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29900diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29901index 57ea7f4..789e3c3 100644
29902--- a/drivers/firewire/core-card.c
29903+++ b/drivers/firewire/core-card.c
29904@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
29905
29906 void fw_core_remove_card(struct fw_card *card)
29907 {
29908- struct fw_card_driver dummy_driver = dummy_driver_template;
29909+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
29910
29911 card->driver->update_phy_reg(card, 4,
29912 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29913diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29914index 2783f69..9f4b0cc 100644
29915--- a/drivers/firewire/core-cdev.c
29916+++ b/drivers/firewire/core-cdev.c
29917@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
29918 int ret;
29919
29920 if ((request->channels == 0 && request->bandwidth == 0) ||
29921- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29922- request->bandwidth < 0)
29923+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29924 return -EINVAL;
29925
29926 r = kmalloc(sizeof(*r), GFP_KERNEL);
29927diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29928index 780708d..ad60a66 100644
29929--- a/drivers/firewire/core-transaction.c
29930+++ b/drivers/firewire/core-transaction.c
29931@@ -37,6 +37,7 @@
29932 #include <linux/timer.h>
29933 #include <linux/types.h>
29934 #include <linux/workqueue.h>
29935+#include <linux/sched.h>
29936
29937 #include <asm/byteorder.h>
29938
29939diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29940index 515a42c..5ecf3ba 100644
29941--- a/drivers/firewire/core.h
29942+++ b/drivers/firewire/core.h
29943@@ -111,6 +111,7 @@ struct fw_card_driver {
29944
29945 int (*stop_iso)(struct fw_iso_context *ctx);
29946 };
29947+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29948
29949 void fw_card_initialize(struct fw_card *card,
29950 const struct fw_card_driver *driver, struct device *device);
29951diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29952index 153980b..4b4d046 100644
29953--- a/drivers/firmware/dmi_scan.c
29954+++ b/drivers/firmware/dmi_scan.c
29955@@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29956 }
29957 }
29958 else {
29959- /*
29960- * no iounmap() for that ioremap(); it would be a no-op, but
29961- * it's so early in setup that sucker gets confused into doing
29962- * what it shouldn't if we actually call it.
29963- */
29964 p = dmi_ioremap(0xF0000, 0x10000);
29965 if (p == NULL)
29966 goto error;
29967@@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29968 if (buf == NULL)
29969 return -1;
29970
29971- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29972+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29973
29974 iounmap(buf);
29975 return 0;
29976diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29977index 82d5c20..44a7177 100644
29978--- a/drivers/gpio/gpio-vr41xx.c
29979+++ b/drivers/gpio/gpio-vr41xx.c
29980@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
29981 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
29982 maskl, pendl, maskh, pendh);
29983
29984- atomic_inc(&irq_err_count);
29985+ atomic_inc_unchecked(&irq_err_count);
29986
29987 return -EINVAL;
29988 }
29989diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
29990index 3252e70..b5314ace 100644
29991--- a/drivers/gpu/drm/drm_crtc_helper.c
29992+++ b/drivers/gpu/drm/drm_crtc_helper.c
29993@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
29994 struct drm_crtc *tmp;
29995 int crtc_mask = 1;
29996
29997- WARN(!crtc, "checking null crtc?\n");
29998+ BUG_ON(!crtc);
29999
30000 dev = crtc->dev;
30001
30002diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30003index 8a9d079..606cdd5 100644
30004--- a/drivers/gpu/drm/drm_drv.c
30005+++ b/drivers/gpu/drm/drm_drv.c
30006@@ -318,7 +318,7 @@ module_exit(drm_core_exit);
30007 /**
30008 * Copy and IOCTL return string to user space
30009 */
30010-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30011+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30012 {
30013 int len;
30014
30015@@ -401,7 +401,7 @@ long drm_ioctl(struct file *filp,
30016 return -ENODEV;
30017
30018 atomic_inc(&dev->ioctl_count);
30019- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30020+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30021 ++file_priv->ioctl_count;
30022
30023 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30024diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30025index 123de28..43a0897 100644
30026--- a/drivers/gpu/drm/drm_fops.c
30027+++ b/drivers/gpu/drm/drm_fops.c
30028@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30029 }
30030
30031 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30032- atomic_set(&dev->counts[i], 0);
30033+ atomic_set_unchecked(&dev->counts[i], 0);
30034
30035 dev->sigdata.lock = NULL;
30036
30037@@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30038
30039 retcode = drm_open_helper(inode, filp, dev);
30040 if (!retcode) {
30041- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30042- if (!dev->open_count++)
30043+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30044+ if (local_inc_return(&dev->open_count) == 1)
30045 retcode = drm_setup(dev);
30046 }
30047 if (!retcode) {
30048@@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30049
30050 mutex_lock(&drm_global_mutex);
30051
30052- DRM_DEBUG("open_count = %d\n", dev->open_count);
30053+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30054
30055 if (dev->driver->preclose)
30056 dev->driver->preclose(dev, file_priv);
30057@@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30058 * Begin inline drm_release
30059 */
30060
30061- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30062+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30063 task_pid_nr(current),
30064 (long)old_encode_dev(file_priv->minor->device),
30065- dev->open_count);
30066+ local_read(&dev->open_count));
30067
30068 /* Release any auth tokens that might point to this file_priv,
30069 (do that under the drm_global_mutex) */
30070@@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30071 * End inline drm_release
30072 */
30073
30074- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30075- if (!--dev->open_count) {
30076+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30077+ if (local_dec_and_test(&dev->open_count)) {
30078 if (atomic_read(&dev->ioctl_count)) {
30079 DRM_ERROR("Device busy: %d\n",
30080 atomic_read(&dev->ioctl_count));
30081diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30082index c87dc96..326055d 100644
30083--- a/drivers/gpu/drm/drm_global.c
30084+++ b/drivers/gpu/drm/drm_global.c
30085@@ -36,7 +36,7 @@
30086 struct drm_global_item {
30087 struct mutex mutex;
30088 void *object;
30089- int refcount;
30090+ atomic_t refcount;
30091 };
30092
30093 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30094@@ -49,7 +49,7 @@ void drm_global_init(void)
30095 struct drm_global_item *item = &glob[i];
30096 mutex_init(&item->mutex);
30097 item->object = NULL;
30098- item->refcount = 0;
30099+ atomic_set(&item->refcount, 0);
30100 }
30101 }
30102
30103@@ -59,7 +59,7 @@ void drm_global_release(void)
30104 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30105 struct drm_global_item *item = &glob[i];
30106 BUG_ON(item->object != NULL);
30107- BUG_ON(item->refcount != 0);
30108+ BUG_ON(atomic_read(&item->refcount) != 0);
30109 }
30110 }
30111
30112@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30113 void *object;
30114
30115 mutex_lock(&item->mutex);
30116- if (item->refcount == 0) {
30117+ if (atomic_read(&item->refcount) == 0) {
30118 item->object = kzalloc(ref->size, GFP_KERNEL);
30119 if (unlikely(item->object == NULL)) {
30120 ret = -ENOMEM;
30121@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30122 goto out_err;
30123
30124 }
30125- ++item->refcount;
30126+ atomic_inc(&item->refcount);
30127 ref->object = item->object;
30128 object = item->object;
30129 mutex_unlock(&item->mutex);
30130@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30131 struct drm_global_item *item = &glob[ref->global_type];
30132
30133 mutex_lock(&item->mutex);
30134- BUG_ON(item->refcount == 0);
30135+ BUG_ON(atomic_read(&item->refcount) == 0);
30136 BUG_ON(ref->object != item->object);
30137- if (--item->refcount == 0) {
30138+ if (atomic_dec_and_test(&item->refcount)) {
30139 ref->release(ref);
30140 item->object = NULL;
30141 }
30142diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30143index ab1162d..42587b2 100644
30144--- a/drivers/gpu/drm/drm_info.c
30145+++ b/drivers/gpu/drm/drm_info.c
30146@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30147 struct drm_local_map *map;
30148 struct drm_map_list *r_list;
30149
30150- /* Hardcoded from _DRM_FRAME_BUFFER,
30151- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30152- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30153- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30154+ static const char * const types[] = {
30155+ [_DRM_FRAME_BUFFER] = "FB",
30156+ [_DRM_REGISTERS] = "REG",
30157+ [_DRM_SHM] = "SHM",
30158+ [_DRM_AGP] = "AGP",
30159+ [_DRM_SCATTER_GATHER] = "SG",
30160+ [_DRM_CONSISTENT] = "PCI",
30161+ [_DRM_GEM] = "GEM" };
30162 const char *type;
30163 int i;
30164
30165@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30166 map = r_list->map;
30167 if (!map)
30168 continue;
30169- if (map->type < 0 || map->type > 5)
30170+ if (map->type >= ARRAY_SIZE(types))
30171 type = "??";
30172 else
30173 type = types[map->type];
30174@@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30175 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30176 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30177 vma->vm_flags & VM_IO ? 'i' : '-',
30178+#ifdef CONFIG_GRKERNSEC_HIDESYM
30179+ 0);
30180+#else
30181 vma->vm_pgoff);
30182+#endif
30183
30184 #if defined(__i386__)
30185 pgprot = pgprot_val(vma->vm_page_prot);
30186diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30187index 637fcc3..e890b33 100644
30188--- a/drivers/gpu/drm/drm_ioc32.c
30189+++ b/drivers/gpu/drm/drm_ioc32.c
30190@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30191 request = compat_alloc_user_space(nbytes);
30192 if (!access_ok(VERIFY_WRITE, request, nbytes))
30193 return -EFAULT;
30194- list = (struct drm_buf_desc *) (request + 1);
30195+ list = (struct drm_buf_desc __user *) (request + 1);
30196
30197 if (__put_user(count, &request->count)
30198 || __put_user(list, &request->list))
30199@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30200 request = compat_alloc_user_space(nbytes);
30201 if (!access_ok(VERIFY_WRITE, request, nbytes))
30202 return -EFAULT;
30203- list = (struct drm_buf_pub *) (request + 1);
30204+ list = (struct drm_buf_pub __user *) (request + 1);
30205
30206 if (__put_user(count, &request->count)
30207 || __put_user(list, &request->list))
30208diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30209index 64a62c6..ceab35e 100644
30210--- a/drivers/gpu/drm/drm_ioctl.c
30211+++ b/drivers/gpu/drm/drm_ioctl.c
30212@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30213 stats->data[i].value =
30214 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30215 else
30216- stats->data[i].value = atomic_read(&dev->counts[i]);
30217+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30218 stats->data[i].type = dev->types[i];
30219 }
30220
30221diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30222index 5211520..c744d85 100644
30223--- a/drivers/gpu/drm/drm_lock.c
30224+++ b/drivers/gpu/drm/drm_lock.c
30225@@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30226 if (drm_lock_take(&master->lock, lock->context)) {
30227 master->lock.file_priv = file_priv;
30228 master->lock.lock_time = jiffies;
30229- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30230+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30231 break; /* Got lock */
30232 }
30233
30234@@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30235 return -EINVAL;
30236 }
30237
30238- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30239+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30240
30241 if (drm_lock_free(&master->lock, lock->context)) {
30242 /* FIXME: Should really bail out here. */
30243diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30244index 21bcd4a..8e074e0 100644
30245--- a/drivers/gpu/drm/drm_stub.c
30246+++ b/drivers/gpu/drm/drm_stub.c
30247@@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30248
30249 drm_device_set_unplugged(dev);
30250
30251- if (dev->open_count == 0) {
30252+ if (local_read(&dev->open_count) == 0) {
30253 drm_put_dev(dev);
30254 }
30255 mutex_unlock(&drm_global_mutex);
30256diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30257index fa94391..ed26ec8 100644
30258--- a/drivers/gpu/drm/i810/i810_dma.c
30259+++ b/drivers/gpu/drm/i810/i810_dma.c
30260@@ -943,8 +943,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30261 dma->buflist[vertex->idx],
30262 vertex->discard, vertex->used);
30263
30264- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30265- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30266+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30267+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30268 sarea_priv->last_enqueue = dev_priv->counter - 1;
30269 sarea_priv->last_dispatch = (int)hw_status[5];
30270
30271@@ -1104,8 +1104,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30272 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30273 mc->last_render);
30274
30275- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30276- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30277+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30278+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30279 sarea_priv->last_enqueue = dev_priv->counter - 1;
30280 sarea_priv->last_dispatch = (int)hw_status[5];
30281
30282diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30283index c9339f4..f5e1b9d 100644
30284--- a/drivers/gpu/drm/i810/i810_drv.h
30285+++ b/drivers/gpu/drm/i810/i810_drv.h
30286@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30287 int page_flipping;
30288
30289 wait_queue_head_t irq_queue;
30290- atomic_t irq_received;
30291- atomic_t irq_emitted;
30292+ atomic_unchecked_t irq_received;
30293+ atomic_unchecked_t irq_emitted;
30294
30295 int front_offset;
30296 } drm_i810_private_t;
30297diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30298index 5363e9c..59360d1 100644
30299--- a/drivers/gpu/drm/i915/i915_debugfs.c
30300+++ b/drivers/gpu/drm/i915/i915_debugfs.c
30301@@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30302 I915_READ(GTIMR));
30303 }
30304 seq_printf(m, "Interrupts received: %d\n",
30305- atomic_read(&dev_priv->irq_received));
30306+ atomic_read_unchecked(&dev_priv->irq_received));
30307 for (i = 0; i < I915_NUM_RINGS; i++) {
30308 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30309 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30310diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30311index 36822b9..b725e1b 100644
30312--- a/drivers/gpu/drm/i915/i915_dma.c
30313+++ b/drivers/gpu/drm/i915/i915_dma.c
30314@@ -1266,7 +1266,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30315 bool can_switch;
30316
30317 spin_lock(&dev->count_lock);
30318- can_switch = (dev->open_count == 0);
30319+ can_switch = (local_read(&dev->open_count) == 0);
30320 spin_unlock(&dev->count_lock);
30321 return can_switch;
30322 }
30323diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30324index b0b676a..d107105 100644
30325--- a/drivers/gpu/drm/i915/i915_drv.h
30326+++ b/drivers/gpu/drm/i915/i915_drv.h
30327@@ -268,7 +268,7 @@ struct drm_i915_display_funcs {
30328 /* render clock increase/decrease */
30329 /* display clock increase/decrease */
30330 /* pll clock increase/decrease */
30331-};
30332+} __no_const;
30333
30334 struct intel_device_info {
30335 u8 gen;
30336@@ -386,7 +386,7 @@ typedef struct drm_i915_private {
30337 int current_page;
30338 int page_flipping;
30339
30340- atomic_t irq_received;
30341+ atomic_unchecked_t irq_received;
30342
30343 /* protects the irq masks */
30344 spinlock_t irq_lock;
30345@@ -985,7 +985,7 @@ struct drm_i915_gem_object {
30346 * will be page flipped away on the next vblank. When it
30347 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30348 */
30349- atomic_t pending_flip;
30350+ atomic_unchecked_t pending_flip;
30351 };
30352
30353 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30354@@ -1434,7 +1434,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30355 struct drm_i915_private *dev_priv, unsigned port);
30356 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30357 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30358-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30359+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30360 {
30361 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30362 }
30363diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30364index 974a9f1..b3ebd45 100644
30365--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30366+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30367@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30368 i915_gem_clflush_object(obj);
30369
30370 if (obj->base.pending_write_domain)
30371- cd->flips |= atomic_read(&obj->pending_flip);
30372+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30373
30374 /* The actual obj->write_domain will be updated with
30375 * pending_write_domain after we emit the accumulated flush for all
30376@@ -916,9 +916,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30377
30378 static int
30379 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30380- int count)
30381+ unsigned int count)
30382 {
30383- int i;
30384+ unsigned int i;
30385
30386 for (i = 0; i < count; i++) {
30387 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30388diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30389index ed3224c..6618589 100644
30390--- a/drivers/gpu/drm/i915/i915_irq.c
30391+++ b/drivers/gpu/drm/i915/i915_irq.c
30392@@ -433,7 +433,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30393 int vblank = 0;
30394 bool blc_event;
30395
30396- atomic_inc(&dev_priv->irq_received);
30397+ atomic_inc_unchecked(&dev_priv->irq_received);
30398
30399 vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS |
30400 PIPE_VBLANK_INTERRUPT_STATUS;
30401@@ -586,7 +586,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30402 irqreturn_t ret = IRQ_NONE;
30403 int i;
30404
30405- atomic_inc(&dev_priv->irq_received);
30406+ atomic_inc_unchecked(&dev_priv->irq_received);
30407
30408 /* disable master interrupt before clearing iir */
30409 de_ier = I915_READ(DEIER);
30410@@ -661,7 +661,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30411 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30412 u32 hotplug_mask;
30413
30414- atomic_inc(&dev_priv->irq_received);
30415+ atomic_inc_unchecked(&dev_priv->irq_received);
30416
30417 /* disable master interrupt before clearing iir */
30418 de_ier = I915_READ(DEIER);
30419@@ -1646,7 +1646,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30420 {
30421 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30422
30423- atomic_set(&dev_priv->irq_received, 0);
30424+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30425
30426
30427 I915_WRITE(HWSTAM, 0xeffe);
30428@@ -1673,7 +1673,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30429 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30430 int pipe;
30431
30432- atomic_set(&dev_priv->irq_received, 0);
30433+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30434
30435 /* VLV magic */
30436 I915_WRITE(VLV_IMR, 0);
30437@@ -1969,7 +1969,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30438 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30439 int pipe;
30440
30441- atomic_set(&dev_priv->irq_received, 0);
30442+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30443
30444 for_each_pipe(pipe)
30445 I915_WRITE(PIPESTAT(pipe), 0);
30446@@ -2020,7 +2020,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30447 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30448 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30449
30450- atomic_inc(&dev_priv->irq_received);
30451+ atomic_inc_unchecked(&dev_priv->irq_received);
30452
30453 iir = I915_READ16(IIR);
30454 if (iir == 0)
30455@@ -2105,7 +2105,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30456 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30457 int pipe;
30458
30459- atomic_set(&dev_priv->irq_received, 0);
30460+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30461
30462 if (I915_HAS_HOTPLUG(dev)) {
30463 I915_WRITE(PORT_HOTPLUG_EN, 0);
30464@@ -2200,7 +2200,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30465 };
30466 int pipe, ret = IRQ_NONE;
30467
30468- atomic_inc(&dev_priv->irq_received);
30469+ atomic_inc_unchecked(&dev_priv->irq_received);
30470
30471 iir = I915_READ(IIR);
30472 do {
30473@@ -2326,7 +2326,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30474 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30475 int pipe;
30476
30477- atomic_set(&dev_priv->irq_received, 0);
30478+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30479
30480 if (I915_HAS_HOTPLUG(dev)) {
30481 I915_WRITE(PORT_HOTPLUG_EN, 0);
30482@@ -2436,7 +2436,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30483 int irq_received;
30484 int ret = IRQ_NONE, pipe;
30485
30486- atomic_inc(&dev_priv->irq_received);
30487+ atomic_inc_unchecked(&dev_priv->irq_received);
30488
30489 iir = I915_READ(IIR);
30490
30491diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30492index a8538ac..4868a05 100644
30493--- a/drivers/gpu/drm/i915/intel_display.c
30494+++ b/drivers/gpu/drm/i915/intel_display.c
30495@@ -2000,7 +2000,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30496
30497 wait_event(dev_priv->pending_flip_queue,
30498 atomic_read(&dev_priv->mm.wedged) ||
30499- atomic_read(&obj->pending_flip) == 0);
30500+ atomic_read_unchecked(&obj->pending_flip) == 0);
30501
30502 /* Big Hammer, we also need to ensure that any pending
30503 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30504@@ -5925,9 +5925,8 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30505
30506 obj = work->old_fb_obj;
30507
30508- atomic_clear_mask(1 << intel_crtc->plane,
30509- &obj->pending_flip.counter);
30510- if (atomic_read(&obj->pending_flip) == 0)
30511+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30512+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
30513 wake_up(&dev_priv->pending_flip_queue);
30514
30515 schedule_work(&work->work);
30516@@ -6264,7 +6263,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30517 /* Block clients from rendering to the new back buffer until
30518 * the flip occurs and the object is no longer visible.
30519 */
30520- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30521+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30522
30523 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30524 if (ret)
30525@@ -6279,7 +6278,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30526 return 0;
30527
30528 cleanup_pending:
30529- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30530+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30531 drm_gem_object_unreference(&work->old_fb_obj->base);
30532 drm_gem_object_unreference(&obj->base);
30533 mutex_unlock(&dev->struct_mutex);
30534diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30535index 54558a0..2d97005 100644
30536--- a/drivers/gpu/drm/mga/mga_drv.h
30537+++ b/drivers/gpu/drm/mga/mga_drv.h
30538@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30539 u32 clear_cmd;
30540 u32 maccess;
30541
30542- atomic_t vbl_received; /**< Number of vblanks received. */
30543+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30544 wait_queue_head_t fence_queue;
30545- atomic_t last_fence_retired;
30546+ atomic_unchecked_t last_fence_retired;
30547 u32 next_fence_to_post;
30548
30549 unsigned int fb_cpp;
30550diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30551index 2581202..f230a8d9 100644
30552--- a/drivers/gpu/drm/mga/mga_irq.c
30553+++ b/drivers/gpu/drm/mga/mga_irq.c
30554@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30555 if (crtc != 0)
30556 return 0;
30557
30558- return atomic_read(&dev_priv->vbl_received);
30559+ return atomic_read_unchecked(&dev_priv->vbl_received);
30560 }
30561
30562
30563@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30564 /* VBLANK interrupt */
30565 if (status & MGA_VLINEPEN) {
30566 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30567- atomic_inc(&dev_priv->vbl_received);
30568+ atomic_inc_unchecked(&dev_priv->vbl_received);
30569 drm_handle_vblank(dev, 0);
30570 handled = 1;
30571 }
30572@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30573 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30574 MGA_WRITE(MGA_PRIMEND, prim_end);
30575
30576- atomic_inc(&dev_priv->last_fence_retired);
30577+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
30578 DRM_WAKEUP(&dev_priv->fence_queue);
30579 handled = 1;
30580 }
30581@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30582 * using fences.
30583 */
30584 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30585- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30586+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30587 - *sequence) <= (1 << 23)));
30588
30589 *sequence = cur_fence;
30590diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30591index 2f11e16..191267e 100644
30592--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30593+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30594@@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30595 struct bit_table {
30596 const char id;
30597 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30598-};
30599+} __no_const;
30600
30601 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30602
30603diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30604index 8613cb2..ea038e7 100644
30605--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30606+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30607@@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30608 u32 handle, u16 class);
30609 void (*set_tile_region)(struct drm_device *dev, int i);
30610 void (*tlb_flush)(struct drm_device *, int engine);
30611-};
30612+} __no_const;
30613
30614 struct nouveau_instmem_engine {
30615 void *priv;
30616@@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30617 struct nouveau_mc_engine {
30618 int (*init)(struct drm_device *dev);
30619 void (*takedown)(struct drm_device *dev);
30620-};
30621+} __no_const;
30622
30623 struct nouveau_timer_engine {
30624 int (*init)(struct drm_device *dev);
30625 void (*takedown)(struct drm_device *dev);
30626 uint64_t (*read)(struct drm_device *dev);
30627-};
30628+} __no_const;
30629
30630 struct nouveau_fb_engine {
30631 int num_tiles;
30632@@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30633 void (*put)(struct drm_device *, struct nouveau_mem **);
30634
30635 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30636-};
30637+} __no_const;
30638
30639 struct nouveau_engine {
30640 struct nouveau_instmem_engine instmem;
30641@@ -695,7 +695,7 @@ struct drm_nouveau_private {
30642 struct drm_global_reference mem_global_ref;
30643 struct ttm_bo_global_ref bo_global_ref;
30644 struct ttm_bo_device bdev;
30645- atomic_t validate_sequence;
30646+ atomic_unchecked_t validate_sequence;
30647 int (*move)(struct nouveau_channel *,
30648 struct ttm_buffer_object *,
30649 struct ttm_mem_reg *, struct ttm_mem_reg *);
30650diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30651index 30f5423..abca136 100644
30652--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30653+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30654@@ -319,7 +319,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30655 int trycnt = 0;
30656 int ret, i;
30657
30658- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30659+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30660 retry:
30661 if (++trycnt > 100000) {
30662 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30663diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30664index 19706f0..f257368 100644
30665--- a/drivers/gpu/drm/nouveau/nouveau_state.c
30666+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30667@@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30668 bool can_switch;
30669
30670 spin_lock(&dev->count_lock);
30671- can_switch = (dev->open_count == 0);
30672+ can_switch = (local_read(&dev->open_count) == 0);
30673 spin_unlock(&dev->count_lock);
30674 return can_switch;
30675 }
30676diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30677index a9514ea..369d511 100644
30678--- a/drivers/gpu/drm/nouveau/nv50_sor.c
30679+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30680@@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30681 }
30682
30683 if (nv_encoder->dcb->type == OUTPUT_DP) {
30684- struct dp_train_func func = {
30685+ static struct dp_train_func func = {
30686 .link_set = nv50_sor_dp_link_set,
30687 .train_set = nv50_sor_dp_train_set,
30688 .train_adj = nv50_sor_dp_train_adj
30689diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30690index c486d3c..3a7d6f4 100644
30691--- a/drivers/gpu/drm/nouveau/nvd0_display.c
30692+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30693@@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30694 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30695
30696 if (nv_encoder->dcb->type == OUTPUT_DP) {
30697- struct dp_train_func func = {
30698+ static struct dp_train_func func = {
30699 .link_set = nvd0_sor_dp_link_set,
30700 .train_set = nvd0_sor_dp_train_set,
30701 .train_adj = nvd0_sor_dp_train_adj
30702diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30703index bcac90b..53bfc76 100644
30704--- a/drivers/gpu/drm/r128/r128_cce.c
30705+++ b/drivers/gpu/drm/r128/r128_cce.c
30706@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30707
30708 /* GH: Simple idle check.
30709 */
30710- atomic_set(&dev_priv->idle_count, 0);
30711+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30712
30713 /* We don't support anything other than bus-mastering ring mode,
30714 * but the ring can be in either AGP or PCI space for the ring
30715diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30716index 930c71b..499aded 100644
30717--- a/drivers/gpu/drm/r128/r128_drv.h
30718+++ b/drivers/gpu/drm/r128/r128_drv.h
30719@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30720 int is_pci;
30721 unsigned long cce_buffers_offset;
30722
30723- atomic_t idle_count;
30724+ atomic_unchecked_t idle_count;
30725
30726 int page_flipping;
30727 int current_page;
30728 u32 crtc_offset;
30729 u32 crtc_offset_cntl;
30730
30731- atomic_t vbl_received;
30732+ atomic_unchecked_t vbl_received;
30733
30734 u32 color_fmt;
30735 unsigned int front_offset;
30736diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30737index 429d5a0..7e899ed 100644
30738--- a/drivers/gpu/drm/r128/r128_irq.c
30739+++ b/drivers/gpu/drm/r128/r128_irq.c
30740@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30741 if (crtc != 0)
30742 return 0;
30743
30744- return atomic_read(&dev_priv->vbl_received);
30745+ return atomic_read_unchecked(&dev_priv->vbl_received);
30746 }
30747
30748 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30749@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30750 /* VBLANK interrupt */
30751 if (status & R128_CRTC_VBLANK_INT) {
30752 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30753- atomic_inc(&dev_priv->vbl_received);
30754+ atomic_inc_unchecked(&dev_priv->vbl_received);
30755 drm_handle_vblank(dev, 0);
30756 return IRQ_HANDLED;
30757 }
30758diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30759index a9e33ce..09edd4b 100644
30760--- a/drivers/gpu/drm/r128/r128_state.c
30761+++ b/drivers/gpu/drm/r128/r128_state.c
30762@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30763
30764 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30765 {
30766- if (atomic_read(&dev_priv->idle_count) == 0)
30767+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30768 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30769 else
30770- atomic_set(&dev_priv->idle_count, 0);
30771+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30772 }
30773
30774 #endif
30775diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30776index 5a82b6b..9e69c73 100644
30777--- a/drivers/gpu/drm/radeon/mkregtable.c
30778+++ b/drivers/gpu/drm/radeon/mkregtable.c
30779@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30780 regex_t mask_rex;
30781 regmatch_t match[4];
30782 char buf[1024];
30783- size_t end;
30784+ long end;
30785 int len;
30786 int done = 0;
30787 int r;
30788 unsigned o;
30789 struct offset *offset;
30790 char last_reg_s[10];
30791- int last_reg;
30792+ unsigned long last_reg;
30793
30794 if (regcomp
30795 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30796diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30797index fefcca5..20a5b90 100644
30798--- a/drivers/gpu/drm/radeon/radeon.h
30799+++ b/drivers/gpu/drm/radeon/radeon.h
30800@@ -743,7 +743,7 @@ struct r600_blit_cp_primitives {
30801 int x2, int y2);
30802 void (*draw_auto)(struct radeon_device *rdev);
30803 void (*set_default_state)(struct radeon_device *rdev);
30804-};
30805+} __no_const;
30806
30807 struct r600_blit {
30808 struct radeon_bo *shader_obj;
30809@@ -1244,7 +1244,7 @@ struct radeon_asic {
30810 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30811 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30812 } pflip;
30813-};
30814+} __no_const;
30815
30816 /*
30817 * Asic structures
30818diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30819index 066c98b..96ab858 100644
30820--- a/drivers/gpu/drm/radeon/radeon_device.c
30821+++ b/drivers/gpu/drm/radeon/radeon_device.c
30822@@ -692,7 +692,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30823 bool can_switch;
30824
30825 spin_lock(&dev->count_lock);
30826- can_switch = (dev->open_count == 0);
30827+ can_switch = (local_read(&dev->open_count) == 0);
30828 spin_unlock(&dev->count_lock);
30829 return can_switch;
30830 }
30831diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30832index a1b59ca..86f2d44 100644
30833--- a/drivers/gpu/drm/radeon/radeon_drv.h
30834+++ b/drivers/gpu/drm/radeon/radeon_drv.h
30835@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30836
30837 /* SW interrupt */
30838 wait_queue_head_t swi_queue;
30839- atomic_t swi_emitted;
30840+ atomic_unchecked_t swi_emitted;
30841 int vblank_crtc;
30842 uint32_t irq_enable_reg;
30843 uint32_t r500_disp_irq_reg;
30844diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30845index 48b7cea..342236f 100644
30846--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30847+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30848@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30849 request = compat_alloc_user_space(sizeof(*request));
30850 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30851 || __put_user(req32.param, &request->param)
30852- || __put_user((void __user *)(unsigned long)req32.value,
30853+ || __put_user((unsigned long)req32.value,
30854 &request->value))
30855 return -EFAULT;
30856
30857diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30858index 00da384..32f972d 100644
30859--- a/drivers/gpu/drm/radeon/radeon_irq.c
30860+++ b/drivers/gpu/drm/radeon/radeon_irq.c
30861@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30862 unsigned int ret;
30863 RING_LOCALS;
30864
30865- atomic_inc(&dev_priv->swi_emitted);
30866- ret = atomic_read(&dev_priv->swi_emitted);
30867+ atomic_inc_unchecked(&dev_priv->swi_emitted);
30868+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30869
30870 BEGIN_RING(4);
30871 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30872@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30873 drm_radeon_private_t *dev_priv =
30874 (drm_radeon_private_t *) dev->dev_private;
30875
30876- atomic_set(&dev_priv->swi_emitted, 0);
30877+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30878 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30879
30880 dev->max_vblank_count = 0x001fffff;
30881diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30882index e8422ae..d22d4a8 100644
30883--- a/drivers/gpu/drm/radeon/radeon_state.c
30884+++ b/drivers/gpu/drm/radeon/radeon_state.c
30885@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30886 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30887 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30888
30889- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30890+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30891 sarea_priv->nbox * sizeof(depth_boxes[0])))
30892 return -EFAULT;
30893
30894@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30895 {
30896 drm_radeon_private_t *dev_priv = dev->dev_private;
30897 drm_radeon_getparam_t *param = data;
30898- int value;
30899+ int value = 0;
30900
30901 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30902
30903diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30904index c94a225..5795d34 100644
30905--- a/drivers/gpu/drm/radeon/radeon_ttm.c
30906+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30907@@ -852,8 +852,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30908 }
30909 if (unlikely(ttm_vm_ops == NULL)) {
30910 ttm_vm_ops = vma->vm_ops;
30911- radeon_ttm_vm_ops = *ttm_vm_ops;
30912- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30913+ pax_open_kernel();
30914+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30915+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30916+ pax_close_kernel();
30917 }
30918 vma->vm_ops = &radeon_ttm_vm_ops;
30919 return 0;
30920diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30921index 159b6a4..fa82487 100644
30922--- a/drivers/gpu/drm/radeon/rs690.c
30923+++ b/drivers/gpu/drm/radeon/rs690.c
30924@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30925 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30926 rdev->pm.sideport_bandwidth.full)
30927 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30928- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30929+ read_delay_latency.full = dfixed_const(800 * 1000);
30930 read_delay_latency.full = dfixed_div(read_delay_latency,
30931 rdev->pm.igp_sideport_mclk);
30932+ a.full = dfixed_const(370);
30933+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30934 } else {
30935 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30936 rdev->pm.k8_bandwidth.full)
30937diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30938index ebc6fac..a8313ed 100644
30939--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30940+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30941@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
30942 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30943 struct shrink_control *sc)
30944 {
30945- static atomic_t start_pool = ATOMIC_INIT(0);
30946+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30947 unsigned i;
30948- unsigned pool_offset = atomic_add_return(1, &start_pool);
30949+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30950 struct ttm_page_pool *pool;
30951 int shrink_pages = sc->nr_to_scan;
30952
30953diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30954index 88edacc..1e5412b 100644
30955--- a/drivers/gpu/drm/via/via_drv.h
30956+++ b/drivers/gpu/drm/via/via_drv.h
30957@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
30958 typedef uint32_t maskarray_t[5];
30959
30960 typedef struct drm_via_irq {
30961- atomic_t irq_received;
30962+ atomic_unchecked_t irq_received;
30963 uint32_t pending_mask;
30964 uint32_t enable_mask;
30965 wait_queue_head_t irq_queue;
30966@@ -75,7 +75,7 @@ typedef struct drm_via_private {
30967 struct timeval last_vblank;
30968 int last_vblank_valid;
30969 unsigned usec_per_vblank;
30970- atomic_t vbl_received;
30971+ atomic_unchecked_t vbl_received;
30972 drm_via_state_t hc_state;
30973 char pci_buf[VIA_PCI_BUF_SIZE];
30974 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
30975diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
30976index d391f48..10c8ca3 100644
30977--- a/drivers/gpu/drm/via/via_irq.c
30978+++ b/drivers/gpu/drm/via/via_irq.c
30979@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
30980 if (crtc != 0)
30981 return 0;
30982
30983- return atomic_read(&dev_priv->vbl_received);
30984+ return atomic_read_unchecked(&dev_priv->vbl_received);
30985 }
30986
30987 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30988@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30989
30990 status = VIA_READ(VIA_REG_INTERRUPT);
30991 if (status & VIA_IRQ_VBLANK_PENDING) {
30992- atomic_inc(&dev_priv->vbl_received);
30993- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
30994+ atomic_inc_unchecked(&dev_priv->vbl_received);
30995+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
30996 do_gettimeofday(&cur_vblank);
30997 if (dev_priv->last_vblank_valid) {
30998 dev_priv->usec_per_vblank =
30999@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31000 dev_priv->last_vblank = cur_vblank;
31001 dev_priv->last_vblank_valid = 1;
31002 }
31003- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31004+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31005 DRM_DEBUG("US per vblank is: %u\n",
31006 dev_priv->usec_per_vblank);
31007 }
31008@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31009
31010 for (i = 0; i < dev_priv->num_irqs; ++i) {
31011 if (status & cur_irq->pending_mask) {
31012- atomic_inc(&cur_irq->irq_received);
31013+ atomic_inc_unchecked(&cur_irq->irq_received);
31014 DRM_WAKEUP(&cur_irq->irq_queue);
31015 handled = 1;
31016 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31017@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31018 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31019 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31020 masks[irq][4]));
31021- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31022+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31023 } else {
31024 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31025 (((cur_irq_sequence =
31026- atomic_read(&cur_irq->irq_received)) -
31027+ atomic_read_unchecked(&cur_irq->irq_received)) -
31028 *sequence) <= (1 << 23)));
31029 }
31030 *sequence = cur_irq_sequence;
31031@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31032 }
31033
31034 for (i = 0; i < dev_priv->num_irqs; ++i) {
31035- atomic_set(&cur_irq->irq_received, 0);
31036+ atomic_set_unchecked(&cur_irq->irq_received, 0);
31037 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31038 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31039 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31040@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31041 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31042 case VIA_IRQ_RELATIVE:
31043 irqwait->request.sequence +=
31044- atomic_read(&cur_irq->irq_received);
31045+ atomic_read_unchecked(&cur_irq->irq_received);
31046 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31047 case VIA_IRQ_ABSOLUTE:
31048 break;
31049diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31050index d0f2c07..9ebd9c3 100644
31051--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31052+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31053@@ -263,7 +263,7 @@ struct vmw_private {
31054 * Fencing and IRQs.
31055 */
31056
31057- atomic_t marker_seq;
31058+ atomic_unchecked_t marker_seq;
31059 wait_queue_head_t fence_queue;
31060 wait_queue_head_t fifo_queue;
31061 int fence_queue_waiters; /* Protected by hw_mutex */
31062diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31063index a0c2f12..68ae6cb 100644
31064--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31065+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31066@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31067 (unsigned int) min,
31068 (unsigned int) fifo->capabilities);
31069
31070- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31071+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31072 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31073 vmw_marker_queue_init(&fifo->marker_queue);
31074 return vmw_fifo_send_fence(dev_priv, &dummy);
31075@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31076 if (reserveable)
31077 iowrite32(bytes, fifo_mem +
31078 SVGA_FIFO_RESERVED);
31079- return fifo_mem + (next_cmd >> 2);
31080+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31081 } else {
31082 need_bounce = true;
31083 }
31084@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31085
31086 fm = vmw_fifo_reserve(dev_priv, bytes);
31087 if (unlikely(fm == NULL)) {
31088- *seqno = atomic_read(&dev_priv->marker_seq);
31089+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31090 ret = -ENOMEM;
31091 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31092 false, 3*HZ);
31093@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31094 }
31095
31096 do {
31097- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31098+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31099 } while (*seqno == 0);
31100
31101 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31102diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31103index cabc95f..14b3d77 100644
31104--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31105+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31106@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31107 * emitted. Then the fence is stale and signaled.
31108 */
31109
31110- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31111+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31112 > VMW_FENCE_WRAP);
31113
31114 return ret;
31115@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31116
31117 if (fifo_idle)
31118 down_read(&fifo_state->rwsem);
31119- signal_seq = atomic_read(&dev_priv->marker_seq);
31120+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31121 ret = 0;
31122
31123 for (;;) {
31124diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31125index 8a8725c..afed796 100644
31126--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31127+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31128@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31129 while (!vmw_lag_lt(queue, us)) {
31130 spin_lock(&queue->lock);
31131 if (list_empty(&queue->head))
31132- seqno = atomic_read(&dev_priv->marker_seq);
31133+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31134 else {
31135 marker = list_first_entry(&queue->head,
31136 struct vmw_marker, head);
31137diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31138index 4c87276..9ecc3c7 100644
31139--- a/drivers/hid/hid-core.c
31140+++ b/drivers/hid/hid-core.c
31141@@ -2151,7 +2151,7 @@ static bool hid_ignore(struct hid_device *hdev)
31142
31143 int hid_add_device(struct hid_device *hdev)
31144 {
31145- static atomic_t id = ATOMIC_INIT(0);
31146+ static atomic_unchecked_t id = ATOMIC_INIT(0);
31147 int ret;
31148
31149 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31150@@ -2186,7 +2186,7 @@ int hid_add_device(struct hid_device *hdev)
31151 /* XXX hack, any other cleaner solution after the driver core
31152 * is converted to allow more than 20 bytes as the device name? */
31153 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31154- hdev->vendor, hdev->product, atomic_inc_return(&id));
31155+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31156
31157 hid_debug_register(hdev, dev_name(&hdev->dev));
31158 ret = device_add(&hdev->dev);
31159diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31160index eec3291..8ed706b 100644
31161--- a/drivers/hid/hid-wiimote-debug.c
31162+++ b/drivers/hid/hid-wiimote-debug.c
31163@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31164 else if (size == 0)
31165 return -EIO;
31166
31167- if (copy_to_user(u, buf, size))
31168+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
31169 return -EFAULT;
31170
31171 *off += size;
31172diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31173index 14599e2..711c965 100644
31174--- a/drivers/hid/usbhid/hiddev.c
31175+++ b/drivers/hid/usbhid/hiddev.c
31176@@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31177 break;
31178
31179 case HIDIOCAPPLICATION:
31180- if (arg < 0 || arg >= hid->maxapplication)
31181+ if (arg >= hid->maxapplication)
31182 break;
31183
31184 for (i = 0; i < hid->maxcollection; i++)
31185diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31186index 4065374..10ed7dc 100644
31187--- a/drivers/hv/channel.c
31188+++ b/drivers/hv/channel.c
31189@@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31190 int ret = 0;
31191 int t;
31192
31193- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31194- atomic_inc(&vmbus_connection.next_gpadl_handle);
31195+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31196+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31197
31198 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31199 if (ret)
31200diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31201index 86f8885..ab9cb2b 100644
31202--- a/drivers/hv/hv.c
31203+++ b/drivers/hv/hv.c
31204@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31205 u64 output_address = (output) ? virt_to_phys(output) : 0;
31206 u32 output_address_hi = output_address >> 32;
31207 u32 output_address_lo = output_address & 0xFFFFFFFF;
31208- void *hypercall_page = hv_context.hypercall_page;
31209+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31210
31211 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31212 "=a"(hv_status_lo) : "d" (control_hi),
31213diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31214index b9426a6..677ce34 100644
31215--- a/drivers/hv/hyperv_vmbus.h
31216+++ b/drivers/hv/hyperv_vmbus.h
31217@@ -555,7 +555,7 @@ enum vmbus_connect_state {
31218 struct vmbus_connection {
31219 enum vmbus_connect_state conn_state;
31220
31221- atomic_t next_gpadl_handle;
31222+ atomic_unchecked_t next_gpadl_handle;
31223
31224 /*
31225 * Represents channel interrupts. Each bit position represents a
31226diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31227index a220e57..428f54d 100644
31228--- a/drivers/hv/vmbus_drv.c
31229+++ b/drivers/hv/vmbus_drv.c
31230@@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31231 {
31232 int ret = 0;
31233
31234- static atomic_t device_num = ATOMIC_INIT(0);
31235+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31236
31237 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31238- atomic_inc_return(&device_num));
31239+ atomic_inc_return_unchecked(&device_num));
31240
31241 child_device_obj->device.bus = &hv_bus;
31242 child_device_obj->device.parent = &hv_acpi_dev->dev;
31243diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31244index 34ad5a2..e2b0ae8 100644
31245--- a/drivers/hwmon/acpi_power_meter.c
31246+++ b/drivers/hwmon/acpi_power_meter.c
31247@@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31248 return res;
31249
31250 temp /= 1000;
31251- if (temp < 0)
31252- return -EINVAL;
31253
31254 mutex_lock(&resource->lock);
31255 resource->trip[attr->index - 7] = temp;
31256diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31257index 8b011d0..3de24a1 100644
31258--- a/drivers/hwmon/sht15.c
31259+++ b/drivers/hwmon/sht15.c
31260@@ -166,7 +166,7 @@ struct sht15_data {
31261 int supply_uV;
31262 bool supply_uV_valid;
31263 struct work_struct update_supply_work;
31264- atomic_t interrupt_handled;
31265+ atomic_unchecked_t interrupt_handled;
31266 };
31267
31268 /**
31269@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31270 return ret;
31271
31272 gpio_direction_input(data->pdata->gpio_data);
31273- atomic_set(&data->interrupt_handled, 0);
31274+ atomic_set_unchecked(&data->interrupt_handled, 0);
31275
31276 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31277 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31278 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31279 /* Only relevant if the interrupt hasn't occurred. */
31280- if (!atomic_read(&data->interrupt_handled))
31281+ if (!atomic_read_unchecked(&data->interrupt_handled))
31282 schedule_work(&data->read_work);
31283 }
31284 ret = wait_event_timeout(data->wait_queue,
31285@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31286
31287 /* First disable the interrupt */
31288 disable_irq_nosync(irq);
31289- atomic_inc(&data->interrupt_handled);
31290+ atomic_inc_unchecked(&data->interrupt_handled);
31291 /* Then schedule a reading work struct */
31292 if (data->state != SHT15_READING_NOTHING)
31293 schedule_work(&data->read_work);
31294@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31295 * If not, then start the interrupt again - care here as could
31296 * have gone low in meantime so verify it hasn't!
31297 */
31298- atomic_set(&data->interrupt_handled, 0);
31299+ atomic_set_unchecked(&data->interrupt_handled, 0);
31300 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31301 /* If still not occurred or another handler was scheduled */
31302 if (gpio_get_value(data->pdata->gpio_data)
31303- || atomic_read(&data->interrupt_handled))
31304+ || atomic_read_unchecked(&data->interrupt_handled))
31305 return;
31306 }
31307
31308diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31309index 378fcb5..5e91fa8 100644
31310--- a/drivers/i2c/busses/i2c-amd756-s4882.c
31311+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31312@@ -43,7 +43,7 @@
31313 extern struct i2c_adapter amd756_smbus;
31314
31315 static struct i2c_adapter *s4882_adapter;
31316-static struct i2c_algorithm *s4882_algo;
31317+static i2c_algorithm_no_const *s4882_algo;
31318
31319 /* Wrapper access functions for multiplexed SMBus */
31320 static DEFINE_MUTEX(amd756_lock);
31321diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31322index 29015eb..af2d8e9 100644
31323--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31324+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31325@@ -41,7 +41,7 @@
31326 extern struct i2c_adapter *nforce2_smbus;
31327
31328 static struct i2c_adapter *s4985_adapter;
31329-static struct i2c_algorithm *s4985_algo;
31330+static i2c_algorithm_no_const *s4985_algo;
31331
31332 /* Wrapper access functions for multiplexed SMBus */
31333 static DEFINE_MUTEX(nforce2_lock);
31334diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31335index 1038c38..eb92f51 100644
31336--- a/drivers/i2c/i2c-mux.c
31337+++ b/drivers/i2c/i2c-mux.c
31338@@ -30,7 +30,7 @@
31339 /* multiplexer per channel data */
31340 struct i2c_mux_priv {
31341 struct i2c_adapter adap;
31342- struct i2c_algorithm algo;
31343+ i2c_algorithm_no_const algo;
31344
31345 struct i2c_adapter *parent;
31346 void *mux_priv; /* the mux chip/device */
31347diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31348index 57d00ca..0145194 100644
31349--- a/drivers/ide/aec62xx.c
31350+++ b/drivers/ide/aec62xx.c
31351@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31352 .cable_detect = atp86x_cable_detect,
31353 };
31354
31355-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31356+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31357 { /* 0: AEC6210 */
31358 .name = DRV_NAME,
31359 .init_chipset = init_chipset_aec62xx,
31360diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31361index 2c8016a..911a27c 100644
31362--- a/drivers/ide/alim15x3.c
31363+++ b/drivers/ide/alim15x3.c
31364@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31365 .dma_sff_read_status = ide_dma_sff_read_status,
31366 };
31367
31368-static const struct ide_port_info ali15x3_chipset __devinitdata = {
31369+static const struct ide_port_info ali15x3_chipset __devinitconst = {
31370 .name = DRV_NAME,
31371 .init_chipset = init_chipset_ali15x3,
31372 .init_hwif = init_hwif_ali15x3,
31373diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31374index 3747b25..56fc995 100644
31375--- a/drivers/ide/amd74xx.c
31376+++ b/drivers/ide/amd74xx.c
31377@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31378 .udma_mask = udma, \
31379 }
31380
31381-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31382+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31383 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31384 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31385 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31386diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31387index 15f0ead..cb43480 100644
31388--- a/drivers/ide/atiixp.c
31389+++ b/drivers/ide/atiixp.c
31390@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31391 .cable_detect = atiixp_cable_detect,
31392 };
31393
31394-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31395+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31396 { /* 0: IXP200/300/400/700 */
31397 .name = DRV_NAME,
31398 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31399diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31400index 5f80312..d1fc438 100644
31401--- a/drivers/ide/cmd64x.c
31402+++ b/drivers/ide/cmd64x.c
31403@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31404 .dma_sff_read_status = ide_dma_sff_read_status,
31405 };
31406
31407-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31408+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31409 { /* 0: CMD643 */
31410 .name = DRV_NAME,
31411 .init_chipset = init_chipset_cmd64x,
31412diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31413index 2c1e5f7..1444762 100644
31414--- a/drivers/ide/cs5520.c
31415+++ b/drivers/ide/cs5520.c
31416@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31417 .set_dma_mode = cs5520_set_dma_mode,
31418 };
31419
31420-static const struct ide_port_info cyrix_chipset __devinitdata = {
31421+static const struct ide_port_info cyrix_chipset __devinitconst = {
31422 .name = DRV_NAME,
31423 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31424 .port_ops = &cs5520_port_ops,
31425diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31426index 4dc4eb9..49b40ad 100644
31427--- a/drivers/ide/cs5530.c
31428+++ b/drivers/ide/cs5530.c
31429@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31430 .udma_filter = cs5530_udma_filter,
31431 };
31432
31433-static const struct ide_port_info cs5530_chipset __devinitdata = {
31434+static const struct ide_port_info cs5530_chipset __devinitconst = {
31435 .name = DRV_NAME,
31436 .init_chipset = init_chipset_cs5530,
31437 .init_hwif = init_hwif_cs5530,
31438diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31439index 5059faf..18d4c85 100644
31440--- a/drivers/ide/cs5535.c
31441+++ b/drivers/ide/cs5535.c
31442@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31443 .cable_detect = cs5535_cable_detect,
31444 };
31445
31446-static const struct ide_port_info cs5535_chipset __devinitdata = {
31447+static const struct ide_port_info cs5535_chipset __devinitconst = {
31448 .name = DRV_NAME,
31449 .port_ops = &cs5535_port_ops,
31450 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31451diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31452index 847553f..3ffb49d 100644
31453--- a/drivers/ide/cy82c693.c
31454+++ b/drivers/ide/cy82c693.c
31455@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31456 .set_dma_mode = cy82c693_set_dma_mode,
31457 };
31458
31459-static const struct ide_port_info cy82c693_chipset __devinitdata = {
31460+static const struct ide_port_info cy82c693_chipset __devinitconst = {
31461 .name = DRV_NAME,
31462 .init_iops = init_iops_cy82c693,
31463 .port_ops = &cy82c693_port_ops,
31464diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31465index 58c51cd..4aec3b8 100644
31466--- a/drivers/ide/hpt366.c
31467+++ b/drivers/ide/hpt366.c
31468@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31469 }
31470 };
31471
31472-static const struct hpt_info hpt36x __devinitdata = {
31473+static const struct hpt_info hpt36x __devinitconst = {
31474 .chip_name = "HPT36x",
31475 .chip_type = HPT36x,
31476 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31477@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31478 .timings = &hpt36x_timings
31479 };
31480
31481-static const struct hpt_info hpt370 __devinitdata = {
31482+static const struct hpt_info hpt370 __devinitconst = {
31483 .chip_name = "HPT370",
31484 .chip_type = HPT370,
31485 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31486@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31487 .timings = &hpt37x_timings
31488 };
31489
31490-static const struct hpt_info hpt370a __devinitdata = {
31491+static const struct hpt_info hpt370a __devinitconst = {
31492 .chip_name = "HPT370A",
31493 .chip_type = HPT370A,
31494 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31495@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31496 .timings = &hpt37x_timings
31497 };
31498
31499-static const struct hpt_info hpt374 __devinitdata = {
31500+static const struct hpt_info hpt374 __devinitconst = {
31501 .chip_name = "HPT374",
31502 .chip_type = HPT374,
31503 .udma_mask = ATA_UDMA5,
31504@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31505 .timings = &hpt37x_timings
31506 };
31507
31508-static const struct hpt_info hpt372 __devinitdata = {
31509+static const struct hpt_info hpt372 __devinitconst = {
31510 .chip_name = "HPT372",
31511 .chip_type = HPT372,
31512 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31513@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31514 .timings = &hpt37x_timings
31515 };
31516
31517-static const struct hpt_info hpt372a __devinitdata = {
31518+static const struct hpt_info hpt372a __devinitconst = {
31519 .chip_name = "HPT372A",
31520 .chip_type = HPT372A,
31521 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31522@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31523 .timings = &hpt37x_timings
31524 };
31525
31526-static const struct hpt_info hpt302 __devinitdata = {
31527+static const struct hpt_info hpt302 __devinitconst = {
31528 .chip_name = "HPT302",
31529 .chip_type = HPT302,
31530 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31531@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31532 .timings = &hpt37x_timings
31533 };
31534
31535-static const struct hpt_info hpt371 __devinitdata = {
31536+static const struct hpt_info hpt371 __devinitconst = {
31537 .chip_name = "HPT371",
31538 .chip_type = HPT371,
31539 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31540@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31541 .timings = &hpt37x_timings
31542 };
31543
31544-static const struct hpt_info hpt372n __devinitdata = {
31545+static const struct hpt_info hpt372n __devinitconst = {
31546 .chip_name = "HPT372N",
31547 .chip_type = HPT372N,
31548 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31549@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31550 .timings = &hpt37x_timings
31551 };
31552
31553-static const struct hpt_info hpt302n __devinitdata = {
31554+static const struct hpt_info hpt302n __devinitconst = {
31555 .chip_name = "HPT302N",
31556 .chip_type = HPT302N,
31557 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31558@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31559 .timings = &hpt37x_timings
31560 };
31561
31562-static const struct hpt_info hpt371n __devinitdata = {
31563+static const struct hpt_info hpt371n __devinitconst = {
31564 .chip_name = "HPT371N",
31565 .chip_type = HPT371N,
31566 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31567@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31568 .dma_sff_read_status = ide_dma_sff_read_status,
31569 };
31570
31571-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31572+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31573 { /* 0: HPT36x */
31574 .name = DRV_NAME,
31575 .init_chipset = init_chipset_hpt366,
31576diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31577index 8126824..55a2798 100644
31578--- a/drivers/ide/ide-cd.c
31579+++ b/drivers/ide/ide-cd.c
31580@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31581 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31582 if ((unsigned long)buf & alignment
31583 || blk_rq_bytes(rq) & q->dma_pad_mask
31584- || object_is_on_stack(buf))
31585+ || object_starts_on_stack(buf))
31586 drive->dma = 0;
31587 }
31588 }
31589diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31590index 7f56b73..dab5b67 100644
31591--- a/drivers/ide/ide-pci-generic.c
31592+++ b/drivers/ide/ide-pci-generic.c
31593@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31594 .udma_mask = ATA_UDMA6, \
31595 }
31596
31597-static const struct ide_port_info generic_chipsets[] __devinitdata = {
31598+static const struct ide_port_info generic_chipsets[] __devinitconst = {
31599 /* 0: Unknown */
31600 DECLARE_GENERIC_PCI_DEV(0),
31601
31602diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31603index 560e66d..d5dd180 100644
31604--- a/drivers/ide/it8172.c
31605+++ b/drivers/ide/it8172.c
31606@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31607 .set_dma_mode = it8172_set_dma_mode,
31608 };
31609
31610-static const struct ide_port_info it8172_port_info __devinitdata = {
31611+static const struct ide_port_info it8172_port_info __devinitconst = {
31612 .name = DRV_NAME,
31613 .port_ops = &it8172_port_ops,
31614 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31615diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31616index 46816ba..1847aeb 100644
31617--- a/drivers/ide/it8213.c
31618+++ b/drivers/ide/it8213.c
31619@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31620 .cable_detect = it8213_cable_detect,
31621 };
31622
31623-static const struct ide_port_info it8213_chipset __devinitdata = {
31624+static const struct ide_port_info it8213_chipset __devinitconst = {
31625 .name = DRV_NAME,
31626 .enablebits = { {0x41, 0x80, 0x80} },
31627 .port_ops = &it8213_port_ops,
31628diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31629index 2e3169f..c5611db 100644
31630--- a/drivers/ide/it821x.c
31631+++ b/drivers/ide/it821x.c
31632@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31633 .cable_detect = it821x_cable_detect,
31634 };
31635
31636-static const struct ide_port_info it821x_chipset __devinitdata = {
31637+static const struct ide_port_info it821x_chipset __devinitconst = {
31638 .name = DRV_NAME,
31639 .init_chipset = init_chipset_it821x,
31640 .init_hwif = init_hwif_it821x,
31641diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31642index 74c2c4a..efddd7d 100644
31643--- a/drivers/ide/jmicron.c
31644+++ b/drivers/ide/jmicron.c
31645@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31646 .cable_detect = jmicron_cable_detect,
31647 };
31648
31649-static const struct ide_port_info jmicron_chipset __devinitdata = {
31650+static const struct ide_port_info jmicron_chipset __devinitconst = {
31651 .name = DRV_NAME,
31652 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31653 .port_ops = &jmicron_port_ops,
31654diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31655index 95327a2..73f78d8 100644
31656--- a/drivers/ide/ns87415.c
31657+++ b/drivers/ide/ns87415.c
31658@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31659 .dma_sff_read_status = superio_dma_sff_read_status,
31660 };
31661
31662-static const struct ide_port_info ns87415_chipset __devinitdata = {
31663+static const struct ide_port_info ns87415_chipset __devinitconst = {
31664 .name = DRV_NAME,
31665 .init_hwif = init_hwif_ns87415,
31666 .tp_ops = &ns87415_tp_ops,
31667diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31668index 1a53a4c..39edc66 100644
31669--- a/drivers/ide/opti621.c
31670+++ b/drivers/ide/opti621.c
31671@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31672 .set_pio_mode = opti621_set_pio_mode,
31673 };
31674
31675-static const struct ide_port_info opti621_chipset __devinitdata = {
31676+static const struct ide_port_info opti621_chipset __devinitconst = {
31677 .name = DRV_NAME,
31678 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31679 .port_ops = &opti621_port_ops,
31680diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31681index 9546fe2..2e5ceb6 100644
31682--- a/drivers/ide/pdc202xx_new.c
31683+++ b/drivers/ide/pdc202xx_new.c
31684@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31685 .udma_mask = udma, \
31686 }
31687
31688-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31689+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31690 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31691 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31692 };
31693diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31694index 3a35ec6..5634510 100644
31695--- a/drivers/ide/pdc202xx_old.c
31696+++ b/drivers/ide/pdc202xx_old.c
31697@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31698 .max_sectors = sectors, \
31699 }
31700
31701-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31702+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31703 { /* 0: PDC20246 */
31704 .name = DRV_NAME,
31705 .init_chipset = init_chipset_pdc202xx,
31706diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31707index 1892e81..fe0fd60 100644
31708--- a/drivers/ide/piix.c
31709+++ b/drivers/ide/piix.c
31710@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31711 .udma_mask = udma, \
31712 }
31713
31714-static const struct ide_port_info piix_pci_info[] __devinitdata = {
31715+static const struct ide_port_info piix_pci_info[] __devinitconst = {
31716 /* 0: MPIIX */
31717 { /*
31718 * MPIIX actually has only a single IDE channel mapped to
31719diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31720index a6414a8..c04173e 100644
31721--- a/drivers/ide/rz1000.c
31722+++ b/drivers/ide/rz1000.c
31723@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31724 }
31725 }
31726
31727-static const struct ide_port_info rz1000_chipset __devinitdata = {
31728+static const struct ide_port_info rz1000_chipset __devinitconst = {
31729 .name = DRV_NAME,
31730 .host_flags = IDE_HFLAG_NO_DMA,
31731 };
31732diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31733index 356b9b5..d4758eb 100644
31734--- a/drivers/ide/sc1200.c
31735+++ b/drivers/ide/sc1200.c
31736@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31737 .dma_sff_read_status = ide_dma_sff_read_status,
31738 };
31739
31740-static const struct ide_port_info sc1200_chipset __devinitdata = {
31741+static const struct ide_port_info sc1200_chipset __devinitconst = {
31742 .name = DRV_NAME,
31743 .port_ops = &sc1200_port_ops,
31744 .dma_ops = &sc1200_dma_ops,
31745diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31746index b7f5b0c..9701038 100644
31747--- a/drivers/ide/scc_pata.c
31748+++ b/drivers/ide/scc_pata.c
31749@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31750 .dma_sff_read_status = scc_dma_sff_read_status,
31751 };
31752
31753-static const struct ide_port_info scc_chipset __devinitdata = {
31754+static const struct ide_port_info scc_chipset __devinitconst = {
31755 .name = "sccIDE",
31756 .init_iops = init_iops_scc,
31757 .init_dma = scc_init_dma,
31758diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31759index 35fb8da..24d72ef 100644
31760--- a/drivers/ide/serverworks.c
31761+++ b/drivers/ide/serverworks.c
31762@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31763 .cable_detect = svwks_cable_detect,
31764 };
31765
31766-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31767+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31768 { /* 0: OSB4 */
31769 .name = DRV_NAME,
31770 .init_chipset = init_chipset_svwks,
31771diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31772index ddeda44..46f7e30 100644
31773--- a/drivers/ide/siimage.c
31774+++ b/drivers/ide/siimage.c
31775@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31776 .udma_mask = ATA_UDMA6, \
31777 }
31778
31779-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31780+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31781 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31782 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31783 };
31784diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31785index 4a00225..09e61b4 100644
31786--- a/drivers/ide/sis5513.c
31787+++ b/drivers/ide/sis5513.c
31788@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31789 .cable_detect = sis_cable_detect,
31790 };
31791
31792-static const struct ide_port_info sis5513_chipset __devinitdata = {
31793+static const struct ide_port_info sis5513_chipset __devinitconst = {
31794 .name = DRV_NAME,
31795 .init_chipset = init_chipset_sis5513,
31796 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31797diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31798index f21dc2a..d051cd2 100644
31799--- a/drivers/ide/sl82c105.c
31800+++ b/drivers/ide/sl82c105.c
31801@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31802 .dma_sff_read_status = ide_dma_sff_read_status,
31803 };
31804
31805-static const struct ide_port_info sl82c105_chipset __devinitdata = {
31806+static const struct ide_port_info sl82c105_chipset __devinitconst = {
31807 .name = DRV_NAME,
31808 .init_chipset = init_chipset_sl82c105,
31809 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31810diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31811index 864ffe0..863a5e9 100644
31812--- a/drivers/ide/slc90e66.c
31813+++ b/drivers/ide/slc90e66.c
31814@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31815 .cable_detect = slc90e66_cable_detect,
31816 };
31817
31818-static const struct ide_port_info slc90e66_chipset __devinitdata = {
31819+static const struct ide_port_info slc90e66_chipset __devinitconst = {
31820 .name = DRV_NAME,
31821 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31822 .port_ops = &slc90e66_port_ops,
31823diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31824index 4799d5c..1794678 100644
31825--- a/drivers/ide/tc86c001.c
31826+++ b/drivers/ide/tc86c001.c
31827@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31828 .dma_sff_read_status = ide_dma_sff_read_status,
31829 };
31830
31831-static const struct ide_port_info tc86c001_chipset __devinitdata = {
31832+static const struct ide_port_info tc86c001_chipset __devinitconst = {
31833 .name = DRV_NAME,
31834 .init_hwif = init_hwif_tc86c001,
31835 .port_ops = &tc86c001_port_ops,
31836diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31837index 281c914..55ce1b8 100644
31838--- a/drivers/ide/triflex.c
31839+++ b/drivers/ide/triflex.c
31840@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31841 .set_dma_mode = triflex_set_mode,
31842 };
31843
31844-static const struct ide_port_info triflex_device __devinitdata = {
31845+static const struct ide_port_info triflex_device __devinitconst = {
31846 .name = DRV_NAME,
31847 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31848 .port_ops = &triflex_port_ops,
31849diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31850index 4b42ca0..e494a98 100644
31851--- a/drivers/ide/trm290.c
31852+++ b/drivers/ide/trm290.c
31853@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31854 .dma_check = trm290_dma_check,
31855 };
31856
31857-static const struct ide_port_info trm290_chipset __devinitdata = {
31858+static const struct ide_port_info trm290_chipset __devinitconst = {
31859 .name = DRV_NAME,
31860 .init_hwif = init_hwif_trm290,
31861 .tp_ops = &trm290_tp_ops,
31862diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31863index f46f49c..eb77678 100644
31864--- a/drivers/ide/via82cxxx.c
31865+++ b/drivers/ide/via82cxxx.c
31866@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31867 .cable_detect = via82cxxx_cable_detect,
31868 };
31869
31870-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31871+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31872 .name = DRV_NAME,
31873 .init_chipset = init_chipset_via82cxxx,
31874 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31875diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31876index 73d4531..c90cd2d 100644
31877--- a/drivers/ieee802154/fakehard.c
31878+++ b/drivers/ieee802154/fakehard.c
31879@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31880 phy->transmit_power = 0xbf;
31881
31882 dev->netdev_ops = &fake_ops;
31883- dev->ml_priv = &fake_mlme;
31884+ dev->ml_priv = (void *)&fake_mlme;
31885
31886 priv = netdev_priv(dev);
31887 priv->phy = phy;
31888diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31889index c889aae..6cf5aa7 100644
31890--- a/drivers/infiniband/core/cm.c
31891+++ b/drivers/infiniband/core/cm.c
31892@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31893
31894 struct cm_counter_group {
31895 struct kobject obj;
31896- atomic_long_t counter[CM_ATTR_COUNT];
31897+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31898 };
31899
31900 struct cm_counter_attribute {
31901@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31902 struct ib_mad_send_buf *msg = NULL;
31903 int ret;
31904
31905- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31906+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31907 counter[CM_REQ_COUNTER]);
31908
31909 /* Quick state check to discard duplicate REQs. */
31910@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31911 if (!cm_id_priv)
31912 return;
31913
31914- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31915+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31916 counter[CM_REP_COUNTER]);
31917 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31918 if (ret)
31919@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31920 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31921 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31922 spin_unlock_irq(&cm_id_priv->lock);
31923- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31924+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31925 counter[CM_RTU_COUNTER]);
31926 goto out;
31927 }
31928@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31929 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31930 dreq_msg->local_comm_id);
31931 if (!cm_id_priv) {
31932- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31933+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31934 counter[CM_DREQ_COUNTER]);
31935 cm_issue_drep(work->port, work->mad_recv_wc);
31936 return -EINVAL;
31937@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31938 case IB_CM_MRA_REP_RCVD:
31939 break;
31940 case IB_CM_TIMEWAIT:
31941- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31942+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31943 counter[CM_DREQ_COUNTER]);
31944 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31945 goto unlock;
31946@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31947 cm_free_msg(msg);
31948 goto deref;
31949 case IB_CM_DREQ_RCVD:
31950- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31951+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31952 counter[CM_DREQ_COUNTER]);
31953 goto unlock;
31954 default:
31955@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31956 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31957 cm_id_priv->msg, timeout)) {
31958 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
31959- atomic_long_inc(&work->port->
31960+ atomic_long_inc_unchecked(&work->port->
31961 counter_group[CM_RECV_DUPLICATES].
31962 counter[CM_MRA_COUNTER]);
31963 goto out;
31964@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
31965 break;
31966 case IB_CM_MRA_REQ_RCVD:
31967 case IB_CM_MRA_REP_RCVD:
31968- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31969+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31970 counter[CM_MRA_COUNTER]);
31971 /* fall through */
31972 default:
31973@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
31974 case IB_CM_LAP_IDLE:
31975 break;
31976 case IB_CM_MRA_LAP_SENT:
31977- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31978+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31979 counter[CM_LAP_COUNTER]);
31980 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31981 goto unlock;
31982@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
31983 cm_free_msg(msg);
31984 goto deref;
31985 case IB_CM_LAP_RCVD:
31986- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31987+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31988 counter[CM_LAP_COUNTER]);
31989 goto unlock;
31990 default:
31991@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
31992 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
31993 if (cur_cm_id_priv) {
31994 spin_unlock_irq(&cm.lock);
31995- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31996+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31997 counter[CM_SIDR_REQ_COUNTER]);
31998 goto out; /* Duplicate message. */
31999 }
32000@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32001 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32002 msg->retries = 1;
32003
32004- atomic_long_add(1 + msg->retries,
32005+ atomic_long_add_unchecked(1 + msg->retries,
32006 &port->counter_group[CM_XMIT].counter[attr_index]);
32007 if (msg->retries)
32008- atomic_long_add(msg->retries,
32009+ atomic_long_add_unchecked(msg->retries,
32010 &port->counter_group[CM_XMIT_RETRIES].
32011 counter[attr_index]);
32012
32013@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32014 }
32015
32016 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32017- atomic_long_inc(&port->counter_group[CM_RECV].
32018+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32019 counter[attr_id - CM_ATTR_ID_OFFSET]);
32020
32021 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32022@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32023 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32024
32025 return sprintf(buf, "%ld\n",
32026- atomic_long_read(&group->counter[cm_attr->index]));
32027+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32028 }
32029
32030 static const struct sysfs_ops cm_counter_ops = {
32031diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32032index 176c8f9..2627b62 100644
32033--- a/drivers/infiniband/core/fmr_pool.c
32034+++ b/drivers/infiniband/core/fmr_pool.c
32035@@ -98,8 +98,8 @@ struct ib_fmr_pool {
32036
32037 struct task_struct *thread;
32038
32039- atomic_t req_ser;
32040- atomic_t flush_ser;
32041+ atomic_unchecked_t req_ser;
32042+ atomic_unchecked_t flush_ser;
32043
32044 wait_queue_head_t force_wait;
32045 };
32046@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32047 struct ib_fmr_pool *pool = pool_ptr;
32048
32049 do {
32050- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32051+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32052 ib_fmr_batch_release(pool);
32053
32054- atomic_inc(&pool->flush_ser);
32055+ atomic_inc_unchecked(&pool->flush_ser);
32056 wake_up_interruptible(&pool->force_wait);
32057
32058 if (pool->flush_function)
32059@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32060 }
32061
32062 set_current_state(TASK_INTERRUPTIBLE);
32063- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32064+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32065 !kthread_should_stop())
32066 schedule();
32067 __set_current_state(TASK_RUNNING);
32068@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32069 pool->dirty_watermark = params->dirty_watermark;
32070 pool->dirty_len = 0;
32071 spin_lock_init(&pool->pool_lock);
32072- atomic_set(&pool->req_ser, 0);
32073- atomic_set(&pool->flush_ser, 0);
32074+ atomic_set_unchecked(&pool->req_ser, 0);
32075+ atomic_set_unchecked(&pool->flush_ser, 0);
32076 init_waitqueue_head(&pool->force_wait);
32077
32078 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32079@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32080 }
32081 spin_unlock_irq(&pool->pool_lock);
32082
32083- serial = atomic_inc_return(&pool->req_ser);
32084+ serial = atomic_inc_return_unchecked(&pool->req_ser);
32085 wake_up_process(pool->thread);
32086
32087 if (wait_event_interruptible(pool->force_wait,
32088- atomic_read(&pool->flush_ser) - serial >= 0))
32089+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32090 return -EINTR;
32091
32092 return 0;
32093@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32094 } else {
32095 list_add_tail(&fmr->list, &pool->dirty_list);
32096 if (++pool->dirty_len >= pool->dirty_watermark) {
32097- atomic_inc(&pool->req_ser);
32098+ atomic_inc_unchecked(&pool->req_ser);
32099 wake_up_process(pool->thread);
32100 }
32101 }
32102diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32103index 57e07c6..56d09d4 100644
32104--- a/drivers/infiniband/hw/cxgb4/mem.c
32105+++ b/drivers/infiniband/hw/cxgb4/mem.c
32106@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32107 int err;
32108 struct fw_ri_tpte tpt;
32109 u32 stag_idx;
32110- static atomic_t key;
32111+ static atomic_unchecked_t key;
32112
32113 if (c4iw_fatal_error(rdev))
32114 return -EIO;
32115@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32116 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32117 rdev->stats.stag.max = rdev->stats.stag.cur;
32118 mutex_unlock(&rdev->stats.lock);
32119- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32120+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32121 }
32122 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32123 __func__, stag_state, type, pdid, stag_idx);
32124diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32125index 79b3dbc..96e5fcc 100644
32126--- a/drivers/infiniband/hw/ipath/ipath_rc.c
32127+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32128@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32129 struct ib_atomic_eth *ateth;
32130 struct ipath_ack_entry *e;
32131 u64 vaddr;
32132- atomic64_t *maddr;
32133+ atomic64_unchecked_t *maddr;
32134 u64 sdata;
32135 u32 rkey;
32136 u8 next;
32137@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32138 IB_ACCESS_REMOTE_ATOMIC)))
32139 goto nack_acc_unlck;
32140 /* Perform atomic OP and save result. */
32141- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32142+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32143 sdata = be64_to_cpu(ateth->swap_data);
32144 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32145 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32146- (u64) atomic64_add_return(sdata, maddr) - sdata :
32147+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32148 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32149 be64_to_cpu(ateth->compare_data),
32150 sdata);
32151diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32152index 1f95bba..9530f87 100644
32153--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32154+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32155@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32156 unsigned long flags;
32157 struct ib_wc wc;
32158 u64 sdata;
32159- atomic64_t *maddr;
32160+ atomic64_unchecked_t *maddr;
32161 enum ib_wc_status send_status;
32162
32163 /*
32164@@ -382,11 +382,11 @@ again:
32165 IB_ACCESS_REMOTE_ATOMIC)))
32166 goto acc_err;
32167 /* Perform atomic OP and save result. */
32168- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32169+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32170 sdata = wqe->wr.wr.atomic.compare_add;
32171 *(u64 *) sqp->s_sge.sge.vaddr =
32172 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32173- (u64) atomic64_add_return(sdata, maddr) - sdata :
32174+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32175 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32176 sdata, wqe->wr.wr.atomic.swap);
32177 goto send_comp;
32178diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32179index 7140199..da60063 100644
32180--- a/drivers/infiniband/hw/nes/nes.c
32181+++ b/drivers/infiniband/hw/nes/nes.c
32182@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32183 LIST_HEAD(nes_adapter_list);
32184 static LIST_HEAD(nes_dev_list);
32185
32186-atomic_t qps_destroyed;
32187+atomic_unchecked_t qps_destroyed;
32188
32189 static unsigned int ee_flsh_adapter;
32190 static unsigned int sysfs_nonidx_addr;
32191@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32192 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32193 struct nes_adapter *nesadapter = nesdev->nesadapter;
32194
32195- atomic_inc(&qps_destroyed);
32196+ atomic_inc_unchecked(&qps_destroyed);
32197
32198 /* Free the control structures */
32199
32200diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32201index c438e46..ca30356 100644
32202--- a/drivers/infiniband/hw/nes/nes.h
32203+++ b/drivers/infiniband/hw/nes/nes.h
32204@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32205 extern unsigned int wqm_quanta;
32206 extern struct list_head nes_adapter_list;
32207
32208-extern atomic_t cm_connects;
32209-extern atomic_t cm_accepts;
32210-extern atomic_t cm_disconnects;
32211-extern atomic_t cm_closes;
32212-extern atomic_t cm_connecteds;
32213-extern atomic_t cm_connect_reqs;
32214-extern atomic_t cm_rejects;
32215-extern atomic_t mod_qp_timouts;
32216-extern atomic_t qps_created;
32217-extern atomic_t qps_destroyed;
32218-extern atomic_t sw_qps_destroyed;
32219+extern atomic_unchecked_t cm_connects;
32220+extern atomic_unchecked_t cm_accepts;
32221+extern atomic_unchecked_t cm_disconnects;
32222+extern atomic_unchecked_t cm_closes;
32223+extern atomic_unchecked_t cm_connecteds;
32224+extern atomic_unchecked_t cm_connect_reqs;
32225+extern atomic_unchecked_t cm_rejects;
32226+extern atomic_unchecked_t mod_qp_timouts;
32227+extern atomic_unchecked_t qps_created;
32228+extern atomic_unchecked_t qps_destroyed;
32229+extern atomic_unchecked_t sw_qps_destroyed;
32230 extern u32 mh_detected;
32231 extern u32 mh_pauses_sent;
32232 extern u32 cm_packets_sent;
32233@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32234 extern u32 cm_packets_received;
32235 extern u32 cm_packets_dropped;
32236 extern u32 cm_packets_retrans;
32237-extern atomic_t cm_listens_created;
32238-extern atomic_t cm_listens_destroyed;
32239+extern atomic_unchecked_t cm_listens_created;
32240+extern atomic_unchecked_t cm_listens_destroyed;
32241 extern u32 cm_backlog_drops;
32242-extern atomic_t cm_loopbacks;
32243-extern atomic_t cm_nodes_created;
32244-extern atomic_t cm_nodes_destroyed;
32245-extern atomic_t cm_accel_dropped_pkts;
32246-extern atomic_t cm_resets_recvd;
32247-extern atomic_t pau_qps_created;
32248-extern atomic_t pau_qps_destroyed;
32249+extern atomic_unchecked_t cm_loopbacks;
32250+extern atomic_unchecked_t cm_nodes_created;
32251+extern atomic_unchecked_t cm_nodes_destroyed;
32252+extern atomic_unchecked_t cm_accel_dropped_pkts;
32253+extern atomic_unchecked_t cm_resets_recvd;
32254+extern atomic_unchecked_t pau_qps_created;
32255+extern atomic_unchecked_t pau_qps_destroyed;
32256
32257 extern u32 int_mod_timer_init;
32258 extern u32 int_mod_cq_depth_256;
32259diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32260index 020e95c..fbb3450 100644
32261--- a/drivers/infiniband/hw/nes/nes_cm.c
32262+++ b/drivers/infiniband/hw/nes/nes_cm.c
32263@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32264 u32 cm_packets_retrans;
32265 u32 cm_packets_created;
32266 u32 cm_packets_received;
32267-atomic_t cm_listens_created;
32268-atomic_t cm_listens_destroyed;
32269+atomic_unchecked_t cm_listens_created;
32270+atomic_unchecked_t cm_listens_destroyed;
32271 u32 cm_backlog_drops;
32272-atomic_t cm_loopbacks;
32273-atomic_t cm_nodes_created;
32274-atomic_t cm_nodes_destroyed;
32275-atomic_t cm_accel_dropped_pkts;
32276-atomic_t cm_resets_recvd;
32277+atomic_unchecked_t cm_loopbacks;
32278+atomic_unchecked_t cm_nodes_created;
32279+atomic_unchecked_t cm_nodes_destroyed;
32280+atomic_unchecked_t cm_accel_dropped_pkts;
32281+atomic_unchecked_t cm_resets_recvd;
32282
32283 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32284 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32285@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32286
32287 static struct nes_cm_core *g_cm_core;
32288
32289-atomic_t cm_connects;
32290-atomic_t cm_accepts;
32291-atomic_t cm_disconnects;
32292-atomic_t cm_closes;
32293-atomic_t cm_connecteds;
32294-atomic_t cm_connect_reqs;
32295-atomic_t cm_rejects;
32296+atomic_unchecked_t cm_connects;
32297+atomic_unchecked_t cm_accepts;
32298+atomic_unchecked_t cm_disconnects;
32299+atomic_unchecked_t cm_closes;
32300+atomic_unchecked_t cm_connecteds;
32301+atomic_unchecked_t cm_connect_reqs;
32302+atomic_unchecked_t cm_rejects;
32303
32304 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32305 {
32306@@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32307 kfree(listener);
32308 listener = NULL;
32309 ret = 0;
32310- atomic_inc(&cm_listens_destroyed);
32311+ atomic_inc_unchecked(&cm_listens_destroyed);
32312 } else {
32313 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32314 }
32315@@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32316 cm_node->rem_mac);
32317
32318 add_hte_node(cm_core, cm_node);
32319- atomic_inc(&cm_nodes_created);
32320+ atomic_inc_unchecked(&cm_nodes_created);
32321
32322 return cm_node;
32323 }
32324@@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32325 }
32326
32327 atomic_dec(&cm_core->node_cnt);
32328- atomic_inc(&cm_nodes_destroyed);
32329+ atomic_inc_unchecked(&cm_nodes_destroyed);
32330 nesqp = cm_node->nesqp;
32331 if (nesqp) {
32332 nesqp->cm_node = NULL;
32333@@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32334
32335 static void drop_packet(struct sk_buff *skb)
32336 {
32337- atomic_inc(&cm_accel_dropped_pkts);
32338+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32339 dev_kfree_skb_any(skb);
32340 }
32341
32342@@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32343 {
32344
32345 int reset = 0; /* whether to send reset in case of err.. */
32346- atomic_inc(&cm_resets_recvd);
32347+ atomic_inc_unchecked(&cm_resets_recvd);
32348 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32349 " refcnt=%d\n", cm_node, cm_node->state,
32350 atomic_read(&cm_node->ref_count));
32351@@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32352 rem_ref_cm_node(cm_node->cm_core, cm_node);
32353 return NULL;
32354 }
32355- atomic_inc(&cm_loopbacks);
32356+ atomic_inc_unchecked(&cm_loopbacks);
32357 loopbackremotenode->loopbackpartner = cm_node;
32358 loopbackremotenode->tcp_cntxt.rcv_wscale =
32359 NES_CM_DEFAULT_RCV_WND_SCALE;
32360@@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32361 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32362 else {
32363 rem_ref_cm_node(cm_core, cm_node);
32364- atomic_inc(&cm_accel_dropped_pkts);
32365+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32366 dev_kfree_skb_any(skb);
32367 }
32368 break;
32369@@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32370
32371 if ((cm_id) && (cm_id->event_handler)) {
32372 if (issue_disconn) {
32373- atomic_inc(&cm_disconnects);
32374+ atomic_inc_unchecked(&cm_disconnects);
32375 cm_event.event = IW_CM_EVENT_DISCONNECT;
32376 cm_event.status = disconn_status;
32377 cm_event.local_addr = cm_id->local_addr;
32378@@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32379 }
32380
32381 if (issue_close) {
32382- atomic_inc(&cm_closes);
32383+ atomic_inc_unchecked(&cm_closes);
32384 nes_disconnect(nesqp, 1);
32385
32386 cm_id->provider_data = nesqp;
32387@@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32388
32389 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32390 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32391- atomic_inc(&cm_accepts);
32392+ atomic_inc_unchecked(&cm_accepts);
32393
32394 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32395 netdev_refcnt_read(nesvnic->netdev));
32396@@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32397 struct nes_cm_core *cm_core;
32398 u8 *start_buff;
32399
32400- atomic_inc(&cm_rejects);
32401+ atomic_inc_unchecked(&cm_rejects);
32402 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32403 loopback = cm_node->loopbackpartner;
32404 cm_core = cm_node->cm_core;
32405@@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32406 ntohl(cm_id->local_addr.sin_addr.s_addr),
32407 ntohs(cm_id->local_addr.sin_port));
32408
32409- atomic_inc(&cm_connects);
32410+ atomic_inc_unchecked(&cm_connects);
32411 nesqp->active_conn = 1;
32412
32413 /* cache the cm_id in the qp */
32414@@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32415 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32416 return err;
32417 }
32418- atomic_inc(&cm_listens_created);
32419+ atomic_inc_unchecked(&cm_listens_created);
32420 }
32421
32422 cm_id->add_ref(cm_id);
32423@@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32424
32425 if (nesqp->destroyed)
32426 return;
32427- atomic_inc(&cm_connecteds);
32428+ atomic_inc_unchecked(&cm_connecteds);
32429 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32430 " local port 0x%04X. jiffies = %lu.\n",
32431 nesqp->hwqp.qp_id,
32432@@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32433
32434 cm_id->add_ref(cm_id);
32435 ret = cm_id->event_handler(cm_id, &cm_event);
32436- atomic_inc(&cm_closes);
32437+ atomic_inc_unchecked(&cm_closes);
32438 cm_event.event = IW_CM_EVENT_CLOSE;
32439 cm_event.status = 0;
32440 cm_event.provider_data = cm_id->provider_data;
32441@@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32442 return;
32443 cm_id = cm_node->cm_id;
32444
32445- atomic_inc(&cm_connect_reqs);
32446+ atomic_inc_unchecked(&cm_connect_reqs);
32447 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32448 cm_node, cm_id, jiffies);
32449
32450@@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32451 return;
32452 cm_id = cm_node->cm_id;
32453
32454- atomic_inc(&cm_connect_reqs);
32455+ atomic_inc_unchecked(&cm_connect_reqs);
32456 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32457 cm_node, cm_id, jiffies);
32458
32459diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32460index 3ba7be3..c81f6ff 100644
32461--- a/drivers/infiniband/hw/nes/nes_mgt.c
32462+++ b/drivers/infiniband/hw/nes/nes_mgt.c
32463@@ -40,8 +40,8 @@
32464 #include "nes.h"
32465 #include "nes_mgt.h"
32466
32467-atomic_t pau_qps_created;
32468-atomic_t pau_qps_destroyed;
32469+atomic_unchecked_t pau_qps_created;
32470+atomic_unchecked_t pau_qps_destroyed;
32471
32472 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32473 {
32474@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32475 {
32476 struct sk_buff *skb;
32477 unsigned long flags;
32478- atomic_inc(&pau_qps_destroyed);
32479+ atomic_inc_unchecked(&pau_qps_destroyed);
32480
32481 /* Free packets that have not yet been forwarded */
32482 /* Lock is acquired by skb_dequeue when removing the skb */
32483@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32484 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32485 skb_queue_head_init(&nesqp->pau_list);
32486 spin_lock_init(&nesqp->pau_lock);
32487- atomic_inc(&pau_qps_created);
32488+ atomic_inc_unchecked(&pau_qps_created);
32489 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32490 }
32491
32492diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32493index f3a3ecf..57d311d 100644
32494--- a/drivers/infiniband/hw/nes/nes_nic.c
32495+++ b/drivers/infiniband/hw/nes/nes_nic.c
32496@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32497 target_stat_values[++index] = mh_detected;
32498 target_stat_values[++index] = mh_pauses_sent;
32499 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32500- target_stat_values[++index] = atomic_read(&cm_connects);
32501- target_stat_values[++index] = atomic_read(&cm_accepts);
32502- target_stat_values[++index] = atomic_read(&cm_disconnects);
32503- target_stat_values[++index] = atomic_read(&cm_connecteds);
32504- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32505- target_stat_values[++index] = atomic_read(&cm_rejects);
32506- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32507- target_stat_values[++index] = atomic_read(&qps_created);
32508- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32509- target_stat_values[++index] = atomic_read(&qps_destroyed);
32510- target_stat_values[++index] = atomic_read(&cm_closes);
32511+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32512+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32513+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32514+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32515+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32516+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32517+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32518+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32519+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32520+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32521+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32522 target_stat_values[++index] = cm_packets_sent;
32523 target_stat_values[++index] = cm_packets_bounced;
32524 target_stat_values[++index] = cm_packets_created;
32525 target_stat_values[++index] = cm_packets_received;
32526 target_stat_values[++index] = cm_packets_dropped;
32527 target_stat_values[++index] = cm_packets_retrans;
32528- target_stat_values[++index] = atomic_read(&cm_listens_created);
32529- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32530+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32531+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32532 target_stat_values[++index] = cm_backlog_drops;
32533- target_stat_values[++index] = atomic_read(&cm_loopbacks);
32534- target_stat_values[++index] = atomic_read(&cm_nodes_created);
32535- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32536- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32537- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32538+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32539+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32540+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32541+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32542+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32543 target_stat_values[++index] = nesadapter->free_4kpbl;
32544 target_stat_values[++index] = nesadapter->free_256pbl;
32545 target_stat_values[++index] = int_mod_timer_init;
32546 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32547 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32548 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32549- target_stat_values[++index] = atomic_read(&pau_qps_created);
32550- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32551+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32552+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32553 }
32554
32555 /**
32556diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32557index 8b8812d..a5e1133 100644
32558--- a/drivers/infiniband/hw/nes/nes_verbs.c
32559+++ b/drivers/infiniband/hw/nes/nes_verbs.c
32560@@ -46,9 +46,9 @@
32561
32562 #include <rdma/ib_umem.h>
32563
32564-atomic_t mod_qp_timouts;
32565-atomic_t qps_created;
32566-atomic_t sw_qps_destroyed;
32567+atomic_unchecked_t mod_qp_timouts;
32568+atomic_unchecked_t qps_created;
32569+atomic_unchecked_t sw_qps_destroyed;
32570
32571 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32572
32573@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32574 if (init_attr->create_flags)
32575 return ERR_PTR(-EINVAL);
32576
32577- atomic_inc(&qps_created);
32578+ atomic_inc_unchecked(&qps_created);
32579 switch (init_attr->qp_type) {
32580 case IB_QPT_RC:
32581 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32582@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32583 struct iw_cm_event cm_event;
32584 int ret = 0;
32585
32586- atomic_inc(&sw_qps_destroyed);
32587+ atomic_inc_unchecked(&sw_qps_destroyed);
32588 nesqp->destroyed = 1;
32589
32590 /* Blow away the connection if it exists. */
32591diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32592index 7e62f41..4c2b8e2 100644
32593--- a/drivers/infiniband/hw/qib/qib.h
32594+++ b/drivers/infiniband/hw/qib/qib.h
32595@@ -51,6 +51,7 @@
32596 #include <linux/completion.h>
32597 #include <linux/kref.h>
32598 #include <linux/sched.h>
32599+#include <linux/slab.h>
32600
32601 #include "qib_common.h"
32602 #include "qib_verbs.h"
32603diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32604index da739d9..da1c7f4 100644
32605--- a/drivers/input/gameport/gameport.c
32606+++ b/drivers/input/gameport/gameport.c
32607@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32608 */
32609 static void gameport_init_port(struct gameport *gameport)
32610 {
32611- static atomic_t gameport_no = ATOMIC_INIT(0);
32612+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32613
32614 __module_get(THIS_MODULE);
32615
32616 mutex_init(&gameport->drv_mutex);
32617 device_initialize(&gameport->dev);
32618 dev_set_name(&gameport->dev, "gameport%lu",
32619- (unsigned long)atomic_inc_return(&gameport_no) - 1);
32620+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32621 gameport->dev.bus = &gameport_bus;
32622 gameport->dev.release = gameport_release_port;
32623 if (gameport->parent)
32624diff --git a/drivers/input/input.c b/drivers/input/input.c
32625index 8921c61..f5cd63d 100644
32626--- a/drivers/input/input.c
32627+++ b/drivers/input/input.c
32628@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32629 */
32630 int input_register_device(struct input_dev *dev)
32631 {
32632- static atomic_t input_no = ATOMIC_INIT(0);
32633+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32634 struct input_handler *handler;
32635 const char *path;
32636 int error;
32637@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32638 dev->setkeycode = input_default_setkeycode;
32639
32640 dev_set_name(&dev->dev, "input%ld",
32641- (unsigned long) atomic_inc_return(&input_no) - 1);
32642+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32643
32644 error = device_add(&dev->dev);
32645 if (error)
32646diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32647index 04c69af..5f92d00 100644
32648--- a/drivers/input/joystick/sidewinder.c
32649+++ b/drivers/input/joystick/sidewinder.c
32650@@ -30,6 +30,7 @@
32651 #include <linux/kernel.h>
32652 #include <linux/module.h>
32653 #include <linux/slab.h>
32654+#include <linux/sched.h>
32655 #include <linux/init.h>
32656 #include <linux/input.h>
32657 #include <linux/gameport.h>
32658diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32659index 83811e4..0822b90 100644
32660--- a/drivers/input/joystick/xpad.c
32661+++ b/drivers/input/joystick/xpad.c
32662@@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32663
32664 static int xpad_led_probe(struct usb_xpad *xpad)
32665 {
32666- static atomic_t led_seq = ATOMIC_INIT(0);
32667+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32668 long led_no;
32669 struct xpad_led *led;
32670 struct led_classdev *led_cdev;
32671@@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32672 if (!led)
32673 return -ENOMEM;
32674
32675- led_no = (long)atomic_inc_return(&led_seq) - 1;
32676+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32677
32678 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32679 led->xpad = xpad;
32680diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32681index 0110b5a..d3ad144 100644
32682--- a/drivers/input/mousedev.c
32683+++ b/drivers/input/mousedev.c
32684@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32685
32686 spin_unlock_irq(&client->packet_lock);
32687
32688- if (copy_to_user(buffer, data, count))
32689+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
32690 return -EFAULT;
32691
32692 return count;
32693diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32694index d0f7533..fb8215b 100644
32695--- a/drivers/input/serio/serio.c
32696+++ b/drivers/input/serio/serio.c
32697@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32698 */
32699 static void serio_init_port(struct serio *serio)
32700 {
32701- static atomic_t serio_no = ATOMIC_INIT(0);
32702+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32703
32704 __module_get(THIS_MODULE);
32705
32706@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32707 mutex_init(&serio->drv_mutex);
32708 device_initialize(&serio->dev);
32709 dev_set_name(&serio->dev, "serio%ld",
32710- (long)atomic_inc_return(&serio_no) - 1);
32711+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
32712 serio->dev.bus = &serio_bus;
32713 serio->dev.release = serio_release_port;
32714 serio->dev.groups = serio_device_attr_groups;
32715diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32716index 38c4bd8..58965d9 100644
32717--- a/drivers/isdn/capi/capi.c
32718+++ b/drivers/isdn/capi/capi.c
32719@@ -83,8 +83,8 @@ struct capiminor {
32720
32721 struct capi20_appl *ap;
32722 u32 ncci;
32723- atomic_t datahandle;
32724- atomic_t msgid;
32725+ atomic_unchecked_t datahandle;
32726+ atomic_unchecked_t msgid;
32727
32728 struct tty_port port;
32729 int ttyinstop;
32730@@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32731 capimsg_setu16(s, 2, mp->ap->applid);
32732 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32733 capimsg_setu8 (s, 5, CAPI_RESP);
32734- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32735+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32736 capimsg_setu32(s, 8, mp->ncci);
32737 capimsg_setu16(s, 12, datahandle);
32738 }
32739@@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
32740 mp->outbytes -= len;
32741 spin_unlock_bh(&mp->outlock);
32742
32743- datahandle = atomic_inc_return(&mp->datahandle);
32744+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32745 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32746 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32747 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32748 capimsg_setu16(skb->data, 2, mp->ap->applid);
32749 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32750 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32751- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32752+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32753 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32754 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32755 capimsg_setu16(skb->data, 16, len); /* Data length */
32756diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32757index a6d9fd2..afdb8a3 100644
32758--- a/drivers/isdn/gigaset/interface.c
32759+++ b/drivers/isdn/gigaset/interface.c
32760@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32761 }
32762 tty->driver_data = cs;
32763
32764- ++cs->port.count;
32765+ atomic_inc(&cs->port.count);
32766
32767- if (cs->port.count == 1) {
32768+ if (atomic_read(&cs->port.count) == 1) {
32769 tty_port_tty_set(&cs->port, tty);
32770 tty->low_latency = 1;
32771 }
32772@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32773
32774 if (!cs->connected)
32775 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32776- else if (!cs->port.count)
32777+ else if (!atomic_read(&cs->port.count))
32778 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32779- else if (!--cs->port.count)
32780+ else if (!atomic_dec_return(&cs->port.count))
32781 tty_port_tty_set(&cs->port, NULL);
32782
32783 mutex_unlock(&cs->mutex);
32784diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32785index 821f7ac..28d4030 100644
32786--- a/drivers/isdn/hardware/avm/b1.c
32787+++ b/drivers/isdn/hardware/avm/b1.c
32788@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32789 }
32790 if (left) {
32791 if (t4file->user) {
32792- if (copy_from_user(buf, dp, left))
32793+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32794 return -EFAULT;
32795 } else {
32796 memcpy(buf, dp, left);
32797@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32798 }
32799 if (left) {
32800 if (config->user) {
32801- if (copy_from_user(buf, dp, left))
32802+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32803 return -EFAULT;
32804 } else {
32805 memcpy(buf, dp, left);
32806diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32807index dd6b53a..19d9ee6 100644
32808--- a/drivers/isdn/hardware/eicon/divasync.h
32809+++ b/drivers/isdn/hardware/eicon/divasync.h
32810@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32811 } diva_didd_add_adapter_t;
32812 typedef struct _diva_didd_remove_adapter {
32813 IDI_CALL p_request;
32814-} diva_didd_remove_adapter_t;
32815+} __no_const diva_didd_remove_adapter_t;
32816 typedef struct _diva_didd_read_adapter_array {
32817 void *buffer;
32818 dword length;
32819diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32820index d303e65..28bcb7b 100644
32821--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32822+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32823@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32824 typedef struct _diva_os_idi_adapter_interface {
32825 diva_init_card_proc_t cleanup_adapter_proc;
32826 diva_cmd_card_proc_t cmd_proc;
32827-} diva_os_idi_adapter_interface_t;
32828+} __no_const diva_os_idi_adapter_interface_t;
32829
32830 typedef struct _diva_os_xdi_adapter {
32831 struct list_head link;
32832diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
32833index 7bc5067..fd36232 100644
32834--- a/drivers/isdn/i4l/isdn_tty.c
32835+++ b/drivers/isdn/i4l/isdn_tty.c
32836@@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
32837 port = &info->port;
32838 #ifdef ISDN_DEBUG_MODEM_OPEN
32839 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
32840- port->count);
32841+ atomic_read(&port->count))
32842 #endif
32843- port->count++;
32844+ atomic_inc(&port->count);
32845 tty->driver_data = info;
32846 port->tty = tty;
32847 tty->port = port;
32848@@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32849 #endif
32850 return;
32851 }
32852- if ((tty->count == 1) && (port->count != 1)) {
32853+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
32854 /*
32855 * Uh, oh. tty->count is 1, which means that the tty
32856 * structure will be freed. Info->count should always
32857@@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32858 * serial port won't be shutdown.
32859 */
32860 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
32861- "info->count is %d\n", port->count);
32862- port->count = 1;
32863+ "info->count is %d\n", atomic_read(&port->count));
32864+ atomic_set(&port->count, 1);
32865 }
32866- if (--port->count < 0) {
32867+ if (atomic_dec_return(&port->count) < 0) {
32868 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
32869- info->line, port->count);
32870- port->count = 0;
32871+ info->line, atomic_read(&port->count));
32872+ atomic_set(&port->count, 0);
32873 }
32874- if (port->count) {
32875+ if (atomic_read(&port->count)) {
32876 #ifdef ISDN_DEBUG_MODEM_OPEN
32877 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
32878 #endif
32879@@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
32880 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
32881 return;
32882 isdn_tty_shutdown(info);
32883- port->count = 0;
32884+ atomic_set(&port->count, 0);
32885 port->flags &= ~ASYNC_NORMAL_ACTIVE;
32886 port->tty = NULL;
32887 wake_up_interruptible(&port->open_wait);
32888@@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
32889 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
32890 modem_info *info = &dev->mdm.info[i];
32891
32892- if (info->port.count == 0)
32893+ if (atomic_read(&info->port.count) == 0)
32894 continue;
32895 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
32896 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
32897diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32898index e74df7c..03a03ba 100644
32899--- a/drivers/isdn/icn/icn.c
32900+++ b/drivers/isdn/icn/icn.c
32901@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
32902 if (count > len)
32903 count = len;
32904 if (user) {
32905- if (copy_from_user(msg, buf, count))
32906+ if (count > sizeof msg || copy_from_user(msg, buf, count))
32907 return -EFAULT;
32908 } else
32909 memcpy(msg, buf, count);
32910diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32911index b5fdcb7..5b6c59f 100644
32912--- a/drivers/lguest/core.c
32913+++ b/drivers/lguest/core.c
32914@@ -92,9 +92,17 @@ static __init int map_switcher(void)
32915 * it's worked so far. The end address needs +1 because __get_vm_area
32916 * allocates an extra guard page, so we need space for that.
32917 */
32918+
32919+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32920+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32921+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32922+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32923+#else
32924 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32925 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32926 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32927+#endif
32928+
32929 if (!switcher_vma) {
32930 err = -ENOMEM;
32931 printk("lguest: could not map switcher pages high\n");
32932@@ -119,7 +127,7 @@ static __init int map_switcher(void)
32933 * Now the Switcher is mapped at the right address, we can't fail!
32934 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32935 */
32936- memcpy(switcher_vma->addr, start_switcher_text,
32937+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32938 end_switcher_text - start_switcher_text);
32939
32940 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32941diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32942index 39809035..ce25c5e 100644
32943--- a/drivers/lguest/x86/core.c
32944+++ b/drivers/lguest/x86/core.c
32945@@ -59,7 +59,7 @@ static struct {
32946 /* Offset from where switcher.S was compiled to where we've copied it */
32947 static unsigned long switcher_offset(void)
32948 {
32949- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32950+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32951 }
32952
32953 /* This cpu's struct lguest_pages. */
32954@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32955 * These copies are pretty cheap, so we do them unconditionally: */
32956 /* Save the current Host top-level page directory.
32957 */
32958+
32959+#ifdef CONFIG_PAX_PER_CPU_PGD
32960+ pages->state.host_cr3 = read_cr3();
32961+#else
32962 pages->state.host_cr3 = __pa(current->mm->pgd);
32963+#endif
32964+
32965 /*
32966 * Set up the Guest's page tables to see this CPU's pages (and no
32967 * other CPU's pages).
32968@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32969 * compiled-in switcher code and the high-mapped copy we just made.
32970 */
32971 for (i = 0; i < IDT_ENTRIES; i++)
32972- default_idt_entries[i] += switcher_offset();
32973+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32974
32975 /*
32976 * Set up the Switcher's per-cpu areas.
32977@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
32978 * it will be undisturbed when we switch. To change %cs and jump we
32979 * need this structure to feed to Intel's "lcall" instruction.
32980 */
32981- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
32982+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
32983 lguest_entry.segment = LGUEST_CS;
32984
32985 /*
32986diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
32987index 40634b0..4f5855e 100644
32988--- a/drivers/lguest/x86/switcher_32.S
32989+++ b/drivers/lguest/x86/switcher_32.S
32990@@ -87,6 +87,7 @@
32991 #include <asm/page.h>
32992 #include <asm/segment.h>
32993 #include <asm/lguest.h>
32994+#include <asm/processor-flags.h>
32995
32996 // We mark the start of the code to copy
32997 // It's placed in .text tho it's never run here
32998@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
32999 // Changes type when we load it: damn Intel!
33000 // For after we switch over our page tables
33001 // That entry will be read-only: we'd crash.
33002+
33003+#ifdef CONFIG_PAX_KERNEXEC
33004+ mov %cr0, %edx
33005+ xor $X86_CR0_WP, %edx
33006+ mov %edx, %cr0
33007+#endif
33008+
33009 movl $(GDT_ENTRY_TSS*8), %edx
33010 ltr %dx
33011
33012@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33013 // Let's clear it again for our return.
33014 // The GDT descriptor of the Host
33015 // Points to the table after two "size" bytes
33016- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33017+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33018 // Clear "used" from type field (byte 5, bit 2)
33019- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33020+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33021+
33022+#ifdef CONFIG_PAX_KERNEXEC
33023+ mov %cr0, %eax
33024+ xor $X86_CR0_WP, %eax
33025+ mov %eax, %cr0
33026+#endif
33027
33028 // Once our page table's switched, the Guest is live!
33029 // The Host fades as we run this final step.
33030@@ -295,13 +309,12 @@ deliver_to_host:
33031 // I consulted gcc, and it gave
33032 // These instructions, which I gladly credit:
33033 leal (%edx,%ebx,8), %eax
33034- movzwl (%eax),%edx
33035- movl 4(%eax), %eax
33036- xorw %ax, %ax
33037- orl %eax, %edx
33038+ movl 4(%eax), %edx
33039+ movw (%eax), %dx
33040 // Now the address of the handler's in %edx
33041 // We call it now: its "iret" drops us home.
33042- jmp *%edx
33043+ ljmp $__KERNEL_CS, $1f
33044+1: jmp *%edx
33045
33046 // Every interrupt can come to us here
33047 // But we must truly tell each apart.
33048diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33049index 20e5c2c..9e849a9 100644
33050--- a/drivers/macintosh/macio_asic.c
33051+++ b/drivers/macintosh/macio_asic.c
33052@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33053 * MacIO is matched against any Apple ID, it's probe() function
33054 * will then decide wether it applies or not
33055 */
33056-static const struct pci_device_id __devinitdata pci_ids [] = { {
33057+static const struct pci_device_id __devinitconst pci_ids [] = { {
33058 .vendor = PCI_VENDOR_ID_APPLE,
33059 .device = PCI_ANY_ID,
33060 .subvendor = PCI_ANY_ID,
33061diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33062index 15dbe03..743fc65 100644
33063--- a/drivers/md/bitmap.c
33064+++ b/drivers/md/bitmap.c
33065@@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33066 chunk_kb ? "KB" : "B");
33067 if (bitmap->storage.file) {
33068 seq_printf(seq, ", file: ");
33069- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33070+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33071 }
33072
33073 seq_printf(seq, "\n");
33074diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33075index a1a3e6d..1918bfc 100644
33076--- a/drivers/md/dm-ioctl.c
33077+++ b/drivers/md/dm-ioctl.c
33078@@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33079 cmd == DM_LIST_VERSIONS_CMD)
33080 return 0;
33081
33082- if ((cmd == DM_DEV_CREATE_CMD)) {
33083+ if (cmd == DM_DEV_CREATE_CMD) {
33084 if (!*param->name) {
33085 DMWARN("name not supplied when creating device");
33086 return -EINVAL;
33087diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33088index b58b7a3..8018b19 100644
33089--- a/drivers/md/dm-raid1.c
33090+++ b/drivers/md/dm-raid1.c
33091@@ -40,7 +40,7 @@ enum dm_raid1_error {
33092
33093 struct mirror {
33094 struct mirror_set *ms;
33095- atomic_t error_count;
33096+ atomic_unchecked_t error_count;
33097 unsigned long error_type;
33098 struct dm_dev *dev;
33099 sector_t offset;
33100@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33101 struct mirror *m;
33102
33103 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33104- if (!atomic_read(&m->error_count))
33105+ if (!atomic_read_unchecked(&m->error_count))
33106 return m;
33107
33108 return NULL;
33109@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33110 * simple way to tell if a device has encountered
33111 * errors.
33112 */
33113- atomic_inc(&m->error_count);
33114+ atomic_inc_unchecked(&m->error_count);
33115
33116 if (test_and_set_bit(error_type, &m->error_type))
33117 return;
33118@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33119 struct mirror *m = get_default_mirror(ms);
33120
33121 do {
33122- if (likely(!atomic_read(&m->error_count)))
33123+ if (likely(!atomic_read_unchecked(&m->error_count)))
33124 return m;
33125
33126 if (m-- == ms->mirror)
33127@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33128 {
33129 struct mirror *default_mirror = get_default_mirror(m->ms);
33130
33131- return !atomic_read(&default_mirror->error_count);
33132+ return !atomic_read_unchecked(&default_mirror->error_count);
33133 }
33134
33135 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33136@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33137 */
33138 if (likely(region_in_sync(ms, region, 1)))
33139 m = choose_mirror(ms, bio->bi_sector);
33140- else if (m && atomic_read(&m->error_count))
33141+ else if (m && atomic_read_unchecked(&m->error_count))
33142 m = NULL;
33143
33144 if (likely(m))
33145@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33146 }
33147
33148 ms->mirror[mirror].ms = ms;
33149- atomic_set(&(ms->mirror[mirror].error_count), 0);
33150+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33151 ms->mirror[mirror].error_type = 0;
33152 ms->mirror[mirror].offset = offset;
33153
33154@@ -1352,7 +1352,7 @@ static void mirror_resume(struct dm_target *ti)
33155 */
33156 static char device_status_char(struct mirror *m)
33157 {
33158- if (!atomic_read(&(m->error_count)))
33159+ if (!atomic_read_unchecked(&(m->error_count)))
33160 return 'A';
33161
33162 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33163diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33164index 35c94ff..20d4c17 100644
33165--- a/drivers/md/dm-stripe.c
33166+++ b/drivers/md/dm-stripe.c
33167@@ -20,7 +20,7 @@ struct stripe {
33168 struct dm_dev *dev;
33169 sector_t physical_start;
33170
33171- atomic_t error_count;
33172+ atomic_unchecked_t error_count;
33173 };
33174
33175 struct stripe_c {
33176@@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33177 kfree(sc);
33178 return r;
33179 }
33180- atomic_set(&(sc->stripe[i].error_count), 0);
33181+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33182 }
33183
33184 ti->private = sc;
33185@@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33186 DMEMIT("%d ", sc->stripes);
33187 for (i = 0; i < sc->stripes; i++) {
33188 DMEMIT("%s ", sc->stripe[i].dev->name);
33189- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33190+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33191 'D' : 'A';
33192 }
33193 buffer[i] = '\0';
33194@@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33195 */
33196 for (i = 0; i < sc->stripes; i++)
33197 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33198- atomic_inc(&(sc->stripe[i].error_count));
33199- if (atomic_read(&(sc->stripe[i].error_count)) <
33200+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
33201+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33202 DM_IO_ERROR_THRESHOLD)
33203 schedule_work(&sc->trigger_event);
33204 }
33205diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33206index 2e227fb..44ead1f 100644
33207--- a/drivers/md/dm-table.c
33208+++ b/drivers/md/dm-table.c
33209@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33210 if (!dev_size)
33211 return 0;
33212
33213- if ((start >= dev_size) || (start + len > dev_size)) {
33214+ if ((start >= dev_size) || (len > dev_size - start)) {
33215 DMWARN("%s: %s too small for target: "
33216 "start=%llu, len=%llu, dev_size=%llu",
33217 dm_device_name(ti->table->md), bdevname(bdev, b),
33218diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33219index 3e2907f..c28851a 100644
33220--- a/drivers/md/dm-thin-metadata.c
33221+++ b/drivers/md/dm-thin-metadata.c
33222@@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33223
33224 pmd->info.tm = tm;
33225 pmd->info.levels = 2;
33226- pmd->info.value_type.context = pmd->data_sm;
33227+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33228 pmd->info.value_type.size = sizeof(__le64);
33229 pmd->info.value_type.inc = data_block_inc;
33230 pmd->info.value_type.dec = data_block_dec;
33231@@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33232
33233 pmd->bl_info.tm = tm;
33234 pmd->bl_info.levels = 1;
33235- pmd->bl_info.value_type.context = pmd->data_sm;
33236+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33237 pmd->bl_info.value_type.size = sizeof(__le64);
33238 pmd->bl_info.value_type.inc = data_block_inc;
33239 pmd->bl_info.value_type.dec = data_block_dec;
33240diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33241index e24143c..ce2f21a1 100644
33242--- a/drivers/md/dm.c
33243+++ b/drivers/md/dm.c
33244@@ -176,9 +176,9 @@ struct mapped_device {
33245 /*
33246 * Event handling.
33247 */
33248- atomic_t event_nr;
33249+ atomic_unchecked_t event_nr;
33250 wait_queue_head_t eventq;
33251- atomic_t uevent_seq;
33252+ atomic_unchecked_t uevent_seq;
33253 struct list_head uevent_list;
33254 spinlock_t uevent_lock; /* Protect access to uevent_list */
33255
33256@@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33257 rwlock_init(&md->map_lock);
33258 atomic_set(&md->holders, 1);
33259 atomic_set(&md->open_count, 0);
33260- atomic_set(&md->event_nr, 0);
33261- atomic_set(&md->uevent_seq, 0);
33262+ atomic_set_unchecked(&md->event_nr, 0);
33263+ atomic_set_unchecked(&md->uevent_seq, 0);
33264 INIT_LIST_HEAD(&md->uevent_list);
33265 spin_lock_init(&md->uevent_lock);
33266
33267@@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33268
33269 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33270
33271- atomic_inc(&md->event_nr);
33272+ atomic_inc_unchecked(&md->event_nr);
33273 wake_up(&md->eventq);
33274 }
33275
33276@@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33277
33278 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33279 {
33280- return atomic_add_return(1, &md->uevent_seq);
33281+ return atomic_add_return_unchecked(1, &md->uevent_seq);
33282 }
33283
33284 uint32_t dm_get_event_nr(struct mapped_device *md)
33285 {
33286- return atomic_read(&md->event_nr);
33287+ return atomic_read_unchecked(&md->event_nr);
33288 }
33289
33290 int dm_wait_event(struct mapped_device *md, int event_nr)
33291 {
33292 return wait_event_interruptible(md->eventq,
33293- (event_nr != atomic_read(&md->event_nr)));
33294+ (event_nr != atomic_read_unchecked(&md->event_nr)));
33295 }
33296
33297 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33298diff --git a/drivers/md/md.c b/drivers/md/md.c
33299index d5ab449..7e9ed7b 100644
33300--- a/drivers/md/md.c
33301+++ b/drivers/md/md.c
33302@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33303 * start build, activate spare
33304 */
33305 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33306-static atomic_t md_event_count;
33307+static atomic_unchecked_t md_event_count;
33308 void md_new_event(struct mddev *mddev)
33309 {
33310- atomic_inc(&md_event_count);
33311+ atomic_inc_unchecked(&md_event_count);
33312 wake_up(&md_event_waiters);
33313 }
33314 EXPORT_SYMBOL_GPL(md_new_event);
33315@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33316 */
33317 static void md_new_event_inintr(struct mddev *mddev)
33318 {
33319- atomic_inc(&md_event_count);
33320+ atomic_inc_unchecked(&md_event_count);
33321 wake_up(&md_event_waiters);
33322 }
33323
33324@@ -1565,7 +1565,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33325 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33326 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33327 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33328- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33329+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33330
33331 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33332 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33333@@ -1809,7 +1809,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33334 else
33335 sb->resync_offset = cpu_to_le64(0);
33336
33337- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33338+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33339
33340 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33341 sb->size = cpu_to_le64(mddev->dev_sectors);
33342@@ -2803,7 +2803,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33343 static ssize_t
33344 errors_show(struct md_rdev *rdev, char *page)
33345 {
33346- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33347+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33348 }
33349
33350 static ssize_t
33351@@ -2812,7 +2812,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33352 char *e;
33353 unsigned long n = simple_strtoul(buf, &e, 10);
33354 if (*buf && (*e == 0 || *e == '\n')) {
33355- atomic_set(&rdev->corrected_errors, n);
33356+ atomic_set_unchecked(&rdev->corrected_errors, n);
33357 return len;
33358 }
33359 return -EINVAL;
33360@@ -3259,8 +3259,8 @@ int md_rdev_init(struct md_rdev *rdev)
33361 rdev->sb_loaded = 0;
33362 rdev->bb_page = NULL;
33363 atomic_set(&rdev->nr_pending, 0);
33364- atomic_set(&rdev->read_errors, 0);
33365- atomic_set(&rdev->corrected_errors, 0);
33366+ atomic_set_unchecked(&rdev->read_errors, 0);
33367+ atomic_set_unchecked(&rdev->corrected_errors, 0);
33368
33369 INIT_LIST_HEAD(&rdev->same_set);
33370 init_waitqueue_head(&rdev->blocked_wait);
33371@@ -6997,7 +6997,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33372
33373 spin_unlock(&pers_lock);
33374 seq_printf(seq, "\n");
33375- seq->poll_event = atomic_read(&md_event_count);
33376+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33377 return 0;
33378 }
33379 if (v == (void*)2) {
33380@@ -7100,7 +7100,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33381 return error;
33382
33383 seq = file->private_data;
33384- seq->poll_event = atomic_read(&md_event_count);
33385+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33386 return error;
33387 }
33388
33389@@ -7114,7 +7114,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33390 /* always allow read */
33391 mask = POLLIN | POLLRDNORM;
33392
33393- if (seq->poll_event != atomic_read(&md_event_count))
33394+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33395 mask |= POLLERR | POLLPRI;
33396 return mask;
33397 }
33398@@ -7158,7 +7158,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33399 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33400 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33401 (int)part_stat_read(&disk->part0, sectors[1]) -
33402- atomic_read(&disk->sync_io);
33403+ atomic_read_unchecked(&disk->sync_io);
33404 /* sync IO will cause sync_io to increase before the disk_stats
33405 * as sync_io is counted when a request starts, and
33406 * disk_stats is counted when it completes.
33407diff --git a/drivers/md/md.h b/drivers/md/md.h
33408index 7b4a3c3..994ad4f 100644
33409--- a/drivers/md/md.h
33410+++ b/drivers/md/md.h
33411@@ -94,13 +94,13 @@ struct md_rdev {
33412 * only maintained for arrays that
33413 * support hot removal
33414 */
33415- atomic_t read_errors; /* number of consecutive read errors that
33416+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
33417 * we have tried to ignore.
33418 */
33419 struct timespec last_read_error; /* monotonic time since our
33420 * last read error
33421 */
33422- atomic_t corrected_errors; /* number of corrected read errors,
33423+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33424 * for reporting to userspace and storing
33425 * in superblock.
33426 */
33427@@ -435,7 +435,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33428
33429 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33430 {
33431- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33432+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33433 }
33434
33435 struct md_personality
33436diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33437index fc90c11..c8cd9a9 100644
33438--- a/drivers/md/persistent-data/dm-space-map-checker.c
33439+++ b/drivers/md/persistent-data/dm-space-map-checker.c
33440@@ -167,7 +167,7 @@ static int ca_commit(struct count_array *old, struct count_array *new)
33441 /*----------------------------------------------------------------*/
33442
33443 struct sm_checker {
33444- struct dm_space_map sm;
33445+ dm_space_map_no_const sm;
33446
33447 struct count_array old_counts;
33448 struct count_array counts;
33449diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33450index 3d0ed53..35dc592 100644
33451--- a/drivers/md/persistent-data/dm-space-map-disk.c
33452+++ b/drivers/md/persistent-data/dm-space-map-disk.c
33453@@ -23,7 +23,7 @@
33454 * Space map interface.
33455 */
33456 struct sm_disk {
33457- struct dm_space_map sm;
33458+ dm_space_map_no_const sm;
33459
33460 struct ll_disk ll;
33461 struct ll_disk old_ll;
33462diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33463index e89ae5e..062e4c2 100644
33464--- a/drivers/md/persistent-data/dm-space-map-metadata.c
33465+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33466@@ -43,7 +43,7 @@ struct block_op {
33467 };
33468
33469 struct sm_metadata {
33470- struct dm_space_map sm;
33471+ dm_space_map_no_const sm;
33472
33473 struct ll_disk ll;
33474 struct ll_disk old_ll;
33475diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33476index 1cbfc6b..56e1dbb 100644
33477--- a/drivers/md/persistent-data/dm-space-map.h
33478+++ b/drivers/md/persistent-data/dm-space-map.h
33479@@ -60,6 +60,7 @@ struct dm_space_map {
33480 int (*root_size)(struct dm_space_map *sm, size_t *result);
33481 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33482 };
33483+typedef struct dm_space_map __no_const dm_space_map_no_const;
33484
33485 /*----------------------------------------------------------------*/
33486
33487diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33488index cacd008..2823610 100644
33489--- a/drivers/md/raid1.c
33490+++ b/drivers/md/raid1.c
33491@@ -1685,7 +1685,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33492 if (r1_sync_page_io(rdev, sect, s,
33493 bio->bi_io_vec[idx].bv_page,
33494 READ) != 0)
33495- atomic_add(s, &rdev->corrected_errors);
33496+ atomic_add_unchecked(s, &rdev->corrected_errors);
33497 }
33498 sectors -= s;
33499 sect += s;
33500@@ -1907,7 +1907,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33501 test_bit(In_sync, &rdev->flags)) {
33502 if (r1_sync_page_io(rdev, sect, s,
33503 conf->tmppage, READ)) {
33504- atomic_add(s, &rdev->corrected_errors);
33505+ atomic_add_unchecked(s, &rdev->corrected_errors);
33506 printk(KERN_INFO
33507 "md/raid1:%s: read error corrected "
33508 "(%d sectors at %llu on %s)\n",
33509diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33510index 8da6282..8ec7103 100644
33511--- a/drivers/md/raid10.c
33512+++ b/drivers/md/raid10.c
33513@@ -1784,7 +1784,7 @@ static void end_sync_read(struct bio *bio, int error)
33514 /* The write handler will notice the lack of
33515 * R10BIO_Uptodate and record any errors etc
33516 */
33517- atomic_add(r10_bio->sectors,
33518+ atomic_add_unchecked(r10_bio->sectors,
33519 &conf->mirrors[d].rdev->corrected_errors);
33520
33521 /* for reconstruct, we always reschedule after a read.
33522@@ -2133,7 +2133,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33523 {
33524 struct timespec cur_time_mon;
33525 unsigned long hours_since_last;
33526- unsigned int read_errors = atomic_read(&rdev->read_errors);
33527+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33528
33529 ktime_get_ts(&cur_time_mon);
33530
33531@@ -2155,9 +2155,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33532 * overflowing the shift of read_errors by hours_since_last.
33533 */
33534 if (hours_since_last >= 8 * sizeof(read_errors))
33535- atomic_set(&rdev->read_errors, 0);
33536+ atomic_set_unchecked(&rdev->read_errors, 0);
33537 else
33538- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33539+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33540 }
33541
33542 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33543@@ -2211,8 +2211,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33544 return;
33545
33546 check_decay_read_errors(mddev, rdev);
33547- atomic_inc(&rdev->read_errors);
33548- if (atomic_read(&rdev->read_errors) > max_read_errors) {
33549+ atomic_inc_unchecked(&rdev->read_errors);
33550+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33551 char b[BDEVNAME_SIZE];
33552 bdevname(rdev->bdev, b);
33553
33554@@ -2220,7 +2220,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33555 "md/raid10:%s: %s: Raid device exceeded "
33556 "read_error threshold [cur %d:max %d]\n",
33557 mdname(mddev), b,
33558- atomic_read(&rdev->read_errors), max_read_errors);
33559+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33560 printk(KERN_NOTICE
33561 "md/raid10:%s: %s: Failing raid device\n",
33562 mdname(mddev), b);
33563@@ -2375,7 +2375,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33564 sect +
33565 choose_data_offset(r10_bio, rdev)),
33566 bdevname(rdev->bdev, b));
33567- atomic_add(s, &rdev->corrected_errors);
33568+ atomic_add_unchecked(s, &rdev->corrected_errors);
33569 }
33570
33571 rdev_dec_pending(rdev, mddev);
33572diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33573index 04348d7..62a4b9b 100644
33574--- a/drivers/md/raid5.c
33575+++ b/drivers/md/raid5.c
33576@@ -1736,19 +1736,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
33577 mdname(conf->mddev), STRIPE_SECTORS,
33578 (unsigned long long)s,
33579 bdevname(rdev->bdev, b));
33580- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33581+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33582 clear_bit(R5_ReadError, &sh->dev[i].flags);
33583 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33584 }
33585- if (atomic_read(&rdev->read_errors))
33586- atomic_set(&rdev->read_errors, 0);
33587+ if (atomic_read_unchecked(&rdev->read_errors))
33588+ atomic_set_unchecked(&rdev->read_errors, 0);
33589 } else {
33590 const char *bdn = bdevname(rdev->bdev, b);
33591 int retry = 0;
33592 int set_bad = 0;
33593
33594 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33595- atomic_inc(&rdev->read_errors);
33596+ atomic_inc_unchecked(&rdev->read_errors);
33597 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33598 printk_ratelimited(
33599 KERN_WARNING
33600@@ -1776,7 +1776,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33601 mdname(conf->mddev),
33602 (unsigned long long)s,
33603 bdn);
33604- } else if (atomic_read(&rdev->read_errors)
33605+ } else if (atomic_read_unchecked(&rdev->read_errors)
33606 > conf->max_nr_stripes)
33607 printk(KERN_WARNING
33608 "md/raid:%s: Too many read errors, failing device %s.\n",
33609diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33610index 131b938..8572ed1 100644
33611--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33612+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33613@@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33614 .subvendor = _subvend, .subdevice = _subdev, \
33615 .driver_data = (unsigned long)&_driverdata }
33616
33617-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33618+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33619 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33620 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33621 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33622diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33623index fa7188a..04a045e 100644
33624--- a/drivers/media/dvb/dvb-core/dvb_demux.h
33625+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33626@@ -73,7 +73,7 @@ struct dvb_demux_feed {
33627 union {
33628 dmx_ts_cb ts;
33629 dmx_section_cb sec;
33630- } cb;
33631+ } __no_const cb;
33632
33633 struct dvb_demux *demux;
33634 void *priv;
33635diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33636index 39eab73..60033e7 100644
33637--- a/drivers/media/dvb/dvb-core/dvbdev.c
33638+++ b/drivers/media/dvb/dvb-core/dvbdev.c
33639@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33640 const struct dvb_device *template, void *priv, int type)
33641 {
33642 struct dvb_device *dvbdev;
33643- struct file_operations *dvbdevfops;
33644+ file_operations_no_const *dvbdevfops;
33645 struct device *clsdev;
33646 int minor;
33647 int id;
33648diff --git a/drivers/media/dvb/dvb-usb/az6007.c b/drivers/media/dvb/dvb-usb/az6007.c
33649index 4008b9c..ce714f5 100644
33650--- a/drivers/media/dvb/dvb-usb/az6007.c
33651+++ b/drivers/media/dvb/dvb-usb/az6007.c
33652@@ -590,7 +590,7 @@ static int az6007_read_mac_addr(struct dvb_usb_device *d, u8 mac[6])
33653 int ret;
33654
33655 ret = az6007_read(d, AZ6007_READ_DATA, 6, 0, st->data, 6);
33656- memcpy(mac, st->data, sizeof(mac));
33657+ memcpy(mac, st->data, 6);
33658
33659 if (ret > 0)
33660 deb_info("%s: mac is %02x:%02x:%02x:%02x:%02x:%02x\n",
33661diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33662index 3940bb0..fb3952a 100644
33663--- a/drivers/media/dvb/dvb-usb/cxusb.c
33664+++ b/drivers/media/dvb/dvb-usb/cxusb.c
33665@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33666
33667 struct dib0700_adapter_state {
33668 int (*set_param_save) (struct dvb_frontend *);
33669-};
33670+} __no_const;
33671
33672 static int dib7070_set_param_override(struct dvb_frontend *fe)
33673 {
33674diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33675index 9382895..ac8093c 100644
33676--- a/drivers/media/dvb/dvb-usb/dw2102.c
33677+++ b/drivers/media/dvb/dvb-usb/dw2102.c
33678@@ -95,7 +95,7 @@ struct su3000_state {
33679
33680 struct s6x0_state {
33681 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33682-};
33683+} __no_const;
33684
33685 /* debug */
33686 static int dvb_usb_dw2102_debug;
33687diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33688index 404f63a..4796533 100644
33689--- a/drivers/media/dvb/frontends/dib3000.h
33690+++ b/drivers/media/dvb/frontends/dib3000.h
33691@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33692 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33693 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33694 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33695-};
33696+} __no_const;
33697
33698 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33699 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33700diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33701index 7539a5d..06531a6 100644
33702--- a/drivers/media/dvb/ngene/ngene-cards.c
33703+++ b/drivers/media/dvb/ngene/ngene-cards.c
33704@@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33705
33706 /****************************************************************************/
33707
33708-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33709+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33710 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33711 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33712 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33713diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33714index 16a089f..1661b11 100644
33715--- a/drivers/media/radio/radio-cadet.c
33716+++ b/drivers/media/radio/radio-cadet.c
33717@@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33718 unsigned char readbuf[RDS_BUFFER];
33719 int i = 0;
33720
33721+ if (count > RDS_BUFFER)
33722+ return -EFAULT;
33723 mutex_lock(&dev->lock);
33724 if (dev->rdsstat == 0) {
33725 dev->rdsstat = 1;
33726@@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33727 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33728 mutex_unlock(&dev->lock);
33729
33730- if (copy_to_user(data, readbuf, i))
33731+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33732 return -EFAULT;
33733 return i;
33734 }
33735diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33736index 9cde353..8c6a1c3 100644
33737--- a/drivers/media/video/au0828/au0828.h
33738+++ b/drivers/media/video/au0828/au0828.h
33739@@ -191,7 +191,7 @@ struct au0828_dev {
33740
33741 /* I2C */
33742 struct i2c_adapter i2c_adap;
33743- struct i2c_algorithm i2c_algo;
33744+ i2c_algorithm_no_const i2c_algo;
33745 struct i2c_client i2c_client;
33746 u32 i2c_rc;
33747
33748diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33749index 04bf662..e0ac026 100644
33750--- a/drivers/media/video/cx88/cx88-alsa.c
33751+++ b/drivers/media/video/cx88/cx88-alsa.c
33752@@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33753 * Only boards with eeprom and byte 1 at eeprom=1 have it
33754 */
33755
33756-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33757+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33758 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33759 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33760 {0, }
33761diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33762index 88cf9d9..bbc4b2c 100644
33763--- a/drivers/media/video/omap/omap_vout.c
33764+++ b/drivers/media/video/omap/omap_vout.c
33765@@ -64,7 +64,6 @@ enum omap_vout_channels {
33766 OMAP_VIDEO2,
33767 };
33768
33769-static struct videobuf_queue_ops video_vbq_ops;
33770 /* Variables configurable through module params*/
33771 static u32 video1_numbuffers = 3;
33772 static u32 video2_numbuffers = 3;
33773@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33774 {
33775 struct videobuf_queue *q;
33776 struct omap_vout_device *vout = NULL;
33777+ static struct videobuf_queue_ops video_vbq_ops = {
33778+ .buf_setup = omap_vout_buffer_setup,
33779+ .buf_prepare = omap_vout_buffer_prepare,
33780+ .buf_release = omap_vout_buffer_release,
33781+ .buf_queue = omap_vout_buffer_queue,
33782+ };
33783
33784 vout = video_drvdata(file);
33785 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33786@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33787 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33788
33789 q = &vout->vbq;
33790- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33791- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33792- video_vbq_ops.buf_release = omap_vout_buffer_release;
33793- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33794 spin_lock_init(&vout->vbq_lock);
33795
33796 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33797diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33798index 036952f..80d356d 100644
33799--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33800+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33801@@ -196,7 +196,7 @@ struct pvr2_hdw {
33802
33803 /* I2C stuff */
33804 struct i2c_adapter i2c_adap;
33805- struct i2c_algorithm i2c_algo;
33806+ i2c_algorithm_no_const i2c_algo;
33807 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33808 int i2c_cx25840_hack_state;
33809 int i2c_linked;
33810diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33811index 02194c0..091733b 100644
33812--- a/drivers/media/video/timblogiw.c
33813+++ b/drivers/media/video/timblogiw.c
33814@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33815
33816 /* Platform device functions */
33817
33818-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33819+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33820 .vidioc_querycap = timblogiw_querycap,
33821 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33822 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33823@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33824 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33825 };
33826
33827-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33828+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33829 .owner = THIS_MODULE,
33830 .open = timblogiw_open,
33831 .release = timblogiw_close,
33832diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33833index d99db56..a16b959 100644
33834--- a/drivers/message/fusion/mptbase.c
33835+++ b/drivers/message/fusion/mptbase.c
33836@@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33837 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33838 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33839
33840+#ifdef CONFIG_GRKERNSEC_HIDESYM
33841+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33842+#else
33843 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33844 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33845+#endif
33846+
33847 /*
33848 * Rounding UP to nearest 4-kB boundary here...
33849 */
33850diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33851index 551262e..7551198 100644
33852--- a/drivers/message/fusion/mptsas.c
33853+++ b/drivers/message/fusion/mptsas.c
33854@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33855 return 0;
33856 }
33857
33858+static inline void
33859+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33860+{
33861+ if (phy_info->port_details) {
33862+ phy_info->port_details->rphy = rphy;
33863+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33864+ ioc->name, rphy));
33865+ }
33866+
33867+ if (rphy) {
33868+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33869+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33870+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33871+ ioc->name, rphy, rphy->dev.release));
33872+ }
33873+}
33874+
33875 /* no mutex */
33876 static void
33877 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33878@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33879 return NULL;
33880 }
33881
33882-static inline void
33883-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33884-{
33885- if (phy_info->port_details) {
33886- phy_info->port_details->rphy = rphy;
33887- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33888- ioc->name, rphy));
33889- }
33890-
33891- if (rphy) {
33892- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33893- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33894- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33895- ioc->name, rphy, rphy->dev.release));
33896- }
33897-}
33898-
33899 static inline struct sas_port *
33900 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33901 {
33902diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33903index 0c3ced7..1fe34ec 100644
33904--- a/drivers/message/fusion/mptscsih.c
33905+++ b/drivers/message/fusion/mptscsih.c
33906@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33907
33908 h = shost_priv(SChost);
33909
33910- if (h) {
33911- if (h->info_kbuf == NULL)
33912- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33913- return h->info_kbuf;
33914- h->info_kbuf[0] = '\0';
33915+ if (!h)
33916+ return NULL;
33917
33918- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33919- h->info_kbuf[size-1] = '\0';
33920- }
33921+ if (h->info_kbuf == NULL)
33922+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33923+ return h->info_kbuf;
33924+ h->info_kbuf[0] = '\0';
33925+
33926+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33927+ h->info_kbuf[size-1] = '\0';
33928
33929 return h->info_kbuf;
33930 }
33931diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
33932index 506c36f..b137580 100644
33933--- a/drivers/message/i2o/i2o_proc.c
33934+++ b/drivers/message/i2o/i2o_proc.c
33935@@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33936 "Array Controller Device"
33937 };
33938
33939-static char *chtostr(u8 * chars, int n)
33940-{
33941- char tmp[256];
33942- tmp[0] = 0;
33943- return strncat(tmp, (char *)chars, n);
33944-}
33945-
33946 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33947 char *group)
33948 {
33949@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
33950
33951 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33952 seq_printf(seq, "%-#8x", ddm_table.module_id);
33953- seq_printf(seq, "%-29s",
33954- chtostr(ddm_table.module_name_version, 28));
33955+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33956 seq_printf(seq, "%9d ", ddm_table.data_size);
33957 seq_printf(seq, "%8d", ddm_table.code_size);
33958
33959@@ -927,8 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
33960
33961 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33962 seq_printf(seq, "%-#8x", dst->module_id);
33963- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33964- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33965+ seq_printf(seq, "%-.28s", dst->module_name_version);
33966+ seq_printf(seq, "%-.8s", dst->date);
33967 seq_printf(seq, "%8d ", dst->module_size);
33968 seq_printf(seq, "%8d ", dst->mpb_size);
33969 seq_printf(seq, "0x%04x", dst->module_flags);
33970@@ -1259,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
33971 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33972 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33973 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33974- seq_printf(seq, "Vendor info : %s\n",
33975- chtostr((u8 *) (work32 + 2), 16));
33976- seq_printf(seq, "Product info : %s\n",
33977- chtostr((u8 *) (work32 + 6), 16));
33978- seq_printf(seq, "Description : %s\n",
33979- chtostr((u8 *) (work32 + 10), 16));
33980- seq_printf(seq, "Product rev. : %s\n",
33981- chtostr((u8 *) (work32 + 14), 8));
33982+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33983+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33984+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33985+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33986
33987 seq_printf(seq, "Serial number : ");
33988 print_serial_number(seq, (u8 *) (work32 + 16),
33989@@ -1311,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
33990 }
33991
33992 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33993- seq_printf(seq, "Module name : %s\n",
33994- chtostr(result.module_name, 24));
33995- seq_printf(seq, "Module revision : %s\n",
33996- chtostr(result.module_rev, 8));
33997+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
33998+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
33999
34000 seq_printf(seq, "Serial number : ");
34001 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34002@@ -1345,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34003 return 0;
34004 }
34005
34006- seq_printf(seq, "Device name : %s\n",
34007- chtostr(result.device_name, 64));
34008- seq_printf(seq, "Service name : %s\n",
34009- chtostr(result.service_name, 64));
34010- seq_printf(seq, "Physical name : %s\n",
34011- chtostr(result.physical_location, 64));
34012- seq_printf(seq, "Instance number : %s\n",
34013- chtostr(result.instance_number, 4));
34014+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
34015+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
34016+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34017+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34018
34019 return 0;
34020 }
34021diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34022index a8c08f3..155fe3d 100644
34023--- a/drivers/message/i2o/iop.c
34024+++ b/drivers/message/i2o/iop.c
34025@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34026
34027 spin_lock_irqsave(&c->context_list_lock, flags);
34028
34029- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34030- atomic_inc(&c->context_list_counter);
34031+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34032+ atomic_inc_unchecked(&c->context_list_counter);
34033
34034- entry->context = atomic_read(&c->context_list_counter);
34035+ entry->context = atomic_read_unchecked(&c->context_list_counter);
34036
34037 list_add(&entry->list, &c->context_list);
34038
34039@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34040
34041 #if BITS_PER_LONG == 64
34042 spin_lock_init(&c->context_list_lock);
34043- atomic_set(&c->context_list_counter, 0);
34044+ atomic_set_unchecked(&c->context_list_counter, 0);
34045 INIT_LIST_HEAD(&c->context_list);
34046 #endif
34047
34048diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34049index 7ce65f4..e66e9bc 100644
34050--- a/drivers/mfd/abx500-core.c
34051+++ b/drivers/mfd/abx500-core.c
34052@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34053
34054 struct abx500_device_entry {
34055 struct list_head list;
34056- struct abx500_ops ops;
34057+ abx500_ops_no_const ops;
34058 struct device *dev;
34059 };
34060
34061diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34062index 2ea9998..51dabee 100644
34063--- a/drivers/mfd/janz-cmodio.c
34064+++ b/drivers/mfd/janz-cmodio.c
34065@@ -13,6 +13,7 @@
34066
34067 #include <linux/kernel.h>
34068 #include <linux/module.h>
34069+#include <linux/slab.h>
34070 #include <linux/init.h>
34071 #include <linux/pci.h>
34072 #include <linux/interrupt.h>
34073diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34074index a981e2a..5ca0c8b 100644
34075--- a/drivers/misc/lis3lv02d/lis3lv02d.c
34076+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34077@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34078 * the lid is closed. This leads to interrupts as soon as a little move
34079 * is done.
34080 */
34081- atomic_inc(&lis3->count);
34082+ atomic_inc_unchecked(&lis3->count);
34083
34084 wake_up_interruptible(&lis3->misc_wait);
34085 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34086@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34087 if (lis3->pm_dev)
34088 pm_runtime_get_sync(lis3->pm_dev);
34089
34090- atomic_set(&lis3->count, 0);
34091+ atomic_set_unchecked(&lis3->count, 0);
34092 return 0;
34093 }
34094
34095@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34096 add_wait_queue(&lis3->misc_wait, &wait);
34097 while (true) {
34098 set_current_state(TASK_INTERRUPTIBLE);
34099- data = atomic_xchg(&lis3->count, 0);
34100+ data = atomic_xchg_unchecked(&lis3->count, 0);
34101 if (data)
34102 break;
34103
34104@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34105 struct lis3lv02d, miscdev);
34106
34107 poll_wait(file, &lis3->misc_wait, wait);
34108- if (atomic_read(&lis3->count))
34109+ if (atomic_read_unchecked(&lis3->count))
34110 return POLLIN | POLLRDNORM;
34111 return 0;
34112 }
34113diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34114index 2b1482a..5d33616 100644
34115--- a/drivers/misc/lis3lv02d/lis3lv02d.h
34116+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34117@@ -266,7 +266,7 @@ struct lis3lv02d {
34118 struct input_polled_dev *idev; /* input device */
34119 struct platform_device *pdev; /* platform device */
34120 struct regulator_bulk_data regulators[2];
34121- atomic_t count; /* interrupt count after last read */
34122+ atomic_unchecked_t count; /* interrupt count after last read */
34123 union axis_conversion ac; /* hw -> logical axis */
34124 int mapped_btns[3];
34125
34126diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
34127index 28adefe..08aad69 100644
34128--- a/drivers/misc/lkdtm.c
34129+++ b/drivers/misc/lkdtm.c
34130@@ -477,6 +477,8 @@ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
34131 int i, n, out;
34132
34133 buf = (char *)__get_free_page(GFP_KERNEL);
34134+ if (buf == NULL)
34135+ return -ENOMEM;
34136
34137 n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
34138 for (i = 0; i < ARRAY_SIZE(cp_type); i++)
34139diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34140index 2f30bad..c4c13d0 100644
34141--- a/drivers/misc/sgi-gru/gruhandles.c
34142+++ b/drivers/misc/sgi-gru/gruhandles.c
34143@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34144 unsigned long nsec;
34145
34146 nsec = CLKS2NSEC(clks);
34147- atomic_long_inc(&mcs_op_statistics[op].count);
34148- atomic_long_add(nsec, &mcs_op_statistics[op].total);
34149+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34150+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34151 if (mcs_op_statistics[op].max < nsec)
34152 mcs_op_statistics[op].max = nsec;
34153 }
34154diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34155index 950dbe9..eeef0f8 100644
34156--- a/drivers/misc/sgi-gru/gruprocfs.c
34157+++ b/drivers/misc/sgi-gru/gruprocfs.c
34158@@ -32,9 +32,9 @@
34159
34160 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34161
34162-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34163+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34164 {
34165- unsigned long val = atomic_long_read(v);
34166+ unsigned long val = atomic_long_read_unchecked(v);
34167
34168 seq_printf(s, "%16lu %s\n", val, id);
34169 }
34170@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34171
34172 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34173 for (op = 0; op < mcsop_last; op++) {
34174- count = atomic_long_read(&mcs_op_statistics[op].count);
34175- total = atomic_long_read(&mcs_op_statistics[op].total);
34176+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34177+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34178 max = mcs_op_statistics[op].max;
34179 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34180 count ? total / count : 0, max);
34181diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34182index 5c3ce24..4915ccb 100644
34183--- a/drivers/misc/sgi-gru/grutables.h
34184+++ b/drivers/misc/sgi-gru/grutables.h
34185@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34186 * GRU statistics.
34187 */
34188 struct gru_stats_s {
34189- atomic_long_t vdata_alloc;
34190- atomic_long_t vdata_free;
34191- atomic_long_t gts_alloc;
34192- atomic_long_t gts_free;
34193- atomic_long_t gms_alloc;
34194- atomic_long_t gms_free;
34195- atomic_long_t gts_double_allocate;
34196- atomic_long_t assign_context;
34197- atomic_long_t assign_context_failed;
34198- atomic_long_t free_context;
34199- atomic_long_t load_user_context;
34200- atomic_long_t load_kernel_context;
34201- atomic_long_t lock_kernel_context;
34202- atomic_long_t unlock_kernel_context;
34203- atomic_long_t steal_user_context;
34204- atomic_long_t steal_kernel_context;
34205- atomic_long_t steal_context_failed;
34206- atomic_long_t nopfn;
34207- atomic_long_t asid_new;
34208- atomic_long_t asid_next;
34209- atomic_long_t asid_wrap;
34210- atomic_long_t asid_reuse;
34211- atomic_long_t intr;
34212- atomic_long_t intr_cbr;
34213- atomic_long_t intr_tfh;
34214- atomic_long_t intr_spurious;
34215- atomic_long_t intr_mm_lock_failed;
34216- atomic_long_t call_os;
34217- atomic_long_t call_os_wait_queue;
34218- atomic_long_t user_flush_tlb;
34219- atomic_long_t user_unload_context;
34220- atomic_long_t user_exception;
34221- atomic_long_t set_context_option;
34222- atomic_long_t check_context_retarget_intr;
34223- atomic_long_t check_context_unload;
34224- atomic_long_t tlb_dropin;
34225- atomic_long_t tlb_preload_page;
34226- atomic_long_t tlb_dropin_fail_no_asid;
34227- atomic_long_t tlb_dropin_fail_upm;
34228- atomic_long_t tlb_dropin_fail_invalid;
34229- atomic_long_t tlb_dropin_fail_range_active;
34230- atomic_long_t tlb_dropin_fail_idle;
34231- atomic_long_t tlb_dropin_fail_fmm;
34232- atomic_long_t tlb_dropin_fail_no_exception;
34233- atomic_long_t tfh_stale_on_fault;
34234- atomic_long_t mmu_invalidate_range;
34235- atomic_long_t mmu_invalidate_page;
34236- atomic_long_t flush_tlb;
34237- atomic_long_t flush_tlb_gru;
34238- atomic_long_t flush_tlb_gru_tgh;
34239- atomic_long_t flush_tlb_gru_zero_asid;
34240+ atomic_long_unchecked_t vdata_alloc;
34241+ atomic_long_unchecked_t vdata_free;
34242+ atomic_long_unchecked_t gts_alloc;
34243+ atomic_long_unchecked_t gts_free;
34244+ atomic_long_unchecked_t gms_alloc;
34245+ atomic_long_unchecked_t gms_free;
34246+ atomic_long_unchecked_t gts_double_allocate;
34247+ atomic_long_unchecked_t assign_context;
34248+ atomic_long_unchecked_t assign_context_failed;
34249+ atomic_long_unchecked_t free_context;
34250+ atomic_long_unchecked_t load_user_context;
34251+ atomic_long_unchecked_t load_kernel_context;
34252+ atomic_long_unchecked_t lock_kernel_context;
34253+ atomic_long_unchecked_t unlock_kernel_context;
34254+ atomic_long_unchecked_t steal_user_context;
34255+ atomic_long_unchecked_t steal_kernel_context;
34256+ atomic_long_unchecked_t steal_context_failed;
34257+ atomic_long_unchecked_t nopfn;
34258+ atomic_long_unchecked_t asid_new;
34259+ atomic_long_unchecked_t asid_next;
34260+ atomic_long_unchecked_t asid_wrap;
34261+ atomic_long_unchecked_t asid_reuse;
34262+ atomic_long_unchecked_t intr;
34263+ atomic_long_unchecked_t intr_cbr;
34264+ atomic_long_unchecked_t intr_tfh;
34265+ atomic_long_unchecked_t intr_spurious;
34266+ atomic_long_unchecked_t intr_mm_lock_failed;
34267+ atomic_long_unchecked_t call_os;
34268+ atomic_long_unchecked_t call_os_wait_queue;
34269+ atomic_long_unchecked_t user_flush_tlb;
34270+ atomic_long_unchecked_t user_unload_context;
34271+ atomic_long_unchecked_t user_exception;
34272+ atomic_long_unchecked_t set_context_option;
34273+ atomic_long_unchecked_t check_context_retarget_intr;
34274+ atomic_long_unchecked_t check_context_unload;
34275+ atomic_long_unchecked_t tlb_dropin;
34276+ atomic_long_unchecked_t tlb_preload_page;
34277+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34278+ atomic_long_unchecked_t tlb_dropin_fail_upm;
34279+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
34280+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
34281+ atomic_long_unchecked_t tlb_dropin_fail_idle;
34282+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
34283+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34284+ atomic_long_unchecked_t tfh_stale_on_fault;
34285+ atomic_long_unchecked_t mmu_invalidate_range;
34286+ atomic_long_unchecked_t mmu_invalidate_page;
34287+ atomic_long_unchecked_t flush_tlb;
34288+ atomic_long_unchecked_t flush_tlb_gru;
34289+ atomic_long_unchecked_t flush_tlb_gru_tgh;
34290+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34291
34292- atomic_long_t copy_gpa;
34293- atomic_long_t read_gpa;
34294+ atomic_long_unchecked_t copy_gpa;
34295+ atomic_long_unchecked_t read_gpa;
34296
34297- atomic_long_t mesq_receive;
34298- atomic_long_t mesq_receive_none;
34299- atomic_long_t mesq_send;
34300- atomic_long_t mesq_send_failed;
34301- atomic_long_t mesq_noop;
34302- atomic_long_t mesq_send_unexpected_error;
34303- atomic_long_t mesq_send_lb_overflow;
34304- atomic_long_t mesq_send_qlimit_reached;
34305- atomic_long_t mesq_send_amo_nacked;
34306- atomic_long_t mesq_send_put_nacked;
34307- atomic_long_t mesq_page_overflow;
34308- atomic_long_t mesq_qf_locked;
34309- atomic_long_t mesq_qf_noop_not_full;
34310- atomic_long_t mesq_qf_switch_head_failed;
34311- atomic_long_t mesq_qf_unexpected_error;
34312- atomic_long_t mesq_noop_unexpected_error;
34313- atomic_long_t mesq_noop_lb_overflow;
34314- atomic_long_t mesq_noop_qlimit_reached;
34315- atomic_long_t mesq_noop_amo_nacked;
34316- atomic_long_t mesq_noop_put_nacked;
34317- atomic_long_t mesq_noop_page_overflow;
34318+ atomic_long_unchecked_t mesq_receive;
34319+ atomic_long_unchecked_t mesq_receive_none;
34320+ atomic_long_unchecked_t mesq_send;
34321+ atomic_long_unchecked_t mesq_send_failed;
34322+ atomic_long_unchecked_t mesq_noop;
34323+ atomic_long_unchecked_t mesq_send_unexpected_error;
34324+ atomic_long_unchecked_t mesq_send_lb_overflow;
34325+ atomic_long_unchecked_t mesq_send_qlimit_reached;
34326+ atomic_long_unchecked_t mesq_send_amo_nacked;
34327+ atomic_long_unchecked_t mesq_send_put_nacked;
34328+ atomic_long_unchecked_t mesq_page_overflow;
34329+ atomic_long_unchecked_t mesq_qf_locked;
34330+ atomic_long_unchecked_t mesq_qf_noop_not_full;
34331+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
34332+ atomic_long_unchecked_t mesq_qf_unexpected_error;
34333+ atomic_long_unchecked_t mesq_noop_unexpected_error;
34334+ atomic_long_unchecked_t mesq_noop_lb_overflow;
34335+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
34336+ atomic_long_unchecked_t mesq_noop_amo_nacked;
34337+ atomic_long_unchecked_t mesq_noop_put_nacked;
34338+ atomic_long_unchecked_t mesq_noop_page_overflow;
34339
34340 };
34341
34342@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34343 tghop_invalidate, mcsop_last};
34344
34345 struct mcs_op_statistic {
34346- atomic_long_t count;
34347- atomic_long_t total;
34348+ atomic_long_unchecked_t count;
34349+ atomic_long_unchecked_t total;
34350 unsigned long max;
34351 };
34352
34353@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34354
34355 #define STAT(id) do { \
34356 if (gru_options & OPT_STATS) \
34357- atomic_long_inc(&gru_stats.id); \
34358+ atomic_long_inc_unchecked(&gru_stats.id); \
34359 } while (0)
34360
34361 #ifdef CONFIG_SGI_GRU_DEBUG
34362diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34363index c862cd4..0d176fe 100644
34364--- a/drivers/misc/sgi-xp/xp.h
34365+++ b/drivers/misc/sgi-xp/xp.h
34366@@ -288,7 +288,7 @@ struct xpc_interface {
34367 xpc_notify_func, void *);
34368 void (*received) (short, int, void *);
34369 enum xp_retval (*partid_to_nasids) (short, void *);
34370-};
34371+} __no_const;
34372
34373 extern struct xpc_interface xpc_interface;
34374
34375diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34376index b94d5f7..7f494c5 100644
34377--- a/drivers/misc/sgi-xp/xpc.h
34378+++ b/drivers/misc/sgi-xp/xpc.h
34379@@ -835,6 +835,7 @@ struct xpc_arch_operations {
34380 void (*received_payload) (struct xpc_channel *, void *);
34381 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34382 };
34383+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34384
34385 /* struct xpc_partition act_state values (for XPC HB) */
34386
34387@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34388 /* found in xpc_main.c */
34389 extern struct device *xpc_part;
34390 extern struct device *xpc_chan;
34391-extern struct xpc_arch_operations xpc_arch_ops;
34392+extern xpc_arch_operations_no_const xpc_arch_ops;
34393 extern int xpc_disengage_timelimit;
34394 extern int xpc_disengage_timedout;
34395 extern int xpc_activate_IRQ_rcvd;
34396diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34397index 8d082b4..aa749ae 100644
34398--- a/drivers/misc/sgi-xp/xpc_main.c
34399+++ b/drivers/misc/sgi-xp/xpc_main.c
34400@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34401 .notifier_call = xpc_system_die,
34402 };
34403
34404-struct xpc_arch_operations xpc_arch_ops;
34405+xpc_arch_operations_no_const xpc_arch_ops;
34406
34407 /*
34408 * Timer function to enforce the timelimit on the partition disengage.
34409diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
34410index 2b62232..acfaeeb 100644
34411--- a/drivers/misc/ti-st/st_core.c
34412+++ b/drivers/misc/ti-st/st_core.c
34413@@ -349,6 +349,11 @@ void st_int_recv(void *disc_data,
34414 st_gdata->rx_skb = alloc_skb(
34415 st_gdata->list[type]->max_frame_size,
34416 GFP_ATOMIC);
34417+ if (st_gdata->rx_skb == NULL) {
34418+ pr_err("out of memory: dropping\n");
34419+ goto done;
34420+ }
34421+
34422 skb_reserve(st_gdata->rx_skb,
34423 st_gdata->list[type]->reserve);
34424 /* next 2 required for BT only */
34425diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34426index 69ef0be..f3ef91e 100644
34427--- a/drivers/mmc/host/sdhci-pci.c
34428+++ b/drivers/mmc/host/sdhci-pci.c
34429@@ -652,7 +652,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34430 .probe = via_probe,
34431 };
34432
34433-static const struct pci_device_id pci_ids[] __devinitdata = {
34434+static const struct pci_device_id pci_ids[] __devinitconst = {
34435 {
34436 .vendor = PCI_VENDOR_ID_RICOH,
34437 .device = PCI_DEVICE_ID_RICOH_R5C822,
34438diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34439index a4eb8b5..8c0628f 100644
34440--- a/drivers/mtd/devices/doc2000.c
34441+++ b/drivers/mtd/devices/doc2000.c
34442@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34443
34444 /* The ECC will not be calculated correctly if less than 512 is written */
34445 /* DBB-
34446- if (len != 0x200 && eccbuf)
34447+ if (len != 0x200)
34448 printk(KERN_WARNING
34449 "ECC needs a full sector write (adr: %lx size %lx)\n",
34450 (long) to, (long) len);
34451diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34452index 0650aaf..7718762 100644
34453--- a/drivers/mtd/nand/denali.c
34454+++ b/drivers/mtd/nand/denali.c
34455@@ -26,6 +26,7 @@
34456 #include <linux/pci.h>
34457 #include <linux/mtd/mtd.h>
34458 #include <linux/module.h>
34459+#include <linux/slab.h>
34460
34461 #include "denali.h"
34462
34463diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34464index 51b9d6a..52af9a7 100644
34465--- a/drivers/mtd/nftlmount.c
34466+++ b/drivers/mtd/nftlmount.c
34467@@ -24,6 +24,7 @@
34468 #include <asm/errno.h>
34469 #include <linux/delay.h>
34470 #include <linux/slab.h>
34471+#include <linux/sched.h>
34472 #include <linux/mtd/mtd.h>
34473 #include <linux/mtd/nand.h>
34474 #include <linux/mtd/nftl.h>
34475diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34476index 6762dc4..9956862 100644
34477--- a/drivers/net/ethernet/atheros/atlx/atl2.c
34478+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34479@@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34480 */
34481
34482 #define ATL2_PARAM(X, desc) \
34483- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34484+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34485 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34486 MODULE_PARM_DESC(X, desc);
34487 #else
34488diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34489index efd80bd..21fcff0 100644
34490--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34491+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34492@@ -487,7 +487,7 @@ struct bnx2x_rx_mode_obj {
34493
34494 int (*wait_comp)(struct bnx2x *bp,
34495 struct bnx2x_rx_mode_ramrod_params *p);
34496-};
34497+} __no_const;
34498
34499 /********************** Set multicast group ***********************************/
34500
34501diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34502index 93865f8..5448741 100644
34503--- a/drivers/net/ethernet/broadcom/tg3.h
34504+++ b/drivers/net/ethernet/broadcom/tg3.h
34505@@ -140,6 +140,7 @@
34506 #define CHIPREV_ID_5750_A0 0x4000
34507 #define CHIPREV_ID_5750_A1 0x4001
34508 #define CHIPREV_ID_5750_A3 0x4003
34509+#define CHIPREV_ID_5750_C1 0x4201
34510 #define CHIPREV_ID_5750_C2 0x4202
34511 #define CHIPREV_ID_5752_A0_HW 0x5000
34512 #define CHIPREV_ID_5752_A0 0x6000
34513diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34514index c4e8643..0979484 100644
34515--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34516+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34517@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34518 */
34519 struct l2t_skb_cb {
34520 arp_failure_handler_func arp_failure_handler;
34521-};
34522+} __no_const;
34523
34524 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34525
34526diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34527index d3cd489..0fd52dd 100644
34528--- a/drivers/net/ethernet/dec/tulip/de4x5.c
34529+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34530@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34531 for (i=0; i<ETH_ALEN; i++) {
34532 tmp.addr[i] = dev->dev_addr[i];
34533 }
34534- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34535+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34536 break;
34537
34538 case DE4X5_SET_HWADDR: /* Set the hardware address */
34539@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34540 spin_lock_irqsave(&lp->lock, flags);
34541 memcpy(&statbuf, &lp->pktStats, ioc->len);
34542 spin_unlock_irqrestore(&lp->lock, flags);
34543- if (copy_to_user(ioc->data, &statbuf, ioc->len))
34544+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34545 return -EFAULT;
34546 break;
34547 }
34548diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34549index ed7d1dc..d426748 100644
34550--- a/drivers/net/ethernet/dec/tulip/eeprom.c
34551+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34552@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34553 {NULL}};
34554
34555
34556-static const char *block_name[] __devinitdata = {
34557+static const char *block_name[] __devinitconst = {
34558 "21140 non-MII",
34559 "21140 MII PHY",
34560 "21142 Serial PHY",
34561diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34562index 75d45f8..3d9c55b 100644
34563--- a/drivers/net/ethernet/dec/tulip/uli526x.c
34564+++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34565@@ -129,7 +129,7 @@ struct uli526x_board_info {
34566 struct uli_phy_ops {
34567 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34568 u16 (*read)(struct uli526x_board_info *, u8, u8);
34569- } phy;
34570+ } __no_const phy;
34571 struct net_device *next_dev; /* next device */
34572 struct pci_dev *pdev; /* PCI device */
34573 spinlock_t lock;
34574diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34575index 4d1ffca..7c1ec4d 100644
34576--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34577+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34578@@ -236,7 +236,7 @@ struct pci_id_info {
34579 int drv_flags; /* Driver use, intended as capability flags. */
34580 };
34581
34582-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34583+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34584 { /* Sometime a Level-One switch card. */
34585 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34586 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34587diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34588index d7bb52a..3b83588 100644
34589--- a/drivers/net/ethernet/dlink/sundance.c
34590+++ b/drivers/net/ethernet/dlink/sundance.c
34591@@ -218,7 +218,7 @@ enum {
34592 struct pci_id_info {
34593 const char *name;
34594 };
34595-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34596+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34597 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34598 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34599 {"D-Link DFE-580TX 4 port Server Adapter"},
34600diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34601index 501dfa9..aa9ec11 100644
34602--- a/drivers/net/ethernet/emulex/benet/be_main.c
34603+++ b/drivers/net/ethernet/emulex/benet/be_main.c
34604@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34605
34606 if (wrapped)
34607 newacc += 65536;
34608- ACCESS_ONCE(*acc) = newacc;
34609+ ACCESS_ONCE_RW(*acc) = newacc;
34610 }
34611
34612 void be_parse_stats(struct be_adapter *adapter)
34613diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34614index 16b0704..d2c07d7 100644
34615--- a/drivers/net/ethernet/faraday/ftgmac100.c
34616+++ b/drivers/net/ethernet/faraday/ftgmac100.c
34617@@ -31,6 +31,8 @@
34618 #include <linux/netdevice.h>
34619 #include <linux/phy.h>
34620 #include <linux/platform_device.h>
34621+#include <linux/interrupt.h>
34622+#include <linux/irqreturn.h>
34623 #include <net/ip.h>
34624
34625 #include "ftgmac100.h"
34626diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34627index 829b109..4ae5f6a 100644
34628--- a/drivers/net/ethernet/faraday/ftmac100.c
34629+++ b/drivers/net/ethernet/faraday/ftmac100.c
34630@@ -31,6 +31,8 @@
34631 #include <linux/module.h>
34632 #include <linux/netdevice.h>
34633 #include <linux/platform_device.h>
34634+#include <linux/interrupt.h>
34635+#include <linux/irqreturn.h>
34636
34637 #include "ftmac100.h"
34638
34639diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34640index 9d71c9c..0e4a0ac 100644
34641--- a/drivers/net/ethernet/fealnx.c
34642+++ b/drivers/net/ethernet/fealnx.c
34643@@ -150,7 +150,7 @@ struct chip_info {
34644 int flags;
34645 };
34646
34647-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34648+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34649 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34650 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34651 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34652diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34653index 6e6fffb..588f361 100644
34654--- a/drivers/net/ethernet/intel/e1000e/e1000.h
34655+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34656@@ -181,7 +181,7 @@ struct e1000_info;
34657 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34658 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34659 E1000_TXDCTL_COUNT_DESC | \
34660- (5 << 16) | /* wthresh must be +1 more than desired */\
34661+ (1 << 16) | /* wthresh must be +1 more than desired */\
34662 (1 << 8) | /* hthresh */ \
34663 0x1f) /* pthresh */
34664
34665diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34666index ed5b409..ec37828 100644
34667--- a/drivers/net/ethernet/intel/e1000e/hw.h
34668+++ b/drivers/net/ethernet/intel/e1000e/hw.h
34669@@ -797,6 +797,7 @@ struct e1000_mac_operations {
34670 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34671 s32 (*read_mac_addr)(struct e1000_hw *);
34672 };
34673+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34674
34675 /*
34676 * When to use various PHY register access functions:
34677@@ -837,6 +838,7 @@ struct e1000_phy_operations {
34678 void (*power_up)(struct e1000_hw *);
34679 void (*power_down)(struct e1000_hw *);
34680 };
34681+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34682
34683 /* Function pointers for the NVM. */
34684 struct e1000_nvm_operations {
34685@@ -849,9 +851,10 @@ struct e1000_nvm_operations {
34686 s32 (*validate)(struct e1000_hw *);
34687 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34688 };
34689+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34690
34691 struct e1000_mac_info {
34692- struct e1000_mac_operations ops;
34693+ e1000_mac_operations_no_const ops;
34694 u8 addr[ETH_ALEN];
34695 u8 perm_addr[ETH_ALEN];
34696
34697@@ -892,7 +895,7 @@ struct e1000_mac_info {
34698 };
34699
34700 struct e1000_phy_info {
34701- struct e1000_phy_operations ops;
34702+ e1000_phy_operations_no_const ops;
34703
34704 enum e1000_phy_type type;
34705
34706@@ -926,7 +929,7 @@ struct e1000_phy_info {
34707 };
34708
34709 struct e1000_nvm_info {
34710- struct e1000_nvm_operations ops;
34711+ e1000_nvm_operations_no_const ops;
34712
34713 enum e1000_nvm_type type;
34714 enum e1000_nvm_override override;
34715diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34716index c2a51dc..c2bd262 100644
34717--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34718+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34719@@ -327,6 +327,7 @@ struct e1000_mac_operations {
34720 void (*release_swfw_sync)(struct e1000_hw *, u16);
34721
34722 };
34723+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34724
34725 struct e1000_phy_operations {
34726 s32 (*acquire)(struct e1000_hw *);
34727@@ -343,6 +344,7 @@ struct e1000_phy_operations {
34728 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34729 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34730 };
34731+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34732
34733 struct e1000_nvm_operations {
34734 s32 (*acquire)(struct e1000_hw *);
34735@@ -353,6 +355,7 @@ struct e1000_nvm_operations {
34736 s32 (*validate)(struct e1000_hw *);
34737 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
34738 };
34739+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34740
34741 struct e1000_info {
34742 s32 (*get_invariants)(struct e1000_hw *);
34743@@ -364,7 +367,7 @@ struct e1000_info {
34744 extern const struct e1000_info e1000_82575_info;
34745
34746 struct e1000_mac_info {
34747- struct e1000_mac_operations ops;
34748+ e1000_mac_operations_no_const ops;
34749
34750 u8 addr[6];
34751 u8 perm_addr[6];
34752@@ -402,7 +405,7 @@ struct e1000_mac_info {
34753 };
34754
34755 struct e1000_phy_info {
34756- struct e1000_phy_operations ops;
34757+ e1000_phy_operations_no_const ops;
34758
34759 enum e1000_phy_type type;
34760
34761@@ -437,7 +440,7 @@ struct e1000_phy_info {
34762 };
34763
34764 struct e1000_nvm_info {
34765- struct e1000_nvm_operations ops;
34766+ e1000_nvm_operations_no_const ops;
34767 enum e1000_nvm_type type;
34768 enum e1000_nvm_override override;
34769
34770@@ -482,6 +485,7 @@ struct e1000_mbx_operations {
34771 s32 (*check_for_ack)(struct e1000_hw *, u16);
34772 s32 (*check_for_rst)(struct e1000_hw *, u16);
34773 };
34774+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34775
34776 struct e1000_mbx_stats {
34777 u32 msgs_tx;
34778@@ -493,7 +497,7 @@ struct e1000_mbx_stats {
34779 };
34780
34781 struct e1000_mbx_info {
34782- struct e1000_mbx_operations ops;
34783+ e1000_mbx_operations_no_const ops;
34784 struct e1000_mbx_stats stats;
34785 u32 timeout;
34786 u32 usec_delay;
34787diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34788index 57db3c6..aa825fc 100644
34789--- a/drivers/net/ethernet/intel/igbvf/vf.h
34790+++ b/drivers/net/ethernet/intel/igbvf/vf.h
34791@@ -189,9 +189,10 @@ struct e1000_mac_operations {
34792 s32 (*read_mac_addr)(struct e1000_hw *);
34793 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34794 };
34795+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34796
34797 struct e1000_mac_info {
34798- struct e1000_mac_operations ops;
34799+ e1000_mac_operations_no_const ops;
34800 u8 addr[6];
34801 u8 perm_addr[6];
34802
34803@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34804 s32 (*check_for_ack)(struct e1000_hw *);
34805 s32 (*check_for_rst)(struct e1000_hw *);
34806 };
34807+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34808
34809 struct e1000_mbx_stats {
34810 u32 msgs_tx;
34811@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34812 };
34813
34814 struct e1000_mbx_info {
34815- struct e1000_mbx_operations ops;
34816+ e1000_mbx_operations_no_const ops;
34817 struct e1000_mbx_stats stats;
34818 u32 timeout;
34819 u32 usec_delay;
34820diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34821index dcebd12..c1fe8be 100644
34822--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34823+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34824@@ -805,7 +805,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
34825 /* store the new cycle speed */
34826 adapter->cycle_speed = cycle_speed;
34827
34828- ACCESS_ONCE(adapter->base_incval) = incval;
34829+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
34830 smp_mb();
34831
34832 /* grab the ptp lock */
34833diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34834index 204848d..d8aeaec 100644
34835--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34836+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34837@@ -2791,6 +2791,7 @@ struct ixgbe_eeprom_operations {
34838 s32 (*update_checksum)(struct ixgbe_hw *);
34839 u16 (*calc_checksum)(struct ixgbe_hw *);
34840 };
34841+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34842
34843 struct ixgbe_mac_operations {
34844 s32 (*init_hw)(struct ixgbe_hw *);
34845@@ -2856,6 +2857,7 @@ struct ixgbe_mac_operations {
34846 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
34847 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
34848 };
34849+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34850
34851 struct ixgbe_phy_operations {
34852 s32 (*identify)(struct ixgbe_hw *);
34853@@ -2875,9 +2877,10 @@ struct ixgbe_phy_operations {
34854 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34855 s32 (*check_overtemp)(struct ixgbe_hw *);
34856 };
34857+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34858
34859 struct ixgbe_eeprom_info {
34860- struct ixgbe_eeprom_operations ops;
34861+ ixgbe_eeprom_operations_no_const ops;
34862 enum ixgbe_eeprom_type type;
34863 u32 semaphore_delay;
34864 u16 word_size;
34865@@ -2887,7 +2890,7 @@ struct ixgbe_eeprom_info {
34866
34867 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34868 struct ixgbe_mac_info {
34869- struct ixgbe_mac_operations ops;
34870+ ixgbe_mac_operations_no_const ops;
34871 enum ixgbe_mac_type type;
34872 u8 addr[ETH_ALEN];
34873 u8 perm_addr[ETH_ALEN];
34874@@ -2916,7 +2919,7 @@ struct ixgbe_mac_info {
34875 };
34876
34877 struct ixgbe_phy_info {
34878- struct ixgbe_phy_operations ops;
34879+ ixgbe_phy_operations_no_const ops;
34880 struct mdio_if_info mdio;
34881 enum ixgbe_phy_type type;
34882 u32 id;
34883@@ -2944,6 +2947,7 @@ struct ixgbe_mbx_operations {
34884 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34885 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34886 };
34887+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34888
34889 struct ixgbe_mbx_stats {
34890 u32 msgs_tx;
34891@@ -2955,7 +2959,7 @@ struct ixgbe_mbx_stats {
34892 };
34893
34894 struct ixgbe_mbx_info {
34895- struct ixgbe_mbx_operations ops;
34896+ ixgbe_mbx_operations_no_const ops;
34897 struct ixgbe_mbx_stats stats;
34898 u32 timeout;
34899 u32 usec_delay;
34900diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34901index 25c951d..cc7cf33 100644
34902--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34903+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34904@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34905 s32 (*clear_vfta)(struct ixgbe_hw *);
34906 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34907 };
34908+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34909
34910 enum ixgbe_mac_type {
34911 ixgbe_mac_unknown = 0,
34912@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34913 };
34914
34915 struct ixgbe_mac_info {
34916- struct ixgbe_mac_operations ops;
34917+ ixgbe_mac_operations_no_const ops;
34918 u8 addr[6];
34919 u8 perm_addr[6];
34920
34921@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
34922 s32 (*check_for_ack)(struct ixgbe_hw *);
34923 s32 (*check_for_rst)(struct ixgbe_hw *);
34924 };
34925+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34926
34927 struct ixgbe_mbx_stats {
34928 u32 msgs_tx;
34929@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
34930 };
34931
34932 struct ixgbe_mbx_info {
34933- struct ixgbe_mbx_operations ops;
34934+ ixgbe_mbx_operations_no_const ops;
34935 struct ixgbe_mbx_stats stats;
34936 u32 timeout;
34937 u32 udelay;
34938diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
34939index a0313de..e83a572 100644
34940--- a/drivers/net/ethernet/mellanox/mlx4/main.c
34941+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
34942@@ -41,6 +41,7 @@
34943 #include <linux/slab.h>
34944 #include <linux/io-mapping.h>
34945 #include <linux/delay.h>
34946+#include <linux/sched.h>
34947
34948 #include <linux/mlx4/device.h>
34949 #include <linux/mlx4/doorbell.h>
34950diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34951index 5046a64..71ca936 100644
34952--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
34953+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34954@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34955 void (*link_down)(struct __vxge_hw_device *devh);
34956 void (*crit_err)(struct __vxge_hw_device *devh,
34957 enum vxge_hw_event type, u64 ext_data);
34958-};
34959+} __no_const;
34960
34961 /*
34962 * struct __vxge_hw_blockpool_entry - Block private data structure
34963diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34964index 4a518a3..936b334 100644
34965--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34966+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34967@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
34968 struct vxge_hw_mempool_dma *dma_object,
34969 u32 index,
34970 u32 is_last);
34971-};
34972+} __no_const;
34973
34974 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
34975 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
34976diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
34977index d7a04e0..76d0431 100644
34978--- a/drivers/net/ethernet/realtek/r8169.c
34979+++ b/drivers/net/ethernet/realtek/r8169.c
34980@@ -723,22 +723,22 @@ struct rtl8169_private {
34981 struct mdio_ops {
34982 void (*write)(void __iomem *, int, int);
34983 int (*read)(void __iomem *, int);
34984- } mdio_ops;
34985+ } __no_const mdio_ops;
34986
34987 struct pll_power_ops {
34988 void (*down)(struct rtl8169_private *);
34989 void (*up)(struct rtl8169_private *);
34990- } pll_power_ops;
34991+ } __no_const pll_power_ops;
34992
34993 struct jumbo_ops {
34994 void (*enable)(struct rtl8169_private *);
34995 void (*disable)(struct rtl8169_private *);
34996- } jumbo_ops;
34997+ } __no_const jumbo_ops;
34998
34999 struct csi_ops {
35000 void (*write)(void __iomem *, int, int);
35001 u32 (*read)(void __iomem *, int);
35002- } csi_ops;
35003+ } __no_const csi_ops;
35004
35005 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35006 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35007diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35008index 4613591..d816601 100644
35009--- a/drivers/net/ethernet/sis/sis190.c
35010+++ b/drivers/net/ethernet/sis/sis190.c
35011@@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35012 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35013 struct net_device *dev)
35014 {
35015- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35016+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35017 struct sis190_private *tp = netdev_priv(dev);
35018 struct pci_dev *isa_bridge;
35019 u8 reg, tmp8;
35020diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35021index c07cfe9..81cbf7e 100644
35022--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35023+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35024@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35025
35026 writel(value, ioaddr + MMC_CNTRL);
35027
35028- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35029- MMC_CNTRL, value);
35030+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35031+// MMC_CNTRL, value);
35032 }
35033
35034 /* To mask all all interrupts.*/
35035diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35036index 2857ab0..9a1f9b0 100644
35037--- a/drivers/net/hyperv/hyperv_net.h
35038+++ b/drivers/net/hyperv/hyperv_net.h
35039@@ -99,7 +99,7 @@ struct rndis_device {
35040
35041 enum rndis_device_state state;
35042 bool link_state;
35043- atomic_t new_req_id;
35044+ atomic_unchecked_t new_req_id;
35045
35046 spinlock_t request_lock;
35047 struct list_head req_list;
35048diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35049index 981ebb1..b34959b 100644
35050--- a/drivers/net/hyperv/rndis_filter.c
35051+++ b/drivers/net/hyperv/rndis_filter.c
35052@@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35053 * template
35054 */
35055 set = &rndis_msg->msg.set_req;
35056- set->req_id = atomic_inc_return(&dev->new_req_id);
35057+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35058
35059 /* Add to the request list */
35060 spin_lock_irqsave(&dev->request_lock, flags);
35061@@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35062
35063 /* Setup the rndis set */
35064 halt = &request->request_msg.msg.halt_req;
35065- halt->req_id = atomic_inc_return(&dev->new_req_id);
35066+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35067
35068 /* Ignore return since this msg is optional. */
35069 rndis_filter_send_request(dev, request);
35070diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35071index 5c05572..389610b 100644
35072--- a/drivers/net/ppp/ppp_generic.c
35073+++ b/drivers/net/ppp/ppp_generic.c
35074@@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35075 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35076 struct ppp_stats stats;
35077 struct ppp_comp_stats cstats;
35078- char *vers;
35079
35080 switch (cmd) {
35081 case SIOCGPPPSTATS:
35082@@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35083 break;
35084
35085 case SIOCGPPPVER:
35086- vers = PPP_VERSION;
35087- if (copy_to_user(addr, vers, strlen(vers) + 1))
35088+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35089 break;
35090 err = 0;
35091 break;
35092diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35093index 62f30b4..ff99dfd 100644
35094--- a/drivers/net/usb/hso.c
35095+++ b/drivers/net/usb/hso.c
35096@@ -71,7 +71,7 @@
35097 #include <asm/byteorder.h>
35098 #include <linux/serial_core.h>
35099 #include <linux/serial.h>
35100-
35101+#include <asm/local.h>
35102
35103 #define MOD_AUTHOR "Option Wireless"
35104 #define MOD_DESCRIPTION "USB High Speed Option driver"
35105@@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35106 struct urb *urb;
35107
35108 urb = serial->rx_urb[0];
35109- if (serial->port.count > 0) {
35110+ if (atomic_read(&serial->port.count) > 0) {
35111 count = put_rxbuf_data(urb, serial);
35112 if (count == -1)
35113 return;
35114@@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35115 DUMP1(urb->transfer_buffer, urb->actual_length);
35116
35117 /* Anyone listening? */
35118- if (serial->port.count == 0)
35119+ if (atomic_read(&serial->port.count) == 0)
35120 return;
35121
35122 if (status == 0) {
35123@@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35124 tty_port_tty_set(&serial->port, tty);
35125
35126 /* check for port already opened, if not set the termios */
35127- serial->port.count++;
35128- if (serial->port.count == 1) {
35129+ if (atomic_inc_return(&serial->port.count) == 1) {
35130 serial->rx_state = RX_IDLE;
35131 /* Force default termio settings */
35132 _hso_serial_set_termios(tty, NULL);
35133@@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35134 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35135 if (result) {
35136 hso_stop_serial_device(serial->parent);
35137- serial->port.count--;
35138+ atomic_dec(&serial->port.count);
35139 kref_put(&serial->parent->ref, hso_serial_ref_free);
35140 }
35141 } else {
35142@@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35143
35144 /* reset the rts and dtr */
35145 /* do the actual close */
35146- serial->port.count--;
35147+ atomic_dec(&serial->port.count);
35148
35149- if (serial->port.count <= 0) {
35150- serial->port.count = 0;
35151+ if (atomic_read(&serial->port.count) <= 0) {
35152+ atomic_set(&serial->port.count, 0);
35153 tty_port_tty_set(&serial->port, NULL);
35154 if (!usb_gone)
35155 hso_stop_serial_device(serial->parent);
35156@@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35157
35158 /* the actual setup */
35159 spin_lock_irqsave(&serial->serial_lock, flags);
35160- if (serial->port.count)
35161+ if (atomic_read(&serial->port.count))
35162 _hso_serial_set_termios(tty, old);
35163 else
35164 tty->termios = old;
35165@@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35166 D1("Pending read interrupt on port %d\n", i);
35167 spin_lock(&serial->serial_lock);
35168 if (serial->rx_state == RX_IDLE &&
35169- serial->port.count > 0) {
35170+ atomic_read(&serial->port.count) > 0) {
35171 /* Setup and send a ctrl req read on
35172 * port i */
35173 if (!serial->rx_urb_filled[0]) {
35174@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35175 /* Start all serial ports */
35176 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35177 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35178- if (dev2ser(serial_table[i])->port.count) {
35179+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35180 result =
35181 hso_start_serial_device(serial_table[i], GFP_NOIO);
35182 hso_kick_transmit(dev2ser(serial_table[i]));
35183diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35184index 420d69b..74f90a2 100644
35185--- a/drivers/net/wireless/ath/ath.h
35186+++ b/drivers/net/wireless/ath/ath.h
35187@@ -119,6 +119,7 @@ struct ath_ops {
35188 void (*write_flush) (void *);
35189 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35190 };
35191+typedef struct ath_ops __no_const ath_ops_no_const;
35192
35193 struct ath_common;
35194 struct ath_bus_ops;
35195diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35196index 8d78253..bebbb68 100644
35197--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35198+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35199@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35200 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35201 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35202
35203- ACCESS_ONCE(ads->ds_link) = i->link;
35204- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35205+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
35206+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35207
35208 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35209 ctl6 = SM(i->keytype, AR_EncrType);
35210@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35211
35212 if ((i->is_first || i->is_last) &&
35213 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35214- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35215+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35216 | set11nTries(i->rates, 1)
35217 | set11nTries(i->rates, 2)
35218 | set11nTries(i->rates, 3)
35219 | (i->dur_update ? AR_DurUpdateEna : 0)
35220 | SM(0, AR_BurstDur);
35221
35222- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35223+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35224 | set11nRate(i->rates, 1)
35225 | set11nRate(i->rates, 2)
35226 | set11nRate(i->rates, 3);
35227 } else {
35228- ACCESS_ONCE(ads->ds_ctl2) = 0;
35229- ACCESS_ONCE(ads->ds_ctl3) = 0;
35230+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35231+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35232 }
35233
35234 if (!i->is_first) {
35235- ACCESS_ONCE(ads->ds_ctl0) = 0;
35236- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35237- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35238+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35239+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35240+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35241 return;
35242 }
35243
35244@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35245 break;
35246 }
35247
35248- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35249+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35250 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35251 | SM(i->txpower, AR_XmitPower)
35252 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35253@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35254 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35255 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35256
35257- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35258- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35259+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35260+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35261
35262 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35263 return;
35264
35265- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35266+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35267 | set11nPktDurRTSCTS(i->rates, 1);
35268
35269- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35270+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35271 | set11nPktDurRTSCTS(i->rates, 3);
35272
35273- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35274+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35275 | set11nRateFlags(i->rates, 1)
35276 | set11nRateFlags(i->rates, 2)
35277 | set11nRateFlags(i->rates, 3)
35278diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35279index d9e0824..1a874e7 100644
35280--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35281+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35282@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35283 (i->qcu << AR_TxQcuNum_S) | desc_len;
35284
35285 checksum += val;
35286- ACCESS_ONCE(ads->info) = val;
35287+ ACCESS_ONCE_RW(ads->info) = val;
35288
35289 checksum += i->link;
35290- ACCESS_ONCE(ads->link) = i->link;
35291+ ACCESS_ONCE_RW(ads->link) = i->link;
35292
35293 checksum += i->buf_addr[0];
35294- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35295+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35296 checksum += i->buf_addr[1];
35297- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35298+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35299 checksum += i->buf_addr[2];
35300- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35301+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35302 checksum += i->buf_addr[3];
35303- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35304+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35305
35306 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35307- ACCESS_ONCE(ads->ctl3) = val;
35308+ ACCESS_ONCE_RW(ads->ctl3) = val;
35309 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35310- ACCESS_ONCE(ads->ctl5) = val;
35311+ ACCESS_ONCE_RW(ads->ctl5) = val;
35312 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35313- ACCESS_ONCE(ads->ctl7) = val;
35314+ ACCESS_ONCE_RW(ads->ctl7) = val;
35315 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35316- ACCESS_ONCE(ads->ctl9) = val;
35317+ ACCESS_ONCE_RW(ads->ctl9) = val;
35318
35319 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35320- ACCESS_ONCE(ads->ctl10) = checksum;
35321+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
35322
35323 if (i->is_first || i->is_last) {
35324- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35325+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35326 | set11nTries(i->rates, 1)
35327 | set11nTries(i->rates, 2)
35328 | set11nTries(i->rates, 3)
35329 | (i->dur_update ? AR_DurUpdateEna : 0)
35330 | SM(0, AR_BurstDur);
35331
35332- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35333+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35334 | set11nRate(i->rates, 1)
35335 | set11nRate(i->rates, 2)
35336 | set11nRate(i->rates, 3);
35337 } else {
35338- ACCESS_ONCE(ads->ctl13) = 0;
35339- ACCESS_ONCE(ads->ctl14) = 0;
35340+ ACCESS_ONCE_RW(ads->ctl13) = 0;
35341+ ACCESS_ONCE_RW(ads->ctl14) = 0;
35342 }
35343
35344 ads->ctl20 = 0;
35345@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35346
35347 ctl17 = SM(i->keytype, AR_EncrType);
35348 if (!i->is_first) {
35349- ACCESS_ONCE(ads->ctl11) = 0;
35350- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35351- ACCESS_ONCE(ads->ctl15) = 0;
35352- ACCESS_ONCE(ads->ctl16) = 0;
35353- ACCESS_ONCE(ads->ctl17) = ctl17;
35354- ACCESS_ONCE(ads->ctl18) = 0;
35355- ACCESS_ONCE(ads->ctl19) = 0;
35356+ ACCESS_ONCE_RW(ads->ctl11) = 0;
35357+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35358+ ACCESS_ONCE_RW(ads->ctl15) = 0;
35359+ ACCESS_ONCE_RW(ads->ctl16) = 0;
35360+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35361+ ACCESS_ONCE_RW(ads->ctl18) = 0;
35362+ ACCESS_ONCE_RW(ads->ctl19) = 0;
35363 return;
35364 }
35365
35366- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35367+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35368 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35369 | SM(i->txpower, AR_XmitPower)
35370 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35371@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35372 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35373 ctl12 |= SM(val, AR_PAPRDChainMask);
35374
35375- ACCESS_ONCE(ads->ctl12) = ctl12;
35376- ACCESS_ONCE(ads->ctl17) = ctl17;
35377+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35378+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35379
35380- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35381+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35382 | set11nPktDurRTSCTS(i->rates, 1);
35383
35384- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35385+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35386 | set11nPktDurRTSCTS(i->rates, 3);
35387
35388- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35389+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35390 | set11nRateFlags(i->rates, 1)
35391 | set11nRateFlags(i->rates, 2)
35392 | set11nRateFlags(i->rates, 3)
35393 | SM(i->rtscts_rate, AR_RTSCTSRate);
35394
35395- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35396+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35397 }
35398
35399 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35400diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35401index b620c55..a76cd49 100644
35402--- a/drivers/net/wireless/ath/ath9k/hw.h
35403+++ b/drivers/net/wireless/ath/ath9k/hw.h
35404@@ -609,7 +609,7 @@ struct ath_hw_private_ops {
35405
35406 /* ANI */
35407 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35408-};
35409+} __no_const;
35410
35411 /**
35412 * struct ath_hw_ops - callbacks used by hardware code and driver code
35413@@ -639,7 +639,7 @@ struct ath_hw_ops {
35414 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35415 struct ath_hw_antcomb_conf *antconf);
35416
35417-};
35418+} __no_const;
35419
35420 struct ath_nf_limits {
35421 s16 max;
35422@@ -659,7 +659,7 @@ enum ath_cal_list {
35423 #define AH_FASTCC 0x4
35424
35425 struct ath_hw {
35426- struct ath_ops reg_ops;
35427+ ath_ops_no_const reg_ops;
35428
35429 struct ieee80211_hw *hw;
35430 struct ath_common common;
35431diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35432index af00e2c..ab04d34 100644
35433--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35434+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35435@@ -545,7 +545,7 @@ struct phy_func_ptr {
35436 void (*carrsuppr)(struct brcms_phy *);
35437 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35438 void (*detach)(struct brcms_phy *);
35439-};
35440+} __no_const;
35441
35442 struct brcms_phy {
35443 struct brcms_phy_pub pubpi_ro;
35444diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35445index faec404..a5277f1 100644
35446--- a/drivers/net/wireless/iwlegacy/3945-mac.c
35447+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35448@@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35449 */
35450 if (il3945_mod_params.disable_hw_scan) {
35451 D_INFO("Disabling hw_scan\n");
35452- il3945_mac_ops.hw_scan = NULL;
35453+ pax_open_kernel();
35454+ *(void **)&il3945_mac_ops.hw_scan = NULL;
35455+ pax_close_kernel();
35456 }
35457
35458 D_INFO("*** LOAD DRIVER ***\n");
35459diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35460index a0b7cfd..20b49f7 100644
35461--- a/drivers/net/wireless/mac80211_hwsim.c
35462+++ b/drivers/net/wireless/mac80211_hwsim.c
35463@@ -1752,9 +1752,11 @@ static int __init init_mac80211_hwsim(void)
35464 return -EINVAL;
35465
35466 if (fake_hw_scan) {
35467- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35468- mac80211_hwsim_ops.sw_scan_start = NULL;
35469- mac80211_hwsim_ops.sw_scan_complete = NULL;
35470+ pax_open_kernel();
35471+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35472+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35473+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35474+ pax_close_kernel();
35475 }
35476
35477 spin_lock_init(&hwsim_radio_lock);
35478diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35479index bd3b0bf..f9db92a 100644
35480--- a/drivers/net/wireless/mwifiex/main.h
35481+++ b/drivers/net/wireless/mwifiex/main.h
35482@@ -567,7 +567,7 @@ struct mwifiex_if_ops {
35483 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35484 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35485 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35486-};
35487+} __no_const;
35488
35489 struct mwifiex_adapter {
35490 u8 iface_type;
35491diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35492index dfcd02a..a42a59d 100644
35493--- a/drivers/net/wireless/rndis_wlan.c
35494+++ b/drivers/net/wireless/rndis_wlan.c
35495@@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35496
35497 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35498
35499- if (rts_threshold < 0 || rts_threshold > 2347)
35500+ if (rts_threshold > 2347)
35501 rts_threshold = 2347;
35502
35503 tmp = cpu_to_le32(rts_threshold);
35504diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35505index 8f75402..eed109d 100644
35506--- a/drivers/net/wireless/rt2x00/rt2x00.h
35507+++ b/drivers/net/wireless/rt2x00/rt2x00.h
35508@@ -396,7 +396,7 @@ struct rt2x00_intf {
35509 * for hardware which doesn't support hardware
35510 * sequence counting.
35511 */
35512- atomic_t seqno;
35513+ atomic_unchecked_t seqno;
35514 };
35515
35516 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35517diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35518index 2fd8301..9767e8c 100644
35519--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35520+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35521@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35522 * sequence counter given by mac80211.
35523 */
35524 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35525- seqno = atomic_add_return(0x10, &intf->seqno);
35526+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35527 else
35528- seqno = atomic_read(&intf->seqno);
35529+ seqno = atomic_read_unchecked(&intf->seqno);
35530
35531 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35532 hdr->seq_ctrl |= cpu_to_le16(seqno);
35533diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35534index 9d8f581..0f6589e 100644
35535--- a/drivers/net/wireless/ti/wl1251/wl1251.h
35536+++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35537@@ -266,7 +266,7 @@ struct wl1251_if_operations {
35538 void (*reset)(struct wl1251 *wl);
35539 void (*enable_irq)(struct wl1251 *wl);
35540 void (*disable_irq)(struct wl1251 *wl);
35541-};
35542+} __no_const;
35543
35544 struct wl1251 {
35545 struct ieee80211_hw *hw;
35546diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35547index 0b3f0b5..62f68bd 100644
35548--- a/drivers/net/wireless/ti/wlcore/wlcore.h
35549+++ b/drivers/net/wireless/ti/wlcore/wlcore.h
35550@@ -61,7 +61,7 @@ struct wlcore_ops {
35551 struct wl12xx_vif *wlvif);
35552 s8 (*get_pg_ver)(struct wl1271 *wl);
35553 void (*get_mac)(struct wl1271 *wl);
35554-};
35555+} __no_const;
35556
35557 enum wlcore_partitions {
35558 PART_DOWN,
35559diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35560index f34b5b2..b5abb9f 100644
35561--- a/drivers/oprofile/buffer_sync.c
35562+++ b/drivers/oprofile/buffer_sync.c
35563@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35564 if (cookie == NO_COOKIE)
35565 offset = pc;
35566 if (cookie == INVALID_COOKIE) {
35567- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35568+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35569 offset = pc;
35570 }
35571 if (cookie != last_cookie) {
35572@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35573 /* add userspace sample */
35574
35575 if (!mm) {
35576- atomic_inc(&oprofile_stats.sample_lost_no_mm);
35577+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35578 return 0;
35579 }
35580
35581 cookie = lookup_dcookie(mm, s->eip, &offset);
35582
35583 if (cookie == INVALID_COOKIE) {
35584- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35585+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35586 return 0;
35587 }
35588
35589@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35590 /* ignore backtraces if failed to add a sample */
35591 if (state == sb_bt_start) {
35592 state = sb_bt_ignore;
35593- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35594+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35595 }
35596 }
35597 release_mm(mm);
35598diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35599index c0cc4e7..44d4e54 100644
35600--- a/drivers/oprofile/event_buffer.c
35601+++ b/drivers/oprofile/event_buffer.c
35602@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35603 }
35604
35605 if (buffer_pos == buffer_size) {
35606- atomic_inc(&oprofile_stats.event_lost_overflow);
35607+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35608 return;
35609 }
35610
35611diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35612index ed2c3ec..deda85a 100644
35613--- a/drivers/oprofile/oprof.c
35614+++ b/drivers/oprofile/oprof.c
35615@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35616 if (oprofile_ops.switch_events())
35617 return;
35618
35619- atomic_inc(&oprofile_stats.multiplex_counter);
35620+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35621 start_switch_worker();
35622 }
35623
35624diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35625index 917d28e..d62d981 100644
35626--- a/drivers/oprofile/oprofile_stats.c
35627+++ b/drivers/oprofile/oprofile_stats.c
35628@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35629 cpu_buf->sample_invalid_eip = 0;
35630 }
35631
35632- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35633- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35634- atomic_set(&oprofile_stats.event_lost_overflow, 0);
35635- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35636- atomic_set(&oprofile_stats.multiplex_counter, 0);
35637+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35638+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35639+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35640+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35641+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35642 }
35643
35644
35645diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35646index 38b6fc0..b5cbfce 100644
35647--- a/drivers/oprofile/oprofile_stats.h
35648+++ b/drivers/oprofile/oprofile_stats.h
35649@@ -13,11 +13,11 @@
35650 #include <linux/atomic.h>
35651
35652 struct oprofile_stat_struct {
35653- atomic_t sample_lost_no_mm;
35654- atomic_t sample_lost_no_mapping;
35655- atomic_t bt_lost_no_mapping;
35656- atomic_t event_lost_overflow;
35657- atomic_t multiplex_counter;
35658+ atomic_unchecked_t sample_lost_no_mm;
35659+ atomic_unchecked_t sample_lost_no_mapping;
35660+ atomic_unchecked_t bt_lost_no_mapping;
35661+ atomic_unchecked_t event_lost_overflow;
35662+ atomic_unchecked_t multiplex_counter;
35663 };
35664
35665 extern struct oprofile_stat_struct oprofile_stats;
35666diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35667index 849357c..b83c1e0 100644
35668--- a/drivers/oprofile/oprofilefs.c
35669+++ b/drivers/oprofile/oprofilefs.c
35670@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35671
35672
35673 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35674- char const *name, atomic_t *val)
35675+ char const *name, atomic_unchecked_t *val)
35676 {
35677 return __oprofilefs_create_file(sb, root, name,
35678 &atomic_ro_fops, 0444, val);
35679diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35680index 3f56bc0..707d642 100644
35681--- a/drivers/parport/procfs.c
35682+++ b/drivers/parport/procfs.c
35683@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35684
35685 *ppos += len;
35686
35687- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35688+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35689 }
35690
35691 #ifdef CONFIG_PARPORT_1284
35692@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35693
35694 *ppos += len;
35695
35696- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35697+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35698 }
35699 #endif /* IEEE1284.3 support. */
35700
35701diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35702index 9fff878..ad0ad53 100644
35703--- a/drivers/pci/hotplug/cpci_hotplug.h
35704+++ b/drivers/pci/hotplug/cpci_hotplug.h
35705@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35706 int (*hardware_test) (struct slot* slot, u32 value);
35707 u8 (*get_power) (struct slot* slot);
35708 int (*set_power) (struct slot* slot, int value);
35709-};
35710+} __no_const;
35711
35712 struct cpci_hp_controller {
35713 unsigned int irq;
35714diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35715index 76ba8a1..20ca857 100644
35716--- a/drivers/pci/hotplug/cpqphp_nvram.c
35717+++ b/drivers/pci/hotplug/cpqphp_nvram.c
35718@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35719
35720 void compaq_nvram_init (void __iomem *rom_start)
35721 {
35722+
35723+#ifndef CONFIG_PAX_KERNEXEC
35724 if (rom_start) {
35725 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35726 }
35727+#endif
35728+
35729 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35730
35731 /* initialize our int15 lock */
35732diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35733index b500840..d7159d3 100644
35734--- a/drivers/pci/pcie/aspm.c
35735+++ b/drivers/pci/pcie/aspm.c
35736@@ -27,9 +27,9 @@
35737 #define MODULE_PARAM_PREFIX "pcie_aspm."
35738
35739 /* Note: those are not register definitions */
35740-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35741-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35742-#define ASPM_STATE_L1 (4) /* L1 state */
35743+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35744+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35745+#define ASPM_STATE_L1 (4U) /* L1 state */
35746 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35747 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35748
35749diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35750index 658ac97..05e1b90 100644
35751--- a/drivers/pci/probe.c
35752+++ b/drivers/pci/probe.c
35753@@ -137,7 +137,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35754 u16 orig_cmd;
35755 struct pci_bus_region region;
35756
35757- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35758+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35759
35760 if (!dev->mmio_always_on) {
35761 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35762diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35763index 27911b5..5b6db88 100644
35764--- a/drivers/pci/proc.c
35765+++ b/drivers/pci/proc.c
35766@@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35767 static int __init pci_proc_init(void)
35768 {
35769 struct pci_dev *dev = NULL;
35770+
35771+#ifdef CONFIG_GRKERNSEC_PROC_ADD
35772+#ifdef CONFIG_GRKERNSEC_PROC_USER
35773+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35774+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35775+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35776+#endif
35777+#else
35778 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35779+#endif
35780 proc_create("devices", 0, proc_bus_pci_dir,
35781 &proc_bus_pci_dev_operations);
35782 proc_initialized = 1;
35783diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35784index 8b5610d..a4c22bb 100644
35785--- a/drivers/platform/x86/thinkpad_acpi.c
35786+++ b/drivers/platform/x86/thinkpad_acpi.c
35787@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35788 return 0;
35789 }
35790
35791-void static hotkey_mask_warn_incomplete_mask(void)
35792+static void hotkey_mask_warn_incomplete_mask(void)
35793 {
35794 /* log only what the user can fix... */
35795 const u32 wantedmask = hotkey_driver_mask &
35796@@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35797 }
35798 }
35799
35800-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35801- struct tp_nvram_state *newn,
35802- const u32 event_mask)
35803-{
35804-
35805 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35806 do { \
35807 if ((event_mask & (1 << __scancode)) && \
35808@@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35809 tpacpi_hotkey_send_key(__scancode); \
35810 } while (0)
35811
35812- void issue_volchange(const unsigned int oldvol,
35813- const unsigned int newvol)
35814- {
35815- unsigned int i = oldvol;
35816+static void issue_volchange(const unsigned int oldvol,
35817+ const unsigned int newvol,
35818+ const u32 event_mask)
35819+{
35820+ unsigned int i = oldvol;
35821
35822- while (i > newvol) {
35823- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35824- i--;
35825- }
35826- while (i < newvol) {
35827- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35828- i++;
35829- }
35830+ while (i > newvol) {
35831+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35832+ i--;
35833 }
35834+ while (i < newvol) {
35835+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35836+ i++;
35837+ }
35838+}
35839
35840- void issue_brightnesschange(const unsigned int oldbrt,
35841- const unsigned int newbrt)
35842- {
35843- unsigned int i = oldbrt;
35844+static void issue_brightnesschange(const unsigned int oldbrt,
35845+ const unsigned int newbrt,
35846+ const u32 event_mask)
35847+{
35848+ unsigned int i = oldbrt;
35849
35850- while (i > newbrt) {
35851- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35852- i--;
35853- }
35854- while (i < newbrt) {
35855- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35856- i++;
35857- }
35858+ while (i > newbrt) {
35859+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35860+ i--;
35861+ }
35862+ while (i < newbrt) {
35863+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35864+ i++;
35865 }
35866+}
35867
35868+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35869+ struct tp_nvram_state *newn,
35870+ const u32 event_mask)
35871+{
35872 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35873 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35874 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35875@@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35876 oldn->volume_level != newn->volume_level) {
35877 /* recently muted, or repeated mute keypress, or
35878 * multiple presses ending in mute */
35879- issue_volchange(oldn->volume_level, newn->volume_level);
35880+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35881 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35882 }
35883 } else {
35884@@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35885 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35886 }
35887 if (oldn->volume_level != newn->volume_level) {
35888- issue_volchange(oldn->volume_level, newn->volume_level);
35889+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35890 } else if (oldn->volume_toggle != newn->volume_toggle) {
35891 /* repeated vol up/down keypress at end of scale ? */
35892 if (newn->volume_level == 0)
35893@@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35894 /* handle brightness */
35895 if (oldn->brightness_level != newn->brightness_level) {
35896 issue_brightnesschange(oldn->brightness_level,
35897- newn->brightness_level);
35898+ newn->brightness_level,
35899+ event_mask);
35900 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35901 /* repeated key presses that didn't change state */
35902 if (newn->brightness_level == 0)
35903@@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35904 && !tp_features.bright_unkfw)
35905 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35906 }
35907+}
35908
35909 #undef TPACPI_COMPARE_KEY
35910 #undef TPACPI_MAY_SEND_KEY
35911-}
35912
35913 /*
35914 * Polling driver
35915diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35916index 769d265..a3a05ca 100644
35917--- a/drivers/pnp/pnpbios/bioscalls.c
35918+++ b/drivers/pnp/pnpbios/bioscalls.c
35919@@ -58,7 +58,7 @@ do { \
35920 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35921 } while(0)
35922
35923-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35924+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35925 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35926
35927 /*
35928@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35929
35930 cpu = get_cpu();
35931 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35932+
35933+ pax_open_kernel();
35934 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35935+ pax_close_kernel();
35936
35937 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35938 spin_lock_irqsave(&pnp_bios_lock, flags);
35939@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35940 :"memory");
35941 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35942
35943+ pax_open_kernel();
35944 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35945+ pax_close_kernel();
35946+
35947 put_cpu();
35948
35949 /* If we get here and this is set then the PnP BIOS faulted on us. */
35950@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
35951 return status;
35952 }
35953
35954-void pnpbios_calls_init(union pnp_bios_install_struct *header)
35955+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
35956 {
35957 int i;
35958
35959@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35960 pnp_bios_callpoint.offset = header->fields.pm16offset;
35961 pnp_bios_callpoint.segment = PNP_CS16;
35962
35963+ pax_open_kernel();
35964+
35965 for_each_possible_cpu(i) {
35966 struct desc_struct *gdt = get_cpu_gdt_table(i);
35967 if (!gdt)
35968@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35969 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
35970 (unsigned long)__va(header->fields.pm16dseg));
35971 }
35972+
35973+ pax_close_kernel();
35974 }
35975diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
35976index b0ecacb..7c9da2e 100644
35977--- a/drivers/pnp/resource.c
35978+++ b/drivers/pnp/resource.c
35979@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
35980 return 1;
35981
35982 /* check if the resource is valid */
35983- if (*irq < 0 || *irq > 15)
35984+ if (*irq > 15)
35985 return 0;
35986
35987 /* check if the resource is reserved */
35988@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
35989 return 1;
35990
35991 /* check if the resource is valid */
35992- if (*dma < 0 || *dma == 4 || *dma > 7)
35993+ if (*dma == 4 || *dma > 7)
35994 return 0;
35995
35996 /* check if the resource is reserved */
35997diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
35998index f5d6d37..739f6a9 100644
35999--- a/drivers/power/bq27x00_battery.c
36000+++ b/drivers/power/bq27x00_battery.c
36001@@ -72,7 +72,7 @@
36002 struct bq27x00_device_info;
36003 struct bq27x00_access_methods {
36004 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36005-};
36006+} __no_const;
36007
36008 enum bq27x00_chip { BQ27000, BQ27500 };
36009
36010diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36011index 8d53174..04c65de 100644
36012--- a/drivers/regulator/max8660.c
36013+++ b/drivers/regulator/max8660.c
36014@@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36015 max8660->shadow_regs[MAX8660_OVER1] = 5;
36016 } else {
36017 /* Otherwise devices can be toggled via software */
36018- max8660_dcdc_ops.enable = max8660_dcdc_enable;
36019- max8660_dcdc_ops.disable = max8660_dcdc_disable;
36020+ pax_open_kernel();
36021+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36022+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36023+ pax_close_kernel();
36024 }
36025
36026 /*
36027diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36028index 970a233..ee1f241 100644
36029--- a/drivers/regulator/mc13892-regulator.c
36030+++ b/drivers/regulator/mc13892-regulator.c
36031@@ -566,10 +566,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36032 }
36033 mc13xxx_unlock(mc13892);
36034
36035- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36036+ pax_open_kernel();
36037+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36038 = mc13892_vcam_set_mode;
36039- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36040+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36041 = mc13892_vcam_get_mode;
36042+ pax_close_kernel();
36043
36044 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36045 ARRAY_SIZE(mc13892_regulators));
36046diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36047index cace6d3..f623fda 100644
36048--- a/drivers/rtc/rtc-dev.c
36049+++ b/drivers/rtc/rtc-dev.c
36050@@ -14,6 +14,7 @@
36051 #include <linux/module.h>
36052 #include <linux/rtc.h>
36053 #include <linux/sched.h>
36054+#include <linux/grsecurity.h>
36055 #include "rtc-core.h"
36056
36057 static dev_t rtc_devt;
36058@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36059 if (copy_from_user(&tm, uarg, sizeof(tm)))
36060 return -EFAULT;
36061
36062+ gr_log_timechange();
36063+
36064 return rtc_set_time(rtc, &tm);
36065
36066 case RTC_PIE_ON:
36067diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36068index 3fcf627..f334910 100644
36069--- a/drivers/scsi/aacraid/aacraid.h
36070+++ b/drivers/scsi/aacraid/aacraid.h
36071@@ -492,7 +492,7 @@ struct adapter_ops
36072 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36073 /* Administrative operations */
36074 int (*adapter_comm)(struct aac_dev * dev, int comm);
36075-};
36076+} __no_const;
36077
36078 /*
36079 * Define which interrupt handler needs to be installed
36080diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36081index 0d279c44..3d25a97 100644
36082--- a/drivers/scsi/aacraid/linit.c
36083+++ b/drivers/scsi/aacraid/linit.c
36084@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36085 #elif defined(__devinitconst)
36086 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36087 #else
36088-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36089+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36090 #endif
36091 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36092 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36093diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36094index ff80552..1c4120c 100644
36095--- a/drivers/scsi/aic94xx/aic94xx_init.c
36096+++ b/drivers/scsi/aic94xx/aic94xx_init.c
36097@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36098 .lldd_ata_set_dmamode = asd_set_dmamode,
36099 };
36100
36101-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36102+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36103 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36104 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36105 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36106diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36107index 4ad7e36..d004679 100644
36108--- a/drivers/scsi/bfa/bfa.h
36109+++ b/drivers/scsi/bfa/bfa.h
36110@@ -196,7 +196,7 @@ struct bfa_hwif_s {
36111 u32 *end);
36112 int cpe_vec_q0;
36113 int rme_vec_q0;
36114-};
36115+} __no_const;
36116 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36117
36118 struct bfa_faa_cbfn_s {
36119diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36120index f0f80e2..8ec946b 100644
36121--- a/drivers/scsi/bfa/bfa_fcpim.c
36122+++ b/drivers/scsi/bfa/bfa_fcpim.c
36123@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36124
36125 bfa_iotag_attach(fcp);
36126
36127- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36128+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36129 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36130 (fcp->num_itns * sizeof(struct bfa_itn_s));
36131 memset(fcp->itn_arr, 0,
36132@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36133 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36134 {
36135 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36136- struct bfa_itn_s *itn;
36137+ bfa_itn_s_no_const *itn;
36138
36139 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36140 itn->isr = isr;
36141diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36142index 36f26da..38a34a8 100644
36143--- a/drivers/scsi/bfa/bfa_fcpim.h
36144+++ b/drivers/scsi/bfa/bfa_fcpim.h
36145@@ -37,6 +37,7 @@ struct bfa_iotag_s {
36146 struct bfa_itn_s {
36147 bfa_isr_func_t isr;
36148 };
36149+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36150
36151 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36152 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36153@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36154 struct list_head iotag_tio_free_q; /* free IO resources */
36155 struct list_head iotag_unused_q; /* unused IO resources*/
36156 struct bfa_iotag_s *iotag_arr;
36157- struct bfa_itn_s *itn_arr;
36158+ bfa_itn_s_no_const *itn_arr;
36159 int num_ioim_reqs;
36160 int num_fwtio_reqs;
36161 int num_itns;
36162diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36163index 1a99d4b..e85d64b 100644
36164--- a/drivers/scsi/bfa/bfa_ioc.h
36165+++ b/drivers/scsi/bfa/bfa_ioc.h
36166@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36167 bfa_ioc_disable_cbfn_t disable_cbfn;
36168 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36169 bfa_ioc_reset_cbfn_t reset_cbfn;
36170-};
36171+} __no_const;
36172
36173 /*
36174 * IOC event notification mechanism.
36175@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36176 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36177 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36178 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36179-};
36180+} __no_const;
36181
36182 /*
36183 * Queue element to wait for room in request queue. FIFO order is
36184diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36185index a3a056a..b9bbc2f 100644
36186--- a/drivers/scsi/hosts.c
36187+++ b/drivers/scsi/hosts.c
36188@@ -42,7 +42,7 @@
36189 #include "scsi_logging.h"
36190
36191
36192-static atomic_t scsi_host_next_hn; /* host_no for next new host */
36193+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36194
36195
36196 static void scsi_host_cls_release(struct device *dev)
36197@@ -360,7 +360,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36198 * subtract one because we increment first then return, but we need to
36199 * know what the next host number was before increment
36200 */
36201- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36202+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36203 shost->dma_channel = 0xff;
36204
36205 /* These three are default values which can be overridden */
36206diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36207index 796482b..d08435c 100644
36208--- a/drivers/scsi/hpsa.c
36209+++ b/drivers/scsi/hpsa.c
36210@@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36211 unsigned long flags;
36212
36213 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36214- return h->access.command_completed(h, q);
36215+ return h->access->command_completed(h, q);
36216
36217 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36218 a = rq->head[rq->current_entry];
36219@@ -3354,7 +3354,7 @@ static void start_io(struct ctlr_info *h)
36220 while (!list_empty(&h->reqQ)) {
36221 c = list_entry(h->reqQ.next, struct CommandList, list);
36222 /* can't do anything if fifo is full */
36223- if ((h->access.fifo_full(h))) {
36224+ if ((h->access->fifo_full(h))) {
36225 dev_warn(&h->pdev->dev, "fifo full\n");
36226 break;
36227 }
36228@@ -3376,7 +3376,7 @@ static void start_io(struct ctlr_info *h)
36229
36230 /* Tell the controller execute command */
36231 spin_unlock_irqrestore(&h->lock, flags);
36232- h->access.submit_command(h, c);
36233+ h->access->submit_command(h, c);
36234 spin_lock_irqsave(&h->lock, flags);
36235 }
36236 spin_unlock_irqrestore(&h->lock, flags);
36237@@ -3384,17 +3384,17 @@ static void start_io(struct ctlr_info *h)
36238
36239 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36240 {
36241- return h->access.command_completed(h, q);
36242+ return h->access->command_completed(h, q);
36243 }
36244
36245 static inline bool interrupt_pending(struct ctlr_info *h)
36246 {
36247- return h->access.intr_pending(h);
36248+ return h->access->intr_pending(h);
36249 }
36250
36251 static inline long interrupt_not_for_us(struct ctlr_info *h)
36252 {
36253- return (h->access.intr_pending(h) == 0) ||
36254+ return (h->access->intr_pending(h) == 0) ||
36255 (h->interrupts_enabled == 0);
36256 }
36257
36258@@ -4298,7 +4298,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36259 if (prod_index < 0)
36260 return -ENODEV;
36261 h->product_name = products[prod_index].product_name;
36262- h->access = *(products[prod_index].access);
36263+ h->access = products[prod_index].access;
36264
36265 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36266 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36267@@ -4580,7 +4580,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36268
36269 assert_spin_locked(&lockup_detector_lock);
36270 remove_ctlr_from_lockup_detector_list(h);
36271- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36272+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36273 spin_lock_irqsave(&h->lock, flags);
36274 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36275 spin_unlock_irqrestore(&h->lock, flags);
36276@@ -4758,7 +4758,7 @@ reinit_after_soft_reset:
36277 }
36278
36279 /* make sure the board interrupts are off */
36280- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36281+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36282
36283 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36284 goto clean2;
36285@@ -4792,7 +4792,7 @@ reinit_after_soft_reset:
36286 * fake ones to scoop up any residual completions.
36287 */
36288 spin_lock_irqsave(&h->lock, flags);
36289- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36290+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36291 spin_unlock_irqrestore(&h->lock, flags);
36292 free_irqs(h);
36293 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36294@@ -4811,9 +4811,9 @@ reinit_after_soft_reset:
36295 dev_info(&h->pdev->dev, "Board READY.\n");
36296 dev_info(&h->pdev->dev,
36297 "Waiting for stale completions to drain.\n");
36298- h->access.set_intr_mask(h, HPSA_INTR_ON);
36299+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36300 msleep(10000);
36301- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36302+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36303
36304 rc = controller_reset_failed(h->cfgtable);
36305 if (rc)
36306@@ -4834,7 +4834,7 @@ reinit_after_soft_reset:
36307 }
36308
36309 /* Turn the interrupts on so we can service requests */
36310- h->access.set_intr_mask(h, HPSA_INTR_ON);
36311+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36312
36313 hpsa_hba_inquiry(h);
36314 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36315@@ -4886,7 +4886,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36316 * To write all data in the battery backed cache to disks
36317 */
36318 hpsa_flush_cache(h);
36319- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36320+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36321 hpsa_free_irqs_and_disable_msix(h);
36322 }
36323
36324@@ -5055,7 +5055,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36325 return;
36326 }
36327 /* Change the access methods to the performant access methods */
36328- h->access = SA5_performant_access;
36329+ h->access = &SA5_performant_access;
36330 h->transMethod = CFGTBL_Trans_Performant;
36331 }
36332
36333diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36334index 9816479..c5d4e97 100644
36335--- a/drivers/scsi/hpsa.h
36336+++ b/drivers/scsi/hpsa.h
36337@@ -79,7 +79,7 @@ struct ctlr_info {
36338 unsigned int msix_vector;
36339 unsigned int msi_vector;
36340 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36341- struct access_method access;
36342+ struct access_method *access;
36343
36344 /* queue and queue Info */
36345 struct list_head reqQ;
36346diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36347index f2df059..a3a9930 100644
36348--- a/drivers/scsi/ips.h
36349+++ b/drivers/scsi/ips.h
36350@@ -1027,7 +1027,7 @@ typedef struct {
36351 int (*intr)(struct ips_ha *);
36352 void (*enableint)(struct ips_ha *);
36353 uint32_t (*statupd)(struct ips_ha *);
36354-} ips_hw_func_t;
36355+} __no_const ips_hw_func_t;
36356
36357 typedef struct ips_ha {
36358 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36359diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36360index aceffad..c35c08d 100644
36361--- a/drivers/scsi/libfc/fc_exch.c
36362+++ b/drivers/scsi/libfc/fc_exch.c
36363@@ -105,12 +105,12 @@ struct fc_exch_mgr {
36364 * all together if not used XXX
36365 */
36366 struct {
36367- atomic_t no_free_exch;
36368- atomic_t no_free_exch_xid;
36369- atomic_t xid_not_found;
36370- atomic_t xid_busy;
36371- atomic_t seq_not_found;
36372- atomic_t non_bls_resp;
36373+ atomic_unchecked_t no_free_exch;
36374+ atomic_unchecked_t no_free_exch_xid;
36375+ atomic_unchecked_t xid_not_found;
36376+ atomic_unchecked_t xid_busy;
36377+ atomic_unchecked_t seq_not_found;
36378+ atomic_unchecked_t non_bls_resp;
36379 } stats;
36380 };
36381
36382@@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36383 /* allocate memory for exchange */
36384 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36385 if (!ep) {
36386- atomic_inc(&mp->stats.no_free_exch);
36387+ atomic_inc_unchecked(&mp->stats.no_free_exch);
36388 goto out;
36389 }
36390 memset(ep, 0, sizeof(*ep));
36391@@ -780,7 +780,7 @@ out:
36392 return ep;
36393 err:
36394 spin_unlock_bh(&pool->lock);
36395- atomic_inc(&mp->stats.no_free_exch_xid);
36396+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36397 mempool_free(ep, mp->ep_pool);
36398 return NULL;
36399 }
36400@@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36401 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36402 ep = fc_exch_find(mp, xid);
36403 if (!ep) {
36404- atomic_inc(&mp->stats.xid_not_found);
36405+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36406 reject = FC_RJT_OX_ID;
36407 goto out;
36408 }
36409@@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36410 ep = fc_exch_find(mp, xid);
36411 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36412 if (ep) {
36413- atomic_inc(&mp->stats.xid_busy);
36414+ atomic_inc_unchecked(&mp->stats.xid_busy);
36415 reject = FC_RJT_RX_ID;
36416 goto rel;
36417 }
36418@@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36419 }
36420 xid = ep->xid; /* get our XID */
36421 } else if (!ep) {
36422- atomic_inc(&mp->stats.xid_not_found);
36423+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36424 reject = FC_RJT_RX_ID; /* XID not found */
36425 goto out;
36426 }
36427@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36428 } else {
36429 sp = &ep->seq;
36430 if (sp->id != fh->fh_seq_id) {
36431- atomic_inc(&mp->stats.seq_not_found);
36432+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36433 if (f_ctl & FC_FC_END_SEQ) {
36434 /*
36435 * Update sequence_id based on incoming last
36436@@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36437
36438 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36439 if (!ep) {
36440- atomic_inc(&mp->stats.xid_not_found);
36441+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36442 goto out;
36443 }
36444 if (ep->esb_stat & ESB_ST_COMPLETE) {
36445- atomic_inc(&mp->stats.xid_not_found);
36446+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36447 goto rel;
36448 }
36449 if (ep->rxid == FC_XID_UNKNOWN)
36450 ep->rxid = ntohs(fh->fh_rx_id);
36451 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36452- atomic_inc(&mp->stats.xid_not_found);
36453+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36454 goto rel;
36455 }
36456 if (ep->did != ntoh24(fh->fh_s_id) &&
36457 ep->did != FC_FID_FLOGI) {
36458- atomic_inc(&mp->stats.xid_not_found);
36459+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36460 goto rel;
36461 }
36462 sof = fr_sof(fp);
36463@@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36464 sp->ssb_stat |= SSB_ST_RESP;
36465 sp->id = fh->fh_seq_id;
36466 } else if (sp->id != fh->fh_seq_id) {
36467- atomic_inc(&mp->stats.seq_not_found);
36468+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36469 goto rel;
36470 }
36471
36472@@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36473 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36474
36475 if (!sp)
36476- atomic_inc(&mp->stats.xid_not_found);
36477+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36478 else
36479- atomic_inc(&mp->stats.non_bls_resp);
36480+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
36481
36482 fc_frame_free(fp);
36483 }
36484diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36485index d109cc3..09f4e7d 100644
36486--- a/drivers/scsi/libsas/sas_ata.c
36487+++ b/drivers/scsi/libsas/sas_ata.c
36488@@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36489 .postreset = ata_std_postreset,
36490 .error_handler = ata_std_error_handler,
36491 .post_internal_cmd = sas_ata_post_internal,
36492- .qc_defer = ata_std_qc_defer,
36493+ .qc_defer = ata_std_qc_defer,
36494 .qc_prep = ata_noop_qc_prep,
36495 .qc_issue = sas_ata_qc_issue,
36496 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36497diff --git a/drivers/scsi/lpfc/Makefile b/drivers/scsi/lpfc/Makefile
36498index fe5d396..e93d526 100644
36499--- a/drivers/scsi/lpfc/Makefile
36500+++ b/drivers/scsi/lpfc/Makefile
36501@@ -22,7 +22,7 @@
36502 ccflags-$(GCOV) := -fprofile-arcs -ftest-coverage
36503 ccflags-$(GCOV) += -O0
36504
36505-ccflags-y += -Werror
36506+#ccflags-y += -Werror
36507
36508 obj-$(CONFIG_SCSI_LPFC) := lpfc.o
36509
36510diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36511index e5da6da..c888d48 100644
36512--- a/drivers/scsi/lpfc/lpfc.h
36513+++ b/drivers/scsi/lpfc/lpfc.h
36514@@ -416,7 +416,7 @@ struct lpfc_vport {
36515 struct dentry *debug_nodelist;
36516 struct dentry *vport_debugfs_root;
36517 struct lpfc_debugfs_trc *disc_trc;
36518- atomic_t disc_trc_cnt;
36519+ atomic_unchecked_t disc_trc_cnt;
36520 #endif
36521 uint8_t stat_data_enabled;
36522 uint8_t stat_data_blocked;
36523@@ -830,8 +830,8 @@ struct lpfc_hba {
36524 struct timer_list fabric_block_timer;
36525 unsigned long bit_flags;
36526 #define FABRIC_COMANDS_BLOCKED 0
36527- atomic_t num_rsrc_err;
36528- atomic_t num_cmd_success;
36529+ atomic_unchecked_t num_rsrc_err;
36530+ atomic_unchecked_t num_cmd_success;
36531 unsigned long last_rsrc_error_time;
36532 unsigned long last_ramp_down_time;
36533 unsigned long last_ramp_up_time;
36534@@ -867,7 +867,7 @@ struct lpfc_hba {
36535
36536 struct dentry *debug_slow_ring_trc;
36537 struct lpfc_debugfs_trc *slow_ring_trc;
36538- atomic_t slow_ring_trc_cnt;
36539+ atomic_unchecked_t slow_ring_trc_cnt;
36540 /* iDiag debugfs sub-directory */
36541 struct dentry *idiag_root;
36542 struct dentry *idiag_pci_cfg;
36543diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36544index 3217d63..c417981 100644
36545--- a/drivers/scsi/lpfc/lpfc_debugfs.c
36546+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36547@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36548
36549 #include <linux/debugfs.h>
36550
36551-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36552+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36553 static unsigned long lpfc_debugfs_start_time = 0L;
36554
36555 /* iDiag */
36556@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36557 lpfc_debugfs_enable = 0;
36558
36559 len = 0;
36560- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36561+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36562 (lpfc_debugfs_max_disc_trc - 1);
36563 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36564 dtp = vport->disc_trc + i;
36565@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36566 lpfc_debugfs_enable = 0;
36567
36568 len = 0;
36569- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36570+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36571 (lpfc_debugfs_max_slow_ring_trc - 1);
36572 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36573 dtp = phba->slow_ring_trc + i;
36574@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36575 !vport || !vport->disc_trc)
36576 return;
36577
36578- index = atomic_inc_return(&vport->disc_trc_cnt) &
36579+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36580 (lpfc_debugfs_max_disc_trc - 1);
36581 dtp = vport->disc_trc + index;
36582 dtp->fmt = fmt;
36583 dtp->data1 = data1;
36584 dtp->data2 = data2;
36585 dtp->data3 = data3;
36586- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36587+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36588 dtp->jif = jiffies;
36589 #endif
36590 return;
36591@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36592 !phba || !phba->slow_ring_trc)
36593 return;
36594
36595- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36596+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36597 (lpfc_debugfs_max_slow_ring_trc - 1);
36598 dtp = phba->slow_ring_trc + index;
36599 dtp->fmt = fmt;
36600 dtp->data1 = data1;
36601 dtp->data2 = data2;
36602 dtp->data3 = data3;
36603- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36604+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36605 dtp->jif = jiffies;
36606 #endif
36607 return;
36608@@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36609 "slow_ring buffer\n");
36610 goto debug_failed;
36611 }
36612- atomic_set(&phba->slow_ring_trc_cnt, 0);
36613+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36614 memset(phba->slow_ring_trc, 0,
36615 (sizeof(struct lpfc_debugfs_trc) *
36616 lpfc_debugfs_max_slow_ring_trc));
36617@@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36618 "buffer\n");
36619 goto debug_failed;
36620 }
36621- atomic_set(&vport->disc_trc_cnt, 0);
36622+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36623
36624 snprintf(name, sizeof(name), "discovery_trace");
36625 vport->debug_disc_trc =
36626diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36627index 411ed48..967f553 100644
36628--- a/drivers/scsi/lpfc/lpfc_init.c
36629+++ b/drivers/scsi/lpfc/lpfc_init.c
36630@@ -10341,8 +10341,10 @@ lpfc_init(void)
36631 "misc_register returned with status %d", error);
36632
36633 if (lpfc_enable_npiv) {
36634- lpfc_transport_functions.vport_create = lpfc_vport_create;
36635- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36636+ pax_open_kernel();
36637+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36638+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36639+ pax_close_kernel();
36640 }
36641 lpfc_transport_template =
36642 fc_attach_transport(&lpfc_transport_functions);
36643diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36644index 66e0906..1620281 100644
36645--- a/drivers/scsi/lpfc/lpfc_scsi.c
36646+++ b/drivers/scsi/lpfc/lpfc_scsi.c
36647@@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36648 uint32_t evt_posted;
36649
36650 spin_lock_irqsave(&phba->hbalock, flags);
36651- atomic_inc(&phba->num_rsrc_err);
36652+ atomic_inc_unchecked(&phba->num_rsrc_err);
36653 phba->last_rsrc_error_time = jiffies;
36654
36655 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36656@@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36657 unsigned long flags;
36658 struct lpfc_hba *phba = vport->phba;
36659 uint32_t evt_posted;
36660- atomic_inc(&phba->num_cmd_success);
36661+ atomic_inc_unchecked(&phba->num_cmd_success);
36662
36663 if (vport->cfg_lun_queue_depth <= queue_depth)
36664 return;
36665@@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36666 unsigned long num_rsrc_err, num_cmd_success;
36667 int i;
36668
36669- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36670- num_cmd_success = atomic_read(&phba->num_cmd_success);
36671+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36672+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36673
36674 /*
36675 * The error and success command counters are global per
36676@@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36677 }
36678 }
36679 lpfc_destroy_vport_work_array(phba, vports);
36680- atomic_set(&phba->num_rsrc_err, 0);
36681- atomic_set(&phba->num_cmd_success, 0);
36682+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36683+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36684 }
36685
36686 /**
36687@@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36688 }
36689 }
36690 lpfc_destroy_vport_work_array(phba, vports);
36691- atomic_set(&phba->num_rsrc_err, 0);
36692- atomic_set(&phba->num_cmd_success, 0);
36693+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36694+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36695 }
36696
36697 /**
36698diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36699index ea8a0b4..812a124 100644
36700--- a/drivers/scsi/pmcraid.c
36701+++ b/drivers/scsi/pmcraid.c
36702@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36703 res->scsi_dev = scsi_dev;
36704 scsi_dev->hostdata = res;
36705 res->change_detected = 0;
36706- atomic_set(&res->read_failures, 0);
36707- atomic_set(&res->write_failures, 0);
36708+ atomic_set_unchecked(&res->read_failures, 0);
36709+ atomic_set_unchecked(&res->write_failures, 0);
36710 rc = 0;
36711 }
36712 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36713@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36714
36715 /* If this was a SCSI read/write command keep count of errors */
36716 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36717- atomic_inc(&res->read_failures);
36718+ atomic_inc_unchecked(&res->read_failures);
36719 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36720- atomic_inc(&res->write_failures);
36721+ atomic_inc_unchecked(&res->write_failures);
36722
36723 if (!RES_IS_GSCSI(res->cfg_entry) &&
36724 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36725@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36726 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36727 * hrrq_id assigned here in queuecommand
36728 */
36729- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36730+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36731 pinstance->num_hrrq;
36732 cmd->cmd_done = pmcraid_io_done;
36733
36734@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36735 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36736 * hrrq_id assigned here in queuecommand
36737 */
36738- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36739+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36740 pinstance->num_hrrq;
36741
36742 if (request_size) {
36743@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36744
36745 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36746 /* add resources only after host is added into system */
36747- if (!atomic_read(&pinstance->expose_resources))
36748+ if (!atomic_read_unchecked(&pinstance->expose_resources))
36749 return;
36750
36751 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36752@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36753 init_waitqueue_head(&pinstance->reset_wait_q);
36754
36755 atomic_set(&pinstance->outstanding_cmds, 0);
36756- atomic_set(&pinstance->last_message_id, 0);
36757- atomic_set(&pinstance->expose_resources, 0);
36758+ atomic_set_unchecked(&pinstance->last_message_id, 0);
36759+ atomic_set_unchecked(&pinstance->expose_resources, 0);
36760
36761 INIT_LIST_HEAD(&pinstance->free_res_q);
36762 INIT_LIST_HEAD(&pinstance->used_res_q);
36763@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36764 /* Schedule worker thread to handle CCN and take care of adding and
36765 * removing devices to OS
36766 */
36767- atomic_set(&pinstance->expose_resources, 1);
36768+ atomic_set_unchecked(&pinstance->expose_resources, 1);
36769 schedule_work(&pinstance->worker_q);
36770 return rc;
36771
36772diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36773index e1d150f..6c6df44 100644
36774--- a/drivers/scsi/pmcraid.h
36775+++ b/drivers/scsi/pmcraid.h
36776@@ -748,7 +748,7 @@ struct pmcraid_instance {
36777 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36778
36779 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36780- atomic_t last_message_id;
36781+ atomic_unchecked_t last_message_id;
36782
36783 /* configuration table */
36784 struct pmcraid_config_table *cfg_table;
36785@@ -777,7 +777,7 @@ struct pmcraid_instance {
36786 atomic_t outstanding_cmds;
36787
36788 /* should add/delete resources to mid-layer now ?*/
36789- atomic_t expose_resources;
36790+ atomic_unchecked_t expose_resources;
36791
36792
36793
36794@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36795 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36796 };
36797 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36798- atomic_t read_failures; /* count of failed READ commands */
36799- atomic_t write_failures; /* count of failed WRITE commands */
36800+ atomic_unchecked_t read_failures; /* count of failed READ commands */
36801+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36802
36803 /* To indicate add/delete/modify during CCN */
36804 u8 change_detected;
36805diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
36806index 5ab9530..2dd80f7 100644
36807--- a/drivers/scsi/qla2xxx/qla_attr.c
36808+++ b/drivers/scsi/qla2xxx/qla_attr.c
36809@@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
36810 return 0;
36811 }
36812
36813-struct fc_function_template qla2xxx_transport_functions = {
36814+fc_function_template_no_const qla2xxx_transport_functions = {
36815
36816 .show_host_node_name = 1,
36817 .show_host_port_name = 1,
36818@@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
36819 .bsg_timeout = qla24xx_bsg_timeout,
36820 };
36821
36822-struct fc_function_template qla2xxx_transport_vport_functions = {
36823+fc_function_template_no_const qla2xxx_transport_vport_functions = {
36824
36825 .show_host_node_name = 1,
36826 .show_host_port_name = 1,
36827diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36828index 39007f5..7fafc64 100644
36829--- a/drivers/scsi/qla2xxx/qla_def.h
36830+++ b/drivers/scsi/qla2xxx/qla_def.h
36831@@ -2284,7 +2284,7 @@ struct isp_operations {
36832 int (*start_scsi) (srb_t *);
36833 int (*abort_isp) (struct scsi_qla_host *);
36834 int (*iospace_config)(struct qla_hw_data*);
36835-};
36836+} __no_const;
36837
36838 /* MSI-X Support *************************************************************/
36839
36840diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
36841index 9eacd2d..d79629c 100644
36842--- a/drivers/scsi/qla2xxx/qla_gbl.h
36843+++ b/drivers/scsi/qla2xxx/qla_gbl.h
36844@@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
36845 struct device_attribute;
36846 extern struct device_attribute *qla2x00_host_attrs[];
36847 struct fc_function_template;
36848-extern struct fc_function_template qla2xxx_transport_functions;
36849-extern struct fc_function_template qla2xxx_transport_vport_functions;
36850+extern fc_function_template_no_const qla2xxx_transport_functions;
36851+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
36852 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
36853 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
36854 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
36855diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36856index 96a5616..eeb185a 100644
36857--- a/drivers/scsi/qla4xxx/ql4_def.h
36858+++ b/drivers/scsi/qla4xxx/ql4_def.h
36859@@ -268,7 +268,7 @@ struct ddb_entry {
36860 * (4000 only) */
36861 atomic_t relogin_timer; /* Max Time to wait for
36862 * relogin to complete */
36863- atomic_t relogin_retry_count; /* Num of times relogin has been
36864+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36865 * retried */
36866 uint32_t default_time2wait; /* Default Min time between
36867 * relogins (+aens) */
36868diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36869index cd15678..f7e6846 100644
36870--- a/drivers/scsi/qla4xxx/ql4_os.c
36871+++ b/drivers/scsi/qla4xxx/ql4_os.c
36872@@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36873 */
36874 if (!iscsi_is_session_online(cls_sess)) {
36875 /* Reset retry relogin timer */
36876- atomic_inc(&ddb_entry->relogin_retry_count);
36877+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36878 DEBUG2(ql4_printk(KERN_INFO, ha,
36879 "%s: index[%d] relogin timed out-retrying"
36880 " relogin (%d), retry (%d)\n", __func__,
36881 ddb_entry->fw_ddb_index,
36882- atomic_read(&ddb_entry->relogin_retry_count),
36883+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36884 ddb_entry->default_time2wait + 4));
36885 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36886 atomic_set(&ddb_entry->retry_relogin_timer,
36887@@ -4517,7 +4517,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36888
36889 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36890 atomic_set(&ddb_entry->relogin_timer, 0);
36891- atomic_set(&ddb_entry->relogin_retry_count, 0);
36892+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36893 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36894 ddb_entry->default_relogin_timeout =
36895 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
36896diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36897index bbbc9c9..ce22f77 100644
36898--- a/drivers/scsi/scsi.c
36899+++ b/drivers/scsi/scsi.c
36900@@ -659,7 +659,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36901 unsigned long timeout;
36902 int rtn = 0;
36903
36904- atomic_inc(&cmd->device->iorequest_cnt);
36905+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36906
36907 /* check if the device is still usable */
36908 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36909diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36910index 6dfb978..ddc470e 100644
36911--- a/drivers/scsi/scsi_lib.c
36912+++ b/drivers/scsi/scsi_lib.c
36913@@ -1415,7 +1415,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36914 shost = sdev->host;
36915 scsi_init_cmd_errh(cmd);
36916 cmd->result = DID_NO_CONNECT << 16;
36917- atomic_inc(&cmd->device->iorequest_cnt);
36918+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36919
36920 /*
36921 * SCSI request completion path will do scsi_device_unbusy(),
36922@@ -1441,9 +1441,9 @@ static void scsi_softirq_done(struct request *rq)
36923
36924 INIT_LIST_HEAD(&cmd->eh_entry);
36925
36926- atomic_inc(&cmd->device->iodone_cnt);
36927+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
36928 if (cmd->result)
36929- atomic_inc(&cmd->device->ioerr_cnt);
36930+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36931
36932 disposition = scsi_decide_disposition(cmd);
36933 if (disposition != SUCCESS &&
36934diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36935index 04c2a27..9d8bd66 100644
36936--- a/drivers/scsi/scsi_sysfs.c
36937+++ b/drivers/scsi/scsi_sysfs.c
36938@@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36939 char *buf) \
36940 { \
36941 struct scsi_device *sdev = to_scsi_device(dev); \
36942- unsigned long long count = atomic_read(&sdev->field); \
36943+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
36944 return snprintf(buf, 20, "0x%llx\n", count); \
36945 } \
36946 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36947diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36948index 84a1fdf..693b0d6 100644
36949--- a/drivers/scsi/scsi_tgt_lib.c
36950+++ b/drivers/scsi/scsi_tgt_lib.c
36951@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36952 int err;
36953
36954 dprintk("%lx %u\n", uaddr, len);
36955- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36956+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36957 if (err) {
36958 /*
36959 * TODO: need to fixup sg_tablesize, max_segment_size,
36960diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36961index 5797604..289a5b5 100644
36962--- a/drivers/scsi/scsi_transport_fc.c
36963+++ b/drivers/scsi/scsi_transport_fc.c
36964@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36965 * Netlink Infrastructure
36966 */
36967
36968-static atomic_t fc_event_seq;
36969+static atomic_unchecked_t fc_event_seq;
36970
36971 /**
36972 * fc_get_event_number - Obtain the next sequential FC event number
36973@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
36974 u32
36975 fc_get_event_number(void)
36976 {
36977- return atomic_add_return(1, &fc_event_seq);
36978+ return atomic_add_return_unchecked(1, &fc_event_seq);
36979 }
36980 EXPORT_SYMBOL(fc_get_event_number);
36981
36982@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
36983 {
36984 int error;
36985
36986- atomic_set(&fc_event_seq, 0);
36987+ atomic_set_unchecked(&fc_event_seq, 0);
36988
36989 error = transport_class_register(&fc_host_class);
36990 if (error)
36991@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
36992 char *cp;
36993
36994 *val = simple_strtoul(buf, &cp, 0);
36995- if ((*cp && (*cp != '\n')) || (*val < 0))
36996+ if (*cp && (*cp != '\n'))
36997 return -EINVAL;
36998 /*
36999 * Check for overflow; dev_loss_tmo is u32
37000diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37001index 1cf640e..78e9014 100644
37002--- a/drivers/scsi/scsi_transport_iscsi.c
37003+++ b/drivers/scsi/scsi_transport_iscsi.c
37004@@ -79,7 +79,7 @@ struct iscsi_internal {
37005 struct transport_container session_cont;
37006 };
37007
37008-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37009+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37010 static struct workqueue_struct *iscsi_eh_timer_workq;
37011
37012 static DEFINE_IDA(iscsi_sess_ida);
37013@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37014 int err;
37015
37016 ihost = shost->shost_data;
37017- session->sid = atomic_add_return(1, &iscsi_session_nr);
37018+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37019
37020 if (target_id == ISCSI_MAX_TARGET) {
37021 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37022@@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37023 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37024 ISCSI_TRANSPORT_VERSION);
37025
37026- atomic_set(&iscsi_session_nr, 0);
37027+ atomic_set_unchecked(&iscsi_session_nr, 0);
37028
37029 err = class_register(&iscsi_transport_class);
37030 if (err)
37031diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37032index 21a045e..ec89e03 100644
37033--- a/drivers/scsi/scsi_transport_srp.c
37034+++ b/drivers/scsi/scsi_transport_srp.c
37035@@ -33,7 +33,7 @@
37036 #include "scsi_transport_srp_internal.h"
37037
37038 struct srp_host_attrs {
37039- atomic_t next_port_id;
37040+ atomic_unchecked_t next_port_id;
37041 };
37042 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37043
37044@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37045 struct Scsi_Host *shost = dev_to_shost(dev);
37046 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37047
37048- atomic_set(&srp_host->next_port_id, 0);
37049+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37050 return 0;
37051 }
37052
37053@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37054 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37055 rport->roles = ids->roles;
37056
37057- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37058+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37059 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37060
37061 transport_setup_device(&rport->dev);
37062diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37063index 9c5c5f2..8414557 100644
37064--- a/drivers/scsi/sg.c
37065+++ b/drivers/scsi/sg.c
37066@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37067 sdp->disk->disk_name,
37068 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37069 NULL,
37070- (char *)arg);
37071+ (char __user *)arg);
37072 case BLKTRACESTART:
37073 return blk_trace_startstop(sdp->device->request_queue, 1);
37074 case BLKTRACESTOP:
37075diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37076index 1041cb8..4a946fa 100644
37077--- a/drivers/spi/spi.c
37078+++ b/drivers/spi/spi.c
37079@@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37080 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37081
37082 /* portable code must never pass more than 32 bytes */
37083-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37084+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37085
37086 static u8 *buf;
37087
37088diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37089index 34afc16..ffe44dd 100644
37090--- a/drivers/staging/octeon/ethernet-rx.c
37091+++ b/drivers/staging/octeon/ethernet-rx.c
37092@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37093 /* Increment RX stats for virtual ports */
37094 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37095 #ifdef CONFIG_64BIT
37096- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37097- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37098+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37099+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37100 #else
37101- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37102- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37103+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37104+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37105 #endif
37106 }
37107 netif_receive_skb(skb);
37108@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37109 dev->name);
37110 */
37111 #ifdef CONFIG_64BIT
37112- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37113+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37114 #else
37115- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37116+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37117 #endif
37118 dev_kfree_skb_irq(skb);
37119 }
37120diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37121index 18f7a79..cc3bc24 100644
37122--- a/drivers/staging/octeon/ethernet.c
37123+++ b/drivers/staging/octeon/ethernet.c
37124@@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37125 * since the RX tasklet also increments it.
37126 */
37127 #ifdef CONFIG_64BIT
37128- atomic64_add(rx_status.dropped_packets,
37129- (atomic64_t *)&priv->stats.rx_dropped);
37130+ atomic64_add_unchecked(rx_status.dropped_packets,
37131+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37132 #else
37133- atomic_add(rx_status.dropped_packets,
37134- (atomic_t *)&priv->stats.rx_dropped);
37135+ atomic_add_unchecked(rx_status.dropped_packets,
37136+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37137 #endif
37138 }
37139
37140diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37141index dc23395..cf7e9b1 100644
37142--- a/drivers/staging/rtl8712/rtl871x_io.h
37143+++ b/drivers/staging/rtl8712/rtl871x_io.h
37144@@ -108,7 +108,7 @@ struct _io_ops {
37145 u8 *pmem);
37146 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37147 u8 *pmem);
37148-};
37149+} __no_const;
37150
37151 struct io_req {
37152 struct list_head list;
37153diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37154index c7b5e8b..783d6cb 100644
37155--- a/drivers/staging/sbe-2t3e3/netdev.c
37156+++ b/drivers/staging/sbe-2t3e3/netdev.c
37157@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37158 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37159
37160 if (rlen)
37161- if (copy_to_user(data, &resp, rlen))
37162+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37163 return -EFAULT;
37164
37165 return 0;
37166diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37167index 42cdafe..2769103 100644
37168--- a/drivers/staging/speakup/speakup_soft.c
37169+++ b/drivers/staging/speakup/speakup_soft.c
37170@@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37171 break;
37172 } else if (!initialized) {
37173 if (*init) {
37174- ch = *init;
37175 init++;
37176 } else {
37177 initialized = 1;
37178 }
37179+ ch = *init;
37180 } else {
37181 ch = synth_buffer_getc();
37182 }
37183diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37184index 5d89c0f..9261317 100644
37185--- a/drivers/staging/usbip/usbip_common.h
37186+++ b/drivers/staging/usbip/usbip_common.h
37187@@ -289,7 +289,7 @@ struct usbip_device {
37188 void (*shutdown)(struct usbip_device *);
37189 void (*reset)(struct usbip_device *);
37190 void (*unusable)(struct usbip_device *);
37191- } eh_ops;
37192+ } __no_const eh_ops;
37193 };
37194
37195 #define kthread_get_run(threadfn, data, namefmt, ...) \
37196diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37197index 88b3298..3783eee 100644
37198--- a/drivers/staging/usbip/vhci.h
37199+++ b/drivers/staging/usbip/vhci.h
37200@@ -88,7 +88,7 @@ struct vhci_hcd {
37201 unsigned resuming:1;
37202 unsigned long re_timeout;
37203
37204- atomic_t seqnum;
37205+ atomic_unchecked_t seqnum;
37206
37207 /*
37208 * NOTE:
37209diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37210index f708cba..2de6d72 100644
37211--- a/drivers/staging/usbip/vhci_hcd.c
37212+++ b/drivers/staging/usbip/vhci_hcd.c
37213@@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37214 return;
37215 }
37216
37217- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37218+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37219 if (priv->seqnum == 0xffff)
37220 dev_info(&urb->dev->dev, "seqnum max\n");
37221
37222@@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37223 return -ENOMEM;
37224 }
37225
37226- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37227+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37228 if (unlink->seqnum == 0xffff)
37229 pr_info("seqnum max\n");
37230
37231@@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37232 vdev->rhport = rhport;
37233 }
37234
37235- atomic_set(&vhci->seqnum, 0);
37236+ atomic_set_unchecked(&vhci->seqnum, 0);
37237 spin_lock_init(&vhci->lock);
37238
37239 hcd->power_budget = 0; /* no limit */
37240diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37241index f0eaf04..5a82e06 100644
37242--- a/drivers/staging/usbip/vhci_rx.c
37243+++ b/drivers/staging/usbip/vhci_rx.c
37244@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37245 if (!urb) {
37246 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37247 pr_info("max seqnum %d\n",
37248- atomic_read(&the_controller->seqnum));
37249+ atomic_read_unchecked(&the_controller->seqnum));
37250 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37251 return;
37252 }
37253diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37254index 7735027..30eed13 100644
37255--- a/drivers/staging/vt6655/hostap.c
37256+++ b/drivers/staging/vt6655/hostap.c
37257@@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37258 *
37259 */
37260
37261+static net_device_ops_no_const apdev_netdev_ops;
37262+
37263 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37264 {
37265 PSDevice apdev_priv;
37266 struct net_device *dev = pDevice->dev;
37267 int ret;
37268- const struct net_device_ops apdev_netdev_ops = {
37269- .ndo_start_xmit = pDevice->tx_80211,
37270- };
37271
37272 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37273
37274@@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37275 *apdev_priv = *pDevice;
37276 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37277
37278+ /* only half broken now */
37279+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37280 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37281
37282 pDevice->apdev->type = ARPHRD_IEEE80211;
37283diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37284index 51b5adf..098e320 100644
37285--- a/drivers/staging/vt6656/hostap.c
37286+++ b/drivers/staging/vt6656/hostap.c
37287@@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37288 *
37289 */
37290
37291+static net_device_ops_no_const apdev_netdev_ops;
37292+
37293 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37294 {
37295 PSDevice apdev_priv;
37296 struct net_device *dev = pDevice->dev;
37297 int ret;
37298- const struct net_device_ops apdev_netdev_ops = {
37299- .ndo_start_xmit = pDevice->tx_80211,
37300- };
37301
37302 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37303
37304@@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37305 *apdev_priv = *pDevice;
37306 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37307
37308+ /* only half broken now */
37309+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37310 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37311
37312 pDevice->apdev->type = ARPHRD_IEEE80211;
37313diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37314index 7843dfd..3db105f 100644
37315--- a/drivers/staging/wlan-ng/hfa384x_usb.c
37316+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37317@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37318
37319 struct usbctlx_completor {
37320 int (*complete) (struct usbctlx_completor *);
37321-};
37322+} __no_const;
37323
37324 static int
37325 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37326diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37327index 1ca66ea..76f1343 100644
37328--- a/drivers/staging/zcache/tmem.c
37329+++ b/drivers/staging/zcache/tmem.c
37330@@ -39,7 +39,7 @@
37331 * A tmem host implementation must use this function to register callbacks
37332 * for memory allocation.
37333 */
37334-static struct tmem_hostops tmem_hostops;
37335+static tmem_hostops_no_const tmem_hostops;
37336
37337 static void tmem_objnode_tree_init(void);
37338
37339@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37340 * A tmem host implementation must use this function to register
37341 * callbacks for a page-accessible memory (PAM) implementation
37342 */
37343-static struct tmem_pamops tmem_pamops;
37344+static tmem_pamops_no_const tmem_pamops;
37345
37346 void tmem_register_pamops(struct tmem_pamops *m)
37347 {
37348diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37349index 0d4aa82..f7832d4 100644
37350--- a/drivers/staging/zcache/tmem.h
37351+++ b/drivers/staging/zcache/tmem.h
37352@@ -180,6 +180,7 @@ struct tmem_pamops {
37353 void (*new_obj)(struct tmem_obj *);
37354 int (*replace_in_obj)(void *, struct tmem_obj *);
37355 };
37356+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37357 extern void tmem_register_pamops(struct tmem_pamops *m);
37358
37359 /* memory allocation methods provided by the host implementation */
37360@@ -189,6 +190,7 @@ struct tmem_hostops {
37361 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37362 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37363 };
37364+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37365 extern void tmem_register_hostops(struct tmem_hostops *m);
37366
37367 /* core tmem accessor functions */
37368diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37369index 634d0f3..efff61f 100644
37370--- a/drivers/target/target_core_transport.c
37371+++ b/drivers/target/target_core_transport.c
37372@@ -1233,7 +1233,7 @@ struct se_device *transport_add_device_to_core_hba(
37373 spin_lock_init(&dev->se_port_lock);
37374 spin_lock_init(&dev->se_tmr_lock);
37375 spin_lock_init(&dev->qf_cmd_lock);
37376- atomic_set(&dev->dev_ordered_id, 0);
37377+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
37378
37379 se_dev_set_default_attribs(dev, dev_limits);
37380
37381@@ -1402,7 +1402,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37382 * Used to determine when ORDERED commands should go from
37383 * Dormant to Active status.
37384 */
37385- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37386+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37387 smp_mb__after_atomic_inc();
37388 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37389 cmd->se_ordered_id, cmd->sam_task_attr,
37390diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37391index e61cabd..7617d26 100644
37392--- a/drivers/tty/cyclades.c
37393+++ b/drivers/tty/cyclades.c
37394@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37395 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37396 info->port.count);
37397 #endif
37398- info->port.count++;
37399+ atomic_inc(&info->port.count);
37400 #ifdef CY_DEBUG_COUNT
37401 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37402- current->pid, info->port.count);
37403+ current->pid, atomic_read(&info->port.count));
37404 #endif
37405
37406 /*
37407@@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37408 for (j = 0; j < cy_card[i].nports; j++) {
37409 info = &cy_card[i].ports[j];
37410
37411- if (info->port.count) {
37412+ if (atomic_read(&info->port.count)) {
37413 /* XXX is the ldisc num worth this? */
37414 struct tty_struct *tty;
37415 struct tty_ldisc *ld;
37416diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37417index 2d691eb..be02ebd 100644
37418--- a/drivers/tty/hvc/hvc_console.c
37419+++ b/drivers/tty/hvc/hvc_console.c
37420@@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37421
37422 spin_lock_irqsave(&hp->port.lock, flags);
37423 /* Check and then increment for fast path open. */
37424- if (hp->port.count++ > 0) {
37425+ if (atomic_inc_return(&hp->port.count) > 1) {
37426 spin_unlock_irqrestore(&hp->port.lock, flags);
37427 hvc_kick();
37428 return 0;
37429@@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37430
37431 spin_lock_irqsave(&hp->port.lock, flags);
37432
37433- if (--hp->port.count == 0) {
37434+ if (atomic_dec_return(&hp->port.count) == 0) {
37435 spin_unlock_irqrestore(&hp->port.lock, flags);
37436 /* We are done with the tty pointer now. */
37437 tty_port_tty_set(&hp->port, NULL);
37438@@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37439 */
37440 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37441 } else {
37442- if (hp->port.count < 0)
37443+ if (atomic_read(&hp->port.count) < 0)
37444 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37445- hp->vtermno, hp->port.count);
37446+ hp->vtermno, atomic_read(&hp->port.count));
37447 spin_unlock_irqrestore(&hp->port.lock, flags);
37448 }
37449
37450@@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37451 * open->hangup case this can be called after the final close so prevent
37452 * that from happening for now.
37453 */
37454- if (hp->port.count <= 0) {
37455+ if (atomic_read(&hp->port.count) <= 0) {
37456 spin_unlock_irqrestore(&hp->port.lock, flags);
37457 return;
37458 }
37459
37460- temp_open_count = hp->port.count;
37461- hp->port.count = 0;
37462+ temp_open_count = atomic_read(&hp->port.count);
37463+ atomic_set(&hp->port.count, 0);
37464 spin_unlock_irqrestore(&hp->port.lock, flags);
37465 tty_port_tty_set(&hp->port, NULL);
37466
37467@@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37468 return -EPIPE;
37469
37470 /* FIXME what's this (unprotected) check for? */
37471- if (hp->port.count <= 0)
37472+ if (atomic_read(&hp->port.count) <= 0)
37473 return -EIO;
37474
37475 spin_lock_irqsave(&hp->lock, flags);
37476diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37477index d56788c..12d8f85 100644
37478--- a/drivers/tty/hvc/hvcs.c
37479+++ b/drivers/tty/hvc/hvcs.c
37480@@ -83,6 +83,7 @@
37481 #include <asm/hvcserver.h>
37482 #include <asm/uaccess.h>
37483 #include <asm/vio.h>
37484+#include <asm/local.h>
37485
37486 /*
37487 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37488@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37489
37490 spin_lock_irqsave(&hvcsd->lock, flags);
37491
37492- if (hvcsd->port.count > 0) {
37493+ if (atomic_read(&hvcsd->port.count) > 0) {
37494 spin_unlock_irqrestore(&hvcsd->lock, flags);
37495 printk(KERN_INFO "HVCS: vterm state unchanged. "
37496 "The hvcs device node is still in use.\n");
37497@@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37498 if ((retval = hvcs_partner_connect(hvcsd)))
37499 goto error_release;
37500
37501- hvcsd->port.count = 1;
37502+ atomic_set(&hvcsd->port.count, 1);
37503 hvcsd->port.tty = tty;
37504 tty->driver_data = hvcsd;
37505
37506@@ -1168,7 +1169,7 @@ fast_open:
37507
37508 spin_lock_irqsave(&hvcsd->lock, flags);
37509 tty_port_get(&hvcsd->port);
37510- hvcsd->port.count++;
37511+ atomic_inc(&hvcsd->port.count);
37512 hvcsd->todo_mask |= HVCS_SCHED_READ;
37513 spin_unlock_irqrestore(&hvcsd->lock, flags);
37514
37515@@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37516 hvcsd = tty->driver_data;
37517
37518 spin_lock_irqsave(&hvcsd->lock, flags);
37519- if (--hvcsd->port.count == 0) {
37520+ if (atomic_dec_and_test(&hvcsd->port.count)) {
37521
37522 vio_disable_interrupts(hvcsd->vdev);
37523
37524@@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37525 free_irq(irq, hvcsd);
37526 tty_port_put(&hvcsd->port);
37527 return;
37528- } else if (hvcsd->port.count < 0) {
37529+ } else if (atomic_read(&hvcsd->port.count) < 0) {
37530 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37531 " is missmanaged.\n",
37532- hvcsd->vdev->unit_address, hvcsd->port.count);
37533+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37534 }
37535
37536 spin_unlock_irqrestore(&hvcsd->lock, flags);
37537@@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37538
37539 spin_lock_irqsave(&hvcsd->lock, flags);
37540 /* Preserve this so that we know how many kref refs to put */
37541- temp_open_count = hvcsd->port.count;
37542+ temp_open_count = atomic_read(&hvcsd->port.count);
37543
37544 /*
37545 * Don't kref put inside the spinlock because the destruction
37546@@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37547 tty->driver_data = NULL;
37548 hvcsd->port.tty = NULL;
37549
37550- hvcsd->port.count = 0;
37551+ atomic_set(&hvcsd->port.count, 0);
37552
37553 /* This will drop any buffered data on the floor which is OK in a hangup
37554 * scenario. */
37555@@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
37556 * the middle of a write operation? This is a crummy place to do this
37557 * but we want to keep it all in the spinlock.
37558 */
37559- if (hvcsd->port.count <= 0) {
37560+ if (atomic_read(&hvcsd->port.count) <= 0) {
37561 spin_unlock_irqrestore(&hvcsd->lock, flags);
37562 return -ENODEV;
37563 }
37564@@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37565 {
37566 struct hvcs_struct *hvcsd = tty->driver_data;
37567
37568- if (!hvcsd || hvcsd->port.count <= 0)
37569+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
37570 return 0;
37571
37572 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37573diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37574index f8b5fa0..4ba9f89 100644
37575--- a/drivers/tty/ipwireless/tty.c
37576+++ b/drivers/tty/ipwireless/tty.c
37577@@ -29,6 +29,7 @@
37578 #include <linux/tty_driver.h>
37579 #include <linux/tty_flip.h>
37580 #include <linux/uaccess.h>
37581+#include <asm/local.h>
37582
37583 #include "tty.h"
37584 #include "network.h"
37585@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37586 mutex_unlock(&tty->ipw_tty_mutex);
37587 return -ENODEV;
37588 }
37589- if (tty->port.count == 0)
37590+ if (atomic_read(&tty->port.count) == 0)
37591 tty->tx_bytes_queued = 0;
37592
37593- tty->port.count++;
37594+ atomic_inc(&tty->port.count);
37595
37596 tty->port.tty = linux_tty;
37597 linux_tty->driver_data = tty;
37598@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37599
37600 static void do_ipw_close(struct ipw_tty *tty)
37601 {
37602- tty->port.count--;
37603-
37604- if (tty->port.count == 0) {
37605+ if (atomic_dec_return(&tty->port.count) == 0) {
37606 struct tty_struct *linux_tty = tty->port.tty;
37607
37608 if (linux_tty != NULL) {
37609@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37610 return;
37611
37612 mutex_lock(&tty->ipw_tty_mutex);
37613- if (tty->port.count == 0) {
37614+ if (atomic_read(&tty->port.count) == 0) {
37615 mutex_unlock(&tty->ipw_tty_mutex);
37616 return;
37617 }
37618@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37619 return;
37620 }
37621
37622- if (!tty->port.count) {
37623+ if (!atomic_read(&tty->port.count)) {
37624 mutex_unlock(&tty->ipw_tty_mutex);
37625 return;
37626 }
37627@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37628 return -ENODEV;
37629
37630 mutex_lock(&tty->ipw_tty_mutex);
37631- if (!tty->port.count) {
37632+ if (!atomic_read(&tty->port.count)) {
37633 mutex_unlock(&tty->ipw_tty_mutex);
37634 return -EINVAL;
37635 }
37636@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37637 if (!tty)
37638 return -ENODEV;
37639
37640- if (!tty->port.count)
37641+ if (!atomic_read(&tty->port.count))
37642 return -EINVAL;
37643
37644 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37645@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37646 if (!tty)
37647 return 0;
37648
37649- if (!tty->port.count)
37650+ if (!atomic_read(&tty->port.count))
37651 return 0;
37652
37653 return tty->tx_bytes_queued;
37654@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37655 if (!tty)
37656 return -ENODEV;
37657
37658- if (!tty->port.count)
37659+ if (!atomic_read(&tty->port.count))
37660 return -EINVAL;
37661
37662 return get_control_lines(tty);
37663@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37664 if (!tty)
37665 return -ENODEV;
37666
37667- if (!tty->port.count)
37668+ if (!atomic_read(&tty->port.count))
37669 return -EINVAL;
37670
37671 return set_control_lines(tty, set, clear);
37672@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37673 if (!tty)
37674 return -ENODEV;
37675
37676- if (!tty->port.count)
37677+ if (!atomic_read(&tty->port.count))
37678 return -EINVAL;
37679
37680 /* FIXME: Exactly how is the tty object locked here .. */
37681@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37682 * are gone */
37683 mutex_lock(&ttyj->ipw_tty_mutex);
37684 }
37685- while (ttyj->port.count)
37686+ while (atomic_read(&ttyj->port.count))
37687 do_ipw_close(ttyj);
37688 ipwireless_disassociate_network_ttys(network,
37689 ttyj->channel_idx);
37690diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
37691index 324467d..504cc25 100644
37692--- a/drivers/tty/moxa.c
37693+++ b/drivers/tty/moxa.c
37694@@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
37695 }
37696
37697 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
37698- ch->port.count++;
37699+ atomic_inc(&ch->port.count);
37700 tty->driver_data = ch;
37701 tty_port_tty_set(&ch->port, tty);
37702 mutex_lock(&ch->port.mutex);
37703diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37704index c43b683..4dab83e 100644
37705--- a/drivers/tty/n_gsm.c
37706+++ b/drivers/tty/n_gsm.c
37707@@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37708 kref_init(&dlci->ref);
37709 mutex_init(&dlci->mutex);
37710 dlci->fifo = &dlci->_fifo;
37711- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37712+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37713 kfree(dlci);
37714 return NULL;
37715 }
37716@@ -2895,7 +2895,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
37717 if (dlci == NULL)
37718 return -ENOMEM;
37719 port = &dlci->port;
37720- port->count++;
37721+ atomic_inc(&port->count);
37722 tty->driver_data = dlci;
37723 dlci_get(dlci);
37724 dlci_get(dlci->gsm->dlci[0]);
37725diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37726index ee1c268..0e97caf 100644
37727--- a/drivers/tty/n_tty.c
37728+++ b/drivers/tty/n_tty.c
37729@@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37730 {
37731 *ops = tty_ldisc_N_TTY;
37732 ops->owner = NULL;
37733- ops->refcount = ops->flags = 0;
37734+ atomic_set(&ops->refcount, 0);
37735+ ops->flags = 0;
37736 }
37737 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37738diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37739index 5505ffc..7affff9 100644
37740--- a/drivers/tty/pty.c
37741+++ b/drivers/tty/pty.c
37742@@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
37743 panic("Couldn't register Unix98 pts driver");
37744
37745 /* Now create the /dev/ptmx special device */
37746+ pax_open_kernel();
37747 tty_default_fops(&ptmx_fops);
37748- ptmx_fops.open = ptmx_open;
37749+ *(void **)&ptmx_fops.open = ptmx_open;
37750+ pax_close_kernel();
37751
37752 cdev_init(&ptmx_cdev, &ptmx_fops);
37753 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37754diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
37755index 777d5f9..56d67ca 100644
37756--- a/drivers/tty/rocket.c
37757+++ b/drivers/tty/rocket.c
37758@@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37759 tty->driver_data = info;
37760 tty_port_tty_set(port, tty);
37761
37762- if (port->count++ == 0) {
37763+ if (atomic_inc_return(&port->count) == 1) {
37764 atomic_inc(&rp_num_ports_open);
37765
37766 #ifdef ROCKET_DEBUG_OPEN
37767@@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37768 #endif
37769 }
37770 #ifdef ROCKET_DEBUG_OPEN
37771- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
37772+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
37773 #endif
37774
37775 /*
37776@@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
37777 spin_unlock_irqrestore(&info->port.lock, flags);
37778 return;
37779 }
37780- if (info->port.count)
37781+ if (atomic_read(&info->port.count))
37782 atomic_dec(&rp_num_ports_open);
37783 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
37784 spin_unlock_irqrestore(&info->port.lock, flags);
37785diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37786index 2b42a01..32a2ed3 100644
37787--- a/drivers/tty/serial/kgdboc.c
37788+++ b/drivers/tty/serial/kgdboc.c
37789@@ -24,8 +24,9 @@
37790 #define MAX_CONFIG_LEN 40
37791
37792 static struct kgdb_io kgdboc_io_ops;
37793+static struct kgdb_io kgdboc_io_ops_console;
37794
37795-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37796+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37797 static int configured = -1;
37798
37799 static char config[MAX_CONFIG_LEN];
37800@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37801 kgdboc_unregister_kbd();
37802 if (configured == 1)
37803 kgdb_unregister_io_module(&kgdboc_io_ops);
37804+ else if (configured == 2)
37805+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
37806 }
37807
37808 static int configure_kgdboc(void)
37809@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37810 int err;
37811 char *cptr = config;
37812 struct console *cons;
37813+ int is_console = 0;
37814
37815 err = kgdboc_option_setup(config);
37816 if (err || !strlen(config) || isspace(config[0]))
37817 goto noconfig;
37818
37819 err = -ENODEV;
37820- kgdboc_io_ops.is_console = 0;
37821 kgdb_tty_driver = NULL;
37822
37823 kgdboc_use_kms = 0;
37824@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37825 int idx;
37826 if (cons->device && cons->device(cons, &idx) == p &&
37827 idx == tty_line) {
37828- kgdboc_io_ops.is_console = 1;
37829+ is_console = 1;
37830 break;
37831 }
37832 cons = cons->next;
37833@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37834 kgdb_tty_line = tty_line;
37835
37836 do_register:
37837- err = kgdb_register_io_module(&kgdboc_io_ops);
37838+ if (is_console) {
37839+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
37840+ configured = 2;
37841+ } else {
37842+ err = kgdb_register_io_module(&kgdboc_io_ops);
37843+ configured = 1;
37844+ }
37845 if (err)
37846 goto noconfig;
37847
37848- configured = 1;
37849-
37850 return 0;
37851
37852 noconfig:
37853@@ -213,7 +220,7 @@ noconfig:
37854 static int __init init_kgdboc(void)
37855 {
37856 /* Already configured? */
37857- if (configured == 1)
37858+ if (configured >= 1)
37859 return 0;
37860
37861 return configure_kgdboc();
37862@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37863 if (config[len - 1] == '\n')
37864 config[len - 1] = '\0';
37865
37866- if (configured == 1)
37867+ if (configured >= 1)
37868 cleanup_kgdboc();
37869
37870 /* Go and configure with the new params. */
37871@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37872 .post_exception = kgdboc_post_exp_handler,
37873 };
37874
37875+static struct kgdb_io kgdboc_io_ops_console = {
37876+ .name = "kgdboc",
37877+ .read_char = kgdboc_get_char,
37878+ .write_char = kgdboc_put_char,
37879+ .pre_exception = kgdboc_pre_exp_handler,
37880+ .post_exception = kgdboc_post_exp_handler,
37881+ .is_console = 1
37882+};
37883+
37884 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37885 /* This is only available if kgdboc is a built in for early debugging */
37886 static int __init kgdboc_early_init(char *opt)
37887diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
37888index 246b823..9e0db76 100644
37889--- a/drivers/tty/serial/serial_core.c
37890+++ b/drivers/tty/serial/serial_core.c
37891@@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
37892 uart_flush_buffer(tty);
37893 uart_shutdown(tty, state);
37894 spin_lock_irqsave(&port->lock, flags);
37895- port->count = 0;
37896+ atomic_set(&port->count, 0);
37897 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
37898 spin_unlock_irqrestore(&port->lock, flags);
37899 tty_port_tty_set(port, NULL);
37900@@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37901 goto end;
37902 }
37903
37904- port->count++;
37905+ atomic_inc(&port->count);
37906 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
37907 retval = -ENXIO;
37908 goto err_dec_count;
37909@@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37910 /*
37911 * Make sure the device is in D0 state.
37912 */
37913- if (port->count == 1)
37914+ if (atomic_read(&port->count) == 1)
37915 uart_change_pm(state, 0);
37916
37917 /*
37918@@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37919 end:
37920 return retval;
37921 err_dec_count:
37922- port->count--;
37923+ atomic_inc(&port->count);
37924 mutex_unlock(&port->mutex);
37925 goto end;
37926 }
37927diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
37928index 593d40a..bdc61f3 100644
37929--- a/drivers/tty/synclink.c
37930+++ b/drivers/tty/synclink.c
37931@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
37932
37933 if (debug_level >= DEBUG_LEVEL_INFO)
37934 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
37935- __FILE__,__LINE__, info->device_name, info->port.count);
37936+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
37937
37938 if (tty_port_close_start(&info->port, tty, filp) == 0)
37939 goto cleanup;
37940@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
37941 cleanup:
37942 if (debug_level >= DEBUG_LEVEL_INFO)
37943 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
37944- tty->driver->name, info->port.count);
37945+ tty->driver->name, atomic_read(&info->port.count));
37946
37947 } /* end of mgsl_close() */
37948
37949@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
37950
37951 mgsl_flush_buffer(tty);
37952 shutdown(info);
37953-
37954- info->port.count = 0;
37955+
37956+ atomic_set(&info->port.count, 0);
37957 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
37958 info->port.tty = NULL;
37959
37960@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
37961
37962 if (debug_level >= DEBUG_LEVEL_INFO)
37963 printk("%s(%d):block_til_ready before block on %s count=%d\n",
37964- __FILE__,__LINE__, tty->driver->name, port->count );
37965+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
37966
37967 spin_lock_irqsave(&info->irq_spinlock, flags);
37968 if (!tty_hung_up_p(filp)) {
37969 extra_count = true;
37970- port->count--;
37971+ atomic_dec(&port->count);
37972 }
37973 spin_unlock_irqrestore(&info->irq_spinlock, flags);
37974 port->blocked_open++;
37975@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
37976
37977 if (debug_level >= DEBUG_LEVEL_INFO)
37978 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
37979- __FILE__,__LINE__, tty->driver->name, port->count );
37980+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
37981
37982 tty_unlock();
37983 schedule();
37984@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
37985
37986 /* FIXME: Racy on hangup during close wait */
37987 if (extra_count)
37988- port->count++;
37989+ atomic_inc(&port->count);
37990 port->blocked_open--;
37991
37992 if (debug_level >= DEBUG_LEVEL_INFO)
37993 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
37994- __FILE__,__LINE__, tty->driver->name, port->count );
37995+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
37996
37997 if (!retval)
37998 port->flags |= ASYNC_NORMAL_ACTIVE;
37999@@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38000
38001 if (debug_level >= DEBUG_LEVEL_INFO)
38002 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38003- __FILE__,__LINE__,tty->driver->name, info->port.count);
38004+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38005
38006 /* If port is closing, signal caller to try again */
38007 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38008@@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38009 spin_unlock_irqrestore(&info->netlock, flags);
38010 goto cleanup;
38011 }
38012- info->port.count++;
38013+ atomic_inc(&info->port.count);
38014 spin_unlock_irqrestore(&info->netlock, flags);
38015
38016- if (info->port.count == 1) {
38017+ if (atomic_read(&info->port.count) == 1) {
38018 /* 1st open on this device, init hardware */
38019 retval = startup(info);
38020 if (retval < 0)
38021@@ -3444,8 +3444,8 @@ cleanup:
38022 if (retval) {
38023 if (tty->count == 1)
38024 info->port.tty = NULL; /* tty layer will release tty struct */
38025- if(info->port.count)
38026- info->port.count--;
38027+ if (atomic_read(&info->port.count))
38028+ atomic_dec(&info->port.count);
38029 }
38030
38031 return retval;
38032@@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38033 unsigned short new_crctype;
38034
38035 /* return error if TTY interface open */
38036- if (info->port.count)
38037+ if (atomic_read(&info->port.count))
38038 return -EBUSY;
38039
38040 switch (encoding)
38041@@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38042
38043 /* arbitrate between network and tty opens */
38044 spin_lock_irqsave(&info->netlock, flags);
38045- if (info->port.count != 0 || info->netcount != 0) {
38046+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38047 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38048 spin_unlock_irqrestore(&info->netlock, flags);
38049 return -EBUSY;
38050@@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38051 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38052
38053 /* return error if TTY interface open */
38054- if (info->port.count)
38055+ if (atomic_read(&info->port.count))
38056 return -EBUSY;
38057
38058 if (cmd != SIOCWANDEV)
38059diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38060index aa1debf..9297a16 100644
38061--- a/drivers/tty/synclink_gt.c
38062+++ b/drivers/tty/synclink_gt.c
38063@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38064 tty->driver_data = info;
38065 info->port.tty = tty;
38066
38067- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38068+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38069
38070 /* If port is closing, signal caller to try again */
38071 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38072@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38073 mutex_unlock(&info->port.mutex);
38074 goto cleanup;
38075 }
38076- info->port.count++;
38077+ atomic_inc(&info->port.count);
38078 spin_unlock_irqrestore(&info->netlock, flags);
38079
38080- if (info->port.count == 1) {
38081+ if (atomic_read(&info->port.count) == 1) {
38082 /* 1st open on this device, init hardware */
38083 retval = startup(info);
38084 if (retval < 0) {
38085@@ -716,8 +716,8 @@ cleanup:
38086 if (retval) {
38087 if (tty->count == 1)
38088 info->port.tty = NULL; /* tty layer will release tty struct */
38089- if(info->port.count)
38090- info->port.count--;
38091+ if(atomic_read(&info->port.count))
38092+ atomic_dec(&info->port.count);
38093 }
38094
38095 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38096@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38097
38098 if (sanity_check(info, tty->name, "close"))
38099 return;
38100- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38101+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38102
38103 if (tty_port_close_start(&info->port, tty, filp) == 0)
38104 goto cleanup;
38105@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38106 tty_port_close_end(&info->port, tty);
38107 info->port.tty = NULL;
38108 cleanup:
38109- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38110+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38111 }
38112
38113 static void hangup(struct tty_struct *tty)
38114@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38115 shutdown(info);
38116
38117 spin_lock_irqsave(&info->port.lock, flags);
38118- info->port.count = 0;
38119+ atomic_set(&info->port.count, 0);
38120 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38121 info->port.tty = NULL;
38122 spin_unlock_irqrestore(&info->port.lock, flags);
38123@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38124 unsigned short new_crctype;
38125
38126 /* return error if TTY interface open */
38127- if (info->port.count)
38128+ if (atomic_read(&info->port.count))
38129 return -EBUSY;
38130
38131 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38132@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38133
38134 /* arbitrate between network and tty opens */
38135 spin_lock_irqsave(&info->netlock, flags);
38136- if (info->port.count != 0 || info->netcount != 0) {
38137+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38138 DBGINFO(("%s hdlc_open busy\n", dev->name));
38139 spin_unlock_irqrestore(&info->netlock, flags);
38140 return -EBUSY;
38141@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38142 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38143
38144 /* return error if TTY interface open */
38145- if (info->port.count)
38146+ if (atomic_read(&info->port.count))
38147 return -EBUSY;
38148
38149 if (cmd != SIOCWANDEV)
38150@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38151 if (port == NULL)
38152 continue;
38153 spin_lock(&port->lock);
38154- if ((port->port.count || port->netcount) &&
38155+ if ((atomic_read(&port->port.count) || port->netcount) &&
38156 port->pending_bh && !port->bh_running &&
38157 !port->bh_requested) {
38158 DBGISR(("%s bh queued\n", port->device_name));
38159@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38160 spin_lock_irqsave(&info->lock, flags);
38161 if (!tty_hung_up_p(filp)) {
38162 extra_count = true;
38163- port->count--;
38164+ atomic_dec(&port->count);
38165 }
38166 spin_unlock_irqrestore(&info->lock, flags);
38167 port->blocked_open++;
38168@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38169 remove_wait_queue(&port->open_wait, &wait);
38170
38171 if (extra_count)
38172- port->count++;
38173+ atomic_inc(&port->count);
38174 port->blocked_open--;
38175
38176 if (!retval)
38177diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38178index a3dddc1..8905ab2 100644
38179--- a/drivers/tty/synclinkmp.c
38180+++ b/drivers/tty/synclinkmp.c
38181@@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38182
38183 if (debug_level >= DEBUG_LEVEL_INFO)
38184 printk("%s(%d):%s open(), old ref count = %d\n",
38185- __FILE__,__LINE__,tty->driver->name, info->port.count);
38186+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38187
38188 /* If port is closing, signal caller to try again */
38189 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38190@@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38191 spin_unlock_irqrestore(&info->netlock, flags);
38192 goto cleanup;
38193 }
38194- info->port.count++;
38195+ atomic_inc(&info->port.count);
38196 spin_unlock_irqrestore(&info->netlock, flags);
38197
38198- if (info->port.count == 1) {
38199+ if (atomic_read(&info->port.count) == 1) {
38200 /* 1st open on this device, init hardware */
38201 retval = startup(info);
38202 if (retval < 0)
38203@@ -788,8 +788,8 @@ cleanup:
38204 if (retval) {
38205 if (tty->count == 1)
38206 info->port.tty = NULL; /* tty layer will release tty struct */
38207- if(info->port.count)
38208- info->port.count--;
38209+ if(atomic_read(&info->port.count))
38210+ atomic_dec(&info->port.count);
38211 }
38212
38213 return retval;
38214@@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38215
38216 if (debug_level >= DEBUG_LEVEL_INFO)
38217 printk("%s(%d):%s close() entry, count=%d\n",
38218- __FILE__,__LINE__, info->device_name, info->port.count);
38219+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38220
38221 if (tty_port_close_start(&info->port, tty, filp) == 0)
38222 goto cleanup;
38223@@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38224 cleanup:
38225 if (debug_level >= DEBUG_LEVEL_INFO)
38226 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38227- tty->driver->name, info->port.count);
38228+ tty->driver->name, atomic_read(&info->port.count));
38229 }
38230
38231 /* Called by tty_hangup() when a hangup is signaled.
38232@@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38233 shutdown(info);
38234
38235 spin_lock_irqsave(&info->port.lock, flags);
38236- info->port.count = 0;
38237+ atomic_set(&info->port.count, 0);
38238 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38239 info->port.tty = NULL;
38240 spin_unlock_irqrestore(&info->port.lock, flags);
38241@@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38242 unsigned short new_crctype;
38243
38244 /* return error if TTY interface open */
38245- if (info->port.count)
38246+ if (atomic_read(&info->port.count))
38247 return -EBUSY;
38248
38249 switch (encoding)
38250@@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38251
38252 /* arbitrate between network and tty opens */
38253 spin_lock_irqsave(&info->netlock, flags);
38254- if (info->port.count != 0 || info->netcount != 0) {
38255+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38256 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38257 spin_unlock_irqrestore(&info->netlock, flags);
38258 return -EBUSY;
38259@@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38260 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38261
38262 /* return error if TTY interface open */
38263- if (info->port.count)
38264+ if (atomic_read(&info->port.count))
38265 return -EBUSY;
38266
38267 if (cmd != SIOCWANDEV)
38268@@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38269 * do not request bottom half processing if the
38270 * device is not open in a normal mode.
38271 */
38272- if ( port && (port->port.count || port->netcount) &&
38273+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38274 port->pending_bh && !port->bh_running &&
38275 !port->bh_requested ) {
38276 if ( debug_level >= DEBUG_LEVEL_ISR )
38277@@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38278
38279 if (debug_level >= DEBUG_LEVEL_INFO)
38280 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38281- __FILE__,__LINE__, tty->driver->name, port->count );
38282+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38283
38284 spin_lock_irqsave(&info->lock, flags);
38285 if (!tty_hung_up_p(filp)) {
38286 extra_count = true;
38287- port->count--;
38288+ atomic_dec(&port->count);
38289 }
38290 spin_unlock_irqrestore(&info->lock, flags);
38291 port->blocked_open++;
38292@@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38293
38294 if (debug_level >= DEBUG_LEVEL_INFO)
38295 printk("%s(%d):%s block_til_ready() count=%d\n",
38296- __FILE__,__LINE__, tty->driver->name, port->count );
38297+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38298
38299 tty_unlock();
38300 schedule();
38301@@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38302 remove_wait_queue(&port->open_wait, &wait);
38303
38304 if (extra_count)
38305- port->count++;
38306+ atomic_inc(&port->count);
38307 port->blocked_open--;
38308
38309 if (debug_level >= DEBUG_LEVEL_INFO)
38310 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38311- __FILE__,__LINE__, tty->driver->name, port->count );
38312+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38313
38314 if (!retval)
38315 port->flags |= ASYNC_NORMAL_ACTIVE;
38316diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38317index 05728894..b9d44c6 100644
38318--- a/drivers/tty/sysrq.c
38319+++ b/drivers/tty/sysrq.c
38320@@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38321 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38322 size_t count, loff_t *ppos)
38323 {
38324- if (count) {
38325+ if (count && capable(CAP_SYS_ADMIN)) {
38326 char c;
38327
38328 if (get_user(c, buf))
38329diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38330index b425c79..08a3f06 100644
38331--- a/drivers/tty/tty_io.c
38332+++ b/drivers/tty/tty_io.c
38333@@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38334
38335 void tty_default_fops(struct file_operations *fops)
38336 {
38337- *fops = tty_fops;
38338+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38339 }
38340
38341 /*
38342diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38343index 9911eb6..5abe0e1 100644
38344--- a/drivers/tty/tty_ldisc.c
38345+++ b/drivers/tty/tty_ldisc.c
38346@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38347 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38348 struct tty_ldisc_ops *ldo = ld->ops;
38349
38350- ldo->refcount--;
38351+ atomic_dec(&ldo->refcount);
38352 module_put(ldo->owner);
38353 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38354
38355@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38356 spin_lock_irqsave(&tty_ldisc_lock, flags);
38357 tty_ldiscs[disc] = new_ldisc;
38358 new_ldisc->num = disc;
38359- new_ldisc->refcount = 0;
38360+ atomic_set(&new_ldisc->refcount, 0);
38361 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38362
38363 return ret;
38364@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38365 return -EINVAL;
38366
38367 spin_lock_irqsave(&tty_ldisc_lock, flags);
38368- if (tty_ldiscs[disc]->refcount)
38369+ if (atomic_read(&tty_ldiscs[disc]->refcount))
38370 ret = -EBUSY;
38371 else
38372 tty_ldiscs[disc] = NULL;
38373@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38374 if (ldops) {
38375 ret = ERR_PTR(-EAGAIN);
38376 if (try_module_get(ldops->owner)) {
38377- ldops->refcount++;
38378+ atomic_inc(&ldops->refcount);
38379 ret = ldops;
38380 }
38381 }
38382@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38383 unsigned long flags;
38384
38385 spin_lock_irqsave(&tty_ldisc_lock, flags);
38386- ldops->refcount--;
38387+ atomic_dec(&ldops->refcount);
38388 module_put(ldops->owner);
38389 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38390 }
38391diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38392index bf6e238..d401c04 100644
38393--- a/drivers/tty/tty_port.c
38394+++ b/drivers/tty/tty_port.c
38395@@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38396 unsigned long flags;
38397
38398 spin_lock_irqsave(&port->lock, flags);
38399- port->count = 0;
38400+ atomic_set(&port->count, 0);
38401 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38402 if (port->tty) {
38403 set_bit(TTY_IO_ERROR, &port->tty->flags);
38404@@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38405 /* The port lock protects the port counts */
38406 spin_lock_irqsave(&port->lock, flags);
38407 if (!tty_hung_up_p(filp))
38408- port->count--;
38409+ atomic_dec(&port->count);
38410 port->blocked_open++;
38411 spin_unlock_irqrestore(&port->lock, flags);
38412
38413@@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38414 we must not mess that up further */
38415 spin_lock_irqsave(&port->lock, flags);
38416 if (!tty_hung_up_p(filp))
38417- port->count++;
38418+ atomic_inc(&port->count);
38419 port->blocked_open--;
38420 if (retval == 0)
38421 port->flags |= ASYNC_NORMAL_ACTIVE;
38422@@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38423 return 0;
38424 }
38425
38426- if (tty->count == 1 && port->count != 1) {
38427+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
38428 printk(KERN_WARNING
38429 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38430- port->count);
38431- port->count = 1;
38432+ atomic_read(&port->count));
38433+ atomic_set(&port->count, 1);
38434 }
38435- if (--port->count < 0) {
38436+ if (atomic_dec_return(&port->count) < 0) {
38437 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38438- port->count);
38439- port->count = 0;
38440+ atomic_read(&port->count));
38441+ atomic_set(&port->count, 0);
38442 }
38443
38444- if (port->count) {
38445+ if (atomic_read(&port->count)) {
38446 spin_unlock_irqrestore(&port->lock, flags);
38447 if (port->ops->drop)
38448 port->ops->drop(port);
38449@@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38450 {
38451 spin_lock_irq(&port->lock);
38452 if (!tty_hung_up_p(filp))
38453- ++port->count;
38454+ atomic_inc(&port->count);
38455 spin_unlock_irq(&port->lock);
38456 tty_port_tty_set(port, tty);
38457
38458diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38459index 48cc6f2..85584dd 100644
38460--- a/drivers/tty/vt/keyboard.c
38461+++ b/drivers/tty/vt/keyboard.c
38462@@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38463 kbd->kbdmode == VC_OFF) &&
38464 value != KVAL(K_SAK))
38465 return; /* SAK is allowed even in raw mode */
38466+
38467+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38468+ {
38469+ void *func = fn_handler[value];
38470+ if (func == fn_show_state || func == fn_show_ptregs ||
38471+ func == fn_show_mem)
38472+ return;
38473+ }
38474+#endif
38475+
38476 fn_handler[value](vc);
38477 }
38478
38479@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38480 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38481 return -EFAULT;
38482
38483- if (!capable(CAP_SYS_TTY_CONFIG))
38484- perm = 0;
38485-
38486 switch (cmd) {
38487 case KDGKBENT:
38488 /* Ensure another thread doesn't free it under us */
38489@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38490 spin_unlock_irqrestore(&kbd_event_lock, flags);
38491 return put_user(val, &user_kbe->kb_value);
38492 case KDSKBENT:
38493+ if (!capable(CAP_SYS_TTY_CONFIG))
38494+ perm = 0;
38495+
38496 if (!perm)
38497 return -EPERM;
38498 if (!i && v == K_NOSUCHMAP) {
38499@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38500 int i, j, k;
38501 int ret;
38502
38503- if (!capable(CAP_SYS_TTY_CONFIG))
38504- perm = 0;
38505-
38506 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38507 if (!kbs) {
38508 ret = -ENOMEM;
38509@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38510 kfree(kbs);
38511 return ((p && *p) ? -EOVERFLOW : 0);
38512 case KDSKBSENT:
38513+ if (!capable(CAP_SYS_TTY_CONFIG))
38514+ perm = 0;
38515+
38516 if (!perm) {
38517 ret = -EPERM;
38518 goto reterr;
38519diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38520index a783d53..cb30d94 100644
38521--- a/drivers/uio/uio.c
38522+++ b/drivers/uio/uio.c
38523@@ -25,6 +25,7 @@
38524 #include <linux/kobject.h>
38525 #include <linux/cdev.h>
38526 #include <linux/uio_driver.h>
38527+#include <asm/local.h>
38528
38529 #define UIO_MAX_DEVICES (1U << MINORBITS)
38530
38531@@ -32,10 +33,10 @@ struct uio_device {
38532 struct module *owner;
38533 struct device *dev;
38534 int minor;
38535- atomic_t event;
38536+ atomic_unchecked_t event;
38537 struct fasync_struct *async_queue;
38538 wait_queue_head_t wait;
38539- int vma_count;
38540+ local_t vma_count;
38541 struct uio_info *info;
38542 struct kobject *map_dir;
38543 struct kobject *portio_dir;
38544@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38545 struct device_attribute *attr, char *buf)
38546 {
38547 struct uio_device *idev = dev_get_drvdata(dev);
38548- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38549+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38550 }
38551
38552 static struct device_attribute uio_class_attributes[] = {
38553@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38554 {
38555 struct uio_device *idev = info->uio_dev;
38556
38557- atomic_inc(&idev->event);
38558+ atomic_inc_unchecked(&idev->event);
38559 wake_up_interruptible(&idev->wait);
38560 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38561 }
38562@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38563 }
38564
38565 listener->dev = idev;
38566- listener->event_count = atomic_read(&idev->event);
38567+ listener->event_count = atomic_read_unchecked(&idev->event);
38568 filep->private_data = listener;
38569
38570 if (idev->info->open) {
38571@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38572 return -EIO;
38573
38574 poll_wait(filep, &idev->wait, wait);
38575- if (listener->event_count != atomic_read(&idev->event))
38576+ if (listener->event_count != atomic_read_unchecked(&idev->event))
38577 return POLLIN | POLLRDNORM;
38578 return 0;
38579 }
38580@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38581 do {
38582 set_current_state(TASK_INTERRUPTIBLE);
38583
38584- event_count = atomic_read(&idev->event);
38585+ event_count = atomic_read_unchecked(&idev->event);
38586 if (event_count != listener->event_count) {
38587 if (copy_to_user(buf, &event_count, count))
38588 retval = -EFAULT;
38589@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38590 static void uio_vma_open(struct vm_area_struct *vma)
38591 {
38592 struct uio_device *idev = vma->vm_private_data;
38593- idev->vma_count++;
38594+ local_inc(&idev->vma_count);
38595 }
38596
38597 static void uio_vma_close(struct vm_area_struct *vma)
38598 {
38599 struct uio_device *idev = vma->vm_private_data;
38600- idev->vma_count--;
38601+ local_dec(&idev->vma_count);
38602 }
38603
38604 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38605@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38606 idev->owner = owner;
38607 idev->info = info;
38608 init_waitqueue_head(&idev->wait);
38609- atomic_set(&idev->event, 0);
38610+ atomic_set_unchecked(&idev->event, 0);
38611
38612 ret = uio_get_minor(idev);
38613 if (ret)
38614diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38615index b7eb86a..36d28af 100644
38616--- a/drivers/usb/atm/cxacru.c
38617+++ b/drivers/usb/atm/cxacru.c
38618@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38619 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38620 if (ret < 2)
38621 return -EINVAL;
38622- if (index < 0 || index > 0x7f)
38623+ if (index > 0x7f)
38624 return -EINVAL;
38625 pos += tmp;
38626
38627diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38628index ee62b35..b663594 100644
38629--- a/drivers/usb/atm/usbatm.c
38630+++ b/drivers/usb/atm/usbatm.c
38631@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38632 if (printk_ratelimit())
38633 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38634 __func__, vpi, vci);
38635- atomic_inc(&vcc->stats->rx_err);
38636+ atomic_inc_unchecked(&vcc->stats->rx_err);
38637 return;
38638 }
38639
38640@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38641 if (length > ATM_MAX_AAL5_PDU) {
38642 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38643 __func__, length, vcc);
38644- atomic_inc(&vcc->stats->rx_err);
38645+ atomic_inc_unchecked(&vcc->stats->rx_err);
38646 goto out;
38647 }
38648
38649@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38650 if (sarb->len < pdu_length) {
38651 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38652 __func__, pdu_length, sarb->len, vcc);
38653- atomic_inc(&vcc->stats->rx_err);
38654+ atomic_inc_unchecked(&vcc->stats->rx_err);
38655 goto out;
38656 }
38657
38658 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38659 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38660 __func__, vcc);
38661- atomic_inc(&vcc->stats->rx_err);
38662+ atomic_inc_unchecked(&vcc->stats->rx_err);
38663 goto out;
38664 }
38665
38666@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38667 if (printk_ratelimit())
38668 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38669 __func__, length);
38670- atomic_inc(&vcc->stats->rx_drop);
38671+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38672 goto out;
38673 }
38674
38675@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38676
38677 vcc->push(vcc, skb);
38678
38679- atomic_inc(&vcc->stats->rx);
38680+ atomic_inc_unchecked(&vcc->stats->rx);
38681 out:
38682 skb_trim(sarb, 0);
38683 }
38684@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38685 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38686
38687 usbatm_pop(vcc, skb);
38688- atomic_inc(&vcc->stats->tx);
38689+ atomic_inc_unchecked(&vcc->stats->tx);
38690
38691 skb = skb_dequeue(&instance->sndqueue);
38692 }
38693@@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38694 if (!left--)
38695 return sprintf(page,
38696 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38697- atomic_read(&atm_dev->stats.aal5.tx),
38698- atomic_read(&atm_dev->stats.aal5.tx_err),
38699- atomic_read(&atm_dev->stats.aal5.rx),
38700- atomic_read(&atm_dev->stats.aal5.rx_err),
38701- atomic_read(&atm_dev->stats.aal5.rx_drop));
38702+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38703+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38704+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38705+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38706+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38707
38708 if (!left--) {
38709 if (instance->disconnected)
38710diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38711index d956965..4179a77 100644
38712--- a/drivers/usb/core/devices.c
38713+++ b/drivers/usb/core/devices.c
38714@@ -126,7 +126,7 @@ static const char format_endpt[] =
38715 * time it gets called.
38716 */
38717 static struct device_connect_event {
38718- atomic_t count;
38719+ atomic_unchecked_t count;
38720 wait_queue_head_t wait;
38721 } device_event = {
38722 .count = ATOMIC_INIT(1),
38723@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38724
38725 void usbfs_conn_disc_event(void)
38726 {
38727- atomic_add(2, &device_event.count);
38728+ atomic_add_unchecked(2, &device_event.count);
38729 wake_up(&device_event.wait);
38730 }
38731
38732@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38733
38734 poll_wait(file, &device_event.wait, wait);
38735
38736- event_count = atomic_read(&device_event.count);
38737+ event_count = atomic_read_unchecked(&device_event.count);
38738 if (file->f_version != event_count) {
38739 file->f_version = event_count;
38740 return POLLIN | POLLRDNORM;
38741diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38742index 1fc8f12..20647c1 100644
38743--- a/drivers/usb/early/ehci-dbgp.c
38744+++ b/drivers/usb/early/ehci-dbgp.c
38745@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38746
38747 #ifdef CONFIG_KGDB
38748 static struct kgdb_io kgdbdbgp_io_ops;
38749-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38750+static struct kgdb_io kgdbdbgp_io_ops_console;
38751+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38752 #else
38753 #define dbgp_kgdb_mode (0)
38754 #endif
38755@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38756 .write_char = kgdbdbgp_write_char,
38757 };
38758
38759+static struct kgdb_io kgdbdbgp_io_ops_console = {
38760+ .name = "kgdbdbgp",
38761+ .read_char = kgdbdbgp_read_char,
38762+ .write_char = kgdbdbgp_write_char,
38763+ .is_console = 1
38764+};
38765+
38766 static int kgdbdbgp_wait_time;
38767
38768 static int __init kgdbdbgp_parse_config(char *str)
38769@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38770 ptr++;
38771 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38772 }
38773- kgdb_register_io_module(&kgdbdbgp_io_ops);
38774- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38775+ if (early_dbgp_console.index != -1)
38776+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38777+ else
38778+ kgdb_register_io_module(&kgdbdbgp_io_ops);
38779
38780 return 0;
38781 }
38782diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
38783index 5b3f5ff..6e00893 100644
38784--- a/drivers/usb/gadget/u_serial.c
38785+++ b/drivers/usb/gadget/u_serial.c
38786@@ -731,9 +731,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38787 spin_lock_irq(&port->port_lock);
38788
38789 /* already open? Great. */
38790- if (port->port.count) {
38791+ if (atomic_read(&port->port.count)) {
38792 status = 0;
38793- port->port.count++;
38794+ atomic_inc(&port->port.count);
38795
38796 /* currently opening/closing? wait ... */
38797 } else if (port->openclose) {
38798@@ -792,7 +792,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38799 tty->driver_data = port;
38800 port->port.tty = tty;
38801
38802- port->port.count = 1;
38803+ atomic_set(&port->port.count, 1);
38804 port->openclose = false;
38805
38806 /* if connected, start the I/O stream */
38807@@ -834,11 +834,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38808
38809 spin_lock_irq(&port->port_lock);
38810
38811- if (port->port.count != 1) {
38812- if (port->port.count == 0)
38813+ if (atomic_read(&port->port.count) != 1) {
38814+ if (atomic_read(&port->port.count) == 0)
38815 WARN_ON(1);
38816 else
38817- --port->port.count;
38818+ atomic_dec(&port->port.count);
38819 goto exit;
38820 }
38821
38822@@ -848,7 +848,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38823 * and sleep if necessary
38824 */
38825 port->openclose = true;
38826- port->port.count = 0;
38827+ atomic_set(&port->port.count, 0);
38828
38829 gser = port->port_usb;
38830 if (gser && gser->disconnect)
38831@@ -1152,7 +1152,7 @@ static int gs_closed(struct gs_port *port)
38832 int cond;
38833
38834 spin_lock_irq(&port->port_lock);
38835- cond = (port->port.count == 0) && !port->openclose;
38836+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
38837 spin_unlock_irq(&port->port_lock);
38838 return cond;
38839 }
38840@@ -1265,7 +1265,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
38841 /* if it's already open, start I/O ... and notify the serial
38842 * protocol about open/close status (connect/disconnect).
38843 */
38844- if (port->port.count) {
38845+ if (atomic_read(&port->port.count)) {
38846 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
38847 gs_start_io(port);
38848 if (gser->connect)
38849@@ -1312,7 +1312,7 @@ void gserial_disconnect(struct gserial *gser)
38850
38851 port->port_usb = NULL;
38852 gser->ioport = NULL;
38853- if (port->port.count > 0 || port->openclose) {
38854+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
38855 wake_up_interruptible(&port->drain_wait);
38856 if (port->port.tty)
38857 tty_hangup(port->port.tty);
38858@@ -1328,7 +1328,7 @@ void gserial_disconnect(struct gserial *gser)
38859
38860 /* finally, free any unused/unusable I/O buffers */
38861 spin_lock_irqsave(&port->port_lock, flags);
38862- if (port->port.count == 0 && !port->openclose)
38863+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
38864 gs_buf_free(&port->port_write_buf);
38865 gs_free_requests(gser->out, &port->read_pool, NULL);
38866 gs_free_requests(gser->out, &port->read_queue, NULL);
38867diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
38868index b9cca6d..75c75df 100644
38869--- a/drivers/usb/serial/console.c
38870+++ b/drivers/usb/serial/console.c
38871@@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
38872
38873 info->port = port;
38874
38875- ++port->port.count;
38876+ atomic_inc(&port->port.count);
38877 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
38878 if (serial->type->set_termios) {
38879 /*
38880@@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
38881 }
38882 /* Now that any required fake tty operations are completed restore
38883 * the tty port count */
38884- --port->port.count;
38885+ atomic_dec(&port->port.count);
38886 /* The console is special in terms of closing the device so
38887 * indicate this port is now acting as a system console. */
38888 port->port.console = 1;
38889@@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
38890 free_tty:
38891 kfree(tty);
38892 reset_open_count:
38893- port->port.count = 0;
38894+ atomic_set(&port->port.count, 0);
38895 usb_autopm_put_interface(serial->interface);
38896 error_get_interface:
38897 usb_serial_put(serial);
38898diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38899index d6bea3e..60b250e 100644
38900--- a/drivers/usb/wusbcore/wa-hc.h
38901+++ b/drivers/usb/wusbcore/wa-hc.h
38902@@ -192,7 +192,7 @@ struct wahc {
38903 struct list_head xfer_delayed_list;
38904 spinlock_t xfer_list_lock;
38905 struct work_struct xfer_work;
38906- atomic_t xfer_id_count;
38907+ atomic_unchecked_t xfer_id_count;
38908 };
38909
38910
38911@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38912 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38913 spin_lock_init(&wa->xfer_list_lock);
38914 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38915- atomic_set(&wa->xfer_id_count, 1);
38916+ atomic_set_unchecked(&wa->xfer_id_count, 1);
38917 }
38918
38919 /**
38920diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38921index 57c01ab..8a05959 100644
38922--- a/drivers/usb/wusbcore/wa-xfer.c
38923+++ b/drivers/usb/wusbcore/wa-xfer.c
38924@@ -296,7 +296,7 @@ out:
38925 */
38926 static void wa_xfer_id_init(struct wa_xfer *xfer)
38927 {
38928- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38929+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38930 }
38931
38932 /*
38933diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38934index 112156f..eb81154 100644
38935--- a/drivers/vhost/vhost.c
38936+++ b/drivers/vhost/vhost.c
38937@@ -635,7 +635,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38938 return 0;
38939 }
38940
38941-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38942+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38943 {
38944 struct file *eventfp, *filep = NULL,
38945 *pollstart = NULL, *pollstop = NULL;
38946diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38947index b0b2ac3..89a4399 100644
38948--- a/drivers/video/aty/aty128fb.c
38949+++ b/drivers/video/aty/aty128fb.c
38950@@ -148,7 +148,7 @@ enum {
38951 };
38952
38953 /* Must match above enum */
38954-static const char *r128_family[] __devinitdata = {
38955+static const char *r128_family[] __devinitconst = {
38956 "AGP",
38957 "PCI",
38958 "PRO AGP",
38959diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38960index 5c3960d..15cf8fc 100644
38961--- a/drivers/video/fbcmap.c
38962+++ b/drivers/video/fbcmap.c
38963@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38964 rc = -ENODEV;
38965 goto out;
38966 }
38967- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38968- !info->fbops->fb_setcmap)) {
38969+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38970 rc = -EINVAL;
38971 goto out1;
38972 }
38973diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38974index 0dff12a..2ef47b3 100644
38975--- a/drivers/video/fbmem.c
38976+++ b/drivers/video/fbmem.c
38977@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38978 image->dx += image->width + 8;
38979 }
38980 } else if (rotate == FB_ROTATE_UD) {
38981- for (x = 0; x < num && image->dx >= 0; x++) {
38982+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38983 info->fbops->fb_imageblit(info, image);
38984 image->dx -= image->width + 8;
38985 }
38986@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38987 image->dy += image->height + 8;
38988 }
38989 } else if (rotate == FB_ROTATE_CCW) {
38990- for (x = 0; x < num && image->dy >= 0; x++) {
38991+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38992 info->fbops->fb_imageblit(info, image);
38993 image->dy -= image->height + 8;
38994 }
38995@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38996 return -EFAULT;
38997 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38998 return -EINVAL;
38999- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39000+ if (con2fb.framebuffer >= FB_MAX)
39001 return -EINVAL;
39002 if (!registered_fb[con2fb.framebuffer])
39003 request_module("fb%d", con2fb.framebuffer);
39004diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39005index 5a5d092..265c5ed 100644
39006--- a/drivers/video/geode/gx1fb_core.c
39007+++ b/drivers/video/geode/gx1fb_core.c
39008@@ -29,7 +29,7 @@ static int crt_option = 1;
39009 static char panel_option[32] = "";
39010
39011 /* Modes relevant to the GX1 (taken from modedb.c) */
39012-static const struct fb_videomode __devinitdata gx1_modedb[] = {
39013+static const struct fb_videomode __devinitconst gx1_modedb[] = {
39014 /* 640x480-60 VESA */
39015 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39016 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39017diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39018index 0fad23f..0e9afa4 100644
39019--- a/drivers/video/gxt4500.c
39020+++ b/drivers/video/gxt4500.c
39021@@ -156,7 +156,7 @@ struct gxt4500_par {
39022 static char *mode_option;
39023
39024 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39025-static const struct fb_videomode defaultmode __devinitdata = {
39026+static const struct fb_videomode defaultmode __devinitconst = {
39027 .refresh = 60,
39028 .xres = 1280,
39029 .yres = 1024,
39030@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39031 return 0;
39032 }
39033
39034-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39035+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39036 .id = "IBM GXT4500P",
39037 .type = FB_TYPE_PACKED_PIXELS,
39038 .visual = FB_VISUAL_PSEUDOCOLOR,
39039diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39040index 7672d2e..b56437f 100644
39041--- a/drivers/video/i810/i810_accel.c
39042+++ b/drivers/video/i810/i810_accel.c
39043@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39044 }
39045 }
39046 printk("ringbuffer lockup!!!\n");
39047+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39048 i810_report_error(mmio);
39049 par->dev_flags |= LOCKUP;
39050 info->pixmap.scan_align = 1;
39051diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39052index b83f361..2b05a91 100644
39053--- a/drivers/video/i810/i810_main.c
39054+++ b/drivers/video/i810/i810_main.c
39055@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39056 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39057
39058 /* PCI */
39059-static const char *i810_pci_list[] __devinitdata = {
39060+static const char *i810_pci_list[] __devinitconst = {
39061 "Intel(R) 810 Framebuffer Device" ,
39062 "Intel(R) 810-DC100 Framebuffer Device" ,
39063 "Intel(R) 810E Framebuffer Device" ,
39064diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39065index de36693..3c63fc2 100644
39066--- a/drivers/video/jz4740_fb.c
39067+++ b/drivers/video/jz4740_fb.c
39068@@ -136,7 +136,7 @@ struct jzfb {
39069 uint32_t pseudo_palette[16];
39070 };
39071
39072-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39073+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39074 .id = "JZ4740 FB",
39075 .type = FB_TYPE_PACKED_PIXELS,
39076 .visual = FB_VISUAL_TRUECOLOR,
39077diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39078index 3c14e43..eafa544 100644
39079--- a/drivers/video/logo/logo_linux_clut224.ppm
39080+++ b/drivers/video/logo/logo_linux_clut224.ppm
39081@@ -1,1604 +1,1123 @@
39082 P3
39083-# Standard 224-color Linux logo
39084 80 80
39085 255
39086- 0 0 0 0 0 0 0 0 0 0 0 0
39087- 0 0 0 0 0 0 0 0 0 0 0 0
39088- 0 0 0 0 0 0 0 0 0 0 0 0
39089- 0 0 0 0 0 0 0 0 0 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- 6 6 6 6 6 6 10 10 10 10 10 10
39096- 10 10 10 6 6 6 6 6 6 6 6 6
39097- 0 0 0 0 0 0 0 0 0 0 0 0
39098- 0 0 0 0 0 0 0 0 0 0 0 0
39099- 0 0 0 0 0 0 0 0 0 0 0 0
39100- 0 0 0 0 0 0 0 0 0 0 0 0
39101- 0 0 0 0 0 0 0 0 0 0 0 0
39102- 0 0 0 0 0 0 0 0 0 0 0 0
39103- 0 0 0 0 0 0 0 0 0 0 0 0
39104- 0 0 0 0 0 0 0 0 0 0 0 0
39105- 0 0 0 0 0 0 0 0 0 0 0 0
39106- 0 0 0 0 0 0 0 0 0 0 0 0
39107- 0 0 0 0 0 0 0 0 0 0 0 0
39108- 0 0 0 0 0 0 0 0 0 0 0 0
39109- 0 0 0 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
39115- 22 22 22 26 26 26 30 30 30 34 34 34
39116- 30 30 30 30 30 30 26 26 26 18 18 18
39117- 14 14 14 10 10 10 6 6 6 0 0 0
39118- 0 0 0 0 0 0 0 0 0 0 0 0
39119- 0 0 0 0 0 0 0 0 0 0 0 0
39120- 0 0 0 0 0 0 0 0 0 0 0 0
39121- 0 0 0 0 0 0 0 0 0 0 0 0
39122- 0 0 0 0 0 0 0 0 0 0 0 0
39123- 0 0 0 0 0 0 0 0 0 0 0 0
39124- 0 0 0 0 0 0 0 0 0 0 0 0
39125- 0 0 0 0 0 0 0 0 0 0 0 0
39126- 0 0 0 0 0 0 0 0 0 0 0 0
39127- 0 0 0 0 0 1 0 0 1 0 0 0
39128- 0 0 0 0 0 0 0 0 0 0 0 0
39129- 0 0 0 0 0 0 0 0 0 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- 6 6 6 14 14 14 26 26 26 42 42 42
39135- 54 54 54 66 66 66 78 78 78 78 78 78
39136- 78 78 78 74 74 74 66 66 66 54 54 54
39137- 42 42 42 26 26 26 18 18 18 10 10 10
39138- 6 6 6 0 0 0 0 0 0 0 0 0
39139- 0 0 0 0 0 0 0 0 0 0 0 0
39140- 0 0 0 0 0 0 0 0 0 0 0 0
39141- 0 0 0 0 0 0 0 0 0 0 0 0
39142- 0 0 0 0 0 0 0 0 0 0 0 0
39143- 0 0 0 0 0 0 0 0 0 0 0 0
39144- 0 0 0 0 0 0 0 0 0 0 0 0
39145- 0 0 0 0 0 0 0 0 0 0 0 0
39146- 0 0 0 0 0 0 0 0 0 0 0 0
39147- 0 0 1 0 0 0 0 0 0 0 0 0
39148- 0 0 0 0 0 0 0 0 0 0 0 0
39149- 0 0 0 0 0 0 0 0 0 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 10 10 10
39154- 22 22 22 42 42 42 66 66 66 86 86 86
39155- 66 66 66 38 38 38 38 38 38 22 22 22
39156- 26 26 26 34 34 34 54 54 54 66 66 66
39157- 86 86 86 70 70 70 46 46 46 26 26 26
39158- 14 14 14 6 6 6 0 0 0 0 0 0
39159- 0 0 0 0 0 0 0 0 0 0 0 0
39160- 0 0 0 0 0 0 0 0 0 0 0 0
39161- 0 0 0 0 0 0 0 0 0 0 0 0
39162- 0 0 0 0 0 0 0 0 0 0 0 0
39163- 0 0 0 0 0 0 0 0 0 0 0 0
39164- 0 0 0 0 0 0 0 0 0 0 0 0
39165- 0 0 0 0 0 0 0 0 0 0 0 0
39166- 0 0 0 0 0 0 0 0 0 0 0 0
39167- 0 0 1 0 0 1 0 0 1 0 0 0
39168- 0 0 0 0 0 0 0 0 0 0 0 0
39169- 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26
39174- 50 50 50 82 82 82 58 58 58 6 6 6
39175- 2 2 6 2 2 6 2 2 6 2 2 6
39176- 2 2 6 2 2 6 2 2 6 2 2 6
39177- 6 6 6 54 54 54 86 86 86 66 66 66
39178- 38 38 38 18 18 18 6 6 6 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 0 0 0
39183- 0 0 0 0 0 0 0 0 0 0 0 0
39184- 0 0 0 0 0 0 0 0 0 0 0 0
39185- 0 0 0 0 0 0 0 0 0 0 0 0
39186- 0 0 0 0 0 0 0 0 0 0 0 0
39187- 0 0 0 0 0 0 0 0 0 0 0 0
39188- 0 0 0 0 0 0 0 0 0 0 0 0
39189- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 22 22 22 50 50 50
39194- 78 78 78 34 34 34 2 2 6 2 2 6
39195- 2 2 6 2 2 6 2 2 6 2 2 6
39196- 2 2 6 2 2 6 2 2 6 2 2 6
39197- 2 2 6 2 2 6 6 6 6 70 70 70
39198- 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0
39203- 0 0 0 0 0 0 0 0 0 0 0 0
39204- 0 0 0 0 0 0 0 0 0 0 0 0
39205- 0 0 0 0 0 0 0 0 0 0 0 0
39206- 0 0 0 0 0 0 0 0 0 0 0 0
39207- 0 0 1 0 0 1 0 0 1 0 0 0
39208- 0 0 0 0 0 0 0 0 0 0 0 0
39209- 0 0 0 0 0 0 0 0 0 0 0 0
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- 6 6 6 18 18 18 42 42 42 82 82 82
39214- 26 26 26 2 2 6 2 2 6 2 2 6
39215- 2 2 6 2 2 6 2 2 6 2 2 6
39216- 2 2 6 2 2 6 2 2 6 14 14 14
39217- 46 46 46 34 34 34 6 6 6 2 2 6
39218- 42 42 42 78 78 78 42 42 42 18 18 18
39219- 6 6 6 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 0 0 0
39223- 0 0 0 0 0 0 0 0 0 0 0 0
39224- 0 0 0 0 0 0 0 0 0 0 0 0
39225- 0 0 0 0 0 0 0 0 0 0 0 0
39226- 0 0 0 0 0 0 0 0 0 0 0 0
39227- 0 0 1 0 0 0 0 0 1 0 0 0
39228- 0 0 0 0 0 0 0 0 0 0 0 0
39229- 0 0 0 0 0 0 0 0 0 0 0 0
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- 10 10 10 30 30 30 66 66 66 58 58 58
39234- 2 2 6 2 2 6 2 2 6 2 2 6
39235- 2 2 6 2 2 6 2 2 6 2 2 6
39236- 2 2 6 2 2 6 2 2 6 26 26 26
39237- 86 86 86 101 101 101 46 46 46 10 10 10
39238- 2 2 6 58 58 58 70 70 70 34 34 34
39239- 10 10 10 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 0 0 0
39243- 0 0 0 0 0 0 0 0 0 0 0 0
39244- 0 0 0 0 0 0 0 0 0 0 0 0
39245- 0 0 0 0 0 0 0 0 0 0 0 0
39246- 0 0 0 0 0 0 0 0 0 0 0 0
39247- 0 0 1 0 0 1 0 0 1 0 0 0
39248- 0 0 0 0 0 0 0 0 0 0 0 0
39249- 0 0 0 0 0 0 0 0 0 0 0 0
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- 14 14 14 42 42 42 86 86 86 10 10 10
39254- 2 2 6 2 2 6 2 2 6 2 2 6
39255- 2 2 6 2 2 6 2 2 6 2 2 6
39256- 2 2 6 2 2 6 2 2 6 30 30 30
39257- 94 94 94 94 94 94 58 58 58 26 26 26
39258- 2 2 6 6 6 6 78 78 78 54 54 54
39259- 22 22 22 6 6 6 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 0 0 0
39263- 0 0 0 0 0 0 0 0 0 0 0 0
39264- 0 0 0 0 0 0 0 0 0 0 0 0
39265- 0 0 0 0 0 0 0 0 0 0 0 0
39266- 0 0 0 0 0 0 0 0 0 0 0 0
39267- 0 0 0 0 0 0 0 0 0 0 0 0
39268- 0 0 0 0 0 0 0 0 0 0 0 0
39269- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
39273- 22 22 22 62 62 62 62 62 62 2 2 6
39274- 2 2 6 2 2 6 2 2 6 2 2 6
39275- 2 2 6 2 2 6 2 2 6 2 2 6
39276- 2 2 6 2 2 6 2 2 6 26 26 26
39277- 54 54 54 38 38 38 18 18 18 10 10 10
39278- 2 2 6 2 2 6 34 34 34 82 82 82
39279- 38 38 38 14 14 14 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 0 0 0
39283- 0 0 0 0 0 0 0 0 0 0 0 0
39284- 0 0 0 0 0 0 0 0 0 0 0 0
39285- 0 0 0 0 0 0 0 0 0 0 0 0
39286- 0 0 0 0 0 0 0 0 0 0 0 0
39287- 0 0 0 0 0 1 0 0 1 0 0 0
39288- 0 0 0 0 0 0 0 0 0 0 0 0
39289- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
39293- 30 30 30 78 78 78 30 30 30 2 2 6
39294- 2 2 6 2 2 6 2 2 6 2 2 6
39295- 2 2 6 2 2 6 2 2 6 2 2 6
39296- 2 2 6 2 2 6 2 2 6 10 10 10
39297- 10 10 10 2 2 6 2 2 6 2 2 6
39298- 2 2 6 2 2 6 2 2 6 78 78 78
39299- 50 50 50 18 18 18 6 6 6 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 0 0 0
39303- 0 0 0 0 0 0 0 0 0 0 0 0
39304- 0 0 0 0 0 0 0 0 0 0 0 0
39305- 0 0 0 0 0 0 0 0 0 0 0 0
39306- 0 0 0 0 0 0 0 0 0 0 0 0
39307- 0 0 1 0 0 0 0 0 0 0 0 0
39308- 0 0 0 0 0 0 0 0 0 0 0 0
39309- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
39313- 38 38 38 86 86 86 14 14 14 2 2 6
39314- 2 2 6 2 2 6 2 2 6 2 2 6
39315- 2 2 6 2 2 6 2 2 6 2 2 6
39316- 2 2 6 2 2 6 2 2 6 2 2 6
39317- 2 2 6 2 2 6 2 2 6 2 2 6
39318- 2 2 6 2 2 6 2 2 6 54 54 54
39319- 66 66 66 26 26 26 6 6 6 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 0 0 0
39323- 0 0 0 0 0 0 0 0 0 0 0 0
39324- 0 0 0 0 0 0 0 0 0 0 0 0
39325- 0 0 0 0 0 0 0 0 0 0 0 0
39326- 0 0 0 0 0 0 0 0 0 0 0 0
39327- 0 0 0 0 0 1 0 0 1 0 0 0
39328- 0 0 0 0 0 0 0 0 0 0 0 0
39329- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
39333- 42 42 42 82 82 82 2 2 6 2 2 6
39334- 2 2 6 6 6 6 10 10 10 2 2 6
39335- 2 2 6 2 2 6 2 2 6 2 2 6
39336- 2 2 6 2 2 6 2 2 6 6 6 6
39337- 14 14 14 10 10 10 2 2 6 2 2 6
39338- 2 2 6 2 2 6 2 2 6 18 18 18
39339- 82 82 82 34 34 34 10 10 10 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 0 0 0
39343- 0 0 0 0 0 0 0 0 0 0 0 0
39344- 0 0 0 0 0 0 0 0 0 0 0 0
39345- 0 0 0 0 0 0 0 0 0 0 0 0
39346- 0 0 0 0 0 0 0 0 0 0 0 0
39347- 0 0 1 0 0 0 0 0 0 0 0 0
39348- 0 0 0 0 0 0 0 0 0 0 0 0
39349- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
39353- 46 46 46 86 86 86 2 2 6 2 2 6
39354- 6 6 6 6 6 6 22 22 22 34 34 34
39355- 6 6 6 2 2 6 2 2 6 2 2 6
39356- 2 2 6 2 2 6 18 18 18 34 34 34
39357- 10 10 10 50 50 50 22 22 22 2 2 6
39358- 2 2 6 2 2 6 2 2 6 10 10 10
39359- 86 86 86 42 42 42 14 14 14 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 0 0 0
39363- 0 0 0 0 0 0 0 0 0 0 0 0
39364- 0 0 0 0 0 0 0 0 0 0 0 0
39365- 0 0 0 0 0 0 0 0 0 0 0 0
39366- 0 0 0 0 0 0 0 0 0 0 0 0
39367- 0 0 1 0 0 1 0 0 1 0 0 0
39368- 0 0 0 0 0 0 0 0 0 0 0 0
39369- 0 0 0 0 0 0 0 0 0 0 0 0
39370- 0 0 0 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 14 14 14
39373- 46 46 46 86 86 86 2 2 6 2 2 6
39374- 38 38 38 116 116 116 94 94 94 22 22 22
39375- 22 22 22 2 2 6 2 2 6 2 2 6
39376- 14 14 14 86 86 86 138 138 138 162 162 162
39377-154 154 154 38 38 38 26 26 26 6 6 6
39378- 2 2 6 2 2 6 2 2 6 2 2 6
39379- 86 86 86 46 46 46 14 14 14 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 0 0 0
39383- 0 0 0 0 0 0 0 0 0 0 0 0
39384- 0 0 0 0 0 0 0 0 0 0 0 0
39385- 0 0 0 0 0 0 0 0 0 0 0 0
39386- 0 0 0 0 0 0 0 0 0 0 0 0
39387- 0 0 0 0 0 0 0 0 0 0 0 0
39388- 0 0 0 0 0 0 0 0 0 0 0 0
39389- 0 0 0 0 0 0 0 0 0 0 0 0
39390- 0 0 0 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 14 14 14
39393- 46 46 46 86 86 86 2 2 6 14 14 14
39394-134 134 134 198 198 198 195 195 195 116 116 116
39395- 10 10 10 2 2 6 2 2 6 6 6 6
39396-101 98 89 187 187 187 210 210 210 218 218 218
39397-214 214 214 134 134 134 14 14 14 6 6 6
39398- 2 2 6 2 2 6 2 2 6 2 2 6
39399- 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0
39403- 0 0 0 0 0 0 0 0 0 0 0 0
39404- 0 0 0 0 0 0 0 0 0 0 0 0
39405- 0 0 0 0 0 0 0 0 0 0 0 0
39406- 0 0 0 0 0 0 0 0 1 0 0 0
39407- 0 0 1 0 0 1 0 0 1 0 0 0
39408- 0 0 0 0 0 0 0 0 0 0 0 0
39409- 0 0 0 0 0 0 0 0 0 0 0 0
39410- 0 0 0 0 0 0 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 14 14 14
39413- 46 46 46 86 86 86 2 2 6 54 54 54
39414-218 218 218 195 195 195 226 226 226 246 246 246
39415- 58 58 58 2 2 6 2 2 6 30 30 30
39416-210 210 210 253 253 253 174 174 174 123 123 123
39417-221 221 221 234 234 234 74 74 74 2 2 6
39418- 2 2 6 2 2 6 2 2 6 2 2 6
39419- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
39423- 0 0 0 0 0 0 0 0 0 0 0 0
39424- 0 0 0 0 0 0 0 0 0 0 0 0
39425- 0 0 0 0 0 0 0 0 0 0 0 0
39426- 0 0 0 0 0 0 0 0 0 0 0 0
39427- 0 0 0 0 0 0 0 0 0 0 0 0
39428- 0 0 0 0 0 0 0 0 0 0 0 0
39429- 0 0 0 0 0 0 0 0 0 0 0 0
39430- 0 0 0 0 0 0 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 14 14 14
39433- 46 46 46 82 82 82 2 2 6 106 106 106
39434-170 170 170 26 26 26 86 86 86 226 226 226
39435-123 123 123 10 10 10 14 14 14 46 46 46
39436-231 231 231 190 190 190 6 6 6 70 70 70
39437- 90 90 90 238 238 238 158 158 158 2 2 6
39438- 2 2 6 2 2 6 2 2 6 2 2 6
39439- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0
39443- 0 0 0 0 0 0 0 0 0 0 0 0
39444- 0 0 0 0 0 0 0 0 0 0 0 0
39445- 0 0 0 0 0 0 0 0 0 0 0 0
39446- 0 0 0 0 0 0 0 0 1 0 0 0
39447- 0 0 1 0 0 1 0 0 1 0 0 0
39448- 0 0 0 0 0 0 0 0 0 0 0 0
39449- 0 0 0 0 0 0 0 0 0 0 0 0
39450- 0 0 0 0 0 0 0 0 0 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 14 14 14
39453- 42 42 42 86 86 86 6 6 6 116 116 116
39454-106 106 106 6 6 6 70 70 70 149 149 149
39455-128 128 128 18 18 18 38 38 38 54 54 54
39456-221 221 221 106 106 106 2 2 6 14 14 14
39457- 46 46 46 190 190 190 198 198 198 2 2 6
39458- 2 2 6 2 2 6 2 2 6 2 2 6
39459- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0 0 0 0
39463- 0 0 0 0 0 0 0 0 0 0 0 0
39464- 0 0 0 0 0 0 0 0 0 0 0 0
39465- 0 0 0 0 0 0 0 0 0 0 0 0
39466- 0 0 0 0 0 0 0 0 1 0 0 0
39467- 0 0 1 0 0 0 0 0 1 0 0 0
39468- 0 0 0 0 0 0 0 0 0 0 0 0
39469- 0 0 0 0 0 0 0 0 0 0 0 0
39470- 0 0 0 0 0 0 0 0 0 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 14 14 14
39473- 42 42 42 94 94 94 14 14 14 101 101 101
39474-128 128 128 2 2 6 18 18 18 116 116 116
39475-118 98 46 121 92 8 121 92 8 98 78 10
39476-162 162 162 106 106 106 2 2 6 2 2 6
39477- 2 2 6 195 195 195 195 195 195 6 6 6
39478- 2 2 6 2 2 6 2 2 6 2 2 6
39479- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
39483- 0 0 0 0 0 0 0 0 0 0 0 0
39484- 0 0 0 0 0 0 0 0 0 0 0 0
39485- 0 0 0 0 0 0 0 0 0 0 0 0
39486- 0 0 0 0 0 0 0 0 1 0 0 1
39487- 0 0 1 0 0 0 0 0 1 0 0 0
39488- 0 0 0 0 0 0 0 0 0 0 0 0
39489- 0 0 0 0 0 0 0 0 0 0 0 0
39490- 0 0 0 0 0 0 0 0 0 0 0 0
39491- 0 0 0 0 0 0 0 0 0 0 0 0
39492- 0 0 0 0 0 0 0 0 0 10 10 10
39493- 38 38 38 90 90 90 14 14 14 58 58 58
39494-210 210 210 26 26 26 54 38 6 154 114 10
39495-226 170 11 236 186 11 225 175 15 184 144 12
39496-215 174 15 175 146 61 37 26 9 2 2 6
39497- 70 70 70 246 246 246 138 138 138 2 2 6
39498- 2 2 6 2 2 6 2 2 6 2 2 6
39499- 70 70 70 66 66 66 26 26 26 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
39503- 0 0 0 0 0 0 0 0 0 0 0 0
39504- 0 0 0 0 0 0 0 0 0 0 0 0
39505- 0 0 0 0 0 0 0 0 0 0 0 0
39506- 0 0 0 0 0 0 0 0 0 0 0 0
39507- 0 0 0 0 0 0 0 0 0 0 0 0
39508- 0 0 0 0 0 0 0 0 0 0 0 0
39509- 0 0 0 0 0 0 0 0 0 0 0 0
39510- 0 0 0 0 0 0 0 0 0 0 0 0
39511- 0 0 0 0 0 0 0 0 0 0 0 0
39512- 0 0 0 0 0 0 0 0 0 10 10 10
39513- 38 38 38 86 86 86 14 14 14 10 10 10
39514-195 195 195 188 164 115 192 133 9 225 175 15
39515-239 182 13 234 190 10 232 195 16 232 200 30
39516-245 207 45 241 208 19 232 195 16 184 144 12
39517-218 194 134 211 206 186 42 42 42 2 2 6
39518- 2 2 6 2 2 6 2 2 6 2 2 6
39519- 50 50 50 74 74 74 30 30 30 6 6 6
39520- 0 0 0 0 0 0 0 0 0 0 0 0
39521- 0 0 0 0 0 0 0 0 0 0 0 0
39522- 0 0 0 0 0 0 0 0 0 0 0 0
39523- 0 0 0 0 0 0 0 0 0 0 0 0
39524- 0 0 0 0 0 0 0 0 0 0 0 0
39525- 0 0 0 0 0 0 0 0 0 0 0 0
39526- 0 0 0 0 0 0 0 0 0 0 0 0
39527- 0 0 0 0 0 0 0 0 0 0 0 0
39528- 0 0 0 0 0 0 0 0 0 0 0 0
39529- 0 0 0 0 0 0 0 0 0 0 0 0
39530- 0 0 0 0 0 0 0 0 0 0 0 0
39531- 0 0 0 0 0 0 0 0 0 0 0 0
39532- 0 0 0 0 0 0 0 0 0 10 10 10
39533- 34 34 34 86 86 86 14 14 14 2 2 6
39534-121 87 25 192 133 9 219 162 10 239 182 13
39535-236 186 11 232 195 16 241 208 19 244 214 54
39536-246 218 60 246 218 38 246 215 20 241 208 19
39537-241 208 19 226 184 13 121 87 25 2 2 6
39538- 2 2 6 2 2 6 2 2 6 2 2 6
39539- 50 50 50 82 82 82 34 34 34 10 10 10
39540- 0 0 0 0 0 0 0 0 0 0 0 0
39541- 0 0 0 0 0 0 0 0 0 0 0 0
39542- 0 0 0 0 0 0 0 0 0 0 0 0
39543- 0 0 0 0 0 0 0 0 0 0 0 0
39544- 0 0 0 0 0 0 0 0 0 0 0 0
39545- 0 0 0 0 0 0 0 0 0 0 0 0
39546- 0 0 0 0 0 0 0 0 0 0 0 0
39547- 0 0 0 0 0 0 0 0 0 0 0 0
39548- 0 0 0 0 0 0 0 0 0 0 0 0
39549- 0 0 0 0 0 0 0 0 0 0 0 0
39550- 0 0 0 0 0 0 0 0 0 0 0 0
39551- 0 0 0 0 0 0 0 0 0 0 0 0
39552- 0 0 0 0 0 0 0 0 0 10 10 10
39553- 34 34 34 82 82 82 30 30 30 61 42 6
39554-180 123 7 206 145 10 230 174 11 239 182 13
39555-234 190 10 238 202 15 241 208 19 246 218 74
39556-246 218 38 246 215 20 246 215 20 246 215 20
39557-226 184 13 215 174 15 184 144 12 6 6 6
39558- 2 2 6 2 2 6 2 2 6 2 2 6
39559- 26 26 26 94 94 94 42 42 42 14 14 14
39560- 0 0 0 0 0 0 0 0 0 0 0 0
39561- 0 0 0 0 0 0 0 0 0 0 0 0
39562- 0 0 0 0 0 0 0 0 0 0 0 0
39563- 0 0 0 0 0 0 0 0 0 0 0 0
39564- 0 0 0 0 0 0 0 0 0 0 0 0
39565- 0 0 0 0 0 0 0 0 0 0 0 0
39566- 0 0 0 0 0 0 0 0 0 0 0 0
39567- 0 0 0 0 0 0 0 0 0 0 0 0
39568- 0 0 0 0 0 0 0 0 0 0 0 0
39569- 0 0 0 0 0 0 0 0 0 0 0 0
39570- 0 0 0 0 0 0 0 0 0 0 0 0
39571- 0 0 0 0 0 0 0 0 0 0 0 0
39572- 0 0 0 0 0 0 0 0 0 10 10 10
39573- 30 30 30 78 78 78 50 50 50 104 69 6
39574-192 133 9 216 158 10 236 178 12 236 186 11
39575-232 195 16 241 208 19 244 214 54 245 215 43
39576-246 215 20 246 215 20 241 208 19 198 155 10
39577-200 144 11 216 158 10 156 118 10 2 2 6
39578- 2 2 6 2 2 6 2 2 6 2 2 6
39579- 6 6 6 90 90 90 54 54 54 18 18 18
39580- 6 6 6 0 0 0 0 0 0 0 0 0
39581- 0 0 0 0 0 0 0 0 0 0 0 0
39582- 0 0 0 0 0 0 0 0 0 0 0 0
39583- 0 0 0 0 0 0 0 0 0 0 0 0
39584- 0 0 0 0 0 0 0 0 0 0 0 0
39585- 0 0 0 0 0 0 0 0 0 0 0 0
39586- 0 0 0 0 0 0 0 0 0 0 0 0
39587- 0 0 0 0 0 0 0 0 0 0 0 0
39588- 0 0 0 0 0 0 0 0 0 0 0 0
39589- 0 0 0 0 0 0 0 0 0 0 0 0
39590- 0 0 0 0 0 0 0 0 0 0 0 0
39591- 0 0 0 0 0 0 0 0 0 0 0 0
39592- 0 0 0 0 0 0 0 0 0 10 10 10
39593- 30 30 30 78 78 78 46 46 46 22 22 22
39594-137 92 6 210 162 10 239 182 13 238 190 10
39595-238 202 15 241 208 19 246 215 20 246 215 20
39596-241 208 19 203 166 17 185 133 11 210 150 10
39597-216 158 10 210 150 10 102 78 10 2 2 6
39598- 6 6 6 54 54 54 14 14 14 2 2 6
39599- 2 2 6 62 62 62 74 74 74 30 30 30
39600- 10 10 10 0 0 0 0 0 0 0 0 0
39601- 0 0 0 0 0 0 0 0 0 0 0 0
39602- 0 0 0 0 0 0 0 0 0 0 0 0
39603- 0 0 0 0 0 0 0 0 0 0 0 0
39604- 0 0 0 0 0 0 0 0 0 0 0 0
39605- 0 0 0 0 0 0 0 0 0 0 0 0
39606- 0 0 0 0 0 0 0 0 0 0 0 0
39607- 0 0 0 0 0 0 0 0 0 0 0 0
39608- 0 0 0 0 0 0 0 0 0 0 0 0
39609- 0 0 0 0 0 0 0 0 0 0 0 0
39610- 0 0 0 0 0 0 0 0 0 0 0 0
39611- 0 0 0 0 0 0 0 0 0 0 0 0
39612- 0 0 0 0 0 0 0 0 0 10 10 10
39613- 34 34 34 78 78 78 50 50 50 6 6 6
39614- 94 70 30 139 102 15 190 146 13 226 184 13
39615-232 200 30 232 195 16 215 174 15 190 146 13
39616-168 122 10 192 133 9 210 150 10 213 154 11
39617-202 150 34 182 157 106 101 98 89 2 2 6
39618- 2 2 6 78 78 78 116 116 116 58 58 58
39619- 2 2 6 22 22 22 90 90 90 46 46 46
39620- 18 18 18 6 6 6 0 0 0 0 0 0
39621- 0 0 0 0 0 0 0 0 0 0 0 0
39622- 0 0 0 0 0 0 0 0 0 0 0 0
39623- 0 0 0 0 0 0 0 0 0 0 0 0
39624- 0 0 0 0 0 0 0 0 0 0 0 0
39625- 0 0 0 0 0 0 0 0 0 0 0 0
39626- 0 0 0 0 0 0 0 0 0 0 0 0
39627- 0 0 0 0 0 0 0 0 0 0 0 0
39628- 0 0 0 0 0 0 0 0 0 0 0 0
39629- 0 0 0 0 0 0 0 0 0 0 0 0
39630- 0 0 0 0 0 0 0 0 0 0 0 0
39631- 0 0 0 0 0 0 0 0 0 0 0 0
39632- 0 0 0 0 0 0 0 0 0 10 10 10
39633- 38 38 38 86 86 86 50 50 50 6 6 6
39634-128 128 128 174 154 114 156 107 11 168 122 10
39635-198 155 10 184 144 12 197 138 11 200 144 11
39636-206 145 10 206 145 10 197 138 11 188 164 115
39637-195 195 195 198 198 198 174 174 174 14 14 14
39638- 2 2 6 22 22 22 116 116 116 116 116 116
39639- 22 22 22 2 2 6 74 74 74 70 70 70
39640- 30 30 30 10 10 10 0 0 0 0 0 0
39641- 0 0 0 0 0 0 0 0 0 0 0 0
39642- 0 0 0 0 0 0 0 0 0 0 0 0
39643- 0 0 0 0 0 0 0 0 0 0 0 0
39644- 0 0 0 0 0 0 0 0 0 0 0 0
39645- 0 0 0 0 0 0 0 0 0 0 0 0
39646- 0 0 0 0 0 0 0 0 0 0 0 0
39647- 0 0 0 0 0 0 0 0 0 0 0 0
39648- 0 0 0 0 0 0 0 0 0 0 0 0
39649- 0 0 0 0 0 0 0 0 0 0 0 0
39650- 0 0 0 0 0 0 0 0 0 0 0 0
39651- 0 0 0 0 0 0 0 0 0 0 0 0
39652- 0 0 0 0 0 0 6 6 6 18 18 18
39653- 50 50 50 101 101 101 26 26 26 10 10 10
39654-138 138 138 190 190 190 174 154 114 156 107 11
39655-197 138 11 200 144 11 197 138 11 192 133 9
39656-180 123 7 190 142 34 190 178 144 187 187 187
39657-202 202 202 221 221 221 214 214 214 66 66 66
39658- 2 2 6 2 2 6 50 50 50 62 62 62
39659- 6 6 6 2 2 6 10 10 10 90 90 90
39660- 50 50 50 18 18 18 6 6 6 0 0 0
39661- 0 0 0 0 0 0 0 0 0 0 0 0
39662- 0 0 0 0 0 0 0 0 0 0 0 0
39663- 0 0 0 0 0 0 0 0 0 0 0 0
39664- 0 0 0 0 0 0 0 0 0 0 0 0
39665- 0 0 0 0 0 0 0 0 0 0 0 0
39666- 0 0 0 0 0 0 0 0 0 0 0 0
39667- 0 0 0 0 0 0 0 0 0 0 0 0
39668- 0 0 0 0 0 0 0 0 0 0 0 0
39669- 0 0 0 0 0 0 0 0 0 0 0 0
39670- 0 0 0 0 0 0 0 0 0 0 0 0
39671- 0 0 0 0 0 0 0 0 0 0 0 0
39672- 0 0 0 0 0 0 10 10 10 34 34 34
39673- 74 74 74 74 74 74 2 2 6 6 6 6
39674-144 144 144 198 198 198 190 190 190 178 166 146
39675-154 121 60 156 107 11 156 107 11 168 124 44
39676-174 154 114 187 187 187 190 190 190 210 210 210
39677-246 246 246 253 253 253 253 253 253 182 182 182
39678- 6 6 6 2 2 6 2 2 6 2 2 6
39679- 2 2 6 2 2 6 2 2 6 62 62 62
39680- 74 74 74 34 34 34 14 14 14 0 0 0
39681- 0 0 0 0 0 0 0 0 0 0 0 0
39682- 0 0 0 0 0 0 0 0 0 0 0 0
39683- 0 0 0 0 0 0 0 0 0 0 0 0
39684- 0 0 0 0 0 0 0 0 0 0 0 0
39685- 0 0 0 0 0 0 0 0 0 0 0 0
39686- 0 0 0 0 0 0 0 0 0 0 0 0
39687- 0 0 0 0 0 0 0 0 0 0 0 0
39688- 0 0 0 0 0 0 0 0 0 0 0 0
39689- 0 0 0 0 0 0 0 0 0 0 0 0
39690- 0 0 0 0 0 0 0 0 0 0 0 0
39691- 0 0 0 0 0 0 0 0 0 0 0 0
39692- 0 0 0 10 10 10 22 22 22 54 54 54
39693- 94 94 94 18 18 18 2 2 6 46 46 46
39694-234 234 234 221 221 221 190 190 190 190 190 190
39695-190 190 190 187 187 187 187 187 187 190 190 190
39696-190 190 190 195 195 195 214 214 214 242 242 242
39697-253 253 253 253 253 253 253 253 253 253 253 253
39698- 82 82 82 2 2 6 2 2 6 2 2 6
39699- 2 2 6 2 2 6 2 2 6 14 14 14
39700- 86 86 86 54 54 54 22 22 22 6 6 6
39701- 0 0 0 0 0 0 0 0 0 0 0 0
39702- 0 0 0 0 0 0 0 0 0 0 0 0
39703- 0 0 0 0 0 0 0 0 0 0 0 0
39704- 0 0 0 0 0 0 0 0 0 0 0 0
39705- 0 0 0 0 0 0 0 0 0 0 0 0
39706- 0 0 0 0 0 0 0 0 0 0 0 0
39707- 0 0 0 0 0 0 0 0 0 0 0 0
39708- 0 0 0 0 0 0 0 0 0 0 0 0
39709- 0 0 0 0 0 0 0 0 0 0 0 0
39710- 0 0 0 0 0 0 0 0 0 0 0 0
39711- 0 0 0 0 0 0 0 0 0 0 0 0
39712- 6 6 6 18 18 18 46 46 46 90 90 90
39713- 46 46 46 18 18 18 6 6 6 182 182 182
39714-253 253 253 246 246 246 206 206 206 190 190 190
39715-190 190 190 190 190 190 190 190 190 190 190 190
39716-206 206 206 231 231 231 250 250 250 253 253 253
39717-253 253 253 253 253 253 253 253 253 253 253 253
39718-202 202 202 14 14 14 2 2 6 2 2 6
39719- 2 2 6 2 2 6 2 2 6 2 2 6
39720- 42 42 42 86 86 86 42 42 42 18 18 18
39721- 6 6 6 0 0 0 0 0 0 0 0 0
39722- 0 0 0 0 0 0 0 0 0 0 0 0
39723- 0 0 0 0 0 0 0 0 0 0 0 0
39724- 0 0 0 0 0 0 0 0 0 0 0 0
39725- 0 0 0 0 0 0 0 0 0 0 0 0
39726- 0 0 0 0 0 0 0 0 0 0 0 0
39727- 0 0 0 0 0 0 0 0 0 0 0 0
39728- 0 0 0 0 0 0 0 0 0 0 0 0
39729- 0 0 0 0 0 0 0 0 0 0 0 0
39730- 0 0 0 0 0 0 0 0 0 0 0 0
39731- 0 0 0 0 0 0 0 0 0 6 6 6
39732- 14 14 14 38 38 38 74 74 74 66 66 66
39733- 2 2 6 6 6 6 90 90 90 250 250 250
39734-253 253 253 253 253 253 238 238 238 198 198 198
39735-190 190 190 190 190 190 195 195 195 221 221 221
39736-246 246 246 253 253 253 253 253 253 253 253 253
39737-253 253 253 253 253 253 253 253 253 253 253 253
39738-253 253 253 82 82 82 2 2 6 2 2 6
39739- 2 2 6 2 2 6 2 2 6 2 2 6
39740- 2 2 6 78 78 78 70 70 70 34 34 34
39741- 14 14 14 6 6 6 0 0 0 0 0 0
39742- 0 0 0 0 0 0 0 0 0 0 0 0
39743- 0 0 0 0 0 0 0 0 0 0 0 0
39744- 0 0 0 0 0 0 0 0 0 0 0 0
39745- 0 0 0 0 0 0 0 0 0 0 0 0
39746- 0 0 0 0 0 0 0 0 0 0 0 0
39747- 0 0 0 0 0 0 0 0 0 0 0 0
39748- 0 0 0 0 0 0 0 0 0 0 0 0
39749- 0 0 0 0 0 0 0 0 0 0 0 0
39750- 0 0 0 0 0 0 0 0 0 0 0 0
39751- 0 0 0 0 0 0 0 0 0 14 14 14
39752- 34 34 34 66 66 66 78 78 78 6 6 6
39753- 2 2 6 18 18 18 218 218 218 253 253 253
39754-253 253 253 253 253 253 253 253 253 246 246 246
39755-226 226 226 231 231 231 246 246 246 253 253 253
39756-253 253 253 253 253 253 253 253 253 253 253 253
39757-253 253 253 253 253 253 253 253 253 253 253 253
39758-253 253 253 178 178 178 2 2 6 2 2 6
39759- 2 2 6 2 2 6 2 2 6 2 2 6
39760- 2 2 6 18 18 18 90 90 90 62 62 62
39761- 30 30 30 10 10 10 0 0 0 0 0 0
39762- 0 0 0 0 0 0 0 0 0 0 0 0
39763- 0 0 0 0 0 0 0 0 0 0 0 0
39764- 0 0 0 0 0 0 0 0 0 0 0 0
39765- 0 0 0 0 0 0 0 0 0 0 0 0
39766- 0 0 0 0 0 0 0 0 0 0 0 0
39767- 0 0 0 0 0 0 0 0 0 0 0 0
39768- 0 0 0 0 0 0 0 0 0 0 0 0
39769- 0 0 0 0 0 0 0 0 0 0 0 0
39770- 0 0 0 0 0 0 0 0 0 0 0 0
39771- 0 0 0 0 0 0 10 10 10 26 26 26
39772- 58 58 58 90 90 90 18 18 18 2 2 6
39773- 2 2 6 110 110 110 253 253 253 253 253 253
39774-253 253 253 253 253 253 253 253 253 253 253 253
39775-250 250 250 253 253 253 253 253 253 253 253 253
39776-253 253 253 253 253 253 253 253 253 253 253 253
39777-253 253 253 253 253 253 253 253 253 253 253 253
39778-253 253 253 231 231 231 18 18 18 2 2 6
39779- 2 2 6 2 2 6 2 2 6 2 2 6
39780- 2 2 6 2 2 6 18 18 18 94 94 94
39781- 54 54 54 26 26 26 10 10 10 0 0 0
39782- 0 0 0 0 0 0 0 0 0 0 0 0
39783- 0 0 0 0 0 0 0 0 0 0 0 0
39784- 0 0 0 0 0 0 0 0 0 0 0 0
39785- 0 0 0 0 0 0 0 0 0 0 0 0
39786- 0 0 0 0 0 0 0 0 0 0 0 0
39787- 0 0 0 0 0 0 0 0 0 0 0 0
39788- 0 0 0 0 0 0 0 0 0 0 0 0
39789- 0 0 0 0 0 0 0 0 0 0 0 0
39790- 0 0 0 0 0 0 0 0 0 0 0 0
39791- 0 0 0 6 6 6 22 22 22 50 50 50
39792- 90 90 90 26 26 26 2 2 6 2 2 6
39793- 14 14 14 195 195 195 250 250 250 253 253 253
39794-253 253 253 253 253 253 253 253 253 253 253 253
39795-253 253 253 253 253 253 253 253 253 253 253 253
39796-253 253 253 253 253 253 253 253 253 253 253 253
39797-253 253 253 253 253 253 253 253 253 253 253 253
39798-250 250 250 242 242 242 54 54 54 2 2 6
39799- 2 2 6 2 2 6 2 2 6 2 2 6
39800- 2 2 6 2 2 6 2 2 6 38 38 38
39801- 86 86 86 50 50 50 22 22 22 6 6 6
39802- 0 0 0 0 0 0 0 0 0 0 0 0
39803- 0 0 0 0 0 0 0 0 0 0 0 0
39804- 0 0 0 0 0 0 0 0 0 0 0 0
39805- 0 0 0 0 0 0 0 0 0 0 0 0
39806- 0 0 0 0 0 0 0 0 0 0 0 0
39807- 0 0 0 0 0 0 0 0 0 0 0 0
39808- 0 0 0 0 0 0 0 0 0 0 0 0
39809- 0 0 0 0 0 0 0 0 0 0 0 0
39810- 0 0 0 0 0 0 0 0 0 0 0 0
39811- 6 6 6 14 14 14 38 38 38 82 82 82
39812- 34 34 34 2 2 6 2 2 6 2 2 6
39813- 42 42 42 195 195 195 246 246 246 253 253 253
39814-253 253 253 253 253 253 253 253 253 250 250 250
39815-242 242 242 242 242 242 250 250 250 253 253 253
39816-253 253 253 253 253 253 253 253 253 253 253 253
39817-253 253 253 250 250 250 246 246 246 238 238 238
39818-226 226 226 231 231 231 101 101 101 6 6 6
39819- 2 2 6 2 2 6 2 2 6 2 2 6
39820- 2 2 6 2 2 6 2 2 6 2 2 6
39821- 38 38 38 82 82 82 42 42 42 14 14 14
39822- 6 6 6 0 0 0 0 0 0 0 0 0
39823- 0 0 0 0 0 0 0 0 0 0 0 0
39824- 0 0 0 0 0 0 0 0 0 0 0 0
39825- 0 0 0 0 0 0 0 0 0 0 0 0
39826- 0 0 0 0 0 0 0 0 0 0 0 0
39827- 0 0 0 0 0 0 0 0 0 0 0 0
39828- 0 0 0 0 0 0 0 0 0 0 0 0
39829- 0 0 0 0 0 0 0 0 0 0 0 0
39830- 0 0 0 0 0 0 0 0 0 0 0 0
39831- 10 10 10 26 26 26 62 62 62 66 66 66
39832- 2 2 6 2 2 6 2 2 6 6 6 6
39833- 70 70 70 170 170 170 206 206 206 234 234 234
39834-246 246 246 250 250 250 250 250 250 238 238 238
39835-226 226 226 231 231 231 238 238 238 250 250 250
39836-250 250 250 250 250 250 246 246 246 231 231 231
39837-214 214 214 206 206 206 202 202 202 202 202 202
39838-198 198 198 202 202 202 182 182 182 18 18 18
39839- 2 2 6 2 2 6 2 2 6 2 2 6
39840- 2 2 6 2 2 6 2 2 6 2 2 6
39841- 2 2 6 62 62 62 66 66 66 30 30 30
39842- 10 10 10 0 0 0 0 0 0 0 0 0
39843- 0 0 0 0 0 0 0 0 0 0 0 0
39844- 0 0 0 0 0 0 0 0 0 0 0 0
39845- 0 0 0 0 0 0 0 0 0 0 0 0
39846- 0 0 0 0 0 0 0 0 0 0 0 0
39847- 0 0 0 0 0 0 0 0 0 0 0 0
39848- 0 0 0 0 0 0 0 0 0 0 0 0
39849- 0 0 0 0 0 0 0 0 0 0 0 0
39850- 0 0 0 0 0 0 0 0 0 0 0 0
39851- 14 14 14 42 42 42 82 82 82 18 18 18
39852- 2 2 6 2 2 6 2 2 6 10 10 10
39853- 94 94 94 182 182 182 218 218 218 242 242 242
39854-250 250 250 253 253 253 253 253 253 250 250 250
39855-234 234 234 253 253 253 253 253 253 253 253 253
39856-253 253 253 253 253 253 253 253 253 246 246 246
39857-238 238 238 226 226 226 210 210 210 202 202 202
39858-195 195 195 195 195 195 210 210 210 158 158 158
39859- 6 6 6 14 14 14 50 50 50 14 14 14
39860- 2 2 6 2 2 6 2 2 6 2 2 6
39861- 2 2 6 6 6 6 86 86 86 46 46 46
39862- 18 18 18 6 6 6 0 0 0 0 0 0
39863- 0 0 0 0 0 0 0 0 0 0 0 0
39864- 0 0 0 0 0 0 0 0 0 0 0 0
39865- 0 0 0 0 0 0 0 0 0 0 0 0
39866- 0 0 0 0 0 0 0 0 0 0 0 0
39867- 0 0 0 0 0 0 0 0 0 0 0 0
39868- 0 0 0 0 0 0 0 0 0 0 0 0
39869- 0 0 0 0 0 0 0 0 0 0 0 0
39870- 0 0 0 0 0 0 0 0 0 6 6 6
39871- 22 22 22 54 54 54 70 70 70 2 2 6
39872- 2 2 6 10 10 10 2 2 6 22 22 22
39873-166 166 166 231 231 231 250 250 250 253 253 253
39874-253 253 253 253 253 253 253 253 253 250 250 250
39875-242 242 242 253 253 253 253 253 253 253 253 253
39876-253 253 253 253 253 253 253 253 253 253 253 253
39877-253 253 253 253 253 253 253 253 253 246 246 246
39878-231 231 231 206 206 206 198 198 198 226 226 226
39879- 94 94 94 2 2 6 6 6 6 38 38 38
39880- 30 30 30 2 2 6 2 2 6 2 2 6
39881- 2 2 6 2 2 6 62 62 62 66 66 66
39882- 26 26 26 10 10 10 0 0 0 0 0 0
39883- 0 0 0 0 0 0 0 0 0 0 0 0
39884- 0 0 0 0 0 0 0 0 0 0 0 0
39885- 0 0 0 0 0 0 0 0 0 0 0 0
39886- 0 0 0 0 0 0 0 0 0 0 0 0
39887- 0 0 0 0 0 0 0 0 0 0 0 0
39888- 0 0 0 0 0 0 0 0 0 0 0 0
39889- 0 0 0 0 0 0 0 0 0 0 0 0
39890- 0 0 0 0 0 0 0 0 0 10 10 10
39891- 30 30 30 74 74 74 50 50 50 2 2 6
39892- 26 26 26 26 26 26 2 2 6 106 106 106
39893-238 238 238 253 253 253 253 253 253 253 253 253
39894-253 253 253 253 253 253 253 253 253 253 253 253
39895-253 253 253 253 253 253 253 253 253 253 253 253
39896-253 253 253 253 253 253 253 253 253 253 253 253
39897-253 253 253 253 253 253 253 253 253 253 253 253
39898-253 253 253 246 246 246 218 218 218 202 202 202
39899-210 210 210 14 14 14 2 2 6 2 2 6
39900- 30 30 30 22 22 22 2 2 6 2 2 6
39901- 2 2 6 2 2 6 18 18 18 86 86 86
39902- 42 42 42 14 14 14 0 0 0 0 0 0
39903- 0 0 0 0 0 0 0 0 0 0 0 0
39904- 0 0 0 0 0 0 0 0 0 0 0 0
39905- 0 0 0 0 0 0 0 0 0 0 0 0
39906- 0 0 0 0 0 0 0 0 0 0 0 0
39907- 0 0 0 0 0 0 0 0 0 0 0 0
39908- 0 0 0 0 0 0 0 0 0 0 0 0
39909- 0 0 0 0 0 0 0 0 0 0 0 0
39910- 0 0 0 0 0 0 0 0 0 14 14 14
39911- 42 42 42 90 90 90 22 22 22 2 2 6
39912- 42 42 42 2 2 6 18 18 18 218 218 218
39913-253 253 253 253 253 253 253 253 253 253 253 253
39914-253 253 253 253 253 253 253 253 253 253 253 253
39915-253 253 253 253 253 253 253 253 253 253 253 253
39916-253 253 253 253 253 253 253 253 253 253 253 253
39917-253 253 253 253 253 253 253 253 253 253 253 253
39918-253 253 253 253 253 253 250 250 250 221 221 221
39919-218 218 218 101 101 101 2 2 6 14 14 14
39920- 18 18 18 38 38 38 10 10 10 2 2 6
39921- 2 2 6 2 2 6 2 2 6 78 78 78
39922- 58 58 58 22 22 22 6 6 6 0 0 0
39923- 0 0 0 0 0 0 0 0 0 0 0 0
39924- 0 0 0 0 0 0 0 0 0 0 0 0
39925- 0 0 0 0 0 0 0 0 0 0 0 0
39926- 0 0 0 0 0 0 0 0 0 0 0 0
39927- 0 0 0 0 0 0 0 0 0 0 0 0
39928- 0 0 0 0 0 0 0 0 0 0 0 0
39929- 0 0 0 0 0 0 0 0 0 0 0 0
39930- 0 0 0 0 0 0 6 6 6 18 18 18
39931- 54 54 54 82 82 82 2 2 6 26 26 26
39932- 22 22 22 2 2 6 123 123 123 253 253 253
39933-253 253 253 253 253 253 253 253 253 253 253 253
39934-253 253 253 253 253 253 253 253 253 253 253 253
39935-253 253 253 253 253 253 253 253 253 253 253 253
39936-253 253 253 253 253 253 253 253 253 253 253 253
39937-253 253 253 253 253 253 253 253 253 253 253 253
39938-253 253 253 253 253 253 253 253 253 250 250 250
39939-238 238 238 198 198 198 6 6 6 38 38 38
39940- 58 58 58 26 26 26 38 38 38 2 2 6
39941- 2 2 6 2 2 6 2 2 6 46 46 46
39942- 78 78 78 30 30 30 10 10 10 0 0 0
39943- 0 0 0 0 0 0 0 0 0 0 0 0
39944- 0 0 0 0 0 0 0 0 0 0 0 0
39945- 0 0 0 0 0 0 0 0 0 0 0 0
39946- 0 0 0 0 0 0 0 0 0 0 0 0
39947- 0 0 0 0 0 0 0 0 0 0 0 0
39948- 0 0 0 0 0 0 0 0 0 0 0 0
39949- 0 0 0 0 0 0 0 0 0 0 0 0
39950- 0 0 0 0 0 0 10 10 10 30 30 30
39951- 74 74 74 58 58 58 2 2 6 42 42 42
39952- 2 2 6 22 22 22 231 231 231 253 253 253
39953-253 253 253 253 253 253 253 253 253 253 253 253
39954-253 253 253 253 253 253 253 253 253 250 250 250
39955-253 253 253 253 253 253 253 253 253 253 253 253
39956-253 253 253 253 253 253 253 253 253 253 253 253
39957-253 253 253 253 253 253 253 253 253 253 253 253
39958-253 253 253 253 253 253 253 253 253 253 253 253
39959-253 253 253 246 246 246 46 46 46 38 38 38
39960- 42 42 42 14 14 14 38 38 38 14 14 14
39961- 2 2 6 2 2 6 2 2 6 6 6 6
39962- 86 86 86 46 46 46 14 14 14 0 0 0
39963- 0 0 0 0 0 0 0 0 0 0 0 0
39964- 0 0 0 0 0 0 0 0 0 0 0 0
39965- 0 0 0 0 0 0 0 0 0 0 0 0
39966- 0 0 0 0 0 0 0 0 0 0 0 0
39967- 0 0 0 0 0 0 0 0 0 0 0 0
39968- 0 0 0 0 0 0 0 0 0 0 0 0
39969- 0 0 0 0 0 0 0 0 0 0 0 0
39970- 0 0 0 6 6 6 14 14 14 42 42 42
39971- 90 90 90 18 18 18 18 18 18 26 26 26
39972- 2 2 6 116 116 116 253 253 253 253 253 253
39973-253 253 253 253 253 253 253 253 253 253 253 253
39974-253 253 253 253 253 253 250 250 250 238 238 238
39975-253 253 253 253 253 253 253 253 253 253 253 253
39976-253 253 253 253 253 253 253 253 253 253 253 253
39977-253 253 253 253 253 253 253 253 253 253 253 253
39978-253 253 253 253 253 253 253 253 253 253 253 253
39979-253 253 253 253 253 253 94 94 94 6 6 6
39980- 2 2 6 2 2 6 10 10 10 34 34 34
39981- 2 2 6 2 2 6 2 2 6 2 2 6
39982- 74 74 74 58 58 58 22 22 22 6 6 6
39983- 0 0 0 0 0 0 0 0 0 0 0 0
39984- 0 0 0 0 0 0 0 0 0 0 0 0
39985- 0 0 0 0 0 0 0 0 0 0 0 0
39986- 0 0 0 0 0 0 0 0 0 0 0 0
39987- 0 0 0 0 0 0 0 0 0 0 0 0
39988- 0 0 0 0 0 0 0 0 0 0 0 0
39989- 0 0 0 0 0 0 0 0 0 0 0 0
39990- 0 0 0 10 10 10 26 26 26 66 66 66
39991- 82 82 82 2 2 6 38 38 38 6 6 6
39992- 14 14 14 210 210 210 253 253 253 253 253 253
39993-253 253 253 253 253 253 253 253 253 253 253 253
39994-253 253 253 253 253 253 246 246 246 242 242 242
39995-253 253 253 253 253 253 253 253 253 253 253 253
39996-253 253 253 253 253 253 253 253 253 253 253 253
39997-253 253 253 253 253 253 253 253 253 253 253 253
39998-253 253 253 253 253 253 253 253 253 253 253 253
39999-253 253 253 253 253 253 144 144 144 2 2 6
40000- 2 2 6 2 2 6 2 2 6 46 46 46
40001- 2 2 6 2 2 6 2 2 6 2 2 6
40002- 42 42 42 74 74 74 30 30 30 10 10 10
40003- 0 0 0 0 0 0 0 0 0 0 0 0
40004- 0 0 0 0 0 0 0 0 0 0 0 0
40005- 0 0 0 0 0 0 0 0 0 0 0 0
40006- 0 0 0 0 0 0 0 0 0 0 0 0
40007- 0 0 0 0 0 0 0 0 0 0 0 0
40008- 0 0 0 0 0 0 0 0 0 0 0 0
40009- 0 0 0 0 0 0 0 0 0 0 0 0
40010- 6 6 6 14 14 14 42 42 42 90 90 90
40011- 26 26 26 6 6 6 42 42 42 2 2 6
40012- 74 74 74 250 250 250 253 253 253 253 253 253
40013-253 253 253 253 253 253 253 253 253 253 253 253
40014-253 253 253 253 253 253 242 242 242 242 242 242
40015-253 253 253 253 253 253 253 253 253 253 253 253
40016-253 253 253 253 253 253 253 253 253 253 253 253
40017-253 253 253 253 253 253 253 253 253 253 253 253
40018-253 253 253 253 253 253 253 253 253 253 253 253
40019-253 253 253 253 253 253 182 182 182 2 2 6
40020- 2 2 6 2 2 6 2 2 6 46 46 46
40021- 2 2 6 2 2 6 2 2 6 2 2 6
40022- 10 10 10 86 86 86 38 38 38 10 10 10
40023- 0 0 0 0 0 0 0 0 0 0 0 0
40024- 0 0 0 0 0 0 0 0 0 0 0 0
40025- 0 0 0 0 0 0 0 0 0 0 0 0
40026- 0 0 0 0 0 0 0 0 0 0 0 0
40027- 0 0 0 0 0 0 0 0 0 0 0 0
40028- 0 0 0 0 0 0 0 0 0 0 0 0
40029- 0 0 0 0 0 0 0 0 0 0 0 0
40030- 10 10 10 26 26 26 66 66 66 82 82 82
40031- 2 2 6 22 22 22 18 18 18 2 2 6
40032-149 149 149 253 253 253 253 253 253 253 253 253
40033-253 253 253 253 253 253 253 253 253 253 253 253
40034-253 253 253 253 253 253 234 234 234 242 242 242
40035-253 253 253 253 253 253 253 253 253 253 253 253
40036-253 253 253 253 253 253 253 253 253 253 253 253
40037-253 253 253 253 253 253 253 253 253 253 253 253
40038-253 253 253 253 253 253 253 253 253 253 253 253
40039-253 253 253 253 253 253 206 206 206 2 2 6
40040- 2 2 6 2 2 6 2 2 6 38 38 38
40041- 2 2 6 2 2 6 2 2 6 2 2 6
40042- 6 6 6 86 86 86 46 46 46 14 14 14
40043- 0 0 0 0 0 0 0 0 0 0 0 0
40044- 0 0 0 0 0 0 0 0 0 0 0 0
40045- 0 0 0 0 0 0 0 0 0 0 0 0
40046- 0 0 0 0 0 0 0 0 0 0 0 0
40047- 0 0 0 0 0 0 0 0 0 0 0 0
40048- 0 0 0 0 0 0 0 0 0 0 0 0
40049- 0 0 0 0 0 0 0 0 0 6 6 6
40050- 18 18 18 46 46 46 86 86 86 18 18 18
40051- 2 2 6 34 34 34 10 10 10 6 6 6
40052-210 210 210 253 253 253 253 253 253 253 253 253
40053-253 253 253 253 253 253 253 253 253 253 253 253
40054-253 253 253 253 253 253 234 234 234 242 242 242
40055-253 253 253 253 253 253 253 253 253 253 253 253
40056-253 253 253 253 253 253 253 253 253 253 253 253
40057-253 253 253 253 253 253 253 253 253 253 253 253
40058-253 253 253 253 253 253 253 253 253 253 253 253
40059-253 253 253 253 253 253 221 221 221 6 6 6
40060- 2 2 6 2 2 6 6 6 6 30 30 30
40061- 2 2 6 2 2 6 2 2 6 2 2 6
40062- 2 2 6 82 82 82 54 54 54 18 18 18
40063- 6 6 6 0 0 0 0 0 0 0 0 0
40064- 0 0 0 0 0 0 0 0 0 0 0 0
40065- 0 0 0 0 0 0 0 0 0 0 0 0
40066- 0 0 0 0 0 0 0 0 0 0 0 0
40067- 0 0 0 0 0 0 0 0 0 0 0 0
40068- 0 0 0 0 0 0 0 0 0 0 0 0
40069- 0 0 0 0 0 0 0 0 0 10 10 10
40070- 26 26 26 66 66 66 62 62 62 2 2 6
40071- 2 2 6 38 38 38 10 10 10 26 26 26
40072-238 238 238 253 253 253 253 253 253 253 253 253
40073-253 253 253 253 253 253 253 253 253 253 253 253
40074-253 253 253 253 253 253 231 231 231 238 238 238
40075-253 253 253 253 253 253 253 253 253 253 253 253
40076-253 253 253 253 253 253 253 253 253 253 253 253
40077-253 253 253 253 253 253 253 253 253 253 253 253
40078-253 253 253 253 253 253 253 253 253 253 253 253
40079-253 253 253 253 253 253 231 231 231 6 6 6
40080- 2 2 6 2 2 6 10 10 10 30 30 30
40081- 2 2 6 2 2 6 2 2 6 2 2 6
40082- 2 2 6 66 66 66 58 58 58 22 22 22
40083- 6 6 6 0 0 0 0 0 0 0 0 0
40084- 0 0 0 0 0 0 0 0 0 0 0 0
40085- 0 0 0 0 0 0 0 0 0 0 0 0
40086- 0 0 0 0 0 0 0 0 0 0 0 0
40087- 0 0 0 0 0 0 0 0 0 0 0 0
40088- 0 0 0 0 0 0 0 0 0 0 0 0
40089- 0 0 0 0 0 0 0 0 0 10 10 10
40090- 38 38 38 78 78 78 6 6 6 2 2 6
40091- 2 2 6 46 46 46 14 14 14 42 42 42
40092-246 246 246 253 253 253 253 253 253 253 253 253
40093-253 253 253 253 253 253 253 253 253 253 253 253
40094-253 253 253 253 253 253 231 231 231 242 242 242
40095-253 253 253 253 253 253 253 253 253 253 253 253
40096-253 253 253 253 253 253 253 253 253 253 253 253
40097-253 253 253 253 253 253 253 253 253 253 253 253
40098-253 253 253 253 253 253 253 253 253 253 253 253
40099-253 253 253 253 253 253 234 234 234 10 10 10
40100- 2 2 6 2 2 6 22 22 22 14 14 14
40101- 2 2 6 2 2 6 2 2 6 2 2 6
40102- 2 2 6 66 66 66 62 62 62 22 22 22
40103- 6 6 6 0 0 0 0 0 0 0 0 0
40104- 0 0 0 0 0 0 0 0 0 0 0 0
40105- 0 0 0 0 0 0 0 0 0 0 0 0
40106- 0 0 0 0 0 0 0 0 0 0 0 0
40107- 0 0 0 0 0 0 0 0 0 0 0 0
40108- 0 0 0 0 0 0 0 0 0 0 0 0
40109- 0 0 0 0 0 0 6 6 6 18 18 18
40110- 50 50 50 74 74 74 2 2 6 2 2 6
40111- 14 14 14 70 70 70 34 34 34 62 62 62
40112-250 250 250 253 253 253 253 253 253 253 253 253
40113-253 253 253 253 253 253 253 253 253 253 253 253
40114-253 253 253 253 253 253 231 231 231 246 246 246
40115-253 253 253 253 253 253 253 253 253 253 253 253
40116-253 253 253 253 253 253 253 253 253 253 253 253
40117-253 253 253 253 253 253 253 253 253 253 253 253
40118-253 253 253 253 253 253 253 253 253 253 253 253
40119-253 253 253 253 253 253 234 234 234 14 14 14
40120- 2 2 6 2 2 6 30 30 30 2 2 6
40121- 2 2 6 2 2 6 2 2 6 2 2 6
40122- 2 2 6 66 66 66 62 62 62 22 22 22
40123- 6 6 6 0 0 0 0 0 0 0 0 0
40124- 0 0 0 0 0 0 0 0 0 0 0 0
40125- 0 0 0 0 0 0 0 0 0 0 0 0
40126- 0 0 0 0 0 0 0 0 0 0 0 0
40127- 0 0 0 0 0 0 0 0 0 0 0 0
40128- 0 0 0 0 0 0 0 0 0 0 0 0
40129- 0 0 0 0 0 0 6 6 6 18 18 18
40130- 54 54 54 62 62 62 2 2 6 2 2 6
40131- 2 2 6 30 30 30 46 46 46 70 70 70
40132-250 250 250 253 253 253 253 253 253 253 253 253
40133-253 253 253 253 253 253 253 253 253 253 253 253
40134-253 253 253 253 253 253 231 231 231 246 246 246
40135-253 253 253 253 253 253 253 253 253 253 253 253
40136-253 253 253 253 253 253 253 253 253 253 253 253
40137-253 253 253 253 253 253 253 253 253 253 253 253
40138-253 253 253 253 253 253 253 253 253 253 253 253
40139-253 253 253 253 253 253 226 226 226 10 10 10
40140- 2 2 6 6 6 6 30 30 30 2 2 6
40141- 2 2 6 2 2 6 2 2 6 2 2 6
40142- 2 2 6 66 66 66 58 58 58 22 22 22
40143- 6 6 6 0 0 0 0 0 0 0 0 0
40144- 0 0 0 0 0 0 0 0 0 0 0 0
40145- 0 0 0 0 0 0 0 0 0 0 0 0
40146- 0 0 0 0 0 0 0 0 0 0 0 0
40147- 0 0 0 0 0 0 0 0 0 0 0 0
40148- 0 0 0 0 0 0 0 0 0 0 0 0
40149- 0 0 0 0 0 0 6 6 6 22 22 22
40150- 58 58 58 62 62 62 2 2 6 2 2 6
40151- 2 2 6 2 2 6 30 30 30 78 78 78
40152-250 250 250 253 253 253 253 253 253 253 253 253
40153-253 253 253 253 253 253 253 253 253 253 253 253
40154-253 253 253 253 253 253 231 231 231 246 246 246
40155-253 253 253 253 253 253 253 253 253 253 253 253
40156-253 253 253 253 253 253 253 253 253 253 253 253
40157-253 253 253 253 253 253 253 253 253 253 253 253
40158-253 253 253 253 253 253 253 253 253 253 253 253
40159-253 253 253 253 253 253 206 206 206 2 2 6
40160- 22 22 22 34 34 34 18 14 6 22 22 22
40161- 26 26 26 18 18 18 6 6 6 2 2 6
40162- 2 2 6 82 82 82 54 54 54 18 18 18
40163- 6 6 6 0 0 0 0 0 0 0 0 0
40164- 0 0 0 0 0 0 0 0 0 0 0 0
40165- 0 0 0 0 0 0 0 0 0 0 0 0
40166- 0 0 0 0 0 0 0 0 0 0 0 0
40167- 0 0 0 0 0 0 0 0 0 0 0 0
40168- 0 0 0 0 0 0 0 0 0 0 0 0
40169- 0 0 0 0 0 0 6 6 6 26 26 26
40170- 62 62 62 106 106 106 74 54 14 185 133 11
40171-210 162 10 121 92 8 6 6 6 62 62 62
40172-238 238 238 253 253 253 253 253 253 253 253 253
40173-253 253 253 253 253 253 253 253 253 253 253 253
40174-253 253 253 253 253 253 231 231 231 246 246 246
40175-253 253 253 253 253 253 253 253 253 253 253 253
40176-253 253 253 253 253 253 253 253 253 253 253 253
40177-253 253 253 253 253 253 253 253 253 253 253 253
40178-253 253 253 253 253 253 253 253 253 253 253 253
40179-253 253 253 253 253 253 158 158 158 18 18 18
40180- 14 14 14 2 2 6 2 2 6 2 2 6
40181- 6 6 6 18 18 18 66 66 66 38 38 38
40182- 6 6 6 94 94 94 50 50 50 18 18 18
40183- 6 6 6 0 0 0 0 0 0 0 0 0
40184- 0 0 0 0 0 0 0 0 0 0 0 0
40185- 0 0 0 0 0 0 0 0 0 0 0 0
40186- 0 0 0 0 0 0 0 0 0 0 0 0
40187- 0 0 0 0 0 0 0 0 0 0 0 0
40188- 0 0 0 0 0 0 0 0 0 6 6 6
40189- 10 10 10 10 10 10 18 18 18 38 38 38
40190- 78 78 78 142 134 106 216 158 10 242 186 14
40191-246 190 14 246 190 14 156 118 10 10 10 10
40192- 90 90 90 238 238 238 253 253 253 253 253 253
40193-253 253 253 253 253 253 253 253 253 253 253 253
40194-253 253 253 253 253 253 231 231 231 250 250 250
40195-253 253 253 253 253 253 253 253 253 253 253 253
40196-253 253 253 253 253 253 253 253 253 253 253 253
40197-253 253 253 253 253 253 253 253 253 253 253 253
40198-253 253 253 253 253 253 253 253 253 246 230 190
40199-238 204 91 238 204 91 181 142 44 37 26 9
40200- 2 2 6 2 2 6 2 2 6 2 2 6
40201- 2 2 6 2 2 6 38 38 38 46 46 46
40202- 26 26 26 106 106 106 54 54 54 18 18 18
40203- 6 6 6 0 0 0 0 0 0 0 0 0
40204- 0 0 0 0 0 0 0 0 0 0 0 0
40205- 0 0 0 0 0 0 0 0 0 0 0 0
40206- 0 0 0 0 0 0 0 0 0 0 0 0
40207- 0 0 0 0 0 0 0 0 0 0 0 0
40208- 0 0 0 6 6 6 14 14 14 22 22 22
40209- 30 30 30 38 38 38 50 50 50 70 70 70
40210-106 106 106 190 142 34 226 170 11 242 186 14
40211-246 190 14 246 190 14 246 190 14 154 114 10
40212- 6 6 6 74 74 74 226 226 226 253 253 253
40213-253 253 253 253 253 253 253 253 253 253 253 253
40214-253 253 253 253 253 253 231 231 231 250 250 250
40215-253 253 253 253 253 253 253 253 253 253 253 253
40216-253 253 253 253 253 253 253 253 253 253 253 253
40217-253 253 253 253 253 253 253 253 253 253 253 253
40218-253 253 253 253 253 253 253 253 253 228 184 62
40219-241 196 14 241 208 19 232 195 16 38 30 10
40220- 2 2 6 2 2 6 2 2 6 2 2 6
40221- 2 2 6 6 6 6 30 30 30 26 26 26
40222-203 166 17 154 142 90 66 66 66 26 26 26
40223- 6 6 6 0 0 0 0 0 0 0 0 0
40224- 0 0 0 0 0 0 0 0 0 0 0 0
40225- 0 0 0 0 0 0 0 0 0 0 0 0
40226- 0 0 0 0 0 0 0 0 0 0 0 0
40227- 0 0 0 0 0 0 0 0 0 0 0 0
40228- 6 6 6 18 18 18 38 38 38 58 58 58
40229- 78 78 78 86 86 86 101 101 101 123 123 123
40230-175 146 61 210 150 10 234 174 13 246 186 14
40231-246 190 14 246 190 14 246 190 14 238 190 10
40232-102 78 10 2 2 6 46 46 46 198 198 198
40233-253 253 253 253 253 253 253 253 253 253 253 253
40234-253 253 253 253 253 253 234 234 234 242 242 242
40235-253 253 253 253 253 253 253 253 253 253 253 253
40236-253 253 253 253 253 253 253 253 253 253 253 253
40237-253 253 253 253 253 253 253 253 253 253 253 253
40238-253 253 253 253 253 253 253 253 253 224 178 62
40239-242 186 14 241 196 14 210 166 10 22 18 6
40240- 2 2 6 2 2 6 2 2 6 2 2 6
40241- 2 2 6 2 2 6 6 6 6 121 92 8
40242-238 202 15 232 195 16 82 82 82 34 34 34
40243- 10 10 10 0 0 0 0 0 0 0 0 0
40244- 0 0 0 0 0 0 0 0 0 0 0 0
40245- 0 0 0 0 0 0 0 0 0 0 0 0
40246- 0 0 0 0 0 0 0 0 0 0 0 0
40247- 0 0 0 0 0 0 0 0 0 0 0 0
40248- 14 14 14 38 38 38 70 70 70 154 122 46
40249-190 142 34 200 144 11 197 138 11 197 138 11
40250-213 154 11 226 170 11 242 186 14 246 190 14
40251-246 190 14 246 190 14 246 190 14 246 190 14
40252-225 175 15 46 32 6 2 2 6 22 22 22
40253-158 158 158 250 250 250 253 253 253 253 253 253
40254-253 253 253 253 253 253 253 253 253 253 253 253
40255-253 253 253 253 253 253 253 253 253 253 253 253
40256-253 253 253 253 253 253 253 253 253 253 253 253
40257-253 253 253 253 253 253 253 253 253 253 253 253
40258-253 253 253 250 250 250 242 242 242 224 178 62
40259-239 182 13 236 186 11 213 154 11 46 32 6
40260- 2 2 6 2 2 6 2 2 6 2 2 6
40261- 2 2 6 2 2 6 61 42 6 225 175 15
40262-238 190 10 236 186 11 112 100 78 42 42 42
40263- 14 14 14 0 0 0 0 0 0 0 0 0
40264- 0 0 0 0 0 0 0 0 0 0 0 0
40265- 0 0 0 0 0 0 0 0 0 0 0 0
40266- 0 0 0 0 0 0 0 0 0 0 0 0
40267- 0 0 0 0 0 0 0 0 0 6 6 6
40268- 22 22 22 54 54 54 154 122 46 213 154 11
40269-226 170 11 230 174 11 226 170 11 226 170 11
40270-236 178 12 242 186 14 246 190 14 246 190 14
40271-246 190 14 246 190 14 246 190 14 246 190 14
40272-241 196 14 184 144 12 10 10 10 2 2 6
40273- 6 6 6 116 116 116 242 242 242 253 253 253
40274-253 253 253 253 253 253 253 253 253 253 253 253
40275-253 253 253 253 253 253 253 253 253 253 253 253
40276-253 253 253 253 253 253 253 253 253 253 253 253
40277-253 253 253 253 253 253 253 253 253 253 253 253
40278-253 253 253 231 231 231 198 198 198 214 170 54
40279-236 178 12 236 178 12 210 150 10 137 92 6
40280- 18 14 6 2 2 6 2 2 6 2 2 6
40281- 6 6 6 70 47 6 200 144 11 236 178 12
40282-239 182 13 239 182 13 124 112 88 58 58 58
40283- 22 22 22 6 6 6 0 0 0 0 0 0
40284- 0 0 0 0 0 0 0 0 0 0 0 0
40285- 0 0 0 0 0 0 0 0 0 0 0 0
40286- 0 0 0 0 0 0 0 0 0 0 0 0
40287- 0 0 0 0 0 0 0 0 0 10 10 10
40288- 30 30 30 70 70 70 180 133 36 226 170 11
40289-239 182 13 242 186 14 242 186 14 246 186 14
40290-246 190 14 246 190 14 246 190 14 246 190 14
40291-246 190 14 246 190 14 246 190 14 246 190 14
40292-246 190 14 232 195 16 98 70 6 2 2 6
40293- 2 2 6 2 2 6 66 66 66 221 221 221
40294-253 253 253 253 253 253 253 253 253 253 253 253
40295-253 253 253 253 253 253 253 253 253 253 253 253
40296-253 253 253 253 253 253 253 253 253 253 253 253
40297-253 253 253 253 253 253 253 253 253 253 253 253
40298-253 253 253 206 206 206 198 198 198 214 166 58
40299-230 174 11 230 174 11 216 158 10 192 133 9
40300-163 110 8 116 81 8 102 78 10 116 81 8
40301-167 114 7 197 138 11 226 170 11 239 182 13
40302-242 186 14 242 186 14 162 146 94 78 78 78
40303- 34 34 34 14 14 14 6 6 6 0 0 0
40304- 0 0 0 0 0 0 0 0 0 0 0 0
40305- 0 0 0 0 0 0 0 0 0 0 0 0
40306- 0 0 0 0 0 0 0 0 0 0 0 0
40307- 0 0 0 0 0 0 0 0 0 6 6 6
40308- 30 30 30 78 78 78 190 142 34 226 170 11
40309-239 182 13 246 190 14 246 190 14 246 190 14
40310-246 190 14 246 190 14 246 190 14 246 190 14
40311-246 190 14 246 190 14 246 190 14 246 190 14
40312-246 190 14 241 196 14 203 166 17 22 18 6
40313- 2 2 6 2 2 6 2 2 6 38 38 38
40314-218 218 218 253 253 253 253 253 253 253 253 253
40315-253 253 253 253 253 253 253 253 253 253 253 253
40316-253 253 253 253 253 253 253 253 253 253 253 253
40317-253 253 253 253 253 253 253 253 253 253 253 253
40318-250 250 250 206 206 206 198 198 198 202 162 69
40319-226 170 11 236 178 12 224 166 10 210 150 10
40320-200 144 11 197 138 11 192 133 9 197 138 11
40321-210 150 10 226 170 11 242 186 14 246 190 14
40322-246 190 14 246 186 14 225 175 15 124 112 88
40323- 62 62 62 30 30 30 14 14 14 6 6 6
40324- 0 0 0 0 0 0 0 0 0 0 0 0
40325- 0 0 0 0 0 0 0 0 0 0 0 0
40326- 0 0 0 0 0 0 0 0 0 0 0 0
40327- 0 0 0 0 0 0 0 0 0 10 10 10
40328- 30 30 30 78 78 78 174 135 50 224 166 10
40329-239 182 13 246 190 14 246 190 14 246 190 14
40330-246 190 14 246 190 14 246 190 14 246 190 14
40331-246 190 14 246 190 14 246 190 14 246 190 14
40332-246 190 14 246 190 14 241 196 14 139 102 15
40333- 2 2 6 2 2 6 2 2 6 2 2 6
40334- 78 78 78 250 250 250 253 253 253 253 253 253
40335-253 253 253 253 253 253 253 253 253 253 253 253
40336-253 253 253 253 253 253 253 253 253 253 253 253
40337-253 253 253 253 253 253 253 253 253 253 253 253
40338-250 250 250 214 214 214 198 198 198 190 150 46
40339-219 162 10 236 178 12 234 174 13 224 166 10
40340-216 158 10 213 154 11 213 154 11 216 158 10
40341-226 170 11 239 182 13 246 190 14 246 190 14
40342-246 190 14 246 190 14 242 186 14 206 162 42
40343-101 101 101 58 58 58 30 30 30 14 14 14
40344- 6 6 6 0 0 0 0 0 0 0 0 0
40345- 0 0 0 0 0 0 0 0 0 0 0 0
40346- 0 0 0 0 0 0 0 0 0 0 0 0
40347- 0 0 0 0 0 0 0 0 0 10 10 10
40348- 30 30 30 74 74 74 174 135 50 216 158 10
40349-236 178 12 246 190 14 246 190 14 246 190 14
40350-246 190 14 246 190 14 246 190 14 246 190 14
40351-246 190 14 246 190 14 246 190 14 246 190 14
40352-246 190 14 246 190 14 241 196 14 226 184 13
40353- 61 42 6 2 2 6 2 2 6 2 2 6
40354- 22 22 22 238 238 238 253 253 253 253 253 253
40355-253 253 253 253 253 253 253 253 253 253 253 253
40356-253 253 253 253 253 253 253 253 253 253 253 253
40357-253 253 253 253 253 253 253 253 253 253 253 253
40358-253 253 253 226 226 226 187 187 187 180 133 36
40359-216 158 10 236 178 12 239 182 13 236 178 12
40360-230 174 11 226 170 11 226 170 11 230 174 11
40361-236 178 12 242 186 14 246 190 14 246 190 14
40362-246 190 14 246 190 14 246 186 14 239 182 13
40363-206 162 42 106 106 106 66 66 66 34 34 34
40364- 14 14 14 6 6 6 0 0 0 0 0 0
40365- 0 0 0 0 0 0 0 0 0 0 0 0
40366- 0 0 0 0 0 0 0 0 0 0 0 0
40367- 0 0 0 0 0 0 0 0 0 6 6 6
40368- 26 26 26 70 70 70 163 133 67 213 154 11
40369-236 178 12 246 190 14 246 190 14 246 190 14
40370-246 190 14 246 190 14 246 190 14 246 190 14
40371-246 190 14 246 190 14 246 190 14 246 190 14
40372-246 190 14 246 190 14 246 190 14 241 196 14
40373-190 146 13 18 14 6 2 2 6 2 2 6
40374- 46 46 46 246 246 246 253 253 253 253 253 253
40375-253 253 253 253 253 253 253 253 253 253 253 253
40376-253 253 253 253 253 253 253 253 253 253 253 253
40377-253 253 253 253 253 253 253 253 253 253 253 253
40378-253 253 253 221 221 221 86 86 86 156 107 11
40379-216 158 10 236 178 12 242 186 14 246 186 14
40380-242 186 14 239 182 13 239 182 13 242 186 14
40381-242 186 14 246 186 14 246 190 14 246 190 14
40382-246 190 14 246 190 14 246 190 14 246 190 14
40383-242 186 14 225 175 15 142 122 72 66 66 66
40384- 30 30 30 10 10 10 0 0 0 0 0 0
40385- 0 0 0 0 0 0 0 0 0 0 0 0
40386- 0 0 0 0 0 0 0 0 0 0 0 0
40387- 0 0 0 0 0 0 0 0 0 6 6 6
40388- 26 26 26 70 70 70 163 133 67 210 150 10
40389-236 178 12 246 190 14 246 190 14 246 190 14
40390-246 190 14 246 190 14 246 190 14 246 190 14
40391-246 190 14 246 190 14 246 190 14 246 190 14
40392-246 190 14 246 190 14 246 190 14 246 190 14
40393-232 195 16 121 92 8 34 34 34 106 106 106
40394-221 221 221 253 253 253 253 253 253 253 253 253
40395-253 253 253 253 253 253 253 253 253 253 253 253
40396-253 253 253 253 253 253 253 253 253 253 253 253
40397-253 253 253 253 253 253 253 253 253 253 253 253
40398-242 242 242 82 82 82 18 14 6 163 110 8
40399-216 158 10 236 178 12 242 186 14 246 190 14
40400-246 190 14 246 190 14 246 190 14 246 190 14
40401-246 190 14 246 190 14 246 190 14 246 190 14
40402-246 190 14 246 190 14 246 190 14 246 190 14
40403-246 190 14 246 190 14 242 186 14 163 133 67
40404- 46 46 46 18 18 18 6 6 6 0 0 0
40405- 0 0 0 0 0 0 0 0 0 0 0 0
40406- 0 0 0 0 0 0 0 0 0 0 0 0
40407- 0 0 0 0 0 0 0 0 0 10 10 10
40408- 30 30 30 78 78 78 163 133 67 210 150 10
40409-236 178 12 246 186 14 246 190 14 246 190 14
40410-246 190 14 246 190 14 246 190 14 246 190 14
40411-246 190 14 246 190 14 246 190 14 246 190 14
40412-246 190 14 246 190 14 246 190 14 246 190 14
40413-241 196 14 215 174 15 190 178 144 253 253 253
40414-253 253 253 253 253 253 253 253 253 253 253 253
40415-253 253 253 253 253 253 253 253 253 253 253 253
40416-253 253 253 253 253 253 253 253 253 253 253 253
40417-253 253 253 253 253 253 253 253 253 218 218 218
40418- 58 58 58 2 2 6 22 18 6 167 114 7
40419-216 158 10 236 178 12 246 186 14 246 190 14
40420-246 190 14 246 190 14 246 190 14 246 190 14
40421-246 190 14 246 190 14 246 190 14 246 190 14
40422-246 190 14 246 190 14 246 190 14 246 190 14
40423-246 190 14 246 186 14 242 186 14 190 150 46
40424- 54 54 54 22 22 22 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 14 14 14
40428- 38 38 38 86 86 86 180 133 36 213 154 11
40429-236 178 12 246 186 14 246 190 14 246 190 14
40430-246 190 14 246 190 14 246 190 14 246 190 14
40431-246 190 14 246 190 14 246 190 14 246 190 14
40432-246 190 14 246 190 14 246 190 14 246 190 14
40433-246 190 14 232 195 16 190 146 13 214 214 214
40434-253 253 253 253 253 253 253 253 253 253 253 253
40435-253 253 253 253 253 253 253 253 253 253 253 253
40436-253 253 253 253 253 253 253 253 253 253 253 253
40437-253 253 253 250 250 250 170 170 170 26 26 26
40438- 2 2 6 2 2 6 37 26 9 163 110 8
40439-219 162 10 239 182 13 246 186 14 246 190 14
40440-246 190 14 246 190 14 246 190 14 246 190 14
40441-246 190 14 246 190 14 246 190 14 246 190 14
40442-246 190 14 246 190 14 246 190 14 246 190 14
40443-246 186 14 236 178 12 224 166 10 142 122 72
40444- 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
40448- 50 50 50 109 106 95 192 133 9 224 166 10
40449-242 186 14 246 190 14 246 190 14 246 190 14
40450-246 190 14 246 190 14 246 190 14 246 190 14
40451-246 190 14 246 190 14 246 190 14 246 190 14
40452-246 190 14 246 190 14 246 190 14 246 190 14
40453-242 186 14 226 184 13 210 162 10 142 110 46
40454-226 226 226 253 253 253 253 253 253 253 253 253
40455-253 253 253 253 253 253 253 253 253 253 253 253
40456-253 253 253 253 253 253 253 253 253 253 253 253
40457-198 198 198 66 66 66 2 2 6 2 2 6
40458- 2 2 6 2 2 6 50 34 6 156 107 11
40459-219 162 10 239 182 13 246 186 14 246 190 14
40460-246 190 14 246 190 14 246 190 14 246 190 14
40461-246 190 14 246 190 14 246 190 14 246 190 14
40462-246 190 14 246 190 14 246 190 14 242 186 14
40463-234 174 13 213 154 11 154 122 46 66 66 66
40464- 30 30 30 10 10 10 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 6 6 6 22 22 22
40468- 58 58 58 154 121 60 206 145 10 234 174 13
40469-242 186 14 246 186 14 246 190 14 246 190 14
40470-246 190 14 246 190 14 246 190 14 246 190 14
40471-246 190 14 246 190 14 246 190 14 246 190 14
40472-246 190 14 246 190 14 246 190 14 246 190 14
40473-246 186 14 236 178 12 210 162 10 163 110 8
40474- 61 42 6 138 138 138 218 218 218 250 250 250
40475-253 253 253 253 253 253 253 253 253 250 250 250
40476-242 242 242 210 210 210 144 144 144 66 66 66
40477- 6 6 6 2 2 6 2 2 6 2 2 6
40478- 2 2 6 2 2 6 61 42 6 163 110 8
40479-216 158 10 236 178 12 246 190 14 246 190 14
40480-246 190 14 246 190 14 246 190 14 246 190 14
40481-246 190 14 246 190 14 246 190 14 246 190 14
40482-246 190 14 239 182 13 230 174 11 216 158 10
40483-190 142 34 124 112 88 70 70 70 38 38 38
40484- 18 18 18 6 6 6 0 0 0 0 0 0
40485- 0 0 0 0 0 0 0 0 0 0 0 0
40486- 0 0 0 0 0 0 0 0 0 0 0 0
40487- 0 0 0 0 0 0 6 6 6 22 22 22
40488- 62 62 62 168 124 44 206 145 10 224 166 10
40489-236 178 12 239 182 13 242 186 14 242 186 14
40490-246 186 14 246 190 14 246 190 14 246 190 14
40491-246 190 14 246 190 14 246 190 14 246 190 14
40492-246 190 14 246 190 14 246 190 14 246 190 14
40493-246 190 14 236 178 12 216 158 10 175 118 6
40494- 80 54 7 2 2 6 6 6 6 30 30 30
40495- 54 54 54 62 62 62 50 50 50 38 38 38
40496- 14 14 14 2 2 6 2 2 6 2 2 6
40497- 2 2 6 2 2 6 2 2 6 2 2 6
40498- 2 2 6 6 6 6 80 54 7 167 114 7
40499-213 154 11 236 178 12 246 190 14 246 190 14
40500-246 190 14 246 190 14 246 190 14 246 190 14
40501-246 190 14 242 186 14 239 182 13 239 182 13
40502-230 174 11 210 150 10 174 135 50 124 112 88
40503- 82 82 82 54 54 54 34 34 34 18 18 18
40504- 6 6 6 0 0 0 0 0 0 0 0 0
40505- 0 0 0 0 0 0 0 0 0 0 0 0
40506- 0 0 0 0 0 0 0 0 0 0 0 0
40507- 0 0 0 0 0 0 6 6 6 18 18 18
40508- 50 50 50 158 118 36 192 133 9 200 144 11
40509-216 158 10 219 162 10 224 166 10 226 170 11
40510-230 174 11 236 178 12 239 182 13 239 182 13
40511-242 186 14 246 186 14 246 190 14 246 190 14
40512-246 190 14 246 190 14 246 190 14 246 190 14
40513-246 186 14 230 174 11 210 150 10 163 110 8
40514-104 69 6 10 10 10 2 2 6 2 2 6
40515- 2 2 6 2 2 6 2 2 6 2 2 6
40516- 2 2 6 2 2 6 2 2 6 2 2 6
40517- 2 2 6 2 2 6 2 2 6 2 2 6
40518- 2 2 6 6 6 6 91 60 6 167 114 7
40519-206 145 10 230 174 11 242 186 14 246 190 14
40520-246 190 14 246 190 14 246 186 14 242 186 14
40521-239 182 13 230 174 11 224 166 10 213 154 11
40522-180 133 36 124 112 88 86 86 86 58 58 58
40523- 38 38 38 22 22 22 10 10 10 6 6 6
40524- 0 0 0 0 0 0 0 0 0 0 0 0
40525- 0 0 0 0 0 0 0 0 0 0 0 0
40526- 0 0 0 0 0 0 0 0 0 0 0 0
40527- 0 0 0 0 0 0 0 0 0 14 14 14
40528- 34 34 34 70 70 70 138 110 50 158 118 36
40529-167 114 7 180 123 7 192 133 9 197 138 11
40530-200 144 11 206 145 10 213 154 11 219 162 10
40531-224 166 10 230 174 11 239 182 13 242 186 14
40532-246 186 14 246 186 14 246 186 14 246 186 14
40533-239 182 13 216 158 10 185 133 11 152 99 6
40534-104 69 6 18 14 6 2 2 6 2 2 6
40535- 2 2 6 2 2 6 2 2 6 2 2 6
40536- 2 2 6 2 2 6 2 2 6 2 2 6
40537- 2 2 6 2 2 6 2 2 6 2 2 6
40538- 2 2 6 6 6 6 80 54 7 152 99 6
40539-192 133 9 219 162 10 236 178 12 239 182 13
40540-246 186 14 242 186 14 239 182 13 236 178 12
40541-224 166 10 206 145 10 192 133 9 154 121 60
40542- 94 94 94 62 62 62 42 42 42 22 22 22
40543- 14 14 14 6 6 6 0 0 0 0 0 0
40544- 0 0 0 0 0 0 0 0 0 0 0 0
40545- 0 0 0 0 0 0 0 0 0 0 0 0
40546- 0 0 0 0 0 0 0 0 0 0 0 0
40547- 0 0 0 0 0 0 0 0 0 6 6 6
40548- 18 18 18 34 34 34 58 58 58 78 78 78
40549-101 98 89 124 112 88 142 110 46 156 107 11
40550-163 110 8 167 114 7 175 118 6 180 123 7
40551-185 133 11 197 138 11 210 150 10 219 162 10
40552-226 170 11 236 178 12 236 178 12 234 174 13
40553-219 162 10 197 138 11 163 110 8 130 83 6
40554- 91 60 6 10 10 10 2 2 6 2 2 6
40555- 18 18 18 38 38 38 38 38 38 38 38 38
40556- 38 38 38 38 38 38 38 38 38 38 38 38
40557- 38 38 38 38 38 38 26 26 26 2 2 6
40558- 2 2 6 6 6 6 70 47 6 137 92 6
40559-175 118 6 200 144 11 219 162 10 230 174 11
40560-234 174 13 230 174 11 219 162 10 210 150 10
40561-192 133 9 163 110 8 124 112 88 82 82 82
40562- 50 50 50 30 30 30 14 14 14 6 6 6
40563- 0 0 0 0 0 0 0 0 0 0 0 0
40564- 0 0 0 0 0 0 0 0 0 0 0 0
40565- 0 0 0 0 0 0 0 0 0 0 0 0
40566- 0 0 0 0 0 0 0 0 0 0 0 0
40567- 0 0 0 0 0 0 0 0 0 0 0 0
40568- 6 6 6 14 14 14 22 22 22 34 34 34
40569- 42 42 42 58 58 58 74 74 74 86 86 86
40570-101 98 89 122 102 70 130 98 46 121 87 25
40571-137 92 6 152 99 6 163 110 8 180 123 7
40572-185 133 11 197 138 11 206 145 10 200 144 11
40573-180 123 7 156 107 11 130 83 6 104 69 6
40574- 50 34 6 54 54 54 110 110 110 101 98 89
40575- 86 86 86 82 82 82 78 78 78 78 78 78
40576- 78 78 78 78 78 78 78 78 78 78 78 78
40577- 78 78 78 82 82 82 86 86 86 94 94 94
40578-106 106 106 101 101 101 86 66 34 124 80 6
40579-156 107 11 180 123 7 192 133 9 200 144 11
40580-206 145 10 200 144 11 192 133 9 175 118 6
40581-139 102 15 109 106 95 70 70 70 42 42 42
40582- 22 22 22 10 10 10 0 0 0 0 0 0
40583- 0 0 0 0 0 0 0 0 0 0 0 0
40584- 0 0 0 0 0 0 0 0 0 0 0 0
40585- 0 0 0 0 0 0 0 0 0 0 0 0
40586- 0 0 0 0 0 0 0 0 0 0 0 0
40587- 0 0 0 0 0 0 0 0 0 0 0 0
40588- 0 0 0 0 0 0 6 6 6 10 10 10
40589- 14 14 14 22 22 22 30 30 30 38 38 38
40590- 50 50 50 62 62 62 74 74 74 90 90 90
40591-101 98 89 112 100 78 121 87 25 124 80 6
40592-137 92 6 152 99 6 152 99 6 152 99 6
40593-138 86 6 124 80 6 98 70 6 86 66 30
40594-101 98 89 82 82 82 58 58 58 46 46 46
40595- 38 38 38 34 34 34 34 34 34 34 34 34
40596- 34 34 34 34 34 34 34 34 34 34 34 34
40597- 34 34 34 34 34 34 38 38 38 42 42 42
40598- 54 54 54 82 82 82 94 86 76 91 60 6
40599-134 86 6 156 107 11 167 114 7 175 118 6
40600-175 118 6 167 114 7 152 99 6 121 87 25
40601-101 98 89 62 62 62 34 34 34 18 18 18
40602- 6 6 6 0 0 0 0 0 0 0 0 0
40603- 0 0 0 0 0 0 0 0 0 0 0 0
40604- 0 0 0 0 0 0 0 0 0 0 0 0
40605- 0 0 0 0 0 0 0 0 0 0 0 0
40606- 0 0 0 0 0 0 0 0 0 0 0 0
40607- 0 0 0 0 0 0 0 0 0 0 0 0
40608- 0 0 0 0 0 0 0 0 0 0 0 0
40609- 0 0 0 6 6 6 6 6 6 10 10 10
40610- 18 18 18 22 22 22 30 30 30 42 42 42
40611- 50 50 50 66 66 66 86 86 86 101 98 89
40612-106 86 58 98 70 6 104 69 6 104 69 6
40613-104 69 6 91 60 6 82 62 34 90 90 90
40614- 62 62 62 38 38 38 22 22 22 14 14 14
40615- 10 10 10 10 10 10 10 10 10 10 10 10
40616- 10 10 10 10 10 10 6 6 6 10 10 10
40617- 10 10 10 10 10 10 10 10 10 14 14 14
40618- 22 22 22 42 42 42 70 70 70 89 81 66
40619- 80 54 7 104 69 6 124 80 6 137 92 6
40620-134 86 6 116 81 8 100 82 52 86 86 86
40621- 58 58 58 30 30 30 14 14 14 6 6 6
40622- 0 0 0 0 0 0 0 0 0 0 0 0
40623- 0 0 0 0 0 0 0 0 0 0 0 0
40624- 0 0 0 0 0 0 0 0 0 0 0 0
40625- 0 0 0 0 0 0 0 0 0 0 0 0
40626- 0 0 0 0 0 0 0 0 0 0 0 0
40627- 0 0 0 0 0 0 0 0 0 0 0 0
40628- 0 0 0 0 0 0 0 0 0 0 0 0
40629- 0 0 0 0 0 0 0 0 0 0 0 0
40630- 0 0 0 6 6 6 10 10 10 14 14 14
40631- 18 18 18 26 26 26 38 38 38 54 54 54
40632- 70 70 70 86 86 86 94 86 76 89 81 66
40633- 89 81 66 86 86 86 74 74 74 50 50 50
40634- 30 30 30 14 14 14 6 6 6 0 0 0
40635- 0 0 0 0 0 0 0 0 0 0 0 0
40636- 0 0 0 0 0 0 0 0 0 0 0 0
40637- 0 0 0 0 0 0 0 0 0 0 0 0
40638- 6 6 6 18 18 18 34 34 34 58 58 58
40639- 82 82 82 89 81 66 89 81 66 89 81 66
40640- 94 86 66 94 86 76 74 74 74 50 50 50
40641- 26 26 26 14 14 14 6 6 6 0 0 0
40642- 0 0 0 0 0 0 0 0 0 0 0 0
40643- 0 0 0 0 0 0 0 0 0 0 0 0
40644- 0 0 0 0 0 0 0 0 0 0 0 0
40645- 0 0 0 0 0 0 0 0 0 0 0 0
40646- 0 0 0 0 0 0 0 0 0 0 0 0
40647- 0 0 0 0 0 0 0 0 0 0 0 0
40648- 0 0 0 0 0 0 0 0 0 0 0 0
40649- 0 0 0 0 0 0 0 0 0 0 0 0
40650- 0 0 0 0 0 0 0 0 0 0 0 0
40651- 6 6 6 6 6 6 14 14 14 18 18 18
40652- 30 30 30 38 38 38 46 46 46 54 54 54
40653- 50 50 50 42 42 42 30 30 30 18 18 18
40654- 10 10 10 0 0 0 0 0 0 0 0 0
40655- 0 0 0 0 0 0 0 0 0 0 0 0
40656- 0 0 0 0 0 0 0 0 0 0 0 0
40657- 0 0 0 0 0 0 0 0 0 0 0 0
40658- 0 0 0 6 6 6 14 14 14 26 26 26
40659- 38 38 38 50 50 50 58 58 58 58 58 58
40660- 54 54 54 42 42 42 30 30 30 18 18 18
40661- 10 10 10 0 0 0 0 0 0 0 0 0
40662- 0 0 0 0 0 0 0 0 0 0 0 0
40663- 0 0 0 0 0 0 0 0 0 0 0 0
40664- 0 0 0 0 0 0 0 0 0 0 0 0
40665- 0 0 0 0 0 0 0 0 0 0 0 0
40666- 0 0 0 0 0 0 0 0 0 0 0 0
40667- 0 0 0 0 0 0 0 0 0 0 0 0
40668- 0 0 0 0 0 0 0 0 0 0 0 0
40669- 0 0 0 0 0 0 0 0 0 0 0 0
40670- 0 0 0 0 0 0 0 0 0 0 0 0
40671- 0 0 0 0 0 0 0 0 0 6 6 6
40672- 6 6 6 10 10 10 14 14 14 18 18 18
40673- 18 18 18 14 14 14 10 10 10 6 6 6
40674- 0 0 0 0 0 0 0 0 0 0 0 0
40675- 0 0 0 0 0 0 0 0 0 0 0 0
40676- 0 0 0 0 0 0 0 0 0 0 0 0
40677- 0 0 0 0 0 0 0 0 0 0 0 0
40678- 0 0 0 0 0 0 0 0 0 6 6 6
40679- 14 14 14 18 18 18 22 22 22 22 22 22
40680- 18 18 18 14 14 14 10 10 10 6 6 6
40681- 0 0 0 0 0 0 0 0 0 0 0 0
40682- 0 0 0 0 0 0 0 0 0 0 0 0
40683- 0 0 0 0 0 0 0 0 0 0 0 0
40684- 0 0 0 0 0 0 0 0 0 0 0 0
40685- 0 0 0 0 0 0 0 0 0 0 0 0
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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
40702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40727+4 4 4 4 4 4
40728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40741+4 4 4 4 4 4
40742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40755+4 4 4 4 4 4
40756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40769+4 4 4 4 4 4
40770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40774+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40775+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40779+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40780+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40781+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40783+4 4 4 4 4 4
40784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40788+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40789+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40790+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40793+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40794+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40795+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40796+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40797+4 4 4 4 4 4
40798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40802+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40803+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40804+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40807+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40808+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40809+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40810+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40811+4 4 4 4 4 4
40812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40815+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40816+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40817+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40818+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40820+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40821+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40822+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40823+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40824+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40825+4 4 4 4 4 4
40826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40829+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40830+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40831+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40832+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40833+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40834+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40835+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40836+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40837+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40838+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40839+4 4 4 4 4 4
40840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40843+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40844+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40845+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40846+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40847+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40848+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40849+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40850+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40851+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40852+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40853+4 4 4 4 4 4
40854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40856+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40857+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40858+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40859+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40860+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40861+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40862+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40863+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40864+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40865+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40866+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40867+4 4 4 4 4 4
40868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40870+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40871+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40872+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40873+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40874+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40875+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40876+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40877+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40878+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40879+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40880+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40881+4 4 4 4 4 4
40882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40884+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40885+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40886+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40887+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40888+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40889+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40890+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40891+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40892+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40893+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40894+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40895+4 4 4 4 4 4
40896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40898+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40899+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40900+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40901+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40902+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40903+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40904+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40905+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40906+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40907+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40908+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40909+4 4 4 4 4 4
40910+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40911+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40912+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40913+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40914+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40915+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40916+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40917+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40918+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40919+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40920+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40921+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40922+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40923+4 4 4 4 4 4
40924+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40925+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40926+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40927+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40928+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40929+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40930+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40931+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40932+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40933+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40934+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40935+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40936+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40937+0 0 0 4 4 4
40938+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40939+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40940+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40941+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40942+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40943+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40944+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40945+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40946+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40947+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40948+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40949+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40950+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40951+2 0 0 0 0 0
40952+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40953+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40954+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40955+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40956+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40957+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40958+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40959+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40960+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40961+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40962+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40963+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40964+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40965+37 38 37 0 0 0
40966+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40967+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40968+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40969+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40970+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40971+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40972+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40973+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40974+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40975+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40976+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40977+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40978+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40979+85 115 134 4 0 0
40980+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40981+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40982+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40983+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40984+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40985+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40986+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40987+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40988+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40989+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40990+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40991+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40992+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40993+60 73 81 4 0 0
40994+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40995+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40996+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40997+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40998+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40999+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41000+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41001+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41002+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41003+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41004+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41005+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41006+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41007+16 19 21 4 0 0
41008+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41009+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41010+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41011+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41012+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41013+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41014+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41015+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41016+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41017+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41018+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41019+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41020+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41021+4 0 0 4 3 3
41022+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41023+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41024+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41026+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41027+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41028+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41029+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41030+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41031+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41032+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41033+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41034+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41035+3 2 2 4 4 4
41036+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41037+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41038+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41039+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41040+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41041+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41042+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41043+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41044+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41045+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41046+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41047+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41048+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41049+4 4 4 4 4 4
41050+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41051+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41052+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41053+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41054+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41055+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41056+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41057+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41058+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41059+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41060+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41061+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41062+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41063+4 4 4 4 4 4
41064+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41065+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41066+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41067+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41068+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41069+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41070+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41071+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41072+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41073+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41074+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41075+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41076+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41077+5 5 5 5 5 5
41078+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41079+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41080+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41081+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41082+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41083+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41084+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41085+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41086+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41087+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41088+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41089+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41090+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41091+5 5 5 4 4 4
41092+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41093+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41094+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41095+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41096+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41097+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41098+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41099+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41100+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41101+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41102+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41103+4 0 0 4 0 0 5 5 5 5 5 5 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+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41107+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41108+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41109+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41110+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41111+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41112+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41113+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41114+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41115+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41116+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41117+3 3 3 5 5 5 6 6 6 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 41 54 63 137 136 137 153 152 153 137 136 137
41121+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41122+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41123+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41124+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41125+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41126+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41127+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41128+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41129+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41130+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41135+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41136+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41137+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41138+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41139+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41140+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41141+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41142+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41143+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41144+6 6 6 4 0 0 4 0 0 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 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41149+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41150+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41151+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41152+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41153+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41154+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41155+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41156+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41157+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41158+4 0 0 4 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+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41163+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41164+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41165+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41166+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41167+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41168+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41169+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41170+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41171+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41172+6 6 6 4 0 0 6 6 6 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 41 54 63 163 162 163 166 165 166 154 154 154
41177+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41178+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41179+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41180+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41181+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41182+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41183+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41184+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41185+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41186+4 0 0 3 2 2 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+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41191+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41192+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41193+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41194+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41195+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41196+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41197+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41198+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41199+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41200+4 0 0 4 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 167 166 167 174 174 174 163 162 163
41205+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41206+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41207+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41208+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41209+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41210+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41211+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41212+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41213+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41214+4 0 0 4 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+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41219+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41220+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41221+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41222+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41223+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41224+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41225+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41226+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41227+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41228+4 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+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41233+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41234+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41235+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41236+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41237+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41238+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41239+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41240+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41241+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
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+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41247+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41248+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41249+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41250+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41251+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41252+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41253+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41254+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41255+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41256+0 0 0 3 3 3 5 5 5 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+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41261+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41262+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41263+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41264+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41265+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41266+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41267+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41268+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41269+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41270+0 0 0 3 3 3 5 5 5 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+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41275+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41276+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41277+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41278+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41279+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41280+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41281+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41282+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41283+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41284+0 0 0 3 3 3 5 5 5 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+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41289+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41290+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41291+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41292+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41293+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41294+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41295+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41296+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41297+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41298+0 0 0 3 3 3 5 5 5 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+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41303+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41304+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41305+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41306+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41307+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41308+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41309+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41310+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41311+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41312+0 0 0 3 3 3 5 5 5 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+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41317+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41318+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41319+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41320+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41321+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41322+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41323+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41324+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41325+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41326+0 0 0 3 3 3 5 5 5 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+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41331+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41332+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41333+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41334+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41335+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41336+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41337+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41338+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41339+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41340+0 0 0 3 3 3 5 5 5 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 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41345+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41346+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41347+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41348+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41349+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41350+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41351+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41352+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41353+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41354+0 0 0 3 3 3 5 5 5 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+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41359+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41360+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41361+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41362+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41363+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41364+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41365+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41366+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41367+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41368+0 0 0 3 3 3 5 5 5 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 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41373+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41374+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41375+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41376+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41377+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41378+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41379+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41380+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41381+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41382+0 0 0 3 3 3 5 5 5 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 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41387+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41388+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41389+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41390+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41391+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41392+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41393+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41394+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41395+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41396+0 0 0 3 3 3 5 5 5 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 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41401+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41402+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41403+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41404+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41405+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41406+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41407+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41408+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41409+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41410+0 0 0 3 3 3 5 5 5 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 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41415+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41416+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41417+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41418+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41419+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41420+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41421+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41422+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41423+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41424+0 0 0 3 3 3 5 5 5 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 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41429+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41430+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41431+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41432+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41433+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41434+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41435+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41436+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41437+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41438+0 0 0 3 3 3 5 5 5 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 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41443+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41444+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41445+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41446+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41447+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41448+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41449+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41450+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41451+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41452+0 0 0 3 3 3 5 5 5 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 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41457+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41458+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41459+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41460+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41461+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41462+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41463+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41464+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41465+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41466+0 0 0 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+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41471+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41472+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41473+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41474+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41475+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41476+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41477+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41478+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41479+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41480+4 3 3 5 5 5 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 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41485+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41486+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41487+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41488+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41489+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41490+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41491+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41492+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41493+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41494+5 5 5 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+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41499+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41500+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41501+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41502+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41503+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41504+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41505+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41506+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41507+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41513+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41514+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41515+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41516+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41517+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41518+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41519+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41520+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41521+13 16 17 4 0 0 4 0 0 4 3 3 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+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41527+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41528+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41529+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41530+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41531+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41532+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41533+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41534+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41535+4 0 0 4 0 0 5 5 5 5 5 5 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+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41541+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41542+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41543+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41544+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41545+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41546+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41547+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41548+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41549+4 3 3 5 5 5 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 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41555+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41556+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41557+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41558+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41559+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41560+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41561+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41562+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41569+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41570+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41571+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41572+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41573+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41574+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41575+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41576+4 0 0 4 0 0 4 0 0 6 6 6 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 5 5 5 4 3 3 5 5 5 6 6 6
41583+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41584+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41585+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41586+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41587+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41588+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41589+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41590+4 0 0 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
41596+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41597+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41598+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41599+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41600+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41601+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41602+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41603+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41609+4 4 4 4 4 4
41610+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41611+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41612+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41613+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41614+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41615+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41616+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41617+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41623+4 4 4 4 4 4
41624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41625+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41626+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41627+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41628+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41629+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41630+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41631+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41637+4 4 4 4 4 4
41638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41639+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41640+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41641+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41642+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41643+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41644+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41645+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41651+4 4 4 4 4 4
41652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41653+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41654+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41655+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41656+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41657+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41658+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41659+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41665+4 4 4 4 4 4
41666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41668+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41669+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41670+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41671+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41672+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41673+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41679+4 4 4 4 4 4
41680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41683+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41684+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41685+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41686+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41693+4 4 4 4 4 4
41694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41697+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41698+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41699+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41700+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41707+4 4 4 4 4 4
41708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41711+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41712+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41713+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41714+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41721+4 4 4 4 4 4
41722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41725+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41726+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41727+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41728+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41735+4 4 4 4 4 4
41736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41740+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41741+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41742+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41749+4 4 4 4 4 4
41750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41754+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41755+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41756+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41763+4 4 4 4 4 4
41764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41768+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41769+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41770+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41777+4 4 4 4 4 4
41778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41782+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41783+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41791+4 4 4 4 4 4
41792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41796+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41797+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41805+4 4 4 4 4 4
41806diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41807index 8af6414..658c030 100644
41808--- a/drivers/video/udlfb.c
41809+++ b/drivers/video/udlfb.c
41810@@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41811 dlfb_urb_completion(urb);
41812
41813 error:
41814- atomic_add(bytes_sent, &dev->bytes_sent);
41815- atomic_add(bytes_identical, &dev->bytes_identical);
41816- atomic_add(width*height*2, &dev->bytes_rendered);
41817+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41818+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41819+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41820 end_cycles = get_cycles();
41821- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41822+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41823 >> 10)), /* Kcycles */
41824 &dev->cpu_kcycles_used);
41825
41826@@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41827 dlfb_urb_completion(urb);
41828
41829 error:
41830- atomic_add(bytes_sent, &dev->bytes_sent);
41831- atomic_add(bytes_identical, &dev->bytes_identical);
41832- atomic_add(bytes_rendered, &dev->bytes_rendered);
41833+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41834+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41835+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41836 end_cycles = get_cycles();
41837- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41838+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41839 >> 10)), /* Kcycles */
41840 &dev->cpu_kcycles_used);
41841 }
41842@@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41843 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41844 struct dlfb_data *dev = fb_info->par;
41845 return snprintf(buf, PAGE_SIZE, "%u\n",
41846- atomic_read(&dev->bytes_rendered));
41847+ atomic_read_unchecked(&dev->bytes_rendered));
41848 }
41849
41850 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41851@@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41852 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41853 struct dlfb_data *dev = fb_info->par;
41854 return snprintf(buf, PAGE_SIZE, "%u\n",
41855- atomic_read(&dev->bytes_identical));
41856+ atomic_read_unchecked(&dev->bytes_identical));
41857 }
41858
41859 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41860@@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41861 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41862 struct dlfb_data *dev = fb_info->par;
41863 return snprintf(buf, PAGE_SIZE, "%u\n",
41864- atomic_read(&dev->bytes_sent));
41865+ atomic_read_unchecked(&dev->bytes_sent));
41866 }
41867
41868 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41869@@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41870 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41871 struct dlfb_data *dev = fb_info->par;
41872 return snprintf(buf, PAGE_SIZE, "%u\n",
41873- atomic_read(&dev->cpu_kcycles_used));
41874+ atomic_read_unchecked(&dev->cpu_kcycles_used));
41875 }
41876
41877 static ssize_t edid_show(
41878@@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41879 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41880 struct dlfb_data *dev = fb_info->par;
41881
41882- atomic_set(&dev->bytes_rendered, 0);
41883- atomic_set(&dev->bytes_identical, 0);
41884- atomic_set(&dev->bytes_sent, 0);
41885- atomic_set(&dev->cpu_kcycles_used, 0);
41886+ atomic_set_unchecked(&dev->bytes_rendered, 0);
41887+ atomic_set_unchecked(&dev->bytes_identical, 0);
41888+ atomic_set_unchecked(&dev->bytes_sent, 0);
41889+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41890
41891 return count;
41892 }
41893diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41894index b0e2a42..e2df3ad 100644
41895--- a/drivers/video/uvesafb.c
41896+++ b/drivers/video/uvesafb.c
41897@@ -19,6 +19,7 @@
41898 #include <linux/io.h>
41899 #include <linux/mutex.h>
41900 #include <linux/slab.h>
41901+#include <linux/moduleloader.h>
41902 #include <video/edid.h>
41903 #include <video/uvesafb.h>
41904 #ifdef CONFIG_X86
41905@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41906 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41907 par->pmi_setpal = par->ypan = 0;
41908 } else {
41909+
41910+#ifdef CONFIG_PAX_KERNEXEC
41911+#ifdef CONFIG_MODULES
41912+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41913+#endif
41914+ if (!par->pmi_code) {
41915+ par->pmi_setpal = par->ypan = 0;
41916+ return 0;
41917+ }
41918+#endif
41919+
41920 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41921 + task->t.regs.edi);
41922+
41923+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41924+ pax_open_kernel();
41925+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41926+ pax_close_kernel();
41927+
41928+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41929+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41930+#else
41931 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41932 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41933+#endif
41934+
41935 printk(KERN_INFO "uvesafb: protected mode interface info at "
41936 "%04x:%04x\n",
41937 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41938@@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
41939 par->ypan = ypan;
41940
41941 if (par->pmi_setpal || par->ypan) {
41942+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
41943 if (__supported_pte_mask & _PAGE_NX) {
41944 par->pmi_setpal = par->ypan = 0;
41945 printk(KERN_WARNING "uvesafb: NX protection is actively."
41946 "We have better not to use the PMI.\n");
41947- } else {
41948+ } else
41949+#endif
41950 uvesafb_vbe_getpmi(task, par);
41951- }
41952 }
41953 #else
41954 /* The protected mode interface is not available on non-x86. */
41955@@ -1836,6 +1860,11 @@ out:
41956 if (par->vbe_modes)
41957 kfree(par->vbe_modes);
41958
41959+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41960+ if (par->pmi_code)
41961+ module_free_exec(NULL, par->pmi_code);
41962+#endif
41963+
41964 framebuffer_release(info);
41965 return err;
41966 }
41967@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
41968 kfree(par->vbe_state_orig);
41969 if (par->vbe_state_saved)
41970 kfree(par->vbe_state_saved);
41971+
41972+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41973+ if (par->pmi_code)
41974+ module_free_exec(NULL, par->pmi_code);
41975+#endif
41976+
41977 }
41978
41979 framebuffer_release(info);
41980diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41981index 501b340..86bd4cf 100644
41982--- a/drivers/video/vesafb.c
41983+++ b/drivers/video/vesafb.c
41984@@ -9,6 +9,7 @@
41985 */
41986
41987 #include <linux/module.h>
41988+#include <linux/moduleloader.h>
41989 #include <linux/kernel.h>
41990 #include <linux/errno.h>
41991 #include <linux/string.h>
41992@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41993 static int vram_total __initdata; /* Set total amount of memory */
41994 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41995 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41996-static void (*pmi_start)(void) __read_mostly;
41997-static void (*pmi_pal) (void) __read_mostly;
41998+static void (*pmi_start)(void) __read_only;
41999+static void (*pmi_pal) (void) __read_only;
42000 static int depth __read_mostly;
42001 static int vga_compat __read_mostly;
42002 /* --------------------------------------------------------------------- */
42003@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42004 unsigned int size_vmode;
42005 unsigned int size_remap;
42006 unsigned int size_total;
42007+ void *pmi_code = NULL;
42008
42009 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42010 return -ENODEV;
42011@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42012 size_remap = size_total;
42013 vesafb_fix.smem_len = size_remap;
42014
42015-#ifndef __i386__
42016- screen_info.vesapm_seg = 0;
42017-#endif
42018-
42019 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42020 printk(KERN_WARNING
42021 "vesafb: cannot reserve video memory at 0x%lx\n",
42022@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42023 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42024 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42025
42026+#ifdef __i386__
42027+
42028+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42029+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
42030+ if (!pmi_code)
42031+#elif !defined(CONFIG_PAX_KERNEXEC)
42032+ if (0)
42033+#endif
42034+
42035+#endif
42036+ screen_info.vesapm_seg = 0;
42037+
42038 if (screen_info.vesapm_seg) {
42039- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42040- screen_info.vesapm_seg,screen_info.vesapm_off);
42041+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42042+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42043 }
42044
42045 if (screen_info.vesapm_seg < 0xc000)
42046@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42047
42048 if (ypan || pmi_setpal) {
42049 unsigned short *pmi_base;
42050+
42051 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42052- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42053- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42054+
42055+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42056+ pax_open_kernel();
42057+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42058+#else
42059+ pmi_code = pmi_base;
42060+#endif
42061+
42062+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42063+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42064+
42065+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42066+ pmi_start = ktva_ktla(pmi_start);
42067+ pmi_pal = ktva_ktla(pmi_pal);
42068+ pax_close_kernel();
42069+#endif
42070+
42071 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42072 if (pmi_base[3]) {
42073 printk(KERN_INFO "vesafb: pmi: ports = ");
42074@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42075 info->node, info->fix.id);
42076 return 0;
42077 err:
42078+
42079+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42080+ module_free_exec(NULL, pmi_code);
42081+#endif
42082+
42083 if (info->screen_base)
42084 iounmap(info->screen_base);
42085 framebuffer_release(info);
42086diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42087index 88714ae..16c2e11 100644
42088--- a/drivers/video/via/via_clock.h
42089+++ b/drivers/video/via/via_clock.h
42090@@ -56,7 +56,7 @@ struct via_clock {
42091
42092 void (*set_engine_pll_state)(u8 state);
42093 void (*set_engine_pll)(struct via_pll_config config);
42094-};
42095+} __no_const;
42096
42097
42098 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42099diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42100index e56c934..fc22f4b 100644
42101--- a/drivers/xen/xen-pciback/conf_space.h
42102+++ b/drivers/xen/xen-pciback/conf_space.h
42103@@ -44,15 +44,15 @@ struct config_field {
42104 struct {
42105 conf_dword_write write;
42106 conf_dword_read read;
42107- } dw;
42108+ } __no_const dw;
42109 struct {
42110 conf_word_write write;
42111 conf_word_read read;
42112- } w;
42113+ } __no_const w;
42114 struct {
42115 conf_byte_write write;
42116 conf_byte_read read;
42117- } b;
42118+ } __no_const b;
42119 } u;
42120 struct list_head list;
42121 };
42122diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42123index 57ccb75..f6d05f8 100644
42124--- a/fs/9p/vfs_inode.c
42125+++ b/fs/9p/vfs_inode.c
42126@@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42127 void
42128 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42129 {
42130- char *s = nd_get_link(nd);
42131+ const char *s = nd_get_link(nd);
42132
42133 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42134 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42135diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42136index 0225742..1cd4732 100644
42137--- a/fs/Kconfig.binfmt
42138+++ b/fs/Kconfig.binfmt
42139@@ -89,7 +89,7 @@ config HAVE_AOUT
42140
42141 config BINFMT_AOUT
42142 tristate "Kernel support for a.out and ECOFF binaries"
42143- depends on HAVE_AOUT
42144+ depends on HAVE_AOUT && BROKEN
42145 ---help---
42146 A.out (Assembler.OUTput) is a set of formats for libraries and
42147 executables used in the earliest versions of UNIX. Linux used
42148diff --git a/fs/aio.c b/fs/aio.c
42149index 55c4c76..11aee6f 100644
42150--- a/fs/aio.c
42151+++ b/fs/aio.c
42152@@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42153 size += sizeof(struct io_event) * nr_events;
42154 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42155
42156- if (nr_pages < 0)
42157+ if (nr_pages <= 0)
42158 return -EINVAL;
42159
42160 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42161@@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42162 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42163 {
42164 ssize_t ret;
42165+ struct iovec iovstack;
42166
42167 #ifdef CONFIG_COMPAT
42168 if (compat)
42169 ret = compat_rw_copy_check_uvector(type,
42170 (struct compat_iovec __user *)kiocb->ki_buf,
42171- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42172+ kiocb->ki_nbytes, 1, &iovstack,
42173 &kiocb->ki_iovec);
42174 else
42175 #endif
42176 ret = rw_copy_check_uvector(type,
42177 (struct iovec __user *)kiocb->ki_buf,
42178- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42179+ kiocb->ki_nbytes, 1, &iovstack,
42180 &kiocb->ki_iovec);
42181 if (ret < 0)
42182 goto out;
42183@@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42184 if (ret < 0)
42185 goto out;
42186
42187+ if (kiocb->ki_iovec == &iovstack) {
42188+ kiocb->ki_inline_vec = iovstack;
42189+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
42190+ }
42191 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42192 kiocb->ki_cur_seg = 0;
42193 /* ki_nbytes/left now reflect bytes instead of segs */
42194diff --git a/fs/attr.c b/fs/attr.c
42195index 0da9095..1386693 100644
42196--- a/fs/attr.c
42197+++ b/fs/attr.c
42198@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42199 unsigned long limit;
42200
42201 limit = rlimit(RLIMIT_FSIZE);
42202+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42203 if (limit != RLIM_INFINITY && offset > limit)
42204 goto out_sig;
42205 if (offset > inode->i_sb->s_maxbytes)
42206diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42207index da8876d..9f3e6d8 100644
42208--- a/fs/autofs4/waitq.c
42209+++ b/fs/autofs4/waitq.c
42210@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42211 {
42212 unsigned long sigpipe, flags;
42213 mm_segment_t fs;
42214- const char *data = (const char *)addr;
42215+ const char __user *data = (const char __force_user *)addr;
42216 ssize_t wr = 0;
42217
42218 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42219diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42220index e18da23..affc30e 100644
42221--- a/fs/befs/linuxvfs.c
42222+++ b/fs/befs/linuxvfs.c
42223@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42224 {
42225 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42226 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42227- char *link = nd_get_link(nd);
42228+ const char *link = nd_get_link(nd);
42229 if (!IS_ERR(link))
42230 kfree(link);
42231 }
42232diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42233index d146e18..12d1bd1 100644
42234--- a/fs/binfmt_aout.c
42235+++ b/fs/binfmt_aout.c
42236@@ -16,6 +16,7 @@
42237 #include <linux/string.h>
42238 #include <linux/fs.h>
42239 #include <linux/file.h>
42240+#include <linux/security.h>
42241 #include <linux/stat.h>
42242 #include <linux/fcntl.h>
42243 #include <linux/ptrace.h>
42244@@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42245 #endif
42246 # define START_STACK(u) ((void __user *)u.start_stack)
42247
42248+ memset(&dump, 0, sizeof(dump));
42249+
42250 fs = get_fs();
42251 set_fs(KERNEL_DS);
42252 has_dumped = 1;
42253@@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42254
42255 /* If the size of the dump file exceeds the rlimit, then see what would happen
42256 if we wrote the stack, but not the data area. */
42257+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42258 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42259 dump.u_dsize = 0;
42260
42261 /* Make sure we have enough room to write the stack and data areas. */
42262+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42263 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42264 dump.u_ssize = 0;
42265
42266@@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42267 rlim = rlimit(RLIMIT_DATA);
42268 if (rlim >= RLIM_INFINITY)
42269 rlim = ~0;
42270+
42271+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42272 if (ex.a_data + ex.a_bss > rlim)
42273 return -ENOMEM;
42274
42275@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42276
42277 install_exec_creds(bprm);
42278
42279+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42280+ current->mm->pax_flags = 0UL;
42281+#endif
42282+
42283+#ifdef CONFIG_PAX_PAGEEXEC
42284+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42285+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42286+
42287+#ifdef CONFIG_PAX_EMUTRAMP
42288+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42289+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42290+#endif
42291+
42292+#ifdef CONFIG_PAX_MPROTECT
42293+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42294+ current->mm->pax_flags |= MF_PAX_MPROTECT;
42295+#endif
42296+
42297+ }
42298+#endif
42299+
42300 if (N_MAGIC(ex) == OMAGIC) {
42301 unsigned long text_addr, map_size;
42302 loff_t pos;
42303@@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42304 }
42305
42306 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42307- PROT_READ | PROT_WRITE | PROT_EXEC,
42308+ PROT_READ | PROT_WRITE,
42309 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42310 fd_offset + ex.a_text);
42311 if (error != N_DATADDR(ex)) {
42312diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42313index 1b52956..271266e 100644
42314--- a/fs/binfmt_elf.c
42315+++ b/fs/binfmt_elf.c
42316@@ -32,6 +32,7 @@
42317 #include <linux/elf.h>
42318 #include <linux/utsname.h>
42319 #include <linux/coredump.h>
42320+#include <linux/xattr.h>
42321 #include <asm/uaccess.h>
42322 #include <asm/param.h>
42323 #include <asm/page.h>
42324@@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42325 #define elf_core_dump NULL
42326 #endif
42327
42328+#ifdef CONFIG_PAX_MPROTECT
42329+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42330+#endif
42331+
42332 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42333 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42334 #else
42335@@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42336 .load_binary = load_elf_binary,
42337 .load_shlib = load_elf_library,
42338 .core_dump = elf_core_dump,
42339+
42340+#ifdef CONFIG_PAX_MPROTECT
42341+ .handle_mprotect= elf_handle_mprotect,
42342+#endif
42343+
42344 .min_coredump = ELF_EXEC_PAGESIZE,
42345 };
42346
42347@@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42348
42349 static int set_brk(unsigned long start, unsigned long end)
42350 {
42351+ unsigned long e = end;
42352+
42353 start = ELF_PAGEALIGN(start);
42354 end = ELF_PAGEALIGN(end);
42355 if (end > start) {
42356@@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42357 if (BAD_ADDR(addr))
42358 return addr;
42359 }
42360- current->mm->start_brk = current->mm->brk = end;
42361+ current->mm->start_brk = current->mm->brk = e;
42362 return 0;
42363 }
42364
42365@@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42366 elf_addr_t __user *u_rand_bytes;
42367 const char *k_platform = ELF_PLATFORM;
42368 const char *k_base_platform = ELF_BASE_PLATFORM;
42369- unsigned char k_rand_bytes[16];
42370+ u32 k_rand_bytes[4];
42371 int items;
42372 elf_addr_t *elf_info;
42373 int ei_index = 0;
42374 const struct cred *cred = current_cred();
42375 struct vm_area_struct *vma;
42376+ unsigned long saved_auxv[AT_VECTOR_SIZE];
42377
42378 /*
42379 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42380@@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42381 * Generate 16 random bytes for userspace PRNG seeding.
42382 */
42383 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42384- u_rand_bytes = (elf_addr_t __user *)
42385- STACK_ALLOC(p, sizeof(k_rand_bytes));
42386+ srandom32(k_rand_bytes[0] ^ random32());
42387+ srandom32(k_rand_bytes[1] ^ random32());
42388+ srandom32(k_rand_bytes[2] ^ random32());
42389+ srandom32(k_rand_bytes[3] ^ random32());
42390+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
42391+ u_rand_bytes = (elf_addr_t __user *) p;
42392 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42393 return -EFAULT;
42394
42395@@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42396 return -EFAULT;
42397 current->mm->env_end = p;
42398
42399+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42400+
42401 /* Put the elf_info on the stack in the right place. */
42402 sp = (elf_addr_t __user *)envp + 1;
42403- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42404+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42405 return -EFAULT;
42406 return 0;
42407 }
42408@@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42409 {
42410 struct elf_phdr *elf_phdata;
42411 struct elf_phdr *eppnt;
42412- unsigned long load_addr = 0;
42413+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42414 int load_addr_set = 0;
42415 unsigned long last_bss = 0, elf_bss = 0;
42416- unsigned long error = ~0UL;
42417+ unsigned long error = -EINVAL;
42418 unsigned long total_size;
42419 int retval, i, size;
42420
42421@@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42422 goto out_close;
42423 }
42424
42425+#ifdef CONFIG_PAX_SEGMEXEC
42426+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42427+ pax_task_size = SEGMEXEC_TASK_SIZE;
42428+#endif
42429+
42430 eppnt = elf_phdata;
42431 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42432 if (eppnt->p_type == PT_LOAD) {
42433@@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42434 k = load_addr + eppnt->p_vaddr;
42435 if (BAD_ADDR(k) ||
42436 eppnt->p_filesz > eppnt->p_memsz ||
42437- eppnt->p_memsz > TASK_SIZE ||
42438- TASK_SIZE - eppnt->p_memsz < k) {
42439+ eppnt->p_memsz > pax_task_size ||
42440+ pax_task_size - eppnt->p_memsz < k) {
42441 error = -ENOMEM;
42442 goto out_close;
42443 }
42444@@ -523,6 +547,311 @@ out:
42445 return error;
42446 }
42447
42448+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42449+#ifdef CONFIG_PAX_SOFTMODE
42450+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42451+{
42452+ unsigned long pax_flags = 0UL;
42453+
42454+#ifdef CONFIG_PAX_PAGEEXEC
42455+ if (elf_phdata->p_flags & PF_PAGEEXEC)
42456+ pax_flags |= MF_PAX_PAGEEXEC;
42457+#endif
42458+
42459+#ifdef CONFIG_PAX_SEGMEXEC
42460+ if (elf_phdata->p_flags & PF_SEGMEXEC)
42461+ pax_flags |= MF_PAX_SEGMEXEC;
42462+#endif
42463+
42464+#ifdef CONFIG_PAX_EMUTRAMP
42465+ if (elf_phdata->p_flags & PF_EMUTRAMP)
42466+ pax_flags |= MF_PAX_EMUTRAMP;
42467+#endif
42468+
42469+#ifdef CONFIG_PAX_MPROTECT
42470+ if (elf_phdata->p_flags & PF_MPROTECT)
42471+ pax_flags |= MF_PAX_MPROTECT;
42472+#endif
42473+
42474+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42475+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42476+ pax_flags |= MF_PAX_RANDMMAP;
42477+#endif
42478+
42479+ return pax_flags;
42480+}
42481+#endif
42482+
42483+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42484+{
42485+ unsigned long pax_flags = 0UL;
42486+
42487+#ifdef CONFIG_PAX_PAGEEXEC
42488+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42489+ pax_flags |= MF_PAX_PAGEEXEC;
42490+#endif
42491+
42492+#ifdef CONFIG_PAX_SEGMEXEC
42493+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42494+ pax_flags |= MF_PAX_SEGMEXEC;
42495+#endif
42496+
42497+#ifdef CONFIG_PAX_EMUTRAMP
42498+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42499+ pax_flags |= MF_PAX_EMUTRAMP;
42500+#endif
42501+
42502+#ifdef CONFIG_PAX_MPROTECT
42503+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42504+ pax_flags |= MF_PAX_MPROTECT;
42505+#endif
42506+
42507+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42508+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42509+ pax_flags |= MF_PAX_RANDMMAP;
42510+#endif
42511+
42512+ return pax_flags;
42513+}
42514+#endif
42515+
42516+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42517+#ifdef CONFIG_PAX_SOFTMODE
42518+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42519+{
42520+ unsigned long pax_flags = 0UL;
42521+
42522+#ifdef CONFIG_PAX_PAGEEXEC
42523+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42524+ pax_flags |= MF_PAX_PAGEEXEC;
42525+#endif
42526+
42527+#ifdef CONFIG_PAX_SEGMEXEC
42528+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42529+ pax_flags |= MF_PAX_SEGMEXEC;
42530+#endif
42531+
42532+#ifdef CONFIG_PAX_EMUTRAMP
42533+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42534+ pax_flags |= MF_PAX_EMUTRAMP;
42535+#endif
42536+
42537+#ifdef CONFIG_PAX_MPROTECT
42538+ if (pax_flags_softmode & MF_PAX_MPROTECT)
42539+ pax_flags |= MF_PAX_MPROTECT;
42540+#endif
42541+
42542+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42543+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42544+ pax_flags |= MF_PAX_RANDMMAP;
42545+#endif
42546+
42547+ return pax_flags;
42548+}
42549+#endif
42550+
42551+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42552+{
42553+ unsigned long pax_flags = 0UL;
42554+
42555+#ifdef CONFIG_PAX_PAGEEXEC
42556+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42557+ pax_flags |= MF_PAX_PAGEEXEC;
42558+#endif
42559+
42560+#ifdef CONFIG_PAX_SEGMEXEC
42561+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42562+ pax_flags |= MF_PAX_SEGMEXEC;
42563+#endif
42564+
42565+#ifdef CONFIG_PAX_EMUTRAMP
42566+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42567+ pax_flags |= MF_PAX_EMUTRAMP;
42568+#endif
42569+
42570+#ifdef CONFIG_PAX_MPROTECT
42571+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42572+ pax_flags |= MF_PAX_MPROTECT;
42573+#endif
42574+
42575+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42576+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42577+ pax_flags |= MF_PAX_RANDMMAP;
42578+#endif
42579+
42580+ return pax_flags;
42581+}
42582+#endif
42583+
42584+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42585+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42586+{
42587+ unsigned long pax_flags = 0UL;
42588+
42589+#ifdef CONFIG_PAX_EI_PAX
42590+
42591+#ifdef CONFIG_PAX_PAGEEXEC
42592+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42593+ pax_flags |= MF_PAX_PAGEEXEC;
42594+#endif
42595+
42596+#ifdef CONFIG_PAX_SEGMEXEC
42597+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42598+ pax_flags |= MF_PAX_SEGMEXEC;
42599+#endif
42600+
42601+#ifdef CONFIG_PAX_EMUTRAMP
42602+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42603+ pax_flags |= MF_PAX_EMUTRAMP;
42604+#endif
42605+
42606+#ifdef CONFIG_PAX_MPROTECT
42607+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42608+ pax_flags |= MF_PAX_MPROTECT;
42609+#endif
42610+
42611+#ifdef CONFIG_PAX_ASLR
42612+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42613+ pax_flags |= MF_PAX_RANDMMAP;
42614+#endif
42615+
42616+#else
42617+
42618+#ifdef CONFIG_PAX_PAGEEXEC
42619+ pax_flags |= MF_PAX_PAGEEXEC;
42620+#endif
42621+
42622+#ifdef CONFIG_PAX_SEGMEXEC
42623+ pax_flags |= MF_PAX_SEGMEXEC;
42624+#endif
42625+
42626+#ifdef CONFIG_PAX_MPROTECT
42627+ pax_flags |= MF_PAX_MPROTECT;
42628+#endif
42629+
42630+#ifdef CONFIG_PAX_RANDMMAP
42631+ if (randomize_va_space)
42632+ pax_flags |= MF_PAX_RANDMMAP;
42633+#endif
42634+
42635+#endif
42636+
42637+ return pax_flags;
42638+}
42639+
42640+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42641+{
42642+
42643+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42644+ unsigned long i;
42645+
42646+ for (i = 0UL; i < elf_ex->e_phnum; i++)
42647+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42648+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42649+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42650+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42651+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42652+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42653+ return ~0UL;
42654+
42655+#ifdef CONFIG_PAX_SOFTMODE
42656+ if (pax_softmode)
42657+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42658+ else
42659+#endif
42660+
42661+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42662+ break;
42663+ }
42664+#endif
42665+
42666+ return ~0UL;
42667+}
42668+
42669+static unsigned long pax_parse_xattr_pax(struct file * const file)
42670+{
42671+
42672+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42673+ ssize_t xattr_size, i;
42674+ unsigned char xattr_value[5];
42675+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42676+
42677+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42678+ if (xattr_size <= 0)
42679+ return ~0UL;
42680+
42681+ for (i = 0; i < xattr_size; i++)
42682+ switch (xattr_value[i]) {
42683+ default:
42684+ return ~0UL;
42685+
42686+#define parse_flag(option1, option2, flag) \
42687+ case option1: \
42688+ pax_flags_hardmode |= MF_PAX_##flag; \
42689+ break; \
42690+ case option2: \
42691+ pax_flags_softmode |= MF_PAX_##flag; \
42692+ break;
42693+
42694+ parse_flag('p', 'P', PAGEEXEC);
42695+ parse_flag('e', 'E', EMUTRAMP);
42696+ parse_flag('m', 'M', MPROTECT);
42697+ parse_flag('r', 'R', RANDMMAP);
42698+ parse_flag('s', 'S', SEGMEXEC);
42699+
42700+#undef parse_flag
42701+ }
42702+
42703+ if (pax_flags_hardmode & pax_flags_softmode)
42704+ return ~0UL;
42705+
42706+#ifdef CONFIG_PAX_SOFTMODE
42707+ if (pax_softmode)
42708+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42709+ else
42710+#endif
42711+
42712+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42713+#else
42714+ return ~0UL;
42715+#endif
42716+
42717+}
42718+
42719+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42720+{
42721+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42722+
42723+ pax_flags = pax_parse_ei_pax(elf_ex);
42724+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42725+ xattr_pax_flags = pax_parse_xattr_pax(file);
42726+
42727+ if (pt_pax_flags == ~0UL)
42728+ pt_pax_flags = xattr_pax_flags;
42729+ else if (xattr_pax_flags == ~0UL)
42730+ xattr_pax_flags = pt_pax_flags;
42731+ if (pt_pax_flags != xattr_pax_flags)
42732+ return -EINVAL;
42733+ if (pt_pax_flags != ~0UL)
42734+ pax_flags = pt_pax_flags;
42735+
42736+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42737+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42738+ if ((__supported_pte_mask & _PAGE_NX))
42739+ pax_flags &= ~MF_PAX_SEGMEXEC;
42740+ else
42741+ pax_flags &= ~MF_PAX_PAGEEXEC;
42742+ }
42743+#endif
42744+
42745+ if (0 > pax_check_flags(&pax_flags))
42746+ return -EINVAL;
42747+
42748+ current->mm->pax_flags = pax_flags;
42749+ return 0;
42750+}
42751+#endif
42752+
42753 /*
42754 * These are the functions used to load ELF style executables and shared
42755 * libraries. There is no binary dependent code anywhere else.
42756@@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42757 {
42758 unsigned int random_variable = 0;
42759
42760+#ifdef CONFIG_PAX_RANDUSTACK
42761+ if (randomize_va_space)
42762+ return stack_top - current->mm->delta_stack;
42763+#endif
42764+
42765 if ((current->flags & PF_RANDOMIZE) &&
42766 !(current->personality & ADDR_NO_RANDOMIZE)) {
42767 random_variable = get_random_int() & STACK_RND_MASK;
42768@@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42769 unsigned long load_addr = 0, load_bias = 0;
42770 int load_addr_set = 0;
42771 char * elf_interpreter = NULL;
42772- unsigned long error;
42773+ unsigned long error = 0;
42774 struct elf_phdr *elf_ppnt, *elf_phdata;
42775 unsigned long elf_bss, elf_brk;
42776 int retval, i;
42777@@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42778 unsigned long start_code, end_code, start_data, end_data;
42779 unsigned long reloc_func_desc __maybe_unused = 0;
42780 int executable_stack = EXSTACK_DEFAULT;
42781- unsigned long def_flags = 0;
42782 struct {
42783 struct elfhdr elf_ex;
42784 struct elfhdr interp_elf_ex;
42785 } *loc;
42786+ unsigned long pax_task_size = TASK_SIZE;
42787
42788 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42789 if (!loc) {
42790@@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42791 goto out_free_dentry;
42792
42793 /* OK, This is the point of no return */
42794- current->mm->def_flags = def_flags;
42795+
42796+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42797+ current->mm->pax_flags = 0UL;
42798+#endif
42799+
42800+#ifdef CONFIG_PAX_DLRESOLVE
42801+ current->mm->call_dl_resolve = 0UL;
42802+#endif
42803+
42804+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42805+ current->mm->call_syscall = 0UL;
42806+#endif
42807+
42808+#ifdef CONFIG_PAX_ASLR
42809+ current->mm->delta_mmap = 0UL;
42810+ current->mm->delta_stack = 0UL;
42811+#endif
42812+
42813+ current->mm->def_flags = 0;
42814+
42815+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42816+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42817+ send_sig(SIGKILL, current, 0);
42818+ goto out_free_dentry;
42819+ }
42820+#endif
42821+
42822+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42823+ pax_set_initial_flags(bprm);
42824+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42825+ if (pax_set_initial_flags_func)
42826+ (pax_set_initial_flags_func)(bprm);
42827+#endif
42828+
42829+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42830+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42831+ current->mm->context.user_cs_limit = PAGE_SIZE;
42832+ current->mm->def_flags |= VM_PAGEEXEC;
42833+ }
42834+#endif
42835+
42836+#ifdef CONFIG_PAX_SEGMEXEC
42837+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42838+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42839+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42840+ pax_task_size = SEGMEXEC_TASK_SIZE;
42841+ current->mm->def_flags |= VM_NOHUGEPAGE;
42842+ }
42843+#endif
42844+
42845+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42846+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42847+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42848+ put_cpu();
42849+ }
42850+#endif
42851
42852 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42853 may depend on the personality. */
42854 SET_PERSONALITY(loc->elf_ex);
42855+
42856+#ifdef CONFIG_PAX_ASLR
42857+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42858+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42859+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42860+ }
42861+#endif
42862+
42863+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42864+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42865+ executable_stack = EXSTACK_DISABLE_X;
42866+ current->personality &= ~READ_IMPLIES_EXEC;
42867+ } else
42868+#endif
42869+
42870 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42871 current->personality |= READ_IMPLIES_EXEC;
42872
42873@@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42874 #else
42875 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42876 #endif
42877+
42878+#ifdef CONFIG_PAX_RANDMMAP
42879+ /* PaX: randomize base address at the default exe base if requested */
42880+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42881+#ifdef CONFIG_SPARC64
42882+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42883+#else
42884+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42885+#endif
42886+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42887+ elf_flags |= MAP_FIXED;
42888+ }
42889+#endif
42890+
42891 }
42892
42893 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42894@@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42895 * allowed task size. Note that p_filesz must always be
42896 * <= p_memsz so it is only necessary to check p_memsz.
42897 */
42898- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42899- elf_ppnt->p_memsz > TASK_SIZE ||
42900- TASK_SIZE - elf_ppnt->p_memsz < k) {
42901+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42902+ elf_ppnt->p_memsz > pax_task_size ||
42903+ pax_task_size - elf_ppnt->p_memsz < k) {
42904 /* set_brk can never work. Avoid overflows. */
42905 send_sig(SIGKILL, current, 0);
42906 retval = -EINVAL;
42907@@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42908 goto out_free_dentry;
42909 }
42910 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42911- send_sig(SIGSEGV, current, 0);
42912- retval = -EFAULT; /* Nobody gets to see this, but.. */
42913- goto out_free_dentry;
42914+ /*
42915+ * This bss-zeroing can fail if the ELF
42916+ * file specifies odd protections. So
42917+ * we don't check the return value
42918+ */
42919 }
42920
42921+#ifdef CONFIG_PAX_RANDMMAP
42922+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42923+ unsigned long start, size;
42924+
42925+ start = ELF_PAGEALIGN(elf_brk);
42926+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42927+ down_read(&current->mm->mmap_sem);
42928+ retval = -ENOMEM;
42929+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42930+ unsigned long prot = PROT_NONE;
42931+
42932+ up_read(&current->mm->mmap_sem);
42933+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42934+// if (current->personality & ADDR_NO_RANDOMIZE)
42935+// prot = PROT_READ;
42936+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42937+ retval = IS_ERR_VALUE(start) ? start : 0;
42938+ } else
42939+ up_read(&current->mm->mmap_sem);
42940+ if (retval == 0)
42941+ retval = set_brk(start + size, start + size + PAGE_SIZE);
42942+ if (retval < 0) {
42943+ send_sig(SIGKILL, current, 0);
42944+ goto out_free_dentry;
42945+ }
42946+ }
42947+#endif
42948+
42949 if (elf_interpreter) {
42950 unsigned long uninitialized_var(interp_map_addr);
42951
42952@@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
42953 * Decide what to dump of a segment, part, all or none.
42954 */
42955 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42956- unsigned long mm_flags)
42957+ unsigned long mm_flags, long signr)
42958 {
42959 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42960
42961@@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42962 if (vma->vm_file == NULL)
42963 return 0;
42964
42965- if (FILTER(MAPPED_PRIVATE))
42966+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42967 goto whole;
42968
42969 /*
42970@@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42971 {
42972 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42973 int i = 0;
42974- do
42975+ do {
42976 i += 2;
42977- while (auxv[i - 2] != AT_NULL);
42978+ } while (auxv[i - 2] != AT_NULL);
42979 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42980 }
42981
42982@@ -1890,14 +2338,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42983 }
42984
42985 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42986- unsigned long mm_flags)
42987+ struct coredump_params *cprm)
42988 {
42989 struct vm_area_struct *vma;
42990 size_t size = 0;
42991
42992 for (vma = first_vma(current, gate_vma); vma != NULL;
42993 vma = next_vma(vma, gate_vma))
42994- size += vma_dump_size(vma, mm_flags);
42995+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42996 return size;
42997 }
42998
42999@@ -1991,7 +2439,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43000
43001 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43002
43003- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43004+ offset += elf_core_vma_data_size(gate_vma, cprm);
43005 offset += elf_core_extra_data_size();
43006 e_shoff = offset;
43007
43008@@ -2005,10 +2453,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43009 offset = dataoff;
43010
43011 size += sizeof(*elf);
43012+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43013 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43014 goto end_coredump;
43015
43016 size += sizeof(*phdr4note);
43017+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43018 if (size > cprm->limit
43019 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43020 goto end_coredump;
43021@@ -2022,7 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43022 phdr.p_offset = offset;
43023 phdr.p_vaddr = vma->vm_start;
43024 phdr.p_paddr = 0;
43025- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43026+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43027 phdr.p_memsz = vma->vm_end - vma->vm_start;
43028 offset += phdr.p_filesz;
43029 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43030@@ -2033,6 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43031 phdr.p_align = ELF_EXEC_PAGESIZE;
43032
43033 size += sizeof(phdr);
43034+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43035 if (size > cprm->limit
43036 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43037 goto end_coredump;
43038@@ -2057,7 +2508,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43039 unsigned long addr;
43040 unsigned long end;
43041
43042- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43043+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43044
43045 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43046 struct page *page;
43047@@ -2066,6 +2517,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43048 page = get_dump_page(addr);
43049 if (page) {
43050 void *kaddr = kmap(page);
43051+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43052 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43053 !dump_write(cprm->file, kaddr,
43054 PAGE_SIZE);
43055@@ -2083,6 +2535,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43056
43057 if (e_phnum == PN_XNUM) {
43058 size += sizeof(*shdr4extnum);
43059+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43060 if (size > cprm->limit
43061 || !dump_write(cprm->file, shdr4extnum,
43062 sizeof(*shdr4extnum)))
43063@@ -2103,6 +2556,97 @@ out:
43064
43065 #endif /* CONFIG_ELF_CORE */
43066
43067+#ifdef CONFIG_PAX_MPROTECT
43068+/* PaX: non-PIC ELF libraries need relocations on their executable segments
43069+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43070+ * we'll remove VM_MAYWRITE for good on RELRO segments.
43071+ *
43072+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43073+ * basis because we want to allow the common case and not the special ones.
43074+ */
43075+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43076+{
43077+ struct elfhdr elf_h;
43078+ struct elf_phdr elf_p;
43079+ unsigned long i;
43080+ unsigned long oldflags;
43081+ bool is_textrel_rw, is_textrel_rx, is_relro;
43082+
43083+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43084+ return;
43085+
43086+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43087+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43088+
43089+#ifdef CONFIG_PAX_ELFRELOCS
43090+ /* possible TEXTREL */
43091+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43092+ 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);
43093+#else
43094+ is_textrel_rw = false;
43095+ is_textrel_rx = false;
43096+#endif
43097+
43098+ /* possible RELRO */
43099+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43100+
43101+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43102+ return;
43103+
43104+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43105+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43106+
43107+#ifdef CONFIG_PAX_ETEXECRELOCS
43108+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43109+#else
43110+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43111+#endif
43112+
43113+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43114+ !elf_check_arch(&elf_h) ||
43115+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43116+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43117+ return;
43118+
43119+ for (i = 0UL; i < elf_h.e_phnum; i++) {
43120+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43121+ return;
43122+ switch (elf_p.p_type) {
43123+ case PT_DYNAMIC:
43124+ if (!is_textrel_rw && !is_textrel_rx)
43125+ continue;
43126+ i = 0UL;
43127+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43128+ elf_dyn dyn;
43129+
43130+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43131+ return;
43132+ if (dyn.d_tag == DT_NULL)
43133+ return;
43134+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43135+ gr_log_textrel(vma);
43136+ if (is_textrel_rw)
43137+ vma->vm_flags |= VM_MAYWRITE;
43138+ else
43139+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43140+ vma->vm_flags &= ~VM_MAYWRITE;
43141+ return;
43142+ }
43143+ i++;
43144+ }
43145+ return;
43146+
43147+ case PT_GNU_RELRO:
43148+ if (!is_relro)
43149+ continue;
43150+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43151+ vma->vm_flags &= ~VM_MAYWRITE;
43152+ return;
43153+ }
43154+ }
43155+}
43156+#endif
43157+
43158 static int __init init_elf_binfmt(void)
43159 {
43160 register_binfmt(&elf_format);
43161diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43162index 178cb70..8972997 100644
43163--- a/fs/binfmt_flat.c
43164+++ b/fs/binfmt_flat.c
43165@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43166 realdatastart = (unsigned long) -ENOMEM;
43167 printk("Unable to allocate RAM for process data, errno %d\n",
43168 (int)-realdatastart);
43169+ down_write(&current->mm->mmap_sem);
43170 vm_munmap(textpos, text_len);
43171+ up_write(&current->mm->mmap_sem);
43172 ret = realdatastart;
43173 goto err;
43174 }
43175@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43176 }
43177 if (IS_ERR_VALUE(result)) {
43178 printk("Unable to read data+bss, errno %d\n", (int)-result);
43179+ down_write(&current->mm->mmap_sem);
43180 vm_munmap(textpos, text_len);
43181 vm_munmap(realdatastart, len);
43182+ up_write(&current->mm->mmap_sem);
43183 ret = result;
43184 goto err;
43185 }
43186@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43187 }
43188 if (IS_ERR_VALUE(result)) {
43189 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43190+ down_write(&current->mm->mmap_sem);
43191 vm_munmap(textpos, text_len + data_len + extra +
43192 MAX_SHARED_LIBS * sizeof(unsigned long));
43193+ up_write(&current->mm->mmap_sem);
43194 ret = result;
43195 goto err;
43196 }
43197diff --git a/fs/bio.c b/fs/bio.c
43198index 73922ab..16642dd 100644
43199--- a/fs/bio.c
43200+++ b/fs/bio.c
43201@@ -841,7 +841,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43202 /*
43203 * Overflow, abort
43204 */
43205- if (end < start)
43206+ if (end < start || end - start > INT_MAX - nr_pages)
43207 return ERR_PTR(-EINVAL);
43208
43209 nr_pages += end - start;
43210@@ -975,7 +975,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43211 /*
43212 * Overflow, abort
43213 */
43214- if (end < start)
43215+ if (end < start || end - start > INT_MAX - nr_pages)
43216 return ERR_PTR(-EINVAL);
43217
43218 nr_pages += end - start;
43219@@ -1237,7 +1237,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43220 const int read = bio_data_dir(bio) == READ;
43221 struct bio_map_data *bmd = bio->bi_private;
43222 int i;
43223- char *p = bmd->sgvecs[0].iov_base;
43224+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43225
43226 __bio_for_each_segment(bvec, bio, i, 0) {
43227 char *addr = page_address(bvec->bv_page);
43228diff --git a/fs/block_dev.c b/fs/block_dev.c
43229index c2bbe1f..9dfbc23 100644
43230--- a/fs/block_dev.c
43231+++ b/fs/block_dev.c
43232@@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43233 else if (bdev->bd_contains == bdev)
43234 return true; /* is a whole device which isn't held */
43235
43236- else if (whole->bd_holder == bd_may_claim)
43237+ else if (whole->bd_holder == (void *)bd_may_claim)
43238 return true; /* is a partition of a device that is being partitioned */
43239 else if (whole->bd_holder != NULL)
43240 return false; /* is a partition of a held device */
43241diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43242index da6e936..1598dd0 100644
43243--- a/fs/btrfs/check-integrity.c
43244+++ b/fs/btrfs/check-integrity.c
43245@@ -155,7 +155,7 @@ struct btrfsic_block {
43246 union {
43247 bio_end_io_t *bio;
43248 bh_end_io_t *bh;
43249- } orig_bio_bh_end_io;
43250+ } __no_const orig_bio_bh_end_io;
43251 int submit_bio_bh_rw;
43252 u64 flush_gen; /* only valid if !never_written */
43253 };
43254diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43255index 8206b39..06d5654 100644
43256--- a/fs/btrfs/ctree.c
43257+++ b/fs/btrfs/ctree.c
43258@@ -973,9 +973,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43259 free_extent_buffer(buf);
43260 add_root_to_dirty_list(root);
43261 } else {
43262- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43263- parent_start = parent->start;
43264- else
43265+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43266+ if (parent)
43267+ parent_start = parent->start;
43268+ else
43269+ parent_start = 0;
43270+ } else
43271 parent_start = 0;
43272
43273 WARN_ON(trans->transid != btrfs_header_generation(parent));
43274diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43275index a7d1921..a32dba2 100644
43276--- a/fs/btrfs/inode.c
43277+++ b/fs/btrfs/inode.c
43278@@ -7111,7 +7111,7 @@ fail:
43279 return -ENOMEM;
43280 }
43281
43282-static int btrfs_getattr(struct vfsmount *mnt,
43283+int btrfs_getattr(struct vfsmount *mnt,
43284 struct dentry *dentry, struct kstat *stat)
43285 {
43286 struct inode *inode = dentry->d_inode;
43287@@ -7125,6 +7125,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43288 return 0;
43289 }
43290
43291+EXPORT_SYMBOL(btrfs_getattr);
43292+
43293+dev_t get_btrfs_dev_from_inode(struct inode *inode)
43294+{
43295+ return BTRFS_I(inode)->root->anon_dev;
43296+}
43297+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43298+
43299 /*
43300 * If a file is moved, it will inherit the cow and compression flags of the new
43301 * directory.
43302diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43303index 0e92e57..8b560de 100644
43304--- a/fs/btrfs/ioctl.c
43305+++ b/fs/btrfs/ioctl.c
43306@@ -2902,9 +2902,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43307 for (i = 0; i < num_types; i++) {
43308 struct btrfs_space_info *tmp;
43309
43310+ /* Don't copy in more than we allocated */
43311 if (!slot_count)
43312 break;
43313
43314+ slot_count--;
43315+
43316 info = NULL;
43317 rcu_read_lock();
43318 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43319@@ -2926,10 +2929,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43320 memcpy(dest, &space, sizeof(space));
43321 dest++;
43322 space_args.total_spaces++;
43323- slot_count--;
43324 }
43325- if (!slot_count)
43326- break;
43327 }
43328 up_read(&info->groups_sem);
43329 }
43330diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43331index 646ee21..f020f87 100644
43332--- a/fs/btrfs/relocation.c
43333+++ b/fs/btrfs/relocation.c
43334@@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43335 }
43336 spin_unlock(&rc->reloc_root_tree.lock);
43337
43338- BUG_ON((struct btrfs_root *)node->data != root);
43339+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
43340
43341 if (!del) {
43342 spin_lock(&rc->reloc_root_tree.lock);
43343diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43344index 622f469..e8d2d55 100644
43345--- a/fs/cachefiles/bind.c
43346+++ b/fs/cachefiles/bind.c
43347@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43348 args);
43349
43350 /* start by checking things over */
43351- ASSERT(cache->fstop_percent >= 0 &&
43352- cache->fstop_percent < cache->fcull_percent &&
43353+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
43354 cache->fcull_percent < cache->frun_percent &&
43355 cache->frun_percent < 100);
43356
43357- ASSERT(cache->bstop_percent >= 0 &&
43358- cache->bstop_percent < cache->bcull_percent &&
43359+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
43360 cache->bcull_percent < cache->brun_percent &&
43361 cache->brun_percent < 100);
43362
43363diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43364index 0a1467b..6a53245 100644
43365--- a/fs/cachefiles/daemon.c
43366+++ b/fs/cachefiles/daemon.c
43367@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43368 if (n > buflen)
43369 return -EMSGSIZE;
43370
43371- if (copy_to_user(_buffer, buffer, n) != 0)
43372+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43373 return -EFAULT;
43374
43375 return n;
43376@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43377 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43378 return -EIO;
43379
43380- if (datalen < 0 || datalen > PAGE_SIZE - 1)
43381+ if (datalen > PAGE_SIZE - 1)
43382 return -EOPNOTSUPP;
43383
43384 /* drag the command string into the kernel so we can parse it */
43385@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43386 if (args[0] != '%' || args[1] != '\0')
43387 return -EINVAL;
43388
43389- if (fstop < 0 || fstop >= cache->fcull_percent)
43390+ if (fstop >= cache->fcull_percent)
43391 return cachefiles_daemon_range_error(cache, args);
43392
43393 cache->fstop_percent = fstop;
43394@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43395 if (args[0] != '%' || args[1] != '\0')
43396 return -EINVAL;
43397
43398- if (bstop < 0 || bstop >= cache->bcull_percent)
43399+ if (bstop >= cache->bcull_percent)
43400 return cachefiles_daemon_range_error(cache, args);
43401
43402 cache->bstop_percent = bstop;
43403diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43404index bd6bc1b..b627b53 100644
43405--- a/fs/cachefiles/internal.h
43406+++ b/fs/cachefiles/internal.h
43407@@ -57,7 +57,7 @@ struct cachefiles_cache {
43408 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43409 struct rb_root active_nodes; /* active nodes (can't be culled) */
43410 rwlock_t active_lock; /* lock for active_nodes */
43411- atomic_t gravecounter; /* graveyard uniquifier */
43412+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43413 unsigned frun_percent; /* when to stop culling (% files) */
43414 unsigned fcull_percent; /* when to start culling (% files) */
43415 unsigned fstop_percent; /* when to stop allocating (% files) */
43416@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43417 * proc.c
43418 */
43419 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43420-extern atomic_t cachefiles_lookup_histogram[HZ];
43421-extern atomic_t cachefiles_mkdir_histogram[HZ];
43422-extern atomic_t cachefiles_create_histogram[HZ];
43423+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43424+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43425+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43426
43427 extern int __init cachefiles_proc_init(void);
43428 extern void cachefiles_proc_cleanup(void);
43429 static inline
43430-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43431+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43432 {
43433 unsigned long jif = jiffies - start_jif;
43434 if (jif >= HZ)
43435 jif = HZ - 1;
43436- atomic_inc(&histogram[jif]);
43437+ atomic_inc_unchecked(&histogram[jif]);
43438 }
43439
43440 #else
43441diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43442index 7f0771d..87d4f36 100644
43443--- a/fs/cachefiles/namei.c
43444+++ b/fs/cachefiles/namei.c
43445@@ -318,7 +318,7 @@ try_again:
43446 /* first step is to make up a grave dentry in the graveyard */
43447 sprintf(nbuffer, "%08x%08x",
43448 (uint32_t) get_seconds(),
43449- (uint32_t) atomic_inc_return(&cache->gravecounter));
43450+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43451
43452 /* do the multiway lock magic */
43453 trap = lock_rename(cache->graveyard, dir);
43454diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43455index eccd339..4c1d995 100644
43456--- a/fs/cachefiles/proc.c
43457+++ b/fs/cachefiles/proc.c
43458@@ -14,9 +14,9 @@
43459 #include <linux/seq_file.h>
43460 #include "internal.h"
43461
43462-atomic_t cachefiles_lookup_histogram[HZ];
43463-atomic_t cachefiles_mkdir_histogram[HZ];
43464-atomic_t cachefiles_create_histogram[HZ];
43465+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43466+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43467+atomic_unchecked_t cachefiles_create_histogram[HZ];
43468
43469 /*
43470 * display the latency histogram
43471@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43472 return 0;
43473 default:
43474 index = (unsigned long) v - 3;
43475- x = atomic_read(&cachefiles_lookup_histogram[index]);
43476- y = atomic_read(&cachefiles_mkdir_histogram[index]);
43477- z = atomic_read(&cachefiles_create_histogram[index]);
43478+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43479+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43480+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43481 if (x == 0 && y == 0 && z == 0)
43482 return 0;
43483
43484diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43485index 0e3c092..818480e 100644
43486--- a/fs/cachefiles/rdwr.c
43487+++ b/fs/cachefiles/rdwr.c
43488@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43489 old_fs = get_fs();
43490 set_fs(KERNEL_DS);
43491 ret = file->f_op->write(
43492- file, (const void __user *) data, len, &pos);
43493+ file, (const void __force_user *) data, len, &pos);
43494 set_fs(old_fs);
43495 kunmap(page);
43496 if (ret != len)
43497diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43498index 3e8094b..cb3ff3d 100644
43499--- a/fs/ceph/dir.c
43500+++ b/fs/ceph/dir.c
43501@@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43502 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43503 struct ceph_mds_client *mdsc = fsc->mdsc;
43504 unsigned frag = fpos_frag(filp->f_pos);
43505- int off = fpos_off(filp->f_pos);
43506+ unsigned int off = fpos_off(filp->f_pos);
43507 int err;
43508 u32 ftype;
43509 struct ceph_mds_reply_info_parsed *rinfo;
43510@@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43511 if (nd &&
43512 (nd->flags & LOOKUP_OPEN) &&
43513 !(nd->intent.open.flags & O_CREAT)) {
43514- int mode = nd->intent.open.create_mode & ~current->fs->umask;
43515+ int mode = nd->intent.open.create_mode & ~current_umask();
43516 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43517 }
43518
43519diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43520index e814052..28dcdf7 100644
43521--- a/fs/cifs/cifs_debug.c
43522+++ b/fs/cifs/cifs_debug.c
43523@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43524
43525 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43526 #ifdef CONFIG_CIFS_STATS2
43527- atomic_set(&totBufAllocCount, 0);
43528- atomic_set(&totSmBufAllocCount, 0);
43529+ atomic_set_unchecked(&totBufAllocCount, 0);
43530+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43531 #endif /* CONFIG_CIFS_STATS2 */
43532 spin_lock(&cifs_tcp_ses_lock);
43533 list_for_each(tmp1, &cifs_tcp_ses_list) {
43534@@ -281,25 +281,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43535 tcon = list_entry(tmp3,
43536 struct cifs_tcon,
43537 tcon_list);
43538- atomic_set(&tcon->num_smbs_sent, 0);
43539- atomic_set(&tcon->num_writes, 0);
43540- atomic_set(&tcon->num_reads, 0);
43541- atomic_set(&tcon->num_oplock_brks, 0);
43542- atomic_set(&tcon->num_opens, 0);
43543- atomic_set(&tcon->num_posixopens, 0);
43544- atomic_set(&tcon->num_posixmkdirs, 0);
43545- atomic_set(&tcon->num_closes, 0);
43546- atomic_set(&tcon->num_deletes, 0);
43547- atomic_set(&tcon->num_mkdirs, 0);
43548- atomic_set(&tcon->num_rmdirs, 0);
43549- atomic_set(&tcon->num_renames, 0);
43550- atomic_set(&tcon->num_t2renames, 0);
43551- atomic_set(&tcon->num_ffirst, 0);
43552- atomic_set(&tcon->num_fnext, 0);
43553- atomic_set(&tcon->num_fclose, 0);
43554- atomic_set(&tcon->num_hardlinks, 0);
43555- atomic_set(&tcon->num_symlinks, 0);
43556- atomic_set(&tcon->num_locks, 0);
43557+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43558+ atomic_set_unchecked(&tcon->num_writes, 0);
43559+ atomic_set_unchecked(&tcon->num_reads, 0);
43560+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43561+ atomic_set_unchecked(&tcon->num_opens, 0);
43562+ atomic_set_unchecked(&tcon->num_posixopens, 0);
43563+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43564+ atomic_set_unchecked(&tcon->num_closes, 0);
43565+ atomic_set_unchecked(&tcon->num_deletes, 0);
43566+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
43567+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
43568+ atomic_set_unchecked(&tcon->num_renames, 0);
43569+ atomic_set_unchecked(&tcon->num_t2renames, 0);
43570+ atomic_set_unchecked(&tcon->num_ffirst, 0);
43571+ atomic_set_unchecked(&tcon->num_fnext, 0);
43572+ atomic_set_unchecked(&tcon->num_fclose, 0);
43573+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
43574+ atomic_set_unchecked(&tcon->num_symlinks, 0);
43575+ atomic_set_unchecked(&tcon->num_locks, 0);
43576 }
43577 }
43578 }
43579@@ -329,8 +329,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43580 smBufAllocCount.counter, cifs_min_small);
43581 #ifdef CONFIG_CIFS_STATS2
43582 seq_printf(m, "Total Large %d Small %d Allocations\n",
43583- atomic_read(&totBufAllocCount),
43584- atomic_read(&totSmBufAllocCount));
43585+ atomic_read_unchecked(&totBufAllocCount),
43586+ atomic_read_unchecked(&totSmBufAllocCount));
43587 #endif /* CONFIG_CIFS_STATS2 */
43588
43589 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43590@@ -359,41 +359,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43591 if (tcon->need_reconnect)
43592 seq_puts(m, "\tDISCONNECTED ");
43593 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43594- atomic_read(&tcon->num_smbs_sent),
43595- atomic_read(&tcon->num_oplock_brks));
43596+ atomic_read_unchecked(&tcon->num_smbs_sent),
43597+ atomic_read_unchecked(&tcon->num_oplock_brks));
43598 seq_printf(m, "\nReads: %d Bytes: %lld",
43599- atomic_read(&tcon->num_reads),
43600+ atomic_read_unchecked(&tcon->num_reads),
43601 (long long)(tcon->bytes_read));
43602 seq_printf(m, "\nWrites: %d Bytes: %lld",
43603- atomic_read(&tcon->num_writes),
43604+ atomic_read_unchecked(&tcon->num_writes),
43605 (long long)(tcon->bytes_written));
43606 seq_printf(m, "\nFlushes: %d",
43607- atomic_read(&tcon->num_flushes));
43608+ atomic_read_unchecked(&tcon->num_flushes));
43609 seq_printf(m, "\nLocks: %d HardLinks: %d "
43610 "Symlinks: %d",
43611- atomic_read(&tcon->num_locks),
43612- atomic_read(&tcon->num_hardlinks),
43613- atomic_read(&tcon->num_symlinks));
43614+ atomic_read_unchecked(&tcon->num_locks),
43615+ atomic_read_unchecked(&tcon->num_hardlinks),
43616+ atomic_read_unchecked(&tcon->num_symlinks));
43617 seq_printf(m, "\nOpens: %d Closes: %d "
43618 "Deletes: %d",
43619- atomic_read(&tcon->num_opens),
43620- atomic_read(&tcon->num_closes),
43621- atomic_read(&tcon->num_deletes));
43622+ atomic_read_unchecked(&tcon->num_opens),
43623+ atomic_read_unchecked(&tcon->num_closes),
43624+ atomic_read_unchecked(&tcon->num_deletes));
43625 seq_printf(m, "\nPosix Opens: %d "
43626 "Posix Mkdirs: %d",
43627- atomic_read(&tcon->num_posixopens),
43628- atomic_read(&tcon->num_posixmkdirs));
43629+ atomic_read_unchecked(&tcon->num_posixopens),
43630+ atomic_read_unchecked(&tcon->num_posixmkdirs));
43631 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43632- atomic_read(&tcon->num_mkdirs),
43633- atomic_read(&tcon->num_rmdirs));
43634+ atomic_read_unchecked(&tcon->num_mkdirs),
43635+ atomic_read_unchecked(&tcon->num_rmdirs));
43636 seq_printf(m, "\nRenames: %d T2 Renames %d",
43637- atomic_read(&tcon->num_renames),
43638- atomic_read(&tcon->num_t2renames));
43639+ atomic_read_unchecked(&tcon->num_renames),
43640+ atomic_read_unchecked(&tcon->num_t2renames));
43641 seq_printf(m, "\nFindFirst: %d FNext %d "
43642 "FClose %d",
43643- atomic_read(&tcon->num_ffirst),
43644- atomic_read(&tcon->num_fnext),
43645- atomic_read(&tcon->num_fclose));
43646+ atomic_read_unchecked(&tcon->num_ffirst),
43647+ atomic_read_unchecked(&tcon->num_fnext),
43648+ atomic_read_unchecked(&tcon->num_fclose));
43649 }
43650 }
43651 }
43652diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43653index 8b6e344..303a662 100644
43654--- a/fs/cifs/cifsfs.c
43655+++ b/fs/cifs/cifsfs.c
43656@@ -994,7 +994,7 @@ cifs_init_request_bufs(void)
43657 cifs_req_cachep = kmem_cache_create("cifs_request",
43658 CIFSMaxBufSize +
43659 MAX_CIFS_HDR_SIZE, 0,
43660- SLAB_HWCACHE_ALIGN, NULL);
43661+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43662 if (cifs_req_cachep == NULL)
43663 return -ENOMEM;
43664
43665@@ -1021,7 +1021,7 @@ cifs_init_request_bufs(void)
43666 efficient to alloc 1 per page off the slab compared to 17K (5page)
43667 alloc of large cifs buffers even when page debugging is on */
43668 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43669- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43670+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43671 NULL);
43672 if (cifs_sm_req_cachep == NULL) {
43673 mempool_destroy(cifs_req_poolp);
43674@@ -1106,8 +1106,8 @@ init_cifs(void)
43675 atomic_set(&bufAllocCount, 0);
43676 atomic_set(&smBufAllocCount, 0);
43677 #ifdef CONFIG_CIFS_STATS2
43678- atomic_set(&totBufAllocCount, 0);
43679- atomic_set(&totSmBufAllocCount, 0);
43680+ atomic_set_unchecked(&totBufAllocCount, 0);
43681+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43682 #endif /* CONFIG_CIFS_STATS2 */
43683
43684 atomic_set(&midCount, 0);
43685diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43686index 6df0cbe..eb7ecbb 100644
43687--- a/fs/cifs/cifsglob.h
43688+++ b/fs/cifs/cifsglob.h
43689@@ -491,28 +491,28 @@ struct cifs_tcon {
43690 __u16 Flags; /* optional support bits */
43691 enum statusEnum tidStatus;
43692 #ifdef CONFIG_CIFS_STATS
43693- atomic_t num_smbs_sent;
43694- atomic_t num_writes;
43695- atomic_t num_reads;
43696- atomic_t num_flushes;
43697- atomic_t num_oplock_brks;
43698- atomic_t num_opens;
43699- atomic_t num_closes;
43700- atomic_t num_deletes;
43701- atomic_t num_mkdirs;
43702- atomic_t num_posixopens;
43703- atomic_t num_posixmkdirs;
43704- atomic_t num_rmdirs;
43705- atomic_t num_renames;
43706- atomic_t num_t2renames;
43707- atomic_t num_ffirst;
43708- atomic_t num_fnext;
43709- atomic_t num_fclose;
43710- atomic_t num_hardlinks;
43711- atomic_t num_symlinks;
43712- atomic_t num_locks;
43713- atomic_t num_acl_get;
43714- atomic_t num_acl_set;
43715+ atomic_unchecked_t num_smbs_sent;
43716+ atomic_unchecked_t num_writes;
43717+ atomic_unchecked_t num_reads;
43718+ atomic_unchecked_t num_flushes;
43719+ atomic_unchecked_t num_oplock_brks;
43720+ atomic_unchecked_t num_opens;
43721+ atomic_unchecked_t num_closes;
43722+ atomic_unchecked_t num_deletes;
43723+ atomic_unchecked_t num_mkdirs;
43724+ atomic_unchecked_t num_posixopens;
43725+ atomic_unchecked_t num_posixmkdirs;
43726+ atomic_unchecked_t num_rmdirs;
43727+ atomic_unchecked_t num_renames;
43728+ atomic_unchecked_t num_t2renames;
43729+ atomic_unchecked_t num_ffirst;
43730+ atomic_unchecked_t num_fnext;
43731+ atomic_unchecked_t num_fclose;
43732+ atomic_unchecked_t num_hardlinks;
43733+ atomic_unchecked_t num_symlinks;
43734+ atomic_unchecked_t num_locks;
43735+ atomic_unchecked_t num_acl_get;
43736+ atomic_unchecked_t num_acl_set;
43737 #ifdef CONFIG_CIFS_STATS2
43738 unsigned long long time_writes;
43739 unsigned long long time_reads;
43740@@ -735,7 +735,7 @@ convert_delimiter(char *path, char delim)
43741 }
43742
43743 #ifdef CONFIG_CIFS_STATS
43744-#define cifs_stats_inc atomic_inc
43745+#define cifs_stats_inc atomic_inc_unchecked
43746
43747 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43748 unsigned int bytes)
43749@@ -1093,8 +1093,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43750 /* Various Debug counters */
43751 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43752 #ifdef CONFIG_CIFS_STATS2
43753-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43754-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43755+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43756+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43757 #endif
43758 GLOBAL_EXTERN atomic_t smBufAllocCount;
43759 GLOBAL_EXTERN atomic_t midCount;
43760diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43761index 6b0e064..94e6c3c 100644
43762--- a/fs/cifs/link.c
43763+++ b/fs/cifs/link.c
43764@@ -600,7 +600,7 @@ symlink_exit:
43765
43766 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43767 {
43768- char *p = nd_get_link(nd);
43769+ const char *p = nd_get_link(nd);
43770 if (!IS_ERR(p))
43771 kfree(p);
43772 }
43773diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43774index 557506a..2fd3816 100644
43775--- a/fs/cifs/misc.c
43776+++ b/fs/cifs/misc.c
43777@@ -156,7 +156,7 @@ cifs_buf_get(void)
43778 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43779 atomic_inc(&bufAllocCount);
43780 #ifdef CONFIG_CIFS_STATS2
43781- atomic_inc(&totBufAllocCount);
43782+ atomic_inc_unchecked(&totBufAllocCount);
43783 #endif /* CONFIG_CIFS_STATS2 */
43784 }
43785
43786@@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43787 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43788 atomic_inc(&smBufAllocCount);
43789 #ifdef CONFIG_CIFS_STATS2
43790- atomic_inc(&totSmBufAllocCount);
43791+ atomic_inc_unchecked(&totSmBufAllocCount);
43792 #endif /* CONFIG_CIFS_STATS2 */
43793
43794 }
43795diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43796index 6901578..d402eb5 100644
43797--- a/fs/coda/cache.c
43798+++ b/fs/coda/cache.c
43799@@ -24,7 +24,7 @@
43800 #include "coda_linux.h"
43801 #include "coda_cache.h"
43802
43803-static atomic_t permission_epoch = ATOMIC_INIT(0);
43804+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43805
43806 /* replace or extend an acl cache hit */
43807 void coda_cache_enter(struct inode *inode, int mask)
43808@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43809 struct coda_inode_info *cii = ITOC(inode);
43810
43811 spin_lock(&cii->c_lock);
43812- cii->c_cached_epoch = atomic_read(&permission_epoch);
43813+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43814 if (cii->c_uid != current_fsuid()) {
43815 cii->c_uid = current_fsuid();
43816 cii->c_cached_perm = mask;
43817@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43818 {
43819 struct coda_inode_info *cii = ITOC(inode);
43820 spin_lock(&cii->c_lock);
43821- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43822+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43823 spin_unlock(&cii->c_lock);
43824 }
43825
43826 /* remove all acl caches */
43827 void coda_cache_clear_all(struct super_block *sb)
43828 {
43829- atomic_inc(&permission_epoch);
43830+ atomic_inc_unchecked(&permission_epoch);
43831 }
43832
43833
43834@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43835 spin_lock(&cii->c_lock);
43836 hit = (mask & cii->c_cached_perm) == mask &&
43837 cii->c_uid == current_fsuid() &&
43838- cii->c_cached_epoch == atomic_read(&permission_epoch);
43839+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43840 spin_unlock(&cii->c_lock);
43841
43842 return hit;
43843diff --git a/fs/compat.c b/fs/compat.c
43844index 6161255..512b1a1 100644
43845--- a/fs/compat.c
43846+++ b/fs/compat.c
43847@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43848
43849 set_fs(KERNEL_DS);
43850 /* The __user pointer cast is valid because of the set_fs() */
43851- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43852+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43853 set_fs(oldfs);
43854 /* truncating is ok because it's a user address */
43855 if (!ret)
43856@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43857 goto out;
43858
43859 ret = -EINVAL;
43860- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43861+ if (nr_segs > UIO_MAXIOV)
43862 goto out;
43863 if (nr_segs > fast_segs) {
43864 ret = -ENOMEM;
43865@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
43866
43867 struct compat_readdir_callback {
43868 struct compat_old_linux_dirent __user *dirent;
43869+ struct file * file;
43870 int result;
43871 };
43872
43873@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43874 buf->result = -EOVERFLOW;
43875 return -EOVERFLOW;
43876 }
43877+
43878+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43879+ return 0;
43880+
43881 buf->result++;
43882 dirent = buf->dirent;
43883 if (!access_ok(VERIFY_WRITE, dirent,
43884@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43885
43886 buf.result = 0;
43887 buf.dirent = dirent;
43888+ buf.file = file;
43889
43890 error = vfs_readdir(file, compat_fillonedir, &buf);
43891 if (buf.result)
43892@@ -899,6 +905,7 @@ struct compat_linux_dirent {
43893 struct compat_getdents_callback {
43894 struct compat_linux_dirent __user *current_dir;
43895 struct compat_linux_dirent __user *previous;
43896+ struct file * file;
43897 int count;
43898 int error;
43899 };
43900@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43901 buf->error = -EOVERFLOW;
43902 return -EOVERFLOW;
43903 }
43904+
43905+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43906+ return 0;
43907+
43908 dirent = buf->previous;
43909 if (dirent) {
43910 if (__put_user(offset, &dirent->d_off))
43911@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43912 buf.previous = NULL;
43913 buf.count = count;
43914 buf.error = 0;
43915+ buf.file = file;
43916
43917 error = vfs_readdir(file, compat_filldir, &buf);
43918 if (error >= 0)
43919@@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43920 struct compat_getdents_callback64 {
43921 struct linux_dirent64 __user *current_dir;
43922 struct linux_dirent64 __user *previous;
43923+ struct file * file;
43924 int count;
43925 int error;
43926 };
43927@@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43928 buf->error = -EINVAL; /* only used if we fail.. */
43929 if (reclen > buf->count)
43930 return -EINVAL;
43931+
43932+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43933+ return 0;
43934+
43935 dirent = buf->previous;
43936
43937 if (dirent) {
43938@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43939 buf.previous = NULL;
43940 buf.count = count;
43941 buf.error = 0;
43942+ buf.file = file;
43943
43944 error = vfs_readdir(file, compat_filldir64, &buf);
43945 if (error >= 0)
43946 error = buf.error;
43947 lastdirent = buf.previous;
43948 if (lastdirent) {
43949- typeof(lastdirent->d_off) d_off = file->f_pos;
43950+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43951 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43952 error = -EFAULT;
43953 else
43954diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43955index 112e45a..b59845b 100644
43956--- a/fs/compat_binfmt_elf.c
43957+++ b/fs/compat_binfmt_elf.c
43958@@ -30,11 +30,13 @@
43959 #undef elf_phdr
43960 #undef elf_shdr
43961 #undef elf_note
43962+#undef elf_dyn
43963 #undef elf_addr_t
43964 #define elfhdr elf32_hdr
43965 #define elf_phdr elf32_phdr
43966 #define elf_shdr elf32_shdr
43967 #define elf_note elf32_note
43968+#define elf_dyn Elf32_Dyn
43969 #define elf_addr_t Elf32_Addr
43970
43971 /*
43972diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43973index debdfe0..75d31d4 100644
43974--- a/fs/compat_ioctl.c
43975+++ b/fs/compat_ioctl.c
43976@@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43977
43978 err = get_user(palp, &up->palette);
43979 err |= get_user(length, &up->length);
43980+ if (err)
43981+ return -EFAULT;
43982
43983 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43984 err = put_user(compat_ptr(palp), &up_native->palette);
43985@@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43986 return -EFAULT;
43987 if (__get_user(udata, &ss32->iomem_base))
43988 return -EFAULT;
43989- ss.iomem_base = compat_ptr(udata);
43990+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43991 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43992 __get_user(ss.port_high, &ss32->port_high))
43993 return -EFAULT;
43994@@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
43995 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43996 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43997 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43998- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43999+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44000 return -EFAULT;
44001
44002 return ioctl_preallocate(file, p);
44003@@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44004 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44005 {
44006 unsigned int a, b;
44007- a = *(unsigned int *)p;
44008- b = *(unsigned int *)q;
44009+ a = *(const unsigned int *)p;
44010+ b = *(const unsigned int *)q;
44011 if (a > b)
44012 return 1;
44013 if (a < b)
44014diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44015index 7e6c52d..94bc756 100644
44016--- a/fs/configfs/dir.c
44017+++ b/fs/configfs/dir.c
44018@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44019 }
44020 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44021 struct configfs_dirent *next;
44022- const char * name;
44023+ const unsigned char * name;
44024+ char d_name[sizeof(next->s_dentry->d_iname)];
44025 int len;
44026 struct inode *inode = NULL;
44027
44028@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44029 continue;
44030
44031 name = configfs_get_name(next);
44032- len = strlen(name);
44033+ if (next->s_dentry && name == next->s_dentry->d_iname) {
44034+ len = next->s_dentry->d_name.len;
44035+ memcpy(d_name, name, len);
44036+ name = d_name;
44037+ } else
44038+ len = strlen(name);
44039
44040 /*
44041 * We'll have a dentry and an inode for
44042diff --git a/fs/dcache.c b/fs/dcache.c
44043index 4046904..5e31505 100644
44044--- a/fs/dcache.c
44045+++ b/fs/dcache.c
44046@@ -3154,7 +3154,7 @@ void __init vfs_caches_init(unsigned long mempages)
44047 mempages -= reserve;
44048
44049 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44050- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44051+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44052
44053 dcache_init();
44054 inode_init();
44055diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44056index b80bc84..0d46d1a 100644
44057--- a/fs/debugfs/inode.c
44058+++ b/fs/debugfs/inode.c
44059@@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44060 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44061 {
44062 return debugfs_create_file(name,
44063+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44064+ S_IFDIR | S_IRWXU,
44065+#else
44066 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44067+#endif
44068 parent, NULL, NULL);
44069 }
44070 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44071diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44072index a07441a..046fc0d 100644
44073--- a/fs/ecryptfs/inode.c
44074+++ b/fs/ecryptfs/inode.c
44075@@ -671,7 +671,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44076 old_fs = get_fs();
44077 set_fs(get_ds());
44078 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44079- (char __user *)lower_buf,
44080+ (char __force_user *)lower_buf,
44081 PATH_MAX);
44082 set_fs(old_fs);
44083 if (rc < 0)
44084@@ -703,7 +703,7 @@ out:
44085 static void
44086 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44087 {
44088- char *buf = nd_get_link(nd);
44089+ const char *buf = nd_get_link(nd);
44090 if (!IS_ERR(buf)) {
44091 /* Free the char* */
44092 kfree(buf);
44093diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44094index c0038f6..47ab347 100644
44095--- a/fs/ecryptfs/miscdev.c
44096+++ b/fs/ecryptfs/miscdev.c
44097@@ -355,7 +355,7 @@ check_list:
44098 goto out_unlock_msg_ctx;
44099 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44100 if (msg_ctx->msg) {
44101- if (copy_to_user(&buf[i], packet_length, packet_length_size))
44102+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44103 goto out_unlock_msg_ctx;
44104 i += packet_length_size;
44105 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44106diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44107index b2a34a1..162fa69 100644
44108--- a/fs/ecryptfs/read_write.c
44109+++ b/fs/ecryptfs/read_write.c
44110@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44111 return -EIO;
44112 fs_save = get_fs();
44113 set_fs(get_ds());
44114- rc = vfs_write(lower_file, data, size, &offset);
44115+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44116 set_fs(fs_save);
44117 mark_inode_dirty_sync(ecryptfs_inode);
44118 return rc;
44119@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44120 return -EIO;
44121 fs_save = get_fs();
44122 set_fs(get_ds());
44123- rc = vfs_read(lower_file, data, size, &offset);
44124+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44125 set_fs(fs_save);
44126 return rc;
44127 }
44128diff --git a/fs/exec.c b/fs/exec.c
44129index da27b91..5a05624 100644
44130--- a/fs/exec.c
44131+++ b/fs/exec.c
44132@@ -55,6 +55,15 @@
44133 #include <linux/pipe_fs_i.h>
44134 #include <linux/oom.h>
44135 #include <linux/compat.h>
44136+#include <linux/random.h>
44137+#include <linux/seq_file.h>
44138+
44139+#ifdef CONFIG_PAX_REFCOUNT
44140+#include <linux/kallsyms.h>
44141+#include <linux/kdebug.h>
44142+#endif
44143+
44144+#include <trace/events/fs.h>
44145
44146 #include <asm/uaccess.h>
44147 #include <asm/mmu_context.h>
44148@@ -66,6 +75,18 @@
44149
44150 #include <trace/events/sched.h>
44151
44152+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44153+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44154+{
44155+ WARN_ONCE(1, "PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
44156+}
44157+#endif
44158+
44159+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44160+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44161+EXPORT_SYMBOL(pax_set_initial_flags_func);
44162+#endif
44163+
44164 int core_uses_pid;
44165 char core_pattern[CORENAME_MAX_SIZE] = "core";
44166 unsigned int core_pipe_limit;
44167@@ -75,7 +96,7 @@ struct core_name {
44168 char *corename;
44169 int used, size;
44170 };
44171-static atomic_t call_count = ATOMIC_INIT(1);
44172+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44173
44174 /* The maximal length of core_pattern is also specified in sysctl.c */
44175
44176@@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44177 int write)
44178 {
44179 struct page *page;
44180- int ret;
44181
44182-#ifdef CONFIG_STACK_GROWSUP
44183- if (write) {
44184- ret = expand_downwards(bprm->vma, pos);
44185- if (ret < 0)
44186- return NULL;
44187- }
44188-#endif
44189- ret = get_user_pages(current, bprm->mm, pos,
44190- 1, write, 1, &page, NULL);
44191- if (ret <= 0)
44192+ if (0 > expand_downwards(bprm->vma, pos))
44193+ return NULL;
44194+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44195 return NULL;
44196
44197 if (write) {
44198@@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44199 if (size <= ARG_MAX)
44200 return page;
44201
44202+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44203+ // only allow 512KB for argv+env on suid/sgid binaries
44204+ // to prevent easy ASLR exhaustion
44205+ if (((bprm->cred->euid != current_euid()) ||
44206+ (bprm->cred->egid != current_egid())) &&
44207+ (size > (512 * 1024))) {
44208+ put_page(page);
44209+ return NULL;
44210+ }
44211+#endif
44212+
44213 /*
44214 * Limit to 1/4-th the stack size for the argv+env strings.
44215 * This ensures that:
44216@@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44217 vma->vm_end = STACK_TOP_MAX;
44218 vma->vm_start = vma->vm_end - PAGE_SIZE;
44219 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44220+
44221+#ifdef CONFIG_PAX_SEGMEXEC
44222+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44223+#endif
44224+
44225 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44226 INIT_LIST_HEAD(&vma->anon_vma_chain);
44227
44228@@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44229 mm->stack_vm = mm->total_vm = 1;
44230 up_write(&mm->mmap_sem);
44231 bprm->p = vma->vm_end - sizeof(void *);
44232+
44233+#ifdef CONFIG_PAX_RANDUSTACK
44234+ if (randomize_va_space)
44235+ bprm->p ^= random32() & ~PAGE_MASK;
44236+#endif
44237+
44238 return 0;
44239 err:
44240 up_write(&mm->mmap_sem);
44241@@ -395,19 +430,7 @@ err:
44242 return err;
44243 }
44244
44245-struct user_arg_ptr {
44246-#ifdef CONFIG_COMPAT
44247- bool is_compat;
44248-#endif
44249- union {
44250- const char __user *const __user *native;
44251-#ifdef CONFIG_COMPAT
44252- compat_uptr_t __user *compat;
44253-#endif
44254- } ptr;
44255-};
44256-
44257-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44258+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44259 {
44260 const char __user *native;
44261
44262@@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44263 compat_uptr_t compat;
44264
44265 if (get_user(compat, argv.ptr.compat + nr))
44266- return ERR_PTR(-EFAULT);
44267+ return (const char __force_user *)ERR_PTR(-EFAULT);
44268
44269 return compat_ptr(compat);
44270 }
44271 #endif
44272
44273 if (get_user(native, argv.ptr.native + nr))
44274- return ERR_PTR(-EFAULT);
44275+ return (const char __force_user *)ERR_PTR(-EFAULT);
44276
44277 return native;
44278 }
44279@@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44280 if (!p)
44281 break;
44282
44283- if (IS_ERR(p))
44284+ if (IS_ERR((const char __force_kernel *)p))
44285 return -EFAULT;
44286
44287 if (i++ >= max)
44288@@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44289
44290 ret = -EFAULT;
44291 str = get_user_arg_ptr(argv, argc);
44292- if (IS_ERR(str))
44293+ if (IS_ERR((const char __force_kernel *)str))
44294 goto out;
44295
44296 len = strnlen_user(str, MAX_ARG_STRLEN);
44297@@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44298 int r;
44299 mm_segment_t oldfs = get_fs();
44300 struct user_arg_ptr argv = {
44301- .ptr.native = (const char __user *const __user *)__argv,
44302+ .ptr.native = (const char __force_user *const __force_user *)__argv,
44303 };
44304
44305 set_fs(KERNEL_DS);
44306@@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44307 unsigned long new_end = old_end - shift;
44308 struct mmu_gather tlb;
44309
44310- BUG_ON(new_start > new_end);
44311+ if (new_start >= new_end || new_start < mmap_min_addr)
44312+ return -ENOMEM;
44313
44314 /*
44315 * ensure there are no vmas between where we want to go
44316@@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44317 if (vma != find_vma(mm, new_start))
44318 return -EFAULT;
44319
44320+#ifdef CONFIG_PAX_SEGMEXEC
44321+ BUG_ON(pax_find_mirror_vma(vma));
44322+#endif
44323+
44324 /*
44325 * cover the whole range: [new_start, old_end)
44326 */
44327@@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44328 stack_top = arch_align_stack(stack_top);
44329 stack_top = PAGE_ALIGN(stack_top);
44330
44331- if (unlikely(stack_top < mmap_min_addr) ||
44332- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44333- return -ENOMEM;
44334-
44335 stack_shift = vma->vm_end - stack_top;
44336
44337 bprm->p -= stack_shift;
44338@@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44339 bprm->exec -= stack_shift;
44340
44341 down_write(&mm->mmap_sem);
44342+
44343+ /* Move stack pages down in memory. */
44344+ if (stack_shift) {
44345+ ret = shift_arg_pages(vma, stack_shift);
44346+ if (ret)
44347+ goto out_unlock;
44348+ }
44349+
44350 vm_flags = VM_STACK_FLAGS;
44351
44352+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44353+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44354+ vm_flags &= ~VM_EXEC;
44355+
44356+#ifdef CONFIG_PAX_MPROTECT
44357+ if (mm->pax_flags & MF_PAX_MPROTECT)
44358+ vm_flags &= ~VM_MAYEXEC;
44359+#endif
44360+
44361+ }
44362+#endif
44363+
44364 /*
44365 * Adjust stack execute permissions; explicitly enable for
44366 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44367@@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44368 goto out_unlock;
44369 BUG_ON(prev != vma);
44370
44371- /* Move stack pages down in memory. */
44372- if (stack_shift) {
44373- ret = shift_arg_pages(vma, stack_shift);
44374- if (ret)
44375- goto out_unlock;
44376- }
44377-
44378 /* mprotect_fixup is overkill to remove the temporary stack flags */
44379 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44380
44381@@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
44382
44383 fsnotify_open(file);
44384
44385+ trace_open_exec(name);
44386+
44387 err = deny_write_access(file);
44388 if (err)
44389 goto exit;
44390@@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
44391 old_fs = get_fs();
44392 set_fs(get_ds());
44393 /* The cast to a user pointer is valid due to the set_fs() */
44394- result = vfs_read(file, (void __user *)addr, count, &pos);
44395+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
44396 set_fs(old_fs);
44397 return result;
44398 }
44399@@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44400 }
44401 rcu_read_unlock();
44402
44403- if (p->fs->users > n_fs) {
44404+ if (atomic_read(&p->fs->users) > n_fs) {
44405 bprm->unsafe |= LSM_UNSAFE_SHARE;
44406 } else {
44407 res = -EAGAIN;
44408@@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44409
44410 EXPORT_SYMBOL(search_binary_handler);
44411
44412+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44413+static DEFINE_PER_CPU(u64, exec_counter);
44414+static int __init init_exec_counters(void)
44415+{
44416+ unsigned int cpu;
44417+
44418+ for_each_possible_cpu(cpu) {
44419+ per_cpu(exec_counter, cpu) = (u64)cpu;
44420+ }
44421+
44422+ return 0;
44423+}
44424+early_initcall(init_exec_counters);
44425+static inline void increment_exec_counter(void)
44426+{
44427+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
44428+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44429+}
44430+#else
44431+static inline void increment_exec_counter(void) {}
44432+#endif
44433+
44434 /*
44435 * sys_execve() executes a new program.
44436 */
44437@@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
44438 struct user_arg_ptr envp,
44439 struct pt_regs *regs)
44440 {
44441+#ifdef CONFIG_GRKERNSEC
44442+ struct file *old_exec_file;
44443+ struct acl_subject_label *old_acl;
44444+ struct rlimit old_rlim[RLIM_NLIMITS];
44445+#endif
44446 struct linux_binprm *bprm;
44447 struct file *file;
44448 struct files_struct *displaced;
44449@@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
44450 int retval;
44451 const struct cred *cred = current_cred();
44452
44453+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44454+
44455 /*
44456 * We move the actual failure in case of RLIMIT_NPROC excess from
44457 * set*uid() to execve() because too many poorly written programs
44458@@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
44459 if (IS_ERR(file))
44460 goto out_unmark;
44461
44462+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
44463+ retval = -EPERM;
44464+ goto out_file;
44465+ }
44466+
44467 sched_exec();
44468
44469 bprm->file = file;
44470 bprm->filename = filename;
44471 bprm->interp = filename;
44472
44473+ if (gr_process_user_ban()) {
44474+ retval = -EPERM;
44475+ goto out_file;
44476+ }
44477+
44478+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44479+ retval = -EACCES;
44480+ goto out_file;
44481+ }
44482+
44483 retval = bprm_mm_init(bprm);
44484 if (retval)
44485 goto out_file;
44486@@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
44487 if (retval < 0)
44488 goto out;
44489
44490+#ifdef CONFIG_GRKERNSEC
44491+ old_acl = current->acl;
44492+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44493+ old_exec_file = current->exec_file;
44494+ get_file(file);
44495+ current->exec_file = file;
44496+#endif
44497+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44498+ /* limit suid stack to 8MB
44499+ we saved the old limits above and will restore them if this exec fails
44500+ */
44501+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44502+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44503+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44504+#endif
44505+
44506+ if (!gr_tpe_allow(file)) {
44507+ retval = -EACCES;
44508+ goto out_fail;
44509+ }
44510+
44511+ if (gr_check_crash_exec(file)) {
44512+ retval = -EACCES;
44513+ goto out_fail;
44514+ }
44515+
44516+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44517+ bprm->unsafe);
44518+ if (retval < 0)
44519+ goto out_fail;
44520+
44521 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44522 if (retval < 0)
44523- goto out;
44524+ goto out_fail;
44525
44526 bprm->exec = bprm->p;
44527 retval = copy_strings(bprm->envc, envp, bprm);
44528 if (retval < 0)
44529- goto out;
44530+ goto out_fail;
44531
44532 retval = copy_strings(bprm->argc, argv, bprm);
44533 if (retval < 0)
44534- goto out;
44535+ goto out_fail;
44536+
44537+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44538+
44539+ gr_handle_exec_args(bprm, argv);
44540
44541 retval = search_binary_handler(bprm,regs);
44542 if (retval < 0)
44543- goto out;
44544+ goto out_fail;
44545+#ifdef CONFIG_GRKERNSEC
44546+ if (old_exec_file)
44547+ fput(old_exec_file);
44548+#endif
44549
44550 /* execve succeeded */
44551+
44552+ increment_exec_counter();
44553 current->fs->in_exec = 0;
44554 current->in_execve = 0;
44555 acct_update_integrals(current);
44556@@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
44557 put_files_struct(displaced);
44558 return retval;
44559
44560+out_fail:
44561+#ifdef CONFIG_GRKERNSEC
44562+ current->acl = old_acl;
44563+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44564+ fput(current->exec_file);
44565+ current->exec_file = old_exec_file;
44566+#endif
44567+
44568 out:
44569 if (bprm->mm) {
44570 acct_arg_size(bprm, 0);
44571@@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
44572 {
44573 char *old_corename = cn->corename;
44574
44575- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44576+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44577 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44578
44579 if (!cn->corename) {
44580@@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
44581 int pid_in_pattern = 0;
44582 int err = 0;
44583
44584- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44585+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44586 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44587 cn->used = 0;
44588
44589@@ -1830,6 +1962,250 @@ out:
44590 return ispipe;
44591 }
44592
44593+int pax_check_flags(unsigned long *flags)
44594+{
44595+ int retval = 0;
44596+
44597+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44598+ if (*flags & MF_PAX_SEGMEXEC)
44599+ {
44600+ *flags &= ~MF_PAX_SEGMEXEC;
44601+ retval = -EINVAL;
44602+ }
44603+#endif
44604+
44605+ if ((*flags & MF_PAX_PAGEEXEC)
44606+
44607+#ifdef CONFIG_PAX_PAGEEXEC
44608+ && (*flags & MF_PAX_SEGMEXEC)
44609+#endif
44610+
44611+ )
44612+ {
44613+ *flags &= ~MF_PAX_PAGEEXEC;
44614+ retval = -EINVAL;
44615+ }
44616+
44617+ if ((*flags & MF_PAX_MPROTECT)
44618+
44619+#ifdef CONFIG_PAX_MPROTECT
44620+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44621+#endif
44622+
44623+ )
44624+ {
44625+ *flags &= ~MF_PAX_MPROTECT;
44626+ retval = -EINVAL;
44627+ }
44628+
44629+ if ((*flags & MF_PAX_EMUTRAMP)
44630+
44631+#ifdef CONFIG_PAX_EMUTRAMP
44632+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44633+#endif
44634+
44635+ )
44636+ {
44637+ *flags &= ~MF_PAX_EMUTRAMP;
44638+ retval = -EINVAL;
44639+ }
44640+
44641+ return retval;
44642+}
44643+
44644+EXPORT_SYMBOL(pax_check_flags);
44645+
44646+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44647+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44648+{
44649+ struct task_struct *tsk = current;
44650+ struct mm_struct *mm = current->mm;
44651+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44652+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44653+ char *path_exec = NULL;
44654+ char *path_fault = NULL;
44655+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
44656+
44657+ if (buffer_exec && buffer_fault) {
44658+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44659+
44660+ down_read(&mm->mmap_sem);
44661+ vma = mm->mmap;
44662+ while (vma && (!vma_exec || !vma_fault)) {
44663+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44664+ vma_exec = vma;
44665+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44666+ vma_fault = vma;
44667+ vma = vma->vm_next;
44668+ }
44669+ if (vma_exec) {
44670+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44671+ if (IS_ERR(path_exec))
44672+ path_exec = "<path too long>";
44673+ else {
44674+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44675+ if (path_exec) {
44676+ *path_exec = 0;
44677+ path_exec = buffer_exec;
44678+ } else
44679+ path_exec = "<path too long>";
44680+ }
44681+ }
44682+ if (vma_fault) {
44683+ start = vma_fault->vm_start;
44684+ end = vma_fault->vm_end;
44685+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44686+ if (vma_fault->vm_file) {
44687+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44688+ if (IS_ERR(path_fault))
44689+ path_fault = "<path too long>";
44690+ else {
44691+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44692+ if (path_fault) {
44693+ *path_fault = 0;
44694+ path_fault = buffer_fault;
44695+ } else
44696+ path_fault = "<path too long>";
44697+ }
44698+ } else
44699+ path_fault = "<anonymous mapping>";
44700+ }
44701+ up_read(&mm->mmap_sem);
44702+ }
44703+ if (tsk->signal->curr_ip)
44704+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44705+ else
44706+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44707+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44708+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44709+ task_uid(tsk), task_euid(tsk), pc, sp);
44710+ free_page((unsigned long)buffer_exec);
44711+ free_page((unsigned long)buffer_fault);
44712+ pax_report_insns(regs, pc, sp);
44713+ do_coredump(SIGKILL, SIGKILL, regs);
44714+}
44715+#endif
44716+
44717+#ifdef CONFIG_PAX_REFCOUNT
44718+void pax_report_refcount_overflow(struct pt_regs *regs)
44719+{
44720+ if (current->signal->curr_ip)
44721+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44722+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44723+ else
44724+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44725+ current->comm, task_pid_nr(current), current_uid(), current_euid());
44726+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44727+ show_regs(regs);
44728+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44729+}
44730+#endif
44731+
44732+#ifdef CONFIG_PAX_USERCOPY
44733+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44734+static noinline int check_stack_object(const void *obj, unsigned long len)
44735+{
44736+ const void * const stack = task_stack_page(current);
44737+ const void * const stackend = stack + THREAD_SIZE;
44738+
44739+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44740+ const void *frame = NULL;
44741+ const void *oldframe;
44742+#endif
44743+
44744+ if (obj + len < obj)
44745+ return -1;
44746+
44747+ if (obj + len <= stack || stackend <= obj)
44748+ return 0;
44749+
44750+ if (obj < stack || stackend < obj + len)
44751+ return -1;
44752+
44753+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44754+ oldframe = __builtin_frame_address(1);
44755+ if (oldframe)
44756+ frame = __builtin_frame_address(2);
44757+ /*
44758+ low ----------------------------------------------> high
44759+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
44760+ ^----------------^
44761+ allow copies only within here
44762+ */
44763+ while (stack <= frame && frame < stackend) {
44764+ /* if obj + len extends past the last frame, this
44765+ check won't pass and the next frame will be 0,
44766+ causing us to bail out and correctly report
44767+ the copy as invalid
44768+ */
44769+ if (obj + len <= frame)
44770+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44771+ oldframe = frame;
44772+ frame = *(const void * const *)frame;
44773+ }
44774+ return -1;
44775+#else
44776+ return 1;
44777+#endif
44778+}
44779+
44780+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44781+{
44782+ if (current->signal->curr_ip)
44783+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44784+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44785+ else
44786+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44787+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44788+ dump_stack();
44789+ gr_handle_kernel_exploit();
44790+ do_group_exit(SIGKILL);
44791+}
44792+#endif
44793+
44794+void check_object_size(const void *ptr, unsigned long n, bool to)
44795+{
44796+
44797+#ifdef CONFIG_PAX_USERCOPY
44798+ const char *type;
44799+
44800+ if (!n)
44801+ return;
44802+
44803+ type = check_heap_object(ptr, n, to);
44804+ if (!type) {
44805+ if (check_stack_object(ptr, n) != -1)
44806+ return;
44807+ type = "<process stack>";
44808+ }
44809+
44810+ pax_report_usercopy(ptr, n, to, type);
44811+#endif
44812+
44813+}
44814+EXPORT_SYMBOL(check_object_size);
44815+
44816+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44817+void pax_track_stack(void)
44818+{
44819+ unsigned long sp = (unsigned long)&sp;
44820+ if (sp < current_thread_info()->lowest_stack &&
44821+ sp > (unsigned long)task_stack_page(current))
44822+ current_thread_info()->lowest_stack = sp;
44823+}
44824+EXPORT_SYMBOL(pax_track_stack);
44825+#endif
44826+
44827+#ifdef CONFIG_PAX_SIZE_OVERFLOW
44828+void report_size_overflow(const char *file, unsigned int line, const char *func)
44829+{
44830+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44831+ dump_stack();
44832+ do_group_exit(SIGKILL);
44833+}
44834+EXPORT_SYMBOL(report_size_overflow);
44835+#endif
44836+
44837 static int zap_process(struct task_struct *start, int exit_code)
44838 {
44839 struct task_struct *t;
44840@@ -2002,17 +2378,17 @@ static void coredump_finish(struct mm_struct *mm)
44841 void set_dumpable(struct mm_struct *mm, int value)
44842 {
44843 switch (value) {
44844- case 0:
44845+ case SUID_DUMPABLE_DISABLED:
44846 clear_bit(MMF_DUMPABLE, &mm->flags);
44847 smp_wmb();
44848 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44849 break;
44850- case 1:
44851+ case SUID_DUMPABLE_ENABLED:
44852 set_bit(MMF_DUMPABLE, &mm->flags);
44853 smp_wmb();
44854 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44855 break;
44856- case 2:
44857+ case SUID_DUMPABLE_SAFE:
44858 set_bit(MMF_DUMP_SECURELY, &mm->flags);
44859 smp_wmb();
44860 set_bit(MMF_DUMPABLE, &mm->flags);
44861@@ -2025,7 +2401,7 @@ static int __get_dumpable(unsigned long mm_flags)
44862 int ret;
44863
44864 ret = mm_flags & MMF_DUMPABLE_MASK;
44865- return (ret >= 2) ? 2 : ret;
44866+ return (ret > SUID_DUMPABLE_ENABLED) ? SUID_DUMPABLE_SAFE : ret;
44867 }
44868
44869 int get_dumpable(struct mm_struct *mm)
44870@@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
44871 pipe = file->f_path.dentry->d_inode->i_pipe;
44872
44873 pipe_lock(pipe);
44874- pipe->readers++;
44875- pipe->writers--;
44876+ atomic_inc(&pipe->readers);
44877+ atomic_dec(&pipe->writers);
44878
44879- while ((pipe->readers > 1) && (!signal_pending(current))) {
44880+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44881 wake_up_interruptible_sync(&pipe->wait);
44882 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44883 pipe_wait(pipe);
44884 }
44885
44886- pipe->readers--;
44887- pipe->writers++;
44888+ atomic_dec(&pipe->readers);
44889+ atomic_inc(&pipe->writers);
44890 pipe_unlock(pipe);
44891
44892 }
44893@@ -2111,7 +2487,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44894 int retval = 0;
44895 int flag = 0;
44896 int ispipe;
44897- static atomic_t core_dump_count = ATOMIC_INIT(0);
44898+ bool need_nonrelative = false;
44899+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44900 struct coredump_params cprm = {
44901 .signr = signr,
44902 .regs = regs,
44903@@ -2126,6 +2503,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44904
44905 audit_core_dumps(signr);
44906
44907+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44908+ gr_handle_brute_attach(current, cprm.mm_flags);
44909+
44910 binfmt = mm->binfmt;
44911 if (!binfmt || !binfmt->core_dump)
44912 goto fail;
44913@@ -2136,14 +2516,16 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44914 if (!cred)
44915 goto fail;
44916 /*
44917- * We cannot trust fsuid as being the "true" uid of the
44918- * process nor do we know its entire history. We only know it
44919- * was tainted so we dump it as root in mode 2.
44920+ * We cannot trust fsuid as being the "true" uid of the process
44921+ * nor do we know its entire history. We only know it was tainted
44922+ * so we dump it as root in mode 2, and only into a controlled
44923+ * environment (pipe handler or fully qualified path).
44924 */
44925- if (__get_dumpable(cprm.mm_flags) == 2) {
44926+ if (__get_dumpable(cprm.mm_flags) == SUID_DUMPABLE_SAFE) {
44927 /* Setuid core dump mode */
44928 flag = O_EXCL; /* Stop rewrite attacks */
44929 cred->fsuid = GLOBAL_ROOT_UID; /* Dump root private */
44930+ need_nonrelative = true;
44931 }
44932
44933 retval = coredump_wait(exit_code, &core_state);
44934@@ -2193,7 +2575,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44935 }
44936 cprm.limit = RLIM_INFINITY;
44937
44938- dump_count = atomic_inc_return(&core_dump_count);
44939+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
44940 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44941 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44942 task_tgid_vnr(current), current->comm);
44943@@ -2220,9 +2602,19 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44944 } else {
44945 struct inode *inode;
44946
44947+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44948+
44949 if (cprm.limit < binfmt->min_coredump)
44950 goto fail_unlock;
44951
44952+ if (need_nonrelative && cn.corename[0] != '/') {
44953+ printk(KERN_WARNING "Pid %d(%s) can only dump core "\
44954+ "to fully qualified path!\n",
44955+ task_tgid_vnr(current), current->comm);
44956+ printk(KERN_WARNING "Skipping core dump\n");
44957+ goto fail_unlock;
44958+ }
44959+
44960 cprm.file = filp_open(cn.corename,
44961 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
44962 0600);
44963@@ -2263,7 +2655,7 @@ close_fail:
44964 filp_close(cprm.file, NULL);
44965 fail_dropcount:
44966 if (ispipe)
44967- atomic_dec(&core_dump_count);
44968+ atomic_dec_unchecked(&core_dump_count);
44969 fail_unlock:
44970 kfree(cn.corename);
44971 fail_corename:
44972@@ -2282,7 +2674,7 @@ fail:
44973 */
44974 int dump_write(struct file *file, const void *addr, int nr)
44975 {
44976- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44977+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44978 }
44979 EXPORT_SYMBOL(dump_write);
44980
44981diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44982index 1c36139..cf6b350 100644
44983--- a/fs/ext2/balloc.c
44984+++ b/fs/ext2/balloc.c
44985@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44986
44987 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44988 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44989- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44990+ if (free_blocks < root_blocks + 1 &&
44991 !uid_eq(sbi->s_resuid, current_fsuid()) &&
44992 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
44993- !in_group_p (sbi->s_resgid))) {
44994+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
44995 return 0;
44996 }
44997 return 1;
44998diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44999index 25cd608..9ed5294 100644
45000--- a/fs/ext3/balloc.c
45001+++ b/fs/ext3/balloc.c
45002@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45003
45004 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45005 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45006- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45007+ if (free_blocks < root_blocks + 1 &&
45008 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45009 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45010- !in_group_p (sbi->s_resgid))) {
45011+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45012 return 0;
45013 }
45014 return 1;
45015diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45016index cee7812..0e8e65c 100644
45017--- a/fs/ext4/balloc.c
45018+++ b/fs/ext4/balloc.c
45019@@ -488,8 +488,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45020 /* Hm, nope. Are (enough) root reserved clusters available? */
45021 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45022 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45023- capable(CAP_SYS_RESOURCE) ||
45024- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45025+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45026+ capable_nolog(CAP_SYS_RESOURCE)) {
45027
45028 if (free_clusters >= (nclusters + dirty_clusters))
45029 return 1;
45030diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45031index cfc4e01..2f3fd3c 100644
45032--- a/fs/ext4/ext4.h
45033+++ b/fs/ext4/ext4.h
45034@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
45035 unsigned long s_mb_last_start;
45036
45037 /* stats for buddy allocator */
45038- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45039- atomic_t s_bal_success; /* we found long enough chunks */
45040- atomic_t s_bal_allocated; /* in blocks */
45041- atomic_t s_bal_ex_scanned; /* total extents scanned */
45042- atomic_t s_bal_goals; /* goal hits */
45043- atomic_t s_bal_breaks; /* too long searches */
45044- atomic_t s_bal_2orders; /* 2^order hits */
45045+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45046+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45047+ atomic_unchecked_t s_bal_allocated; /* in blocks */
45048+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45049+ atomic_unchecked_t s_bal_goals; /* goal hits */
45050+ atomic_unchecked_t s_bal_breaks; /* too long searches */
45051+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45052 spinlock_t s_bal_lock;
45053 unsigned long s_mb_buddies_generated;
45054 unsigned long long s_mb_generation_time;
45055- atomic_t s_mb_lost_chunks;
45056- atomic_t s_mb_preallocated;
45057- atomic_t s_mb_discarded;
45058+ atomic_unchecked_t s_mb_lost_chunks;
45059+ atomic_unchecked_t s_mb_preallocated;
45060+ atomic_unchecked_t s_mb_discarded;
45061 atomic_t s_lock_busy;
45062
45063 /* locality groups */
45064diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45065index 1cd6994..5799d45 100644
45066--- a/fs/ext4/mballoc.c
45067+++ b/fs/ext4/mballoc.c
45068@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45069 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45070
45071 if (EXT4_SB(sb)->s_mb_stats)
45072- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45073+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45074
45075 break;
45076 }
45077@@ -2041,7 +2041,7 @@ repeat:
45078 ac->ac_status = AC_STATUS_CONTINUE;
45079 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45080 cr = 3;
45081- atomic_inc(&sbi->s_mb_lost_chunks);
45082+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45083 goto repeat;
45084 }
45085 }
45086@@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
45087 if (sbi->s_mb_stats) {
45088 ext4_msg(sb, KERN_INFO,
45089 "mballoc: %u blocks %u reqs (%u success)",
45090- atomic_read(&sbi->s_bal_allocated),
45091- atomic_read(&sbi->s_bal_reqs),
45092- atomic_read(&sbi->s_bal_success));
45093+ atomic_read_unchecked(&sbi->s_bal_allocated),
45094+ atomic_read_unchecked(&sbi->s_bal_reqs),
45095+ atomic_read_unchecked(&sbi->s_bal_success));
45096 ext4_msg(sb, KERN_INFO,
45097 "mballoc: %u extents scanned, %u goal hits, "
45098 "%u 2^N hits, %u breaks, %u lost",
45099- atomic_read(&sbi->s_bal_ex_scanned),
45100- atomic_read(&sbi->s_bal_goals),
45101- atomic_read(&sbi->s_bal_2orders),
45102- atomic_read(&sbi->s_bal_breaks),
45103- atomic_read(&sbi->s_mb_lost_chunks));
45104+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45105+ atomic_read_unchecked(&sbi->s_bal_goals),
45106+ atomic_read_unchecked(&sbi->s_bal_2orders),
45107+ atomic_read_unchecked(&sbi->s_bal_breaks),
45108+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45109 ext4_msg(sb, KERN_INFO,
45110 "mballoc: %lu generated and it took %Lu",
45111 sbi->s_mb_buddies_generated,
45112 sbi->s_mb_generation_time);
45113 ext4_msg(sb, KERN_INFO,
45114 "mballoc: %u preallocated, %u discarded",
45115- atomic_read(&sbi->s_mb_preallocated),
45116- atomic_read(&sbi->s_mb_discarded));
45117+ atomic_read_unchecked(&sbi->s_mb_preallocated),
45118+ atomic_read_unchecked(&sbi->s_mb_discarded));
45119 }
45120
45121 free_percpu(sbi->s_locality_groups);
45122@@ -3047,16 +3047,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45123 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45124
45125 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45126- atomic_inc(&sbi->s_bal_reqs);
45127- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45128+ atomic_inc_unchecked(&sbi->s_bal_reqs);
45129+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45130 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45131- atomic_inc(&sbi->s_bal_success);
45132- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45133+ atomic_inc_unchecked(&sbi->s_bal_success);
45134+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45135 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45136 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45137- atomic_inc(&sbi->s_bal_goals);
45138+ atomic_inc_unchecked(&sbi->s_bal_goals);
45139 if (ac->ac_found > sbi->s_mb_max_to_scan)
45140- atomic_inc(&sbi->s_bal_breaks);
45141+ atomic_inc_unchecked(&sbi->s_bal_breaks);
45142 }
45143
45144 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45145@@ -3456,7 +3456,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45146 trace_ext4_mb_new_inode_pa(ac, pa);
45147
45148 ext4_mb_use_inode_pa(ac, pa);
45149- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45150+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45151
45152 ei = EXT4_I(ac->ac_inode);
45153 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45154@@ -3516,7 +3516,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45155 trace_ext4_mb_new_group_pa(ac, pa);
45156
45157 ext4_mb_use_group_pa(ac, pa);
45158- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45159+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45160
45161 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45162 lg = ac->ac_lg;
45163@@ -3605,7 +3605,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45164 * from the bitmap and continue.
45165 */
45166 }
45167- atomic_add(free, &sbi->s_mb_discarded);
45168+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
45169
45170 return err;
45171 }
45172@@ -3623,7 +3623,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45173 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45174 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45175 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45176- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45177+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45178 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45179
45180 return 0;
45181diff --git a/fs/fcntl.c b/fs/fcntl.c
45182index 81b70e6..d9ae6cf 100644
45183--- a/fs/fcntl.c
45184+++ b/fs/fcntl.c
45185@@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45186 if (err)
45187 return err;
45188
45189+ if (gr_handle_chroot_fowner(pid, type))
45190+ return -ENOENT;
45191+ if (gr_check_protected_task_fowner(pid, type))
45192+ return -EACCES;
45193+
45194 f_modown(filp, pid, type, force);
45195 return 0;
45196 }
45197@@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
45198
45199 static int f_setown_ex(struct file *filp, unsigned long arg)
45200 {
45201- struct f_owner_ex * __user owner_p = (void * __user)arg;
45202+ struct f_owner_ex __user *owner_p = (void __user *)arg;
45203 struct f_owner_ex owner;
45204 struct pid *pid;
45205 int type;
45206@@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45207
45208 static int f_getown_ex(struct file *filp, unsigned long arg)
45209 {
45210- struct f_owner_ex * __user owner_p = (void * __user)arg;
45211+ struct f_owner_ex __user *owner_p = (void __user *)arg;
45212 struct f_owner_ex owner;
45213 int ret = 0;
45214
45215@@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45216 switch (cmd) {
45217 case F_DUPFD:
45218 case F_DUPFD_CLOEXEC:
45219+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45220 if (arg >= rlimit(RLIMIT_NOFILE))
45221 break;
45222 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45223diff --git a/fs/fifo.c b/fs/fifo.c
45224index cf6f434..3d7942c 100644
45225--- a/fs/fifo.c
45226+++ b/fs/fifo.c
45227@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45228 */
45229 filp->f_op = &read_pipefifo_fops;
45230 pipe->r_counter++;
45231- if (pipe->readers++ == 0)
45232+ if (atomic_inc_return(&pipe->readers) == 1)
45233 wake_up_partner(inode);
45234
45235- if (!pipe->writers) {
45236+ if (!atomic_read(&pipe->writers)) {
45237 if ((filp->f_flags & O_NONBLOCK)) {
45238 /* suppress POLLHUP until we have
45239 * seen a writer */
45240@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45241 * errno=ENXIO when there is no process reading the FIFO.
45242 */
45243 ret = -ENXIO;
45244- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45245+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45246 goto err;
45247
45248 filp->f_op = &write_pipefifo_fops;
45249 pipe->w_counter++;
45250- if (!pipe->writers++)
45251+ if (atomic_inc_return(&pipe->writers) == 1)
45252 wake_up_partner(inode);
45253
45254- if (!pipe->readers) {
45255+ if (!atomic_read(&pipe->readers)) {
45256 if (wait_for_partner(inode, &pipe->r_counter))
45257 goto err_wr;
45258 }
45259@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45260 */
45261 filp->f_op = &rdwr_pipefifo_fops;
45262
45263- pipe->readers++;
45264- pipe->writers++;
45265+ atomic_inc(&pipe->readers);
45266+ atomic_inc(&pipe->writers);
45267 pipe->r_counter++;
45268 pipe->w_counter++;
45269- if (pipe->readers == 1 || pipe->writers == 1)
45270+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45271 wake_up_partner(inode);
45272 break;
45273
45274@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45275 return 0;
45276
45277 err_rd:
45278- if (!--pipe->readers)
45279+ if (atomic_dec_and_test(&pipe->readers))
45280 wake_up_interruptible(&pipe->wait);
45281 ret = -ERESTARTSYS;
45282 goto err;
45283
45284 err_wr:
45285- if (!--pipe->writers)
45286+ if (atomic_dec_and_test(&pipe->writers))
45287 wake_up_interruptible(&pipe->wait);
45288 ret = -ERESTARTSYS;
45289 goto err;
45290
45291 err:
45292- if (!pipe->readers && !pipe->writers)
45293+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45294 free_pipe_info(inode);
45295
45296 err_nocleanup:
45297diff --git a/fs/file.c b/fs/file.c
45298index ba3f605..fade102 100644
45299--- a/fs/file.c
45300+++ b/fs/file.c
45301@@ -15,6 +15,7 @@
45302 #include <linux/slab.h>
45303 #include <linux/vmalloc.h>
45304 #include <linux/file.h>
45305+#include <linux/security.h>
45306 #include <linux/fdtable.h>
45307 #include <linux/bitops.h>
45308 #include <linux/interrupt.h>
45309@@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45310 * N.B. For clone tasks sharing a files structure, this test
45311 * will limit the total number of files that can be opened.
45312 */
45313+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45314 if (nr >= rlimit(RLIMIT_NOFILE))
45315 return -EMFILE;
45316
45317diff --git a/fs/filesystems.c b/fs/filesystems.c
45318index 96f2428..f5eeb8e 100644
45319--- a/fs/filesystems.c
45320+++ b/fs/filesystems.c
45321@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45322 int len = dot ? dot - name : strlen(name);
45323
45324 fs = __get_fs_type(name, len);
45325+
45326+#ifdef CONFIG_GRKERNSEC_MODHARDEN
45327+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45328+#else
45329 if (!fs && (request_module("%.*s", len, name) == 0))
45330+#endif
45331 fs = __get_fs_type(name, len);
45332
45333 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45334diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45335index e159e68..e7d2a6f 100644
45336--- a/fs/fs_struct.c
45337+++ b/fs/fs_struct.c
45338@@ -4,6 +4,7 @@
45339 #include <linux/path.h>
45340 #include <linux/slab.h>
45341 #include <linux/fs_struct.h>
45342+#include <linux/grsecurity.h>
45343 #include "internal.h"
45344
45345 static inline void path_get_longterm(struct path *path)
45346@@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45347 write_seqcount_begin(&fs->seq);
45348 old_root = fs->root;
45349 fs->root = *path;
45350+ gr_set_chroot_entries(current, path);
45351 write_seqcount_end(&fs->seq);
45352 spin_unlock(&fs->lock);
45353 if (old_root.dentry)
45354@@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45355 return 1;
45356 }
45357
45358+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45359+{
45360+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45361+ return 0;
45362+ *p = *new;
45363+
45364+ gr_set_chroot_entries(task, new);
45365+
45366+ return 1;
45367+}
45368+
45369 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45370 {
45371 struct task_struct *g, *p;
45372@@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45373 int hits = 0;
45374 spin_lock(&fs->lock);
45375 write_seqcount_begin(&fs->seq);
45376- hits += replace_path(&fs->root, old_root, new_root);
45377+ hits += replace_root_path(p, &fs->root, old_root, new_root);
45378 hits += replace_path(&fs->pwd, old_root, new_root);
45379 write_seqcount_end(&fs->seq);
45380 while (hits--) {
45381@@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
45382 task_lock(tsk);
45383 spin_lock(&fs->lock);
45384 tsk->fs = NULL;
45385- kill = !--fs->users;
45386+ gr_clear_chroot_entries(tsk);
45387+ kill = !atomic_dec_return(&fs->users);
45388 spin_unlock(&fs->lock);
45389 task_unlock(tsk);
45390 if (kill)
45391@@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45392 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45393 /* We don't need to lock fs - think why ;-) */
45394 if (fs) {
45395- fs->users = 1;
45396+ atomic_set(&fs->users, 1);
45397 fs->in_exec = 0;
45398 spin_lock_init(&fs->lock);
45399 seqcount_init(&fs->seq);
45400@@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45401 spin_lock(&old->lock);
45402 fs->root = old->root;
45403 path_get_longterm(&fs->root);
45404+ /* instead of calling gr_set_chroot_entries here,
45405+ we call it from every caller of this function
45406+ */
45407 fs->pwd = old->pwd;
45408 path_get_longterm(&fs->pwd);
45409 spin_unlock(&old->lock);
45410@@ -151,8 +168,9 @@ int unshare_fs_struct(void)
45411
45412 task_lock(current);
45413 spin_lock(&fs->lock);
45414- kill = !--fs->users;
45415+ kill = !atomic_dec_return(&fs->users);
45416 current->fs = new_fs;
45417+ gr_set_chroot_entries(current, &new_fs->root);
45418 spin_unlock(&fs->lock);
45419 task_unlock(current);
45420
45421@@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45422
45423 int current_umask(void)
45424 {
45425- return current->fs->umask;
45426+ return current->fs->umask | gr_acl_umask();
45427 }
45428 EXPORT_SYMBOL(current_umask);
45429
45430 /* to be mentioned only in INIT_TASK */
45431 struct fs_struct init_fs = {
45432- .users = 1,
45433+ .users = ATOMIC_INIT(1),
45434 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45435 .seq = SEQCNT_ZERO,
45436 .umask = 0022,
45437@@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
45438 task_lock(current);
45439
45440 spin_lock(&init_fs.lock);
45441- init_fs.users++;
45442+ atomic_inc(&init_fs.users);
45443 spin_unlock(&init_fs.lock);
45444
45445 spin_lock(&fs->lock);
45446 current->fs = &init_fs;
45447- kill = !--fs->users;
45448+ gr_set_chroot_entries(current, &current->fs->root);
45449+ kill = !atomic_dec_return(&fs->users);
45450 spin_unlock(&fs->lock);
45451
45452 task_unlock(current);
45453diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45454index 9905350..02eaec4 100644
45455--- a/fs/fscache/cookie.c
45456+++ b/fs/fscache/cookie.c
45457@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45458 parent ? (char *) parent->def->name : "<no-parent>",
45459 def->name, netfs_data);
45460
45461- fscache_stat(&fscache_n_acquires);
45462+ fscache_stat_unchecked(&fscache_n_acquires);
45463
45464 /* if there's no parent cookie, then we don't create one here either */
45465 if (!parent) {
45466- fscache_stat(&fscache_n_acquires_null);
45467+ fscache_stat_unchecked(&fscache_n_acquires_null);
45468 _leave(" [no parent]");
45469 return NULL;
45470 }
45471@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45472 /* allocate and initialise a cookie */
45473 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45474 if (!cookie) {
45475- fscache_stat(&fscache_n_acquires_oom);
45476+ fscache_stat_unchecked(&fscache_n_acquires_oom);
45477 _leave(" [ENOMEM]");
45478 return NULL;
45479 }
45480@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45481
45482 switch (cookie->def->type) {
45483 case FSCACHE_COOKIE_TYPE_INDEX:
45484- fscache_stat(&fscache_n_cookie_index);
45485+ fscache_stat_unchecked(&fscache_n_cookie_index);
45486 break;
45487 case FSCACHE_COOKIE_TYPE_DATAFILE:
45488- fscache_stat(&fscache_n_cookie_data);
45489+ fscache_stat_unchecked(&fscache_n_cookie_data);
45490 break;
45491 default:
45492- fscache_stat(&fscache_n_cookie_special);
45493+ fscache_stat_unchecked(&fscache_n_cookie_special);
45494 break;
45495 }
45496
45497@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45498 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45499 atomic_dec(&parent->n_children);
45500 __fscache_cookie_put(cookie);
45501- fscache_stat(&fscache_n_acquires_nobufs);
45502+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45503 _leave(" = NULL");
45504 return NULL;
45505 }
45506 }
45507
45508- fscache_stat(&fscache_n_acquires_ok);
45509+ fscache_stat_unchecked(&fscache_n_acquires_ok);
45510 _leave(" = %p", cookie);
45511 return cookie;
45512 }
45513@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45514 cache = fscache_select_cache_for_object(cookie->parent);
45515 if (!cache) {
45516 up_read(&fscache_addremove_sem);
45517- fscache_stat(&fscache_n_acquires_no_cache);
45518+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45519 _leave(" = -ENOMEDIUM [no cache]");
45520 return -ENOMEDIUM;
45521 }
45522@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45523 object = cache->ops->alloc_object(cache, cookie);
45524 fscache_stat_d(&fscache_n_cop_alloc_object);
45525 if (IS_ERR(object)) {
45526- fscache_stat(&fscache_n_object_no_alloc);
45527+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
45528 ret = PTR_ERR(object);
45529 goto error;
45530 }
45531
45532- fscache_stat(&fscache_n_object_alloc);
45533+ fscache_stat_unchecked(&fscache_n_object_alloc);
45534
45535 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45536
45537@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45538 struct fscache_object *object;
45539 struct hlist_node *_p;
45540
45541- fscache_stat(&fscache_n_updates);
45542+ fscache_stat_unchecked(&fscache_n_updates);
45543
45544 if (!cookie) {
45545- fscache_stat(&fscache_n_updates_null);
45546+ fscache_stat_unchecked(&fscache_n_updates_null);
45547 _leave(" [no cookie]");
45548 return;
45549 }
45550@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45551 struct fscache_object *object;
45552 unsigned long event;
45553
45554- fscache_stat(&fscache_n_relinquishes);
45555+ fscache_stat_unchecked(&fscache_n_relinquishes);
45556 if (retire)
45557- fscache_stat(&fscache_n_relinquishes_retire);
45558+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45559
45560 if (!cookie) {
45561- fscache_stat(&fscache_n_relinquishes_null);
45562+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
45563 _leave(" [no cookie]");
45564 return;
45565 }
45566@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45567
45568 /* wait for the cookie to finish being instantiated (or to fail) */
45569 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45570- fscache_stat(&fscache_n_relinquishes_waitcrt);
45571+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45572 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45573 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45574 }
45575diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45576index f6aad48..88dcf26 100644
45577--- a/fs/fscache/internal.h
45578+++ b/fs/fscache/internal.h
45579@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45580 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45581 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45582
45583-extern atomic_t fscache_n_op_pend;
45584-extern atomic_t fscache_n_op_run;
45585-extern atomic_t fscache_n_op_enqueue;
45586-extern atomic_t fscache_n_op_deferred_release;
45587-extern atomic_t fscache_n_op_release;
45588-extern atomic_t fscache_n_op_gc;
45589-extern atomic_t fscache_n_op_cancelled;
45590-extern atomic_t fscache_n_op_rejected;
45591+extern atomic_unchecked_t fscache_n_op_pend;
45592+extern atomic_unchecked_t fscache_n_op_run;
45593+extern atomic_unchecked_t fscache_n_op_enqueue;
45594+extern atomic_unchecked_t fscache_n_op_deferred_release;
45595+extern atomic_unchecked_t fscache_n_op_release;
45596+extern atomic_unchecked_t fscache_n_op_gc;
45597+extern atomic_unchecked_t fscache_n_op_cancelled;
45598+extern atomic_unchecked_t fscache_n_op_rejected;
45599
45600-extern atomic_t fscache_n_attr_changed;
45601-extern atomic_t fscache_n_attr_changed_ok;
45602-extern atomic_t fscache_n_attr_changed_nobufs;
45603-extern atomic_t fscache_n_attr_changed_nomem;
45604-extern atomic_t fscache_n_attr_changed_calls;
45605+extern atomic_unchecked_t fscache_n_attr_changed;
45606+extern atomic_unchecked_t fscache_n_attr_changed_ok;
45607+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45608+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45609+extern atomic_unchecked_t fscache_n_attr_changed_calls;
45610
45611-extern atomic_t fscache_n_allocs;
45612-extern atomic_t fscache_n_allocs_ok;
45613-extern atomic_t fscache_n_allocs_wait;
45614-extern atomic_t fscache_n_allocs_nobufs;
45615-extern atomic_t fscache_n_allocs_intr;
45616-extern atomic_t fscache_n_allocs_object_dead;
45617-extern atomic_t fscache_n_alloc_ops;
45618-extern atomic_t fscache_n_alloc_op_waits;
45619+extern atomic_unchecked_t fscache_n_allocs;
45620+extern atomic_unchecked_t fscache_n_allocs_ok;
45621+extern atomic_unchecked_t fscache_n_allocs_wait;
45622+extern atomic_unchecked_t fscache_n_allocs_nobufs;
45623+extern atomic_unchecked_t fscache_n_allocs_intr;
45624+extern atomic_unchecked_t fscache_n_allocs_object_dead;
45625+extern atomic_unchecked_t fscache_n_alloc_ops;
45626+extern atomic_unchecked_t fscache_n_alloc_op_waits;
45627
45628-extern atomic_t fscache_n_retrievals;
45629-extern atomic_t fscache_n_retrievals_ok;
45630-extern atomic_t fscache_n_retrievals_wait;
45631-extern atomic_t fscache_n_retrievals_nodata;
45632-extern atomic_t fscache_n_retrievals_nobufs;
45633-extern atomic_t fscache_n_retrievals_intr;
45634-extern atomic_t fscache_n_retrievals_nomem;
45635-extern atomic_t fscache_n_retrievals_object_dead;
45636-extern atomic_t fscache_n_retrieval_ops;
45637-extern atomic_t fscache_n_retrieval_op_waits;
45638+extern atomic_unchecked_t fscache_n_retrievals;
45639+extern atomic_unchecked_t fscache_n_retrievals_ok;
45640+extern atomic_unchecked_t fscache_n_retrievals_wait;
45641+extern atomic_unchecked_t fscache_n_retrievals_nodata;
45642+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45643+extern atomic_unchecked_t fscache_n_retrievals_intr;
45644+extern atomic_unchecked_t fscache_n_retrievals_nomem;
45645+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45646+extern atomic_unchecked_t fscache_n_retrieval_ops;
45647+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45648
45649-extern atomic_t fscache_n_stores;
45650-extern atomic_t fscache_n_stores_ok;
45651-extern atomic_t fscache_n_stores_again;
45652-extern atomic_t fscache_n_stores_nobufs;
45653-extern atomic_t fscache_n_stores_oom;
45654-extern atomic_t fscache_n_store_ops;
45655-extern atomic_t fscache_n_store_calls;
45656-extern atomic_t fscache_n_store_pages;
45657-extern atomic_t fscache_n_store_radix_deletes;
45658-extern atomic_t fscache_n_store_pages_over_limit;
45659+extern atomic_unchecked_t fscache_n_stores;
45660+extern atomic_unchecked_t fscache_n_stores_ok;
45661+extern atomic_unchecked_t fscache_n_stores_again;
45662+extern atomic_unchecked_t fscache_n_stores_nobufs;
45663+extern atomic_unchecked_t fscache_n_stores_oom;
45664+extern atomic_unchecked_t fscache_n_store_ops;
45665+extern atomic_unchecked_t fscache_n_store_calls;
45666+extern atomic_unchecked_t fscache_n_store_pages;
45667+extern atomic_unchecked_t fscache_n_store_radix_deletes;
45668+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45669
45670-extern atomic_t fscache_n_store_vmscan_not_storing;
45671-extern atomic_t fscache_n_store_vmscan_gone;
45672-extern atomic_t fscache_n_store_vmscan_busy;
45673-extern atomic_t fscache_n_store_vmscan_cancelled;
45674+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45675+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45676+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45677+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45678
45679-extern atomic_t fscache_n_marks;
45680-extern atomic_t fscache_n_uncaches;
45681+extern atomic_unchecked_t fscache_n_marks;
45682+extern atomic_unchecked_t fscache_n_uncaches;
45683
45684-extern atomic_t fscache_n_acquires;
45685-extern atomic_t fscache_n_acquires_null;
45686-extern atomic_t fscache_n_acquires_no_cache;
45687-extern atomic_t fscache_n_acquires_ok;
45688-extern atomic_t fscache_n_acquires_nobufs;
45689-extern atomic_t fscache_n_acquires_oom;
45690+extern atomic_unchecked_t fscache_n_acquires;
45691+extern atomic_unchecked_t fscache_n_acquires_null;
45692+extern atomic_unchecked_t fscache_n_acquires_no_cache;
45693+extern atomic_unchecked_t fscache_n_acquires_ok;
45694+extern atomic_unchecked_t fscache_n_acquires_nobufs;
45695+extern atomic_unchecked_t fscache_n_acquires_oom;
45696
45697-extern atomic_t fscache_n_updates;
45698-extern atomic_t fscache_n_updates_null;
45699-extern atomic_t fscache_n_updates_run;
45700+extern atomic_unchecked_t fscache_n_updates;
45701+extern atomic_unchecked_t fscache_n_updates_null;
45702+extern atomic_unchecked_t fscache_n_updates_run;
45703
45704-extern atomic_t fscache_n_relinquishes;
45705-extern atomic_t fscache_n_relinquishes_null;
45706-extern atomic_t fscache_n_relinquishes_waitcrt;
45707-extern atomic_t fscache_n_relinquishes_retire;
45708+extern atomic_unchecked_t fscache_n_relinquishes;
45709+extern atomic_unchecked_t fscache_n_relinquishes_null;
45710+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45711+extern atomic_unchecked_t fscache_n_relinquishes_retire;
45712
45713-extern atomic_t fscache_n_cookie_index;
45714-extern atomic_t fscache_n_cookie_data;
45715-extern atomic_t fscache_n_cookie_special;
45716+extern atomic_unchecked_t fscache_n_cookie_index;
45717+extern atomic_unchecked_t fscache_n_cookie_data;
45718+extern atomic_unchecked_t fscache_n_cookie_special;
45719
45720-extern atomic_t fscache_n_object_alloc;
45721-extern atomic_t fscache_n_object_no_alloc;
45722-extern atomic_t fscache_n_object_lookups;
45723-extern atomic_t fscache_n_object_lookups_negative;
45724-extern atomic_t fscache_n_object_lookups_positive;
45725-extern atomic_t fscache_n_object_lookups_timed_out;
45726-extern atomic_t fscache_n_object_created;
45727-extern atomic_t fscache_n_object_avail;
45728-extern atomic_t fscache_n_object_dead;
45729+extern atomic_unchecked_t fscache_n_object_alloc;
45730+extern atomic_unchecked_t fscache_n_object_no_alloc;
45731+extern atomic_unchecked_t fscache_n_object_lookups;
45732+extern atomic_unchecked_t fscache_n_object_lookups_negative;
45733+extern atomic_unchecked_t fscache_n_object_lookups_positive;
45734+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45735+extern atomic_unchecked_t fscache_n_object_created;
45736+extern atomic_unchecked_t fscache_n_object_avail;
45737+extern atomic_unchecked_t fscache_n_object_dead;
45738
45739-extern atomic_t fscache_n_checkaux_none;
45740-extern atomic_t fscache_n_checkaux_okay;
45741-extern atomic_t fscache_n_checkaux_update;
45742-extern atomic_t fscache_n_checkaux_obsolete;
45743+extern atomic_unchecked_t fscache_n_checkaux_none;
45744+extern atomic_unchecked_t fscache_n_checkaux_okay;
45745+extern atomic_unchecked_t fscache_n_checkaux_update;
45746+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45747
45748 extern atomic_t fscache_n_cop_alloc_object;
45749 extern atomic_t fscache_n_cop_lookup_object;
45750@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45751 atomic_inc(stat);
45752 }
45753
45754+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45755+{
45756+ atomic_inc_unchecked(stat);
45757+}
45758+
45759 static inline void fscache_stat_d(atomic_t *stat)
45760 {
45761 atomic_dec(stat);
45762@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45763
45764 #define __fscache_stat(stat) (NULL)
45765 #define fscache_stat(stat) do {} while (0)
45766+#define fscache_stat_unchecked(stat) do {} while (0)
45767 #define fscache_stat_d(stat) do {} while (0)
45768 #endif
45769
45770diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45771index b6b897c..0ffff9c 100644
45772--- a/fs/fscache/object.c
45773+++ b/fs/fscache/object.c
45774@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45775 /* update the object metadata on disk */
45776 case FSCACHE_OBJECT_UPDATING:
45777 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45778- fscache_stat(&fscache_n_updates_run);
45779+ fscache_stat_unchecked(&fscache_n_updates_run);
45780 fscache_stat(&fscache_n_cop_update_object);
45781 object->cache->ops->update_object(object);
45782 fscache_stat_d(&fscache_n_cop_update_object);
45783@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45784 spin_lock(&object->lock);
45785 object->state = FSCACHE_OBJECT_DEAD;
45786 spin_unlock(&object->lock);
45787- fscache_stat(&fscache_n_object_dead);
45788+ fscache_stat_unchecked(&fscache_n_object_dead);
45789 goto terminal_transit;
45790
45791 /* handle the parent cache of this object being withdrawn from
45792@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45793 spin_lock(&object->lock);
45794 object->state = FSCACHE_OBJECT_DEAD;
45795 spin_unlock(&object->lock);
45796- fscache_stat(&fscache_n_object_dead);
45797+ fscache_stat_unchecked(&fscache_n_object_dead);
45798 goto terminal_transit;
45799
45800 /* complain about the object being woken up once it is
45801@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45802 parent->cookie->def->name, cookie->def->name,
45803 object->cache->tag->name);
45804
45805- fscache_stat(&fscache_n_object_lookups);
45806+ fscache_stat_unchecked(&fscache_n_object_lookups);
45807 fscache_stat(&fscache_n_cop_lookup_object);
45808 ret = object->cache->ops->lookup_object(object);
45809 fscache_stat_d(&fscache_n_cop_lookup_object);
45810@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45811 if (ret == -ETIMEDOUT) {
45812 /* probably stuck behind another object, so move this one to
45813 * the back of the queue */
45814- fscache_stat(&fscache_n_object_lookups_timed_out);
45815+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45816 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45817 }
45818
45819@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45820
45821 spin_lock(&object->lock);
45822 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45823- fscache_stat(&fscache_n_object_lookups_negative);
45824+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45825
45826 /* transit here to allow write requests to begin stacking up
45827 * and read requests to begin returning ENODATA */
45828@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45829 * result, in which case there may be data available */
45830 spin_lock(&object->lock);
45831 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45832- fscache_stat(&fscache_n_object_lookups_positive);
45833+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45834
45835 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45836
45837@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45838 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45839 } else {
45840 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45841- fscache_stat(&fscache_n_object_created);
45842+ fscache_stat_unchecked(&fscache_n_object_created);
45843
45844 object->state = FSCACHE_OBJECT_AVAILABLE;
45845 spin_unlock(&object->lock);
45846@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45847 fscache_enqueue_dependents(object);
45848
45849 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45850- fscache_stat(&fscache_n_object_avail);
45851+ fscache_stat_unchecked(&fscache_n_object_avail);
45852
45853 _leave("");
45854 }
45855@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45856 enum fscache_checkaux result;
45857
45858 if (!object->cookie->def->check_aux) {
45859- fscache_stat(&fscache_n_checkaux_none);
45860+ fscache_stat_unchecked(&fscache_n_checkaux_none);
45861 return FSCACHE_CHECKAUX_OKAY;
45862 }
45863
45864@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45865 switch (result) {
45866 /* entry okay as is */
45867 case FSCACHE_CHECKAUX_OKAY:
45868- fscache_stat(&fscache_n_checkaux_okay);
45869+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
45870 break;
45871
45872 /* entry requires update */
45873 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45874- fscache_stat(&fscache_n_checkaux_update);
45875+ fscache_stat_unchecked(&fscache_n_checkaux_update);
45876 break;
45877
45878 /* entry requires deletion */
45879 case FSCACHE_CHECKAUX_OBSOLETE:
45880- fscache_stat(&fscache_n_checkaux_obsolete);
45881+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45882 break;
45883
45884 default:
45885diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45886index 30afdfa..2256596 100644
45887--- a/fs/fscache/operation.c
45888+++ b/fs/fscache/operation.c
45889@@ -17,7 +17,7 @@
45890 #include <linux/slab.h>
45891 #include "internal.h"
45892
45893-atomic_t fscache_op_debug_id;
45894+atomic_unchecked_t fscache_op_debug_id;
45895 EXPORT_SYMBOL(fscache_op_debug_id);
45896
45897 /**
45898@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45899 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45900 ASSERTCMP(atomic_read(&op->usage), >, 0);
45901
45902- fscache_stat(&fscache_n_op_enqueue);
45903+ fscache_stat_unchecked(&fscache_n_op_enqueue);
45904 switch (op->flags & FSCACHE_OP_TYPE) {
45905 case FSCACHE_OP_ASYNC:
45906 _debug("queue async");
45907@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45908 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45909 if (op->processor)
45910 fscache_enqueue_operation(op);
45911- fscache_stat(&fscache_n_op_run);
45912+ fscache_stat_unchecked(&fscache_n_op_run);
45913 }
45914
45915 /*
45916@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45917 if (object->n_ops > 1) {
45918 atomic_inc(&op->usage);
45919 list_add_tail(&op->pend_link, &object->pending_ops);
45920- fscache_stat(&fscache_n_op_pend);
45921+ fscache_stat_unchecked(&fscache_n_op_pend);
45922 } else if (!list_empty(&object->pending_ops)) {
45923 atomic_inc(&op->usage);
45924 list_add_tail(&op->pend_link, &object->pending_ops);
45925- fscache_stat(&fscache_n_op_pend);
45926+ fscache_stat_unchecked(&fscache_n_op_pend);
45927 fscache_start_operations(object);
45928 } else {
45929 ASSERTCMP(object->n_in_progress, ==, 0);
45930@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45931 object->n_exclusive++; /* reads and writes must wait */
45932 atomic_inc(&op->usage);
45933 list_add_tail(&op->pend_link, &object->pending_ops);
45934- fscache_stat(&fscache_n_op_pend);
45935+ fscache_stat_unchecked(&fscache_n_op_pend);
45936 ret = 0;
45937 } else {
45938 /* not allowed to submit ops in any other state */
45939@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45940 if (object->n_exclusive > 0) {
45941 atomic_inc(&op->usage);
45942 list_add_tail(&op->pend_link, &object->pending_ops);
45943- fscache_stat(&fscache_n_op_pend);
45944+ fscache_stat_unchecked(&fscache_n_op_pend);
45945 } else if (!list_empty(&object->pending_ops)) {
45946 atomic_inc(&op->usage);
45947 list_add_tail(&op->pend_link, &object->pending_ops);
45948- fscache_stat(&fscache_n_op_pend);
45949+ fscache_stat_unchecked(&fscache_n_op_pend);
45950 fscache_start_operations(object);
45951 } else {
45952 ASSERTCMP(object->n_exclusive, ==, 0);
45953@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45954 object->n_ops++;
45955 atomic_inc(&op->usage);
45956 list_add_tail(&op->pend_link, &object->pending_ops);
45957- fscache_stat(&fscache_n_op_pend);
45958+ fscache_stat_unchecked(&fscache_n_op_pend);
45959 ret = 0;
45960 } else if (object->state == FSCACHE_OBJECT_DYING ||
45961 object->state == FSCACHE_OBJECT_LC_DYING ||
45962 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45963- fscache_stat(&fscache_n_op_rejected);
45964+ fscache_stat_unchecked(&fscache_n_op_rejected);
45965 ret = -ENOBUFS;
45966 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45967 fscache_report_unexpected_submission(object, op, ostate);
45968@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45969
45970 ret = -EBUSY;
45971 if (!list_empty(&op->pend_link)) {
45972- fscache_stat(&fscache_n_op_cancelled);
45973+ fscache_stat_unchecked(&fscache_n_op_cancelled);
45974 list_del_init(&op->pend_link);
45975 object->n_ops--;
45976 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45977@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45978 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45979 BUG();
45980
45981- fscache_stat(&fscache_n_op_release);
45982+ fscache_stat_unchecked(&fscache_n_op_release);
45983
45984 if (op->release) {
45985 op->release(op);
45986@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45987 * lock, and defer it otherwise */
45988 if (!spin_trylock(&object->lock)) {
45989 _debug("defer put");
45990- fscache_stat(&fscache_n_op_deferred_release);
45991+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
45992
45993 cache = object->cache;
45994 spin_lock(&cache->op_gc_list_lock);
45995@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45996
45997 _debug("GC DEFERRED REL OBJ%x OP%x",
45998 object->debug_id, op->debug_id);
45999- fscache_stat(&fscache_n_op_gc);
46000+ fscache_stat_unchecked(&fscache_n_op_gc);
46001
46002 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46003
46004diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46005index 3f7a59b..cf196cc 100644
46006--- a/fs/fscache/page.c
46007+++ b/fs/fscache/page.c
46008@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46009 val = radix_tree_lookup(&cookie->stores, page->index);
46010 if (!val) {
46011 rcu_read_unlock();
46012- fscache_stat(&fscache_n_store_vmscan_not_storing);
46013+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46014 __fscache_uncache_page(cookie, page);
46015 return true;
46016 }
46017@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46018 spin_unlock(&cookie->stores_lock);
46019
46020 if (xpage) {
46021- fscache_stat(&fscache_n_store_vmscan_cancelled);
46022- fscache_stat(&fscache_n_store_radix_deletes);
46023+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46024+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46025 ASSERTCMP(xpage, ==, page);
46026 } else {
46027- fscache_stat(&fscache_n_store_vmscan_gone);
46028+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46029 }
46030
46031 wake_up_bit(&cookie->flags, 0);
46032@@ -107,7 +107,7 @@ page_busy:
46033 /* we might want to wait here, but that could deadlock the allocator as
46034 * the work threads writing to the cache may all end up sleeping
46035 * on memory allocation */
46036- fscache_stat(&fscache_n_store_vmscan_busy);
46037+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46038 return false;
46039 }
46040 EXPORT_SYMBOL(__fscache_maybe_release_page);
46041@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46042 FSCACHE_COOKIE_STORING_TAG);
46043 if (!radix_tree_tag_get(&cookie->stores, page->index,
46044 FSCACHE_COOKIE_PENDING_TAG)) {
46045- fscache_stat(&fscache_n_store_radix_deletes);
46046+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46047 xpage = radix_tree_delete(&cookie->stores, page->index);
46048 }
46049 spin_unlock(&cookie->stores_lock);
46050@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46051
46052 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46053
46054- fscache_stat(&fscache_n_attr_changed_calls);
46055+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46056
46057 if (fscache_object_is_active(object)) {
46058 fscache_stat(&fscache_n_cop_attr_changed);
46059@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46060
46061 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46062
46063- fscache_stat(&fscache_n_attr_changed);
46064+ fscache_stat_unchecked(&fscache_n_attr_changed);
46065
46066 op = kzalloc(sizeof(*op), GFP_KERNEL);
46067 if (!op) {
46068- fscache_stat(&fscache_n_attr_changed_nomem);
46069+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46070 _leave(" = -ENOMEM");
46071 return -ENOMEM;
46072 }
46073@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46074 if (fscache_submit_exclusive_op(object, op) < 0)
46075 goto nobufs;
46076 spin_unlock(&cookie->lock);
46077- fscache_stat(&fscache_n_attr_changed_ok);
46078+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46079 fscache_put_operation(op);
46080 _leave(" = 0");
46081 return 0;
46082@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46083 nobufs:
46084 spin_unlock(&cookie->lock);
46085 kfree(op);
46086- fscache_stat(&fscache_n_attr_changed_nobufs);
46087+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46088 _leave(" = %d", -ENOBUFS);
46089 return -ENOBUFS;
46090 }
46091@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46092 /* allocate a retrieval operation and attempt to submit it */
46093 op = kzalloc(sizeof(*op), GFP_NOIO);
46094 if (!op) {
46095- fscache_stat(&fscache_n_retrievals_nomem);
46096+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46097 return NULL;
46098 }
46099
46100@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46101 return 0;
46102 }
46103
46104- fscache_stat(&fscache_n_retrievals_wait);
46105+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
46106
46107 jif = jiffies;
46108 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46109 fscache_wait_bit_interruptible,
46110 TASK_INTERRUPTIBLE) != 0) {
46111- fscache_stat(&fscache_n_retrievals_intr);
46112+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46113 _leave(" = -ERESTARTSYS");
46114 return -ERESTARTSYS;
46115 }
46116@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46117 */
46118 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46119 struct fscache_retrieval *op,
46120- atomic_t *stat_op_waits,
46121- atomic_t *stat_object_dead)
46122+ atomic_unchecked_t *stat_op_waits,
46123+ atomic_unchecked_t *stat_object_dead)
46124 {
46125 int ret;
46126
46127@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46128 goto check_if_dead;
46129
46130 _debug(">>> WT");
46131- fscache_stat(stat_op_waits);
46132+ fscache_stat_unchecked(stat_op_waits);
46133 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46134 fscache_wait_bit_interruptible,
46135 TASK_INTERRUPTIBLE) < 0) {
46136@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46137
46138 check_if_dead:
46139 if (unlikely(fscache_object_is_dead(object))) {
46140- fscache_stat(stat_object_dead);
46141+ fscache_stat_unchecked(stat_object_dead);
46142 return -ENOBUFS;
46143 }
46144 return 0;
46145@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46146
46147 _enter("%p,%p,,,", cookie, page);
46148
46149- fscache_stat(&fscache_n_retrievals);
46150+ fscache_stat_unchecked(&fscache_n_retrievals);
46151
46152 if (hlist_empty(&cookie->backing_objects))
46153 goto nobufs;
46154@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46155 goto nobufs_unlock;
46156 spin_unlock(&cookie->lock);
46157
46158- fscache_stat(&fscache_n_retrieval_ops);
46159+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46160
46161 /* pin the netfs read context in case we need to do the actual netfs
46162 * read because we've encountered a cache read failure */
46163@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46164
46165 error:
46166 if (ret == -ENOMEM)
46167- fscache_stat(&fscache_n_retrievals_nomem);
46168+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46169 else if (ret == -ERESTARTSYS)
46170- fscache_stat(&fscache_n_retrievals_intr);
46171+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46172 else if (ret == -ENODATA)
46173- fscache_stat(&fscache_n_retrievals_nodata);
46174+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46175 else if (ret < 0)
46176- fscache_stat(&fscache_n_retrievals_nobufs);
46177+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46178 else
46179- fscache_stat(&fscache_n_retrievals_ok);
46180+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46181
46182 fscache_put_retrieval(op);
46183 _leave(" = %d", ret);
46184@@ -429,7 +429,7 @@ nobufs_unlock:
46185 spin_unlock(&cookie->lock);
46186 kfree(op);
46187 nobufs:
46188- fscache_stat(&fscache_n_retrievals_nobufs);
46189+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46190 _leave(" = -ENOBUFS");
46191 return -ENOBUFS;
46192 }
46193@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46194
46195 _enter("%p,,%d,,,", cookie, *nr_pages);
46196
46197- fscache_stat(&fscache_n_retrievals);
46198+ fscache_stat_unchecked(&fscache_n_retrievals);
46199
46200 if (hlist_empty(&cookie->backing_objects))
46201 goto nobufs;
46202@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46203 goto nobufs_unlock;
46204 spin_unlock(&cookie->lock);
46205
46206- fscache_stat(&fscache_n_retrieval_ops);
46207+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46208
46209 /* pin the netfs read context in case we need to do the actual netfs
46210 * read because we've encountered a cache read failure */
46211@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46212
46213 error:
46214 if (ret == -ENOMEM)
46215- fscache_stat(&fscache_n_retrievals_nomem);
46216+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46217 else if (ret == -ERESTARTSYS)
46218- fscache_stat(&fscache_n_retrievals_intr);
46219+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46220 else if (ret == -ENODATA)
46221- fscache_stat(&fscache_n_retrievals_nodata);
46222+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46223 else if (ret < 0)
46224- fscache_stat(&fscache_n_retrievals_nobufs);
46225+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46226 else
46227- fscache_stat(&fscache_n_retrievals_ok);
46228+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46229
46230 fscache_put_retrieval(op);
46231 _leave(" = %d", ret);
46232@@ -545,7 +545,7 @@ nobufs_unlock:
46233 spin_unlock(&cookie->lock);
46234 kfree(op);
46235 nobufs:
46236- fscache_stat(&fscache_n_retrievals_nobufs);
46237+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46238 _leave(" = -ENOBUFS");
46239 return -ENOBUFS;
46240 }
46241@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46242
46243 _enter("%p,%p,,,", cookie, page);
46244
46245- fscache_stat(&fscache_n_allocs);
46246+ fscache_stat_unchecked(&fscache_n_allocs);
46247
46248 if (hlist_empty(&cookie->backing_objects))
46249 goto nobufs;
46250@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46251 goto nobufs_unlock;
46252 spin_unlock(&cookie->lock);
46253
46254- fscache_stat(&fscache_n_alloc_ops);
46255+ fscache_stat_unchecked(&fscache_n_alloc_ops);
46256
46257 ret = fscache_wait_for_retrieval_activation(
46258 object, op,
46259@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46260
46261 error:
46262 if (ret == -ERESTARTSYS)
46263- fscache_stat(&fscache_n_allocs_intr);
46264+ fscache_stat_unchecked(&fscache_n_allocs_intr);
46265 else if (ret < 0)
46266- fscache_stat(&fscache_n_allocs_nobufs);
46267+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46268 else
46269- fscache_stat(&fscache_n_allocs_ok);
46270+ fscache_stat_unchecked(&fscache_n_allocs_ok);
46271
46272 fscache_put_retrieval(op);
46273 _leave(" = %d", ret);
46274@@ -625,7 +625,7 @@ nobufs_unlock:
46275 spin_unlock(&cookie->lock);
46276 kfree(op);
46277 nobufs:
46278- fscache_stat(&fscache_n_allocs_nobufs);
46279+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46280 _leave(" = -ENOBUFS");
46281 return -ENOBUFS;
46282 }
46283@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46284
46285 spin_lock(&cookie->stores_lock);
46286
46287- fscache_stat(&fscache_n_store_calls);
46288+ fscache_stat_unchecked(&fscache_n_store_calls);
46289
46290 /* find a page to store */
46291 page = NULL;
46292@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46293 page = results[0];
46294 _debug("gang %d [%lx]", n, page->index);
46295 if (page->index > op->store_limit) {
46296- fscache_stat(&fscache_n_store_pages_over_limit);
46297+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46298 goto superseded;
46299 }
46300
46301@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46302 spin_unlock(&cookie->stores_lock);
46303 spin_unlock(&object->lock);
46304
46305- fscache_stat(&fscache_n_store_pages);
46306+ fscache_stat_unchecked(&fscache_n_store_pages);
46307 fscache_stat(&fscache_n_cop_write_page);
46308 ret = object->cache->ops->write_page(op, page);
46309 fscache_stat_d(&fscache_n_cop_write_page);
46310@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46311 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46312 ASSERT(PageFsCache(page));
46313
46314- fscache_stat(&fscache_n_stores);
46315+ fscache_stat_unchecked(&fscache_n_stores);
46316
46317 op = kzalloc(sizeof(*op), GFP_NOIO);
46318 if (!op)
46319@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46320 spin_unlock(&cookie->stores_lock);
46321 spin_unlock(&object->lock);
46322
46323- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46324+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46325 op->store_limit = object->store_limit;
46326
46327 if (fscache_submit_op(object, &op->op) < 0)
46328@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46329
46330 spin_unlock(&cookie->lock);
46331 radix_tree_preload_end();
46332- fscache_stat(&fscache_n_store_ops);
46333- fscache_stat(&fscache_n_stores_ok);
46334+ fscache_stat_unchecked(&fscache_n_store_ops);
46335+ fscache_stat_unchecked(&fscache_n_stores_ok);
46336
46337 /* the work queue now carries its own ref on the object */
46338 fscache_put_operation(&op->op);
46339@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46340 return 0;
46341
46342 already_queued:
46343- fscache_stat(&fscache_n_stores_again);
46344+ fscache_stat_unchecked(&fscache_n_stores_again);
46345 already_pending:
46346 spin_unlock(&cookie->stores_lock);
46347 spin_unlock(&object->lock);
46348 spin_unlock(&cookie->lock);
46349 radix_tree_preload_end();
46350 kfree(op);
46351- fscache_stat(&fscache_n_stores_ok);
46352+ fscache_stat_unchecked(&fscache_n_stores_ok);
46353 _leave(" = 0");
46354 return 0;
46355
46356@@ -851,14 +851,14 @@ nobufs:
46357 spin_unlock(&cookie->lock);
46358 radix_tree_preload_end();
46359 kfree(op);
46360- fscache_stat(&fscache_n_stores_nobufs);
46361+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
46362 _leave(" = -ENOBUFS");
46363 return -ENOBUFS;
46364
46365 nomem_free:
46366 kfree(op);
46367 nomem:
46368- fscache_stat(&fscache_n_stores_oom);
46369+ fscache_stat_unchecked(&fscache_n_stores_oom);
46370 _leave(" = -ENOMEM");
46371 return -ENOMEM;
46372 }
46373@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46374 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46375 ASSERTCMP(page, !=, NULL);
46376
46377- fscache_stat(&fscache_n_uncaches);
46378+ fscache_stat_unchecked(&fscache_n_uncaches);
46379
46380 /* cache withdrawal may beat us to it */
46381 if (!PageFsCache(page))
46382@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46383 unsigned long loop;
46384
46385 #ifdef CONFIG_FSCACHE_STATS
46386- atomic_add(pagevec->nr, &fscache_n_marks);
46387+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46388 #endif
46389
46390 for (loop = 0; loop < pagevec->nr; loop++) {
46391diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46392index 4765190..2a067f2 100644
46393--- a/fs/fscache/stats.c
46394+++ b/fs/fscache/stats.c
46395@@ -18,95 +18,95 @@
46396 /*
46397 * operation counters
46398 */
46399-atomic_t fscache_n_op_pend;
46400-atomic_t fscache_n_op_run;
46401-atomic_t fscache_n_op_enqueue;
46402-atomic_t fscache_n_op_requeue;
46403-atomic_t fscache_n_op_deferred_release;
46404-atomic_t fscache_n_op_release;
46405-atomic_t fscache_n_op_gc;
46406-atomic_t fscache_n_op_cancelled;
46407-atomic_t fscache_n_op_rejected;
46408+atomic_unchecked_t fscache_n_op_pend;
46409+atomic_unchecked_t fscache_n_op_run;
46410+atomic_unchecked_t fscache_n_op_enqueue;
46411+atomic_unchecked_t fscache_n_op_requeue;
46412+atomic_unchecked_t fscache_n_op_deferred_release;
46413+atomic_unchecked_t fscache_n_op_release;
46414+atomic_unchecked_t fscache_n_op_gc;
46415+atomic_unchecked_t fscache_n_op_cancelled;
46416+atomic_unchecked_t fscache_n_op_rejected;
46417
46418-atomic_t fscache_n_attr_changed;
46419-atomic_t fscache_n_attr_changed_ok;
46420-atomic_t fscache_n_attr_changed_nobufs;
46421-atomic_t fscache_n_attr_changed_nomem;
46422-atomic_t fscache_n_attr_changed_calls;
46423+atomic_unchecked_t fscache_n_attr_changed;
46424+atomic_unchecked_t fscache_n_attr_changed_ok;
46425+atomic_unchecked_t fscache_n_attr_changed_nobufs;
46426+atomic_unchecked_t fscache_n_attr_changed_nomem;
46427+atomic_unchecked_t fscache_n_attr_changed_calls;
46428
46429-atomic_t fscache_n_allocs;
46430-atomic_t fscache_n_allocs_ok;
46431-atomic_t fscache_n_allocs_wait;
46432-atomic_t fscache_n_allocs_nobufs;
46433-atomic_t fscache_n_allocs_intr;
46434-atomic_t fscache_n_allocs_object_dead;
46435-atomic_t fscache_n_alloc_ops;
46436-atomic_t fscache_n_alloc_op_waits;
46437+atomic_unchecked_t fscache_n_allocs;
46438+atomic_unchecked_t fscache_n_allocs_ok;
46439+atomic_unchecked_t fscache_n_allocs_wait;
46440+atomic_unchecked_t fscache_n_allocs_nobufs;
46441+atomic_unchecked_t fscache_n_allocs_intr;
46442+atomic_unchecked_t fscache_n_allocs_object_dead;
46443+atomic_unchecked_t fscache_n_alloc_ops;
46444+atomic_unchecked_t fscache_n_alloc_op_waits;
46445
46446-atomic_t fscache_n_retrievals;
46447-atomic_t fscache_n_retrievals_ok;
46448-atomic_t fscache_n_retrievals_wait;
46449-atomic_t fscache_n_retrievals_nodata;
46450-atomic_t fscache_n_retrievals_nobufs;
46451-atomic_t fscache_n_retrievals_intr;
46452-atomic_t fscache_n_retrievals_nomem;
46453-atomic_t fscache_n_retrievals_object_dead;
46454-atomic_t fscache_n_retrieval_ops;
46455-atomic_t fscache_n_retrieval_op_waits;
46456+atomic_unchecked_t fscache_n_retrievals;
46457+atomic_unchecked_t fscache_n_retrievals_ok;
46458+atomic_unchecked_t fscache_n_retrievals_wait;
46459+atomic_unchecked_t fscache_n_retrievals_nodata;
46460+atomic_unchecked_t fscache_n_retrievals_nobufs;
46461+atomic_unchecked_t fscache_n_retrievals_intr;
46462+atomic_unchecked_t fscache_n_retrievals_nomem;
46463+atomic_unchecked_t fscache_n_retrievals_object_dead;
46464+atomic_unchecked_t fscache_n_retrieval_ops;
46465+atomic_unchecked_t fscache_n_retrieval_op_waits;
46466
46467-atomic_t fscache_n_stores;
46468-atomic_t fscache_n_stores_ok;
46469-atomic_t fscache_n_stores_again;
46470-atomic_t fscache_n_stores_nobufs;
46471-atomic_t fscache_n_stores_oom;
46472-atomic_t fscache_n_store_ops;
46473-atomic_t fscache_n_store_calls;
46474-atomic_t fscache_n_store_pages;
46475-atomic_t fscache_n_store_radix_deletes;
46476-atomic_t fscache_n_store_pages_over_limit;
46477+atomic_unchecked_t fscache_n_stores;
46478+atomic_unchecked_t fscache_n_stores_ok;
46479+atomic_unchecked_t fscache_n_stores_again;
46480+atomic_unchecked_t fscache_n_stores_nobufs;
46481+atomic_unchecked_t fscache_n_stores_oom;
46482+atomic_unchecked_t fscache_n_store_ops;
46483+atomic_unchecked_t fscache_n_store_calls;
46484+atomic_unchecked_t fscache_n_store_pages;
46485+atomic_unchecked_t fscache_n_store_radix_deletes;
46486+atomic_unchecked_t fscache_n_store_pages_over_limit;
46487
46488-atomic_t fscache_n_store_vmscan_not_storing;
46489-atomic_t fscache_n_store_vmscan_gone;
46490-atomic_t fscache_n_store_vmscan_busy;
46491-atomic_t fscache_n_store_vmscan_cancelled;
46492+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46493+atomic_unchecked_t fscache_n_store_vmscan_gone;
46494+atomic_unchecked_t fscache_n_store_vmscan_busy;
46495+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46496
46497-atomic_t fscache_n_marks;
46498-atomic_t fscache_n_uncaches;
46499+atomic_unchecked_t fscache_n_marks;
46500+atomic_unchecked_t fscache_n_uncaches;
46501
46502-atomic_t fscache_n_acquires;
46503-atomic_t fscache_n_acquires_null;
46504-atomic_t fscache_n_acquires_no_cache;
46505-atomic_t fscache_n_acquires_ok;
46506-atomic_t fscache_n_acquires_nobufs;
46507-atomic_t fscache_n_acquires_oom;
46508+atomic_unchecked_t fscache_n_acquires;
46509+atomic_unchecked_t fscache_n_acquires_null;
46510+atomic_unchecked_t fscache_n_acquires_no_cache;
46511+atomic_unchecked_t fscache_n_acquires_ok;
46512+atomic_unchecked_t fscache_n_acquires_nobufs;
46513+atomic_unchecked_t fscache_n_acquires_oom;
46514
46515-atomic_t fscache_n_updates;
46516-atomic_t fscache_n_updates_null;
46517-atomic_t fscache_n_updates_run;
46518+atomic_unchecked_t fscache_n_updates;
46519+atomic_unchecked_t fscache_n_updates_null;
46520+atomic_unchecked_t fscache_n_updates_run;
46521
46522-atomic_t fscache_n_relinquishes;
46523-atomic_t fscache_n_relinquishes_null;
46524-atomic_t fscache_n_relinquishes_waitcrt;
46525-atomic_t fscache_n_relinquishes_retire;
46526+atomic_unchecked_t fscache_n_relinquishes;
46527+atomic_unchecked_t fscache_n_relinquishes_null;
46528+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46529+atomic_unchecked_t fscache_n_relinquishes_retire;
46530
46531-atomic_t fscache_n_cookie_index;
46532-atomic_t fscache_n_cookie_data;
46533-atomic_t fscache_n_cookie_special;
46534+atomic_unchecked_t fscache_n_cookie_index;
46535+atomic_unchecked_t fscache_n_cookie_data;
46536+atomic_unchecked_t fscache_n_cookie_special;
46537
46538-atomic_t fscache_n_object_alloc;
46539-atomic_t fscache_n_object_no_alloc;
46540-atomic_t fscache_n_object_lookups;
46541-atomic_t fscache_n_object_lookups_negative;
46542-atomic_t fscache_n_object_lookups_positive;
46543-atomic_t fscache_n_object_lookups_timed_out;
46544-atomic_t fscache_n_object_created;
46545-atomic_t fscache_n_object_avail;
46546-atomic_t fscache_n_object_dead;
46547+atomic_unchecked_t fscache_n_object_alloc;
46548+atomic_unchecked_t fscache_n_object_no_alloc;
46549+atomic_unchecked_t fscache_n_object_lookups;
46550+atomic_unchecked_t fscache_n_object_lookups_negative;
46551+atomic_unchecked_t fscache_n_object_lookups_positive;
46552+atomic_unchecked_t fscache_n_object_lookups_timed_out;
46553+atomic_unchecked_t fscache_n_object_created;
46554+atomic_unchecked_t fscache_n_object_avail;
46555+atomic_unchecked_t fscache_n_object_dead;
46556
46557-atomic_t fscache_n_checkaux_none;
46558-atomic_t fscache_n_checkaux_okay;
46559-atomic_t fscache_n_checkaux_update;
46560-atomic_t fscache_n_checkaux_obsolete;
46561+atomic_unchecked_t fscache_n_checkaux_none;
46562+atomic_unchecked_t fscache_n_checkaux_okay;
46563+atomic_unchecked_t fscache_n_checkaux_update;
46564+atomic_unchecked_t fscache_n_checkaux_obsolete;
46565
46566 atomic_t fscache_n_cop_alloc_object;
46567 atomic_t fscache_n_cop_lookup_object;
46568@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46569 seq_puts(m, "FS-Cache statistics\n");
46570
46571 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46572- atomic_read(&fscache_n_cookie_index),
46573- atomic_read(&fscache_n_cookie_data),
46574- atomic_read(&fscache_n_cookie_special));
46575+ atomic_read_unchecked(&fscache_n_cookie_index),
46576+ atomic_read_unchecked(&fscache_n_cookie_data),
46577+ atomic_read_unchecked(&fscache_n_cookie_special));
46578
46579 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46580- atomic_read(&fscache_n_object_alloc),
46581- atomic_read(&fscache_n_object_no_alloc),
46582- atomic_read(&fscache_n_object_avail),
46583- atomic_read(&fscache_n_object_dead));
46584+ atomic_read_unchecked(&fscache_n_object_alloc),
46585+ atomic_read_unchecked(&fscache_n_object_no_alloc),
46586+ atomic_read_unchecked(&fscache_n_object_avail),
46587+ atomic_read_unchecked(&fscache_n_object_dead));
46588 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46589- atomic_read(&fscache_n_checkaux_none),
46590- atomic_read(&fscache_n_checkaux_okay),
46591- atomic_read(&fscache_n_checkaux_update),
46592- atomic_read(&fscache_n_checkaux_obsolete));
46593+ atomic_read_unchecked(&fscache_n_checkaux_none),
46594+ atomic_read_unchecked(&fscache_n_checkaux_okay),
46595+ atomic_read_unchecked(&fscache_n_checkaux_update),
46596+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46597
46598 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46599- atomic_read(&fscache_n_marks),
46600- atomic_read(&fscache_n_uncaches));
46601+ atomic_read_unchecked(&fscache_n_marks),
46602+ atomic_read_unchecked(&fscache_n_uncaches));
46603
46604 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46605 " oom=%u\n",
46606- atomic_read(&fscache_n_acquires),
46607- atomic_read(&fscache_n_acquires_null),
46608- atomic_read(&fscache_n_acquires_no_cache),
46609- atomic_read(&fscache_n_acquires_ok),
46610- atomic_read(&fscache_n_acquires_nobufs),
46611- atomic_read(&fscache_n_acquires_oom));
46612+ atomic_read_unchecked(&fscache_n_acquires),
46613+ atomic_read_unchecked(&fscache_n_acquires_null),
46614+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
46615+ atomic_read_unchecked(&fscache_n_acquires_ok),
46616+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
46617+ atomic_read_unchecked(&fscache_n_acquires_oom));
46618
46619 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46620- atomic_read(&fscache_n_object_lookups),
46621- atomic_read(&fscache_n_object_lookups_negative),
46622- atomic_read(&fscache_n_object_lookups_positive),
46623- atomic_read(&fscache_n_object_created),
46624- atomic_read(&fscache_n_object_lookups_timed_out));
46625+ atomic_read_unchecked(&fscache_n_object_lookups),
46626+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
46627+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
46628+ atomic_read_unchecked(&fscache_n_object_created),
46629+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46630
46631 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46632- atomic_read(&fscache_n_updates),
46633- atomic_read(&fscache_n_updates_null),
46634- atomic_read(&fscache_n_updates_run));
46635+ atomic_read_unchecked(&fscache_n_updates),
46636+ atomic_read_unchecked(&fscache_n_updates_null),
46637+ atomic_read_unchecked(&fscache_n_updates_run));
46638
46639 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46640- atomic_read(&fscache_n_relinquishes),
46641- atomic_read(&fscache_n_relinquishes_null),
46642- atomic_read(&fscache_n_relinquishes_waitcrt),
46643- atomic_read(&fscache_n_relinquishes_retire));
46644+ atomic_read_unchecked(&fscache_n_relinquishes),
46645+ atomic_read_unchecked(&fscache_n_relinquishes_null),
46646+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46647+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
46648
46649 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46650- atomic_read(&fscache_n_attr_changed),
46651- atomic_read(&fscache_n_attr_changed_ok),
46652- atomic_read(&fscache_n_attr_changed_nobufs),
46653- atomic_read(&fscache_n_attr_changed_nomem),
46654- atomic_read(&fscache_n_attr_changed_calls));
46655+ atomic_read_unchecked(&fscache_n_attr_changed),
46656+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
46657+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46658+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46659+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
46660
46661 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46662- atomic_read(&fscache_n_allocs),
46663- atomic_read(&fscache_n_allocs_ok),
46664- atomic_read(&fscache_n_allocs_wait),
46665- atomic_read(&fscache_n_allocs_nobufs),
46666- atomic_read(&fscache_n_allocs_intr));
46667+ atomic_read_unchecked(&fscache_n_allocs),
46668+ atomic_read_unchecked(&fscache_n_allocs_ok),
46669+ atomic_read_unchecked(&fscache_n_allocs_wait),
46670+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
46671+ atomic_read_unchecked(&fscache_n_allocs_intr));
46672 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46673- atomic_read(&fscache_n_alloc_ops),
46674- atomic_read(&fscache_n_alloc_op_waits),
46675- atomic_read(&fscache_n_allocs_object_dead));
46676+ atomic_read_unchecked(&fscache_n_alloc_ops),
46677+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
46678+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
46679
46680 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46681 " int=%u oom=%u\n",
46682- atomic_read(&fscache_n_retrievals),
46683- atomic_read(&fscache_n_retrievals_ok),
46684- atomic_read(&fscache_n_retrievals_wait),
46685- atomic_read(&fscache_n_retrievals_nodata),
46686- atomic_read(&fscache_n_retrievals_nobufs),
46687- atomic_read(&fscache_n_retrievals_intr),
46688- atomic_read(&fscache_n_retrievals_nomem));
46689+ atomic_read_unchecked(&fscache_n_retrievals),
46690+ atomic_read_unchecked(&fscache_n_retrievals_ok),
46691+ atomic_read_unchecked(&fscache_n_retrievals_wait),
46692+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
46693+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46694+ atomic_read_unchecked(&fscache_n_retrievals_intr),
46695+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
46696 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46697- atomic_read(&fscache_n_retrieval_ops),
46698- atomic_read(&fscache_n_retrieval_op_waits),
46699- atomic_read(&fscache_n_retrievals_object_dead));
46700+ atomic_read_unchecked(&fscache_n_retrieval_ops),
46701+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46702+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46703
46704 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46705- atomic_read(&fscache_n_stores),
46706- atomic_read(&fscache_n_stores_ok),
46707- atomic_read(&fscache_n_stores_again),
46708- atomic_read(&fscache_n_stores_nobufs),
46709- atomic_read(&fscache_n_stores_oom));
46710+ atomic_read_unchecked(&fscache_n_stores),
46711+ atomic_read_unchecked(&fscache_n_stores_ok),
46712+ atomic_read_unchecked(&fscache_n_stores_again),
46713+ atomic_read_unchecked(&fscache_n_stores_nobufs),
46714+ atomic_read_unchecked(&fscache_n_stores_oom));
46715 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46716- atomic_read(&fscache_n_store_ops),
46717- atomic_read(&fscache_n_store_calls),
46718- atomic_read(&fscache_n_store_pages),
46719- atomic_read(&fscache_n_store_radix_deletes),
46720- atomic_read(&fscache_n_store_pages_over_limit));
46721+ atomic_read_unchecked(&fscache_n_store_ops),
46722+ atomic_read_unchecked(&fscache_n_store_calls),
46723+ atomic_read_unchecked(&fscache_n_store_pages),
46724+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
46725+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46726
46727 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46728- atomic_read(&fscache_n_store_vmscan_not_storing),
46729- atomic_read(&fscache_n_store_vmscan_gone),
46730- atomic_read(&fscache_n_store_vmscan_busy),
46731- atomic_read(&fscache_n_store_vmscan_cancelled));
46732+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46733+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46734+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46735+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46736
46737 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46738- atomic_read(&fscache_n_op_pend),
46739- atomic_read(&fscache_n_op_run),
46740- atomic_read(&fscache_n_op_enqueue),
46741- atomic_read(&fscache_n_op_cancelled),
46742- atomic_read(&fscache_n_op_rejected));
46743+ atomic_read_unchecked(&fscache_n_op_pend),
46744+ atomic_read_unchecked(&fscache_n_op_run),
46745+ atomic_read_unchecked(&fscache_n_op_enqueue),
46746+ atomic_read_unchecked(&fscache_n_op_cancelled),
46747+ atomic_read_unchecked(&fscache_n_op_rejected));
46748 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46749- atomic_read(&fscache_n_op_deferred_release),
46750- atomic_read(&fscache_n_op_release),
46751- atomic_read(&fscache_n_op_gc));
46752+ atomic_read_unchecked(&fscache_n_op_deferred_release),
46753+ atomic_read_unchecked(&fscache_n_op_release),
46754+ atomic_read_unchecked(&fscache_n_op_gc));
46755
46756 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46757 atomic_read(&fscache_n_cop_alloc_object),
46758diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46759index 3426521..3b75162 100644
46760--- a/fs/fuse/cuse.c
46761+++ b/fs/fuse/cuse.c
46762@@ -587,10 +587,12 @@ static int __init cuse_init(void)
46763 INIT_LIST_HEAD(&cuse_conntbl[i]);
46764
46765 /* inherit and extend fuse_dev_operations */
46766- cuse_channel_fops = fuse_dev_operations;
46767- cuse_channel_fops.owner = THIS_MODULE;
46768- cuse_channel_fops.open = cuse_channel_open;
46769- cuse_channel_fops.release = cuse_channel_release;
46770+ pax_open_kernel();
46771+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46772+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46773+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
46774+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
46775+ pax_close_kernel();
46776
46777 cuse_class = class_create(THIS_MODULE, "cuse");
46778 if (IS_ERR(cuse_class))
46779diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46780index 7df2b5e..5804aa7 100644
46781--- a/fs/fuse/dev.c
46782+++ b/fs/fuse/dev.c
46783@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46784 ret = 0;
46785 pipe_lock(pipe);
46786
46787- if (!pipe->readers) {
46788+ if (!atomic_read(&pipe->readers)) {
46789 send_sig(SIGPIPE, current, 0);
46790 if (!ret)
46791 ret = -EPIPE;
46792diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46793index 334e0b1..fc571e8 100644
46794--- a/fs/fuse/dir.c
46795+++ b/fs/fuse/dir.c
46796@@ -1189,7 +1189,7 @@ static char *read_link(struct dentry *dentry)
46797 return link;
46798 }
46799
46800-static void free_link(char *link)
46801+static void free_link(const char *link)
46802 {
46803 if (!IS_ERR(link))
46804 free_page((unsigned long) link);
46805diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46806index a9ba244..d9df391 100644
46807--- a/fs/gfs2/inode.c
46808+++ b/fs/gfs2/inode.c
46809@@ -1496,7 +1496,7 @@ out:
46810
46811 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46812 {
46813- char *s = nd_get_link(nd);
46814+ const char *s = nd_get_link(nd);
46815 if (!IS_ERR(s))
46816 kfree(s);
46817 }
46818diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46819index cc9281b..58996fb 100644
46820--- a/fs/hugetlbfs/inode.c
46821+++ b/fs/hugetlbfs/inode.c
46822@@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46823 .kill_sb = kill_litter_super,
46824 };
46825
46826-static struct vfsmount *hugetlbfs_vfsmount;
46827+struct vfsmount *hugetlbfs_vfsmount;
46828
46829 static int can_do_hugetlb_shm(void)
46830 {
46831diff --git a/fs/inode.c b/fs/inode.c
46832index c99163b..a11ad40 100644
46833--- a/fs/inode.c
46834+++ b/fs/inode.c
46835@@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
46836
46837 #ifdef CONFIG_SMP
46838 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46839- static atomic_t shared_last_ino;
46840- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46841+ static atomic_unchecked_t shared_last_ino;
46842+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46843
46844 res = next - LAST_INO_BATCH;
46845 }
46846diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46847index 4a6cf28..d3a29d3 100644
46848--- a/fs/jffs2/erase.c
46849+++ b/fs/jffs2/erase.c
46850@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46851 struct jffs2_unknown_node marker = {
46852 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46853 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46854- .totlen = cpu_to_je32(c->cleanmarker_size)
46855+ .totlen = cpu_to_je32(c->cleanmarker_size),
46856+ .hdr_crc = cpu_to_je32(0)
46857 };
46858
46859 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46860diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46861index 6f4529d..bf12806 100644
46862--- a/fs/jffs2/wbuf.c
46863+++ b/fs/jffs2/wbuf.c
46864@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46865 {
46866 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46867 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46868- .totlen = constant_cpu_to_je32(8)
46869+ .totlen = constant_cpu_to_je32(8),
46870+ .hdr_crc = constant_cpu_to_je32(0)
46871 };
46872
46873 /*
46874diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46875index 4a82950..bcaa0cb 100644
46876--- a/fs/jfs/super.c
46877+++ b/fs/jfs/super.c
46878@@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46879
46880 jfs_inode_cachep =
46881 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46882- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46883+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46884 init_once);
46885 if (jfs_inode_cachep == NULL)
46886 return -ENOMEM;
46887diff --git a/fs/libfs.c b/fs/libfs.c
46888index f86ec27..4734776 100644
46889--- a/fs/libfs.c
46890+++ b/fs/libfs.c
46891@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46892
46893 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46894 struct dentry *next;
46895+ char d_name[sizeof(next->d_iname)];
46896+ const unsigned char *name;
46897+
46898 next = list_entry(p, struct dentry, d_u.d_child);
46899 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46900 if (!simple_positive(next)) {
46901@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46902
46903 spin_unlock(&next->d_lock);
46904 spin_unlock(&dentry->d_lock);
46905- if (filldir(dirent, next->d_name.name,
46906+ name = next->d_name.name;
46907+ if (name == next->d_iname) {
46908+ memcpy(d_name, name, next->d_name.len);
46909+ name = d_name;
46910+ }
46911+ if (filldir(dirent, name,
46912 next->d_name.len, filp->f_pos,
46913 next->d_inode->i_ino,
46914 dt_type(next->d_inode)) < 0)
46915diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46916index 8392cb8..80d6193 100644
46917--- a/fs/lockd/clntproc.c
46918+++ b/fs/lockd/clntproc.c
46919@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46920 /*
46921 * Cookie counter for NLM requests
46922 */
46923-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46924+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46925
46926 void nlmclnt_next_cookie(struct nlm_cookie *c)
46927 {
46928- u32 cookie = atomic_inc_return(&nlm_cookie);
46929+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46930
46931 memcpy(c->data, &cookie, 4);
46932 c->len=4;
46933diff --git a/fs/locks.c b/fs/locks.c
46934index fce6238..34e929c 100644
46935--- a/fs/locks.c
46936+++ b/fs/locks.c
46937@@ -308,7 +308,7 @@ static int flock_make_lock(struct file *filp, struct file_lock **lock,
46938 return 0;
46939 }
46940
46941-static int assign_type(struct file_lock *fl, int type)
46942+static int assign_type(struct file_lock *fl, long type)
46943 {
46944 switch (type) {
46945 case F_RDLCK:
46946@@ -445,7 +445,7 @@ static const struct lock_manager_operations lease_manager_ops = {
46947 /*
46948 * Initialize a lease, use the default lock manager operations
46949 */
46950-static int lease_init(struct file *filp, int type, struct file_lock *fl)
46951+static int lease_init(struct file *filp, long type, struct file_lock *fl)
46952 {
46953 if (assign_type(fl, type) != 0)
46954 return -EINVAL;
46955@@ -463,7 +463,7 @@ static int lease_init(struct file *filp, int type, struct file_lock *fl)
46956 }
46957
46958 /* Allocate a file_lock initialised to this type of lease */
46959-static struct file_lock *lease_alloc(struct file *filp, int type)
46960+static struct file_lock *lease_alloc(struct file *filp, long type)
46961 {
46962 struct file_lock *fl = locks_alloc_lock();
46963 int error = -ENOMEM;
46964@@ -2076,16 +2076,16 @@ void locks_remove_flock(struct file *filp)
46965 return;
46966
46967 if (filp->f_op && filp->f_op->flock) {
46968- struct file_lock fl = {
46969+ struct file_lock flock = {
46970 .fl_pid = current->tgid,
46971 .fl_file = filp,
46972 .fl_flags = FL_FLOCK,
46973 .fl_type = F_UNLCK,
46974 .fl_end = OFFSET_MAX,
46975 };
46976- filp->f_op->flock(filp, F_SETLKW, &fl);
46977- if (fl.fl_ops && fl.fl_ops->fl_release_private)
46978- fl.fl_ops->fl_release_private(&fl);
46979+ filp->f_op->flock(filp, F_SETLKW, &flock);
46980+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
46981+ flock.fl_ops->fl_release_private(&flock);
46982 }
46983
46984 lock_flocks();
46985diff --git a/fs/namei.c b/fs/namei.c
46986index 7d69419..1487852 100644
46987--- a/fs/namei.c
46988+++ b/fs/namei.c
46989@@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
46990 if (ret != -EACCES)
46991 return ret;
46992
46993+#ifdef CONFIG_GRKERNSEC
46994+ /* we'll block if we have to log due to a denied capability use */
46995+ if (mask & MAY_NOT_BLOCK)
46996+ return -ECHILD;
46997+#endif
46998+
46999 if (S_ISDIR(inode->i_mode)) {
47000 /* DACs are overridable for directories */
47001- if (inode_capable(inode, CAP_DAC_OVERRIDE))
47002- return 0;
47003 if (!(mask & MAY_WRITE))
47004- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47005+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47006+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47007 return 0;
47008+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
47009+ return 0;
47010 return -EACCES;
47011 }
47012 /*
47013+ * Searching includes executable on directories, else just read.
47014+ */
47015+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47016+ if (mask == MAY_READ)
47017+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47018+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47019+ return 0;
47020+
47021+ /*
47022 * Read/write DACs are always overridable.
47023 * Executable DACs are overridable when there is
47024 * at least one exec bit set.
47025@@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47026 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47027 return 0;
47028
47029- /*
47030- * Searching includes executable on directories, else just read.
47031- */
47032- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47033- if (mask == MAY_READ)
47034- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47035- return 0;
47036-
47037 return -EACCES;
47038 }
47039
47040@@ -639,11 +647,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47041 return error;
47042 }
47043
47044+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
47045+ dentry->d_inode, dentry, nd->path.mnt)) {
47046+ error = -EACCES;
47047+ *p = ERR_PTR(error); /* no ->put_link(), please */
47048+ path_put(&nd->path);
47049+ return error;
47050+ }
47051+
47052 nd->last_type = LAST_BIND;
47053 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47054 error = PTR_ERR(*p);
47055 if (!IS_ERR(*p)) {
47056- char *s = nd_get_link(nd);
47057+ const char *s = nd_get_link(nd);
47058 error = 0;
47059 if (s)
47060 error = __vfs_follow_link(nd, s);
47061@@ -1386,6 +1402,9 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47062 if (!res)
47063 res = walk_component(nd, path, &nd->last,
47064 nd->last_type, LOOKUP_FOLLOW);
47065+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode)) {
47066+ res = -EACCES;
47067+ }
47068 put_link(nd, &link, cookie);
47069 } while (res > 0);
47070
47071@@ -1779,6 +1798,9 @@ static int path_lookupat(int dfd, const char *name,
47072 err = follow_link(&link, nd, &cookie);
47073 if (!err)
47074 err = lookup_last(nd, &path);
47075+ if (!err && gr_handle_symlink_owner(&link, nd->inode)) {
47076+ err = -EACCES;
47077+ }
47078 put_link(nd, &link, cookie);
47079 }
47080 }
47081@@ -1786,6 +1808,21 @@ static int path_lookupat(int dfd, const char *name,
47082 if (!err)
47083 err = complete_walk(nd);
47084
47085+ if (!(nd->flags & LOOKUP_PARENT)) {
47086+#ifdef CONFIG_GRKERNSEC
47087+ if (flags & LOOKUP_RCU) {
47088+ if (!err)
47089+ path_put(&nd->path);
47090+ err = -ECHILD;
47091+ } else
47092+#endif
47093+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47094+ if (!err)
47095+ path_put(&nd->path);
47096+ err = -ENOENT;
47097+ }
47098+ }
47099+
47100 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47101 if (!nd->inode->i_op->lookup) {
47102 path_put(&nd->path);
47103@@ -1813,6 +1850,15 @@ static int do_path_lookup(int dfd, const char *name,
47104 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47105
47106 if (likely(!retval)) {
47107+ if (*name != '/' && nd->path.dentry && nd->inode) {
47108+#ifdef CONFIG_GRKERNSEC
47109+ if (flags & LOOKUP_RCU)
47110+ return -ECHILD;
47111+#endif
47112+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47113+ return -ENOENT;
47114+ }
47115+
47116 if (unlikely(!audit_dummy_context())) {
47117 if (nd->path.dentry && nd->inode)
47118 audit_inode(name, nd->path.dentry);
47119@@ -2155,6 +2201,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47120 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47121 return -EPERM;
47122
47123+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47124+ return -EPERM;
47125+ if (gr_handle_rawio(inode))
47126+ return -EPERM;
47127+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47128+ return -EACCES;
47129+
47130 return 0;
47131 }
47132
47133@@ -2220,6 +2273,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47134 error = complete_walk(nd);
47135 if (error)
47136 return ERR_PTR(error);
47137+#ifdef CONFIG_GRKERNSEC
47138+ if (nd->flags & LOOKUP_RCU) {
47139+ error = -ECHILD;
47140+ goto exit;
47141+ }
47142+#endif
47143+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47144+ error = -ENOENT;
47145+ goto exit;
47146+ }
47147 audit_inode(pathname, nd->path.dentry);
47148 if (open_flag & O_CREAT) {
47149 error = -EISDIR;
47150@@ -2230,6 +2293,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47151 error = complete_walk(nd);
47152 if (error)
47153 return ERR_PTR(error);
47154+#ifdef CONFIG_GRKERNSEC
47155+ if (nd->flags & LOOKUP_RCU) {
47156+ error = -ECHILD;
47157+ goto exit;
47158+ }
47159+#endif
47160+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47161+ error = -ENOENT;
47162+ goto exit;
47163+ }
47164 audit_inode(pathname, dir);
47165 goto ok;
47166 }
47167@@ -2285,6 +2358,12 @@ retry_lookup:
47168 /* Negative dentry, just create the file */
47169 if (!dentry->d_inode) {
47170 umode_t mode = op->mode;
47171+
47172+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47173+ error = -EACCES;
47174+ goto exit_mutex_unlock;
47175+ }
47176+
47177 if (!IS_POSIXACL(dir->d_inode))
47178 mode &= ~current_umask();
47179 /*
47180@@ -2308,6 +2387,8 @@ retry_lookup:
47181 error = vfs_create(dir->d_inode, dentry, mode, nd);
47182 if (error)
47183 goto exit_mutex_unlock;
47184+ else
47185+ gr_handle_create(path->dentry, path->mnt);
47186 mutex_unlock(&dir->d_inode->i_mutex);
47187 dput(nd->path.dentry);
47188 nd->path.dentry = dentry;
47189@@ -2317,6 +2398,19 @@ retry_lookup:
47190 /*
47191 * It already exists.
47192 */
47193+
47194+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47195+ error = -ENOENT;
47196+ goto exit_mutex_unlock;
47197+ }
47198+
47199+ /* only check if O_CREAT is specified, all other checks need to go
47200+ into may_open */
47201+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47202+ error = -EACCES;
47203+ goto exit_mutex_unlock;
47204+ }
47205+
47206 mutex_unlock(&dir->d_inode->i_mutex);
47207 audit_inode(pathname, path->dentry);
47208
47209@@ -2367,6 +2461,16 @@ finish_lookup:
47210 path_put(&save_parent);
47211 return ERR_PTR(error);
47212 }
47213+#ifdef CONFIG_GRKERNSEC
47214+ if (nd->flags & LOOKUP_RCU) {
47215+ error = -ECHILD;
47216+ goto exit;
47217+ }
47218+#endif
47219+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47220+ error = -ENOENT;
47221+ goto exit;
47222+ }
47223 error = -EISDIR;
47224 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47225 goto exit;
47226@@ -2476,8 +2580,14 @@ static struct file *path_openat(int dfd, const char *pathname,
47227 error = follow_link(&link, nd, &cookie);
47228 if (unlikely(error))
47229 filp = ERR_PTR(error);
47230- else
47231+ else {
47232 filp = do_last(nd, &path, op, pathname);
47233+ if (!IS_ERR(filp) && gr_handle_symlink_owner(&link, nd->inode)) {
47234+ if (filp)
47235+ fput(filp);
47236+ filp = ERR_PTR(-EACCES);
47237+ }
47238+ }
47239 put_link(nd, &link, cookie);
47240 }
47241 out:
47242@@ -2577,6 +2687,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47243 *path = nd.path;
47244 return dentry;
47245 eexist:
47246+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47247+ dput(dentry);
47248+ dentry = ERR_PTR(-ENOENT);
47249+ goto fail;
47250+ }
47251 dput(dentry);
47252 dentry = ERR_PTR(-EEXIST);
47253 fail:
47254@@ -2599,6 +2714,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47255 }
47256 EXPORT_SYMBOL(user_path_create);
47257
47258+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47259+{
47260+ char *tmp = getname(pathname);
47261+ struct dentry *res;
47262+ if (IS_ERR(tmp))
47263+ return ERR_CAST(tmp);
47264+ res = kern_path_create(dfd, tmp, path, is_dir);
47265+ if (IS_ERR(res))
47266+ putname(tmp);
47267+ else
47268+ *to = tmp;
47269+ return res;
47270+}
47271+
47272 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47273 {
47274 int error = may_create(dir, dentry);
47275@@ -2665,6 +2794,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47276 error = mnt_want_write(path.mnt);
47277 if (error)
47278 goto out_dput;
47279+
47280+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47281+ error = -EPERM;
47282+ goto out_drop_write;
47283+ }
47284+
47285+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47286+ error = -EACCES;
47287+ goto out_drop_write;
47288+ }
47289+
47290 error = security_path_mknod(&path, dentry, mode, dev);
47291 if (error)
47292 goto out_drop_write;
47293@@ -2682,6 +2822,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47294 }
47295 out_drop_write:
47296 mnt_drop_write(path.mnt);
47297+
47298+ if (!error)
47299+ gr_handle_create(dentry, path.mnt);
47300 out_dput:
47301 dput(dentry);
47302 mutex_unlock(&path.dentry->d_inode->i_mutex);
47303@@ -2735,12 +2878,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47304 error = mnt_want_write(path.mnt);
47305 if (error)
47306 goto out_dput;
47307+
47308+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47309+ error = -EACCES;
47310+ goto out_drop_write;
47311+ }
47312+
47313 error = security_path_mkdir(&path, dentry, mode);
47314 if (error)
47315 goto out_drop_write;
47316 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47317 out_drop_write:
47318 mnt_drop_write(path.mnt);
47319+
47320+ if (!error)
47321+ gr_handle_create(dentry, path.mnt);
47322 out_dput:
47323 dput(dentry);
47324 mutex_unlock(&path.dentry->d_inode->i_mutex);
47325@@ -2820,6 +2972,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47326 char * name;
47327 struct dentry *dentry;
47328 struct nameidata nd;
47329+ ino_t saved_ino = 0;
47330+ dev_t saved_dev = 0;
47331
47332 error = user_path_parent(dfd, pathname, &nd, &name);
47333 if (error)
47334@@ -2848,6 +3002,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47335 error = -ENOENT;
47336 goto exit3;
47337 }
47338+
47339+ saved_ino = dentry->d_inode->i_ino;
47340+ saved_dev = gr_get_dev_from_dentry(dentry);
47341+
47342+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47343+ error = -EACCES;
47344+ goto exit3;
47345+ }
47346+
47347 error = mnt_want_write(nd.path.mnt);
47348 if (error)
47349 goto exit3;
47350@@ -2855,6 +3018,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47351 if (error)
47352 goto exit4;
47353 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47354+ if (!error && (saved_dev || saved_ino))
47355+ gr_handle_delete(saved_ino, saved_dev);
47356 exit4:
47357 mnt_drop_write(nd.path.mnt);
47358 exit3:
47359@@ -2917,6 +3082,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47360 struct dentry *dentry;
47361 struct nameidata nd;
47362 struct inode *inode = NULL;
47363+ ino_t saved_ino = 0;
47364+ dev_t saved_dev = 0;
47365
47366 error = user_path_parent(dfd, pathname, &nd, &name);
47367 if (error)
47368@@ -2939,6 +3106,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47369 if (!inode)
47370 goto slashes;
47371 ihold(inode);
47372+
47373+ if (inode->i_nlink <= 1) {
47374+ saved_ino = inode->i_ino;
47375+ saved_dev = gr_get_dev_from_dentry(dentry);
47376+ }
47377+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47378+ error = -EACCES;
47379+ goto exit2;
47380+ }
47381+
47382 error = mnt_want_write(nd.path.mnt);
47383 if (error)
47384 goto exit2;
47385@@ -2946,6 +3123,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47386 if (error)
47387 goto exit3;
47388 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47389+ if (!error && (saved_ino || saved_dev))
47390+ gr_handle_delete(saved_ino, saved_dev);
47391 exit3:
47392 mnt_drop_write(nd.path.mnt);
47393 exit2:
47394@@ -3021,10 +3200,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47395 error = mnt_want_write(path.mnt);
47396 if (error)
47397 goto out_dput;
47398+
47399+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47400+ error = -EACCES;
47401+ goto out_drop_write;
47402+ }
47403+
47404 error = security_path_symlink(&path, dentry, from);
47405 if (error)
47406 goto out_drop_write;
47407 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47408+ if (!error)
47409+ gr_handle_create(dentry, path.mnt);
47410 out_drop_write:
47411 mnt_drop_write(path.mnt);
47412 out_dput:
47413@@ -3099,6 +3286,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47414 {
47415 struct dentry *new_dentry;
47416 struct path old_path, new_path;
47417+ char *to = NULL;
47418 int how = 0;
47419 int error;
47420
47421@@ -3122,7 +3310,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47422 if (error)
47423 return error;
47424
47425- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47426+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47427 error = PTR_ERR(new_dentry);
47428 if (IS_ERR(new_dentry))
47429 goto out;
47430@@ -3133,13 +3321,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47431 error = mnt_want_write(new_path.mnt);
47432 if (error)
47433 goto out_dput;
47434+
47435+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47436+ old_path.dentry->d_inode,
47437+ old_path.dentry->d_inode->i_mode, to)) {
47438+ error = -EACCES;
47439+ goto out_drop_write;
47440+ }
47441+
47442+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47443+ old_path.dentry, old_path.mnt, to)) {
47444+ error = -EACCES;
47445+ goto out_drop_write;
47446+ }
47447+
47448 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47449 if (error)
47450 goto out_drop_write;
47451 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47452+ if (!error)
47453+ gr_handle_create(new_dentry, new_path.mnt);
47454 out_drop_write:
47455 mnt_drop_write(new_path.mnt);
47456 out_dput:
47457+ putname(to);
47458 dput(new_dentry);
47459 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47460 path_put(&new_path);
47461@@ -3373,6 +3578,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47462 if (new_dentry == trap)
47463 goto exit5;
47464
47465+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47466+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
47467+ to);
47468+ if (error)
47469+ goto exit5;
47470+
47471 error = mnt_want_write(oldnd.path.mnt);
47472 if (error)
47473 goto exit5;
47474@@ -3382,6 +3593,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47475 goto exit6;
47476 error = vfs_rename(old_dir->d_inode, old_dentry,
47477 new_dir->d_inode, new_dentry);
47478+ if (!error)
47479+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47480+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47481 exit6:
47482 mnt_drop_write(oldnd.path.mnt);
47483 exit5:
47484@@ -3407,6 +3621,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47485
47486 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47487 {
47488+ char tmpbuf[64];
47489+ const char *newlink;
47490 int len;
47491
47492 len = PTR_ERR(link);
47493@@ -3416,7 +3632,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47494 len = strlen(link);
47495 if (len > (unsigned) buflen)
47496 len = buflen;
47497- if (copy_to_user(buffer, link, len))
47498+
47499+ if (len < sizeof(tmpbuf)) {
47500+ memcpy(tmpbuf, link, len);
47501+ newlink = tmpbuf;
47502+ } else
47503+ newlink = link;
47504+
47505+ if (copy_to_user(buffer, newlink, len))
47506 len = -EFAULT;
47507 out:
47508 return len;
47509diff --git a/fs/namespace.c b/fs/namespace.c
47510index 1e4a5fe..a5ce747 100644
47511--- a/fs/namespace.c
47512+++ b/fs/namespace.c
47513@@ -1157,6 +1157,9 @@ static int do_umount(struct mount *mnt, int flags)
47514 if (!(sb->s_flags & MS_RDONLY))
47515 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47516 up_write(&sb->s_umount);
47517+
47518+ gr_log_remount(mnt->mnt_devname, retval);
47519+
47520 return retval;
47521 }
47522
47523@@ -1176,6 +1179,9 @@ static int do_umount(struct mount *mnt, int flags)
47524 br_write_unlock(&vfsmount_lock);
47525 up_write(&namespace_sem);
47526 release_mounts(&umount_list);
47527+
47528+ gr_log_unmount(mnt->mnt_devname, retval);
47529+
47530 return retval;
47531 }
47532
47533@@ -2177,6 +2183,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47534 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47535 MS_STRICTATIME);
47536
47537+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47538+ retval = -EPERM;
47539+ goto dput_out;
47540+ }
47541+
47542+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47543+ retval = -EPERM;
47544+ goto dput_out;
47545+ }
47546+
47547 if (flags & MS_REMOUNT)
47548 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47549 data_page);
47550@@ -2191,6 +2207,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47551 dev_name, data_page);
47552 dput_out:
47553 path_put(&path);
47554+
47555+ gr_log_mount(dev_name, dir_name, retval);
47556+
47557 return retval;
47558 }
47559
47560@@ -2472,6 +2491,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47561 if (error)
47562 goto out2;
47563
47564+ if (gr_handle_chroot_pivot()) {
47565+ error = -EPERM;
47566+ goto out2;
47567+ }
47568+
47569 get_fs_root(current->fs, &root);
47570 error = lock_mount(&old);
47571 if (error)
47572diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47573index f729698..2bac081 100644
47574--- a/fs/nfs/inode.c
47575+++ b/fs/nfs/inode.c
47576@@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47577 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47578 nfsi->attrtimeo_timestamp = jiffies;
47579
47580- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47581+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47582 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47583 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47584 else
47585@@ -1008,16 +1008,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47586 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47587 }
47588
47589-static atomic_long_t nfs_attr_generation_counter;
47590+static atomic_long_unchecked_t nfs_attr_generation_counter;
47591
47592 static unsigned long nfs_read_attr_generation_counter(void)
47593 {
47594- return atomic_long_read(&nfs_attr_generation_counter);
47595+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47596 }
47597
47598 unsigned long nfs_inc_attr_generation_counter(void)
47599 {
47600- return atomic_long_inc_return(&nfs_attr_generation_counter);
47601+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47602 }
47603
47604 void nfs_fattr_init(struct nfs_fattr *fattr)
47605diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47606index c8bd9c3..4f83416 100644
47607--- a/fs/nfsd/vfs.c
47608+++ b/fs/nfsd/vfs.c
47609@@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47610 } else {
47611 oldfs = get_fs();
47612 set_fs(KERNEL_DS);
47613- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47614+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47615 set_fs(oldfs);
47616 }
47617
47618@@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47619
47620 /* Write the data. */
47621 oldfs = get_fs(); set_fs(KERNEL_DS);
47622- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47623+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47624 set_fs(oldfs);
47625 if (host_err < 0)
47626 goto out_nfserr;
47627@@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47628 */
47629
47630 oldfs = get_fs(); set_fs(KERNEL_DS);
47631- host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
47632+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
47633 set_fs(oldfs);
47634
47635 if (host_err < 0)
47636diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47637index 3568c8a..e0240d8 100644
47638--- a/fs/notify/fanotify/fanotify_user.c
47639+++ b/fs/notify/fanotify/fanotify_user.c
47640@@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47641 goto out_close_fd;
47642
47643 ret = -EFAULT;
47644- if (copy_to_user(buf, &fanotify_event_metadata,
47645+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47646+ copy_to_user(buf, &fanotify_event_metadata,
47647 fanotify_event_metadata.event_len))
47648 goto out_kill_access_response;
47649
47650diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47651index c887b13..0fdf472 100644
47652--- a/fs/notify/notification.c
47653+++ b/fs/notify/notification.c
47654@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47655 * get set to 0 so it will never get 'freed'
47656 */
47657 static struct fsnotify_event *q_overflow_event;
47658-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47659+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47660
47661 /**
47662 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47663@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47664 */
47665 u32 fsnotify_get_cookie(void)
47666 {
47667- return atomic_inc_return(&fsnotify_sync_cookie);
47668+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47669 }
47670 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47671
47672diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47673index 99e3610..02c1068 100644
47674--- a/fs/ntfs/dir.c
47675+++ b/fs/ntfs/dir.c
47676@@ -1329,7 +1329,7 @@ find_next_index_buffer:
47677 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47678 ~(s64)(ndir->itype.index.block_size - 1)));
47679 /* Bounds checks. */
47680- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47681+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47682 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47683 "inode 0x%lx or driver bug.", vdir->i_ino);
47684 goto err_out;
47685diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47686index 7389d2d..dfd5dbe 100644
47687--- a/fs/ntfs/file.c
47688+++ b/fs/ntfs/file.c
47689@@ -2231,6 +2231,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47690 #endif /* NTFS_RW */
47691 };
47692
47693-const struct file_operations ntfs_empty_file_ops = {};
47694+const struct file_operations ntfs_empty_file_ops __read_only;
47695
47696-const struct inode_operations ntfs_empty_inode_ops = {};
47697+const struct inode_operations ntfs_empty_inode_ops __read_only;
47698diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47699index 210c352..a174f83 100644
47700--- a/fs/ocfs2/localalloc.c
47701+++ b/fs/ocfs2/localalloc.c
47702@@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47703 goto bail;
47704 }
47705
47706- atomic_inc(&osb->alloc_stats.moves);
47707+ atomic_inc_unchecked(&osb->alloc_stats.moves);
47708
47709 bail:
47710 if (handle)
47711diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47712index d355e6e..578d905 100644
47713--- a/fs/ocfs2/ocfs2.h
47714+++ b/fs/ocfs2/ocfs2.h
47715@@ -235,11 +235,11 @@ enum ocfs2_vol_state
47716
47717 struct ocfs2_alloc_stats
47718 {
47719- atomic_t moves;
47720- atomic_t local_data;
47721- atomic_t bitmap_data;
47722- atomic_t bg_allocs;
47723- atomic_t bg_extends;
47724+ atomic_unchecked_t moves;
47725+ atomic_unchecked_t local_data;
47726+ atomic_unchecked_t bitmap_data;
47727+ atomic_unchecked_t bg_allocs;
47728+ atomic_unchecked_t bg_extends;
47729 };
47730
47731 enum ocfs2_local_alloc_state
47732diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47733index f169da4..9112253 100644
47734--- a/fs/ocfs2/suballoc.c
47735+++ b/fs/ocfs2/suballoc.c
47736@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47737 mlog_errno(status);
47738 goto bail;
47739 }
47740- atomic_inc(&osb->alloc_stats.bg_extends);
47741+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47742
47743 /* You should never ask for this much metadata */
47744 BUG_ON(bits_wanted >
47745@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47746 mlog_errno(status);
47747 goto bail;
47748 }
47749- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47750+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47751
47752 *suballoc_loc = res.sr_bg_blkno;
47753 *suballoc_bit_start = res.sr_bit_offset;
47754@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47755 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47756 res->sr_bits);
47757
47758- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47759+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47760
47761 BUG_ON(res->sr_bits != 1);
47762
47763@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47764 mlog_errno(status);
47765 goto bail;
47766 }
47767- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47768+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47769
47770 BUG_ON(res.sr_bits != 1);
47771
47772@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47773 cluster_start,
47774 num_clusters);
47775 if (!status)
47776- atomic_inc(&osb->alloc_stats.local_data);
47777+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
47778 } else {
47779 if (min_clusters > (osb->bitmap_cpg - 1)) {
47780 /* The only paths asking for contiguousness
47781@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47782 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47783 res.sr_bg_blkno,
47784 res.sr_bit_offset);
47785- atomic_inc(&osb->alloc_stats.bitmap_data);
47786+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47787 *num_clusters = res.sr_bits;
47788 }
47789 }
47790diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47791index 68f4541..89cfe6a 100644
47792--- a/fs/ocfs2/super.c
47793+++ b/fs/ocfs2/super.c
47794@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47795 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47796 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47797 "Stats",
47798- atomic_read(&osb->alloc_stats.bitmap_data),
47799- atomic_read(&osb->alloc_stats.local_data),
47800- atomic_read(&osb->alloc_stats.bg_allocs),
47801- atomic_read(&osb->alloc_stats.moves),
47802- atomic_read(&osb->alloc_stats.bg_extends));
47803+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47804+ atomic_read_unchecked(&osb->alloc_stats.local_data),
47805+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47806+ atomic_read_unchecked(&osb->alloc_stats.moves),
47807+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47808
47809 out += snprintf(buf + out, len - out,
47810 "%10s => State: %u Descriptor: %llu Size: %u bits "
47811@@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47812 spin_lock_init(&osb->osb_xattr_lock);
47813 ocfs2_init_steal_slots(osb);
47814
47815- atomic_set(&osb->alloc_stats.moves, 0);
47816- atomic_set(&osb->alloc_stats.local_data, 0);
47817- atomic_set(&osb->alloc_stats.bitmap_data, 0);
47818- atomic_set(&osb->alloc_stats.bg_allocs, 0);
47819- atomic_set(&osb->alloc_stats.bg_extends, 0);
47820+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47821+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47822+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47823+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47824+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47825
47826 /* Copy the blockcheck stats from the superblock probe */
47827 osb->osb_ecc_stats = *stats;
47828diff --git a/fs/open.c b/fs/open.c
47829index 1540632..79d7242 100644
47830--- a/fs/open.c
47831+++ b/fs/open.c
47832@@ -31,6 +31,8 @@
47833 #include <linux/ima.h>
47834 #include <linux/dnotify.h>
47835
47836+#define CREATE_TRACE_POINTS
47837+#include <trace/events/fs.h>
47838 #include "internal.h"
47839
47840 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
47841@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47842 error = locks_verify_truncate(inode, NULL, length);
47843 if (!error)
47844 error = security_path_truncate(&path);
47845+
47846+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47847+ error = -EACCES;
47848+
47849 if (!error)
47850 error = do_truncate(path.dentry, length, 0, NULL);
47851
47852@@ -359,6 +365,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47853 if (__mnt_is_readonly(path.mnt))
47854 res = -EROFS;
47855
47856+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47857+ res = -EACCES;
47858+
47859 out_path_release:
47860 path_put(&path);
47861 out:
47862@@ -385,6 +394,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47863 if (error)
47864 goto dput_and_out;
47865
47866+ gr_log_chdir(path.dentry, path.mnt);
47867+
47868 set_fs_pwd(current->fs, &path);
47869
47870 dput_and_out:
47871@@ -411,6 +422,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47872 goto out_putf;
47873
47874 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47875+
47876+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47877+ error = -EPERM;
47878+
47879+ if (!error)
47880+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47881+
47882 if (!error)
47883 set_fs_pwd(current->fs, &file->f_path);
47884 out_putf:
47885@@ -439,7 +457,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47886 if (error)
47887 goto dput_and_out;
47888
47889+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47890+ goto dput_and_out;
47891+
47892 set_fs_root(current->fs, &path);
47893+
47894+ gr_handle_chroot_chdir(&path);
47895+
47896 error = 0;
47897 dput_and_out:
47898 path_put(&path);
47899@@ -457,6 +481,16 @@ static int chmod_common(struct path *path, umode_t mode)
47900 if (error)
47901 return error;
47902 mutex_lock(&inode->i_mutex);
47903+
47904+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47905+ error = -EACCES;
47906+ goto out_unlock;
47907+ }
47908+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47909+ error = -EACCES;
47910+ goto out_unlock;
47911+ }
47912+
47913 error = security_path_chmod(path, mode);
47914 if (error)
47915 goto out_unlock;
47916@@ -512,6 +546,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47917 uid = make_kuid(current_user_ns(), user);
47918 gid = make_kgid(current_user_ns(), group);
47919
47920+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
47921+ return -EACCES;
47922+
47923 newattrs.ia_valid = ATTR_CTIME;
47924 if (user != (uid_t) -1) {
47925 if (!uid_valid(uid))
47926@@ -1035,6 +1072,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
47927 } else {
47928 fsnotify_open(f);
47929 fd_install(fd, f);
47930+ trace_do_sys_open(tmp, flags, mode);
47931 }
47932 }
47933 putname(tmp);
47934diff --git a/fs/pipe.c b/fs/pipe.c
47935index 49c1065..13b9e12 100644
47936--- a/fs/pipe.c
47937+++ b/fs/pipe.c
47938@@ -438,9 +438,9 @@ redo:
47939 }
47940 if (bufs) /* More to do? */
47941 continue;
47942- if (!pipe->writers)
47943+ if (!atomic_read(&pipe->writers))
47944 break;
47945- if (!pipe->waiting_writers) {
47946+ if (!atomic_read(&pipe->waiting_writers)) {
47947 /* syscall merging: Usually we must not sleep
47948 * if O_NONBLOCK is set, or if we got some data.
47949 * But if a writer sleeps in kernel space, then
47950@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47951 mutex_lock(&inode->i_mutex);
47952 pipe = inode->i_pipe;
47953
47954- if (!pipe->readers) {
47955+ if (!atomic_read(&pipe->readers)) {
47956 send_sig(SIGPIPE, current, 0);
47957 ret = -EPIPE;
47958 goto out;
47959@@ -553,7 +553,7 @@ redo1:
47960 for (;;) {
47961 int bufs;
47962
47963- if (!pipe->readers) {
47964+ if (!atomic_read(&pipe->readers)) {
47965 send_sig(SIGPIPE, current, 0);
47966 if (!ret)
47967 ret = -EPIPE;
47968@@ -644,9 +644,9 @@ redo2:
47969 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47970 do_wakeup = 0;
47971 }
47972- pipe->waiting_writers++;
47973+ atomic_inc(&pipe->waiting_writers);
47974 pipe_wait(pipe);
47975- pipe->waiting_writers--;
47976+ atomic_dec(&pipe->waiting_writers);
47977 }
47978 out:
47979 mutex_unlock(&inode->i_mutex);
47980@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47981 mask = 0;
47982 if (filp->f_mode & FMODE_READ) {
47983 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47984- if (!pipe->writers && filp->f_version != pipe->w_counter)
47985+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47986 mask |= POLLHUP;
47987 }
47988
47989@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47990 * Most Unices do not set POLLERR for FIFOs but on Linux they
47991 * behave exactly like pipes for poll().
47992 */
47993- if (!pipe->readers)
47994+ if (!atomic_read(&pipe->readers))
47995 mask |= POLLERR;
47996 }
47997
47998@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47999
48000 mutex_lock(&inode->i_mutex);
48001 pipe = inode->i_pipe;
48002- pipe->readers -= decr;
48003- pipe->writers -= decw;
48004+ atomic_sub(decr, &pipe->readers);
48005+ atomic_sub(decw, &pipe->writers);
48006
48007- if (!pipe->readers && !pipe->writers) {
48008+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48009 free_pipe_info(inode);
48010 } else {
48011 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48012@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48013
48014 if (inode->i_pipe) {
48015 ret = 0;
48016- inode->i_pipe->readers++;
48017+ atomic_inc(&inode->i_pipe->readers);
48018 }
48019
48020 mutex_unlock(&inode->i_mutex);
48021@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48022
48023 if (inode->i_pipe) {
48024 ret = 0;
48025- inode->i_pipe->writers++;
48026+ atomic_inc(&inode->i_pipe->writers);
48027 }
48028
48029 mutex_unlock(&inode->i_mutex);
48030@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48031 if (inode->i_pipe) {
48032 ret = 0;
48033 if (filp->f_mode & FMODE_READ)
48034- inode->i_pipe->readers++;
48035+ atomic_inc(&inode->i_pipe->readers);
48036 if (filp->f_mode & FMODE_WRITE)
48037- inode->i_pipe->writers++;
48038+ atomic_inc(&inode->i_pipe->writers);
48039 }
48040
48041 mutex_unlock(&inode->i_mutex);
48042@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48043 inode->i_pipe = NULL;
48044 }
48045
48046-static struct vfsmount *pipe_mnt __read_mostly;
48047+struct vfsmount *pipe_mnt __read_mostly;
48048
48049 /*
48050 * pipefs_dname() is called from d_path().
48051@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48052 goto fail_iput;
48053 inode->i_pipe = pipe;
48054
48055- pipe->readers = pipe->writers = 1;
48056+ atomic_set(&pipe->readers, 1);
48057+ atomic_set(&pipe->writers, 1);
48058 inode->i_fop = &rdwr_pipefifo_fops;
48059
48060 /*
48061diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48062index 15af622..0e9f4467 100644
48063--- a/fs/proc/Kconfig
48064+++ b/fs/proc/Kconfig
48065@@ -30,12 +30,12 @@ config PROC_FS
48066
48067 config PROC_KCORE
48068 bool "/proc/kcore support" if !ARM
48069- depends on PROC_FS && MMU
48070+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48071
48072 config PROC_VMCORE
48073 bool "/proc/vmcore support"
48074- depends on PROC_FS && CRASH_DUMP
48075- default y
48076+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48077+ default n
48078 help
48079 Exports the dump image of crashed kernel in ELF format.
48080
48081@@ -59,8 +59,8 @@ config PROC_SYSCTL
48082 limited in memory.
48083
48084 config PROC_PAGE_MONITOR
48085- default y
48086- depends on PROC_FS && MMU
48087+ default n
48088+ depends on PROC_FS && MMU && !GRKERNSEC
48089 bool "Enable /proc page monitoring" if EXPERT
48090 help
48091 Various /proc files exist to monitor process memory utilization:
48092diff --git a/fs/proc/array.c b/fs/proc/array.c
48093index c1c207c..5179411 100644
48094--- a/fs/proc/array.c
48095+++ b/fs/proc/array.c
48096@@ -60,6 +60,7 @@
48097 #include <linux/tty.h>
48098 #include <linux/string.h>
48099 #include <linux/mman.h>
48100+#include <linux/grsecurity.h>
48101 #include <linux/proc_fs.h>
48102 #include <linux/ioport.h>
48103 #include <linux/uaccess.h>
48104@@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48105 seq_putc(m, '\n');
48106 }
48107
48108+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48109+static inline void task_pax(struct seq_file *m, struct task_struct *p)
48110+{
48111+ if (p->mm)
48112+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48113+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48114+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48115+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48116+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48117+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48118+ else
48119+ seq_printf(m, "PaX:\t-----\n");
48120+}
48121+#endif
48122+
48123 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48124 struct pid *pid, struct task_struct *task)
48125 {
48126@@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48127 task_cpus_allowed(m, task);
48128 cpuset_task_status_allowed(m, task);
48129 task_context_switch_counts(m, task);
48130+
48131+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48132+ task_pax(m, task);
48133+#endif
48134+
48135+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48136+ task_grsec_rbac(m, task);
48137+#endif
48138+
48139 return 0;
48140 }
48141
48142+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48143+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48144+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48145+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48146+#endif
48147+
48148 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48149 struct pid *pid, struct task_struct *task, int whole)
48150 {
48151@@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48152 char tcomm[sizeof(task->comm)];
48153 unsigned long flags;
48154
48155+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48156+ if (current->exec_id != m->exec_id) {
48157+ gr_log_badprocpid("stat");
48158+ return 0;
48159+ }
48160+#endif
48161+
48162 state = *get_task_state(task);
48163 vsize = eip = esp = 0;
48164 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48165@@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48166 gtime = task->gtime;
48167 }
48168
48169+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48170+ if (PAX_RAND_FLAGS(mm)) {
48171+ eip = 0;
48172+ esp = 0;
48173+ wchan = 0;
48174+ }
48175+#endif
48176+#ifdef CONFIG_GRKERNSEC_HIDESYM
48177+ wchan = 0;
48178+ eip =0;
48179+ esp =0;
48180+#endif
48181+
48182 /* scale priority and nice values from timeslices to -20..20 */
48183 /* to make it look like a "normal" Unix priority/nice value */
48184 priority = task_prio(task);
48185@@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48186 seq_put_decimal_ull(m, ' ', vsize);
48187 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48188 seq_put_decimal_ull(m, ' ', rsslim);
48189+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48190+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48191+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48192+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48193+#else
48194 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48195 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48196 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48197+#endif
48198 seq_put_decimal_ull(m, ' ', esp);
48199 seq_put_decimal_ull(m, ' ', eip);
48200 /* The signal information here is obsolete.
48201@@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48202 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48203 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48204
48205- if (mm && permitted) {
48206+ if (mm && permitted
48207+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48208+ && !PAX_RAND_FLAGS(mm)
48209+#endif
48210+ ) {
48211 seq_put_decimal_ull(m, ' ', mm->start_data);
48212 seq_put_decimal_ull(m, ' ', mm->end_data);
48213 seq_put_decimal_ull(m, ' ', mm->start_brk);
48214@@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48215 struct pid *pid, struct task_struct *task)
48216 {
48217 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48218- struct mm_struct *mm = get_task_mm(task);
48219+ struct mm_struct *mm;
48220
48221+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48222+ if (current->exec_id != m->exec_id) {
48223+ gr_log_badprocpid("statm");
48224+ return 0;
48225+ }
48226+#endif
48227+ mm = get_task_mm(task);
48228 if (mm) {
48229 size = task_statm(mm, &shared, &text, &data, &resident);
48230 mmput(mm);
48231@@ -580,6 +648,21 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48232 return 0;
48233 }
48234
48235+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48236+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48237+{
48238+ u32 curr_ip = 0;
48239+ unsigned long flags;
48240+
48241+ if (lock_task_sighand(task, &flags)) {
48242+ curr_ip = task->signal->curr_ip;
48243+ unlock_task_sighand(task, &flags);
48244+ }
48245+
48246+ return sprintf(buffer, "%pI4\n", &curr_ip);
48247+}
48248+#endif
48249+
48250 #ifdef CONFIG_CHECKPOINT_RESTORE
48251 static struct pid *
48252 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48253diff --git a/fs/proc/base.c b/fs/proc/base.c
48254index 437195f..cd2210d 100644
48255--- a/fs/proc/base.c
48256+++ b/fs/proc/base.c
48257@@ -110,6 +110,14 @@ struct pid_entry {
48258 union proc_op op;
48259 };
48260
48261+struct getdents_callback {
48262+ struct linux_dirent __user * current_dir;
48263+ struct linux_dirent __user * previous;
48264+ struct file * file;
48265+ int count;
48266+ int error;
48267+};
48268+
48269 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48270 .name = (NAME), \
48271 .len = sizeof(NAME) - 1, \
48272@@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48273 if (!mm->arg_end)
48274 goto out_mm; /* Shh! No looking before we're done */
48275
48276+ if (gr_acl_handle_procpidmem(task))
48277+ goto out_mm;
48278+
48279 len = mm->arg_end - mm->arg_start;
48280
48281 if (len > PAGE_SIZE)
48282@@ -236,12 +247,28 @@ out:
48283 return res;
48284 }
48285
48286+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48287+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48288+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48289+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48290+#endif
48291+
48292 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48293 {
48294 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48295 int res = PTR_ERR(mm);
48296 if (mm && !IS_ERR(mm)) {
48297 unsigned int nwords = 0;
48298+
48299+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48300+ /* allow if we're currently ptracing this task */
48301+ if (PAX_RAND_FLAGS(mm) &&
48302+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48303+ mmput(mm);
48304+ return 0;
48305+ }
48306+#endif
48307+
48308 do {
48309 nwords += 2;
48310 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48311@@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48312 }
48313
48314
48315-#ifdef CONFIG_KALLSYMS
48316+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48317 /*
48318 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48319 * Returns the resolved symbol. If that fails, simply return the address.
48320@@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48321 mutex_unlock(&task->signal->cred_guard_mutex);
48322 }
48323
48324-#ifdef CONFIG_STACKTRACE
48325+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48326
48327 #define MAX_STACK_TRACE_DEPTH 64
48328
48329@@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48330 return count;
48331 }
48332
48333-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48334+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48335 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48336 {
48337 long nr;
48338@@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48339 /************************************************************************/
48340
48341 /* permission checks */
48342-static int proc_fd_access_allowed(struct inode *inode)
48343+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48344 {
48345 struct task_struct *task;
48346 int allowed = 0;
48347@@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48348 */
48349 task = get_proc_task(inode);
48350 if (task) {
48351- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48352+ if (log)
48353+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48354+ else
48355+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48356 put_task_struct(task);
48357 }
48358 return allowed;
48359@@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48360 struct task_struct *task,
48361 int hide_pid_min)
48362 {
48363+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48364+ return false;
48365+
48366+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48367+ rcu_read_lock();
48368+ {
48369+ const struct cred *tmpcred = current_cred();
48370+ const struct cred *cred = __task_cred(task);
48371+
48372+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48373+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48374+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48375+#endif
48376+ ) {
48377+ rcu_read_unlock();
48378+ return true;
48379+ }
48380+ }
48381+ rcu_read_unlock();
48382+
48383+ if (!pid->hide_pid)
48384+ return false;
48385+#endif
48386+
48387 if (pid->hide_pid < hide_pid_min)
48388 return true;
48389 if (in_group_p(pid->pid_gid))
48390 return true;
48391+
48392 return ptrace_may_access(task, PTRACE_MODE_READ);
48393 }
48394
48395@@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48396 put_task_struct(task);
48397
48398 if (!has_perms) {
48399+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48400+ {
48401+#else
48402 if (pid->hide_pid == 2) {
48403+#endif
48404 /*
48405 * Let's make getdents(), stat(), and open()
48406 * consistent with each other. If a process
48407@@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48408 if (!task)
48409 return -ESRCH;
48410
48411+ if (gr_acl_handle_procpidmem(task)) {
48412+ put_task_struct(task);
48413+ return -EPERM;
48414+ }
48415+
48416 mm = mm_access(task, mode);
48417 put_task_struct(task);
48418
48419@@ -695,16 +759,24 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48420 mmput(mm);
48421 }
48422
48423- /* OK to pass negative loff_t, we can catch out-of-range */
48424- file->f_mode |= FMODE_UNSIGNED_OFFSET;
48425 file->private_data = mm;
48426
48427+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48428+ file->f_version = current->exec_id;
48429+#endif
48430+
48431 return 0;
48432 }
48433
48434 static int mem_open(struct inode *inode, struct file *file)
48435 {
48436- return __mem_open(inode, file, PTRACE_MODE_ATTACH);
48437+ int ret;
48438+ ret = __mem_open(inode, file, PTRACE_MODE_ATTACH);
48439+
48440+ /* OK to pass negative loff_t, we can catch out-of-range */
48441+ file->f_mode |= FMODE_UNSIGNED_OFFSET;
48442+
48443+ return ret;
48444 }
48445
48446 static ssize_t mem_rw(struct file *file, char __user *buf,
48447@@ -715,6 +787,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48448 ssize_t copied;
48449 char *page;
48450
48451+#ifdef CONFIG_GRKERNSEC
48452+ if (write)
48453+ return -EPERM;
48454+#endif
48455+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48456+ if (file->f_version != current->exec_id) {
48457+ gr_log_badprocpid("mem");
48458+ return 0;
48459+ }
48460+#endif
48461+
48462 if (!mm)
48463 return 0;
48464
48465@@ -819,6 +902,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48466 if (!mm)
48467 return 0;
48468
48469+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48470+ if (file->f_version != current->exec_id) {
48471+ gr_log_badprocpid("environ");
48472+ return 0;
48473+ }
48474+#endif
48475+
48476 page = (char *)__get_free_page(GFP_TEMPORARY);
48477 if (!page)
48478 return -ENOMEM;
48479@@ -827,15 +917,17 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48480 if (!atomic_inc_not_zero(&mm->mm_users))
48481 goto free;
48482 while (count > 0) {
48483- int this_len, retval, max_len;
48484+ size_t this_len, max_len;
48485+ int retval;
48486+
48487+ if (src >= (mm->env_end - mm->env_start))
48488+ break;
48489
48490 this_len = mm->env_end - (mm->env_start + src);
48491
48492- if (this_len <= 0)
48493- break;
48494
48495- max_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
48496- this_len = (this_len > max_len) ? max_len : this_len;
48497+ max_len = min_t(size_t, PAGE_SIZE, count);
48498+ this_len = min(max_len, this_len);
48499
48500 retval = access_remote_vm(mm, (mm->env_start + src),
48501 page, this_len, 0);
48502@@ -1433,7 +1525,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48503 path_put(&nd->path);
48504
48505 /* Are we allowed to snoop on the tasks file descriptors? */
48506- if (!proc_fd_access_allowed(inode))
48507+ if (!proc_fd_access_allowed(inode, 0))
48508 goto out;
48509
48510 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48511@@ -1472,8 +1564,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48512 struct path path;
48513
48514 /* Are we allowed to snoop on the tasks file descriptors? */
48515- if (!proc_fd_access_allowed(inode))
48516- goto out;
48517+ /* logging this is needed for learning on chromium to work properly,
48518+ but we don't want to flood the logs from 'ps' which does a readlink
48519+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48520+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
48521+ */
48522+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48523+ if (!proc_fd_access_allowed(inode,0))
48524+ goto out;
48525+ } else {
48526+ if (!proc_fd_access_allowed(inode,1))
48527+ goto out;
48528+ }
48529
48530 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48531 if (error)
48532@@ -1538,7 +1640,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48533 rcu_read_lock();
48534 cred = __task_cred(task);
48535 inode->i_uid = cred->euid;
48536+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48537+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48538+#else
48539 inode->i_gid = cred->egid;
48540+#endif
48541 rcu_read_unlock();
48542 }
48543 security_task_to_inode(task, inode);
48544@@ -1574,10 +1680,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48545 return -ENOENT;
48546 }
48547 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48548+#ifdef CONFIG_GRKERNSEC_PROC_USER
48549+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48550+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48551+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48552+#endif
48553 task_dumpable(task)) {
48554 cred = __task_cred(task);
48555 stat->uid = cred->euid;
48556+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48557+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48558+#else
48559 stat->gid = cred->egid;
48560+#endif
48561 }
48562 }
48563 rcu_read_unlock();
48564@@ -1615,11 +1730,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48565
48566 if (task) {
48567 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48568+#ifdef CONFIG_GRKERNSEC_PROC_USER
48569+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48570+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48571+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48572+#endif
48573 task_dumpable(task)) {
48574 rcu_read_lock();
48575 cred = __task_cred(task);
48576 inode->i_uid = cred->euid;
48577+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48578+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48579+#else
48580 inode->i_gid = cred->egid;
48581+#endif
48582 rcu_read_unlock();
48583 } else {
48584 inode->i_uid = GLOBAL_ROOT_UID;
48585@@ -1737,7 +1861,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48586 int fd = proc_fd(inode);
48587
48588 if (task) {
48589- files = get_files_struct(task);
48590+ if (!gr_acl_handle_procpidmem(task))
48591+ files = get_files_struct(task);
48592 put_task_struct(task);
48593 }
48594 if (files) {
48595@@ -2336,11 +2461,21 @@ static const struct file_operations proc_map_files_operations = {
48596 */
48597 static int proc_fd_permission(struct inode *inode, int mask)
48598 {
48599+ struct task_struct *task;
48600 int rv = generic_permission(inode, mask);
48601- if (rv == 0)
48602- return 0;
48603+
48604 if (task_pid(current) == proc_pid(inode))
48605 rv = 0;
48606+
48607+ task = get_proc_task(inode);
48608+ if (task == NULL)
48609+ return rv;
48610+
48611+ if (gr_acl_handle_procpidmem(task))
48612+ rv = -EACCES;
48613+
48614+ put_task_struct(task);
48615+
48616 return rv;
48617 }
48618
48619@@ -2450,6 +2585,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48620 if (!task)
48621 goto out_no_task;
48622
48623+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48624+ goto out;
48625+
48626 /*
48627 * Yes, it does not scale. And it should not. Don't add
48628 * new entries into /proc/<tgid>/ without very good reasons.
48629@@ -2494,6 +2632,9 @@ static int proc_pident_readdir(struct file *filp,
48630 if (!task)
48631 goto out_no_task;
48632
48633+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48634+ goto out;
48635+
48636 ret = 0;
48637 i = filp->f_pos;
48638 switch (i) {
48639@@ -2764,7 +2905,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48640 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48641 void *cookie)
48642 {
48643- char *s = nd_get_link(nd);
48644+ const char *s = nd_get_link(nd);
48645 if (!IS_ERR(s))
48646 __putname(s);
48647 }
48648@@ -3033,7 +3174,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48649 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48650 #endif
48651 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48652-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48653+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48654 INF("syscall", S_IRUGO, proc_pid_syscall),
48655 #endif
48656 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48657@@ -3058,10 +3199,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48658 #ifdef CONFIG_SECURITY
48659 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48660 #endif
48661-#ifdef CONFIG_KALLSYMS
48662+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48663 INF("wchan", S_IRUGO, proc_pid_wchan),
48664 #endif
48665-#ifdef CONFIG_STACKTRACE
48666+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48667 ONE("stack", S_IRUGO, proc_pid_stack),
48668 #endif
48669 #ifdef CONFIG_SCHEDSTATS
48670@@ -3095,6 +3236,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48671 #ifdef CONFIG_HARDWALL
48672 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48673 #endif
48674+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48675+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48676+#endif
48677 #ifdef CONFIG_USER_NS
48678 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
48679 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
48680@@ -3225,7 +3369,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48681 if (!inode)
48682 goto out;
48683
48684+#ifdef CONFIG_GRKERNSEC_PROC_USER
48685+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48686+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48687+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48688+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48689+#else
48690 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48691+#endif
48692 inode->i_op = &proc_tgid_base_inode_operations;
48693 inode->i_fop = &proc_tgid_base_operations;
48694 inode->i_flags|=S_IMMUTABLE;
48695@@ -3267,7 +3418,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48696 if (!task)
48697 goto out;
48698
48699+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48700+ goto out_put_task;
48701+
48702 result = proc_pid_instantiate(dir, dentry, task, NULL);
48703+out_put_task:
48704 put_task_struct(task);
48705 out:
48706 return result;
48707@@ -3330,6 +3485,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48708 static int fake_filldir(void *buf, const char *name, int namelen,
48709 loff_t offset, u64 ino, unsigned d_type)
48710 {
48711+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
48712+ __buf->error = -EINVAL;
48713 return 0;
48714 }
48715
48716@@ -3396,7 +3553,7 @@ static const struct pid_entry tid_base_stuff[] = {
48717 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48718 #endif
48719 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48720-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48721+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48722 INF("syscall", S_IRUGO, proc_pid_syscall),
48723 #endif
48724 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48725@@ -3423,10 +3580,10 @@ static const struct pid_entry tid_base_stuff[] = {
48726 #ifdef CONFIG_SECURITY
48727 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48728 #endif
48729-#ifdef CONFIG_KALLSYMS
48730+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48731 INF("wchan", S_IRUGO, proc_pid_wchan),
48732 #endif
48733-#ifdef CONFIG_STACKTRACE
48734+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48735 ONE("stack", S_IRUGO, proc_pid_stack),
48736 #endif
48737 #ifdef CONFIG_SCHEDSTATS
48738diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48739index 82676e3..5f8518a 100644
48740--- a/fs/proc/cmdline.c
48741+++ b/fs/proc/cmdline.c
48742@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48743
48744 static int __init proc_cmdline_init(void)
48745 {
48746+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48747+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48748+#else
48749 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48750+#endif
48751 return 0;
48752 }
48753 module_init(proc_cmdline_init);
48754diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48755index b143471..bb105e5 100644
48756--- a/fs/proc/devices.c
48757+++ b/fs/proc/devices.c
48758@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48759
48760 static int __init proc_devices_init(void)
48761 {
48762+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48763+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48764+#else
48765 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48766+#endif
48767 return 0;
48768 }
48769 module_init(proc_devices_init);
48770diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48771index 7ac817b..abab1a5 100644
48772--- a/fs/proc/inode.c
48773+++ b/fs/proc/inode.c
48774@@ -21,11 +21,17 @@
48775 #include <linux/seq_file.h>
48776 #include <linux/slab.h>
48777 #include <linux/mount.h>
48778+#include <linux/grsecurity.h>
48779
48780 #include <asm/uaccess.h>
48781
48782 #include "internal.h"
48783
48784+#ifdef CONFIG_PROC_SYSCTL
48785+extern const struct inode_operations proc_sys_inode_operations;
48786+extern const struct inode_operations proc_sys_dir_operations;
48787+#endif
48788+
48789 static void proc_evict_inode(struct inode *inode)
48790 {
48791 struct proc_dir_entry *de;
48792@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
48793 ns_ops = PROC_I(inode)->ns_ops;
48794 if (ns_ops && ns_ops->put)
48795 ns_ops->put(PROC_I(inode)->ns);
48796+
48797+#ifdef CONFIG_PROC_SYSCTL
48798+ if (inode->i_op == &proc_sys_inode_operations ||
48799+ inode->i_op == &proc_sys_dir_operations)
48800+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48801+#endif
48802+
48803 }
48804
48805 static struct kmem_cache * proc_inode_cachep;
48806@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48807 if (de->mode) {
48808 inode->i_mode = de->mode;
48809 inode->i_uid = de->uid;
48810+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48811+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48812+#else
48813 inode->i_gid = de->gid;
48814+#endif
48815 }
48816 if (de->size)
48817 inode->i_size = de->size;
48818diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48819index eca4aca..19166b2 100644
48820--- a/fs/proc/internal.h
48821+++ b/fs/proc/internal.h
48822@@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48823 struct pid *pid, struct task_struct *task);
48824 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48825 struct pid *pid, struct task_struct *task);
48826+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48827+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48828+#endif
48829 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48830
48831 extern const struct file_operations proc_tid_children_operations;
48832diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48833index 86c67ee..cdca321 100644
48834--- a/fs/proc/kcore.c
48835+++ b/fs/proc/kcore.c
48836@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48837 * the addresses in the elf_phdr on our list.
48838 */
48839 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48840- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48841+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48842+ if (tsz > buflen)
48843 tsz = buflen;
48844-
48845+
48846 while (buflen) {
48847 struct kcore_list *m;
48848
48849@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48850 kfree(elf_buf);
48851 } else {
48852 if (kern_addr_valid(start)) {
48853- unsigned long n;
48854+ char *elf_buf;
48855+ mm_segment_t oldfs;
48856
48857- n = copy_to_user(buffer, (char *)start, tsz);
48858- /*
48859- * We cannot distinguish between fault on source
48860- * and fault on destination. When this happens
48861- * we clear too and hope it will trigger the
48862- * EFAULT again.
48863- */
48864- if (n) {
48865- if (clear_user(buffer + tsz - n,
48866- n))
48867+ elf_buf = kmalloc(tsz, GFP_KERNEL);
48868+ if (!elf_buf)
48869+ return -ENOMEM;
48870+ oldfs = get_fs();
48871+ set_fs(KERNEL_DS);
48872+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48873+ set_fs(oldfs);
48874+ if (copy_to_user(buffer, elf_buf, tsz)) {
48875+ kfree(elf_buf);
48876 return -EFAULT;
48877+ }
48878 }
48879+ set_fs(oldfs);
48880+ kfree(elf_buf);
48881 } else {
48882 if (clear_user(buffer, tsz))
48883 return -EFAULT;
48884@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48885
48886 static int open_kcore(struct inode *inode, struct file *filp)
48887 {
48888+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48889+ return -EPERM;
48890+#endif
48891 if (!capable(CAP_SYS_RAWIO))
48892 return -EPERM;
48893 if (kcore_need_update)
48894diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48895index 80e4645..53e5fcf 100644
48896--- a/fs/proc/meminfo.c
48897+++ b/fs/proc/meminfo.c
48898@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48899 vmi.used >> 10,
48900 vmi.largest_chunk >> 10
48901 #ifdef CONFIG_MEMORY_FAILURE
48902- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48903+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48904 #endif
48905 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48906 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48907diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48908index b1822dd..df622cb 100644
48909--- a/fs/proc/nommu.c
48910+++ b/fs/proc/nommu.c
48911@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48912 if (len < 1)
48913 len = 1;
48914 seq_printf(m, "%*c", len, ' ');
48915- seq_path(m, &file->f_path, "");
48916+ seq_path(m, &file->f_path, "\n\\");
48917 }
48918
48919 seq_putc(m, '\n');
48920diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48921index 06e1cc1..177cd98 100644
48922--- a/fs/proc/proc_net.c
48923+++ b/fs/proc/proc_net.c
48924@@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48925 struct task_struct *task;
48926 struct nsproxy *ns;
48927 struct net *net = NULL;
48928+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48929+ const struct cred *cred = current_cred();
48930+#endif
48931+
48932+#ifdef CONFIG_GRKERNSEC_PROC_USER
48933+ if (cred->fsuid)
48934+ return net;
48935+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48936+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48937+ return net;
48938+#endif
48939
48940 rcu_read_lock();
48941 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48942diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48943index 3476bca..cb6d86a 100644
48944--- a/fs/proc/proc_sysctl.c
48945+++ b/fs/proc/proc_sysctl.c
48946@@ -12,11 +12,15 @@
48947 #include <linux/module.h>
48948 #include "internal.h"
48949
48950+extern int gr_handle_chroot_sysctl(const int op);
48951+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
48952+ const int op);
48953+
48954 static const struct dentry_operations proc_sys_dentry_operations;
48955 static const struct file_operations proc_sys_file_operations;
48956-static const struct inode_operations proc_sys_inode_operations;
48957+const struct inode_operations proc_sys_inode_operations;
48958 static const struct file_operations proc_sys_dir_file_operations;
48959-static const struct inode_operations proc_sys_dir_operations;
48960+const struct inode_operations proc_sys_dir_operations;
48961
48962 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48963 {
48964@@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48965
48966 err = NULL;
48967 d_set_d_op(dentry, &proc_sys_dentry_operations);
48968+
48969+ gr_handle_proc_create(dentry, inode);
48970+
48971 d_add(dentry, inode);
48972
48973+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
48974+ err = ERR_PTR(-ENOENT);
48975+
48976 out:
48977 sysctl_head_finish(head);
48978 return err;
48979@@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48980 struct inode *inode = filp->f_path.dentry->d_inode;
48981 struct ctl_table_header *head = grab_header(inode);
48982 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
48983+ int op = write ? MAY_WRITE : MAY_READ;
48984 ssize_t error;
48985 size_t res;
48986
48987 if (IS_ERR(head))
48988 return PTR_ERR(head);
48989
48990+
48991 /*
48992 * At this point we know that the sysctl was not unregistered
48993 * and won't be until we finish.
48994 */
48995 error = -EPERM;
48996- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
48997+ if (sysctl_perm(head->root, table, op))
48998 goto out;
48999
49000 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49001@@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49002 if (!table->proc_handler)
49003 goto out;
49004
49005+#ifdef CONFIG_GRKERNSEC
49006+ error = -EPERM;
49007+ if (gr_handle_chroot_sysctl(op))
49008+ goto out;
49009+ dget(filp->f_path.dentry);
49010+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49011+ dput(filp->f_path.dentry);
49012+ goto out;
49013+ }
49014+ dput(filp->f_path.dentry);
49015+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49016+ goto out;
49017+ if (write && !capable(CAP_SYS_ADMIN))
49018+ goto out;
49019+#endif
49020+
49021 /* careful: calling conventions are nasty here */
49022 res = count;
49023 error = table->proc_handler(table, write, buf, &res, ppos);
49024@@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49025 return -ENOMEM;
49026 } else {
49027 d_set_d_op(child, &proc_sys_dentry_operations);
49028+
49029+ gr_handle_proc_create(child, inode);
49030+
49031 d_add(child, inode);
49032 }
49033 } else {
49034@@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49035 if ((*pos)++ < file->f_pos)
49036 return 0;
49037
49038+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49039+ return 0;
49040+
49041 if (unlikely(S_ISLNK(table->mode)))
49042 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49043 else
49044@@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49045 if (IS_ERR(head))
49046 return PTR_ERR(head);
49047
49048+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49049+ return -ENOENT;
49050+
49051 generic_fillattr(inode, stat);
49052 if (table)
49053 stat->mode = (stat->mode & S_IFMT) | table->mode;
49054@@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49055 .llseek = generic_file_llseek,
49056 };
49057
49058-static const struct inode_operations proc_sys_inode_operations = {
49059+const struct inode_operations proc_sys_inode_operations = {
49060 .permission = proc_sys_permission,
49061 .setattr = proc_sys_setattr,
49062 .getattr = proc_sys_getattr,
49063 };
49064
49065-static const struct inode_operations proc_sys_dir_operations = {
49066+const struct inode_operations proc_sys_dir_operations = {
49067 .lookup = proc_sys_lookup,
49068 .permission = proc_sys_permission,
49069 .setattr = proc_sys_setattr,
49070diff --git a/fs/proc/root.c b/fs/proc/root.c
49071index 7c30fce..b3d3aa2 100644
49072--- a/fs/proc/root.c
49073+++ b/fs/proc/root.c
49074@@ -188,7 +188,15 @@ void __init proc_root_init(void)
49075 #ifdef CONFIG_PROC_DEVICETREE
49076 proc_device_tree_init();
49077 #endif
49078+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49079+#ifdef CONFIG_GRKERNSEC_PROC_USER
49080+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49081+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49082+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49083+#endif
49084+#else
49085 proc_mkdir("bus", NULL);
49086+#endif
49087 proc_sys_init();
49088 }
49089
49090diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49091index 4540b8f..1b9772f 100644
49092--- a/fs/proc/task_mmu.c
49093+++ b/fs/proc/task_mmu.c
49094@@ -11,12 +11,19 @@
49095 #include <linux/rmap.h>
49096 #include <linux/swap.h>
49097 #include <linux/swapops.h>
49098+#include <linux/grsecurity.h>
49099
49100 #include <asm/elf.h>
49101 #include <asm/uaccess.h>
49102 #include <asm/tlbflush.h>
49103 #include "internal.h"
49104
49105+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49106+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49107+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49108+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49109+#endif
49110+
49111 void task_mem(struct seq_file *m, struct mm_struct *mm)
49112 {
49113 unsigned long data, text, lib, swap;
49114@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49115 "VmExe:\t%8lu kB\n"
49116 "VmLib:\t%8lu kB\n"
49117 "VmPTE:\t%8lu kB\n"
49118- "VmSwap:\t%8lu kB\n",
49119- hiwater_vm << (PAGE_SHIFT-10),
49120+ "VmSwap:\t%8lu kB\n"
49121+
49122+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49123+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49124+#endif
49125+
49126+ ,hiwater_vm << (PAGE_SHIFT-10),
49127 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49128 mm->locked_vm << (PAGE_SHIFT-10),
49129 mm->pinned_vm << (PAGE_SHIFT-10),
49130@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49131 data << (PAGE_SHIFT-10),
49132 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49133 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49134- swap << (PAGE_SHIFT-10));
49135+ swap << (PAGE_SHIFT-10)
49136+
49137+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49138+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49139+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49140+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49141+#else
49142+ , mm->context.user_cs_base
49143+ , mm->context.user_cs_limit
49144+#endif
49145+#endif
49146+
49147+ );
49148 }
49149
49150 unsigned long task_vsize(struct mm_struct *mm)
49151@@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49152 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49153 }
49154
49155- /* We don't show the stack guard page in /proc/maps */
49156+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49157+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49158+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49159+#else
49160 start = vma->vm_start;
49161- if (stack_guard_page_start(vma, start))
49162- start += PAGE_SIZE;
49163 end = vma->vm_end;
49164- if (stack_guard_page_end(vma, end))
49165- end -= PAGE_SIZE;
49166+#endif
49167
49168 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49169 start,
49170@@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49171 flags & VM_WRITE ? 'w' : '-',
49172 flags & VM_EXEC ? 'x' : '-',
49173 flags & VM_MAYSHARE ? 's' : 'p',
49174+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49175+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49176+#else
49177 pgoff,
49178+#endif
49179 MAJOR(dev), MINOR(dev), ino, &len);
49180
49181 /*
49182@@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49183 */
49184 if (file) {
49185 pad_len_spaces(m, len);
49186- seq_path(m, &file->f_path, "\n");
49187+ seq_path(m, &file->f_path, "\n\\");
49188 goto done;
49189 }
49190
49191@@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49192 * Thread stack in /proc/PID/task/TID/maps or
49193 * the main process stack.
49194 */
49195- if (!is_pid || (vma->vm_start <= mm->start_stack &&
49196- vma->vm_end >= mm->start_stack)) {
49197+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49198+ (vma->vm_start <= mm->start_stack &&
49199+ vma->vm_end >= mm->start_stack)) {
49200 name = "[stack]";
49201 } else {
49202 /* Thread stack in /proc/PID/maps */
49203@@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49204 struct proc_maps_private *priv = m->private;
49205 struct task_struct *task = priv->task;
49206
49207+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49208+ if (current->exec_id != m->exec_id) {
49209+ gr_log_badprocpid("maps");
49210+ return 0;
49211+ }
49212+#endif
49213+
49214 show_map_vma(m, vma, is_pid);
49215
49216 if (m->count < m->size) /* vma is copied successfully */
49217@@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49218 .private = &mss,
49219 };
49220
49221+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49222+ if (current->exec_id != m->exec_id) {
49223+ gr_log_badprocpid("smaps");
49224+ return 0;
49225+ }
49226+#endif
49227 memset(&mss, 0, sizeof mss);
49228- mss.vma = vma;
49229- /* mmap_sem is held in m_start */
49230- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49231- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49232-
49233+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49234+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49235+#endif
49236+ mss.vma = vma;
49237+ /* mmap_sem is held in m_start */
49238+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49239+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49240+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49241+ }
49242+#endif
49243 show_map_vma(m, vma, is_pid);
49244
49245 seq_printf(m,
49246@@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49247 "KernelPageSize: %8lu kB\n"
49248 "MMUPageSize: %8lu kB\n"
49249 "Locked: %8lu kB\n",
49250+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49251+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49252+#else
49253 (vma->vm_end - vma->vm_start) >> 10,
49254+#endif
49255 mss.resident >> 10,
49256 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49257 mss.shared_clean >> 10,
49258@@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49259 int n;
49260 char buffer[50];
49261
49262+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49263+ if (current->exec_id != m->exec_id) {
49264+ gr_log_badprocpid("numa_maps");
49265+ return 0;
49266+ }
49267+#endif
49268+
49269 if (!mm)
49270 return 0;
49271
49272@@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49273 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49274 mpol_cond_put(pol);
49275
49276+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49277+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49278+#else
49279 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49280+#endif
49281
49282 if (file) {
49283 seq_printf(m, " file=");
49284- seq_path(m, &file->f_path, "\n\t= ");
49285+ seq_path(m, &file->f_path, "\n\t\\= ");
49286 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49287 seq_printf(m, " heap");
49288 } else {
49289diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49290index 1ccfa53..0848f95 100644
49291--- a/fs/proc/task_nommu.c
49292+++ b/fs/proc/task_nommu.c
49293@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49294 else
49295 bytes += kobjsize(mm);
49296
49297- if (current->fs && current->fs->users > 1)
49298+ if (current->fs && atomic_read(&current->fs->users) > 1)
49299 sbytes += kobjsize(current->fs);
49300 else
49301 bytes += kobjsize(current->fs);
49302@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49303
49304 if (file) {
49305 pad_len_spaces(m, len);
49306- seq_path(m, &file->f_path, "");
49307+ seq_path(m, &file->f_path, "\n\\");
49308 } else if (mm) {
49309 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49310
49311diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49312index d67908b..d13f6a6 100644
49313--- a/fs/quota/netlink.c
49314+++ b/fs/quota/netlink.c
49315@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49316 void quota_send_warning(short type, unsigned int id, dev_t dev,
49317 const char warntype)
49318 {
49319- static atomic_t seq;
49320+ static atomic_unchecked_t seq;
49321 struct sk_buff *skb;
49322 void *msg_head;
49323 int ret;
49324@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49325 "VFS: Not enough memory to send quota warning.\n");
49326 return;
49327 }
49328- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49329+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49330 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49331 if (!msg_head) {
49332 printk(KERN_ERR
49333diff --git a/fs/readdir.c b/fs/readdir.c
49334index 39e3370..20d446d 100644
49335--- a/fs/readdir.c
49336+++ b/fs/readdir.c
49337@@ -17,6 +17,7 @@
49338 #include <linux/security.h>
49339 #include <linux/syscalls.h>
49340 #include <linux/unistd.h>
49341+#include <linux/namei.h>
49342
49343 #include <asm/uaccess.h>
49344
49345@@ -67,6 +68,7 @@ struct old_linux_dirent {
49346
49347 struct readdir_callback {
49348 struct old_linux_dirent __user * dirent;
49349+ struct file * file;
49350 int result;
49351 };
49352
49353@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49354 buf->result = -EOVERFLOW;
49355 return -EOVERFLOW;
49356 }
49357+
49358+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49359+ return 0;
49360+
49361 buf->result++;
49362 dirent = buf->dirent;
49363 if (!access_ok(VERIFY_WRITE, dirent,
49364@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49365
49366 buf.result = 0;
49367 buf.dirent = dirent;
49368+ buf.file = file;
49369
49370 error = vfs_readdir(file, fillonedir, &buf);
49371 if (buf.result)
49372@@ -141,6 +148,7 @@ struct linux_dirent {
49373 struct getdents_callback {
49374 struct linux_dirent __user * current_dir;
49375 struct linux_dirent __user * previous;
49376+ struct file * file;
49377 int count;
49378 int error;
49379 };
49380@@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49381 buf->error = -EOVERFLOW;
49382 return -EOVERFLOW;
49383 }
49384+
49385+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49386+ return 0;
49387+
49388 dirent = buf->previous;
49389 if (dirent) {
49390 if (__put_user(offset, &dirent->d_off))
49391@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49392 buf.previous = NULL;
49393 buf.count = count;
49394 buf.error = 0;
49395+ buf.file = file;
49396
49397 error = vfs_readdir(file, filldir, &buf);
49398 if (error >= 0)
49399@@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49400 struct getdents_callback64 {
49401 struct linux_dirent64 __user * current_dir;
49402 struct linux_dirent64 __user * previous;
49403+ struct file *file;
49404 int count;
49405 int error;
49406 };
49407@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49408 buf->error = -EINVAL; /* only used if we fail.. */
49409 if (reclen > buf->count)
49410 return -EINVAL;
49411+
49412+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49413+ return 0;
49414+
49415 dirent = buf->previous;
49416 if (dirent) {
49417 if (__put_user(offset, &dirent->d_off))
49418@@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49419
49420 buf.current_dir = dirent;
49421 buf.previous = NULL;
49422+ buf.file = file;
49423 buf.count = count;
49424 buf.error = 0;
49425
49426@@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49427 error = buf.error;
49428 lastdirent = buf.previous;
49429 if (lastdirent) {
49430- typeof(lastdirent->d_off) d_off = file->f_pos;
49431+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49432 if (__put_user(d_off, &lastdirent->d_off))
49433 error = -EFAULT;
49434 else
49435diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49436index 2b7882b..1c5ef48 100644
49437--- a/fs/reiserfs/do_balan.c
49438+++ b/fs/reiserfs/do_balan.c
49439@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49440 return;
49441 }
49442
49443- atomic_inc(&(fs_generation(tb->tb_sb)));
49444+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49445 do_balance_starts(tb);
49446
49447 /* balance leaf returns 0 except if combining L R and S into
49448diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49449index 2c1ade6..8c59d8d 100644
49450--- a/fs/reiserfs/procfs.c
49451+++ b/fs/reiserfs/procfs.c
49452@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49453 "SMALL_TAILS " : "NO_TAILS ",
49454 replay_only(sb) ? "REPLAY_ONLY " : "",
49455 convert_reiserfs(sb) ? "CONV " : "",
49456- atomic_read(&r->s_generation_counter),
49457+ atomic_read_unchecked(&r->s_generation_counter),
49458 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49459 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49460 SF(s_good_search_by_key_reada), SF(s_bmaps),
49461diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
49462index 33215f5..c5d427a 100644
49463--- a/fs/reiserfs/reiserfs.h
49464+++ b/fs/reiserfs/reiserfs.h
49465@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
49466 /* Comment? -Hans */
49467 wait_queue_head_t s_wait;
49468 /* To be obsoleted soon by per buffer seals.. -Hans */
49469- atomic_t s_generation_counter; // increased by one every time the
49470+ atomic_unchecked_t s_generation_counter; // increased by one every time the
49471 // tree gets re-balanced
49472 unsigned long s_properties; /* File system properties. Currently holds
49473 on-disk FS format */
49474@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
49475 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
49476
49477 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
49478-#define get_generation(s) atomic_read (&fs_generation(s))
49479+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
49480 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
49481 #define __fs_changed(gen,s) (gen != get_generation (s))
49482 #define fs_changed(gen,s) \
49483diff --git a/fs/select.c b/fs/select.c
49484index bae3215..06b4707 100644
49485--- a/fs/select.c
49486+++ b/fs/select.c
49487@@ -20,6 +20,7 @@
49488 #include <linux/export.h>
49489 #include <linux/slab.h>
49490 #include <linux/poll.h>
49491+#include <linux/security.h>
49492 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49493 #include <linux/file.h>
49494 #include <linux/fdtable.h>
49495@@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49496 struct poll_list *walk = head;
49497 unsigned long todo = nfds;
49498
49499+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49500 if (nfds > rlimit(RLIMIT_NOFILE))
49501 return -EINVAL;
49502
49503diff --git a/fs/seq_file.c b/fs/seq_file.c
49504index 0cbd049..64e705c 100644
49505--- a/fs/seq_file.c
49506+++ b/fs/seq_file.c
49507@@ -9,6 +9,7 @@
49508 #include <linux/export.h>
49509 #include <linux/seq_file.h>
49510 #include <linux/slab.h>
49511+#include <linux/sched.h>
49512
49513 #include <asm/uaccess.h>
49514 #include <asm/page.h>
49515@@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49516 memset(p, 0, sizeof(*p));
49517 mutex_init(&p->lock);
49518 p->op = op;
49519+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49520+ p->exec_id = current->exec_id;
49521+#endif
49522
49523 /*
49524 * Wrappers around seq_open(e.g. swaps_open) need to be
49525@@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49526 return 0;
49527 }
49528 if (!m->buf) {
49529- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49530+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49531 if (!m->buf)
49532 return -ENOMEM;
49533 }
49534@@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49535 Eoverflow:
49536 m->op->stop(m, p);
49537 kfree(m->buf);
49538- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49539+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49540 return !m->buf ? -ENOMEM : -EAGAIN;
49541 }
49542
49543@@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49544
49545 /* grab buffer if we didn't have one */
49546 if (!m->buf) {
49547- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49548+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49549 if (!m->buf)
49550 goto Enomem;
49551 }
49552@@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49553 goto Fill;
49554 m->op->stop(m, p);
49555 kfree(m->buf);
49556- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49557+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49558 if (!m->buf)
49559 goto Enomem;
49560 m->count = 0;
49561@@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
49562 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49563 void *data)
49564 {
49565- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49566+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49567 int res = -ENOMEM;
49568
49569 if (op) {
49570diff --git a/fs/splice.c b/fs/splice.c
49571index 7bf08fa..eb35c2f 100644
49572--- a/fs/splice.c
49573+++ b/fs/splice.c
49574@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49575 pipe_lock(pipe);
49576
49577 for (;;) {
49578- if (!pipe->readers) {
49579+ if (!atomic_read(&pipe->readers)) {
49580 send_sig(SIGPIPE, current, 0);
49581 if (!ret)
49582 ret = -EPIPE;
49583@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49584 do_wakeup = 0;
49585 }
49586
49587- pipe->waiting_writers++;
49588+ atomic_inc(&pipe->waiting_writers);
49589 pipe_wait(pipe);
49590- pipe->waiting_writers--;
49591+ atomic_dec(&pipe->waiting_writers);
49592 }
49593
49594 pipe_unlock(pipe);
49595@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49596 old_fs = get_fs();
49597 set_fs(get_ds());
49598 /* The cast to a user pointer is valid due to the set_fs() */
49599- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49600+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49601 set_fs(old_fs);
49602
49603 return res;
49604@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49605 old_fs = get_fs();
49606 set_fs(get_ds());
49607 /* The cast to a user pointer is valid due to the set_fs() */
49608- res = vfs_write(file, (const char __user *)buf, count, &pos);
49609+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49610 set_fs(old_fs);
49611
49612 return res;
49613@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49614 goto err;
49615
49616 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49617- vec[i].iov_base = (void __user *) page_address(page);
49618+ vec[i].iov_base = (void __force_user *) page_address(page);
49619 vec[i].iov_len = this_len;
49620 spd.pages[i] = page;
49621 spd.nr_pages++;
49622@@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49623 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49624 {
49625 while (!pipe->nrbufs) {
49626- if (!pipe->writers)
49627+ if (!atomic_read(&pipe->writers))
49628 return 0;
49629
49630- if (!pipe->waiting_writers && sd->num_spliced)
49631+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49632 return 0;
49633
49634 if (sd->flags & SPLICE_F_NONBLOCK)
49635@@ -1187,7 +1187,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49636 * out of the pipe right after the splice_to_pipe(). So set
49637 * PIPE_READERS appropriately.
49638 */
49639- pipe->readers = 1;
49640+ atomic_set(&pipe->readers, 1);
49641
49642 current->splice_pipe = pipe;
49643 }
49644@@ -1740,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49645 ret = -ERESTARTSYS;
49646 break;
49647 }
49648- if (!pipe->writers)
49649+ if (!atomic_read(&pipe->writers))
49650 break;
49651- if (!pipe->waiting_writers) {
49652+ if (!atomic_read(&pipe->waiting_writers)) {
49653 if (flags & SPLICE_F_NONBLOCK) {
49654 ret = -EAGAIN;
49655 break;
49656@@ -1774,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49657 pipe_lock(pipe);
49658
49659 while (pipe->nrbufs >= pipe->buffers) {
49660- if (!pipe->readers) {
49661+ if (!atomic_read(&pipe->readers)) {
49662 send_sig(SIGPIPE, current, 0);
49663 ret = -EPIPE;
49664 break;
49665@@ -1787,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49666 ret = -ERESTARTSYS;
49667 break;
49668 }
49669- pipe->waiting_writers++;
49670+ atomic_inc(&pipe->waiting_writers);
49671 pipe_wait(pipe);
49672- pipe->waiting_writers--;
49673+ atomic_dec(&pipe->waiting_writers);
49674 }
49675
49676 pipe_unlock(pipe);
49677@@ -1825,14 +1825,14 @@ retry:
49678 pipe_double_lock(ipipe, opipe);
49679
49680 do {
49681- if (!opipe->readers) {
49682+ if (!atomic_read(&opipe->readers)) {
49683 send_sig(SIGPIPE, current, 0);
49684 if (!ret)
49685 ret = -EPIPE;
49686 break;
49687 }
49688
49689- if (!ipipe->nrbufs && !ipipe->writers)
49690+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49691 break;
49692
49693 /*
49694@@ -1929,7 +1929,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49695 pipe_double_lock(ipipe, opipe);
49696
49697 do {
49698- if (!opipe->readers) {
49699+ if (!atomic_read(&opipe->readers)) {
49700 send_sig(SIGPIPE, current, 0);
49701 if (!ret)
49702 ret = -EPIPE;
49703@@ -1974,7 +1974,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49704 * return EAGAIN if we have the potential of some data in the
49705 * future, otherwise just return 0
49706 */
49707- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49708+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49709 ret = -EAGAIN;
49710
49711 pipe_unlock(ipipe);
49712diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49713index e6bb9b2..d8e3951 100644
49714--- a/fs/sysfs/dir.c
49715+++ b/fs/sysfs/dir.c
49716@@ -678,6 +678,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49717 struct sysfs_dirent *sd;
49718 int rc;
49719
49720+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49721+ const char *parent_name = parent_sd->s_name;
49722+
49723+ mode = S_IFDIR | S_IRWXU;
49724+
49725+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49726+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49727+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49728+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49729+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49730+#endif
49731+
49732 /* allocate */
49733 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49734 if (!sd)
49735diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49736index 00012e3..8392349 100644
49737--- a/fs/sysfs/file.c
49738+++ b/fs/sysfs/file.c
49739@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49740
49741 struct sysfs_open_dirent {
49742 atomic_t refcnt;
49743- atomic_t event;
49744+ atomic_unchecked_t event;
49745 wait_queue_head_t poll;
49746 struct list_head buffers; /* goes through sysfs_buffer.list */
49747 };
49748@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49749 if (!sysfs_get_active(attr_sd))
49750 return -ENODEV;
49751
49752- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49753+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49754 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49755
49756 sysfs_put_active(attr_sd);
49757@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49758 return -ENOMEM;
49759
49760 atomic_set(&new_od->refcnt, 0);
49761- atomic_set(&new_od->event, 1);
49762+ atomic_set_unchecked(&new_od->event, 1);
49763 init_waitqueue_head(&new_od->poll);
49764 INIT_LIST_HEAD(&new_od->buffers);
49765 goto retry;
49766@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49767
49768 sysfs_put_active(attr_sd);
49769
49770- if (buffer->event != atomic_read(&od->event))
49771+ if (buffer->event != atomic_read_unchecked(&od->event))
49772 goto trigger;
49773
49774 return DEFAULT_POLLMASK;
49775@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49776
49777 od = sd->s_attr.open;
49778 if (od) {
49779- atomic_inc(&od->event);
49780+ atomic_inc_unchecked(&od->event);
49781 wake_up_interruptible(&od->poll);
49782 }
49783
49784diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49785index a7ac78f..02158e1 100644
49786--- a/fs/sysfs/symlink.c
49787+++ b/fs/sysfs/symlink.c
49788@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49789
49790 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49791 {
49792- char *page = nd_get_link(nd);
49793+ const char *page = nd_get_link(nd);
49794 if (!IS_ERR(page))
49795 free_page((unsigned long)page);
49796 }
49797diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49798index c175b4d..8f36a16 100644
49799--- a/fs/udf/misc.c
49800+++ b/fs/udf/misc.c
49801@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49802
49803 u8 udf_tag_checksum(const struct tag *t)
49804 {
49805- u8 *data = (u8 *)t;
49806+ const u8 *data = (const u8 *)t;
49807 u8 checksum = 0;
49808 int i;
49809 for (i = 0; i < sizeof(struct tag); ++i)
49810diff --git a/fs/utimes.c b/fs/utimes.c
49811index fa4dbe4..e12d1b9 100644
49812--- a/fs/utimes.c
49813+++ b/fs/utimes.c
49814@@ -1,6 +1,7 @@
49815 #include <linux/compiler.h>
49816 #include <linux/file.h>
49817 #include <linux/fs.h>
49818+#include <linux/security.h>
49819 #include <linux/linkage.h>
49820 #include <linux/mount.h>
49821 #include <linux/namei.h>
49822@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49823 goto mnt_drop_write_and_out;
49824 }
49825 }
49826+
49827+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49828+ error = -EACCES;
49829+ goto mnt_drop_write_and_out;
49830+ }
49831+
49832 mutex_lock(&inode->i_mutex);
49833 error = notify_change(path->dentry, &newattrs);
49834 mutex_unlock(&inode->i_mutex);
49835diff --git a/fs/xattr.c b/fs/xattr.c
49836index 1d7ac37..23cb9ec 100644
49837--- a/fs/xattr.c
49838+++ b/fs/xattr.c
49839@@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49840 * Extended attribute SET operations
49841 */
49842 static long
49843-setxattr(struct dentry *d, const char __user *name, const void __user *value,
49844+setxattr(struct path *path, const char __user *name, const void __user *value,
49845 size_t size, int flags)
49846 {
49847 int error;
49848@@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49849 }
49850 }
49851
49852- error = vfs_setxattr(d, kname, kvalue, size, flags);
49853+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49854+ error = -EACCES;
49855+ goto out;
49856+ }
49857+
49858+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49859 out:
49860 if (vvalue)
49861 vfree(vvalue);
49862@@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49863 return error;
49864 error = mnt_want_write(path.mnt);
49865 if (!error) {
49866- error = setxattr(path.dentry, name, value, size, flags);
49867+ error = setxattr(&path, name, value, size, flags);
49868 mnt_drop_write(path.mnt);
49869 }
49870 path_put(&path);
49871@@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49872 return error;
49873 error = mnt_want_write(path.mnt);
49874 if (!error) {
49875- error = setxattr(path.dentry, name, value, size, flags);
49876+ error = setxattr(&path, name, value, size, flags);
49877 mnt_drop_write(path.mnt);
49878 }
49879 path_put(&path);
49880@@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49881 {
49882 int fput_needed;
49883 struct file *f;
49884- struct dentry *dentry;
49885 int error = -EBADF;
49886
49887 f = fget_light(fd, &fput_needed);
49888 if (!f)
49889 return error;
49890- dentry = f->f_path.dentry;
49891- audit_inode(NULL, dentry);
49892+ audit_inode(NULL, f->f_path.dentry);
49893 error = mnt_want_write_file(f);
49894 if (!error) {
49895- error = setxattr(dentry, name, value, size, flags);
49896+ error = setxattr(&f->f_path, name, value, size, flags);
49897 mnt_drop_write_file(f);
49898 }
49899 fput_light(f, fput_needed);
49900diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49901index 69d06b0..c0996e5 100644
49902--- a/fs/xattr_acl.c
49903+++ b/fs/xattr_acl.c
49904@@ -17,8 +17,8 @@
49905 struct posix_acl *
49906 posix_acl_from_xattr(const void *value, size_t size)
49907 {
49908- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49909- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49910+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49911+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49912 int count;
49913 struct posix_acl *acl;
49914 struct posix_acl_entry *acl_e;
49915diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49916index 58b815e..595ddee 100644
49917--- a/fs/xfs/xfs_bmap.c
49918+++ b/fs/xfs/xfs_bmap.c
49919@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
49920 int nmap,
49921 int ret_nmap);
49922 #else
49923-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49924+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49925 #endif /* DEBUG */
49926
49927 STATIC int
49928diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49929index 19bf0c5..9f26b02 100644
49930--- a/fs/xfs/xfs_dir2_sf.c
49931+++ b/fs/xfs/xfs_dir2_sf.c
49932@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
49933 }
49934
49935 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49936- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49937+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49938+ char name[sfep->namelen];
49939+ memcpy(name, sfep->name, sfep->namelen);
49940+ if (filldir(dirent, name, sfep->namelen,
49941+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
49942+ *offset = off & 0x7fffffff;
49943+ return 0;
49944+ }
49945+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49946 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49947 *offset = off & 0x7fffffff;
49948 return 0;
49949diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49950index 3a05a41..320bec6 100644
49951--- a/fs/xfs/xfs_ioctl.c
49952+++ b/fs/xfs/xfs_ioctl.c
49953@@ -126,7 +126,7 @@ xfs_find_handle(
49954 }
49955
49956 error = -EFAULT;
49957- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49958+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49959 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49960 goto out_put;
49961
49962diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49963index 1a25fd8..e935581 100644
49964--- a/fs/xfs/xfs_iops.c
49965+++ b/fs/xfs/xfs_iops.c
49966@@ -394,7 +394,7 @@ xfs_vn_put_link(
49967 struct nameidata *nd,
49968 void *p)
49969 {
49970- char *s = nd_get_link(nd);
49971+ const char *s = nd_get_link(nd);
49972
49973 if (!IS_ERR(s))
49974 kfree(s);
49975diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49976new file mode 100644
49977index 0000000..4d533f1
49978--- /dev/null
49979+++ b/grsecurity/Kconfig
49980@@ -0,0 +1,941 @@
49981+#
49982+# grecurity configuration
49983+#
49984+menu "Memory Protections"
49985+depends on GRKERNSEC
49986+
49987+config GRKERNSEC_KMEM
49988+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49989+ default y if GRKERNSEC_CONFIG_AUTO
49990+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49991+ help
49992+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49993+ be written to or read from to modify or leak the contents of the running
49994+ kernel. /dev/port will also not be allowed to be opened. If you have module
49995+ support disabled, enabling this will close up four ways that are
49996+ currently used to insert malicious code into the running kernel.
49997+ Even with all these features enabled, we still highly recommend that
49998+ you use the RBAC system, as it is still possible for an attacker to
49999+ modify the running kernel through privileged I/O granted by ioperm/iopl.
50000+ If you are not using XFree86, you may be able to stop this additional
50001+ case by enabling the 'Disable privileged I/O' option. Though nothing
50002+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50003+ but only to video memory, which is the only writing we allow in this
50004+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50005+ not be allowed to mprotect it with PROT_WRITE later.
50006+ It is highly recommended that you say Y here if you meet all the
50007+ conditions above.
50008+
50009+config GRKERNSEC_VM86
50010+ bool "Restrict VM86 mode"
50011+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50012+ depends on X86_32
50013+
50014+ help
50015+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50016+ make use of a special execution mode on 32bit x86 processors called
50017+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50018+ video cards and will still work with this option enabled. The purpose
50019+ of the option is to prevent exploitation of emulation errors in
50020+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
50021+ Nearly all users should be able to enable this option.
50022+
50023+config GRKERNSEC_IO
50024+ bool "Disable privileged I/O"
50025+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50026+ depends on X86
50027+ select RTC_CLASS
50028+ select RTC_INTF_DEV
50029+ select RTC_DRV_CMOS
50030+
50031+ help
50032+ If you say Y here, all ioperm and iopl calls will return an error.
50033+ Ioperm and iopl can be used to modify the running kernel.
50034+ Unfortunately, some programs need this access to operate properly,
50035+ the most notable of which are XFree86 and hwclock. hwclock can be
50036+ remedied by having RTC support in the kernel, so real-time
50037+ clock support is enabled if this option is enabled, to ensure
50038+ that hwclock operates correctly. XFree86 still will not
50039+ operate correctly with this option enabled, so DO NOT CHOOSE Y
50040+ IF YOU USE XFree86. If you use XFree86 and you still want to
50041+ protect your kernel against modification, use the RBAC system.
50042+
50043+config GRKERNSEC_PROC_MEMMAP
50044+ bool "Harden ASLR against information leaks and entropy reduction"
50045+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50046+ depends on PAX_NOEXEC || PAX_ASLR
50047+ help
50048+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50049+ give no information about the addresses of its mappings if
50050+ PaX features that rely on random addresses are enabled on the task.
50051+ In addition to sanitizing this information and disabling other
50052+ dangerous sources of information, this option causes reads of sensitive
50053+ /proc/<pid> entries where the file descriptor was opened in a different
50054+ task than the one performing the read. Such attempts are logged.
50055+ This option also limits argv/env strings for suid/sgid binaries
50056+ to 512KB to prevent a complete exhaustion of the stack entropy provided
50057+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50058+ binaries to prevent alternative mmap layouts from being abused.
50059+
50060+ If you use PaX it is essential that you say Y here as it closes up
50061+ several holes that make full ASLR useless locally.
50062+
50063+config GRKERNSEC_BRUTE
50064+ bool "Deter exploit bruteforcing"
50065+ default y if GRKERNSEC_CONFIG_AUTO
50066+ help
50067+ If you say Y here, attempts to bruteforce exploits against forking
50068+ daemons such as apache or sshd, as well as against suid/sgid binaries
50069+ will be deterred. When a child of a forking daemon is killed by PaX
50070+ or crashes due to an illegal instruction or other suspicious signal,
50071+ the parent process will be delayed 30 seconds upon every subsequent
50072+ fork until the administrator is able to assess the situation and
50073+ restart the daemon.
50074+ In the suid/sgid case, the attempt is logged, the user has all their
50075+ processes terminated, and they are prevented from executing any further
50076+ processes for 15 minutes.
50077+ It is recommended that you also enable signal logging in the auditing
50078+ section so that logs are generated when a process triggers a suspicious
50079+ signal.
50080+ If the sysctl option is enabled, a sysctl option with name
50081+ "deter_bruteforce" is created.
50082+
50083+
50084+config GRKERNSEC_MODHARDEN
50085+ bool "Harden module auto-loading"
50086+ default y if GRKERNSEC_CONFIG_AUTO
50087+ depends on MODULES
50088+ help
50089+ If you say Y here, module auto-loading in response to use of some
50090+ feature implemented by an unloaded module will be restricted to
50091+ root users. Enabling this option helps defend against attacks
50092+ by unprivileged users who abuse the auto-loading behavior to
50093+ cause a vulnerable module to load that is then exploited.
50094+
50095+ If this option prevents a legitimate use of auto-loading for a
50096+ non-root user, the administrator can execute modprobe manually
50097+ with the exact name of the module mentioned in the alert log.
50098+ Alternatively, the administrator can add the module to the list
50099+ of modules loaded at boot by modifying init scripts.
50100+
50101+ Modification of init scripts will most likely be needed on
50102+ Ubuntu servers with encrypted home directory support enabled,
50103+ as the first non-root user logging in will cause the ecb(aes),
50104+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50105+
50106+config GRKERNSEC_HIDESYM
50107+ bool "Hide kernel symbols"
50108+ default y if GRKERNSEC_CONFIG_AUTO
50109+ select PAX_USERCOPY_SLABS
50110+ help
50111+ If you say Y here, getting information on loaded modules, and
50112+ displaying all kernel symbols through a syscall will be restricted
50113+ to users with CAP_SYS_MODULE. For software compatibility reasons,
50114+ /proc/kallsyms will be restricted to the root user. The RBAC
50115+ system can hide that entry even from root.
50116+
50117+ This option also prevents leaking of kernel addresses through
50118+ several /proc entries.
50119+
50120+ Note that this option is only effective provided the following
50121+ conditions are met:
50122+ 1) The kernel using grsecurity is not precompiled by some distribution
50123+ 2) You have also enabled GRKERNSEC_DMESG
50124+ 3) You are using the RBAC system and hiding other files such as your
50125+ kernel image and System.map. Alternatively, enabling this option
50126+ causes the permissions on /boot, /lib/modules, and the kernel
50127+ source directory to change at compile time to prevent
50128+ reading by non-root users.
50129+ If the above conditions are met, this option will aid in providing a
50130+ useful protection against local kernel exploitation of overflows
50131+ and arbitrary read/write vulnerabilities.
50132+
50133+config GRKERNSEC_KERN_LOCKOUT
50134+ bool "Active kernel exploit response"
50135+ default y if GRKERNSEC_CONFIG_AUTO
50136+ depends on X86 || ARM || PPC || SPARC
50137+ help
50138+ If you say Y here, when a PaX alert is triggered due to suspicious
50139+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50140+ or an OOPS occurs due to bad memory accesses, instead of just
50141+ terminating the offending process (and potentially allowing
50142+ a subsequent exploit from the same user), we will take one of two
50143+ actions:
50144+ If the user was root, we will panic the system
50145+ If the user was non-root, we will log the attempt, terminate
50146+ all processes owned by the user, then prevent them from creating
50147+ any new processes until the system is restarted
50148+ This deters repeated kernel exploitation/bruteforcing attempts
50149+ and is useful for later forensics.
50150+
50151+endmenu
50152+menu "Role Based Access Control Options"
50153+depends on GRKERNSEC
50154+
50155+config GRKERNSEC_RBAC_DEBUG
50156+ bool
50157+
50158+config GRKERNSEC_NO_RBAC
50159+ bool "Disable RBAC system"
50160+ help
50161+ If you say Y here, the /dev/grsec device will be removed from the kernel,
50162+ preventing the RBAC system from being enabled. You should only say Y
50163+ here if you have no intention of using the RBAC system, so as to prevent
50164+ an attacker with root access from misusing the RBAC system to hide files
50165+ and processes when loadable module support and /dev/[k]mem have been
50166+ locked down.
50167+
50168+config GRKERNSEC_ACL_HIDEKERN
50169+ bool "Hide kernel processes"
50170+ help
50171+ If you say Y here, all kernel threads will be hidden to all
50172+ processes but those whose subject has the "view hidden processes"
50173+ flag.
50174+
50175+config GRKERNSEC_ACL_MAXTRIES
50176+ int "Maximum tries before password lockout"
50177+ default 3
50178+ help
50179+ This option enforces the maximum number of times a user can attempt
50180+ to authorize themselves with the grsecurity RBAC system before being
50181+ denied the ability to attempt authorization again for a specified time.
50182+ The lower the number, the harder it will be to brute-force a password.
50183+
50184+config GRKERNSEC_ACL_TIMEOUT
50185+ int "Time to wait after max password tries, in seconds"
50186+ default 30
50187+ help
50188+ This option specifies the time the user must wait after attempting to
50189+ authorize to the RBAC system with the maximum number of invalid
50190+ passwords. The higher the number, the harder it will be to brute-force
50191+ a password.
50192+
50193+endmenu
50194+menu "Filesystem Protections"
50195+depends on GRKERNSEC
50196+
50197+config GRKERNSEC_PROC
50198+ bool "Proc restrictions"
50199+ default y if GRKERNSEC_CONFIG_AUTO
50200+ help
50201+ If you say Y here, the permissions of the /proc filesystem
50202+ will be altered to enhance system security and privacy. You MUST
50203+ choose either a user only restriction or a user and group restriction.
50204+ Depending upon the option you choose, you can either restrict users to
50205+ see only the processes they themselves run, or choose a group that can
50206+ view all processes and files normally restricted to root if you choose
50207+ the "restrict to user only" option. NOTE: If you're running identd or
50208+ ntpd as a non-root user, you will have to run it as the group you
50209+ specify here.
50210+
50211+config GRKERNSEC_PROC_USER
50212+ bool "Restrict /proc to user only"
50213+ depends on GRKERNSEC_PROC
50214+ help
50215+ If you say Y here, non-root users will only be able to view their own
50216+ processes, and restricts them from viewing network-related information,
50217+ and viewing kernel symbol and module information.
50218+
50219+config GRKERNSEC_PROC_USERGROUP
50220+ bool "Allow special group"
50221+ default y if GRKERNSEC_CONFIG_AUTO
50222+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50223+ help
50224+ If you say Y here, you will be able to select a group that will be
50225+ able to view all processes and network-related information. If you've
50226+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50227+ remain hidden. This option is useful if you want to run identd as
50228+ a non-root user.
50229+
50230+config GRKERNSEC_PROC_GID
50231+ int "GID for special group"
50232+ depends on GRKERNSEC_PROC_USERGROUP
50233+ default 1001
50234+
50235+config GRKERNSEC_PROC_ADD
50236+ bool "Additional restrictions"
50237+ default y if GRKERNSEC_CONFIG_AUTO
50238+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50239+ help
50240+ If you say Y here, additional restrictions will be placed on
50241+ /proc that keep normal users from viewing device information and
50242+ slabinfo information that could be useful for exploits.
50243+
50244+config GRKERNSEC_LINK
50245+ bool "Linking restrictions"
50246+ default y if GRKERNSEC_CONFIG_AUTO
50247+ help
50248+ If you say Y here, /tmp race exploits will be prevented, since users
50249+ will no longer be able to follow symlinks owned by other users in
50250+ world-writable +t directories (e.g. /tmp), unless the owner of the
50251+ symlink is the owner of the directory. users will also not be
50252+ able to hardlink to files they do not own. If the sysctl option is
50253+ enabled, a sysctl option with name "linking_restrictions" is created.
50254+
50255+config GRKERNSEC_SYMLINKOWN
50256+ bool "Kernel-enforced SymlinksIfOwnerMatch"
50257+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50258+ help
50259+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
50260+ that prevents it from being used as a security feature. As Apache
50261+ verifies the symlink by performing a stat() against the target of
50262+ the symlink before it is followed, an attacker can setup a symlink
50263+ to point to a same-owned file, then replace the symlink with one
50264+ that targets another user's file just after Apache "validates" the
50265+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
50266+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50267+ will be in place for the group you specify. If the sysctl option
50268+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
50269+ created.
50270+
50271+config GRKERNSEC_SYMLINKOWN_GID
50272+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50273+ depends on GRKERNSEC_SYMLINKOWN
50274+ default 1006
50275+ help
50276+ Setting this GID determines what group kernel-enforced
50277+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50278+ is enabled, a sysctl option with name "symlinkown_gid" is created.
50279+
50280+config GRKERNSEC_FIFO
50281+ bool "FIFO restrictions"
50282+ default y if GRKERNSEC_CONFIG_AUTO
50283+ help
50284+ If you say Y here, users will not be able to write to FIFOs they don't
50285+ own in world-writable +t directories (e.g. /tmp), unless the owner of
50286+ the FIFO is the same owner of the directory it's held in. If the sysctl
50287+ option is enabled, a sysctl option with name "fifo_restrictions" is
50288+ created.
50289+
50290+config GRKERNSEC_SYSFS_RESTRICT
50291+ bool "Sysfs/debugfs restriction"
50292+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50293+ depends on SYSFS
50294+ help
50295+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50296+ any filesystem normally mounted under it (e.g. debugfs) will be
50297+ mostly accessible only by root. These filesystems generally provide access
50298+ to hardware and debug information that isn't appropriate for unprivileged
50299+ users of the system. Sysfs and debugfs have also become a large source
50300+ of new vulnerabilities, ranging from infoleaks to local compromise.
50301+ There has been very little oversight with an eye toward security involved
50302+ in adding new exporters of information to these filesystems, so their
50303+ use is discouraged.
50304+ For reasons of compatibility, a few directories have been whitelisted
50305+ for access by non-root users:
50306+ /sys/fs/selinux
50307+ /sys/fs/fuse
50308+ /sys/devices/system/cpu
50309+
50310+config GRKERNSEC_ROFS
50311+ bool "Runtime read-only mount protection"
50312+ help
50313+ If you say Y here, a sysctl option with name "romount_protect" will
50314+ be created. By setting this option to 1 at runtime, filesystems
50315+ will be protected in the following ways:
50316+ * No new writable mounts will be allowed
50317+ * Existing read-only mounts won't be able to be remounted read/write
50318+ * Write operations will be denied on all block devices
50319+ This option acts independently of grsec_lock: once it is set to 1,
50320+ it cannot be turned off. Therefore, please be mindful of the resulting
50321+ behavior if this option is enabled in an init script on a read-only
50322+ filesystem. This feature is mainly intended for secure embedded systems.
50323+
50324+config GRKERNSEC_CHROOT
50325+ bool "Chroot jail restrictions"
50326+ default y if GRKERNSEC_CONFIG_AUTO
50327+ help
50328+ If you say Y here, you will be able to choose several options that will
50329+ make breaking out of a chrooted jail much more difficult. If you
50330+ encounter no software incompatibilities with the following options, it
50331+ is recommended that you enable each one.
50332+
50333+config GRKERNSEC_CHROOT_MOUNT
50334+ bool "Deny mounts"
50335+ default y if GRKERNSEC_CONFIG_AUTO
50336+ depends on GRKERNSEC_CHROOT
50337+ help
50338+ If you say Y here, processes inside a chroot will not be able to
50339+ mount or remount filesystems. If the sysctl option is enabled, a
50340+ sysctl option with name "chroot_deny_mount" is created.
50341+
50342+config GRKERNSEC_CHROOT_DOUBLE
50343+ bool "Deny double-chroots"
50344+ default y if GRKERNSEC_CONFIG_AUTO
50345+ depends on GRKERNSEC_CHROOT
50346+ help
50347+ If you say Y here, processes inside a chroot will not be able to chroot
50348+ again outside the chroot. This is a widely used method of breaking
50349+ out of a chroot jail and should not be allowed. If the sysctl
50350+ option is enabled, a sysctl option with name
50351+ "chroot_deny_chroot" is created.
50352+
50353+config GRKERNSEC_CHROOT_PIVOT
50354+ bool "Deny pivot_root in chroot"
50355+ default y if GRKERNSEC_CONFIG_AUTO
50356+ depends on GRKERNSEC_CHROOT
50357+ help
50358+ If you say Y here, processes inside a chroot will not be able to use
50359+ a function called pivot_root() that was introduced in Linux 2.3.41. It
50360+ works similar to chroot in that it changes the root filesystem. This
50361+ function could be misused in a chrooted process to attempt to break out
50362+ of the chroot, and therefore should not be allowed. If the sysctl
50363+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
50364+ created.
50365+
50366+config GRKERNSEC_CHROOT_CHDIR
50367+ bool "Enforce chdir(\"/\") on all chroots"
50368+ default y if GRKERNSEC_CONFIG_AUTO
50369+ depends on GRKERNSEC_CHROOT
50370+ help
50371+ If you say Y here, the current working directory of all newly-chrooted
50372+ applications will be set to the the root directory of the chroot.
50373+ The man page on chroot(2) states:
50374+ Note that this call does not change the current working
50375+ directory, so that `.' can be outside the tree rooted at
50376+ `/'. In particular, the super-user can escape from a
50377+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50378+
50379+ It is recommended that you say Y here, since it's not known to break
50380+ any software. If the sysctl option is enabled, a sysctl option with
50381+ name "chroot_enforce_chdir" is created.
50382+
50383+config GRKERNSEC_CHROOT_CHMOD
50384+ bool "Deny (f)chmod +s"
50385+ default y if GRKERNSEC_CONFIG_AUTO
50386+ depends on GRKERNSEC_CHROOT
50387+ help
50388+ If you say Y here, processes inside a chroot will not be able to chmod
50389+ or fchmod files to make them have suid or sgid bits. This protects
50390+ against another published method of breaking a chroot. If the sysctl
50391+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
50392+ created.
50393+
50394+config GRKERNSEC_CHROOT_FCHDIR
50395+ bool "Deny fchdir out of chroot"
50396+ default y if GRKERNSEC_CONFIG_AUTO
50397+ depends on GRKERNSEC_CHROOT
50398+ help
50399+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
50400+ to a file descriptor of the chrooting process that points to a directory
50401+ outside the filesystem will be stopped. If the sysctl option
50402+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50403+
50404+config GRKERNSEC_CHROOT_MKNOD
50405+ bool "Deny mknod"
50406+ default y if GRKERNSEC_CONFIG_AUTO
50407+ depends on GRKERNSEC_CHROOT
50408+ help
50409+ If you say Y here, processes inside a chroot will not be allowed to
50410+ mknod. The problem with using mknod inside a chroot is that it
50411+ would allow an attacker to create a device entry that is the same
50412+ as one on the physical root of your system, which could range from
50413+ anything from the console device to a device for your harddrive (which
50414+ they could then use to wipe the drive or steal data). It is recommended
50415+ that you say Y here, unless you run into software incompatibilities.
50416+ If the sysctl option is enabled, a sysctl option with name
50417+ "chroot_deny_mknod" is created.
50418+
50419+config GRKERNSEC_CHROOT_SHMAT
50420+ bool "Deny shmat() out of chroot"
50421+ default y if GRKERNSEC_CONFIG_AUTO
50422+ depends on GRKERNSEC_CHROOT
50423+ help
50424+ If you say Y here, processes inside a chroot will not be able to attach
50425+ to shared memory segments that were created outside of the chroot jail.
50426+ It is recommended that you say Y here. If the sysctl option is enabled,
50427+ a sysctl option with name "chroot_deny_shmat" is created.
50428+
50429+config GRKERNSEC_CHROOT_UNIX
50430+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
50431+ default y if GRKERNSEC_CONFIG_AUTO
50432+ depends on GRKERNSEC_CHROOT
50433+ help
50434+ If you say Y here, processes inside a chroot will not be able to
50435+ connect to abstract (meaning not belonging to a filesystem) Unix
50436+ domain sockets that were bound outside of a chroot. It is recommended
50437+ that you say Y here. If the sysctl option is enabled, a sysctl option
50438+ with name "chroot_deny_unix" is created.
50439+
50440+config GRKERNSEC_CHROOT_FINDTASK
50441+ bool "Protect outside processes"
50442+ default y if GRKERNSEC_CONFIG_AUTO
50443+ depends on GRKERNSEC_CHROOT
50444+ help
50445+ If you say Y here, processes inside a chroot will not be able to
50446+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50447+ getsid, or view any process outside of the chroot. If the sysctl
50448+ option is enabled, a sysctl option with name "chroot_findtask" is
50449+ created.
50450+
50451+config GRKERNSEC_CHROOT_NICE
50452+ bool "Restrict priority changes"
50453+ default y if GRKERNSEC_CONFIG_AUTO
50454+ depends on GRKERNSEC_CHROOT
50455+ help
50456+ If you say Y here, processes inside a chroot will not be able to raise
50457+ the priority of processes in the chroot, or alter the priority of
50458+ processes outside the chroot. This provides more security than simply
50459+ removing CAP_SYS_NICE from the process' capability set. If the
50460+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50461+ is created.
50462+
50463+config GRKERNSEC_CHROOT_SYSCTL
50464+ bool "Deny sysctl writes"
50465+ default y if GRKERNSEC_CONFIG_AUTO
50466+ depends on GRKERNSEC_CHROOT
50467+ help
50468+ If you say Y here, an attacker in a chroot will not be able to
50469+ write to sysctl entries, either by sysctl(2) or through a /proc
50470+ interface. It is strongly recommended that you say Y here. If the
50471+ sysctl option is enabled, a sysctl option with name
50472+ "chroot_deny_sysctl" is created.
50473+
50474+config GRKERNSEC_CHROOT_CAPS
50475+ bool "Capability restrictions"
50476+ default y if GRKERNSEC_CONFIG_AUTO
50477+ depends on GRKERNSEC_CHROOT
50478+ help
50479+ If you say Y here, the capabilities on all processes within a
50480+ chroot jail will be lowered to stop module insertion, raw i/o,
50481+ system and net admin tasks, rebooting the system, modifying immutable
50482+ files, modifying IPC owned by another, and changing the system time.
50483+ This is left an option because it can break some apps. Disable this
50484+ if your chrooted apps are having problems performing those kinds of
50485+ tasks. If the sysctl option is enabled, a sysctl option with
50486+ name "chroot_caps" is created.
50487+
50488+endmenu
50489+menu "Kernel Auditing"
50490+depends on GRKERNSEC
50491+
50492+config GRKERNSEC_AUDIT_GROUP
50493+ bool "Single group for auditing"
50494+ help
50495+ If you say Y here, the exec, chdir, and (un)mount logging features
50496+ will only operate on a group you specify. This option is recommended
50497+ if you only want to watch certain users instead of having a large
50498+ amount of logs from the entire system. If the sysctl option is enabled,
50499+ a sysctl option with name "audit_group" is created.
50500+
50501+config GRKERNSEC_AUDIT_GID
50502+ int "GID for auditing"
50503+ depends on GRKERNSEC_AUDIT_GROUP
50504+ default 1007
50505+
50506+config GRKERNSEC_EXECLOG
50507+ bool "Exec logging"
50508+ help
50509+ If you say Y here, all execve() calls will be logged (since the
50510+ other exec*() calls are frontends to execve(), all execution
50511+ will be logged). Useful for shell-servers that like to keep track
50512+ of their users. If the sysctl option is enabled, a sysctl option with
50513+ name "exec_logging" is created.
50514+ WARNING: This option when enabled will produce a LOT of logs, especially
50515+ on an active system.
50516+
50517+config GRKERNSEC_RESLOG
50518+ bool "Resource logging"
50519+ default y if GRKERNSEC_CONFIG_AUTO
50520+ help
50521+ If you say Y here, all attempts to overstep resource limits will
50522+ be logged with the resource name, the requested size, and the current
50523+ limit. It is highly recommended that you say Y here. If the sysctl
50524+ option is enabled, a sysctl option with name "resource_logging" is
50525+ created. If the RBAC system is enabled, the sysctl value is ignored.
50526+
50527+config GRKERNSEC_CHROOT_EXECLOG
50528+ bool "Log execs within chroot"
50529+ help
50530+ If you say Y here, all executions inside a chroot jail will be logged
50531+ to syslog. This can cause a large amount of logs if certain
50532+ applications (eg. djb's daemontools) are installed on the system, and
50533+ is therefore left as an option. If the sysctl option is enabled, a
50534+ sysctl option with name "chroot_execlog" is created.
50535+
50536+config GRKERNSEC_AUDIT_PTRACE
50537+ bool "Ptrace logging"
50538+ help
50539+ If you say Y here, all attempts to attach to a process via ptrace
50540+ will be logged. If the sysctl option is enabled, a sysctl option
50541+ with name "audit_ptrace" is created.
50542+
50543+config GRKERNSEC_AUDIT_CHDIR
50544+ bool "Chdir logging"
50545+ help
50546+ If you say Y here, all chdir() calls will be logged. If the sysctl
50547+ option is enabled, a sysctl option with name "audit_chdir" is created.
50548+
50549+config GRKERNSEC_AUDIT_MOUNT
50550+ bool "(Un)Mount logging"
50551+ help
50552+ If you say Y here, all mounts and unmounts will be logged. If the
50553+ sysctl option is enabled, a sysctl option with name "audit_mount" is
50554+ created.
50555+
50556+config GRKERNSEC_SIGNAL
50557+ bool "Signal logging"
50558+ default y if GRKERNSEC_CONFIG_AUTO
50559+ help
50560+ If you say Y here, certain important signals will be logged, such as
50561+ SIGSEGV, which will as a result inform you of when a error in a program
50562+ occurred, which in some cases could mean a possible exploit attempt.
50563+ If the sysctl option is enabled, a sysctl option with name
50564+ "signal_logging" is created.
50565+
50566+config GRKERNSEC_FORKFAIL
50567+ bool "Fork failure logging"
50568+ help
50569+ If you say Y here, all failed fork() attempts will be logged.
50570+ This could suggest a fork bomb, or someone attempting to overstep
50571+ their process limit. If the sysctl option is enabled, a sysctl option
50572+ with name "forkfail_logging" is created.
50573+
50574+config GRKERNSEC_TIME
50575+ bool "Time change logging"
50576+ default y if GRKERNSEC_CONFIG_AUTO
50577+ help
50578+ If you say Y here, any changes of the system clock will be logged.
50579+ If the sysctl option is enabled, a sysctl option with name
50580+ "timechange_logging" is created.
50581+
50582+config GRKERNSEC_PROC_IPADDR
50583+ bool "/proc/<pid>/ipaddr support"
50584+ default y if GRKERNSEC_CONFIG_AUTO
50585+ help
50586+ If you say Y here, a new entry will be added to each /proc/<pid>
50587+ directory that contains the IP address of the person using the task.
50588+ The IP is carried across local TCP and AF_UNIX stream sockets.
50589+ This information can be useful for IDS/IPSes to perform remote response
50590+ to a local attack. The entry is readable by only the owner of the
50591+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50592+ the RBAC system), and thus does not create privacy concerns.
50593+
50594+config GRKERNSEC_RWXMAP_LOG
50595+ bool 'Denied RWX mmap/mprotect logging'
50596+ default y if GRKERNSEC_CONFIG_AUTO
50597+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50598+ help
50599+ If you say Y here, calls to mmap() and mprotect() with explicit
50600+ usage of PROT_WRITE and PROT_EXEC together will be logged when
50601+ denied by the PAX_MPROTECT feature. If the sysctl option is
50602+ enabled, a sysctl option with name "rwxmap_logging" is created.
50603+
50604+config GRKERNSEC_AUDIT_TEXTREL
50605+ bool 'ELF text relocations logging (READ HELP)'
50606+ depends on PAX_MPROTECT
50607+ help
50608+ If you say Y here, text relocations will be logged with the filename
50609+ of the offending library or binary. The purpose of the feature is
50610+ to help Linux distribution developers get rid of libraries and
50611+ binaries that need text relocations which hinder the future progress
50612+ of PaX. Only Linux distribution developers should say Y here, and
50613+ never on a production machine, as this option creates an information
50614+ leak that could aid an attacker in defeating the randomization of
50615+ a single memory region. If the sysctl option is enabled, a sysctl
50616+ option with name "audit_textrel" is created.
50617+
50618+endmenu
50619+
50620+menu "Executable Protections"
50621+depends on GRKERNSEC
50622+
50623+config GRKERNSEC_DMESG
50624+ bool "Dmesg(8) restriction"
50625+ default y if GRKERNSEC_CONFIG_AUTO
50626+ help
50627+ If you say Y here, non-root users will not be able to use dmesg(8)
50628+ to view up to the last 4kb of messages in the kernel's log buffer.
50629+ The kernel's log buffer often contains kernel addresses and other
50630+ identifying information useful to an attacker in fingerprinting a
50631+ system for a targeted exploit.
50632+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
50633+ created.
50634+
50635+config GRKERNSEC_HARDEN_PTRACE
50636+ bool "Deter ptrace-based process snooping"
50637+ default y if GRKERNSEC_CONFIG_AUTO
50638+ help
50639+ If you say Y here, TTY sniffers and other malicious monitoring
50640+ programs implemented through ptrace will be defeated. If you
50641+ have been using the RBAC system, this option has already been
50642+ enabled for several years for all users, with the ability to make
50643+ fine-grained exceptions.
50644+
50645+ This option only affects the ability of non-root users to ptrace
50646+ processes that are not a descendent of the ptracing process.
50647+ This means that strace ./binary and gdb ./binary will still work,
50648+ but attaching to arbitrary processes will not. If the sysctl
50649+ option is enabled, a sysctl option with name "harden_ptrace" is
50650+ created.
50651+
50652+config GRKERNSEC_PTRACE_READEXEC
50653+ bool "Require read access to ptrace sensitive binaries"
50654+ default y if GRKERNSEC_CONFIG_AUTO
50655+ help
50656+ If you say Y here, unprivileged users will not be able to ptrace unreadable
50657+ binaries. This option is useful in environments that
50658+ remove the read bits (e.g. file mode 4711) from suid binaries to
50659+ prevent infoleaking of their contents. This option adds
50660+ consistency to the use of that file mode, as the binary could normally
50661+ be read out when run without privileges while ptracing.
50662+
50663+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50664+ is created.
50665+
50666+config GRKERNSEC_SETXID
50667+ bool "Enforce consistent multithreaded privileges"
50668+ default y if GRKERNSEC_CONFIG_AUTO
50669+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
50670+ help
50671+ If you say Y here, a change from a root uid to a non-root uid
50672+ in a multithreaded application will cause the resulting uids,
50673+ gids, supplementary groups, and capabilities in that thread
50674+ to be propagated to the other threads of the process. In most
50675+ cases this is unnecessary, as glibc will emulate this behavior
50676+ on behalf of the application. Other libcs do not act in the
50677+ same way, allowing the other threads of the process to continue
50678+ running with root privileges. If the sysctl option is enabled,
50679+ a sysctl option with name "consistent_setxid" is created.
50680+
50681+config GRKERNSEC_TPE
50682+ bool "Trusted Path Execution (TPE)"
50683+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50684+ help
50685+ If you say Y here, you will be able to choose a gid to add to the
50686+ supplementary groups of users you want to mark as "untrusted."
50687+ These users will not be able to execute any files that are not in
50688+ root-owned directories writable only by root. If the sysctl option
50689+ is enabled, a sysctl option with name "tpe" is created.
50690+
50691+config GRKERNSEC_TPE_ALL
50692+ bool "Partially restrict all non-root users"
50693+ depends on GRKERNSEC_TPE
50694+ help
50695+ If you say Y here, all non-root users will be covered under
50696+ a weaker TPE restriction. This is separate from, and in addition to,
50697+ the main TPE options that you have selected elsewhere. Thus, if a
50698+ "trusted" GID is chosen, this restriction applies to even that GID.
50699+ Under this restriction, all non-root users will only be allowed to
50700+ execute files in directories they own that are not group or
50701+ world-writable, or in directories owned by root and writable only by
50702+ root. If the sysctl option is enabled, a sysctl option with name
50703+ "tpe_restrict_all" is created.
50704+
50705+config GRKERNSEC_TPE_INVERT
50706+ bool "Invert GID option"
50707+ depends on GRKERNSEC_TPE
50708+ help
50709+ If you say Y here, the group you specify in the TPE configuration will
50710+ decide what group TPE restrictions will be *disabled* for. This
50711+ option is useful if you want TPE restrictions to be applied to most
50712+ users on the system. If the sysctl option is enabled, a sysctl option
50713+ with name "tpe_invert" is created. Unlike other sysctl options, this
50714+ entry will default to on for backward-compatibility.
50715+
50716+config GRKERNSEC_TPE_GID
50717+ int "GID for untrusted users"
50718+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50719+ default 1005
50720+ help
50721+ Setting this GID determines what group TPE restrictions will be
50722+ *enabled* for. If the sysctl option is enabled, a sysctl option
50723+ with name "tpe_gid" is created.
50724+
50725+config GRKERNSEC_TPE_GID
50726+ int "GID for trusted users"
50727+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50728+ default 1005
50729+ help
50730+ Setting this GID determines what group TPE restrictions will be
50731+ *disabled* for. If the sysctl option is enabled, a sysctl option
50732+ with name "tpe_gid" is created.
50733+
50734+endmenu
50735+menu "Network Protections"
50736+depends on GRKERNSEC
50737+
50738+config GRKERNSEC_RANDNET
50739+ bool "Larger entropy pools"
50740+ default y if GRKERNSEC_CONFIG_AUTO
50741+ help
50742+ If you say Y here, the entropy pools used for many features of Linux
50743+ and grsecurity will be doubled in size. Since several grsecurity
50744+ features use additional randomness, it is recommended that you say Y
50745+ here. Saying Y here has a similar effect as modifying
50746+ /proc/sys/kernel/random/poolsize.
50747+
50748+config GRKERNSEC_BLACKHOLE
50749+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50750+ default y if GRKERNSEC_CONFIG_AUTO
50751+ depends on NET
50752+ help
50753+ If you say Y here, neither TCP resets nor ICMP
50754+ destination-unreachable packets will be sent in response to packets
50755+ sent to ports for which no associated listening process exists.
50756+ This feature supports both IPV4 and IPV6 and exempts the
50757+ loopback interface from blackholing. Enabling this feature
50758+ makes a host more resilient to DoS attacks and reduces network
50759+ visibility against scanners.
50760+
50761+ The blackhole feature as-implemented is equivalent to the FreeBSD
50762+ blackhole feature, as it prevents RST responses to all packets, not
50763+ just SYNs. Under most application behavior this causes no
50764+ problems, but applications (like haproxy) may not close certain
50765+ connections in a way that cleanly terminates them on the remote
50766+ end, leaving the remote host in LAST_ACK state. Because of this
50767+ side-effect and to prevent intentional LAST_ACK DoSes, this
50768+ feature also adds automatic mitigation against such attacks.
50769+ The mitigation drastically reduces the amount of time a socket
50770+ can spend in LAST_ACK state. If you're using haproxy and not
50771+ all servers it connects to have this option enabled, consider
50772+ disabling this feature on the haproxy host.
50773+
50774+ If the sysctl option is enabled, two sysctl options with names
50775+ "ip_blackhole" and "lastack_retries" will be created.
50776+ While "ip_blackhole" takes the standard zero/non-zero on/off
50777+ toggle, "lastack_retries" uses the same kinds of values as
50778+ "tcp_retries1" and "tcp_retries2". The default value of 4
50779+ prevents a socket from lasting more than 45 seconds in LAST_ACK
50780+ state.
50781+
50782+config GRKERNSEC_SOCKET
50783+ bool "Socket restrictions"
50784+ depends on NET
50785+ help
50786+ If you say Y here, you will be able to choose from several options.
50787+ If you assign a GID on your system and add it to the supplementary
50788+ groups of users you want to restrict socket access to, this patch
50789+ will perform up to three things, based on the option(s) you choose.
50790+
50791+config GRKERNSEC_SOCKET_ALL
50792+ bool "Deny any sockets to group"
50793+ depends on GRKERNSEC_SOCKET
50794+ help
50795+ If you say Y here, you will be able to choose a GID of whose users will
50796+ be unable to connect to other hosts from your machine or run server
50797+ applications from your machine. If the sysctl option is enabled, a
50798+ sysctl option with name "socket_all" is created.
50799+
50800+config GRKERNSEC_SOCKET_ALL_GID
50801+ int "GID to deny all sockets for"
50802+ depends on GRKERNSEC_SOCKET_ALL
50803+ default 1004
50804+ help
50805+ Here you can choose the GID to disable socket access for. Remember to
50806+ add the users you want socket access disabled for to the GID
50807+ specified here. If the sysctl option is enabled, a sysctl option
50808+ with name "socket_all_gid" is created.
50809+
50810+config GRKERNSEC_SOCKET_CLIENT
50811+ bool "Deny client sockets to group"
50812+ depends on GRKERNSEC_SOCKET
50813+ help
50814+ If you say Y here, you will be able to choose a GID of whose users will
50815+ be unable to connect to other hosts from your machine, but will be
50816+ able to run servers. If this option is enabled, all users in the group
50817+ you specify will have to use passive mode when initiating ftp transfers
50818+ from the shell on your machine. If the sysctl option is enabled, a
50819+ sysctl option with name "socket_client" is created.
50820+
50821+config GRKERNSEC_SOCKET_CLIENT_GID
50822+ int "GID to deny client sockets for"
50823+ depends on GRKERNSEC_SOCKET_CLIENT
50824+ default 1003
50825+ help
50826+ Here you can choose the GID to disable client socket access for.
50827+ Remember to add the users you want client socket access disabled for to
50828+ the GID specified here. If the sysctl option is enabled, a sysctl
50829+ option with name "socket_client_gid" is created.
50830+
50831+config GRKERNSEC_SOCKET_SERVER
50832+ bool "Deny server sockets to group"
50833+ depends on GRKERNSEC_SOCKET
50834+ help
50835+ If you say Y here, you will be able to choose a GID of whose users will
50836+ be unable to run server applications from your machine. If the sysctl
50837+ option is enabled, a sysctl option with name "socket_server" is created.
50838+
50839+config GRKERNSEC_SOCKET_SERVER_GID
50840+ int "GID to deny server sockets for"
50841+ depends on GRKERNSEC_SOCKET_SERVER
50842+ default 1002
50843+ help
50844+ Here you can choose the GID to disable server socket access for.
50845+ Remember to add the users you want server socket access disabled for to
50846+ the GID specified here. If the sysctl option is enabled, a sysctl
50847+ option with name "socket_server_gid" is created.
50848+
50849+endmenu
50850+menu "Sysctl Support"
50851+depends on GRKERNSEC && SYSCTL
50852+
50853+config GRKERNSEC_SYSCTL
50854+ bool "Sysctl support"
50855+ default y if GRKERNSEC_CONFIG_AUTO
50856+ help
50857+ If you say Y here, you will be able to change the options that
50858+ grsecurity runs with at bootup, without having to recompile your
50859+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50860+ to enable (1) or disable (0) various features. All the sysctl entries
50861+ are mutable until the "grsec_lock" entry is set to a non-zero value.
50862+ All features enabled in the kernel configuration are disabled at boot
50863+ if you do not say Y to the "Turn on features by default" option.
50864+ All options should be set at startup, and the grsec_lock entry should
50865+ be set to a non-zero value after all the options are set.
50866+ *THIS IS EXTREMELY IMPORTANT*
50867+
50868+config GRKERNSEC_SYSCTL_DISTRO
50869+ bool "Extra sysctl support for distro makers (READ HELP)"
50870+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50871+ help
50872+ If you say Y here, additional sysctl options will be created
50873+ for features that affect processes running as root. Therefore,
50874+ it is critical when using this option that the grsec_lock entry be
50875+ enabled after boot. Only distros with prebuilt kernel packages
50876+ with this option enabled that can ensure grsec_lock is enabled
50877+ after boot should use this option.
50878+ *Failure to set grsec_lock after boot makes all grsec features
50879+ this option covers useless*
50880+
50881+ Currently this option creates the following sysctl entries:
50882+ "Disable Privileged I/O": "disable_priv_io"
50883+
50884+config GRKERNSEC_SYSCTL_ON
50885+ bool "Turn on features by default"
50886+ default y if GRKERNSEC_CONFIG_AUTO
50887+ depends on GRKERNSEC_SYSCTL
50888+ help
50889+ If you say Y here, instead of having all features enabled in the
50890+ kernel configuration disabled at boot time, the features will be
50891+ enabled at boot time. It is recommended you say Y here unless
50892+ there is some reason you would want all sysctl-tunable features to
50893+ be disabled by default. As mentioned elsewhere, it is important
50894+ to enable the grsec_lock entry once you have finished modifying
50895+ the sysctl entries.
50896+
50897+endmenu
50898+menu "Logging Options"
50899+depends on GRKERNSEC
50900+
50901+config GRKERNSEC_FLOODTIME
50902+ int "Seconds in between log messages (minimum)"
50903+ default 10
50904+ help
50905+ This option allows you to enforce the number of seconds between
50906+ grsecurity log messages. The default should be suitable for most
50907+ people, however, if you choose to change it, choose a value small enough
50908+ to allow informative logs to be produced, but large enough to
50909+ prevent flooding.
50910+
50911+config GRKERNSEC_FLOODBURST
50912+ int "Number of messages in a burst (maximum)"
50913+ default 6
50914+ help
50915+ This option allows you to choose the maximum number of messages allowed
50916+ within the flood time interval you chose in a separate option. The
50917+ default should be suitable for most people, however if you find that
50918+ many of your logs are being interpreted as flooding, you may want to
50919+ raise this value.
50920+
50921+endmenu
50922diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50923new file mode 100644
50924index 0000000..1b9afa9
50925--- /dev/null
50926+++ b/grsecurity/Makefile
50927@@ -0,0 +1,38 @@
50928+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50929+# during 2001-2009 it has been completely redesigned by Brad Spengler
50930+# into an RBAC system
50931+#
50932+# All code in this directory and various hooks inserted throughout the kernel
50933+# are copyright Brad Spengler - Open Source Security, Inc., and released
50934+# under the GPL v2 or higher
50935+
50936+KBUILD_CFLAGS += -Werror
50937+
50938+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50939+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
50940+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50941+
50942+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50943+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50944+ gracl_learn.o grsec_log.o
50945+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50946+
50947+ifdef CONFIG_NET
50948+obj-y += grsec_sock.o
50949+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50950+endif
50951+
50952+ifndef CONFIG_GRKERNSEC
50953+obj-y += grsec_disabled.o
50954+endif
50955+
50956+ifdef CONFIG_GRKERNSEC_HIDESYM
50957+extra-y := grsec_hidesym.o
50958+$(obj)/grsec_hidesym.o:
50959+ @-chmod -f 500 /boot
50960+ @-chmod -f 500 /lib/modules
50961+ @-chmod -f 500 /lib64/modules
50962+ @-chmod -f 500 /lib32/modules
50963+ @-chmod -f 700 .
50964+ @echo ' grsec: protected kernel image paths'
50965+endif
50966diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50967new file mode 100644
50968index 0000000..4480ed8
50969--- /dev/null
50970+++ b/grsecurity/gracl.c
50971@@ -0,0 +1,4017 @@
50972+#include <linux/kernel.h>
50973+#include <linux/module.h>
50974+#include <linux/sched.h>
50975+#include <linux/mm.h>
50976+#include <linux/file.h>
50977+#include <linux/fs.h>
50978+#include <linux/namei.h>
50979+#include <linux/mount.h>
50980+#include <linux/tty.h>
50981+#include <linux/proc_fs.h>
50982+#include <linux/lglock.h>
50983+#include <linux/slab.h>
50984+#include <linux/vmalloc.h>
50985+#include <linux/types.h>
50986+#include <linux/sysctl.h>
50987+#include <linux/netdevice.h>
50988+#include <linux/ptrace.h>
50989+#include <linux/gracl.h>
50990+#include <linux/gralloc.h>
50991+#include <linux/security.h>
50992+#include <linux/grinternal.h>
50993+#include <linux/pid_namespace.h>
50994+#include <linux/stop_machine.h>
50995+#include <linux/fdtable.h>
50996+#include <linux/percpu.h>
50997+#include <linux/lglock.h>
50998+#include "../fs/mount.h"
50999+
51000+#include <asm/uaccess.h>
51001+#include <asm/errno.h>
51002+#include <asm/mman.h>
51003+
51004+extern struct lglock vfsmount_lock;
51005+
51006+static struct acl_role_db acl_role_set;
51007+static struct name_db name_set;
51008+static struct inodev_db inodev_set;
51009+
51010+/* for keeping track of userspace pointers used for subjects, so we
51011+ can share references in the kernel as well
51012+*/
51013+
51014+static struct path real_root;
51015+
51016+static struct acl_subj_map_db subj_map_set;
51017+
51018+static struct acl_role_label *default_role;
51019+
51020+static struct acl_role_label *role_list;
51021+
51022+static u16 acl_sp_role_value;
51023+
51024+extern char *gr_shared_page[4];
51025+static DEFINE_MUTEX(gr_dev_mutex);
51026+DEFINE_RWLOCK(gr_inode_lock);
51027+
51028+struct gr_arg *gr_usermode;
51029+
51030+static unsigned int gr_status __read_only = GR_STATUS_INIT;
51031+
51032+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51033+extern void gr_clear_learn_entries(void);
51034+
51035+#ifdef CONFIG_GRKERNSEC_RESLOG
51036+extern void gr_log_resource(const struct task_struct *task,
51037+ const int res, const unsigned long wanted, const int gt);
51038+#endif
51039+
51040+unsigned char *gr_system_salt;
51041+unsigned char *gr_system_sum;
51042+
51043+static struct sprole_pw **acl_special_roles = NULL;
51044+static __u16 num_sprole_pws = 0;
51045+
51046+static struct acl_role_label *kernel_role = NULL;
51047+
51048+static unsigned int gr_auth_attempts = 0;
51049+static unsigned long gr_auth_expires = 0UL;
51050+
51051+#ifdef CONFIG_NET
51052+extern struct vfsmount *sock_mnt;
51053+#endif
51054+
51055+extern struct vfsmount *pipe_mnt;
51056+extern struct vfsmount *shm_mnt;
51057+#ifdef CONFIG_HUGETLBFS
51058+extern struct vfsmount *hugetlbfs_vfsmount;
51059+#endif
51060+
51061+static struct acl_object_label *fakefs_obj_rw;
51062+static struct acl_object_label *fakefs_obj_rwx;
51063+
51064+extern int gr_init_uidset(void);
51065+extern void gr_free_uidset(void);
51066+extern void gr_remove_uid(uid_t uid);
51067+extern int gr_find_uid(uid_t uid);
51068+
51069+__inline__ int
51070+gr_acl_is_enabled(void)
51071+{
51072+ return (gr_status & GR_READY);
51073+}
51074+
51075+#ifdef CONFIG_BTRFS_FS
51076+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51077+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51078+#endif
51079+
51080+static inline dev_t __get_dev(const struct dentry *dentry)
51081+{
51082+#ifdef CONFIG_BTRFS_FS
51083+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51084+ return get_btrfs_dev_from_inode(dentry->d_inode);
51085+ else
51086+#endif
51087+ return dentry->d_inode->i_sb->s_dev;
51088+}
51089+
51090+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51091+{
51092+ return __get_dev(dentry);
51093+}
51094+
51095+static char gr_task_roletype_to_char(struct task_struct *task)
51096+{
51097+ switch (task->role->roletype &
51098+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51099+ GR_ROLE_SPECIAL)) {
51100+ case GR_ROLE_DEFAULT:
51101+ return 'D';
51102+ case GR_ROLE_USER:
51103+ return 'U';
51104+ case GR_ROLE_GROUP:
51105+ return 'G';
51106+ case GR_ROLE_SPECIAL:
51107+ return 'S';
51108+ }
51109+
51110+ return 'X';
51111+}
51112+
51113+char gr_roletype_to_char(void)
51114+{
51115+ return gr_task_roletype_to_char(current);
51116+}
51117+
51118+__inline__ int
51119+gr_acl_tpe_check(void)
51120+{
51121+ if (unlikely(!(gr_status & GR_READY)))
51122+ return 0;
51123+ if (current->role->roletype & GR_ROLE_TPE)
51124+ return 1;
51125+ else
51126+ return 0;
51127+}
51128+
51129+int
51130+gr_handle_rawio(const struct inode *inode)
51131+{
51132+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51133+ if (inode && S_ISBLK(inode->i_mode) &&
51134+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51135+ !capable(CAP_SYS_RAWIO))
51136+ return 1;
51137+#endif
51138+ return 0;
51139+}
51140+
51141+static int
51142+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51143+{
51144+ if (likely(lena != lenb))
51145+ return 0;
51146+
51147+ return !memcmp(a, b, lena);
51148+}
51149+
51150+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51151+{
51152+ *buflen -= namelen;
51153+ if (*buflen < 0)
51154+ return -ENAMETOOLONG;
51155+ *buffer -= namelen;
51156+ memcpy(*buffer, str, namelen);
51157+ return 0;
51158+}
51159+
51160+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51161+{
51162+ return prepend(buffer, buflen, name->name, name->len);
51163+}
51164+
51165+static int prepend_path(const struct path *path, struct path *root,
51166+ char **buffer, int *buflen)
51167+{
51168+ struct dentry *dentry = path->dentry;
51169+ struct vfsmount *vfsmnt = path->mnt;
51170+ struct mount *mnt = real_mount(vfsmnt);
51171+ bool slash = false;
51172+ int error = 0;
51173+
51174+ while (dentry != root->dentry || vfsmnt != root->mnt) {
51175+ struct dentry * parent;
51176+
51177+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51178+ /* Global root? */
51179+ if (!mnt_has_parent(mnt)) {
51180+ goto out;
51181+ }
51182+ dentry = mnt->mnt_mountpoint;
51183+ mnt = mnt->mnt_parent;
51184+ vfsmnt = &mnt->mnt;
51185+ continue;
51186+ }
51187+ parent = dentry->d_parent;
51188+ prefetch(parent);
51189+ spin_lock(&dentry->d_lock);
51190+ error = prepend_name(buffer, buflen, &dentry->d_name);
51191+ spin_unlock(&dentry->d_lock);
51192+ if (!error)
51193+ error = prepend(buffer, buflen, "/", 1);
51194+ if (error)
51195+ break;
51196+
51197+ slash = true;
51198+ dentry = parent;
51199+ }
51200+
51201+out:
51202+ if (!error && !slash)
51203+ error = prepend(buffer, buflen, "/", 1);
51204+
51205+ return error;
51206+}
51207+
51208+/* this must be called with vfsmount_lock and rename_lock held */
51209+
51210+static char *__our_d_path(const struct path *path, struct path *root,
51211+ char *buf, int buflen)
51212+{
51213+ char *res = buf + buflen;
51214+ int error;
51215+
51216+ prepend(&res, &buflen, "\0", 1);
51217+ error = prepend_path(path, root, &res, &buflen);
51218+ if (error)
51219+ return ERR_PTR(error);
51220+
51221+ return res;
51222+}
51223+
51224+static char *
51225+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51226+{
51227+ char *retval;
51228+
51229+ retval = __our_d_path(path, root, buf, buflen);
51230+ if (unlikely(IS_ERR(retval)))
51231+ retval = strcpy(buf, "<path too long>");
51232+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51233+ retval[1] = '\0';
51234+
51235+ return retval;
51236+}
51237+
51238+static char *
51239+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51240+ char *buf, int buflen)
51241+{
51242+ struct path path;
51243+ char *res;
51244+
51245+ path.dentry = (struct dentry *)dentry;
51246+ path.mnt = (struct vfsmount *)vfsmnt;
51247+
51248+ /* we can use real_root.dentry, real_root.mnt, because this is only called
51249+ by the RBAC system */
51250+ res = gen_full_path(&path, &real_root, buf, buflen);
51251+
51252+ return res;
51253+}
51254+
51255+static char *
51256+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51257+ char *buf, int buflen)
51258+{
51259+ char *res;
51260+ struct path path;
51261+ struct path root;
51262+ struct task_struct *reaper = init_pid_ns.child_reaper;
51263+
51264+ path.dentry = (struct dentry *)dentry;
51265+ path.mnt = (struct vfsmount *)vfsmnt;
51266+
51267+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51268+ get_fs_root(reaper->fs, &root);
51269+
51270+ write_seqlock(&rename_lock);
51271+ br_read_lock(&vfsmount_lock);
51272+ res = gen_full_path(&path, &root, buf, buflen);
51273+ br_read_unlock(&vfsmount_lock);
51274+ write_sequnlock(&rename_lock);
51275+
51276+ path_put(&root);
51277+ return res;
51278+}
51279+
51280+static char *
51281+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51282+{
51283+ char *ret;
51284+ write_seqlock(&rename_lock);
51285+ br_read_lock(&vfsmount_lock);
51286+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51287+ PAGE_SIZE);
51288+ br_read_unlock(&vfsmount_lock);
51289+ write_sequnlock(&rename_lock);
51290+ return ret;
51291+}
51292+
51293+static char *
51294+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51295+{
51296+ char *ret;
51297+ char *buf;
51298+ int buflen;
51299+
51300+ write_seqlock(&rename_lock);
51301+ br_read_lock(&vfsmount_lock);
51302+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51303+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51304+ buflen = (int)(ret - buf);
51305+ if (buflen >= 5)
51306+ prepend(&ret, &buflen, "/proc", 5);
51307+ else
51308+ ret = strcpy(buf, "<path too long>");
51309+ br_read_unlock(&vfsmount_lock);
51310+ write_sequnlock(&rename_lock);
51311+ return ret;
51312+}
51313+
51314+char *
51315+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51316+{
51317+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51318+ PAGE_SIZE);
51319+}
51320+
51321+char *
51322+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51323+{
51324+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51325+ PAGE_SIZE);
51326+}
51327+
51328+char *
51329+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51330+{
51331+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51332+ PAGE_SIZE);
51333+}
51334+
51335+char *
51336+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51337+{
51338+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51339+ PAGE_SIZE);
51340+}
51341+
51342+char *
51343+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51344+{
51345+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51346+ PAGE_SIZE);
51347+}
51348+
51349+__inline__ __u32
51350+to_gr_audit(const __u32 reqmode)
51351+{
51352+ /* masks off auditable permission flags, then shifts them to create
51353+ auditing flags, and adds the special case of append auditing if
51354+ we're requesting write */
51355+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51356+}
51357+
51358+struct acl_subject_label *
51359+lookup_subject_map(const struct acl_subject_label *userp)
51360+{
51361+ unsigned int index = shash(userp, subj_map_set.s_size);
51362+ struct subject_map *match;
51363+
51364+ match = subj_map_set.s_hash[index];
51365+
51366+ while (match && match->user != userp)
51367+ match = match->next;
51368+
51369+ if (match != NULL)
51370+ return match->kernel;
51371+ else
51372+ return NULL;
51373+}
51374+
51375+static void
51376+insert_subj_map_entry(struct subject_map *subjmap)
51377+{
51378+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51379+ struct subject_map **curr;
51380+
51381+ subjmap->prev = NULL;
51382+
51383+ curr = &subj_map_set.s_hash[index];
51384+ if (*curr != NULL)
51385+ (*curr)->prev = subjmap;
51386+
51387+ subjmap->next = *curr;
51388+ *curr = subjmap;
51389+
51390+ return;
51391+}
51392+
51393+static struct acl_role_label *
51394+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51395+ const gid_t gid)
51396+{
51397+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51398+ struct acl_role_label *match;
51399+ struct role_allowed_ip *ipp;
51400+ unsigned int x;
51401+ u32 curr_ip = task->signal->curr_ip;
51402+
51403+ task->signal->saved_ip = curr_ip;
51404+
51405+ match = acl_role_set.r_hash[index];
51406+
51407+ while (match) {
51408+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51409+ for (x = 0; x < match->domain_child_num; x++) {
51410+ if (match->domain_children[x] == uid)
51411+ goto found;
51412+ }
51413+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51414+ break;
51415+ match = match->next;
51416+ }
51417+found:
51418+ if (match == NULL) {
51419+ try_group:
51420+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51421+ match = acl_role_set.r_hash[index];
51422+
51423+ while (match) {
51424+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51425+ for (x = 0; x < match->domain_child_num; x++) {
51426+ if (match->domain_children[x] == gid)
51427+ goto found2;
51428+ }
51429+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51430+ break;
51431+ match = match->next;
51432+ }
51433+found2:
51434+ if (match == NULL)
51435+ match = default_role;
51436+ if (match->allowed_ips == NULL)
51437+ return match;
51438+ else {
51439+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51440+ if (likely
51441+ ((ntohl(curr_ip) & ipp->netmask) ==
51442+ (ntohl(ipp->addr) & ipp->netmask)))
51443+ return match;
51444+ }
51445+ match = default_role;
51446+ }
51447+ } else if (match->allowed_ips == NULL) {
51448+ return match;
51449+ } else {
51450+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51451+ if (likely
51452+ ((ntohl(curr_ip) & ipp->netmask) ==
51453+ (ntohl(ipp->addr) & ipp->netmask)))
51454+ return match;
51455+ }
51456+ goto try_group;
51457+ }
51458+
51459+ return match;
51460+}
51461+
51462+struct acl_subject_label *
51463+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51464+ const struct acl_role_label *role)
51465+{
51466+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51467+ struct acl_subject_label *match;
51468+
51469+ match = role->subj_hash[index];
51470+
51471+ while (match && (match->inode != ino || match->device != dev ||
51472+ (match->mode & GR_DELETED))) {
51473+ match = match->next;
51474+ }
51475+
51476+ if (match && !(match->mode & GR_DELETED))
51477+ return match;
51478+ else
51479+ return NULL;
51480+}
51481+
51482+struct acl_subject_label *
51483+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51484+ const struct acl_role_label *role)
51485+{
51486+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51487+ struct acl_subject_label *match;
51488+
51489+ match = role->subj_hash[index];
51490+
51491+ while (match && (match->inode != ino || match->device != dev ||
51492+ !(match->mode & GR_DELETED))) {
51493+ match = match->next;
51494+ }
51495+
51496+ if (match && (match->mode & GR_DELETED))
51497+ return match;
51498+ else
51499+ return NULL;
51500+}
51501+
51502+static struct acl_object_label *
51503+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51504+ const struct acl_subject_label *subj)
51505+{
51506+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51507+ struct acl_object_label *match;
51508+
51509+ match = subj->obj_hash[index];
51510+
51511+ while (match && (match->inode != ino || match->device != dev ||
51512+ (match->mode & GR_DELETED))) {
51513+ match = match->next;
51514+ }
51515+
51516+ if (match && !(match->mode & GR_DELETED))
51517+ return match;
51518+ else
51519+ return NULL;
51520+}
51521+
51522+static struct acl_object_label *
51523+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51524+ const struct acl_subject_label *subj)
51525+{
51526+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51527+ struct acl_object_label *match;
51528+
51529+ match = subj->obj_hash[index];
51530+
51531+ while (match && (match->inode != ino || match->device != dev ||
51532+ !(match->mode & GR_DELETED))) {
51533+ match = match->next;
51534+ }
51535+
51536+ if (match && (match->mode & GR_DELETED))
51537+ return match;
51538+
51539+ match = subj->obj_hash[index];
51540+
51541+ while (match && (match->inode != ino || match->device != dev ||
51542+ (match->mode & GR_DELETED))) {
51543+ match = match->next;
51544+ }
51545+
51546+ if (match && !(match->mode & GR_DELETED))
51547+ return match;
51548+ else
51549+ return NULL;
51550+}
51551+
51552+static struct name_entry *
51553+lookup_name_entry(const char *name)
51554+{
51555+ unsigned int len = strlen(name);
51556+ unsigned int key = full_name_hash(name, len);
51557+ unsigned int index = key % name_set.n_size;
51558+ struct name_entry *match;
51559+
51560+ match = name_set.n_hash[index];
51561+
51562+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51563+ match = match->next;
51564+
51565+ return match;
51566+}
51567+
51568+static struct name_entry *
51569+lookup_name_entry_create(const char *name)
51570+{
51571+ unsigned int len = strlen(name);
51572+ unsigned int key = full_name_hash(name, len);
51573+ unsigned int index = key % name_set.n_size;
51574+ struct name_entry *match;
51575+
51576+ match = name_set.n_hash[index];
51577+
51578+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51579+ !match->deleted))
51580+ match = match->next;
51581+
51582+ if (match && match->deleted)
51583+ return match;
51584+
51585+ match = name_set.n_hash[index];
51586+
51587+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51588+ match->deleted))
51589+ match = match->next;
51590+
51591+ if (match && !match->deleted)
51592+ return match;
51593+ else
51594+ return NULL;
51595+}
51596+
51597+static struct inodev_entry *
51598+lookup_inodev_entry(const ino_t ino, const dev_t dev)
51599+{
51600+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
51601+ struct inodev_entry *match;
51602+
51603+ match = inodev_set.i_hash[index];
51604+
51605+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51606+ match = match->next;
51607+
51608+ return match;
51609+}
51610+
51611+static void
51612+insert_inodev_entry(struct inodev_entry *entry)
51613+{
51614+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51615+ inodev_set.i_size);
51616+ struct inodev_entry **curr;
51617+
51618+ entry->prev = NULL;
51619+
51620+ curr = &inodev_set.i_hash[index];
51621+ if (*curr != NULL)
51622+ (*curr)->prev = entry;
51623+
51624+ entry->next = *curr;
51625+ *curr = entry;
51626+
51627+ return;
51628+}
51629+
51630+static void
51631+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51632+{
51633+ unsigned int index =
51634+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51635+ struct acl_role_label **curr;
51636+ struct acl_role_label *tmp, *tmp2;
51637+
51638+ curr = &acl_role_set.r_hash[index];
51639+
51640+ /* simple case, slot is empty, just set it to our role */
51641+ if (*curr == NULL) {
51642+ *curr = role;
51643+ } else {
51644+ /* example:
51645+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
51646+ 2 -> 3
51647+ */
51648+ /* first check to see if we can already be reached via this slot */
51649+ tmp = *curr;
51650+ while (tmp && tmp != role)
51651+ tmp = tmp->next;
51652+ if (tmp == role) {
51653+ /* we don't need to add ourselves to this slot's chain */
51654+ return;
51655+ }
51656+ /* we need to add ourselves to this chain, two cases */
51657+ if (role->next == NULL) {
51658+ /* simple case, append the current chain to our role */
51659+ role->next = *curr;
51660+ *curr = role;
51661+ } else {
51662+ /* 1 -> 2 -> 3 -> 4
51663+ 2 -> 3 -> 4
51664+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51665+ */
51666+ /* trickier case: walk our role's chain until we find
51667+ the role for the start of the current slot's chain */
51668+ tmp = role;
51669+ tmp2 = *curr;
51670+ while (tmp->next && tmp->next != tmp2)
51671+ tmp = tmp->next;
51672+ if (tmp->next == tmp2) {
51673+ /* from example above, we found 3, so just
51674+ replace this slot's chain with ours */
51675+ *curr = role;
51676+ } else {
51677+ /* we didn't find a subset of our role's chain
51678+ in the current slot's chain, so append their
51679+ chain to ours, and set us as the first role in
51680+ the slot's chain
51681+
51682+ we could fold this case with the case above,
51683+ but making it explicit for clarity
51684+ */
51685+ tmp->next = tmp2;
51686+ *curr = role;
51687+ }
51688+ }
51689+ }
51690+
51691+ return;
51692+}
51693+
51694+static void
51695+insert_acl_role_label(struct acl_role_label *role)
51696+{
51697+ int i;
51698+
51699+ if (role_list == NULL) {
51700+ role_list = role;
51701+ role->prev = NULL;
51702+ } else {
51703+ role->prev = role_list;
51704+ role_list = role;
51705+ }
51706+
51707+ /* used for hash chains */
51708+ role->next = NULL;
51709+
51710+ if (role->roletype & GR_ROLE_DOMAIN) {
51711+ for (i = 0; i < role->domain_child_num; i++)
51712+ __insert_acl_role_label(role, role->domain_children[i]);
51713+ } else
51714+ __insert_acl_role_label(role, role->uidgid);
51715+}
51716+
51717+static int
51718+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51719+{
51720+ struct name_entry **curr, *nentry;
51721+ struct inodev_entry *ientry;
51722+ unsigned int len = strlen(name);
51723+ unsigned int key = full_name_hash(name, len);
51724+ unsigned int index = key % name_set.n_size;
51725+
51726+ curr = &name_set.n_hash[index];
51727+
51728+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51729+ curr = &((*curr)->next);
51730+
51731+ if (*curr != NULL)
51732+ return 1;
51733+
51734+ nentry = acl_alloc(sizeof (struct name_entry));
51735+ if (nentry == NULL)
51736+ return 0;
51737+ ientry = acl_alloc(sizeof (struct inodev_entry));
51738+ if (ientry == NULL)
51739+ return 0;
51740+ ientry->nentry = nentry;
51741+
51742+ nentry->key = key;
51743+ nentry->name = name;
51744+ nentry->inode = inode;
51745+ nentry->device = device;
51746+ nentry->len = len;
51747+ nentry->deleted = deleted;
51748+
51749+ nentry->prev = NULL;
51750+ curr = &name_set.n_hash[index];
51751+ if (*curr != NULL)
51752+ (*curr)->prev = nentry;
51753+ nentry->next = *curr;
51754+ *curr = nentry;
51755+
51756+ /* insert us into the table searchable by inode/dev */
51757+ insert_inodev_entry(ientry);
51758+
51759+ return 1;
51760+}
51761+
51762+static void
51763+insert_acl_obj_label(struct acl_object_label *obj,
51764+ struct acl_subject_label *subj)
51765+{
51766+ unsigned int index =
51767+ fhash(obj->inode, obj->device, subj->obj_hash_size);
51768+ struct acl_object_label **curr;
51769+
51770+
51771+ obj->prev = NULL;
51772+
51773+ curr = &subj->obj_hash[index];
51774+ if (*curr != NULL)
51775+ (*curr)->prev = obj;
51776+
51777+ obj->next = *curr;
51778+ *curr = obj;
51779+
51780+ return;
51781+}
51782+
51783+static void
51784+insert_acl_subj_label(struct acl_subject_label *obj,
51785+ struct acl_role_label *role)
51786+{
51787+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51788+ struct acl_subject_label **curr;
51789+
51790+ obj->prev = NULL;
51791+
51792+ curr = &role->subj_hash[index];
51793+ if (*curr != NULL)
51794+ (*curr)->prev = obj;
51795+
51796+ obj->next = *curr;
51797+ *curr = obj;
51798+
51799+ return;
51800+}
51801+
51802+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51803+
51804+static void *
51805+create_table(__u32 * len, int elementsize)
51806+{
51807+ unsigned int table_sizes[] = {
51808+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51809+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51810+ 4194301, 8388593, 16777213, 33554393, 67108859
51811+ };
51812+ void *newtable = NULL;
51813+ unsigned int pwr = 0;
51814+
51815+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51816+ table_sizes[pwr] <= *len)
51817+ pwr++;
51818+
51819+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51820+ return newtable;
51821+
51822+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51823+ newtable =
51824+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51825+ else
51826+ newtable = vmalloc(table_sizes[pwr] * elementsize);
51827+
51828+ *len = table_sizes[pwr];
51829+
51830+ return newtable;
51831+}
51832+
51833+static int
51834+init_variables(const struct gr_arg *arg)
51835+{
51836+ struct task_struct *reaper = init_pid_ns.child_reaper;
51837+ unsigned int stacksize;
51838+
51839+ subj_map_set.s_size = arg->role_db.num_subjects;
51840+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51841+ name_set.n_size = arg->role_db.num_objects;
51842+ inodev_set.i_size = arg->role_db.num_objects;
51843+
51844+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
51845+ !name_set.n_size || !inodev_set.i_size)
51846+ return 1;
51847+
51848+ if (!gr_init_uidset())
51849+ return 1;
51850+
51851+ /* set up the stack that holds allocation info */
51852+
51853+ stacksize = arg->role_db.num_pointers + 5;
51854+
51855+ if (!acl_alloc_stack_init(stacksize))
51856+ return 1;
51857+
51858+ /* grab reference for the real root dentry and vfsmount */
51859+ get_fs_root(reaper->fs, &real_root);
51860+
51861+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51862+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51863+#endif
51864+
51865+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51866+ if (fakefs_obj_rw == NULL)
51867+ return 1;
51868+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51869+
51870+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51871+ if (fakefs_obj_rwx == NULL)
51872+ return 1;
51873+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51874+
51875+ subj_map_set.s_hash =
51876+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51877+ acl_role_set.r_hash =
51878+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51879+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51880+ inodev_set.i_hash =
51881+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51882+
51883+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51884+ !name_set.n_hash || !inodev_set.i_hash)
51885+ return 1;
51886+
51887+ memset(subj_map_set.s_hash, 0,
51888+ sizeof(struct subject_map *) * subj_map_set.s_size);
51889+ memset(acl_role_set.r_hash, 0,
51890+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
51891+ memset(name_set.n_hash, 0,
51892+ sizeof (struct name_entry *) * name_set.n_size);
51893+ memset(inodev_set.i_hash, 0,
51894+ sizeof (struct inodev_entry *) * inodev_set.i_size);
51895+
51896+ return 0;
51897+}
51898+
51899+/* free information not needed after startup
51900+ currently contains user->kernel pointer mappings for subjects
51901+*/
51902+
51903+static void
51904+free_init_variables(void)
51905+{
51906+ __u32 i;
51907+
51908+ if (subj_map_set.s_hash) {
51909+ for (i = 0; i < subj_map_set.s_size; i++) {
51910+ if (subj_map_set.s_hash[i]) {
51911+ kfree(subj_map_set.s_hash[i]);
51912+ subj_map_set.s_hash[i] = NULL;
51913+ }
51914+ }
51915+
51916+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51917+ PAGE_SIZE)
51918+ kfree(subj_map_set.s_hash);
51919+ else
51920+ vfree(subj_map_set.s_hash);
51921+ }
51922+
51923+ return;
51924+}
51925+
51926+static void
51927+free_variables(void)
51928+{
51929+ struct acl_subject_label *s;
51930+ struct acl_role_label *r;
51931+ struct task_struct *task, *task2;
51932+ unsigned int x;
51933+
51934+ gr_clear_learn_entries();
51935+
51936+ read_lock(&tasklist_lock);
51937+ do_each_thread(task2, task) {
51938+ task->acl_sp_role = 0;
51939+ task->acl_role_id = 0;
51940+ task->acl = NULL;
51941+ task->role = NULL;
51942+ } while_each_thread(task2, task);
51943+ read_unlock(&tasklist_lock);
51944+
51945+ /* release the reference to the real root dentry and vfsmount */
51946+ path_put(&real_root);
51947+ memset(&real_root, 0, sizeof(real_root));
51948+
51949+ /* free all object hash tables */
51950+
51951+ FOR_EACH_ROLE_START(r)
51952+ if (r->subj_hash == NULL)
51953+ goto next_role;
51954+ FOR_EACH_SUBJECT_START(r, s, x)
51955+ if (s->obj_hash == NULL)
51956+ break;
51957+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51958+ kfree(s->obj_hash);
51959+ else
51960+ vfree(s->obj_hash);
51961+ FOR_EACH_SUBJECT_END(s, x)
51962+ FOR_EACH_NESTED_SUBJECT_START(r, s)
51963+ if (s->obj_hash == NULL)
51964+ break;
51965+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51966+ kfree(s->obj_hash);
51967+ else
51968+ vfree(s->obj_hash);
51969+ FOR_EACH_NESTED_SUBJECT_END(s)
51970+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51971+ kfree(r->subj_hash);
51972+ else
51973+ vfree(r->subj_hash);
51974+ r->subj_hash = NULL;
51975+next_role:
51976+ FOR_EACH_ROLE_END(r)
51977+
51978+ acl_free_all();
51979+
51980+ if (acl_role_set.r_hash) {
51981+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51982+ PAGE_SIZE)
51983+ kfree(acl_role_set.r_hash);
51984+ else
51985+ vfree(acl_role_set.r_hash);
51986+ }
51987+ if (name_set.n_hash) {
51988+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
51989+ PAGE_SIZE)
51990+ kfree(name_set.n_hash);
51991+ else
51992+ vfree(name_set.n_hash);
51993+ }
51994+
51995+ if (inodev_set.i_hash) {
51996+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51997+ PAGE_SIZE)
51998+ kfree(inodev_set.i_hash);
51999+ else
52000+ vfree(inodev_set.i_hash);
52001+ }
52002+
52003+ gr_free_uidset();
52004+
52005+ memset(&name_set, 0, sizeof (struct name_db));
52006+ memset(&inodev_set, 0, sizeof (struct inodev_db));
52007+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52008+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52009+
52010+ default_role = NULL;
52011+ kernel_role = NULL;
52012+ role_list = NULL;
52013+
52014+ return;
52015+}
52016+
52017+static __u32
52018+count_user_objs(struct acl_object_label *userp)
52019+{
52020+ struct acl_object_label o_tmp;
52021+ __u32 num = 0;
52022+
52023+ while (userp) {
52024+ if (copy_from_user(&o_tmp, userp,
52025+ sizeof (struct acl_object_label)))
52026+ break;
52027+
52028+ userp = o_tmp.prev;
52029+ num++;
52030+ }
52031+
52032+ return num;
52033+}
52034+
52035+static struct acl_subject_label *
52036+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52037+
52038+static int
52039+copy_user_glob(struct acl_object_label *obj)
52040+{
52041+ struct acl_object_label *g_tmp, **guser;
52042+ unsigned int len;
52043+ char *tmp;
52044+
52045+ if (obj->globbed == NULL)
52046+ return 0;
52047+
52048+ guser = &obj->globbed;
52049+ while (*guser) {
52050+ g_tmp = (struct acl_object_label *)
52051+ acl_alloc(sizeof (struct acl_object_label));
52052+ if (g_tmp == NULL)
52053+ return -ENOMEM;
52054+
52055+ if (copy_from_user(g_tmp, *guser,
52056+ sizeof (struct acl_object_label)))
52057+ return -EFAULT;
52058+
52059+ len = strnlen_user(g_tmp->filename, PATH_MAX);
52060+
52061+ if (!len || len >= PATH_MAX)
52062+ return -EINVAL;
52063+
52064+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52065+ return -ENOMEM;
52066+
52067+ if (copy_from_user(tmp, g_tmp->filename, len))
52068+ return -EFAULT;
52069+ tmp[len-1] = '\0';
52070+ g_tmp->filename = tmp;
52071+
52072+ *guser = g_tmp;
52073+ guser = &(g_tmp->next);
52074+ }
52075+
52076+ return 0;
52077+}
52078+
52079+static int
52080+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52081+ struct acl_role_label *role)
52082+{
52083+ struct acl_object_label *o_tmp;
52084+ unsigned int len;
52085+ int ret;
52086+ char *tmp;
52087+
52088+ while (userp) {
52089+ if ((o_tmp = (struct acl_object_label *)
52090+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
52091+ return -ENOMEM;
52092+
52093+ if (copy_from_user(o_tmp, userp,
52094+ sizeof (struct acl_object_label)))
52095+ return -EFAULT;
52096+
52097+ userp = o_tmp->prev;
52098+
52099+ len = strnlen_user(o_tmp->filename, PATH_MAX);
52100+
52101+ if (!len || len >= PATH_MAX)
52102+ return -EINVAL;
52103+
52104+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52105+ return -ENOMEM;
52106+
52107+ if (copy_from_user(tmp, o_tmp->filename, len))
52108+ return -EFAULT;
52109+ tmp[len-1] = '\0';
52110+ o_tmp->filename = tmp;
52111+
52112+ insert_acl_obj_label(o_tmp, subj);
52113+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52114+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52115+ return -ENOMEM;
52116+
52117+ ret = copy_user_glob(o_tmp);
52118+ if (ret)
52119+ return ret;
52120+
52121+ if (o_tmp->nested) {
52122+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52123+ if (IS_ERR(o_tmp->nested))
52124+ return PTR_ERR(o_tmp->nested);
52125+
52126+ /* insert into nested subject list */
52127+ o_tmp->nested->next = role->hash->first;
52128+ role->hash->first = o_tmp->nested;
52129+ }
52130+ }
52131+
52132+ return 0;
52133+}
52134+
52135+static __u32
52136+count_user_subjs(struct acl_subject_label *userp)
52137+{
52138+ struct acl_subject_label s_tmp;
52139+ __u32 num = 0;
52140+
52141+ while (userp) {
52142+ if (copy_from_user(&s_tmp, userp,
52143+ sizeof (struct acl_subject_label)))
52144+ break;
52145+
52146+ userp = s_tmp.prev;
52147+ /* do not count nested subjects against this count, since
52148+ they are not included in the hash table, but are
52149+ attached to objects. We have already counted
52150+ the subjects in userspace for the allocation
52151+ stack
52152+ */
52153+ if (!(s_tmp.mode & GR_NESTED))
52154+ num++;
52155+ }
52156+
52157+ return num;
52158+}
52159+
52160+static int
52161+copy_user_allowedips(struct acl_role_label *rolep)
52162+{
52163+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52164+
52165+ ruserip = rolep->allowed_ips;
52166+
52167+ while (ruserip) {
52168+ rlast = rtmp;
52169+
52170+ if ((rtmp = (struct role_allowed_ip *)
52171+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52172+ return -ENOMEM;
52173+
52174+ if (copy_from_user(rtmp, ruserip,
52175+ sizeof (struct role_allowed_ip)))
52176+ return -EFAULT;
52177+
52178+ ruserip = rtmp->prev;
52179+
52180+ if (!rlast) {
52181+ rtmp->prev = NULL;
52182+ rolep->allowed_ips = rtmp;
52183+ } else {
52184+ rlast->next = rtmp;
52185+ rtmp->prev = rlast;
52186+ }
52187+
52188+ if (!ruserip)
52189+ rtmp->next = NULL;
52190+ }
52191+
52192+ return 0;
52193+}
52194+
52195+static int
52196+copy_user_transitions(struct acl_role_label *rolep)
52197+{
52198+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
52199+
52200+ unsigned int len;
52201+ char *tmp;
52202+
52203+ rusertp = rolep->transitions;
52204+
52205+ while (rusertp) {
52206+ rlast = rtmp;
52207+
52208+ if ((rtmp = (struct role_transition *)
52209+ acl_alloc(sizeof (struct role_transition))) == NULL)
52210+ return -ENOMEM;
52211+
52212+ if (copy_from_user(rtmp, rusertp,
52213+ sizeof (struct role_transition)))
52214+ return -EFAULT;
52215+
52216+ rusertp = rtmp->prev;
52217+
52218+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52219+
52220+ if (!len || len >= GR_SPROLE_LEN)
52221+ return -EINVAL;
52222+
52223+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52224+ return -ENOMEM;
52225+
52226+ if (copy_from_user(tmp, rtmp->rolename, len))
52227+ return -EFAULT;
52228+ tmp[len-1] = '\0';
52229+ rtmp->rolename = tmp;
52230+
52231+ if (!rlast) {
52232+ rtmp->prev = NULL;
52233+ rolep->transitions = rtmp;
52234+ } else {
52235+ rlast->next = rtmp;
52236+ rtmp->prev = rlast;
52237+ }
52238+
52239+ if (!rusertp)
52240+ rtmp->next = NULL;
52241+ }
52242+
52243+ return 0;
52244+}
52245+
52246+static struct acl_subject_label *
52247+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52248+{
52249+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52250+ unsigned int len;
52251+ char *tmp;
52252+ __u32 num_objs;
52253+ struct acl_ip_label **i_tmp, *i_utmp2;
52254+ struct gr_hash_struct ghash;
52255+ struct subject_map *subjmap;
52256+ unsigned int i_num;
52257+ int err;
52258+
52259+ s_tmp = lookup_subject_map(userp);
52260+
52261+ /* we've already copied this subject into the kernel, just return
52262+ the reference to it, and don't copy it over again
52263+ */
52264+ if (s_tmp)
52265+ return(s_tmp);
52266+
52267+ if ((s_tmp = (struct acl_subject_label *)
52268+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52269+ return ERR_PTR(-ENOMEM);
52270+
52271+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52272+ if (subjmap == NULL)
52273+ return ERR_PTR(-ENOMEM);
52274+
52275+ subjmap->user = userp;
52276+ subjmap->kernel = s_tmp;
52277+ insert_subj_map_entry(subjmap);
52278+
52279+ if (copy_from_user(s_tmp, userp,
52280+ sizeof (struct acl_subject_label)))
52281+ return ERR_PTR(-EFAULT);
52282+
52283+ len = strnlen_user(s_tmp->filename, PATH_MAX);
52284+
52285+ if (!len || len >= PATH_MAX)
52286+ return ERR_PTR(-EINVAL);
52287+
52288+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52289+ return ERR_PTR(-ENOMEM);
52290+
52291+ if (copy_from_user(tmp, s_tmp->filename, len))
52292+ return ERR_PTR(-EFAULT);
52293+ tmp[len-1] = '\0';
52294+ s_tmp->filename = tmp;
52295+
52296+ if (!strcmp(s_tmp->filename, "/"))
52297+ role->root_label = s_tmp;
52298+
52299+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52300+ return ERR_PTR(-EFAULT);
52301+
52302+ /* copy user and group transition tables */
52303+
52304+ if (s_tmp->user_trans_num) {
52305+ uid_t *uidlist;
52306+
52307+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52308+ if (uidlist == NULL)
52309+ return ERR_PTR(-ENOMEM);
52310+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52311+ return ERR_PTR(-EFAULT);
52312+
52313+ s_tmp->user_transitions = uidlist;
52314+ }
52315+
52316+ if (s_tmp->group_trans_num) {
52317+ gid_t *gidlist;
52318+
52319+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52320+ if (gidlist == NULL)
52321+ return ERR_PTR(-ENOMEM);
52322+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52323+ return ERR_PTR(-EFAULT);
52324+
52325+ s_tmp->group_transitions = gidlist;
52326+ }
52327+
52328+ /* set up object hash table */
52329+ num_objs = count_user_objs(ghash.first);
52330+
52331+ s_tmp->obj_hash_size = num_objs;
52332+ s_tmp->obj_hash =
52333+ (struct acl_object_label **)
52334+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52335+
52336+ if (!s_tmp->obj_hash)
52337+ return ERR_PTR(-ENOMEM);
52338+
52339+ memset(s_tmp->obj_hash, 0,
52340+ s_tmp->obj_hash_size *
52341+ sizeof (struct acl_object_label *));
52342+
52343+ /* add in objects */
52344+ err = copy_user_objs(ghash.first, s_tmp, role);
52345+
52346+ if (err)
52347+ return ERR_PTR(err);
52348+
52349+ /* set pointer for parent subject */
52350+ if (s_tmp->parent_subject) {
52351+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52352+
52353+ if (IS_ERR(s_tmp2))
52354+ return s_tmp2;
52355+
52356+ s_tmp->parent_subject = s_tmp2;
52357+ }
52358+
52359+ /* add in ip acls */
52360+
52361+ if (!s_tmp->ip_num) {
52362+ s_tmp->ips = NULL;
52363+ goto insert;
52364+ }
52365+
52366+ i_tmp =
52367+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52368+ sizeof (struct acl_ip_label *));
52369+
52370+ if (!i_tmp)
52371+ return ERR_PTR(-ENOMEM);
52372+
52373+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52374+ *(i_tmp + i_num) =
52375+ (struct acl_ip_label *)
52376+ acl_alloc(sizeof (struct acl_ip_label));
52377+ if (!*(i_tmp + i_num))
52378+ return ERR_PTR(-ENOMEM);
52379+
52380+ if (copy_from_user
52381+ (&i_utmp2, s_tmp->ips + i_num,
52382+ sizeof (struct acl_ip_label *)))
52383+ return ERR_PTR(-EFAULT);
52384+
52385+ if (copy_from_user
52386+ (*(i_tmp + i_num), i_utmp2,
52387+ sizeof (struct acl_ip_label)))
52388+ return ERR_PTR(-EFAULT);
52389+
52390+ if ((*(i_tmp + i_num))->iface == NULL)
52391+ continue;
52392+
52393+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52394+ if (!len || len >= IFNAMSIZ)
52395+ return ERR_PTR(-EINVAL);
52396+ tmp = acl_alloc(len);
52397+ if (tmp == NULL)
52398+ return ERR_PTR(-ENOMEM);
52399+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52400+ return ERR_PTR(-EFAULT);
52401+ (*(i_tmp + i_num))->iface = tmp;
52402+ }
52403+
52404+ s_tmp->ips = i_tmp;
52405+
52406+insert:
52407+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52408+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52409+ return ERR_PTR(-ENOMEM);
52410+
52411+ return s_tmp;
52412+}
52413+
52414+static int
52415+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52416+{
52417+ struct acl_subject_label s_pre;
52418+ struct acl_subject_label * ret;
52419+ int err;
52420+
52421+ while (userp) {
52422+ if (copy_from_user(&s_pre, userp,
52423+ sizeof (struct acl_subject_label)))
52424+ return -EFAULT;
52425+
52426+ /* do not add nested subjects here, add
52427+ while parsing objects
52428+ */
52429+
52430+ if (s_pre.mode & GR_NESTED) {
52431+ userp = s_pre.prev;
52432+ continue;
52433+ }
52434+
52435+ ret = do_copy_user_subj(userp, role);
52436+
52437+ err = PTR_ERR(ret);
52438+ if (IS_ERR(ret))
52439+ return err;
52440+
52441+ insert_acl_subj_label(ret, role);
52442+
52443+ userp = s_pre.prev;
52444+ }
52445+
52446+ return 0;
52447+}
52448+
52449+static int
52450+copy_user_acl(struct gr_arg *arg)
52451+{
52452+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52453+ struct sprole_pw *sptmp;
52454+ struct gr_hash_struct *ghash;
52455+ uid_t *domainlist;
52456+ unsigned int r_num;
52457+ unsigned int len;
52458+ char *tmp;
52459+ int err = 0;
52460+ __u16 i;
52461+ __u32 num_subjs;
52462+
52463+ /* we need a default and kernel role */
52464+ if (arg->role_db.num_roles < 2)
52465+ return -EINVAL;
52466+
52467+ /* copy special role authentication info from userspace */
52468+
52469+ num_sprole_pws = arg->num_sprole_pws;
52470+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52471+
52472+ if (!acl_special_roles && num_sprole_pws)
52473+ return -ENOMEM;
52474+
52475+ for (i = 0; i < num_sprole_pws; i++) {
52476+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52477+ if (!sptmp)
52478+ return -ENOMEM;
52479+ if (copy_from_user(sptmp, arg->sprole_pws + i,
52480+ sizeof (struct sprole_pw)))
52481+ return -EFAULT;
52482+
52483+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52484+
52485+ if (!len || len >= GR_SPROLE_LEN)
52486+ return -EINVAL;
52487+
52488+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52489+ return -ENOMEM;
52490+
52491+ if (copy_from_user(tmp, sptmp->rolename, len))
52492+ return -EFAULT;
52493+
52494+ tmp[len-1] = '\0';
52495+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52496+ printk(KERN_ALERT "Copying special role %s\n", tmp);
52497+#endif
52498+ sptmp->rolename = tmp;
52499+ acl_special_roles[i] = sptmp;
52500+ }
52501+
52502+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52503+
52504+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52505+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
52506+
52507+ if (!r_tmp)
52508+ return -ENOMEM;
52509+
52510+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
52511+ sizeof (struct acl_role_label *)))
52512+ return -EFAULT;
52513+
52514+ if (copy_from_user(r_tmp, r_utmp2,
52515+ sizeof (struct acl_role_label)))
52516+ return -EFAULT;
52517+
52518+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52519+
52520+ if (!len || len >= PATH_MAX)
52521+ return -EINVAL;
52522+
52523+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52524+ return -ENOMEM;
52525+
52526+ if (copy_from_user(tmp, r_tmp->rolename, len))
52527+ return -EFAULT;
52528+
52529+ tmp[len-1] = '\0';
52530+ r_tmp->rolename = tmp;
52531+
52532+ if (!strcmp(r_tmp->rolename, "default")
52533+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52534+ default_role = r_tmp;
52535+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52536+ kernel_role = r_tmp;
52537+ }
52538+
52539+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52540+ return -ENOMEM;
52541+
52542+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52543+ return -EFAULT;
52544+
52545+ r_tmp->hash = ghash;
52546+
52547+ num_subjs = count_user_subjs(r_tmp->hash->first);
52548+
52549+ r_tmp->subj_hash_size = num_subjs;
52550+ r_tmp->subj_hash =
52551+ (struct acl_subject_label **)
52552+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52553+
52554+ if (!r_tmp->subj_hash)
52555+ return -ENOMEM;
52556+
52557+ err = copy_user_allowedips(r_tmp);
52558+ if (err)
52559+ return err;
52560+
52561+ /* copy domain info */
52562+ if (r_tmp->domain_children != NULL) {
52563+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52564+ if (domainlist == NULL)
52565+ return -ENOMEM;
52566+
52567+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52568+ return -EFAULT;
52569+
52570+ r_tmp->domain_children = domainlist;
52571+ }
52572+
52573+ err = copy_user_transitions(r_tmp);
52574+ if (err)
52575+ return err;
52576+
52577+ memset(r_tmp->subj_hash, 0,
52578+ r_tmp->subj_hash_size *
52579+ sizeof (struct acl_subject_label *));
52580+
52581+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52582+
52583+ if (err)
52584+ return err;
52585+
52586+ /* set nested subject list to null */
52587+ r_tmp->hash->first = NULL;
52588+
52589+ insert_acl_role_label(r_tmp);
52590+ }
52591+
52592+ if (default_role == NULL || kernel_role == NULL)
52593+ return -EINVAL;
52594+
52595+ return err;
52596+}
52597+
52598+static int
52599+gracl_init(struct gr_arg *args)
52600+{
52601+ int error = 0;
52602+
52603+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52604+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52605+
52606+ if (init_variables(args)) {
52607+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52608+ error = -ENOMEM;
52609+ free_variables();
52610+ goto out;
52611+ }
52612+
52613+ error = copy_user_acl(args);
52614+ free_init_variables();
52615+ if (error) {
52616+ free_variables();
52617+ goto out;
52618+ }
52619+
52620+ if ((error = gr_set_acls(0))) {
52621+ free_variables();
52622+ goto out;
52623+ }
52624+
52625+ pax_open_kernel();
52626+ gr_status |= GR_READY;
52627+ pax_close_kernel();
52628+
52629+ out:
52630+ return error;
52631+}
52632+
52633+/* derived from glibc fnmatch() 0: match, 1: no match*/
52634+
52635+static int
52636+glob_match(const char *p, const char *n)
52637+{
52638+ char c;
52639+
52640+ while ((c = *p++) != '\0') {
52641+ switch (c) {
52642+ case '?':
52643+ if (*n == '\0')
52644+ return 1;
52645+ else if (*n == '/')
52646+ return 1;
52647+ break;
52648+ case '\\':
52649+ if (*n != c)
52650+ return 1;
52651+ break;
52652+ case '*':
52653+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
52654+ if (*n == '/')
52655+ return 1;
52656+ else if (c == '?') {
52657+ if (*n == '\0')
52658+ return 1;
52659+ else
52660+ ++n;
52661+ }
52662+ }
52663+ if (c == '\0') {
52664+ return 0;
52665+ } else {
52666+ const char *endp;
52667+
52668+ if ((endp = strchr(n, '/')) == NULL)
52669+ endp = n + strlen(n);
52670+
52671+ if (c == '[') {
52672+ for (--p; n < endp; ++n)
52673+ if (!glob_match(p, n))
52674+ return 0;
52675+ } else if (c == '/') {
52676+ while (*n != '\0' && *n != '/')
52677+ ++n;
52678+ if (*n == '/' && !glob_match(p, n + 1))
52679+ return 0;
52680+ } else {
52681+ for (--p; n < endp; ++n)
52682+ if (*n == c && !glob_match(p, n))
52683+ return 0;
52684+ }
52685+
52686+ return 1;
52687+ }
52688+ case '[':
52689+ {
52690+ int not;
52691+ char cold;
52692+
52693+ if (*n == '\0' || *n == '/')
52694+ return 1;
52695+
52696+ not = (*p == '!' || *p == '^');
52697+ if (not)
52698+ ++p;
52699+
52700+ c = *p++;
52701+ for (;;) {
52702+ unsigned char fn = (unsigned char)*n;
52703+
52704+ if (c == '\0')
52705+ return 1;
52706+ else {
52707+ if (c == fn)
52708+ goto matched;
52709+ cold = c;
52710+ c = *p++;
52711+
52712+ if (c == '-' && *p != ']') {
52713+ unsigned char cend = *p++;
52714+
52715+ if (cend == '\0')
52716+ return 1;
52717+
52718+ if (cold <= fn && fn <= cend)
52719+ goto matched;
52720+
52721+ c = *p++;
52722+ }
52723+ }
52724+
52725+ if (c == ']')
52726+ break;
52727+ }
52728+ if (!not)
52729+ return 1;
52730+ break;
52731+ matched:
52732+ while (c != ']') {
52733+ if (c == '\0')
52734+ return 1;
52735+
52736+ c = *p++;
52737+ }
52738+ if (not)
52739+ return 1;
52740+ }
52741+ break;
52742+ default:
52743+ if (c != *n)
52744+ return 1;
52745+ }
52746+
52747+ ++n;
52748+ }
52749+
52750+ if (*n == '\0')
52751+ return 0;
52752+
52753+ if (*n == '/')
52754+ return 0;
52755+
52756+ return 1;
52757+}
52758+
52759+static struct acl_object_label *
52760+chk_glob_label(struct acl_object_label *globbed,
52761+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52762+{
52763+ struct acl_object_label *tmp;
52764+
52765+ if (*path == NULL)
52766+ *path = gr_to_filename_nolock(dentry, mnt);
52767+
52768+ tmp = globbed;
52769+
52770+ while (tmp) {
52771+ if (!glob_match(tmp->filename, *path))
52772+ return tmp;
52773+ tmp = tmp->next;
52774+ }
52775+
52776+ return NULL;
52777+}
52778+
52779+static struct acl_object_label *
52780+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52781+ const ino_t curr_ino, const dev_t curr_dev,
52782+ const struct acl_subject_label *subj, char **path, const int checkglob)
52783+{
52784+ struct acl_subject_label *tmpsubj;
52785+ struct acl_object_label *retval;
52786+ struct acl_object_label *retval2;
52787+
52788+ tmpsubj = (struct acl_subject_label *) subj;
52789+ read_lock(&gr_inode_lock);
52790+ do {
52791+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52792+ if (retval) {
52793+ if (checkglob && retval->globbed) {
52794+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52795+ if (retval2)
52796+ retval = retval2;
52797+ }
52798+ break;
52799+ }
52800+ } while ((tmpsubj = tmpsubj->parent_subject));
52801+ read_unlock(&gr_inode_lock);
52802+
52803+ return retval;
52804+}
52805+
52806+static __inline__ struct acl_object_label *
52807+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52808+ struct dentry *curr_dentry,
52809+ const struct acl_subject_label *subj, char **path, const int checkglob)
52810+{
52811+ int newglob = checkglob;
52812+ ino_t inode;
52813+ dev_t device;
52814+
52815+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52816+ as we don't want a / * rule to match instead of the / object
52817+ don't do this for create lookups that call this function though, since they're looking up
52818+ on the parent and thus need globbing checks on all paths
52819+ */
52820+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52821+ newglob = GR_NO_GLOB;
52822+
52823+ spin_lock(&curr_dentry->d_lock);
52824+ inode = curr_dentry->d_inode->i_ino;
52825+ device = __get_dev(curr_dentry);
52826+ spin_unlock(&curr_dentry->d_lock);
52827+
52828+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52829+}
52830+
52831+static struct acl_object_label *
52832+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52833+ const struct acl_subject_label *subj, char *path, const int checkglob)
52834+{
52835+ struct dentry *dentry = (struct dentry *) l_dentry;
52836+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52837+ struct mount *real_mnt = real_mount(mnt);
52838+ struct acl_object_label *retval;
52839+ struct dentry *parent;
52840+
52841+ write_seqlock(&rename_lock);
52842+ br_read_lock(&vfsmount_lock);
52843+
52844+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52845+#ifdef CONFIG_NET
52846+ mnt == sock_mnt ||
52847+#endif
52848+#ifdef CONFIG_HUGETLBFS
52849+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52850+#endif
52851+ /* ignore Eric Biederman */
52852+ IS_PRIVATE(l_dentry->d_inode))) {
52853+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52854+ goto out;
52855+ }
52856+
52857+ for (;;) {
52858+ if (dentry == real_root.dentry && mnt == real_root.mnt)
52859+ break;
52860+
52861+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52862+ if (!mnt_has_parent(real_mnt))
52863+ break;
52864+
52865+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52866+ if (retval != NULL)
52867+ goto out;
52868+
52869+ dentry = real_mnt->mnt_mountpoint;
52870+ real_mnt = real_mnt->mnt_parent;
52871+ mnt = &real_mnt->mnt;
52872+ continue;
52873+ }
52874+
52875+ parent = dentry->d_parent;
52876+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52877+ if (retval != NULL)
52878+ goto out;
52879+
52880+ dentry = parent;
52881+ }
52882+
52883+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52884+
52885+ /* real_root is pinned so we don't have to hold a reference */
52886+ if (retval == NULL)
52887+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52888+out:
52889+ br_read_unlock(&vfsmount_lock);
52890+ write_sequnlock(&rename_lock);
52891+
52892+ BUG_ON(retval == NULL);
52893+
52894+ return retval;
52895+}
52896+
52897+static __inline__ struct acl_object_label *
52898+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52899+ const struct acl_subject_label *subj)
52900+{
52901+ char *path = NULL;
52902+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52903+}
52904+
52905+static __inline__ struct acl_object_label *
52906+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52907+ const struct acl_subject_label *subj)
52908+{
52909+ char *path = NULL;
52910+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52911+}
52912+
52913+static __inline__ struct acl_object_label *
52914+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52915+ const struct acl_subject_label *subj, char *path)
52916+{
52917+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52918+}
52919+
52920+static struct acl_subject_label *
52921+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52922+ const struct acl_role_label *role)
52923+{
52924+ struct dentry *dentry = (struct dentry *) l_dentry;
52925+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52926+ struct mount *real_mnt = real_mount(mnt);
52927+ struct acl_subject_label *retval;
52928+ struct dentry *parent;
52929+
52930+ write_seqlock(&rename_lock);
52931+ br_read_lock(&vfsmount_lock);
52932+
52933+ for (;;) {
52934+ if (dentry == real_root.dentry && mnt == real_root.mnt)
52935+ break;
52936+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52937+ if (!mnt_has_parent(real_mnt))
52938+ break;
52939+
52940+ spin_lock(&dentry->d_lock);
52941+ read_lock(&gr_inode_lock);
52942+ retval =
52943+ lookup_acl_subj_label(dentry->d_inode->i_ino,
52944+ __get_dev(dentry), role);
52945+ read_unlock(&gr_inode_lock);
52946+ spin_unlock(&dentry->d_lock);
52947+ if (retval != NULL)
52948+ goto out;
52949+
52950+ dentry = real_mnt->mnt_mountpoint;
52951+ real_mnt = real_mnt->mnt_parent;
52952+ mnt = &real_mnt->mnt;
52953+ continue;
52954+ }
52955+
52956+ spin_lock(&dentry->d_lock);
52957+ read_lock(&gr_inode_lock);
52958+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52959+ __get_dev(dentry), role);
52960+ read_unlock(&gr_inode_lock);
52961+ parent = dentry->d_parent;
52962+ spin_unlock(&dentry->d_lock);
52963+
52964+ if (retval != NULL)
52965+ goto out;
52966+
52967+ dentry = parent;
52968+ }
52969+
52970+ spin_lock(&dentry->d_lock);
52971+ read_lock(&gr_inode_lock);
52972+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52973+ __get_dev(dentry), role);
52974+ read_unlock(&gr_inode_lock);
52975+ spin_unlock(&dentry->d_lock);
52976+
52977+ if (unlikely(retval == NULL)) {
52978+ /* real_root is pinned, we don't need to hold a reference */
52979+ read_lock(&gr_inode_lock);
52980+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52981+ __get_dev(real_root.dentry), role);
52982+ read_unlock(&gr_inode_lock);
52983+ }
52984+out:
52985+ br_read_unlock(&vfsmount_lock);
52986+ write_sequnlock(&rename_lock);
52987+
52988+ BUG_ON(retval == NULL);
52989+
52990+ return retval;
52991+}
52992+
52993+static void
52994+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52995+{
52996+ struct task_struct *task = current;
52997+ const struct cred *cred = current_cred();
52998+
52999+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53000+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53001+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53002+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53003+
53004+ return;
53005+}
53006+
53007+static void
53008+gr_log_learn_id_change(const char type, const unsigned int real,
53009+ const unsigned int effective, const unsigned int fs)
53010+{
53011+ struct task_struct *task = current;
53012+ const struct cred *cred = current_cred();
53013+
53014+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53015+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53016+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53017+ type, real, effective, fs, &task->signal->saved_ip);
53018+
53019+ return;
53020+}
53021+
53022+__u32
53023+gr_search_file(const struct dentry * dentry, const __u32 mode,
53024+ const struct vfsmount * mnt)
53025+{
53026+ __u32 retval = mode;
53027+ struct acl_subject_label *curracl;
53028+ struct acl_object_label *currobj;
53029+
53030+ if (unlikely(!(gr_status & GR_READY)))
53031+ return (mode & ~GR_AUDITS);
53032+
53033+ curracl = current->acl;
53034+
53035+ currobj = chk_obj_label(dentry, mnt, curracl);
53036+ retval = currobj->mode & mode;
53037+
53038+ /* if we're opening a specified transfer file for writing
53039+ (e.g. /dev/initctl), then transfer our role to init
53040+ */
53041+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53042+ current->role->roletype & GR_ROLE_PERSIST)) {
53043+ struct task_struct *task = init_pid_ns.child_reaper;
53044+
53045+ if (task->role != current->role) {
53046+ task->acl_sp_role = 0;
53047+ task->acl_role_id = current->acl_role_id;
53048+ task->role = current->role;
53049+ rcu_read_lock();
53050+ read_lock(&grsec_exec_file_lock);
53051+ gr_apply_subject_to_task(task);
53052+ read_unlock(&grsec_exec_file_lock);
53053+ rcu_read_unlock();
53054+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53055+ }
53056+ }
53057+
53058+ if (unlikely
53059+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53060+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53061+ __u32 new_mode = mode;
53062+
53063+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53064+
53065+ retval = new_mode;
53066+
53067+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53068+ new_mode |= GR_INHERIT;
53069+
53070+ if (!(mode & GR_NOLEARN))
53071+ gr_log_learn(dentry, mnt, new_mode);
53072+ }
53073+
53074+ return retval;
53075+}
53076+
53077+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53078+ const struct dentry *parent,
53079+ const struct vfsmount *mnt)
53080+{
53081+ struct name_entry *match;
53082+ struct acl_object_label *matchpo;
53083+ struct acl_subject_label *curracl;
53084+ char *path;
53085+
53086+ if (unlikely(!(gr_status & GR_READY)))
53087+ return NULL;
53088+
53089+ preempt_disable();
53090+ path = gr_to_filename_rbac(new_dentry, mnt);
53091+ match = lookup_name_entry_create(path);
53092+
53093+ curracl = current->acl;
53094+
53095+ if (match) {
53096+ read_lock(&gr_inode_lock);
53097+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53098+ read_unlock(&gr_inode_lock);
53099+
53100+ if (matchpo) {
53101+ preempt_enable();
53102+ return matchpo;
53103+ }
53104+ }
53105+
53106+ // lookup parent
53107+
53108+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53109+
53110+ preempt_enable();
53111+ return matchpo;
53112+}
53113+
53114+__u32
53115+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53116+ const struct vfsmount * mnt, const __u32 mode)
53117+{
53118+ struct acl_object_label *matchpo;
53119+ __u32 retval;
53120+
53121+ if (unlikely(!(gr_status & GR_READY)))
53122+ return (mode & ~GR_AUDITS);
53123+
53124+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
53125+
53126+ retval = matchpo->mode & mode;
53127+
53128+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53129+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53130+ __u32 new_mode = mode;
53131+
53132+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53133+
53134+ gr_log_learn(new_dentry, mnt, new_mode);
53135+ return new_mode;
53136+ }
53137+
53138+ return retval;
53139+}
53140+
53141+__u32
53142+gr_check_link(const struct dentry * new_dentry,
53143+ const struct dentry * parent_dentry,
53144+ const struct vfsmount * parent_mnt,
53145+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53146+{
53147+ struct acl_object_label *obj;
53148+ __u32 oldmode, newmode;
53149+ __u32 needmode;
53150+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53151+ GR_DELETE | GR_INHERIT;
53152+
53153+ if (unlikely(!(gr_status & GR_READY)))
53154+ return (GR_CREATE | GR_LINK);
53155+
53156+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53157+ oldmode = obj->mode;
53158+
53159+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53160+ newmode = obj->mode;
53161+
53162+ needmode = newmode & checkmodes;
53163+
53164+ // old name for hardlink must have at least the permissions of the new name
53165+ if ((oldmode & needmode) != needmode)
53166+ goto bad;
53167+
53168+ // if old name had restrictions/auditing, make sure the new name does as well
53169+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53170+
53171+ // don't allow hardlinking of suid/sgid files without permission
53172+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53173+ needmode |= GR_SETID;
53174+
53175+ if ((newmode & needmode) != needmode)
53176+ goto bad;
53177+
53178+ // enforce minimum permissions
53179+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53180+ return newmode;
53181+bad:
53182+ needmode = oldmode;
53183+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53184+ needmode |= GR_SETID;
53185+
53186+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53187+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53188+ return (GR_CREATE | GR_LINK);
53189+ } else if (newmode & GR_SUPPRESS)
53190+ return GR_SUPPRESS;
53191+ else
53192+ return 0;
53193+}
53194+
53195+int
53196+gr_check_hidden_task(const struct task_struct *task)
53197+{
53198+ if (unlikely(!(gr_status & GR_READY)))
53199+ return 0;
53200+
53201+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53202+ return 1;
53203+
53204+ return 0;
53205+}
53206+
53207+int
53208+gr_check_protected_task(const struct task_struct *task)
53209+{
53210+ if (unlikely(!(gr_status & GR_READY) || !task))
53211+ return 0;
53212+
53213+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53214+ task->acl != current->acl)
53215+ return 1;
53216+
53217+ return 0;
53218+}
53219+
53220+int
53221+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53222+{
53223+ struct task_struct *p;
53224+ int ret = 0;
53225+
53226+ if (unlikely(!(gr_status & GR_READY) || !pid))
53227+ return ret;
53228+
53229+ read_lock(&tasklist_lock);
53230+ do_each_pid_task(pid, type, p) {
53231+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53232+ p->acl != current->acl) {
53233+ ret = 1;
53234+ goto out;
53235+ }
53236+ } while_each_pid_task(pid, type, p);
53237+out:
53238+ read_unlock(&tasklist_lock);
53239+
53240+ return ret;
53241+}
53242+
53243+void
53244+gr_copy_label(struct task_struct *tsk)
53245+{
53246+ tsk->signal->used_accept = 0;
53247+ tsk->acl_sp_role = 0;
53248+ tsk->acl_role_id = current->acl_role_id;
53249+ tsk->acl = current->acl;
53250+ tsk->role = current->role;
53251+ tsk->signal->curr_ip = current->signal->curr_ip;
53252+ tsk->signal->saved_ip = current->signal->saved_ip;
53253+ if (current->exec_file)
53254+ get_file(current->exec_file);
53255+ tsk->exec_file = current->exec_file;
53256+ tsk->is_writable = current->is_writable;
53257+ if (unlikely(current->signal->used_accept)) {
53258+ current->signal->curr_ip = 0;
53259+ current->signal->saved_ip = 0;
53260+ }
53261+
53262+ return;
53263+}
53264+
53265+static void
53266+gr_set_proc_res(struct task_struct *task)
53267+{
53268+ struct acl_subject_label *proc;
53269+ unsigned short i;
53270+
53271+ proc = task->acl;
53272+
53273+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53274+ return;
53275+
53276+ for (i = 0; i < RLIM_NLIMITS; i++) {
53277+ if (!(proc->resmask & (1 << i)))
53278+ continue;
53279+
53280+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53281+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53282+ }
53283+
53284+ return;
53285+}
53286+
53287+extern int __gr_process_user_ban(struct user_struct *user);
53288+
53289+int
53290+gr_check_user_change(int real, int effective, int fs)
53291+{
53292+ unsigned int i;
53293+ __u16 num;
53294+ uid_t *uidlist;
53295+ int curuid;
53296+ int realok = 0;
53297+ int effectiveok = 0;
53298+ int fsok = 0;
53299+
53300+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53301+ struct user_struct *user;
53302+
53303+ if (real == -1)
53304+ goto skipit;
53305+
53306+ user = find_user(real);
53307+ if (user == NULL)
53308+ goto skipit;
53309+
53310+ if (__gr_process_user_ban(user)) {
53311+ /* for find_user */
53312+ free_uid(user);
53313+ return 1;
53314+ }
53315+
53316+ /* for find_user */
53317+ free_uid(user);
53318+
53319+skipit:
53320+#endif
53321+
53322+ if (unlikely(!(gr_status & GR_READY)))
53323+ return 0;
53324+
53325+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53326+ gr_log_learn_id_change('u', real, effective, fs);
53327+
53328+ num = current->acl->user_trans_num;
53329+ uidlist = current->acl->user_transitions;
53330+
53331+ if (uidlist == NULL)
53332+ return 0;
53333+
53334+ if (real == -1)
53335+ realok = 1;
53336+ if (effective == -1)
53337+ effectiveok = 1;
53338+ if (fs == -1)
53339+ fsok = 1;
53340+
53341+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
53342+ for (i = 0; i < num; i++) {
53343+ curuid = (int)uidlist[i];
53344+ if (real == curuid)
53345+ realok = 1;
53346+ if (effective == curuid)
53347+ effectiveok = 1;
53348+ if (fs == curuid)
53349+ fsok = 1;
53350+ }
53351+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
53352+ for (i = 0; i < num; i++) {
53353+ curuid = (int)uidlist[i];
53354+ if (real == curuid)
53355+ break;
53356+ if (effective == curuid)
53357+ break;
53358+ if (fs == curuid)
53359+ break;
53360+ }
53361+ /* not in deny list */
53362+ if (i == num) {
53363+ realok = 1;
53364+ effectiveok = 1;
53365+ fsok = 1;
53366+ }
53367+ }
53368+
53369+ if (realok && effectiveok && fsok)
53370+ return 0;
53371+ else {
53372+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53373+ return 1;
53374+ }
53375+}
53376+
53377+int
53378+gr_check_group_change(int real, int effective, int fs)
53379+{
53380+ unsigned int i;
53381+ __u16 num;
53382+ gid_t *gidlist;
53383+ int curgid;
53384+ int realok = 0;
53385+ int effectiveok = 0;
53386+ int fsok = 0;
53387+
53388+ if (unlikely(!(gr_status & GR_READY)))
53389+ return 0;
53390+
53391+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53392+ gr_log_learn_id_change('g', real, effective, fs);
53393+
53394+ num = current->acl->group_trans_num;
53395+ gidlist = current->acl->group_transitions;
53396+
53397+ if (gidlist == NULL)
53398+ return 0;
53399+
53400+ if (real == -1)
53401+ realok = 1;
53402+ if (effective == -1)
53403+ effectiveok = 1;
53404+ if (fs == -1)
53405+ fsok = 1;
53406+
53407+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
53408+ for (i = 0; i < num; i++) {
53409+ curgid = (int)gidlist[i];
53410+ if (real == curgid)
53411+ realok = 1;
53412+ if (effective == curgid)
53413+ effectiveok = 1;
53414+ if (fs == curgid)
53415+ fsok = 1;
53416+ }
53417+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
53418+ for (i = 0; i < num; i++) {
53419+ curgid = (int)gidlist[i];
53420+ if (real == curgid)
53421+ break;
53422+ if (effective == curgid)
53423+ break;
53424+ if (fs == curgid)
53425+ break;
53426+ }
53427+ /* not in deny list */
53428+ if (i == num) {
53429+ realok = 1;
53430+ effectiveok = 1;
53431+ fsok = 1;
53432+ }
53433+ }
53434+
53435+ if (realok && effectiveok && fsok)
53436+ return 0;
53437+ else {
53438+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53439+ return 1;
53440+ }
53441+}
53442+
53443+extern int gr_acl_is_capable(const int cap);
53444+
53445+void
53446+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53447+{
53448+ struct acl_role_label *role = task->role;
53449+ struct acl_subject_label *subj = NULL;
53450+ struct acl_object_label *obj;
53451+ struct file *filp;
53452+
53453+ if (unlikely(!(gr_status & GR_READY)))
53454+ return;
53455+
53456+ filp = task->exec_file;
53457+
53458+ /* kernel process, we'll give them the kernel role */
53459+ if (unlikely(!filp)) {
53460+ task->role = kernel_role;
53461+ task->acl = kernel_role->root_label;
53462+ return;
53463+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53464+ role = lookup_acl_role_label(task, uid, gid);
53465+
53466+ /* don't change the role if we're not a privileged process */
53467+ if (role && task->role != role &&
53468+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53469+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53470+ return;
53471+
53472+ /* perform subject lookup in possibly new role
53473+ we can use this result below in the case where role == task->role
53474+ */
53475+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53476+
53477+ /* if we changed uid/gid, but result in the same role
53478+ and are using inheritance, don't lose the inherited subject
53479+ if current subject is other than what normal lookup
53480+ would result in, we arrived via inheritance, don't
53481+ lose subject
53482+ */
53483+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53484+ (subj == task->acl)))
53485+ task->acl = subj;
53486+
53487+ task->role = role;
53488+
53489+ task->is_writable = 0;
53490+
53491+ /* ignore additional mmap checks for processes that are writable
53492+ by the default ACL */
53493+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53494+ if (unlikely(obj->mode & GR_WRITE))
53495+ task->is_writable = 1;
53496+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53497+ if (unlikely(obj->mode & GR_WRITE))
53498+ task->is_writable = 1;
53499+
53500+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53501+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53502+#endif
53503+
53504+ gr_set_proc_res(task);
53505+
53506+ return;
53507+}
53508+
53509+int
53510+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53511+ const int unsafe_flags)
53512+{
53513+ struct task_struct *task = current;
53514+ struct acl_subject_label *newacl;
53515+ struct acl_object_label *obj;
53516+ __u32 retmode;
53517+
53518+ if (unlikely(!(gr_status & GR_READY)))
53519+ return 0;
53520+
53521+ newacl = chk_subj_label(dentry, mnt, task->role);
53522+
53523+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53524+ did an exec
53525+ */
53526+ rcu_read_lock();
53527+ read_lock(&tasklist_lock);
53528+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53529+ (task->parent->acl->mode & GR_POVERRIDE))) {
53530+ read_unlock(&tasklist_lock);
53531+ rcu_read_unlock();
53532+ goto skip_check;
53533+ }
53534+ read_unlock(&tasklist_lock);
53535+ rcu_read_unlock();
53536+
53537+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53538+ !(task->role->roletype & GR_ROLE_GOD) &&
53539+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53540+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53541+ if (unsafe_flags & LSM_UNSAFE_SHARE)
53542+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53543+ else
53544+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53545+ return -EACCES;
53546+ }
53547+
53548+skip_check:
53549+
53550+ obj = chk_obj_label(dentry, mnt, task->acl);
53551+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53552+
53553+ if (!(task->acl->mode & GR_INHERITLEARN) &&
53554+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53555+ if (obj->nested)
53556+ task->acl = obj->nested;
53557+ else
53558+ task->acl = newacl;
53559+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53560+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53561+
53562+ task->is_writable = 0;
53563+
53564+ /* ignore additional mmap checks for processes that are writable
53565+ by the default ACL */
53566+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
53567+ if (unlikely(obj->mode & GR_WRITE))
53568+ task->is_writable = 1;
53569+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
53570+ if (unlikely(obj->mode & GR_WRITE))
53571+ task->is_writable = 1;
53572+
53573+ gr_set_proc_res(task);
53574+
53575+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53576+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53577+#endif
53578+ return 0;
53579+}
53580+
53581+/* always called with valid inodev ptr */
53582+static void
53583+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53584+{
53585+ struct acl_object_label *matchpo;
53586+ struct acl_subject_label *matchps;
53587+ struct acl_subject_label *subj;
53588+ struct acl_role_label *role;
53589+ unsigned int x;
53590+
53591+ FOR_EACH_ROLE_START(role)
53592+ FOR_EACH_SUBJECT_START(role, subj, x)
53593+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53594+ matchpo->mode |= GR_DELETED;
53595+ FOR_EACH_SUBJECT_END(subj,x)
53596+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53597+ if (subj->inode == ino && subj->device == dev)
53598+ subj->mode |= GR_DELETED;
53599+ FOR_EACH_NESTED_SUBJECT_END(subj)
53600+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53601+ matchps->mode |= GR_DELETED;
53602+ FOR_EACH_ROLE_END(role)
53603+
53604+ inodev->nentry->deleted = 1;
53605+
53606+ return;
53607+}
53608+
53609+void
53610+gr_handle_delete(const ino_t ino, const dev_t dev)
53611+{
53612+ struct inodev_entry *inodev;
53613+
53614+ if (unlikely(!(gr_status & GR_READY)))
53615+ return;
53616+
53617+ write_lock(&gr_inode_lock);
53618+ inodev = lookup_inodev_entry(ino, dev);
53619+ if (inodev != NULL)
53620+ do_handle_delete(inodev, ino, dev);
53621+ write_unlock(&gr_inode_lock);
53622+
53623+ return;
53624+}
53625+
53626+static void
53627+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53628+ const ino_t newinode, const dev_t newdevice,
53629+ struct acl_subject_label *subj)
53630+{
53631+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53632+ struct acl_object_label *match;
53633+
53634+ match = subj->obj_hash[index];
53635+
53636+ while (match && (match->inode != oldinode ||
53637+ match->device != olddevice ||
53638+ !(match->mode & GR_DELETED)))
53639+ match = match->next;
53640+
53641+ if (match && (match->inode == oldinode)
53642+ && (match->device == olddevice)
53643+ && (match->mode & GR_DELETED)) {
53644+ if (match->prev == NULL) {
53645+ subj->obj_hash[index] = match->next;
53646+ if (match->next != NULL)
53647+ match->next->prev = NULL;
53648+ } else {
53649+ match->prev->next = match->next;
53650+ if (match->next != NULL)
53651+ match->next->prev = match->prev;
53652+ }
53653+ match->prev = NULL;
53654+ match->next = NULL;
53655+ match->inode = newinode;
53656+ match->device = newdevice;
53657+ match->mode &= ~GR_DELETED;
53658+
53659+ insert_acl_obj_label(match, subj);
53660+ }
53661+
53662+ return;
53663+}
53664+
53665+static void
53666+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53667+ const ino_t newinode, const dev_t newdevice,
53668+ struct acl_role_label *role)
53669+{
53670+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53671+ struct acl_subject_label *match;
53672+
53673+ match = role->subj_hash[index];
53674+
53675+ while (match && (match->inode != oldinode ||
53676+ match->device != olddevice ||
53677+ !(match->mode & GR_DELETED)))
53678+ match = match->next;
53679+
53680+ if (match && (match->inode == oldinode)
53681+ && (match->device == olddevice)
53682+ && (match->mode & GR_DELETED)) {
53683+ if (match->prev == NULL) {
53684+ role->subj_hash[index] = match->next;
53685+ if (match->next != NULL)
53686+ match->next->prev = NULL;
53687+ } else {
53688+ match->prev->next = match->next;
53689+ if (match->next != NULL)
53690+ match->next->prev = match->prev;
53691+ }
53692+ match->prev = NULL;
53693+ match->next = NULL;
53694+ match->inode = newinode;
53695+ match->device = newdevice;
53696+ match->mode &= ~GR_DELETED;
53697+
53698+ insert_acl_subj_label(match, role);
53699+ }
53700+
53701+ return;
53702+}
53703+
53704+static void
53705+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53706+ const ino_t newinode, const dev_t newdevice)
53707+{
53708+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53709+ struct inodev_entry *match;
53710+
53711+ match = inodev_set.i_hash[index];
53712+
53713+ while (match && (match->nentry->inode != oldinode ||
53714+ match->nentry->device != olddevice || !match->nentry->deleted))
53715+ match = match->next;
53716+
53717+ if (match && (match->nentry->inode == oldinode)
53718+ && (match->nentry->device == olddevice) &&
53719+ match->nentry->deleted) {
53720+ if (match->prev == NULL) {
53721+ inodev_set.i_hash[index] = match->next;
53722+ if (match->next != NULL)
53723+ match->next->prev = NULL;
53724+ } else {
53725+ match->prev->next = match->next;
53726+ if (match->next != NULL)
53727+ match->next->prev = match->prev;
53728+ }
53729+ match->prev = NULL;
53730+ match->next = NULL;
53731+ match->nentry->inode = newinode;
53732+ match->nentry->device = newdevice;
53733+ match->nentry->deleted = 0;
53734+
53735+ insert_inodev_entry(match);
53736+ }
53737+
53738+ return;
53739+}
53740+
53741+static void
53742+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53743+{
53744+ struct acl_subject_label *subj;
53745+ struct acl_role_label *role;
53746+ unsigned int x;
53747+
53748+ FOR_EACH_ROLE_START(role)
53749+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53750+
53751+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53752+ if ((subj->inode == ino) && (subj->device == dev)) {
53753+ subj->inode = ino;
53754+ subj->device = dev;
53755+ }
53756+ FOR_EACH_NESTED_SUBJECT_END(subj)
53757+ FOR_EACH_SUBJECT_START(role, subj, x)
53758+ update_acl_obj_label(matchn->inode, matchn->device,
53759+ ino, dev, subj);
53760+ FOR_EACH_SUBJECT_END(subj,x)
53761+ FOR_EACH_ROLE_END(role)
53762+
53763+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53764+
53765+ return;
53766+}
53767+
53768+static void
53769+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53770+ const struct vfsmount *mnt)
53771+{
53772+ ino_t ino = dentry->d_inode->i_ino;
53773+ dev_t dev = __get_dev(dentry);
53774+
53775+ __do_handle_create(matchn, ino, dev);
53776+
53777+ return;
53778+}
53779+
53780+void
53781+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53782+{
53783+ struct name_entry *matchn;
53784+
53785+ if (unlikely(!(gr_status & GR_READY)))
53786+ return;
53787+
53788+ preempt_disable();
53789+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53790+
53791+ if (unlikely((unsigned long)matchn)) {
53792+ write_lock(&gr_inode_lock);
53793+ do_handle_create(matchn, dentry, mnt);
53794+ write_unlock(&gr_inode_lock);
53795+ }
53796+ preempt_enable();
53797+
53798+ return;
53799+}
53800+
53801+void
53802+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53803+{
53804+ struct name_entry *matchn;
53805+
53806+ if (unlikely(!(gr_status & GR_READY)))
53807+ return;
53808+
53809+ preempt_disable();
53810+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53811+
53812+ if (unlikely((unsigned long)matchn)) {
53813+ write_lock(&gr_inode_lock);
53814+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53815+ write_unlock(&gr_inode_lock);
53816+ }
53817+ preempt_enable();
53818+
53819+ return;
53820+}
53821+
53822+void
53823+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53824+ struct dentry *old_dentry,
53825+ struct dentry *new_dentry,
53826+ struct vfsmount *mnt, const __u8 replace)
53827+{
53828+ struct name_entry *matchn;
53829+ struct inodev_entry *inodev;
53830+ struct inode *inode = new_dentry->d_inode;
53831+ ino_t old_ino = old_dentry->d_inode->i_ino;
53832+ dev_t old_dev = __get_dev(old_dentry);
53833+
53834+ /* vfs_rename swaps the name and parent link for old_dentry and
53835+ new_dentry
53836+ at this point, old_dentry has the new name, parent link, and inode
53837+ for the renamed file
53838+ if a file is being replaced by a rename, new_dentry has the inode
53839+ and name for the replaced file
53840+ */
53841+
53842+ if (unlikely(!(gr_status & GR_READY)))
53843+ return;
53844+
53845+ preempt_disable();
53846+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53847+
53848+ /* we wouldn't have to check d_inode if it weren't for
53849+ NFS silly-renaming
53850+ */
53851+
53852+ write_lock(&gr_inode_lock);
53853+ if (unlikely(replace && inode)) {
53854+ ino_t new_ino = inode->i_ino;
53855+ dev_t new_dev = __get_dev(new_dentry);
53856+
53857+ inodev = lookup_inodev_entry(new_ino, new_dev);
53858+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53859+ do_handle_delete(inodev, new_ino, new_dev);
53860+ }
53861+
53862+ inodev = lookup_inodev_entry(old_ino, old_dev);
53863+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53864+ do_handle_delete(inodev, old_ino, old_dev);
53865+
53866+ if (unlikely((unsigned long)matchn))
53867+ do_handle_create(matchn, old_dentry, mnt);
53868+
53869+ write_unlock(&gr_inode_lock);
53870+ preempt_enable();
53871+
53872+ return;
53873+}
53874+
53875+static int
53876+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53877+ unsigned char **sum)
53878+{
53879+ struct acl_role_label *r;
53880+ struct role_allowed_ip *ipp;
53881+ struct role_transition *trans;
53882+ unsigned int i;
53883+ int found = 0;
53884+ u32 curr_ip = current->signal->curr_ip;
53885+
53886+ current->signal->saved_ip = curr_ip;
53887+
53888+ /* check transition table */
53889+
53890+ for (trans = current->role->transitions; trans; trans = trans->next) {
53891+ if (!strcmp(rolename, trans->rolename)) {
53892+ found = 1;
53893+ break;
53894+ }
53895+ }
53896+
53897+ if (!found)
53898+ return 0;
53899+
53900+ /* handle special roles that do not require authentication
53901+ and check ip */
53902+
53903+ FOR_EACH_ROLE_START(r)
53904+ if (!strcmp(rolename, r->rolename) &&
53905+ (r->roletype & GR_ROLE_SPECIAL)) {
53906+ found = 0;
53907+ if (r->allowed_ips != NULL) {
53908+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53909+ if ((ntohl(curr_ip) & ipp->netmask) ==
53910+ (ntohl(ipp->addr) & ipp->netmask))
53911+ found = 1;
53912+ }
53913+ } else
53914+ found = 2;
53915+ if (!found)
53916+ return 0;
53917+
53918+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53919+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53920+ *salt = NULL;
53921+ *sum = NULL;
53922+ return 1;
53923+ }
53924+ }
53925+ FOR_EACH_ROLE_END(r)
53926+
53927+ for (i = 0; i < num_sprole_pws; i++) {
53928+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53929+ *salt = acl_special_roles[i]->salt;
53930+ *sum = acl_special_roles[i]->sum;
53931+ return 1;
53932+ }
53933+ }
53934+
53935+ return 0;
53936+}
53937+
53938+static void
53939+assign_special_role(char *rolename)
53940+{
53941+ struct acl_object_label *obj;
53942+ struct acl_role_label *r;
53943+ struct acl_role_label *assigned = NULL;
53944+ struct task_struct *tsk;
53945+ struct file *filp;
53946+
53947+ FOR_EACH_ROLE_START(r)
53948+ if (!strcmp(rolename, r->rolename) &&
53949+ (r->roletype & GR_ROLE_SPECIAL)) {
53950+ assigned = r;
53951+ break;
53952+ }
53953+ FOR_EACH_ROLE_END(r)
53954+
53955+ if (!assigned)
53956+ return;
53957+
53958+ read_lock(&tasklist_lock);
53959+ read_lock(&grsec_exec_file_lock);
53960+
53961+ tsk = current->real_parent;
53962+ if (tsk == NULL)
53963+ goto out_unlock;
53964+
53965+ filp = tsk->exec_file;
53966+ if (filp == NULL)
53967+ goto out_unlock;
53968+
53969+ tsk->is_writable = 0;
53970+
53971+ tsk->acl_sp_role = 1;
53972+ tsk->acl_role_id = ++acl_sp_role_value;
53973+ tsk->role = assigned;
53974+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53975+
53976+ /* ignore additional mmap checks for processes that are writable
53977+ by the default ACL */
53978+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53979+ if (unlikely(obj->mode & GR_WRITE))
53980+ tsk->is_writable = 1;
53981+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53982+ if (unlikely(obj->mode & GR_WRITE))
53983+ tsk->is_writable = 1;
53984+
53985+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53986+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53987+#endif
53988+
53989+out_unlock:
53990+ read_unlock(&grsec_exec_file_lock);
53991+ read_unlock(&tasklist_lock);
53992+ return;
53993+}
53994+
53995+int gr_check_secure_terminal(struct task_struct *task)
53996+{
53997+ struct task_struct *p, *p2, *p3;
53998+ struct files_struct *files;
53999+ struct fdtable *fdt;
54000+ struct file *our_file = NULL, *file;
54001+ int i;
54002+
54003+ if (task->signal->tty == NULL)
54004+ return 1;
54005+
54006+ files = get_files_struct(task);
54007+ if (files != NULL) {
54008+ rcu_read_lock();
54009+ fdt = files_fdtable(files);
54010+ for (i=0; i < fdt->max_fds; i++) {
54011+ file = fcheck_files(files, i);
54012+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54013+ get_file(file);
54014+ our_file = file;
54015+ }
54016+ }
54017+ rcu_read_unlock();
54018+ put_files_struct(files);
54019+ }
54020+
54021+ if (our_file == NULL)
54022+ return 1;
54023+
54024+ read_lock(&tasklist_lock);
54025+ do_each_thread(p2, p) {
54026+ files = get_files_struct(p);
54027+ if (files == NULL ||
54028+ (p->signal && p->signal->tty == task->signal->tty)) {
54029+ if (files != NULL)
54030+ put_files_struct(files);
54031+ continue;
54032+ }
54033+ rcu_read_lock();
54034+ fdt = files_fdtable(files);
54035+ for (i=0; i < fdt->max_fds; i++) {
54036+ file = fcheck_files(files, i);
54037+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54038+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54039+ p3 = task;
54040+ while (p3->pid > 0) {
54041+ if (p3 == p)
54042+ break;
54043+ p3 = p3->real_parent;
54044+ }
54045+ if (p3 == p)
54046+ break;
54047+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54048+ gr_handle_alertkill(p);
54049+ rcu_read_unlock();
54050+ put_files_struct(files);
54051+ read_unlock(&tasklist_lock);
54052+ fput(our_file);
54053+ return 0;
54054+ }
54055+ }
54056+ rcu_read_unlock();
54057+ put_files_struct(files);
54058+ } while_each_thread(p2, p);
54059+ read_unlock(&tasklist_lock);
54060+
54061+ fput(our_file);
54062+ return 1;
54063+}
54064+
54065+static int gr_rbac_disable(void *unused)
54066+{
54067+ pax_open_kernel();
54068+ gr_status &= ~GR_READY;
54069+ pax_close_kernel();
54070+
54071+ return 0;
54072+}
54073+
54074+ssize_t
54075+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54076+{
54077+ struct gr_arg_wrapper uwrap;
54078+ unsigned char *sprole_salt = NULL;
54079+ unsigned char *sprole_sum = NULL;
54080+ int error = sizeof (struct gr_arg_wrapper);
54081+ int error2 = 0;
54082+
54083+ mutex_lock(&gr_dev_mutex);
54084+
54085+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54086+ error = -EPERM;
54087+ goto out;
54088+ }
54089+
54090+ if (count != sizeof (struct gr_arg_wrapper)) {
54091+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54092+ error = -EINVAL;
54093+ goto out;
54094+ }
54095+
54096+
54097+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54098+ gr_auth_expires = 0;
54099+ gr_auth_attempts = 0;
54100+ }
54101+
54102+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54103+ error = -EFAULT;
54104+ goto out;
54105+ }
54106+
54107+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54108+ error = -EINVAL;
54109+ goto out;
54110+ }
54111+
54112+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54113+ error = -EFAULT;
54114+ goto out;
54115+ }
54116+
54117+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54118+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54119+ time_after(gr_auth_expires, get_seconds())) {
54120+ error = -EBUSY;
54121+ goto out;
54122+ }
54123+
54124+ /* if non-root trying to do anything other than use a special role,
54125+ do not attempt authentication, do not count towards authentication
54126+ locking
54127+ */
54128+
54129+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54130+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54131+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54132+ error = -EPERM;
54133+ goto out;
54134+ }
54135+
54136+ /* ensure pw and special role name are null terminated */
54137+
54138+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54139+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54140+
54141+ /* Okay.
54142+ * We have our enough of the argument structure..(we have yet
54143+ * to copy_from_user the tables themselves) . Copy the tables
54144+ * only if we need them, i.e. for loading operations. */
54145+
54146+ switch (gr_usermode->mode) {
54147+ case GR_STATUS:
54148+ if (gr_status & GR_READY) {
54149+ error = 1;
54150+ if (!gr_check_secure_terminal(current))
54151+ error = 3;
54152+ } else
54153+ error = 2;
54154+ goto out;
54155+ case GR_SHUTDOWN:
54156+ if ((gr_status & GR_READY)
54157+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54158+ stop_machine(gr_rbac_disable, NULL, NULL);
54159+ free_variables();
54160+ memset(gr_usermode, 0, sizeof (struct gr_arg));
54161+ memset(gr_system_salt, 0, GR_SALT_LEN);
54162+ memset(gr_system_sum, 0, GR_SHA_LEN);
54163+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54164+ } else if (gr_status & GR_READY) {
54165+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54166+ error = -EPERM;
54167+ } else {
54168+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54169+ error = -EAGAIN;
54170+ }
54171+ break;
54172+ case GR_ENABLE:
54173+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54174+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54175+ else {
54176+ if (gr_status & GR_READY)
54177+ error = -EAGAIN;
54178+ else
54179+ error = error2;
54180+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54181+ }
54182+ break;
54183+ case GR_RELOAD:
54184+ if (!(gr_status & GR_READY)) {
54185+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54186+ error = -EAGAIN;
54187+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54188+ stop_machine(gr_rbac_disable, NULL, NULL);
54189+ free_variables();
54190+ error2 = gracl_init(gr_usermode);
54191+ if (!error2)
54192+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54193+ else {
54194+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54195+ error = error2;
54196+ }
54197+ } else {
54198+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54199+ error = -EPERM;
54200+ }
54201+ break;
54202+ case GR_SEGVMOD:
54203+ if (unlikely(!(gr_status & GR_READY))) {
54204+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54205+ error = -EAGAIN;
54206+ break;
54207+ }
54208+
54209+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54210+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54211+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54212+ struct acl_subject_label *segvacl;
54213+ segvacl =
54214+ lookup_acl_subj_label(gr_usermode->segv_inode,
54215+ gr_usermode->segv_device,
54216+ current->role);
54217+ if (segvacl) {
54218+ segvacl->crashes = 0;
54219+ segvacl->expires = 0;
54220+ }
54221+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54222+ gr_remove_uid(gr_usermode->segv_uid);
54223+ }
54224+ } else {
54225+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54226+ error = -EPERM;
54227+ }
54228+ break;
54229+ case GR_SPROLE:
54230+ case GR_SPROLEPAM:
54231+ if (unlikely(!(gr_status & GR_READY))) {
54232+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54233+ error = -EAGAIN;
54234+ break;
54235+ }
54236+
54237+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54238+ current->role->expires = 0;
54239+ current->role->auth_attempts = 0;
54240+ }
54241+
54242+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54243+ time_after(current->role->expires, get_seconds())) {
54244+ error = -EBUSY;
54245+ goto out;
54246+ }
54247+
54248+ if (lookup_special_role_auth
54249+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54250+ && ((!sprole_salt && !sprole_sum)
54251+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54252+ char *p = "";
54253+ assign_special_role(gr_usermode->sp_role);
54254+ read_lock(&tasklist_lock);
54255+ if (current->real_parent)
54256+ p = current->real_parent->role->rolename;
54257+ read_unlock(&tasklist_lock);
54258+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54259+ p, acl_sp_role_value);
54260+ } else {
54261+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54262+ error = -EPERM;
54263+ if(!(current->role->auth_attempts++))
54264+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54265+
54266+ goto out;
54267+ }
54268+ break;
54269+ case GR_UNSPROLE:
54270+ if (unlikely(!(gr_status & GR_READY))) {
54271+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54272+ error = -EAGAIN;
54273+ break;
54274+ }
54275+
54276+ if (current->role->roletype & GR_ROLE_SPECIAL) {
54277+ char *p = "";
54278+ int i = 0;
54279+
54280+ read_lock(&tasklist_lock);
54281+ if (current->real_parent) {
54282+ p = current->real_parent->role->rolename;
54283+ i = current->real_parent->acl_role_id;
54284+ }
54285+ read_unlock(&tasklist_lock);
54286+
54287+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54288+ gr_set_acls(1);
54289+ } else {
54290+ error = -EPERM;
54291+ goto out;
54292+ }
54293+ break;
54294+ default:
54295+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54296+ error = -EINVAL;
54297+ break;
54298+ }
54299+
54300+ if (error != -EPERM)
54301+ goto out;
54302+
54303+ if(!(gr_auth_attempts++))
54304+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54305+
54306+ out:
54307+ mutex_unlock(&gr_dev_mutex);
54308+ return error;
54309+}
54310+
54311+/* must be called with
54312+ rcu_read_lock();
54313+ read_lock(&tasklist_lock);
54314+ read_lock(&grsec_exec_file_lock);
54315+*/
54316+int gr_apply_subject_to_task(struct task_struct *task)
54317+{
54318+ struct acl_object_label *obj;
54319+ char *tmpname;
54320+ struct acl_subject_label *tmpsubj;
54321+ struct file *filp;
54322+ struct name_entry *nmatch;
54323+
54324+ filp = task->exec_file;
54325+ if (filp == NULL)
54326+ return 0;
54327+
54328+ /* the following is to apply the correct subject
54329+ on binaries running when the RBAC system
54330+ is enabled, when the binaries have been
54331+ replaced or deleted since their execution
54332+ -----
54333+ when the RBAC system starts, the inode/dev
54334+ from exec_file will be one the RBAC system
54335+ is unaware of. It only knows the inode/dev
54336+ of the present file on disk, or the absence
54337+ of it.
54338+ */
54339+ preempt_disable();
54340+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54341+
54342+ nmatch = lookup_name_entry(tmpname);
54343+ preempt_enable();
54344+ tmpsubj = NULL;
54345+ if (nmatch) {
54346+ if (nmatch->deleted)
54347+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54348+ else
54349+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54350+ if (tmpsubj != NULL)
54351+ task->acl = tmpsubj;
54352+ }
54353+ if (tmpsubj == NULL)
54354+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54355+ task->role);
54356+ if (task->acl) {
54357+ task->is_writable = 0;
54358+ /* ignore additional mmap checks for processes that are writable
54359+ by the default ACL */
54360+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54361+ if (unlikely(obj->mode & GR_WRITE))
54362+ task->is_writable = 1;
54363+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54364+ if (unlikely(obj->mode & GR_WRITE))
54365+ task->is_writable = 1;
54366+
54367+ gr_set_proc_res(task);
54368+
54369+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54370+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54371+#endif
54372+ } else {
54373+ return 1;
54374+ }
54375+
54376+ return 0;
54377+}
54378+
54379+int
54380+gr_set_acls(const int type)
54381+{
54382+ struct task_struct *task, *task2;
54383+ struct acl_role_label *role = current->role;
54384+ __u16 acl_role_id = current->acl_role_id;
54385+ const struct cred *cred;
54386+ int ret;
54387+
54388+ rcu_read_lock();
54389+ read_lock(&tasklist_lock);
54390+ read_lock(&grsec_exec_file_lock);
54391+ do_each_thread(task2, task) {
54392+ /* check to see if we're called from the exit handler,
54393+ if so, only replace ACLs that have inherited the admin
54394+ ACL */
54395+
54396+ if (type && (task->role != role ||
54397+ task->acl_role_id != acl_role_id))
54398+ continue;
54399+
54400+ task->acl_role_id = 0;
54401+ task->acl_sp_role = 0;
54402+
54403+ if (task->exec_file) {
54404+ cred = __task_cred(task);
54405+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54406+ ret = gr_apply_subject_to_task(task);
54407+ if (ret) {
54408+ read_unlock(&grsec_exec_file_lock);
54409+ read_unlock(&tasklist_lock);
54410+ rcu_read_unlock();
54411+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54412+ return ret;
54413+ }
54414+ } else {
54415+ // it's a kernel process
54416+ task->role = kernel_role;
54417+ task->acl = kernel_role->root_label;
54418+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54419+ task->acl->mode &= ~GR_PROCFIND;
54420+#endif
54421+ }
54422+ } while_each_thread(task2, task);
54423+ read_unlock(&grsec_exec_file_lock);
54424+ read_unlock(&tasklist_lock);
54425+ rcu_read_unlock();
54426+
54427+ return 0;
54428+}
54429+
54430+void
54431+gr_learn_resource(const struct task_struct *task,
54432+ const int res, const unsigned long wanted, const int gt)
54433+{
54434+ struct acl_subject_label *acl;
54435+ const struct cred *cred;
54436+
54437+ if (unlikely((gr_status & GR_READY) &&
54438+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54439+ goto skip_reslog;
54440+
54441+#ifdef CONFIG_GRKERNSEC_RESLOG
54442+ gr_log_resource(task, res, wanted, gt);
54443+#endif
54444+ skip_reslog:
54445+
54446+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54447+ return;
54448+
54449+ acl = task->acl;
54450+
54451+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54452+ !(acl->resmask & (1 << (unsigned short) res))))
54453+ return;
54454+
54455+ if (wanted >= acl->res[res].rlim_cur) {
54456+ unsigned long res_add;
54457+
54458+ res_add = wanted;
54459+ switch (res) {
54460+ case RLIMIT_CPU:
54461+ res_add += GR_RLIM_CPU_BUMP;
54462+ break;
54463+ case RLIMIT_FSIZE:
54464+ res_add += GR_RLIM_FSIZE_BUMP;
54465+ break;
54466+ case RLIMIT_DATA:
54467+ res_add += GR_RLIM_DATA_BUMP;
54468+ break;
54469+ case RLIMIT_STACK:
54470+ res_add += GR_RLIM_STACK_BUMP;
54471+ break;
54472+ case RLIMIT_CORE:
54473+ res_add += GR_RLIM_CORE_BUMP;
54474+ break;
54475+ case RLIMIT_RSS:
54476+ res_add += GR_RLIM_RSS_BUMP;
54477+ break;
54478+ case RLIMIT_NPROC:
54479+ res_add += GR_RLIM_NPROC_BUMP;
54480+ break;
54481+ case RLIMIT_NOFILE:
54482+ res_add += GR_RLIM_NOFILE_BUMP;
54483+ break;
54484+ case RLIMIT_MEMLOCK:
54485+ res_add += GR_RLIM_MEMLOCK_BUMP;
54486+ break;
54487+ case RLIMIT_AS:
54488+ res_add += GR_RLIM_AS_BUMP;
54489+ break;
54490+ case RLIMIT_LOCKS:
54491+ res_add += GR_RLIM_LOCKS_BUMP;
54492+ break;
54493+ case RLIMIT_SIGPENDING:
54494+ res_add += GR_RLIM_SIGPENDING_BUMP;
54495+ break;
54496+ case RLIMIT_MSGQUEUE:
54497+ res_add += GR_RLIM_MSGQUEUE_BUMP;
54498+ break;
54499+ case RLIMIT_NICE:
54500+ res_add += GR_RLIM_NICE_BUMP;
54501+ break;
54502+ case RLIMIT_RTPRIO:
54503+ res_add += GR_RLIM_RTPRIO_BUMP;
54504+ break;
54505+ case RLIMIT_RTTIME:
54506+ res_add += GR_RLIM_RTTIME_BUMP;
54507+ break;
54508+ }
54509+
54510+ acl->res[res].rlim_cur = res_add;
54511+
54512+ if (wanted > acl->res[res].rlim_max)
54513+ acl->res[res].rlim_max = res_add;
54514+
54515+ /* only log the subject filename, since resource logging is supported for
54516+ single-subject learning only */
54517+ rcu_read_lock();
54518+ cred = __task_cred(task);
54519+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54520+ task->role->roletype, cred->uid, cred->gid, acl->filename,
54521+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54522+ "", (unsigned long) res, &task->signal->saved_ip);
54523+ rcu_read_unlock();
54524+ }
54525+
54526+ return;
54527+}
54528+
54529+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54530+void
54531+pax_set_initial_flags(struct linux_binprm *bprm)
54532+{
54533+ struct task_struct *task = current;
54534+ struct acl_subject_label *proc;
54535+ unsigned long flags;
54536+
54537+ if (unlikely(!(gr_status & GR_READY)))
54538+ return;
54539+
54540+ flags = pax_get_flags(task);
54541+
54542+ proc = task->acl;
54543+
54544+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54545+ flags &= ~MF_PAX_PAGEEXEC;
54546+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54547+ flags &= ~MF_PAX_SEGMEXEC;
54548+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54549+ flags &= ~MF_PAX_RANDMMAP;
54550+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54551+ flags &= ~MF_PAX_EMUTRAMP;
54552+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54553+ flags &= ~MF_PAX_MPROTECT;
54554+
54555+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54556+ flags |= MF_PAX_PAGEEXEC;
54557+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54558+ flags |= MF_PAX_SEGMEXEC;
54559+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54560+ flags |= MF_PAX_RANDMMAP;
54561+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54562+ flags |= MF_PAX_EMUTRAMP;
54563+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54564+ flags |= MF_PAX_MPROTECT;
54565+
54566+ pax_set_flags(task, flags);
54567+
54568+ return;
54569+}
54570+#endif
54571+
54572+int
54573+gr_handle_proc_ptrace(struct task_struct *task)
54574+{
54575+ struct file *filp;
54576+ struct task_struct *tmp = task;
54577+ struct task_struct *curtemp = current;
54578+ __u32 retmode;
54579+
54580+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54581+ if (unlikely(!(gr_status & GR_READY)))
54582+ return 0;
54583+#endif
54584+
54585+ read_lock(&tasklist_lock);
54586+ read_lock(&grsec_exec_file_lock);
54587+ filp = task->exec_file;
54588+
54589+ while (tmp->pid > 0) {
54590+ if (tmp == curtemp)
54591+ break;
54592+ tmp = tmp->real_parent;
54593+ }
54594+
54595+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54596+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54597+ read_unlock(&grsec_exec_file_lock);
54598+ read_unlock(&tasklist_lock);
54599+ return 1;
54600+ }
54601+
54602+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54603+ if (!(gr_status & GR_READY)) {
54604+ read_unlock(&grsec_exec_file_lock);
54605+ read_unlock(&tasklist_lock);
54606+ return 0;
54607+ }
54608+#endif
54609+
54610+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54611+ read_unlock(&grsec_exec_file_lock);
54612+ read_unlock(&tasklist_lock);
54613+
54614+ if (retmode & GR_NOPTRACE)
54615+ return 1;
54616+
54617+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54618+ && (current->acl != task->acl || (current->acl != current->role->root_label
54619+ && current->pid != task->pid)))
54620+ return 1;
54621+
54622+ return 0;
54623+}
54624+
54625+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54626+{
54627+ if (unlikely(!(gr_status & GR_READY)))
54628+ return;
54629+
54630+ if (!(current->role->roletype & GR_ROLE_GOD))
54631+ return;
54632+
54633+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54634+ p->role->rolename, gr_task_roletype_to_char(p),
54635+ p->acl->filename);
54636+}
54637+
54638+int
54639+gr_handle_ptrace(struct task_struct *task, const long request)
54640+{
54641+ struct task_struct *tmp = task;
54642+ struct task_struct *curtemp = current;
54643+ __u32 retmode;
54644+
54645+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54646+ if (unlikely(!(gr_status & GR_READY)))
54647+ return 0;
54648+#endif
54649+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
54650+ read_lock(&tasklist_lock);
54651+ while (tmp->pid > 0) {
54652+ if (tmp == curtemp)
54653+ break;
54654+ tmp = tmp->real_parent;
54655+ }
54656+
54657+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54658+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54659+ read_unlock(&tasklist_lock);
54660+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54661+ return 1;
54662+ }
54663+ read_unlock(&tasklist_lock);
54664+ }
54665+
54666+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54667+ if (!(gr_status & GR_READY))
54668+ return 0;
54669+#endif
54670+
54671+ read_lock(&grsec_exec_file_lock);
54672+ if (unlikely(!task->exec_file)) {
54673+ read_unlock(&grsec_exec_file_lock);
54674+ return 0;
54675+ }
54676+
54677+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54678+ read_unlock(&grsec_exec_file_lock);
54679+
54680+ if (retmode & GR_NOPTRACE) {
54681+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54682+ return 1;
54683+ }
54684+
54685+ if (retmode & GR_PTRACERD) {
54686+ switch (request) {
54687+ case PTRACE_SEIZE:
54688+ case PTRACE_POKETEXT:
54689+ case PTRACE_POKEDATA:
54690+ case PTRACE_POKEUSR:
54691+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54692+ case PTRACE_SETREGS:
54693+ case PTRACE_SETFPREGS:
54694+#endif
54695+#ifdef CONFIG_X86
54696+ case PTRACE_SETFPXREGS:
54697+#endif
54698+#ifdef CONFIG_ALTIVEC
54699+ case PTRACE_SETVRREGS:
54700+#endif
54701+ return 1;
54702+ default:
54703+ return 0;
54704+ }
54705+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
54706+ !(current->role->roletype & GR_ROLE_GOD) &&
54707+ (current->acl != task->acl)) {
54708+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54709+ return 1;
54710+ }
54711+
54712+ return 0;
54713+}
54714+
54715+static int is_writable_mmap(const struct file *filp)
54716+{
54717+ struct task_struct *task = current;
54718+ struct acl_object_label *obj, *obj2;
54719+
54720+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54721+ !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))) {
54722+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54723+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54724+ task->role->root_label);
54725+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54726+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54727+ return 1;
54728+ }
54729+ }
54730+ return 0;
54731+}
54732+
54733+int
54734+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54735+{
54736+ __u32 mode;
54737+
54738+ if (unlikely(!file || !(prot & PROT_EXEC)))
54739+ return 1;
54740+
54741+ if (is_writable_mmap(file))
54742+ return 0;
54743+
54744+ mode =
54745+ gr_search_file(file->f_path.dentry,
54746+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54747+ file->f_path.mnt);
54748+
54749+ if (!gr_tpe_allow(file))
54750+ return 0;
54751+
54752+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54753+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54754+ return 0;
54755+ } else if (unlikely(!(mode & GR_EXEC))) {
54756+ return 0;
54757+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54758+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54759+ return 1;
54760+ }
54761+
54762+ return 1;
54763+}
54764+
54765+int
54766+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54767+{
54768+ __u32 mode;
54769+
54770+ if (unlikely(!file || !(prot & PROT_EXEC)))
54771+ return 1;
54772+
54773+ if (is_writable_mmap(file))
54774+ return 0;
54775+
54776+ mode =
54777+ gr_search_file(file->f_path.dentry,
54778+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54779+ file->f_path.mnt);
54780+
54781+ if (!gr_tpe_allow(file))
54782+ return 0;
54783+
54784+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54785+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54786+ return 0;
54787+ } else if (unlikely(!(mode & GR_EXEC))) {
54788+ return 0;
54789+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54790+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54791+ return 1;
54792+ }
54793+
54794+ return 1;
54795+}
54796+
54797+void
54798+gr_acl_handle_psacct(struct task_struct *task, const long code)
54799+{
54800+ unsigned long runtime;
54801+ unsigned long cputime;
54802+ unsigned int wday, cday;
54803+ __u8 whr, chr;
54804+ __u8 wmin, cmin;
54805+ __u8 wsec, csec;
54806+ struct timespec timeval;
54807+
54808+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54809+ !(task->acl->mode & GR_PROCACCT)))
54810+ return;
54811+
54812+ do_posix_clock_monotonic_gettime(&timeval);
54813+ runtime = timeval.tv_sec - task->start_time.tv_sec;
54814+ wday = runtime / (3600 * 24);
54815+ runtime -= wday * (3600 * 24);
54816+ whr = runtime / 3600;
54817+ runtime -= whr * 3600;
54818+ wmin = runtime / 60;
54819+ runtime -= wmin * 60;
54820+ wsec = runtime;
54821+
54822+ cputime = (task->utime + task->stime) / HZ;
54823+ cday = cputime / (3600 * 24);
54824+ cputime -= cday * (3600 * 24);
54825+ chr = cputime / 3600;
54826+ cputime -= chr * 3600;
54827+ cmin = cputime / 60;
54828+ cputime -= cmin * 60;
54829+ csec = cputime;
54830+
54831+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54832+
54833+ return;
54834+}
54835+
54836+void gr_set_kernel_label(struct task_struct *task)
54837+{
54838+ if (gr_status & GR_READY) {
54839+ task->role = kernel_role;
54840+ task->acl = kernel_role->root_label;
54841+ }
54842+ return;
54843+}
54844+
54845+#ifdef CONFIG_TASKSTATS
54846+int gr_is_taskstats_denied(int pid)
54847+{
54848+ struct task_struct *task;
54849+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54850+ const struct cred *cred;
54851+#endif
54852+ int ret = 0;
54853+
54854+ /* restrict taskstats viewing to un-chrooted root users
54855+ who have the 'view' subject flag if the RBAC system is enabled
54856+ */
54857+
54858+ rcu_read_lock();
54859+ read_lock(&tasklist_lock);
54860+ task = find_task_by_vpid(pid);
54861+ if (task) {
54862+#ifdef CONFIG_GRKERNSEC_CHROOT
54863+ if (proc_is_chrooted(task))
54864+ ret = -EACCES;
54865+#endif
54866+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54867+ cred = __task_cred(task);
54868+#ifdef CONFIG_GRKERNSEC_PROC_USER
54869+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
54870+ ret = -EACCES;
54871+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54872+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID)) && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54873+ ret = -EACCES;
54874+#endif
54875+#endif
54876+ if (gr_status & GR_READY) {
54877+ if (!(task->acl->mode & GR_VIEW))
54878+ ret = -EACCES;
54879+ }
54880+ } else
54881+ ret = -ENOENT;
54882+
54883+ read_unlock(&tasklist_lock);
54884+ rcu_read_unlock();
54885+
54886+ return ret;
54887+}
54888+#endif
54889+
54890+/* AUXV entries are filled via a descendant of search_binary_handler
54891+ after we've already applied the subject for the target
54892+*/
54893+int gr_acl_enable_at_secure(void)
54894+{
54895+ if (unlikely(!(gr_status & GR_READY)))
54896+ return 0;
54897+
54898+ if (current->acl->mode & GR_ATSECURE)
54899+ return 1;
54900+
54901+ return 0;
54902+}
54903+
54904+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54905+{
54906+ struct task_struct *task = current;
54907+ struct dentry *dentry = file->f_path.dentry;
54908+ struct vfsmount *mnt = file->f_path.mnt;
54909+ struct acl_object_label *obj, *tmp;
54910+ struct acl_subject_label *subj;
54911+ unsigned int bufsize;
54912+ int is_not_root;
54913+ char *path;
54914+ dev_t dev = __get_dev(dentry);
54915+
54916+ if (unlikely(!(gr_status & GR_READY)))
54917+ return 1;
54918+
54919+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54920+ return 1;
54921+
54922+ /* ignore Eric Biederman */
54923+ if (IS_PRIVATE(dentry->d_inode))
54924+ return 1;
54925+
54926+ subj = task->acl;
54927+ read_lock(&gr_inode_lock);
54928+ do {
54929+ obj = lookup_acl_obj_label(ino, dev, subj);
54930+ if (obj != NULL) {
54931+ read_unlock(&gr_inode_lock);
54932+ return (obj->mode & GR_FIND) ? 1 : 0;
54933+ }
54934+ } while ((subj = subj->parent_subject));
54935+ read_unlock(&gr_inode_lock);
54936+
54937+ /* this is purely an optimization since we're looking for an object
54938+ for the directory we're doing a readdir on
54939+ if it's possible for any globbed object to match the entry we're
54940+ filling into the directory, then the object we find here will be
54941+ an anchor point with attached globbed objects
54942+ */
54943+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54944+ if (obj->globbed == NULL)
54945+ return (obj->mode & GR_FIND) ? 1 : 0;
54946+
54947+ is_not_root = ((obj->filename[0] == '/') &&
54948+ (obj->filename[1] == '\0')) ? 0 : 1;
54949+ bufsize = PAGE_SIZE - namelen - is_not_root;
54950+
54951+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
54952+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54953+ return 1;
54954+
54955+ preempt_disable();
54956+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54957+ bufsize);
54958+
54959+ bufsize = strlen(path);
54960+
54961+ /* if base is "/", don't append an additional slash */
54962+ if (is_not_root)
54963+ *(path + bufsize) = '/';
54964+ memcpy(path + bufsize + is_not_root, name, namelen);
54965+ *(path + bufsize + namelen + is_not_root) = '\0';
54966+
54967+ tmp = obj->globbed;
54968+ while (tmp) {
54969+ if (!glob_match(tmp->filename, path)) {
54970+ preempt_enable();
54971+ return (tmp->mode & GR_FIND) ? 1 : 0;
54972+ }
54973+ tmp = tmp->next;
54974+ }
54975+ preempt_enable();
54976+ return (obj->mode & GR_FIND) ? 1 : 0;
54977+}
54978+
54979+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54980+EXPORT_SYMBOL(gr_acl_is_enabled);
54981+#endif
54982+EXPORT_SYMBOL(gr_learn_resource);
54983+EXPORT_SYMBOL(gr_set_kernel_label);
54984+#ifdef CONFIG_SECURITY
54985+EXPORT_SYMBOL(gr_check_user_change);
54986+EXPORT_SYMBOL(gr_check_group_change);
54987+#endif
54988+
54989diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54990new file mode 100644
54991index 0000000..34fefda
54992--- /dev/null
54993+++ b/grsecurity/gracl_alloc.c
54994@@ -0,0 +1,105 @@
54995+#include <linux/kernel.h>
54996+#include <linux/mm.h>
54997+#include <linux/slab.h>
54998+#include <linux/vmalloc.h>
54999+#include <linux/gracl.h>
55000+#include <linux/grsecurity.h>
55001+
55002+static unsigned long alloc_stack_next = 1;
55003+static unsigned long alloc_stack_size = 1;
55004+static void **alloc_stack;
55005+
55006+static __inline__ int
55007+alloc_pop(void)
55008+{
55009+ if (alloc_stack_next == 1)
55010+ return 0;
55011+
55012+ kfree(alloc_stack[alloc_stack_next - 2]);
55013+
55014+ alloc_stack_next--;
55015+
55016+ return 1;
55017+}
55018+
55019+static __inline__ int
55020+alloc_push(void *buf)
55021+{
55022+ if (alloc_stack_next >= alloc_stack_size)
55023+ return 1;
55024+
55025+ alloc_stack[alloc_stack_next - 1] = buf;
55026+
55027+ alloc_stack_next++;
55028+
55029+ return 0;
55030+}
55031+
55032+void *
55033+acl_alloc(unsigned long len)
55034+{
55035+ void *ret = NULL;
55036+
55037+ if (!len || len > PAGE_SIZE)
55038+ goto out;
55039+
55040+ ret = kmalloc(len, GFP_KERNEL);
55041+
55042+ if (ret) {
55043+ if (alloc_push(ret)) {
55044+ kfree(ret);
55045+ ret = NULL;
55046+ }
55047+ }
55048+
55049+out:
55050+ return ret;
55051+}
55052+
55053+void *
55054+acl_alloc_num(unsigned long num, unsigned long len)
55055+{
55056+ if (!len || (num > (PAGE_SIZE / len)))
55057+ return NULL;
55058+
55059+ return acl_alloc(num * len);
55060+}
55061+
55062+void
55063+acl_free_all(void)
55064+{
55065+ if (gr_acl_is_enabled() || !alloc_stack)
55066+ return;
55067+
55068+ while (alloc_pop()) ;
55069+
55070+ if (alloc_stack) {
55071+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55072+ kfree(alloc_stack);
55073+ else
55074+ vfree(alloc_stack);
55075+ }
55076+
55077+ alloc_stack = NULL;
55078+ alloc_stack_size = 1;
55079+ alloc_stack_next = 1;
55080+
55081+ return;
55082+}
55083+
55084+int
55085+acl_alloc_stack_init(unsigned long size)
55086+{
55087+ if ((size * sizeof (void *)) <= PAGE_SIZE)
55088+ alloc_stack =
55089+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55090+ else
55091+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
55092+
55093+ alloc_stack_size = size;
55094+
55095+ if (!alloc_stack)
55096+ return 0;
55097+ else
55098+ return 1;
55099+}
55100diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55101new file mode 100644
55102index 0000000..6d21049
55103--- /dev/null
55104+++ b/grsecurity/gracl_cap.c
55105@@ -0,0 +1,110 @@
55106+#include <linux/kernel.h>
55107+#include <linux/module.h>
55108+#include <linux/sched.h>
55109+#include <linux/gracl.h>
55110+#include <linux/grsecurity.h>
55111+#include <linux/grinternal.h>
55112+
55113+extern const char *captab_log[];
55114+extern int captab_log_entries;
55115+
55116+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55117+{
55118+ struct acl_subject_label *curracl;
55119+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55120+ kernel_cap_t cap_audit = __cap_empty_set;
55121+
55122+ if (!gr_acl_is_enabled())
55123+ return 1;
55124+
55125+ curracl = task->acl;
55126+
55127+ cap_drop = curracl->cap_lower;
55128+ cap_mask = curracl->cap_mask;
55129+ cap_audit = curracl->cap_invert_audit;
55130+
55131+ while ((curracl = curracl->parent_subject)) {
55132+ /* if the cap isn't specified in the current computed mask but is specified in the
55133+ current level subject, and is lowered in the current level subject, then add
55134+ it to the set of dropped capabilities
55135+ otherwise, add the current level subject's mask to the current computed mask
55136+ */
55137+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55138+ cap_raise(cap_mask, cap);
55139+ if (cap_raised(curracl->cap_lower, cap))
55140+ cap_raise(cap_drop, cap);
55141+ if (cap_raised(curracl->cap_invert_audit, cap))
55142+ cap_raise(cap_audit, cap);
55143+ }
55144+ }
55145+
55146+ if (!cap_raised(cap_drop, cap)) {
55147+ if (cap_raised(cap_audit, cap))
55148+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55149+ return 1;
55150+ }
55151+
55152+ curracl = task->acl;
55153+
55154+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55155+ && cap_raised(cred->cap_effective, cap)) {
55156+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55157+ task->role->roletype, cred->uid,
55158+ cred->gid, task->exec_file ?
55159+ gr_to_filename(task->exec_file->f_path.dentry,
55160+ task->exec_file->f_path.mnt) : curracl->filename,
55161+ curracl->filename, 0UL,
55162+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55163+ return 1;
55164+ }
55165+
55166+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55167+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55168+
55169+ return 0;
55170+}
55171+
55172+int
55173+gr_acl_is_capable(const int cap)
55174+{
55175+ return gr_task_acl_is_capable(current, current_cred(), cap);
55176+}
55177+
55178+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55179+{
55180+ struct acl_subject_label *curracl;
55181+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55182+
55183+ if (!gr_acl_is_enabled())
55184+ return 1;
55185+
55186+ curracl = task->acl;
55187+
55188+ cap_drop = curracl->cap_lower;
55189+ cap_mask = curracl->cap_mask;
55190+
55191+ while ((curracl = curracl->parent_subject)) {
55192+ /* if the cap isn't specified in the current computed mask but is specified in the
55193+ current level subject, and is lowered in the current level subject, then add
55194+ it to the set of dropped capabilities
55195+ otherwise, add the current level subject's mask to the current computed mask
55196+ */
55197+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55198+ cap_raise(cap_mask, cap);
55199+ if (cap_raised(curracl->cap_lower, cap))
55200+ cap_raise(cap_drop, cap);
55201+ }
55202+ }
55203+
55204+ if (!cap_raised(cap_drop, cap))
55205+ return 1;
55206+
55207+ return 0;
55208+}
55209+
55210+int
55211+gr_acl_is_capable_nolog(const int cap)
55212+{
55213+ return gr_task_acl_is_capable_nolog(current, cap);
55214+}
55215+
55216diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55217new file mode 100644
55218index 0000000..88d0e87
55219--- /dev/null
55220+++ b/grsecurity/gracl_fs.c
55221@@ -0,0 +1,435 @@
55222+#include <linux/kernel.h>
55223+#include <linux/sched.h>
55224+#include <linux/types.h>
55225+#include <linux/fs.h>
55226+#include <linux/file.h>
55227+#include <linux/stat.h>
55228+#include <linux/grsecurity.h>
55229+#include <linux/grinternal.h>
55230+#include <linux/gracl.h>
55231+
55232+umode_t
55233+gr_acl_umask(void)
55234+{
55235+ if (unlikely(!gr_acl_is_enabled()))
55236+ return 0;
55237+
55238+ return current->role->umask;
55239+}
55240+
55241+__u32
55242+gr_acl_handle_hidden_file(const struct dentry * dentry,
55243+ const struct vfsmount * mnt)
55244+{
55245+ __u32 mode;
55246+
55247+ if (unlikely(!dentry->d_inode))
55248+ return GR_FIND;
55249+
55250+ mode =
55251+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55252+
55253+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55254+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55255+ return mode;
55256+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55257+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55258+ return 0;
55259+ } else if (unlikely(!(mode & GR_FIND)))
55260+ return 0;
55261+
55262+ return GR_FIND;
55263+}
55264+
55265+__u32
55266+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55267+ int acc_mode)
55268+{
55269+ __u32 reqmode = GR_FIND;
55270+ __u32 mode;
55271+
55272+ if (unlikely(!dentry->d_inode))
55273+ return reqmode;
55274+
55275+ if (acc_mode & MAY_APPEND)
55276+ reqmode |= GR_APPEND;
55277+ else if (acc_mode & MAY_WRITE)
55278+ reqmode |= GR_WRITE;
55279+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55280+ reqmode |= GR_READ;
55281+
55282+ mode =
55283+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55284+ mnt);
55285+
55286+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55287+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55288+ reqmode & GR_READ ? " reading" : "",
55289+ reqmode & GR_WRITE ? " writing" : reqmode &
55290+ GR_APPEND ? " appending" : "");
55291+ return reqmode;
55292+ } else
55293+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55294+ {
55295+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55296+ reqmode & GR_READ ? " reading" : "",
55297+ reqmode & GR_WRITE ? " writing" : reqmode &
55298+ GR_APPEND ? " appending" : "");
55299+ return 0;
55300+ } else if (unlikely((mode & reqmode) != reqmode))
55301+ return 0;
55302+
55303+ return reqmode;
55304+}
55305+
55306+__u32
55307+gr_acl_handle_creat(const struct dentry * dentry,
55308+ const struct dentry * p_dentry,
55309+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55310+ const int imode)
55311+{
55312+ __u32 reqmode = GR_WRITE | GR_CREATE;
55313+ __u32 mode;
55314+
55315+ if (acc_mode & MAY_APPEND)
55316+ reqmode |= GR_APPEND;
55317+ // if a directory was required or the directory already exists, then
55318+ // don't count this open as a read
55319+ if ((acc_mode & MAY_READ) &&
55320+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55321+ reqmode |= GR_READ;
55322+ if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
55323+ reqmode |= GR_SETID;
55324+
55325+ mode =
55326+ gr_check_create(dentry, p_dentry, p_mnt,
55327+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55328+
55329+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55330+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55331+ reqmode & GR_READ ? " reading" : "",
55332+ reqmode & GR_WRITE ? " writing" : reqmode &
55333+ GR_APPEND ? " appending" : "");
55334+ return reqmode;
55335+ } else
55336+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55337+ {
55338+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55339+ reqmode & GR_READ ? " reading" : "",
55340+ reqmode & GR_WRITE ? " writing" : reqmode &
55341+ GR_APPEND ? " appending" : "");
55342+ return 0;
55343+ } else if (unlikely((mode & reqmode) != reqmode))
55344+ return 0;
55345+
55346+ return reqmode;
55347+}
55348+
55349+__u32
55350+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55351+ const int fmode)
55352+{
55353+ __u32 mode, reqmode = GR_FIND;
55354+
55355+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55356+ reqmode |= GR_EXEC;
55357+ if (fmode & S_IWOTH)
55358+ reqmode |= GR_WRITE;
55359+ if (fmode & S_IROTH)
55360+ reqmode |= GR_READ;
55361+
55362+ mode =
55363+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55364+ mnt);
55365+
55366+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55367+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55368+ reqmode & GR_READ ? " reading" : "",
55369+ reqmode & GR_WRITE ? " writing" : "",
55370+ reqmode & GR_EXEC ? " executing" : "");
55371+ return reqmode;
55372+ } else
55373+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55374+ {
55375+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55376+ reqmode & GR_READ ? " reading" : "",
55377+ reqmode & GR_WRITE ? " writing" : "",
55378+ reqmode & GR_EXEC ? " executing" : "");
55379+ return 0;
55380+ } else if (unlikely((mode & reqmode) != reqmode))
55381+ return 0;
55382+
55383+ return reqmode;
55384+}
55385+
55386+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55387+{
55388+ __u32 mode;
55389+
55390+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55391+
55392+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55393+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55394+ return mode;
55395+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55396+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55397+ return 0;
55398+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55399+ return 0;
55400+
55401+ return (reqmode);
55402+}
55403+
55404+__u32
55405+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55406+{
55407+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55408+}
55409+
55410+__u32
55411+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55412+{
55413+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55414+}
55415+
55416+__u32
55417+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55418+{
55419+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55420+}
55421+
55422+__u32
55423+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55424+{
55425+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55426+}
55427+
55428+__u32
55429+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55430+ umode_t *modeptr)
55431+{
55432+ umode_t mode;
55433+
55434+ *modeptr &= ~gr_acl_umask();
55435+ mode = *modeptr;
55436+
55437+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55438+ return 1;
55439+
55440+ if (unlikely(mode & (S_ISUID | S_ISGID))) {
55441+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55442+ GR_CHMOD_ACL_MSG);
55443+ } else {
55444+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55445+ }
55446+}
55447+
55448+__u32
55449+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55450+{
55451+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55452+}
55453+
55454+__u32
55455+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55456+{
55457+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55458+}
55459+
55460+__u32
55461+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55462+{
55463+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55464+}
55465+
55466+__u32
55467+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55468+{
55469+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55470+ GR_UNIXCONNECT_ACL_MSG);
55471+}
55472+
55473+/* hardlinks require at minimum create and link permission,
55474+ any additional privilege required is based on the
55475+ privilege of the file being linked to
55476+*/
55477+__u32
55478+gr_acl_handle_link(const struct dentry * new_dentry,
55479+ const struct dentry * parent_dentry,
55480+ const struct vfsmount * parent_mnt,
55481+ const struct dentry * old_dentry,
55482+ const struct vfsmount * old_mnt, const char *to)
55483+{
55484+ __u32 mode;
55485+ __u32 needmode = GR_CREATE | GR_LINK;
55486+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55487+
55488+ mode =
55489+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55490+ old_mnt);
55491+
55492+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55493+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55494+ return mode;
55495+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55496+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55497+ return 0;
55498+ } else if (unlikely((mode & needmode) != needmode))
55499+ return 0;
55500+
55501+ return 1;
55502+}
55503+
55504+__u32
55505+gr_acl_handle_symlink(const struct dentry * new_dentry,
55506+ const struct dentry * parent_dentry,
55507+ const struct vfsmount * parent_mnt, const char *from)
55508+{
55509+ __u32 needmode = GR_WRITE | GR_CREATE;
55510+ __u32 mode;
55511+
55512+ mode =
55513+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
55514+ GR_CREATE | GR_AUDIT_CREATE |
55515+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55516+
55517+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55518+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55519+ return mode;
55520+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55521+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55522+ return 0;
55523+ } else if (unlikely((mode & needmode) != needmode))
55524+ return 0;
55525+
55526+ return (GR_WRITE | GR_CREATE);
55527+}
55528+
55529+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)
55530+{
55531+ __u32 mode;
55532+
55533+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55534+
55535+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55536+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55537+ return mode;
55538+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55539+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55540+ return 0;
55541+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55542+ return 0;
55543+
55544+ return (reqmode);
55545+}
55546+
55547+__u32
55548+gr_acl_handle_mknod(const struct dentry * new_dentry,
55549+ const struct dentry * parent_dentry,
55550+ const struct vfsmount * parent_mnt,
55551+ const int mode)
55552+{
55553+ __u32 reqmode = GR_WRITE | GR_CREATE;
55554+ if (unlikely(mode & (S_ISUID | S_ISGID)))
55555+ reqmode |= GR_SETID;
55556+
55557+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55558+ reqmode, GR_MKNOD_ACL_MSG);
55559+}
55560+
55561+__u32
55562+gr_acl_handle_mkdir(const struct dentry *new_dentry,
55563+ const struct dentry *parent_dentry,
55564+ const struct vfsmount *parent_mnt)
55565+{
55566+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55567+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55568+}
55569+
55570+#define RENAME_CHECK_SUCCESS(old, new) \
55571+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55572+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55573+
55574+int
55575+gr_acl_handle_rename(struct dentry *new_dentry,
55576+ struct dentry *parent_dentry,
55577+ const struct vfsmount *parent_mnt,
55578+ struct dentry *old_dentry,
55579+ struct inode *old_parent_inode,
55580+ struct vfsmount *old_mnt, const char *newname)
55581+{
55582+ __u32 comp1, comp2;
55583+ int error = 0;
55584+
55585+ if (unlikely(!gr_acl_is_enabled()))
55586+ return 0;
55587+
55588+ if (!new_dentry->d_inode) {
55589+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55590+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55591+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55592+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55593+ GR_DELETE | GR_AUDIT_DELETE |
55594+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55595+ GR_SUPPRESS, old_mnt);
55596+ } else {
55597+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55598+ GR_CREATE | GR_DELETE |
55599+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55600+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55601+ GR_SUPPRESS, parent_mnt);
55602+ comp2 =
55603+ gr_search_file(old_dentry,
55604+ GR_READ | GR_WRITE | GR_AUDIT_READ |
55605+ GR_DELETE | GR_AUDIT_DELETE |
55606+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55607+ }
55608+
55609+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55610+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55611+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55612+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55613+ && !(comp2 & GR_SUPPRESS)) {
55614+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55615+ error = -EACCES;
55616+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55617+ error = -EACCES;
55618+
55619+ return error;
55620+}
55621+
55622+void
55623+gr_acl_handle_exit(void)
55624+{
55625+ u16 id;
55626+ char *rolename;
55627+ struct file *exec_file;
55628+
55629+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55630+ !(current->role->roletype & GR_ROLE_PERSIST))) {
55631+ id = current->acl_role_id;
55632+ rolename = current->role->rolename;
55633+ gr_set_acls(1);
55634+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55635+ }
55636+
55637+ write_lock(&grsec_exec_file_lock);
55638+ exec_file = current->exec_file;
55639+ current->exec_file = NULL;
55640+ write_unlock(&grsec_exec_file_lock);
55641+
55642+ if (exec_file)
55643+ fput(exec_file);
55644+}
55645+
55646+int
55647+gr_acl_handle_procpidmem(const struct task_struct *task)
55648+{
55649+ if (unlikely(!gr_acl_is_enabled()))
55650+ return 0;
55651+
55652+ if (task != current && task->acl->mode & GR_PROTPROCFD)
55653+ return -EACCES;
55654+
55655+ return 0;
55656+}
55657diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55658new file mode 100644
55659index 0000000..58800a7
55660--- /dev/null
55661+++ b/grsecurity/gracl_ip.c
55662@@ -0,0 +1,384 @@
55663+#include <linux/kernel.h>
55664+#include <asm/uaccess.h>
55665+#include <asm/errno.h>
55666+#include <net/sock.h>
55667+#include <linux/file.h>
55668+#include <linux/fs.h>
55669+#include <linux/net.h>
55670+#include <linux/in.h>
55671+#include <linux/skbuff.h>
55672+#include <linux/ip.h>
55673+#include <linux/udp.h>
55674+#include <linux/types.h>
55675+#include <linux/sched.h>
55676+#include <linux/netdevice.h>
55677+#include <linux/inetdevice.h>
55678+#include <linux/gracl.h>
55679+#include <linux/grsecurity.h>
55680+#include <linux/grinternal.h>
55681+
55682+#define GR_BIND 0x01
55683+#define GR_CONNECT 0x02
55684+#define GR_INVERT 0x04
55685+#define GR_BINDOVERRIDE 0x08
55686+#define GR_CONNECTOVERRIDE 0x10
55687+#define GR_SOCK_FAMILY 0x20
55688+
55689+static const char * gr_protocols[IPPROTO_MAX] = {
55690+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55691+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55692+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55693+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55694+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55695+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55696+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55697+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55698+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55699+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55700+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55701+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55702+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55703+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55704+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55705+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55706+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55707+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55708+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55709+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55710+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55711+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55712+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55713+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55714+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55715+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55716+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55717+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55718+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55719+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55720+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55721+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55722+ };
55723+
55724+static const char * gr_socktypes[SOCK_MAX] = {
55725+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55726+ "unknown:7", "unknown:8", "unknown:9", "packet"
55727+ };
55728+
55729+static const char * gr_sockfamilies[AF_MAX+1] = {
55730+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55731+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55732+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55733+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55734+ };
55735+
55736+const char *
55737+gr_proto_to_name(unsigned char proto)
55738+{
55739+ return gr_protocols[proto];
55740+}
55741+
55742+const char *
55743+gr_socktype_to_name(unsigned char type)
55744+{
55745+ return gr_socktypes[type];
55746+}
55747+
55748+const char *
55749+gr_sockfamily_to_name(unsigned char family)
55750+{
55751+ return gr_sockfamilies[family];
55752+}
55753+
55754+int
55755+gr_search_socket(const int domain, const int type, const int protocol)
55756+{
55757+ struct acl_subject_label *curr;
55758+ const struct cred *cred = current_cred();
55759+
55760+ if (unlikely(!gr_acl_is_enabled()))
55761+ goto exit;
55762+
55763+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
55764+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55765+ goto exit; // let the kernel handle it
55766+
55767+ curr = current->acl;
55768+
55769+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55770+ /* the family is allowed, if this is PF_INET allow it only if
55771+ the extra sock type/protocol checks pass */
55772+ if (domain == PF_INET)
55773+ goto inet_check;
55774+ goto exit;
55775+ } else {
55776+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55777+ __u32 fakeip = 0;
55778+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55779+ current->role->roletype, cred->uid,
55780+ cred->gid, current->exec_file ?
55781+ gr_to_filename(current->exec_file->f_path.dentry,
55782+ current->exec_file->f_path.mnt) :
55783+ curr->filename, curr->filename,
55784+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55785+ &current->signal->saved_ip);
55786+ goto exit;
55787+ }
55788+ goto exit_fail;
55789+ }
55790+
55791+inet_check:
55792+ /* the rest of this checking is for IPv4 only */
55793+ if (!curr->ips)
55794+ goto exit;
55795+
55796+ if ((curr->ip_type & (1 << type)) &&
55797+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55798+ goto exit;
55799+
55800+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55801+ /* we don't place acls on raw sockets , and sometimes
55802+ dgram/ip sockets are opened for ioctl and not
55803+ bind/connect, so we'll fake a bind learn log */
55804+ if (type == SOCK_RAW || type == SOCK_PACKET) {
55805+ __u32 fakeip = 0;
55806+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55807+ current->role->roletype, cred->uid,
55808+ cred->gid, current->exec_file ?
55809+ gr_to_filename(current->exec_file->f_path.dentry,
55810+ current->exec_file->f_path.mnt) :
55811+ curr->filename, curr->filename,
55812+ &fakeip, 0, type,
55813+ protocol, GR_CONNECT, &current->signal->saved_ip);
55814+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55815+ __u32 fakeip = 0;
55816+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55817+ current->role->roletype, cred->uid,
55818+ cred->gid, current->exec_file ?
55819+ gr_to_filename(current->exec_file->f_path.dentry,
55820+ current->exec_file->f_path.mnt) :
55821+ curr->filename, curr->filename,
55822+ &fakeip, 0, type,
55823+ protocol, GR_BIND, &current->signal->saved_ip);
55824+ }
55825+ /* we'll log when they use connect or bind */
55826+ goto exit;
55827+ }
55828+
55829+exit_fail:
55830+ if (domain == PF_INET)
55831+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55832+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
55833+ else
55834+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55835+ gr_socktype_to_name(type), protocol);
55836+
55837+ return 0;
55838+exit:
55839+ return 1;
55840+}
55841+
55842+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)
55843+{
55844+ if ((ip->mode & mode) &&
55845+ (ip_port >= ip->low) &&
55846+ (ip_port <= ip->high) &&
55847+ ((ntohl(ip_addr) & our_netmask) ==
55848+ (ntohl(our_addr) & our_netmask))
55849+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55850+ && (ip->type & (1 << type))) {
55851+ if (ip->mode & GR_INVERT)
55852+ return 2; // specifically denied
55853+ else
55854+ return 1; // allowed
55855+ }
55856+
55857+ return 0; // not specifically allowed, may continue parsing
55858+}
55859+
55860+static int
55861+gr_search_connectbind(const int full_mode, struct sock *sk,
55862+ struct sockaddr_in *addr, const int type)
55863+{
55864+ char iface[IFNAMSIZ] = {0};
55865+ struct acl_subject_label *curr;
55866+ struct acl_ip_label *ip;
55867+ struct inet_sock *isk;
55868+ struct net_device *dev;
55869+ struct in_device *idev;
55870+ unsigned long i;
55871+ int ret;
55872+ int mode = full_mode & (GR_BIND | GR_CONNECT);
55873+ __u32 ip_addr = 0;
55874+ __u32 our_addr;
55875+ __u32 our_netmask;
55876+ char *p;
55877+ __u16 ip_port = 0;
55878+ const struct cred *cred = current_cred();
55879+
55880+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55881+ return 0;
55882+
55883+ curr = current->acl;
55884+ isk = inet_sk(sk);
55885+
55886+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55887+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55888+ addr->sin_addr.s_addr = curr->inaddr_any_override;
55889+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55890+ struct sockaddr_in saddr;
55891+ int err;
55892+
55893+ saddr.sin_family = AF_INET;
55894+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
55895+ saddr.sin_port = isk->inet_sport;
55896+
55897+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55898+ if (err)
55899+ return err;
55900+
55901+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55902+ if (err)
55903+ return err;
55904+ }
55905+
55906+ if (!curr->ips)
55907+ return 0;
55908+
55909+ ip_addr = addr->sin_addr.s_addr;
55910+ ip_port = ntohs(addr->sin_port);
55911+
55912+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55913+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55914+ current->role->roletype, cred->uid,
55915+ cred->gid, current->exec_file ?
55916+ gr_to_filename(current->exec_file->f_path.dentry,
55917+ current->exec_file->f_path.mnt) :
55918+ curr->filename, curr->filename,
55919+ &ip_addr, ip_port, type,
55920+ sk->sk_protocol, mode, &current->signal->saved_ip);
55921+ return 0;
55922+ }
55923+
55924+ for (i = 0; i < curr->ip_num; i++) {
55925+ ip = *(curr->ips + i);
55926+ if (ip->iface != NULL) {
55927+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
55928+ p = strchr(iface, ':');
55929+ if (p != NULL)
55930+ *p = '\0';
55931+ dev = dev_get_by_name(sock_net(sk), iface);
55932+ if (dev == NULL)
55933+ continue;
55934+ idev = in_dev_get(dev);
55935+ if (idev == NULL) {
55936+ dev_put(dev);
55937+ continue;
55938+ }
55939+ rcu_read_lock();
55940+ for_ifa(idev) {
55941+ if (!strcmp(ip->iface, ifa->ifa_label)) {
55942+ our_addr = ifa->ifa_address;
55943+ our_netmask = 0xffffffff;
55944+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55945+ if (ret == 1) {
55946+ rcu_read_unlock();
55947+ in_dev_put(idev);
55948+ dev_put(dev);
55949+ return 0;
55950+ } else if (ret == 2) {
55951+ rcu_read_unlock();
55952+ in_dev_put(idev);
55953+ dev_put(dev);
55954+ goto denied;
55955+ }
55956+ }
55957+ } endfor_ifa(idev);
55958+ rcu_read_unlock();
55959+ in_dev_put(idev);
55960+ dev_put(dev);
55961+ } else {
55962+ our_addr = ip->addr;
55963+ our_netmask = ip->netmask;
55964+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55965+ if (ret == 1)
55966+ return 0;
55967+ else if (ret == 2)
55968+ goto denied;
55969+ }
55970+ }
55971+
55972+denied:
55973+ if (mode == GR_BIND)
55974+ 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));
55975+ else if (mode == GR_CONNECT)
55976+ 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));
55977+
55978+ return -EACCES;
55979+}
55980+
55981+int
55982+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55983+{
55984+ /* always allow disconnection of dgram sockets with connect */
55985+ if (addr->sin_family == AF_UNSPEC)
55986+ return 0;
55987+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55988+}
55989+
55990+int
55991+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55992+{
55993+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55994+}
55995+
55996+int gr_search_listen(struct socket *sock)
55997+{
55998+ struct sock *sk = sock->sk;
55999+ struct sockaddr_in addr;
56000+
56001+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56002+ addr.sin_port = inet_sk(sk)->inet_sport;
56003+
56004+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56005+}
56006+
56007+int gr_search_accept(struct socket *sock)
56008+{
56009+ struct sock *sk = sock->sk;
56010+ struct sockaddr_in addr;
56011+
56012+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56013+ addr.sin_port = inet_sk(sk)->inet_sport;
56014+
56015+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56016+}
56017+
56018+int
56019+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56020+{
56021+ if (addr)
56022+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56023+ else {
56024+ struct sockaddr_in sin;
56025+ const struct inet_sock *inet = inet_sk(sk);
56026+
56027+ sin.sin_addr.s_addr = inet->inet_daddr;
56028+ sin.sin_port = inet->inet_dport;
56029+
56030+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56031+ }
56032+}
56033+
56034+int
56035+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56036+{
56037+ struct sockaddr_in sin;
56038+
56039+ if (unlikely(skb->len < sizeof (struct udphdr)))
56040+ return 0; // skip this packet
56041+
56042+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56043+ sin.sin_port = udp_hdr(skb)->source;
56044+
56045+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56046+}
56047diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56048new file mode 100644
56049index 0000000..25f54ef
56050--- /dev/null
56051+++ b/grsecurity/gracl_learn.c
56052@@ -0,0 +1,207 @@
56053+#include <linux/kernel.h>
56054+#include <linux/mm.h>
56055+#include <linux/sched.h>
56056+#include <linux/poll.h>
56057+#include <linux/string.h>
56058+#include <linux/file.h>
56059+#include <linux/types.h>
56060+#include <linux/vmalloc.h>
56061+#include <linux/grinternal.h>
56062+
56063+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56064+ size_t count, loff_t *ppos);
56065+extern int gr_acl_is_enabled(void);
56066+
56067+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56068+static int gr_learn_attached;
56069+
56070+/* use a 512k buffer */
56071+#define LEARN_BUFFER_SIZE (512 * 1024)
56072+
56073+static DEFINE_SPINLOCK(gr_learn_lock);
56074+static DEFINE_MUTEX(gr_learn_user_mutex);
56075+
56076+/* we need to maintain two buffers, so that the kernel context of grlearn
56077+ uses a semaphore around the userspace copying, and the other kernel contexts
56078+ use a spinlock when copying into the buffer, since they cannot sleep
56079+*/
56080+static char *learn_buffer;
56081+static char *learn_buffer_user;
56082+static int learn_buffer_len;
56083+static int learn_buffer_user_len;
56084+
56085+static ssize_t
56086+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56087+{
56088+ DECLARE_WAITQUEUE(wait, current);
56089+ ssize_t retval = 0;
56090+
56091+ add_wait_queue(&learn_wait, &wait);
56092+ set_current_state(TASK_INTERRUPTIBLE);
56093+ do {
56094+ mutex_lock(&gr_learn_user_mutex);
56095+ spin_lock(&gr_learn_lock);
56096+ if (learn_buffer_len)
56097+ break;
56098+ spin_unlock(&gr_learn_lock);
56099+ mutex_unlock(&gr_learn_user_mutex);
56100+ if (file->f_flags & O_NONBLOCK) {
56101+ retval = -EAGAIN;
56102+ goto out;
56103+ }
56104+ if (signal_pending(current)) {
56105+ retval = -ERESTARTSYS;
56106+ goto out;
56107+ }
56108+
56109+ schedule();
56110+ } while (1);
56111+
56112+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56113+ learn_buffer_user_len = learn_buffer_len;
56114+ retval = learn_buffer_len;
56115+ learn_buffer_len = 0;
56116+
56117+ spin_unlock(&gr_learn_lock);
56118+
56119+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56120+ retval = -EFAULT;
56121+
56122+ mutex_unlock(&gr_learn_user_mutex);
56123+out:
56124+ set_current_state(TASK_RUNNING);
56125+ remove_wait_queue(&learn_wait, &wait);
56126+ return retval;
56127+}
56128+
56129+static unsigned int
56130+poll_learn(struct file * file, poll_table * wait)
56131+{
56132+ poll_wait(file, &learn_wait, wait);
56133+
56134+ if (learn_buffer_len)
56135+ return (POLLIN | POLLRDNORM);
56136+
56137+ return 0;
56138+}
56139+
56140+void
56141+gr_clear_learn_entries(void)
56142+{
56143+ char *tmp;
56144+
56145+ mutex_lock(&gr_learn_user_mutex);
56146+ spin_lock(&gr_learn_lock);
56147+ tmp = learn_buffer;
56148+ learn_buffer = NULL;
56149+ spin_unlock(&gr_learn_lock);
56150+ if (tmp)
56151+ vfree(tmp);
56152+ if (learn_buffer_user != NULL) {
56153+ vfree(learn_buffer_user);
56154+ learn_buffer_user = NULL;
56155+ }
56156+ learn_buffer_len = 0;
56157+ mutex_unlock(&gr_learn_user_mutex);
56158+
56159+ return;
56160+}
56161+
56162+void
56163+gr_add_learn_entry(const char *fmt, ...)
56164+{
56165+ va_list args;
56166+ unsigned int len;
56167+
56168+ if (!gr_learn_attached)
56169+ return;
56170+
56171+ spin_lock(&gr_learn_lock);
56172+
56173+ /* leave a gap at the end so we know when it's "full" but don't have to
56174+ compute the exact length of the string we're trying to append
56175+ */
56176+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56177+ spin_unlock(&gr_learn_lock);
56178+ wake_up_interruptible(&learn_wait);
56179+ return;
56180+ }
56181+ if (learn_buffer == NULL) {
56182+ spin_unlock(&gr_learn_lock);
56183+ return;
56184+ }
56185+
56186+ va_start(args, fmt);
56187+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56188+ va_end(args);
56189+
56190+ learn_buffer_len += len + 1;
56191+
56192+ spin_unlock(&gr_learn_lock);
56193+ wake_up_interruptible(&learn_wait);
56194+
56195+ return;
56196+}
56197+
56198+static int
56199+open_learn(struct inode *inode, struct file *file)
56200+{
56201+ if (file->f_mode & FMODE_READ && gr_learn_attached)
56202+ return -EBUSY;
56203+ if (file->f_mode & FMODE_READ) {
56204+ int retval = 0;
56205+ mutex_lock(&gr_learn_user_mutex);
56206+ if (learn_buffer == NULL)
56207+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56208+ if (learn_buffer_user == NULL)
56209+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56210+ if (learn_buffer == NULL) {
56211+ retval = -ENOMEM;
56212+ goto out_error;
56213+ }
56214+ if (learn_buffer_user == NULL) {
56215+ retval = -ENOMEM;
56216+ goto out_error;
56217+ }
56218+ learn_buffer_len = 0;
56219+ learn_buffer_user_len = 0;
56220+ gr_learn_attached = 1;
56221+out_error:
56222+ mutex_unlock(&gr_learn_user_mutex);
56223+ return retval;
56224+ }
56225+ return 0;
56226+}
56227+
56228+static int
56229+close_learn(struct inode *inode, struct file *file)
56230+{
56231+ if (file->f_mode & FMODE_READ) {
56232+ char *tmp = NULL;
56233+ mutex_lock(&gr_learn_user_mutex);
56234+ spin_lock(&gr_learn_lock);
56235+ tmp = learn_buffer;
56236+ learn_buffer = NULL;
56237+ spin_unlock(&gr_learn_lock);
56238+ if (tmp)
56239+ vfree(tmp);
56240+ if (learn_buffer_user != NULL) {
56241+ vfree(learn_buffer_user);
56242+ learn_buffer_user = NULL;
56243+ }
56244+ learn_buffer_len = 0;
56245+ learn_buffer_user_len = 0;
56246+ gr_learn_attached = 0;
56247+ mutex_unlock(&gr_learn_user_mutex);
56248+ }
56249+
56250+ return 0;
56251+}
56252+
56253+const struct file_operations grsec_fops = {
56254+ .read = read_learn,
56255+ .write = write_grsec_handler,
56256+ .open = open_learn,
56257+ .release = close_learn,
56258+ .poll = poll_learn,
56259+};
56260diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56261new file mode 100644
56262index 0000000..39645c9
56263--- /dev/null
56264+++ b/grsecurity/gracl_res.c
56265@@ -0,0 +1,68 @@
56266+#include <linux/kernel.h>
56267+#include <linux/sched.h>
56268+#include <linux/gracl.h>
56269+#include <linux/grinternal.h>
56270+
56271+static const char *restab_log[] = {
56272+ [RLIMIT_CPU] = "RLIMIT_CPU",
56273+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56274+ [RLIMIT_DATA] = "RLIMIT_DATA",
56275+ [RLIMIT_STACK] = "RLIMIT_STACK",
56276+ [RLIMIT_CORE] = "RLIMIT_CORE",
56277+ [RLIMIT_RSS] = "RLIMIT_RSS",
56278+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
56279+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56280+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56281+ [RLIMIT_AS] = "RLIMIT_AS",
56282+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56283+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56284+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56285+ [RLIMIT_NICE] = "RLIMIT_NICE",
56286+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56287+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56288+ [GR_CRASH_RES] = "RLIMIT_CRASH"
56289+};
56290+
56291+void
56292+gr_log_resource(const struct task_struct *task,
56293+ const int res, const unsigned long wanted, const int gt)
56294+{
56295+ const struct cred *cred;
56296+ unsigned long rlim;
56297+
56298+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
56299+ return;
56300+
56301+ // not yet supported resource
56302+ if (unlikely(!restab_log[res]))
56303+ return;
56304+
56305+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56306+ rlim = task_rlimit_max(task, res);
56307+ else
56308+ rlim = task_rlimit(task, res);
56309+
56310+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56311+ return;
56312+
56313+ rcu_read_lock();
56314+ cred = __task_cred(task);
56315+
56316+ if (res == RLIMIT_NPROC &&
56317+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56318+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56319+ goto out_rcu_unlock;
56320+ else if (res == RLIMIT_MEMLOCK &&
56321+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56322+ goto out_rcu_unlock;
56323+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56324+ goto out_rcu_unlock;
56325+ rcu_read_unlock();
56326+
56327+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56328+
56329+ return;
56330+out_rcu_unlock:
56331+ rcu_read_unlock();
56332+ return;
56333+}
56334diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56335new file mode 100644
56336index 0000000..25197e9
56337--- /dev/null
56338+++ b/grsecurity/gracl_segv.c
56339@@ -0,0 +1,299 @@
56340+#include <linux/kernel.h>
56341+#include <linux/mm.h>
56342+#include <asm/uaccess.h>
56343+#include <asm/errno.h>
56344+#include <asm/mman.h>
56345+#include <net/sock.h>
56346+#include <linux/file.h>
56347+#include <linux/fs.h>
56348+#include <linux/net.h>
56349+#include <linux/in.h>
56350+#include <linux/slab.h>
56351+#include <linux/types.h>
56352+#include <linux/sched.h>
56353+#include <linux/timer.h>
56354+#include <linux/gracl.h>
56355+#include <linux/grsecurity.h>
56356+#include <linux/grinternal.h>
56357+
56358+static struct crash_uid *uid_set;
56359+static unsigned short uid_used;
56360+static DEFINE_SPINLOCK(gr_uid_lock);
56361+extern rwlock_t gr_inode_lock;
56362+extern struct acl_subject_label *
56363+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56364+ struct acl_role_label *role);
56365+
56366+#ifdef CONFIG_BTRFS_FS
56367+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56368+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56369+#endif
56370+
56371+static inline dev_t __get_dev(const struct dentry *dentry)
56372+{
56373+#ifdef CONFIG_BTRFS_FS
56374+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56375+ return get_btrfs_dev_from_inode(dentry->d_inode);
56376+ else
56377+#endif
56378+ return dentry->d_inode->i_sb->s_dev;
56379+}
56380+
56381+int
56382+gr_init_uidset(void)
56383+{
56384+ uid_set =
56385+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56386+ uid_used = 0;
56387+
56388+ return uid_set ? 1 : 0;
56389+}
56390+
56391+void
56392+gr_free_uidset(void)
56393+{
56394+ if (uid_set)
56395+ kfree(uid_set);
56396+
56397+ return;
56398+}
56399+
56400+int
56401+gr_find_uid(const uid_t uid)
56402+{
56403+ struct crash_uid *tmp = uid_set;
56404+ uid_t buid;
56405+ int low = 0, high = uid_used - 1, mid;
56406+
56407+ while (high >= low) {
56408+ mid = (low + high) >> 1;
56409+ buid = tmp[mid].uid;
56410+ if (buid == uid)
56411+ return mid;
56412+ if (buid > uid)
56413+ high = mid - 1;
56414+ if (buid < uid)
56415+ low = mid + 1;
56416+ }
56417+
56418+ return -1;
56419+}
56420+
56421+static __inline__ void
56422+gr_insertsort(void)
56423+{
56424+ unsigned short i, j;
56425+ struct crash_uid index;
56426+
56427+ for (i = 1; i < uid_used; i++) {
56428+ index = uid_set[i];
56429+ j = i;
56430+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56431+ uid_set[j] = uid_set[j - 1];
56432+ j--;
56433+ }
56434+ uid_set[j] = index;
56435+ }
56436+
56437+ return;
56438+}
56439+
56440+static __inline__ void
56441+gr_insert_uid(const uid_t uid, const unsigned long expires)
56442+{
56443+ int loc;
56444+
56445+ if (uid_used == GR_UIDTABLE_MAX)
56446+ return;
56447+
56448+ loc = gr_find_uid(uid);
56449+
56450+ if (loc >= 0) {
56451+ uid_set[loc].expires = expires;
56452+ return;
56453+ }
56454+
56455+ uid_set[uid_used].uid = uid;
56456+ uid_set[uid_used].expires = expires;
56457+ uid_used++;
56458+
56459+ gr_insertsort();
56460+
56461+ return;
56462+}
56463+
56464+void
56465+gr_remove_uid(const unsigned short loc)
56466+{
56467+ unsigned short i;
56468+
56469+ for (i = loc + 1; i < uid_used; i++)
56470+ uid_set[i - 1] = uid_set[i];
56471+
56472+ uid_used--;
56473+
56474+ return;
56475+}
56476+
56477+int
56478+gr_check_crash_uid(const uid_t uid)
56479+{
56480+ int loc;
56481+ int ret = 0;
56482+
56483+ if (unlikely(!gr_acl_is_enabled()))
56484+ return 0;
56485+
56486+ spin_lock(&gr_uid_lock);
56487+ loc = gr_find_uid(uid);
56488+
56489+ if (loc < 0)
56490+ goto out_unlock;
56491+
56492+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
56493+ gr_remove_uid(loc);
56494+ else
56495+ ret = 1;
56496+
56497+out_unlock:
56498+ spin_unlock(&gr_uid_lock);
56499+ return ret;
56500+}
56501+
56502+static __inline__ int
56503+proc_is_setxid(const struct cred *cred)
56504+{
56505+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
56506+ !uid_eq(cred->uid, cred->fsuid))
56507+ return 1;
56508+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
56509+ !uid_eq(cred->gid, cred->fsgid))
56510+ return 1;
56511+
56512+ return 0;
56513+}
56514+
56515+extern int gr_fake_force_sig(int sig, struct task_struct *t);
56516+
56517+void
56518+gr_handle_crash(struct task_struct *task, const int sig)
56519+{
56520+ struct acl_subject_label *curr;
56521+ struct task_struct *tsk, *tsk2;
56522+ const struct cred *cred;
56523+ const struct cred *cred2;
56524+
56525+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56526+ return;
56527+
56528+ if (unlikely(!gr_acl_is_enabled()))
56529+ return;
56530+
56531+ curr = task->acl;
56532+
56533+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
56534+ return;
56535+
56536+ if (time_before_eq(curr->expires, get_seconds())) {
56537+ curr->expires = 0;
56538+ curr->crashes = 0;
56539+ }
56540+
56541+ curr->crashes++;
56542+
56543+ if (!curr->expires)
56544+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56545+
56546+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56547+ time_after(curr->expires, get_seconds())) {
56548+ rcu_read_lock();
56549+ cred = __task_cred(task);
56550+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
56551+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56552+ spin_lock(&gr_uid_lock);
56553+ gr_insert_uid(cred->uid, curr->expires);
56554+ spin_unlock(&gr_uid_lock);
56555+ curr->expires = 0;
56556+ curr->crashes = 0;
56557+ read_lock(&tasklist_lock);
56558+ do_each_thread(tsk2, tsk) {
56559+ cred2 = __task_cred(tsk);
56560+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
56561+ gr_fake_force_sig(SIGKILL, tsk);
56562+ } while_each_thread(tsk2, tsk);
56563+ read_unlock(&tasklist_lock);
56564+ } else {
56565+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56566+ read_lock(&tasklist_lock);
56567+ read_lock(&grsec_exec_file_lock);
56568+ do_each_thread(tsk2, tsk) {
56569+ if (likely(tsk != task)) {
56570+ // if this thread has the same subject as the one that triggered
56571+ // RES_CRASH and it's the same binary, kill it
56572+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56573+ gr_fake_force_sig(SIGKILL, tsk);
56574+ }
56575+ } while_each_thread(tsk2, tsk);
56576+ read_unlock(&grsec_exec_file_lock);
56577+ read_unlock(&tasklist_lock);
56578+ }
56579+ rcu_read_unlock();
56580+ }
56581+
56582+ return;
56583+}
56584+
56585+int
56586+gr_check_crash_exec(const struct file *filp)
56587+{
56588+ struct acl_subject_label *curr;
56589+
56590+ if (unlikely(!gr_acl_is_enabled()))
56591+ return 0;
56592+
56593+ read_lock(&gr_inode_lock);
56594+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56595+ __get_dev(filp->f_path.dentry),
56596+ current->role);
56597+ read_unlock(&gr_inode_lock);
56598+
56599+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56600+ (!curr->crashes && !curr->expires))
56601+ return 0;
56602+
56603+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56604+ time_after(curr->expires, get_seconds()))
56605+ return 1;
56606+ else if (time_before_eq(curr->expires, get_seconds())) {
56607+ curr->crashes = 0;
56608+ curr->expires = 0;
56609+ }
56610+
56611+ return 0;
56612+}
56613+
56614+void
56615+gr_handle_alertkill(struct task_struct *task)
56616+{
56617+ struct acl_subject_label *curracl;
56618+ __u32 curr_ip;
56619+ struct task_struct *p, *p2;
56620+
56621+ if (unlikely(!gr_acl_is_enabled()))
56622+ return;
56623+
56624+ curracl = task->acl;
56625+ curr_ip = task->signal->curr_ip;
56626+
56627+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56628+ read_lock(&tasklist_lock);
56629+ do_each_thread(p2, p) {
56630+ if (p->signal->curr_ip == curr_ip)
56631+ gr_fake_force_sig(SIGKILL, p);
56632+ } while_each_thread(p2, p);
56633+ read_unlock(&tasklist_lock);
56634+ } else if (curracl->mode & GR_KILLPROC)
56635+ gr_fake_force_sig(SIGKILL, task);
56636+
56637+ return;
56638+}
56639diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56640new file mode 100644
56641index 0000000..9d83a69
56642--- /dev/null
56643+++ b/grsecurity/gracl_shm.c
56644@@ -0,0 +1,40 @@
56645+#include <linux/kernel.h>
56646+#include <linux/mm.h>
56647+#include <linux/sched.h>
56648+#include <linux/file.h>
56649+#include <linux/ipc.h>
56650+#include <linux/gracl.h>
56651+#include <linux/grsecurity.h>
56652+#include <linux/grinternal.h>
56653+
56654+int
56655+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56656+ const time_t shm_createtime, const uid_t cuid, const int shmid)
56657+{
56658+ struct task_struct *task;
56659+
56660+ if (!gr_acl_is_enabled())
56661+ return 1;
56662+
56663+ rcu_read_lock();
56664+ read_lock(&tasklist_lock);
56665+
56666+ task = find_task_by_vpid(shm_cprid);
56667+
56668+ if (unlikely(!task))
56669+ task = find_task_by_vpid(shm_lapid);
56670+
56671+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56672+ (task->pid == shm_lapid)) &&
56673+ (task->acl->mode & GR_PROTSHM) &&
56674+ (task->acl != current->acl))) {
56675+ read_unlock(&tasklist_lock);
56676+ rcu_read_unlock();
56677+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56678+ return 0;
56679+ }
56680+ read_unlock(&tasklist_lock);
56681+ rcu_read_unlock();
56682+
56683+ return 1;
56684+}
56685diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56686new file mode 100644
56687index 0000000..bc0be01
56688--- /dev/null
56689+++ b/grsecurity/grsec_chdir.c
56690@@ -0,0 +1,19 @@
56691+#include <linux/kernel.h>
56692+#include <linux/sched.h>
56693+#include <linux/fs.h>
56694+#include <linux/file.h>
56695+#include <linux/grsecurity.h>
56696+#include <linux/grinternal.h>
56697+
56698+void
56699+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56700+{
56701+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56702+ if ((grsec_enable_chdir && grsec_enable_group &&
56703+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56704+ !grsec_enable_group)) {
56705+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56706+ }
56707+#endif
56708+ return;
56709+}
56710diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56711new file mode 100644
56712index 0000000..9807ee2
56713--- /dev/null
56714+++ b/grsecurity/grsec_chroot.c
56715@@ -0,0 +1,368 @@
56716+#include <linux/kernel.h>
56717+#include <linux/module.h>
56718+#include <linux/sched.h>
56719+#include <linux/file.h>
56720+#include <linux/fs.h>
56721+#include <linux/mount.h>
56722+#include <linux/types.h>
56723+#include "../fs/mount.h"
56724+#include <linux/grsecurity.h>
56725+#include <linux/grinternal.h>
56726+
56727+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56728+{
56729+#ifdef CONFIG_GRKERNSEC
56730+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56731+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56732+ task->gr_is_chrooted = 1;
56733+ else
56734+ task->gr_is_chrooted = 0;
56735+
56736+ task->gr_chroot_dentry = path->dentry;
56737+#endif
56738+ return;
56739+}
56740+
56741+void gr_clear_chroot_entries(struct task_struct *task)
56742+{
56743+#ifdef CONFIG_GRKERNSEC
56744+ task->gr_is_chrooted = 0;
56745+ task->gr_chroot_dentry = NULL;
56746+#endif
56747+ return;
56748+}
56749+
56750+int
56751+gr_handle_chroot_unix(const pid_t pid)
56752+{
56753+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56754+ struct task_struct *p;
56755+
56756+ if (unlikely(!grsec_enable_chroot_unix))
56757+ return 1;
56758+
56759+ if (likely(!proc_is_chrooted(current)))
56760+ return 1;
56761+
56762+ rcu_read_lock();
56763+ read_lock(&tasklist_lock);
56764+ p = find_task_by_vpid_unrestricted(pid);
56765+ if (unlikely(p && !have_same_root(current, p))) {
56766+ read_unlock(&tasklist_lock);
56767+ rcu_read_unlock();
56768+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56769+ return 0;
56770+ }
56771+ read_unlock(&tasklist_lock);
56772+ rcu_read_unlock();
56773+#endif
56774+ return 1;
56775+}
56776+
56777+int
56778+gr_handle_chroot_nice(void)
56779+{
56780+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56781+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56782+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56783+ return -EPERM;
56784+ }
56785+#endif
56786+ return 0;
56787+}
56788+
56789+int
56790+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56791+{
56792+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56793+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56794+ && proc_is_chrooted(current)) {
56795+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56796+ return -EACCES;
56797+ }
56798+#endif
56799+ return 0;
56800+}
56801+
56802+int
56803+gr_handle_chroot_rawio(const struct inode *inode)
56804+{
56805+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56806+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56807+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56808+ return 1;
56809+#endif
56810+ return 0;
56811+}
56812+
56813+int
56814+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56815+{
56816+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56817+ struct task_struct *p;
56818+ int ret = 0;
56819+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56820+ return ret;
56821+
56822+ read_lock(&tasklist_lock);
56823+ do_each_pid_task(pid, type, p) {
56824+ if (!have_same_root(current, p)) {
56825+ ret = 1;
56826+ goto out;
56827+ }
56828+ } while_each_pid_task(pid, type, p);
56829+out:
56830+ read_unlock(&tasklist_lock);
56831+ return ret;
56832+#endif
56833+ return 0;
56834+}
56835+
56836+int
56837+gr_pid_is_chrooted(struct task_struct *p)
56838+{
56839+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56840+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56841+ return 0;
56842+
56843+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56844+ !have_same_root(current, p)) {
56845+ return 1;
56846+ }
56847+#endif
56848+ return 0;
56849+}
56850+
56851+EXPORT_SYMBOL(gr_pid_is_chrooted);
56852+
56853+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56854+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56855+{
56856+ struct path path, currentroot;
56857+ int ret = 0;
56858+
56859+ path.dentry = (struct dentry *)u_dentry;
56860+ path.mnt = (struct vfsmount *)u_mnt;
56861+ get_fs_root(current->fs, &currentroot);
56862+ if (path_is_under(&path, &currentroot))
56863+ ret = 1;
56864+ path_put(&currentroot);
56865+
56866+ return ret;
56867+}
56868+#endif
56869+
56870+int
56871+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56872+{
56873+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56874+ if (!grsec_enable_chroot_fchdir)
56875+ return 1;
56876+
56877+ if (!proc_is_chrooted(current))
56878+ return 1;
56879+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56880+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56881+ return 0;
56882+ }
56883+#endif
56884+ return 1;
56885+}
56886+
56887+int
56888+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56889+ const time_t shm_createtime)
56890+{
56891+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56892+ struct task_struct *p;
56893+ time_t starttime;
56894+
56895+ if (unlikely(!grsec_enable_chroot_shmat))
56896+ return 1;
56897+
56898+ if (likely(!proc_is_chrooted(current)))
56899+ return 1;
56900+
56901+ rcu_read_lock();
56902+ read_lock(&tasklist_lock);
56903+
56904+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56905+ starttime = p->start_time.tv_sec;
56906+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56907+ if (have_same_root(current, p)) {
56908+ goto allow;
56909+ } else {
56910+ read_unlock(&tasklist_lock);
56911+ rcu_read_unlock();
56912+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56913+ return 0;
56914+ }
56915+ }
56916+ /* creator exited, pid reuse, fall through to next check */
56917+ }
56918+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56919+ if (unlikely(!have_same_root(current, p))) {
56920+ read_unlock(&tasklist_lock);
56921+ rcu_read_unlock();
56922+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56923+ return 0;
56924+ }
56925+ }
56926+
56927+allow:
56928+ read_unlock(&tasklist_lock);
56929+ rcu_read_unlock();
56930+#endif
56931+ return 1;
56932+}
56933+
56934+void
56935+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56936+{
56937+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56938+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56939+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56940+#endif
56941+ return;
56942+}
56943+
56944+int
56945+gr_handle_chroot_mknod(const struct dentry *dentry,
56946+ const struct vfsmount *mnt, const int mode)
56947+{
56948+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56949+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56950+ proc_is_chrooted(current)) {
56951+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56952+ return -EPERM;
56953+ }
56954+#endif
56955+ return 0;
56956+}
56957+
56958+int
56959+gr_handle_chroot_mount(const struct dentry *dentry,
56960+ const struct vfsmount *mnt, const char *dev_name)
56961+{
56962+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56963+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56964+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56965+ return -EPERM;
56966+ }
56967+#endif
56968+ return 0;
56969+}
56970+
56971+int
56972+gr_handle_chroot_pivot(void)
56973+{
56974+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56975+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56976+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56977+ return -EPERM;
56978+ }
56979+#endif
56980+ return 0;
56981+}
56982+
56983+int
56984+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56985+{
56986+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56987+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56988+ !gr_is_outside_chroot(dentry, mnt)) {
56989+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56990+ return -EPERM;
56991+ }
56992+#endif
56993+ return 0;
56994+}
56995+
56996+extern const char *captab_log[];
56997+extern int captab_log_entries;
56998+
56999+int
57000+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57001+{
57002+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57003+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57004+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57005+ if (cap_raised(chroot_caps, cap)) {
57006+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57007+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57008+ }
57009+ return 0;
57010+ }
57011+ }
57012+#endif
57013+ return 1;
57014+}
57015+
57016+int
57017+gr_chroot_is_capable(const int cap)
57018+{
57019+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57020+ return gr_task_chroot_is_capable(current, current_cred(), cap);
57021+#endif
57022+ return 1;
57023+}
57024+
57025+int
57026+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57027+{
57028+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57029+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57030+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57031+ if (cap_raised(chroot_caps, cap)) {
57032+ return 0;
57033+ }
57034+ }
57035+#endif
57036+ return 1;
57037+}
57038+
57039+int
57040+gr_chroot_is_capable_nolog(const int cap)
57041+{
57042+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57043+ return gr_task_chroot_is_capable_nolog(current, cap);
57044+#endif
57045+ return 1;
57046+}
57047+
57048+int
57049+gr_handle_chroot_sysctl(const int op)
57050+{
57051+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57052+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57053+ proc_is_chrooted(current))
57054+ return -EACCES;
57055+#endif
57056+ return 0;
57057+}
57058+
57059+void
57060+gr_handle_chroot_chdir(struct path *path)
57061+{
57062+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57063+ if (grsec_enable_chroot_chdir)
57064+ set_fs_pwd(current->fs, path);
57065+#endif
57066+ return;
57067+}
57068+
57069+int
57070+gr_handle_chroot_chmod(const struct dentry *dentry,
57071+ const struct vfsmount *mnt, const int mode)
57072+{
57073+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57074+ /* allow chmod +s on directories, but not files */
57075+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57076+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57077+ proc_is_chrooted(current)) {
57078+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57079+ return -EPERM;
57080+ }
57081+#endif
57082+ return 0;
57083+}
57084diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57085new file mode 100644
57086index 0000000..213ad8b
57087--- /dev/null
57088+++ b/grsecurity/grsec_disabled.c
57089@@ -0,0 +1,437 @@
57090+#include <linux/kernel.h>
57091+#include <linux/module.h>
57092+#include <linux/sched.h>
57093+#include <linux/file.h>
57094+#include <linux/fs.h>
57095+#include <linux/kdev_t.h>
57096+#include <linux/net.h>
57097+#include <linux/in.h>
57098+#include <linux/ip.h>
57099+#include <linux/skbuff.h>
57100+#include <linux/sysctl.h>
57101+
57102+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57103+void
57104+pax_set_initial_flags(struct linux_binprm *bprm)
57105+{
57106+ return;
57107+}
57108+#endif
57109+
57110+#ifdef CONFIG_SYSCTL
57111+__u32
57112+gr_handle_sysctl(const struct ctl_table * table, const int op)
57113+{
57114+ return 0;
57115+}
57116+#endif
57117+
57118+#ifdef CONFIG_TASKSTATS
57119+int gr_is_taskstats_denied(int pid)
57120+{
57121+ return 0;
57122+}
57123+#endif
57124+
57125+int
57126+gr_acl_is_enabled(void)
57127+{
57128+ return 0;
57129+}
57130+
57131+void
57132+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57133+{
57134+ return;
57135+}
57136+
57137+int
57138+gr_handle_rawio(const struct inode *inode)
57139+{
57140+ return 0;
57141+}
57142+
57143+void
57144+gr_acl_handle_psacct(struct task_struct *task, const long code)
57145+{
57146+ return;
57147+}
57148+
57149+int
57150+gr_handle_ptrace(struct task_struct *task, const long request)
57151+{
57152+ return 0;
57153+}
57154+
57155+int
57156+gr_handle_proc_ptrace(struct task_struct *task)
57157+{
57158+ return 0;
57159+}
57160+
57161+void
57162+gr_learn_resource(const struct task_struct *task,
57163+ const int res, const unsigned long wanted, const int gt)
57164+{
57165+ return;
57166+}
57167+
57168+int
57169+gr_set_acls(const int type)
57170+{
57171+ return 0;
57172+}
57173+
57174+int
57175+gr_check_hidden_task(const struct task_struct *tsk)
57176+{
57177+ return 0;
57178+}
57179+
57180+int
57181+gr_check_protected_task(const struct task_struct *task)
57182+{
57183+ return 0;
57184+}
57185+
57186+int
57187+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57188+{
57189+ return 0;
57190+}
57191+
57192+void
57193+gr_copy_label(struct task_struct *tsk)
57194+{
57195+ return;
57196+}
57197+
57198+void
57199+gr_set_pax_flags(struct task_struct *task)
57200+{
57201+ return;
57202+}
57203+
57204+int
57205+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57206+ const int unsafe_share)
57207+{
57208+ return 0;
57209+}
57210+
57211+void
57212+gr_handle_delete(const ino_t ino, const dev_t dev)
57213+{
57214+ return;
57215+}
57216+
57217+void
57218+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57219+{
57220+ return;
57221+}
57222+
57223+void
57224+gr_handle_crash(struct task_struct *task, const int sig)
57225+{
57226+ return;
57227+}
57228+
57229+int
57230+gr_check_crash_exec(const struct file *filp)
57231+{
57232+ return 0;
57233+}
57234+
57235+int
57236+gr_check_crash_uid(const uid_t uid)
57237+{
57238+ return 0;
57239+}
57240+
57241+void
57242+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57243+ struct dentry *old_dentry,
57244+ struct dentry *new_dentry,
57245+ struct vfsmount *mnt, const __u8 replace)
57246+{
57247+ return;
57248+}
57249+
57250+int
57251+gr_search_socket(const int family, const int type, const int protocol)
57252+{
57253+ return 1;
57254+}
57255+
57256+int
57257+gr_search_connectbind(const int mode, const struct socket *sock,
57258+ const struct sockaddr_in *addr)
57259+{
57260+ return 0;
57261+}
57262+
57263+void
57264+gr_handle_alertkill(struct task_struct *task)
57265+{
57266+ return;
57267+}
57268+
57269+__u32
57270+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57271+{
57272+ return 1;
57273+}
57274+
57275+__u32
57276+gr_acl_handle_hidden_file(const struct dentry * dentry,
57277+ const struct vfsmount * mnt)
57278+{
57279+ return 1;
57280+}
57281+
57282+__u32
57283+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57284+ int acc_mode)
57285+{
57286+ return 1;
57287+}
57288+
57289+__u32
57290+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57291+{
57292+ return 1;
57293+}
57294+
57295+__u32
57296+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57297+{
57298+ return 1;
57299+}
57300+
57301+int
57302+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57303+ unsigned int *vm_flags)
57304+{
57305+ return 1;
57306+}
57307+
57308+__u32
57309+gr_acl_handle_truncate(const struct dentry * dentry,
57310+ const struct vfsmount * mnt)
57311+{
57312+ return 1;
57313+}
57314+
57315+__u32
57316+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57317+{
57318+ return 1;
57319+}
57320+
57321+__u32
57322+gr_acl_handle_access(const struct dentry * dentry,
57323+ const struct vfsmount * mnt, const int fmode)
57324+{
57325+ return 1;
57326+}
57327+
57328+__u32
57329+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57330+ umode_t *mode)
57331+{
57332+ return 1;
57333+}
57334+
57335+__u32
57336+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57337+{
57338+ return 1;
57339+}
57340+
57341+__u32
57342+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57343+{
57344+ return 1;
57345+}
57346+
57347+void
57348+grsecurity_init(void)
57349+{
57350+ return;
57351+}
57352+
57353+umode_t gr_acl_umask(void)
57354+{
57355+ return 0;
57356+}
57357+
57358+__u32
57359+gr_acl_handle_mknod(const struct dentry * new_dentry,
57360+ const struct dentry * parent_dentry,
57361+ const struct vfsmount * parent_mnt,
57362+ const int mode)
57363+{
57364+ return 1;
57365+}
57366+
57367+__u32
57368+gr_acl_handle_mkdir(const struct dentry * new_dentry,
57369+ const struct dentry * parent_dentry,
57370+ const struct vfsmount * parent_mnt)
57371+{
57372+ return 1;
57373+}
57374+
57375+__u32
57376+gr_acl_handle_symlink(const struct dentry * new_dentry,
57377+ const struct dentry * parent_dentry,
57378+ const struct vfsmount * parent_mnt, const char *from)
57379+{
57380+ return 1;
57381+}
57382+
57383+__u32
57384+gr_acl_handle_link(const struct dentry * new_dentry,
57385+ const struct dentry * parent_dentry,
57386+ const struct vfsmount * parent_mnt,
57387+ const struct dentry * old_dentry,
57388+ const struct vfsmount * old_mnt, const char *to)
57389+{
57390+ return 1;
57391+}
57392+
57393+int
57394+gr_acl_handle_rename(const struct dentry *new_dentry,
57395+ const struct dentry *parent_dentry,
57396+ const struct vfsmount *parent_mnt,
57397+ const struct dentry *old_dentry,
57398+ const struct inode *old_parent_inode,
57399+ const struct vfsmount *old_mnt, const char *newname)
57400+{
57401+ return 0;
57402+}
57403+
57404+int
57405+gr_acl_handle_filldir(const struct file *file, const char *name,
57406+ const int namelen, const ino_t ino)
57407+{
57408+ return 1;
57409+}
57410+
57411+int
57412+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57413+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57414+{
57415+ return 1;
57416+}
57417+
57418+int
57419+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57420+{
57421+ return 0;
57422+}
57423+
57424+int
57425+gr_search_accept(const struct socket *sock)
57426+{
57427+ return 0;
57428+}
57429+
57430+int
57431+gr_search_listen(const struct socket *sock)
57432+{
57433+ return 0;
57434+}
57435+
57436+int
57437+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57438+{
57439+ return 0;
57440+}
57441+
57442+__u32
57443+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57444+{
57445+ return 1;
57446+}
57447+
57448+__u32
57449+gr_acl_handle_creat(const struct dentry * dentry,
57450+ const struct dentry * p_dentry,
57451+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57452+ const int imode)
57453+{
57454+ return 1;
57455+}
57456+
57457+void
57458+gr_acl_handle_exit(void)
57459+{
57460+ return;
57461+}
57462+
57463+int
57464+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57465+{
57466+ return 1;
57467+}
57468+
57469+void
57470+gr_set_role_label(const uid_t uid, const gid_t gid)
57471+{
57472+ return;
57473+}
57474+
57475+int
57476+gr_acl_handle_procpidmem(const struct task_struct *task)
57477+{
57478+ return 0;
57479+}
57480+
57481+int
57482+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57483+{
57484+ return 0;
57485+}
57486+
57487+int
57488+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57489+{
57490+ return 0;
57491+}
57492+
57493+void
57494+gr_set_kernel_label(struct task_struct *task)
57495+{
57496+ return;
57497+}
57498+
57499+int
57500+gr_check_user_change(int real, int effective, int fs)
57501+{
57502+ return 0;
57503+}
57504+
57505+int
57506+gr_check_group_change(int real, int effective, int fs)
57507+{
57508+ return 0;
57509+}
57510+
57511+int gr_acl_enable_at_secure(void)
57512+{
57513+ return 0;
57514+}
57515+
57516+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57517+{
57518+ return dentry->d_inode->i_sb->s_dev;
57519+}
57520+
57521+EXPORT_SYMBOL(gr_learn_resource);
57522+EXPORT_SYMBOL(gr_set_kernel_label);
57523+#ifdef CONFIG_SECURITY
57524+EXPORT_SYMBOL(gr_check_user_change);
57525+EXPORT_SYMBOL(gr_check_group_change);
57526+#endif
57527diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57528new file mode 100644
57529index 0000000..abfa971
57530--- /dev/null
57531+++ b/grsecurity/grsec_exec.c
57532@@ -0,0 +1,174 @@
57533+#include <linux/kernel.h>
57534+#include <linux/sched.h>
57535+#include <linux/file.h>
57536+#include <linux/binfmts.h>
57537+#include <linux/fs.h>
57538+#include <linux/types.h>
57539+#include <linux/grdefs.h>
57540+#include <linux/grsecurity.h>
57541+#include <linux/grinternal.h>
57542+#include <linux/capability.h>
57543+#include <linux/module.h>
57544+
57545+#include <asm/uaccess.h>
57546+
57547+#ifdef CONFIG_GRKERNSEC_EXECLOG
57548+static char gr_exec_arg_buf[132];
57549+static DEFINE_MUTEX(gr_exec_arg_mutex);
57550+#endif
57551+
57552+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57553+
57554+void
57555+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57556+{
57557+#ifdef CONFIG_GRKERNSEC_EXECLOG
57558+ char *grarg = gr_exec_arg_buf;
57559+ unsigned int i, x, execlen = 0;
57560+ char c;
57561+
57562+ if (!((grsec_enable_execlog && grsec_enable_group &&
57563+ in_group_p(grsec_audit_gid))
57564+ || (grsec_enable_execlog && !grsec_enable_group)))
57565+ return;
57566+
57567+ mutex_lock(&gr_exec_arg_mutex);
57568+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
57569+
57570+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
57571+ const char __user *p;
57572+ unsigned int len;
57573+
57574+ p = get_user_arg_ptr(argv, i);
57575+ if (IS_ERR(p))
57576+ goto log;
57577+
57578+ len = strnlen_user(p, 128 - execlen);
57579+ if (len > 128 - execlen)
57580+ len = 128 - execlen;
57581+ else if (len > 0)
57582+ len--;
57583+ if (copy_from_user(grarg + execlen, p, len))
57584+ goto log;
57585+
57586+ /* rewrite unprintable characters */
57587+ for (x = 0; x < len; x++) {
57588+ c = *(grarg + execlen + x);
57589+ if (c < 32 || c > 126)
57590+ *(grarg + execlen + x) = ' ';
57591+ }
57592+
57593+ execlen += len;
57594+ *(grarg + execlen) = ' ';
57595+ *(grarg + execlen + 1) = '\0';
57596+ execlen++;
57597+ }
57598+
57599+ log:
57600+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57601+ bprm->file->f_path.mnt, grarg);
57602+ mutex_unlock(&gr_exec_arg_mutex);
57603+#endif
57604+ return;
57605+}
57606+
57607+#ifdef CONFIG_GRKERNSEC
57608+extern int gr_acl_is_capable(const int cap);
57609+extern int gr_acl_is_capable_nolog(const int cap);
57610+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57611+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57612+extern int gr_chroot_is_capable(const int cap);
57613+extern int gr_chroot_is_capable_nolog(const int cap);
57614+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57615+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57616+#endif
57617+
57618+const char *captab_log[] = {
57619+ "CAP_CHOWN",
57620+ "CAP_DAC_OVERRIDE",
57621+ "CAP_DAC_READ_SEARCH",
57622+ "CAP_FOWNER",
57623+ "CAP_FSETID",
57624+ "CAP_KILL",
57625+ "CAP_SETGID",
57626+ "CAP_SETUID",
57627+ "CAP_SETPCAP",
57628+ "CAP_LINUX_IMMUTABLE",
57629+ "CAP_NET_BIND_SERVICE",
57630+ "CAP_NET_BROADCAST",
57631+ "CAP_NET_ADMIN",
57632+ "CAP_NET_RAW",
57633+ "CAP_IPC_LOCK",
57634+ "CAP_IPC_OWNER",
57635+ "CAP_SYS_MODULE",
57636+ "CAP_SYS_RAWIO",
57637+ "CAP_SYS_CHROOT",
57638+ "CAP_SYS_PTRACE",
57639+ "CAP_SYS_PACCT",
57640+ "CAP_SYS_ADMIN",
57641+ "CAP_SYS_BOOT",
57642+ "CAP_SYS_NICE",
57643+ "CAP_SYS_RESOURCE",
57644+ "CAP_SYS_TIME",
57645+ "CAP_SYS_TTY_CONFIG",
57646+ "CAP_MKNOD",
57647+ "CAP_LEASE",
57648+ "CAP_AUDIT_WRITE",
57649+ "CAP_AUDIT_CONTROL",
57650+ "CAP_SETFCAP",
57651+ "CAP_MAC_OVERRIDE",
57652+ "CAP_MAC_ADMIN",
57653+ "CAP_SYSLOG",
57654+ "CAP_WAKE_ALARM"
57655+};
57656+
57657+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57658+
57659+int gr_is_capable(const int cap)
57660+{
57661+#ifdef CONFIG_GRKERNSEC
57662+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57663+ return 1;
57664+ return 0;
57665+#else
57666+ return 1;
57667+#endif
57668+}
57669+
57670+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57671+{
57672+#ifdef CONFIG_GRKERNSEC
57673+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57674+ return 1;
57675+ return 0;
57676+#else
57677+ return 1;
57678+#endif
57679+}
57680+
57681+int gr_is_capable_nolog(const int cap)
57682+{
57683+#ifdef CONFIG_GRKERNSEC
57684+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57685+ return 1;
57686+ return 0;
57687+#else
57688+ return 1;
57689+#endif
57690+}
57691+
57692+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57693+{
57694+#ifdef CONFIG_GRKERNSEC
57695+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57696+ return 1;
57697+ return 0;
57698+#else
57699+ return 1;
57700+#endif
57701+}
57702+
57703+EXPORT_SYMBOL(gr_is_capable);
57704+EXPORT_SYMBOL(gr_is_capable_nolog);
57705+EXPORT_SYMBOL(gr_task_is_capable);
57706+EXPORT_SYMBOL(gr_task_is_capable_nolog);
57707diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57708new file mode 100644
57709index 0000000..d3ee748
57710--- /dev/null
57711+++ b/grsecurity/grsec_fifo.c
57712@@ -0,0 +1,24 @@
57713+#include <linux/kernel.h>
57714+#include <linux/sched.h>
57715+#include <linux/fs.h>
57716+#include <linux/file.h>
57717+#include <linux/grinternal.h>
57718+
57719+int
57720+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57721+ const struct dentry *dir, const int flag, const int acc_mode)
57722+{
57723+#ifdef CONFIG_GRKERNSEC_FIFO
57724+ const struct cred *cred = current_cred();
57725+
57726+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57727+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57728+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57729+ (cred->fsuid != dentry->d_inode->i_uid)) {
57730+ if (!inode_permission(dentry->d_inode, acc_mode))
57731+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57732+ return -EACCES;
57733+ }
57734+#endif
57735+ return 0;
57736+}
57737diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57738new file mode 100644
57739index 0000000..8ca18bf
57740--- /dev/null
57741+++ b/grsecurity/grsec_fork.c
57742@@ -0,0 +1,23 @@
57743+#include <linux/kernel.h>
57744+#include <linux/sched.h>
57745+#include <linux/grsecurity.h>
57746+#include <linux/grinternal.h>
57747+#include <linux/errno.h>
57748+
57749+void
57750+gr_log_forkfail(const int retval)
57751+{
57752+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57753+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57754+ switch (retval) {
57755+ case -EAGAIN:
57756+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57757+ break;
57758+ case -ENOMEM:
57759+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57760+ break;
57761+ }
57762+ }
57763+#endif
57764+ return;
57765+}
57766diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57767new file mode 100644
57768index 0000000..05a6015
57769--- /dev/null
57770+++ b/grsecurity/grsec_init.c
57771@@ -0,0 +1,283 @@
57772+#include <linux/kernel.h>
57773+#include <linux/sched.h>
57774+#include <linux/mm.h>
57775+#include <linux/gracl.h>
57776+#include <linux/slab.h>
57777+#include <linux/vmalloc.h>
57778+#include <linux/percpu.h>
57779+#include <linux/module.h>
57780+
57781+int grsec_enable_ptrace_readexec;
57782+int grsec_enable_setxid;
57783+int grsec_enable_symlinkown;
57784+int grsec_symlinkown_gid;
57785+int grsec_enable_brute;
57786+int grsec_enable_link;
57787+int grsec_enable_dmesg;
57788+int grsec_enable_harden_ptrace;
57789+int grsec_enable_fifo;
57790+int grsec_enable_execlog;
57791+int grsec_enable_signal;
57792+int grsec_enable_forkfail;
57793+int grsec_enable_audit_ptrace;
57794+int grsec_enable_time;
57795+int grsec_enable_audit_textrel;
57796+int grsec_enable_group;
57797+int grsec_audit_gid;
57798+int grsec_enable_chdir;
57799+int grsec_enable_mount;
57800+int grsec_enable_rofs;
57801+int grsec_enable_chroot_findtask;
57802+int grsec_enable_chroot_mount;
57803+int grsec_enable_chroot_shmat;
57804+int grsec_enable_chroot_fchdir;
57805+int grsec_enable_chroot_double;
57806+int grsec_enable_chroot_pivot;
57807+int grsec_enable_chroot_chdir;
57808+int grsec_enable_chroot_chmod;
57809+int grsec_enable_chroot_mknod;
57810+int grsec_enable_chroot_nice;
57811+int grsec_enable_chroot_execlog;
57812+int grsec_enable_chroot_caps;
57813+int grsec_enable_chroot_sysctl;
57814+int grsec_enable_chroot_unix;
57815+int grsec_enable_tpe;
57816+int grsec_tpe_gid;
57817+int grsec_enable_blackhole;
57818+#ifdef CONFIG_IPV6_MODULE
57819+EXPORT_SYMBOL(grsec_enable_blackhole);
57820+#endif
57821+int grsec_lastack_retries;
57822+int grsec_enable_tpe_all;
57823+int grsec_enable_tpe_invert;
57824+int grsec_enable_socket_all;
57825+int grsec_socket_all_gid;
57826+int grsec_enable_socket_client;
57827+int grsec_socket_client_gid;
57828+int grsec_enable_socket_server;
57829+int grsec_socket_server_gid;
57830+int grsec_resource_logging;
57831+int grsec_disable_privio;
57832+int grsec_enable_log_rwxmaps;
57833+int grsec_lock;
57834+
57835+DEFINE_SPINLOCK(grsec_alert_lock);
57836+unsigned long grsec_alert_wtime = 0;
57837+unsigned long grsec_alert_fyet = 0;
57838+
57839+DEFINE_SPINLOCK(grsec_audit_lock);
57840+
57841+DEFINE_RWLOCK(grsec_exec_file_lock);
57842+
57843+char *gr_shared_page[4];
57844+
57845+char *gr_alert_log_fmt;
57846+char *gr_audit_log_fmt;
57847+char *gr_alert_log_buf;
57848+char *gr_audit_log_buf;
57849+
57850+extern struct gr_arg *gr_usermode;
57851+extern unsigned char *gr_system_salt;
57852+extern unsigned char *gr_system_sum;
57853+
57854+void __init
57855+grsecurity_init(void)
57856+{
57857+ int j;
57858+ /* create the per-cpu shared pages */
57859+
57860+#ifdef CONFIG_X86
57861+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57862+#endif
57863+
57864+ for (j = 0; j < 4; j++) {
57865+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57866+ if (gr_shared_page[j] == NULL) {
57867+ panic("Unable to allocate grsecurity shared page");
57868+ return;
57869+ }
57870+ }
57871+
57872+ /* allocate log buffers */
57873+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57874+ if (!gr_alert_log_fmt) {
57875+ panic("Unable to allocate grsecurity alert log format buffer");
57876+ return;
57877+ }
57878+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57879+ if (!gr_audit_log_fmt) {
57880+ panic("Unable to allocate grsecurity audit log format buffer");
57881+ return;
57882+ }
57883+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57884+ if (!gr_alert_log_buf) {
57885+ panic("Unable to allocate grsecurity alert log buffer");
57886+ return;
57887+ }
57888+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57889+ if (!gr_audit_log_buf) {
57890+ panic("Unable to allocate grsecurity audit log buffer");
57891+ return;
57892+ }
57893+
57894+ /* allocate memory for authentication structure */
57895+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57896+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57897+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57898+
57899+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57900+ panic("Unable to allocate grsecurity authentication structure");
57901+ return;
57902+ }
57903+
57904+
57905+#ifdef CONFIG_GRKERNSEC_IO
57906+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57907+ grsec_disable_privio = 1;
57908+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57909+ grsec_disable_privio = 1;
57910+#else
57911+ grsec_disable_privio = 0;
57912+#endif
57913+#endif
57914+
57915+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57916+ /* for backward compatibility, tpe_invert always defaults to on if
57917+ enabled in the kernel
57918+ */
57919+ grsec_enable_tpe_invert = 1;
57920+#endif
57921+
57922+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57923+#ifndef CONFIG_GRKERNSEC_SYSCTL
57924+ grsec_lock = 1;
57925+#endif
57926+
57927+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57928+ grsec_enable_audit_textrel = 1;
57929+#endif
57930+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57931+ grsec_enable_log_rwxmaps = 1;
57932+#endif
57933+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57934+ grsec_enable_group = 1;
57935+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57936+#endif
57937+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57938+ grsec_enable_ptrace_readexec = 1;
57939+#endif
57940+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57941+ grsec_enable_chdir = 1;
57942+#endif
57943+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57944+ grsec_enable_harden_ptrace = 1;
57945+#endif
57946+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57947+ grsec_enable_mount = 1;
57948+#endif
57949+#ifdef CONFIG_GRKERNSEC_LINK
57950+ grsec_enable_link = 1;
57951+#endif
57952+#ifdef CONFIG_GRKERNSEC_BRUTE
57953+ grsec_enable_brute = 1;
57954+#endif
57955+#ifdef CONFIG_GRKERNSEC_DMESG
57956+ grsec_enable_dmesg = 1;
57957+#endif
57958+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57959+ grsec_enable_blackhole = 1;
57960+ grsec_lastack_retries = 4;
57961+#endif
57962+#ifdef CONFIG_GRKERNSEC_FIFO
57963+ grsec_enable_fifo = 1;
57964+#endif
57965+#ifdef CONFIG_GRKERNSEC_EXECLOG
57966+ grsec_enable_execlog = 1;
57967+#endif
57968+#ifdef CONFIG_GRKERNSEC_SETXID
57969+ grsec_enable_setxid = 1;
57970+#endif
57971+#ifdef CONFIG_GRKERNSEC_SIGNAL
57972+ grsec_enable_signal = 1;
57973+#endif
57974+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57975+ grsec_enable_forkfail = 1;
57976+#endif
57977+#ifdef CONFIG_GRKERNSEC_TIME
57978+ grsec_enable_time = 1;
57979+#endif
57980+#ifdef CONFIG_GRKERNSEC_RESLOG
57981+ grsec_resource_logging = 1;
57982+#endif
57983+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57984+ grsec_enable_chroot_findtask = 1;
57985+#endif
57986+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57987+ grsec_enable_chroot_unix = 1;
57988+#endif
57989+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57990+ grsec_enable_chroot_mount = 1;
57991+#endif
57992+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57993+ grsec_enable_chroot_fchdir = 1;
57994+#endif
57995+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57996+ grsec_enable_chroot_shmat = 1;
57997+#endif
57998+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57999+ grsec_enable_audit_ptrace = 1;
58000+#endif
58001+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58002+ grsec_enable_chroot_double = 1;
58003+#endif
58004+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58005+ grsec_enable_chroot_pivot = 1;
58006+#endif
58007+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58008+ grsec_enable_chroot_chdir = 1;
58009+#endif
58010+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58011+ grsec_enable_chroot_chmod = 1;
58012+#endif
58013+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58014+ grsec_enable_chroot_mknod = 1;
58015+#endif
58016+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58017+ grsec_enable_chroot_nice = 1;
58018+#endif
58019+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58020+ grsec_enable_chroot_execlog = 1;
58021+#endif
58022+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58023+ grsec_enable_chroot_caps = 1;
58024+#endif
58025+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58026+ grsec_enable_chroot_sysctl = 1;
58027+#endif
58028+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58029+ grsec_enable_symlinkown = 1;
58030+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58031+#endif
58032+#ifdef CONFIG_GRKERNSEC_TPE
58033+ grsec_enable_tpe = 1;
58034+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58035+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58036+ grsec_enable_tpe_all = 1;
58037+#endif
58038+#endif
58039+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58040+ grsec_enable_socket_all = 1;
58041+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58042+#endif
58043+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58044+ grsec_enable_socket_client = 1;
58045+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58046+#endif
58047+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58048+ grsec_enable_socket_server = 1;
58049+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58050+#endif
58051+#endif
58052+
58053+ return;
58054+}
58055diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58056new file mode 100644
58057index 0000000..551a2e7
58058--- /dev/null
58059+++ b/grsecurity/grsec_link.c
58060@@ -0,0 +1,59 @@
58061+#include <linux/kernel.h>
58062+#include <linux/sched.h>
58063+#include <linux/fs.h>
58064+#include <linux/file.h>
58065+#include <linux/grinternal.h>
58066+
58067+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58068+{
58069+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58070+ const struct inode *link_inode = link->dentry->d_inode;
58071+
58072+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58073+ /* ignore root-owned links, e.g. /proc/self */
58074+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) &&
58075+ !uid_eq(link_inode->i_uid, target->i_uid)) {
58076+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58077+ return 1;
58078+ }
58079+#endif
58080+ return 0;
58081+}
58082+
58083+int
58084+gr_handle_follow_link(const struct inode *parent,
58085+ const struct inode *inode,
58086+ const struct dentry *dentry, const struct vfsmount *mnt)
58087+{
58088+#ifdef CONFIG_GRKERNSEC_LINK
58089+ const struct cred *cred = current_cred();
58090+
58091+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58092+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58093+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58094+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58095+ return -EACCES;
58096+ }
58097+#endif
58098+ return 0;
58099+}
58100+
58101+int
58102+gr_handle_hardlink(const struct dentry *dentry,
58103+ const struct vfsmount *mnt,
58104+ struct inode *inode, const int mode, const char *to)
58105+{
58106+#ifdef CONFIG_GRKERNSEC_LINK
58107+ const struct cred *cred = current_cred();
58108+
58109+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58110+ (!S_ISREG(mode) || (mode & S_ISUID) ||
58111+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
58112+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58113+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58114+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58115+ return -EPERM;
58116+ }
58117+#endif
58118+ return 0;
58119+}
58120diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58121new file mode 100644
58122index 0000000..a45d2e9
58123--- /dev/null
58124+++ b/grsecurity/grsec_log.c
58125@@ -0,0 +1,322 @@
58126+#include <linux/kernel.h>
58127+#include <linux/sched.h>
58128+#include <linux/file.h>
58129+#include <linux/tty.h>
58130+#include <linux/fs.h>
58131+#include <linux/grinternal.h>
58132+
58133+#ifdef CONFIG_TREE_PREEMPT_RCU
58134+#define DISABLE_PREEMPT() preempt_disable()
58135+#define ENABLE_PREEMPT() preempt_enable()
58136+#else
58137+#define DISABLE_PREEMPT()
58138+#define ENABLE_PREEMPT()
58139+#endif
58140+
58141+#define BEGIN_LOCKS(x) \
58142+ DISABLE_PREEMPT(); \
58143+ rcu_read_lock(); \
58144+ read_lock(&tasklist_lock); \
58145+ read_lock(&grsec_exec_file_lock); \
58146+ if (x != GR_DO_AUDIT) \
58147+ spin_lock(&grsec_alert_lock); \
58148+ else \
58149+ spin_lock(&grsec_audit_lock)
58150+
58151+#define END_LOCKS(x) \
58152+ if (x != GR_DO_AUDIT) \
58153+ spin_unlock(&grsec_alert_lock); \
58154+ else \
58155+ spin_unlock(&grsec_audit_lock); \
58156+ read_unlock(&grsec_exec_file_lock); \
58157+ read_unlock(&tasklist_lock); \
58158+ rcu_read_unlock(); \
58159+ ENABLE_PREEMPT(); \
58160+ if (x == GR_DONT_AUDIT) \
58161+ gr_handle_alertkill(current)
58162+
58163+enum {
58164+ FLOODING,
58165+ NO_FLOODING
58166+};
58167+
58168+extern char *gr_alert_log_fmt;
58169+extern char *gr_audit_log_fmt;
58170+extern char *gr_alert_log_buf;
58171+extern char *gr_audit_log_buf;
58172+
58173+static int gr_log_start(int audit)
58174+{
58175+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58176+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58177+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58178+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58179+ unsigned long curr_secs = get_seconds();
58180+
58181+ if (audit == GR_DO_AUDIT)
58182+ goto set_fmt;
58183+
58184+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58185+ grsec_alert_wtime = curr_secs;
58186+ grsec_alert_fyet = 0;
58187+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58188+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58189+ grsec_alert_fyet++;
58190+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58191+ grsec_alert_wtime = curr_secs;
58192+ grsec_alert_fyet++;
58193+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58194+ return FLOODING;
58195+ }
58196+ else return FLOODING;
58197+
58198+set_fmt:
58199+#endif
58200+ memset(buf, 0, PAGE_SIZE);
58201+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
58202+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58203+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58204+ } else if (current->signal->curr_ip) {
58205+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58206+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58207+ } else if (gr_acl_is_enabled()) {
58208+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58209+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58210+ } else {
58211+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
58212+ strcpy(buf, fmt);
58213+ }
58214+
58215+ return NO_FLOODING;
58216+}
58217+
58218+static void gr_log_middle(int audit, const char *msg, va_list ap)
58219+ __attribute__ ((format (printf, 2, 0)));
58220+
58221+static void gr_log_middle(int audit, const char *msg, va_list ap)
58222+{
58223+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58224+ unsigned int len = strlen(buf);
58225+
58226+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58227+
58228+ return;
58229+}
58230+
58231+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58232+ __attribute__ ((format (printf, 2, 3)));
58233+
58234+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58235+{
58236+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58237+ unsigned int len = strlen(buf);
58238+ va_list ap;
58239+
58240+ va_start(ap, msg);
58241+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58242+ va_end(ap);
58243+
58244+ return;
58245+}
58246+
58247+static void gr_log_end(int audit, int append_default)
58248+{
58249+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58250+
58251+ if (append_default) {
58252+ unsigned int len = strlen(buf);
58253+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58254+ }
58255+
58256+ printk("%s\n", buf);
58257+
58258+ return;
58259+}
58260+
58261+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58262+{
58263+ int logtype;
58264+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58265+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58266+ void *voidptr = NULL;
58267+ int num1 = 0, num2 = 0;
58268+ unsigned long ulong1 = 0, ulong2 = 0;
58269+ struct dentry *dentry = NULL;
58270+ struct vfsmount *mnt = NULL;
58271+ struct file *file = NULL;
58272+ struct task_struct *task = NULL;
58273+ const struct cred *cred, *pcred;
58274+ va_list ap;
58275+
58276+ BEGIN_LOCKS(audit);
58277+ logtype = gr_log_start(audit);
58278+ if (logtype == FLOODING) {
58279+ END_LOCKS(audit);
58280+ return;
58281+ }
58282+ va_start(ap, argtypes);
58283+ switch (argtypes) {
58284+ case GR_TTYSNIFF:
58285+ task = va_arg(ap, struct task_struct *);
58286+ 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);
58287+ break;
58288+ case GR_SYSCTL_HIDDEN:
58289+ str1 = va_arg(ap, char *);
58290+ gr_log_middle_varargs(audit, msg, result, str1);
58291+ break;
58292+ case GR_RBAC:
58293+ dentry = va_arg(ap, struct dentry *);
58294+ mnt = va_arg(ap, struct vfsmount *);
58295+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58296+ break;
58297+ case GR_RBAC_STR:
58298+ dentry = va_arg(ap, struct dentry *);
58299+ mnt = va_arg(ap, struct vfsmount *);
58300+ str1 = va_arg(ap, char *);
58301+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58302+ break;
58303+ case GR_STR_RBAC:
58304+ str1 = va_arg(ap, char *);
58305+ dentry = va_arg(ap, struct dentry *);
58306+ mnt = va_arg(ap, struct vfsmount *);
58307+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58308+ break;
58309+ case GR_RBAC_MODE2:
58310+ dentry = va_arg(ap, struct dentry *);
58311+ mnt = va_arg(ap, struct vfsmount *);
58312+ str1 = va_arg(ap, char *);
58313+ str2 = va_arg(ap, char *);
58314+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58315+ break;
58316+ case GR_RBAC_MODE3:
58317+ dentry = va_arg(ap, struct dentry *);
58318+ mnt = va_arg(ap, struct vfsmount *);
58319+ str1 = va_arg(ap, char *);
58320+ str2 = va_arg(ap, char *);
58321+ str3 = va_arg(ap, char *);
58322+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58323+ break;
58324+ case GR_FILENAME:
58325+ dentry = va_arg(ap, struct dentry *);
58326+ mnt = va_arg(ap, struct vfsmount *);
58327+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58328+ break;
58329+ case GR_STR_FILENAME:
58330+ str1 = va_arg(ap, char *);
58331+ dentry = va_arg(ap, struct dentry *);
58332+ mnt = va_arg(ap, struct vfsmount *);
58333+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58334+ break;
58335+ case GR_FILENAME_STR:
58336+ dentry = va_arg(ap, struct dentry *);
58337+ mnt = va_arg(ap, struct vfsmount *);
58338+ str1 = va_arg(ap, char *);
58339+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58340+ break;
58341+ case GR_FILENAME_TWO_INT:
58342+ dentry = va_arg(ap, struct dentry *);
58343+ mnt = va_arg(ap, struct vfsmount *);
58344+ num1 = va_arg(ap, int);
58345+ num2 = va_arg(ap, int);
58346+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58347+ break;
58348+ case GR_FILENAME_TWO_INT_STR:
58349+ dentry = va_arg(ap, struct dentry *);
58350+ mnt = va_arg(ap, struct vfsmount *);
58351+ num1 = va_arg(ap, int);
58352+ num2 = va_arg(ap, int);
58353+ str1 = va_arg(ap, char *);
58354+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58355+ break;
58356+ case GR_TEXTREL:
58357+ file = va_arg(ap, struct file *);
58358+ ulong1 = va_arg(ap, unsigned long);
58359+ ulong2 = va_arg(ap, unsigned long);
58360+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58361+ break;
58362+ case GR_PTRACE:
58363+ task = va_arg(ap, struct task_struct *);
58364+ 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);
58365+ break;
58366+ case GR_RESOURCE:
58367+ task = va_arg(ap, struct task_struct *);
58368+ cred = __task_cred(task);
58369+ pcred = __task_cred(task->real_parent);
58370+ ulong1 = va_arg(ap, unsigned long);
58371+ str1 = va_arg(ap, char *);
58372+ ulong2 = va_arg(ap, unsigned long);
58373+ 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);
58374+ break;
58375+ case GR_CAP:
58376+ task = va_arg(ap, struct task_struct *);
58377+ cred = __task_cred(task);
58378+ pcred = __task_cred(task->real_parent);
58379+ str1 = va_arg(ap, char *);
58380+ 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);
58381+ break;
58382+ case GR_SIG:
58383+ str1 = va_arg(ap, char *);
58384+ voidptr = va_arg(ap, void *);
58385+ gr_log_middle_varargs(audit, msg, str1, voidptr);
58386+ break;
58387+ case GR_SIG2:
58388+ task = va_arg(ap, struct task_struct *);
58389+ cred = __task_cred(task);
58390+ pcred = __task_cred(task->real_parent);
58391+ num1 = va_arg(ap, int);
58392+ 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);
58393+ break;
58394+ case GR_CRASH1:
58395+ task = va_arg(ap, struct task_struct *);
58396+ cred = __task_cred(task);
58397+ pcred = __task_cred(task->real_parent);
58398+ ulong1 = va_arg(ap, unsigned long);
58399+ 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);
58400+ break;
58401+ case GR_CRASH2:
58402+ task = va_arg(ap, struct task_struct *);
58403+ cred = __task_cred(task);
58404+ pcred = __task_cred(task->real_parent);
58405+ ulong1 = va_arg(ap, unsigned long);
58406+ 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);
58407+ break;
58408+ case GR_RWXMAP:
58409+ file = va_arg(ap, struct file *);
58410+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58411+ break;
58412+ case GR_PSACCT:
58413+ {
58414+ unsigned int wday, cday;
58415+ __u8 whr, chr;
58416+ __u8 wmin, cmin;
58417+ __u8 wsec, csec;
58418+ char cur_tty[64] = { 0 };
58419+ char parent_tty[64] = { 0 };
58420+
58421+ task = va_arg(ap, struct task_struct *);
58422+ wday = va_arg(ap, unsigned int);
58423+ cday = va_arg(ap, unsigned int);
58424+ whr = va_arg(ap, int);
58425+ chr = va_arg(ap, int);
58426+ wmin = va_arg(ap, int);
58427+ cmin = va_arg(ap, int);
58428+ wsec = va_arg(ap, int);
58429+ csec = va_arg(ap, int);
58430+ ulong1 = va_arg(ap, unsigned long);
58431+ cred = __task_cred(task);
58432+ pcred = __task_cred(task->real_parent);
58433+
58434+ 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);
58435+ }
58436+ break;
58437+ default:
58438+ gr_log_middle(audit, msg, ap);
58439+ }
58440+ va_end(ap);
58441+ // these don't need DEFAULTSECARGS printed on the end
58442+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58443+ gr_log_end(audit, 0);
58444+ else
58445+ gr_log_end(audit, 1);
58446+ END_LOCKS(audit);
58447+}
58448diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58449new file mode 100644
58450index 0000000..f536303
58451--- /dev/null
58452+++ b/grsecurity/grsec_mem.c
58453@@ -0,0 +1,40 @@
58454+#include <linux/kernel.h>
58455+#include <linux/sched.h>
58456+#include <linux/mm.h>
58457+#include <linux/mman.h>
58458+#include <linux/grinternal.h>
58459+
58460+void
58461+gr_handle_ioperm(void)
58462+{
58463+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58464+ return;
58465+}
58466+
58467+void
58468+gr_handle_iopl(void)
58469+{
58470+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58471+ return;
58472+}
58473+
58474+void
58475+gr_handle_mem_readwrite(u64 from, u64 to)
58476+{
58477+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58478+ return;
58479+}
58480+
58481+void
58482+gr_handle_vm86(void)
58483+{
58484+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58485+ return;
58486+}
58487+
58488+void
58489+gr_log_badprocpid(const char *entry)
58490+{
58491+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58492+ return;
58493+}
58494diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58495new file mode 100644
58496index 0000000..2131422
58497--- /dev/null
58498+++ b/grsecurity/grsec_mount.c
58499@@ -0,0 +1,62 @@
58500+#include <linux/kernel.h>
58501+#include <linux/sched.h>
58502+#include <linux/mount.h>
58503+#include <linux/grsecurity.h>
58504+#include <linux/grinternal.h>
58505+
58506+void
58507+gr_log_remount(const char *devname, const int retval)
58508+{
58509+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58510+ if (grsec_enable_mount && (retval >= 0))
58511+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58512+#endif
58513+ return;
58514+}
58515+
58516+void
58517+gr_log_unmount(const char *devname, const int retval)
58518+{
58519+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58520+ if (grsec_enable_mount && (retval >= 0))
58521+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58522+#endif
58523+ return;
58524+}
58525+
58526+void
58527+gr_log_mount(const char *from, const char *to, const int retval)
58528+{
58529+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58530+ if (grsec_enable_mount && (retval >= 0))
58531+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58532+#endif
58533+ return;
58534+}
58535+
58536+int
58537+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58538+{
58539+#ifdef CONFIG_GRKERNSEC_ROFS
58540+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58541+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58542+ return -EPERM;
58543+ } else
58544+ return 0;
58545+#endif
58546+ return 0;
58547+}
58548+
58549+int
58550+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58551+{
58552+#ifdef CONFIG_GRKERNSEC_ROFS
58553+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58554+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58555+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58556+ return -EPERM;
58557+ } else
58558+ return 0;
58559+#endif
58560+ return 0;
58561+}
58562diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58563new file mode 100644
58564index 0000000..a3b12a0
58565--- /dev/null
58566+++ b/grsecurity/grsec_pax.c
58567@@ -0,0 +1,36 @@
58568+#include <linux/kernel.h>
58569+#include <linux/sched.h>
58570+#include <linux/mm.h>
58571+#include <linux/file.h>
58572+#include <linux/grinternal.h>
58573+#include <linux/grsecurity.h>
58574+
58575+void
58576+gr_log_textrel(struct vm_area_struct * vma)
58577+{
58578+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58579+ if (grsec_enable_audit_textrel)
58580+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58581+#endif
58582+ return;
58583+}
58584+
58585+void
58586+gr_log_rwxmmap(struct file *file)
58587+{
58588+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58589+ if (grsec_enable_log_rwxmaps)
58590+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58591+#endif
58592+ return;
58593+}
58594+
58595+void
58596+gr_log_rwxmprotect(struct file *file)
58597+{
58598+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58599+ if (grsec_enable_log_rwxmaps)
58600+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58601+#endif
58602+ return;
58603+}
58604diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58605new file mode 100644
58606index 0000000..f7f29aa
58607--- /dev/null
58608+++ b/grsecurity/grsec_ptrace.c
58609@@ -0,0 +1,30 @@
58610+#include <linux/kernel.h>
58611+#include <linux/sched.h>
58612+#include <linux/grinternal.h>
58613+#include <linux/security.h>
58614+
58615+void
58616+gr_audit_ptrace(struct task_struct *task)
58617+{
58618+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58619+ if (grsec_enable_audit_ptrace)
58620+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58621+#endif
58622+ return;
58623+}
58624+
58625+int
58626+gr_ptrace_readexec(struct file *file, int unsafe_flags)
58627+{
58628+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58629+ const struct dentry *dentry = file->f_path.dentry;
58630+ const struct vfsmount *mnt = file->f_path.mnt;
58631+
58632+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58633+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58634+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58635+ return -EACCES;
58636+ }
58637+#endif
58638+ return 0;
58639+}
58640diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58641new file mode 100644
58642index 0000000..b4ac94c
58643--- /dev/null
58644+++ b/grsecurity/grsec_sig.c
58645@@ -0,0 +1,209 @@
58646+#include <linux/kernel.h>
58647+#include <linux/sched.h>
58648+#include <linux/delay.h>
58649+#include <linux/grsecurity.h>
58650+#include <linux/grinternal.h>
58651+#include <linux/hardirq.h>
58652+
58653+char *signames[] = {
58654+ [SIGSEGV] = "Segmentation fault",
58655+ [SIGILL] = "Illegal instruction",
58656+ [SIGABRT] = "Abort",
58657+ [SIGBUS] = "Invalid alignment/Bus error"
58658+};
58659+
58660+void
58661+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58662+{
58663+#ifdef CONFIG_GRKERNSEC_SIGNAL
58664+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58665+ (sig == SIGABRT) || (sig == SIGBUS))) {
58666+ if (t->pid == current->pid) {
58667+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58668+ } else {
58669+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58670+ }
58671+ }
58672+#endif
58673+ return;
58674+}
58675+
58676+int
58677+gr_handle_signal(const struct task_struct *p, const int sig)
58678+{
58679+#ifdef CONFIG_GRKERNSEC
58680+ /* ignore the 0 signal for protected task checks */
58681+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58682+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58683+ return -EPERM;
58684+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58685+ return -EPERM;
58686+ }
58687+#endif
58688+ return 0;
58689+}
58690+
58691+#ifdef CONFIG_GRKERNSEC
58692+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58693+
58694+int gr_fake_force_sig(int sig, struct task_struct *t)
58695+{
58696+ unsigned long int flags;
58697+ int ret, blocked, ignored;
58698+ struct k_sigaction *action;
58699+
58700+ spin_lock_irqsave(&t->sighand->siglock, flags);
58701+ action = &t->sighand->action[sig-1];
58702+ ignored = action->sa.sa_handler == SIG_IGN;
58703+ blocked = sigismember(&t->blocked, sig);
58704+ if (blocked || ignored) {
58705+ action->sa.sa_handler = SIG_DFL;
58706+ if (blocked) {
58707+ sigdelset(&t->blocked, sig);
58708+ recalc_sigpending_and_wake(t);
58709+ }
58710+ }
58711+ if (action->sa.sa_handler == SIG_DFL)
58712+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
58713+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58714+
58715+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
58716+
58717+ return ret;
58718+}
58719+#endif
58720+
58721+#ifdef CONFIG_GRKERNSEC_BRUTE
58722+#define GR_USER_BAN_TIME (15 * 60)
58723+
58724+static int __get_dumpable(unsigned long mm_flags)
58725+{
58726+ int ret;
58727+
58728+ ret = mm_flags & MMF_DUMPABLE_MASK;
58729+ return (ret >= 2) ? 2 : ret;
58730+}
58731+#endif
58732+
58733+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58734+{
58735+#ifdef CONFIG_GRKERNSEC_BRUTE
58736+ kuid_t uid = GLOBAL_ROOT_UID;
58737+
58738+ if (!grsec_enable_brute)
58739+ return;
58740+
58741+ rcu_read_lock();
58742+ read_lock(&tasklist_lock);
58743+ read_lock(&grsec_exec_file_lock);
58744+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58745+ p->real_parent->brute = 1;
58746+ else {
58747+ const struct cred *cred = __task_cred(p), *cred2;
58748+ struct task_struct *tsk, *tsk2;
58749+
58750+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58751+ struct user_struct *user;
58752+
58753+ uid = cred->uid;
58754+
58755+ /* this is put upon execution past expiration */
58756+ user = find_user(uid);
58757+ if (user == NULL)
58758+ goto unlock;
58759+ user->banned = 1;
58760+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58761+ if (user->ban_expires == ~0UL)
58762+ user->ban_expires--;
58763+
58764+ do_each_thread(tsk2, tsk) {
58765+ cred2 = __task_cred(tsk);
58766+ if (tsk != p && uid_eq(cred2->uid, uid))
58767+ gr_fake_force_sig(SIGKILL, tsk);
58768+ } while_each_thread(tsk2, tsk);
58769+ }
58770+ }
58771+unlock:
58772+ read_unlock(&grsec_exec_file_lock);
58773+ read_unlock(&tasklist_lock);
58774+ rcu_read_unlock();
58775+
58776+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
58777+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
58778+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
58779+
58780+#endif
58781+ return;
58782+}
58783+
58784+void gr_handle_brute_check(void)
58785+{
58786+#ifdef CONFIG_GRKERNSEC_BRUTE
58787+ if (current->brute)
58788+ msleep(30 * 1000);
58789+#endif
58790+ return;
58791+}
58792+
58793+void gr_handle_kernel_exploit(void)
58794+{
58795+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58796+ const struct cred *cred;
58797+ struct task_struct *tsk, *tsk2;
58798+ struct user_struct *user;
58799+ kuid_t uid;
58800+
58801+ if (in_irq() || in_serving_softirq() || in_nmi())
58802+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58803+
58804+ uid = current_uid();
58805+
58806+ if (uid_eq(uid, GLOBAL_ROOT_UID))
58807+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
58808+ else {
58809+ /* kill all the processes of this user, hold a reference
58810+ to their creds struct, and prevent them from creating
58811+ another process until system reset
58812+ */
58813+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
58814+ from_kuid_munged(&init_user_ns, uid));
58815+ /* we intentionally leak this ref */
58816+ user = get_uid(current->cred->user);
58817+ if (user) {
58818+ user->banned = 1;
58819+ user->ban_expires = ~0UL;
58820+ }
58821+
58822+ read_lock(&tasklist_lock);
58823+ do_each_thread(tsk2, tsk) {
58824+ cred = __task_cred(tsk);
58825+ if (uid_eq(cred->uid, uid))
58826+ gr_fake_force_sig(SIGKILL, tsk);
58827+ } while_each_thread(tsk2, tsk);
58828+ read_unlock(&tasklist_lock);
58829+ }
58830+#endif
58831+}
58832+
58833+int __gr_process_user_ban(struct user_struct *user)
58834+{
58835+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58836+ if (unlikely(user->banned)) {
58837+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58838+ user->banned = 0;
58839+ user->ban_expires = 0;
58840+ free_uid(user);
58841+ } else
58842+ return -EPERM;
58843+ }
58844+#endif
58845+ return 0;
58846+}
58847+
58848+int gr_process_user_ban(void)
58849+{
58850+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58851+ return __gr_process_user_ban(current->cred->user);
58852+#endif
58853+ return 0;
58854+}
58855diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58856new file mode 100644
58857index 0000000..4030d57
58858--- /dev/null
58859+++ b/grsecurity/grsec_sock.c
58860@@ -0,0 +1,244 @@
58861+#include <linux/kernel.h>
58862+#include <linux/module.h>
58863+#include <linux/sched.h>
58864+#include <linux/file.h>
58865+#include <linux/net.h>
58866+#include <linux/in.h>
58867+#include <linux/ip.h>
58868+#include <net/sock.h>
58869+#include <net/inet_sock.h>
58870+#include <linux/grsecurity.h>
58871+#include <linux/grinternal.h>
58872+#include <linux/gracl.h>
58873+
58874+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58875+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58876+
58877+EXPORT_SYMBOL(gr_search_udp_recvmsg);
58878+EXPORT_SYMBOL(gr_search_udp_sendmsg);
58879+
58880+#ifdef CONFIG_UNIX_MODULE
58881+EXPORT_SYMBOL(gr_acl_handle_unix);
58882+EXPORT_SYMBOL(gr_acl_handle_mknod);
58883+EXPORT_SYMBOL(gr_handle_chroot_unix);
58884+EXPORT_SYMBOL(gr_handle_create);
58885+#endif
58886+
58887+#ifdef CONFIG_GRKERNSEC
58888+#define gr_conn_table_size 32749
58889+struct conn_table_entry {
58890+ struct conn_table_entry *next;
58891+ struct signal_struct *sig;
58892+};
58893+
58894+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58895+DEFINE_SPINLOCK(gr_conn_table_lock);
58896+
58897+extern const char * gr_socktype_to_name(unsigned char type);
58898+extern const char * gr_proto_to_name(unsigned char proto);
58899+extern const char * gr_sockfamily_to_name(unsigned char family);
58900+
58901+static __inline__ int
58902+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58903+{
58904+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58905+}
58906+
58907+static __inline__ int
58908+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58909+ __u16 sport, __u16 dport)
58910+{
58911+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58912+ sig->gr_sport == sport && sig->gr_dport == dport))
58913+ return 1;
58914+ else
58915+ return 0;
58916+}
58917+
58918+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58919+{
58920+ struct conn_table_entry **match;
58921+ unsigned int index;
58922+
58923+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58924+ sig->gr_sport, sig->gr_dport,
58925+ gr_conn_table_size);
58926+
58927+ newent->sig = sig;
58928+
58929+ match = &gr_conn_table[index];
58930+ newent->next = *match;
58931+ *match = newent;
58932+
58933+ return;
58934+}
58935+
58936+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58937+{
58938+ struct conn_table_entry *match, *last = NULL;
58939+ unsigned int index;
58940+
58941+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58942+ sig->gr_sport, sig->gr_dport,
58943+ gr_conn_table_size);
58944+
58945+ match = gr_conn_table[index];
58946+ while (match && !conn_match(match->sig,
58947+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58948+ sig->gr_dport)) {
58949+ last = match;
58950+ match = match->next;
58951+ }
58952+
58953+ if (match) {
58954+ if (last)
58955+ last->next = match->next;
58956+ else
58957+ gr_conn_table[index] = NULL;
58958+ kfree(match);
58959+ }
58960+
58961+ return;
58962+}
58963+
58964+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58965+ __u16 sport, __u16 dport)
58966+{
58967+ struct conn_table_entry *match;
58968+ unsigned int index;
58969+
58970+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58971+
58972+ match = gr_conn_table[index];
58973+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58974+ match = match->next;
58975+
58976+ if (match)
58977+ return match->sig;
58978+ else
58979+ return NULL;
58980+}
58981+
58982+#endif
58983+
58984+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58985+{
58986+#ifdef CONFIG_GRKERNSEC
58987+ struct signal_struct *sig = task->signal;
58988+ struct conn_table_entry *newent;
58989+
58990+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58991+ if (newent == NULL)
58992+ return;
58993+ /* no bh lock needed since we are called with bh disabled */
58994+ spin_lock(&gr_conn_table_lock);
58995+ gr_del_task_from_ip_table_nolock(sig);
58996+ sig->gr_saddr = inet->inet_rcv_saddr;
58997+ sig->gr_daddr = inet->inet_daddr;
58998+ sig->gr_sport = inet->inet_sport;
58999+ sig->gr_dport = inet->inet_dport;
59000+ gr_add_to_task_ip_table_nolock(sig, newent);
59001+ spin_unlock(&gr_conn_table_lock);
59002+#endif
59003+ return;
59004+}
59005+
59006+void gr_del_task_from_ip_table(struct task_struct *task)
59007+{
59008+#ifdef CONFIG_GRKERNSEC
59009+ spin_lock_bh(&gr_conn_table_lock);
59010+ gr_del_task_from_ip_table_nolock(task->signal);
59011+ spin_unlock_bh(&gr_conn_table_lock);
59012+#endif
59013+ return;
59014+}
59015+
59016+void
59017+gr_attach_curr_ip(const struct sock *sk)
59018+{
59019+#ifdef CONFIG_GRKERNSEC
59020+ struct signal_struct *p, *set;
59021+ const struct inet_sock *inet = inet_sk(sk);
59022+
59023+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59024+ return;
59025+
59026+ set = current->signal;
59027+
59028+ spin_lock_bh(&gr_conn_table_lock);
59029+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59030+ inet->inet_dport, inet->inet_sport);
59031+ if (unlikely(p != NULL)) {
59032+ set->curr_ip = p->curr_ip;
59033+ set->used_accept = 1;
59034+ gr_del_task_from_ip_table_nolock(p);
59035+ spin_unlock_bh(&gr_conn_table_lock);
59036+ return;
59037+ }
59038+ spin_unlock_bh(&gr_conn_table_lock);
59039+
59040+ set->curr_ip = inet->inet_daddr;
59041+ set->used_accept = 1;
59042+#endif
59043+ return;
59044+}
59045+
59046+int
59047+gr_handle_sock_all(const int family, const int type, const int protocol)
59048+{
59049+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59050+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59051+ (family != AF_UNIX)) {
59052+ if (family == AF_INET)
59053+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59054+ else
59055+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59056+ return -EACCES;
59057+ }
59058+#endif
59059+ return 0;
59060+}
59061+
59062+int
59063+gr_handle_sock_server(const struct sockaddr *sck)
59064+{
59065+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59066+ if (grsec_enable_socket_server &&
59067+ in_group_p(grsec_socket_server_gid) &&
59068+ sck && (sck->sa_family != AF_UNIX) &&
59069+ (sck->sa_family != AF_LOCAL)) {
59070+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59071+ return -EACCES;
59072+ }
59073+#endif
59074+ return 0;
59075+}
59076+
59077+int
59078+gr_handle_sock_server_other(const struct sock *sck)
59079+{
59080+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59081+ if (grsec_enable_socket_server &&
59082+ in_group_p(grsec_socket_server_gid) &&
59083+ sck && (sck->sk_family != AF_UNIX) &&
59084+ (sck->sk_family != AF_LOCAL)) {
59085+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59086+ return -EACCES;
59087+ }
59088+#endif
59089+ return 0;
59090+}
59091+
59092+int
59093+gr_handle_sock_client(const struct sockaddr *sck)
59094+{
59095+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59096+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59097+ sck && (sck->sa_family != AF_UNIX) &&
59098+ (sck->sa_family != AF_LOCAL)) {
59099+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59100+ return -EACCES;
59101+ }
59102+#endif
59103+ return 0;
59104+}
59105diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59106new file mode 100644
59107index 0000000..f55ef0f
59108--- /dev/null
59109+++ b/grsecurity/grsec_sysctl.c
59110@@ -0,0 +1,469 @@
59111+#include <linux/kernel.h>
59112+#include <linux/sched.h>
59113+#include <linux/sysctl.h>
59114+#include <linux/grsecurity.h>
59115+#include <linux/grinternal.h>
59116+
59117+int
59118+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59119+{
59120+#ifdef CONFIG_GRKERNSEC_SYSCTL
59121+ if (dirname == NULL || name == NULL)
59122+ return 0;
59123+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59124+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59125+ return -EACCES;
59126+ }
59127+#endif
59128+ return 0;
59129+}
59130+
59131+#ifdef CONFIG_GRKERNSEC_ROFS
59132+static int __maybe_unused one = 1;
59133+#endif
59134+
59135+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59136+struct ctl_table grsecurity_table[] = {
59137+#ifdef CONFIG_GRKERNSEC_SYSCTL
59138+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59139+#ifdef CONFIG_GRKERNSEC_IO
59140+ {
59141+ .procname = "disable_priv_io",
59142+ .data = &grsec_disable_privio,
59143+ .maxlen = sizeof(int),
59144+ .mode = 0600,
59145+ .proc_handler = &proc_dointvec,
59146+ },
59147+#endif
59148+#endif
59149+#ifdef CONFIG_GRKERNSEC_LINK
59150+ {
59151+ .procname = "linking_restrictions",
59152+ .data = &grsec_enable_link,
59153+ .maxlen = sizeof(int),
59154+ .mode = 0600,
59155+ .proc_handler = &proc_dointvec,
59156+ },
59157+#endif
59158+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59159+ {
59160+ .procname = "enforce_symlinksifowner",
59161+ .data = &grsec_enable_symlinkown,
59162+ .maxlen = sizeof(int),
59163+ .mode = 0600,
59164+ .proc_handler = &proc_dointvec,
59165+ },
59166+ {
59167+ .procname = "symlinkown_gid",
59168+ .data = &grsec_symlinkown_gid,
59169+ .maxlen = sizeof(int),
59170+ .mode = 0600,
59171+ .proc_handler = &proc_dointvec,
59172+ },
59173+#endif
59174+#ifdef CONFIG_GRKERNSEC_BRUTE
59175+ {
59176+ .procname = "deter_bruteforce",
59177+ .data = &grsec_enable_brute,
59178+ .maxlen = sizeof(int),
59179+ .mode = 0600,
59180+ .proc_handler = &proc_dointvec,
59181+ },
59182+#endif
59183+#ifdef CONFIG_GRKERNSEC_FIFO
59184+ {
59185+ .procname = "fifo_restrictions",
59186+ .data = &grsec_enable_fifo,
59187+ .maxlen = sizeof(int),
59188+ .mode = 0600,
59189+ .proc_handler = &proc_dointvec,
59190+ },
59191+#endif
59192+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59193+ {
59194+ .procname = "ptrace_readexec",
59195+ .data = &grsec_enable_ptrace_readexec,
59196+ .maxlen = sizeof(int),
59197+ .mode = 0600,
59198+ .proc_handler = &proc_dointvec,
59199+ },
59200+#endif
59201+#ifdef CONFIG_GRKERNSEC_SETXID
59202+ {
59203+ .procname = "consistent_setxid",
59204+ .data = &grsec_enable_setxid,
59205+ .maxlen = sizeof(int),
59206+ .mode = 0600,
59207+ .proc_handler = &proc_dointvec,
59208+ },
59209+#endif
59210+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59211+ {
59212+ .procname = "ip_blackhole",
59213+ .data = &grsec_enable_blackhole,
59214+ .maxlen = sizeof(int),
59215+ .mode = 0600,
59216+ .proc_handler = &proc_dointvec,
59217+ },
59218+ {
59219+ .procname = "lastack_retries",
59220+ .data = &grsec_lastack_retries,
59221+ .maxlen = sizeof(int),
59222+ .mode = 0600,
59223+ .proc_handler = &proc_dointvec,
59224+ },
59225+#endif
59226+#ifdef CONFIG_GRKERNSEC_EXECLOG
59227+ {
59228+ .procname = "exec_logging",
59229+ .data = &grsec_enable_execlog,
59230+ .maxlen = sizeof(int),
59231+ .mode = 0600,
59232+ .proc_handler = &proc_dointvec,
59233+ },
59234+#endif
59235+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59236+ {
59237+ .procname = "rwxmap_logging",
59238+ .data = &grsec_enable_log_rwxmaps,
59239+ .maxlen = sizeof(int),
59240+ .mode = 0600,
59241+ .proc_handler = &proc_dointvec,
59242+ },
59243+#endif
59244+#ifdef CONFIG_GRKERNSEC_SIGNAL
59245+ {
59246+ .procname = "signal_logging",
59247+ .data = &grsec_enable_signal,
59248+ .maxlen = sizeof(int),
59249+ .mode = 0600,
59250+ .proc_handler = &proc_dointvec,
59251+ },
59252+#endif
59253+#ifdef CONFIG_GRKERNSEC_FORKFAIL
59254+ {
59255+ .procname = "forkfail_logging",
59256+ .data = &grsec_enable_forkfail,
59257+ .maxlen = sizeof(int),
59258+ .mode = 0600,
59259+ .proc_handler = &proc_dointvec,
59260+ },
59261+#endif
59262+#ifdef CONFIG_GRKERNSEC_TIME
59263+ {
59264+ .procname = "timechange_logging",
59265+ .data = &grsec_enable_time,
59266+ .maxlen = sizeof(int),
59267+ .mode = 0600,
59268+ .proc_handler = &proc_dointvec,
59269+ },
59270+#endif
59271+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59272+ {
59273+ .procname = "chroot_deny_shmat",
59274+ .data = &grsec_enable_chroot_shmat,
59275+ .maxlen = sizeof(int),
59276+ .mode = 0600,
59277+ .proc_handler = &proc_dointvec,
59278+ },
59279+#endif
59280+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59281+ {
59282+ .procname = "chroot_deny_unix",
59283+ .data = &grsec_enable_chroot_unix,
59284+ .maxlen = sizeof(int),
59285+ .mode = 0600,
59286+ .proc_handler = &proc_dointvec,
59287+ },
59288+#endif
59289+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59290+ {
59291+ .procname = "chroot_deny_mount",
59292+ .data = &grsec_enable_chroot_mount,
59293+ .maxlen = sizeof(int),
59294+ .mode = 0600,
59295+ .proc_handler = &proc_dointvec,
59296+ },
59297+#endif
59298+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59299+ {
59300+ .procname = "chroot_deny_fchdir",
59301+ .data = &grsec_enable_chroot_fchdir,
59302+ .maxlen = sizeof(int),
59303+ .mode = 0600,
59304+ .proc_handler = &proc_dointvec,
59305+ },
59306+#endif
59307+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59308+ {
59309+ .procname = "chroot_deny_chroot",
59310+ .data = &grsec_enable_chroot_double,
59311+ .maxlen = sizeof(int),
59312+ .mode = 0600,
59313+ .proc_handler = &proc_dointvec,
59314+ },
59315+#endif
59316+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59317+ {
59318+ .procname = "chroot_deny_pivot",
59319+ .data = &grsec_enable_chroot_pivot,
59320+ .maxlen = sizeof(int),
59321+ .mode = 0600,
59322+ .proc_handler = &proc_dointvec,
59323+ },
59324+#endif
59325+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59326+ {
59327+ .procname = "chroot_enforce_chdir",
59328+ .data = &grsec_enable_chroot_chdir,
59329+ .maxlen = sizeof(int),
59330+ .mode = 0600,
59331+ .proc_handler = &proc_dointvec,
59332+ },
59333+#endif
59334+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59335+ {
59336+ .procname = "chroot_deny_chmod",
59337+ .data = &grsec_enable_chroot_chmod,
59338+ .maxlen = sizeof(int),
59339+ .mode = 0600,
59340+ .proc_handler = &proc_dointvec,
59341+ },
59342+#endif
59343+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59344+ {
59345+ .procname = "chroot_deny_mknod",
59346+ .data = &grsec_enable_chroot_mknod,
59347+ .maxlen = sizeof(int),
59348+ .mode = 0600,
59349+ .proc_handler = &proc_dointvec,
59350+ },
59351+#endif
59352+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59353+ {
59354+ .procname = "chroot_restrict_nice",
59355+ .data = &grsec_enable_chroot_nice,
59356+ .maxlen = sizeof(int),
59357+ .mode = 0600,
59358+ .proc_handler = &proc_dointvec,
59359+ },
59360+#endif
59361+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59362+ {
59363+ .procname = "chroot_execlog",
59364+ .data = &grsec_enable_chroot_execlog,
59365+ .maxlen = sizeof(int),
59366+ .mode = 0600,
59367+ .proc_handler = &proc_dointvec,
59368+ },
59369+#endif
59370+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59371+ {
59372+ .procname = "chroot_caps",
59373+ .data = &grsec_enable_chroot_caps,
59374+ .maxlen = sizeof(int),
59375+ .mode = 0600,
59376+ .proc_handler = &proc_dointvec,
59377+ },
59378+#endif
59379+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59380+ {
59381+ .procname = "chroot_deny_sysctl",
59382+ .data = &grsec_enable_chroot_sysctl,
59383+ .maxlen = sizeof(int),
59384+ .mode = 0600,
59385+ .proc_handler = &proc_dointvec,
59386+ },
59387+#endif
59388+#ifdef CONFIG_GRKERNSEC_TPE
59389+ {
59390+ .procname = "tpe",
59391+ .data = &grsec_enable_tpe,
59392+ .maxlen = sizeof(int),
59393+ .mode = 0600,
59394+ .proc_handler = &proc_dointvec,
59395+ },
59396+ {
59397+ .procname = "tpe_gid",
59398+ .data = &grsec_tpe_gid,
59399+ .maxlen = sizeof(int),
59400+ .mode = 0600,
59401+ .proc_handler = &proc_dointvec,
59402+ },
59403+#endif
59404+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59405+ {
59406+ .procname = "tpe_invert",
59407+ .data = &grsec_enable_tpe_invert,
59408+ .maxlen = sizeof(int),
59409+ .mode = 0600,
59410+ .proc_handler = &proc_dointvec,
59411+ },
59412+#endif
59413+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59414+ {
59415+ .procname = "tpe_restrict_all",
59416+ .data = &grsec_enable_tpe_all,
59417+ .maxlen = sizeof(int),
59418+ .mode = 0600,
59419+ .proc_handler = &proc_dointvec,
59420+ },
59421+#endif
59422+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59423+ {
59424+ .procname = "socket_all",
59425+ .data = &grsec_enable_socket_all,
59426+ .maxlen = sizeof(int),
59427+ .mode = 0600,
59428+ .proc_handler = &proc_dointvec,
59429+ },
59430+ {
59431+ .procname = "socket_all_gid",
59432+ .data = &grsec_socket_all_gid,
59433+ .maxlen = sizeof(int),
59434+ .mode = 0600,
59435+ .proc_handler = &proc_dointvec,
59436+ },
59437+#endif
59438+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59439+ {
59440+ .procname = "socket_client",
59441+ .data = &grsec_enable_socket_client,
59442+ .maxlen = sizeof(int),
59443+ .mode = 0600,
59444+ .proc_handler = &proc_dointvec,
59445+ },
59446+ {
59447+ .procname = "socket_client_gid",
59448+ .data = &grsec_socket_client_gid,
59449+ .maxlen = sizeof(int),
59450+ .mode = 0600,
59451+ .proc_handler = &proc_dointvec,
59452+ },
59453+#endif
59454+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59455+ {
59456+ .procname = "socket_server",
59457+ .data = &grsec_enable_socket_server,
59458+ .maxlen = sizeof(int),
59459+ .mode = 0600,
59460+ .proc_handler = &proc_dointvec,
59461+ },
59462+ {
59463+ .procname = "socket_server_gid",
59464+ .data = &grsec_socket_server_gid,
59465+ .maxlen = sizeof(int),
59466+ .mode = 0600,
59467+ .proc_handler = &proc_dointvec,
59468+ },
59469+#endif
59470+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59471+ {
59472+ .procname = "audit_group",
59473+ .data = &grsec_enable_group,
59474+ .maxlen = sizeof(int),
59475+ .mode = 0600,
59476+ .proc_handler = &proc_dointvec,
59477+ },
59478+ {
59479+ .procname = "audit_gid",
59480+ .data = &grsec_audit_gid,
59481+ .maxlen = sizeof(int),
59482+ .mode = 0600,
59483+ .proc_handler = &proc_dointvec,
59484+ },
59485+#endif
59486+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59487+ {
59488+ .procname = "audit_chdir",
59489+ .data = &grsec_enable_chdir,
59490+ .maxlen = sizeof(int),
59491+ .mode = 0600,
59492+ .proc_handler = &proc_dointvec,
59493+ },
59494+#endif
59495+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59496+ {
59497+ .procname = "audit_mount",
59498+ .data = &grsec_enable_mount,
59499+ .maxlen = sizeof(int),
59500+ .mode = 0600,
59501+ .proc_handler = &proc_dointvec,
59502+ },
59503+#endif
59504+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59505+ {
59506+ .procname = "audit_textrel",
59507+ .data = &grsec_enable_audit_textrel,
59508+ .maxlen = sizeof(int),
59509+ .mode = 0600,
59510+ .proc_handler = &proc_dointvec,
59511+ },
59512+#endif
59513+#ifdef CONFIG_GRKERNSEC_DMESG
59514+ {
59515+ .procname = "dmesg",
59516+ .data = &grsec_enable_dmesg,
59517+ .maxlen = sizeof(int),
59518+ .mode = 0600,
59519+ .proc_handler = &proc_dointvec,
59520+ },
59521+#endif
59522+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59523+ {
59524+ .procname = "chroot_findtask",
59525+ .data = &grsec_enable_chroot_findtask,
59526+ .maxlen = sizeof(int),
59527+ .mode = 0600,
59528+ .proc_handler = &proc_dointvec,
59529+ },
59530+#endif
59531+#ifdef CONFIG_GRKERNSEC_RESLOG
59532+ {
59533+ .procname = "resource_logging",
59534+ .data = &grsec_resource_logging,
59535+ .maxlen = sizeof(int),
59536+ .mode = 0600,
59537+ .proc_handler = &proc_dointvec,
59538+ },
59539+#endif
59540+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59541+ {
59542+ .procname = "audit_ptrace",
59543+ .data = &grsec_enable_audit_ptrace,
59544+ .maxlen = sizeof(int),
59545+ .mode = 0600,
59546+ .proc_handler = &proc_dointvec,
59547+ },
59548+#endif
59549+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59550+ {
59551+ .procname = "harden_ptrace",
59552+ .data = &grsec_enable_harden_ptrace,
59553+ .maxlen = sizeof(int),
59554+ .mode = 0600,
59555+ .proc_handler = &proc_dointvec,
59556+ },
59557+#endif
59558+ {
59559+ .procname = "grsec_lock",
59560+ .data = &grsec_lock,
59561+ .maxlen = sizeof(int),
59562+ .mode = 0600,
59563+ .proc_handler = &proc_dointvec,
59564+ },
59565+#endif
59566+#ifdef CONFIG_GRKERNSEC_ROFS
59567+ {
59568+ .procname = "romount_protect",
59569+ .data = &grsec_enable_rofs,
59570+ .maxlen = sizeof(int),
59571+ .mode = 0600,
59572+ .proc_handler = &proc_dointvec_minmax,
59573+ .extra1 = &one,
59574+ .extra2 = &one,
59575+ },
59576+#endif
59577+ { }
59578+};
59579+#endif
59580diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59581new file mode 100644
59582index 0000000..0dc13c3
59583--- /dev/null
59584+++ b/grsecurity/grsec_time.c
59585@@ -0,0 +1,16 @@
59586+#include <linux/kernel.h>
59587+#include <linux/sched.h>
59588+#include <linux/grinternal.h>
59589+#include <linux/module.h>
59590+
59591+void
59592+gr_log_timechange(void)
59593+{
59594+#ifdef CONFIG_GRKERNSEC_TIME
59595+ if (grsec_enable_time)
59596+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59597+#endif
59598+ return;
59599+}
59600+
59601+EXPORT_SYMBOL(gr_log_timechange);
59602diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59603new file mode 100644
59604index 0000000..07e0dc0
59605--- /dev/null
59606+++ b/grsecurity/grsec_tpe.c
59607@@ -0,0 +1,73 @@
59608+#include <linux/kernel.h>
59609+#include <linux/sched.h>
59610+#include <linux/file.h>
59611+#include <linux/fs.h>
59612+#include <linux/grinternal.h>
59613+
59614+extern int gr_acl_tpe_check(void);
59615+
59616+int
59617+gr_tpe_allow(const struct file *file)
59618+{
59619+#ifdef CONFIG_GRKERNSEC
59620+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59621+ const struct cred *cred = current_cred();
59622+ char *msg = NULL;
59623+ char *msg2 = NULL;
59624+
59625+ // never restrict root
59626+ if (!cred->uid)
59627+ return 1;
59628+
59629+ if (grsec_enable_tpe) {
59630+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59631+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59632+ msg = "not being in trusted group";
59633+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59634+ msg = "being in untrusted group";
59635+#else
59636+ if (in_group_p(grsec_tpe_gid))
59637+ msg = "being in untrusted group";
59638+#endif
59639+ }
59640+ if (!msg && gr_acl_tpe_check())
59641+ msg = "being in untrusted role";
59642+
59643+ // not in any affected group/role
59644+ if (!msg)
59645+ goto next_check;
59646+
59647+ if (inode->i_uid)
59648+ msg2 = "file in non-root-owned directory";
59649+ else if (inode->i_mode & S_IWOTH)
59650+ msg2 = "file in world-writable directory";
59651+ else if (inode->i_mode & S_IWGRP)
59652+ msg2 = "file in group-writable directory";
59653+
59654+ if (msg && msg2) {
59655+ char fullmsg[70] = {0};
59656+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59657+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59658+ return 0;
59659+ }
59660+ msg = NULL;
59661+next_check:
59662+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59663+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59664+ return 1;
59665+
59666+ if (inode->i_uid && (inode->i_uid != cred->uid))
59667+ msg = "directory not owned by user";
59668+ else if (inode->i_mode & S_IWOTH)
59669+ msg = "file in world-writable directory";
59670+ else if (inode->i_mode & S_IWGRP)
59671+ msg = "file in group-writable directory";
59672+
59673+ if (msg) {
59674+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59675+ return 0;
59676+ }
59677+#endif
59678+#endif
59679+ return 1;
59680+}
59681diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59682new file mode 100644
59683index 0000000..9f7b1ac
59684--- /dev/null
59685+++ b/grsecurity/grsum.c
59686@@ -0,0 +1,61 @@
59687+#include <linux/err.h>
59688+#include <linux/kernel.h>
59689+#include <linux/sched.h>
59690+#include <linux/mm.h>
59691+#include <linux/scatterlist.h>
59692+#include <linux/crypto.h>
59693+#include <linux/gracl.h>
59694+
59695+
59696+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59697+#error "crypto and sha256 must be built into the kernel"
59698+#endif
59699+
59700+int
59701+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59702+{
59703+ char *p;
59704+ struct crypto_hash *tfm;
59705+ struct hash_desc desc;
59706+ struct scatterlist sg;
59707+ unsigned char temp_sum[GR_SHA_LEN];
59708+ volatile int retval = 0;
59709+ volatile int dummy = 0;
59710+ unsigned int i;
59711+
59712+ sg_init_table(&sg, 1);
59713+
59714+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59715+ if (IS_ERR(tfm)) {
59716+ /* should never happen, since sha256 should be built in */
59717+ return 1;
59718+ }
59719+
59720+ desc.tfm = tfm;
59721+ desc.flags = 0;
59722+
59723+ crypto_hash_init(&desc);
59724+
59725+ p = salt;
59726+ sg_set_buf(&sg, p, GR_SALT_LEN);
59727+ crypto_hash_update(&desc, &sg, sg.length);
59728+
59729+ p = entry->pw;
59730+ sg_set_buf(&sg, p, strlen(p));
59731+
59732+ crypto_hash_update(&desc, &sg, sg.length);
59733+
59734+ crypto_hash_final(&desc, temp_sum);
59735+
59736+ memset(entry->pw, 0, GR_PW_LEN);
59737+
59738+ for (i = 0; i < GR_SHA_LEN; i++)
59739+ if (sum[i] != temp_sum[i])
59740+ retval = 1;
59741+ else
59742+ dummy = 1; // waste a cycle
59743+
59744+ crypto_free_hash(tfm);
59745+
59746+ return retval;
59747+}
59748diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59749index 9e6e1c6..d47b906 100644
59750--- a/include/acpi/acpi_bus.h
59751+++ b/include/acpi/acpi_bus.h
59752@@ -138,7 +138,7 @@ struct acpi_device_ops {
59753 acpi_op_bind bind;
59754 acpi_op_unbind unbind;
59755 acpi_op_notify notify;
59756-};
59757+} __no_const;
59758
59759 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59760
59761diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59762index b7babf0..3ba8aee 100644
59763--- a/include/asm-generic/atomic-long.h
59764+++ b/include/asm-generic/atomic-long.h
59765@@ -22,6 +22,12 @@
59766
59767 typedef atomic64_t atomic_long_t;
59768
59769+#ifdef CONFIG_PAX_REFCOUNT
59770+typedef atomic64_unchecked_t atomic_long_unchecked_t;
59771+#else
59772+typedef atomic64_t atomic_long_unchecked_t;
59773+#endif
59774+
59775 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59776
59777 static inline long atomic_long_read(atomic_long_t *l)
59778@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59779 return (long)atomic64_read(v);
59780 }
59781
59782+#ifdef CONFIG_PAX_REFCOUNT
59783+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59784+{
59785+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59786+
59787+ return (long)atomic64_read_unchecked(v);
59788+}
59789+#endif
59790+
59791 static inline void atomic_long_set(atomic_long_t *l, long i)
59792 {
59793 atomic64_t *v = (atomic64_t *)l;
59794@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59795 atomic64_set(v, i);
59796 }
59797
59798+#ifdef CONFIG_PAX_REFCOUNT
59799+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59800+{
59801+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59802+
59803+ atomic64_set_unchecked(v, i);
59804+}
59805+#endif
59806+
59807 static inline void atomic_long_inc(atomic_long_t *l)
59808 {
59809 atomic64_t *v = (atomic64_t *)l;
59810@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59811 atomic64_inc(v);
59812 }
59813
59814+#ifdef CONFIG_PAX_REFCOUNT
59815+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59816+{
59817+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59818+
59819+ atomic64_inc_unchecked(v);
59820+}
59821+#endif
59822+
59823 static inline void atomic_long_dec(atomic_long_t *l)
59824 {
59825 atomic64_t *v = (atomic64_t *)l;
59826@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59827 atomic64_dec(v);
59828 }
59829
59830+#ifdef CONFIG_PAX_REFCOUNT
59831+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59832+{
59833+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59834+
59835+ atomic64_dec_unchecked(v);
59836+}
59837+#endif
59838+
59839 static inline void atomic_long_add(long i, atomic_long_t *l)
59840 {
59841 atomic64_t *v = (atomic64_t *)l;
59842@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59843 atomic64_add(i, v);
59844 }
59845
59846+#ifdef CONFIG_PAX_REFCOUNT
59847+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59848+{
59849+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59850+
59851+ atomic64_add_unchecked(i, v);
59852+}
59853+#endif
59854+
59855 static inline void atomic_long_sub(long i, atomic_long_t *l)
59856 {
59857 atomic64_t *v = (atomic64_t *)l;
59858@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59859 atomic64_sub(i, v);
59860 }
59861
59862+#ifdef CONFIG_PAX_REFCOUNT
59863+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59864+{
59865+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59866+
59867+ atomic64_sub_unchecked(i, v);
59868+}
59869+#endif
59870+
59871 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59872 {
59873 atomic64_t *v = (atomic64_t *)l;
59874@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59875 return (long)atomic64_inc_return(v);
59876 }
59877
59878+#ifdef CONFIG_PAX_REFCOUNT
59879+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59880+{
59881+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59882+
59883+ return (long)atomic64_inc_return_unchecked(v);
59884+}
59885+#endif
59886+
59887 static inline long atomic_long_dec_return(atomic_long_t *l)
59888 {
59889 atomic64_t *v = (atomic64_t *)l;
59890@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59891
59892 typedef atomic_t atomic_long_t;
59893
59894+#ifdef CONFIG_PAX_REFCOUNT
59895+typedef atomic_unchecked_t atomic_long_unchecked_t;
59896+#else
59897+typedef atomic_t atomic_long_unchecked_t;
59898+#endif
59899+
59900 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59901 static inline long atomic_long_read(atomic_long_t *l)
59902 {
59903@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59904 return (long)atomic_read(v);
59905 }
59906
59907+#ifdef CONFIG_PAX_REFCOUNT
59908+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59909+{
59910+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59911+
59912+ return (long)atomic_read_unchecked(v);
59913+}
59914+#endif
59915+
59916 static inline void atomic_long_set(atomic_long_t *l, long i)
59917 {
59918 atomic_t *v = (atomic_t *)l;
59919@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59920 atomic_set(v, i);
59921 }
59922
59923+#ifdef CONFIG_PAX_REFCOUNT
59924+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59925+{
59926+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59927+
59928+ atomic_set_unchecked(v, i);
59929+}
59930+#endif
59931+
59932 static inline void atomic_long_inc(atomic_long_t *l)
59933 {
59934 atomic_t *v = (atomic_t *)l;
59935@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59936 atomic_inc(v);
59937 }
59938
59939+#ifdef CONFIG_PAX_REFCOUNT
59940+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59941+{
59942+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59943+
59944+ atomic_inc_unchecked(v);
59945+}
59946+#endif
59947+
59948 static inline void atomic_long_dec(atomic_long_t *l)
59949 {
59950 atomic_t *v = (atomic_t *)l;
59951@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59952 atomic_dec(v);
59953 }
59954
59955+#ifdef CONFIG_PAX_REFCOUNT
59956+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59957+{
59958+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59959+
59960+ atomic_dec_unchecked(v);
59961+}
59962+#endif
59963+
59964 static inline void atomic_long_add(long i, atomic_long_t *l)
59965 {
59966 atomic_t *v = (atomic_t *)l;
59967@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59968 atomic_add(i, v);
59969 }
59970
59971+#ifdef CONFIG_PAX_REFCOUNT
59972+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59973+{
59974+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59975+
59976+ atomic_add_unchecked(i, v);
59977+}
59978+#endif
59979+
59980 static inline void atomic_long_sub(long i, atomic_long_t *l)
59981 {
59982 atomic_t *v = (atomic_t *)l;
59983@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59984 atomic_sub(i, v);
59985 }
59986
59987+#ifdef CONFIG_PAX_REFCOUNT
59988+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59989+{
59990+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59991+
59992+ atomic_sub_unchecked(i, v);
59993+}
59994+#endif
59995+
59996 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59997 {
59998 atomic_t *v = (atomic_t *)l;
59999@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60000 return (long)atomic_inc_return(v);
60001 }
60002
60003+#ifdef CONFIG_PAX_REFCOUNT
60004+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60005+{
60006+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60007+
60008+ return (long)atomic_inc_return_unchecked(v);
60009+}
60010+#endif
60011+
60012 static inline long atomic_long_dec_return(atomic_long_t *l)
60013 {
60014 atomic_t *v = (atomic_t *)l;
60015@@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60016
60017 #endif /* BITS_PER_LONG == 64 */
60018
60019+#ifdef CONFIG_PAX_REFCOUNT
60020+static inline void pax_refcount_needs_these_functions(void)
60021+{
60022+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
60023+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60024+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60025+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60026+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60027+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60028+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60029+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60030+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60031+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60032+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60033+#ifdef CONFIG_X86
60034+ atomic_clear_mask_unchecked(0, NULL);
60035+ atomic_set_mask_unchecked(0, NULL);
60036+#endif
60037+
60038+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60039+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60040+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60041+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60042+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60043+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60044+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60045+}
60046+#else
60047+#define atomic_read_unchecked(v) atomic_read(v)
60048+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60049+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60050+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60051+#define atomic_inc_unchecked(v) atomic_inc(v)
60052+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60053+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60054+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60055+#define atomic_dec_unchecked(v) atomic_dec(v)
60056+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60057+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60058+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60059+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60060+
60061+#define atomic_long_read_unchecked(v) atomic_long_read(v)
60062+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60063+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60064+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60065+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60066+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60067+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60068+#endif
60069+
60070 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60071diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60072index 1ced641..c896ee8 100644
60073--- a/include/asm-generic/atomic.h
60074+++ b/include/asm-generic/atomic.h
60075@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60076 * Atomically clears the bits set in @mask from @v
60077 */
60078 #ifndef atomic_clear_mask
60079-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60080+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60081 {
60082 unsigned long flags;
60083
60084diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60085index b18ce4f..2ee2843 100644
60086--- a/include/asm-generic/atomic64.h
60087+++ b/include/asm-generic/atomic64.h
60088@@ -16,6 +16,8 @@ typedef struct {
60089 long long counter;
60090 } atomic64_t;
60091
60092+typedef atomic64_t atomic64_unchecked_t;
60093+
60094 #define ATOMIC64_INIT(i) { (i) }
60095
60096 extern long long atomic64_read(const atomic64_t *v);
60097@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60098 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60099 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60100
60101+#define atomic64_read_unchecked(v) atomic64_read(v)
60102+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60103+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60104+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60105+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60106+#define atomic64_inc_unchecked(v) atomic64_inc(v)
60107+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60108+#define atomic64_dec_unchecked(v) atomic64_dec(v)
60109+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60110+
60111 #endif /* _ASM_GENERIC_ATOMIC64_H */
60112diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60113index 1bfcfe5..e04c5c9 100644
60114--- a/include/asm-generic/cache.h
60115+++ b/include/asm-generic/cache.h
60116@@ -6,7 +6,7 @@
60117 * cache lines need to provide their own cache.h.
60118 */
60119
60120-#define L1_CACHE_SHIFT 5
60121-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60122+#define L1_CACHE_SHIFT 5UL
60123+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60124
60125 #endif /* __ASM_GENERIC_CACHE_H */
60126diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60127index 0d68a1e..b74a761 100644
60128--- a/include/asm-generic/emergency-restart.h
60129+++ b/include/asm-generic/emergency-restart.h
60130@@ -1,7 +1,7 @@
60131 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60132 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60133
60134-static inline void machine_emergency_restart(void)
60135+static inline __noreturn void machine_emergency_restart(void)
60136 {
60137 machine_restart(NULL);
60138 }
60139diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60140index 0232ccb..13d9165 100644
60141--- a/include/asm-generic/kmap_types.h
60142+++ b/include/asm-generic/kmap_types.h
60143@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60144 KMAP_D(17) KM_NMI,
60145 KMAP_D(18) KM_NMI_PTE,
60146 KMAP_D(19) KM_KDB,
60147+KMAP_D(20) KM_CLEARPAGE,
60148 /*
60149 * Remember to update debug_kmap_atomic() when adding new kmap types!
60150 */
60151-KMAP_D(20) KM_TYPE_NR
60152+KMAP_D(21) KM_TYPE_NR
60153 };
60154
60155 #undef KMAP_D
60156diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60157index 9ceb03b..2efbcbd 100644
60158--- a/include/asm-generic/local.h
60159+++ b/include/asm-generic/local.h
60160@@ -39,6 +39,7 @@ typedef struct
60161 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60162 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60163 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60164+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60165
60166 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60167 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60168diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60169index 725612b..9cc513a 100644
60170--- a/include/asm-generic/pgtable-nopmd.h
60171+++ b/include/asm-generic/pgtable-nopmd.h
60172@@ -1,14 +1,19 @@
60173 #ifndef _PGTABLE_NOPMD_H
60174 #define _PGTABLE_NOPMD_H
60175
60176-#ifndef __ASSEMBLY__
60177-
60178 #include <asm-generic/pgtable-nopud.h>
60179
60180-struct mm_struct;
60181-
60182 #define __PAGETABLE_PMD_FOLDED
60183
60184+#define PMD_SHIFT PUD_SHIFT
60185+#define PTRS_PER_PMD 1
60186+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60187+#define PMD_MASK (~(PMD_SIZE-1))
60188+
60189+#ifndef __ASSEMBLY__
60190+
60191+struct mm_struct;
60192+
60193 /*
60194 * Having the pmd type consist of a pud gets the size right, and allows
60195 * us to conceptually access the pud entry that this pmd is folded into
60196@@ -16,11 +21,6 @@ struct mm_struct;
60197 */
60198 typedef struct { pud_t pud; } pmd_t;
60199
60200-#define PMD_SHIFT PUD_SHIFT
60201-#define PTRS_PER_PMD 1
60202-#define PMD_SIZE (1UL << PMD_SHIFT)
60203-#define PMD_MASK (~(PMD_SIZE-1))
60204-
60205 /*
60206 * The "pud_xxx()" functions here are trivial for a folded two-level
60207 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60208diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60209index 810431d..0ec4804f 100644
60210--- a/include/asm-generic/pgtable-nopud.h
60211+++ b/include/asm-generic/pgtable-nopud.h
60212@@ -1,10 +1,15 @@
60213 #ifndef _PGTABLE_NOPUD_H
60214 #define _PGTABLE_NOPUD_H
60215
60216-#ifndef __ASSEMBLY__
60217-
60218 #define __PAGETABLE_PUD_FOLDED
60219
60220+#define PUD_SHIFT PGDIR_SHIFT
60221+#define PTRS_PER_PUD 1
60222+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60223+#define PUD_MASK (~(PUD_SIZE-1))
60224+
60225+#ifndef __ASSEMBLY__
60226+
60227 /*
60228 * Having the pud type consist of a pgd gets the size right, and allows
60229 * us to conceptually access the pgd entry that this pud is folded into
60230@@ -12,11 +17,6 @@
60231 */
60232 typedef struct { pgd_t pgd; } pud_t;
60233
60234-#define PUD_SHIFT PGDIR_SHIFT
60235-#define PTRS_PER_PUD 1
60236-#define PUD_SIZE (1UL << PUD_SHIFT)
60237-#define PUD_MASK (~(PUD_SIZE-1))
60238-
60239 /*
60240 * The "pgd_xxx()" functions here are trivial for a folded two-level
60241 * setup: the pud is never bad, and a pud always exists (as it's folded
60242@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60243 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60244
60245 #define pgd_populate(mm, pgd, pud) do { } while (0)
60246+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60247 /*
60248 * (puds are folded into pgds so this doesn't get actually called,
60249 * but the define is needed for a generic inline function.)
60250diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60251index ff4947b..f48183f 100644
60252--- a/include/asm-generic/pgtable.h
60253+++ b/include/asm-generic/pgtable.h
60254@@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60255 #endif
60256 }
60257
60258+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60259+static inline unsigned long pax_open_kernel(void) { return 0; }
60260+#endif
60261+
60262+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60263+static inline unsigned long pax_close_kernel(void) { return 0; }
60264+#endif
60265+
60266 #endif /* CONFIG_MMU */
60267
60268 #endif /* !__ASSEMBLY__ */
60269diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60270index 4e2e1cc..12c266b 100644
60271--- a/include/asm-generic/vmlinux.lds.h
60272+++ b/include/asm-generic/vmlinux.lds.h
60273@@ -218,6 +218,7 @@
60274 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60275 VMLINUX_SYMBOL(__start_rodata) = .; \
60276 *(.rodata) *(.rodata.*) \
60277+ *(.data..read_only) \
60278 *(__vermagic) /* Kernel version magic */ \
60279 . = ALIGN(8); \
60280 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60281@@ -716,17 +717,18 @@
60282 * section in the linker script will go there too. @phdr should have
60283 * a leading colon.
60284 *
60285- * Note that this macros defines __per_cpu_load as an absolute symbol.
60286+ * Note that this macros defines per_cpu_load as an absolute symbol.
60287 * If there is no need to put the percpu section at a predetermined
60288 * address, use PERCPU_SECTION.
60289 */
60290 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60291- VMLINUX_SYMBOL(__per_cpu_load) = .; \
60292- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60293+ per_cpu_load = .; \
60294+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60295 - LOAD_OFFSET) { \
60296+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60297 PERCPU_INPUT(cacheline) \
60298 } phdr \
60299- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60300+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60301
60302 /**
60303 * PERCPU_SECTION - define output section for percpu area, simple version
60304diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60305index 31ad880..4e79884 100644
60306--- a/include/drm/drmP.h
60307+++ b/include/drm/drmP.h
60308@@ -72,6 +72,7 @@
60309 #include <linux/workqueue.h>
60310 #include <linux/poll.h>
60311 #include <asm/pgalloc.h>
60312+#include <asm/local.h>
60313 #include "drm.h"
60314
60315 #include <linux/idr.h>
60316@@ -1074,7 +1075,7 @@ struct drm_device {
60317
60318 /** \name Usage Counters */
60319 /*@{ */
60320- int open_count; /**< Outstanding files open */
60321+ local_t open_count; /**< Outstanding files open */
60322 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60323 atomic_t vma_count; /**< Outstanding vma areas open */
60324 int buf_use; /**< Buffers in use -- cannot alloc */
60325@@ -1085,7 +1086,7 @@ struct drm_device {
60326 /*@{ */
60327 unsigned long counters;
60328 enum drm_stat_type types[15];
60329- atomic_t counts[15];
60330+ atomic_unchecked_t counts[15];
60331 /*@} */
60332
60333 struct list_head filelist;
60334diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60335index 7988e55..ec974c9 100644
60336--- a/include/drm/drm_crtc_helper.h
60337+++ b/include/drm/drm_crtc_helper.h
60338@@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60339
60340 /* disable crtc when not in use - more explicit than dpms off */
60341 void (*disable)(struct drm_crtc *crtc);
60342-};
60343+} __no_const;
60344
60345 /**
60346 * drm_encoder_helper_funcs - helper operations for encoders
60347@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60348 struct drm_connector *connector);
60349 /* disable encoder when not in use - more explicit than dpms off */
60350 void (*disable)(struct drm_encoder *encoder);
60351-};
60352+} __no_const;
60353
60354 /**
60355 * drm_connector_helper_funcs - helper operations for connectors
60356diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60357index d6d1da4..fdd1ac5 100644
60358--- a/include/drm/ttm/ttm_memory.h
60359+++ b/include/drm/ttm/ttm_memory.h
60360@@ -48,7 +48,7 @@
60361
60362 struct ttm_mem_shrink {
60363 int (*do_shrink) (struct ttm_mem_shrink *);
60364-};
60365+} __no_const;
60366
60367 /**
60368 * struct ttm_mem_global - Global memory accounting structure.
60369diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60370index e86dfca..40cc55f 100644
60371--- a/include/linux/a.out.h
60372+++ b/include/linux/a.out.h
60373@@ -39,6 +39,14 @@ enum machine_type {
60374 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60375 };
60376
60377+/* Constants for the N_FLAGS field */
60378+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60379+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60380+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60381+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60382+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60383+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60384+
60385 #if !defined (N_MAGIC)
60386 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60387 #endif
60388diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60389index 06fd4bb..1caec0d 100644
60390--- a/include/linux/atmdev.h
60391+++ b/include/linux/atmdev.h
60392@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60393 #endif
60394
60395 struct k_atm_aal_stats {
60396-#define __HANDLE_ITEM(i) atomic_t i
60397+#define __HANDLE_ITEM(i) atomic_unchecked_t i
60398 __AAL_STAT_ITEMS
60399 #undef __HANDLE_ITEM
60400 };
60401diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60402index 366422b..1fa7f84 100644
60403--- a/include/linux/binfmts.h
60404+++ b/include/linux/binfmts.h
60405@@ -89,6 +89,7 @@ struct linux_binfmt {
60406 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60407 int (*load_shlib)(struct file *);
60408 int (*core_dump)(struct coredump_params *cprm);
60409+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60410 unsigned long min_coredump; /* minimal dump size */
60411 };
60412
60413diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60414index 07954b0..cb2ae71 100644
60415--- a/include/linux/blkdev.h
60416+++ b/include/linux/blkdev.h
60417@@ -1393,7 +1393,7 @@ struct block_device_operations {
60418 /* this callback is with swap_lock and sometimes page table lock held */
60419 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60420 struct module *owner;
60421-};
60422+} __do_const;
60423
60424 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60425 unsigned long);
60426diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60427index 4d1a074..88f929a 100644
60428--- a/include/linux/blktrace_api.h
60429+++ b/include/linux/blktrace_api.h
60430@@ -162,7 +162,7 @@ struct blk_trace {
60431 struct dentry *dir;
60432 struct dentry *dropped_file;
60433 struct dentry *msg_file;
60434- atomic_t dropped;
60435+ atomic_unchecked_t dropped;
60436 };
60437
60438 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60439diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60440index 83195fb..0b0f77d 100644
60441--- a/include/linux/byteorder/little_endian.h
60442+++ b/include/linux/byteorder/little_endian.h
60443@@ -42,51 +42,51 @@
60444
60445 static inline __le64 __cpu_to_le64p(const __u64 *p)
60446 {
60447- return (__force __le64)*p;
60448+ return (__force const __le64)*p;
60449 }
60450 static inline __u64 __le64_to_cpup(const __le64 *p)
60451 {
60452- return (__force __u64)*p;
60453+ return (__force const __u64)*p;
60454 }
60455 static inline __le32 __cpu_to_le32p(const __u32 *p)
60456 {
60457- return (__force __le32)*p;
60458+ return (__force const __le32)*p;
60459 }
60460 static inline __u32 __le32_to_cpup(const __le32 *p)
60461 {
60462- return (__force __u32)*p;
60463+ return (__force const __u32)*p;
60464 }
60465 static inline __le16 __cpu_to_le16p(const __u16 *p)
60466 {
60467- return (__force __le16)*p;
60468+ return (__force const __le16)*p;
60469 }
60470 static inline __u16 __le16_to_cpup(const __le16 *p)
60471 {
60472- return (__force __u16)*p;
60473+ return (__force const __u16)*p;
60474 }
60475 static inline __be64 __cpu_to_be64p(const __u64 *p)
60476 {
60477- return (__force __be64)__swab64p(p);
60478+ return (__force const __be64)__swab64p(p);
60479 }
60480 static inline __u64 __be64_to_cpup(const __be64 *p)
60481 {
60482- return __swab64p((__u64 *)p);
60483+ return __swab64p((const __u64 *)p);
60484 }
60485 static inline __be32 __cpu_to_be32p(const __u32 *p)
60486 {
60487- return (__force __be32)__swab32p(p);
60488+ return (__force const __be32)__swab32p(p);
60489 }
60490 static inline __u32 __be32_to_cpup(const __be32 *p)
60491 {
60492- return __swab32p((__u32 *)p);
60493+ return __swab32p((const __u32 *)p);
60494 }
60495 static inline __be16 __cpu_to_be16p(const __u16 *p)
60496 {
60497- return (__force __be16)__swab16p(p);
60498+ return (__force const __be16)__swab16p(p);
60499 }
60500 static inline __u16 __be16_to_cpup(const __be16 *p)
60501 {
60502- return __swab16p((__u16 *)p);
60503+ return __swab16p((const __u16 *)p);
60504 }
60505 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60506 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60507diff --git a/include/linux/cache.h b/include/linux/cache.h
60508index 4c57065..4307975 100644
60509--- a/include/linux/cache.h
60510+++ b/include/linux/cache.h
60511@@ -16,6 +16,10 @@
60512 #define __read_mostly
60513 #endif
60514
60515+#ifndef __read_only
60516+#define __read_only __read_mostly
60517+#endif
60518+
60519 #ifndef ____cacheline_aligned
60520 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60521 #endif
60522diff --git a/include/linux/capability.h b/include/linux/capability.h
60523index d10b7ed..11390a1 100644
60524--- a/include/linux/capability.h
60525+++ b/include/linux/capability.h
60526@@ -553,6 +553,9 @@ extern bool capable(int cap);
60527 extern bool ns_capable(struct user_namespace *ns, int cap);
60528 extern bool nsown_capable(int cap);
60529 extern bool inode_capable(const struct inode *inode, int cap);
60530+extern bool capable_nolog(int cap);
60531+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60532+extern bool inode_capable_nolog(const struct inode *inode, int cap);
60533
60534 /* audit system wants to get cap info from files as well */
60535 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60536diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60537index 42e55de..1cd0e66 100644
60538--- a/include/linux/cleancache.h
60539+++ b/include/linux/cleancache.h
60540@@ -31,7 +31,7 @@ struct cleancache_ops {
60541 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
60542 void (*invalidate_inode)(int, struct cleancache_filekey);
60543 void (*invalidate_fs)(int);
60544-};
60545+} __no_const;
60546
60547 extern struct cleancache_ops
60548 cleancache_register_ops(struct cleancache_ops *ops);
60549diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60550index 2f40791..9c9e13c 100644
60551--- a/include/linux/compiler-gcc4.h
60552+++ b/include/linux/compiler-gcc4.h
60553@@ -32,6 +32,20 @@
60554 #define __linktime_error(message) __attribute__((__error__(message)))
60555
60556 #if __GNUC_MINOR__ >= 5
60557+
60558+#ifdef CONSTIFY_PLUGIN
60559+#define __no_const __attribute__((no_const))
60560+#define __do_const __attribute__((do_const))
60561+#endif
60562+
60563+#ifdef SIZE_OVERFLOW_PLUGIN
60564+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60565+#endif
60566+
60567+#ifdef LATENT_ENTROPY_PLUGIN
60568+#define __latent_entropy __attribute__((latent_entropy))
60569+#endif
60570+
60571 /*
60572 * Mark a position in code as unreachable. This can be used to
60573 * suppress control flow warnings after asm blocks that transfer
60574@@ -47,6 +61,11 @@
60575 #define __noclone __attribute__((__noclone__))
60576
60577 #endif
60578+
60579+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60580+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60581+#define __bos0(ptr) __bos((ptr), 0)
60582+#define __bos1(ptr) __bos((ptr), 1)
60583 #endif
60584
60585 #if __GNUC_MINOR__ > 0
60586diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60587index 923d093..1fef491 100644
60588--- a/include/linux/compiler.h
60589+++ b/include/linux/compiler.h
60590@@ -5,31 +5,62 @@
60591
60592 #ifdef __CHECKER__
60593 # define __user __attribute__((noderef, address_space(1)))
60594+# define __force_user __force __user
60595 # define __kernel __attribute__((address_space(0)))
60596+# define __force_kernel __force __kernel
60597 # define __safe __attribute__((safe))
60598 # define __force __attribute__((force))
60599 # define __nocast __attribute__((nocast))
60600 # define __iomem __attribute__((noderef, address_space(2)))
60601+# define __force_iomem __force __iomem
60602 # define __acquires(x) __attribute__((context(x,0,1)))
60603 # define __releases(x) __attribute__((context(x,1,0)))
60604 # define __acquire(x) __context__(x,1)
60605 # define __release(x) __context__(x,-1)
60606 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60607 # define __percpu __attribute__((noderef, address_space(3)))
60608+# define __force_percpu __force __percpu
60609 #ifdef CONFIG_SPARSE_RCU_POINTER
60610 # define __rcu __attribute__((noderef, address_space(4)))
60611+# define __force_rcu __force __rcu
60612 #else
60613 # define __rcu
60614+# define __force_rcu
60615 #endif
60616 extern void __chk_user_ptr(const volatile void __user *);
60617 extern void __chk_io_ptr(const volatile void __iomem *);
60618+#elif defined(CHECKER_PLUGIN)
60619+//# define __user
60620+//# define __force_user
60621+//# define __kernel
60622+//# define __force_kernel
60623+# define __safe
60624+# define __force
60625+# define __nocast
60626+# define __iomem
60627+# define __force_iomem
60628+# define __chk_user_ptr(x) (void)0
60629+# define __chk_io_ptr(x) (void)0
60630+# define __builtin_warning(x, y...) (1)
60631+# define __acquires(x)
60632+# define __releases(x)
60633+# define __acquire(x) (void)0
60634+# define __release(x) (void)0
60635+# define __cond_lock(x,c) (c)
60636+# define __percpu
60637+# define __force_percpu
60638+# define __rcu
60639+# define __force_rcu
60640 #else
60641 # define __user
60642+# define __force_user
60643 # define __kernel
60644+# define __force_kernel
60645 # define __safe
60646 # define __force
60647 # define __nocast
60648 # define __iomem
60649+# define __force_iomem
60650 # define __chk_user_ptr(x) (void)0
60651 # define __chk_io_ptr(x) (void)0
60652 # define __builtin_warning(x, y...) (1)
60653@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60654 # define __release(x) (void)0
60655 # define __cond_lock(x,c) (c)
60656 # define __percpu
60657+# define __force_percpu
60658 # define __rcu
60659+# define __force_rcu
60660 #endif
60661
60662 #ifdef __KERNEL__
60663@@ -264,6 +297,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60664 # define __attribute_const__ /* unimplemented */
60665 #endif
60666
60667+#ifndef __no_const
60668+# define __no_const
60669+#endif
60670+
60671+#ifndef __do_const
60672+# define __do_const
60673+#endif
60674+
60675+#ifndef __size_overflow
60676+# define __size_overflow(...)
60677+#endif
60678+
60679+#ifndef __latent_entropy
60680+# define __latent_entropy
60681+#endif
60682+
60683 /*
60684 * Tell gcc if a function is cold. The compiler will assume any path
60685 * directly leading to the call is unlikely.
60686@@ -273,6 +322,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60687 #define __cold
60688 #endif
60689
60690+#ifndef __alloc_size
60691+#define __alloc_size(...)
60692+#endif
60693+
60694+#ifndef __bos
60695+#define __bos(ptr, arg)
60696+#endif
60697+
60698+#ifndef __bos0
60699+#define __bos0(ptr)
60700+#endif
60701+
60702+#ifndef __bos1
60703+#define __bos1(ptr)
60704+#endif
60705+
60706 /* Simple shorthand for a section definition */
60707 #ifndef __section
60708 # define __section(S) __attribute__ ((__section__(#S)))
60709@@ -308,6 +373,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60710 * use is to mediate communication between process-level code and irq/NMI
60711 * handlers, all running on the same CPU.
60712 */
60713-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60714+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60715+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60716
60717 #endif /* __LINUX_COMPILER_H */
60718diff --git a/include/linux/cred.h b/include/linux/cred.h
60719index ebbed2c..908cc2c 100644
60720--- a/include/linux/cred.h
60721+++ b/include/linux/cred.h
60722@@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60723 static inline void validate_process_creds(void)
60724 {
60725 }
60726+static inline void validate_task_creds(struct task_struct *task)
60727+{
60728+}
60729 #endif
60730
60731 /**
60732diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60733index b92eadf..b4ecdc1 100644
60734--- a/include/linux/crypto.h
60735+++ b/include/linux/crypto.h
60736@@ -373,7 +373,7 @@ struct cipher_tfm {
60737 const u8 *key, unsigned int keylen);
60738 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60739 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60740-};
60741+} __no_const;
60742
60743 struct hash_tfm {
60744 int (*init)(struct hash_desc *desc);
60745@@ -394,13 +394,13 @@ struct compress_tfm {
60746 int (*cot_decompress)(struct crypto_tfm *tfm,
60747 const u8 *src, unsigned int slen,
60748 u8 *dst, unsigned int *dlen);
60749-};
60750+} __no_const;
60751
60752 struct rng_tfm {
60753 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60754 unsigned int dlen);
60755 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60756-};
60757+} __no_const;
60758
60759 #define crt_ablkcipher crt_u.ablkcipher
60760 #define crt_aead crt_u.aead
60761diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60762index 7925bf0..d5143d2 100644
60763--- a/include/linux/decompress/mm.h
60764+++ b/include/linux/decompress/mm.h
60765@@ -77,7 +77,7 @@ static void free(void *where)
60766 * warnings when not needed (indeed large_malloc / large_free are not
60767 * needed by inflate */
60768
60769-#define malloc(a) kmalloc(a, GFP_KERNEL)
60770+#define malloc(a) kmalloc((a), GFP_KERNEL)
60771 #define free(a) kfree(a)
60772
60773 #define large_malloc(a) vmalloc(a)
60774diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60775index dfc099e..e583e66 100644
60776--- a/include/linux/dma-mapping.h
60777+++ b/include/linux/dma-mapping.h
60778@@ -51,7 +51,7 @@ struct dma_map_ops {
60779 u64 (*get_required_mask)(struct device *dev);
60780 #endif
60781 int is_phys;
60782-};
60783+} __do_const;
60784
60785 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60786
60787diff --git a/include/linux/efi.h b/include/linux/efi.h
60788index ec45ccd..9923c32 100644
60789--- a/include/linux/efi.h
60790+++ b/include/linux/efi.h
60791@@ -635,7 +635,7 @@ struct efivar_operations {
60792 efi_get_variable_t *get_variable;
60793 efi_get_next_variable_t *get_next_variable;
60794 efi_set_variable_t *set_variable;
60795-};
60796+} __no_const;
60797
60798 struct efivars {
60799 /*
60800diff --git a/include/linux/elf.h b/include/linux/elf.h
60801index 999b4f5..57753b4 100644
60802--- a/include/linux/elf.h
60803+++ b/include/linux/elf.h
60804@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60805 #define PT_GNU_EH_FRAME 0x6474e550
60806
60807 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60808+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60809+
60810+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60811+
60812+/* Constants for the e_flags field */
60813+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60814+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60815+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60816+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60817+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60818+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60819
60820 /*
60821 * Extended Numbering
60822@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60823 #define DT_DEBUG 21
60824 #define DT_TEXTREL 22
60825 #define DT_JMPREL 23
60826+#define DT_FLAGS 30
60827+ #define DF_TEXTREL 0x00000004
60828 #define DT_ENCODING 32
60829 #define OLD_DT_LOOS 0x60000000
60830 #define DT_LOOS 0x6000000d
60831@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60832 #define PF_W 0x2
60833 #define PF_X 0x1
60834
60835+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60836+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60837+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60838+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60839+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60840+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60841+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60842+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60843+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60844+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60845+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60846+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60847+
60848 typedef struct elf32_phdr{
60849 Elf32_Word p_type;
60850 Elf32_Off p_offset;
60851@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60852 #define EI_OSABI 7
60853 #define EI_PAD 8
60854
60855+#define EI_PAX 14
60856+
60857 #define ELFMAG0 0x7f /* EI_MAG */
60858 #define ELFMAG1 'E'
60859 #define ELFMAG2 'L'
60860@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60861 #define elf_note elf32_note
60862 #define elf_addr_t Elf32_Off
60863 #define Elf_Half Elf32_Half
60864+#define elf_dyn Elf32_Dyn
60865
60866 #else
60867
60868@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60869 #define elf_note elf64_note
60870 #define elf_addr_t Elf64_Off
60871 #define Elf_Half Elf64_Half
60872+#define elf_dyn Elf64_Dyn
60873
60874 #endif
60875
60876diff --git a/include/linux/filter.h b/include/linux/filter.h
60877index 82b0135..917914d 100644
60878--- a/include/linux/filter.h
60879+++ b/include/linux/filter.h
60880@@ -146,6 +146,7 @@ struct compat_sock_fprog {
60881
60882 struct sk_buff;
60883 struct sock;
60884+struct bpf_jit_work;
60885
60886 struct sk_filter
60887 {
60888@@ -153,6 +154,9 @@ struct sk_filter
60889 unsigned int len; /* Number of filter blocks */
60890 unsigned int (*bpf_func)(const struct sk_buff *skb,
60891 const struct sock_filter *filter);
60892+#ifdef CONFIG_BPF_JIT
60893+ struct bpf_jit_work *work;
60894+#endif
60895 struct rcu_head rcu;
60896 struct sock_filter insns[0];
60897 };
60898diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60899index 7edcf10..714d5e8 100644
60900--- a/include/linux/firewire.h
60901+++ b/include/linux/firewire.h
60902@@ -430,7 +430,7 @@ struct fw_iso_context {
60903 union {
60904 fw_iso_callback_t sc;
60905 fw_iso_mc_callback_t mc;
60906- } callback;
60907+ } __no_const callback;
60908 void *callback_data;
60909 };
60910
60911diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
60912index 0e4e2ee..4ff4312 100644
60913--- a/include/linux/frontswap.h
60914+++ b/include/linux/frontswap.h
60915@@ -11,7 +11,7 @@ struct frontswap_ops {
60916 int (*load)(unsigned, pgoff_t, struct page *);
60917 void (*invalidate_page)(unsigned, pgoff_t);
60918 void (*invalidate_area)(unsigned);
60919-};
60920+} __no_const;
60921
60922 extern bool frontswap_enabled;
60923 extern struct frontswap_ops
60924diff --git a/include/linux/fs.h b/include/linux/fs.h
60925index 17fd887..8eebca0 100644
60926--- a/include/linux/fs.h
60927+++ b/include/linux/fs.h
60928@@ -1663,7 +1663,8 @@ struct file_operations {
60929 int (*setlease)(struct file *, long, struct file_lock **);
60930 long (*fallocate)(struct file *file, int mode, loff_t offset,
60931 loff_t len);
60932-};
60933+} __do_const;
60934+typedef struct file_operations __no_const file_operations_no_const;
60935
60936 struct inode_operations {
60937 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60938diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60939index 003dc0f..3c4ea97 100644
60940--- a/include/linux/fs_struct.h
60941+++ b/include/linux/fs_struct.h
60942@@ -6,7 +6,7 @@
60943 #include <linux/seqlock.h>
60944
60945 struct fs_struct {
60946- int users;
60947+ atomic_t users;
60948 spinlock_t lock;
60949 seqcount_t seq;
60950 int umask;
60951diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60952index ce31408..b1ad003 100644
60953--- a/include/linux/fscache-cache.h
60954+++ b/include/linux/fscache-cache.h
60955@@ -102,7 +102,7 @@ struct fscache_operation {
60956 fscache_operation_release_t release;
60957 };
60958
60959-extern atomic_t fscache_op_debug_id;
60960+extern atomic_unchecked_t fscache_op_debug_id;
60961 extern void fscache_op_work_func(struct work_struct *work);
60962
60963 extern void fscache_enqueue_operation(struct fscache_operation *);
60964@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60965 {
60966 INIT_WORK(&op->work, fscache_op_work_func);
60967 atomic_set(&op->usage, 1);
60968- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60969+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60970 op->processor = processor;
60971 op->release = release;
60972 INIT_LIST_HEAD(&op->pend_link);
60973diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60974index a6dfe69..569586df 100644
60975--- a/include/linux/fsnotify.h
60976+++ b/include/linux/fsnotify.h
60977@@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60978 */
60979 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60980 {
60981- return kstrdup(name, GFP_KERNEL);
60982+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60983 }
60984
60985 /*
60986diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60987index 63d966d..cdcb717 100644
60988--- a/include/linux/fsnotify_backend.h
60989+++ b/include/linux/fsnotify_backend.h
60990@@ -105,6 +105,7 @@ struct fsnotify_ops {
60991 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60992 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60993 };
60994+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60995
60996 /*
60997 * A group is a "thing" that wants to receive notification about filesystem
60998diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60999index 176a939..1462211 100644
61000--- a/include/linux/ftrace_event.h
61001+++ b/include/linux/ftrace_event.h
61002@@ -97,7 +97,7 @@ struct trace_event_functions {
61003 trace_print_func raw;
61004 trace_print_func hex;
61005 trace_print_func binary;
61006-};
61007+} __no_const;
61008
61009 struct trace_event {
61010 struct hlist_node node;
61011@@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61012 extern int trace_add_event_call(struct ftrace_event_call *call);
61013 extern void trace_remove_event_call(struct ftrace_event_call *call);
61014
61015-#define is_signed_type(type) (((type)(-1)) < 0)
61016+#define is_signed_type(type) (((type)(-1)) < (type)1)
61017
61018 int trace_set_clr_event(const char *system, const char *event, int set);
61019
61020diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61021index 017a7fb..33a8507 100644
61022--- a/include/linux/genhd.h
61023+++ b/include/linux/genhd.h
61024@@ -185,7 +185,7 @@ struct gendisk {
61025 struct kobject *slave_dir;
61026
61027 struct timer_rand_state *random;
61028- atomic_t sync_io; /* RAID */
61029+ atomic_unchecked_t sync_io; /* RAID */
61030 struct disk_events *ev;
61031 #ifdef CONFIG_BLK_DEV_INTEGRITY
61032 struct blk_integrity *integrity;
61033diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61034index 1e49be4..b8a9305 100644
61035--- a/include/linux/gfp.h
61036+++ b/include/linux/gfp.h
61037@@ -38,6 +38,12 @@ struct vm_area_struct;
61038 #define ___GFP_OTHER_NODE 0x800000u
61039 #define ___GFP_WRITE 0x1000000u
61040
61041+#ifdef CONFIG_PAX_USERCOPY_SLABS
61042+#define ___GFP_USERCOPY 0x2000000u
61043+#else
61044+#define ___GFP_USERCOPY 0
61045+#endif
61046+
61047 /*
61048 * GFP bitmasks..
61049 *
61050@@ -87,6 +93,7 @@ struct vm_area_struct;
61051 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61052 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61053 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61054+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61055
61056 /*
61057 * This may seem redundant, but it's a way of annotating false positives vs.
61058@@ -94,7 +101,7 @@ struct vm_area_struct;
61059 */
61060 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61061
61062-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61063+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61064 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61065
61066 /* This equals 0, but use constants in case they ever change */
61067@@ -148,6 +155,8 @@ struct vm_area_struct;
61068 /* 4GB DMA on some platforms */
61069 #define GFP_DMA32 __GFP_DMA32
61070
61071+#define GFP_USERCOPY __GFP_USERCOPY
61072+
61073 /* Convert GFP flags to their corresponding migrate type */
61074 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61075 {
61076diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61077new file mode 100644
61078index 0000000..c938b1f
61079--- /dev/null
61080+++ b/include/linux/gracl.h
61081@@ -0,0 +1,319 @@
61082+#ifndef GR_ACL_H
61083+#define GR_ACL_H
61084+
61085+#include <linux/grdefs.h>
61086+#include <linux/resource.h>
61087+#include <linux/capability.h>
61088+#include <linux/dcache.h>
61089+#include <asm/resource.h>
61090+
61091+/* Major status information */
61092+
61093+#define GR_VERSION "grsecurity 2.9.1"
61094+#define GRSECURITY_VERSION 0x2901
61095+
61096+enum {
61097+ GR_SHUTDOWN = 0,
61098+ GR_ENABLE = 1,
61099+ GR_SPROLE = 2,
61100+ GR_RELOAD = 3,
61101+ GR_SEGVMOD = 4,
61102+ GR_STATUS = 5,
61103+ GR_UNSPROLE = 6,
61104+ GR_PASSSET = 7,
61105+ GR_SPROLEPAM = 8,
61106+};
61107+
61108+/* Password setup definitions
61109+ * kernel/grhash.c */
61110+enum {
61111+ GR_PW_LEN = 128,
61112+ GR_SALT_LEN = 16,
61113+ GR_SHA_LEN = 32,
61114+};
61115+
61116+enum {
61117+ GR_SPROLE_LEN = 64,
61118+};
61119+
61120+enum {
61121+ GR_NO_GLOB = 0,
61122+ GR_REG_GLOB,
61123+ GR_CREATE_GLOB
61124+};
61125+
61126+#define GR_NLIMITS 32
61127+
61128+/* Begin Data Structures */
61129+
61130+struct sprole_pw {
61131+ unsigned char *rolename;
61132+ unsigned char salt[GR_SALT_LEN];
61133+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61134+};
61135+
61136+struct name_entry {
61137+ __u32 key;
61138+ ino_t inode;
61139+ dev_t device;
61140+ char *name;
61141+ __u16 len;
61142+ __u8 deleted;
61143+ struct name_entry *prev;
61144+ struct name_entry *next;
61145+};
61146+
61147+struct inodev_entry {
61148+ struct name_entry *nentry;
61149+ struct inodev_entry *prev;
61150+ struct inodev_entry *next;
61151+};
61152+
61153+struct acl_role_db {
61154+ struct acl_role_label **r_hash;
61155+ __u32 r_size;
61156+};
61157+
61158+struct inodev_db {
61159+ struct inodev_entry **i_hash;
61160+ __u32 i_size;
61161+};
61162+
61163+struct name_db {
61164+ struct name_entry **n_hash;
61165+ __u32 n_size;
61166+};
61167+
61168+struct crash_uid {
61169+ uid_t uid;
61170+ unsigned long expires;
61171+};
61172+
61173+struct gr_hash_struct {
61174+ void **table;
61175+ void **nametable;
61176+ void *first;
61177+ __u32 table_size;
61178+ __u32 used_size;
61179+ int type;
61180+};
61181+
61182+/* Userspace Grsecurity ACL data structures */
61183+
61184+struct acl_subject_label {
61185+ char *filename;
61186+ ino_t inode;
61187+ dev_t device;
61188+ __u32 mode;
61189+ kernel_cap_t cap_mask;
61190+ kernel_cap_t cap_lower;
61191+ kernel_cap_t cap_invert_audit;
61192+
61193+ struct rlimit res[GR_NLIMITS];
61194+ __u32 resmask;
61195+
61196+ __u8 user_trans_type;
61197+ __u8 group_trans_type;
61198+ uid_t *user_transitions;
61199+ gid_t *group_transitions;
61200+ __u16 user_trans_num;
61201+ __u16 group_trans_num;
61202+
61203+ __u32 sock_families[2];
61204+ __u32 ip_proto[8];
61205+ __u32 ip_type;
61206+ struct acl_ip_label **ips;
61207+ __u32 ip_num;
61208+ __u32 inaddr_any_override;
61209+
61210+ __u32 crashes;
61211+ unsigned long expires;
61212+
61213+ struct acl_subject_label *parent_subject;
61214+ struct gr_hash_struct *hash;
61215+ struct acl_subject_label *prev;
61216+ struct acl_subject_label *next;
61217+
61218+ struct acl_object_label **obj_hash;
61219+ __u32 obj_hash_size;
61220+ __u16 pax_flags;
61221+};
61222+
61223+struct role_allowed_ip {
61224+ __u32 addr;
61225+ __u32 netmask;
61226+
61227+ struct role_allowed_ip *prev;
61228+ struct role_allowed_ip *next;
61229+};
61230+
61231+struct role_transition {
61232+ char *rolename;
61233+
61234+ struct role_transition *prev;
61235+ struct role_transition *next;
61236+};
61237+
61238+struct acl_role_label {
61239+ char *rolename;
61240+ uid_t uidgid;
61241+ __u16 roletype;
61242+
61243+ __u16 auth_attempts;
61244+ unsigned long expires;
61245+
61246+ struct acl_subject_label *root_label;
61247+ struct gr_hash_struct *hash;
61248+
61249+ struct acl_role_label *prev;
61250+ struct acl_role_label *next;
61251+
61252+ struct role_transition *transitions;
61253+ struct role_allowed_ip *allowed_ips;
61254+ uid_t *domain_children;
61255+ __u16 domain_child_num;
61256+
61257+ umode_t umask;
61258+
61259+ struct acl_subject_label **subj_hash;
61260+ __u32 subj_hash_size;
61261+};
61262+
61263+struct user_acl_role_db {
61264+ struct acl_role_label **r_table;
61265+ __u32 num_pointers; /* Number of allocations to track */
61266+ __u32 num_roles; /* Number of roles */
61267+ __u32 num_domain_children; /* Number of domain children */
61268+ __u32 num_subjects; /* Number of subjects */
61269+ __u32 num_objects; /* Number of objects */
61270+};
61271+
61272+struct acl_object_label {
61273+ char *filename;
61274+ ino_t inode;
61275+ dev_t device;
61276+ __u32 mode;
61277+
61278+ struct acl_subject_label *nested;
61279+ struct acl_object_label *globbed;
61280+
61281+ /* next two structures not used */
61282+
61283+ struct acl_object_label *prev;
61284+ struct acl_object_label *next;
61285+};
61286+
61287+struct acl_ip_label {
61288+ char *iface;
61289+ __u32 addr;
61290+ __u32 netmask;
61291+ __u16 low, high;
61292+ __u8 mode;
61293+ __u32 type;
61294+ __u32 proto[8];
61295+
61296+ /* next two structures not used */
61297+
61298+ struct acl_ip_label *prev;
61299+ struct acl_ip_label *next;
61300+};
61301+
61302+struct gr_arg {
61303+ struct user_acl_role_db role_db;
61304+ unsigned char pw[GR_PW_LEN];
61305+ unsigned char salt[GR_SALT_LEN];
61306+ unsigned char sum[GR_SHA_LEN];
61307+ unsigned char sp_role[GR_SPROLE_LEN];
61308+ struct sprole_pw *sprole_pws;
61309+ dev_t segv_device;
61310+ ino_t segv_inode;
61311+ uid_t segv_uid;
61312+ __u16 num_sprole_pws;
61313+ __u16 mode;
61314+};
61315+
61316+struct gr_arg_wrapper {
61317+ struct gr_arg *arg;
61318+ __u32 version;
61319+ __u32 size;
61320+};
61321+
61322+struct subject_map {
61323+ struct acl_subject_label *user;
61324+ struct acl_subject_label *kernel;
61325+ struct subject_map *prev;
61326+ struct subject_map *next;
61327+};
61328+
61329+struct acl_subj_map_db {
61330+ struct subject_map **s_hash;
61331+ __u32 s_size;
61332+};
61333+
61334+/* End Data Structures Section */
61335+
61336+/* Hash functions generated by empirical testing by Brad Spengler
61337+ Makes good use of the low bits of the inode. Generally 0-1 times
61338+ in loop for successful match. 0-3 for unsuccessful match.
61339+ Shift/add algorithm with modulus of table size and an XOR*/
61340+
61341+static __inline__ unsigned int
61342+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61343+{
61344+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
61345+}
61346+
61347+ static __inline__ unsigned int
61348+shash(const struct acl_subject_label *userp, const unsigned int sz)
61349+{
61350+ return ((const unsigned long)userp % sz);
61351+}
61352+
61353+static __inline__ unsigned int
61354+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61355+{
61356+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61357+}
61358+
61359+static __inline__ unsigned int
61360+nhash(const char *name, const __u16 len, const unsigned int sz)
61361+{
61362+ return full_name_hash((const unsigned char *)name, len) % sz;
61363+}
61364+
61365+#define FOR_EACH_ROLE_START(role) \
61366+ role = role_list; \
61367+ while (role) {
61368+
61369+#define FOR_EACH_ROLE_END(role) \
61370+ role = role->prev; \
61371+ }
61372+
61373+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61374+ subj = NULL; \
61375+ iter = 0; \
61376+ while (iter < role->subj_hash_size) { \
61377+ if (subj == NULL) \
61378+ subj = role->subj_hash[iter]; \
61379+ if (subj == NULL) { \
61380+ iter++; \
61381+ continue; \
61382+ }
61383+
61384+#define FOR_EACH_SUBJECT_END(subj,iter) \
61385+ subj = subj->next; \
61386+ if (subj == NULL) \
61387+ iter++; \
61388+ }
61389+
61390+
61391+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61392+ subj = role->hash->first; \
61393+ while (subj != NULL) {
61394+
61395+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61396+ subj = subj->next; \
61397+ }
61398+
61399+#endif
61400+
61401diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61402new file mode 100644
61403index 0000000..323ecf2
61404--- /dev/null
61405+++ b/include/linux/gralloc.h
61406@@ -0,0 +1,9 @@
61407+#ifndef __GRALLOC_H
61408+#define __GRALLOC_H
61409+
61410+void acl_free_all(void);
61411+int acl_alloc_stack_init(unsigned long size);
61412+void *acl_alloc(unsigned long len);
61413+void *acl_alloc_num(unsigned long num, unsigned long len);
61414+
61415+#endif
61416diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61417new file mode 100644
61418index 0000000..b30e9bc
61419--- /dev/null
61420+++ b/include/linux/grdefs.h
61421@@ -0,0 +1,140 @@
61422+#ifndef GRDEFS_H
61423+#define GRDEFS_H
61424+
61425+/* Begin grsecurity status declarations */
61426+
61427+enum {
61428+ GR_READY = 0x01,
61429+ GR_STATUS_INIT = 0x00 // disabled state
61430+};
61431+
61432+/* Begin ACL declarations */
61433+
61434+/* Role flags */
61435+
61436+enum {
61437+ GR_ROLE_USER = 0x0001,
61438+ GR_ROLE_GROUP = 0x0002,
61439+ GR_ROLE_DEFAULT = 0x0004,
61440+ GR_ROLE_SPECIAL = 0x0008,
61441+ GR_ROLE_AUTH = 0x0010,
61442+ GR_ROLE_NOPW = 0x0020,
61443+ GR_ROLE_GOD = 0x0040,
61444+ GR_ROLE_LEARN = 0x0080,
61445+ GR_ROLE_TPE = 0x0100,
61446+ GR_ROLE_DOMAIN = 0x0200,
61447+ GR_ROLE_PAM = 0x0400,
61448+ GR_ROLE_PERSIST = 0x0800
61449+};
61450+
61451+/* ACL Subject and Object mode flags */
61452+enum {
61453+ GR_DELETED = 0x80000000
61454+};
61455+
61456+/* ACL Object-only mode flags */
61457+enum {
61458+ GR_READ = 0x00000001,
61459+ GR_APPEND = 0x00000002,
61460+ GR_WRITE = 0x00000004,
61461+ GR_EXEC = 0x00000008,
61462+ GR_FIND = 0x00000010,
61463+ GR_INHERIT = 0x00000020,
61464+ GR_SETID = 0x00000040,
61465+ GR_CREATE = 0x00000080,
61466+ GR_DELETE = 0x00000100,
61467+ GR_LINK = 0x00000200,
61468+ GR_AUDIT_READ = 0x00000400,
61469+ GR_AUDIT_APPEND = 0x00000800,
61470+ GR_AUDIT_WRITE = 0x00001000,
61471+ GR_AUDIT_EXEC = 0x00002000,
61472+ GR_AUDIT_FIND = 0x00004000,
61473+ GR_AUDIT_INHERIT= 0x00008000,
61474+ GR_AUDIT_SETID = 0x00010000,
61475+ GR_AUDIT_CREATE = 0x00020000,
61476+ GR_AUDIT_DELETE = 0x00040000,
61477+ GR_AUDIT_LINK = 0x00080000,
61478+ GR_PTRACERD = 0x00100000,
61479+ GR_NOPTRACE = 0x00200000,
61480+ GR_SUPPRESS = 0x00400000,
61481+ GR_NOLEARN = 0x00800000,
61482+ GR_INIT_TRANSFER= 0x01000000
61483+};
61484+
61485+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61486+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61487+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61488+
61489+/* ACL subject-only mode flags */
61490+enum {
61491+ GR_KILL = 0x00000001,
61492+ GR_VIEW = 0x00000002,
61493+ GR_PROTECTED = 0x00000004,
61494+ GR_LEARN = 0x00000008,
61495+ GR_OVERRIDE = 0x00000010,
61496+ /* just a placeholder, this mode is only used in userspace */
61497+ GR_DUMMY = 0x00000020,
61498+ GR_PROTSHM = 0x00000040,
61499+ GR_KILLPROC = 0x00000080,
61500+ GR_KILLIPPROC = 0x00000100,
61501+ /* just a placeholder, this mode is only used in userspace */
61502+ GR_NOTROJAN = 0x00000200,
61503+ GR_PROTPROCFD = 0x00000400,
61504+ GR_PROCACCT = 0x00000800,
61505+ GR_RELAXPTRACE = 0x00001000,
61506+ GR_NESTED = 0x00002000,
61507+ GR_INHERITLEARN = 0x00004000,
61508+ GR_PROCFIND = 0x00008000,
61509+ GR_POVERRIDE = 0x00010000,
61510+ GR_KERNELAUTH = 0x00020000,
61511+ GR_ATSECURE = 0x00040000,
61512+ GR_SHMEXEC = 0x00080000
61513+};
61514+
61515+enum {
61516+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61517+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61518+ GR_PAX_ENABLE_MPROTECT = 0x0004,
61519+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
61520+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61521+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61522+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61523+ GR_PAX_DISABLE_MPROTECT = 0x0400,
61524+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
61525+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61526+};
61527+
61528+enum {
61529+ GR_ID_USER = 0x01,
61530+ GR_ID_GROUP = 0x02,
61531+};
61532+
61533+enum {
61534+ GR_ID_ALLOW = 0x01,
61535+ GR_ID_DENY = 0x02,
61536+};
61537+
61538+#define GR_CRASH_RES 31
61539+#define GR_UIDTABLE_MAX 500
61540+
61541+/* begin resource learning section */
61542+enum {
61543+ GR_RLIM_CPU_BUMP = 60,
61544+ GR_RLIM_FSIZE_BUMP = 50000,
61545+ GR_RLIM_DATA_BUMP = 10000,
61546+ GR_RLIM_STACK_BUMP = 1000,
61547+ GR_RLIM_CORE_BUMP = 10000,
61548+ GR_RLIM_RSS_BUMP = 500000,
61549+ GR_RLIM_NPROC_BUMP = 1,
61550+ GR_RLIM_NOFILE_BUMP = 5,
61551+ GR_RLIM_MEMLOCK_BUMP = 50000,
61552+ GR_RLIM_AS_BUMP = 500000,
61553+ GR_RLIM_LOCKS_BUMP = 2,
61554+ GR_RLIM_SIGPENDING_BUMP = 5,
61555+ GR_RLIM_MSGQUEUE_BUMP = 10000,
61556+ GR_RLIM_NICE_BUMP = 1,
61557+ GR_RLIM_RTPRIO_BUMP = 1,
61558+ GR_RLIM_RTTIME_BUMP = 1000000
61559+};
61560+
61561+#endif
61562diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61563new file mode 100644
61564index 0000000..c9292f7
61565--- /dev/null
61566+++ b/include/linux/grinternal.h
61567@@ -0,0 +1,223 @@
61568+#ifndef __GRINTERNAL_H
61569+#define __GRINTERNAL_H
61570+
61571+#ifdef CONFIG_GRKERNSEC
61572+
61573+#include <linux/fs.h>
61574+#include <linux/mnt_namespace.h>
61575+#include <linux/nsproxy.h>
61576+#include <linux/gracl.h>
61577+#include <linux/grdefs.h>
61578+#include <linux/grmsg.h>
61579+
61580+void gr_add_learn_entry(const char *fmt, ...)
61581+ __attribute__ ((format (printf, 1, 2)));
61582+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61583+ const struct vfsmount *mnt);
61584+__u32 gr_check_create(const struct dentry *new_dentry,
61585+ const struct dentry *parent,
61586+ const struct vfsmount *mnt, const __u32 mode);
61587+int gr_check_protected_task(const struct task_struct *task);
61588+__u32 to_gr_audit(const __u32 reqmode);
61589+int gr_set_acls(const int type);
61590+int gr_apply_subject_to_task(struct task_struct *task);
61591+int gr_acl_is_enabled(void);
61592+char gr_roletype_to_char(void);
61593+
61594+void gr_handle_alertkill(struct task_struct *task);
61595+char *gr_to_filename(const struct dentry *dentry,
61596+ const struct vfsmount *mnt);
61597+char *gr_to_filename1(const struct dentry *dentry,
61598+ const struct vfsmount *mnt);
61599+char *gr_to_filename2(const struct dentry *dentry,
61600+ const struct vfsmount *mnt);
61601+char *gr_to_filename3(const struct dentry *dentry,
61602+ const struct vfsmount *mnt);
61603+
61604+extern int grsec_enable_ptrace_readexec;
61605+extern int grsec_enable_harden_ptrace;
61606+extern int grsec_enable_link;
61607+extern int grsec_enable_fifo;
61608+extern int grsec_enable_execve;
61609+extern int grsec_enable_shm;
61610+extern int grsec_enable_execlog;
61611+extern int grsec_enable_signal;
61612+extern int grsec_enable_audit_ptrace;
61613+extern int grsec_enable_forkfail;
61614+extern int grsec_enable_time;
61615+extern int grsec_enable_rofs;
61616+extern int grsec_enable_chroot_shmat;
61617+extern int grsec_enable_chroot_mount;
61618+extern int grsec_enable_chroot_double;
61619+extern int grsec_enable_chroot_pivot;
61620+extern int grsec_enable_chroot_chdir;
61621+extern int grsec_enable_chroot_chmod;
61622+extern int grsec_enable_chroot_mknod;
61623+extern int grsec_enable_chroot_fchdir;
61624+extern int grsec_enable_chroot_nice;
61625+extern int grsec_enable_chroot_execlog;
61626+extern int grsec_enable_chroot_caps;
61627+extern int grsec_enable_chroot_sysctl;
61628+extern int grsec_enable_chroot_unix;
61629+extern int grsec_enable_symlinkown;
61630+extern int grsec_symlinkown_gid;
61631+extern int grsec_enable_tpe;
61632+extern int grsec_tpe_gid;
61633+extern int grsec_enable_tpe_all;
61634+extern int grsec_enable_tpe_invert;
61635+extern int grsec_enable_socket_all;
61636+extern int grsec_socket_all_gid;
61637+extern int grsec_enable_socket_client;
61638+extern int grsec_socket_client_gid;
61639+extern int grsec_enable_socket_server;
61640+extern int grsec_socket_server_gid;
61641+extern int grsec_audit_gid;
61642+extern int grsec_enable_group;
61643+extern int grsec_enable_audit_textrel;
61644+extern int grsec_enable_log_rwxmaps;
61645+extern int grsec_enable_mount;
61646+extern int grsec_enable_chdir;
61647+extern int grsec_resource_logging;
61648+extern int grsec_enable_blackhole;
61649+extern int grsec_lastack_retries;
61650+extern int grsec_enable_brute;
61651+extern int grsec_lock;
61652+
61653+extern spinlock_t grsec_alert_lock;
61654+extern unsigned long grsec_alert_wtime;
61655+extern unsigned long grsec_alert_fyet;
61656+
61657+extern spinlock_t grsec_audit_lock;
61658+
61659+extern rwlock_t grsec_exec_file_lock;
61660+
61661+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61662+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61663+ (tsk)->exec_file->f_vfsmnt) : "/")
61664+
61665+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61666+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61667+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61668+
61669+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61670+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
61671+ (tsk)->exec_file->f_vfsmnt) : "/")
61672+
61673+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61674+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61675+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61676+
61677+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61678+
61679+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61680+
61681+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61682+ (task)->pid, (cred)->uid, \
61683+ (cred)->euid, (cred)->gid, (cred)->egid, \
61684+ gr_parent_task_fullpath(task), \
61685+ (task)->real_parent->comm, (task)->real_parent->pid, \
61686+ (pcred)->uid, (pcred)->euid, \
61687+ (pcred)->gid, (pcred)->egid
61688+
61689+#define GR_CHROOT_CAPS {{ \
61690+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61691+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61692+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61693+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61694+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61695+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61696+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61697+
61698+#define security_learn(normal_msg,args...) \
61699+({ \
61700+ read_lock(&grsec_exec_file_lock); \
61701+ gr_add_learn_entry(normal_msg "\n", ## args); \
61702+ read_unlock(&grsec_exec_file_lock); \
61703+})
61704+
61705+enum {
61706+ GR_DO_AUDIT,
61707+ GR_DONT_AUDIT,
61708+ /* used for non-audit messages that we shouldn't kill the task on */
61709+ GR_DONT_AUDIT_GOOD
61710+};
61711+
61712+enum {
61713+ GR_TTYSNIFF,
61714+ GR_RBAC,
61715+ GR_RBAC_STR,
61716+ GR_STR_RBAC,
61717+ GR_RBAC_MODE2,
61718+ GR_RBAC_MODE3,
61719+ GR_FILENAME,
61720+ GR_SYSCTL_HIDDEN,
61721+ GR_NOARGS,
61722+ GR_ONE_INT,
61723+ GR_ONE_INT_TWO_STR,
61724+ GR_ONE_STR,
61725+ GR_STR_INT,
61726+ GR_TWO_STR_INT,
61727+ GR_TWO_INT,
61728+ GR_TWO_U64,
61729+ GR_THREE_INT,
61730+ GR_FIVE_INT_TWO_STR,
61731+ GR_TWO_STR,
61732+ GR_THREE_STR,
61733+ GR_FOUR_STR,
61734+ GR_STR_FILENAME,
61735+ GR_FILENAME_STR,
61736+ GR_FILENAME_TWO_INT,
61737+ GR_FILENAME_TWO_INT_STR,
61738+ GR_TEXTREL,
61739+ GR_PTRACE,
61740+ GR_RESOURCE,
61741+ GR_CAP,
61742+ GR_SIG,
61743+ GR_SIG2,
61744+ GR_CRASH1,
61745+ GR_CRASH2,
61746+ GR_PSACCT,
61747+ GR_RWXMAP
61748+};
61749+
61750+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61751+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61752+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61753+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61754+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61755+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61756+#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)
61757+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61758+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61759+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61760+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61761+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61762+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61763+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61764+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61765+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61766+#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)
61767+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61768+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61769+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61770+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61771+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61772+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61773+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61774+#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)
61775+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61776+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61777+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61778+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61779+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61780+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61781+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61782+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61783+#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)
61784+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61785+
61786+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61787+
61788+#endif
61789+
61790+#endif
61791diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61792new file mode 100644
61793index 0000000..54f4e85
61794--- /dev/null
61795+++ b/include/linux/grmsg.h
61796@@ -0,0 +1,110 @@
61797+#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"
61798+#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"
61799+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61800+#define GR_STOPMOD_MSG "denied modification of module state by "
61801+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61802+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61803+#define GR_IOPERM_MSG "denied use of ioperm() by "
61804+#define GR_IOPL_MSG "denied use of iopl() by "
61805+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61806+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61807+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61808+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61809+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61810+#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"
61811+#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"
61812+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61813+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61814+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61815+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61816+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61817+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61818+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61819+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61820+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61821+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61822+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61823+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61824+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61825+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61826+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61827+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61828+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61829+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61830+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61831+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61832+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61833+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61834+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61835+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61836+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61837+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61838+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61839+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61840+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61841+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61842+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61843+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61844+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61845+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61846+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61847+#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"
61848+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61849+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61850+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61851+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61852+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61853+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61854+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61855+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61856+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61857+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61858+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61859+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61860+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61861+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61862+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61863+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61864+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61865+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61866+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61867+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61868+#define GR_FAILFORK_MSG "failed fork with errno %s by "
61869+#define GR_NICE_CHROOT_MSG "denied priority change by "
61870+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61871+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61872+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61873+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61874+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61875+#define GR_TIME_MSG "time set by "
61876+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61877+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61878+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61879+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61880+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61881+#define GR_BIND_MSG "denied bind() by "
61882+#define GR_CONNECT_MSG "denied connect() by "
61883+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61884+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61885+#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"
61886+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61887+#define GR_CAP_ACL_MSG "use of %s denied for "
61888+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61889+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61890+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61891+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61892+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61893+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61894+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61895+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61896+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61897+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61898+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61899+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61900+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61901+#define GR_VM86_MSG "denied use of vm86 by "
61902+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61903+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61904+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61905+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61906+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
61907diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61908new file mode 100644
61909index 0000000..38bfb04
61910--- /dev/null
61911+++ b/include/linux/grsecurity.h
61912@@ -0,0 +1,233 @@
61913+#ifndef GR_SECURITY_H
61914+#define GR_SECURITY_H
61915+#include <linux/fs.h>
61916+#include <linux/fs_struct.h>
61917+#include <linux/binfmts.h>
61918+#include <linux/gracl.h>
61919+
61920+/* notify of brain-dead configs */
61921+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61922+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61923+#endif
61924+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61925+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61926+#endif
61927+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61928+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61929+#endif
61930+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61931+#error "CONFIG_PAX enabled, but no PaX options are enabled."
61932+#endif
61933+
61934+#include <linux/compat.h>
61935+
61936+struct user_arg_ptr {
61937+#ifdef CONFIG_COMPAT
61938+ bool is_compat;
61939+#endif
61940+ union {
61941+ const char __user *const __user *native;
61942+#ifdef CONFIG_COMPAT
61943+ compat_uptr_t __user *compat;
61944+#endif
61945+ } ptr;
61946+};
61947+
61948+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61949+void gr_handle_brute_check(void);
61950+void gr_handle_kernel_exploit(void);
61951+int gr_process_user_ban(void);
61952+
61953+char gr_roletype_to_char(void);
61954+
61955+int gr_acl_enable_at_secure(void);
61956+
61957+int gr_check_user_change(int real, int effective, int fs);
61958+int gr_check_group_change(int real, int effective, int fs);
61959+
61960+void gr_del_task_from_ip_table(struct task_struct *p);
61961+
61962+int gr_pid_is_chrooted(struct task_struct *p);
61963+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61964+int gr_handle_chroot_nice(void);
61965+int gr_handle_chroot_sysctl(const int op);
61966+int gr_handle_chroot_setpriority(struct task_struct *p,
61967+ const int niceval);
61968+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61969+int gr_handle_chroot_chroot(const struct dentry *dentry,
61970+ const struct vfsmount *mnt);
61971+void gr_handle_chroot_chdir(struct path *path);
61972+int gr_handle_chroot_chmod(const struct dentry *dentry,
61973+ const struct vfsmount *mnt, const int mode);
61974+int gr_handle_chroot_mknod(const struct dentry *dentry,
61975+ const struct vfsmount *mnt, const int mode);
61976+int gr_handle_chroot_mount(const struct dentry *dentry,
61977+ const struct vfsmount *mnt,
61978+ const char *dev_name);
61979+int gr_handle_chroot_pivot(void);
61980+int gr_handle_chroot_unix(const pid_t pid);
61981+
61982+int gr_handle_rawio(const struct inode *inode);
61983+
61984+void gr_handle_ioperm(void);
61985+void gr_handle_iopl(void);
61986+
61987+umode_t gr_acl_umask(void);
61988+
61989+int gr_tpe_allow(const struct file *file);
61990+
61991+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61992+void gr_clear_chroot_entries(struct task_struct *task);
61993+
61994+void gr_log_forkfail(const int retval);
61995+void gr_log_timechange(void);
61996+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61997+void gr_log_chdir(const struct dentry *dentry,
61998+ const struct vfsmount *mnt);
61999+void gr_log_chroot_exec(const struct dentry *dentry,
62000+ const struct vfsmount *mnt);
62001+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62002+void gr_log_remount(const char *devname, const int retval);
62003+void gr_log_unmount(const char *devname, const int retval);
62004+void gr_log_mount(const char *from, const char *to, const int retval);
62005+void gr_log_textrel(struct vm_area_struct *vma);
62006+void gr_log_rwxmmap(struct file *file);
62007+void gr_log_rwxmprotect(struct file *file);
62008+
62009+int gr_handle_follow_link(const struct inode *parent,
62010+ const struct inode *inode,
62011+ const struct dentry *dentry,
62012+ const struct vfsmount *mnt);
62013+int gr_handle_fifo(const struct dentry *dentry,
62014+ const struct vfsmount *mnt,
62015+ const struct dentry *dir, const int flag,
62016+ const int acc_mode);
62017+int gr_handle_hardlink(const struct dentry *dentry,
62018+ const struct vfsmount *mnt,
62019+ struct inode *inode,
62020+ const int mode, const char *to);
62021+
62022+int gr_is_capable(const int cap);
62023+int gr_is_capable_nolog(const int cap);
62024+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62025+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62026+
62027+void gr_learn_resource(const struct task_struct *task, const int limit,
62028+ const unsigned long wanted, const int gt);
62029+void gr_copy_label(struct task_struct *tsk);
62030+void gr_handle_crash(struct task_struct *task, const int sig);
62031+int gr_handle_signal(const struct task_struct *p, const int sig);
62032+int gr_check_crash_uid(const uid_t uid);
62033+int gr_check_protected_task(const struct task_struct *task);
62034+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62035+int gr_acl_handle_mmap(const struct file *file,
62036+ const unsigned long prot);
62037+int gr_acl_handle_mprotect(const struct file *file,
62038+ const unsigned long prot);
62039+int gr_check_hidden_task(const struct task_struct *tsk);
62040+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62041+ const struct vfsmount *mnt);
62042+__u32 gr_acl_handle_utime(const struct dentry *dentry,
62043+ const struct vfsmount *mnt);
62044+__u32 gr_acl_handle_access(const struct dentry *dentry,
62045+ const struct vfsmount *mnt, const int fmode);
62046+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62047+ const struct vfsmount *mnt, umode_t *mode);
62048+__u32 gr_acl_handle_chown(const struct dentry *dentry,
62049+ const struct vfsmount *mnt);
62050+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62051+ const struct vfsmount *mnt);
62052+int gr_handle_ptrace(struct task_struct *task, const long request);
62053+int gr_handle_proc_ptrace(struct task_struct *task);
62054+__u32 gr_acl_handle_execve(const struct dentry *dentry,
62055+ const struct vfsmount *mnt);
62056+int gr_check_crash_exec(const struct file *filp);
62057+int gr_acl_is_enabled(void);
62058+void gr_set_kernel_label(struct task_struct *task);
62059+void gr_set_role_label(struct task_struct *task, const uid_t uid,
62060+ const gid_t gid);
62061+int gr_set_proc_label(const struct dentry *dentry,
62062+ const struct vfsmount *mnt,
62063+ const int unsafe_flags);
62064+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62065+ const struct vfsmount *mnt);
62066+__u32 gr_acl_handle_open(const struct dentry *dentry,
62067+ const struct vfsmount *mnt, int acc_mode);
62068+__u32 gr_acl_handle_creat(const struct dentry *dentry,
62069+ const struct dentry *p_dentry,
62070+ const struct vfsmount *p_mnt,
62071+ int open_flags, int acc_mode, const int imode);
62072+void gr_handle_create(const struct dentry *dentry,
62073+ const struct vfsmount *mnt);
62074+void gr_handle_proc_create(const struct dentry *dentry,
62075+ const struct inode *inode);
62076+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62077+ const struct dentry *parent_dentry,
62078+ const struct vfsmount *parent_mnt,
62079+ const int mode);
62080+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62081+ const struct dentry *parent_dentry,
62082+ const struct vfsmount *parent_mnt);
62083+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62084+ const struct vfsmount *mnt);
62085+void gr_handle_delete(const ino_t ino, const dev_t dev);
62086+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62087+ const struct vfsmount *mnt);
62088+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62089+ const struct dentry *parent_dentry,
62090+ const struct vfsmount *parent_mnt,
62091+ const char *from);
62092+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62093+ const struct dentry *parent_dentry,
62094+ const struct vfsmount *parent_mnt,
62095+ const struct dentry *old_dentry,
62096+ const struct vfsmount *old_mnt, const char *to);
62097+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62098+int gr_acl_handle_rename(struct dentry *new_dentry,
62099+ struct dentry *parent_dentry,
62100+ const struct vfsmount *parent_mnt,
62101+ struct dentry *old_dentry,
62102+ struct inode *old_parent_inode,
62103+ struct vfsmount *old_mnt, const char *newname);
62104+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62105+ struct dentry *old_dentry,
62106+ struct dentry *new_dentry,
62107+ struct vfsmount *mnt, const __u8 replace);
62108+__u32 gr_check_link(const struct dentry *new_dentry,
62109+ const struct dentry *parent_dentry,
62110+ const struct vfsmount *parent_mnt,
62111+ const struct dentry *old_dentry,
62112+ const struct vfsmount *old_mnt);
62113+int gr_acl_handle_filldir(const struct file *file, const char *name,
62114+ const unsigned int namelen, const ino_t ino);
62115+
62116+__u32 gr_acl_handle_unix(const struct dentry *dentry,
62117+ const struct vfsmount *mnt);
62118+void gr_acl_handle_exit(void);
62119+void gr_acl_handle_psacct(struct task_struct *task, const long code);
62120+int gr_acl_handle_procpidmem(const struct task_struct *task);
62121+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62122+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62123+void gr_audit_ptrace(struct task_struct *task);
62124+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62125+
62126+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62127+
62128+#ifdef CONFIG_GRKERNSEC
62129+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62130+void gr_handle_vm86(void);
62131+void gr_handle_mem_readwrite(u64 from, u64 to);
62132+
62133+void gr_log_badprocpid(const char *entry);
62134+
62135+extern int grsec_enable_dmesg;
62136+extern int grsec_disable_privio;
62137+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62138+extern int grsec_enable_chroot_findtask;
62139+#endif
62140+#ifdef CONFIG_GRKERNSEC_SETXID
62141+extern int grsec_enable_setxid;
62142+#endif
62143+#endif
62144+
62145+#endif
62146diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62147new file mode 100644
62148index 0000000..e7ffaaf
62149--- /dev/null
62150+++ b/include/linux/grsock.h
62151@@ -0,0 +1,19 @@
62152+#ifndef __GRSOCK_H
62153+#define __GRSOCK_H
62154+
62155+extern void gr_attach_curr_ip(const struct sock *sk);
62156+extern int gr_handle_sock_all(const int family, const int type,
62157+ const int protocol);
62158+extern int gr_handle_sock_server(const struct sockaddr *sck);
62159+extern int gr_handle_sock_server_other(const struct sock *sck);
62160+extern int gr_handle_sock_client(const struct sockaddr *sck);
62161+extern int gr_search_connect(struct socket * sock,
62162+ struct sockaddr_in * addr);
62163+extern int gr_search_bind(struct socket * sock,
62164+ struct sockaddr_in * addr);
62165+extern int gr_search_listen(struct socket * sock);
62166+extern int gr_search_accept(struct socket * sock);
62167+extern int gr_search_socket(const int domain, const int type,
62168+ const int protocol);
62169+
62170+#endif
62171diff --git a/include/linux/hid.h b/include/linux/hid.h
62172index 449fa38..b37c8cc 100644
62173--- a/include/linux/hid.h
62174+++ b/include/linux/hid.h
62175@@ -704,7 +704,7 @@ struct hid_ll_driver {
62176 unsigned int code, int value);
62177
62178 int (*parse)(struct hid_device *hdev);
62179-};
62180+} __no_const;
62181
62182 #define PM_HINT_FULLON 1<<5
62183 #define PM_HINT_NORMAL 1<<1
62184diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62185index d3999b4..1304cb4 100644
62186--- a/include/linux/highmem.h
62187+++ b/include/linux/highmem.h
62188@@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
62189 kunmap_atomic(kaddr);
62190 }
62191
62192+static inline void sanitize_highpage(struct page *page)
62193+{
62194+ void *kaddr;
62195+ unsigned long flags;
62196+
62197+ local_irq_save(flags);
62198+ kaddr = kmap_atomic(page);
62199+ clear_page(kaddr);
62200+ kunmap_atomic(kaddr);
62201+ local_irq_restore(flags);
62202+}
62203+
62204 static inline void zero_user_segments(struct page *page,
62205 unsigned start1, unsigned end1,
62206 unsigned start2, unsigned end2)
62207diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62208index ddfa041..a44cfff 100644
62209--- a/include/linux/i2c.h
62210+++ b/include/linux/i2c.h
62211@@ -366,6 +366,7 @@ struct i2c_algorithm {
62212 /* To determine what the adapter supports */
62213 u32 (*functionality) (struct i2c_adapter *);
62214 };
62215+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62216
62217 /*
62218 * i2c_adapter is the structure used to identify a physical i2c bus along
62219diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62220index d23c3c2..eb63c81 100644
62221--- a/include/linux/i2o.h
62222+++ b/include/linux/i2o.h
62223@@ -565,7 +565,7 @@ struct i2o_controller {
62224 struct i2o_device *exec; /* Executive */
62225 #if BITS_PER_LONG == 64
62226 spinlock_t context_list_lock; /* lock for context_list */
62227- atomic_t context_list_counter; /* needed for unique contexts */
62228+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62229 struct list_head context_list; /* list of context id's
62230 and pointers */
62231 #endif
62232diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62233index 8185f57..7b2d222 100644
62234--- a/include/linux/if_team.h
62235+++ b/include/linux/if_team.h
62236@@ -74,6 +74,7 @@ struct team_mode_ops {
62237 void (*port_leave)(struct team *team, struct team_port *port);
62238 void (*port_change_mac)(struct team *team, struct team_port *port);
62239 };
62240+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62241
62242 enum team_option_type {
62243 TEAM_OPTION_TYPE_U32,
62244@@ -136,7 +137,7 @@ struct team {
62245 struct list_head option_inst_list; /* list of option instances */
62246
62247 const struct team_mode *mode;
62248- struct team_mode_ops ops;
62249+ team_mode_ops_no_const ops;
62250 long mode_priv[TEAM_MODE_PRIV_LONGS];
62251 };
62252
62253diff --git a/include/linux/init.h b/include/linux/init.h
62254index 6b95109..bcbdd68 100644
62255--- a/include/linux/init.h
62256+++ b/include/linux/init.h
62257@@ -39,9 +39,15 @@
62258 * Also note, that this data cannot be "const".
62259 */
62260
62261+#ifdef MODULE
62262+#define add_latent_entropy
62263+#else
62264+#define add_latent_entropy __latent_entropy
62265+#endif
62266+
62267 /* These are for everybody (although not all archs will actually
62268 discard it in modules) */
62269-#define __init __section(.init.text) __cold notrace
62270+#define __init __section(.init.text) __cold notrace add_latent_entropy
62271 #define __initdata __section(.init.data)
62272 #define __initconst __section(.init.rodata)
62273 #define __exitdata __section(.exit.data)
62274@@ -83,7 +89,7 @@
62275 #define __exit __section(.exit.text) __exitused __cold notrace
62276
62277 /* Used for HOTPLUG */
62278-#define __devinit __section(.devinit.text) __cold notrace
62279+#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62280 #define __devinitdata __section(.devinit.data)
62281 #define __devinitconst __section(.devinit.rodata)
62282 #define __devexit __section(.devexit.text) __exitused __cold notrace
62283@@ -91,7 +97,7 @@
62284 #define __devexitconst __section(.devexit.rodata)
62285
62286 /* Used for HOTPLUG_CPU */
62287-#define __cpuinit __section(.cpuinit.text) __cold notrace
62288+#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62289 #define __cpuinitdata __section(.cpuinit.data)
62290 #define __cpuinitconst __section(.cpuinit.rodata)
62291 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62292@@ -99,7 +105,7 @@
62293 #define __cpuexitconst __section(.cpuexit.rodata)
62294
62295 /* Used for MEMORY_HOTPLUG */
62296-#define __meminit __section(.meminit.text) __cold notrace
62297+#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62298 #define __meminitdata __section(.meminit.data)
62299 #define __meminitconst __section(.meminit.rodata)
62300 #define __memexit __section(.memexit.text) __exitused __cold notrace
62301@@ -294,13 +300,13 @@ void __init parse_early_options(char *cmdline);
62302
62303 /* Each module must use one module_init(). */
62304 #define module_init(initfn) \
62305- static inline initcall_t __inittest(void) \
62306+ static inline __used initcall_t __inittest(void) \
62307 { return initfn; } \
62308 int init_module(void) __attribute__((alias(#initfn)));
62309
62310 /* This is only required if you want to be unloadable. */
62311 #define module_exit(exitfn) \
62312- static inline exitcall_t __exittest(void) \
62313+ static inline __used exitcall_t __exittest(void) \
62314 { return exitfn; } \
62315 void cleanup_module(void) __attribute__((alias(#exitfn)));
62316
62317diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62318index 9e65eff..b131e8b 100644
62319--- a/include/linux/init_task.h
62320+++ b/include/linux/init_task.h
62321@@ -134,6 +134,12 @@ extern struct cred init_cred;
62322
62323 #define INIT_TASK_COMM "swapper"
62324
62325+#ifdef CONFIG_X86
62326+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62327+#else
62328+#define INIT_TASK_THREAD_INFO
62329+#endif
62330+
62331 /*
62332 * INIT_TASK is used to set up the first task table, touch at
62333 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62334@@ -172,6 +178,7 @@ extern struct cred init_cred;
62335 RCU_INIT_POINTER(.cred, &init_cred), \
62336 .comm = INIT_TASK_COMM, \
62337 .thread = INIT_THREAD, \
62338+ INIT_TASK_THREAD_INFO \
62339 .fs = &init_fs, \
62340 .files = &init_files, \
62341 .signal = &init_signals, \
62342diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62343index e6ca56d..8583707 100644
62344--- a/include/linux/intel-iommu.h
62345+++ b/include/linux/intel-iommu.h
62346@@ -296,7 +296,7 @@ struct iommu_flush {
62347 u8 fm, u64 type);
62348 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62349 unsigned int size_order, u64 type);
62350-};
62351+} __no_const;
62352
62353 enum {
62354 SR_DMAR_FECTL_REG,
62355diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62356index e68a8e5..811b9af 100644
62357--- a/include/linux/interrupt.h
62358+++ b/include/linux/interrupt.h
62359@@ -435,7 +435,7 @@ enum
62360 /* map softirq index to softirq name. update 'softirq_to_name' in
62361 * kernel/softirq.c when adding a new softirq.
62362 */
62363-extern char *softirq_to_name[NR_SOFTIRQS];
62364+extern const char * const softirq_to_name[NR_SOFTIRQS];
62365
62366 /* softirq mask and active fields moved to irq_cpustat_t in
62367 * asm/hardirq.h to get better cache usage. KAO
62368@@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62369
62370 struct softirq_action
62371 {
62372- void (*action)(struct softirq_action *);
62373+ void (*action)(void);
62374 };
62375
62376 asmlinkage void do_softirq(void);
62377 asmlinkage void __do_softirq(void);
62378-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62379+extern void open_softirq(int nr, void (*action)(void));
62380 extern void softirq_init(void);
62381 extern void __raise_softirq_irqoff(unsigned int nr);
62382
62383diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62384index 6883e19..06992b1 100644
62385--- a/include/linux/kallsyms.h
62386+++ b/include/linux/kallsyms.h
62387@@ -15,7 +15,8 @@
62388
62389 struct module;
62390
62391-#ifdef CONFIG_KALLSYMS
62392+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62393+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62394 /* Lookup the address for a symbol. Returns 0 if not found. */
62395 unsigned long kallsyms_lookup_name(const char *name);
62396
62397@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62398 /* Stupid that this does nothing, but I didn't create this mess. */
62399 #define __print_symbol(fmt, addr)
62400 #endif /*CONFIG_KALLSYMS*/
62401+#else /* when included by kallsyms.c, vsnprintf.c, or
62402+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62403+extern void __print_symbol(const char *fmt, unsigned long address);
62404+extern int sprint_backtrace(char *buffer, unsigned long address);
62405+extern int sprint_symbol(char *buffer, unsigned long address);
62406+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
62407+const char *kallsyms_lookup(unsigned long addr,
62408+ unsigned long *symbolsize,
62409+ unsigned long *offset,
62410+ char **modname, char *namebuf);
62411+#endif
62412
62413 /* This macro allows us to keep printk typechecking */
62414 static __printf(1, 2)
62415diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62416index c4d2fc1..5df9c19 100644
62417--- a/include/linux/kgdb.h
62418+++ b/include/linux/kgdb.h
62419@@ -53,7 +53,7 @@ extern int kgdb_connected;
62420 extern int kgdb_io_module_registered;
62421
62422 extern atomic_t kgdb_setting_breakpoint;
62423-extern atomic_t kgdb_cpu_doing_single_step;
62424+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62425
62426 extern struct task_struct *kgdb_usethread;
62427 extern struct task_struct *kgdb_contthread;
62428@@ -252,7 +252,7 @@ struct kgdb_arch {
62429 void (*disable_hw_break)(struct pt_regs *regs);
62430 void (*remove_all_hw_break)(void);
62431 void (*correct_hw_break)(void);
62432-};
62433+} __do_const;
62434
62435 /**
62436 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62437@@ -277,7 +277,7 @@ struct kgdb_io {
62438 void (*pre_exception) (void);
62439 void (*post_exception) (void);
62440 int is_console;
62441-};
62442+} __do_const;
62443
62444 extern struct kgdb_arch arch_kgdb_ops;
62445
62446diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62447index 5398d58..5883a34 100644
62448--- a/include/linux/kmod.h
62449+++ b/include/linux/kmod.h
62450@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62451 * usually useless though. */
62452 extern __printf(2, 3)
62453 int __request_module(bool wait, const char *name, ...);
62454+extern __printf(3, 4)
62455+int ___request_module(bool wait, char *param_name, const char *name, ...);
62456 #define request_module(mod...) __request_module(true, mod)
62457 #define request_module_nowait(mod...) __request_module(false, mod)
62458 #define try_then_request_module(x, mod...) \
62459diff --git a/include/linux/kref.h b/include/linux/kref.h
62460index 9c07dce..a92fa71 100644
62461--- a/include/linux/kref.h
62462+++ b/include/linux/kref.h
62463@@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62464 static inline int kref_sub(struct kref *kref, unsigned int count,
62465 void (*release)(struct kref *kref))
62466 {
62467- WARN_ON(release == NULL);
62468+ BUG_ON(release == NULL);
62469
62470 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62471 release(kref);
62472diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62473index 96c158a..1864db5 100644
62474--- a/include/linux/kvm_host.h
62475+++ b/include/linux/kvm_host.h
62476@@ -345,7 +345,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62477 void vcpu_load(struct kvm_vcpu *vcpu);
62478 void vcpu_put(struct kvm_vcpu *vcpu);
62479
62480-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62481+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62482 struct module *module);
62483 void kvm_exit(void);
62484
62485@@ -511,7 +511,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62486 struct kvm_guest_debug *dbg);
62487 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62488
62489-int kvm_arch_init(void *opaque);
62490+int kvm_arch_init(const void *opaque);
62491 void kvm_arch_exit(void);
62492
62493 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62494diff --git a/include/linux/libata.h b/include/linux/libata.h
62495index 6e887c7..4539601 100644
62496--- a/include/linux/libata.h
62497+++ b/include/linux/libata.h
62498@@ -910,7 +910,7 @@ struct ata_port_operations {
62499 * fields must be pointers.
62500 */
62501 const struct ata_port_operations *inherits;
62502-};
62503+} __do_const;
62504
62505 struct ata_port_info {
62506 unsigned long flags;
62507diff --git a/include/linux/memory.h b/include/linux/memory.h
62508index 1ac7f6e..a5794d0 100644
62509--- a/include/linux/memory.h
62510+++ b/include/linux/memory.h
62511@@ -143,7 +143,7 @@ struct memory_accessor {
62512 size_t count);
62513 ssize_t (*write)(struct memory_accessor *, const char *buf,
62514 off_t offset, size_t count);
62515-};
62516+} __no_const;
62517
62518 /*
62519 * Kernel text modification mutex, used for code patching. Users of this lock
62520diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62521index 1318ca6..7521340 100644
62522--- a/include/linux/mfd/abx500.h
62523+++ b/include/linux/mfd/abx500.h
62524@@ -452,6 +452,7 @@ struct abx500_ops {
62525 int (*event_registers_startup_state_get) (struct device *, u8 *);
62526 int (*startup_irq_enabled) (struct device *, unsigned int);
62527 };
62528+typedef struct abx500_ops __no_const abx500_ops_no_const;
62529
62530 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62531 void abx500_remove_ops(struct device *dev);
62532diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
62533index 9b07725..3d55001 100644
62534--- a/include/linux/mfd/abx500/ux500_chargalg.h
62535+++ b/include/linux/mfd/abx500/ux500_chargalg.h
62536@@ -19,7 +19,7 @@ struct ux500_charger_ops {
62537 int (*enable) (struct ux500_charger *, int, int, int);
62538 int (*kick_wd) (struct ux500_charger *);
62539 int (*update_curr) (struct ux500_charger *, int);
62540-};
62541+} __no_const;
62542
62543 /**
62544 * struct ux500_charger - power supply ux500 charger sub class
62545diff --git a/include/linux/mm.h b/include/linux/mm.h
62546index b36d08c..410ee7c 100644
62547--- a/include/linux/mm.h
62548+++ b/include/linux/mm.h
62549@@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
62550
62551 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62552 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62553+
62554+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62555+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62556+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62557+#else
62558 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62559+#endif
62560+
62561 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62562 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62563
62564@@ -1009,34 +1016,6 @@ int set_page_dirty(struct page *page);
62565 int set_page_dirty_lock(struct page *page);
62566 int clear_page_dirty_for_io(struct page *page);
62567
62568-/* Is the vma a continuation of the stack vma above it? */
62569-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62570-{
62571- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62572-}
62573-
62574-static inline int stack_guard_page_start(struct vm_area_struct *vma,
62575- unsigned long addr)
62576-{
62577- return (vma->vm_flags & VM_GROWSDOWN) &&
62578- (vma->vm_start == addr) &&
62579- !vma_growsdown(vma->vm_prev, addr);
62580-}
62581-
62582-/* Is the vma a continuation of the stack vma below it? */
62583-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62584-{
62585- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62586-}
62587-
62588-static inline int stack_guard_page_end(struct vm_area_struct *vma,
62589- unsigned long addr)
62590-{
62591- return (vma->vm_flags & VM_GROWSUP) &&
62592- (vma->vm_end == addr) &&
62593- !vma_growsup(vma->vm_next, addr);
62594-}
62595-
62596 extern pid_t
62597 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
62598
62599@@ -1135,6 +1114,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
62600 }
62601 #endif
62602
62603+#ifdef CONFIG_MMU
62604+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62605+#else
62606+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62607+{
62608+ return __pgprot(0);
62609+}
62610+#endif
62611+
62612 int vma_wants_writenotify(struct vm_area_struct *vma);
62613
62614 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62615@@ -1153,8 +1141,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
62616 {
62617 return 0;
62618 }
62619+
62620+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
62621+ unsigned long address)
62622+{
62623+ return 0;
62624+}
62625 #else
62626 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62627+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62628 #endif
62629
62630 #ifdef __PAGETABLE_PMD_FOLDED
62631@@ -1163,8 +1158,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
62632 {
62633 return 0;
62634 }
62635+
62636+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
62637+ unsigned long address)
62638+{
62639+ return 0;
62640+}
62641 #else
62642 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
62643+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
62644 #endif
62645
62646 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
62647@@ -1182,11 +1184,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
62648 NULL: pud_offset(pgd, address);
62649 }
62650
62651+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
62652+{
62653+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
62654+ NULL: pud_offset(pgd, address);
62655+}
62656+
62657 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
62658 {
62659 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
62660 NULL: pmd_offset(pud, address);
62661 }
62662+
62663+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
62664+{
62665+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
62666+ NULL: pmd_offset(pud, address);
62667+}
62668 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
62669
62670 #if USE_SPLIT_PTLOCKS
62671@@ -1396,6 +1410,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
62672 unsigned long, unsigned long,
62673 unsigned long, unsigned long);
62674 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62675+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62676
62677 /* These take the mm semaphore themselves */
62678 extern unsigned long vm_brk(unsigned long, unsigned long);
62679@@ -1458,6 +1473,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62680 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62681 struct vm_area_struct **pprev);
62682
62683+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62684+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62685+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62686+
62687 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62688 NULL if none. Assume start_addr < end_addr. */
62689 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62690@@ -1486,15 +1505,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62691 return vma;
62692 }
62693
62694-#ifdef CONFIG_MMU
62695-pgprot_t vm_get_page_prot(unsigned long vm_flags);
62696-#else
62697-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62698-{
62699- return __pgprot(0);
62700-}
62701-#endif
62702-
62703 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62704 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62705 unsigned long pfn, unsigned long size, pgprot_t);
62706@@ -1598,7 +1608,7 @@ extern int unpoison_memory(unsigned long pfn);
62707 extern int sysctl_memory_failure_early_kill;
62708 extern int sysctl_memory_failure_recovery;
62709 extern void shake_page(struct page *p, int access);
62710-extern atomic_long_t mce_bad_pages;
62711+extern atomic_long_unchecked_t mce_bad_pages;
62712 extern int soft_offline_page(struct page *page, int flags);
62713
62714 extern void dump_page(struct page *page);
62715@@ -1629,5 +1639,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62716 static inline bool page_is_guard(struct page *page) { return false; }
62717 #endif /* CONFIG_DEBUG_PAGEALLOC */
62718
62719+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62720+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62721+#else
62722+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62723+#endif
62724+
62725 #endif /* __KERNEL__ */
62726 #endif /* _LINUX_MM_H */
62727diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62728index 704a626..56c7d46 100644
62729--- a/include/linux/mm_types.h
62730+++ b/include/linux/mm_types.h
62731@@ -263,6 +263,8 @@ struct vm_area_struct {
62732 #ifdef CONFIG_NUMA
62733 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62734 #endif
62735+
62736+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62737 };
62738
62739 struct core_thread {
62740@@ -337,7 +339,7 @@ struct mm_struct {
62741 unsigned long def_flags;
62742 unsigned long nr_ptes; /* Page table pages */
62743 unsigned long start_code, end_code, start_data, end_data;
62744- unsigned long start_brk, brk, start_stack;
62745+ unsigned long brk_gap, start_brk, brk, start_stack;
62746 unsigned long arg_start, arg_end, env_start, env_end;
62747
62748 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62749@@ -389,6 +391,24 @@ struct mm_struct {
62750 struct cpumask cpumask_allocation;
62751 #endif
62752 struct uprobes_state uprobes_state;
62753+
62754+#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)
62755+ unsigned long pax_flags;
62756+#endif
62757+
62758+#ifdef CONFIG_PAX_DLRESOLVE
62759+ unsigned long call_dl_resolve;
62760+#endif
62761+
62762+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62763+ unsigned long call_syscall;
62764+#endif
62765+
62766+#ifdef CONFIG_PAX_ASLR
62767+ unsigned long delta_mmap; /* randomized offset */
62768+ unsigned long delta_stack; /* randomized offset */
62769+#endif
62770+
62771 };
62772
62773 static inline void mm_init_cpumask(struct mm_struct *mm)
62774diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62775index 1d1b1e1..2a13c78 100644
62776--- a/include/linux/mmu_notifier.h
62777+++ b/include/linux/mmu_notifier.h
62778@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62779 */
62780 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62781 ({ \
62782- pte_t __pte; \
62783+ pte_t ___pte; \
62784 struct vm_area_struct *___vma = __vma; \
62785 unsigned long ___address = __address; \
62786- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62787+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62788 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62789- __pte; \
62790+ ___pte; \
62791 })
62792
62793 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62794diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62795index 68c569f..5f43753 100644
62796--- a/include/linux/mmzone.h
62797+++ b/include/linux/mmzone.h
62798@@ -411,7 +411,7 @@ struct zone {
62799 unsigned long flags; /* zone flags, see below */
62800
62801 /* Zone statistics */
62802- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62803+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62804
62805 /*
62806 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62807diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62808index 5db9382..50e801d 100644
62809--- a/include/linux/mod_devicetable.h
62810+++ b/include/linux/mod_devicetable.h
62811@@ -12,7 +12,7 @@
62812 typedef unsigned long kernel_ulong_t;
62813 #endif
62814
62815-#define PCI_ANY_ID (~0)
62816+#define PCI_ANY_ID ((__u16)~0)
62817
62818 struct pci_device_id {
62819 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62820@@ -131,7 +131,7 @@ struct usb_device_id {
62821 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62822 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62823
62824-#define HID_ANY_ID (~0)
62825+#define HID_ANY_ID (~0U)
62826 #define HID_BUS_ANY 0xffff
62827 #define HID_GROUP_ANY 0x0000
62828
62829diff --git a/include/linux/module.h b/include/linux/module.h
62830index fbcafe2..e5d9587 100644
62831--- a/include/linux/module.h
62832+++ b/include/linux/module.h
62833@@ -17,6 +17,7 @@
62834 #include <linux/moduleparam.h>
62835 #include <linux/tracepoint.h>
62836 #include <linux/export.h>
62837+#include <linux/fs.h>
62838
62839 #include <linux/percpu.h>
62840 #include <asm/module.h>
62841@@ -273,19 +274,16 @@ struct module
62842 int (*init)(void);
62843
62844 /* If this is non-NULL, vfree after init() returns */
62845- void *module_init;
62846+ void *module_init_rx, *module_init_rw;
62847
62848 /* Here is the actual code + data, vfree'd on unload. */
62849- void *module_core;
62850+ void *module_core_rx, *module_core_rw;
62851
62852 /* Here are the sizes of the init and core sections */
62853- unsigned int init_size, core_size;
62854+ unsigned int init_size_rw, core_size_rw;
62855
62856 /* The size of the executable code in each section. */
62857- unsigned int init_text_size, core_text_size;
62858-
62859- /* Size of RO sections of the module (text+rodata) */
62860- unsigned int init_ro_size, core_ro_size;
62861+ unsigned int init_size_rx, core_size_rx;
62862
62863 /* Arch-specific module values */
62864 struct mod_arch_specific arch;
62865@@ -341,6 +339,10 @@ struct module
62866 #ifdef CONFIG_EVENT_TRACING
62867 struct ftrace_event_call **trace_events;
62868 unsigned int num_trace_events;
62869+ struct file_operations trace_id;
62870+ struct file_operations trace_enable;
62871+ struct file_operations trace_format;
62872+ struct file_operations trace_filter;
62873 #endif
62874 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62875 unsigned int num_ftrace_callsites;
62876@@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
62877 bool is_module_percpu_address(unsigned long addr);
62878 bool is_module_text_address(unsigned long addr);
62879
62880+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62881+{
62882+
62883+#ifdef CONFIG_PAX_KERNEXEC
62884+ if (ktla_ktva(addr) >= (unsigned long)start &&
62885+ ktla_ktva(addr) < (unsigned long)start + size)
62886+ return 1;
62887+#endif
62888+
62889+ return ((void *)addr >= start && (void *)addr < start + size);
62890+}
62891+
62892+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62893+{
62894+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62895+}
62896+
62897+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62898+{
62899+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62900+}
62901+
62902+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62903+{
62904+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62905+}
62906+
62907+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62908+{
62909+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62910+}
62911+
62912 static inline int within_module_core(unsigned long addr, struct module *mod)
62913 {
62914- return (unsigned long)mod->module_core <= addr &&
62915- addr < (unsigned long)mod->module_core + mod->core_size;
62916+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62917 }
62918
62919 static inline int within_module_init(unsigned long addr, struct module *mod)
62920 {
62921- return (unsigned long)mod->module_init <= addr &&
62922- addr < (unsigned long)mod->module_init + mod->init_size;
62923+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62924 }
62925
62926 /* Search for module by name: must hold module_mutex. */
62927diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62928index b2be02e..72d2f78 100644
62929--- a/include/linux/moduleloader.h
62930+++ b/include/linux/moduleloader.h
62931@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62932
62933 /* Allocator used for allocating struct module, core sections and init
62934 sections. Returns NULL on failure. */
62935-void *module_alloc(unsigned long size);
62936+void *module_alloc(unsigned long size) __size_overflow(1);
62937+
62938+#ifdef CONFIG_PAX_KERNEXEC
62939+void *module_alloc_exec(unsigned long size) __size_overflow(1);
62940+#else
62941+#define module_alloc_exec(x) module_alloc(x)
62942+#endif
62943
62944 /* Free memory returned from module_alloc. */
62945 void module_free(struct module *mod, void *module_region);
62946
62947+#ifdef CONFIG_PAX_KERNEXEC
62948+void module_free_exec(struct module *mod, void *module_region);
62949+#else
62950+#define module_free_exec(x, y) module_free((x), (y))
62951+#endif
62952+
62953 /* Apply the given relocation to the (simplified) ELF. Return -error
62954 or 0. */
62955 int apply_relocate(Elf_Shdr *sechdrs,
62956diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62957index d6a5806..7c13347 100644
62958--- a/include/linux/moduleparam.h
62959+++ b/include/linux/moduleparam.h
62960@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
62961 * @len is usually just sizeof(string).
62962 */
62963 #define module_param_string(name, string, len, perm) \
62964- static const struct kparam_string __param_string_##name \
62965+ static const struct kparam_string __param_string_##name __used \
62966 = { len, string }; \
62967 __module_param_call(MODULE_PARAM_PREFIX, name, \
62968 &param_ops_string, \
62969@@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62970 */
62971 #define module_param_array_named(name, array, type, nump, perm) \
62972 param_check_##type(name, &(array)[0]); \
62973- static const struct kparam_array __param_arr_##name \
62974+ static const struct kparam_array __param_arr_##name __used \
62975 = { .max = ARRAY_SIZE(array), .num = nump, \
62976 .ops = &param_ops_##type, \
62977 .elemsize = sizeof(array[0]), .elem = array }; \
62978diff --git a/include/linux/namei.h b/include/linux/namei.h
62979index ffc0213..2c1f2cb 100644
62980--- a/include/linux/namei.h
62981+++ b/include/linux/namei.h
62982@@ -24,7 +24,7 @@ struct nameidata {
62983 unsigned seq;
62984 int last_type;
62985 unsigned depth;
62986- char *saved_names[MAX_NESTED_LINKS + 1];
62987+ const char *saved_names[MAX_NESTED_LINKS + 1];
62988
62989 /* Intent data */
62990 union {
62991@@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62992 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62993 extern void unlock_rename(struct dentry *, struct dentry *);
62994
62995-static inline void nd_set_link(struct nameidata *nd, char *path)
62996+static inline void nd_set_link(struct nameidata *nd, const char *path)
62997 {
62998 nd->saved_names[nd->depth] = path;
62999 }
63000
63001-static inline char *nd_get_link(struct nameidata *nd)
63002+static inline const char *nd_get_link(const struct nameidata *nd)
63003 {
63004 return nd->saved_names[nd->depth];
63005 }
63006diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63007index d94cb14..e64c951 100644
63008--- a/include/linux/netdevice.h
63009+++ b/include/linux/netdevice.h
63010@@ -1026,6 +1026,7 @@ struct net_device_ops {
63011 struct net_device *dev,
63012 int idx);
63013 };
63014+typedef struct net_device_ops __no_const net_device_ops_no_const;
63015
63016 /*
63017 * The DEVICE structure.
63018@@ -1087,7 +1088,7 @@ struct net_device {
63019 int iflink;
63020
63021 struct net_device_stats stats;
63022- atomic_long_t rx_dropped; /* dropped packets by core network
63023+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63024 * Do not use this in drivers.
63025 */
63026
63027diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63028new file mode 100644
63029index 0000000..33f4af8
63030--- /dev/null
63031+++ b/include/linux/netfilter/xt_gradm.h
63032@@ -0,0 +1,9 @@
63033+#ifndef _LINUX_NETFILTER_XT_GRADM_H
63034+#define _LINUX_NETFILTER_XT_GRADM_H 1
63035+
63036+struct xt_gradm_mtinfo {
63037+ __u16 flags;
63038+ __u16 invflags;
63039+};
63040+
63041+#endif
63042diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63043index c65a18a..0c05f3a 100644
63044--- a/include/linux/of_pdt.h
63045+++ b/include/linux/of_pdt.h
63046@@ -32,7 +32,7 @@ struct of_pdt_ops {
63047
63048 /* return 0 on success; fill in 'len' with number of bytes in path */
63049 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63050-};
63051+} __no_const;
63052
63053 extern void *prom_early_alloc(unsigned long size);
63054
63055diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63056index a4c5624..79d6d88 100644
63057--- a/include/linux/oprofile.h
63058+++ b/include/linux/oprofile.h
63059@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63060 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63061 char const * name, ulong * val);
63062
63063-/** Create a file for read-only access to an atomic_t. */
63064+/** Create a file for read-only access to an atomic_unchecked_t. */
63065 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63066- char const * name, atomic_t * val);
63067+ char const * name, atomic_unchecked_t * val);
63068
63069 /** create a directory */
63070 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63071diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63072index 45db49f..386788e 100644
63073--- a/include/linux/perf_event.h
63074+++ b/include/linux/perf_event.h
63075@@ -879,8 +879,8 @@ struct perf_event {
63076
63077 enum perf_event_active_state state;
63078 unsigned int attach_state;
63079- local64_t count;
63080- atomic64_t child_count;
63081+ local64_t count; /* PaX: fix it one day */
63082+ atomic64_unchecked_t child_count;
63083
63084 /*
63085 * These are the total time in nanoseconds that the event
63086@@ -931,8 +931,8 @@ struct perf_event {
63087 * These accumulate total time (in nanoseconds) that children
63088 * events have been enabled and running, respectively.
63089 */
63090- atomic64_t child_total_time_enabled;
63091- atomic64_t child_total_time_running;
63092+ atomic64_unchecked_t child_total_time_enabled;
63093+ atomic64_unchecked_t child_total_time_running;
63094
63095 /*
63096 * Protect attach/detach and child_list:
63097diff --git a/include/linux/personality.h b/include/linux/personality.h
63098index 8fc7dd1a..c19d89e 100644
63099--- a/include/linux/personality.h
63100+++ b/include/linux/personality.h
63101@@ -44,6 +44,7 @@ enum {
63102 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63103 ADDR_NO_RANDOMIZE | \
63104 ADDR_COMPAT_LAYOUT | \
63105+ ADDR_LIMIT_3GB | \
63106 MMAP_PAGE_ZERO)
63107
63108 /*
63109diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63110index e1ac1ce..0675fed 100644
63111--- a/include/linux/pipe_fs_i.h
63112+++ b/include/linux/pipe_fs_i.h
63113@@ -45,9 +45,9 @@ struct pipe_buffer {
63114 struct pipe_inode_info {
63115 wait_queue_head_t wait;
63116 unsigned int nrbufs, curbuf, buffers;
63117- unsigned int readers;
63118- unsigned int writers;
63119- unsigned int waiting_writers;
63120+ atomic_t readers;
63121+ atomic_t writers;
63122+ atomic_t waiting_writers;
63123 unsigned int r_counter;
63124 unsigned int w_counter;
63125 struct page *tmp_page;
63126diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63127index f271860..6b3bec5 100644
63128--- a/include/linux/pm_runtime.h
63129+++ b/include/linux/pm_runtime.h
63130@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63131
63132 static inline void pm_runtime_mark_last_busy(struct device *dev)
63133 {
63134- ACCESS_ONCE(dev->power.last_busy) = jiffies;
63135+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63136 }
63137
63138 #else /* !CONFIG_PM_RUNTIME */
63139diff --git a/include/linux/poison.h b/include/linux/poison.h
63140index 2110a81..13a11bb 100644
63141--- a/include/linux/poison.h
63142+++ b/include/linux/poison.h
63143@@ -19,8 +19,8 @@
63144 * under normal circumstances, used to verify that nobody uses
63145 * non-initialized list entries.
63146 */
63147-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63148-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63149+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63150+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63151
63152 /********** include/linux/timer.h **********/
63153 /*
63154diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63155index 5a710b9..0b0dab9 100644
63156--- a/include/linux/preempt.h
63157+++ b/include/linux/preempt.h
63158@@ -126,7 +126,7 @@ struct preempt_ops {
63159 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63160 void (*sched_out)(struct preempt_notifier *notifier,
63161 struct task_struct *next);
63162-};
63163+} __no_const;
63164
63165 /**
63166 * preempt_notifier - key for installing preemption notifiers
63167diff --git a/include/linux/printk.h b/include/linux/printk.h
63168index 1bec2f7..b66e833 100644
63169--- a/include/linux/printk.h
63170+++ b/include/linux/printk.h
63171@@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
63172 extern int printk_needs_cpu(int cpu);
63173 extern void printk_tick(void);
63174
63175+extern int kptr_restrict;
63176+
63177 #ifdef CONFIG_PRINTK
63178 asmlinkage __printf(5, 0)
63179 int vprintk_emit(int facility, int level,
63180@@ -128,7 +130,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63181
63182 extern int printk_delay_msec;
63183 extern int dmesg_restrict;
63184-extern int kptr_restrict;
63185
63186 void log_buf_kexec_setup(void);
63187 void __init setup_log_buf(int early);
63188diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63189index 3fd2e87..d93a721 100644
63190--- a/include/linux/proc_fs.h
63191+++ b/include/linux/proc_fs.h
63192@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63193 return proc_create_data(name, mode, parent, proc_fops, NULL);
63194 }
63195
63196+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63197+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63198+{
63199+#ifdef CONFIG_GRKERNSEC_PROC_USER
63200+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63201+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63202+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63203+#else
63204+ return proc_create_data(name, mode, parent, proc_fops, NULL);
63205+#endif
63206+}
63207+
63208 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63209 umode_t mode, struct proc_dir_entry *base,
63210 read_proc_t *read_proc, void * data)
63211@@ -258,7 +270,7 @@ union proc_op {
63212 int (*proc_show)(struct seq_file *m,
63213 struct pid_namespace *ns, struct pid *pid,
63214 struct task_struct *task);
63215-};
63216+} __no_const;
63217
63218 struct ctl_table_header;
63219 struct ctl_table;
63220diff --git a/include/linux/random.h b/include/linux/random.h
63221index 8f74538..de61694 100644
63222--- a/include/linux/random.h
63223+++ b/include/linux/random.h
63224@@ -54,6 +54,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63225 unsigned int value);
63226 extern void add_interrupt_randomness(int irq);
63227
63228+#ifdef CONFIG_PAX_LATENT_ENTROPY
63229+extern void transfer_latent_entropy(void);
63230+#endif
63231+
63232 extern void get_random_bytes(void *buf, int nbytes);
63233 void generate_random_uuid(unsigned char uuid_out[16]);
63234
63235@@ -69,12 +73,17 @@ void srandom32(u32 seed);
63236
63237 u32 prandom32(struct rnd_state *);
63238
63239+static inline unsigned long pax_get_random_long(void)
63240+{
63241+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63242+}
63243+
63244 /*
63245 * Handle minimum values for seeds
63246 */
63247 static inline u32 __seed(u32 x, u32 m)
63248 {
63249- return (x < m) ? x + m : x;
63250+ return (x <= m) ? x + m + 1 : x;
63251 }
63252
63253 /**
63254diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63255index e0879a7..a12f962 100644
63256--- a/include/linux/reboot.h
63257+++ b/include/linux/reboot.h
63258@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63259 * Architecture-specific implementations of sys_reboot commands.
63260 */
63261
63262-extern void machine_restart(char *cmd);
63263-extern void machine_halt(void);
63264-extern void machine_power_off(void);
63265+extern void machine_restart(char *cmd) __noreturn;
63266+extern void machine_halt(void) __noreturn;
63267+extern void machine_power_off(void) __noreturn;
63268
63269 extern void machine_shutdown(void);
63270 struct pt_regs;
63271@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63272 */
63273
63274 extern void kernel_restart_prepare(char *cmd);
63275-extern void kernel_restart(char *cmd);
63276-extern void kernel_halt(void);
63277-extern void kernel_power_off(void);
63278+extern void kernel_restart(char *cmd) __noreturn;
63279+extern void kernel_halt(void) __noreturn;
63280+extern void kernel_power_off(void) __noreturn;
63281
63282 extern int C_A_D; /* for sysctl */
63283 void ctrl_alt_del(void);
63284@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63285 * Emergency restart, callable from an interrupt handler.
63286 */
63287
63288-extern void emergency_restart(void);
63289+extern void emergency_restart(void) __noreturn;
63290 #include <asm/emergency-restart.h>
63291
63292 #endif
63293diff --git a/include/linux/relay.h b/include/linux/relay.h
63294index 91cacc3..b55ff74 100644
63295--- a/include/linux/relay.h
63296+++ b/include/linux/relay.h
63297@@ -160,7 +160,7 @@ struct rchan_callbacks
63298 * The callback should return 0 if successful, negative if not.
63299 */
63300 int (*remove_buf_file)(struct dentry *dentry);
63301-};
63302+} __no_const;
63303
63304 /*
63305 * CONFIG_RELAY kernel API, kernel/relay.c
63306diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63307index 6fdf027..ff72610 100644
63308--- a/include/linux/rfkill.h
63309+++ b/include/linux/rfkill.h
63310@@ -147,6 +147,7 @@ struct rfkill_ops {
63311 void (*query)(struct rfkill *rfkill, void *data);
63312 int (*set_block)(void *data, bool blocked);
63313 };
63314+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63315
63316 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63317 /**
63318diff --git a/include/linux/rio.h b/include/linux/rio.h
63319index a90ebad..fd87b5d 100644
63320--- a/include/linux/rio.h
63321+++ b/include/linux/rio.h
63322@@ -321,7 +321,7 @@ struct rio_ops {
63323 int mbox, void *buffer, size_t len);
63324 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63325 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63326-};
63327+} __no_const;
63328
63329 #define RIO_RESOURCE_MEM 0x00000100
63330 #define RIO_RESOURCE_DOORBELL 0x00000200
63331diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63332index 3fce545..b4fed6e 100644
63333--- a/include/linux/rmap.h
63334+++ b/include/linux/rmap.h
63335@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63336 void anon_vma_init(void); /* create anon_vma_cachep */
63337 int anon_vma_prepare(struct vm_area_struct *);
63338 void unlink_anon_vmas(struct vm_area_struct *);
63339-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63340+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63341 void anon_vma_moveto_tail(struct vm_area_struct *);
63342-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63343+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63344
63345 static inline void anon_vma_merge(struct vm_area_struct *vma,
63346 struct vm_area_struct *next)
63347diff --git a/include/linux/sched.h b/include/linux/sched.h
63348index 4a1f493..5812aeb 100644
63349--- a/include/linux/sched.h
63350+++ b/include/linux/sched.h
63351@@ -101,6 +101,7 @@ struct bio_list;
63352 struct fs_struct;
63353 struct perf_event_context;
63354 struct blk_plug;
63355+struct linux_binprm;
63356
63357 /*
63358 * List of flags we want to share for kernel threads,
63359@@ -384,10 +385,13 @@ struct user_namespace;
63360 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63361
63362 extern int sysctl_max_map_count;
63363+extern unsigned long sysctl_heap_stack_gap;
63364
63365 #include <linux/aio.h>
63366
63367 #ifdef CONFIG_MMU
63368+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63369+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63370 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63371 extern unsigned long
63372 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63373@@ -406,6 +410,11 @@ static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
63374 extern void set_dumpable(struct mm_struct *mm, int value);
63375 extern int get_dumpable(struct mm_struct *mm);
63376
63377+/* get/set_dumpable() values */
63378+#define SUID_DUMPABLE_DISABLED 0
63379+#define SUID_DUMPABLE_ENABLED 1
63380+#define SUID_DUMPABLE_SAFE 2
63381+
63382 /* mm flags */
63383 /* dumpable bits */
63384 #define MMF_DUMPABLE 0 /* core dump is permitted */
63385@@ -646,6 +655,17 @@ struct signal_struct {
63386 #ifdef CONFIG_TASKSTATS
63387 struct taskstats *stats;
63388 #endif
63389+
63390+#ifdef CONFIG_GRKERNSEC
63391+ u32 curr_ip;
63392+ u32 saved_ip;
63393+ u32 gr_saddr;
63394+ u32 gr_daddr;
63395+ u16 gr_sport;
63396+ u16 gr_dport;
63397+ u8 used_accept:1;
63398+#endif
63399+
63400 #ifdef CONFIG_AUDIT
63401 unsigned audit_tty;
63402 struct tty_audit_buf *tty_audit_buf;
63403@@ -729,6 +749,11 @@ struct user_struct {
63404 struct key *session_keyring; /* UID's default session keyring */
63405 #endif
63406
63407+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63408+ unsigned int banned;
63409+ unsigned long ban_expires;
63410+#endif
63411+
63412 /* Hash table maintenance information */
63413 struct hlist_node uidhash_node;
63414 kuid_t uid;
63415@@ -1348,8 +1373,8 @@ struct task_struct {
63416 struct list_head thread_group;
63417
63418 struct completion *vfork_done; /* for vfork() */
63419- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63420- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63421+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63422+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63423
63424 cputime_t utime, stime, utimescaled, stimescaled;
63425 cputime_t gtime;
63426@@ -1365,11 +1390,6 @@ struct task_struct {
63427 struct task_cputime cputime_expires;
63428 struct list_head cpu_timers[3];
63429
63430-/* process credentials */
63431- const struct cred __rcu *real_cred; /* objective and real subjective task
63432- * credentials (COW) */
63433- const struct cred __rcu *cred; /* effective (overridable) subjective task
63434- * credentials (COW) */
63435 char comm[TASK_COMM_LEN]; /* executable name excluding path
63436 - access with [gs]et_task_comm (which lock
63437 it with task_lock())
63438@@ -1386,8 +1406,16 @@ struct task_struct {
63439 #endif
63440 /* CPU-specific state of this task */
63441 struct thread_struct thread;
63442+/* thread_info moved to task_struct */
63443+#ifdef CONFIG_X86
63444+ struct thread_info tinfo;
63445+#endif
63446 /* filesystem information */
63447 struct fs_struct *fs;
63448+
63449+ const struct cred __rcu *cred; /* effective (overridable) subjective task
63450+ * credentials (COW) */
63451+
63452 /* open file information */
63453 struct files_struct *files;
63454 /* namespaces */
63455@@ -1431,6 +1459,11 @@ struct task_struct {
63456 struct rt_mutex_waiter *pi_blocked_on;
63457 #endif
63458
63459+/* process credentials */
63460+ const struct cred __rcu *real_cred; /* objective and real subjective task
63461+ * credentials (COW) */
63462+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63463+
63464 #ifdef CONFIG_DEBUG_MUTEXES
63465 /* mutex deadlock detection */
63466 struct mutex_waiter *blocked_on;
63467@@ -1547,6 +1580,27 @@ struct task_struct {
63468 unsigned long default_timer_slack_ns;
63469
63470 struct list_head *scm_work_list;
63471+
63472+#ifdef CONFIG_GRKERNSEC
63473+ /* grsecurity */
63474+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63475+ u64 exec_id;
63476+#endif
63477+#ifdef CONFIG_GRKERNSEC_SETXID
63478+ const struct cred *delayed_cred;
63479+#endif
63480+ struct dentry *gr_chroot_dentry;
63481+ struct acl_subject_label *acl;
63482+ struct acl_role_label *role;
63483+ struct file *exec_file;
63484+ u16 acl_role_id;
63485+ /* is this the task that authenticated to the special role */
63486+ u8 acl_sp_role;
63487+ u8 is_writable;
63488+ u8 brute;
63489+ u8 gr_is_chrooted;
63490+#endif
63491+
63492 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63493 /* Index of current stored address in ret_stack */
63494 int curr_ret_stack;
63495@@ -1585,6 +1639,51 @@ struct task_struct {
63496 #endif
63497 };
63498
63499+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63500+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63501+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63502+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63503+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63504+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63505+
63506+#ifdef CONFIG_PAX_SOFTMODE
63507+extern int pax_softmode;
63508+#endif
63509+
63510+extern int pax_check_flags(unsigned long *);
63511+
63512+/* if tsk != current then task_lock must be held on it */
63513+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63514+static inline unsigned long pax_get_flags(struct task_struct *tsk)
63515+{
63516+ if (likely(tsk->mm))
63517+ return tsk->mm->pax_flags;
63518+ else
63519+ return 0UL;
63520+}
63521+
63522+/* if tsk != current then task_lock must be held on it */
63523+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63524+{
63525+ if (likely(tsk->mm)) {
63526+ tsk->mm->pax_flags = flags;
63527+ return 0;
63528+ }
63529+ return -EINVAL;
63530+}
63531+#endif
63532+
63533+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63534+extern void pax_set_initial_flags(struct linux_binprm *bprm);
63535+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63536+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63537+#endif
63538+
63539+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63540+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63541+extern void pax_report_refcount_overflow(struct pt_regs *regs);
63542+extern void check_object_size(const void *ptr, unsigned long n, bool to);
63543+
63544 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63545 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63546
63547@@ -2112,7 +2211,9 @@ void yield(void);
63548 extern struct exec_domain default_exec_domain;
63549
63550 union thread_union {
63551+#ifndef CONFIG_X86
63552 struct thread_info thread_info;
63553+#endif
63554 unsigned long stack[THREAD_SIZE/sizeof(long)];
63555 };
63556
63557@@ -2145,6 +2246,7 @@ extern struct pid_namespace init_pid_ns;
63558 */
63559
63560 extern struct task_struct *find_task_by_vpid(pid_t nr);
63561+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63562 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63563 struct pid_namespace *ns);
63564
63565@@ -2301,7 +2403,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63566 extern void exit_itimers(struct signal_struct *);
63567 extern void flush_itimer_signals(void);
63568
63569-extern void do_group_exit(int);
63570+extern __noreturn void do_group_exit(int);
63571
63572 extern void daemonize(const char *, ...);
63573 extern int allow_signal(int);
63574@@ -2502,9 +2604,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63575
63576 #endif
63577
63578-static inline int object_is_on_stack(void *obj)
63579+static inline int object_starts_on_stack(void *obj)
63580 {
63581- void *stack = task_stack_page(current);
63582+ const void *stack = task_stack_page(current);
63583
63584 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63585 }
63586diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63587index 899fbb4..1cb4138 100644
63588--- a/include/linux/screen_info.h
63589+++ b/include/linux/screen_info.h
63590@@ -43,7 +43,8 @@ struct screen_info {
63591 __u16 pages; /* 0x32 */
63592 __u16 vesa_attributes; /* 0x34 */
63593 __u32 capabilities; /* 0x36 */
63594- __u8 _reserved[6]; /* 0x3a */
63595+ __u16 vesapm_size; /* 0x3a */
63596+ __u8 _reserved[4]; /* 0x3c */
63597 } __attribute__((packed));
63598
63599 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63600diff --git a/include/linux/security.h b/include/linux/security.h
63601index 4e5a73c..a5784a1 100644
63602--- a/include/linux/security.h
63603+++ b/include/linux/security.h
63604@@ -26,6 +26,7 @@
63605 #include <linux/capability.h>
63606 #include <linux/slab.h>
63607 #include <linux/err.h>
63608+#include <linux/grsecurity.h>
63609
63610 struct linux_binprm;
63611 struct cred;
63612diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63613index fc61854..d7c490b 100644
63614--- a/include/linux/seq_file.h
63615+++ b/include/linux/seq_file.h
63616@@ -25,6 +25,9 @@ struct seq_file {
63617 struct mutex lock;
63618 const struct seq_operations *op;
63619 int poll_event;
63620+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63621+ u64 exec_id;
63622+#endif
63623 void *private;
63624 };
63625
63626@@ -34,6 +37,7 @@ struct seq_operations {
63627 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63628 int (*show) (struct seq_file *m, void *v);
63629 };
63630+typedef struct seq_operations __no_const seq_operations_no_const;
63631
63632 #define SEQ_SKIP 1
63633
63634diff --git a/include/linux/shm.h b/include/linux/shm.h
63635index 92808b8..c28cac4 100644
63636--- a/include/linux/shm.h
63637+++ b/include/linux/shm.h
63638@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63639
63640 /* The task created the shm object. NULL if the task is dead. */
63641 struct task_struct *shm_creator;
63642+#ifdef CONFIG_GRKERNSEC
63643+ time_t shm_createtime;
63644+ pid_t shm_lapid;
63645+#endif
63646 };
63647
63648 /* shm_mode upper byte flags */
63649diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63650index 642cb73..7ff7f9f 100644
63651--- a/include/linux/skbuff.h
63652+++ b/include/linux/skbuff.h
63653@@ -680,7 +680,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63654 */
63655 static inline int skb_queue_empty(const struct sk_buff_head *list)
63656 {
63657- return list->next == (struct sk_buff *)list;
63658+ return list->next == (const struct sk_buff *)list;
63659 }
63660
63661 /**
63662@@ -693,7 +693,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63663 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63664 const struct sk_buff *skb)
63665 {
63666- return skb->next == (struct sk_buff *)list;
63667+ return skb->next == (const struct sk_buff *)list;
63668 }
63669
63670 /**
63671@@ -706,7 +706,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63672 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63673 const struct sk_buff *skb)
63674 {
63675- return skb->prev == (struct sk_buff *)list;
63676+ return skb->prev == (const struct sk_buff *)list;
63677 }
63678
63679 /**
63680@@ -1605,7 +1605,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63681 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63682 */
63683 #ifndef NET_SKB_PAD
63684-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63685+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63686 #endif
63687
63688 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63689diff --git a/include/linux/slab.h b/include/linux/slab.h
63690index 67d5d94..371d9a7 100644
63691--- a/include/linux/slab.h
63692+++ b/include/linux/slab.h
63693@@ -11,12 +11,20 @@
63694
63695 #include <linux/gfp.h>
63696 #include <linux/types.h>
63697+#include <linux/err.h>
63698
63699 /*
63700 * Flags to pass to kmem_cache_create().
63701 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63702 */
63703 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63704+
63705+#ifdef CONFIG_PAX_USERCOPY_SLABS
63706+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63707+#else
63708+#define SLAB_USERCOPY 0x00000000UL
63709+#endif
63710+
63711 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63712 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63713 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63714@@ -87,10 +95,13 @@
63715 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63716 * Both make kfree a no-op.
63717 */
63718-#define ZERO_SIZE_PTR ((void *)16)
63719+#define ZERO_SIZE_PTR \
63720+({ \
63721+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63722+ (void *)(-MAX_ERRNO-1L); \
63723+})
63724
63725-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63726- (unsigned long)ZERO_SIZE_PTR)
63727+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63728
63729 /*
63730 * struct kmem_cache related prototypes
63731@@ -161,6 +172,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
63732 void kfree(const void *);
63733 void kzfree(const void *);
63734 size_t ksize(const void *);
63735+const char *check_heap_object(const void *ptr, unsigned long n, bool to);
63736+bool is_usercopy_object(const void *ptr);
63737
63738 /*
63739 * Allocator specific definitions. These are mainly used to establish optimized
63740@@ -240,6 +253,7 @@ size_t ksize(const void *);
63741 * for general use, and so are not documented here. For a full list of
63742 * potential flags, always refer to linux/gfp.h.
63743 */
63744+static void *kmalloc_array(size_t n, size_t size, gfp_t flags) __size_overflow(1, 2);
63745 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
63746 {
63747 if (size != 0 && n > SIZE_MAX / size)
63748@@ -298,7 +312,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63749 */
63750 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63751 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63752-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63753+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63754 #define kmalloc_track_caller(size, flags) \
63755 __kmalloc_track_caller(size, flags, _RET_IP_)
63756 #else
63757@@ -317,7 +331,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63758 */
63759 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63760 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63761-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63762+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63763 #define kmalloc_node_track_caller(size, flags, node) \
63764 __kmalloc_node_track_caller(size, flags, node, \
63765 _RET_IP_)
63766diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63767index fbd1117..0a3d314 100644
63768--- a/include/linux/slab_def.h
63769+++ b/include/linux/slab_def.h
63770@@ -66,10 +66,10 @@ struct kmem_cache {
63771 unsigned long node_allocs;
63772 unsigned long node_frees;
63773 unsigned long node_overflow;
63774- atomic_t allochit;
63775- atomic_t allocmiss;
63776- atomic_t freehit;
63777- atomic_t freemiss;
63778+ atomic_unchecked_t allochit;
63779+ atomic_unchecked_t allocmiss;
63780+ atomic_unchecked_t freehit;
63781+ atomic_unchecked_t freemiss;
63782
63783 /*
63784 * If debugging is enabled, then the allocator can add additional
63785@@ -103,11 +103,16 @@ struct cache_sizes {
63786 #ifdef CONFIG_ZONE_DMA
63787 struct kmem_cache *cs_dmacachep;
63788 #endif
63789+
63790+#ifdef CONFIG_PAX_USERCOPY_SLABS
63791+ struct kmem_cache *cs_usercopycachep;
63792+#endif
63793+
63794 };
63795 extern struct cache_sizes malloc_sizes[];
63796
63797 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63798-void *__kmalloc(size_t size, gfp_t flags);
63799+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63800
63801 #ifdef CONFIG_TRACING
63802 extern void *kmem_cache_alloc_trace(size_t size,
63803@@ -150,6 +155,13 @@ found:
63804 cachep = malloc_sizes[i].cs_dmacachep;
63805 else
63806 #endif
63807+
63808+#ifdef CONFIG_PAX_USERCOPY_SLABS
63809+ if (flags & GFP_USERCOPY)
63810+ cachep = malloc_sizes[i].cs_usercopycachep;
63811+ else
63812+#endif
63813+
63814 cachep = malloc_sizes[i].cs_cachep;
63815
63816 ret = kmem_cache_alloc_trace(size, cachep, flags);
63817@@ -160,7 +172,7 @@ found:
63818 }
63819
63820 #ifdef CONFIG_NUMA
63821-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63822+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63823 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63824
63825 #ifdef CONFIG_TRACING
63826@@ -203,6 +215,13 @@ found:
63827 cachep = malloc_sizes[i].cs_dmacachep;
63828 else
63829 #endif
63830+
63831+#ifdef CONFIG_PAX_USERCOPY_SLABS
63832+ if (flags & GFP_USERCOPY)
63833+ cachep = malloc_sizes[i].cs_usercopycachep;
63834+ else
63835+#endif
63836+
63837 cachep = malloc_sizes[i].cs_cachep;
63838
63839 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
63840diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63841index 0ec00b3..39cb7fc 100644
63842--- a/include/linux/slob_def.h
63843+++ b/include/linux/slob_def.h
63844@@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63845 return kmem_cache_alloc_node(cachep, flags, -1);
63846 }
63847
63848-void *__kmalloc_node(size_t size, gfp_t flags, int node);
63849+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63850
63851 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63852 {
63853@@ -29,6 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63854 return __kmalloc_node(size, flags, -1);
63855 }
63856
63857+static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63858 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63859 {
63860 return kmalloc(size, flags);
63861diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63862index c2f8c8b..be9e036 100644
63863--- a/include/linux/slub_def.h
63864+++ b/include/linux/slub_def.h
63865@@ -92,7 +92,7 @@ struct kmem_cache {
63866 struct kmem_cache_order_objects max;
63867 struct kmem_cache_order_objects min;
63868 gfp_t allocflags; /* gfp flags to use on each alloc */
63869- int refcount; /* Refcount for slab cache destroy */
63870+ atomic_t refcount; /* Refcount for slab cache destroy */
63871 void (*ctor)(void *);
63872 int inuse; /* Offset to metadata */
63873 int align; /* Alignment */
63874@@ -153,6 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
63875 * Sorry that the following has to be that ugly but some versions of GCC
63876 * have trouble with constant propagation and loops.
63877 */
63878+static __always_inline int kmalloc_index(size_t size) __size_overflow(1);
63879 static __always_inline int kmalloc_index(size_t size)
63880 {
63881 if (!size)
63882@@ -218,7 +219,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63883 }
63884
63885 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63886-void *__kmalloc(size_t size, gfp_t flags);
63887+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
63888
63889 static __always_inline void *
63890 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63891@@ -259,6 +260,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
63892 }
63893 #endif
63894
63895+static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
63896 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
63897 {
63898 unsigned int order = get_order(size);
63899@@ -284,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63900 }
63901
63902 #ifdef CONFIG_NUMA
63903-void *__kmalloc_node(size_t size, gfp_t flags, int node);
63904+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63905 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63906
63907 #ifdef CONFIG_TRACING
63908diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63909index de8832d..0147b46 100644
63910--- a/include/linux/sonet.h
63911+++ b/include/linux/sonet.h
63912@@ -61,7 +61,7 @@ struct sonet_stats {
63913 #include <linux/atomic.h>
63914
63915 struct k_sonet_stats {
63916-#define __HANDLE_ITEM(i) atomic_t i
63917+#define __HANDLE_ITEM(i) atomic_unchecked_t i
63918 __SONET_ITEMS
63919 #undef __HANDLE_ITEM
63920 };
63921diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63922index 523547e..2cb7140 100644
63923--- a/include/linux/sunrpc/clnt.h
63924+++ b/include/linux/sunrpc/clnt.h
63925@@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63926 {
63927 switch (sap->sa_family) {
63928 case AF_INET:
63929- return ntohs(((struct sockaddr_in *)sap)->sin_port);
63930+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63931 case AF_INET6:
63932- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63933+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63934 }
63935 return 0;
63936 }
63937@@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63938 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63939 const struct sockaddr *src)
63940 {
63941- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63942+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63943 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63944
63945 dsin->sin_family = ssin->sin_family;
63946@@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63947 if (sa->sa_family != AF_INET6)
63948 return 0;
63949
63950- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63951+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63952 }
63953
63954 #endif /* __KERNEL__ */
63955diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63956index dc0c3cc..8503fb6 100644
63957--- a/include/linux/sunrpc/sched.h
63958+++ b/include/linux/sunrpc/sched.h
63959@@ -106,6 +106,7 @@ struct rpc_call_ops {
63960 void (*rpc_count_stats)(struct rpc_task *, void *);
63961 void (*rpc_release)(void *);
63962 };
63963+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63964
63965 struct rpc_task_setup {
63966 struct rpc_task *task;
63967diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63968index 0b8e3e6..33e0a01 100644
63969--- a/include/linux/sunrpc/svc_rdma.h
63970+++ b/include/linux/sunrpc/svc_rdma.h
63971@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63972 extern unsigned int svcrdma_max_requests;
63973 extern unsigned int svcrdma_max_req_size;
63974
63975-extern atomic_t rdma_stat_recv;
63976-extern atomic_t rdma_stat_read;
63977-extern atomic_t rdma_stat_write;
63978-extern atomic_t rdma_stat_sq_starve;
63979-extern atomic_t rdma_stat_rq_starve;
63980-extern atomic_t rdma_stat_rq_poll;
63981-extern atomic_t rdma_stat_rq_prod;
63982-extern atomic_t rdma_stat_sq_poll;
63983-extern atomic_t rdma_stat_sq_prod;
63984+extern atomic_unchecked_t rdma_stat_recv;
63985+extern atomic_unchecked_t rdma_stat_read;
63986+extern atomic_unchecked_t rdma_stat_write;
63987+extern atomic_unchecked_t rdma_stat_sq_starve;
63988+extern atomic_unchecked_t rdma_stat_rq_starve;
63989+extern atomic_unchecked_t rdma_stat_rq_poll;
63990+extern atomic_unchecked_t rdma_stat_rq_prod;
63991+extern atomic_unchecked_t rdma_stat_sq_poll;
63992+extern atomic_unchecked_t rdma_stat_sq_prod;
63993
63994 #define RPCRDMA_VERSION 1
63995
63996diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63997index c34b4c8..a65b67d 100644
63998--- a/include/linux/sysctl.h
63999+++ b/include/linux/sysctl.h
64000@@ -155,7 +155,11 @@ enum
64001 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64002 };
64003
64004-
64005+#ifdef CONFIG_PAX_SOFTMODE
64006+enum {
64007+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64008+};
64009+#endif
64010
64011 /* CTL_VM names: */
64012 enum
64013@@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64014
64015 extern int proc_dostring(struct ctl_table *, int,
64016 void __user *, size_t *, loff_t *);
64017+extern int proc_dostring_modpriv(struct ctl_table *, int,
64018+ void __user *, size_t *, loff_t *);
64019 extern int proc_dointvec(struct ctl_table *, int,
64020 void __user *, size_t *, loff_t *);
64021 extern int proc_dointvec_minmax(struct ctl_table *, int,
64022diff --git a/include/linux/tty.h b/include/linux/tty.h
64023index 9f47ab5..73da944 100644
64024--- a/include/linux/tty.h
64025+++ b/include/linux/tty.h
64026@@ -225,7 +225,7 @@ struct tty_port {
64027 const struct tty_port_operations *ops; /* Port operations */
64028 spinlock_t lock; /* Lock protecting tty field */
64029 int blocked_open; /* Waiting to open */
64030- int count; /* Usage count */
64031+ atomic_t count; /* Usage count */
64032 wait_queue_head_t open_wait; /* Open waiters */
64033 wait_queue_head_t close_wait; /* Close waiters */
64034 wait_queue_head_t delta_msr_wait; /* Modem status change */
64035@@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64036 struct tty_struct *tty, struct file *filp);
64037 static inline int tty_port_users(struct tty_port *port)
64038 {
64039- return port->count + port->blocked_open;
64040+ return atomic_read(&port->count) + port->blocked_open;
64041 }
64042
64043 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64044diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64045index fb79dd8d..07d4773 100644
64046--- a/include/linux/tty_ldisc.h
64047+++ b/include/linux/tty_ldisc.h
64048@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64049
64050 struct module *owner;
64051
64052- int refcount;
64053+ atomic_t refcount;
64054 };
64055
64056 struct tty_ldisc {
64057diff --git a/include/linux/types.h b/include/linux/types.h
64058index 9c1bd53..c2370f6 100644
64059--- a/include/linux/types.h
64060+++ b/include/linux/types.h
64061@@ -220,10 +220,26 @@ typedef struct {
64062 int counter;
64063 } atomic_t;
64064
64065+#ifdef CONFIG_PAX_REFCOUNT
64066+typedef struct {
64067+ int counter;
64068+} atomic_unchecked_t;
64069+#else
64070+typedef atomic_t atomic_unchecked_t;
64071+#endif
64072+
64073 #ifdef CONFIG_64BIT
64074 typedef struct {
64075 long counter;
64076 } atomic64_t;
64077+
64078+#ifdef CONFIG_PAX_REFCOUNT
64079+typedef struct {
64080+ long counter;
64081+} atomic64_unchecked_t;
64082+#else
64083+typedef atomic64_t atomic64_unchecked_t;
64084+#endif
64085 #endif
64086
64087 struct list_head {
64088diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64089index 5ca0951..ab496a5 100644
64090--- a/include/linux/uaccess.h
64091+++ b/include/linux/uaccess.h
64092@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64093 long ret; \
64094 mm_segment_t old_fs = get_fs(); \
64095 \
64096- set_fs(KERNEL_DS); \
64097 pagefault_disable(); \
64098- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64099- pagefault_enable(); \
64100+ set_fs(KERNEL_DS); \
64101+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64102 set_fs(old_fs); \
64103+ pagefault_enable(); \
64104 ret; \
64105 })
64106
64107diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64108index 99c1b4d..bb94261 100644
64109--- a/include/linux/unaligned/access_ok.h
64110+++ b/include/linux/unaligned/access_ok.h
64111@@ -6,32 +6,32 @@
64112
64113 static inline u16 get_unaligned_le16(const void *p)
64114 {
64115- return le16_to_cpup((__le16 *)p);
64116+ return le16_to_cpup((const __le16 *)p);
64117 }
64118
64119 static inline u32 get_unaligned_le32(const void *p)
64120 {
64121- return le32_to_cpup((__le32 *)p);
64122+ return le32_to_cpup((const __le32 *)p);
64123 }
64124
64125 static inline u64 get_unaligned_le64(const void *p)
64126 {
64127- return le64_to_cpup((__le64 *)p);
64128+ return le64_to_cpup((const __le64 *)p);
64129 }
64130
64131 static inline u16 get_unaligned_be16(const void *p)
64132 {
64133- return be16_to_cpup((__be16 *)p);
64134+ return be16_to_cpup((const __be16 *)p);
64135 }
64136
64137 static inline u32 get_unaligned_be32(const void *p)
64138 {
64139- return be32_to_cpup((__be32 *)p);
64140+ return be32_to_cpup((const __be32 *)p);
64141 }
64142
64143 static inline u64 get_unaligned_be64(const void *p)
64144 {
64145- return be64_to_cpup((__be64 *)p);
64146+ return be64_to_cpup((const __be64 *)p);
64147 }
64148
64149 static inline void put_unaligned_le16(u16 val, void *p)
64150diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64151index 547e59c..db6ad19 100644
64152--- a/include/linux/usb/renesas_usbhs.h
64153+++ b/include/linux/usb/renesas_usbhs.h
64154@@ -39,7 +39,7 @@ enum {
64155 */
64156 struct renesas_usbhs_driver_callback {
64157 int (*notify_hotplug)(struct platform_device *pdev);
64158-};
64159+} __no_const;
64160
64161 /*
64162 * callback functions for platform
64163@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64164 * VBUS control is needed for Host
64165 */
64166 int (*set_vbus)(struct platform_device *pdev, int enable);
64167-};
64168+} __no_const;
64169
64170 /*
64171 * parameters for renesas usbhs
64172diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64173index 6f8fbcf..8259001 100644
64174--- a/include/linux/vermagic.h
64175+++ b/include/linux/vermagic.h
64176@@ -25,9 +25,35 @@
64177 #define MODULE_ARCH_VERMAGIC ""
64178 #endif
64179
64180+#ifdef CONFIG_PAX_REFCOUNT
64181+#define MODULE_PAX_REFCOUNT "REFCOUNT "
64182+#else
64183+#define MODULE_PAX_REFCOUNT ""
64184+#endif
64185+
64186+#ifdef CONSTIFY_PLUGIN
64187+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64188+#else
64189+#define MODULE_CONSTIFY_PLUGIN ""
64190+#endif
64191+
64192+#ifdef STACKLEAK_PLUGIN
64193+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64194+#else
64195+#define MODULE_STACKLEAK_PLUGIN ""
64196+#endif
64197+
64198+#ifdef CONFIG_GRKERNSEC
64199+#define MODULE_GRSEC "GRSEC "
64200+#else
64201+#define MODULE_GRSEC ""
64202+#endif
64203+
64204 #define VERMAGIC_STRING \
64205 UTS_RELEASE " " \
64206 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64207 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64208- MODULE_ARCH_VERMAGIC
64209+ MODULE_ARCH_VERMAGIC \
64210+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64211+ MODULE_GRSEC
64212
64213diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64214index dcdfc2b..ec79ab5 100644
64215--- a/include/linux/vmalloc.h
64216+++ b/include/linux/vmalloc.h
64217@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64218 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64219 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64220 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64221+
64222+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64223+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64224+#endif
64225+
64226 /* bits [20..32] reserved for arch specific ioremap internals */
64227
64228 /*
64229@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64230 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64231 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64232 unsigned long start, unsigned long end, gfp_t gfp_mask,
64233- pgprot_t prot, int node, void *caller);
64234+ pgprot_t prot, int node, void *caller) __size_overflow(1);
64235 extern void vfree(const void *addr);
64236
64237 extern void *vmap(struct page **pages, unsigned int count,
64238@@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64239 extern void free_vm_area(struct vm_struct *area);
64240
64241 /* for /dev/kmem */
64242-extern long vread(char *buf, char *addr, unsigned long count);
64243-extern long vwrite(char *buf, char *addr, unsigned long count);
64244+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64245+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64246
64247 /*
64248 * Internals. Dont't use..
64249diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64250index 65efb92..137adbb 100644
64251--- a/include/linux/vmstat.h
64252+++ b/include/linux/vmstat.h
64253@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64254 /*
64255 * Zone based page accounting with per cpu differentials.
64256 */
64257-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64258+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64259
64260 static inline void zone_page_state_add(long x, struct zone *zone,
64261 enum zone_stat_item item)
64262 {
64263- atomic_long_add(x, &zone->vm_stat[item]);
64264- atomic_long_add(x, &vm_stat[item]);
64265+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64266+ atomic_long_add_unchecked(x, &vm_stat[item]);
64267 }
64268
64269 static inline unsigned long global_page_state(enum zone_stat_item item)
64270 {
64271- long x = atomic_long_read(&vm_stat[item]);
64272+ long x = atomic_long_read_unchecked(&vm_stat[item]);
64273 #ifdef CONFIG_SMP
64274 if (x < 0)
64275 x = 0;
64276@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64277 static inline unsigned long zone_page_state(struct zone *zone,
64278 enum zone_stat_item item)
64279 {
64280- long x = atomic_long_read(&zone->vm_stat[item]);
64281+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64282 #ifdef CONFIG_SMP
64283 if (x < 0)
64284 x = 0;
64285@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64286 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64287 enum zone_stat_item item)
64288 {
64289- long x = atomic_long_read(&zone->vm_stat[item]);
64290+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64291
64292 #ifdef CONFIG_SMP
64293 int cpu;
64294@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64295
64296 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64297 {
64298- atomic_long_inc(&zone->vm_stat[item]);
64299- atomic_long_inc(&vm_stat[item]);
64300+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
64301+ atomic_long_inc_unchecked(&vm_stat[item]);
64302 }
64303
64304 static inline void __inc_zone_page_state(struct page *page,
64305@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64306
64307 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64308 {
64309- atomic_long_dec(&zone->vm_stat[item]);
64310- atomic_long_dec(&vm_stat[item]);
64311+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
64312+ atomic_long_dec_unchecked(&vm_stat[item]);
64313 }
64314
64315 static inline void __dec_zone_page_state(struct page *page,
64316diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64317index e5d1220..ef6e406 100644
64318--- a/include/linux/xattr.h
64319+++ b/include/linux/xattr.h
64320@@ -57,6 +57,11 @@
64321 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64322 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64323
64324+/* User namespace */
64325+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64326+#define XATTR_PAX_FLAGS_SUFFIX "flags"
64327+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64328+
64329 #ifdef __KERNEL__
64330
64331 #include <linux/types.h>
64332diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64333index 944ecdf..a3994fc 100644
64334--- a/include/media/saa7146_vv.h
64335+++ b/include/media/saa7146_vv.h
64336@@ -161,8 +161,8 @@ struct saa7146_ext_vv
64337 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64338
64339 /* the extension can override this */
64340- struct v4l2_ioctl_ops vid_ops;
64341- struct v4l2_ioctl_ops vbi_ops;
64342+ v4l2_ioctl_ops_no_const vid_ops;
64343+ v4l2_ioctl_ops_no_const vbi_ops;
64344 /* pointer to the saa7146 core ops */
64345 const struct v4l2_ioctl_ops *core_ops;
64346
64347diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64348index a056e6e..31023a5 100644
64349--- a/include/media/v4l2-dev.h
64350+++ b/include/media/v4l2-dev.h
64351@@ -73,7 +73,8 @@ struct v4l2_file_operations {
64352 int (*mmap) (struct file *, struct vm_area_struct *);
64353 int (*open) (struct file *);
64354 int (*release) (struct file *);
64355-};
64356+} __do_const;
64357+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64358
64359 /*
64360 * Newer version of video_device, handled by videodev2.c
64361diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64362index d8b76f7..7d5aa18 100644
64363--- a/include/media/v4l2-ioctl.h
64364+++ b/include/media/v4l2-ioctl.h
64365@@ -287,7 +287,7 @@ struct v4l2_ioctl_ops {
64366 long (*vidioc_default) (struct file *file, void *fh,
64367 bool valid_prio, int cmd, void *arg);
64368 };
64369-
64370+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64371
64372 /* v4l debugging and diagnostics */
64373
64374diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64375index 439dadc..1c67e3f 100644
64376--- a/include/net/caif/caif_hsi.h
64377+++ b/include/net/caif/caif_hsi.h
64378@@ -98,7 +98,7 @@ struct cfhsi_drv {
64379 void (*rx_done_cb) (struct cfhsi_drv *drv);
64380 void (*wake_up_cb) (struct cfhsi_drv *drv);
64381 void (*wake_down_cb) (struct cfhsi_drv *drv);
64382-};
64383+} __no_const;
64384
64385 /* Structure implemented by HSI device. */
64386 struct cfhsi_dev {
64387diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64388index 9e5425b..8136ffc 100644
64389--- a/include/net/caif/cfctrl.h
64390+++ b/include/net/caif/cfctrl.h
64391@@ -52,7 +52,7 @@ struct cfctrl_rsp {
64392 void (*radioset_rsp)(void);
64393 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64394 struct cflayer *client_layer);
64395-};
64396+} __no_const;
64397
64398 /* Link Setup Parameters for CAIF-Links. */
64399 struct cfctrl_link_param {
64400@@ -101,8 +101,8 @@ struct cfctrl_request_info {
64401 struct cfctrl {
64402 struct cfsrvl serv;
64403 struct cfctrl_rsp res;
64404- atomic_t req_seq_no;
64405- atomic_t rsp_seq_no;
64406+ atomic_unchecked_t req_seq_no;
64407+ atomic_unchecked_t rsp_seq_no;
64408 struct list_head list;
64409 /* Protects from simultaneous access to first_req list */
64410 spinlock_t info_list_lock;
64411diff --git a/include/net/flow.h b/include/net/flow.h
64412index 6c469db..7743b8e 100644
64413--- a/include/net/flow.h
64414+++ b/include/net/flow.h
64415@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64416
64417 extern void flow_cache_flush(void);
64418 extern void flow_cache_flush_deferred(void);
64419-extern atomic_t flow_cache_genid;
64420+extern atomic_unchecked_t flow_cache_genid;
64421
64422 #endif
64423diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64424index 2040bff..f4c0733 100644
64425--- a/include/net/inetpeer.h
64426+++ b/include/net/inetpeer.h
64427@@ -51,8 +51,8 @@ struct inet_peer {
64428 */
64429 union {
64430 struct {
64431- atomic_t rid; /* Frag reception counter */
64432- atomic_t ip_id_count; /* IP ID for the next packet */
64433+ atomic_unchecked_t rid; /* Frag reception counter */
64434+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64435 __u32 tcp_ts;
64436 __u32 tcp_ts_stamp;
64437 };
64438@@ -118,11 +118,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64439 more++;
64440 inet_peer_refcheck(p);
64441 do {
64442- old = atomic_read(&p->ip_id_count);
64443+ old = atomic_read_unchecked(&p->ip_id_count);
64444 new = old + more;
64445 if (!new)
64446 new = 1;
64447- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64448+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64449 return new;
64450 }
64451
64452diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64453index 78df0866..00e5c9b 100644
64454--- a/include/net/ip_fib.h
64455+++ b/include/net/ip_fib.h
64456@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64457
64458 #define FIB_RES_SADDR(net, res) \
64459 ((FIB_RES_NH(res).nh_saddr_genid == \
64460- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64461+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64462 FIB_RES_NH(res).nh_saddr : \
64463 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64464 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64465diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64466index 95374d1..2300e36 100644
64467--- a/include/net/ip_vs.h
64468+++ b/include/net/ip_vs.h
64469@@ -510,7 +510,7 @@ struct ip_vs_conn {
64470 struct ip_vs_conn *control; /* Master control connection */
64471 atomic_t n_control; /* Number of controlled ones */
64472 struct ip_vs_dest *dest; /* real server */
64473- atomic_t in_pkts; /* incoming packet counter */
64474+ atomic_unchecked_t in_pkts; /* incoming packet counter */
64475
64476 /* packet transmitter for different forwarding methods. If it
64477 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64478@@ -648,7 +648,7 @@ struct ip_vs_dest {
64479 __be16 port; /* port number of the server */
64480 union nf_inet_addr addr; /* IP address of the server */
64481 volatile unsigned int flags; /* dest status flags */
64482- atomic_t conn_flags; /* flags to copy to conn */
64483+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
64484 atomic_t weight; /* server weight */
64485
64486 atomic_t refcnt; /* reference counter */
64487diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64488index 69b610a..fe3962c 100644
64489--- a/include/net/irda/ircomm_core.h
64490+++ b/include/net/irda/ircomm_core.h
64491@@ -51,7 +51,7 @@ typedef struct {
64492 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64493 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64494 struct ircomm_info *);
64495-} call_t;
64496+} __no_const call_t;
64497
64498 struct ircomm_cb {
64499 irda_queue_t queue;
64500diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64501index 59ba38bc..d515662 100644
64502--- a/include/net/irda/ircomm_tty.h
64503+++ b/include/net/irda/ircomm_tty.h
64504@@ -35,6 +35,7 @@
64505 #include <linux/termios.h>
64506 #include <linux/timer.h>
64507 #include <linux/tty.h> /* struct tty_struct */
64508+#include <asm/local.h>
64509
64510 #include <net/irda/irias_object.h>
64511 #include <net/irda/ircomm_core.h>
64512@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64513 unsigned short close_delay;
64514 unsigned short closing_wait; /* time to wait before closing */
64515
64516- int open_count;
64517- int blocked_open; /* # of blocked opens */
64518+ local_t open_count;
64519+ local_t blocked_open; /* # of blocked opens */
64520
64521 /* Protect concurent access to :
64522 * o self->open_count
64523diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64524index cc7c197..9f2da2a 100644
64525--- a/include/net/iucv/af_iucv.h
64526+++ b/include/net/iucv/af_iucv.h
64527@@ -141,7 +141,7 @@ struct iucv_sock {
64528 struct iucv_sock_list {
64529 struct hlist_head head;
64530 rwlock_t lock;
64531- atomic_t autobind_name;
64532+ atomic_unchecked_t autobind_name;
64533 };
64534
64535 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64536diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64537index 6cdfeed..55a0256 100644
64538--- a/include/net/neighbour.h
64539+++ b/include/net/neighbour.h
64540@@ -123,7 +123,7 @@ struct neigh_ops {
64541 void (*error_report)(struct neighbour *, struct sk_buff *);
64542 int (*output)(struct neighbour *, struct sk_buff *);
64543 int (*connected_output)(struct neighbour *, struct sk_buff *);
64544-};
64545+} __do_const;
64546
64547 struct pneigh_entry {
64548 struct pneigh_entry *next;
64549diff --git a/include/net/netlink.h b/include/net/netlink.h
64550index 785f37a..c81dc0c 100644
64551--- a/include/net/netlink.h
64552+++ b/include/net/netlink.h
64553@@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64554 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64555 {
64556 if (mark)
64557- skb_trim(skb, (unsigned char *) mark - skb->data);
64558+ skb_trim(skb, (const unsigned char *) mark - skb->data);
64559 }
64560
64561 /**
64562diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64563index bbd023a..97c6d0d 100644
64564--- a/include/net/netns/ipv4.h
64565+++ b/include/net/netns/ipv4.h
64566@@ -57,8 +57,8 @@ struct netns_ipv4 {
64567 unsigned int sysctl_ping_group_range[2];
64568 long sysctl_tcp_mem[3];
64569
64570- atomic_t rt_genid;
64571- atomic_t dev_addr_genid;
64572+ atomic_unchecked_t rt_genid;
64573+ atomic_unchecked_t dev_addr_genid;
64574
64575 #ifdef CONFIG_IP_MROUTE
64576 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64577diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64578index a2ef814..31a8e3f 100644
64579--- a/include/net/sctp/sctp.h
64580+++ b/include/net/sctp/sctp.h
64581@@ -318,9 +318,9 @@ do { \
64582
64583 #else /* SCTP_DEBUG */
64584
64585-#define SCTP_DEBUG_PRINTK(whatever...)
64586-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64587-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64588+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64589+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64590+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64591 #define SCTP_ENABLE_DEBUG
64592 #define SCTP_DISABLE_DEBUG
64593 #define SCTP_ASSERT(expr, str, func)
64594diff --git a/include/net/sock.h b/include/net/sock.h
64595index 4a45216..7af2578 100644
64596--- a/include/net/sock.h
64597+++ b/include/net/sock.h
64598@@ -303,7 +303,7 @@ struct sock {
64599 #ifdef CONFIG_RPS
64600 __u32 sk_rxhash;
64601 #endif
64602- atomic_t sk_drops;
64603+ atomic_unchecked_t sk_drops;
64604 int sk_rcvbuf;
64605
64606 struct sk_filter __rcu *sk_filter;
64607@@ -1726,7 +1726,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64608 }
64609
64610 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64611- char __user *from, char *to,
64612+ char __user *from, unsigned char *to,
64613 int copy, int offset)
64614 {
64615 if (skb->ip_summed == CHECKSUM_NONE) {
64616diff --git a/include/net/tcp.h b/include/net/tcp.h
64617index e79aa48..9929421 100644
64618--- a/include/net/tcp.h
64619+++ b/include/net/tcp.h
64620@@ -1459,7 +1459,7 @@ struct tcp_seq_afinfo {
64621 char *name;
64622 sa_family_t family;
64623 const struct file_operations *seq_fops;
64624- struct seq_operations seq_ops;
64625+ seq_operations_no_const seq_ops;
64626 };
64627
64628 struct tcp_iter_state {
64629diff --git a/include/net/udp.h b/include/net/udp.h
64630index 065f379..b661b40 100644
64631--- a/include/net/udp.h
64632+++ b/include/net/udp.h
64633@@ -244,7 +244,7 @@ struct udp_seq_afinfo {
64634 sa_family_t family;
64635 struct udp_table *udp_table;
64636 const struct file_operations *seq_fops;
64637- struct seq_operations seq_ops;
64638+ seq_operations_no_const seq_ops;
64639 };
64640
64641 struct udp_iter_state {
64642diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64643index e0a55df..5890bca07 100644
64644--- a/include/net/xfrm.h
64645+++ b/include/net/xfrm.h
64646@@ -505,7 +505,7 @@ struct xfrm_policy {
64647 struct timer_list timer;
64648
64649 struct flow_cache_object flo;
64650- atomic_t genid;
64651+ atomic_unchecked_t genid;
64652 u32 priority;
64653 u32 index;
64654 struct xfrm_mark mark;
64655diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64656index 1a046b1..ee0bef0 100644
64657--- a/include/rdma/iw_cm.h
64658+++ b/include/rdma/iw_cm.h
64659@@ -122,7 +122,7 @@ struct iw_cm_verbs {
64660 int backlog);
64661
64662 int (*destroy_listen)(struct iw_cm_id *cm_id);
64663-};
64664+} __no_const;
64665
64666 /**
64667 * iw_create_cm_id - Create an IW CM identifier.
64668diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64669index 8f9dfba..610ab6c 100644
64670--- a/include/scsi/libfc.h
64671+++ b/include/scsi/libfc.h
64672@@ -756,6 +756,7 @@ struct libfc_function_template {
64673 */
64674 void (*disc_stop_final) (struct fc_lport *);
64675 };
64676+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64677
64678 /**
64679 * struct fc_disc - Discovery context
64680@@ -861,7 +862,7 @@ struct fc_lport {
64681 struct fc_vport *vport;
64682
64683 /* Operational Information */
64684- struct libfc_function_template tt;
64685+ libfc_function_template_no_const tt;
64686 u8 link_up;
64687 u8 qfull;
64688 enum fc_lport_state state;
64689diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64690index ba96988..ecf2eb9 100644
64691--- a/include/scsi/scsi_device.h
64692+++ b/include/scsi/scsi_device.h
64693@@ -163,9 +163,9 @@ struct scsi_device {
64694 unsigned int max_device_blocked; /* what device_blocked counts down from */
64695 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64696
64697- atomic_t iorequest_cnt;
64698- atomic_t iodone_cnt;
64699- atomic_t ioerr_cnt;
64700+ atomic_unchecked_t iorequest_cnt;
64701+ atomic_unchecked_t iodone_cnt;
64702+ atomic_unchecked_t ioerr_cnt;
64703
64704 struct device sdev_gendev,
64705 sdev_dev;
64706diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64707index 719faf1..07b6728 100644
64708--- a/include/scsi/scsi_transport_fc.h
64709+++ b/include/scsi/scsi_transport_fc.h
64710@@ -739,7 +739,8 @@ struct fc_function_template {
64711 unsigned long show_host_system_hostname:1;
64712
64713 unsigned long disable_target_scan:1;
64714-};
64715+} __do_const;
64716+typedef struct fc_function_template __no_const fc_function_template_no_const;
64717
64718
64719 /**
64720diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64721index 030b87c..98a6954 100644
64722--- a/include/sound/ak4xxx-adda.h
64723+++ b/include/sound/ak4xxx-adda.h
64724@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64725 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64726 unsigned char val);
64727 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64728-};
64729+} __no_const;
64730
64731 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64732
64733diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64734index 8c05e47..2b5df97 100644
64735--- a/include/sound/hwdep.h
64736+++ b/include/sound/hwdep.h
64737@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64738 struct snd_hwdep_dsp_status *status);
64739 int (*dsp_load)(struct snd_hwdep *hw,
64740 struct snd_hwdep_dsp_image *image);
64741-};
64742+} __no_const;
64743
64744 struct snd_hwdep {
64745 struct snd_card *card;
64746diff --git a/include/sound/info.h b/include/sound/info.h
64747index 9ca1a49..aba1728 100644
64748--- a/include/sound/info.h
64749+++ b/include/sound/info.h
64750@@ -44,7 +44,7 @@ struct snd_info_entry_text {
64751 struct snd_info_buffer *buffer);
64752 void (*write)(struct snd_info_entry *entry,
64753 struct snd_info_buffer *buffer);
64754-};
64755+} __no_const;
64756
64757 struct snd_info_entry_ops {
64758 int (*open)(struct snd_info_entry *entry,
64759diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64760index 0d11128..814178e 100644
64761--- a/include/sound/pcm.h
64762+++ b/include/sound/pcm.h
64763@@ -81,6 +81,7 @@ struct snd_pcm_ops {
64764 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64765 int (*ack)(struct snd_pcm_substream *substream);
64766 };
64767+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64768
64769 /*
64770 *
64771diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64772index af1b49e..a5d55a5 100644
64773--- a/include/sound/sb16_csp.h
64774+++ b/include/sound/sb16_csp.h
64775@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64776 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64777 int (*csp_stop) (struct snd_sb_csp * p);
64778 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64779-};
64780+} __no_const;
64781
64782 /*
64783 * CSP private data
64784diff --git a/include/sound/soc.h b/include/sound/soc.h
64785index c703871..f7fbbbd 100644
64786--- a/include/sound/soc.h
64787+++ b/include/sound/soc.h
64788@@ -757,7 +757,7 @@ struct snd_soc_platform_driver {
64789 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64790 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64791 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
64792-};
64793+} __do_const;
64794
64795 struct snd_soc_platform {
64796 const char *name;
64797@@ -949,7 +949,7 @@ struct snd_soc_pcm_runtime {
64798 struct snd_soc_dai_link *dai_link;
64799 struct mutex pcm_mutex;
64800 enum snd_soc_pcm_subclass pcm_subclass;
64801- struct snd_pcm_ops ops;
64802+ snd_pcm_ops_no_const ops;
64803
64804 unsigned int dev_registered:1;
64805
64806diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
64807index 0c3c2fb..d9d9990 100644
64808--- a/include/sound/tea575x-tuner.h
64809+++ b/include/sound/tea575x-tuner.h
64810@@ -44,7 +44,7 @@ struct snd_tea575x_ops {
64811
64812 struct snd_tea575x {
64813 struct v4l2_device *v4l2_dev;
64814- struct v4l2_file_operations fops;
64815+ v4l2_file_operations_no_const fops;
64816 struct video_device vd; /* video device */
64817 int radio_nr; /* radio_nr */
64818 bool tea5759; /* 5759 chip is present */
64819diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64820index 4119966..1a4671c 100644
64821--- a/include/sound/ymfpci.h
64822+++ b/include/sound/ymfpci.h
64823@@ -358,7 +358,7 @@ struct snd_ymfpci {
64824 spinlock_t reg_lock;
64825 spinlock_t voice_lock;
64826 wait_queue_head_t interrupt_sleep;
64827- atomic_t interrupt_sleep_count;
64828+ atomic_unchecked_t interrupt_sleep_count;
64829 struct snd_info_entry *proc_entry;
64830 const struct firmware *dsp_microcode;
64831 const struct firmware *controller_microcode;
64832diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64833index dc35d86..4725f45 100644
64834--- a/include/target/target_core_base.h
64835+++ b/include/target/target_core_base.h
64836@@ -440,7 +440,7 @@ struct t10_reservation_ops {
64837 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64838 int (*t10_pr_register)(struct se_cmd *);
64839 int (*t10_pr_clear)(struct se_cmd *);
64840-};
64841+} __no_const;
64842
64843 struct t10_reservation {
64844 /* Reservation effects all target ports */
64845@@ -779,7 +779,7 @@ struct se_device {
64846 spinlock_t stats_lock;
64847 /* Active commands on this virtual SE device */
64848 atomic_t simple_cmds;
64849- atomic_t dev_ordered_id;
64850+ atomic_unchecked_t dev_ordered_id;
64851 atomic_t execute_tasks;
64852 atomic_t dev_ordered_sync;
64853 atomic_t dev_qf_count;
64854diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
64855new file mode 100644
64856index 0000000..2efe49d
64857--- /dev/null
64858+++ b/include/trace/events/fs.h
64859@@ -0,0 +1,53 @@
64860+#undef TRACE_SYSTEM
64861+#define TRACE_SYSTEM fs
64862+
64863+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
64864+#define _TRACE_FS_H
64865+
64866+#include <linux/fs.h>
64867+#include <linux/tracepoint.h>
64868+
64869+TRACE_EVENT(do_sys_open,
64870+
64871+ TP_PROTO(char *filename, int flags, int mode),
64872+
64873+ TP_ARGS(filename, flags, mode),
64874+
64875+ TP_STRUCT__entry(
64876+ __string( filename, filename )
64877+ __field( int, flags )
64878+ __field( int, mode )
64879+ ),
64880+
64881+ TP_fast_assign(
64882+ __assign_str(filename, filename);
64883+ __entry->flags = flags;
64884+ __entry->mode = mode;
64885+ ),
64886+
64887+ TP_printk("\"%s\" %x %o",
64888+ __get_str(filename), __entry->flags, __entry->mode)
64889+);
64890+
64891+TRACE_EVENT(open_exec,
64892+
64893+ TP_PROTO(const char *filename),
64894+
64895+ TP_ARGS(filename),
64896+
64897+ TP_STRUCT__entry(
64898+ __string( filename, filename )
64899+ ),
64900+
64901+ TP_fast_assign(
64902+ __assign_str(filename, filename);
64903+ ),
64904+
64905+ TP_printk("\"%s\"",
64906+ __get_str(filename))
64907+);
64908+
64909+#endif /* _TRACE_FS_H */
64910+
64911+/* This part must be outside protection */
64912+#include <trace/define_trace.h>
64913diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64914index 1c09820..7f5ec79 100644
64915--- a/include/trace/events/irq.h
64916+++ b/include/trace/events/irq.h
64917@@ -36,7 +36,7 @@ struct softirq_action;
64918 */
64919 TRACE_EVENT(irq_handler_entry,
64920
64921- TP_PROTO(int irq, struct irqaction *action),
64922+ TP_PROTO(int irq, const struct irqaction *action),
64923
64924 TP_ARGS(irq, action),
64925
64926@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64927 */
64928 TRACE_EVENT(irq_handler_exit,
64929
64930- TP_PROTO(int irq, struct irqaction *action, int ret),
64931+ TP_PROTO(int irq, const struct irqaction *action, int ret),
64932
64933 TP_ARGS(irq, action, ret),
64934
64935diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64936index f9466fa..f4e2b81 100644
64937--- a/include/video/udlfb.h
64938+++ b/include/video/udlfb.h
64939@@ -53,10 +53,10 @@ struct dlfb_data {
64940 u32 pseudo_palette[256];
64941 int blank_mode; /*one of FB_BLANK_ */
64942 /* blit-only rendering path metrics, exposed through sysfs */
64943- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64944- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64945- atomic_t bytes_sent; /* to usb, after compression including overhead */
64946- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64947+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64948+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64949+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64950+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64951 };
64952
64953 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64954diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64955index 0993a22..32ba2fe 100644
64956--- a/include/video/uvesafb.h
64957+++ b/include/video/uvesafb.h
64958@@ -177,6 +177,7 @@ struct uvesafb_par {
64959 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64960 u8 pmi_setpal; /* PMI for palette changes */
64961 u16 *pmi_base; /* protected mode interface location */
64962+ u8 *pmi_code; /* protected mode code location */
64963 void *pmi_start;
64964 void *pmi_pal;
64965 u8 *vbe_state_orig; /*
64966diff --git a/init/Kconfig b/init/Kconfig
64967index d07dcf9..fa47d0e 100644
64968--- a/init/Kconfig
64969+++ b/init/Kconfig
64970@@ -835,6 +835,7 @@ endif # CGROUPS
64971
64972 config CHECKPOINT_RESTORE
64973 bool "Checkpoint/restore support" if EXPERT
64974+ depends on !GRKERNSEC
64975 default n
64976 help
64977 Enables additional kernel features in a sake of checkpoint/restore.
64978@@ -1014,6 +1015,7 @@ config UIDGID_CONVERTED
64979 # Security modules
64980 depends on SECURITY_TOMOYO = n
64981 depends on SECURITY_APPARMOR = n
64982+ depends on GRKERNSEC = n
64983
64984 config UIDGID_STRICT_TYPE_CHECKS
64985 bool "Require conversions between uid/gids and their internal representation"
64986@@ -1401,7 +1403,7 @@ config SLUB_DEBUG
64987
64988 config COMPAT_BRK
64989 bool "Disable heap randomization"
64990- default y
64991+ default n
64992 help
64993 Randomizing heap placement makes heap exploits harder, but it
64994 also breaks ancient binaries (including anything libc5 based).
64995@@ -1584,7 +1586,7 @@ config INIT_ALL_POSSIBLE
64996 config STOP_MACHINE
64997 bool
64998 default y
64999- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65000+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65001 help
65002 Need stop_machine() primitive.
65003
65004diff --git a/init/do_mounts.c b/init/do_mounts.c
65005index d3f0aee..c9322f5 100644
65006--- a/init/do_mounts.c
65007+++ b/init/do_mounts.c
65008@@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65009 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65010 {
65011 struct super_block *s;
65012- int err = sys_mount(name, "/root", fs, flags, data);
65013+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65014 if (err)
65015 return err;
65016
65017- sys_chdir("/root");
65018+ sys_chdir((const char __force_user *)"/root");
65019 s = current->fs->pwd.dentry->d_sb;
65020 ROOT_DEV = s->s_dev;
65021 printk(KERN_INFO
65022@@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65023 va_start(args, fmt);
65024 vsprintf(buf, fmt, args);
65025 va_end(args);
65026- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65027+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65028 if (fd >= 0) {
65029 sys_ioctl(fd, FDEJECT, 0);
65030 sys_close(fd);
65031 }
65032 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65033- fd = sys_open("/dev/console", O_RDWR, 0);
65034+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65035 if (fd >= 0) {
65036 sys_ioctl(fd, TCGETS, (long)&termios);
65037 termios.c_lflag &= ~ICANON;
65038 sys_ioctl(fd, TCSETSF, (long)&termios);
65039- sys_read(fd, &c, 1);
65040+ sys_read(fd, (char __user *)&c, 1);
65041 termios.c_lflag |= ICANON;
65042 sys_ioctl(fd, TCSETSF, (long)&termios);
65043 sys_close(fd);
65044@@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65045 mount_root();
65046 out:
65047 devtmpfs_mount("dev");
65048- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65049- sys_chroot(".");
65050+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65051+ sys_chroot((const char __force_user *)".");
65052 }
65053diff --git a/init/do_mounts.h b/init/do_mounts.h
65054index f5b978a..69dbfe8 100644
65055--- a/init/do_mounts.h
65056+++ b/init/do_mounts.h
65057@@ -15,15 +15,15 @@ extern int root_mountflags;
65058
65059 static inline int create_dev(char *name, dev_t dev)
65060 {
65061- sys_unlink(name);
65062- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65063+ sys_unlink((char __force_user *)name);
65064+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65065 }
65066
65067 #if BITS_PER_LONG == 32
65068 static inline u32 bstat(char *name)
65069 {
65070 struct stat64 stat;
65071- if (sys_stat64(name, &stat) != 0)
65072+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65073 return 0;
65074 if (!S_ISBLK(stat.st_mode))
65075 return 0;
65076@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65077 static inline u32 bstat(char *name)
65078 {
65079 struct stat stat;
65080- if (sys_newstat(name, &stat) != 0)
65081+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65082 return 0;
65083 if (!S_ISBLK(stat.st_mode))
65084 return 0;
65085diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65086index 135959a2..28a3f43 100644
65087--- a/init/do_mounts_initrd.c
65088+++ b/init/do_mounts_initrd.c
65089@@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65090 create_dev("/dev/root.old", Root_RAM0);
65091 /* mount initrd on rootfs' /root */
65092 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65093- sys_mkdir("/old", 0700);
65094- root_fd = sys_open("/", 0, 0);
65095- old_fd = sys_open("/old", 0, 0);
65096+ sys_mkdir((const char __force_user *)"/old", 0700);
65097+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
65098+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65099 /* move initrd over / and chdir/chroot in initrd root */
65100- sys_chdir("/root");
65101- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65102- sys_chroot(".");
65103+ sys_chdir((const char __force_user *)"/root");
65104+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65105+ sys_chroot((const char __force_user *)".");
65106
65107 /*
65108 * In case that a resume from disk is carried out by linuxrc or one of
65109@@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65110
65111 /* move initrd to rootfs' /old */
65112 sys_fchdir(old_fd);
65113- sys_mount("/", ".", NULL, MS_MOVE, NULL);
65114+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65115 /* switch root and cwd back to / of rootfs */
65116 sys_fchdir(root_fd);
65117- sys_chroot(".");
65118+ sys_chroot((const char __force_user *)".");
65119 sys_close(old_fd);
65120 sys_close(root_fd);
65121
65122 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65123- sys_chdir("/old");
65124+ sys_chdir((const char __force_user *)"/old");
65125 return;
65126 }
65127
65128@@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65129 mount_root();
65130
65131 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65132- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65133+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65134 if (!error)
65135 printk("okay\n");
65136 else {
65137- int fd = sys_open("/dev/root.old", O_RDWR, 0);
65138+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65139 if (error == -ENOENT)
65140 printk("/initrd does not exist. Ignored.\n");
65141 else
65142 printk("failed\n");
65143 printk(KERN_NOTICE "Unmounting old root\n");
65144- sys_umount("/old", MNT_DETACH);
65145+ sys_umount((char __force_user *)"/old", MNT_DETACH);
65146 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65147 if (fd < 0) {
65148 error = fd;
65149@@ -125,11 +125,11 @@ int __init initrd_load(void)
65150 * mounted in the normal path.
65151 */
65152 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65153- sys_unlink("/initrd.image");
65154+ sys_unlink((const char __force_user *)"/initrd.image");
65155 handle_initrd();
65156 return 1;
65157 }
65158 }
65159- sys_unlink("/initrd.image");
65160+ sys_unlink((const char __force_user *)"/initrd.image");
65161 return 0;
65162 }
65163diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65164index 8cb6db5..d729f50 100644
65165--- a/init/do_mounts_md.c
65166+++ b/init/do_mounts_md.c
65167@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65168 partitioned ? "_d" : "", minor,
65169 md_setup_args[ent].device_names);
65170
65171- fd = sys_open(name, 0, 0);
65172+ fd = sys_open((char __force_user *)name, 0, 0);
65173 if (fd < 0) {
65174 printk(KERN_ERR "md: open failed - cannot start "
65175 "array %s\n", name);
65176@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65177 * array without it
65178 */
65179 sys_close(fd);
65180- fd = sys_open(name, 0, 0);
65181+ fd = sys_open((char __force_user *)name, 0, 0);
65182 sys_ioctl(fd, BLKRRPART, 0);
65183 }
65184 sys_close(fd);
65185@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65186
65187 wait_for_device_probe();
65188
65189- fd = sys_open("/dev/md0", 0, 0);
65190+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65191 if (fd >= 0) {
65192 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65193 sys_close(fd);
65194diff --git a/init/init_task.c b/init/init_task.c
65195index 8b2f399..f0797c9 100644
65196--- a/init/init_task.c
65197+++ b/init/init_task.c
65198@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65199 * Initial thread structure. Alignment of this is handled by a special
65200 * linker map entry.
65201 */
65202+#ifdef CONFIG_X86
65203+union thread_union init_thread_union __init_task_data;
65204+#else
65205 union thread_union init_thread_union __init_task_data =
65206 { INIT_THREAD_INFO(init_task) };
65207+#endif
65208diff --git a/init/initramfs.c b/init/initramfs.c
65209index 84c6bf1..8899338 100644
65210--- a/init/initramfs.c
65211+++ b/init/initramfs.c
65212@@ -84,7 +84,7 @@ static void __init free_hash(void)
65213 }
65214 }
65215
65216-static long __init do_utime(char *filename, time_t mtime)
65217+static long __init do_utime(char __force_user *filename, time_t mtime)
65218 {
65219 struct timespec t[2];
65220
65221@@ -119,7 +119,7 @@ static void __init dir_utime(void)
65222 struct dir_entry *de, *tmp;
65223 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65224 list_del(&de->list);
65225- do_utime(de->name, de->mtime);
65226+ do_utime((char __force_user *)de->name, de->mtime);
65227 kfree(de->name);
65228 kfree(de);
65229 }
65230@@ -281,7 +281,7 @@ static int __init maybe_link(void)
65231 if (nlink >= 2) {
65232 char *old = find_link(major, minor, ino, mode, collected);
65233 if (old)
65234- return (sys_link(old, collected) < 0) ? -1 : 1;
65235+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65236 }
65237 return 0;
65238 }
65239@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65240 {
65241 struct stat st;
65242
65243- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65244+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65245 if (S_ISDIR(st.st_mode))
65246- sys_rmdir(path);
65247+ sys_rmdir((char __force_user *)path);
65248 else
65249- sys_unlink(path);
65250+ sys_unlink((char __force_user *)path);
65251 }
65252 }
65253
65254@@ -315,7 +315,7 @@ static int __init do_name(void)
65255 int openflags = O_WRONLY|O_CREAT;
65256 if (ml != 1)
65257 openflags |= O_TRUNC;
65258- wfd = sys_open(collected, openflags, mode);
65259+ wfd = sys_open((char __force_user *)collected, openflags, mode);
65260
65261 if (wfd >= 0) {
65262 sys_fchown(wfd, uid, gid);
65263@@ -327,17 +327,17 @@ static int __init do_name(void)
65264 }
65265 }
65266 } else if (S_ISDIR(mode)) {
65267- sys_mkdir(collected, mode);
65268- sys_chown(collected, uid, gid);
65269- sys_chmod(collected, mode);
65270+ sys_mkdir((char __force_user *)collected, mode);
65271+ sys_chown((char __force_user *)collected, uid, gid);
65272+ sys_chmod((char __force_user *)collected, mode);
65273 dir_add(collected, mtime);
65274 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65275 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65276 if (maybe_link() == 0) {
65277- sys_mknod(collected, mode, rdev);
65278- sys_chown(collected, uid, gid);
65279- sys_chmod(collected, mode);
65280- do_utime(collected, mtime);
65281+ sys_mknod((char __force_user *)collected, mode, rdev);
65282+ sys_chown((char __force_user *)collected, uid, gid);
65283+ sys_chmod((char __force_user *)collected, mode);
65284+ do_utime((char __force_user *)collected, mtime);
65285 }
65286 }
65287 return 0;
65288@@ -346,15 +346,15 @@ static int __init do_name(void)
65289 static int __init do_copy(void)
65290 {
65291 if (count >= body_len) {
65292- sys_write(wfd, victim, body_len);
65293+ sys_write(wfd, (char __force_user *)victim, body_len);
65294 sys_close(wfd);
65295- do_utime(vcollected, mtime);
65296+ do_utime((char __force_user *)vcollected, mtime);
65297 kfree(vcollected);
65298 eat(body_len);
65299 state = SkipIt;
65300 return 0;
65301 } else {
65302- sys_write(wfd, victim, count);
65303+ sys_write(wfd, (char __force_user *)victim, count);
65304 body_len -= count;
65305 eat(count);
65306 return 1;
65307@@ -365,9 +365,9 @@ static int __init do_symlink(void)
65308 {
65309 collected[N_ALIGN(name_len) + body_len] = '\0';
65310 clean_path(collected, 0);
65311- sys_symlink(collected + N_ALIGN(name_len), collected);
65312- sys_lchown(collected, uid, gid);
65313- do_utime(collected, mtime);
65314+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
65315+ sys_lchown((char __force_user *)collected, uid, gid);
65316+ do_utime((char __force_user *)collected, mtime);
65317 state = SkipIt;
65318 next_state = Reset;
65319 return 0;
65320diff --git a/init/main.c b/init/main.c
65321index b5cc0a7..5605c91 100644
65322--- a/init/main.c
65323+++ b/init/main.c
65324@@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
65325 extern void tc_init(void);
65326 #endif
65327
65328+extern void grsecurity_init(void);
65329+
65330 /*
65331 * Debug helper: via this flag we know that we are in 'early bootup code'
65332 * where only the boot processor is running with IRQ disabled. This means
65333@@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
65334
65335 __setup("reset_devices", set_reset_devices);
65336
65337+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65338+extern char pax_enter_kernel_user[];
65339+extern char pax_exit_kernel_user[];
65340+extern pgdval_t clone_pgd_mask;
65341+#endif
65342+
65343+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65344+static int __init setup_pax_nouderef(char *str)
65345+{
65346+#ifdef CONFIG_X86_32
65347+ unsigned int cpu;
65348+ struct desc_struct *gdt;
65349+
65350+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65351+ gdt = get_cpu_gdt_table(cpu);
65352+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65353+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65354+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65355+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65356+ }
65357+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65358+#else
65359+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65360+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65361+ clone_pgd_mask = ~(pgdval_t)0UL;
65362+#endif
65363+
65364+ return 0;
65365+}
65366+early_param("pax_nouderef", setup_pax_nouderef);
65367+#endif
65368+
65369+#ifdef CONFIG_PAX_SOFTMODE
65370+int pax_softmode;
65371+
65372+static int __init setup_pax_softmode(char *str)
65373+{
65374+ get_option(&str, &pax_softmode);
65375+ return 1;
65376+}
65377+__setup("pax_softmode=", setup_pax_softmode);
65378+#endif
65379+
65380 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65381 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65382 static const char *panic_later, *panic_param;
65383@@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65384 {
65385 int count = preempt_count();
65386 int ret;
65387+ const char *msg1 = "", *msg2 = "";
65388
65389 if (initcall_debug)
65390 ret = do_one_initcall_debug(fn);
65391@@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65392 sprintf(msgbuf, "error code %d ", ret);
65393
65394 if (preempt_count() != count) {
65395- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65396+ msg1 = " preemption imbalance";
65397 preempt_count() = count;
65398 }
65399 if (irqs_disabled()) {
65400- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65401+ msg2 = " disabled interrupts";
65402 local_irq_enable();
65403 }
65404- if (msgbuf[0]) {
65405- printk("initcall %pF returned with %s\n", fn, msgbuf);
65406+ if (msgbuf[0] || *msg1 || *msg2) {
65407+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65408 }
65409
65410 return ret;
65411@@ -747,8 +793,14 @@ static void __init do_initcall_level(int level)
65412 level, level,
65413 &repair_env_string);
65414
65415- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
65416+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
65417 do_one_initcall(*fn);
65418+
65419+#ifdef CONFIG_PAX_LATENT_ENTROPY
65420+ transfer_latent_entropy();
65421+#endif
65422+
65423+ }
65424 }
65425
65426 static void __init do_initcalls(void)
65427@@ -782,8 +834,14 @@ static void __init do_pre_smp_initcalls(void)
65428 {
65429 initcall_t *fn;
65430
65431- for (fn = __initcall_start; fn < __initcall0_start; fn++)
65432+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
65433 do_one_initcall(*fn);
65434+
65435+#ifdef CONFIG_PAX_LATENT_ENTROPY
65436+ transfer_latent_entropy();
65437+#endif
65438+
65439+ }
65440 }
65441
65442 static void run_init_process(const char *init_filename)
65443@@ -865,7 +923,7 @@ static int __init kernel_init(void * unused)
65444 do_basic_setup();
65445
65446 /* Open the /dev/console on the rootfs, this should never fail */
65447- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65448+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65449 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65450
65451 (void) sys_dup(0);
65452@@ -878,11 +936,13 @@ static int __init kernel_init(void * unused)
65453 if (!ramdisk_execute_command)
65454 ramdisk_execute_command = "/init";
65455
65456- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65457+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65458 ramdisk_execute_command = NULL;
65459 prepare_namespace();
65460 }
65461
65462+ grsecurity_init();
65463+
65464 /*
65465 * Ok, we have completed the initial bootup, and
65466 * we're essentially up and running. Get rid of the
65467diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65468index 8ce5769..4666884 100644
65469--- a/ipc/mqueue.c
65470+++ b/ipc/mqueue.c
65471@@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65472 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
65473 info->attr.mq_msgsize);
65474
65475+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65476 spin_lock(&mq_lock);
65477 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65478 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65479diff --git a/ipc/msg.c b/ipc/msg.c
65480index 7385de2..a8180e08 100644
65481--- a/ipc/msg.c
65482+++ b/ipc/msg.c
65483@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65484 return security_msg_queue_associate(msq, msgflg);
65485 }
65486
65487+static struct ipc_ops msg_ops = {
65488+ .getnew = newque,
65489+ .associate = msg_security,
65490+ .more_checks = NULL
65491+};
65492+
65493 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65494 {
65495 struct ipc_namespace *ns;
65496- struct ipc_ops msg_ops;
65497 struct ipc_params msg_params;
65498
65499 ns = current->nsproxy->ipc_ns;
65500
65501- msg_ops.getnew = newque;
65502- msg_ops.associate = msg_security;
65503- msg_ops.more_checks = NULL;
65504-
65505 msg_params.key = key;
65506 msg_params.flg = msgflg;
65507
65508diff --git a/ipc/sem.c b/ipc/sem.c
65509index 5215a81..cfc0cac 100644
65510--- a/ipc/sem.c
65511+++ b/ipc/sem.c
65512@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65513 return 0;
65514 }
65515
65516+static struct ipc_ops sem_ops = {
65517+ .getnew = newary,
65518+ .associate = sem_security,
65519+ .more_checks = sem_more_checks
65520+};
65521+
65522 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65523 {
65524 struct ipc_namespace *ns;
65525- struct ipc_ops sem_ops;
65526 struct ipc_params sem_params;
65527
65528 ns = current->nsproxy->ipc_ns;
65529@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65530 if (nsems < 0 || nsems > ns->sc_semmsl)
65531 return -EINVAL;
65532
65533- sem_ops.getnew = newary;
65534- sem_ops.associate = sem_security;
65535- sem_ops.more_checks = sem_more_checks;
65536-
65537 sem_params.key = key;
65538 sem_params.flg = semflg;
65539 sem_params.u.nsems = nsems;
65540diff --git a/ipc/shm.c b/ipc/shm.c
65541index 41c1285..cf6404c 100644
65542--- a/ipc/shm.c
65543+++ b/ipc/shm.c
65544@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65545 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65546 #endif
65547
65548+#ifdef CONFIG_GRKERNSEC
65549+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65550+ const time_t shm_createtime, const uid_t cuid,
65551+ const int shmid);
65552+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65553+ const time_t shm_createtime);
65554+#endif
65555+
65556 void shm_init_ns(struct ipc_namespace *ns)
65557 {
65558 ns->shm_ctlmax = SHMMAX;
65559@@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65560 shp->shm_lprid = 0;
65561 shp->shm_atim = shp->shm_dtim = 0;
65562 shp->shm_ctim = get_seconds();
65563+#ifdef CONFIG_GRKERNSEC
65564+ {
65565+ struct timespec timeval;
65566+ do_posix_clock_monotonic_gettime(&timeval);
65567+
65568+ shp->shm_createtime = timeval.tv_sec;
65569+ }
65570+#endif
65571 shp->shm_segsz = size;
65572 shp->shm_nattch = 0;
65573 shp->shm_file = file;
65574@@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65575 return 0;
65576 }
65577
65578+static struct ipc_ops shm_ops = {
65579+ .getnew = newseg,
65580+ .associate = shm_security,
65581+ .more_checks = shm_more_checks
65582+};
65583+
65584 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65585 {
65586 struct ipc_namespace *ns;
65587- struct ipc_ops shm_ops;
65588 struct ipc_params shm_params;
65589
65590 ns = current->nsproxy->ipc_ns;
65591
65592- shm_ops.getnew = newseg;
65593- shm_ops.associate = shm_security;
65594- shm_ops.more_checks = shm_more_checks;
65595-
65596 shm_params.key = key;
65597 shm_params.flg = shmflg;
65598 shm_params.u.size = size;
65599@@ -1000,6 +1017,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65600 f_mode = FMODE_READ | FMODE_WRITE;
65601 }
65602 if (shmflg & SHM_EXEC) {
65603+
65604+#ifdef CONFIG_PAX_MPROTECT
65605+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
65606+ goto out;
65607+#endif
65608+
65609 prot |= PROT_EXEC;
65610 acc_mode |= S_IXUGO;
65611 }
65612@@ -1023,9 +1046,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65613 if (err)
65614 goto out_unlock;
65615
65616+#ifdef CONFIG_GRKERNSEC
65617+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65618+ shp->shm_perm.cuid, shmid) ||
65619+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65620+ err = -EACCES;
65621+ goto out_unlock;
65622+ }
65623+#endif
65624+
65625 path = shp->shm_file->f_path;
65626 path_get(&path);
65627 shp->shm_nattch++;
65628+#ifdef CONFIG_GRKERNSEC
65629+ shp->shm_lapid = current->pid;
65630+#endif
65631 size = i_size_read(path.dentry->d_inode);
65632 shm_unlock(shp);
65633
65634diff --git a/kernel/acct.c b/kernel/acct.c
65635index 02e6167..54824f7 100644
65636--- a/kernel/acct.c
65637+++ b/kernel/acct.c
65638@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65639 */
65640 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65641 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65642- file->f_op->write(file, (char *)&ac,
65643+ file->f_op->write(file, (char __force_user *)&ac,
65644 sizeof(acct_t), &file->f_pos);
65645 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65646 set_fs(fs);
65647diff --git a/kernel/audit.c b/kernel/audit.c
65648index 1c7f2c6..9ba5359 100644
65649--- a/kernel/audit.c
65650+++ b/kernel/audit.c
65651@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65652 3) suppressed due to audit_rate_limit
65653 4) suppressed due to audit_backlog_limit
65654 */
65655-static atomic_t audit_lost = ATOMIC_INIT(0);
65656+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65657
65658 /* The netlink socket. */
65659 static struct sock *audit_sock;
65660@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65661 unsigned long now;
65662 int print;
65663
65664- atomic_inc(&audit_lost);
65665+ atomic_inc_unchecked(&audit_lost);
65666
65667 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65668
65669@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65670 printk(KERN_WARNING
65671 "audit: audit_lost=%d audit_rate_limit=%d "
65672 "audit_backlog_limit=%d\n",
65673- atomic_read(&audit_lost),
65674+ atomic_read_unchecked(&audit_lost),
65675 audit_rate_limit,
65676 audit_backlog_limit);
65677 audit_panic(message);
65678@@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65679 status_set.pid = audit_pid;
65680 status_set.rate_limit = audit_rate_limit;
65681 status_set.backlog_limit = audit_backlog_limit;
65682- status_set.lost = atomic_read(&audit_lost);
65683+ status_set.lost = atomic_read_unchecked(&audit_lost);
65684 status_set.backlog = skb_queue_len(&audit_skb_queue);
65685 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65686 &status_set, sizeof(status_set));
65687diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65688index 4b96415..d8c16ee 100644
65689--- a/kernel/auditsc.c
65690+++ b/kernel/auditsc.c
65691@@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65692 }
65693
65694 /* global counter which is incremented every time something logs in */
65695-static atomic_t session_id = ATOMIC_INIT(0);
65696+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65697
65698 /**
65699 * audit_set_loginuid - set current task's audit_context loginuid
65700@@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
65701 return -EPERM;
65702 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65703
65704- sessionid = atomic_inc_return(&session_id);
65705+ sessionid = atomic_inc_return_unchecked(&session_id);
65706 if (context && context->in_syscall) {
65707 struct audit_buffer *ab;
65708
65709diff --git a/kernel/capability.c b/kernel/capability.c
65710index 493d972..ea17248 100644
65711--- a/kernel/capability.c
65712+++ b/kernel/capability.c
65713@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65714 * before modification is attempted and the application
65715 * fails.
65716 */
65717+ if (tocopy > ARRAY_SIZE(kdata))
65718+ return -EFAULT;
65719+
65720 if (copy_to_user(dataptr, kdata, tocopy
65721 * sizeof(struct __user_cap_data_struct))) {
65722 return -EFAULT;
65723@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65724 int ret;
65725
65726 rcu_read_lock();
65727- ret = security_capable(__task_cred(t), ns, cap);
65728+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65729+ gr_task_is_capable(t, __task_cred(t), cap);
65730 rcu_read_unlock();
65731
65732- return (ret == 0);
65733+ return ret;
65734 }
65735
65736 /**
65737@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65738 int ret;
65739
65740 rcu_read_lock();
65741- ret = security_capable_noaudit(__task_cred(t), ns, cap);
65742+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65743 rcu_read_unlock();
65744
65745- return (ret == 0);
65746+ return ret;
65747 }
65748
65749 /**
65750@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65751 BUG();
65752 }
65753
65754- if (security_capable(current_cred(), ns, cap) == 0) {
65755+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65756 current->flags |= PF_SUPERPRIV;
65757 return true;
65758 }
65759@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65760 }
65761 EXPORT_SYMBOL(ns_capable);
65762
65763+bool ns_capable_nolog(struct user_namespace *ns, int cap)
65764+{
65765+ if (unlikely(!cap_valid(cap))) {
65766+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65767+ BUG();
65768+ }
65769+
65770+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65771+ current->flags |= PF_SUPERPRIV;
65772+ return true;
65773+ }
65774+ return false;
65775+}
65776+EXPORT_SYMBOL(ns_capable_nolog);
65777+
65778 /**
65779 * capable - Determine if the current task has a superior capability in effect
65780 * @cap: The capability to be tested for
65781@@ -408,6 +427,12 @@ bool capable(int cap)
65782 }
65783 EXPORT_SYMBOL(capable);
65784
65785+bool capable_nolog(int cap)
65786+{
65787+ return ns_capable_nolog(&init_user_ns, cap);
65788+}
65789+EXPORT_SYMBOL(capable_nolog);
65790+
65791 /**
65792 * nsown_capable - Check superior capability to one's own user_ns
65793 * @cap: The capability in question
65794@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
65795
65796 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
65797 }
65798+
65799+bool inode_capable_nolog(const struct inode *inode, int cap)
65800+{
65801+ struct user_namespace *ns = current_user_ns();
65802+
65803+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
65804+}
65805diff --git a/kernel/compat.c b/kernel/compat.c
65806index c28a306..b4d0cf3 100644
65807--- a/kernel/compat.c
65808+++ b/kernel/compat.c
65809@@ -13,6 +13,7 @@
65810
65811 #include <linux/linkage.h>
65812 #include <linux/compat.h>
65813+#include <linux/module.h>
65814 #include <linux/errno.h>
65815 #include <linux/time.h>
65816 #include <linux/signal.h>
65817@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65818 mm_segment_t oldfs;
65819 long ret;
65820
65821- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65822+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65823 oldfs = get_fs();
65824 set_fs(KERNEL_DS);
65825 ret = hrtimer_nanosleep_restart(restart);
65826@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65827 oldfs = get_fs();
65828 set_fs(KERNEL_DS);
65829 ret = hrtimer_nanosleep(&tu,
65830- rmtp ? (struct timespec __user *)&rmt : NULL,
65831+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
65832 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65833 set_fs(oldfs);
65834
65835@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65836 mm_segment_t old_fs = get_fs();
65837
65838 set_fs(KERNEL_DS);
65839- ret = sys_sigpending((old_sigset_t __user *) &s);
65840+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
65841 set_fs(old_fs);
65842 if (ret == 0)
65843 ret = put_user(s, set);
65844@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65845 mm_segment_t old_fs = get_fs();
65846
65847 set_fs(KERNEL_DS);
65848- ret = sys_old_getrlimit(resource, &r);
65849+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65850 set_fs(old_fs);
65851
65852 if (!ret) {
65853@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65854 mm_segment_t old_fs = get_fs();
65855
65856 set_fs(KERNEL_DS);
65857- ret = sys_getrusage(who, (struct rusage __user *) &r);
65858+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65859 set_fs(old_fs);
65860
65861 if (ret)
65862@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65863 set_fs (KERNEL_DS);
65864 ret = sys_wait4(pid,
65865 (stat_addr ?
65866- (unsigned int __user *) &status : NULL),
65867- options, (struct rusage __user *) &r);
65868+ (unsigned int __force_user *) &status : NULL),
65869+ options, (struct rusage __force_user *) &r);
65870 set_fs (old_fs);
65871
65872 if (ret > 0) {
65873@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65874 memset(&info, 0, sizeof(info));
65875
65876 set_fs(KERNEL_DS);
65877- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65878- uru ? (struct rusage __user *)&ru : NULL);
65879+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65880+ uru ? (struct rusage __force_user *)&ru : NULL);
65881 set_fs(old_fs);
65882
65883 if ((ret < 0) || (info.si_signo == 0))
65884@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65885 oldfs = get_fs();
65886 set_fs(KERNEL_DS);
65887 err = sys_timer_settime(timer_id, flags,
65888- (struct itimerspec __user *) &newts,
65889- (struct itimerspec __user *) &oldts);
65890+ (struct itimerspec __force_user *) &newts,
65891+ (struct itimerspec __force_user *) &oldts);
65892 set_fs(oldfs);
65893 if (!err && old && put_compat_itimerspec(old, &oldts))
65894 return -EFAULT;
65895@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65896 oldfs = get_fs();
65897 set_fs(KERNEL_DS);
65898 err = sys_timer_gettime(timer_id,
65899- (struct itimerspec __user *) &ts);
65900+ (struct itimerspec __force_user *) &ts);
65901 set_fs(oldfs);
65902 if (!err && put_compat_itimerspec(setting, &ts))
65903 return -EFAULT;
65904@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65905 oldfs = get_fs();
65906 set_fs(KERNEL_DS);
65907 err = sys_clock_settime(which_clock,
65908- (struct timespec __user *) &ts);
65909+ (struct timespec __force_user *) &ts);
65910 set_fs(oldfs);
65911 return err;
65912 }
65913@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65914 oldfs = get_fs();
65915 set_fs(KERNEL_DS);
65916 err = sys_clock_gettime(which_clock,
65917- (struct timespec __user *) &ts);
65918+ (struct timespec __force_user *) &ts);
65919 set_fs(oldfs);
65920 if (!err && put_compat_timespec(&ts, tp))
65921 return -EFAULT;
65922@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65923
65924 oldfs = get_fs();
65925 set_fs(KERNEL_DS);
65926- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65927+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65928 set_fs(oldfs);
65929
65930 err = compat_put_timex(utp, &txc);
65931@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65932 oldfs = get_fs();
65933 set_fs(KERNEL_DS);
65934 err = sys_clock_getres(which_clock,
65935- (struct timespec __user *) &ts);
65936+ (struct timespec __force_user *) &ts);
65937 set_fs(oldfs);
65938 if (!err && tp && put_compat_timespec(&ts, tp))
65939 return -EFAULT;
65940@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65941 long err;
65942 mm_segment_t oldfs;
65943 struct timespec tu;
65944- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65945+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65946
65947- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65948+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65949 oldfs = get_fs();
65950 set_fs(KERNEL_DS);
65951 err = clock_nanosleep_restart(restart);
65952@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
65953 oldfs = get_fs();
65954 set_fs(KERNEL_DS);
65955 err = sys_clock_nanosleep(which_clock, flags,
65956- (struct timespec __user *) &in,
65957- (struct timespec __user *) &out);
65958+ (struct timespec __force_user *) &in,
65959+ (struct timespec __force_user *) &out);
65960 set_fs(oldfs);
65961
65962 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
65963diff --git a/kernel/configs.c b/kernel/configs.c
65964index 42e8fa0..9e7406b 100644
65965--- a/kernel/configs.c
65966+++ b/kernel/configs.c
65967@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
65968 struct proc_dir_entry *entry;
65969
65970 /* create the current config file */
65971+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
65972+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
65973+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
65974+ &ikconfig_file_ops);
65975+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65976+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
65977+ &ikconfig_file_ops);
65978+#endif
65979+#else
65980 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
65981 &ikconfig_file_ops);
65982+#endif
65983+
65984 if (!entry)
65985 return -ENOMEM;
65986
65987diff --git a/kernel/cred.c b/kernel/cred.c
65988index de728ac..e3c267c 100644
65989--- a/kernel/cred.c
65990+++ b/kernel/cred.c
65991@@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
65992 validate_creds(cred);
65993 alter_cred_subscribers(cred, -1);
65994 put_cred(cred);
65995+
65996+#ifdef CONFIG_GRKERNSEC_SETXID
65997+ cred = (struct cred *) tsk->delayed_cred;
65998+ if (cred != NULL) {
65999+ tsk->delayed_cred = NULL;
66000+ validate_creds(cred);
66001+ alter_cred_subscribers(cred, -1);
66002+ put_cred(cred);
66003+ }
66004+#endif
66005 }
66006
66007 /**
66008@@ -469,7 +479,7 @@ error_put:
66009 * Always returns 0 thus allowing this function to be tail-called at the end
66010 * of, say, sys_setgid().
66011 */
66012-int commit_creds(struct cred *new)
66013+static int __commit_creds(struct cred *new)
66014 {
66015 struct task_struct *task = current;
66016 const struct cred *old = task->real_cred;
66017@@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66018
66019 get_cred(new); /* we will require a ref for the subj creds too */
66020
66021+ gr_set_role_label(task, new->uid, new->gid);
66022+
66023 /* dumpability changes */
66024 if (!uid_eq(old->euid, new->euid) ||
66025 !gid_eq(old->egid, new->egid) ||
66026@@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66027 put_cred(old);
66028 return 0;
66029 }
66030+#ifdef CONFIG_GRKERNSEC_SETXID
66031+extern int set_user(struct cred *new);
66032+
66033+void gr_delayed_cred_worker(void)
66034+{
66035+ const struct cred *new = current->delayed_cred;
66036+ struct cred *ncred;
66037+
66038+ current->delayed_cred = NULL;
66039+
66040+ if (current_uid() && new != NULL) {
66041+ // from doing get_cred on it when queueing this
66042+ put_cred(new);
66043+ return;
66044+ } else if (new == NULL)
66045+ return;
66046+
66047+ ncred = prepare_creds();
66048+ if (!ncred)
66049+ goto die;
66050+ // uids
66051+ ncred->uid = new->uid;
66052+ ncred->euid = new->euid;
66053+ ncred->suid = new->suid;
66054+ ncred->fsuid = new->fsuid;
66055+ // gids
66056+ ncred->gid = new->gid;
66057+ ncred->egid = new->egid;
66058+ ncred->sgid = new->sgid;
66059+ ncred->fsgid = new->fsgid;
66060+ // groups
66061+ if (set_groups(ncred, new->group_info) < 0) {
66062+ abort_creds(ncred);
66063+ goto die;
66064+ }
66065+ // caps
66066+ ncred->securebits = new->securebits;
66067+ ncred->cap_inheritable = new->cap_inheritable;
66068+ ncred->cap_permitted = new->cap_permitted;
66069+ ncred->cap_effective = new->cap_effective;
66070+ ncred->cap_bset = new->cap_bset;
66071+
66072+ if (set_user(ncred)) {
66073+ abort_creds(ncred);
66074+ goto die;
66075+ }
66076+
66077+ // from doing get_cred on it when queueing this
66078+ put_cred(new);
66079+
66080+ __commit_creds(ncred);
66081+ return;
66082+die:
66083+ // from doing get_cred on it when queueing this
66084+ put_cred(new);
66085+ do_group_exit(SIGKILL);
66086+}
66087+#endif
66088+
66089+int commit_creds(struct cred *new)
66090+{
66091+#ifdef CONFIG_GRKERNSEC_SETXID
66092+ int ret;
66093+ int schedule_it = 0;
66094+ struct task_struct *t;
66095+
66096+ /* we won't get called with tasklist_lock held for writing
66097+ and interrupts disabled as the cred struct in that case is
66098+ init_cred
66099+ */
66100+ if (grsec_enable_setxid && !current_is_single_threaded() &&
66101+ !current_uid() && new->uid) {
66102+ schedule_it = 1;
66103+ }
66104+ ret = __commit_creds(new);
66105+ if (schedule_it) {
66106+ rcu_read_lock();
66107+ read_lock(&tasklist_lock);
66108+ for (t = next_thread(current); t != current;
66109+ t = next_thread(t)) {
66110+ if (t->delayed_cred == NULL) {
66111+ t->delayed_cred = get_cred(new);
66112+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66113+ set_tsk_need_resched(t);
66114+ }
66115+ }
66116+ read_unlock(&tasklist_lock);
66117+ rcu_read_unlock();
66118+ }
66119+ return ret;
66120+#else
66121+ return __commit_creds(new);
66122+#endif
66123+}
66124+
66125 EXPORT_SYMBOL(commit_creds);
66126
66127 /**
66128diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66129index 0557f24..1a00d9a 100644
66130--- a/kernel/debug/debug_core.c
66131+++ b/kernel/debug/debug_core.c
66132@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66133 */
66134 static atomic_t masters_in_kgdb;
66135 static atomic_t slaves_in_kgdb;
66136-static atomic_t kgdb_break_tasklet_var;
66137+static atomic_unchecked_t kgdb_break_tasklet_var;
66138 atomic_t kgdb_setting_breakpoint;
66139
66140 struct task_struct *kgdb_usethread;
66141@@ -132,7 +132,7 @@ int kgdb_single_step;
66142 static pid_t kgdb_sstep_pid;
66143
66144 /* to keep track of the CPU which is doing the single stepping*/
66145-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66146+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66147
66148 /*
66149 * If you are debugging a problem where roundup (the collection of
66150@@ -540,7 +540,7 @@ return_normal:
66151 * kernel will only try for the value of sstep_tries before
66152 * giving up and continuing on.
66153 */
66154- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66155+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66156 (kgdb_info[cpu].task &&
66157 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66158 atomic_set(&kgdb_active, -1);
66159@@ -634,8 +634,8 @@ cpu_master_loop:
66160 }
66161
66162 kgdb_restore:
66163- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66164- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66165+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66166+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66167 if (kgdb_info[sstep_cpu].task)
66168 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66169 else
66170@@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66171 static void kgdb_tasklet_bpt(unsigned long ing)
66172 {
66173 kgdb_breakpoint();
66174- atomic_set(&kgdb_break_tasklet_var, 0);
66175+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66176 }
66177
66178 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66179
66180 void kgdb_schedule_breakpoint(void)
66181 {
66182- if (atomic_read(&kgdb_break_tasklet_var) ||
66183+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66184 atomic_read(&kgdb_active) != -1 ||
66185 atomic_read(&kgdb_setting_breakpoint))
66186 return;
66187- atomic_inc(&kgdb_break_tasklet_var);
66188+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
66189 tasklet_schedule(&kgdb_tasklet_breakpoint);
66190 }
66191 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66192diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66193index 1f91413..362a0a1 100644
66194--- a/kernel/debug/kdb/kdb_main.c
66195+++ b/kernel/debug/kdb/kdb_main.c
66196@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
66197 list_for_each_entry(mod, kdb_modules, list) {
66198
66199 kdb_printf("%-20s%8u 0x%p ", mod->name,
66200- mod->core_size, (void *)mod);
66201+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
66202 #ifdef CONFIG_MODULE_UNLOAD
66203 kdb_printf("%4ld ", module_refcount(mod));
66204 #endif
66205@@ -1994,7 +1994,7 @@ static int kdb_lsmod(int argc, const char **argv)
66206 kdb_printf(" (Loading)");
66207 else
66208 kdb_printf(" (Live)");
66209- kdb_printf(" 0x%p", mod->module_core);
66210+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66211
66212 #ifdef CONFIG_MODULE_UNLOAD
66213 {
66214diff --git a/kernel/events/core.c b/kernel/events/core.c
66215index d7d71d6..f54b76f 100644
66216--- a/kernel/events/core.c
66217+++ b/kernel/events/core.c
66218@@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66219 return 0;
66220 }
66221
66222-static atomic64_t perf_event_id;
66223+static atomic64_unchecked_t perf_event_id;
66224
66225 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66226 enum event_type_t event_type);
66227@@ -2663,7 +2663,7 @@ static void __perf_event_read(void *info)
66228
66229 static inline u64 perf_event_count(struct perf_event *event)
66230 {
66231- return local64_read(&event->count) + atomic64_read(&event->child_count);
66232+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66233 }
66234
66235 static u64 perf_event_read(struct perf_event *event)
66236@@ -2987,9 +2987,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66237 mutex_lock(&event->child_mutex);
66238 total += perf_event_read(event);
66239 *enabled += event->total_time_enabled +
66240- atomic64_read(&event->child_total_time_enabled);
66241+ atomic64_read_unchecked(&event->child_total_time_enabled);
66242 *running += event->total_time_running +
66243- atomic64_read(&event->child_total_time_running);
66244+ atomic64_read_unchecked(&event->child_total_time_running);
66245
66246 list_for_each_entry(child, &event->child_list, child_list) {
66247 total += perf_event_read(child);
66248@@ -3396,10 +3396,10 @@ void perf_event_update_userpage(struct perf_event *event)
66249 userpg->offset -= local64_read(&event->hw.prev_count);
66250
66251 userpg->time_enabled = enabled +
66252- atomic64_read(&event->child_total_time_enabled);
66253+ atomic64_read_unchecked(&event->child_total_time_enabled);
66254
66255 userpg->time_running = running +
66256- atomic64_read(&event->child_total_time_running);
66257+ atomic64_read_unchecked(&event->child_total_time_running);
66258
66259 arch_perf_update_userpage(userpg, now);
66260
66261@@ -3832,11 +3832,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66262 values[n++] = perf_event_count(event);
66263 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66264 values[n++] = enabled +
66265- atomic64_read(&event->child_total_time_enabled);
66266+ atomic64_read_unchecked(&event->child_total_time_enabled);
66267 }
66268 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
66269 values[n++] = running +
66270- atomic64_read(&event->child_total_time_running);
66271+ atomic64_read_unchecked(&event->child_total_time_running);
66272 }
66273 if (read_format & PERF_FORMAT_ID)
66274 values[n++] = primary_event_id(event);
66275@@ -4514,12 +4514,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66276 * need to add enough zero bytes after the string to handle
66277 * the 64bit alignment we do later.
66278 */
66279- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
66280+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
66281 if (!buf) {
66282 name = strncpy(tmp, "//enomem", sizeof(tmp));
66283 goto got_name;
66284 }
66285- name = d_path(&file->f_path, buf, PATH_MAX);
66286+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
66287 if (IS_ERR(name)) {
66288 name = strncpy(tmp, "//toolong", sizeof(tmp));
66289 goto got_name;
66290@@ -5931,7 +5931,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
66291 event->parent = parent_event;
66292
66293 event->ns = get_pid_ns(current->nsproxy->pid_ns);
66294- event->id = atomic64_inc_return(&perf_event_id);
66295+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
66296
66297 event->state = PERF_EVENT_STATE_INACTIVE;
66298
66299@@ -6493,10 +6493,10 @@ static void sync_child_event(struct perf_event *child_event,
66300 /*
66301 * Add back the child's count to the parent's count:
66302 */
66303- atomic64_add(child_val, &parent_event->child_count);
66304- atomic64_add(child_event->total_time_enabled,
66305+ atomic64_add_unchecked(child_val, &parent_event->child_count);
66306+ atomic64_add_unchecked(child_event->total_time_enabled,
66307 &parent_event->child_total_time_enabled);
66308- atomic64_add(child_event->total_time_running,
66309+ atomic64_add_unchecked(child_event->total_time_running,
66310 &parent_event->child_total_time_running);
66311
66312 /*
66313diff --git a/kernel/exit.c b/kernel/exit.c
66314index 2f59cc3..ce5b167 100644
66315--- a/kernel/exit.c
66316+++ b/kernel/exit.c
66317@@ -59,6 +59,10 @@
66318 #include <asm/pgtable.h>
66319 #include <asm/mmu_context.h>
66320
66321+#ifdef CONFIG_GRKERNSEC
66322+extern rwlock_t grsec_exec_file_lock;
66323+#endif
66324+
66325 static void exit_mm(struct task_struct * tsk);
66326
66327 static void __unhash_process(struct task_struct *p, bool group_dead)
66328@@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
66329 struct task_struct *leader;
66330 int zap_leader;
66331 repeat:
66332+#ifdef CONFIG_NET
66333+ gr_del_task_from_ip_table(p);
66334+#endif
66335+
66336 /* don't need to get the RCU readlock here - the process is dead and
66337 * can't be modifying its own credentials. But shut RCU-lockdep up */
66338 rcu_read_lock();
66339@@ -394,7 +402,7 @@ int allow_signal(int sig)
66340 * know it'll be handled, so that they don't get converted to
66341 * SIGKILL or just silently dropped.
66342 */
66343- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
66344+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
66345 recalc_sigpending();
66346 spin_unlock_irq(&current->sighand->siglock);
66347 return 0;
66348@@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
66349 vsnprintf(current->comm, sizeof(current->comm), name, args);
66350 va_end(args);
66351
66352+#ifdef CONFIG_GRKERNSEC
66353+ write_lock(&grsec_exec_file_lock);
66354+ if (current->exec_file) {
66355+ fput(current->exec_file);
66356+ current->exec_file = NULL;
66357+ }
66358+ write_unlock(&grsec_exec_file_lock);
66359+#endif
66360+
66361+ gr_set_kernel_label(current);
66362+
66363 /*
66364 * If we were started as result of loading a module, close all of the
66365 * user space pages. We don't need them, and if we didn't close them
66366@@ -907,6 +926,8 @@ void do_exit(long code)
66367 struct task_struct *tsk = current;
66368 int group_dead;
66369
66370+ set_fs(USER_DS);
66371+
66372 profile_task_exit(tsk);
66373
66374 WARN_ON(blk_needs_flush_plug(tsk));
66375@@ -923,7 +944,6 @@ void do_exit(long code)
66376 * mm_release()->clear_child_tid() from writing to a user-controlled
66377 * kernel address.
66378 */
66379- set_fs(USER_DS);
66380
66381 ptrace_event(PTRACE_EVENT_EXIT, code);
66382
66383@@ -985,6 +1005,9 @@ void do_exit(long code)
66384 tsk->exit_code = code;
66385 taskstats_exit(tsk, group_dead);
66386
66387+ gr_acl_handle_psacct(tsk, code);
66388+ gr_acl_handle_exit();
66389+
66390 exit_mm(tsk);
66391
66392 if (group_dead)
66393@@ -1101,7 +1124,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66394 * Take down every thread in the group. This is called by fatal signals
66395 * as well as by sys_exit_group (below).
66396 */
66397-void
66398+__noreturn void
66399 do_group_exit(int exit_code)
66400 {
66401 struct signal_struct *sig = current->signal;
66402diff --git a/kernel/fork.c b/kernel/fork.c
66403index f00e319..c212fbc 100644
66404--- a/kernel/fork.c
66405+++ b/kernel/fork.c
66406@@ -321,7 +321,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66407 *stackend = STACK_END_MAGIC; /* for overflow detection */
66408
66409 #ifdef CONFIG_CC_STACKPROTECTOR
66410- tsk->stack_canary = get_random_int();
66411+ tsk->stack_canary = pax_get_random_long();
66412 #endif
66413
66414 /*
66415@@ -345,13 +345,78 @@ out:
66416 }
66417
66418 #ifdef CONFIG_MMU
66419+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
66420+{
66421+ struct vm_area_struct *tmp;
66422+ unsigned long charge;
66423+ struct mempolicy *pol;
66424+ struct file *file;
66425+
66426+ charge = 0;
66427+ if (mpnt->vm_flags & VM_ACCOUNT) {
66428+ unsigned long len;
66429+ len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66430+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66431+ goto fail_nomem;
66432+ charge = len;
66433+ }
66434+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66435+ if (!tmp)
66436+ goto fail_nomem;
66437+ *tmp = *mpnt;
66438+ tmp->vm_mm = mm;
66439+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
66440+ pol = mpol_dup(vma_policy(mpnt));
66441+ if (IS_ERR(pol))
66442+ goto fail_nomem_policy;
66443+ vma_set_policy(tmp, pol);
66444+ if (anon_vma_fork(tmp, mpnt))
66445+ goto fail_nomem_anon_vma_fork;
66446+ tmp->vm_flags &= ~VM_LOCKED;
66447+ tmp->vm_next = tmp->vm_prev = NULL;
66448+ tmp->vm_mirror = NULL;
66449+ file = tmp->vm_file;
66450+ if (file) {
66451+ struct inode *inode = file->f_path.dentry->d_inode;
66452+ struct address_space *mapping = file->f_mapping;
66453+
66454+ get_file(file);
66455+ if (tmp->vm_flags & VM_DENYWRITE)
66456+ atomic_dec(&inode->i_writecount);
66457+ mutex_lock(&mapping->i_mmap_mutex);
66458+ if (tmp->vm_flags & VM_SHARED)
66459+ mapping->i_mmap_writable++;
66460+ flush_dcache_mmap_lock(mapping);
66461+ /* insert tmp into the share list, just after mpnt */
66462+ vma_prio_tree_add(tmp, mpnt);
66463+ flush_dcache_mmap_unlock(mapping);
66464+ mutex_unlock(&mapping->i_mmap_mutex);
66465+ }
66466+
66467+ /*
66468+ * Clear hugetlb-related page reserves for children. This only
66469+ * affects MAP_PRIVATE mappings. Faults generated by the child
66470+ * are not guaranteed to succeed, even if read-only
66471+ */
66472+ if (is_vm_hugetlb_page(tmp))
66473+ reset_vma_resv_huge_pages(tmp);
66474+
66475+ return tmp;
66476+
66477+fail_nomem_anon_vma_fork:
66478+ mpol_put(pol);
66479+fail_nomem_policy:
66480+ kmem_cache_free(vm_area_cachep, tmp);
66481+fail_nomem:
66482+ vm_unacct_memory(charge);
66483+ return NULL;
66484+}
66485+
66486 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66487 {
66488 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66489 struct rb_node **rb_link, *rb_parent;
66490 int retval;
66491- unsigned long charge;
66492- struct mempolicy *pol;
66493
66494 down_write(&oldmm->mmap_sem);
66495 flush_cache_dup_mm(oldmm);
66496@@ -363,8 +428,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66497 mm->locked_vm = 0;
66498 mm->mmap = NULL;
66499 mm->mmap_cache = NULL;
66500- mm->free_area_cache = oldmm->mmap_base;
66501- mm->cached_hole_size = ~0UL;
66502+ mm->free_area_cache = oldmm->free_area_cache;
66503+ mm->cached_hole_size = oldmm->cached_hole_size;
66504 mm->map_count = 0;
66505 cpumask_clear(mm_cpumask(mm));
66506 mm->mm_rb = RB_ROOT;
66507@@ -380,8 +445,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66508
66509 prev = NULL;
66510 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66511- struct file *file;
66512-
66513 if (mpnt->vm_flags & VM_DONTCOPY) {
66514 long pages = vma_pages(mpnt);
66515 mm->total_vm -= pages;
66516@@ -389,54 +452,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66517 -pages);
66518 continue;
66519 }
66520- charge = 0;
66521- if (mpnt->vm_flags & VM_ACCOUNT) {
66522- unsigned long len;
66523- len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66524- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66525- goto fail_nomem;
66526- charge = len;
66527+ tmp = dup_vma(mm, oldmm, mpnt);
66528+ if (!tmp) {
66529+ retval = -ENOMEM;
66530+ goto out;
66531 }
66532- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66533- if (!tmp)
66534- goto fail_nomem;
66535- *tmp = *mpnt;
66536- INIT_LIST_HEAD(&tmp->anon_vma_chain);
66537- pol = mpol_dup(vma_policy(mpnt));
66538- retval = PTR_ERR(pol);
66539- if (IS_ERR(pol))
66540- goto fail_nomem_policy;
66541- vma_set_policy(tmp, pol);
66542- tmp->vm_mm = mm;
66543- if (anon_vma_fork(tmp, mpnt))
66544- goto fail_nomem_anon_vma_fork;
66545- tmp->vm_flags &= ~VM_LOCKED;
66546- tmp->vm_next = tmp->vm_prev = NULL;
66547- file = tmp->vm_file;
66548- if (file) {
66549- struct inode *inode = file->f_path.dentry->d_inode;
66550- struct address_space *mapping = file->f_mapping;
66551-
66552- get_file(file);
66553- if (tmp->vm_flags & VM_DENYWRITE)
66554- atomic_dec(&inode->i_writecount);
66555- mutex_lock(&mapping->i_mmap_mutex);
66556- if (tmp->vm_flags & VM_SHARED)
66557- mapping->i_mmap_writable++;
66558- flush_dcache_mmap_lock(mapping);
66559- /* insert tmp into the share list, just after mpnt */
66560- vma_prio_tree_add(tmp, mpnt);
66561- flush_dcache_mmap_unlock(mapping);
66562- mutex_unlock(&mapping->i_mmap_mutex);
66563- }
66564-
66565- /*
66566- * Clear hugetlb-related page reserves for children. This only
66567- * affects MAP_PRIVATE mappings. Faults generated by the child
66568- * are not guaranteed to succeed, even if read-only
66569- */
66570- if (is_vm_hugetlb_page(tmp))
66571- reset_vma_resv_huge_pages(tmp);
66572
66573 /*
66574 * Link in the new vma and copy the page table entries.
66575@@ -459,9 +479,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66576 if (retval)
66577 goto out;
66578
66579- if (file && uprobe_mmap(tmp))
66580+ if (tmp->vm_file && uprobe_mmap(tmp))
66581 goto out;
66582 }
66583+
66584+#ifdef CONFIG_PAX_SEGMEXEC
66585+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66586+ struct vm_area_struct *mpnt_m;
66587+
66588+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66589+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66590+
66591+ if (!mpnt->vm_mirror)
66592+ continue;
66593+
66594+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66595+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66596+ mpnt->vm_mirror = mpnt_m;
66597+ } else {
66598+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66599+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66600+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66601+ mpnt->vm_mirror->vm_mirror = mpnt;
66602+ }
66603+ }
66604+ BUG_ON(mpnt_m);
66605+ }
66606+#endif
66607+
66608 /* a new mm has just been created */
66609 arch_dup_mmap(oldmm, mm);
66610 retval = 0;
66611@@ -470,14 +515,6 @@ out:
66612 flush_tlb_mm(oldmm);
66613 up_write(&oldmm->mmap_sem);
66614 return retval;
66615-fail_nomem_anon_vma_fork:
66616- mpol_put(pol);
66617-fail_nomem_policy:
66618- kmem_cache_free(vm_area_cachep, tmp);
66619-fail_nomem:
66620- retval = -ENOMEM;
66621- vm_unacct_memory(charge);
66622- goto out;
66623 }
66624
66625 static inline int mm_alloc_pgd(struct mm_struct *mm)
66626@@ -714,8 +751,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66627 return ERR_PTR(err);
66628
66629 mm = get_task_mm(task);
66630- if (mm && mm != current->mm &&
66631- !ptrace_may_access(task, mode)) {
66632+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66633+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66634 mmput(mm);
66635 mm = ERR_PTR(-EACCES);
66636 }
66637@@ -936,13 +973,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66638 spin_unlock(&fs->lock);
66639 return -EAGAIN;
66640 }
66641- fs->users++;
66642+ atomic_inc(&fs->users);
66643 spin_unlock(&fs->lock);
66644 return 0;
66645 }
66646 tsk->fs = copy_fs_struct(fs);
66647 if (!tsk->fs)
66648 return -ENOMEM;
66649+ gr_set_chroot_entries(tsk, &tsk->fs->root);
66650 return 0;
66651 }
66652
66653@@ -1209,6 +1247,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66654 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66655 #endif
66656 retval = -EAGAIN;
66657+
66658+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66659+
66660 if (atomic_read(&p->real_cred->user->processes) >=
66661 task_rlimit(p, RLIMIT_NPROC)) {
66662 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66663@@ -1431,6 +1472,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66664 /* Need tasklist lock for parent etc handling! */
66665 write_lock_irq(&tasklist_lock);
66666
66667+ /* synchronizes with gr_set_acls() */
66668+ gr_copy_label(p);
66669+
66670 /* CLONE_PARENT re-uses the old parent */
66671 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
66672 p->real_parent = current->real_parent;
66673@@ -1541,6 +1585,8 @@ bad_fork_cleanup_count:
66674 bad_fork_free:
66675 free_task(p);
66676 fork_out:
66677+ gr_log_forkfail(retval);
66678+
66679 return ERR_PTR(retval);
66680 }
66681
66682@@ -1641,6 +1687,8 @@ long do_fork(unsigned long clone_flags,
66683 if (clone_flags & CLONE_PARENT_SETTID)
66684 put_user(nr, parent_tidptr);
66685
66686+ gr_handle_brute_check();
66687+
66688 if (clone_flags & CLONE_VFORK) {
66689 p->vfork_done = &vfork;
66690 init_completion(&vfork);
66691@@ -1739,7 +1787,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66692 return 0;
66693
66694 /* don't need lock here; in the worst case we'll do useless copy */
66695- if (fs->users == 1)
66696+ if (atomic_read(&fs->users) == 1)
66697 return 0;
66698
66699 *new_fsp = copy_fs_struct(fs);
66700@@ -1828,7 +1876,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66701 fs = current->fs;
66702 spin_lock(&fs->lock);
66703 current->fs = new_fs;
66704- if (--fs->users)
66705+ gr_set_chroot_entries(current, &current->fs->root);
66706+ if (atomic_dec_return(&fs->users))
66707 new_fs = NULL;
66708 else
66709 new_fs = fs;
66710diff --git a/kernel/futex.c b/kernel/futex.c
66711index e2b0fb9..ced552c 100644
66712--- a/kernel/futex.c
66713+++ b/kernel/futex.c
66714@@ -54,6 +54,7 @@
66715 #include <linux/mount.h>
66716 #include <linux/pagemap.h>
66717 #include <linux/syscalls.h>
66718+#include <linux/ptrace.h>
66719 #include <linux/signal.h>
66720 #include <linux/export.h>
66721 #include <linux/magic.h>
66722@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66723 struct page *page, *page_head;
66724 int err, ro = 0;
66725
66726+#ifdef CONFIG_PAX_SEGMEXEC
66727+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66728+ return -EFAULT;
66729+#endif
66730+
66731 /*
66732 * The futex address must be "naturally" aligned.
66733 */
66734@@ -2231,11 +2237,11 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb,
66735 * @uaddr2: the pi futex we will take prior to returning to user-space
66736 *
66737 * The caller will wait on uaddr and will be requeued by futex_requeue() to
66738- * uaddr2 which must be PI aware. Normal wakeup will wake on uaddr2 and
66739- * complete the acquisition of the rt_mutex prior to returning to userspace.
66740- * This ensures the rt_mutex maintains an owner when it has waiters; without
66741- * one, the pi logic wouldn't know which task to boost/deboost, if there was a
66742- * need to.
66743+ * uaddr2 which must be PI aware and unique from uaddr. Normal wakeup will wake
66744+ * on uaddr2 and complete the acquisition of the rt_mutex prior to returning to
66745+ * userspace. This ensures the rt_mutex maintains an owner when it has waiters;
66746+ * without one, the pi logic would not know which task to boost/deboost, if
66747+ * there was a need to.
66748 *
66749 * We call schedule in futex_wait_queue_me() when we enqueue and return there
66750 * via the following:
66751@@ -2272,6 +2278,9 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
66752 struct futex_q q = futex_q_init;
66753 int res, ret;
66754
66755+ if (uaddr == uaddr2)
66756+ return -EINVAL;
66757+
66758 if (!bitset)
66759 return -EINVAL;
66760
66761@@ -2370,7 +2379,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
66762 * fault, unlock the rt_mutex and return the fault to userspace.
66763 */
66764 if (ret == -EFAULT) {
66765- if (rt_mutex_owner(pi_mutex) == current)
66766+ if (pi_mutex && rt_mutex_owner(pi_mutex) == current)
66767 rt_mutex_unlock(pi_mutex);
66768 } else if (ret == -EINTR) {
66769 /*
66770@@ -2711,6 +2720,7 @@ static int __init futex_init(void)
66771 {
66772 u32 curval;
66773 int i;
66774+ mm_segment_t oldfs;
66775
66776 /*
66777 * This will fail and we want it. Some arch implementations do
66778@@ -2722,8 +2732,11 @@ static int __init futex_init(void)
66779 * implementation, the non-functional ones will return
66780 * -ENOSYS.
66781 */
66782+ oldfs = get_fs();
66783+ set_fs(USER_DS);
66784 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66785 futex_cmpxchg_enabled = 1;
66786+ set_fs(oldfs);
66787
66788 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66789 plist_head_init(&futex_queues[i].chain);
66790diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66791index 9b22d03..6295b62 100644
66792--- a/kernel/gcov/base.c
66793+++ b/kernel/gcov/base.c
66794@@ -102,11 +102,6 @@ void gcov_enable_events(void)
66795 }
66796
66797 #ifdef CONFIG_MODULES
66798-static inline int within(void *addr, void *start, unsigned long size)
66799-{
66800- return ((addr >= start) && (addr < start + size));
66801-}
66802-
66803 /* Update list and generate events when modules are unloaded. */
66804 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66805 void *data)
66806@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66807 prev = NULL;
66808 /* Remove entries located in module from linked list. */
66809 for (info = gcov_info_head; info; info = info->next) {
66810- if (within(info, mod->module_core, mod->core_size)) {
66811+ if (within_module_core_rw((unsigned long)info, mod)) {
66812 if (prev)
66813 prev->next = info->next;
66814 else
66815diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66816index 6db7a5e..25b6648 100644
66817--- a/kernel/hrtimer.c
66818+++ b/kernel/hrtimer.c
66819@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
66820 local_irq_restore(flags);
66821 }
66822
66823-static void run_hrtimer_softirq(struct softirq_action *h)
66824+static void run_hrtimer_softirq(void)
66825 {
66826 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
66827
66828diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66829index 4304919..408c4c0 100644
66830--- a/kernel/jump_label.c
66831+++ b/kernel/jump_label.c
66832@@ -13,6 +13,7 @@
66833 #include <linux/sort.h>
66834 #include <linux/err.h>
66835 #include <linux/static_key.h>
66836+#include <linux/mm.h>
66837
66838 #ifdef HAVE_JUMP_LABEL
66839
66840@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66841
66842 size = (((unsigned long)stop - (unsigned long)start)
66843 / sizeof(struct jump_entry));
66844+ pax_open_kernel();
66845 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66846+ pax_close_kernel();
66847 }
66848
66849 static void jump_label_update(struct static_key *key, int enable);
66850@@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66851 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66852 struct jump_entry *iter;
66853
66854+ pax_open_kernel();
66855 for (iter = iter_start; iter < iter_stop; iter++) {
66856 if (within_module_init(iter->code, mod))
66857 iter->code = 0;
66858 }
66859+ pax_close_kernel();
66860 }
66861
66862 static int
66863diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66864index 2169fee..45c017a 100644
66865--- a/kernel/kallsyms.c
66866+++ b/kernel/kallsyms.c
66867@@ -11,6 +11,9 @@
66868 * Changed the compression method from stem compression to "table lookup"
66869 * compression (see scripts/kallsyms.c for a more complete description)
66870 */
66871+#ifdef CONFIG_GRKERNSEC_HIDESYM
66872+#define __INCLUDED_BY_HIDESYM 1
66873+#endif
66874 #include <linux/kallsyms.h>
66875 #include <linux/module.h>
66876 #include <linux/init.h>
66877@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66878
66879 static inline int is_kernel_inittext(unsigned long addr)
66880 {
66881+ if (system_state != SYSTEM_BOOTING)
66882+ return 0;
66883+
66884 if (addr >= (unsigned long)_sinittext
66885 && addr <= (unsigned long)_einittext)
66886 return 1;
66887 return 0;
66888 }
66889
66890+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66891+#ifdef CONFIG_MODULES
66892+static inline int is_module_text(unsigned long addr)
66893+{
66894+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66895+ return 1;
66896+
66897+ addr = ktla_ktva(addr);
66898+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66899+}
66900+#else
66901+static inline int is_module_text(unsigned long addr)
66902+{
66903+ return 0;
66904+}
66905+#endif
66906+#endif
66907+
66908 static inline int is_kernel_text(unsigned long addr)
66909 {
66910 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66911@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66912
66913 static inline int is_kernel(unsigned long addr)
66914 {
66915+
66916+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66917+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
66918+ return 1;
66919+
66920+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66921+#else
66922 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66923+#endif
66924+
66925 return 1;
66926 return in_gate_area_no_mm(addr);
66927 }
66928
66929 static int is_ksym_addr(unsigned long addr)
66930 {
66931+
66932+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66933+ if (is_module_text(addr))
66934+ return 0;
66935+#endif
66936+
66937 if (all_var)
66938 return is_kernel(addr);
66939
66940@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66941
66942 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66943 {
66944- iter->name[0] = '\0';
66945 iter->nameoff = get_symbol_offset(new_pos);
66946 iter->pos = new_pos;
66947 }
66948@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
66949 {
66950 struct kallsym_iter *iter = m->private;
66951
66952+#ifdef CONFIG_GRKERNSEC_HIDESYM
66953+ if (current_uid())
66954+ return 0;
66955+#endif
66956+
66957 /* Some debugging symbols have no name. Ignore them. */
66958 if (!iter->name[0])
66959 return 0;
66960@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
66961 */
66962 type = iter->exported ? toupper(iter->type) :
66963 tolower(iter->type);
66964+
66965 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
66966 type, iter->name, iter->module_name);
66967 } else
66968@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66969 struct kallsym_iter *iter;
66970 int ret;
66971
66972- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66973+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
66974 if (!iter)
66975 return -ENOMEM;
66976 reset_iter(iter, 0);
66977diff --git a/kernel/kexec.c b/kernel/kexec.c
66978index 4e2e472..cd0c7ae 100644
66979--- a/kernel/kexec.c
66980+++ b/kernel/kexec.c
66981@@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
66982 unsigned long flags)
66983 {
66984 struct compat_kexec_segment in;
66985- struct kexec_segment out, __user *ksegments;
66986+ struct kexec_segment out;
66987+ struct kexec_segment __user *ksegments;
66988 unsigned long i, result;
66989
66990 /* Don't allow clients that don't understand the native
66991diff --git a/kernel/kmod.c b/kernel/kmod.c
66992index ff2c7cb..085d7af 100644
66993--- a/kernel/kmod.c
66994+++ b/kernel/kmod.c
66995@@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
66996 kfree(info->argv);
66997 }
66998
66999-static int call_modprobe(char *module_name, int wait)
67000+static int call_modprobe(char *module_name, char *module_param, int wait)
67001 {
67002 static char *envp[] = {
67003 "HOME=/",
67004@@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
67005 NULL
67006 };
67007
67008- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67009+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67010 if (!argv)
67011 goto out;
67012
67013@@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
67014 argv[1] = "-q";
67015 argv[2] = "--";
67016 argv[3] = module_name; /* check free_modprobe_argv() */
67017- argv[4] = NULL;
67018+ argv[4] = module_param;
67019+ argv[5] = NULL;
67020
67021 return call_usermodehelper_fns(modprobe_path, argv, envp,
67022 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67023@@ -112,9 +113,8 @@ out:
67024 * If module auto-loading support is disabled then this function
67025 * becomes a no-operation.
67026 */
67027-int __request_module(bool wait, const char *fmt, ...)
67028+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67029 {
67030- va_list args;
67031 char module_name[MODULE_NAME_LEN];
67032 unsigned int max_modprobes;
67033 int ret;
67034@@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
67035 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67036 static int kmod_loop_msg;
67037
67038- va_start(args, fmt);
67039- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67040- va_end(args);
67041+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67042 if (ret >= MODULE_NAME_LEN)
67043 return -ENAMETOOLONG;
67044
67045@@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
67046 if (ret)
67047 return ret;
67048
67049+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67050+ if (!current_uid()) {
67051+ /* hack to workaround consolekit/udisks stupidity */
67052+ read_lock(&tasklist_lock);
67053+ if (!strcmp(current->comm, "mount") &&
67054+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67055+ read_unlock(&tasklist_lock);
67056+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67057+ return -EPERM;
67058+ }
67059+ read_unlock(&tasklist_lock);
67060+ }
67061+#endif
67062+
67063 /* If modprobe needs a service that is in a module, we get a recursive
67064 * loop. Limit the number of running kmod threads to max_threads/2 or
67065 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67066@@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
67067
67068 trace_module_request(module_name, wait, _RET_IP_);
67069
67070- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67071+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67072
67073 atomic_dec(&kmod_concurrent);
67074 return ret;
67075 }
67076+
67077+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67078+{
67079+ va_list args;
67080+ int ret;
67081+
67082+ va_start(args, fmt);
67083+ ret = ____request_module(wait, module_param, fmt, args);
67084+ va_end(args);
67085+
67086+ return ret;
67087+}
67088+
67089+int __request_module(bool wait, const char *fmt, ...)
67090+{
67091+ va_list args;
67092+ int ret;
67093+
67094+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67095+ if (current_uid()) {
67096+ char module_param[MODULE_NAME_LEN];
67097+
67098+ memset(module_param, 0, sizeof(module_param));
67099+
67100+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67101+
67102+ va_start(args, fmt);
67103+ ret = ____request_module(wait, module_param, fmt, args);
67104+ va_end(args);
67105+
67106+ return ret;
67107+ }
67108+#endif
67109+
67110+ va_start(args, fmt);
67111+ ret = ____request_module(wait, NULL, fmt, args);
67112+ va_end(args);
67113+
67114+ return ret;
67115+}
67116+
67117 EXPORT_SYMBOL(__request_module);
67118 #endif /* CONFIG_MODULES */
67119
67120@@ -266,7 +319,7 @@ static int wait_for_helper(void *data)
67121 *
67122 * Thus the __user pointer cast is valid here.
67123 */
67124- sys_wait4(pid, (int __user *)&ret, 0, NULL);
67125+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67126
67127 /*
67128 * If ret is 0, either ____call_usermodehelper failed and the
67129diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67130index c62b854..cb67968 100644
67131--- a/kernel/kprobes.c
67132+++ b/kernel/kprobes.c
67133@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67134 * kernel image and loaded module images reside. This is required
67135 * so x86_64 can correctly handle the %rip-relative fixups.
67136 */
67137- kip->insns = module_alloc(PAGE_SIZE);
67138+ kip->insns = module_alloc_exec(PAGE_SIZE);
67139 if (!kip->insns) {
67140 kfree(kip);
67141 return NULL;
67142@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67143 */
67144 if (!list_is_singular(&kip->list)) {
67145 list_del(&kip->list);
67146- module_free(NULL, kip->insns);
67147+ module_free_exec(NULL, kip->insns);
67148 kfree(kip);
67149 }
67150 return 1;
67151@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67152 {
67153 int i, err = 0;
67154 unsigned long offset = 0, size = 0;
67155- char *modname, namebuf[128];
67156+ char *modname, namebuf[KSYM_NAME_LEN];
67157 const char *symbol_name;
67158 void *addr;
67159 struct kprobe_blackpoint *kb;
67160@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67161 const char *sym = NULL;
67162 unsigned int i = *(loff_t *) v;
67163 unsigned long offset = 0;
67164- char *modname, namebuf[128];
67165+ char *modname, namebuf[KSYM_NAME_LEN];
67166
67167 head = &kprobe_table[i];
67168 preempt_disable();
67169diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67170index 4e316e1..5501eef 100644
67171--- a/kernel/ksysfs.c
67172+++ b/kernel/ksysfs.c
67173@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67174 {
67175 if (count+1 > UEVENT_HELPER_PATH_LEN)
67176 return -ENOENT;
67177+ if (!capable(CAP_SYS_ADMIN))
67178+ return -EPERM;
67179 memcpy(uevent_helper, buf, count);
67180 uevent_helper[count] = '\0';
67181 if (count && uevent_helper[count-1] == '\n')
67182diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67183index ea9ee45..67ebc8f 100644
67184--- a/kernel/lockdep.c
67185+++ b/kernel/lockdep.c
67186@@ -590,6 +590,10 @@ static int static_obj(void *obj)
67187 end = (unsigned long) &_end,
67188 addr = (unsigned long) obj;
67189
67190+#ifdef CONFIG_PAX_KERNEXEC
67191+ start = ktla_ktva(start);
67192+#endif
67193+
67194 /*
67195 * static variable?
67196 */
67197@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67198 if (!static_obj(lock->key)) {
67199 debug_locks_off();
67200 printk("INFO: trying to register non-static key.\n");
67201+ printk("lock:%pS key:%pS.\n", lock, lock->key);
67202 printk("the code is fine but needs lockdep annotation.\n");
67203 printk("turning off the locking correctness validator.\n");
67204 dump_stack();
67205@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67206 if (!class)
67207 return 0;
67208 }
67209- atomic_inc((atomic_t *)&class->ops);
67210+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67211 if (very_verbose(class)) {
67212 printk("\nacquire class [%p] %s", class->key, class->name);
67213 if (class->name_version > 1)
67214diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67215index 91c32a0..b2c71c5 100644
67216--- a/kernel/lockdep_proc.c
67217+++ b/kernel/lockdep_proc.c
67218@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67219
67220 static void print_name(struct seq_file *m, struct lock_class *class)
67221 {
67222- char str[128];
67223+ char str[KSYM_NAME_LEN];
67224 const char *name = class->name;
67225
67226 if (!name) {
67227diff --git a/kernel/module.c b/kernel/module.c
67228index 4edbd9c..165e780 100644
67229--- a/kernel/module.c
67230+++ b/kernel/module.c
67231@@ -58,6 +58,7 @@
67232 #include <linux/jump_label.h>
67233 #include <linux/pfn.h>
67234 #include <linux/bsearch.h>
67235+#include <linux/grsecurity.h>
67236
67237 #define CREATE_TRACE_POINTS
67238 #include <trace/events/module.h>
67239@@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67240
67241 /* Bounds of module allocation, for speeding __module_address.
67242 * Protected by module_mutex. */
67243-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67244+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67245+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67246
67247 int register_module_notifier(struct notifier_block * nb)
67248 {
67249@@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67250 return true;
67251
67252 list_for_each_entry_rcu(mod, &modules, list) {
67253- struct symsearch arr[] = {
67254+ struct symsearch modarr[] = {
67255 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67256 NOT_GPL_ONLY, false },
67257 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67258@@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67259 #endif
67260 };
67261
67262- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67263+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67264 return true;
67265 }
67266 return false;
67267@@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
67268 static int percpu_modalloc(struct module *mod,
67269 unsigned long size, unsigned long align)
67270 {
67271- if (align > PAGE_SIZE) {
67272+ if (align-1 >= PAGE_SIZE) {
67273 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67274 mod->name, align, PAGE_SIZE);
67275 align = PAGE_SIZE;
67276@@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
67277 static ssize_t show_coresize(struct module_attribute *mattr,
67278 struct module_kobject *mk, char *buffer)
67279 {
67280- return sprintf(buffer, "%u\n", mk->mod->core_size);
67281+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
67282 }
67283
67284 static struct module_attribute modinfo_coresize =
67285@@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
67286 static ssize_t show_initsize(struct module_attribute *mattr,
67287 struct module_kobject *mk, char *buffer)
67288 {
67289- return sprintf(buffer, "%u\n", mk->mod->init_size);
67290+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
67291 }
67292
67293 static struct module_attribute modinfo_initsize =
67294@@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
67295 */
67296 #ifdef CONFIG_SYSFS
67297
67298-#ifdef CONFIG_KALLSYMS
67299+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67300 static inline bool sect_empty(const Elf_Shdr *sect)
67301 {
67302 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
67303@@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
67304
67305 static void unset_module_core_ro_nx(struct module *mod)
67306 {
67307- set_page_attributes(mod->module_core + mod->core_text_size,
67308- mod->module_core + mod->core_size,
67309+ set_page_attributes(mod->module_core_rw,
67310+ mod->module_core_rw + mod->core_size_rw,
67311 set_memory_x);
67312- set_page_attributes(mod->module_core,
67313- mod->module_core + mod->core_ro_size,
67314+ set_page_attributes(mod->module_core_rx,
67315+ mod->module_core_rx + mod->core_size_rx,
67316 set_memory_rw);
67317 }
67318
67319 static void unset_module_init_ro_nx(struct module *mod)
67320 {
67321- set_page_attributes(mod->module_init + mod->init_text_size,
67322- mod->module_init + mod->init_size,
67323+ set_page_attributes(mod->module_init_rw,
67324+ mod->module_init_rw + mod->init_size_rw,
67325 set_memory_x);
67326- set_page_attributes(mod->module_init,
67327- mod->module_init + mod->init_ro_size,
67328+ set_page_attributes(mod->module_init_rx,
67329+ mod->module_init_rx + mod->init_size_rx,
67330 set_memory_rw);
67331 }
67332
67333@@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
67334
67335 mutex_lock(&module_mutex);
67336 list_for_each_entry_rcu(mod, &modules, list) {
67337- if ((mod->module_core) && (mod->core_text_size)) {
67338- set_page_attributes(mod->module_core,
67339- mod->module_core + mod->core_text_size,
67340+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
67341+ set_page_attributes(mod->module_core_rx,
67342+ mod->module_core_rx + mod->core_size_rx,
67343 set_memory_rw);
67344 }
67345- if ((mod->module_init) && (mod->init_text_size)) {
67346- set_page_attributes(mod->module_init,
67347- mod->module_init + mod->init_text_size,
67348+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
67349+ set_page_attributes(mod->module_init_rx,
67350+ mod->module_init_rx + mod->init_size_rx,
67351 set_memory_rw);
67352 }
67353 }
67354@@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
67355
67356 mutex_lock(&module_mutex);
67357 list_for_each_entry_rcu(mod, &modules, list) {
67358- if ((mod->module_core) && (mod->core_text_size)) {
67359- set_page_attributes(mod->module_core,
67360- mod->module_core + mod->core_text_size,
67361+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
67362+ set_page_attributes(mod->module_core_rx,
67363+ mod->module_core_rx + mod->core_size_rx,
67364 set_memory_ro);
67365 }
67366- if ((mod->module_init) && (mod->init_text_size)) {
67367- set_page_attributes(mod->module_init,
67368- mod->module_init + mod->init_text_size,
67369+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
67370+ set_page_attributes(mod->module_init_rx,
67371+ mod->module_init_rx + mod->init_size_rx,
67372 set_memory_ro);
67373 }
67374 }
67375@@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
67376
67377 /* This may be NULL, but that's OK */
67378 unset_module_init_ro_nx(mod);
67379- module_free(mod, mod->module_init);
67380+ module_free(mod, mod->module_init_rw);
67381+ module_free_exec(mod, mod->module_init_rx);
67382 kfree(mod->args);
67383 percpu_modfree(mod);
67384
67385 /* Free lock-classes: */
67386- lockdep_free_key_range(mod->module_core, mod->core_size);
67387+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
67388+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
67389
67390 /* Finally, free the core (containing the module structure) */
67391 unset_module_core_ro_nx(mod);
67392- module_free(mod, mod->module_core);
67393+ module_free_exec(mod, mod->module_core_rx);
67394+ module_free(mod, mod->module_core_rw);
67395
67396 #ifdef CONFIG_MPU
67397 update_protections(current->mm);
67398@@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67399 int ret = 0;
67400 const struct kernel_symbol *ksym;
67401
67402+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67403+ int is_fs_load = 0;
67404+ int register_filesystem_found = 0;
67405+ char *p;
67406+
67407+ p = strstr(mod->args, "grsec_modharden_fs");
67408+ if (p) {
67409+ char *endptr = p + strlen("grsec_modharden_fs");
67410+ /* copy \0 as well */
67411+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67412+ is_fs_load = 1;
67413+ }
67414+#endif
67415+
67416 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67417 const char *name = info->strtab + sym[i].st_name;
67418
67419+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67420+ /* it's a real shame this will never get ripped and copied
67421+ upstream! ;(
67422+ */
67423+ if (is_fs_load && !strcmp(name, "register_filesystem"))
67424+ register_filesystem_found = 1;
67425+#endif
67426+
67427 switch (sym[i].st_shndx) {
67428 case SHN_COMMON:
67429 /* We compiled with -fno-common. These are not
67430@@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67431 ksym = resolve_symbol_wait(mod, info, name);
67432 /* Ok if resolved. */
67433 if (ksym && !IS_ERR(ksym)) {
67434+ pax_open_kernel();
67435 sym[i].st_value = ksym->value;
67436+ pax_close_kernel();
67437 break;
67438 }
67439
67440@@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67441 secbase = (unsigned long)mod_percpu(mod);
67442 else
67443 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67444+ pax_open_kernel();
67445 sym[i].st_value += secbase;
67446+ pax_close_kernel();
67447 break;
67448 }
67449 }
67450
67451+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67452+ if (is_fs_load && !register_filesystem_found) {
67453+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67454+ ret = -EPERM;
67455+ }
67456+#endif
67457+
67458 return ret;
67459 }
67460
67461@@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67462 || s->sh_entsize != ~0UL
67463 || strstarts(sname, ".init"))
67464 continue;
67465- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67466+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67467+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67468+ else
67469+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67470 pr_debug("\t%s\n", sname);
67471 }
67472- switch (m) {
67473- case 0: /* executable */
67474- mod->core_size = debug_align(mod->core_size);
67475- mod->core_text_size = mod->core_size;
67476- break;
67477- case 1: /* RO: text and ro-data */
67478- mod->core_size = debug_align(mod->core_size);
67479- mod->core_ro_size = mod->core_size;
67480- break;
67481- case 3: /* whole core */
67482- mod->core_size = debug_align(mod->core_size);
67483- break;
67484- }
67485 }
67486
67487 pr_debug("Init section allocation order:\n");
67488@@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67489 || s->sh_entsize != ~0UL
67490 || !strstarts(sname, ".init"))
67491 continue;
67492- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67493- | INIT_OFFSET_MASK);
67494+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67495+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67496+ else
67497+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67498+ s->sh_entsize |= INIT_OFFSET_MASK;
67499 pr_debug("\t%s\n", sname);
67500 }
67501- switch (m) {
67502- case 0: /* executable */
67503- mod->init_size = debug_align(mod->init_size);
67504- mod->init_text_size = mod->init_size;
67505- break;
67506- case 1: /* RO: text and ro-data */
67507- mod->init_size = debug_align(mod->init_size);
67508- mod->init_ro_size = mod->init_size;
67509- break;
67510- case 3: /* whole init */
67511- mod->init_size = debug_align(mod->init_size);
67512- break;
67513- }
67514 }
67515 }
67516
67517@@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67518
67519 /* Put symbol section at end of init part of module. */
67520 symsect->sh_flags |= SHF_ALLOC;
67521- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67522+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67523 info->index.sym) | INIT_OFFSET_MASK;
67524 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67525
67526@@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67527 }
67528
67529 /* Append room for core symbols at end of core part. */
67530- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67531- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67532- mod->core_size += strtab_size;
67533+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67534+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67535+ mod->core_size_rx += strtab_size;
67536
67537 /* Put string table section at end of init part of module. */
67538 strsect->sh_flags |= SHF_ALLOC;
67539- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67540+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67541 info->index.str) | INIT_OFFSET_MASK;
67542 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67543 }
67544@@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67545 /* Make sure we get permanent strtab: don't use info->strtab. */
67546 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67547
67548+ pax_open_kernel();
67549+
67550 /* Set types up while we still have access to sections. */
67551 for (i = 0; i < mod->num_symtab; i++)
67552 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67553
67554- mod->core_symtab = dst = mod->module_core + info->symoffs;
67555- mod->core_strtab = s = mod->module_core + info->stroffs;
67556+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67557+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67558 src = mod->symtab;
67559 *dst = *src;
67560 *s++ = 0;
67561@@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67562 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67563 }
67564 mod->core_num_syms = ndst;
67565+
67566+ pax_close_kernel();
67567 }
67568 #else
67569 static inline void layout_symtab(struct module *mod, struct load_info *info)
67570@@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
67571 return size == 0 ? NULL : vmalloc_exec(size);
67572 }
67573
67574-static void *module_alloc_update_bounds(unsigned long size)
67575+static void *module_alloc_update_bounds_rw(unsigned long size)
67576 {
67577 void *ret = module_alloc(size);
67578
67579 if (ret) {
67580 mutex_lock(&module_mutex);
67581 /* Update module bounds. */
67582- if ((unsigned long)ret < module_addr_min)
67583- module_addr_min = (unsigned long)ret;
67584- if ((unsigned long)ret + size > module_addr_max)
67585- module_addr_max = (unsigned long)ret + size;
67586+ if ((unsigned long)ret < module_addr_min_rw)
67587+ module_addr_min_rw = (unsigned long)ret;
67588+ if ((unsigned long)ret + size > module_addr_max_rw)
67589+ module_addr_max_rw = (unsigned long)ret + size;
67590+ mutex_unlock(&module_mutex);
67591+ }
67592+ return ret;
67593+}
67594+
67595+static void *module_alloc_update_bounds_rx(unsigned long size)
67596+{
67597+ void *ret = module_alloc_exec(size);
67598+
67599+ if (ret) {
67600+ mutex_lock(&module_mutex);
67601+ /* Update module bounds. */
67602+ if ((unsigned long)ret < module_addr_min_rx)
67603+ module_addr_min_rx = (unsigned long)ret;
67604+ if ((unsigned long)ret + size > module_addr_max_rx)
67605+ module_addr_max_rx = (unsigned long)ret + size;
67606 mutex_unlock(&module_mutex);
67607 }
67608 return ret;
67609@@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
67610 static int check_modinfo(struct module *mod, struct load_info *info)
67611 {
67612 const char *modmagic = get_modinfo(info, "vermagic");
67613+ const char *license = get_modinfo(info, "license");
67614 int err;
67615
67616+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67617+ if (!license || !license_is_gpl_compatible(license))
67618+ return -ENOEXEC;
67619+#endif
67620+
67621 /* This is allowed: modprobe --force will invalidate it. */
67622 if (!modmagic) {
67623 err = try_to_force_load(mod, "bad vermagic");
67624@@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67625 }
67626
67627 /* Set up license info based on the info section */
67628- set_license(mod, get_modinfo(info, "license"));
67629+ set_license(mod, license);
67630
67631 return 0;
67632 }
67633@@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
67634 void *ptr;
67635
67636 /* Do the allocs. */
67637- ptr = module_alloc_update_bounds(mod->core_size);
67638+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67639 /*
67640 * The pointer to this block is stored in the module structure
67641 * which is inside the block. Just mark it as not being a
67642@@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
67643 if (!ptr)
67644 return -ENOMEM;
67645
67646- memset(ptr, 0, mod->core_size);
67647- mod->module_core = ptr;
67648+ memset(ptr, 0, mod->core_size_rw);
67649+ mod->module_core_rw = ptr;
67650
67651- ptr = module_alloc_update_bounds(mod->init_size);
67652+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67653 /*
67654 * The pointer to this block is stored in the module structure
67655 * which is inside the block. This block doesn't need to be
67656 * scanned as it contains data and code that will be freed
67657 * after the module is initialized.
67658 */
67659- kmemleak_ignore(ptr);
67660- if (!ptr && mod->init_size) {
67661- module_free(mod, mod->module_core);
67662+ kmemleak_not_leak(ptr);
67663+ if (!ptr && mod->init_size_rw) {
67664+ module_free(mod, mod->module_core_rw);
67665 return -ENOMEM;
67666 }
67667- memset(ptr, 0, mod->init_size);
67668- mod->module_init = ptr;
67669+ memset(ptr, 0, mod->init_size_rw);
67670+ mod->module_init_rw = ptr;
67671+
67672+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67673+ kmemleak_not_leak(ptr);
67674+ if (!ptr) {
67675+ module_free(mod, mod->module_init_rw);
67676+ module_free(mod, mod->module_core_rw);
67677+ return -ENOMEM;
67678+ }
67679+
67680+ pax_open_kernel();
67681+ memset(ptr, 0, mod->core_size_rx);
67682+ pax_close_kernel();
67683+ mod->module_core_rx = ptr;
67684+
67685+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67686+ kmemleak_not_leak(ptr);
67687+ if (!ptr && mod->init_size_rx) {
67688+ module_free_exec(mod, mod->module_core_rx);
67689+ module_free(mod, mod->module_init_rw);
67690+ module_free(mod, mod->module_core_rw);
67691+ return -ENOMEM;
67692+ }
67693+
67694+ pax_open_kernel();
67695+ memset(ptr, 0, mod->init_size_rx);
67696+ pax_close_kernel();
67697+ mod->module_init_rx = ptr;
67698
67699 /* Transfer each section which specifies SHF_ALLOC */
67700 pr_debug("final section addresses:\n");
67701@@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
67702 if (!(shdr->sh_flags & SHF_ALLOC))
67703 continue;
67704
67705- if (shdr->sh_entsize & INIT_OFFSET_MASK)
67706- dest = mod->module_init
67707- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67708- else
67709- dest = mod->module_core + shdr->sh_entsize;
67710+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67711+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67712+ dest = mod->module_init_rw
67713+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67714+ else
67715+ dest = mod->module_init_rx
67716+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67717+ } else {
67718+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67719+ dest = mod->module_core_rw + shdr->sh_entsize;
67720+ else
67721+ dest = mod->module_core_rx + shdr->sh_entsize;
67722+ }
67723+
67724+ if (shdr->sh_type != SHT_NOBITS) {
67725+
67726+#ifdef CONFIG_PAX_KERNEXEC
67727+#ifdef CONFIG_X86_64
67728+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67729+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67730+#endif
67731+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67732+ pax_open_kernel();
67733+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67734+ pax_close_kernel();
67735+ } else
67736+#endif
67737
67738- if (shdr->sh_type != SHT_NOBITS)
67739 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67740+ }
67741 /* Update sh_addr to point to copy in image. */
67742- shdr->sh_addr = (unsigned long)dest;
67743+
67744+#ifdef CONFIG_PAX_KERNEXEC
67745+ if (shdr->sh_flags & SHF_EXECINSTR)
67746+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
67747+ else
67748+#endif
67749+
67750+ shdr->sh_addr = (unsigned long)dest;
67751 pr_debug("\t0x%lx %s\n",
67752 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67753 }
67754@@ -2759,12 +2859,12 @@ static void flush_module_icache(const struct module *mod)
67755 * Do it before processing of module parameters, so the module
67756 * can provide parameter accessor functions of its own.
67757 */
67758- if (mod->module_init)
67759- flush_icache_range((unsigned long)mod->module_init,
67760- (unsigned long)mod->module_init
67761- + mod->init_size);
67762- flush_icache_range((unsigned long)mod->module_core,
67763- (unsigned long)mod->module_core + mod->core_size);
67764+ if (mod->module_init_rx)
67765+ flush_icache_range((unsigned long)mod->module_init_rx,
67766+ (unsigned long)mod->module_init_rx
67767+ + mod->init_size_rx);
67768+ flush_icache_range((unsigned long)mod->module_core_rx,
67769+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
67770
67771 set_fs(old_fs);
67772 }
67773@@ -2834,8 +2934,10 @@ out:
67774 static void module_deallocate(struct module *mod, struct load_info *info)
67775 {
67776 percpu_modfree(mod);
67777- module_free(mod, mod->module_init);
67778- module_free(mod, mod->module_core);
67779+ module_free_exec(mod, mod->module_init_rx);
67780+ module_free_exec(mod, mod->module_core_rx);
67781+ module_free(mod, mod->module_init_rw);
67782+ module_free(mod, mod->module_core_rw);
67783 }
67784
67785 int __weak module_finalize(const Elf_Ehdr *hdr,
67786@@ -2848,7 +2950,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
67787 static int post_relocation(struct module *mod, const struct load_info *info)
67788 {
67789 /* Sort exception table now relocations are done. */
67790+ pax_open_kernel();
67791 sort_extable(mod->extable, mod->extable + mod->num_exentries);
67792+ pax_close_kernel();
67793
67794 /* Copy relocated percpu area over. */
67795 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
67796@@ -2899,9 +3003,38 @@ static struct module *load_module(void __user *umod,
67797 if (err)
67798 goto free_unload;
67799
67800+ /* Now copy in args */
67801+ mod->args = strndup_user(uargs, ~0UL >> 1);
67802+ if (IS_ERR(mod->args)) {
67803+ err = PTR_ERR(mod->args);
67804+ goto free_unload;
67805+ }
67806+
67807 /* Set up MODINFO_ATTR fields */
67808 setup_modinfo(mod, &info);
67809
67810+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67811+ {
67812+ char *p, *p2;
67813+
67814+ if (strstr(mod->args, "grsec_modharden_netdev")) {
67815+ 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);
67816+ err = -EPERM;
67817+ goto free_modinfo;
67818+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67819+ p += strlen("grsec_modharden_normal");
67820+ p2 = strstr(p, "_");
67821+ if (p2) {
67822+ *p2 = '\0';
67823+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67824+ *p2 = '_';
67825+ }
67826+ err = -EPERM;
67827+ goto free_modinfo;
67828+ }
67829+ }
67830+#endif
67831+
67832 /* Fix up syms, so that st_value is a pointer to location. */
67833 err = simplify_symbols(mod, &info);
67834 if (err < 0)
67835@@ -2917,13 +3050,6 @@ static struct module *load_module(void __user *umod,
67836
67837 flush_module_icache(mod);
67838
67839- /* Now copy in args */
67840- mod->args = strndup_user(uargs, ~0UL >> 1);
67841- if (IS_ERR(mod->args)) {
67842- err = PTR_ERR(mod->args);
67843- goto free_arch_cleanup;
67844- }
67845-
67846 /* Mark state as coming so strong_try_module_get() ignores us. */
67847 mod->state = MODULE_STATE_COMING;
67848
67849@@ -2981,11 +3107,10 @@ static struct module *load_module(void __user *umod,
67850 unlock:
67851 mutex_unlock(&module_mutex);
67852 synchronize_sched();
67853- kfree(mod->args);
67854- free_arch_cleanup:
67855 module_arch_cleanup(mod);
67856 free_modinfo:
67857 free_modinfo(mod);
67858+ kfree(mod->args);
67859 free_unload:
67860 module_unload_free(mod);
67861 free_module:
67862@@ -3026,16 +3151,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67863 MODULE_STATE_COMING, mod);
67864
67865 /* Set RO and NX regions for core */
67866- set_section_ro_nx(mod->module_core,
67867- mod->core_text_size,
67868- mod->core_ro_size,
67869- mod->core_size);
67870+ set_section_ro_nx(mod->module_core_rx,
67871+ mod->core_size_rx,
67872+ mod->core_size_rx,
67873+ mod->core_size_rx);
67874
67875 /* Set RO and NX regions for init */
67876- set_section_ro_nx(mod->module_init,
67877- mod->init_text_size,
67878- mod->init_ro_size,
67879- mod->init_size);
67880+ set_section_ro_nx(mod->module_init_rx,
67881+ mod->init_size_rx,
67882+ mod->init_size_rx,
67883+ mod->init_size_rx);
67884
67885 do_mod_ctors(mod);
67886 /* Start the module */
67887@@ -3081,11 +3206,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67888 mod->strtab = mod->core_strtab;
67889 #endif
67890 unset_module_init_ro_nx(mod);
67891- module_free(mod, mod->module_init);
67892- mod->module_init = NULL;
67893- mod->init_size = 0;
67894- mod->init_ro_size = 0;
67895- mod->init_text_size = 0;
67896+ module_free(mod, mod->module_init_rw);
67897+ module_free_exec(mod, mod->module_init_rx);
67898+ mod->module_init_rw = NULL;
67899+ mod->module_init_rx = NULL;
67900+ mod->init_size_rw = 0;
67901+ mod->init_size_rx = 0;
67902 mutex_unlock(&module_mutex);
67903
67904 return 0;
67905@@ -3116,10 +3242,16 @@ static const char *get_ksymbol(struct module *mod,
67906 unsigned long nextval;
67907
67908 /* At worse, next value is at end of module */
67909- if (within_module_init(addr, mod))
67910- nextval = (unsigned long)mod->module_init+mod->init_text_size;
67911+ if (within_module_init_rx(addr, mod))
67912+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67913+ else if (within_module_init_rw(addr, mod))
67914+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67915+ else if (within_module_core_rx(addr, mod))
67916+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67917+ else if (within_module_core_rw(addr, mod))
67918+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67919 else
67920- nextval = (unsigned long)mod->module_core+mod->core_text_size;
67921+ return NULL;
67922
67923 /* Scan for closest preceding symbol, and next symbol. (ELF
67924 starts real symbols at 1). */
67925@@ -3354,7 +3486,7 @@ static int m_show(struct seq_file *m, void *p)
67926 char buf[8];
67927
67928 seq_printf(m, "%s %u",
67929- mod->name, mod->init_size + mod->core_size);
67930+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67931 print_unload_info(m, mod);
67932
67933 /* Informative for users. */
67934@@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
67935 mod->state == MODULE_STATE_COMING ? "Loading":
67936 "Live");
67937 /* Used by oprofile and other similar tools. */
67938- seq_printf(m, " 0x%pK", mod->module_core);
67939+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67940
67941 /* Taints info */
67942 if (mod->taints)
67943@@ -3399,7 +3531,17 @@ static const struct file_operations proc_modules_operations = {
67944
67945 static int __init proc_modules_init(void)
67946 {
67947+#ifndef CONFIG_GRKERNSEC_HIDESYM
67948+#ifdef CONFIG_GRKERNSEC_PROC_USER
67949+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67950+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67951+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67952+#else
67953 proc_create("modules", 0, NULL, &proc_modules_operations);
67954+#endif
67955+#else
67956+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67957+#endif
67958 return 0;
67959 }
67960 module_init(proc_modules_init);
67961@@ -3458,12 +3600,12 @@ struct module *__module_address(unsigned long addr)
67962 {
67963 struct module *mod;
67964
67965- if (addr < module_addr_min || addr > module_addr_max)
67966+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67967+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
67968 return NULL;
67969
67970 list_for_each_entry_rcu(mod, &modules, list)
67971- if (within_module_core(addr, mod)
67972- || within_module_init(addr, mod))
67973+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
67974 return mod;
67975 return NULL;
67976 }
67977@@ -3497,11 +3639,20 @@ bool is_module_text_address(unsigned long addr)
67978 */
67979 struct module *__module_text_address(unsigned long addr)
67980 {
67981- struct module *mod = __module_address(addr);
67982+ struct module *mod;
67983+
67984+#ifdef CONFIG_X86_32
67985+ addr = ktla_ktva(addr);
67986+#endif
67987+
67988+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67989+ return NULL;
67990+
67991+ mod = __module_address(addr);
67992+
67993 if (mod) {
67994 /* Make sure it's within the text section. */
67995- if (!within(addr, mod->module_init, mod->init_text_size)
67996- && !within(addr, mod->module_core, mod->core_text_size))
67997+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
67998 mod = NULL;
67999 }
68000 return mod;
68001diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68002index 7e3443f..b2a1e6b 100644
68003--- a/kernel/mutex-debug.c
68004+++ b/kernel/mutex-debug.c
68005@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68006 }
68007
68008 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68009- struct thread_info *ti)
68010+ struct task_struct *task)
68011 {
68012 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68013
68014 /* Mark the current thread as blocked on the lock: */
68015- ti->task->blocked_on = waiter;
68016+ task->blocked_on = waiter;
68017 }
68018
68019 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68020- struct thread_info *ti)
68021+ struct task_struct *task)
68022 {
68023 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68024- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68025- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68026- ti->task->blocked_on = NULL;
68027+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
68028+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68029+ task->blocked_on = NULL;
68030
68031 list_del_init(&waiter->list);
68032 waiter->task = NULL;
68033diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68034index 0799fd3..d06ae3b 100644
68035--- a/kernel/mutex-debug.h
68036+++ b/kernel/mutex-debug.h
68037@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68038 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68039 extern void debug_mutex_add_waiter(struct mutex *lock,
68040 struct mutex_waiter *waiter,
68041- struct thread_info *ti);
68042+ struct task_struct *task);
68043 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68044- struct thread_info *ti);
68045+ struct task_struct *task);
68046 extern void debug_mutex_unlock(struct mutex *lock);
68047 extern void debug_mutex_init(struct mutex *lock, const char *name,
68048 struct lock_class_key *key);
68049diff --git a/kernel/mutex.c b/kernel/mutex.c
68050index a307cc9..27fd2e9 100644
68051--- a/kernel/mutex.c
68052+++ b/kernel/mutex.c
68053@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68054 spin_lock_mutex(&lock->wait_lock, flags);
68055
68056 debug_mutex_lock_common(lock, &waiter);
68057- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68058+ debug_mutex_add_waiter(lock, &waiter, task);
68059
68060 /* add waiting tasks to the end of the waitqueue (FIFO): */
68061 list_add_tail(&waiter.list, &lock->wait_list);
68062@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68063 * TASK_UNINTERRUPTIBLE case.)
68064 */
68065 if (unlikely(signal_pending_state(state, task))) {
68066- mutex_remove_waiter(lock, &waiter,
68067- task_thread_info(task));
68068+ mutex_remove_waiter(lock, &waiter, task);
68069 mutex_release(&lock->dep_map, 1, ip);
68070 spin_unlock_mutex(&lock->wait_lock, flags);
68071
68072@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68073 done:
68074 lock_acquired(&lock->dep_map, ip);
68075 /* got the lock - rejoice! */
68076- mutex_remove_waiter(lock, &waiter, current_thread_info());
68077+ mutex_remove_waiter(lock, &waiter, task);
68078 mutex_set_owner(lock);
68079
68080 /* set it to 0 if there are no waiters left: */
68081diff --git a/kernel/panic.c b/kernel/panic.c
68082index d2a5f4e..5edc1d9 100644
68083--- a/kernel/panic.c
68084+++ b/kernel/panic.c
68085@@ -75,6 +75,14 @@ void panic(const char *fmt, ...)
68086 int state = 0;
68087
68088 /*
68089+ * Disable local interrupts. This will prevent panic_smp_self_stop
68090+ * from deadlocking the first cpu that invokes the panic, since
68091+ * there is nothing to prevent an interrupt handler (that runs
68092+ * after the panic_lock is acquired) from invoking panic again.
68093+ */
68094+ local_irq_disable();
68095+
68096+ /*
68097 * It's possible to come here directly from a panic-assertion and
68098 * not have preempt disabled. Some functions called from here want
68099 * preempt to be disabled. No point enabling it later though...
68100@@ -402,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68101 const char *board;
68102
68103 printk(KERN_WARNING "------------[ cut here ]------------\n");
68104- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68105+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68106 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68107 if (board)
68108 printk(KERN_WARNING "Hardware name: %s\n", board);
68109@@ -457,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68110 */
68111 void __stack_chk_fail(void)
68112 {
68113- panic("stack-protector: Kernel stack is corrupted in: %p\n",
68114+ dump_stack();
68115+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68116 __builtin_return_address(0));
68117 }
68118 EXPORT_SYMBOL(__stack_chk_fail);
68119diff --git a/kernel/pid.c b/kernel/pid.c
68120index e86b291a..e8b0fb5 100644
68121--- a/kernel/pid.c
68122+++ b/kernel/pid.c
68123@@ -33,6 +33,7 @@
68124 #include <linux/rculist.h>
68125 #include <linux/bootmem.h>
68126 #include <linux/hash.h>
68127+#include <linux/security.h>
68128 #include <linux/pid_namespace.h>
68129 #include <linux/init_task.h>
68130 #include <linux/syscalls.h>
68131@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68132
68133 int pid_max = PID_MAX_DEFAULT;
68134
68135-#define RESERVED_PIDS 300
68136+#define RESERVED_PIDS 500
68137
68138 int pid_max_min = RESERVED_PIDS + 1;
68139 int pid_max_max = PID_MAX_LIMIT;
68140@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68141 */
68142 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68143 {
68144+ struct task_struct *task;
68145+
68146 rcu_lockdep_assert(rcu_read_lock_held(),
68147 "find_task_by_pid_ns() needs rcu_read_lock()"
68148 " protection");
68149- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68150+
68151+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68152+
68153+ if (gr_pid_is_chrooted(task))
68154+ return NULL;
68155+
68156+ return task;
68157 }
68158
68159 struct task_struct *find_task_by_vpid(pid_t vnr)
68160@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68161 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68162 }
68163
68164+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68165+{
68166+ rcu_lockdep_assert(rcu_read_lock_held(),
68167+ "find_task_by_pid_ns() needs rcu_read_lock()"
68168+ " protection");
68169+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68170+}
68171+
68172 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68173 {
68174 struct pid *pid;
68175diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68176index 125cb67..a4d1c30 100644
68177--- a/kernel/posix-cpu-timers.c
68178+++ b/kernel/posix-cpu-timers.c
68179@@ -6,6 +6,7 @@
68180 #include <linux/posix-timers.h>
68181 #include <linux/errno.h>
68182 #include <linux/math64.h>
68183+#include <linux/security.h>
68184 #include <asm/uaccess.h>
68185 #include <linux/kernel_stat.h>
68186 #include <trace/events/timer.h>
68187@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68188
68189 static __init int init_posix_cpu_timers(void)
68190 {
68191- struct k_clock process = {
68192+ static struct k_clock process = {
68193 .clock_getres = process_cpu_clock_getres,
68194 .clock_get = process_cpu_clock_get,
68195 .timer_create = process_cpu_timer_create,
68196 .nsleep = process_cpu_nsleep,
68197 .nsleep_restart = process_cpu_nsleep_restart,
68198 };
68199- struct k_clock thread = {
68200+ static struct k_clock thread = {
68201 .clock_getres = thread_cpu_clock_getres,
68202 .clock_get = thread_cpu_clock_get,
68203 .timer_create = thread_cpu_timer_create,
68204diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68205index 69185ae..cc2847a 100644
68206--- a/kernel/posix-timers.c
68207+++ b/kernel/posix-timers.c
68208@@ -43,6 +43,7 @@
68209 #include <linux/idr.h>
68210 #include <linux/posix-clock.h>
68211 #include <linux/posix-timers.h>
68212+#include <linux/grsecurity.h>
68213 #include <linux/syscalls.h>
68214 #include <linux/wait.h>
68215 #include <linux/workqueue.h>
68216@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68217 * which we beg off on and pass to do_sys_settimeofday().
68218 */
68219
68220-static struct k_clock posix_clocks[MAX_CLOCKS];
68221+static struct k_clock *posix_clocks[MAX_CLOCKS];
68222
68223 /*
68224 * These ones are defined below.
68225@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68226 */
68227 static __init int init_posix_timers(void)
68228 {
68229- struct k_clock clock_realtime = {
68230+ static struct k_clock clock_realtime = {
68231 .clock_getres = hrtimer_get_res,
68232 .clock_get = posix_clock_realtime_get,
68233 .clock_set = posix_clock_realtime_set,
68234@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68235 .timer_get = common_timer_get,
68236 .timer_del = common_timer_del,
68237 };
68238- struct k_clock clock_monotonic = {
68239+ static struct k_clock clock_monotonic = {
68240 .clock_getres = hrtimer_get_res,
68241 .clock_get = posix_ktime_get_ts,
68242 .nsleep = common_nsleep,
68243@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68244 .timer_get = common_timer_get,
68245 .timer_del = common_timer_del,
68246 };
68247- struct k_clock clock_monotonic_raw = {
68248+ static struct k_clock clock_monotonic_raw = {
68249 .clock_getres = hrtimer_get_res,
68250 .clock_get = posix_get_monotonic_raw,
68251 };
68252- struct k_clock clock_realtime_coarse = {
68253+ static struct k_clock clock_realtime_coarse = {
68254 .clock_getres = posix_get_coarse_res,
68255 .clock_get = posix_get_realtime_coarse,
68256 };
68257- struct k_clock clock_monotonic_coarse = {
68258+ static struct k_clock clock_monotonic_coarse = {
68259 .clock_getres = posix_get_coarse_res,
68260 .clock_get = posix_get_monotonic_coarse,
68261 };
68262- struct k_clock clock_boottime = {
68263+ static struct k_clock clock_boottime = {
68264 .clock_getres = hrtimer_get_res,
68265 .clock_get = posix_get_boottime,
68266 .nsleep = common_nsleep,
68267@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
68268 return;
68269 }
68270
68271- posix_clocks[clock_id] = *new_clock;
68272+ posix_clocks[clock_id] = new_clock;
68273 }
68274 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
68275
68276@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
68277 return (id & CLOCKFD_MASK) == CLOCKFD ?
68278 &clock_posix_dynamic : &clock_posix_cpu;
68279
68280- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
68281+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
68282 return NULL;
68283- return &posix_clocks[id];
68284+ return posix_clocks[id];
68285 }
68286
68287 static int common_timer_create(struct k_itimer *new_timer)
68288@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
68289 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
68290 return -EFAULT;
68291
68292+ /* only the CLOCK_REALTIME clock can be set, all other clocks
68293+ have their clock_set fptr set to a nosettime dummy function
68294+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
68295+ call common_clock_set, which calls do_sys_settimeofday, which
68296+ we hook
68297+ */
68298+
68299 return kc->clock_set(which_clock, &new_tp);
68300 }
68301
68302diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
68303index d523593..68197a4 100644
68304--- a/kernel/power/poweroff.c
68305+++ b/kernel/power/poweroff.c
68306@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
68307 .enable_mask = SYSRQ_ENABLE_BOOT,
68308 };
68309
68310-static int pm_sysrq_init(void)
68311+static int __init pm_sysrq_init(void)
68312 {
68313 register_sysrq_key('o', &sysrq_poweroff_op);
68314 return 0;
68315diff --git a/kernel/power/process.c b/kernel/power/process.c
68316index 19db29f..33b52b6 100644
68317--- a/kernel/power/process.c
68318+++ b/kernel/power/process.c
68319@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
68320 u64 elapsed_csecs64;
68321 unsigned int elapsed_csecs;
68322 bool wakeup = false;
68323+ bool timedout = false;
68324
68325 do_gettimeofday(&start);
68326
68327@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
68328
68329 while (true) {
68330 todo = 0;
68331+ if (time_after(jiffies, end_time))
68332+ timedout = true;
68333 read_lock(&tasklist_lock);
68334 do_each_thread(g, p) {
68335 if (p == current || !freeze_task(p))
68336@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
68337 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
68338 * transition can't race with task state testing here.
68339 */
68340- if (!task_is_stopped_or_traced(p) &&
68341- !freezer_should_skip(p))
68342+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
68343 todo++;
68344+ if (timedout) {
68345+ printk(KERN_ERR "Task refusing to freeze:\n");
68346+ sched_show_task(p);
68347+ }
68348+ }
68349 } while_each_thread(g, p);
68350 read_unlock(&tasklist_lock);
68351
68352@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
68353 todo += wq_busy;
68354 }
68355
68356- if (!todo || time_after(jiffies, end_time))
68357+ if (!todo || timedout)
68358 break;
68359
68360 if (pm_wakeup_pending()) {
68361diff --git a/kernel/printk.c b/kernel/printk.c
68362index ac4bc9e..1d2db99 100644
68363--- a/kernel/printk.c
68364+++ b/kernel/printk.c
68365@@ -781,6 +781,11 @@ static int check_syslog_permissions(int type, bool from_file)
68366 if (from_file && type != SYSLOG_ACTION_OPEN)
68367 return 0;
68368
68369+#ifdef CONFIG_GRKERNSEC_DMESG
68370+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
68371+ return -EPERM;
68372+#endif
68373+
68374 if (syslog_action_restricted(type)) {
68375 if (capable(CAP_SYSLOG))
68376 return 0;
68377diff --git a/kernel/profile.c b/kernel/profile.c
68378index 76b8e77..a2930e8 100644
68379--- a/kernel/profile.c
68380+++ b/kernel/profile.c
68381@@ -39,7 +39,7 @@ struct profile_hit {
68382 /* Oprofile timer tick hook */
68383 static int (*timer_hook)(struct pt_regs *) __read_mostly;
68384
68385-static atomic_t *prof_buffer;
68386+static atomic_unchecked_t *prof_buffer;
68387 static unsigned long prof_len, prof_shift;
68388
68389 int prof_on __read_mostly;
68390@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
68391 hits[i].pc = 0;
68392 continue;
68393 }
68394- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68395+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68396 hits[i].hits = hits[i].pc = 0;
68397 }
68398 }
68399@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68400 * Add the current hit(s) and flush the write-queue out
68401 * to the global buffer:
68402 */
68403- atomic_add(nr_hits, &prof_buffer[pc]);
68404+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
68405 for (i = 0; i < NR_PROFILE_HIT; ++i) {
68406- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68407+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68408 hits[i].pc = hits[i].hits = 0;
68409 }
68410 out:
68411@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68412 {
68413 unsigned long pc;
68414 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68415- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68416+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68417 }
68418 #endif /* !CONFIG_SMP */
68419
68420@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68421 return -EFAULT;
68422 buf++; p++; count--; read++;
68423 }
68424- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68425+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68426 if (copy_to_user(buf, (void *)pnt, count))
68427 return -EFAULT;
68428 read += count;
68429@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68430 }
68431 #endif
68432 profile_discard_flip_buffers();
68433- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68434+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68435 return count;
68436 }
68437
68438diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68439index a232bb5..2a65ef9 100644
68440--- a/kernel/ptrace.c
68441+++ b/kernel/ptrace.c
68442@@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68443
68444 if (seize)
68445 flags |= PT_SEIZED;
68446- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68447+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68448 flags |= PT_PTRACE_CAP;
68449 task->ptrace = flags;
68450
68451@@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68452 break;
68453 return -EIO;
68454 }
68455- if (copy_to_user(dst, buf, retval))
68456+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68457 return -EFAULT;
68458 copied += retval;
68459 src += retval;
68460@@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
68461 bool seized = child->ptrace & PT_SEIZED;
68462 int ret = -EIO;
68463 siginfo_t siginfo, *si;
68464- void __user *datavp = (void __user *) data;
68465+ void __user *datavp = (__force void __user *) data;
68466 unsigned long __user *datalp = datavp;
68467 unsigned long flags;
68468
68469@@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68470 goto out;
68471 }
68472
68473+ if (gr_handle_ptrace(child, request)) {
68474+ ret = -EPERM;
68475+ goto out_put_task_struct;
68476+ }
68477+
68478 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68479 ret = ptrace_attach(child, request, addr, data);
68480 /*
68481 * Some architectures need to do book-keeping after
68482 * a ptrace attach.
68483 */
68484- if (!ret)
68485+ if (!ret) {
68486 arch_ptrace_attach(child);
68487+ gr_audit_ptrace(child);
68488+ }
68489 goto out_put_task_struct;
68490 }
68491
68492@@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68493 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68494 if (copied != sizeof(tmp))
68495 return -EIO;
68496- return put_user(tmp, (unsigned long __user *)data);
68497+ return put_user(tmp, (__force unsigned long __user *)data);
68498 }
68499
68500 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68501@@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68502 goto out;
68503 }
68504
68505+ if (gr_handle_ptrace(child, request)) {
68506+ ret = -EPERM;
68507+ goto out_put_task_struct;
68508+ }
68509+
68510 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68511 ret = ptrace_attach(child, request, addr, data);
68512 /*
68513 * Some architectures need to do book-keeping after
68514 * a ptrace attach.
68515 */
68516- if (!ret)
68517+ if (!ret) {
68518 arch_ptrace_attach(child);
68519+ gr_audit_ptrace(child);
68520+ }
68521 goto out_put_task_struct;
68522 }
68523
68524diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68525index 37a5444..eec170a 100644
68526--- a/kernel/rcutiny.c
68527+++ b/kernel/rcutiny.c
68528@@ -46,7 +46,7 @@
68529 struct rcu_ctrlblk;
68530 static void invoke_rcu_callbacks(void);
68531 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68532-static void rcu_process_callbacks(struct softirq_action *unused);
68533+static void rcu_process_callbacks(void);
68534 static void __call_rcu(struct rcu_head *head,
68535 void (*func)(struct rcu_head *rcu),
68536 struct rcu_ctrlblk *rcp);
68537@@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68538 rcu_is_callbacks_kthread()));
68539 }
68540
68541-static void rcu_process_callbacks(struct softirq_action *unused)
68542+static void rcu_process_callbacks(void)
68543 {
68544 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68545 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68546diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68547index fc31a2d..be2ec04 100644
68548--- a/kernel/rcutiny_plugin.h
68549+++ b/kernel/rcutiny_plugin.h
68550@@ -939,7 +939,7 @@ static int rcu_kthread(void *arg)
68551 have_rcu_kthread_work = morework;
68552 local_irq_restore(flags);
68553 if (work)
68554- rcu_process_callbacks(NULL);
68555+ rcu_process_callbacks();
68556 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68557 }
68558
68559diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68560index e66b34a..4b8b626 100644
68561--- a/kernel/rcutorture.c
68562+++ b/kernel/rcutorture.c
68563@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68564 { 0 };
68565 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68566 { 0 };
68567-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68568-static atomic_t n_rcu_torture_alloc;
68569-static atomic_t n_rcu_torture_alloc_fail;
68570-static atomic_t n_rcu_torture_free;
68571-static atomic_t n_rcu_torture_mberror;
68572-static atomic_t n_rcu_torture_error;
68573+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68574+static atomic_unchecked_t n_rcu_torture_alloc;
68575+static atomic_unchecked_t n_rcu_torture_alloc_fail;
68576+static atomic_unchecked_t n_rcu_torture_free;
68577+static atomic_unchecked_t n_rcu_torture_mberror;
68578+static atomic_unchecked_t n_rcu_torture_error;
68579 static long n_rcu_torture_barrier_error;
68580 static long n_rcu_torture_boost_ktrerror;
68581 static long n_rcu_torture_boost_rterror;
68582@@ -265,11 +265,11 @@ rcu_torture_alloc(void)
68583
68584 spin_lock_bh(&rcu_torture_lock);
68585 if (list_empty(&rcu_torture_freelist)) {
68586- atomic_inc(&n_rcu_torture_alloc_fail);
68587+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68588 spin_unlock_bh(&rcu_torture_lock);
68589 return NULL;
68590 }
68591- atomic_inc(&n_rcu_torture_alloc);
68592+ atomic_inc_unchecked(&n_rcu_torture_alloc);
68593 p = rcu_torture_freelist.next;
68594 list_del_init(p);
68595 spin_unlock_bh(&rcu_torture_lock);
68596@@ -282,7 +282,7 @@ rcu_torture_alloc(void)
68597 static void
68598 rcu_torture_free(struct rcu_torture *p)
68599 {
68600- atomic_inc(&n_rcu_torture_free);
68601+ atomic_inc_unchecked(&n_rcu_torture_free);
68602 spin_lock_bh(&rcu_torture_lock);
68603 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68604 spin_unlock_bh(&rcu_torture_lock);
68605@@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
68606 i = rp->rtort_pipe_count;
68607 if (i > RCU_TORTURE_PIPE_LEN)
68608 i = RCU_TORTURE_PIPE_LEN;
68609- atomic_inc(&rcu_torture_wcount[i]);
68610+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68611 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68612 rp->rtort_mbtest = 0;
68613 rcu_torture_free(rp);
68614@@ -451,7 +451,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68615 i = rp->rtort_pipe_count;
68616 if (i > RCU_TORTURE_PIPE_LEN)
68617 i = RCU_TORTURE_PIPE_LEN;
68618- atomic_inc(&rcu_torture_wcount[i]);
68619+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68620 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68621 rp->rtort_mbtest = 0;
68622 list_del(&rp->rtort_free);
68623@@ -983,7 +983,7 @@ rcu_torture_writer(void *arg)
68624 i = old_rp->rtort_pipe_count;
68625 if (i > RCU_TORTURE_PIPE_LEN)
68626 i = RCU_TORTURE_PIPE_LEN;
68627- atomic_inc(&rcu_torture_wcount[i]);
68628+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68629 old_rp->rtort_pipe_count++;
68630 cur_ops->deferred_free(old_rp);
68631 }
68632@@ -1064,7 +1064,7 @@ static void rcu_torture_timer(unsigned long unused)
68633 }
68634 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68635 if (p->rtort_mbtest == 0)
68636- atomic_inc(&n_rcu_torture_mberror);
68637+ atomic_inc_unchecked(&n_rcu_torture_mberror);
68638 spin_lock(&rand_lock);
68639 cur_ops->read_delay(&rand);
68640 n_rcu_torture_timers++;
68641@@ -1128,7 +1128,7 @@ rcu_torture_reader(void *arg)
68642 }
68643 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68644 if (p->rtort_mbtest == 0)
68645- atomic_inc(&n_rcu_torture_mberror);
68646+ atomic_inc_unchecked(&n_rcu_torture_mberror);
68647 cur_ops->read_delay(&rand);
68648 preempt_disable();
68649 pipe_count = p->rtort_pipe_count;
68650@@ -1191,10 +1191,10 @@ rcu_torture_printk(char *page)
68651 rcu_torture_current,
68652 rcu_torture_current_version,
68653 list_empty(&rcu_torture_freelist),
68654- atomic_read(&n_rcu_torture_alloc),
68655- atomic_read(&n_rcu_torture_alloc_fail),
68656- atomic_read(&n_rcu_torture_free),
68657- atomic_read(&n_rcu_torture_mberror),
68658+ atomic_read_unchecked(&n_rcu_torture_alloc),
68659+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68660+ atomic_read_unchecked(&n_rcu_torture_free),
68661+ atomic_read_unchecked(&n_rcu_torture_mberror),
68662 n_rcu_torture_boost_ktrerror,
68663 n_rcu_torture_boost_rterror,
68664 n_rcu_torture_boost_failure,
68665@@ -1208,14 +1208,14 @@ rcu_torture_printk(char *page)
68666 n_barrier_attempts,
68667 n_rcu_torture_barrier_error);
68668 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68669- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68670+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68671 n_rcu_torture_barrier_error != 0 ||
68672 n_rcu_torture_boost_ktrerror != 0 ||
68673 n_rcu_torture_boost_rterror != 0 ||
68674 n_rcu_torture_boost_failure != 0 ||
68675 i > 1) {
68676 cnt += sprintf(&page[cnt], "!!! ");
68677- atomic_inc(&n_rcu_torture_error);
68678+ atomic_inc_unchecked(&n_rcu_torture_error);
68679 WARN_ON_ONCE(1);
68680 }
68681 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68682@@ -1229,7 +1229,7 @@ rcu_torture_printk(char *page)
68683 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68684 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68685 cnt += sprintf(&page[cnt], " %d",
68686- atomic_read(&rcu_torture_wcount[i]));
68687+ atomic_read_unchecked(&rcu_torture_wcount[i]));
68688 }
68689 cnt += sprintf(&page[cnt], "\n");
68690 if (cur_ops->stats)
68691@@ -1888,7 +1888,7 @@ rcu_torture_cleanup(void)
68692
68693 if (cur_ops->cleanup)
68694 cur_ops->cleanup();
68695- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68696+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68697 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68698 else if (n_online_successes != n_online_attempts ||
68699 n_offline_successes != n_offline_attempts)
68700@@ -1958,18 +1958,18 @@ rcu_torture_init(void)
68701
68702 rcu_torture_current = NULL;
68703 rcu_torture_current_version = 0;
68704- atomic_set(&n_rcu_torture_alloc, 0);
68705- atomic_set(&n_rcu_torture_alloc_fail, 0);
68706- atomic_set(&n_rcu_torture_free, 0);
68707- atomic_set(&n_rcu_torture_mberror, 0);
68708- atomic_set(&n_rcu_torture_error, 0);
68709+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68710+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68711+ atomic_set_unchecked(&n_rcu_torture_free, 0);
68712+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68713+ atomic_set_unchecked(&n_rcu_torture_error, 0);
68714 n_rcu_torture_barrier_error = 0;
68715 n_rcu_torture_boost_ktrerror = 0;
68716 n_rcu_torture_boost_rterror = 0;
68717 n_rcu_torture_boost_failure = 0;
68718 n_rcu_torture_boosts = 0;
68719 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68720- atomic_set(&rcu_torture_wcount[i], 0);
68721+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68722 for_each_possible_cpu(cpu) {
68723 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68724 per_cpu(rcu_torture_count, cpu)[i] = 0;
68725diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68726index 4b97bba..b92c9d2 100644
68727--- a/kernel/rcutree.c
68728+++ b/kernel/rcutree.c
68729@@ -366,9 +366,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68730 rcu_prepare_for_idle(smp_processor_id());
68731 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68732 smp_mb__before_atomic_inc(); /* See above. */
68733- atomic_inc(&rdtp->dynticks);
68734+ atomic_inc_unchecked(&rdtp->dynticks);
68735 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68736- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68737+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68738
68739 /*
68740 * The idle task is not permitted to enter the idle loop while
68741@@ -457,10 +457,10 @@ void rcu_irq_exit(void)
68742 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68743 {
68744 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68745- atomic_inc(&rdtp->dynticks);
68746+ atomic_inc_unchecked(&rdtp->dynticks);
68747 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68748 smp_mb__after_atomic_inc(); /* See above. */
68749- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68750+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68751 rcu_cleanup_after_idle(smp_processor_id());
68752 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68753 if (!is_idle_task(current)) {
68754@@ -554,14 +554,14 @@ void rcu_nmi_enter(void)
68755 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68756
68757 if (rdtp->dynticks_nmi_nesting == 0 &&
68758- (atomic_read(&rdtp->dynticks) & 0x1))
68759+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68760 return;
68761 rdtp->dynticks_nmi_nesting++;
68762 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68763- atomic_inc(&rdtp->dynticks);
68764+ atomic_inc_unchecked(&rdtp->dynticks);
68765 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68766 smp_mb__after_atomic_inc(); /* See above. */
68767- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68768+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68769 }
68770
68771 /**
68772@@ -580,9 +580,9 @@ void rcu_nmi_exit(void)
68773 return;
68774 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68775 smp_mb__before_atomic_inc(); /* See above. */
68776- atomic_inc(&rdtp->dynticks);
68777+ atomic_inc_unchecked(&rdtp->dynticks);
68778 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68779- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68780+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68781 }
68782
68783 #ifdef CONFIG_PROVE_RCU
68784@@ -598,7 +598,7 @@ int rcu_is_cpu_idle(void)
68785 int ret;
68786
68787 preempt_disable();
68788- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68789+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68790 preempt_enable();
68791 return ret;
68792 }
68793@@ -668,7 +668,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68794 */
68795 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68796 {
68797- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68798+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68799 return (rdp->dynticks_snap & 0x1) == 0;
68800 }
68801
68802@@ -683,7 +683,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68803 unsigned int curr;
68804 unsigned int snap;
68805
68806- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68807+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68808 snap = (unsigned int)rdp->dynticks_snap;
68809
68810 /*
68811@@ -713,10 +713,10 @@ static int jiffies_till_stall_check(void)
68812 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
68813 */
68814 if (till_stall_check < 3) {
68815- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
68816+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
68817 till_stall_check = 3;
68818 } else if (till_stall_check > 300) {
68819- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
68820+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
68821 till_stall_check = 300;
68822 }
68823 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
68824@@ -1824,7 +1824,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68825 /*
68826 * Do RCU core processing for the current CPU.
68827 */
68828-static void rcu_process_callbacks(struct softirq_action *unused)
68829+static void rcu_process_callbacks(void)
68830 {
68831 trace_rcu_utilization("Start RCU core");
68832 __rcu_process_callbacks(&rcu_sched_state,
68833@@ -2042,8 +2042,8 @@ void synchronize_rcu_bh(void)
68834 }
68835 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
68836
68837-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68838-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68839+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68840+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68841
68842 static int synchronize_sched_expedited_cpu_stop(void *data)
68843 {
68844@@ -2104,7 +2104,7 @@ void synchronize_sched_expedited(void)
68845 int firstsnap, s, snap, trycount = 0;
68846
68847 /* Note that atomic_inc_return() implies full memory barrier. */
68848- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68849+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68850 get_online_cpus();
68851 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
68852
68853@@ -2126,7 +2126,7 @@ void synchronize_sched_expedited(void)
68854 }
68855
68856 /* Check to see if someone else did our work for us. */
68857- s = atomic_read(&sync_sched_expedited_done);
68858+ s = atomic_read_unchecked(&sync_sched_expedited_done);
68859 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68860 smp_mb(); /* ensure test happens before caller kfree */
68861 return;
68862@@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
68863 * grace period works for us.
68864 */
68865 get_online_cpus();
68866- snap = atomic_read(&sync_sched_expedited_started);
68867+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
68868 smp_mb(); /* ensure read is before try_stop_cpus(). */
68869 }
68870
68871@@ -2152,12 +2152,12 @@ void synchronize_sched_expedited(void)
68872 * than we did beat us to the punch.
68873 */
68874 do {
68875- s = atomic_read(&sync_sched_expedited_done);
68876+ s = atomic_read_unchecked(&sync_sched_expedited_done);
68877 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68878 smp_mb(); /* ensure test happens before caller kfree */
68879 break;
68880 }
68881- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68882+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68883
68884 put_online_cpus();
68885 }
68886@@ -2421,7 +2421,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
68887 rdp->qlen = 0;
68888 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
68889 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
68890- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
68891+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
68892 rdp->cpu = cpu;
68893 rdp->rsp = rsp;
68894 raw_spin_unlock_irqrestore(&rnp->lock, flags);
68895@@ -2449,8 +2449,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
68896 rdp->n_force_qs_snap = rsp->n_force_qs;
68897 rdp->blimit = blimit;
68898 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
68899- atomic_set(&rdp->dynticks->dynticks,
68900- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
68901+ atomic_set_unchecked(&rdp->dynticks->dynticks,
68902+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
68903 rcu_prepare_for_idle_init(cpu);
68904 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
68905
68906diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68907index 19b61ac..5c60a94 100644
68908--- a/kernel/rcutree.h
68909+++ b/kernel/rcutree.h
68910@@ -83,7 +83,7 @@ struct rcu_dynticks {
68911 long long dynticks_nesting; /* Track irq/process nesting level. */
68912 /* Process level is worth LLONG_MAX/2. */
68913 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68914- atomic_t dynticks; /* Even value for idle, else odd. */
68915+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
68916 #ifdef CONFIG_RCU_FAST_NO_HZ
68917 int dyntick_drain; /* Prepare-for-idle state variable. */
68918 unsigned long dyntick_holdoff;
68919diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68920index 3e48994..d94f03a 100644
68921--- a/kernel/rcutree_plugin.h
68922+++ b/kernel/rcutree_plugin.h
68923@@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
68924
68925 /* Clean up and exit. */
68926 smp_mb(); /* ensure expedited GP seen before counter increment. */
68927- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68928+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68929 unlock_mb_ret:
68930 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68931 mb_ret:
68932diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68933index d4bc16d..c234a5c 100644
68934--- a/kernel/rcutree_trace.c
68935+++ b/kernel/rcutree_trace.c
68936@@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68937 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68938 rdp->qs_pending);
68939 seq_printf(m, " dt=%d/%llx/%d df=%lu",
68940- atomic_read(&rdp->dynticks->dynticks),
68941+ atomic_read_unchecked(&rdp->dynticks->dynticks),
68942 rdp->dynticks->dynticks_nesting,
68943 rdp->dynticks->dynticks_nmi_nesting,
68944 rdp->dynticks_fqs);
68945@@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68946 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68947 rdp->qs_pending);
68948 seq_printf(m, ",%d,%llx,%d,%lu",
68949- atomic_read(&rdp->dynticks->dynticks),
68950+ atomic_read_unchecked(&rdp->dynticks->dynticks),
68951 rdp->dynticks->dynticks_nesting,
68952 rdp->dynticks->dynticks_nmi_nesting,
68953 rdp->dynticks_fqs);
68954diff --git a/kernel/resource.c b/kernel/resource.c
68955index e1d2b8e..24820bb 100644
68956--- a/kernel/resource.c
68957+++ b/kernel/resource.c
68958@@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68959
68960 static int __init ioresources_init(void)
68961 {
68962+#ifdef CONFIG_GRKERNSEC_PROC_ADD
68963+#ifdef CONFIG_GRKERNSEC_PROC_USER
68964+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68965+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68966+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68967+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68968+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68969+#endif
68970+#else
68971 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68972 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68973+#endif
68974 return 0;
68975 }
68976 __initcall(ioresources_init);
68977diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68978index 98ec494..4241d6d 100644
68979--- a/kernel/rtmutex-tester.c
68980+++ b/kernel/rtmutex-tester.c
68981@@ -20,7 +20,7 @@
68982 #define MAX_RT_TEST_MUTEXES 8
68983
68984 static spinlock_t rttest_lock;
68985-static atomic_t rttest_event;
68986+static atomic_unchecked_t rttest_event;
68987
68988 struct test_thread_data {
68989 int opcode;
68990@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68991
68992 case RTTEST_LOCKCONT:
68993 td->mutexes[td->opdata] = 1;
68994- td->event = atomic_add_return(1, &rttest_event);
68995+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68996 return 0;
68997
68998 case RTTEST_RESET:
68999@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69000 return 0;
69001
69002 case RTTEST_RESETEVENT:
69003- atomic_set(&rttest_event, 0);
69004+ atomic_set_unchecked(&rttest_event, 0);
69005 return 0;
69006
69007 default:
69008@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69009 return ret;
69010
69011 td->mutexes[id] = 1;
69012- td->event = atomic_add_return(1, &rttest_event);
69013+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69014 rt_mutex_lock(&mutexes[id]);
69015- td->event = atomic_add_return(1, &rttest_event);
69016+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69017 td->mutexes[id] = 4;
69018 return 0;
69019
69020@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69021 return ret;
69022
69023 td->mutexes[id] = 1;
69024- td->event = atomic_add_return(1, &rttest_event);
69025+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69026 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69027- td->event = atomic_add_return(1, &rttest_event);
69028+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69029 td->mutexes[id] = ret ? 0 : 4;
69030 return ret ? -EINTR : 0;
69031
69032@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69033 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69034 return ret;
69035
69036- td->event = atomic_add_return(1, &rttest_event);
69037+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69038 rt_mutex_unlock(&mutexes[id]);
69039- td->event = atomic_add_return(1, &rttest_event);
69040+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69041 td->mutexes[id] = 0;
69042 return 0;
69043
69044@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69045 break;
69046
69047 td->mutexes[dat] = 2;
69048- td->event = atomic_add_return(1, &rttest_event);
69049+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69050 break;
69051
69052 default:
69053@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69054 return;
69055
69056 td->mutexes[dat] = 3;
69057- td->event = atomic_add_return(1, &rttest_event);
69058+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69059 break;
69060
69061 case RTTEST_LOCKNOWAIT:
69062@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69063 return;
69064
69065 td->mutexes[dat] = 1;
69066- td->event = atomic_add_return(1, &rttest_event);
69067+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69068 return;
69069
69070 default:
69071diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69072index 0984a21..939f183 100644
69073--- a/kernel/sched/auto_group.c
69074+++ b/kernel/sched/auto_group.c
69075@@ -11,7 +11,7 @@
69076
69077 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69078 static struct autogroup autogroup_default;
69079-static atomic_t autogroup_seq_nr;
69080+static atomic_unchecked_t autogroup_seq_nr;
69081
69082 void __init autogroup_init(struct task_struct *init_task)
69083 {
69084@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69085
69086 kref_init(&ag->kref);
69087 init_rwsem(&ag->lock);
69088- ag->id = atomic_inc_return(&autogroup_seq_nr);
69089+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69090 ag->tg = tg;
69091 #ifdef CONFIG_RT_GROUP_SCHED
69092 /*
69093diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69094index 468bdd4..b941572 100644
69095--- a/kernel/sched/core.c
69096+++ b/kernel/sched/core.c
69097@@ -4097,6 +4097,8 @@ int can_nice(const struct task_struct *p, const int nice)
69098 /* convert nice value [19,-20] to rlimit style value [1,40] */
69099 int nice_rlim = 20 - nice;
69100
69101+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69102+
69103 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69104 capable(CAP_SYS_NICE));
69105 }
69106@@ -4130,7 +4132,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69107 if (nice > 19)
69108 nice = 19;
69109
69110- if (increment < 0 && !can_nice(current, nice))
69111+ if (increment < 0 && (!can_nice(current, nice) ||
69112+ gr_handle_chroot_nice()))
69113 return -EPERM;
69114
69115 retval = security_task_setnice(current, nice);
69116@@ -4284,6 +4287,7 @@ recheck:
69117 unsigned long rlim_rtprio =
69118 task_rlimit(p, RLIMIT_RTPRIO);
69119
69120+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69121 /* can't set/change the rt policy */
69122 if (policy != p->policy && !rlim_rtprio)
69123 return -EPERM;
69124diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69125index c099cc6..06aec4f 100644
69126--- a/kernel/sched/fair.c
69127+++ b/kernel/sched/fair.c
69128@@ -4846,7 +4846,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69129 * run_rebalance_domains is triggered when needed from the scheduler tick.
69130 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69131 */
69132-static void run_rebalance_domains(struct softirq_action *h)
69133+static void run_rebalance_domains(void)
69134 {
69135 int this_cpu = smp_processor_id();
69136 struct rq *this_rq = cpu_rq(this_cpu);
69137diff --git a/kernel/signal.c b/kernel/signal.c
69138index 6771027..763e51e 100644
69139--- a/kernel/signal.c
69140+++ b/kernel/signal.c
69141@@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69142
69143 int print_fatal_signals __read_mostly;
69144
69145-static void __user *sig_handler(struct task_struct *t, int sig)
69146+static __sighandler_t sig_handler(struct task_struct *t, int sig)
69147 {
69148 return t->sighand->action[sig - 1].sa.sa_handler;
69149 }
69150
69151-static int sig_handler_ignored(void __user *handler, int sig)
69152+static int sig_handler_ignored(__sighandler_t handler, int sig)
69153 {
69154 /* Is it explicitly or implicitly ignored? */
69155 return handler == SIG_IGN ||
69156@@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69157
69158 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69159 {
69160- void __user *handler;
69161+ __sighandler_t handler;
69162
69163 handler = sig_handler(t, sig);
69164
69165@@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69166 atomic_inc(&user->sigpending);
69167 rcu_read_unlock();
69168
69169+ if (!override_rlimit)
69170+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69171+
69172 if (override_rlimit ||
69173 atomic_read(&user->sigpending) <=
69174 task_rlimit(t, RLIMIT_SIGPENDING)) {
69175@@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69176
69177 int unhandled_signal(struct task_struct *tsk, int sig)
69178 {
69179- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69180+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69181 if (is_global_init(tsk))
69182 return 1;
69183 if (handler != SIG_IGN && handler != SIG_DFL)
69184@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69185 }
69186 }
69187
69188+ /* allow glibc communication via tgkill to other threads in our
69189+ thread group */
69190+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69191+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69192+ && gr_handle_signal(t, sig))
69193+ return -EPERM;
69194+
69195 return security_task_kill(t, info, sig, 0);
69196 }
69197
69198@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69199 return send_signal(sig, info, p, 1);
69200 }
69201
69202-static int
69203+int
69204 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69205 {
69206 return send_signal(sig, info, t, 0);
69207@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69208 unsigned long int flags;
69209 int ret, blocked, ignored;
69210 struct k_sigaction *action;
69211+ int is_unhandled = 0;
69212
69213 spin_lock_irqsave(&t->sighand->siglock, flags);
69214 action = &t->sighand->action[sig-1];
69215@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69216 }
69217 if (action->sa.sa_handler == SIG_DFL)
69218 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69219+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69220+ is_unhandled = 1;
69221 ret = specific_send_sig_info(sig, info, t);
69222 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69223
69224+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
69225+ normal operation */
69226+ if (is_unhandled) {
69227+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
69228+ gr_handle_crash(t, sig);
69229+ }
69230+
69231 return ret;
69232 }
69233
69234@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69235 ret = check_kill_permission(sig, info, p);
69236 rcu_read_unlock();
69237
69238- if (!ret && sig)
69239+ if (!ret && sig) {
69240 ret = do_send_sig_info(sig, info, p, true);
69241+ if (!ret)
69242+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
69243+ }
69244
69245 return ret;
69246 }
69247@@ -2858,7 +2881,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
69248 int error = -ESRCH;
69249
69250 rcu_read_lock();
69251- p = find_task_by_vpid(pid);
69252+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69253+ /* allow glibc communication via tgkill to other threads in our
69254+ thread group */
69255+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
69256+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
69257+ p = find_task_by_vpid_unrestricted(pid);
69258+ else
69259+#endif
69260+ p = find_task_by_vpid(pid);
69261 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
69262 error = check_kill_permission(sig, info, p);
69263 /*
69264diff --git a/kernel/smp.c b/kernel/smp.c
69265index d0ae5b2..b87c5a8 100644
69266--- a/kernel/smp.c
69267+++ b/kernel/smp.c
69268@@ -582,22 +582,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
69269 }
69270 EXPORT_SYMBOL(smp_call_function);
69271
69272-void ipi_call_lock(void)
69273+void ipi_call_lock(void) __acquires(call_function.lock)
69274 {
69275 raw_spin_lock(&call_function.lock);
69276 }
69277
69278-void ipi_call_unlock(void)
69279+void ipi_call_unlock(void) __releases(call_function.lock)
69280 {
69281 raw_spin_unlock(&call_function.lock);
69282 }
69283
69284-void ipi_call_lock_irq(void)
69285+void ipi_call_lock_irq(void) __acquires(call_function.lock)
69286 {
69287 raw_spin_lock_irq(&call_function.lock);
69288 }
69289
69290-void ipi_call_unlock_irq(void)
69291+void ipi_call_unlock_irq(void) __releases(call_function.lock)
69292 {
69293 raw_spin_unlock_irq(&call_function.lock);
69294 }
69295diff --git a/kernel/softirq.c b/kernel/softirq.c
69296index 671f959..91c51cb 100644
69297--- a/kernel/softirq.c
69298+++ b/kernel/softirq.c
69299@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
69300
69301 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
69302
69303-char *softirq_to_name[NR_SOFTIRQS] = {
69304+const char * const softirq_to_name[NR_SOFTIRQS] = {
69305 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
69306 "TASKLET", "SCHED", "HRTIMER", "RCU"
69307 };
69308@@ -235,7 +235,7 @@ restart:
69309 kstat_incr_softirqs_this_cpu(vec_nr);
69310
69311 trace_softirq_entry(vec_nr);
69312- h->action(h);
69313+ h->action();
69314 trace_softirq_exit(vec_nr);
69315 if (unlikely(prev_count != preempt_count())) {
69316 printk(KERN_ERR "huh, entered softirq %u %s %p"
69317@@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
69318 or_softirq_pending(1UL << nr);
69319 }
69320
69321-void open_softirq(int nr, void (*action)(struct softirq_action *))
69322+void open_softirq(int nr, void (*action)(void))
69323 {
69324- softirq_vec[nr].action = action;
69325+ pax_open_kernel();
69326+ *(void **)&softirq_vec[nr].action = action;
69327+ pax_close_kernel();
69328 }
69329
69330 /*
69331@@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
69332
69333 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
69334
69335-static void tasklet_action(struct softirq_action *a)
69336+static void tasklet_action(void)
69337 {
69338 struct tasklet_struct *list;
69339
69340@@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
69341 }
69342 }
69343
69344-static void tasklet_hi_action(struct softirq_action *a)
69345+static void tasklet_hi_action(void)
69346 {
69347 struct tasklet_struct *list;
69348
69349diff --git a/kernel/srcu.c b/kernel/srcu.c
69350index 2095be3..9a5b89d 100644
69351--- a/kernel/srcu.c
69352+++ b/kernel/srcu.c
69353@@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
69354 preempt_disable();
69355 idx = rcu_dereference_index_check(sp->completed,
69356 rcu_read_lock_sched_held()) & 0x1;
69357- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69358+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69359 smp_mb(); /* B */ /* Avoid leaking the critical section. */
69360- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69361+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69362 preempt_enable();
69363 return idx;
69364 }
69365@@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
69366 {
69367 preempt_disable();
69368 smp_mb(); /* C */ /* Avoid leaking the critical section. */
69369- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69370+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69371 preempt_enable();
69372 }
69373 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
69374diff --git a/kernel/sys.c b/kernel/sys.c
69375index 2d39a84..f778b49 100644
69376--- a/kernel/sys.c
69377+++ b/kernel/sys.c
69378@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
69379 error = -EACCES;
69380 goto out;
69381 }
69382+
69383+ if (gr_handle_chroot_setpriority(p, niceval)) {
69384+ error = -EACCES;
69385+ goto out;
69386+ }
69387+
69388 no_nice = security_task_setnice(p, niceval);
69389 if (no_nice) {
69390 error = no_nice;
69391@@ -594,6 +600,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
69392 goto error;
69393 }
69394
69395+ if (gr_check_group_change(new->gid, new->egid, -1))
69396+ goto error;
69397+
69398 if (rgid != (gid_t) -1 ||
69399 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
69400 new->sgid = new->egid;
69401@@ -629,6 +638,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
69402 old = current_cred();
69403
69404 retval = -EPERM;
69405+
69406+ if (gr_check_group_change(kgid, kgid, kgid))
69407+ goto error;
69408+
69409 if (nsown_capable(CAP_SETGID))
69410 new->gid = new->egid = new->sgid = new->fsgid = kgid;
69411 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
69412@@ -646,7 +659,7 @@ error:
69413 /*
69414 * change the user struct in a credentials set to match the new UID
69415 */
69416-static int set_user(struct cred *new)
69417+int set_user(struct cred *new)
69418 {
69419 struct user_struct *new_user;
69420
69421@@ -726,6 +739,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69422 goto error;
69423 }
69424
69425+ if (gr_check_user_change(new->uid, new->euid, -1))
69426+ goto error;
69427+
69428 if (!uid_eq(new->uid, old->uid)) {
69429 retval = set_user(new);
69430 if (retval < 0)
69431@@ -776,6 +792,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69432 old = current_cred();
69433
69434 retval = -EPERM;
69435+
69436+ if (gr_check_crash_uid(kuid))
69437+ goto error;
69438+ if (gr_check_user_change(kuid, kuid, kuid))
69439+ goto error;
69440+
69441 if (nsown_capable(CAP_SETUID)) {
69442 new->suid = new->uid = kuid;
69443 if (!uid_eq(kuid, old->uid)) {
69444@@ -845,6 +867,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69445 goto error;
69446 }
69447
69448+ if (gr_check_user_change(kruid, keuid, -1))
69449+ goto error;
69450+
69451 if (ruid != (uid_t) -1) {
69452 new->uid = kruid;
69453 if (!uid_eq(kruid, old->uid)) {
69454@@ -927,6 +952,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69455 goto error;
69456 }
69457
69458+ if (gr_check_group_change(krgid, kegid, -1))
69459+ goto error;
69460+
69461 if (rgid != (gid_t) -1)
69462 new->gid = krgid;
69463 if (egid != (gid_t) -1)
69464@@ -980,6 +1008,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69465 if (!uid_valid(kuid))
69466 return old_fsuid;
69467
69468+ if (gr_check_user_change(-1, -1, kuid))
69469+ goto error;
69470+
69471 new = prepare_creds();
69472 if (!new)
69473 return old_fsuid;
69474@@ -994,6 +1025,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69475 }
69476 }
69477
69478+error:
69479 abort_creds(new);
69480 return old_fsuid;
69481
69482@@ -1026,12 +1058,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69483 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
69484 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
69485 nsown_capable(CAP_SETGID)) {
69486+ if (gr_check_group_change(-1, -1, kgid))
69487+ goto error;
69488+
69489 if (!gid_eq(kgid, old->fsgid)) {
69490 new->fsgid = kgid;
69491 goto change_okay;
69492 }
69493 }
69494
69495+error:
69496 abort_creds(new);
69497 return old_fsgid;
69498
69499@@ -1283,7 +1319,10 @@ static int override_release(char __user *release, int len)
69500 }
69501 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69502 snprintf(buf, len, "2.6.%u%s", v, rest);
69503- ret = copy_to_user(release, buf, len);
69504+ if (len > sizeof(buf))
69505+ ret = -EFAULT;
69506+ else
69507+ ret = copy_to_user(release, buf, len);
69508 }
69509 return ret;
69510 }
69511@@ -1337,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69512 return -EFAULT;
69513
69514 down_read(&uts_sem);
69515- error = __copy_to_user(&name->sysname, &utsname()->sysname,
69516+ error = __copy_to_user(name->sysname, &utsname()->sysname,
69517 __OLD_UTS_LEN);
69518 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69519- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69520+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
69521 __OLD_UTS_LEN);
69522 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69523- error |= __copy_to_user(&name->release, &utsname()->release,
69524+ error |= __copy_to_user(name->release, &utsname()->release,
69525 __OLD_UTS_LEN);
69526 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69527- error |= __copy_to_user(&name->version, &utsname()->version,
69528+ error |= __copy_to_user(name->version, &utsname()->version,
69529 __OLD_UTS_LEN);
69530 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69531- error |= __copy_to_user(&name->machine, &utsname()->machine,
69532+ error |= __copy_to_user(name->machine, &utsname()->machine,
69533 __OLD_UTS_LEN);
69534 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69535 up_read(&uts_sem);
69536@@ -2024,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69537 error = get_dumpable(me->mm);
69538 break;
69539 case PR_SET_DUMPABLE:
69540- if (arg2 < 0 || arg2 > 1) {
69541+ if (arg2 > 1) {
69542 error = -EINVAL;
69543 break;
69544 }
69545diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69546index 4ab1187..33f4f2b 100644
69547--- a/kernel/sysctl.c
69548+++ b/kernel/sysctl.c
69549@@ -91,7 +91,6 @@
69550
69551
69552 #if defined(CONFIG_SYSCTL)
69553-
69554 /* External variables not in a header file. */
69555 extern int sysctl_overcommit_memory;
69556 extern int sysctl_overcommit_ratio;
69557@@ -169,10 +168,13 @@ static int proc_taint(struct ctl_table *table, int write,
69558 void __user *buffer, size_t *lenp, loff_t *ppos);
69559 #endif
69560
69561-#ifdef CONFIG_PRINTK
69562 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69563 void __user *buffer, size_t *lenp, loff_t *ppos);
69564-#endif
69565+
69566+static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69567+ void __user *buffer, size_t *lenp, loff_t *ppos);
69568+static int proc_dostring_coredump(struct ctl_table *table, int write,
69569+ void __user *buffer, size_t *lenp, loff_t *ppos);
69570
69571 #ifdef CONFIG_MAGIC_SYSRQ
69572 /* Note: sysrq code uses it's own private copy */
69573@@ -196,6 +198,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69574
69575 #endif
69576
69577+extern struct ctl_table grsecurity_table[];
69578+
69579 static struct ctl_table kern_table[];
69580 static struct ctl_table vm_table[];
69581 static struct ctl_table fs_table[];
69582@@ -210,6 +214,20 @@ extern struct ctl_table epoll_table[];
69583 int sysctl_legacy_va_layout;
69584 #endif
69585
69586+#ifdef CONFIG_PAX_SOFTMODE
69587+static ctl_table pax_table[] = {
69588+ {
69589+ .procname = "softmode",
69590+ .data = &pax_softmode,
69591+ .maxlen = sizeof(unsigned int),
69592+ .mode = 0600,
69593+ .proc_handler = &proc_dointvec,
69594+ },
69595+
69596+ { }
69597+};
69598+#endif
69599+
69600 /* The default sysctl tables: */
69601
69602 static struct ctl_table sysctl_base_table[] = {
69603@@ -256,6 +274,22 @@ static int max_extfrag_threshold = 1000;
69604 #endif
69605
69606 static struct ctl_table kern_table[] = {
69607+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69608+ {
69609+ .procname = "grsecurity",
69610+ .mode = 0500,
69611+ .child = grsecurity_table,
69612+ },
69613+#endif
69614+
69615+#ifdef CONFIG_PAX_SOFTMODE
69616+ {
69617+ .procname = "pax",
69618+ .mode = 0500,
69619+ .child = pax_table,
69620+ },
69621+#endif
69622+
69623 {
69624 .procname = "sched_child_runs_first",
69625 .data = &sysctl_sched_child_runs_first,
69626@@ -410,7 +444,7 @@ static struct ctl_table kern_table[] = {
69627 .data = core_pattern,
69628 .maxlen = CORENAME_MAX_SIZE,
69629 .mode = 0644,
69630- .proc_handler = proc_dostring,
69631+ .proc_handler = proc_dostring_coredump,
69632 },
69633 {
69634 .procname = "core_pipe_limit",
69635@@ -540,7 +574,7 @@ static struct ctl_table kern_table[] = {
69636 .data = &modprobe_path,
69637 .maxlen = KMOD_PATH_LEN,
69638 .mode = 0644,
69639- .proc_handler = proc_dostring,
69640+ .proc_handler = proc_dostring_modpriv,
69641 },
69642 {
69643 .procname = "modules_disabled",
69644@@ -707,16 +741,20 @@ static struct ctl_table kern_table[] = {
69645 .extra1 = &zero,
69646 .extra2 = &one,
69647 },
69648+#endif
69649 {
69650 .procname = "kptr_restrict",
69651 .data = &kptr_restrict,
69652 .maxlen = sizeof(int),
69653 .mode = 0644,
69654 .proc_handler = proc_dointvec_minmax_sysadmin,
69655+#ifdef CONFIG_GRKERNSEC_HIDESYM
69656+ .extra1 = &two,
69657+#else
69658 .extra1 = &zero,
69659+#endif
69660 .extra2 = &two,
69661 },
69662-#endif
69663 {
69664 .procname = "ngroups_max",
69665 .data = &ngroups_max,
69666@@ -1215,6 +1253,13 @@ static struct ctl_table vm_table[] = {
69667 .proc_handler = proc_dointvec_minmax,
69668 .extra1 = &zero,
69669 },
69670+ {
69671+ .procname = "heap_stack_gap",
69672+ .data = &sysctl_heap_stack_gap,
69673+ .maxlen = sizeof(sysctl_heap_stack_gap),
69674+ .mode = 0644,
69675+ .proc_handler = proc_doulongvec_minmax,
69676+ },
69677 #else
69678 {
69679 .procname = "nr_trim_pages",
69680@@ -1498,7 +1543,7 @@ static struct ctl_table fs_table[] = {
69681 .data = &suid_dumpable,
69682 .maxlen = sizeof(int),
69683 .mode = 0644,
69684- .proc_handler = proc_dointvec_minmax,
69685+ .proc_handler = proc_dointvec_minmax_coredump,
69686 .extra1 = &zero,
69687 .extra2 = &two,
69688 },
69689@@ -1645,6 +1690,16 @@ int proc_dostring(struct ctl_table *table, int write,
69690 buffer, lenp, ppos);
69691 }
69692
69693+int proc_dostring_modpriv(struct ctl_table *table, int write,
69694+ void __user *buffer, size_t *lenp, loff_t *ppos)
69695+{
69696+ if (write && !capable(CAP_SYS_MODULE))
69697+ return -EPERM;
69698+
69699+ return _proc_do_string(table->data, table->maxlen, write,
69700+ buffer, lenp, ppos);
69701+}
69702+
69703 static size_t proc_skip_spaces(char **buf)
69704 {
69705 size_t ret;
69706@@ -1750,6 +1805,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69707 len = strlen(tmp);
69708 if (len > *size)
69709 len = *size;
69710+ if (len > sizeof(tmp))
69711+ len = sizeof(tmp);
69712 if (copy_to_user(*buf, tmp, len))
69713 return -EFAULT;
69714 *size -= len;
69715@@ -1942,7 +1999,6 @@ static int proc_taint(struct ctl_table *table, int write,
69716 return err;
69717 }
69718
69719-#ifdef CONFIG_PRINTK
69720 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69721 void __user *buffer, size_t *lenp, loff_t *ppos)
69722 {
69723@@ -1951,7 +2007,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69724
69725 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69726 }
69727-#endif
69728
69729 struct do_proc_dointvec_minmax_conv_param {
69730 int *min;
69731@@ -2009,6 +2064,34 @@ int proc_dointvec_minmax(struct ctl_table *table, int write,
69732 do_proc_dointvec_minmax_conv, &param);
69733 }
69734
69735+static void validate_coredump_safety(void)
69736+{
69737+ if (suid_dumpable == SUID_DUMPABLE_SAFE &&
69738+ core_pattern[0] != '/' && core_pattern[0] != '|') {
69739+ printk(KERN_WARNING "Unsafe core_pattern used with "\
69740+ "suid_dumpable=2. Pipe handler or fully qualified "\
69741+ "core dump path required.\n");
69742+ }
69743+}
69744+
69745+static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69746+ void __user *buffer, size_t *lenp, loff_t *ppos)
69747+{
69748+ int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69749+ if (!error)
69750+ validate_coredump_safety();
69751+ return error;
69752+}
69753+
69754+static int proc_dostring_coredump(struct ctl_table *table, int write,
69755+ void __user *buffer, size_t *lenp, loff_t *ppos)
69756+{
69757+ int error = proc_dostring(table, write, buffer, lenp, ppos);
69758+ if (!error)
69759+ validate_coredump_safety();
69760+ return error;
69761+}
69762+
69763 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
69764 void __user *buffer,
69765 size_t *lenp, loff_t *ppos,
69766@@ -2066,8 +2149,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69767 *i = val;
69768 } else {
69769 val = convdiv * (*i) / convmul;
69770- if (!first)
69771+ if (!first) {
69772 err = proc_put_char(&buffer, &left, '\t');
69773+ if (err)
69774+ break;
69775+ }
69776 err = proc_put_long(&buffer, &left, val, false);
69777 if (err)
69778 break;
69779@@ -2459,6 +2545,12 @@ int proc_dostring(struct ctl_table *table, int write,
69780 return -ENOSYS;
69781 }
69782
69783+int proc_dostring_modpriv(struct ctl_table *table, int write,
69784+ void __user *buffer, size_t *lenp, loff_t *ppos)
69785+{
69786+ return -ENOSYS;
69787+}
69788+
69789 int proc_dointvec(struct ctl_table *table, int write,
69790 void __user *buffer, size_t *lenp, loff_t *ppos)
69791 {
69792@@ -2515,5 +2607,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69793 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69794 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69795 EXPORT_SYMBOL(proc_dostring);
69796+EXPORT_SYMBOL(proc_dostring_modpriv);
69797 EXPORT_SYMBOL(proc_doulongvec_minmax);
69798 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69799diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69800index a650694..aaeeb20 100644
69801--- a/kernel/sysctl_binary.c
69802+++ b/kernel/sysctl_binary.c
69803@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69804 int i;
69805
69806 set_fs(KERNEL_DS);
69807- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69808+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69809 set_fs(old_fs);
69810 if (result < 0)
69811 goto out_kfree;
69812@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69813 }
69814
69815 set_fs(KERNEL_DS);
69816- result = vfs_write(file, buffer, str - buffer, &pos);
69817+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69818 set_fs(old_fs);
69819 if (result < 0)
69820 goto out_kfree;
69821@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69822 int i;
69823
69824 set_fs(KERNEL_DS);
69825- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69826+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69827 set_fs(old_fs);
69828 if (result < 0)
69829 goto out_kfree;
69830@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69831 }
69832
69833 set_fs(KERNEL_DS);
69834- result = vfs_write(file, buffer, str - buffer, &pos);
69835+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69836 set_fs(old_fs);
69837 if (result < 0)
69838 goto out_kfree;
69839@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69840 int i;
69841
69842 set_fs(KERNEL_DS);
69843- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69844+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69845 set_fs(old_fs);
69846 if (result < 0)
69847 goto out;
69848@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69849 __le16 dnaddr;
69850
69851 set_fs(KERNEL_DS);
69852- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69853+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69854 set_fs(old_fs);
69855 if (result < 0)
69856 goto out;
69857@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69858 le16_to_cpu(dnaddr) & 0x3ff);
69859
69860 set_fs(KERNEL_DS);
69861- result = vfs_write(file, buf, len, &pos);
69862+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69863 set_fs(old_fs);
69864 if (result < 0)
69865 goto out;
69866diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69867index e660464..c8b9e67 100644
69868--- a/kernel/taskstats.c
69869+++ b/kernel/taskstats.c
69870@@ -27,9 +27,12 @@
69871 #include <linux/cgroup.h>
69872 #include <linux/fs.h>
69873 #include <linux/file.h>
69874+#include <linux/grsecurity.h>
69875 #include <net/genetlink.h>
69876 #include <linux/atomic.h>
69877
69878+extern int gr_is_taskstats_denied(int pid);
69879+
69880 /*
69881 * Maximum length of a cpumask that can be specified in
69882 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69883@@ -556,6 +559,9 @@ err:
69884
69885 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69886 {
69887+ if (gr_is_taskstats_denied(current->pid))
69888+ return -EACCES;
69889+
69890 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69891 return cmd_attr_register_cpumask(info);
69892 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69893diff --git a/kernel/time.c b/kernel/time.c
69894index ba744cf..267b7c5 100644
69895--- a/kernel/time.c
69896+++ b/kernel/time.c
69897@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69898 return error;
69899
69900 if (tz) {
69901+ /* we log in do_settimeofday called below, so don't log twice
69902+ */
69903+ if (!tv)
69904+ gr_log_timechange();
69905+
69906 sys_tz = *tz;
69907 update_vsyscall_tz();
69908 if (firsttime) {
69909diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69910index aa27d39..34d221c 100644
69911--- a/kernel/time/alarmtimer.c
69912+++ b/kernel/time/alarmtimer.c
69913@@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
69914 struct platform_device *pdev;
69915 int error = 0;
69916 int i;
69917- struct k_clock alarm_clock = {
69918+ static struct k_clock alarm_clock = {
69919 .clock_getres = alarm_clock_getres,
69920 .clock_get = alarm_clock_get,
69921 .timer_create = alarm_timer_create,
69922diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69923index f113755..ec24223 100644
69924--- a/kernel/time/tick-broadcast.c
69925+++ b/kernel/time/tick-broadcast.c
69926@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69927 * then clear the broadcast bit.
69928 */
69929 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69930- int cpu = smp_processor_id();
69931+ cpu = smp_processor_id();
69932
69933 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69934 tick_broadcast_clear_oneshot(cpu);
69935diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69936index 3447cfa..291806b 100644
69937--- a/kernel/time/timekeeping.c
69938+++ b/kernel/time/timekeeping.c
69939@@ -14,6 +14,7 @@
69940 #include <linux/init.h>
69941 #include <linux/mm.h>
69942 #include <linux/sched.h>
69943+#include <linux/grsecurity.h>
69944 #include <linux/syscore_ops.h>
69945 #include <linux/clocksource.h>
69946 #include <linux/jiffies.h>
69947@@ -387,6 +388,8 @@ int do_settimeofday(const struct timespec *tv)
69948 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69949 return -EINVAL;
69950
69951+ gr_log_timechange();
69952+
69953 write_seqlock_irqsave(&timekeeper.lock, flags);
69954
69955 timekeeping_forward_now();
69956diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69957index 3258455..f35227d 100644
69958--- a/kernel/time/timer_list.c
69959+++ b/kernel/time/timer_list.c
69960@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69961
69962 static void print_name_offset(struct seq_file *m, void *sym)
69963 {
69964+#ifdef CONFIG_GRKERNSEC_HIDESYM
69965+ SEQ_printf(m, "<%p>", NULL);
69966+#else
69967 char symname[KSYM_NAME_LEN];
69968
69969 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
69970 SEQ_printf(m, "<%pK>", sym);
69971 else
69972 SEQ_printf(m, "%s", symname);
69973+#endif
69974 }
69975
69976 static void
69977@@ -112,7 +116,11 @@ next_one:
69978 static void
69979 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
69980 {
69981+#ifdef CONFIG_GRKERNSEC_HIDESYM
69982+ SEQ_printf(m, " .base: %p\n", NULL);
69983+#else
69984 SEQ_printf(m, " .base: %pK\n", base);
69985+#endif
69986 SEQ_printf(m, " .index: %d\n",
69987 base->index);
69988 SEQ_printf(m, " .resolution: %Lu nsecs\n",
69989@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
69990 {
69991 struct proc_dir_entry *pe;
69992
69993+#ifdef CONFIG_GRKERNSEC_PROC_ADD
69994+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
69995+#else
69996 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
69997+#endif
69998 if (!pe)
69999 return -ENOMEM;
70000 return 0;
70001diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70002index 0b537f2..9e71eca 100644
70003--- a/kernel/time/timer_stats.c
70004+++ b/kernel/time/timer_stats.c
70005@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70006 static unsigned long nr_entries;
70007 static struct entry entries[MAX_ENTRIES];
70008
70009-static atomic_t overflow_count;
70010+static atomic_unchecked_t overflow_count;
70011
70012 /*
70013 * The entries are in a hash-table, for fast lookup:
70014@@ -140,7 +140,7 @@ static void reset_entries(void)
70015 nr_entries = 0;
70016 memset(entries, 0, sizeof(entries));
70017 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70018- atomic_set(&overflow_count, 0);
70019+ atomic_set_unchecked(&overflow_count, 0);
70020 }
70021
70022 static struct entry *alloc_entry(void)
70023@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70024 if (likely(entry))
70025 entry->count++;
70026 else
70027- atomic_inc(&overflow_count);
70028+ atomic_inc_unchecked(&overflow_count);
70029
70030 out_unlock:
70031 raw_spin_unlock_irqrestore(lock, flags);
70032@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70033
70034 static void print_name_offset(struct seq_file *m, unsigned long addr)
70035 {
70036+#ifdef CONFIG_GRKERNSEC_HIDESYM
70037+ seq_printf(m, "<%p>", NULL);
70038+#else
70039 char symname[KSYM_NAME_LEN];
70040
70041 if (lookup_symbol_name(addr, symname) < 0)
70042 seq_printf(m, "<%p>", (void *)addr);
70043 else
70044 seq_printf(m, "%s", symname);
70045+#endif
70046 }
70047
70048 static int tstats_show(struct seq_file *m, void *v)
70049@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70050
70051 seq_puts(m, "Timer Stats Version: v0.2\n");
70052 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70053- if (atomic_read(&overflow_count))
70054+ if (atomic_read_unchecked(&overflow_count))
70055 seq_printf(m, "Overflow: %d entries\n",
70056- atomic_read(&overflow_count));
70057+ atomic_read_unchecked(&overflow_count));
70058
70059 for (i = 0; i < nr_entries; i++) {
70060 entry = entries + i;
70061@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70062 {
70063 struct proc_dir_entry *pe;
70064
70065+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70066+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70067+#else
70068 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70069+#endif
70070 if (!pe)
70071 return -ENOMEM;
70072 return 0;
70073diff --git a/kernel/timer.c b/kernel/timer.c
70074index 6ec7e7e..cbc448b 100644
70075--- a/kernel/timer.c
70076+++ b/kernel/timer.c
70077@@ -1362,7 +1362,7 @@ void update_process_times(int user_tick)
70078 /*
70079 * This function runs timers and the timer-tq in bottom half context.
70080 */
70081-static void run_timer_softirq(struct softirq_action *h)
70082+static void run_timer_softirq(void)
70083 {
70084 struct tvec_base *base = __this_cpu_read(tvec_bases);
70085
70086diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70087index c0bd030..62a1927 100644
70088--- a/kernel/trace/blktrace.c
70089+++ b/kernel/trace/blktrace.c
70090@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70091 struct blk_trace *bt = filp->private_data;
70092 char buf[16];
70093
70094- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70095+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70096
70097 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70098 }
70099@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70100 return 1;
70101
70102 bt = buf->chan->private_data;
70103- atomic_inc(&bt->dropped);
70104+ atomic_inc_unchecked(&bt->dropped);
70105 return 0;
70106 }
70107
70108@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70109
70110 bt->dir = dir;
70111 bt->dev = dev;
70112- atomic_set(&bt->dropped, 0);
70113+ atomic_set_unchecked(&bt->dropped, 0);
70114
70115 ret = -EIO;
70116 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70117diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70118index a008663..d363254 100644
70119--- a/kernel/trace/ftrace.c
70120+++ b/kernel/trace/ftrace.c
70121@@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70122 if (unlikely(ftrace_disabled))
70123 return 0;
70124
70125+ ret = ftrace_arch_code_modify_prepare();
70126+ FTRACE_WARN_ON(ret);
70127+ if (ret)
70128+ return 0;
70129+
70130 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70131+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70132 if (ret) {
70133 ftrace_bug(ret, ip);
70134- return 0;
70135 }
70136- return 1;
70137+ return ret ? 0 : 1;
70138 }
70139
70140 /*
70141@@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70142
70143 int
70144 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70145- void *data)
70146+ void *data)
70147 {
70148 struct ftrace_func_probe *entry;
70149 struct ftrace_page *pg;
70150diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70151index a7fa070..403bc8d 100644
70152--- a/kernel/trace/trace.c
70153+++ b/kernel/trace/trace.c
70154@@ -4421,10 +4421,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70155 };
70156 #endif
70157
70158-static struct dentry *d_tracer;
70159-
70160 struct dentry *tracing_init_dentry(void)
70161 {
70162+ static struct dentry *d_tracer;
70163 static int once;
70164
70165 if (d_tracer)
70166@@ -4444,10 +4443,9 @@ struct dentry *tracing_init_dentry(void)
70167 return d_tracer;
70168 }
70169
70170-static struct dentry *d_percpu;
70171-
70172 struct dentry *tracing_dentry_percpu(void)
70173 {
70174+ static struct dentry *d_percpu;
70175 static int once;
70176 struct dentry *d_tracer;
70177
70178diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70179index 29111da..d190fe2 100644
70180--- a/kernel/trace/trace_events.c
70181+++ b/kernel/trace/trace_events.c
70182@@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70183 struct ftrace_module_file_ops {
70184 struct list_head list;
70185 struct module *mod;
70186- struct file_operations id;
70187- struct file_operations enable;
70188- struct file_operations format;
70189- struct file_operations filter;
70190 };
70191
70192 static struct ftrace_module_file_ops *
70193@@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70194
70195 file_ops->mod = mod;
70196
70197- file_ops->id = ftrace_event_id_fops;
70198- file_ops->id.owner = mod;
70199-
70200- file_ops->enable = ftrace_enable_fops;
70201- file_ops->enable.owner = mod;
70202-
70203- file_ops->filter = ftrace_event_filter_fops;
70204- file_ops->filter.owner = mod;
70205-
70206- file_ops->format = ftrace_event_format_fops;
70207- file_ops->format.owner = mod;
70208+ pax_open_kernel();
70209+ *(void **)&mod->trace_id.owner = mod;
70210+ *(void **)&mod->trace_enable.owner = mod;
70211+ *(void **)&mod->trace_filter.owner = mod;
70212+ *(void **)&mod->trace_format.owner = mod;
70213+ pax_close_kernel();
70214
70215 list_add(&file_ops->list, &ftrace_module_file_list);
70216
70217@@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70218
70219 for_each_event(call, start, end) {
70220 __trace_add_event_call(*call, mod,
70221- &file_ops->id, &file_ops->enable,
70222- &file_ops->filter, &file_ops->format);
70223+ &mod->trace_id, &mod->trace_enable,
70224+ &mod->trace_filter, &mod->trace_format);
70225 }
70226 }
70227
70228diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70229index fd3c8aa..5f324a6 100644
70230--- a/kernel/trace/trace_mmiotrace.c
70231+++ b/kernel/trace/trace_mmiotrace.c
70232@@ -24,7 +24,7 @@ struct header_iter {
70233 static struct trace_array *mmio_trace_array;
70234 static bool overrun_detected;
70235 static unsigned long prev_overruns;
70236-static atomic_t dropped_count;
70237+static atomic_unchecked_t dropped_count;
70238
70239 static void mmio_reset_data(struct trace_array *tr)
70240 {
70241@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70242
70243 static unsigned long count_overruns(struct trace_iterator *iter)
70244 {
70245- unsigned long cnt = atomic_xchg(&dropped_count, 0);
70246+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70247 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70248
70249 if (over > prev_overruns)
70250@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70251 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70252 sizeof(*entry), 0, pc);
70253 if (!event) {
70254- atomic_inc(&dropped_count);
70255+ atomic_inc_unchecked(&dropped_count);
70256 return;
70257 }
70258 entry = ring_buffer_event_data(event);
70259@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70260 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70261 sizeof(*entry), 0, pc);
70262 if (!event) {
70263- atomic_inc(&dropped_count);
70264+ atomic_inc_unchecked(&dropped_count);
70265 return;
70266 }
70267 entry = ring_buffer_event_data(event);
70268diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70269index df611a0..10d8b32 100644
70270--- a/kernel/trace/trace_output.c
70271+++ b/kernel/trace/trace_output.c
70272@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
70273
70274 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70275 if (!IS_ERR(p)) {
70276- p = mangle_path(s->buffer + s->len, p, "\n");
70277+ p = mangle_path(s->buffer + s->len, p, "\n\\");
70278 if (p) {
70279 s->len = p - s->buffer;
70280 return 1;
70281diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70282index d4545f4..a9010a1 100644
70283--- a/kernel/trace/trace_stack.c
70284+++ b/kernel/trace/trace_stack.c
70285@@ -53,7 +53,7 @@ static inline void check_stack(void)
70286 return;
70287
70288 /* we do not handle interrupt stacks yet */
70289- if (!object_is_on_stack(&this_size))
70290+ if (!object_starts_on_stack(&this_size))
70291 return;
70292
70293 local_irq_save(flags);
70294diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70295index ff5bdee..3eaeba6 100644
70296--- a/lib/Kconfig.debug
70297+++ b/lib/Kconfig.debug
70298@@ -1165,6 +1165,7 @@ config LATENCYTOP
70299 depends on DEBUG_KERNEL
70300 depends on STACKTRACE_SUPPORT
70301 depends on PROC_FS
70302+ depends on !GRKERNSEC_HIDESYM
70303 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
70304 select KALLSYMS
70305 select KALLSYMS_ALL
70306diff --git a/lib/bitmap.c b/lib/bitmap.c
70307index 06fdfa1..97c5c7d 100644
70308--- a/lib/bitmap.c
70309+++ b/lib/bitmap.c
70310@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
70311 {
70312 int c, old_c, totaldigits, ndigits, nchunks, nbits;
70313 u32 chunk;
70314- const char __user __force *ubuf = (const char __user __force *)buf;
70315+ const char __user *ubuf = (const char __force_user *)buf;
70316
70317 bitmap_zero(maskp, nmaskbits);
70318
70319@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
70320 {
70321 if (!access_ok(VERIFY_READ, ubuf, ulen))
70322 return -EFAULT;
70323- return __bitmap_parse((const char __force *)ubuf,
70324+ return __bitmap_parse((const char __force_kernel *)ubuf,
70325 ulen, 1, maskp, nmaskbits);
70326
70327 }
70328@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
70329 {
70330 unsigned a, b;
70331 int c, old_c, totaldigits;
70332- const char __user __force *ubuf = (const char __user __force *)buf;
70333+ const char __user *ubuf = (const char __force_user *)buf;
70334 int exp_digit, in_range;
70335
70336 totaldigits = c = 0;
70337@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
70338 {
70339 if (!access_ok(VERIFY_READ, ubuf, ulen))
70340 return -EFAULT;
70341- return __bitmap_parselist((const char __force *)ubuf,
70342+ return __bitmap_parselist((const char __force_kernel *)ubuf,
70343 ulen, 1, maskp, nmaskbits);
70344 }
70345 EXPORT_SYMBOL(bitmap_parselist_user);
70346diff --git a/lib/bug.c b/lib/bug.c
70347index a28c141..2bd3d95 100644
70348--- a/lib/bug.c
70349+++ b/lib/bug.c
70350@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
70351 return BUG_TRAP_TYPE_NONE;
70352
70353 bug = find_bug(bugaddr);
70354+ if (!bug)
70355+ return BUG_TRAP_TYPE_NONE;
70356
70357 file = NULL;
70358 line = 0;
70359diff --git a/lib/debugobjects.c b/lib/debugobjects.c
70360index d11808c..dc2d6f8 100644
70361--- a/lib/debugobjects.c
70362+++ b/lib/debugobjects.c
70363@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
70364 if (limit > 4)
70365 return;
70366
70367- is_on_stack = object_is_on_stack(addr);
70368+ is_on_stack = object_starts_on_stack(addr);
70369 if (is_on_stack == onstack)
70370 return;
70371
70372diff --git a/lib/devres.c b/lib/devres.c
70373index 80b9c76..9e32279 100644
70374--- a/lib/devres.c
70375+++ b/lib/devres.c
70376@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
70377 void devm_iounmap(struct device *dev, void __iomem *addr)
70378 {
70379 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
70380- (void *)addr));
70381+ (void __force *)addr));
70382 iounmap(addr);
70383 }
70384 EXPORT_SYMBOL(devm_iounmap);
70385@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70386 {
70387 ioport_unmap(addr);
70388 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70389- devm_ioport_map_match, (void *)addr));
70390+ devm_ioport_map_match, (void __force *)addr));
70391 }
70392 EXPORT_SYMBOL(devm_ioport_unmap);
70393
70394diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70395index 66ce414..6f0a0dd 100644
70396--- a/lib/dma-debug.c
70397+++ b/lib/dma-debug.c
70398@@ -924,7 +924,7 @@ out:
70399
70400 static void check_for_stack(struct device *dev, void *addr)
70401 {
70402- if (object_is_on_stack(addr))
70403+ if (object_starts_on_stack(addr))
70404 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70405 "stack [addr=%p]\n", addr);
70406 }
70407diff --git a/lib/extable.c b/lib/extable.c
70408index 4cac81e..4d66cfc 100644
70409--- a/lib/extable.c
70410+++ b/lib/extable.c
70411@@ -13,6 +13,7 @@
70412 #include <linux/init.h>
70413 #include <linux/sort.h>
70414 #include <asm/uaccess.h>
70415+#include <asm/pgtable.h>
70416
70417 #ifndef ARCH_HAS_SORT_EXTABLE
70418 /*
70419diff --git a/lib/inflate.c b/lib/inflate.c
70420index 013a761..c28f3fc 100644
70421--- a/lib/inflate.c
70422+++ b/lib/inflate.c
70423@@ -269,7 +269,7 @@ static void free(void *where)
70424 malloc_ptr = free_mem_ptr;
70425 }
70426 #else
70427-#define malloc(a) kmalloc(a, GFP_KERNEL)
70428+#define malloc(a) kmalloc((a), GFP_KERNEL)
70429 #define free(a) kfree(a)
70430 #endif
70431
70432diff --git a/lib/ioremap.c b/lib/ioremap.c
70433index 0c9216c..863bd89 100644
70434--- a/lib/ioremap.c
70435+++ b/lib/ioremap.c
70436@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
70437 unsigned long next;
70438
70439 phys_addr -= addr;
70440- pmd = pmd_alloc(&init_mm, pud, addr);
70441+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
70442 if (!pmd)
70443 return -ENOMEM;
70444 do {
70445@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
70446 unsigned long next;
70447
70448 phys_addr -= addr;
70449- pud = pud_alloc(&init_mm, pgd, addr);
70450+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
70451 if (!pud)
70452 return -ENOMEM;
70453 do {
70454diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70455index bd2bea9..6b3c95e 100644
70456--- a/lib/is_single_threaded.c
70457+++ b/lib/is_single_threaded.c
70458@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70459 struct task_struct *p, *t;
70460 bool ret;
70461
70462+ if (!mm)
70463+ return true;
70464+
70465 if (atomic_read(&task->signal->live) != 1)
70466 return false;
70467
70468diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70469index e796429..6e38f9f 100644
70470--- a/lib/radix-tree.c
70471+++ b/lib/radix-tree.c
70472@@ -92,7 +92,7 @@ struct radix_tree_preload {
70473 int nr;
70474 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
70475 };
70476-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70477+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70478
70479 static inline void *ptr_to_indirect(void *ptr)
70480 {
70481diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70482index c3f36d41..5c5aeb5 100644
70483--- a/lib/vsprintf.c
70484+++ b/lib/vsprintf.c
70485@@ -16,6 +16,9 @@
70486 * - scnprintf and vscnprintf
70487 */
70488
70489+#ifdef CONFIG_GRKERNSEC_HIDESYM
70490+#define __INCLUDED_BY_HIDESYM 1
70491+#endif
70492 #include <stdarg.h>
70493 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
70494 #include <linux/types.h>
70495@@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70496 char sym[KSYM_SYMBOL_LEN];
70497 if (ext == 'B')
70498 sprint_backtrace(sym, value);
70499- else if (ext != 'f' && ext != 's')
70500+ else if (ext != 'f' && ext != 's' && ext != 'a')
70501 sprint_symbol(sym, value);
70502 else
70503 sprint_symbol_no_offset(sym, value);
70504@@ -912,7 +915,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70505 return number(buf, end, *(const netdev_features_t *)addr, spec);
70506 }
70507
70508+#ifdef CONFIG_GRKERNSEC_HIDESYM
70509+int kptr_restrict __read_mostly = 2;
70510+#else
70511 int kptr_restrict __read_mostly;
70512+#endif
70513
70514 /*
70515 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70516@@ -926,6 +933,8 @@ int kptr_restrict __read_mostly;
70517 * - 'S' For symbolic direct pointers with offset
70518 * - 's' For symbolic direct pointers without offset
70519 * - 'B' For backtraced symbolic direct pointers with offset
70520+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70521+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70522 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70523 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70524 * - 'M' For a 6-byte MAC address, it prints the address in the
70525@@ -973,12 +982,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70526
70527 if (!ptr && *fmt != 'K') {
70528 /*
70529- * Print (null) with the same width as a pointer so it makes
70530+ * Print (nil) with the same width as a pointer so it makes
70531 * tabular output look nice.
70532 */
70533 if (spec.field_width == -1)
70534 spec.field_width = default_width;
70535- return string(buf, end, "(null)", spec);
70536+ return string(buf, end, "(nil)", spec);
70537 }
70538
70539 switch (*fmt) {
70540@@ -988,6 +997,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70541 /* Fallthrough */
70542 case 'S':
70543 case 's':
70544+#ifdef CONFIG_GRKERNSEC_HIDESYM
70545+ break;
70546+#else
70547+ return symbol_string(buf, end, ptr, spec, *fmt);
70548+#endif
70549+ case 'A':
70550+ case 'a':
70551 case 'B':
70552 return symbol_string(buf, end, ptr, spec, *fmt);
70553 case 'R':
70554@@ -1025,12 +1041,15 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70555 va_end(va);
70556 return buf;
70557 }
70558+ case 'P':
70559+ break;
70560 case 'K':
70561 /*
70562 * %pK cannot be used in IRQ context because its test
70563 * for CAP_SYSLOG would be meaningless.
70564 */
70565- if (in_irq() || in_serving_softirq() || in_nmi()) {
70566+ if (kptr_restrict && (in_irq() || in_serving_softirq() ||
70567+ in_nmi())) {
70568 if (spec.field_width == -1)
70569 spec.field_width = default_width;
70570 return string(buf, end, "pK-error", spec);
70571@@ -1047,6 +1066,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70572 }
70573 break;
70574 }
70575+
70576+#ifdef CONFIG_GRKERNSEC_HIDESYM
70577+ /* 'P' = approved pointers to copy to userland,
70578+ as in the /proc/kallsyms case, as we make it display nothing
70579+ for non-root users, and the real contents for root users
70580+ Also ignore 'K' pointers, since we force their NULLing for non-root users
70581+ above
70582+ */
70583+ if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
70584+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
70585+ dump_stack();
70586+ ptr = NULL;
70587+ }
70588+#endif
70589+
70590 spec.flags |= SMALL;
70591 if (spec.field_width == -1) {
70592 spec.field_width = default_width;
70593@@ -1758,11 +1792,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70594 typeof(type) value; \
70595 if (sizeof(type) == 8) { \
70596 args = PTR_ALIGN(args, sizeof(u32)); \
70597- *(u32 *)&value = *(u32 *)args; \
70598- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70599+ *(u32 *)&value = *(const u32 *)args; \
70600+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70601 } else { \
70602 args = PTR_ALIGN(args, sizeof(type)); \
70603- value = *(typeof(type) *)args; \
70604+ value = *(const typeof(type) *)args; \
70605 } \
70606 args += sizeof(type); \
70607 value; \
70608@@ -1825,7 +1859,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70609 case FORMAT_TYPE_STR: {
70610 const char *str_arg = args;
70611 args += strlen(str_arg) + 1;
70612- str = string(str, end, (char *)str_arg, spec);
70613+ str = string(str, end, str_arg, spec);
70614 break;
70615 }
70616
70617diff --git a/localversion-grsec b/localversion-grsec
70618new file mode 100644
70619index 0000000..7cd6065
70620--- /dev/null
70621+++ b/localversion-grsec
70622@@ -0,0 +1 @@
70623+-grsec
70624diff --git a/mm/Kconfig b/mm/Kconfig
70625index 82fed4e..979e814 100644
70626--- a/mm/Kconfig
70627+++ b/mm/Kconfig
70628@@ -247,10 +247,10 @@ config KSM
70629 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70630
70631 config DEFAULT_MMAP_MIN_ADDR
70632- int "Low address space to protect from user allocation"
70633+ int "Low address space to protect from user allocation"
70634 depends on MMU
70635- default 4096
70636- help
70637+ default 65536
70638+ help
70639 This is the portion of low virtual memory which should be protected
70640 from userspace allocation. Keeping a user from writing to low pages
70641 can help reduce the impact of kernel NULL pointer bugs.
70642@@ -280,7 +280,7 @@ config MEMORY_FAILURE
70643
70644 config HWPOISON_INJECT
70645 tristate "HWPoison pages injector"
70646- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
70647+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
70648 select PROC_PAGE_MONITOR
70649
70650 config NOMMU_INITIAL_TRIM_EXCESS
70651diff --git a/mm/filemap.c b/mm/filemap.c
70652index a4a5260..6151dc5 100644
70653--- a/mm/filemap.c
70654+++ b/mm/filemap.c
70655@@ -1723,7 +1723,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70656 struct address_space *mapping = file->f_mapping;
70657
70658 if (!mapping->a_ops->readpage)
70659- return -ENOEXEC;
70660+ return -ENODEV;
70661 file_accessed(file);
70662 vma->vm_ops = &generic_file_vm_ops;
70663 vma->vm_flags |= VM_CAN_NONLINEAR;
70664@@ -2064,6 +2064,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70665 *pos = i_size_read(inode);
70666
70667 if (limit != RLIM_INFINITY) {
70668+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70669 if (*pos >= limit) {
70670 send_sig(SIGXFSZ, current, 0);
70671 return -EFBIG;
70672diff --git a/mm/fremap.c b/mm/fremap.c
70673index 9ed4fd4..c42648d 100644
70674--- a/mm/fremap.c
70675+++ b/mm/fremap.c
70676@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70677 retry:
70678 vma = find_vma(mm, start);
70679
70680+#ifdef CONFIG_PAX_SEGMEXEC
70681+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70682+ goto out;
70683+#endif
70684+
70685 /*
70686 * Make sure the vma is shared, that it supports prefaulting,
70687 * and that the remapped range is valid and fully within
70688diff --git a/mm/highmem.c b/mm/highmem.c
70689index 57d82c6..e9e0552 100644
70690--- a/mm/highmem.c
70691+++ b/mm/highmem.c
70692@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70693 * So no dangers, even with speculative execution.
70694 */
70695 page = pte_page(pkmap_page_table[i]);
70696+ pax_open_kernel();
70697 pte_clear(&init_mm, (unsigned long)page_address(page),
70698 &pkmap_page_table[i]);
70699-
70700+ pax_close_kernel();
70701 set_page_address(page, NULL);
70702 need_flush = 1;
70703 }
70704@@ -186,9 +187,11 @@ start:
70705 }
70706 }
70707 vaddr = PKMAP_ADDR(last_pkmap_nr);
70708+
70709+ pax_open_kernel();
70710 set_pte_at(&init_mm, vaddr,
70711 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70712-
70713+ pax_close_kernel();
70714 pkmap_count[last_pkmap_nr] = 1;
70715 set_page_address(page, (void *)vaddr);
70716
70717diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70718index 57c4b93..24b8f59 100644
70719--- a/mm/huge_memory.c
70720+++ b/mm/huge_memory.c
70721@@ -735,7 +735,7 @@ out:
70722 * run pte_offset_map on the pmd, if an huge pmd could
70723 * materialize from under us from a different thread.
70724 */
70725- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70726+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70727 return VM_FAULT_OOM;
70728 /* if an huge pmd materialized from under us just retry later */
70729 if (unlikely(pmd_trans_huge(*pmd)))
70730diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70731index e198831..38d524f 100644
70732--- a/mm/hugetlb.c
70733+++ b/mm/hugetlb.c
70734@@ -2447,6 +2447,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70735 return 1;
70736 }
70737
70738+#ifdef CONFIG_PAX_SEGMEXEC
70739+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70740+{
70741+ struct mm_struct *mm = vma->vm_mm;
70742+ struct vm_area_struct *vma_m;
70743+ unsigned long address_m;
70744+ pte_t *ptep_m;
70745+
70746+ vma_m = pax_find_mirror_vma(vma);
70747+ if (!vma_m)
70748+ return;
70749+
70750+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70751+ address_m = address + SEGMEXEC_TASK_SIZE;
70752+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70753+ get_page(page_m);
70754+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
70755+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70756+}
70757+#endif
70758+
70759 /*
70760 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70761 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70762@@ -2559,6 +2580,11 @@ retry_avoidcopy:
70763 make_huge_pte(vma, new_page, 1));
70764 page_remove_rmap(old_page);
70765 hugepage_add_new_anon_rmap(new_page, vma, address);
70766+
70767+#ifdef CONFIG_PAX_SEGMEXEC
70768+ pax_mirror_huge_pte(vma, address, new_page);
70769+#endif
70770+
70771 /* Make the old page be freed below */
70772 new_page = old_page;
70773 mmu_notifier_invalidate_range_end(mm,
70774@@ -2713,6 +2739,10 @@ retry:
70775 && (vma->vm_flags & VM_SHARED)));
70776 set_huge_pte_at(mm, address, ptep, new_pte);
70777
70778+#ifdef CONFIG_PAX_SEGMEXEC
70779+ pax_mirror_huge_pte(vma, address, page);
70780+#endif
70781+
70782 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70783 /* Optimization, do the COW without a second fault */
70784 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70785@@ -2742,6 +2772,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70786 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70787 struct hstate *h = hstate_vma(vma);
70788
70789+#ifdef CONFIG_PAX_SEGMEXEC
70790+ struct vm_area_struct *vma_m;
70791+#endif
70792+
70793 address &= huge_page_mask(h);
70794
70795 ptep = huge_pte_offset(mm, address);
70796@@ -2755,6 +2789,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70797 VM_FAULT_SET_HINDEX(h - hstates);
70798 }
70799
70800+#ifdef CONFIG_PAX_SEGMEXEC
70801+ vma_m = pax_find_mirror_vma(vma);
70802+ if (vma_m) {
70803+ unsigned long address_m;
70804+
70805+ if (vma->vm_start > vma_m->vm_start) {
70806+ address_m = address;
70807+ address -= SEGMEXEC_TASK_SIZE;
70808+ vma = vma_m;
70809+ h = hstate_vma(vma);
70810+ } else
70811+ address_m = address + SEGMEXEC_TASK_SIZE;
70812+
70813+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70814+ return VM_FAULT_OOM;
70815+ address_m &= HPAGE_MASK;
70816+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70817+ }
70818+#endif
70819+
70820 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70821 if (!ptep)
70822 return VM_FAULT_OOM;
70823diff --git a/mm/internal.h b/mm/internal.h
70824index 2ba87fb..7f451e2 100644
70825--- a/mm/internal.h
70826+++ b/mm/internal.h
70827@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70828 * in mm/page_alloc.c
70829 */
70830 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70831+extern void free_compound_page(struct page *page);
70832 extern void prep_compound_page(struct page *page, unsigned long order);
70833 #ifdef CONFIG_MEMORY_FAILURE
70834 extern bool is_free_buddy_page(struct page *page);
70835diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70836index 45eb621..6ccd8ea 100644
70837--- a/mm/kmemleak.c
70838+++ b/mm/kmemleak.c
70839@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70840
70841 for (i = 0; i < object->trace_len; i++) {
70842 void *ptr = (void *)object->trace[i];
70843- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70844+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70845 }
70846 }
70847
70848diff --git a/mm/maccess.c b/mm/maccess.c
70849index d53adf9..03a24bf 100644
70850--- a/mm/maccess.c
70851+++ b/mm/maccess.c
70852@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70853 set_fs(KERNEL_DS);
70854 pagefault_disable();
70855 ret = __copy_from_user_inatomic(dst,
70856- (__force const void __user *)src, size);
70857+ (const void __force_user *)src, size);
70858 pagefault_enable();
70859 set_fs(old_fs);
70860
70861@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70862
70863 set_fs(KERNEL_DS);
70864 pagefault_disable();
70865- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70866+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70867 pagefault_enable();
70868 set_fs(old_fs);
70869
70870diff --git a/mm/madvise.c b/mm/madvise.c
70871index 14d260f..b2a80fd 100644
70872--- a/mm/madvise.c
70873+++ b/mm/madvise.c
70874@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70875 pgoff_t pgoff;
70876 unsigned long new_flags = vma->vm_flags;
70877
70878+#ifdef CONFIG_PAX_SEGMEXEC
70879+ struct vm_area_struct *vma_m;
70880+#endif
70881+
70882 switch (behavior) {
70883 case MADV_NORMAL:
70884 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70885@@ -119,6 +123,13 @@ success:
70886 /*
70887 * vm_flags is protected by the mmap_sem held in write mode.
70888 */
70889+
70890+#ifdef CONFIG_PAX_SEGMEXEC
70891+ vma_m = pax_find_mirror_vma(vma);
70892+ if (vma_m)
70893+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70894+#endif
70895+
70896 vma->vm_flags = new_flags;
70897
70898 out:
70899@@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70900 struct vm_area_struct ** prev,
70901 unsigned long start, unsigned long end)
70902 {
70903+
70904+#ifdef CONFIG_PAX_SEGMEXEC
70905+ struct vm_area_struct *vma_m;
70906+#endif
70907+
70908 *prev = vma;
70909 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70910 return -EINVAL;
70911@@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70912 zap_page_range(vma, start, end - start, &details);
70913 } else
70914 zap_page_range(vma, start, end - start, NULL);
70915+
70916+#ifdef CONFIG_PAX_SEGMEXEC
70917+ vma_m = pax_find_mirror_vma(vma);
70918+ if (vma_m) {
70919+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70920+ struct zap_details details = {
70921+ .nonlinear_vma = vma_m,
70922+ .last_index = ULONG_MAX,
70923+ };
70924+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70925+ } else
70926+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70927+ }
70928+#endif
70929+
70930 return 0;
70931 }
70932
70933@@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70934 if (end < start)
70935 goto out;
70936
70937+#ifdef CONFIG_PAX_SEGMEXEC
70938+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70939+ if (end > SEGMEXEC_TASK_SIZE)
70940+ goto out;
70941+ } else
70942+#endif
70943+
70944+ if (end > TASK_SIZE)
70945+ goto out;
70946+
70947 error = 0;
70948 if (end == start)
70949 goto out;
70950diff --git a/mm/memory-failure.c b/mm/memory-failure.c
70951index ab1e714..415de01 100644
70952--- a/mm/memory-failure.c
70953+++ b/mm/memory-failure.c
70954@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
70955
70956 int sysctl_memory_failure_recovery __read_mostly = 1;
70957
70958-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70959+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70960
70961 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
70962
70963@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
70964 pfn, t->comm, t->pid);
70965 si.si_signo = SIGBUS;
70966 si.si_errno = 0;
70967- si.si_addr = (void *)addr;
70968+ si.si_addr = (void __user *)addr;
70969 #ifdef __ARCH_SI_TRAPNO
70970 si.si_trapno = trapno;
70971 #endif
70972@@ -1036,7 +1036,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
70973 }
70974
70975 nr_pages = 1 << compound_trans_order(hpage);
70976- atomic_long_add(nr_pages, &mce_bad_pages);
70977+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
70978
70979 /*
70980 * We need/can do nothing about count=0 pages.
70981@@ -1066,7 +1066,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
70982 if (!PageHWPoison(hpage)
70983 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
70984 || (p != hpage && TestSetPageHWPoison(hpage))) {
70985- atomic_long_sub(nr_pages, &mce_bad_pages);
70986+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70987 return 0;
70988 }
70989 set_page_hwpoison_huge_page(hpage);
70990@@ -1124,7 +1124,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
70991 }
70992 if (hwpoison_filter(p)) {
70993 if (TestClearPageHWPoison(p))
70994- atomic_long_sub(nr_pages, &mce_bad_pages);
70995+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70996 unlock_page(hpage);
70997 put_page(hpage);
70998 return 0;
70999@@ -1319,7 +1319,7 @@ int unpoison_memory(unsigned long pfn)
71000 return 0;
71001 }
71002 if (TestClearPageHWPoison(p))
71003- atomic_long_sub(nr_pages, &mce_bad_pages);
71004+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71005 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71006 return 0;
71007 }
71008@@ -1333,7 +1333,7 @@ int unpoison_memory(unsigned long pfn)
71009 */
71010 if (TestClearPageHWPoison(page)) {
71011 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71012- atomic_long_sub(nr_pages, &mce_bad_pages);
71013+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71014 freeit = 1;
71015 if (PageHuge(page))
71016 clear_page_hwpoison_huge_page(page);
71017@@ -1446,7 +1446,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71018 }
71019 done:
71020 if (!PageHWPoison(hpage))
71021- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
71022+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
71023 set_page_hwpoison_huge_page(hpage);
71024 dequeue_hwpoisoned_huge_page(hpage);
71025 /* keep elevated page count for bad page */
71026@@ -1577,7 +1577,7 @@ int soft_offline_page(struct page *page, int flags)
71027 return ret;
71028
71029 done:
71030- atomic_long_add(1, &mce_bad_pages);
71031+ atomic_long_add_unchecked(1, &mce_bad_pages);
71032 SetPageHWPoison(page);
71033 /* keep elevated page count for bad page */
71034 return ret;
71035diff --git a/mm/memory.c b/mm/memory.c
71036index 2466d12..08be4f6 100644
71037--- a/mm/memory.c
71038+++ b/mm/memory.c
71039@@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71040 return;
71041
71042 pmd = pmd_offset(pud, start);
71043+
71044+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71045 pud_clear(pud);
71046 pmd_free_tlb(tlb, pmd, start);
71047+#endif
71048+
71049 }
71050
71051 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71052@@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71053 if (end - 1 > ceiling - 1)
71054 return;
71055
71056+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71057 pud = pud_offset(pgd, start);
71058 pgd_clear(pgd);
71059 pud_free_tlb(tlb, pud, start);
71060+#endif
71061+
71062 }
71063
71064 /*
71065@@ -1602,12 +1609,6 @@ no_page_table:
71066 return page;
71067 }
71068
71069-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71070-{
71071- return stack_guard_page_start(vma, addr) ||
71072- stack_guard_page_end(vma, addr+PAGE_SIZE);
71073-}
71074-
71075 /**
71076 * __get_user_pages() - pin user pages in memory
71077 * @tsk: task_struct of target task
71078@@ -1680,10 +1681,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71079 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71080 i = 0;
71081
71082- do {
71083+ while (nr_pages) {
71084 struct vm_area_struct *vma;
71085
71086- vma = find_extend_vma(mm, start);
71087+ vma = find_vma(mm, start);
71088 if (!vma && in_gate_area(mm, start)) {
71089 unsigned long pg = start & PAGE_MASK;
71090 pgd_t *pgd;
71091@@ -1731,7 +1732,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71092 goto next_page;
71093 }
71094
71095- if (!vma ||
71096+ if (!vma || start < vma->vm_start ||
71097 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71098 !(vm_flags & vma->vm_flags))
71099 return i ? : -EFAULT;
71100@@ -1758,11 +1759,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71101 int ret;
71102 unsigned int fault_flags = 0;
71103
71104- /* For mlock, just skip the stack guard page. */
71105- if (foll_flags & FOLL_MLOCK) {
71106- if (stack_guard_page(vma, start))
71107- goto next_page;
71108- }
71109 if (foll_flags & FOLL_WRITE)
71110 fault_flags |= FAULT_FLAG_WRITE;
71111 if (nonblocking)
71112@@ -1836,7 +1832,7 @@ next_page:
71113 start += PAGE_SIZE;
71114 nr_pages--;
71115 } while (nr_pages && start < vma->vm_end);
71116- } while (nr_pages);
71117+ }
71118 return i;
71119 }
71120 EXPORT_SYMBOL(__get_user_pages);
71121@@ -2043,6 +2039,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71122 page_add_file_rmap(page);
71123 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71124
71125+#ifdef CONFIG_PAX_SEGMEXEC
71126+ pax_mirror_file_pte(vma, addr, page, ptl);
71127+#endif
71128+
71129 retval = 0;
71130 pte_unmap_unlock(pte, ptl);
71131 return retval;
71132@@ -2077,10 +2077,22 @@ out:
71133 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71134 struct page *page)
71135 {
71136+
71137+#ifdef CONFIG_PAX_SEGMEXEC
71138+ struct vm_area_struct *vma_m;
71139+#endif
71140+
71141 if (addr < vma->vm_start || addr >= vma->vm_end)
71142 return -EFAULT;
71143 if (!page_count(page))
71144 return -EINVAL;
71145+
71146+#ifdef CONFIG_PAX_SEGMEXEC
71147+ vma_m = pax_find_mirror_vma(vma);
71148+ if (vma_m)
71149+ vma_m->vm_flags |= VM_INSERTPAGE;
71150+#endif
71151+
71152 vma->vm_flags |= VM_INSERTPAGE;
71153 return insert_page(vma, addr, page, vma->vm_page_prot);
71154 }
71155@@ -2166,6 +2178,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71156 unsigned long pfn)
71157 {
71158 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71159+ BUG_ON(vma->vm_mirror);
71160
71161 if (addr < vma->vm_start || addr >= vma->vm_end)
71162 return -EFAULT;
71163@@ -2373,7 +2386,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71164
71165 BUG_ON(pud_huge(*pud));
71166
71167- pmd = pmd_alloc(mm, pud, addr);
71168+ pmd = (mm == &init_mm) ?
71169+ pmd_alloc_kernel(mm, pud, addr) :
71170+ pmd_alloc(mm, pud, addr);
71171 if (!pmd)
71172 return -ENOMEM;
71173 do {
71174@@ -2393,7 +2408,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71175 unsigned long next;
71176 int err;
71177
71178- pud = pud_alloc(mm, pgd, addr);
71179+ pud = (mm == &init_mm) ?
71180+ pud_alloc_kernel(mm, pgd, addr) :
71181+ pud_alloc(mm, pgd, addr);
71182 if (!pud)
71183 return -ENOMEM;
71184 do {
71185@@ -2481,6 +2498,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71186 copy_user_highpage(dst, src, va, vma);
71187 }
71188
71189+#ifdef CONFIG_PAX_SEGMEXEC
71190+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71191+{
71192+ struct mm_struct *mm = vma->vm_mm;
71193+ spinlock_t *ptl;
71194+ pte_t *pte, entry;
71195+
71196+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71197+ entry = *pte;
71198+ if (!pte_present(entry)) {
71199+ if (!pte_none(entry)) {
71200+ BUG_ON(pte_file(entry));
71201+ free_swap_and_cache(pte_to_swp_entry(entry));
71202+ pte_clear_not_present_full(mm, address, pte, 0);
71203+ }
71204+ } else {
71205+ struct page *page;
71206+
71207+ flush_cache_page(vma, address, pte_pfn(entry));
71208+ entry = ptep_clear_flush(vma, address, pte);
71209+ BUG_ON(pte_dirty(entry));
71210+ page = vm_normal_page(vma, address, entry);
71211+ if (page) {
71212+ update_hiwater_rss(mm);
71213+ if (PageAnon(page))
71214+ dec_mm_counter_fast(mm, MM_ANONPAGES);
71215+ else
71216+ dec_mm_counter_fast(mm, MM_FILEPAGES);
71217+ page_remove_rmap(page);
71218+ page_cache_release(page);
71219+ }
71220+ }
71221+ pte_unmap_unlock(pte, ptl);
71222+}
71223+
71224+/* PaX: if vma is mirrored, synchronize the mirror's PTE
71225+ *
71226+ * the ptl of the lower mapped page is held on entry and is not released on exit
71227+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71228+ */
71229+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71230+{
71231+ struct mm_struct *mm = vma->vm_mm;
71232+ unsigned long address_m;
71233+ spinlock_t *ptl_m;
71234+ struct vm_area_struct *vma_m;
71235+ pmd_t *pmd_m;
71236+ pte_t *pte_m, entry_m;
71237+
71238+ BUG_ON(!page_m || !PageAnon(page_m));
71239+
71240+ vma_m = pax_find_mirror_vma(vma);
71241+ if (!vma_m)
71242+ return;
71243+
71244+ BUG_ON(!PageLocked(page_m));
71245+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71246+ address_m = address + SEGMEXEC_TASK_SIZE;
71247+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71248+ pte_m = pte_offset_map(pmd_m, address_m);
71249+ ptl_m = pte_lockptr(mm, pmd_m);
71250+ if (ptl != ptl_m) {
71251+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71252+ if (!pte_none(*pte_m))
71253+ goto out;
71254+ }
71255+
71256+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71257+ page_cache_get(page_m);
71258+ page_add_anon_rmap(page_m, vma_m, address_m);
71259+ inc_mm_counter_fast(mm, MM_ANONPAGES);
71260+ set_pte_at(mm, address_m, pte_m, entry_m);
71261+ update_mmu_cache(vma_m, address_m, entry_m);
71262+out:
71263+ if (ptl != ptl_m)
71264+ spin_unlock(ptl_m);
71265+ pte_unmap(pte_m);
71266+ unlock_page(page_m);
71267+}
71268+
71269+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71270+{
71271+ struct mm_struct *mm = vma->vm_mm;
71272+ unsigned long address_m;
71273+ spinlock_t *ptl_m;
71274+ struct vm_area_struct *vma_m;
71275+ pmd_t *pmd_m;
71276+ pte_t *pte_m, entry_m;
71277+
71278+ BUG_ON(!page_m || PageAnon(page_m));
71279+
71280+ vma_m = pax_find_mirror_vma(vma);
71281+ if (!vma_m)
71282+ return;
71283+
71284+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71285+ address_m = address + SEGMEXEC_TASK_SIZE;
71286+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71287+ pte_m = pte_offset_map(pmd_m, address_m);
71288+ ptl_m = pte_lockptr(mm, pmd_m);
71289+ if (ptl != ptl_m) {
71290+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71291+ if (!pte_none(*pte_m))
71292+ goto out;
71293+ }
71294+
71295+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71296+ page_cache_get(page_m);
71297+ page_add_file_rmap(page_m);
71298+ inc_mm_counter_fast(mm, MM_FILEPAGES);
71299+ set_pte_at(mm, address_m, pte_m, entry_m);
71300+ update_mmu_cache(vma_m, address_m, entry_m);
71301+out:
71302+ if (ptl != ptl_m)
71303+ spin_unlock(ptl_m);
71304+ pte_unmap(pte_m);
71305+}
71306+
71307+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71308+{
71309+ struct mm_struct *mm = vma->vm_mm;
71310+ unsigned long address_m;
71311+ spinlock_t *ptl_m;
71312+ struct vm_area_struct *vma_m;
71313+ pmd_t *pmd_m;
71314+ pte_t *pte_m, entry_m;
71315+
71316+ vma_m = pax_find_mirror_vma(vma);
71317+ if (!vma_m)
71318+ return;
71319+
71320+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71321+ address_m = address + SEGMEXEC_TASK_SIZE;
71322+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71323+ pte_m = pte_offset_map(pmd_m, address_m);
71324+ ptl_m = pte_lockptr(mm, pmd_m);
71325+ if (ptl != ptl_m) {
71326+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71327+ if (!pte_none(*pte_m))
71328+ goto out;
71329+ }
71330+
71331+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71332+ set_pte_at(mm, address_m, pte_m, entry_m);
71333+out:
71334+ if (ptl != ptl_m)
71335+ spin_unlock(ptl_m);
71336+ pte_unmap(pte_m);
71337+}
71338+
71339+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71340+{
71341+ struct page *page_m;
71342+ pte_t entry;
71343+
71344+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71345+ goto out;
71346+
71347+ entry = *pte;
71348+ page_m = vm_normal_page(vma, address, entry);
71349+ if (!page_m)
71350+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71351+ else if (PageAnon(page_m)) {
71352+ if (pax_find_mirror_vma(vma)) {
71353+ pte_unmap_unlock(pte, ptl);
71354+ lock_page(page_m);
71355+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71356+ if (pte_same(entry, *pte))
71357+ pax_mirror_anon_pte(vma, address, page_m, ptl);
71358+ else
71359+ unlock_page(page_m);
71360+ }
71361+ } else
71362+ pax_mirror_file_pte(vma, address, page_m, ptl);
71363+
71364+out:
71365+ pte_unmap_unlock(pte, ptl);
71366+}
71367+#endif
71368+
71369 /*
71370 * This routine handles present pages, when users try to write
71371 * to a shared page. It is done by copying the page to a new address
71372@@ -2692,6 +2889,12 @@ gotten:
71373 */
71374 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71375 if (likely(pte_same(*page_table, orig_pte))) {
71376+
71377+#ifdef CONFIG_PAX_SEGMEXEC
71378+ if (pax_find_mirror_vma(vma))
71379+ BUG_ON(!trylock_page(new_page));
71380+#endif
71381+
71382 if (old_page) {
71383 if (!PageAnon(old_page)) {
71384 dec_mm_counter_fast(mm, MM_FILEPAGES);
71385@@ -2743,6 +2946,10 @@ gotten:
71386 page_remove_rmap(old_page);
71387 }
71388
71389+#ifdef CONFIG_PAX_SEGMEXEC
71390+ pax_mirror_anon_pte(vma, address, new_page, ptl);
71391+#endif
71392+
71393 /* Free the old page.. */
71394 new_page = old_page;
71395 ret |= VM_FAULT_WRITE;
71396@@ -3022,6 +3229,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71397 swap_free(entry);
71398 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71399 try_to_free_swap(page);
71400+
71401+#ifdef CONFIG_PAX_SEGMEXEC
71402+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71403+#endif
71404+
71405 unlock_page(page);
71406 if (swapcache) {
71407 /*
71408@@ -3045,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71409
71410 /* No need to invalidate - it was non-present before */
71411 update_mmu_cache(vma, address, page_table);
71412+
71413+#ifdef CONFIG_PAX_SEGMEXEC
71414+ pax_mirror_anon_pte(vma, address, page, ptl);
71415+#endif
71416+
71417 unlock:
71418 pte_unmap_unlock(page_table, ptl);
71419 out:
71420@@ -3064,40 +3281,6 @@ out_release:
71421 }
71422
71423 /*
71424- * This is like a special single-page "expand_{down|up}wards()",
71425- * except we must first make sure that 'address{-|+}PAGE_SIZE'
71426- * doesn't hit another vma.
71427- */
71428-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71429-{
71430- address &= PAGE_MASK;
71431- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71432- struct vm_area_struct *prev = vma->vm_prev;
71433-
71434- /*
71435- * Is there a mapping abutting this one below?
71436- *
71437- * That's only ok if it's the same stack mapping
71438- * that has gotten split..
71439- */
71440- if (prev && prev->vm_end == address)
71441- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71442-
71443- expand_downwards(vma, address - PAGE_SIZE);
71444- }
71445- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71446- struct vm_area_struct *next = vma->vm_next;
71447-
71448- /* As VM_GROWSDOWN but s/below/above/ */
71449- if (next && next->vm_start == address + PAGE_SIZE)
71450- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71451-
71452- expand_upwards(vma, address + PAGE_SIZE);
71453- }
71454- return 0;
71455-}
71456-
71457-/*
71458 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71459 * but allow concurrent faults), and pte mapped but not yet locked.
71460 * We return with mmap_sem still held, but pte unmapped and unlocked.
71461@@ -3106,27 +3289,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71462 unsigned long address, pte_t *page_table, pmd_t *pmd,
71463 unsigned int flags)
71464 {
71465- struct page *page;
71466+ struct page *page = NULL;
71467 spinlock_t *ptl;
71468 pte_t entry;
71469
71470- pte_unmap(page_table);
71471-
71472- /* Check if we need to add a guard page to the stack */
71473- if (check_stack_guard_page(vma, address) < 0)
71474- return VM_FAULT_SIGBUS;
71475-
71476- /* Use the zero-page for reads */
71477 if (!(flags & FAULT_FLAG_WRITE)) {
71478 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71479 vma->vm_page_prot));
71480- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71481+ ptl = pte_lockptr(mm, pmd);
71482+ spin_lock(ptl);
71483 if (!pte_none(*page_table))
71484 goto unlock;
71485 goto setpte;
71486 }
71487
71488 /* Allocate our own private page. */
71489+ pte_unmap(page_table);
71490+
71491 if (unlikely(anon_vma_prepare(vma)))
71492 goto oom;
71493 page = alloc_zeroed_user_highpage_movable(vma, address);
71494@@ -3145,6 +3324,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71495 if (!pte_none(*page_table))
71496 goto release;
71497
71498+#ifdef CONFIG_PAX_SEGMEXEC
71499+ if (pax_find_mirror_vma(vma))
71500+ BUG_ON(!trylock_page(page));
71501+#endif
71502+
71503 inc_mm_counter_fast(mm, MM_ANONPAGES);
71504 page_add_new_anon_rmap(page, vma, address);
71505 setpte:
71506@@ -3152,6 +3336,12 @@ setpte:
71507
71508 /* No need to invalidate - it was non-present before */
71509 update_mmu_cache(vma, address, page_table);
71510+
71511+#ifdef CONFIG_PAX_SEGMEXEC
71512+ if (page)
71513+ pax_mirror_anon_pte(vma, address, page, ptl);
71514+#endif
71515+
71516 unlock:
71517 pte_unmap_unlock(page_table, ptl);
71518 return 0;
71519@@ -3295,6 +3485,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71520 */
71521 /* Only go through if we didn't race with anybody else... */
71522 if (likely(pte_same(*page_table, orig_pte))) {
71523+
71524+#ifdef CONFIG_PAX_SEGMEXEC
71525+ if (anon && pax_find_mirror_vma(vma))
71526+ BUG_ON(!trylock_page(page));
71527+#endif
71528+
71529 flush_icache_page(vma, page);
71530 entry = mk_pte(page, vma->vm_page_prot);
71531 if (flags & FAULT_FLAG_WRITE)
71532@@ -3314,6 +3510,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71533
71534 /* no need to invalidate: a not-present page won't be cached */
71535 update_mmu_cache(vma, address, page_table);
71536+
71537+#ifdef CONFIG_PAX_SEGMEXEC
71538+ if (anon)
71539+ pax_mirror_anon_pte(vma, address, page, ptl);
71540+ else
71541+ pax_mirror_file_pte(vma, address, page, ptl);
71542+#endif
71543+
71544 } else {
71545 if (cow_page)
71546 mem_cgroup_uncharge_page(cow_page);
71547@@ -3467,6 +3671,12 @@ int handle_pte_fault(struct mm_struct *mm,
71548 if (flags & FAULT_FLAG_WRITE)
71549 flush_tlb_fix_spurious_fault(vma, address);
71550 }
71551+
71552+#ifdef CONFIG_PAX_SEGMEXEC
71553+ pax_mirror_pte(vma, address, pte, pmd, ptl);
71554+ return 0;
71555+#endif
71556+
71557 unlock:
71558 pte_unmap_unlock(pte, ptl);
71559 return 0;
71560@@ -3483,6 +3693,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71561 pmd_t *pmd;
71562 pte_t *pte;
71563
71564+#ifdef CONFIG_PAX_SEGMEXEC
71565+ struct vm_area_struct *vma_m;
71566+#endif
71567+
71568 __set_current_state(TASK_RUNNING);
71569
71570 count_vm_event(PGFAULT);
71571@@ -3494,6 +3708,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71572 if (unlikely(is_vm_hugetlb_page(vma)))
71573 return hugetlb_fault(mm, vma, address, flags);
71574
71575+#ifdef CONFIG_PAX_SEGMEXEC
71576+ vma_m = pax_find_mirror_vma(vma);
71577+ if (vma_m) {
71578+ unsigned long address_m;
71579+ pgd_t *pgd_m;
71580+ pud_t *pud_m;
71581+ pmd_t *pmd_m;
71582+
71583+ if (vma->vm_start > vma_m->vm_start) {
71584+ address_m = address;
71585+ address -= SEGMEXEC_TASK_SIZE;
71586+ vma = vma_m;
71587+ } else
71588+ address_m = address + SEGMEXEC_TASK_SIZE;
71589+
71590+ pgd_m = pgd_offset(mm, address_m);
71591+ pud_m = pud_alloc(mm, pgd_m, address_m);
71592+ if (!pud_m)
71593+ return VM_FAULT_OOM;
71594+ pmd_m = pmd_alloc(mm, pud_m, address_m);
71595+ if (!pmd_m)
71596+ return VM_FAULT_OOM;
71597+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71598+ return VM_FAULT_OOM;
71599+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71600+ }
71601+#endif
71602+
71603 retry:
71604 pgd = pgd_offset(mm, address);
71605 pud = pud_alloc(mm, pgd, address);
71606@@ -3535,7 +3777,7 @@ retry:
71607 * run pte_offset_map on the pmd, if an huge pmd could
71608 * materialize from under us from a different thread.
71609 */
71610- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71611+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71612 return VM_FAULT_OOM;
71613 /* if an huge pmd materialized from under us just retry later */
71614 if (unlikely(pmd_trans_huge(*pmd)))
71615@@ -3572,6 +3814,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71616 spin_unlock(&mm->page_table_lock);
71617 return 0;
71618 }
71619+
71620+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71621+{
71622+ pud_t *new = pud_alloc_one(mm, address);
71623+ if (!new)
71624+ return -ENOMEM;
71625+
71626+ smp_wmb(); /* See comment in __pte_alloc */
71627+
71628+ spin_lock(&mm->page_table_lock);
71629+ if (pgd_present(*pgd)) /* Another has populated it */
71630+ pud_free(mm, new);
71631+ else
71632+ pgd_populate_kernel(mm, pgd, new);
71633+ spin_unlock(&mm->page_table_lock);
71634+ return 0;
71635+}
71636 #endif /* __PAGETABLE_PUD_FOLDED */
71637
71638 #ifndef __PAGETABLE_PMD_FOLDED
71639@@ -3602,6 +3861,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71640 spin_unlock(&mm->page_table_lock);
71641 return 0;
71642 }
71643+
71644+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71645+{
71646+ pmd_t *new = pmd_alloc_one(mm, address);
71647+ if (!new)
71648+ return -ENOMEM;
71649+
71650+ smp_wmb(); /* See comment in __pte_alloc */
71651+
71652+ spin_lock(&mm->page_table_lock);
71653+#ifndef __ARCH_HAS_4LEVEL_HACK
71654+ if (pud_present(*pud)) /* Another has populated it */
71655+ pmd_free(mm, new);
71656+ else
71657+ pud_populate_kernel(mm, pud, new);
71658+#else
71659+ if (pgd_present(*pud)) /* Another has populated it */
71660+ pmd_free(mm, new);
71661+ else
71662+ pgd_populate_kernel(mm, pud, new);
71663+#endif /* __ARCH_HAS_4LEVEL_HACK */
71664+ spin_unlock(&mm->page_table_lock);
71665+ return 0;
71666+}
71667 #endif /* __PAGETABLE_PMD_FOLDED */
71668
71669 int make_pages_present(unsigned long addr, unsigned long end)
71670@@ -3639,7 +3922,7 @@ static int __init gate_vma_init(void)
71671 gate_vma.vm_start = FIXADDR_USER_START;
71672 gate_vma.vm_end = FIXADDR_USER_END;
71673 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71674- gate_vma.vm_page_prot = __P101;
71675+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71676
71677 return 0;
71678 }
71679diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71680index 1d771e4..f9a6808 100644
71681--- a/mm/mempolicy.c
71682+++ b/mm/mempolicy.c
71683@@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71684 unsigned long vmstart;
71685 unsigned long vmend;
71686
71687+#ifdef CONFIG_PAX_SEGMEXEC
71688+ struct vm_area_struct *vma_m;
71689+#endif
71690+
71691 vma = find_vma(mm, start);
71692 if (!vma || vma->vm_start > start)
71693 return -EFAULT;
71694@@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71695 if (err)
71696 goto out;
71697 }
71698+
71699+#ifdef CONFIG_PAX_SEGMEXEC
71700+ vma_m = pax_find_mirror_vma(vma);
71701+ if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
71702+ err = vma_m->vm_ops->set_policy(vma_m, new_pol);
71703+ if (err)
71704+ goto out;
71705+ }
71706+#endif
71707+
71708 }
71709
71710 out:
71711@@ -1125,6 +1139,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71712
71713 if (end < start)
71714 return -EINVAL;
71715+
71716+#ifdef CONFIG_PAX_SEGMEXEC
71717+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71718+ if (end > SEGMEXEC_TASK_SIZE)
71719+ return -EINVAL;
71720+ } else
71721+#endif
71722+
71723+ if (end > TASK_SIZE)
71724+ return -EINVAL;
71725+
71726 if (end == start)
71727 return 0;
71728
71729@@ -1348,8 +1373,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71730 */
71731 tcred = __task_cred(task);
71732 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
71733- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
71734- !capable(CAP_SYS_NICE)) {
71735+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
71736 rcu_read_unlock();
71737 err = -EPERM;
71738 goto out_put;
71739@@ -1380,6 +1404,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71740 goto out;
71741 }
71742
71743+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71744+ if (mm != current->mm &&
71745+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71746+ mmput(mm);
71747+ err = -EPERM;
71748+ goto out;
71749+ }
71750+#endif
71751+
71752 err = do_migrate_pages(mm, old, new,
71753 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
71754
71755diff --git a/mm/mlock.c b/mm/mlock.c
71756index ef726e8..cd7f1ec 100644
71757--- a/mm/mlock.c
71758+++ b/mm/mlock.c
71759@@ -13,6 +13,7 @@
71760 #include <linux/pagemap.h>
71761 #include <linux/mempolicy.h>
71762 #include <linux/syscalls.h>
71763+#include <linux/security.h>
71764 #include <linux/sched.h>
71765 #include <linux/export.h>
71766 #include <linux/rmap.h>
71767@@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
71768 {
71769 unsigned long nstart, end, tmp;
71770 struct vm_area_struct * vma, * prev;
71771- int error;
71772+ int error = 0;
71773
71774 VM_BUG_ON(start & ~PAGE_MASK);
71775 VM_BUG_ON(len != PAGE_ALIGN(len));
71776@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71777 return -EINVAL;
71778 if (end == start)
71779 return 0;
71780+ if (end > TASK_SIZE)
71781+ return -EINVAL;
71782+
71783 vma = find_vma(current->mm, start);
71784 if (!vma || vma->vm_start > start)
71785 return -ENOMEM;
71786@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71787 for (nstart = start ; ; ) {
71788 vm_flags_t newflags;
71789
71790+#ifdef CONFIG_PAX_SEGMEXEC
71791+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71792+ break;
71793+#endif
71794+
71795 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71796
71797 newflags = vma->vm_flags | VM_LOCKED;
71798@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71799 lock_limit >>= PAGE_SHIFT;
71800
71801 /* check against resource limits */
71802+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71803 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71804 error = do_mlock(start, len, 1);
71805 up_write(&current->mm->mmap_sem);
71806@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71807 static int do_mlockall(int flags)
71808 {
71809 struct vm_area_struct * vma, * prev = NULL;
71810- unsigned int def_flags = 0;
71811
71812 if (flags & MCL_FUTURE)
71813- def_flags = VM_LOCKED;
71814- current->mm->def_flags = def_flags;
71815+ current->mm->def_flags |= VM_LOCKED;
71816+ else
71817+ current->mm->def_flags &= ~VM_LOCKED;
71818 if (flags == MCL_FUTURE)
71819 goto out;
71820
71821 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71822 vm_flags_t newflags;
71823
71824+#ifdef CONFIG_PAX_SEGMEXEC
71825+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71826+ break;
71827+#endif
71828+
71829+ BUG_ON(vma->vm_end > TASK_SIZE);
71830 newflags = vma->vm_flags | VM_LOCKED;
71831 if (!(flags & MCL_CURRENT))
71832 newflags &= ~VM_LOCKED;
71833@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71834 lock_limit >>= PAGE_SHIFT;
71835
71836 ret = -ENOMEM;
71837+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71838 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71839 capable(CAP_IPC_LOCK))
71840 ret = do_mlockall(flags);
71841diff --git a/mm/mmap.c b/mm/mmap.c
71842index 3edfcdf..4a27ae9 100644
71843--- a/mm/mmap.c
71844+++ b/mm/mmap.c
71845@@ -47,6 +47,16 @@
71846 #define arch_rebalance_pgtables(addr, len) (addr)
71847 #endif
71848
71849+static inline void verify_mm_writelocked(struct mm_struct *mm)
71850+{
71851+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71852+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71853+ up_read(&mm->mmap_sem);
71854+ BUG();
71855+ }
71856+#endif
71857+}
71858+
71859 static void unmap_region(struct mm_struct *mm,
71860 struct vm_area_struct *vma, struct vm_area_struct *prev,
71861 unsigned long start, unsigned long end);
71862@@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
71863 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71864 *
71865 */
71866-pgprot_t protection_map[16] = {
71867+pgprot_t protection_map[16] __read_only = {
71868 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71869 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71870 };
71871
71872-pgprot_t vm_get_page_prot(unsigned long vm_flags)
71873+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71874 {
71875- return __pgprot(pgprot_val(protection_map[vm_flags &
71876+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71877 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71878 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71879+
71880+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71881+ if (!(__supported_pte_mask & _PAGE_NX) &&
71882+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71883+ (vm_flags & (VM_READ | VM_WRITE)))
71884+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71885+#endif
71886+
71887+ return prot;
71888 }
71889 EXPORT_SYMBOL(vm_get_page_prot);
71890
71891 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71892 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71893 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71894+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71895 /*
71896 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71897 * other variables. It can be updated by several CPUs frequently.
71898@@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71899 struct vm_area_struct *next = vma->vm_next;
71900
71901 might_sleep();
71902+ BUG_ON(vma->vm_mirror);
71903 if (vma->vm_ops && vma->vm_ops->close)
71904 vma->vm_ops->close(vma);
71905 if (vma->vm_file) {
71906@@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71907 * not page aligned -Ram Gupta
71908 */
71909 rlim = rlimit(RLIMIT_DATA);
71910+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71911 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71912 (mm->end_data - mm->start_data) > rlim)
71913 goto out;
71914@@ -708,6 +730,12 @@ static int
71915 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71916 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71917 {
71918+
71919+#ifdef CONFIG_PAX_SEGMEXEC
71920+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71921+ return 0;
71922+#endif
71923+
71924 if (is_mergeable_vma(vma, file, vm_flags) &&
71925 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71926 if (vma->vm_pgoff == vm_pgoff)
71927@@ -727,6 +755,12 @@ static int
71928 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71929 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71930 {
71931+
71932+#ifdef CONFIG_PAX_SEGMEXEC
71933+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71934+ return 0;
71935+#endif
71936+
71937 if (is_mergeable_vma(vma, file, vm_flags) &&
71938 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71939 pgoff_t vm_pglen;
71940@@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71941 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71942 struct vm_area_struct *prev, unsigned long addr,
71943 unsigned long end, unsigned long vm_flags,
71944- struct anon_vma *anon_vma, struct file *file,
71945+ struct anon_vma *anon_vma, struct file *file,
71946 pgoff_t pgoff, struct mempolicy *policy)
71947 {
71948 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71949 struct vm_area_struct *area, *next;
71950 int err;
71951
71952+#ifdef CONFIG_PAX_SEGMEXEC
71953+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
71954+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
71955+
71956+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
71957+#endif
71958+
71959 /*
71960 * We later require that vma->vm_flags == vm_flags,
71961 * so this tests vma->vm_flags & VM_SPECIAL, too.
71962@@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71963 if (next && next->vm_end == end) /* cases 6, 7, 8 */
71964 next = next->vm_next;
71965
71966+#ifdef CONFIG_PAX_SEGMEXEC
71967+ if (prev)
71968+ prev_m = pax_find_mirror_vma(prev);
71969+ if (area)
71970+ area_m = pax_find_mirror_vma(area);
71971+ if (next)
71972+ next_m = pax_find_mirror_vma(next);
71973+#endif
71974+
71975 /*
71976 * Can it merge with the predecessor?
71977 */
71978@@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71979 /* cases 1, 6 */
71980 err = vma_adjust(prev, prev->vm_start,
71981 next->vm_end, prev->vm_pgoff, NULL);
71982- } else /* cases 2, 5, 7 */
71983+
71984+#ifdef CONFIG_PAX_SEGMEXEC
71985+ if (!err && prev_m)
71986+ err = vma_adjust(prev_m, prev_m->vm_start,
71987+ next_m->vm_end, prev_m->vm_pgoff, NULL);
71988+#endif
71989+
71990+ } else { /* cases 2, 5, 7 */
71991 err = vma_adjust(prev, prev->vm_start,
71992 end, prev->vm_pgoff, NULL);
71993+
71994+#ifdef CONFIG_PAX_SEGMEXEC
71995+ if (!err && prev_m)
71996+ err = vma_adjust(prev_m, prev_m->vm_start,
71997+ end_m, prev_m->vm_pgoff, NULL);
71998+#endif
71999+
72000+ }
72001 if (err)
72002 return NULL;
72003 khugepaged_enter_vma_merge(prev);
72004@@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72005 mpol_equal(policy, vma_policy(next)) &&
72006 can_vma_merge_before(next, vm_flags,
72007 anon_vma, file, pgoff+pglen)) {
72008- if (prev && addr < prev->vm_end) /* case 4 */
72009+ if (prev && addr < prev->vm_end) { /* case 4 */
72010 err = vma_adjust(prev, prev->vm_start,
72011 addr, prev->vm_pgoff, NULL);
72012- else /* cases 3, 8 */
72013+
72014+#ifdef CONFIG_PAX_SEGMEXEC
72015+ if (!err && prev_m)
72016+ err = vma_adjust(prev_m, prev_m->vm_start,
72017+ addr_m, prev_m->vm_pgoff, NULL);
72018+#endif
72019+
72020+ } else { /* cases 3, 8 */
72021 err = vma_adjust(area, addr, next->vm_end,
72022 next->vm_pgoff - pglen, NULL);
72023+
72024+#ifdef CONFIG_PAX_SEGMEXEC
72025+ if (!err && area_m)
72026+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
72027+ next_m->vm_pgoff - pglen, NULL);
72028+#endif
72029+
72030+ }
72031 if (err)
72032 return NULL;
72033 khugepaged_enter_vma_merge(area);
72034@@ -940,14 +1020,11 @@ none:
72035 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72036 struct file *file, long pages)
72037 {
72038- const unsigned long stack_flags
72039- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72040-
72041 if (file) {
72042 mm->shared_vm += pages;
72043 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72044 mm->exec_vm += pages;
72045- } else if (flags & stack_flags)
72046+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72047 mm->stack_vm += pages;
72048 if (flags & (VM_RESERVED|VM_IO))
72049 mm->reserved_vm += pages;
72050@@ -985,7 +1062,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72051 * (the exception is when the underlying filesystem is noexec
72052 * mounted, in which case we dont add PROT_EXEC.)
72053 */
72054- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72055+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72056 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72057 prot |= PROT_EXEC;
72058
72059@@ -1011,7 +1088,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72060 /* Obtain the address to map to. we verify (or select) it and ensure
72061 * that it represents a valid section of the address space.
72062 */
72063- addr = get_unmapped_area(file, addr, len, pgoff, flags);
72064+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72065 if (addr & ~PAGE_MASK)
72066 return addr;
72067
72068@@ -1022,6 +1099,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72069 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72070 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72071
72072+#ifdef CONFIG_PAX_MPROTECT
72073+ if (mm->pax_flags & MF_PAX_MPROTECT) {
72074+#ifndef CONFIG_PAX_MPROTECT_COMPAT
72075+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72076+ gr_log_rwxmmap(file);
72077+
72078+#ifdef CONFIG_PAX_EMUPLT
72079+ vm_flags &= ~VM_EXEC;
72080+#else
72081+ return -EPERM;
72082+#endif
72083+
72084+ }
72085+
72086+ if (!(vm_flags & VM_EXEC))
72087+ vm_flags &= ~VM_MAYEXEC;
72088+#else
72089+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72090+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72091+#endif
72092+ else
72093+ vm_flags &= ~VM_MAYWRITE;
72094+ }
72095+#endif
72096+
72097+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72098+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72099+ vm_flags &= ~VM_PAGEEXEC;
72100+#endif
72101+
72102 if (flags & MAP_LOCKED)
72103 if (!can_do_mlock())
72104 return -EPERM;
72105@@ -1033,6 +1140,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72106 locked += mm->locked_vm;
72107 lock_limit = rlimit(RLIMIT_MEMLOCK);
72108 lock_limit >>= PAGE_SHIFT;
72109+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72110 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72111 return -EAGAIN;
72112 }
72113@@ -1099,6 +1207,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72114 }
72115 }
72116
72117+ if (!gr_acl_handle_mmap(file, prot))
72118+ return -EACCES;
72119+
72120 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72121 }
72122
72123@@ -1175,7 +1286,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72124 vm_flags_t vm_flags = vma->vm_flags;
72125
72126 /* If it was private or non-writable, the write bit is already clear */
72127- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72128+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72129 return 0;
72130
72131 /* The backer wishes to know when pages are first written to? */
72132@@ -1224,14 +1335,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72133 unsigned long charged = 0;
72134 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72135
72136+#ifdef CONFIG_PAX_SEGMEXEC
72137+ struct vm_area_struct *vma_m = NULL;
72138+#endif
72139+
72140+ /*
72141+ * mm->mmap_sem is required to protect against another thread
72142+ * changing the mappings in case we sleep.
72143+ */
72144+ verify_mm_writelocked(mm);
72145+
72146 /* Clear old maps */
72147 error = -ENOMEM;
72148-munmap_back:
72149 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72150 if (vma && vma->vm_start < addr + len) {
72151 if (do_munmap(mm, addr, len))
72152 return -ENOMEM;
72153- goto munmap_back;
72154+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72155+ BUG_ON(vma && vma->vm_start < addr + len);
72156 }
72157
72158 /* Check against address space limit. */
72159@@ -1280,6 +1401,16 @@ munmap_back:
72160 goto unacct_error;
72161 }
72162
72163+#ifdef CONFIG_PAX_SEGMEXEC
72164+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72165+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72166+ if (!vma_m) {
72167+ error = -ENOMEM;
72168+ goto free_vma;
72169+ }
72170+ }
72171+#endif
72172+
72173 vma->vm_mm = mm;
72174 vma->vm_start = addr;
72175 vma->vm_end = addr + len;
72176@@ -1304,6 +1435,19 @@ munmap_back:
72177 error = file->f_op->mmap(file, vma);
72178 if (error)
72179 goto unmap_and_free_vma;
72180+
72181+#ifdef CONFIG_PAX_SEGMEXEC
72182+ if (vma_m && (vm_flags & VM_EXECUTABLE))
72183+ added_exe_file_vma(mm);
72184+#endif
72185+
72186+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72187+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72188+ vma->vm_flags |= VM_PAGEEXEC;
72189+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72190+ }
72191+#endif
72192+
72193 if (vm_flags & VM_EXECUTABLE)
72194 added_exe_file_vma(mm);
72195
72196@@ -1341,6 +1485,11 @@ munmap_back:
72197 vma_link(mm, vma, prev, rb_link, rb_parent);
72198 file = vma->vm_file;
72199
72200+#ifdef CONFIG_PAX_SEGMEXEC
72201+ if (vma_m)
72202+ BUG_ON(pax_mirror_vma(vma_m, vma));
72203+#endif
72204+
72205 /* Once vma denies write, undo our temporary denial count */
72206 if (correct_wcount)
72207 atomic_inc(&inode->i_writecount);
72208@@ -1349,6 +1498,7 @@ out:
72209
72210 mm->total_vm += len >> PAGE_SHIFT;
72211 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72212+ track_exec_limit(mm, addr, addr + len, vm_flags);
72213 if (vm_flags & VM_LOCKED) {
72214 if (!mlock_vma_pages_range(vma, addr, addr + len))
72215 mm->locked_vm += (len >> PAGE_SHIFT);
72216@@ -1371,6 +1521,12 @@ unmap_and_free_vma:
72217 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72218 charged = 0;
72219 free_vma:
72220+
72221+#ifdef CONFIG_PAX_SEGMEXEC
72222+ if (vma_m)
72223+ kmem_cache_free(vm_area_cachep, vma_m);
72224+#endif
72225+
72226 kmem_cache_free(vm_area_cachep, vma);
72227 unacct_error:
72228 if (charged)
72229@@ -1378,6 +1534,44 @@ unacct_error:
72230 return error;
72231 }
72232
72233+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72234+{
72235+ if (!vma) {
72236+#ifdef CONFIG_STACK_GROWSUP
72237+ if (addr > sysctl_heap_stack_gap)
72238+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72239+ else
72240+ vma = find_vma(current->mm, 0);
72241+ if (vma && (vma->vm_flags & VM_GROWSUP))
72242+ return false;
72243+#endif
72244+ return true;
72245+ }
72246+
72247+ if (addr + len > vma->vm_start)
72248+ return false;
72249+
72250+ if (vma->vm_flags & VM_GROWSDOWN)
72251+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72252+#ifdef CONFIG_STACK_GROWSUP
72253+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72254+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72255+#endif
72256+
72257+ return true;
72258+}
72259+
72260+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72261+{
72262+ if (vma->vm_start < len)
72263+ return -ENOMEM;
72264+ if (!(vma->vm_flags & VM_GROWSDOWN))
72265+ return vma->vm_start - len;
72266+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
72267+ return vma->vm_start - len - sysctl_heap_stack_gap;
72268+ return -ENOMEM;
72269+}
72270+
72271 /* Get an address range which is currently unmapped.
72272 * For shmat() with addr=0.
72273 *
72274@@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
72275 if (flags & MAP_FIXED)
72276 return addr;
72277
72278+#ifdef CONFIG_PAX_RANDMMAP
72279+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72280+#endif
72281+
72282 if (addr) {
72283 addr = PAGE_ALIGN(addr);
72284- vma = find_vma(mm, addr);
72285- if (TASK_SIZE - len >= addr &&
72286- (!vma || addr + len <= vma->vm_start))
72287- return addr;
72288+ if (TASK_SIZE - len >= addr) {
72289+ vma = find_vma(mm, addr);
72290+ if (check_heap_stack_gap(vma, addr, len))
72291+ return addr;
72292+ }
72293 }
72294 if (len > mm->cached_hole_size) {
72295- start_addr = addr = mm->free_area_cache;
72296+ start_addr = addr = mm->free_area_cache;
72297 } else {
72298- start_addr = addr = TASK_UNMAPPED_BASE;
72299- mm->cached_hole_size = 0;
72300+ start_addr = addr = mm->mmap_base;
72301+ mm->cached_hole_size = 0;
72302 }
72303
72304 full_search:
72305@@ -1426,34 +1625,40 @@ full_search:
72306 * Start a new search - just in case we missed
72307 * some holes.
72308 */
72309- if (start_addr != TASK_UNMAPPED_BASE) {
72310- addr = TASK_UNMAPPED_BASE;
72311- start_addr = addr;
72312+ if (start_addr != mm->mmap_base) {
72313+ start_addr = addr = mm->mmap_base;
72314 mm->cached_hole_size = 0;
72315 goto full_search;
72316 }
72317 return -ENOMEM;
72318 }
72319- if (!vma || addr + len <= vma->vm_start) {
72320- /*
72321- * Remember the place where we stopped the search:
72322- */
72323- mm->free_area_cache = addr + len;
72324- return addr;
72325- }
72326+ if (check_heap_stack_gap(vma, addr, len))
72327+ break;
72328 if (addr + mm->cached_hole_size < vma->vm_start)
72329 mm->cached_hole_size = vma->vm_start - addr;
72330 addr = vma->vm_end;
72331 }
72332+
72333+ /*
72334+ * Remember the place where we stopped the search:
72335+ */
72336+ mm->free_area_cache = addr + len;
72337+ return addr;
72338 }
72339 #endif
72340
72341 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72342 {
72343+
72344+#ifdef CONFIG_PAX_SEGMEXEC
72345+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72346+ return;
72347+#endif
72348+
72349 /*
72350 * Is this a new hole at the lowest possible address?
72351 */
72352- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
72353+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
72354 mm->free_area_cache = addr;
72355 }
72356
72357@@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72358 {
72359 struct vm_area_struct *vma;
72360 struct mm_struct *mm = current->mm;
72361- unsigned long addr = addr0, start_addr;
72362+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
72363
72364 /* requested length too big for entire address space */
72365 if (len > TASK_SIZE)
72366@@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72367 if (flags & MAP_FIXED)
72368 return addr;
72369
72370+#ifdef CONFIG_PAX_RANDMMAP
72371+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72372+#endif
72373+
72374 /* requesting a specific address */
72375 if (addr) {
72376 addr = PAGE_ALIGN(addr);
72377- vma = find_vma(mm, addr);
72378- if (TASK_SIZE - len >= addr &&
72379- (!vma || addr + len <= vma->vm_start))
72380- return addr;
72381+ if (TASK_SIZE - len >= addr) {
72382+ vma = find_vma(mm, addr);
72383+ if (check_heap_stack_gap(vma, addr, len))
72384+ return addr;
72385+ }
72386 }
72387
72388 /* check if free_area_cache is useful for us */
72389@@ -1508,7 +1718,7 @@ try_again:
72390 * return with success:
72391 */
72392 vma = find_vma(mm, addr);
72393- if (!vma || addr+len <= vma->vm_start)
72394+ if (check_heap_stack_gap(vma, addr, len))
72395 /* remember the address as a hint for next time */
72396 return (mm->free_area_cache = addr);
72397
72398@@ -1517,8 +1727,8 @@ try_again:
72399 mm->cached_hole_size = vma->vm_start - addr;
72400
72401 /* try just below the current vma->vm_start */
72402- addr = vma->vm_start-len;
72403- } while (len < vma->vm_start);
72404+ addr = skip_heap_stack_gap(vma, len);
72405+ } while (!IS_ERR_VALUE(addr));
72406
72407 fail:
72408 /*
72409@@ -1541,13 +1751,21 @@ fail:
72410 * can happen with large stack limits and large mmap()
72411 * allocations.
72412 */
72413+ mm->mmap_base = TASK_UNMAPPED_BASE;
72414+
72415+#ifdef CONFIG_PAX_RANDMMAP
72416+ if (mm->pax_flags & MF_PAX_RANDMMAP)
72417+ mm->mmap_base += mm->delta_mmap;
72418+#endif
72419+
72420+ mm->free_area_cache = mm->mmap_base;
72421 mm->cached_hole_size = ~0UL;
72422- mm->free_area_cache = TASK_UNMAPPED_BASE;
72423 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72424 /*
72425 * Restore the topdown base:
72426 */
72427- mm->free_area_cache = mm->mmap_base;
72428+ mm->mmap_base = base;
72429+ mm->free_area_cache = base;
72430 mm->cached_hole_size = ~0UL;
72431
72432 return addr;
72433@@ -1556,6 +1774,12 @@ fail:
72434
72435 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72436 {
72437+
72438+#ifdef CONFIG_PAX_SEGMEXEC
72439+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72440+ return;
72441+#endif
72442+
72443 /*
72444 * Is this a new hole at the highest possible address?
72445 */
72446@@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72447 mm->free_area_cache = addr;
72448
72449 /* dont allow allocations above current base */
72450- if (mm->free_area_cache > mm->mmap_base)
72451+ if (mm->free_area_cache > mm->mmap_base) {
72452 mm->free_area_cache = mm->mmap_base;
72453+ mm->cached_hole_size = ~0UL;
72454+ }
72455 }
72456
72457 unsigned long
72458@@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
72459 return vma;
72460 }
72461
72462+#ifdef CONFIG_PAX_SEGMEXEC
72463+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72464+{
72465+ struct vm_area_struct *vma_m;
72466+
72467+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72468+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72469+ BUG_ON(vma->vm_mirror);
72470+ return NULL;
72471+ }
72472+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72473+ vma_m = vma->vm_mirror;
72474+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72475+ BUG_ON(vma->vm_file != vma_m->vm_file);
72476+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72477+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72478+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72479+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72480+ return vma_m;
72481+}
72482+#endif
72483+
72484 /*
72485 * Verify that the stack growth is acceptable and
72486 * update accounting. This is shared with both the
72487@@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72488 return -ENOMEM;
72489
72490 /* Stack limit test */
72491+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
72492 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72493 return -ENOMEM;
72494
72495@@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72496 locked = mm->locked_vm + grow;
72497 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72498 limit >>= PAGE_SHIFT;
72499+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72500 if (locked > limit && !capable(CAP_IPC_LOCK))
72501 return -ENOMEM;
72502 }
72503@@ -1719,37 +1969,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72504 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72505 * vma is the last one with address > vma->vm_end. Have to extend vma.
72506 */
72507+#ifndef CONFIG_IA64
72508+static
72509+#endif
72510 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72511 {
72512 int error;
72513+ bool locknext;
72514
72515 if (!(vma->vm_flags & VM_GROWSUP))
72516 return -EFAULT;
72517
72518+ /* Also guard against wrapping around to address 0. */
72519+ if (address < PAGE_ALIGN(address+1))
72520+ address = PAGE_ALIGN(address+1);
72521+ else
72522+ return -ENOMEM;
72523+
72524 /*
72525 * We must make sure the anon_vma is allocated
72526 * so that the anon_vma locking is not a noop.
72527 */
72528 if (unlikely(anon_vma_prepare(vma)))
72529 return -ENOMEM;
72530+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72531+ if (locknext && anon_vma_prepare(vma->vm_next))
72532+ return -ENOMEM;
72533 vma_lock_anon_vma(vma);
72534+ if (locknext)
72535+ vma_lock_anon_vma(vma->vm_next);
72536
72537 /*
72538 * vma->vm_start/vm_end cannot change under us because the caller
72539 * is required to hold the mmap_sem in read mode. We need the
72540- * anon_vma lock to serialize against concurrent expand_stacks.
72541- * Also guard against wrapping around to address 0.
72542+ * anon_vma locks to serialize against concurrent expand_stacks
72543+ * and expand_upwards.
72544 */
72545- if (address < PAGE_ALIGN(address+4))
72546- address = PAGE_ALIGN(address+4);
72547- else {
72548- vma_unlock_anon_vma(vma);
72549- return -ENOMEM;
72550- }
72551 error = 0;
72552
72553 /* Somebody else might have raced and expanded it already */
72554- if (address > vma->vm_end) {
72555+ 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)
72556+ error = -ENOMEM;
72557+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72558 unsigned long size, grow;
72559
72560 size = address - vma->vm_start;
72561@@ -1764,6 +2025,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72562 }
72563 }
72564 }
72565+ if (locknext)
72566+ vma_unlock_anon_vma(vma->vm_next);
72567 vma_unlock_anon_vma(vma);
72568 khugepaged_enter_vma_merge(vma);
72569 return error;
72570@@ -1777,6 +2040,8 @@ int expand_downwards(struct vm_area_struct *vma,
72571 unsigned long address)
72572 {
72573 int error;
72574+ bool lockprev = false;
72575+ struct vm_area_struct *prev;
72576
72577 /*
72578 * We must make sure the anon_vma is allocated
72579@@ -1790,6 +2055,15 @@ int expand_downwards(struct vm_area_struct *vma,
72580 if (error)
72581 return error;
72582
72583+ prev = vma->vm_prev;
72584+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72585+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72586+#endif
72587+ if (lockprev && anon_vma_prepare(prev))
72588+ return -ENOMEM;
72589+ if (lockprev)
72590+ vma_lock_anon_vma(prev);
72591+
72592 vma_lock_anon_vma(vma);
72593
72594 /*
72595@@ -1799,9 +2073,17 @@ int expand_downwards(struct vm_area_struct *vma,
72596 */
72597
72598 /* Somebody else might have raced and expanded it already */
72599- if (address < vma->vm_start) {
72600+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72601+ error = -ENOMEM;
72602+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72603 unsigned long size, grow;
72604
72605+#ifdef CONFIG_PAX_SEGMEXEC
72606+ struct vm_area_struct *vma_m;
72607+
72608+ vma_m = pax_find_mirror_vma(vma);
72609+#endif
72610+
72611 size = vma->vm_end - address;
72612 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72613
72614@@ -1811,11 +2093,22 @@ int expand_downwards(struct vm_area_struct *vma,
72615 if (!error) {
72616 vma->vm_start = address;
72617 vma->vm_pgoff -= grow;
72618+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72619+
72620+#ifdef CONFIG_PAX_SEGMEXEC
72621+ if (vma_m) {
72622+ vma_m->vm_start -= grow << PAGE_SHIFT;
72623+ vma_m->vm_pgoff -= grow;
72624+ }
72625+#endif
72626+
72627 perf_event_mmap(vma);
72628 }
72629 }
72630 }
72631 vma_unlock_anon_vma(vma);
72632+ if (lockprev)
72633+ vma_unlock_anon_vma(prev);
72634 khugepaged_enter_vma_merge(vma);
72635 return error;
72636 }
72637@@ -1887,6 +2180,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72638 do {
72639 long nrpages = vma_pages(vma);
72640
72641+#ifdef CONFIG_PAX_SEGMEXEC
72642+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72643+ vma = remove_vma(vma);
72644+ continue;
72645+ }
72646+#endif
72647+
72648 if (vma->vm_flags & VM_ACCOUNT)
72649 nr_accounted += nrpages;
72650 mm->total_vm -= nrpages;
72651@@ -1933,6 +2233,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72652 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72653 vma->vm_prev = NULL;
72654 do {
72655+
72656+#ifdef CONFIG_PAX_SEGMEXEC
72657+ if (vma->vm_mirror) {
72658+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72659+ vma->vm_mirror->vm_mirror = NULL;
72660+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
72661+ vma->vm_mirror = NULL;
72662+ }
72663+#endif
72664+
72665 rb_erase(&vma->vm_rb, &mm->mm_rb);
72666 mm->map_count--;
72667 tail_vma = vma;
72668@@ -1961,14 +2271,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72669 struct vm_area_struct *new;
72670 int err = -ENOMEM;
72671
72672+#ifdef CONFIG_PAX_SEGMEXEC
72673+ struct vm_area_struct *vma_m, *new_m = NULL;
72674+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72675+#endif
72676+
72677 if (is_vm_hugetlb_page(vma) && (addr &
72678 ~(huge_page_mask(hstate_vma(vma)))))
72679 return -EINVAL;
72680
72681+#ifdef CONFIG_PAX_SEGMEXEC
72682+ vma_m = pax_find_mirror_vma(vma);
72683+#endif
72684+
72685 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72686 if (!new)
72687 goto out_err;
72688
72689+#ifdef CONFIG_PAX_SEGMEXEC
72690+ if (vma_m) {
72691+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72692+ if (!new_m) {
72693+ kmem_cache_free(vm_area_cachep, new);
72694+ goto out_err;
72695+ }
72696+ }
72697+#endif
72698+
72699 /* most fields are the same, copy all, and then fixup */
72700 *new = *vma;
72701
72702@@ -1981,6 +2310,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72703 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72704 }
72705
72706+#ifdef CONFIG_PAX_SEGMEXEC
72707+ if (vma_m) {
72708+ *new_m = *vma_m;
72709+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
72710+ new_m->vm_mirror = new;
72711+ new->vm_mirror = new_m;
72712+
72713+ if (new_below)
72714+ new_m->vm_end = addr_m;
72715+ else {
72716+ new_m->vm_start = addr_m;
72717+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72718+ }
72719+ }
72720+#endif
72721+
72722 pol = mpol_dup(vma_policy(vma));
72723 if (IS_ERR(pol)) {
72724 err = PTR_ERR(pol);
72725@@ -2006,6 +2351,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72726 else
72727 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72728
72729+#ifdef CONFIG_PAX_SEGMEXEC
72730+ if (!err && vma_m) {
72731+ if (anon_vma_clone(new_m, vma_m))
72732+ goto out_free_mpol;
72733+
72734+ mpol_get(pol);
72735+ vma_set_policy(new_m, pol);
72736+
72737+ if (new_m->vm_file) {
72738+ get_file(new_m->vm_file);
72739+ if (vma_m->vm_flags & VM_EXECUTABLE)
72740+ added_exe_file_vma(mm);
72741+ }
72742+
72743+ if (new_m->vm_ops && new_m->vm_ops->open)
72744+ new_m->vm_ops->open(new_m);
72745+
72746+ if (new_below)
72747+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72748+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72749+ else
72750+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72751+
72752+ if (err) {
72753+ if (new_m->vm_ops && new_m->vm_ops->close)
72754+ new_m->vm_ops->close(new_m);
72755+ if (new_m->vm_file) {
72756+ if (vma_m->vm_flags & VM_EXECUTABLE)
72757+ removed_exe_file_vma(mm);
72758+ fput(new_m->vm_file);
72759+ }
72760+ mpol_put(pol);
72761+ }
72762+ }
72763+#endif
72764+
72765 /* Success. */
72766 if (!err)
72767 return 0;
72768@@ -2018,10 +2399,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72769 removed_exe_file_vma(mm);
72770 fput(new->vm_file);
72771 }
72772- unlink_anon_vmas(new);
72773 out_free_mpol:
72774 mpol_put(pol);
72775 out_free_vma:
72776+
72777+#ifdef CONFIG_PAX_SEGMEXEC
72778+ if (new_m) {
72779+ unlink_anon_vmas(new_m);
72780+ kmem_cache_free(vm_area_cachep, new_m);
72781+ }
72782+#endif
72783+
72784+ unlink_anon_vmas(new);
72785 kmem_cache_free(vm_area_cachep, new);
72786 out_err:
72787 return err;
72788@@ -2034,6 +2423,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72789 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72790 unsigned long addr, int new_below)
72791 {
72792+
72793+#ifdef CONFIG_PAX_SEGMEXEC
72794+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72795+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72796+ if (mm->map_count >= sysctl_max_map_count-1)
72797+ return -ENOMEM;
72798+ } else
72799+#endif
72800+
72801 if (mm->map_count >= sysctl_max_map_count)
72802 return -ENOMEM;
72803
72804@@ -2045,11 +2443,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72805 * work. This now handles partial unmappings.
72806 * Jeremy Fitzhardinge <jeremy@goop.org>
72807 */
72808+#ifdef CONFIG_PAX_SEGMEXEC
72809 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72810 {
72811+ int ret = __do_munmap(mm, start, len);
72812+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72813+ return ret;
72814+
72815+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72816+}
72817+
72818+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72819+#else
72820+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72821+#endif
72822+{
72823 unsigned long end;
72824 struct vm_area_struct *vma, *prev, *last;
72825
72826+ /*
72827+ * mm->mmap_sem is required to protect against another thread
72828+ * changing the mappings in case we sleep.
72829+ */
72830+ verify_mm_writelocked(mm);
72831+
72832 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72833 return -EINVAL;
72834
72835@@ -2124,6 +2541,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72836 /* Fix up all other VM information */
72837 remove_vma_list(mm, vma);
72838
72839+ track_exec_limit(mm, start, end, 0UL);
72840+
72841 return 0;
72842 }
72843
72844@@ -2132,6 +2551,13 @@ int vm_munmap(unsigned long start, size_t len)
72845 int ret;
72846 struct mm_struct *mm = current->mm;
72847
72848+
72849+#ifdef CONFIG_PAX_SEGMEXEC
72850+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72851+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
72852+ return -EINVAL;
72853+#endif
72854+
72855 down_write(&mm->mmap_sem);
72856 ret = do_munmap(mm, start, len);
72857 up_write(&mm->mmap_sem);
72858@@ -2145,16 +2571,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72859 return vm_munmap(addr, len);
72860 }
72861
72862-static inline void verify_mm_writelocked(struct mm_struct *mm)
72863-{
72864-#ifdef CONFIG_DEBUG_VM
72865- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72866- WARN_ON(1);
72867- up_read(&mm->mmap_sem);
72868- }
72869-#endif
72870-}
72871-
72872 /*
72873 * this is really a simplified "do_mmap". it only handles
72874 * anonymous maps. eventually we may be able to do some
72875@@ -2168,6 +2584,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72876 struct rb_node ** rb_link, * rb_parent;
72877 pgoff_t pgoff = addr >> PAGE_SHIFT;
72878 int error;
72879+ unsigned long charged;
72880
72881 len = PAGE_ALIGN(len);
72882 if (!len)
72883@@ -2175,16 +2592,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72884
72885 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72886
72887+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72888+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72889+ flags &= ~VM_EXEC;
72890+
72891+#ifdef CONFIG_PAX_MPROTECT
72892+ if (mm->pax_flags & MF_PAX_MPROTECT)
72893+ flags &= ~VM_MAYEXEC;
72894+#endif
72895+
72896+ }
72897+#endif
72898+
72899 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72900 if (error & ~PAGE_MASK)
72901 return error;
72902
72903+ charged = len >> PAGE_SHIFT;
72904+
72905 /*
72906 * mlock MCL_FUTURE?
72907 */
72908 if (mm->def_flags & VM_LOCKED) {
72909 unsigned long locked, lock_limit;
72910- locked = len >> PAGE_SHIFT;
72911+ locked = charged;
72912 locked += mm->locked_vm;
72913 lock_limit = rlimit(RLIMIT_MEMLOCK);
72914 lock_limit >>= PAGE_SHIFT;
72915@@ -2201,22 +2632,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72916 /*
72917 * Clear old maps. this also does some error checking for us
72918 */
72919- munmap_back:
72920 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72921 if (vma && vma->vm_start < addr + len) {
72922 if (do_munmap(mm, addr, len))
72923 return -ENOMEM;
72924- goto munmap_back;
72925- }
72926+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72927+ BUG_ON(vma && vma->vm_start < addr + len);
72928+ }
72929
72930 /* Check against address space limits *after* clearing old maps... */
72931- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72932+ if (!may_expand_vm(mm, charged))
72933 return -ENOMEM;
72934
72935 if (mm->map_count > sysctl_max_map_count)
72936 return -ENOMEM;
72937
72938- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
72939+ if (security_vm_enough_memory_mm(mm, charged))
72940 return -ENOMEM;
72941
72942 /* Can we just expand an old private anonymous mapping? */
72943@@ -2230,7 +2661,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72944 */
72945 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72946 if (!vma) {
72947- vm_unacct_memory(len >> PAGE_SHIFT);
72948+ vm_unacct_memory(charged);
72949 return -ENOMEM;
72950 }
72951
72952@@ -2244,11 +2675,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72953 vma_link(mm, vma, prev, rb_link, rb_parent);
72954 out:
72955 perf_event_mmap(vma);
72956- mm->total_vm += len >> PAGE_SHIFT;
72957+ mm->total_vm += charged;
72958 if (flags & VM_LOCKED) {
72959 if (!mlock_vma_pages_range(vma, addr, addr + len))
72960- mm->locked_vm += (len >> PAGE_SHIFT);
72961+ mm->locked_vm += charged;
72962 }
72963+ track_exec_limit(mm, addr, addr + len, flags);
72964 return addr;
72965 }
72966
72967@@ -2306,6 +2738,7 @@ void exit_mmap(struct mm_struct *mm)
72968 while (vma) {
72969 if (vma->vm_flags & VM_ACCOUNT)
72970 nr_accounted += vma_pages(vma);
72971+ vma->vm_mirror = NULL;
72972 vma = remove_vma(vma);
72973 }
72974 vm_unacct_memory(nr_accounted);
72975@@ -2322,6 +2755,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72976 struct vm_area_struct * __vma, * prev;
72977 struct rb_node ** rb_link, * rb_parent;
72978
72979+#ifdef CONFIG_PAX_SEGMEXEC
72980+ struct vm_area_struct *vma_m = NULL;
72981+#endif
72982+
72983+ if (security_mmap_addr(vma->vm_start))
72984+ return -EPERM;
72985+
72986 /*
72987 * The vm_pgoff of a purely anonymous vma should be irrelevant
72988 * until its first write fault, when page's anon_vma and index
72989@@ -2348,7 +2788,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72990 if (vma->vm_file && uprobe_mmap(vma))
72991 return -EINVAL;
72992
72993+#ifdef CONFIG_PAX_SEGMEXEC
72994+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
72995+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72996+ if (!vma_m)
72997+ return -ENOMEM;
72998+ }
72999+#endif
73000+
73001 vma_link(mm, vma, prev, rb_link, rb_parent);
73002+
73003+#ifdef CONFIG_PAX_SEGMEXEC
73004+ if (vma_m)
73005+ BUG_ON(pax_mirror_vma(vma_m, vma));
73006+#endif
73007+
73008 return 0;
73009 }
73010
73011@@ -2367,6 +2821,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73012 struct mempolicy *pol;
73013 bool faulted_in_anon_vma = true;
73014
73015+ BUG_ON(vma->vm_mirror);
73016+
73017 /*
73018 * If anonymous vma has not yet been faulted, update new pgoff
73019 * to match new location, to increase its chance of merging.
73020@@ -2438,6 +2894,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73021 return NULL;
73022 }
73023
73024+#ifdef CONFIG_PAX_SEGMEXEC
73025+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73026+{
73027+ struct vm_area_struct *prev_m;
73028+ struct rb_node **rb_link_m, *rb_parent_m;
73029+ struct mempolicy *pol_m;
73030+
73031+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73032+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73033+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73034+ *vma_m = *vma;
73035+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73036+ if (anon_vma_clone(vma_m, vma))
73037+ return -ENOMEM;
73038+ pol_m = vma_policy(vma_m);
73039+ mpol_get(pol_m);
73040+ vma_set_policy(vma_m, pol_m);
73041+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73042+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73043+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73044+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73045+ if (vma_m->vm_file)
73046+ get_file(vma_m->vm_file);
73047+ if (vma_m->vm_ops && vma_m->vm_ops->open)
73048+ vma_m->vm_ops->open(vma_m);
73049+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73050+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73051+ vma_m->vm_mirror = vma;
73052+ vma->vm_mirror = vma_m;
73053+ return 0;
73054+}
73055+#endif
73056+
73057 /*
73058 * Return true if the calling process may expand its vm space by the passed
73059 * number of pages
73060@@ -2449,6 +2938,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73061
73062 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73063
73064+#ifdef CONFIG_PAX_RANDMMAP
73065+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73066+ cur -= mm->brk_gap;
73067+#endif
73068+
73069+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73070 if (cur + npages > lim)
73071 return 0;
73072 return 1;
73073@@ -2519,6 +3014,22 @@ int install_special_mapping(struct mm_struct *mm,
73074 vma->vm_start = addr;
73075 vma->vm_end = addr + len;
73076
73077+#ifdef CONFIG_PAX_MPROTECT
73078+ if (mm->pax_flags & MF_PAX_MPROTECT) {
73079+#ifndef CONFIG_PAX_MPROTECT_COMPAT
73080+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73081+ return -EPERM;
73082+ if (!(vm_flags & VM_EXEC))
73083+ vm_flags &= ~VM_MAYEXEC;
73084+#else
73085+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73086+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73087+#endif
73088+ else
73089+ vm_flags &= ~VM_MAYWRITE;
73090+ }
73091+#endif
73092+
73093 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73094 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73095
73096diff --git a/mm/mprotect.c b/mm/mprotect.c
73097index a409926..8b32e6d 100644
73098--- a/mm/mprotect.c
73099+++ b/mm/mprotect.c
73100@@ -23,10 +23,17 @@
73101 #include <linux/mmu_notifier.h>
73102 #include <linux/migrate.h>
73103 #include <linux/perf_event.h>
73104+
73105+#ifdef CONFIG_PAX_MPROTECT
73106+#include <linux/elf.h>
73107+#include <linux/binfmts.h>
73108+#endif
73109+
73110 #include <asm/uaccess.h>
73111 #include <asm/pgtable.h>
73112 #include <asm/cacheflush.h>
73113 #include <asm/tlbflush.h>
73114+#include <asm/mmu_context.h>
73115
73116 #ifndef pgprot_modify
73117 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73118@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73119 flush_tlb_range(vma, start, end);
73120 }
73121
73122+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73123+/* called while holding the mmap semaphor for writing except stack expansion */
73124+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73125+{
73126+ unsigned long oldlimit, newlimit = 0UL;
73127+
73128+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73129+ return;
73130+
73131+ spin_lock(&mm->page_table_lock);
73132+ oldlimit = mm->context.user_cs_limit;
73133+ if ((prot & VM_EXEC) && oldlimit < end)
73134+ /* USER_CS limit moved up */
73135+ newlimit = end;
73136+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73137+ /* USER_CS limit moved down */
73138+ newlimit = start;
73139+
73140+ if (newlimit) {
73141+ mm->context.user_cs_limit = newlimit;
73142+
73143+#ifdef CONFIG_SMP
73144+ wmb();
73145+ cpus_clear(mm->context.cpu_user_cs_mask);
73146+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73147+#endif
73148+
73149+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73150+ }
73151+ spin_unlock(&mm->page_table_lock);
73152+ if (newlimit == end) {
73153+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
73154+
73155+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
73156+ if (is_vm_hugetlb_page(vma))
73157+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73158+ else
73159+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73160+ }
73161+}
73162+#endif
73163+
73164 int
73165 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73166 unsigned long start, unsigned long end, unsigned long newflags)
73167@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73168 int error;
73169 int dirty_accountable = 0;
73170
73171+#ifdef CONFIG_PAX_SEGMEXEC
73172+ struct vm_area_struct *vma_m = NULL;
73173+ unsigned long start_m, end_m;
73174+
73175+ start_m = start + SEGMEXEC_TASK_SIZE;
73176+ end_m = end + SEGMEXEC_TASK_SIZE;
73177+#endif
73178+
73179 if (newflags == oldflags) {
73180 *pprev = vma;
73181 return 0;
73182 }
73183
73184+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73185+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73186+
73187+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73188+ return -ENOMEM;
73189+
73190+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73191+ return -ENOMEM;
73192+ }
73193+
73194 /*
73195 * If we make a private mapping writable we increase our commit;
73196 * but (without finer accounting) cannot reduce our commit if we
73197@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73198 }
73199 }
73200
73201+#ifdef CONFIG_PAX_SEGMEXEC
73202+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73203+ if (start != vma->vm_start) {
73204+ error = split_vma(mm, vma, start, 1);
73205+ if (error)
73206+ goto fail;
73207+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73208+ *pprev = (*pprev)->vm_next;
73209+ }
73210+
73211+ if (end != vma->vm_end) {
73212+ error = split_vma(mm, vma, end, 0);
73213+ if (error)
73214+ goto fail;
73215+ }
73216+
73217+ if (pax_find_mirror_vma(vma)) {
73218+ error = __do_munmap(mm, start_m, end_m - start_m);
73219+ if (error)
73220+ goto fail;
73221+ } else {
73222+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73223+ if (!vma_m) {
73224+ error = -ENOMEM;
73225+ goto fail;
73226+ }
73227+ vma->vm_flags = newflags;
73228+ error = pax_mirror_vma(vma_m, vma);
73229+ if (error) {
73230+ vma->vm_flags = oldflags;
73231+ goto fail;
73232+ }
73233+ }
73234+ }
73235+#endif
73236+
73237 /*
73238 * First try to merge with previous and/or next vma.
73239 */
73240@@ -204,9 +307,21 @@ success:
73241 * vm_flags and vm_page_prot are protected by the mmap_sem
73242 * held in write mode.
73243 */
73244+
73245+#ifdef CONFIG_PAX_SEGMEXEC
73246+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73247+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73248+#endif
73249+
73250 vma->vm_flags = newflags;
73251+
73252+#ifdef CONFIG_PAX_MPROTECT
73253+ if (mm->binfmt && mm->binfmt->handle_mprotect)
73254+ mm->binfmt->handle_mprotect(vma, newflags);
73255+#endif
73256+
73257 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73258- vm_get_page_prot(newflags));
73259+ vm_get_page_prot(vma->vm_flags));
73260
73261 if (vma_wants_writenotify(vma)) {
73262 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73263@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73264 end = start + len;
73265 if (end <= start)
73266 return -ENOMEM;
73267+
73268+#ifdef CONFIG_PAX_SEGMEXEC
73269+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73270+ if (end > SEGMEXEC_TASK_SIZE)
73271+ return -EINVAL;
73272+ } else
73273+#endif
73274+
73275+ if (end > TASK_SIZE)
73276+ return -EINVAL;
73277+
73278 if (!arch_validate_prot(prot))
73279 return -EINVAL;
73280
73281@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73282 /*
73283 * Does the application expect PROT_READ to imply PROT_EXEC:
73284 */
73285- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73286+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73287 prot |= PROT_EXEC;
73288
73289 vm_flags = calc_vm_prot_bits(prot);
73290@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73291 if (start > vma->vm_start)
73292 prev = vma;
73293
73294+#ifdef CONFIG_PAX_MPROTECT
73295+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73296+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
73297+#endif
73298+
73299 for (nstart = start ; ; ) {
73300 unsigned long newflags;
73301
73302@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73303
73304 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73305 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73306+ if (prot & (PROT_WRITE | PROT_EXEC))
73307+ gr_log_rwxmprotect(vma->vm_file);
73308+
73309+ error = -EACCES;
73310+ goto out;
73311+ }
73312+
73313+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73314 error = -EACCES;
73315 goto out;
73316 }
73317@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73318 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73319 if (error)
73320 goto out;
73321+
73322+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
73323+
73324 nstart = tmp;
73325
73326 if (nstart < prev->vm_end)
73327diff --git a/mm/mremap.c b/mm/mremap.c
73328index 21fed20..6822658 100644
73329--- a/mm/mremap.c
73330+++ b/mm/mremap.c
73331@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
73332 continue;
73333 pte = ptep_get_and_clear(mm, old_addr, old_pte);
73334 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73335+
73336+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73337+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73338+ pte = pte_exprotect(pte);
73339+#endif
73340+
73341 set_pte_at(mm, new_addr, new_pte, pte);
73342 }
73343
73344@@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
73345 if (is_vm_hugetlb_page(vma))
73346 goto Einval;
73347
73348+#ifdef CONFIG_PAX_SEGMEXEC
73349+ if (pax_find_mirror_vma(vma))
73350+ goto Einval;
73351+#endif
73352+
73353 /* We can't remap across vm area boundaries */
73354 if (old_len > vma->vm_end - addr)
73355 goto Efault;
73356@@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
73357 unsigned long ret = -EINVAL;
73358 unsigned long charged = 0;
73359 unsigned long map_flags;
73360+ unsigned long pax_task_size = TASK_SIZE;
73361
73362 if (new_addr & ~PAGE_MASK)
73363 goto out;
73364
73365- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
73366+#ifdef CONFIG_PAX_SEGMEXEC
73367+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
73368+ pax_task_size = SEGMEXEC_TASK_SIZE;
73369+#endif
73370+
73371+ pax_task_size -= PAGE_SIZE;
73372+
73373+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
73374 goto out;
73375
73376 /* Check if the location we're moving into overlaps the
73377 * old location at all, and fail if it does.
73378 */
73379- if ((new_addr <= addr) && (new_addr+new_len) > addr)
73380- goto out;
73381-
73382- if ((addr <= new_addr) && (addr+old_len) > new_addr)
73383+ if (addr + old_len > new_addr && new_addr + new_len > addr)
73384 goto out;
73385
73386 ret = do_munmap(mm, new_addr, new_len);
73387@@ -436,6 +452,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73388 struct vm_area_struct *vma;
73389 unsigned long ret = -EINVAL;
73390 unsigned long charged = 0;
73391+ unsigned long pax_task_size = TASK_SIZE;
73392
73393 down_write(&current->mm->mmap_sem);
73394
73395@@ -456,6 +473,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73396 if (!new_len)
73397 goto out;
73398
73399+#ifdef CONFIG_PAX_SEGMEXEC
73400+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
73401+ pax_task_size = SEGMEXEC_TASK_SIZE;
73402+#endif
73403+
73404+ pax_task_size -= PAGE_SIZE;
73405+
73406+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73407+ old_len > pax_task_size || addr > pax_task_size-old_len)
73408+ goto out;
73409+
73410 if (flags & MREMAP_FIXED) {
73411 if (flags & MREMAP_MAYMOVE)
73412 ret = mremap_to(addr, old_len, new_addr, new_len);
73413@@ -505,6 +533,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73414 addr + new_len);
73415 }
73416 ret = addr;
73417+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73418 goto out;
73419 }
73420 }
73421@@ -528,7 +557,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73422 goto out;
73423 }
73424
73425+ map_flags = vma->vm_flags;
73426 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73427+ if (!(ret & ~PAGE_MASK)) {
73428+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73429+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73430+ }
73431 }
73432 out:
73433 if (ret & ~PAGE_MASK)
73434diff --git a/mm/nommu.c b/mm/nommu.c
73435index d4b0c10..ed421b5 100644
73436--- a/mm/nommu.c
73437+++ b/mm/nommu.c
73438@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73439 int sysctl_overcommit_ratio = 50; /* default is 50% */
73440 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73441 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73442-int heap_stack_gap = 0;
73443
73444 atomic_long_t mmap_pages_allocated;
73445
73446@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73447 EXPORT_SYMBOL(find_vma);
73448
73449 /*
73450- * find a VMA
73451- * - we don't extend stack VMAs under NOMMU conditions
73452- */
73453-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73454-{
73455- return find_vma(mm, addr);
73456-}
73457-
73458-/*
73459 * expand a stack to a given address
73460 * - not supported under NOMMU conditions
73461 */
73462@@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73463
73464 /* most fields are the same, copy all, and then fixup */
73465 *new = *vma;
73466+ INIT_LIST_HEAD(&new->anon_vma_chain);
73467 *region = *vma->vm_region;
73468 new->vm_region = region;
73469
73470diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73471index 4a4f921..eaa5e3a 100644
73472--- a/mm/page_alloc.c
73473+++ b/mm/page_alloc.c
73474@@ -336,7 +336,7 @@ out:
73475 * This usage means that zero-order pages may not be compound.
73476 */
73477
73478-static void free_compound_page(struct page *page)
73479+void free_compound_page(struct page *page)
73480 {
73481 __free_pages_ok(page, compound_order(page));
73482 }
73483@@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73484 int i;
73485 int bad = 0;
73486
73487+#ifdef CONFIG_PAX_MEMORY_SANITIZE
73488+ unsigned long index = 1UL << order;
73489+#endif
73490+
73491 trace_mm_page_free(page, order);
73492 kmemcheck_free_shadow(page, order);
73493
73494@@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73495 debug_check_no_obj_freed(page_address(page),
73496 PAGE_SIZE << order);
73497 }
73498+
73499+#ifdef CONFIG_PAX_MEMORY_SANITIZE
73500+ for (; index; --index)
73501+ sanitize_highpage(page + index - 1);
73502+#endif
73503+
73504 arch_free_page(page, order);
73505 kernel_map_pages(page, 1 << order, 0);
73506
73507@@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73508 arch_alloc_page(page, order);
73509 kernel_map_pages(page, 1 << order, 1);
73510
73511+#ifndef CONFIG_PAX_MEMORY_SANITIZE
73512 if (gfp_flags & __GFP_ZERO)
73513 prep_zero_page(page, order, gfp_flags);
73514+#endif
73515
73516 if (order && (gfp_flags & __GFP_COMP))
73517 prep_compound_page(page, order);
73518@@ -3579,7 +3591,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73519 unsigned long pfn;
73520
73521 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73522+#ifdef CONFIG_X86_32
73523+ /* boot failures in VMware 8 on 32bit vanilla since
73524+ this change */
73525+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73526+#else
73527 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73528+#endif
73529 return 1;
73530 }
73531 return 0;
73532diff --git a/mm/percpu.c b/mm/percpu.c
73533index bb4be74..a43ea85 100644
73534--- a/mm/percpu.c
73535+++ b/mm/percpu.c
73536@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73537 static unsigned int pcpu_high_unit_cpu __read_mostly;
73538
73539 /* the address of the first chunk which starts with the kernel static area */
73540-void *pcpu_base_addr __read_mostly;
73541+void *pcpu_base_addr __read_only;
73542 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73543
73544 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73545diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73546index 926b466..b23df53 100644
73547--- a/mm/process_vm_access.c
73548+++ b/mm/process_vm_access.c
73549@@ -13,6 +13,7 @@
73550 #include <linux/uio.h>
73551 #include <linux/sched.h>
73552 #include <linux/highmem.h>
73553+#include <linux/security.h>
73554 #include <linux/ptrace.h>
73555 #include <linux/slab.h>
73556 #include <linux/syscalls.h>
73557@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73558 size_t iov_l_curr_offset = 0;
73559 ssize_t iov_len;
73560
73561+ return -ENOSYS; // PaX: until properly audited
73562+
73563 /*
73564 * Work out how many pages of struct pages we're going to need
73565 * when eventually calling get_user_pages
73566 */
73567 for (i = 0; i < riovcnt; i++) {
73568 iov_len = rvec[i].iov_len;
73569- if (iov_len > 0) {
73570- nr_pages_iov = ((unsigned long)rvec[i].iov_base
73571- + iov_len)
73572- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73573- / PAGE_SIZE + 1;
73574- nr_pages = max(nr_pages, nr_pages_iov);
73575- }
73576+ if (iov_len <= 0)
73577+ continue;
73578+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73579+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73580+ nr_pages = max(nr_pages, nr_pages_iov);
73581 }
73582
73583 if (nr_pages == 0)
73584@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73585 goto free_proc_pages;
73586 }
73587
73588+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73589+ rc = -EPERM;
73590+ goto put_task_struct;
73591+ }
73592+
73593 mm = mm_access(task, PTRACE_MODE_ATTACH);
73594 if (!mm || IS_ERR(mm)) {
73595 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73596diff --git a/mm/rmap.c b/mm/rmap.c
73597index 0f3b7cd..c5652b6 100644
73598--- a/mm/rmap.c
73599+++ b/mm/rmap.c
73600@@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73601 struct anon_vma *anon_vma = vma->anon_vma;
73602 struct anon_vma_chain *avc;
73603
73604+#ifdef CONFIG_PAX_SEGMEXEC
73605+ struct anon_vma_chain *avc_m = NULL;
73606+#endif
73607+
73608 might_sleep();
73609 if (unlikely(!anon_vma)) {
73610 struct mm_struct *mm = vma->vm_mm;
73611@@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73612 if (!avc)
73613 goto out_enomem;
73614
73615+#ifdef CONFIG_PAX_SEGMEXEC
73616+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73617+ if (!avc_m)
73618+ goto out_enomem_free_avc;
73619+#endif
73620+
73621 anon_vma = find_mergeable_anon_vma(vma);
73622 allocated = NULL;
73623 if (!anon_vma) {
73624@@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73625 /* page_table_lock to protect against threads */
73626 spin_lock(&mm->page_table_lock);
73627 if (likely(!vma->anon_vma)) {
73628+
73629+#ifdef CONFIG_PAX_SEGMEXEC
73630+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73631+
73632+ if (vma_m) {
73633+ BUG_ON(vma_m->anon_vma);
73634+ vma_m->anon_vma = anon_vma;
73635+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
73636+ avc_m = NULL;
73637+ }
73638+#endif
73639+
73640 vma->anon_vma = anon_vma;
73641 anon_vma_chain_link(vma, avc, anon_vma);
73642 allocated = NULL;
73643@@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73644
73645 if (unlikely(allocated))
73646 put_anon_vma(allocated);
73647+
73648+#ifdef CONFIG_PAX_SEGMEXEC
73649+ if (unlikely(avc_m))
73650+ anon_vma_chain_free(avc_m);
73651+#endif
73652+
73653 if (unlikely(avc))
73654 anon_vma_chain_free(avc);
73655 }
73656 return 0;
73657
73658 out_enomem_free_avc:
73659+
73660+#ifdef CONFIG_PAX_SEGMEXEC
73661+ if (avc_m)
73662+ anon_vma_chain_free(avc_m);
73663+#endif
73664+
73665 anon_vma_chain_free(avc);
73666 out_enomem:
73667 return -ENOMEM;
73668@@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
73669 * Attach the anon_vmas from src to dst.
73670 * Returns 0 on success, -ENOMEM on failure.
73671 */
73672-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73673+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73674 {
73675 struct anon_vma_chain *avc, *pavc;
73676 struct anon_vma *root = NULL;
73677@@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73678 * the corresponding VMA in the parent process is attached to.
73679 * Returns 0 on success, non-zero on failure.
73680 */
73681-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73682+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73683 {
73684 struct anon_vma_chain *avc;
73685 struct anon_vma *anon_vma;
73686diff --git a/mm/shmem.c b/mm/shmem.c
73687index bd10636..5c16d49 100644
73688--- a/mm/shmem.c
73689+++ b/mm/shmem.c
73690@@ -31,7 +31,7 @@
73691 #include <linux/export.h>
73692 #include <linux/swap.h>
73693
73694-static struct vfsmount *shm_mnt;
73695+struct vfsmount *shm_mnt;
73696
73697 #ifdef CONFIG_SHMEM
73698 /*
73699@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
73700 #define BOGO_DIRENT_SIZE 20
73701
73702 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73703-#define SHORT_SYMLINK_LEN 128
73704+#define SHORT_SYMLINK_LEN 64
73705
73706 struct shmem_xattr {
73707 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73708@@ -2590,8 +2590,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73709 int err = -ENOMEM;
73710
73711 /* Round up to L1_CACHE_BYTES to resist false sharing */
73712- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73713- L1_CACHE_BYTES), GFP_KERNEL);
73714+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73715 if (!sbinfo)
73716 return -ENOMEM;
73717
73718diff --git a/mm/slab.c b/mm/slab.c
73719index e901a36..ca479fc 100644
73720--- a/mm/slab.c
73721+++ b/mm/slab.c
73722@@ -153,7 +153,7 @@
73723
73724 /* Legal flag mask for kmem_cache_create(). */
73725 #if DEBUG
73726-# define CREATE_MASK (SLAB_RED_ZONE | \
73727+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73728 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73729 SLAB_CACHE_DMA | \
73730 SLAB_STORE_USER | \
73731@@ -161,7 +161,7 @@
73732 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73733 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73734 #else
73735-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73736+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73737 SLAB_CACHE_DMA | \
73738 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73739 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73740@@ -290,7 +290,7 @@ struct kmem_list3 {
73741 * Need this for bootstrapping a per node allocator.
73742 */
73743 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73744-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73745+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73746 #define CACHE_CACHE 0
73747 #define SIZE_AC MAX_NUMNODES
73748 #define SIZE_L3 (2 * MAX_NUMNODES)
73749@@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73750 if ((x)->max_freeable < i) \
73751 (x)->max_freeable = i; \
73752 } while (0)
73753-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73754-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73755-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73756-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73757+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73758+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73759+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73760+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73761 #else
73762 #define STATS_INC_ACTIVE(x) do { } while (0)
73763 #define STATS_DEC_ACTIVE(x) do { } while (0)
73764@@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73765 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73766 */
73767 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73768- const struct slab *slab, void *obj)
73769+ const struct slab *slab, const void *obj)
73770 {
73771 u32 offset = (obj - slab->s_mem);
73772 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73773@@ -563,12 +563,13 @@ EXPORT_SYMBOL(malloc_sizes);
73774 struct cache_names {
73775 char *name;
73776 char *name_dma;
73777+ char *name_usercopy;
73778 };
73779
73780 static struct cache_names __initdata cache_names[] = {
73781-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73782+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
73783 #include <linux/kmalloc_sizes.h>
73784- {NULL,}
73785+ {NULL}
73786 #undef CACHE
73787 };
73788
73789@@ -756,6 +757,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
73790 if (unlikely(gfpflags & GFP_DMA))
73791 return csizep->cs_dmacachep;
73792 #endif
73793+
73794+#ifdef CONFIG_PAX_USERCOPY_SLABS
73795+ if (unlikely(gfpflags & GFP_USERCOPY))
73796+ return csizep->cs_usercopycachep;
73797+#endif
73798+
73799 return csizep->cs_cachep;
73800 }
73801
73802@@ -1588,7 +1595,7 @@ void __init kmem_cache_init(void)
73803 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73804 sizes[INDEX_AC].cs_size,
73805 ARCH_KMALLOC_MINALIGN,
73806- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73807+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73808 NULL);
73809
73810 if (INDEX_AC != INDEX_L3) {
73811@@ -1596,7 +1603,7 @@ void __init kmem_cache_init(void)
73812 kmem_cache_create(names[INDEX_L3].name,
73813 sizes[INDEX_L3].cs_size,
73814 ARCH_KMALLOC_MINALIGN,
73815- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73816+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73817 NULL);
73818 }
73819
73820@@ -1614,7 +1621,7 @@ void __init kmem_cache_init(void)
73821 sizes->cs_cachep = kmem_cache_create(names->name,
73822 sizes->cs_size,
73823 ARCH_KMALLOC_MINALIGN,
73824- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73825+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73826 NULL);
73827 }
73828 #ifdef CONFIG_ZONE_DMA
73829@@ -1626,6 +1633,16 @@ void __init kmem_cache_init(void)
73830 SLAB_PANIC,
73831 NULL);
73832 #endif
73833+
73834+#ifdef CONFIG_PAX_USERCOPY_SLABS
73835+ sizes->cs_usercopycachep = kmem_cache_create(
73836+ names->name_usercopy,
73837+ sizes->cs_size,
73838+ ARCH_KMALLOC_MINALIGN,
73839+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73840+ NULL);
73841+#endif
73842+
73843 sizes++;
73844 names++;
73845 }
73846@@ -4390,10 +4407,10 @@ static int s_show(struct seq_file *m, void *p)
73847 }
73848 /* cpu stats */
73849 {
73850- unsigned long allochit = atomic_read(&cachep->allochit);
73851- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73852- unsigned long freehit = atomic_read(&cachep->freehit);
73853- unsigned long freemiss = atomic_read(&cachep->freemiss);
73854+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73855+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73856+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73857+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73858
73859 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73860 allochit, allocmiss, freehit, freemiss);
73861@@ -4652,13 +4669,68 @@ static int __init slab_proc_init(void)
73862 {
73863 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73864 #ifdef CONFIG_DEBUG_SLAB_LEAK
73865- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73866+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73867 #endif
73868 return 0;
73869 }
73870 module_init(slab_proc_init);
73871 #endif
73872
73873+bool is_usercopy_object(const void *ptr)
73874+{
73875+ struct page *page;
73876+ struct kmem_cache *cachep;
73877+
73878+ if (ZERO_OR_NULL_PTR(ptr))
73879+ return false;
73880+
73881+ if (!virt_addr_valid(ptr))
73882+ return false;
73883+
73884+ page = virt_to_head_page(ptr);
73885+
73886+ if (!PageSlab(page))
73887+ return false;
73888+
73889+ cachep = page_get_cache(page);
73890+ return cachep->flags & SLAB_USERCOPY;
73891+}
73892+
73893+#ifdef CONFIG_PAX_USERCOPY
73894+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
73895+{
73896+ struct page *page;
73897+ struct kmem_cache *cachep;
73898+ struct slab *slabp;
73899+ unsigned int objnr;
73900+ unsigned long offset;
73901+
73902+ if (ZERO_OR_NULL_PTR(ptr))
73903+ return "<null>";
73904+
73905+ if (!virt_addr_valid(ptr))
73906+ return NULL;
73907+
73908+ page = virt_to_head_page(ptr);
73909+
73910+ if (!PageSlab(page))
73911+ return NULL;
73912+
73913+ cachep = page_get_cache(page);
73914+ if (!(cachep->flags & SLAB_USERCOPY))
73915+ return cachep->name;
73916+
73917+ slabp = page_get_slab(page);
73918+ objnr = obj_to_index(cachep, slabp, ptr);
73919+ BUG_ON(objnr >= cachep->num);
73920+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73921+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73922+ return NULL;
73923+
73924+ return cachep->name;
73925+}
73926+#endif
73927+
73928 /**
73929 * ksize - get the actual amount of memory allocated for a given object
73930 * @objp: Pointer to the object
73931diff --git a/mm/slob.c b/mm/slob.c
73932index 8105be4..3c15e57 100644
73933--- a/mm/slob.c
73934+++ b/mm/slob.c
73935@@ -29,7 +29,7 @@
73936 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73937 * alloc_pages() directly, allocating compound pages so the page order
73938 * does not have to be separately tracked, and also stores the exact
73939- * allocation size in page->private so that it can be used to accurately
73940+ * allocation size in slob_page->size so that it can be used to accurately
73941 * provide ksize(). These objects are detected in kfree() because slob_page()
73942 * is false for them.
73943 *
73944@@ -58,6 +58,7 @@
73945 */
73946
73947 #include <linux/kernel.h>
73948+#include <linux/sched.h>
73949 #include <linux/slab.h>
73950 #include <linux/mm.h>
73951 #include <linux/swap.h> /* struct reclaim_state */
73952@@ -102,7 +103,8 @@ struct slob_page {
73953 unsigned long flags; /* mandatory */
73954 atomic_t _count; /* mandatory */
73955 slobidx_t units; /* free units left in page */
73956- unsigned long pad[2];
73957+ unsigned long pad[1];
73958+ unsigned long size; /* size when >=PAGE_SIZE */
73959 slob_t *free; /* first free slob_t in page */
73960 struct list_head list; /* linked list of free pages */
73961 };
73962@@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
73963 */
73964 static inline int is_slob_page(struct slob_page *sp)
73965 {
73966- return PageSlab((struct page *)sp);
73967+ return PageSlab((struct page *)sp) && !sp->size;
73968 }
73969
73970 static inline void set_slob_page(struct slob_page *sp)
73971@@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
73972
73973 static inline struct slob_page *slob_page(const void *addr)
73974 {
73975- return (struct slob_page *)virt_to_page(addr);
73976+ return (struct slob_page *)virt_to_head_page(addr);
73977 }
73978
73979 /*
73980@@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
73981 /*
73982 * Return the size of a slob block.
73983 */
73984-static slobidx_t slob_units(slob_t *s)
73985+static slobidx_t slob_units(const slob_t *s)
73986 {
73987 if (s->units > 0)
73988 return s->units;
73989@@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
73990 /*
73991 * Return the next free slob block pointer after this one.
73992 */
73993-static slob_t *slob_next(slob_t *s)
73994+static slob_t *slob_next(const slob_t *s)
73995 {
73996 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
73997 slobidx_t next;
73998@@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
73999 /*
74000 * Returns true if s is the last free block in its page.
74001 */
74002-static int slob_last(slob_t *s)
74003+static int slob_last(const slob_t *s)
74004 {
74005 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74006 }
74007@@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74008 if (!page)
74009 return NULL;
74010
74011+ set_slob_page(page);
74012 return page_address(page);
74013 }
74014
74015@@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74016 if (!b)
74017 return NULL;
74018 sp = slob_page(b);
74019- set_slob_page(sp);
74020
74021 spin_lock_irqsave(&slob_lock, flags);
74022 sp->units = SLOB_UNITS(PAGE_SIZE);
74023 sp->free = b;
74024+ sp->size = 0;
74025 INIT_LIST_HEAD(&sp->list);
74026 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74027 set_slob_page_free(sp, slob_list);
74028@@ -476,10 +479,9 @@ out:
74029 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74030 */
74031
74032-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74033+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74034 {
74035- unsigned int *m;
74036- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74037+ slob_t *m;
74038 void *ret;
74039
74040 gfp &= gfp_allowed_mask;
74041@@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74042
74043 if (!m)
74044 return NULL;
74045- *m = size;
74046+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74047+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74048+ m[0].units = size;
74049+ m[1].units = align;
74050 ret = (void *)m + align;
74051
74052 trace_kmalloc_node(_RET_IP_, ret,
74053@@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74054 gfp |= __GFP_COMP;
74055 ret = slob_new_pages(gfp, order, node);
74056 if (ret) {
74057- struct page *page;
74058- page = virt_to_page(ret);
74059- page->private = size;
74060+ struct slob_page *sp;
74061+ sp = slob_page(ret);
74062+ sp->size = size;
74063 }
74064
74065 trace_kmalloc_node(_RET_IP_, ret,
74066 size, PAGE_SIZE << order, gfp, node);
74067 }
74068
74069- kmemleak_alloc(ret, size, 1, gfp);
74070+ return ret;
74071+}
74072+
74073+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74074+{
74075+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74076+ void *ret = __kmalloc_node_align(size, gfp, node, align);
74077+
74078+ if (!ZERO_OR_NULL_PTR(ret))
74079+ kmemleak_alloc(ret, size, 1, gfp);
74080 return ret;
74081 }
74082 EXPORT_SYMBOL(__kmalloc_node);
74083@@ -533,13 +547,83 @@ void kfree(const void *block)
74084 sp = slob_page(block);
74085 if (is_slob_page(sp)) {
74086 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74087- unsigned int *m = (unsigned int *)(block - align);
74088- slob_free(m, *m + align);
74089- } else
74090+ slob_t *m = (slob_t *)(block - align);
74091+ slob_free(m, m[0].units + align);
74092+ } else {
74093+ clear_slob_page(sp);
74094+ free_slob_page(sp);
74095+ sp->size = 0;
74096 put_page(&sp->page);
74097+ }
74098 }
74099 EXPORT_SYMBOL(kfree);
74100
74101+bool is_usercopy_object(const void *ptr)
74102+{
74103+ return false;
74104+}
74105+
74106+#ifdef CONFIG_PAX_USERCOPY
74107+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74108+{
74109+ struct slob_page *sp;
74110+ const slob_t *free;
74111+ const void *base;
74112+ unsigned long flags;
74113+
74114+ if (ZERO_OR_NULL_PTR(ptr))
74115+ return "<null>";
74116+
74117+ if (!virt_addr_valid(ptr))
74118+ return NULL;
74119+
74120+ sp = slob_page(ptr);
74121+ if (!PageSlab((struct page *)sp))
74122+ return NULL;
74123+
74124+ if (sp->size) {
74125+ base = page_address(&sp->page);
74126+ if (base <= ptr && n <= sp->size - (ptr - base))
74127+ return NULL;
74128+ return "<slob>";
74129+ }
74130+
74131+ /* some tricky double walking to find the chunk */
74132+ spin_lock_irqsave(&slob_lock, flags);
74133+ base = (void *)((unsigned long)ptr & PAGE_MASK);
74134+ free = sp->free;
74135+
74136+ while (!slob_last(free) && (void *)free <= ptr) {
74137+ base = free + slob_units(free);
74138+ free = slob_next(free);
74139+ }
74140+
74141+ while (base < (void *)free) {
74142+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74143+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
74144+ int offset;
74145+
74146+ if (ptr < base + align)
74147+ break;
74148+
74149+ offset = ptr - base - align;
74150+ if (offset >= m) {
74151+ base += size;
74152+ continue;
74153+ }
74154+
74155+ if (n > m - offset)
74156+ break;
74157+
74158+ spin_unlock_irqrestore(&slob_lock, flags);
74159+ return NULL;
74160+ }
74161+
74162+ spin_unlock_irqrestore(&slob_lock, flags);
74163+ return "<slob>";
74164+}
74165+#endif
74166+
74167 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74168 size_t ksize(const void *block)
74169 {
74170@@ -552,10 +636,10 @@ size_t ksize(const void *block)
74171 sp = slob_page(block);
74172 if (is_slob_page(sp)) {
74173 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74174- unsigned int *m = (unsigned int *)(block - align);
74175- return SLOB_UNITS(*m) * SLOB_UNIT;
74176+ slob_t *m = (slob_t *)(block - align);
74177+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74178 } else
74179- return sp->page.private;
74180+ return sp->size;
74181 }
74182 EXPORT_SYMBOL(ksize);
74183
74184@@ -571,8 +655,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74185 {
74186 struct kmem_cache *c;
74187
74188+#ifdef CONFIG_PAX_USERCOPY_SLABS
74189+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
74190+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74191+#else
74192 c = slob_alloc(sizeof(struct kmem_cache),
74193 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74194+#endif
74195
74196 if (c) {
74197 c->name = name;
74198@@ -614,17 +703,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74199
74200 lockdep_trace_alloc(flags);
74201
74202+#ifdef CONFIG_PAX_USERCOPY_SLABS
74203+ b = __kmalloc_node_align(c->size, flags, node, c->align);
74204+#else
74205 if (c->size < PAGE_SIZE) {
74206 b = slob_alloc(c->size, flags, c->align, node);
74207 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74208 SLOB_UNITS(c->size) * SLOB_UNIT,
74209 flags, node);
74210 } else {
74211+ struct slob_page *sp;
74212+
74213 b = slob_new_pages(flags, get_order(c->size), node);
74214+ sp = slob_page(b);
74215+ sp->size = c->size;
74216 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74217 PAGE_SIZE << get_order(c->size),
74218 flags, node);
74219 }
74220+#endif
74221
74222 if (c->ctor)
74223 c->ctor(b);
74224@@ -636,10 +733,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74225
74226 static void __kmem_cache_free(void *b, int size)
74227 {
74228- if (size < PAGE_SIZE)
74229+ struct slob_page *sp = slob_page(b);
74230+
74231+ if (is_slob_page(sp))
74232 slob_free(b, size);
74233- else
74234+ else {
74235+ clear_slob_page(sp);
74236+ free_slob_page(sp);
74237+ sp->size = 0;
74238 slob_free_pages(b, get_order(size));
74239+ }
74240 }
74241
74242 static void kmem_rcu_free(struct rcu_head *head)
74243@@ -652,17 +755,31 @@ static void kmem_rcu_free(struct rcu_head *head)
74244
74245 void kmem_cache_free(struct kmem_cache *c, void *b)
74246 {
74247+ int size = c->size;
74248+
74249+#ifdef CONFIG_PAX_USERCOPY_SLABS
74250+ if (size + c->align < PAGE_SIZE) {
74251+ size += c->align;
74252+ b -= c->align;
74253+ }
74254+#endif
74255+
74256 kmemleak_free_recursive(b, c->flags);
74257 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74258 struct slob_rcu *slob_rcu;
74259- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74260- slob_rcu->size = c->size;
74261+ slob_rcu = b + (size - sizeof(struct slob_rcu));
74262+ slob_rcu->size = size;
74263 call_rcu(&slob_rcu->head, kmem_rcu_free);
74264 } else {
74265- __kmem_cache_free(b, c->size);
74266+ __kmem_cache_free(b, size);
74267 }
74268
74269+#ifdef CONFIG_PAX_USERCOPY_SLABS
74270+ trace_kfree(_RET_IP_, b);
74271+#else
74272 trace_kmem_cache_free(_RET_IP_, b);
74273+#endif
74274+
74275 }
74276 EXPORT_SYMBOL(kmem_cache_free);
74277
74278diff --git a/mm/slub.c b/mm/slub.c
74279index 8c691fa..ff23a85 100644
74280--- a/mm/slub.c
74281+++ b/mm/slub.c
74282@@ -209,7 +209,7 @@ struct track {
74283
74284 enum track_item { TRACK_ALLOC, TRACK_FREE };
74285
74286-#ifdef CONFIG_SYSFS
74287+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74288 static int sysfs_slab_add(struct kmem_cache *);
74289 static int sysfs_slab_alias(struct kmem_cache *, const char *);
74290 static void sysfs_slab_remove(struct kmem_cache *);
74291@@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
74292 if (!t->addr)
74293 return;
74294
74295- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74296+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74297 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74298 #ifdef CONFIG_STACKTRACE
74299 {
74300@@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
74301
74302 page = virt_to_head_page(x);
74303
74304+ BUG_ON(!PageSlab(page));
74305+
74306 slab_free(s, page, x, _RET_IP_);
74307
74308 trace_kmem_cache_free(_RET_IP_, x);
74309@@ -2636,7 +2638,7 @@ static int slub_min_objects;
74310 * Merge control. If this is set then no merging of slab caches will occur.
74311 * (Could be removed. This was introduced to pacify the merge skeptics.)
74312 */
74313-static int slub_nomerge;
74314+static int slub_nomerge = 1;
74315
74316 /*
74317 * Calculate the order of allocation given an slab object size.
74318@@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
74319 else
74320 s->cpu_partial = 30;
74321
74322- s->refcount = 1;
74323+ atomic_set(&s->refcount, 1);
74324 #ifdef CONFIG_NUMA
74325 s->remote_node_defrag_ratio = 1000;
74326 #endif
74327@@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
74328 void kmem_cache_destroy(struct kmem_cache *s)
74329 {
74330 down_write(&slub_lock);
74331- s->refcount--;
74332- if (!s->refcount) {
74333+ if (atomic_dec_and_test(&s->refcount)) {
74334 list_del(&s->list);
74335 up_write(&slub_lock);
74336 if (kmem_cache_close(s)) {
74337@@ -3223,6 +3224,10 @@ static struct kmem_cache *kmem_cache;
74338 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
74339 #endif
74340
74341+#ifdef CONFIG_PAX_USERCOPY_SLABS
74342+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
74343+#endif
74344+
74345 static int __init setup_slub_min_order(char *str)
74346 {
74347 get_option(&str, &slub_min_order);
74348@@ -3337,6 +3342,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
74349 return kmalloc_dma_caches[index];
74350
74351 #endif
74352+
74353+#ifdef CONFIG_PAX_USERCOPY_SLABS
74354+ if (flags & SLAB_USERCOPY)
74355+ return kmalloc_usercopy_caches[index];
74356+
74357+#endif
74358+
74359 return kmalloc_caches[index];
74360 }
74361
74362@@ -3405,6 +3417,56 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
74363 EXPORT_SYMBOL(__kmalloc_node);
74364 #endif
74365
74366+bool is_usercopy_object(const void *ptr)
74367+{
74368+ struct page *page;
74369+ struct kmem_cache *s;
74370+
74371+ if (ZERO_OR_NULL_PTR(ptr))
74372+ return false;
74373+
74374+ if (!virt_addr_valid(ptr))
74375+ return false;
74376+
74377+ page = virt_to_head_page(ptr);
74378+
74379+ if (!PageSlab(page))
74380+ return false;
74381+
74382+ s = page->slab;
74383+ return s->flags & SLAB_USERCOPY;
74384+}
74385+
74386+#ifdef CONFIG_PAX_USERCOPY
74387+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74388+{
74389+ struct page *page;
74390+ struct kmem_cache *s;
74391+ unsigned long offset;
74392+
74393+ if (ZERO_OR_NULL_PTR(ptr))
74394+ return "<null>";
74395+
74396+ if (!virt_addr_valid(ptr))
74397+ return NULL;
74398+
74399+ page = virt_to_head_page(ptr);
74400+
74401+ if (!PageSlab(page))
74402+ return NULL;
74403+
74404+ s = page->slab;
74405+ if (!(s->flags & SLAB_USERCOPY))
74406+ return s->name;
74407+
74408+ offset = (ptr - page_address(page)) % s->size;
74409+ if (offset <= s->objsize && n <= s->objsize - offset)
74410+ return NULL;
74411+
74412+ return s->name;
74413+}
74414+#endif
74415+
74416 size_t ksize(const void *object)
74417 {
74418 struct page *page;
74419@@ -3679,7 +3741,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
74420 int node;
74421
74422 list_add(&s->list, &slab_caches);
74423- s->refcount = -1;
74424+ atomic_set(&s->refcount, -1);
74425
74426 for_each_node_state(node, N_NORMAL_MEMORY) {
74427 struct kmem_cache_node *n = get_node(s, node);
74428@@ -3799,17 +3861,17 @@ void __init kmem_cache_init(void)
74429
74430 /* Caches that are not of the two-to-the-power-of size */
74431 if (KMALLOC_MIN_SIZE <= 32) {
74432- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74433+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74434 caches++;
74435 }
74436
74437 if (KMALLOC_MIN_SIZE <= 64) {
74438- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74439+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74440 caches++;
74441 }
74442
74443 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74444- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74445+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74446 caches++;
74447 }
74448
74449@@ -3851,6 +3913,22 @@ void __init kmem_cache_init(void)
74450 }
74451 }
74452 #endif
74453+
74454+#ifdef CONFIG_PAX_USERCOPY_SLABS
74455+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
74456+ struct kmem_cache *s = kmalloc_caches[i];
74457+
74458+ if (s && s->size) {
74459+ char *name = kasprintf(GFP_NOWAIT,
74460+ "usercopy-kmalloc-%d", s->objsize);
74461+
74462+ BUG_ON(!name);
74463+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
74464+ s->objsize, SLAB_USERCOPY);
74465+ }
74466+ }
74467+#endif
74468+
74469 printk(KERN_INFO
74470 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
74471 " CPUs=%d, Nodes=%d\n",
74472@@ -3877,7 +3955,7 @@ static int slab_unmergeable(struct kmem_cache *s)
74473 /*
74474 * We may have set a slab to be unmergeable during bootstrap.
74475 */
74476- if (s->refcount < 0)
74477+ if (atomic_read(&s->refcount) < 0)
74478 return 1;
74479
74480 return 0;
74481@@ -3936,7 +4014,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74482 down_write(&slub_lock);
74483 s = find_mergeable(size, align, flags, name, ctor);
74484 if (s) {
74485- s->refcount++;
74486+ atomic_inc(&s->refcount);
74487 /*
74488 * Adjust the object sizes so that we clear
74489 * the complete object on kzalloc.
74490@@ -3945,7 +4023,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74491 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74492
74493 if (sysfs_slab_alias(s, name)) {
74494- s->refcount--;
74495+ atomic_dec(&s->refcount);
74496 goto err;
74497 }
74498 up_write(&slub_lock);
74499@@ -4074,7 +4152,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74500 }
74501 #endif
74502
74503-#ifdef CONFIG_SYSFS
74504+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74505 static int count_inuse(struct page *page)
74506 {
74507 return page->inuse;
74508@@ -4461,12 +4539,12 @@ static void resiliency_test(void)
74509 validate_slab_cache(kmalloc_caches[9]);
74510 }
74511 #else
74512-#ifdef CONFIG_SYSFS
74513+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74514 static void resiliency_test(void) {};
74515 #endif
74516 #endif
74517
74518-#ifdef CONFIG_SYSFS
74519+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74520 enum slab_stat_type {
74521 SL_ALL, /* All slabs */
74522 SL_PARTIAL, /* Only partially allocated slabs */
74523@@ -4709,7 +4787,7 @@ SLAB_ATTR_RO(ctor);
74524
74525 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74526 {
74527- return sprintf(buf, "%d\n", s->refcount - 1);
74528+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74529 }
74530 SLAB_ATTR_RO(aliases);
74531
74532@@ -5280,6 +5358,7 @@ static char *create_unique_id(struct kmem_cache *s)
74533 return name;
74534 }
74535
74536+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74537 static int sysfs_slab_add(struct kmem_cache *s)
74538 {
74539 int err;
74540@@ -5342,6 +5421,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74541 kobject_del(&s->kobj);
74542 kobject_put(&s->kobj);
74543 }
74544+#endif
74545
74546 /*
74547 * Need to buffer aliases during bootup until sysfs becomes
74548@@ -5355,6 +5435,7 @@ struct saved_alias {
74549
74550 static struct saved_alias *alias_list;
74551
74552+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74553 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74554 {
74555 struct saved_alias *al;
74556@@ -5377,6 +5458,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74557 alias_list = al;
74558 return 0;
74559 }
74560+#endif
74561
74562 static int __init slab_sysfs_init(void)
74563 {
74564diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
74565index 1b7e22a..3fcd4f3 100644
74566--- a/mm/sparse-vmemmap.c
74567+++ b/mm/sparse-vmemmap.c
74568@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
74569 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74570 if (!p)
74571 return NULL;
74572- pud_populate(&init_mm, pud, p);
74573+ pud_populate_kernel(&init_mm, pud, p);
74574 }
74575 return pud;
74576 }
74577@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
74578 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74579 if (!p)
74580 return NULL;
74581- pgd_populate(&init_mm, pgd, p);
74582+ pgd_populate_kernel(&init_mm, pgd, p);
74583 }
74584 return pgd;
74585 }
74586diff --git a/mm/swap.c b/mm/swap.c
74587index 4e7e2ec..0c57830 100644
74588--- a/mm/swap.c
74589+++ b/mm/swap.c
74590@@ -30,6 +30,7 @@
74591 #include <linux/backing-dev.h>
74592 #include <linux/memcontrol.h>
74593 #include <linux/gfp.h>
74594+#include <linux/hugetlb.h>
74595
74596 #include "internal.h"
74597
74598@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
74599
74600 __page_cache_release(page);
74601 dtor = get_compound_page_dtor(page);
74602+ if (!PageHuge(page))
74603+ BUG_ON(dtor != free_compound_page);
74604 (*dtor)(page);
74605 }
74606
74607diff --git a/mm/swapfile.c b/mm/swapfile.c
74608index 71373d0..11fa7d9 100644
74609--- a/mm/swapfile.c
74610+++ b/mm/swapfile.c
74611@@ -63,7 +63,7 @@ static DEFINE_MUTEX(swapon_mutex);
74612
74613 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74614 /* Activity counter to indicate that a swapon or swapoff has occurred */
74615-static atomic_t proc_poll_event = ATOMIC_INIT(0);
74616+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74617
74618 static inline unsigned char swap_count(unsigned char ent)
74619 {
74620@@ -1663,7 +1663,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74621 }
74622 filp_close(swap_file, NULL);
74623 err = 0;
74624- atomic_inc(&proc_poll_event);
74625+ atomic_inc_unchecked(&proc_poll_event);
74626 wake_up_interruptible(&proc_poll_wait);
74627
74628 out_dput:
74629@@ -1679,8 +1679,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74630
74631 poll_wait(file, &proc_poll_wait, wait);
74632
74633- if (seq->poll_event != atomic_read(&proc_poll_event)) {
74634- seq->poll_event = atomic_read(&proc_poll_event);
74635+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74636+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74637 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74638 }
74639
74640@@ -1778,7 +1778,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74641 return ret;
74642
74643 seq = file->private_data;
74644- seq->poll_event = atomic_read(&proc_poll_event);
74645+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74646 return 0;
74647 }
74648
74649@@ -2120,7 +2120,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74650 (frontswap_map) ? "FS" : "");
74651
74652 mutex_unlock(&swapon_mutex);
74653- atomic_inc(&proc_poll_event);
74654+ atomic_inc_unchecked(&proc_poll_event);
74655 wake_up_interruptible(&proc_poll_wait);
74656
74657 if (S_ISREG(inode->i_mode))
74658diff --git a/mm/util.c b/mm/util.c
74659index 8c7265a..c96d884 100644
74660--- a/mm/util.c
74661+++ b/mm/util.c
74662@@ -285,6 +285,12 @@ done:
74663 void arch_pick_mmap_layout(struct mm_struct *mm)
74664 {
74665 mm->mmap_base = TASK_UNMAPPED_BASE;
74666+
74667+#ifdef CONFIG_PAX_RANDMMAP
74668+ if (mm->pax_flags & MF_PAX_RANDMMAP)
74669+ mm->mmap_base += mm->delta_mmap;
74670+#endif
74671+
74672 mm->get_unmapped_area = arch_get_unmapped_area;
74673 mm->unmap_area = arch_unmap_area;
74674 }
74675diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74676index 2aad499..2e608e8 100644
74677--- a/mm/vmalloc.c
74678+++ b/mm/vmalloc.c
74679@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74680
74681 pte = pte_offset_kernel(pmd, addr);
74682 do {
74683- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74684- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74685+
74686+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74687+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74688+ BUG_ON(!pte_exec(*pte));
74689+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74690+ continue;
74691+ }
74692+#endif
74693+
74694+ {
74695+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74696+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74697+ }
74698 } while (pte++, addr += PAGE_SIZE, addr != end);
74699 }
74700
74701@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74702 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74703 {
74704 pte_t *pte;
74705+ int ret = -ENOMEM;
74706
74707 /*
74708 * nr is a running index into the array which helps higher level
74709@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74710 pte = pte_alloc_kernel(pmd, addr);
74711 if (!pte)
74712 return -ENOMEM;
74713+
74714+ pax_open_kernel();
74715 do {
74716 struct page *page = pages[*nr];
74717
74718- if (WARN_ON(!pte_none(*pte)))
74719- return -EBUSY;
74720- if (WARN_ON(!page))
74721- return -ENOMEM;
74722+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74723+ if (pgprot_val(prot) & _PAGE_NX)
74724+#endif
74725+
74726+ if (WARN_ON(!pte_none(*pte))) {
74727+ ret = -EBUSY;
74728+ goto out;
74729+ }
74730+ if (WARN_ON(!page)) {
74731+ ret = -ENOMEM;
74732+ goto out;
74733+ }
74734 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74735 (*nr)++;
74736 } while (pte++, addr += PAGE_SIZE, addr != end);
74737- return 0;
74738+ ret = 0;
74739+out:
74740+ pax_close_kernel();
74741+ return ret;
74742 }
74743
74744 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74745@@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74746 pmd_t *pmd;
74747 unsigned long next;
74748
74749- pmd = pmd_alloc(&init_mm, pud, addr);
74750+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74751 if (!pmd)
74752 return -ENOMEM;
74753 do {
74754@@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
74755 pud_t *pud;
74756 unsigned long next;
74757
74758- pud = pud_alloc(&init_mm, pgd, addr);
74759+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
74760 if (!pud)
74761 return -ENOMEM;
74762 do {
74763@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74764 * and fall back on vmalloc() if that fails. Others
74765 * just put it in the vmalloc space.
74766 */
74767-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74768+#ifdef CONFIG_MODULES
74769+#ifdef MODULES_VADDR
74770 unsigned long addr = (unsigned long)x;
74771 if (addr >= MODULES_VADDR && addr < MODULES_END)
74772 return 1;
74773 #endif
74774+
74775+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74776+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74777+ return 1;
74778+#endif
74779+
74780+#endif
74781+
74782 return is_vmalloc_addr(x);
74783 }
74784
74785@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74786
74787 if (!pgd_none(*pgd)) {
74788 pud_t *pud = pud_offset(pgd, addr);
74789+#ifdef CONFIG_X86
74790+ if (!pud_large(*pud))
74791+#endif
74792 if (!pud_none(*pud)) {
74793 pmd_t *pmd = pmd_offset(pud, addr);
74794+#ifdef CONFIG_X86
74795+ if (!pmd_large(*pmd))
74796+#endif
74797 if (!pmd_none(*pmd)) {
74798 pte_t *ptep, pte;
74799
74800@@ -332,6 +372,10 @@ static void purge_vmap_area_lazy(void);
74801 static struct vmap_area *alloc_vmap_area(unsigned long size,
74802 unsigned long align,
74803 unsigned long vstart, unsigned long vend,
74804+ int node, gfp_t gfp_mask) __size_overflow(1);
74805+static struct vmap_area *alloc_vmap_area(unsigned long size,
74806+ unsigned long align,
74807+ unsigned long vstart, unsigned long vend,
74808 int node, gfp_t gfp_mask)
74809 {
74810 struct vmap_area *va;
74811@@ -1320,6 +1364,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74812 struct vm_struct *area;
74813
74814 BUG_ON(in_interrupt());
74815+
74816+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74817+ if (flags & VM_KERNEXEC) {
74818+ if (start != VMALLOC_START || end != VMALLOC_END)
74819+ return NULL;
74820+ start = (unsigned long)MODULES_EXEC_VADDR;
74821+ end = (unsigned long)MODULES_EXEC_END;
74822+ }
74823+#endif
74824+
74825 if (flags & VM_IOREMAP) {
74826 int bit = fls(size);
74827
74828@@ -1552,6 +1606,11 @@ void *vmap(struct page **pages, unsigned int count,
74829 if (count > totalram_pages)
74830 return NULL;
74831
74832+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74833+ if (!(pgprot_val(prot) & _PAGE_NX))
74834+ flags |= VM_KERNEXEC;
74835+#endif
74836+
74837 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74838 __builtin_return_address(0));
74839 if (!area)
74840@@ -1653,6 +1712,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74841 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74842 goto fail;
74843
74844+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74845+ if (!(pgprot_val(prot) & _PAGE_NX))
74846+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74847+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74848+ else
74849+#endif
74850+
74851 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74852 start, end, node, gfp_mask, caller);
74853 if (!area)
74854@@ -1826,10 +1892,9 @@ EXPORT_SYMBOL(vzalloc_node);
74855 * For tight control over page level allocator and protection flags
74856 * use __vmalloc() instead.
74857 */
74858-
74859 void *vmalloc_exec(unsigned long size)
74860 {
74861- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74862+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74863 -1, __builtin_return_address(0));
74864 }
74865
74866@@ -2124,6 +2189,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74867 unsigned long uaddr = vma->vm_start;
74868 unsigned long usize = vma->vm_end - vma->vm_start;
74869
74870+ BUG_ON(vma->vm_mirror);
74871+
74872 if ((PAGE_SIZE-1) & (unsigned long)addr)
74873 return -EINVAL;
74874
74875diff --git a/mm/vmstat.c b/mm/vmstat.c
74876index 1bbbbd9..ff35669 100644
74877--- a/mm/vmstat.c
74878+++ b/mm/vmstat.c
74879@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74880 *
74881 * vm_stat contains the global counters
74882 */
74883-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74884+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74885 EXPORT_SYMBOL(vm_stat);
74886
74887 #ifdef CONFIG_SMP
74888@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74889 v = p->vm_stat_diff[i];
74890 p->vm_stat_diff[i] = 0;
74891 local_irq_restore(flags);
74892- atomic_long_add(v, &zone->vm_stat[i]);
74893+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74894 global_diff[i] += v;
74895 #ifdef CONFIG_NUMA
74896 /* 3 seconds idle till flush */
74897@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74898
74899 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74900 if (global_diff[i])
74901- atomic_long_add(global_diff[i], &vm_stat[i]);
74902+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74903 }
74904
74905 #endif
74906@@ -1211,10 +1211,20 @@ static int __init setup_vmstat(void)
74907 start_cpu_timer(cpu);
74908 #endif
74909 #ifdef CONFIG_PROC_FS
74910- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74911- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74912- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74913- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74914+ {
74915+ mode_t gr_mode = S_IRUGO;
74916+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74917+ gr_mode = S_IRUSR;
74918+#endif
74919+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74920+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74921+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74922+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74923+#else
74924+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74925+#endif
74926+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74927+ }
74928 #endif
74929 return 0;
74930 }
74931diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74932index 9096bcb..43ed7bb 100644
74933--- a/net/8021q/vlan.c
74934+++ b/net/8021q/vlan.c
74935@@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74936 err = -EPERM;
74937 if (!capable(CAP_NET_ADMIN))
74938 break;
74939- if ((args.u.name_type >= 0) &&
74940- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74941+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74942 struct vlan_net *vn;
74943
74944 vn = net_generic(net, vlan_net_id);
74945diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74946index 6449bae..8c1f454 100644
74947--- a/net/9p/trans_fd.c
74948+++ b/net/9p/trans_fd.c
74949@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74950 oldfs = get_fs();
74951 set_fs(get_ds());
74952 /* The cast to a user pointer is valid due to the set_fs() */
74953- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
74954+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
74955 set_fs(oldfs);
74956
74957 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
74958diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
74959index 876fbe8..8bbea9f 100644
74960--- a/net/atm/atm_misc.c
74961+++ b/net/atm/atm_misc.c
74962@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
74963 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
74964 return 1;
74965 atm_return(vcc, truesize);
74966- atomic_inc(&vcc->stats->rx_drop);
74967+ atomic_inc_unchecked(&vcc->stats->rx_drop);
74968 return 0;
74969 }
74970 EXPORT_SYMBOL(atm_charge);
74971@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
74972 }
74973 }
74974 atm_return(vcc, guess);
74975- atomic_inc(&vcc->stats->rx_drop);
74976+ atomic_inc_unchecked(&vcc->stats->rx_drop);
74977 return NULL;
74978 }
74979 EXPORT_SYMBOL(atm_alloc_charge);
74980@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
74981
74982 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74983 {
74984-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74985+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74986 __SONET_ITEMS
74987 #undef __HANDLE_ITEM
74988 }
74989@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
74990
74991 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74992 {
74993-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74994+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
74995 __SONET_ITEMS
74996 #undef __HANDLE_ITEM
74997 }
74998diff --git a/net/atm/lec.h b/net/atm/lec.h
74999index a86aff9..3a0d6f6 100644
75000--- a/net/atm/lec.h
75001+++ b/net/atm/lec.h
75002@@ -48,7 +48,7 @@ struct lane2_ops {
75003 const u8 *tlvs, u32 sizeoftlvs);
75004 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75005 const u8 *tlvs, u32 sizeoftlvs);
75006-};
75007+} __no_const;
75008
75009 /*
75010 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75011diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75012index 0919a88..a23d54e 100644
75013--- a/net/atm/mpc.h
75014+++ b/net/atm/mpc.h
75015@@ -33,7 +33,7 @@ struct mpoa_client {
75016 struct mpc_parameters parameters; /* parameters for this client */
75017
75018 const struct net_device_ops *old_ops;
75019- struct net_device_ops new_ops;
75020+ net_device_ops_no_const new_ops;
75021 };
75022
75023
75024diff --git a/net/atm/proc.c b/net/atm/proc.c
75025index 0d020de..011c7bb 100644
75026--- a/net/atm/proc.c
75027+++ b/net/atm/proc.c
75028@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75029 const struct k_atm_aal_stats *stats)
75030 {
75031 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75032- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75033- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75034- atomic_read(&stats->rx_drop));
75035+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75036+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75037+ atomic_read_unchecked(&stats->rx_drop));
75038 }
75039
75040 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75041diff --git a/net/atm/resources.c b/net/atm/resources.c
75042index 23f45ce..c748f1a 100644
75043--- a/net/atm/resources.c
75044+++ b/net/atm/resources.c
75045@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75046 static void copy_aal_stats(struct k_atm_aal_stats *from,
75047 struct atm_aal_stats *to)
75048 {
75049-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75050+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75051 __AAL_STAT_ITEMS
75052 #undef __HANDLE_ITEM
75053 }
75054@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75055 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75056 struct atm_aal_stats *to)
75057 {
75058-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75059+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75060 __AAL_STAT_ITEMS
75061 #undef __HANDLE_ITEM
75062 }
75063diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75064index dc53798..dc66333 100644
75065--- a/net/batman-adv/bat_iv_ogm.c
75066+++ b/net/batman-adv/bat_iv_ogm.c
75067@@ -63,7 +63,7 @@ static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
75068
75069 /* randomize initial seqno to avoid collision */
75070 get_random_bytes(&random_seqno, sizeof(random_seqno));
75071- atomic_set(&hard_iface->seqno, random_seqno);
75072+ atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75073
75074 hard_iface->packet_len = BATMAN_OGM_HLEN;
75075 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75076@@ -572,7 +572,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75077
75078 /* change sequence number to network order */
75079 batman_ogm_packet->seqno =
75080- htonl((uint32_t)atomic_read(&hard_iface->seqno));
75081+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75082
75083 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75084 batman_ogm_packet->tt_crc = htons((uint16_t)
75085@@ -592,7 +592,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75086 else
75087 batman_ogm_packet->gw_flags = NO_FLAGS;
75088
75089- atomic_inc(&hard_iface->seqno);
75090+ atomic_inc_unchecked(&hard_iface->seqno);
75091
75092 slide_own_bcast_window(hard_iface);
75093 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
75094@@ -956,7 +956,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
75095 return;
75096
75097 /* could be changed by schedule_own_packet() */
75098- if_incoming_seqno = atomic_read(&if_incoming->seqno);
75099+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75100
75101 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
75102
75103diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75104index dc334fa..766a01a 100644
75105--- a/net/batman-adv/hard-interface.c
75106+++ b/net/batman-adv/hard-interface.c
75107@@ -321,7 +321,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
75108 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75109 dev_add_pack(&hard_iface->batman_adv_ptype);
75110
75111- atomic_set(&hard_iface->frag_seqno, 1);
75112+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75113 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75114 hard_iface->net_dev->name);
75115
75116@@ -444,7 +444,7 @@ static struct hard_iface *hardif_add_interface(struct net_device *net_dev)
75117 * This can't be called via a bat_priv callback because
75118 * we have no bat_priv yet.
75119 */
75120- atomic_set(&hard_iface->seqno, 1);
75121+ atomic_set_unchecked(&hard_iface->seqno, 1);
75122 hard_iface->packet_buff = NULL;
75123
75124 return hard_iface;
75125diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75126index a0ec0e4..7beb587 100644
75127--- a/net/batman-adv/soft-interface.c
75128+++ b/net/batman-adv/soft-interface.c
75129@@ -214,7 +214,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
75130
75131 /* set broadcast sequence number */
75132 bcast_packet->seqno =
75133- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75134+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75135
75136 add_bcast_packet_to_list(bat_priv, skb, 1);
75137
75138@@ -390,7 +390,7 @@ struct net_device *softif_create(const char *name)
75139 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75140
75141 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75142- atomic_set(&bat_priv->bcast_seqno, 1);
75143+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75144 atomic_set(&bat_priv->ttvn, 0);
75145 atomic_set(&bat_priv->tt_local_changes, 0);
75146 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75147diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75148index 61308e8..2e142b2 100644
75149--- a/net/batman-adv/types.h
75150+++ b/net/batman-adv/types.h
75151@@ -38,8 +38,8 @@ struct hard_iface {
75152 int16_t if_num;
75153 char if_status;
75154 struct net_device *net_dev;
75155- atomic_t seqno;
75156- atomic_t frag_seqno;
75157+ atomic_unchecked_t seqno;
75158+ atomic_unchecked_t frag_seqno;
75159 unsigned char *packet_buff;
75160 int packet_len;
75161 struct kobject *hardif_obj;
75162@@ -163,7 +163,7 @@ struct bat_priv {
75163 atomic_t orig_interval; /* uint */
75164 atomic_t hop_penalty; /* uint */
75165 atomic_t log_level; /* uint */
75166- atomic_t bcast_seqno;
75167+ atomic_unchecked_t bcast_seqno;
75168 atomic_t bcast_queue_left;
75169 atomic_t batman_queue_left;
75170 atomic_t ttvn; /* translation table version number */
75171diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75172index 74175c2..32f8901 100644
75173--- a/net/batman-adv/unicast.c
75174+++ b/net/batman-adv/unicast.c
75175@@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
75176 frag1->flags = UNI_FRAG_HEAD | large_tail;
75177 frag2->flags = large_tail;
75178
75179- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75180+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75181 frag1->seqno = htons(seqno - 1);
75182 frag2->seqno = htons(seqno);
75183
75184diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75185index 4554e80..b778671 100644
75186--- a/net/bluetooth/l2cap_core.c
75187+++ b/net/bluetooth/l2cap_core.c
75188@@ -2798,8 +2798,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75189 break;
75190
75191 case L2CAP_CONF_RFC:
75192- if (olen == sizeof(rfc))
75193- memcpy(&rfc, (void *)val, olen);
75194+ if (olen != sizeof(rfc))
75195+ break;
75196+
75197+ memcpy(&rfc, (void *)val, olen);
75198
75199 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
75200 rfc.mode != chan->mode)
75201diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
75202index d1820ff..d414b0e 100644
75203--- a/net/bluetooth/rfcomm/tty.c
75204+++ b/net/bluetooth/rfcomm/tty.c
75205@@ -314,7 +314,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
75206 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
75207
75208 spin_lock_irqsave(&dev->port.lock, flags);
75209- if (dev->port.count > 0) {
75210+ if (atomic_read(&dev->port.count) > 0) {
75211 spin_unlock_irqrestore(&dev->port.lock, flags);
75212 return;
75213 }
75214@@ -669,10 +669,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
75215 return -ENODEV;
75216
75217 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
75218- dev->channel, dev->port.count);
75219+ dev->channel, atomic_read(&dev->port.count));
75220
75221 spin_lock_irqsave(&dev->port.lock, flags);
75222- if (++dev->port.count > 1) {
75223+ if (atomic_inc_return(&dev->port.count) > 1) {
75224 spin_unlock_irqrestore(&dev->port.lock, flags);
75225 return 0;
75226 }
75227@@ -737,10 +737,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
75228 return;
75229
75230 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
75231- dev->port.count);
75232+ atomic_read(&dev->port.count));
75233
75234 spin_lock_irqsave(&dev->port.lock, flags);
75235- if (!--dev->port.count) {
75236+ if (!atomic_dec_return(&dev->port.count)) {
75237 spin_unlock_irqrestore(&dev->port.lock, flags);
75238 if (dev->tty_dev->parent)
75239 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
75240diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
75241index 5fe2ff3..10968b5 100644
75242--- a/net/bridge/netfilter/ebtables.c
75243+++ b/net/bridge/netfilter/ebtables.c
75244@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
75245 tmp.valid_hooks = t->table->valid_hooks;
75246 }
75247 mutex_unlock(&ebt_mutex);
75248- if (copy_to_user(user, &tmp, *len) != 0){
75249+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75250 BUGPRINT("c2u Didn't work\n");
75251 ret = -EFAULT;
75252 break;
75253diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
75254index 047cd0e..461fd28 100644
75255--- a/net/caif/cfctrl.c
75256+++ b/net/caif/cfctrl.c
75257@@ -10,6 +10,7 @@
75258 #include <linux/spinlock.h>
75259 #include <linux/slab.h>
75260 #include <linux/pkt_sched.h>
75261+#include <linux/sched.h>
75262 #include <net/caif/caif_layer.h>
75263 #include <net/caif/cfpkt.h>
75264 #include <net/caif/cfctrl.h>
75265@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
75266 memset(&dev_info, 0, sizeof(dev_info));
75267 dev_info.id = 0xff;
75268 cfsrvl_init(&this->serv, 0, &dev_info, false);
75269- atomic_set(&this->req_seq_no, 1);
75270- atomic_set(&this->rsp_seq_no, 1);
75271+ atomic_set_unchecked(&this->req_seq_no, 1);
75272+ atomic_set_unchecked(&this->rsp_seq_no, 1);
75273 this->serv.layer.receive = cfctrl_recv;
75274 sprintf(this->serv.layer.name, "ctrl");
75275 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75276@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
75277 struct cfctrl_request_info *req)
75278 {
75279 spin_lock_bh(&ctrl->info_list_lock);
75280- atomic_inc(&ctrl->req_seq_no);
75281- req->sequence_no = atomic_read(&ctrl->req_seq_no);
75282+ atomic_inc_unchecked(&ctrl->req_seq_no);
75283+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75284 list_add_tail(&req->list, &ctrl->list);
75285 spin_unlock_bh(&ctrl->info_list_lock);
75286 }
75287@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
75288 if (p != first)
75289 pr_warn("Requests are not received in order\n");
75290
75291- atomic_set(&ctrl->rsp_seq_no,
75292+ atomic_set_unchecked(&ctrl->rsp_seq_no,
75293 p->sequence_no);
75294 list_del(&p->list);
75295 goto out;
75296diff --git a/net/can/gw.c b/net/can/gw.c
75297index b41acf2..3affb3a 100644
75298--- a/net/can/gw.c
75299+++ b/net/can/gw.c
75300@@ -96,7 +96,7 @@ struct cf_mod {
75301 struct {
75302 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
75303 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
75304- } csumfunc;
75305+ } __no_const csumfunc;
75306 };
75307
75308
75309diff --git a/net/compat.c b/net/compat.c
75310index 1b96281..a7e6c91 100644
75311--- a/net/compat.c
75312+++ b/net/compat.c
75313@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
75314 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
75315 __get_user(kmsg->msg_flags, &umsg->msg_flags))
75316 return -EFAULT;
75317- kmsg->msg_name = compat_ptr(tmp1);
75318- kmsg->msg_iov = compat_ptr(tmp2);
75319- kmsg->msg_control = compat_ptr(tmp3);
75320+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
75321+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
75322+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
75323 return 0;
75324 }
75325
75326@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75327
75328 if (kern_msg->msg_namelen) {
75329 if (mode == VERIFY_READ) {
75330- int err = move_addr_to_kernel(kern_msg->msg_name,
75331+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
75332 kern_msg->msg_namelen,
75333 kern_address);
75334 if (err < 0)
75335@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75336 kern_msg->msg_name = NULL;
75337
75338 tot_len = iov_from_user_compat_to_kern(kern_iov,
75339- (struct compat_iovec __user *)kern_msg->msg_iov,
75340+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
75341 kern_msg->msg_iovlen);
75342 if (tot_len >= 0)
75343 kern_msg->msg_iov = kern_iov;
75344@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75345
75346 #define CMSG_COMPAT_FIRSTHDR(msg) \
75347 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
75348- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
75349+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
75350 (struct compat_cmsghdr __user *)NULL)
75351
75352 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
75353 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
75354 (ucmlen) <= (unsigned long) \
75355 ((mhdr)->msg_controllen - \
75356- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
75357+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
75358
75359 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
75360 struct compat_cmsghdr __user *cmsg, int cmsg_len)
75361 {
75362 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
75363- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
75364+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
75365 msg->msg_controllen)
75366 return NULL;
75367 return (struct compat_cmsghdr __user *)ptr;
75368@@ -219,7 +219,7 @@ Efault:
75369
75370 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
75371 {
75372- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75373+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75374 struct compat_cmsghdr cmhdr;
75375 int cmlen;
75376
75377@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75378
75379 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75380 {
75381- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75382+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75383 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75384 int fdnum = scm->fp->count;
75385 struct file **fp = scm->fp->fp;
75386@@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
75387 return -EFAULT;
75388 old_fs = get_fs();
75389 set_fs(KERNEL_DS);
75390- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75391+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75392 set_fs(old_fs);
75393
75394 return err;
75395@@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75396 len = sizeof(ktime);
75397 old_fs = get_fs();
75398 set_fs(KERNEL_DS);
75399- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75400+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75401 set_fs(old_fs);
75402
75403 if (!err) {
75404@@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75405 case MCAST_JOIN_GROUP:
75406 case MCAST_LEAVE_GROUP:
75407 {
75408- struct compat_group_req __user *gr32 = (void *)optval;
75409+ struct compat_group_req __user *gr32 = (void __user *)optval;
75410 struct group_req __user *kgr =
75411 compat_alloc_user_space(sizeof(struct group_req));
75412 u32 interface;
75413@@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75414 case MCAST_BLOCK_SOURCE:
75415 case MCAST_UNBLOCK_SOURCE:
75416 {
75417- struct compat_group_source_req __user *gsr32 = (void *)optval;
75418+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75419 struct group_source_req __user *kgsr = compat_alloc_user_space(
75420 sizeof(struct group_source_req));
75421 u32 interface;
75422@@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75423 }
75424 case MCAST_MSFILTER:
75425 {
75426- struct compat_group_filter __user *gf32 = (void *)optval;
75427+ struct compat_group_filter __user *gf32 = (void __user *)optval;
75428 struct group_filter __user *kgf;
75429 u32 interface, fmode, numsrc;
75430
75431@@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75432 char __user *optval, int __user *optlen,
75433 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75434 {
75435- struct compat_group_filter __user *gf32 = (void *)optval;
75436+ struct compat_group_filter __user *gf32 = (void __user *)optval;
75437 struct group_filter __user *kgf;
75438 int __user *koptlen;
75439 u32 interface, fmode, numsrc;
75440diff --git a/net/core/datagram.c b/net/core/datagram.c
75441index ae6acf6..d5c8f66 100644
75442--- a/net/core/datagram.c
75443+++ b/net/core/datagram.c
75444@@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75445 }
75446
75447 kfree_skb(skb);
75448- atomic_inc(&sk->sk_drops);
75449+ atomic_inc_unchecked(&sk->sk_drops);
75450 sk_mem_reclaim_partial(sk);
75451
75452 return err;
75453diff --git a/net/core/dev.c b/net/core/dev.c
75454index 1cb0d8a..0427dd9 100644
75455--- a/net/core/dev.c
75456+++ b/net/core/dev.c
75457@@ -1135,9 +1135,13 @@ void dev_load(struct net *net, const char *name)
75458 if (no_module && capable(CAP_NET_ADMIN))
75459 no_module = request_module("netdev-%s", name);
75460 if (no_module && capable(CAP_SYS_MODULE)) {
75461+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75462+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
75463+#else
75464 if (!request_module("%s", name))
75465 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
75466 name);
75467+#endif
75468 }
75469 }
75470 EXPORT_SYMBOL(dev_load);
75471@@ -1601,7 +1605,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75472 {
75473 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75474 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75475- atomic_long_inc(&dev->rx_dropped);
75476+ atomic_long_inc_unchecked(&dev->rx_dropped);
75477 kfree_skb(skb);
75478 return NET_RX_DROP;
75479 }
75480@@ -1611,7 +1615,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75481 nf_reset(skb);
75482
75483 if (unlikely(!is_skb_forwardable(dev, skb))) {
75484- atomic_long_inc(&dev->rx_dropped);
75485+ atomic_long_inc_unchecked(&dev->rx_dropped);
75486 kfree_skb(skb);
75487 return NET_RX_DROP;
75488 }
75489@@ -2040,7 +2044,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75490
75491 struct dev_gso_cb {
75492 void (*destructor)(struct sk_buff *skb);
75493-};
75494+} __no_const;
75495
75496 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75497
75498@@ -2875,7 +2879,7 @@ enqueue:
75499
75500 local_irq_restore(flags);
75501
75502- atomic_long_inc(&skb->dev->rx_dropped);
75503+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75504 kfree_skb(skb);
75505 return NET_RX_DROP;
75506 }
75507@@ -2947,7 +2951,7 @@ int netif_rx_ni(struct sk_buff *skb)
75508 }
75509 EXPORT_SYMBOL(netif_rx_ni);
75510
75511-static void net_tx_action(struct softirq_action *h)
75512+static void net_tx_action(void)
75513 {
75514 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75515
75516@@ -3234,7 +3238,7 @@ ncls:
75517 if (pt_prev) {
75518 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75519 } else {
75520- atomic_long_inc(&skb->dev->rx_dropped);
75521+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75522 kfree_skb(skb);
75523 /* Jamal, now you will not able to escape explaining
75524 * me how you were going to use this. :-)
75525@@ -3799,7 +3803,7 @@ void netif_napi_del(struct napi_struct *napi)
75526 }
75527 EXPORT_SYMBOL(netif_napi_del);
75528
75529-static void net_rx_action(struct softirq_action *h)
75530+static void net_rx_action(void)
75531 {
75532 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75533 unsigned long time_limit = jiffies + 2;
75534@@ -4269,8 +4273,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
75535 else
75536 seq_printf(seq, "%04x", ntohs(pt->type));
75537
75538+#ifdef CONFIG_GRKERNSEC_HIDESYM
75539+ seq_printf(seq, " %-8s %p\n",
75540+ pt->dev ? pt->dev->name : "", NULL);
75541+#else
75542 seq_printf(seq, " %-8s %pF\n",
75543 pt->dev ? pt->dev->name : "", pt->func);
75544+#endif
75545 }
75546
75547 return 0;
75548@@ -5820,7 +5829,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75549 } else {
75550 netdev_stats_to_stats64(storage, &dev->stats);
75551 }
75552- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75553+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75554 return storage;
75555 }
75556 EXPORT_SYMBOL(dev_get_stats);
75557diff --git a/net/core/flow.c b/net/core/flow.c
75558index e318c7e..168b1d0 100644
75559--- a/net/core/flow.c
75560+++ b/net/core/flow.c
75561@@ -61,7 +61,7 @@ struct flow_cache {
75562 struct timer_list rnd_timer;
75563 };
75564
75565-atomic_t flow_cache_genid = ATOMIC_INIT(0);
75566+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75567 EXPORT_SYMBOL(flow_cache_genid);
75568 static struct flow_cache flow_cache_global;
75569 static struct kmem_cache *flow_cachep __read_mostly;
75570@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75571
75572 static int flow_entry_valid(struct flow_cache_entry *fle)
75573 {
75574- if (atomic_read(&flow_cache_genid) != fle->genid)
75575+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75576 return 0;
75577 if (fle->object && !fle->object->ops->check(fle->object))
75578 return 0;
75579@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75580 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75581 fcp->hash_count++;
75582 }
75583- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75584+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75585 flo = fle->object;
75586 if (!flo)
75587 goto ret_object;
75588@@ -280,7 +280,7 @@ nocache:
75589 }
75590 flo = resolver(net, key, family, dir, flo, ctx);
75591 if (fle) {
75592- fle->genid = atomic_read(&flow_cache_genid);
75593+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
75594 if (!IS_ERR(flo))
75595 fle->object = flo;
75596 else
75597diff --git a/net/core/iovec.c b/net/core/iovec.c
75598index 7e7aeb0..2a998cb 100644
75599--- a/net/core/iovec.c
75600+++ b/net/core/iovec.c
75601@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75602 if (m->msg_namelen) {
75603 if (mode == VERIFY_READ) {
75604 void __user *namep;
75605- namep = (void __user __force *) m->msg_name;
75606+ namep = (void __force_user *) m->msg_name;
75607 err = move_addr_to_kernel(namep, m->msg_namelen,
75608 address);
75609 if (err < 0)
75610@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75611 }
75612
75613 size = m->msg_iovlen * sizeof(struct iovec);
75614- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75615+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75616 return -EFAULT;
75617
75618 m->msg_iov = iov;
75619diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75620index 21318d1..7f105e4 100644
75621--- a/net/core/rtnetlink.c
75622+++ b/net/core/rtnetlink.c
75623@@ -58,7 +58,7 @@ struct rtnl_link {
75624 rtnl_doit_func doit;
75625 rtnl_dumpit_func dumpit;
75626 rtnl_calcit_func calcit;
75627-};
75628+} __no_const;
75629
75630 static DEFINE_MUTEX(rtnl_mutex);
75631
75632diff --git a/net/core/scm.c b/net/core/scm.c
75633index 611c5ef..88f6d6d 100644
75634--- a/net/core/scm.c
75635+++ b/net/core/scm.c
75636@@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
75637 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75638 {
75639 struct cmsghdr __user *cm
75640- = (__force struct cmsghdr __user *)msg->msg_control;
75641+ = (struct cmsghdr __force_user *)msg->msg_control;
75642 struct cmsghdr cmhdr;
75643 int cmlen = CMSG_LEN(len);
75644 int err;
75645@@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75646 err = -EFAULT;
75647 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75648 goto out;
75649- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75650+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75651 goto out;
75652 cmlen = CMSG_SPACE(len);
75653 if (msg->msg_controllen < cmlen)
75654@@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
75655 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75656 {
75657 struct cmsghdr __user *cm
75658- = (__force struct cmsghdr __user*)msg->msg_control;
75659+ = (struct cmsghdr __force_user *)msg->msg_control;
75660
75661 int fdmax = 0;
75662 int fdnum = scm->fp->count;
75663@@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75664 if (fdnum < fdmax)
75665 fdmax = fdnum;
75666
75667- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75668+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75669 i++, cmfptr++)
75670 {
75671 int new_fd;
75672diff --git a/net/core/sock.c b/net/core/sock.c
75673index 9e5b71f..66dec30 100644
75674--- a/net/core/sock.c
75675+++ b/net/core/sock.c
75676@@ -344,7 +344,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75677 struct sk_buff_head *list = &sk->sk_receive_queue;
75678
75679 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75680- atomic_inc(&sk->sk_drops);
75681+ atomic_inc_unchecked(&sk->sk_drops);
75682 trace_sock_rcvqueue_full(sk, skb);
75683 return -ENOMEM;
75684 }
75685@@ -354,7 +354,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75686 return err;
75687
75688 if (!sk_rmem_schedule(sk, skb->truesize)) {
75689- atomic_inc(&sk->sk_drops);
75690+ atomic_inc_unchecked(&sk->sk_drops);
75691 return -ENOBUFS;
75692 }
75693
75694@@ -374,7 +374,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75695 skb_dst_force(skb);
75696
75697 spin_lock_irqsave(&list->lock, flags);
75698- skb->dropcount = atomic_read(&sk->sk_drops);
75699+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75700 __skb_queue_tail(list, skb);
75701 spin_unlock_irqrestore(&list->lock, flags);
75702
75703@@ -394,7 +394,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75704 skb->dev = NULL;
75705
75706 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
75707- atomic_inc(&sk->sk_drops);
75708+ atomic_inc_unchecked(&sk->sk_drops);
75709 goto discard_and_relse;
75710 }
75711 if (nested)
75712@@ -412,7 +412,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75713 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75714 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
75715 bh_unlock_sock(sk);
75716- atomic_inc(&sk->sk_drops);
75717+ atomic_inc_unchecked(&sk->sk_drops);
75718 goto discard_and_relse;
75719 }
75720
75721@@ -976,7 +976,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75722 if (len > sizeof(peercred))
75723 len = sizeof(peercred);
75724 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75725- if (copy_to_user(optval, &peercred, len))
75726+ if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75727 return -EFAULT;
75728 goto lenout;
75729 }
75730@@ -989,7 +989,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75731 return -ENOTCONN;
75732 if (lv < len)
75733 return -EINVAL;
75734- if (copy_to_user(optval, address, len))
75735+ if (len > sizeof(address) || copy_to_user(optval, address, len))
75736 return -EFAULT;
75737 goto lenout;
75738 }
75739@@ -1035,7 +1035,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75740
75741 if (len > lv)
75742 len = lv;
75743- if (copy_to_user(optval, &v, len))
75744+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
75745 return -EFAULT;
75746 lenout:
75747 if (put_user(len, optlen))
75748@@ -2124,7 +2124,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75749 */
75750 smp_wmb();
75751 atomic_set(&sk->sk_refcnt, 1);
75752- atomic_set(&sk->sk_drops, 0);
75753+ atomic_set_unchecked(&sk->sk_drops, 0);
75754 }
75755 EXPORT_SYMBOL(sock_init_data);
75756
75757diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
75758index 5fd1467..8b70900 100644
75759--- a/net/core/sock_diag.c
75760+++ b/net/core/sock_diag.c
75761@@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
75762
75763 int sock_diag_check_cookie(void *sk, __u32 *cookie)
75764 {
75765+#ifndef CONFIG_GRKERNSEC_HIDESYM
75766 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
75767 cookie[1] != INET_DIAG_NOCOOKIE) &&
75768 ((u32)(unsigned long)sk != cookie[0] ||
75769 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
75770 return -ESTALE;
75771 else
75772+#endif
75773 return 0;
75774 }
75775 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
75776
75777 void sock_diag_save_cookie(void *sk, __u32 *cookie)
75778 {
75779+#ifdef CONFIG_GRKERNSEC_HIDESYM
75780+ cookie[0] = 0;
75781+ cookie[1] = 0;
75782+#else
75783 cookie[0] = (u32)(unsigned long)sk;
75784 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75785+#endif
75786 }
75787 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
75788
75789diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75790index a55eecc..dd8428c 100644
75791--- a/net/decnet/sysctl_net_decnet.c
75792+++ b/net/decnet/sysctl_net_decnet.c
75793@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75794
75795 if (len > *lenp) len = *lenp;
75796
75797- if (copy_to_user(buffer, addr, len))
75798+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
75799 return -EFAULT;
75800
75801 *lenp = len;
75802@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75803
75804 if (len > *lenp) len = *lenp;
75805
75806- if (copy_to_user(buffer, devname, len))
75807+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
75808 return -EFAULT;
75809
75810 *lenp = len;
75811diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75812index 3854411..2201a94 100644
75813--- a/net/ipv4/fib_frontend.c
75814+++ b/net/ipv4/fib_frontend.c
75815@@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75816 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75817 fib_sync_up(dev);
75818 #endif
75819- atomic_inc(&net->ipv4.dev_addr_genid);
75820+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75821 rt_cache_flush(dev_net(dev), -1);
75822 break;
75823 case NETDEV_DOWN:
75824 fib_del_ifaddr(ifa, NULL);
75825- atomic_inc(&net->ipv4.dev_addr_genid);
75826+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75827 if (ifa->ifa_dev->ifa_list == NULL) {
75828 /* Last address was deleted from this interface.
75829 * Disable IP.
75830@@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75831 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75832 fib_sync_up(dev);
75833 #endif
75834- atomic_inc(&net->ipv4.dev_addr_genid);
75835+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75836 rt_cache_flush(dev_net(dev), -1);
75837 break;
75838 case NETDEV_DOWN:
75839diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75840index e5b7182..570a90e 100644
75841--- a/net/ipv4/fib_semantics.c
75842+++ b/net/ipv4/fib_semantics.c
75843@@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75844 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75845 nh->nh_gw,
75846 nh->nh_parent->fib_scope);
75847- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75848+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75849
75850 return nh->nh_saddr;
75851 }
75852diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75853index 7880af9..70f92a3 100644
75854--- a/net/ipv4/inet_hashtables.c
75855+++ b/net/ipv4/inet_hashtables.c
75856@@ -18,12 +18,15 @@
75857 #include <linux/sched.h>
75858 #include <linux/slab.h>
75859 #include <linux/wait.h>
75860+#include <linux/security.h>
75861
75862 #include <net/inet_connection_sock.h>
75863 #include <net/inet_hashtables.h>
75864 #include <net/secure_seq.h>
75865 #include <net/ip.h>
75866
75867+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75868+
75869 /*
75870 * Allocate and initialize a new local port bind bucket.
75871 * The bindhash mutex for snum's hash chain must be held here.
75872@@ -530,6 +533,8 @@ ok:
75873 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75874 spin_unlock(&head->lock);
75875
75876+ gr_update_task_in_ip_table(current, inet_sk(sk));
75877+
75878 if (tw) {
75879 inet_twsk_deschedule(tw, death_row);
75880 while (twrefcnt) {
75881diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75882index dfba343..c827d50 100644
75883--- a/net/ipv4/inetpeer.c
75884+++ b/net/ipv4/inetpeer.c
75885@@ -487,8 +487,8 @@ relookup:
75886 if (p) {
75887 p->daddr = *daddr;
75888 atomic_set(&p->refcnt, 1);
75889- atomic_set(&p->rid, 0);
75890- atomic_set(&p->ip_id_count,
75891+ atomic_set_unchecked(&p->rid, 0);
75892+ atomic_set_unchecked(&p->ip_id_count,
75893 (daddr->family == AF_INET) ?
75894 secure_ip_id(daddr->addr.a4) :
75895 secure_ipv6_id(daddr->addr.a6));
75896diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75897index 9dbd3dd..0c59fb2 100644
75898--- a/net/ipv4/ip_fragment.c
75899+++ b/net/ipv4/ip_fragment.c
75900@@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75901 return 0;
75902
75903 start = qp->rid;
75904- end = atomic_inc_return(&peer->rid);
75905+ end = atomic_inc_return_unchecked(&peer->rid);
75906 qp->rid = end;
75907
75908 rc = qp->q.fragments && (end - start) > max;
75909diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75910index 0d11f23..2bb3f64 100644
75911--- a/net/ipv4/ip_sockglue.c
75912+++ b/net/ipv4/ip_sockglue.c
75913@@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75914 len = min_t(unsigned int, len, opt->optlen);
75915 if (put_user(len, optlen))
75916 return -EFAULT;
75917- if (copy_to_user(optval, opt->__data, len))
75918+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75919+ copy_to_user(optval, opt->__data, len))
75920 return -EFAULT;
75921 return 0;
75922 }
75923@@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75924 if (sk->sk_type != SOCK_STREAM)
75925 return -ENOPROTOOPT;
75926
75927- msg.msg_control = optval;
75928+ msg.msg_control = (void __force_kernel *)optval;
75929 msg.msg_controllen = len;
75930 msg.msg_flags = flags;
75931
75932diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75933index 67e8a6b..386764d 100644
75934--- a/net/ipv4/ipconfig.c
75935+++ b/net/ipv4/ipconfig.c
75936@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75937
75938 mm_segment_t oldfs = get_fs();
75939 set_fs(get_ds());
75940- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75941+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75942 set_fs(oldfs);
75943 return res;
75944 }
75945@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
75946
75947 mm_segment_t oldfs = get_fs();
75948 set_fs(get_ds());
75949- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75950+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75951 set_fs(oldfs);
75952 return res;
75953 }
75954@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
75955
75956 mm_segment_t oldfs = get_fs();
75957 set_fs(get_ds());
75958- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
75959+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
75960 set_fs(oldfs);
75961 return res;
75962 }
75963diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
75964index 2c00e8b..45b3bdd 100644
75965--- a/net/ipv4/ping.c
75966+++ b/net/ipv4/ping.c
75967@@ -845,7 +845,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
75968 sk_rmem_alloc_get(sp),
75969 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75970 atomic_read(&sp->sk_refcnt), sp,
75971- atomic_read(&sp->sk_drops), len);
75972+ atomic_read_unchecked(&sp->sk_drops), len);
75973 }
75974
75975 static int ping_seq_show(struct seq_file *seq, void *v)
75976diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
75977index 4032b81..625143c 100644
75978--- a/net/ipv4/raw.c
75979+++ b/net/ipv4/raw.c
75980@@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
75981 int raw_rcv(struct sock *sk, struct sk_buff *skb)
75982 {
75983 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
75984- atomic_inc(&sk->sk_drops);
75985+ atomic_inc_unchecked(&sk->sk_drops);
75986 kfree_skb(skb);
75987 return NET_RX_DROP;
75988 }
75989@@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
75990
75991 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
75992 {
75993+ struct icmp_filter filter;
75994+
75995 if (optlen > sizeof(struct icmp_filter))
75996 optlen = sizeof(struct icmp_filter);
75997- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
75998+ if (copy_from_user(&filter, optval, optlen))
75999 return -EFAULT;
76000+ raw_sk(sk)->filter = filter;
76001 return 0;
76002 }
76003
76004 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76005 {
76006 int len, ret = -EFAULT;
76007+ struct icmp_filter filter;
76008
76009 if (get_user(len, optlen))
76010 goto out;
76011@@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
76012 if (len > sizeof(struct icmp_filter))
76013 len = sizeof(struct icmp_filter);
76014 ret = -EFAULT;
76015- if (put_user(len, optlen) ||
76016- copy_to_user(optval, &raw_sk(sk)->filter, len))
76017+ filter = raw_sk(sk)->filter;
76018+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
76019 goto out;
76020 ret = 0;
76021 out: return ret;
76022@@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76023 sk_wmem_alloc_get(sp),
76024 sk_rmem_alloc_get(sp),
76025 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76026- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76027+ atomic_read(&sp->sk_refcnt),
76028+#ifdef CONFIG_GRKERNSEC_HIDESYM
76029+ NULL,
76030+#else
76031+ sp,
76032+#endif
76033+ atomic_read_unchecked(&sp->sk_drops));
76034 }
76035
76036 static int raw_seq_show(struct seq_file *seq, void *v)
76037diff --git a/net/ipv4/route.c b/net/ipv4/route.c
76038index 98b30d0..cfa3cf7 100644
76039--- a/net/ipv4/route.c
76040+++ b/net/ipv4/route.c
76041@@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
76042
76043 static inline int rt_genid(struct net *net)
76044 {
76045- return atomic_read(&net->ipv4.rt_genid);
76046+ return atomic_read_unchecked(&net->ipv4.rt_genid);
76047 }
76048
76049 #ifdef CONFIG_PROC_FS
76050@@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
76051 unsigned char shuffle;
76052
76053 get_random_bytes(&shuffle, sizeof(shuffle));
76054- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76055+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76056 inetpeer_invalidate_tree(AF_INET);
76057 }
76058
76059@@ -3011,7 +3011,7 @@ static int rt_fill_info(struct net *net,
76060 error = rt->dst.error;
76061 if (peer) {
76062 inet_peer_refcheck(rt->peer);
76063- id = atomic_read(&peer->ip_id_count) & 0xffff;
76064+ id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
76065 if (peer->tcp_ts_stamp) {
76066 ts = peer->tcp_ts;
76067 tsage = get_seconds() - peer->tcp_ts_stamp;
76068diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
76069index c8d28c4..e40f75a 100644
76070--- a/net/ipv4/tcp_ipv4.c
76071+++ b/net/ipv4/tcp_ipv4.c
76072@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
76073 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76074
76075
76076+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76077+extern int grsec_enable_blackhole;
76078+#endif
76079+
76080 #ifdef CONFIG_TCP_MD5SIG
76081 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
76082 __be32 daddr, __be32 saddr, const struct tcphdr *th);
76083@@ -1656,6 +1660,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
76084 return 0;
76085
76086 reset:
76087+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76088+ if (!grsec_enable_blackhole)
76089+#endif
76090 tcp_v4_send_reset(rsk, skb);
76091 discard:
76092 kfree_skb(skb);
76093@@ -1718,12 +1725,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76094 TCP_SKB_CB(skb)->sacked = 0;
76095
76096 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76097- if (!sk)
76098+ if (!sk) {
76099+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76100+ ret = 1;
76101+#endif
76102 goto no_tcp_socket;
76103-
76104+ }
76105 process:
76106- if (sk->sk_state == TCP_TIME_WAIT)
76107+ if (sk->sk_state == TCP_TIME_WAIT) {
76108+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76109+ ret = 2;
76110+#endif
76111 goto do_time_wait;
76112+ }
76113
76114 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76115 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76116@@ -1774,6 +1788,10 @@ no_tcp_socket:
76117 bad_packet:
76118 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76119 } else {
76120+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76121+ if (!grsec_enable_blackhole || (ret == 1 &&
76122+ (skb->dev->flags & IFF_LOOPBACK)))
76123+#endif
76124 tcp_v4_send_reset(NULL, skb);
76125 }
76126
76127@@ -2386,7 +2404,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
76128 0, /* non standard timer */
76129 0, /* open_requests have no inode */
76130 atomic_read(&sk->sk_refcnt),
76131+#ifdef CONFIG_GRKERNSEC_HIDESYM
76132+ NULL,
76133+#else
76134 req,
76135+#endif
76136 len);
76137 }
76138
76139@@ -2436,7 +2458,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
76140 sock_i_uid(sk),
76141 icsk->icsk_probes_out,
76142 sock_i_ino(sk),
76143- atomic_read(&sk->sk_refcnt), sk,
76144+ atomic_read(&sk->sk_refcnt),
76145+#ifdef CONFIG_GRKERNSEC_HIDESYM
76146+ NULL,
76147+#else
76148+ sk,
76149+#endif
76150 jiffies_to_clock_t(icsk->icsk_rto),
76151 jiffies_to_clock_t(icsk->icsk_ack.ato),
76152 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76153@@ -2464,7 +2491,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
76154 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
76155 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76156 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76157- atomic_read(&tw->tw_refcnt), tw, len);
76158+ atomic_read(&tw->tw_refcnt),
76159+#ifdef CONFIG_GRKERNSEC_HIDESYM
76160+ NULL,
76161+#else
76162+ tw,
76163+#endif
76164+ len);
76165 }
76166
76167 #define TMPSZ 150
76168diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
76169index b85d9fe..4b0eed9 100644
76170--- a/net/ipv4/tcp_minisocks.c
76171+++ b/net/ipv4/tcp_minisocks.c
76172@@ -27,6 +27,10 @@
76173 #include <net/inet_common.h>
76174 #include <net/xfrm.h>
76175
76176+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76177+extern int grsec_enable_blackhole;
76178+#endif
76179+
76180 int sysctl_tcp_syncookies __read_mostly = 1;
76181 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76182
76183@@ -754,6 +758,10 @@ listen_overflow:
76184
76185 embryonic_reset:
76186 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76187+
76188+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76189+ if (!grsec_enable_blackhole)
76190+#endif
76191 if (!(flg & TCP_FLAG_RST))
76192 req->rsk_ops->send_reset(sk, skb);
76193
76194diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
76195index 4526fe6..1a34e43 100644
76196--- a/net/ipv4/tcp_probe.c
76197+++ b/net/ipv4/tcp_probe.c
76198@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
76199 if (cnt + width >= len)
76200 break;
76201
76202- if (copy_to_user(buf + cnt, tbuf, width))
76203+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76204 return -EFAULT;
76205 cnt += width;
76206 }
76207diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
76208index e911e6c..d0a9356 100644
76209--- a/net/ipv4/tcp_timer.c
76210+++ b/net/ipv4/tcp_timer.c
76211@@ -22,6 +22,10 @@
76212 #include <linux/gfp.h>
76213 #include <net/tcp.h>
76214
76215+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76216+extern int grsec_lastack_retries;
76217+#endif
76218+
76219 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76220 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76221 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76222@@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
76223 }
76224 }
76225
76226+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76227+ if ((sk->sk_state == TCP_LAST_ACK) &&
76228+ (grsec_lastack_retries > 0) &&
76229+ (grsec_lastack_retries < retry_until))
76230+ retry_until = grsec_lastack_retries;
76231+#endif
76232+
76233 if (retransmits_timed_out(sk, retry_until,
76234 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76235 /* Has it gone just too far? */
76236diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
76237index eaca736..60488ae 100644
76238--- a/net/ipv4/udp.c
76239+++ b/net/ipv4/udp.c
76240@@ -87,6 +87,7 @@
76241 #include <linux/types.h>
76242 #include <linux/fcntl.h>
76243 #include <linux/module.h>
76244+#include <linux/security.h>
76245 #include <linux/socket.h>
76246 #include <linux/sockios.h>
76247 #include <linux/igmp.h>
76248@@ -110,6 +111,10 @@
76249 #include <linux/static_key.h>
76250 #include "udp_impl.h"
76251
76252+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76253+extern int grsec_enable_blackhole;
76254+#endif
76255+
76256 struct udp_table udp_table __read_mostly;
76257 EXPORT_SYMBOL(udp_table);
76258
76259@@ -568,6 +573,9 @@ found:
76260 return s;
76261 }
76262
76263+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76264+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76265+
76266 /*
76267 * This routine is called by the ICMP module when it gets some
76268 * sort of error condition. If err < 0 then the socket should
76269@@ -859,9 +867,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
76270 dport = usin->sin_port;
76271 if (dport == 0)
76272 return -EINVAL;
76273+
76274+ err = gr_search_udp_sendmsg(sk, usin);
76275+ if (err)
76276+ return err;
76277 } else {
76278 if (sk->sk_state != TCP_ESTABLISHED)
76279 return -EDESTADDRREQ;
76280+
76281+ err = gr_search_udp_sendmsg(sk, NULL);
76282+ if (err)
76283+ return err;
76284+
76285 daddr = inet->inet_daddr;
76286 dport = inet->inet_dport;
76287 /* Open fast path for connected socket.
76288@@ -1103,7 +1120,7 @@ static unsigned int first_packet_length(struct sock *sk)
76289 udp_lib_checksum_complete(skb)) {
76290 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76291 IS_UDPLITE(sk));
76292- atomic_inc(&sk->sk_drops);
76293+ atomic_inc_unchecked(&sk->sk_drops);
76294 __skb_unlink(skb, rcvq);
76295 __skb_queue_tail(&list_kill, skb);
76296 }
76297@@ -1189,6 +1206,10 @@ try_again:
76298 if (!skb)
76299 goto out;
76300
76301+ err = gr_search_udp_recvmsg(sk, skb);
76302+ if (err)
76303+ goto out_free;
76304+
76305 ulen = skb->len - sizeof(struct udphdr);
76306 copied = len;
76307 if (copied > ulen)
76308@@ -1498,7 +1519,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76309
76310 drop:
76311 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76312- atomic_inc(&sk->sk_drops);
76313+ atomic_inc_unchecked(&sk->sk_drops);
76314 kfree_skb(skb);
76315 return -1;
76316 }
76317@@ -1517,7 +1538,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76318 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76319
76320 if (!skb1) {
76321- atomic_inc(&sk->sk_drops);
76322+ atomic_inc_unchecked(&sk->sk_drops);
76323 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76324 IS_UDPLITE(sk));
76325 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76326@@ -1686,6 +1707,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76327 goto csum_error;
76328
76329 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76330+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76331+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76332+#endif
76333 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76334
76335 /*
76336@@ -2104,8 +2128,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
76337 sk_wmem_alloc_get(sp),
76338 sk_rmem_alloc_get(sp),
76339 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76340- atomic_read(&sp->sk_refcnt), sp,
76341- atomic_read(&sp->sk_drops), len);
76342+ atomic_read(&sp->sk_refcnt),
76343+#ifdef CONFIG_GRKERNSEC_HIDESYM
76344+ NULL,
76345+#else
76346+ sp,
76347+#endif
76348+ atomic_read_unchecked(&sp->sk_drops), len);
76349 }
76350
76351 int udp4_seq_show(struct seq_file *seq, void *v)
76352diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
76353index 8f6411c..5767579 100644
76354--- a/net/ipv6/addrconf.c
76355+++ b/net/ipv6/addrconf.c
76356@@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
76357 p.iph.ihl = 5;
76358 p.iph.protocol = IPPROTO_IPV6;
76359 p.iph.ttl = 64;
76360- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76361+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76362
76363 if (ops->ndo_do_ioctl) {
76364 mm_segment_t oldfs = get_fs();
76365diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76366index e6cee52..cf47476 100644
76367--- a/net/ipv6/inet6_connection_sock.c
76368+++ b/net/ipv6/inet6_connection_sock.c
76369@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76370 #ifdef CONFIG_XFRM
76371 {
76372 struct rt6_info *rt = (struct rt6_info *)dst;
76373- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76374+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76375 }
76376 #endif
76377 }
76378@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76379 #ifdef CONFIG_XFRM
76380 if (dst) {
76381 struct rt6_info *rt = (struct rt6_info *)dst;
76382- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76383+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76384 __sk_dst_reset(sk);
76385 dst = NULL;
76386 }
76387diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76388index ba6d13d..6899122 100644
76389--- a/net/ipv6/ipv6_sockglue.c
76390+++ b/net/ipv6/ipv6_sockglue.c
76391@@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76392 if (sk->sk_type != SOCK_STREAM)
76393 return -ENOPROTOOPT;
76394
76395- msg.msg_control = optval;
76396+ msg.msg_control = (void __force_kernel *)optval;
76397 msg.msg_controllen = len;
76398 msg.msg_flags = flags;
76399
76400diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76401index 93d6983..8e54c4d 100644
76402--- a/net/ipv6/raw.c
76403+++ b/net/ipv6/raw.c
76404@@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76405 {
76406 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76407 skb_checksum_complete(skb)) {
76408- atomic_inc(&sk->sk_drops);
76409+ atomic_inc_unchecked(&sk->sk_drops);
76410 kfree_skb(skb);
76411 return NET_RX_DROP;
76412 }
76413@@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76414 struct raw6_sock *rp = raw6_sk(sk);
76415
76416 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76417- atomic_inc(&sk->sk_drops);
76418+ atomic_inc_unchecked(&sk->sk_drops);
76419 kfree_skb(skb);
76420 return NET_RX_DROP;
76421 }
76422@@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76423
76424 if (inet->hdrincl) {
76425 if (skb_checksum_complete(skb)) {
76426- atomic_inc(&sk->sk_drops);
76427+ atomic_inc_unchecked(&sk->sk_drops);
76428 kfree_skb(skb);
76429 return NET_RX_DROP;
76430 }
76431@@ -602,7 +602,7 @@ out:
76432 return err;
76433 }
76434
76435-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76436+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76437 struct flowi6 *fl6, struct dst_entry **dstp,
76438 unsigned int flags)
76439 {
76440@@ -914,12 +914,15 @@ do_confirm:
76441 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76442 char __user *optval, int optlen)
76443 {
76444+ struct icmp6_filter filter;
76445+
76446 switch (optname) {
76447 case ICMPV6_FILTER:
76448 if (optlen > sizeof(struct icmp6_filter))
76449 optlen = sizeof(struct icmp6_filter);
76450- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76451+ if (copy_from_user(&filter, optval, optlen))
76452 return -EFAULT;
76453+ raw6_sk(sk)->filter = filter;
76454 return 0;
76455 default:
76456 return -ENOPROTOOPT;
76457@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76458 char __user *optval, int __user *optlen)
76459 {
76460 int len;
76461+ struct icmp6_filter filter;
76462
76463 switch (optname) {
76464 case ICMPV6_FILTER:
76465@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76466 len = sizeof(struct icmp6_filter);
76467 if (put_user(len, optlen))
76468 return -EFAULT;
76469- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76470+ filter = raw6_sk(sk)->filter;
76471+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
76472 return -EFAULT;
76473 return 0;
76474 default:
76475@@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76476 0, 0L, 0,
76477 sock_i_uid(sp), 0,
76478 sock_i_ino(sp),
76479- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76480+ atomic_read(&sp->sk_refcnt),
76481+#ifdef CONFIG_GRKERNSEC_HIDESYM
76482+ NULL,
76483+#else
76484+ sp,
76485+#endif
76486+ atomic_read_unchecked(&sp->sk_drops));
76487 }
76488
76489 static int raw6_seq_show(struct seq_file *seq, void *v)
76490diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76491index 9df64a5..39875da 100644
76492--- a/net/ipv6/tcp_ipv6.c
76493+++ b/net/ipv6/tcp_ipv6.c
76494@@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76495 }
76496 #endif
76497
76498+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76499+extern int grsec_enable_blackhole;
76500+#endif
76501+
76502 static void tcp_v6_hash(struct sock *sk)
76503 {
76504 if (sk->sk_state != TCP_CLOSE) {
76505@@ -1544,6 +1548,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76506 return 0;
76507
76508 reset:
76509+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76510+ if (!grsec_enable_blackhole)
76511+#endif
76512 tcp_v6_send_reset(sk, skb);
76513 discard:
76514 if (opt_skb)
76515@@ -1625,12 +1632,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76516 TCP_SKB_CB(skb)->sacked = 0;
76517
76518 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76519- if (!sk)
76520+ if (!sk) {
76521+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76522+ ret = 1;
76523+#endif
76524 goto no_tcp_socket;
76525+ }
76526
76527 process:
76528- if (sk->sk_state == TCP_TIME_WAIT)
76529+ if (sk->sk_state == TCP_TIME_WAIT) {
76530+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76531+ ret = 2;
76532+#endif
76533 goto do_time_wait;
76534+ }
76535
76536 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76537 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76538@@ -1679,6 +1694,10 @@ no_tcp_socket:
76539 bad_packet:
76540 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76541 } else {
76542+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76543+ if (!grsec_enable_blackhole || (ret == 1 &&
76544+ (skb->dev->flags & IFF_LOOPBACK)))
76545+#endif
76546 tcp_v6_send_reset(NULL, skb);
76547 }
76548
76549@@ -1885,7 +1904,13 @@ static void get_openreq6(struct seq_file *seq,
76550 uid,
76551 0, /* non standard timer */
76552 0, /* open_requests have no inode */
76553- 0, req);
76554+ 0,
76555+#ifdef CONFIG_GRKERNSEC_HIDESYM
76556+ NULL
76557+#else
76558+ req
76559+#endif
76560+ );
76561 }
76562
76563 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76564@@ -1935,7 +1960,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76565 sock_i_uid(sp),
76566 icsk->icsk_probes_out,
76567 sock_i_ino(sp),
76568- atomic_read(&sp->sk_refcnt), sp,
76569+ atomic_read(&sp->sk_refcnt),
76570+#ifdef CONFIG_GRKERNSEC_HIDESYM
76571+ NULL,
76572+#else
76573+ sp,
76574+#endif
76575 jiffies_to_clock_t(icsk->icsk_rto),
76576 jiffies_to_clock_t(icsk->icsk_ack.ato),
76577 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76578@@ -1970,7 +2000,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76579 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76580 tw->tw_substate, 0, 0,
76581 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76582- atomic_read(&tw->tw_refcnt), tw);
76583+ atomic_read(&tw->tw_refcnt),
76584+#ifdef CONFIG_GRKERNSEC_HIDESYM
76585+ NULL
76586+#else
76587+ tw
76588+#endif
76589+ );
76590 }
76591
76592 static int tcp6_seq_show(struct seq_file *seq, void *v)
76593diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76594index f05099f..ea613f0 100644
76595--- a/net/ipv6/udp.c
76596+++ b/net/ipv6/udp.c
76597@@ -50,6 +50,10 @@
76598 #include <linux/seq_file.h>
76599 #include "udp_impl.h"
76600
76601+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76602+extern int grsec_enable_blackhole;
76603+#endif
76604+
76605 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76606 {
76607 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76608@@ -615,7 +619,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76609 return rc;
76610 drop:
76611 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76612- atomic_inc(&sk->sk_drops);
76613+ atomic_inc_unchecked(&sk->sk_drops);
76614 kfree_skb(skb);
76615 return -1;
76616 }
76617@@ -673,7 +677,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76618 if (likely(skb1 == NULL))
76619 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76620 if (!skb1) {
76621- atomic_inc(&sk->sk_drops);
76622+ atomic_inc_unchecked(&sk->sk_drops);
76623 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76624 IS_UDPLITE(sk));
76625 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76626@@ -844,6 +848,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76627 goto discard;
76628
76629 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76630+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76631+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76632+#endif
76633 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76634
76635 kfree_skb(skb);
76636@@ -1453,8 +1460,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76637 0, 0L, 0,
76638 sock_i_uid(sp), 0,
76639 sock_i_ino(sp),
76640- atomic_read(&sp->sk_refcnt), sp,
76641- atomic_read(&sp->sk_drops));
76642+ atomic_read(&sp->sk_refcnt),
76643+#ifdef CONFIG_GRKERNSEC_HIDESYM
76644+ NULL,
76645+#else
76646+ sp,
76647+#endif
76648+ atomic_read_unchecked(&sp->sk_drops));
76649 }
76650
76651 int udp6_seq_show(struct seq_file *seq, void *v)
76652diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76653index 6b9d5a0..4dffaf1 100644
76654--- a/net/irda/ircomm/ircomm_tty.c
76655+++ b/net/irda/ircomm/ircomm_tty.c
76656@@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76657 add_wait_queue(&self->open_wait, &wait);
76658
76659 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76660- __FILE__,__LINE__, tty->driver->name, self->open_count );
76661+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76662
76663 /* As far as I can see, we protect open_count - Jean II */
76664 spin_lock_irqsave(&self->spinlock, flags);
76665 if (!tty_hung_up_p(filp)) {
76666 extra_count = 1;
76667- self->open_count--;
76668+ local_dec(&self->open_count);
76669 }
76670 spin_unlock_irqrestore(&self->spinlock, flags);
76671- self->blocked_open++;
76672+ local_inc(&self->blocked_open);
76673
76674 while (1) {
76675 if (tty->termios->c_cflag & CBAUD) {
76676@@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76677 }
76678
76679 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76680- __FILE__,__LINE__, tty->driver->name, self->open_count );
76681+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76682
76683 schedule();
76684 }
76685@@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76686 if (extra_count) {
76687 /* ++ is not atomic, so this should be protected - Jean II */
76688 spin_lock_irqsave(&self->spinlock, flags);
76689- self->open_count++;
76690+ local_inc(&self->open_count);
76691 spin_unlock_irqrestore(&self->spinlock, flags);
76692 }
76693- self->blocked_open--;
76694+ local_dec(&self->blocked_open);
76695
76696 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76697- __FILE__,__LINE__, tty->driver->name, self->open_count);
76698+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76699
76700 if (!retval)
76701 self->flags |= ASYNC_NORMAL_ACTIVE;
76702@@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76703 }
76704 /* ++ is not atomic, so this should be protected - Jean II */
76705 spin_lock_irqsave(&self->spinlock, flags);
76706- self->open_count++;
76707+ local_inc(&self->open_count);
76708
76709 tty->driver_data = self;
76710 self->tty = tty;
76711 spin_unlock_irqrestore(&self->spinlock, flags);
76712
76713 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76714- self->line, self->open_count);
76715+ self->line, local_read(&self->open_count));
76716
76717 /* Not really used by us, but lets do it anyway */
76718 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76719@@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76720 return;
76721 }
76722
76723- if ((tty->count == 1) && (self->open_count != 1)) {
76724+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76725 /*
76726 * Uh, oh. tty->count is 1, which means that the tty
76727 * structure will be freed. state->count should always
76728@@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76729 */
76730 IRDA_DEBUG(0, "%s(), bad serial port count; "
76731 "tty->count is 1, state->count is %d\n", __func__ ,
76732- self->open_count);
76733- self->open_count = 1;
76734+ local_read(&self->open_count));
76735+ local_set(&self->open_count, 1);
76736 }
76737
76738- if (--self->open_count < 0) {
76739+ if (local_dec_return(&self->open_count) < 0) {
76740 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76741- __func__, self->line, self->open_count);
76742- self->open_count = 0;
76743+ __func__, self->line, local_read(&self->open_count));
76744+ local_set(&self->open_count, 0);
76745 }
76746- if (self->open_count) {
76747+ if (local_read(&self->open_count)) {
76748 spin_unlock_irqrestore(&self->spinlock, flags);
76749
76750 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76751@@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76752 tty->closing = 0;
76753 self->tty = NULL;
76754
76755- if (self->blocked_open) {
76756+ if (local_read(&self->blocked_open)) {
76757 if (self->close_delay)
76758 schedule_timeout_interruptible(self->close_delay);
76759 wake_up_interruptible(&self->open_wait);
76760@@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76761 spin_lock_irqsave(&self->spinlock, flags);
76762 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76763 self->tty = NULL;
76764- self->open_count = 0;
76765+ local_set(&self->open_count, 0);
76766 spin_unlock_irqrestore(&self->spinlock, flags);
76767
76768 wake_up_interruptible(&self->open_wait);
76769@@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76770 seq_putc(m, '\n');
76771
76772 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76773- seq_printf(m, "Open count: %d\n", self->open_count);
76774+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76775 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76776 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76777
76778diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76779index cd6f7a9..e63fe89 100644
76780--- a/net/iucv/af_iucv.c
76781+++ b/net/iucv/af_iucv.c
76782@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
76783
76784 write_lock_bh(&iucv_sk_list.lock);
76785
76786- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76787+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76788 while (__iucv_get_sock_by_name(name)) {
76789 sprintf(name, "%08x",
76790- atomic_inc_return(&iucv_sk_list.autobind_name));
76791+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76792 }
76793
76794 write_unlock_bh(&iucv_sk_list.lock);
76795diff --git a/net/key/af_key.c b/net/key/af_key.c
76796index 34e4185..8823368 100644
76797--- a/net/key/af_key.c
76798+++ b/net/key/af_key.c
76799@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76800 static u32 get_acqseq(void)
76801 {
76802 u32 res;
76803- static atomic_t acqseq;
76804+ static atomic_unchecked_t acqseq;
76805
76806 do {
76807- res = atomic_inc_return(&acqseq);
76808+ res = atomic_inc_return_unchecked(&acqseq);
76809 } while (!res);
76810 return res;
76811 }
76812diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
76813index 3f3cd50..d2cf249 100644
76814--- a/net/mac80211/ieee80211_i.h
76815+++ b/net/mac80211/ieee80211_i.h
76816@@ -28,6 +28,7 @@
76817 #include <net/ieee80211_radiotap.h>
76818 #include <net/cfg80211.h>
76819 #include <net/mac80211.h>
76820+#include <asm/local.h>
76821 #include "key.h"
76822 #include "sta_info.h"
76823
76824@@ -863,7 +864,7 @@ struct ieee80211_local {
76825 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
76826 spinlock_t queue_stop_reason_lock;
76827
76828- int open_count;
76829+ local_t open_count;
76830 int monitors, cooked_mntrs;
76831 /* number of interfaces with corresponding FIF_ flags */
76832 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
76833diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
76834index 8664111..1d6a065 100644
76835--- a/net/mac80211/iface.c
76836+++ b/net/mac80211/iface.c
76837@@ -328,7 +328,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76838 break;
76839 }
76840
76841- if (local->open_count == 0) {
76842+ if (local_read(&local->open_count) == 0) {
76843 res = drv_start(local);
76844 if (res)
76845 goto err_del_bss;
76846@@ -371,7 +371,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76847 break;
76848 }
76849
76850- if (local->monitors == 0 && local->open_count == 0) {
76851+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
76852 res = ieee80211_add_virtual_monitor(local);
76853 if (res)
76854 goto err_stop;
76855@@ -468,7 +468,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76856 mutex_unlock(&local->mtx);
76857
76858 if (coming_up)
76859- local->open_count++;
76860+ local_inc(&local->open_count);
76861
76862 if (hw_reconf_flags)
76863 ieee80211_hw_config(local, hw_reconf_flags);
76864@@ -481,7 +481,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76865 err_del_interface:
76866 drv_remove_interface(local, sdata);
76867 err_stop:
76868- if (!local->open_count)
76869+ if (!local_read(&local->open_count))
76870 drv_stop(local);
76871 err_del_bss:
76872 sdata->bss = NULL;
76873@@ -613,7 +613,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76874 }
76875
76876 if (going_down)
76877- local->open_count--;
76878+ local_dec(&local->open_count);
76879
76880 switch (sdata->vif.type) {
76881 case NL80211_IFTYPE_AP_VLAN:
76882@@ -685,7 +685,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76883
76884 ieee80211_recalc_ps(local, -1);
76885
76886- if (local->open_count == 0) {
76887+ if (local_read(&local->open_count) == 0) {
76888 if (local->ops->napi_poll)
76889 napi_disable(&local->napi);
76890 ieee80211_clear_tx_pending(local);
76891@@ -717,7 +717,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76892 }
76893 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
76894
76895- if (local->monitors == local->open_count && local->monitors > 0)
76896+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
76897 ieee80211_add_virtual_monitor(local);
76898 }
76899
76900diff --git a/net/mac80211/main.c b/net/mac80211/main.c
76901index f5548e9..474a15f 100644
76902--- a/net/mac80211/main.c
76903+++ b/net/mac80211/main.c
76904@@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
76905 local->hw.conf.power_level = power;
76906 }
76907
76908- if (changed && local->open_count) {
76909+ if (changed && local_read(&local->open_count)) {
76910 ret = drv_config(local, changed);
76911 /*
76912 * Goal:
76913diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
76914index af1c4e2..24dbbe3 100644
76915--- a/net/mac80211/pm.c
76916+++ b/net/mac80211/pm.c
76917@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76918 struct ieee80211_sub_if_data *sdata;
76919 struct sta_info *sta;
76920
76921- if (!local->open_count)
76922+ if (!local_read(&local->open_count))
76923 goto suspend;
76924
76925 ieee80211_scan_cancel(local);
76926@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76927 cancel_work_sync(&local->dynamic_ps_enable_work);
76928 del_timer_sync(&local->dynamic_ps_timer);
76929
76930- local->wowlan = wowlan && local->open_count;
76931+ local->wowlan = wowlan && local_read(&local->open_count);
76932 if (local->wowlan) {
76933 int err = drv_suspend(local, wowlan);
76934 if (err < 0) {
76935@@ -132,7 +132,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76936 drv_remove_interface(local, sdata);
76937
76938 /* stop hardware - this must stop RX */
76939- if (local->open_count)
76940+ if (local_read(&local->open_count))
76941 ieee80211_stop_device(local);
76942
76943 suspend:
76944diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
76945index 3313c11..bec9f17 100644
76946--- a/net/mac80211/rate.c
76947+++ b/net/mac80211/rate.c
76948@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
76949
76950 ASSERT_RTNL();
76951
76952- if (local->open_count)
76953+ if (local_read(&local->open_count))
76954 return -EBUSY;
76955
76956 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
76957diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
76958index c97a065..ff61928 100644
76959--- a/net/mac80211/rc80211_pid_debugfs.c
76960+++ b/net/mac80211/rc80211_pid_debugfs.c
76961@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
76962
76963 spin_unlock_irqrestore(&events->lock, status);
76964
76965- if (copy_to_user(buf, pb, p))
76966+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
76967 return -EFAULT;
76968
76969 return p;
76970diff --git a/net/mac80211/util.c b/net/mac80211/util.c
76971index 8dd4712..19594fa 100644
76972--- a/net/mac80211/util.c
76973+++ b/net/mac80211/util.c
76974@@ -1216,7 +1216,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
76975 }
76976 #endif
76977 /* everything else happens only if HW was up & running */
76978- if (!local->open_count)
76979+ if (!local_read(&local->open_count))
76980 goto wake_up;
76981
76982 /*
76983diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
76984index 209c1ed..39484dc 100644
76985--- a/net/netfilter/Kconfig
76986+++ b/net/netfilter/Kconfig
76987@@ -851,6 +851,16 @@ config NETFILTER_XT_MATCH_ESP
76988
76989 To compile it as a module, choose M here. If unsure, say N.
76990
76991+config NETFILTER_XT_MATCH_GRADM
76992+ tristate '"gradm" match support'
76993+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
76994+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
76995+ ---help---
76996+ The gradm match allows to match on grsecurity RBAC being enabled.
76997+ It is useful when iptables rules are applied early on bootup to
76998+ prevent connections to the machine (except from a trusted host)
76999+ while the RBAC system is disabled.
77000+
77001 config NETFILTER_XT_MATCH_HASHLIMIT
77002 tristate '"hashlimit" match support'
77003 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77004diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
77005index 4e7960c..89e48d4 100644
77006--- a/net/netfilter/Makefile
77007+++ b/net/netfilter/Makefile
77008@@ -87,6 +87,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77009 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77010 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
77011 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77012+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77013 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77014 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77015 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77016diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
77017index 1548df9..98ad9b4 100644
77018--- a/net/netfilter/ipvs/ip_vs_conn.c
77019+++ b/net/netfilter/ipvs/ip_vs_conn.c
77020@@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
77021 /* Increase the refcnt counter of the dest */
77022 atomic_inc(&dest->refcnt);
77023
77024- conn_flags = atomic_read(&dest->conn_flags);
77025+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
77026 if (cp->protocol != IPPROTO_UDP)
77027 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77028 flags = cp->flags;
77029@@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
77030 atomic_set(&cp->refcnt, 1);
77031
77032 atomic_set(&cp->n_control, 0);
77033- atomic_set(&cp->in_pkts, 0);
77034+ atomic_set_unchecked(&cp->in_pkts, 0);
77035
77036 atomic_inc(&ipvs->conn_count);
77037 if (flags & IP_VS_CONN_F_NO_CPORT)
77038@@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
77039
77040 /* Don't drop the entry if its number of incoming packets is not
77041 located in [0, 8] */
77042- i = atomic_read(&cp->in_pkts);
77043+ i = atomic_read_unchecked(&cp->in_pkts);
77044 if (i > 8 || i < 0) return 0;
77045
77046 if (!todrop_rate[i]) return 0;
77047diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
77048index a54b018c..07e0120 100644
77049--- a/net/netfilter/ipvs/ip_vs_core.c
77050+++ b/net/netfilter/ipvs/ip_vs_core.c
77051@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
77052 ret = cp->packet_xmit(skb, cp, pd->pp);
77053 /* do not touch skb anymore */
77054
77055- atomic_inc(&cp->in_pkts);
77056+ atomic_inc_unchecked(&cp->in_pkts);
77057 ip_vs_conn_put(cp);
77058 return ret;
77059 }
77060@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
77061 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77062 pkts = sysctl_sync_threshold(ipvs);
77063 else
77064- pkts = atomic_add_return(1, &cp->in_pkts);
77065+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77066
77067 if (ipvs->sync_state & IP_VS_STATE_MASTER)
77068 ip_vs_sync_conn(net, cp, pkts);
77069diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
77070index 84444dd..86adaa0 100644
77071--- a/net/netfilter/ipvs/ip_vs_ctl.c
77072+++ b/net/netfilter/ipvs/ip_vs_ctl.c
77073@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
77074 ip_vs_rs_hash(ipvs, dest);
77075 write_unlock_bh(&ipvs->rs_lock);
77076 }
77077- atomic_set(&dest->conn_flags, conn_flags);
77078+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
77079
77080 /* bind the service */
77081 if (!dest->svc) {
77082@@ -2074,7 +2074,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77083 " %-7s %-6d %-10d %-10d\n",
77084 &dest->addr.in6,
77085 ntohs(dest->port),
77086- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77087+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77088 atomic_read(&dest->weight),
77089 atomic_read(&dest->activeconns),
77090 atomic_read(&dest->inactconns));
77091@@ -2085,7 +2085,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77092 "%-7s %-6d %-10d %-10d\n",
77093 ntohl(dest->addr.ip),
77094 ntohs(dest->port),
77095- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77096+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77097 atomic_read(&dest->weight),
77098 atomic_read(&dest->activeconns),
77099 atomic_read(&dest->inactconns));
77100@@ -2555,7 +2555,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
77101
77102 entry.addr = dest->addr.ip;
77103 entry.port = dest->port;
77104- entry.conn_flags = atomic_read(&dest->conn_flags);
77105+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77106 entry.weight = atomic_read(&dest->weight);
77107 entry.u_threshold = dest->u_threshold;
77108 entry.l_threshold = dest->l_threshold;
77109@@ -3089,7 +3089,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
77110 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
77111 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
77112 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77113- (atomic_read(&dest->conn_flags) &
77114+ (atomic_read_unchecked(&dest->conn_flags) &
77115 IP_VS_CONN_F_FWD_MASK)) ||
77116 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
77117 atomic_read(&dest->weight)) ||
77118diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
77119index effa10c..9058928 100644
77120--- a/net/netfilter/ipvs/ip_vs_sync.c
77121+++ b/net/netfilter/ipvs/ip_vs_sync.c
77122@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
77123 cp = cp->control;
77124 if (cp) {
77125 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77126- pkts = atomic_add_return(1, &cp->in_pkts);
77127+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77128 else
77129 pkts = sysctl_sync_threshold(ipvs);
77130 ip_vs_sync_conn(net, cp->control, pkts);
77131@@ -758,7 +758,7 @@ control:
77132 if (!cp)
77133 return;
77134 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77135- pkts = atomic_add_return(1, &cp->in_pkts);
77136+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77137 else
77138 pkts = sysctl_sync_threshold(ipvs);
77139 goto sloop;
77140@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
77141
77142 if (opt)
77143 memcpy(&cp->in_seq, opt, sizeof(*opt));
77144- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77145+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77146 cp->state = state;
77147 cp->old_state = cp->state;
77148 /*
77149diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
77150index 7fd66de..e6fb361 100644
77151--- a/net/netfilter/ipvs/ip_vs_xmit.c
77152+++ b/net/netfilter/ipvs/ip_vs_xmit.c
77153@@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
77154 else
77155 rc = NF_ACCEPT;
77156 /* do not touch skb anymore */
77157- atomic_inc(&cp->in_pkts);
77158+ atomic_inc_unchecked(&cp->in_pkts);
77159 goto out;
77160 }
77161
77162@@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
77163 else
77164 rc = NF_ACCEPT;
77165 /* do not touch skb anymore */
77166- atomic_inc(&cp->in_pkts);
77167+ atomic_inc_unchecked(&cp->in_pkts);
77168 goto out;
77169 }
77170
77171diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
77172index ac3af97..c134c21 100644
77173--- a/net/netfilter/nf_conntrack_core.c
77174+++ b/net/netfilter/nf_conntrack_core.c
77175@@ -1530,6 +1530,10 @@ err_proto:
77176 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
77177 #define DYING_NULLS_VAL ((1<<30)+1)
77178
77179+#ifdef CONFIG_GRKERNSEC_HIDESYM
77180+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
77181+#endif
77182+
77183 static int nf_conntrack_init_net(struct net *net)
77184 {
77185 int ret;
77186@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
77187 goto err_stat;
77188 }
77189
77190+#ifdef CONFIG_GRKERNSEC_HIDESYM
77191+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
77192+#else
77193 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
77194+#endif
77195 if (!net->ct.slabname) {
77196 ret = -ENOMEM;
77197 goto err_slabname;
77198diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
77199index 3c3cfc0..7a6ea1a 100644
77200--- a/net/netfilter/nfnetlink_log.c
77201+++ b/net/netfilter/nfnetlink_log.c
77202@@ -70,7 +70,7 @@ struct nfulnl_instance {
77203 };
77204
77205 static DEFINE_SPINLOCK(instances_lock);
77206-static atomic_t global_seq;
77207+static atomic_unchecked_t global_seq;
77208
77209 #define INSTANCE_BUCKETS 16
77210 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77211@@ -517,7 +517,7 @@ __build_packet_message(struct nfulnl_instance *inst,
77212 /* global sequence number */
77213 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
77214 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
77215- htonl(atomic_inc_return(&global_seq))))
77216+ htonl(atomic_inc_return_unchecked(&global_seq))))
77217 goto nla_put_failure;
77218
77219 if (data_len) {
77220diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
77221new file mode 100644
77222index 0000000..6905327
77223--- /dev/null
77224+++ b/net/netfilter/xt_gradm.c
77225@@ -0,0 +1,51 @@
77226+/*
77227+ * gradm match for netfilter
77228