]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.5.0-201208062017.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.5.0-201208062017.patch
CommitLineData
dd3a013c
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..cb1b997 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@@ -730,7 +835,7 @@ fault_msg:
16984 * segment size, and 32-bit linear address value:
16985 */
16986
16987- .data
16988+.section .rodata,"a",@progbits
16989 .globl boot_gdt_descr
16990 .globl idt_descr
16991
16992@@ -739,7 +844,7 @@ fault_msg:
16993 .word 0 # 32 bit align gdt_desc.address
16994 boot_gdt_descr:
16995 .word __BOOT_DS+7
16996- .long boot_gdt - __PAGE_OFFSET
16997+ .long pa(boot_gdt)
16998
16999 .word 0 # 32-bit align idt_desc.address
17000 idt_descr:
17001@@ -750,7 +855,7 @@ idt_descr:
17002 .word 0 # 32 bit align gdt_desc.address
17003 ENTRY(early_gdt_descr)
17004 .word GDT_ENTRIES*8-1
17005- .long gdt_page /* Overwritten for secondary CPUs */
17006+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17007
17008 /*
17009 * The boot_gdt must mirror the equivalent in setup.S and is
17010@@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17011 .align L1_CACHE_BYTES
17012 ENTRY(boot_gdt)
17013 .fill GDT_ENTRY_BOOT_CS,8,0
17014- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17015- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17016+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17017+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17018+
17019+ .align PAGE_SIZE_asm
17020+ENTRY(cpu_gdt_table)
17021+ .rept NR_CPUS
17022+ .quad 0x0000000000000000 /* NULL descriptor */
17023+ .quad 0x0000000000000000 /* 0x0b reserved */
17024+ .quad 0x0000000000000000 /* 0x13 reserved */
17025+ .quad 0x0000000000000000 /* 0x1b reserved */
17026+
17027+#ifdef CONFIG_PAX_KERNEXEC
17028+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17029+#else
17030+ .quad 0x0000000000000000 /* 0x20 unused */
17031+#endif
17032+
17033+ .quad 0x0000000000000000 /* 0x28 unused */
17034+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17035+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17036+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17037+ .quad 0x0000000000000000 /* 0x4b reserved */
17038+ .quad 0x0000000000000000 /* 0x53 reserved */
17039+ .quad 0x0000000000000000 /* 0x5b reserved */
17040+
17041+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17042+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17043+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17044+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17045+
17046+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17047+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17048+
17049+ /*
17050+ * Segments used for calling PnP BIOS have byte granularity.
17051+ * The code segments and data segments have fixed 64k limits,
17052+ * the transfer segment sizes are set at run time.
17053+ */
17054+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17055+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17056+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17057+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17058+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17059+
17060+ /*
17061+ * The APM segments have byte granularity and their bases
17062+ * are set at run time. All have 64k limits.
17063+ */
17064+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17065+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17066+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17067+
17068+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17069+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17070+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17071+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17072+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17073+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17074+
17075+ /* Be sure this is zeroed to avoid false validations in Xen */
17076+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17077+ .endr
17078diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17079index 94bf9cc..400455a 100644
17080--- a/arch/x86/kernel/head_64.S
17081+++ b/arch/x86/kernel/head_64.S
17082@@ -20,6 +20,8 @@
17083 #include <asm/processor-flags.h>
17084 #include <asm/percpu.h>
17085 #include <asm/nops.h>
17086+#include <asm/cpufeature.h>
17087+#include <asm/alternative-asm.h>
17088
17089 #ifdef CONFIG_PARAVIRT
17090 #include <asm/asm-offsets.h>
17091@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17092 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17093 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17094 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17095+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17096+L3_VMALLOC_START = pud_index(VMALLOC_START)
17097+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17098+L3_VMALLOC_END = pud_index(VMALLOC_END)
17099+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17100+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17101
17102 .text
17103 __HEAD
17104@@ -88,35 +96,23 @@ startup_64:
17105 */
17106 addq %rbp, init_level4_pgt + 0(%rip)
17107 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17108+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17109+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17110+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17111 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17112
17113 addq %rbp, level3_ident_pgt + 0(%rip)
17114+#ifndef CONFIG_XEN
17115+ addq %rbp, level3_ident_pgt + 8(%rip)
17116+#endif
17117
17118- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17119- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17120+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17121+
17122+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17123+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17124
17125 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17126-
17127- /* Add an Identity mapping if I am above 1G */
17128- leaq _text(%rip), %rdi
17129- andq $PMD_PAGE_MASK, %rdi
17130-
17131- movq %rdi, %rax
17132- shrq $PUD_SHIFT, %rax
17133- andq $(PTRS_PER_PUD - 1), %rax
17134- jz ident_complete
17135-
17136- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17137- leaq level3_ident_pgt(%rip), %rbx
17138- movq %rdx, 0(%rbx, %rax, 8)
17139-
17140- movq %rdi, %rax
17141- shrq $PMD_SHIFT, %rax
17142- andq $(PTRS_PER_PMD - 1), %rax
17143- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17144- leaq level2_spare_pgt(%rip), %rbx
17145- movq %rdx, 0(%rbx, %rax, 8)
17146-ident_complete:
17147+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17148
17149 /*
17150 * Fixup the kernel text+data virtual addresses. Note that
17151@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17152 * after the boot processor executes this code.
17153 */
17154
17155- /* Enable PAE mode and PGE */
17156- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17157+ /* Enable PAE mode and PSE/PGE */
17158+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17159 movq %rax, %cr4
17160
17161 /* Setup early boot stage 4 level pagetables. */
17162@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17163 movl $MSR_EFER, %ecx
17164 rdmsr
17165 btsl $_EFER_SCE, %eax /* Enable System Call */
17166- btl $20,%edi /* No Execute supported? */
17167+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17168 jnc 1f
17169 btsl $_EFER_NX, %eax
17170+ leaq init_level4_pgt(%rip), %rdi
17171+#ifndef CONFIG_EFI
17172+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17173+#endif
17174+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17175+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17176+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17177+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17178 1: wrmsr /* Make changes effective */
17179
17180 /* Setup cr0 */
17181@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17182 * jump. In addition we need to ensure %cs is set so we make this
17183 * a far return.
17184 */
17185+ pax_set_fptr_mask
17186 movq initial_code(%rip),%rax
17187 pushq $0 # fake return address to stop unwinder
17188 pushq $__KERNEL_CS # set correct cs
17189@@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17190 bad_address:
17191 jmp bad_address
17192
17193- .section ".init.text","ax"
17194+ __INIT
17195 .globl early_idt_handlers
17196 early_idt_handlers:
17197 # 104(%rsp) %rflags
17198@@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17199 addq $16,%rsp # drop vector number and error code
17200 decl early_recursion_flag(%rip)
17201 INTERRUPT_RETURN
17202+ .previous
17203
17204+ __INITDATA
17205 .balign 4
17206 early_recursion_flag:
17207 .long 0
17208+ .previous
17209
17210+ .section .rodata,"a",@progbits
17211 #ifdef CONFIG_EARLY_PRINTK
17212 early_idt_msg:
17213 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17214@@ -360,6 +369,7 @@ early_idt_ripmsg:
17215 #endif /* CONFIG_EARLY_PRINTK */
17216 .previous
17217
17218+ .section .rodata,"a",@progbits
17219 #define NEXT_PAGE(name) \
17220 .balign PAGE_SIZE; \
17221 ENTRY(name)
17222@@ -372,7 +382,6 @@ ENTRY(name)
17223 i = i + 1 ; \
17224 .endr
17225
17226- .data
17227 /*
17228 * This default setting generates an ident mapping at address 0x100000
17229 * and a mapping for the kernel that precisely maps virtual address
17230@@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17231 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17232 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17233 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17234+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17235+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17236+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17237+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17238+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17239+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17240 .org init_level4_pgt + L4_START_KERNEL*8, 0
17241 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17242 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17243
17244+#ifdef CONFIG_PAX_PER_CPU_PGD
17245+NEXT_PAGE(cpu_pgd)
17246+ .rept NR_CPUS
17247+ .fill 512,8,0
17248+ .endr
17249+#endif
17250+
17251 NEXT_PAGE(level3_ident_pgt)
17252 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17253+#ifdef CONFIG_XEN
17254 .fill 511,8,0
17255+#else
17256+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17257+ .fill 510,8,0
17258+#endif
17259+
17260+NEXT_PAGE(level3_vmalloc_start_pgt)
17261+ .fill 512,8,0
17262+
17263+NEXT_PAGE(level3_vmalloc_end_pgt)
17264+ .fill 512,8,0
17265+
17266+NEXT_PAGE(level3_vmemmap_pgt)
17267+ .fill L3_VMEMMAP_START,8,0
17268+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17269
17270 NEXT_PAGE(level3_kernel_pgt)
17271 .fill L3_START_KERNEL,8,0
17272@@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17273 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17274 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17275
17276+NEXT_PAGE(level2_vmemmap_pgt)
17277+ .fill 512,8,0
17278+
17279 NEXT_PAGE(level2_fixmap_pgt)
17280- .fill 506,8,0
17281- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17282- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17283- .fill 5,8,0
17284+ .fill 507,8,0
17285+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17286+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17287+ .fill 4,8,0
17288
17289-NEXT_PAGE(level1_fixmap_pgt)
17290+NEXT_PAGE(level1_vsyscall_pgt)
17291 .fill 512,8,0
17292
17293-NEXT_PAGE(level2_ident_pgt)
17294- /* Since I easily can, map the first 1G.
17295+ /* Since I easily can, map the first 2G.
17296 * Don't set NX because code runs from these pages.
17297 */
17298- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17299+NEXT_PAGE(level2_ident_pgt)
17300+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17301
17302 NEXT_PAGE(level2_kernel_pgt)
17303 /*
17304@@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17305 * If you want to increase this then increase MODULES_VADDR
17306 * too.)
17307 */
17308- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17309- KERNEL_IMAGE_SIZE/PMD_SIZE)
17310-
17311-NEXT_PAGE(level2_spare_pgt)
17312- .fill 512, 8, 0
17313+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17314
17315 #undef PMDS
17316 #undef NEXT_PAGE
17317
17318- .data
17319+ .align PAGE_SIZE
17320+ENTRY(cpu_gdt_table)
17321+ .rept NR_CPUS
17322+ .quad 0x0000000000000000 /* NULL descriptor */
17323+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17324+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17325+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17326+ .quad 0x00cffb000000ffff /* __USER32_CS */
17327+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17328+ .quad 0x00affb000000ffff /* __USER_CS */
17329+
17330+#ifdef CONFIG_PAX_KERNEXEC
17331+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17332+#else
17333+ .quad 0x0 /* unused */
17334+#endif
17335+
17336+ .quad 0,0 /* TSS */
17337+ .quad 0,0 /* LDT */
17338+ .quad 0,0,0 /* three TLS descriptors */
17339+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17340+ /* asm/segment.h:GDT_ENTRIES must match this */
17341+
17342+ /* zero the remaining page */
17343+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17344+ .endr
17345+
17346 .align 16
17347 .globl early_gdt_descr
17348 early_gdt_descr:
17349 .word GDT_ENTRIES*8-1
17350 early_gdt_descr_base:
17351- .quad INIT_PER_CPU_VAR(gdt_page)
17352+ .quad cpu_gdt_table
17353
17354 ENTRY(phys_base)
17355 /* This must match the first entry in level2_kernel_pgt */
17356 .quad 0x0000000000000000
17357
17358 #include "../../x86/xen/xen-head.S"
17359-
17360- .section .bss, "aw", @nobits
17361+
17362+ .section .rodata,"a",@progbits
17363 .align L1_CACHE_BYTES
17364 ENTRY(idt_table)
17365- .skip IDT_ENTRIES * 16
17366+ .fill 512,8,0
17367
17368 .align L1_CACHE_BYTES
17369 ENTRY(nmi_idt_table)
17370- .skip IDT_ENTRIES * 16
17371+ .fill 512,8,0
17372
17373 __PAGE_ALIGNED_BSS
17374 .align PAGE_SIZE
17375diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17376index 9c3bd4a..e1d9b35 100644
17377--- a/arch/x86/kernel/i386_ksyms_32.c
17378+++ b/arch/x86/kernel/i386_ksyms_32.c
17379@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17380 EXPORT_SYMBOL(cmpxchg8b_emu);
17381 #endif
17382
17383+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17384+
17385 /* Networking helper routines. */
17386 EXPORT_SYMBOL(csum_partial_copy_generic);
17387+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17388+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17389
17390 EXPORT_SYMBOL(__get_user_1);
17391 EXPORT_SYMBOL(__get_user_2);
17392@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17393
17394 EXPORT_SYMBOL(csum_partial);
17395 EXPORT_SYMBOL(empty_zero_page);
17396+
17397+#ifdef CONFIG_PAX_KERNEXEC
17398+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17399+#endif
17400diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17401index f250431..54097e7 100644
17402--- a/arch/x86/kernel/i387.c
17403+++ b/arch/x86/kernel/i387.c
17404@@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17405 static inline bool interrupted_user_mode(void)
17406 {
17407 struct pt_regs *regs = get_irq_regs();
17408- return regs && user_mode_vm(regs);
17409+ return regs && user_mode(regs);
17410 }
17411
17412 /*
17413diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17414index 36d1853..bf25736 100644
17415--- a/arch/x86/kernel/i8259.c
17416+++ b/arch/x86/kernel/i8259.c
17417@@ -209,7 +209,7 @@ spurious_8259A_irq:
17418 "spurious 8259A interrupt: IRQ%d.\n", irq);
17419 spurious_irq_mask |= irqmask;
17420 }
17421- atomic_inc(&irq_err_count);
17422+ atomic_inc_unchecked(&irq_err_count);
17423 /*
17424 * Theoretically we do not have to handle this IRQ,
17425 * but in Linux this does not cause problems and is
17426diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17427index 8c96897..be66bfa 100644
17428--- a/arch/x86/kernel/ioport.c
17429+++ b/arch/x86/kernel/ioport.c
17430@@ -6,6 +6,7 @@
17431 #include <linux/sched.h>
17432 #include <linux/kernel.h>
17433 #include <linux/capability.h>
17434+#include <linux/security.h>
17435 #include <linux/errno.h>
17436 #include <linux/types.h>
17437 #include <linux/ioport.h>
17438@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17439
17440 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17441 return -EINVAL;
17442+#ifdef CONFIG_GRKERNSEC_IO
17443+ if (turn_on && grsec_disable_privio) {
17444+ gr_handle_ioperm();
17445+ return -EPERM;
17446+ }
17447+#endif
17448 if (turn_on && !capable(CAP_SYS_RAWIO))
17449 return -EPERM;
17450
17451@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17452 * because the ->io_bitmap_max value must match the bitmap
17453 * contents:
17454 */
17455- tss = &per_cpu(init_tss, get_cpu());
17456+ tss = init_tss + get_cpu();
17457
17458 if (turn_on)
17459 bitmap_clear(t->io_bitmap_ptr, from, num);
17460@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17461 return -EINVAL;
17462 /* Trying to gain more privileges? */
17463 if (level > old) {
17464+#ifdef CONFIG_GRKERNSEC_IO
17465+ if (grsec_disable_privio) {
17466+ gr_handle_iopl();
17467+ return -EPERM;
17468+ }
17469+#endif
17470 if (!capable(CAP_SYS_RAWIO))
17471 return -EPERM;
17472 }
17473diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17474index 3dafc60..aa8e9c4 100644
17475--- a/arch/x86/kernel/irq.c
17476+++ b/arch/x86/kernel/irq.c
17477@@ -18,7 +18,7 @@
17478 #include <asm/mce.h>
17479 #include <asm/hw_irq.h>
17480
17481-atomic_t irq_err_count;
17482+atomic_unchecked_t irq_err_count;
17483
17484 /* Function pointer for generic interrupt vector handling */
17485 void (*x86_platform_ipi_callback)(void) = NULL;
17486@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17487 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17488 seq_printf(p, " Machine check polls\n");
17489 #endif
17490- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17491+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17492 #if defined(CONFIG_X86_IO_APIC)
17493- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17494+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17495 #endif
17496 return 0;
17497 }
17498@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17499
17500 u64 arch_irq_stat(void)
17501 {
17502- u64 sum = atomic_read(&irq_err_count);
17503+ u64 sum = atomic_read_unchecked(&irq_err_count);
17504
17505 #ifdef CONFIG_X86_IO_APIC
17506- sum += atomic_read(&irq_mis_count);
17507+ sum += atomic_read_unchecked(&irq_mis_count);
17508 #endif
17509 return sum;
17510 }
17511diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17512index 344faf8..355f60d 100644
17513--- a/arch/x86/kernel/irq_32.c
17514+++ b/arch/x86/kernel/irq_32.c
17515@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17516 __asm__ __volatile__("andl %%esp,%0" :
17517 "=r" (sp) : "0" (THREAD_SIZE - 1));
17518
17519- return sp < (sizeof(struct thread_info) + STACK_WARN);
17520+ return sp < STACK_WARN;
17521 }
17522
17523 static void print_stack_overflow(void)
17524@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17525 * per-CPU IRQ handling contexts (thread information and stack)
17526 */
17527 union irq_ctx {
17528- struct thread_info tinfo;
17529- u32 stack[THREAD_SIZE/sizeof(u32)];
17530+ unsigned long previous_esp;
17531+ u32 stack[THREAD_SIZE/sizeof(u32)];
17532 } __attribute__((aligned(THREAD_SIZE)));
17533
17534 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17535@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17536 static inline int
17537 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17538 {
17539- union irq_ctx *curctx, *irqctx;
17540+ union irq_ctx *irqctx;
17541 u32 *isp, arg1, arg2;
17542
17543- curctx = (union irq_ctx *) current_thread_info();
17544 irqctx = __this_cpu_read(hardirq_ctx);
17545
17546 /*
17547@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17548 * handler) we can't do that and just have to keep using the
17549 * current stack (which is the irq stack already after all)
17550 */
17551- if (unlikely(curctx == irqctx))
17552+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17553 return 0;
17554
17555 /* build the stack frame on the IRQ stack */
17556- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17557- irqctx->tinfo.task = curctx->tinfo.task;
17558- irqctx->tinfo.previous_esp = current_stack_pointer;
17559+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17560+ irqctx->previous_esp = current_stack_pointer;
17561
17562- /* Copy the preempt_count so that the [soft]irq checks work. */
17563- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17564+#ifdef CONFIG_PAX_MEMORY_UDEREF
17565+ __set_fs(MAKE_MM_SEG(0));
17566+#endif
17567
17568 if (unlikely(overflow))
17569 call_on_stack(print_stack_overflow, isp);
17570@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17571 : "0" (irq), "1" (desc), "2" (isp),
17572 "D" (desc->handle_irq)
17573 : "memory", "cc", "ecx");
17574+
17575+#ifdef CONFIG_PAX_MEMORY_UDEREF
17576+ __set_fs(current_thread_info()->addr_limit);
17577+#endif
17578+
17579 return 1;
17580 }
17581
17582@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17583 */
17584 void __cpuinit irq_ctx_init(int cpu)
17585 {
17586- union irq_ctx *irqctx;
17587-
17588 if (per_cpu(hardirq_ctx, cpu))
17589 return;
17590
17591- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17592- THREADINFO_GFP,
17593- THREAD_SIZE_ORDER));
17594- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17595- irqctx->tinfo.cpu = cpu;
17596- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17597- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17598-
17599- per_cpu(hardirq_ctx, cpu) = irqctx;
17600-
17601- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17602- THREADINFO_GFP,
17603- THREAD_SIZE_ORDER));
17604- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17605- irqctx->tinfo.cpu = cpu;
17606- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17607-
17608- per_cpu(softirq_ctx, cpu) = irqctx;
17609+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17610+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17611+
17612+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17613+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17614
17615 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17616 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17617@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17618 asmlinkage void do_softirq(void)
17619 {
17620 unsigned long flags;
17621- struct thread_info *curctx;
17622 union irq_ctx *irqctx;
17623 u32 *isp;
17624
17625@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17626 local_irq_save(flags);
17627
17628 if (local_softirq_pending()) {
17629- curctx = current_thread_info();
17630 irqctx = __this_cpu_read(softirq_ctx);
17631- irqctx->tinfo.task = curctx->task;
17632- irqctx->tinfo.previous_esp = current_stack_pointer;
17633+ irqctx->previous_esp = current_stack_pointer;
17634
17635 /* build the stack frame on the softirq stack */
17636- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17637+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17638+
17639+#ifdef CONFIG_PAX_MEMORY_UDEREF
17640+ __set_fs(MAKE_MM_SEG(0));
17641+#endif
17642
17643 call_on_stack(__do_softirq, isp);
17644+
17645+#ifdef CONFIG_PAX_MEMORY_UDEREF
17646+ __set_fs(current_thread_info()->addr_limit);
17647+#endif
17648+
17649 /*
17650 * Shouldn't happen, we returned above if in_interrupt():
17651 */
17652@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17653 if (unlikely(!desc))
17654 return false;
17655
17656- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17657+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17658 if (unlikely(overflow))
17659 print_stack_overflow();
17660 desc->handle_irq(irq, desc);
17661diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17662index d04d3ec..ea4b374 100644
17663--- a/arch/x86/kernel/irq_64.c
17664+++ b/arch/x86/kernel/irq_64.c
17665@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17666 u64 estack_top, estack_bottom;
17667 u64 curbase = (u64)task_stack_page(current);
17668
17669- if (user_mode_vm(regs))
17670+ if (user_mode(regs))
17671 return;
17672
17673 if (regs->sp >= curbase + sizeof(struct thread_info) +
17674diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17675index 1d5d31e..ab846ed 100644
17676--- a/arch/x86/kernel/kdebugfs.c
17677+++ b/arch/x86/kernel/kdebugfs.c
17678@@ -28,6 +28,8 @@ struct setup_data_node {
17679 };
17680
17681 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17682+ size_t count, loff_t *ppos) __size_overflow(3);
17683+static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17684 size_t count, loff_t *ppos)
17685 {
17686 struct setup_data_node *node = file->private_data;
17687diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17688index 3f61904..873cea9 100644
17689--- a/arch/x86/kernel/kgdb.c
17690+++ b/arch/x86/kernel/kgdb.c
17691@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17692 #ifdef CONFIG_X86_32
17693 switch (regno) {
17694 case GDB_SS:
17695- if (!user_mode_vm(regs))
17696+ if (!user_mode(regs))
17697 *(unsigned long *)mem = __KERNEL_DS;
17698 break;
17699 case GDB_SP:
17700- if (!user_mode_vm(regs))
17701+ if (!user_mode(regs))
17702 *(unsigned long *)mem = kernel_stack_pointer(regs);
17703 break;
17704 case GDB_GS:
17705@@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17706 case 'k':
17707 /* clear the trace bit */
17708 linux_regs->flags &= ~X86_EFLAGS_TF;
17709- atomic_set(&kgdb_cpu_doing_single_step, -1);
17710+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17711
17712 /* set the trace bit if we're stepping */
17713 if (remcomInBuffer[0] == 's') {
17714 linux_regs->flags |= X86_EFLAGS_TF;
17715- atomic_set(&kgdb_cpu_doing_single_step,
17716+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17717 raw_smp_processor_id());
17718 }
17719
17720@@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17721
17722 switch (cmd) {
17723 case DIE_DEBUG:
17724- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17725+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17726 if (user_mode(regs))
17727 return single_step_cont(regs, args);
17728 break;
17729diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17730index c5e410e..da6aaf9 100644
17731--- a/arch/x86/kernel/kprobes-opt.c
17732+++ b/arch/x86/kernel/kprobes-opt.c
17733@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17734 * Verify if the address gap is in 2GB range, because this uses
17735 * a relative jump.
17736 */
17737- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17738+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17739 if (abs(rel) > 0x7fffffff)
17740 return -ERANGE;
17741
17742@@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17743 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17744
17745 /* Set probe function call */
17746- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17747+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17748
17749 /* Set returning jmp instruction at the tail of out-of-line buffer */
17750 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17751- (u8 *)op->kp.addr + op->optinsn.size);
17752+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17753
17754 flush_icache_range((unsigned long) buf,
17755 (unsigned long) buf + TMPL_END_IDX +
17756@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17757 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17758
17759 /* Backup instructions which will be replaced by jump address */
17760- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17761+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17762 RELATIVE_ADDR_SIZE);
17763
17764 insn_buf[0] = RELATIVEJUMP_OPCODE;
17765diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17766index e2f751e..dffa2a0 100644
17767--- a/arch/x86/kernel/kprobes.c
17768+++ b/arch/x86/kernel/kprobes.c
17769@@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17770 } __attribute__((packed)) *insn;
17771
17772 insn = (struct __arch_relative_insn *)from;
17773+
17774+ pax_open_kernel();
17775 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17776 insn->op = op;
17777+ pax_close_kernel();
17778 }
17779
17780 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17781@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17782 kprobe_opcode_t opcode;
17783 kprobe_opcode_t *orig_opcodes = opcodes;
17784
17785- if (search_exception_tables((unsigned long)opcodes))
17786+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17787 return 0; /* Page fault may occur on this address. */
17788
17789 retry:
17790@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17791 /* Another subsystem puts a breakpoint, failed to recover */
17792 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17793 return 0;
17794+ pax_open_kernel();
17795 memcpy(dest, insn.kaddr, insn.length);
17796+ pax_close_kernel();
17797
17798 #ifdef CONFIG_X86_64
17799 if (insn_rip_relative(&insn)) {
17800@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17801 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17802 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17803 disp = (u8 *) dest + insn_offset_displacement(&insn);
17804+ pax_open_kernel();
17805 *(s32 *) disp = (s32) newdisp;
17806+ pax_close_kernel();
17807 }
17808 #endif
17809 return insn.length;
17810@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17811 * nor set current_kprobe, because it doesn't use single
17812 * stepping.
17813 */
17814- regs->ip = (unsigned long)p->ainsn.insn;
17815+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17816 preempt_enable_no_resched();
17817 return;
17818 }
17819@@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17820 if (p->opcode == BREAKPOINT_INSTRUCTION)
17821 regs->ip = (unsigned long)p->addr;
17822 else
17823- regs->ip = (unsigned long)p->ainsn.insn;
17824+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17825 }
17826
17827 /*
17828@@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17829 setup_singlestep(p, regs, kcb, 0);
17830 return 1;
17831 }
17832- } else if (*addr != BREAKPOINT_INSTRUCTION) {
17833+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17834 /*
17835 * The breakpoint instruction was removed right
17836 * after we hit it. Another cpu has removed
17837@@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17838 " movq %rax, 152(%rsp)\n"
17839 RESTORE_REGS_STRING
17840 " popfq\n"
17841+#ifdef KERNEXEC_PLUGIN
17842+ " btsq $63,(%rsp)\n"
17843+#endif
17844 #else
17845 " pushf\n"
17846 SAVE_REGS_STRING
17847@@ -765,7 +775,7 @@ static void __kprobes
17848 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17849 {
17850 unsigned long *tos = stack_addr(regs);
17851- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17852+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17853 unsigned long orig_ip = (unsigned long)p->addr;
17854 kprobe_opcode_t *insn = p->ainsn.insn;
17855
17856@@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
17857 struct die_args *args = data;
17858 int ret = NOTIFY_DONE;
17859
17860- if (args->regs && user_mode_vm(args->regs))
17861+ if (args->regs && user_mode(args->regs))
17862 return ret;
17863
17864 switch (val) {
17865diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17866index ebc9873..1b9724b 100644
17867--- a/arch/x86/kernel/ldt.c
17868+++ b/arch/x86/kernel/ldt.c
17869@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17870 if (reload) {
17871 #ifdef CONFIG_SMP
17872 preempt_disable();
17873- load_LDT(pc);
17874+ load_LDT_nolock(pc);
17875 if (!cpumask_equal(mm_cpumask(current->mm),
17876 cpumask_of(smp_processor_id())))
17877 smp_call_function(flush_ldt, current->mm, 1);
17878 preempt_enable();
17879 #else
17880- load_LDT(pc);
17881+ load_LDT_nolock(pc);
17882 #endif
17883 }
17884 if (oldsize) {
17885@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17886 return err;
17887
17888 for (i = 0; i < old->size; i++)
17889- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17890+ write_ldt_entry(new->ldt, i, old->ldt + i);
17891 return 0;
17892 }
17893
17894@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17895 retval = copy_ldt(&mm->context, &old_mm->context);
17896 mutex_unlock(&old_mm->context.lock);
17897 }
17898+
17899+ if (tsk == current) {
17900+ mm->context.vdso = 0;
17901+
17902+#ifdef CONFIG_X86_32
17903+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17904+ mm->context.user_cs_base = 0UL;
17905+ mm->context.user_cs_limit = ~0UL;
17906+
17907+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17908+ cpus_clear(mm->context.cpu_user_cs_mask);
17909+#endif
17910+
17911+#endif
17912+#endif
17913+
17914+ }
17915+
17916 return retval;
17917 }
17918
17919@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17920 }
17921 }
17922
17923+#ifdef CONFIG_PAX_SEGMEXEC
17924+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17925+ error = -EINVAL;
17926+ goto out_unlock;
17927+ }
17928+#endif
17929+
17930 fill_ldt(&ldt, &ldt_info);
17931 if (oldmode)
17932 ldt.avl = 0;
17933diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17934index 5b19e4d..6476a76 100644
17935--- a/arch/x86/kernel/machine_kexec_32.c
17936+++ b/arch/x86/kernel/machine_kexec_32.c
17937@@ -26,7 +26,7 @@
17938 #include <asm/cacheflush.h>
17939 #include <asm/debugreg.h>
17940
17941-static void set_idt(void *newidt, __u16 limit)
17942+static void set_idt(struct desc_struct *newidt, __u16 limit)
17943 {
17944 struct desc_ptr curidt;
17945
17946@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
17947 }
17948
17949
17950-static void set_gdt(void *newgdt, __u16 limit)
17951+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17952 {
17953 struct desc_ptr curgdt;
17954
17955@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
17956 }
17957
17958 control_page = page_address(image->control_code_page);
17959- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17960+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17961
17962 relocate_kernel_ptr = control_page;
17963 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17964diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17965index 0327e2b..e43737b 100644
17966--- a/arch/x86/kernel/microcode_intel.c
17967+++ b/arch/x86/kernel/microcode_intel.c
17968@@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17969
17970 static int get_ucode_user(void *to, const void *from, size_t n)
17971 {
17972- return copy_from_user(to, from, n);
17973+ return copy_from_user(to, (const void __force_user *)from, n);
17974 }
17975
17976 static enum ucode_state
17977 request_microcode_user(int cpu, const void __user *buf, size_t size)
17978 {
17979- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17980+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17981 }
17982
17983 static void microcode_fini_cpu(int cpu)
17984diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17985index f21fd94..61565cd 100644
17986--- a/arch/x86/kernel/module.c
17987+++ b/arch/x86/kernel/module.c
17988@@ -35,15 +35,60 @@
17989 #define DEBUGP(fmt...)
17990 #endif
17991
17992-void *module_alloc(unsigned long size)
17993+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
17994 {
17995- if (PAGE_ALIGN(size) > MODULES_LEN)
17996+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
17997 return NULL;
17998 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
17999- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18000+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18001 -1, __builtin_return_address(0));
18002 }
18003
18004+void *module_alloc(unsigned long size)
18005+{
18006+
18007+#ifdef CONFIG_PAX_KERNEXEC
18008+ return __module_alloc(size, PAGE_KERNEL);
18009+#else
18010+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18011+#endif
18012+
18013+}
18014+
18015+#ifdef CONFIG_PAX_KERNEXEC
18016+#ifdef CONFIG_X86_32
18017+void *module_alloc_exec(unsigned long size)
18018+{
18019+ struct vm_struct *area;
18020+
18021+ if (size == 0)
18022+ return NULL;
18023+
18024+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18025+ return area ? area->addr : NULL;
18026+}
18027+EXPORT_SYMBOL(module_alloc_exec);
18028+
18029+void module_free_exec(struct module *mod, void *module_region)
18030+{
18031+ vunmap(module_region);
18032+}
18033+EXPORT_SYMBOL(module_free_exec);
18034+#else
18035+void module_free_exec(struct module *mod, void *module_region)
18036+{
18037+ module_free(mod, module_region);
18038+}
18039+EXPORT_SYMBOL(module_free_exec);
18040+
18041+void *module_alloc_exec(unsigned long size)
18042+{
18043+ return __module_alloc(size, PAGE_KERNEL_RX);
18044+}
18045+EXPORT_SYMBOL(module_alloc_exec);
18046+#endif
18047+#endif
18048+
18049 #ifdef CONFIG_X86_32
18050 int apply_relocate(Elf32_Shdr *sechdrs,
18051 const char *strtab,
18052@@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18053 unsigned int i;
18054 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18055 Elf32_Sym *sym;
18056- uint32_t *location;
18057+ uint32_t *plocation, location;
18058
18059 DEBUGP("Applying relocate section %u to %u\n", relsec,
18060 sechdrs[relsec].sh_info);
18061 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18062 /* This is where to make the change */
18063- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18064- + rel[i].r_offset;
18065+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18066+ location = (uint32_t)plocation;
18067+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18068+ plocation = ktla_ktva((void *)plocation);
18069 /* This is the symbol it is referring to. Note that all
18070 undefined symbols have been resolved. */
18071 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18072@@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18073 switch (ELF32_R_TYPE(rel[i].r_info)) {
18074 case R_386_32:
18075 /* We add the value into the location given */
18076- *location += sym->st_value;
18077+ pax_open_kernel();
18078+ *plocation += sym->st_value;
18079+ pax_close_kernel();
18080 break;
18081 case R_386_PC32:
18082 /* Add the value, subtract its postition */
18083- *location += sym->st_value - (uint32_t)location;
18084+ pax_open_kernel();
18085+ *plocation += sym->st_value - location;
18086+ pax_close_kernel();
18087 break;
18088 default:
18089 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18090@@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18091 case R_X86_64_NONE:
18092 break;
18093 case R_X86_64_64:
18094+ pax_open_kernel();
18095 *(u64 *)loc = val;
18096+ pax_close_kernel();
18097 break;
18098 case R_X86_64_32:
18099+ pax_open_kernel();
18100 *(u32 *)loc = val;
18101+ pax_close_kernel();
18102 if (val != *(u32 *)loc)
18103 goto overflow;
18104 break;
18105 case R_X86_64_32S:
18106+ pax_open_kernel();
18107 *(s32 *)loc = val;
18108+ pax_close_kernel();
18109 if ((s64)val != *(s32 *)loc)
18110 goto overflow;
18111 break;
18112 case R_X86_64_PC32:
18113 val -= (u64)loc;
18114+ pax_open_kernel();
18115 *(u32 *)loc = val;
18116+ pax_close_kernel();
18117+
18118 #if 0
18119 if ((s64)val != *(s32 *)loc)
18120 goto overflow;
18121diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18122index a0b2f84..875ab81 100644
18123--- a/arch/x86/kernel/nmi.c
18124+++ b/arch/x86/kernel/nmi.c
18125@@ -460,6 +460,17 @@ static inline void nmi_nesting_postprocess(void)
18126 dotraplinkage notrace __kprobes void
18127 do_nmi(struct pt_regs *regs, long error_code)
18128 {
18129+
18130+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18131+ if (!user_mode(regs)) {
18132+ unsigned long cs = regs->cs & 0xFFFF;
18133+ unsigned long ip = ktva_ktla(regs->ip);
18134+
18135+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18136+ regs->ip = ip;
18137+ }
18138+#endif
18139+
18140 nmi_nesting_preprocess(regs);
18141
18142 nmi_enter();
18143diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18144index 676b8c7..870ba04 100644
18145--- a/arch/x86/kernel/paravirt-spinlocks.c
18146+++ b/arch/x86/kernel/paravirt-spinlocks.c
18147@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18148 arch_spin_lock(lock);
18149 }
18150
18151-struct pv_lock_ops pv_lock_ops = {
18152+struct pv_lock_ops pv_lock_ops __read_only = {
18153 #ifdef CONFIG_SMP
18154 .spin_is_locked = __ticket_spin_is_locked,
18155 .spin_is_contended = __ticket_spin_is_contended,
18156diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18157index 9ce8859..b49bf51 100644
18158--- a/arch/x86/kernel/paravirt.c
18159+++ b/arch/x86/kernel/paravirt.c
18160@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18161 {
18162 return x;
18163 }
18164+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18165+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18166+#endif
18167
18168 void __init default_banner(void)
18169 {
18170@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18171 if (opfunc == NULL)
18172 /* If there's no function, patch it with a ud2a (BUG) */
18173 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18174- else if (opfunc == _paravirt_nop)
18175+ else if (opfunc == (void *)_paravirt_nop)
18176 /* If the operation is a nop, then nop the callsite */
18177 ret = paravirt_patch_nop();
18178
18179 /* identity functions just return their single argument */
18180- else if (opfunc == _paravirt_ident_32)
18181+ else if (opfunc == (void *)_paravirt_ident_32)
18182 ret = paravirt_patch_ident_32(insnbuf, len);
18183- else if (opfunc == _paravirt_ident_64)
18184+ else if (opfunc == (void *)_paravirt_ident_64)
18185 ret = paravirt_patch_ident_64(insnbuf, len);
18186+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18187+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18188+ ret = paravirt_patch_ident_64(insnbuf, len);
18189+#endif
18190
18191 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18192 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18193@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18194 if (insn_len > len || start == NULL)
18195 insn_len = len;
18196 else
18197- memcpy(insnbuf, start, insn_len);
18198+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18199
18200 return insn_len;
18201 }
18202@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18203 preempt_enable();
18204 }
18205
18206-struct pv_info pv_info = {
18207+struct pv_info pv_info __read_only = {
18208 .name = "bare hardware",
18209 .paravirt_enabled = 0,
18210 .kernel_rpl = 0,
18211@@ -315,16 +322,16 @@ struct pv_info pv_info = {
18212 #endif
18213 };
18214
18215-struct pv_init_ops pv_init_ops = {
18216+struct pv_init_ops pv_init_ops __read_only = {
18217 .patch = native_patch,
18218 };
18219
18220-struct pv_time_ops pv_time_ops = {
18221+struct pv_time_ops pv_time_ops __read_only = {
18222 .sched_clock = native_sched_clock,
18223 .steal_clock = native_steal_clock,
18224 };
18225
18226-struct pv_irq_ops pv_irq_ops = {
18227+struct pv_irq_ops pv_irq_ops __read_only = {
18228 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18229 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18230 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18231@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18232 #endif
18233 };
18234
18235-struct pv_cpu_ops pv_cpu_ops = {
18236+struct pv_cpu_ops pv_cpu_ops __read_only = {
18237 .cpuid = native_cpuid,
18238 .get_debugreg = native_get_debugreg,
18239 .set_debugreg = native_set_debugreg,
18240@@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18241 .end_context_switch = paravirt_nop,
18242 };
18243
18244-struct pv_apic_ops pv_apic_ops = {
18245+struct pv_apic_ops pv_apic_ops __read_only = {
18246 #ifdef CONFIG_X86_LOCAL_APIC
18247 .startup_ipi_hook = paravirt_nop,
18248 #endif
18249 };
18250
18251-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18252+#ifdef CONFIG_X86_32
18253+#ifdef CONFIG_X86_PAE
18254+/* 64-bit pagetable entries */
18255+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18256+#else
18257 /* 32-bit pagetable entries */
18258 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18259+#endif
18260 #else
18261 /* 64-bit pagetable entries */
18262 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18263 #endif
18264
18265-struct pv_mmu_ops pv_mmu_ops = {
18266+struct pv_mmu_ops pv_mmu_ops __read_only = {
18267
18268 .read_cr2 = native_read_cr2,
18269 .write_cr2 = native_write_cr2,
18270@@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18271 .make_pud = PTE_IDENT,
18272
18273 .set_pgd = native_set_pgd,
18274+ .set_pgd_batched = native_set_pgd_batched,
18275 #endif
18276 #endif /* PAGETABLE_LEVELS >= 3 */
18277
18278@@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18279 },
18280
18281 .set_fixmap = native_set_fixmap,
18282+
18283+#ifdef CONFIG_PAX_KERNEXEC
18284+ .pax_open_kernel = native_pax_open_kernel,
18285+ .pax_close_kernel = native_pax_close_kernel,
18286+#endif
18287+
18288 };
18289
18290 EXPORT_SYMBOL_GPL(pv_time_ops);
18291diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18292index 35ccf75..7a15747 100644
18293--- a/arch/x86/kernel/pci-iommu_table.c
18294+++ b/arch/x86/kernel/pci-iommu_table.c
18295@@ -2,7 +2,7 @@
18296 #include <asm/iommu_table.h>
18297 #include <linux/string.h>
18298 #include <linux/kallsyms.h>
18299-
18300+#include <linux/sched.h>
18301
18302 #define DEBUG 1
18303
18304diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18305index 735279e..5008677 100644
18306--- a/arch/x86/kernel/process.c
18307+++ b/arch/x86/kernel/process.c
18308@@ -34,7 +34,8 @@
18309 * section. Since TSS's are completely CPU-local, we want them
18310 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18311 */
18312-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18313+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18314+EXPORT_SYMBOL(init_tss);
18315
18316 #ifdef CONFIG_X86_64
18317 static DEFINE_PER_CPU(unsigned char, is_idle);
18318@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
18319 task_xstate_cachep =
18320 kmem_cache_create("task_xstate", xstate_size,
18321 __alignof__(union thread_xstate),
18322- SLAB_PANIC | SLAB_NOTRACK, NULL);
18323+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18324 }
18325
18326 static inline void drop_fpu(struct task_struct *tsk)
18327@@ -115,7 +116,7 @@ void exit_thread(void)
18328 unsigned long *bp = t->io_bitmap_ptr;
18329
18330 if (bp) {
18331- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18332+ struct tss_struct *tss = init_tss + get_cpu();
18333
18334 t->io_bitmap_ptr = NULL;
18335 clear_thread_flag(TIF_IO_BITMAP);
18336@@ -147,7 +148,7 @@ void show_regs_common(void)
18337
18338 printk(KERN_CONT "\n");
18339 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18340- current->pid, current->comm, print_tainted(),
18341+ task_pid_nr(current), current->comm, print_tainted(),
18342 init_utsname()->release,
18343 (int)strcspn(init_utsname()->version, " "),
18344 init_utsname()->version);
18345@@ -161,6 +162,9 @@ void flush_thread(void)
18346 {
18347 struct task_struct *tsk = current;
18348
18349+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18350+ loadsegment(gs, 0);
18351+#endif
18352 flush_ptrace_hw_breakpoint(tsk);
18353 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18354 drop_fpu(tsk);
18355@@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18356 regs.di = (unsigned long) arg;
18357
18358 #ifdef CONFIG_X86_32
18359- regs.ds = __USER_DS;
18360- regs.es = __USER_DS;
18361+ regs.ds = __KERNEL_DS;
18362+ regs.es = __KERNEL_DS;
18363 regs.fs = __KERNEL_PERCPU;
18364- regs.gs = __KERNEL_STACK_CANARY;
18365+ savesegment(gs, regs.gs);
18366 #else
18367 regs.ss = __KERNEL_DS;
18368 #endif
18369@@ -407,7 +411,7 @@ static void __exit_idle(void)
18370 void exit_idle(void)
18371 {
18372 /* idle loop has pid 0 */
18373- if (current->pid)
18374+ if (task_pid_nr(current))
18375 return;
18376 __exit_idle();
18377 }
18378@@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18379
18380 return ret;
18381 }
18382-void stop_this_cpu(void *dummy)
18383+__noreturn void stop_this_cpu(void *dummy)
18384 {
18385 local_irq_disable();
18386 /*
18387@@ -746,16 +750,37 @@ static int __init idle_setup(char *str)
18388 }
18389 early_param("idle", idle_setup);
18390
18391-unsigned long arch_align_stack(unsigned long sp)
18392+#ifdef CONFIG_PAX_RANDKSTACK
18393+void pax_randomize_kstack(struct pt_regs *regs)
18394 {
18395- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18396- sp -= get_random_int() % 8192;
18397- return sp & ~0xf;
18398-}
18399+ struct thread_struct *thread = &current->thread;
18400+ unsigned long time;
18401
18402-unsigned long arch_randomize_brk(struct mm_struct *mm)
18403-{
18404- unsigned long range_end = mm->brk + 0x02000000;
18405- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18406-}
18407+ if (!randomize_va_space)
18408+ return;
18409+
18410+ if (v8086_mode(regs))
18411+ return;
18412
18413+ rdtscl(time);
18414+
18415+ /* P4 seems to return a 0 LSB, ignore it */
18416+#ifdef CONFIG_MPENTIUM4
18417+ time &= 0x3EUL;
18418+ time <<= 2;
18419+#elif defined(CONFIG_X86_64)
18420+ time &= 0xFUL;
18421+ time <<= 4;
18422+#else
18423+ time &= 0x1FUL;
18424+ time <<= 3;
18425+#endif
18426+
18427+ thread->sp0 ^= time;
18428+ load_sp0(init_tss + smp_processor_id(), thread);
18429+
18430+#ifdef CONFIG_X86_64
18431+ this_cpu_write(kernel_stack, thread->sp0);
18432+#endif
18433+}
18434+#endif
18435diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18436index 516fa18..80bd9e6 100644
18437--- a/arch/x86/kernel/process_32.c
18438+++ b/arch/x86/kernel/process_32.c
18439@@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18440 unsigned long thread_saved_pc(struct task_struct *tsk)
18441 {
18442 return ((unsigned long *)tsk->thread.sp)[3];
18443+//XXX return tsk->thread.eip;
18444 }
18445
18446 void __show_regs(struct pt_regs *regs, int all)
18447@@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18448 unsigned long sp;
18449 unsigned short ss, gs;
18450
18451- if (user_mode_vm(regs)) {
18452+ if (user_mode(regs)) {
18453 sp = regs->sp;
18454 ss = regs->ss & 0xffff;
18455- gs = get_user_gs(regs);
18456 } else {
18457 sp = kernel_stack_pointer(regs);
18458 savesegment(ss, ss);
18459- savesegment(gs, gs);
18460 }
18461+ gs = get_user_gs(regs);
18462
18463 show_regs_common();
18464
18465@@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18466 struct task_struct *tsk;
18467 int err;
18468
18469- childregs = task_pt_regs(p);
18470+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18471 *childregs = *regs;
18472 childregs->ax = 0;
18473 childregs->sp = sp;
18474
18475 p->thread.sp = (unsigned long) childregs;
18476 p->thread.sp0 = (unsigned long) (childregs+1);
18477+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18478
18479 p->thread.ip = (unsigned long) ret_from_fork;
18480
18481@@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18482 struct thread_struct *prev = &prev_p->thread,
18483 *next = &next_p->thread;
18484 int cpu = smp_processor_id();
18485- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18486+ struct tss_struct *tss = init_tss + cpu;
18487 fpu_switch_t fpu;
18488
18489 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18490@@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18491 */
18492 lazy_save_gs(prev->gs);
18493
18494+#ifdef CONFIG_PAX_MEMORY_UDEREF
18495+ __set_fs(task_thread_info(next_p)->addr_limit);
18496+#endif
18497+
18498 /*
18499 * Load the per-thread Thread-Local Storage descriptor.
18500 */
18501@@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18502 */
18503 arch_end_context_switch(next_p);
18504
18505+ this_cpu_write(current_task, next_p);
18506+ this_cpu_write(current_tinfo, &next_p->tinfo);
18507+
18508 /*
18509 * Restore %gs if needed (which is common)
18510 */
18511@@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18512
18513 switch_fpu_finish(next_p, fpu);
18514
18515- this_cpu_write(current_task, next_p);
18516-
18517 return prev_p;
18518 }
18519
18520@@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18521 } while (count++ < 16);
18522 return 0;
18523 }
18524-
18525diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18526index 61cdf7f..797f06a 100644
18527--- a/arch/x86/kernel/process_64.c
18528+++ b/arch/x86/kernel/process_64.c
18529@@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18530 struct pt_regs *childregs;
18531 struct task_struct *me = current;
18532
18533- childregs = ((struct pt_regs *)
18534- (THREAD_SIZE + task_stack_page(p))) - 1;
18535+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18536 *childregs = *regs;
18537
18538 childregs->ax = 0;
18539@@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18540 p->thread.sp = (unsigned long) childregs;
18541 p->thread.sp0 = (unsigned long) (childregs+1);
18542 p->thread.usersp = me->thread.usersp;
18543+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18544
18545 set_tsk_thread_flag(p, TIF_FORK);
18546
18547@@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18548 struct thread_struct *prev = &prev_p->thread;
18549 struct thread_struct *next = &next_p->thread;
18550 int cpu = smp_processor_id();
18551- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18552+ struct tss_struct *tss = init_tss + cpu;
18553 unsigned fsindex, gsindex;
18554 fpu_switch_t fpu;
18555
18556@@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18557 prev->usersp = this_cpu_read(old_rsp);
18558 this_cpu_write(old_rsp, next->usersp);
18559 this_cpu_write(current_task, next_p);
18560+ this_cpu_write(current_tinfo, &next_p->tinfo);
18561
18562- this_cpu_write(kernel_stack,
18563- (unsigned long)task_stack_page(next_p) +
18564- THREAD_SIZE - KERNEL_STACK_OFFSET);
18565+ this_cpu_write(kernel_stack, next->sp0);
18566
18567 /*
18568 * Now maybe reload the debug registers and handle I/O bitmaps
18569@@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18570 if (!p || p == current || p->state == TASK_RUNNING)
18571 return 0;
18572 stack = (unsigned long)task_stack_page(p);
18573- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18574+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18575 return 0;
18576 fp = *(u64 *)(p->thread.sp);
18577 do {
18578- if (fp < (unsigned long)stack ||
18579- fp >= (unsigned long)stack+THREAD_SIZE)
18580+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18581 return 0;
18582 ip = *(u64 *)(fp+8);
18583 if (!in_sched_functions(ip))
18584diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18585index c4c6a5c..905f440 100644
18586--- a/arch/x86/kernel/ptrace.c
18587+++ b/arch/x86/kernel/ptrace.c
18588@@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18589 unsigned long addr, unsigned long data)
18590 {
18591 int ret;
18592- unsigned long __user *datap = (unsigned long __user *)data;
18593+ unsigned long __user *datap = (__force unsigned long __user *)data;
18594
18595 switch (request) {
18596 /* read the word at location addr in the USER area. */
18597@@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18598 if ((int) addr < 0)
18599 return -EIO;
18600 ret = do_get_thread_area(child, addr,
18601- (struct user_desc __user *)data);
18602+ (__force struct user_desc __user *) data);
18603 break;
18604
18605 case PTRACE_SET_THREAD_AREA:
18606 if ((int) addr < 0)
18607 return -EIO;
18608 ret = do_set_thread_area(child, addr,
18609- (struct user_desc __user *)data, 0);
18610+ (__force struct user_desc __user *) data, 0);
18611 break;
18612 #endif
18613
18614@@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18615 memset(info, 0, sizeof(*info));
18616 info->si_signo = SIGTRAP;
18617 info->si_code = si_code;
18618- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18619+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18620 }
18621
18622 void user_single_step_siginfo(struct task_struct *tsk,
18623@@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18624 # define IS_IA32 0
18625 #endif
18626
18627+#ifdef CONFIG_GRKERNSEC_SETXID
18628+extern void gr_delayed_cred_worker(void);
18629+#endif
18630+
18631 /*
18632 * We must return the syscall number to actually look up in the table.
18633 * This can be -1L to skip running any syscall at all.
18634@@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18635 {
18636 long ret = 0;
18637
18638+#ifdef CONFIG_GRKERNSEC_SETXID
18639+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18640+ gr_delayed_cred_worker();
18641+#endif
18642+
18643 /*
18644 * If we stepped into a sysenter/syscall insn, it trapped in
18645 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18646@@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18647 {
18648 bool step;
18649
18650+#ifdef CONFIG_GRKERNSEC_SETXID
18651+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18652+ gr_delayed_cred_worker();
18653+#endif
18654+
18655 audit_syscall_exit(regs);
18656
18657 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18658diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18659index 42eb330..139955c 100644
18660--- a/arch/x86/kernel/pvclock.c
18661+++ b/arch/x86/kernel/pvclock.c
18662@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18663 return pv_tsc_khz;
18664 }
18665
18666-static atomic64_t last_value = ATOMIC64_INIT(0);
18667+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18668
18669 void pvclock_resume(void)
18670 {
18671- atomic64_set(&last_value, 0);
18672+ atomic64_set_unchecked(&last_value, 0);
18673 }
18674
18675 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18676@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18677 * updating at the same time, and one of them could be slightly behind,
18678 * making the assumption that last_value always go forward fail to hold.
18679 */
18680- last = atomic64_read(&last_value);
18681+ last = atomic64_read_unchecked(&last_value);
18682 do {
18683 if (ret < last)
18684 return last;
18685- last = atomic64_cmpxchg(&last_value, last, ret);
18686+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18687 } while (unlikely(last != ret));
18688
18689 return ret;
18690diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18691index 5de92f1..2732385 100644
18692--- a/arch/x86/kernel/reboot.c
18693+++ b/arch/x86/kernel/reboot.c
18694@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18695 EXPORT_SYMBOL(pm_power_off);
18696
18697 static const struct desc_ptr no_idt = {};
18698-static int reboot_mode;
18699+static unsigned short reboot_mode;
18700 enum reboot_type reboot_type = BOOT_ACPI;
18701 int reboot_force;
18702
18703@@ -157,11 +157,15 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18704 return 0;
18705 }
18706
18707-void machine_real_restart(unsigned int type)
18708+__noreturn void machine_real_restart(unsigned int type)
18709 {
18710- void (*restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18711+ void (* restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18712 real_mode_header->machine_real_restart_asm;
18713
18714+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18715+ struct desc_struct *gdt;
18716+#endif
18717+
18718 local_irq_disable();
18719
18720 /*
18721@@ -189,10 +193,36 @@ void machine_real_restart(unsigned int type)
18722 * boot)". This seems like a fairly standard thing that gets set by
18723 * REBOOT.COM programs, and the previous reset routine did this
18724 * too. */
18725- *((unsigned short *)0x472) = reboot_mode;
18726+ *(unsigned short *)(__va(0x472)) = reboot_mode;
18727
18728 /* Jump to the identity-mapped low memory code */
18729+
18730+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18731+ gdt = get_cpu_gdt_table(smp_processor_id());
18732+ pax_open_kernel();
18733+#ifdef CONFIG_PAX_MEMORY_UDEREF
18734+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18735+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18736+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18737+#endif
18738+#ifdef CONFIG_PAX_KERNEXEC
18739+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18740+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18741+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18742+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18743+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18744+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18745+#endif
18746+ pax_close_kernel();
18747+#endif
18748+
18749+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18750+ asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18751+ unreachable();
18752+#else
18753 restart_lowmem(type);
18754+#endif
18755+
18756 }
18757 #ifdef CONFIG_APM_MODULE
18758 EXPORT_SYMBOL(machine_real_restart);
18759@@ -543,7 +573,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18760 * try to force a triple fault and then cycle between hitting the keyboard
18761 * controller and doing that
18762 */
18763-static void native_machine_emergency_restart(void)
18764+__noreturn static void native_machine_emergency_restart(void)
18765 {
18766 int i;
18767 int attempt = 0;
18768@@ -670,13 +700,13 @@ void native_machine_shutdown(void)
18769 #endif
18770 }
18771
18772-static void __machine_emergency_restart(int emergency)
18773+static __noreturn void __machine_emergency_restart(int emergency)
18774 {
18775 reboot_emergency = emergency;
18776 machine_ops.emergency_restart();
18777 }
18778
18779-static void native_machine_restart(char *__unused)
18780+static __noreturn void native_machine_restart(char *__unused)
18781 {
18782 printk("machine restart\n");
18783
18784@@ -685,7 +715,7 @@ static void native_machine_restart(char *__unused)
18785 __machine_emergency_restart(0);
18786 }
18787
18788-static void native_machine_halt(void)
18789+static __noreturn void native_machine_halt(void)
18790 {
18791 /* Stop other cpus and apics */
18792 machine_shutdown();
18793@@ -695,7 +725,7 @@ static void native_machine_halt(void)
18794 stop_this_cpu(NULL);
18795 }
18796
18797-static void native_machine_power_off(void)
18798+__noreturn static void native_machine_power_off(void)
18799 {
18800 if (pm_power_off) {
18801 if (!reboot_force)
18802@@ -704,6 +734,7 @@ static void native_machine_power_off(void)
18803 }
18804 /* A fallback in case there is no PM info available */
18805 tboot_shutdown(TB_SHUTDOWN_HALT);
18806+ unreachable();
18807 }
18808
18809 struct machine_ops machine_ops = {
18810diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18811index 7a6f3b3..bed145d7 100644
18812--- a/arch/x86/kernel/relocate_kernel_64.S
18813+++ b/arch/x86/kernel/relocate_kernel_64.S
18814@@ -11,6 +11,7 @@
18815 #include <asm/kexec.h>
18816 #include <asm/processor-flags.h>
18817 #include <asm/pgtable_types.h>
18818+#include <asm/alternative-asm.h>
18819
18820 /*
18821 * Must be relocatable PIC code callable as a C function
18822@@ -160,13 +161,14 @@ identity_mapped:
18823 xorq %rbp, %rbp
18824 xorq %r8, %r8
18825 xorq %r9, %r9
18826- xorq %r10, %r9
18827+ xorq %r10, %r10
18828 xorq %r11, %r11
18829 xorq %r12, %r12
18830 xorq %r13, %r13
18831 xorq %r14, %r14
18832 xorq %r15, %r15
18833
18834+ pax_force_retaddr 0, 1
18835 ret
18836
18837 1:
18838diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18839index 16be6dc..4686132 100644
18840--- a/arch/x86/kernel/setup.c
18841+++ b/arch/x86/kernel/setup.c
18842@@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
18843
18844 switch (data->type) {
18845 case SETUP_E820_EXT:
18846- parse_e820_ext(data);
18847+ parse_e820_ext((struct setup_data __force_kernel *)data);
18848 break;
18849 case SETUP_DTB:
18850 add_dtb(pa_data);
18851@@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
18852 * area (640->1Mb) as ram even though it is not.
18853 * take them out.
18854 */
18855- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18856+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18857 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18858 }
18859
18860@@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
18861
18862 if (!boot_params.hdr.root_flags)
18863 root_mountflags &= ~MS_RDONLY;
18864- init_mm.start_code = (unsigned long) _text;
18865- init_mm.end_code = (unsigned long) _etext;
18866+ init_mm.start_code = ktla_ktva((unsigned long) _text);
18867+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
18868 init_mm.end_data = (unsigned long) _edata;
18869 init_mm.brk = _brk_end;
18870
18871- code_resource.start = virt_to_phys(_text);
18872- code_resource.end = virt_to_phys(_etext)-1;
18873- data_resource.start = virt_to_phys(_etext);
18874+ code_resource.start = virt_to_phys(ktla_ktva(_text));
18875+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18876+ data_resource.start = virt_to_phys(_sdata);
18877 data_resource.end = virt_to_phys(_edata)-1;
18878 bss_resource.start = virt_to_phys(&__bss_start);
18879 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18880diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18881index 5a98aa2..2f9288d 100644
18882--- a/arch/x86/kernel/setup_percpu.c
18883+++ b/arch/x86/kernel/setup_percpu.c
18884@@ -21,19 +21,17 @@
18885 #include <asm/cpu.h>
18886 #include <asm/stackprotector.h>
18887
18888-DEFINE_PER_CPU(int, cpu_number);
18889+#ifdef CONFIG_SMP
18890+DEFINE_PER_CPU(unsigned int, cpu_number);
18891 EXPORT_PER_CPU_SYMBOL(cpu_number);
18892+#endif
18893
18894-#ifdef CONFIG_X86_64
18895 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18896-#else
18897-#define BOOT_PERCPU_OFFSET 0
18898-#endif
18899
18900 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18901 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18902
18903-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18904+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18905 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18906 };
18907 EXPORT_SYMBOL(__per_cpu_offset);
18908@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
18909 {
18910 #ifdef CONFIG_X86_32
18911 struct desc_struct gdt;
18912+ unsigned long base = per_cpu_offset(cpu);
18913
18914- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18915- 0x2 | DESCTYPE_S, 0x8);
18916- gdt.s = 1;
18917+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18918+ 0x83 | DESCTYPE_S, 0xC);
18919 write_gdt_entry(get_cpu_gdt_table(cpu),
18920 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18921 #endif
18922@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
18923 /* alrighty, percpu areas up and running */
18924 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18925 for_each_possible_cpu(cpu) {
18926+#ifdef CONFIG_CC_STACKPROTECTOR
18927+#ifdef CONFIG_X86_32
18928+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
18929+#endif
18930+#endif
18931 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18932 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18933 per_cpu(cpu_number, cpu) = cpu;
18934@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
18935 */
18936 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18937 #endif
18938+#ifdef CONFIG_CC_STACKPROTECTOR
18939+#ifdef CONFIG_X86_32
18940+ if (!cpu)
18941+ per_cpu(stack_canary.canary, cpu) = canary;
18942+#endif
18943+#endif
18944 /*
18945 * Up to this point, the boot CPU has been using .init.data
18946 * area. Reload any changed state for the boot CPU.
18947diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18948index 21af737..fb45e22 100644
18949--- a/arch/x86/kernel/signal.c
18950+++ b/arch/x86/kernel/signal.c
18951@@ -191,7 +191,7 @@ static unsigned long align_sigframe(unsigned long sp)
18952 * Align the stack pointer according to the i386 ABI,
18953 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18954 */
18955- sp = ((sp + 4) & -16ul) - 4;
18956+ sp = ((sp - 12) & -16ul) - 4;
18957 #else /* !CONFIG_X86_32 */
18958 sp = round_down(sp, 16) - 8;
18959 #endif
18960@@ -242,11 +242,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18961 * Return an always-bogus address instead so we will die with SIGSEGV.
18962 */
18963 if (onsigstack && !likely(on_sig_stack(sp)))
18964- return (void __user *)-1L;
18965+ return (__force void __user *)-1L;
18966
18967 /* save i387 state */
18968 if (used_math() && save_i387_xstate(*fpstate) < 0)
18969- return (void __user *)-1L;
18970+ return (__force void __user *)-1L;
18971
18972 return (void __user *)sp;
18973 }
18974@@ -301,9 +301,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18975 }
18976
18977 if (current->mm->context.vdso)
18978- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18979+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18980 else
18981- restorer = &frame->retcode;
18982+ restorer = (void __user *)&frame->retcode;
18983 if (ka->sa.sa_flags & SA_RESTORER)
18984 restorer = ka->sa.sa_restorer;
18985
18986@@ -317,7 +317,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18987 * reasons and because gdb uses it as a signature to notice
18988 * signal handler stack frames.
18989 */
18990- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
18991+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
18992
18993 if (err)
18994 return -EFAULT;
18995@@ -371,7 +371,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18996 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
18997
18998 /* Set up to return from userspace. */
18999- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19000+ if (current->mm->context.vdso)
19001+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19002+ else
19003+ restorer = (void __user *)&frame->retcode;
19004 if (ka->sa.sa_flags & SA_RESTORER)
19005 restorer = ka->sa.sa_restorer;
19006 put_user_ex(restorer, &frame->pretcode);
19007@@ -383,7 +386,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19008 * reasons and because gdb uses it as a signature to notice
19009 * signal handler stack frames.
19010 */
19011- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19012+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19013 } put_user_catch(err);
19014
19015 if (err)
19016diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19017index 7bd8a08..2659b5b 100644
19018--- a/arch/x86/kernel/smpboot.c
19019+++ b/arch/x86/kernel/smpboot.c
19020@@ -679,6 +679,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19021 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19022 (THREAD_SIZE + task_stack_page(idle))) - 1);
19023 per_cpu(current_task, cpu) = idle;
19024+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
19025
19026 #ifdef CONFIG_X86_32
19027 /* Stack for startup_32 can be just as for start_secondary onwards */
19028@@ -686,11 +687,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19029 #else
19030 clear_tsk_thread_flag(idle, TIF_FORK);
19031 initial_gs = per_cpu_offset(cpu);
19032- per_cpu(kernel_stack, cpu) =
19033- (unsigned long)task_stack_page(idle) -
19034- KERNEL_STACK_OFFSET + THREAD_SIZE;
19035+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19036 #endif
19037+
19038+ pax_open_kernel();
19039 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19040+ pax_close_kernel();
19041+
19042 initial_code = (unsigned long)start_secondary;
19043 stack_start = idle->thread.sp;
19044
19045@@ -826,6 +829,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19046
19047 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19048
19049+#ifdef CONFIG_PAX_PER_CPU_PGD
19050+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19051+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19052+ KERNEL_PGD_PTRS);
19053+#endif
19054+
19055 err = do_boot_cpu(apicid, cpu, tidle);
19056 if (err) {
19057 pr_debug("do_boot_cpu failed %d\n", err);
19058diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19059index c346d11..d43b163 100644
19060--- a/arch/x86/kernel/step.c
19061+++ b/arch/x86/kernel/step.c
19062@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19063 struct desc_struct *desc;
19064 unsigned long base;
19065
19066- seg &= ~7UL;
19067+ seg >>= 3;
19068
19069 mutex_lock(&child->mm->context.lock);
19070- if (unlikely((seg >> 3) >= child->mm->context.size))
19071+ if (unlikely(seg >= child->mm->context.size))
19072 addr = -1L; /* bogus selector, access would fault */
19073 else {
19074 desc = child->mm->context.ldt + seg;
19075@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19076 addr += base;
19077 }
19078 mutex_unlock(&child->mm->context.lock);
19079- }
19080+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19081+ addr = ktla_ktva(addr);
19082
19083 return addr;
19084 }
19085@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19086 unsigned char opcode[15];
19087 unsigned long addr = convert_ip_to_linear(child, regs);
19088
19089+ if (addr == -EINVAL)
19090+ return 0;
19091+
19092 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19093 for (i = 0; i < copied; i++) {
19094 switch (opcode[i]) {
19095diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19096index 0b0cb5f..db6b9ed 100644
19097--- a/arch/x86/kernel/sys_i386_32.c
19098+++ b/arch/x86/kernel/sys_i386_32.c
19099@@ -24,17 +24,224 @@
19100
19101 #include <asm/syscalls.h>
19102
19103-/*
19104- * Do a system call from kernel instead of calling sys_execve so we
19105- * end up with proper pt_regs.
19106- */
19107-int kernel_execve(const char *filename,
19108- const char *const argv[],
19109- const char *const envp[])
19110+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19111 {
19112- long __res;
19113- asm volatile ("int $0x80"
19114- : "=a" (__res)
19115- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19116- return __res;
19117+ unsigned long pax_task_size = TASK_SIZE;
19118+
19119+#ifdef CONFIG_PAX_SEGMEXEC
19120+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19121+ pax_task_size = SEGMEXEC_TASK_SIZE;
19122+#endif
19123+
19124+ if (len > pax_task_size || addr > pax_task_size - len)
19125+ return -EINVAL;
19126+
19127+ return 0;
19128+}
19129+
19130+unsigned long
19131+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19132+ unsigned long len, unsigned long pgoff, unsigned long flags)
19133+{
19134+ struct mm_struct *mm = current->mm;
19135+ struct vm_area_struct *vma;
19136+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19137+
19138+#ifdef CONFIG_PAX_SEGMEXEC
19139+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19140+ pax_task_size = SEGMEXEC_TASK_SIZE;
19141+#endif
19142+
19143+ pax_task_size -= PAGE_SIZE;
19144+
19145+ if (len > pax_task_size)
19146+ return -ENOMEM;
19147+
19148+ if (flags & MAP_FIXED)
19149+ return addr;
19150+
19151+#ifdef CONFIG_PAX_RANDMMAP
19152+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19153+#endif
19154+
19155+ if (addr) {
19156+ addr = PAGE_ALIGN(addr);
19157+ if (pax_task_size - len >= addr) {
19158+ vma = find_vma(mm, addr);
19159+ if (check_heap_stack_gap(vma, addr, len))
19160+ return addr;
19161+ }
19162+ }
19163+ if (len > mm->cached_hole_size) {
19164+ start_addr = addr = mm->free_area_cache;
19165+ } else {
19166+ start_addr = addr = mm->mmap_base;
19167+ mm->cached_hole_size = 0;
19168+ }
19169+
19170+#ifdef CONFIG_PAX_PAGEEXEC
19171+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19172+ start_addr = 0x00110000UL;
19173+
19174+#ifdef CONFIG_PAX_RANDMMAP
19175+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19176+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19177+#endif
19178+
19179+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19180+ start_addr = addr = mm->mmap_base;
19181+ else
19182+ addr = start_addr;
19183+ }
19184+#endif
19185+
19186+full_search:
19187+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19188+ /* At this point: (!vma || addr < vma->vm_end). */
19189+ if (pax_task_size - len < addr) {
19190+ /*
19191+ * Start a new search - just in case we missed
19192+ * some holes.
19193+ */
19194+ if (start_addr != mm->mmap_base) {
19195+ start_addr = addr = mm->mmap_base;
19196+ mm->cached_hole_size = 0;
19197+ goto full_search;
19198+ }
19199+ return -ENOMEM;
19200+ }
19201+ if (check_heap_stack_gap(vma, addr, len))
19202+ break;
19203+ if (addr + mm->cached_hole_size < vma->vm_start)
19204+ mm->cached_hole_size = vma->vm_start - addr;
19205+ addr = vma->vm_end;
19206+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19207+ start_addr = addr = mm->mmap_base;
19208+ mm->cached_hole_size = 0;
19209+ goto full_search;
19210+ }
19211+ }
19212+
19213+ /*
19214+ * Remember the place where we stopped the search:
19215+ */
19216+ mm->free_area_cache = addr + len;
19217+ return addr;
19218+}
19219+
19220+unsigned long
19221+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19222+ const unsigned long len, const unsigned long pgoff,
19223+ const unsigned long flags)
19224+{
19225+ struct vm_area_struct *vma;
19226+ struct mm_struct *mm = current->mm;
19227+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19228+
19229+#ifdef CONFIG_PAX_SEGMEXEC
19230+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19231+ pax_task_size = SEGMEXEC_TASK_SIZE;
19232+#endif
19233+
19234+ pax_task_size -= PAGE_SIZE;
19235+
19236+ /* requested length too big for entire address space */
19237+ if (len > pax_task_size)
19238+ return -ENOMEM;
19239+
19240+ if (flags & MAP_FIXED)
19241+ return addr;
19242+
19243+#ifdef CONFIG_PAX_PAGEEXEC
19244+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19245+ goto bottomup;
19246+#endif
19247+
19248+#ifdef CONFIG_PAX_RANDMMAP
19249+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19250+#endif
19251+
19252+ /* requesting a specific address */
19253+ if (addr) {
19254+ addr = PAGE_ALIGN(addr);
19255+ if (pax_task_size - len >= addr) {
19256+ vma = find_vma(mm, addr);
19257+ if (check_heap_stack_gap(vma, addr, len))
19258+ return addr;
19259+ }
19260+ }
19261+
19262+ /* check if free_area_cache is useful for us */
19263+ if (len <= mm->cached_hole_size) {
19264+ mm->cached_hole_size = 0;
19265+ mm->free_area_cache = mm->mmap_base;
19266+ }
19267+
19268+ /* either no address requested or can't fit in requested address hole */
19269+ addr = mm->free_area_cache;
19270+
19271+ /* make sure it can fit in the remaining address space */
19272+ if (addr > len) {
19273+ vma = find_vma(mm, addr-len);
19274+ if (check_heap_stack_gap(vma, addr - len, len))
19275+ /* remember the address as a hint for next time */
19276+ return (mm->free_area_cache = addr-len);
19277+ }
19278+
19279+ if (mm->mmap_base < len)
19280+ goto bottomup;
19281+
19282+ addr = mm->mmap_base-len;
19283+
19284+ do {
19285+ /*
19286+ * Lookup failure means no vma is above this address,
19287+ * else if new region fits below vma->vm_start,
19288+ * return with success:
19289+ */
19290+ vma = find_vma(mm, addr);
19291+ if (check_heap_stack_gap(vma, addr, len))
19292+ /* remember the address as a hint for next time */
19293+ return (mm->free_area_cache = addr);
19294+
19295+ /* remember the largest hole we saw so far */
19296+ if (addr + mm->cached_hole_size < vma->vm_start)
19297+ mm->cached_hole_size = vma->vm_start - addr;
19298+
19299+ /* try just below the current vma->vm_start */
19300+ addr = skip_heap_stack_gap(vma, len);
19301+ } while (!IS_ERR_VALUE(addr));
19302+
19303+bottomup:
19304+ /*
19305+ * A failed mmap() very likely causes application failure,
19306+ * so fall back to the bottom-up function here. This scenario
19307+ * can happen with large stack limits and large mmap()
19308+ * allocations.
19309+ */
19310+
19311+#ifdef CONFIG_PAX_SEGMEXEC
19312+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19313+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19314+ else
19315+#endif
19316+
19317+ mm->mmap_base = TASK_UNMAPPED_BASE;
19318+
19319+#ifdef CONFIG_PAX_RANDMMAP
19320+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19321+ mm->mmap_base += mm->delta_mmap;
19322+#endif
19323+
19324+ mm->free_area_cache = mm->mmap_base;
19325+ mm->cached_hole_size = ~0UL;
19326+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19327+ /*
19328+ * Restore the topdown base:
19329+ */
19330+ mm->mmap_base = base;
19331+ mm->free_area_cache = base;
19332+ mm->cached_hole_size = ~0UL;
19333+
19334+ return addr;
19335 }
19336diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19337index b4d3c39..82bb73b 100644
19338--- a/arch/x86/kernel/sys_x86_64.c
19339+++ b/arch/x86/kernel/sys_x86_64.c
19340@@ -95,8 +95,8 @@ out:
19341 return error;
19342 }
19343
19344-static void find_start_end(unsigned long flags, unsigned long *begin,
19345- unsigned long *end)
19346+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19347+ unsigned long *begin, unsigned long *end)
19348 {
19349 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19350 unsigned long new_begin;
19351@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19352 *begin = new_begin;
19353 }
19354 } else {
19355- *begin = TASK_UNMAPPED_BASE;
19356+ *begin = mm->mmap_base;
19357 *end = TASK_SIZE;
19358 }
19359 }
19360@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19361 if (flags & MAP_FIXED)
19362 return addr;
19363
19364- find_start_end(flags, &begin, &end);
19365+ find_start_end(mm, flags, &begin, &end);
19366
19367 if (len > end)
19368 return -ENOMEM;
19369
19370+#ifdef CONFIG_PAX_RANDMMAP
19371+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19372+#endif
19373+
19374 if (addr) {
19375 addr = PAGE_ALIGN(addr);
19376 vma = find_vma(mm, addr);
19377- if (end - len >= addr &&
19378- (!vma || addr + len <= vma->vm_start))
19379+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19380 return addr;
19381 }
19382 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19383@@ -172,7 +175,7 @@ full_search:
19384 }
19385 return -ENOMEM;
19386 }
19387- if (!vma || addr + len <= vma->vm_start) {
19388+ if (check_heap_stack_gap(vma, addr, len)) {
19389 /*
19390 * Remember the place where we stopped the search:
19391 */
19392@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19393 {
19394 struct vm_area_struct *vma;
19395 struct mm_struct *mm = current->mm;
19396- unsigned long addr = addr0, start_addr;
19397+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19398
19399 /* requested length too big for entire address space */
19400 if (len > TASK_SIZE)
19401@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19402 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19403 goto bottomup;
19404
19405+#ifdef CONFIG_PAX_RANDMMAP
19406+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19407+#endif
19408+
19409 /* requesting a specific address */
19410 if (addr) {
19411 addr = PAGE_ALIGN(addr);
19412- vma = find_vma(mm, addr);
19413- if (TASK_SIZE - len >= addr &&
19414- (!vma || addr + len <= vma->vm_start))
19415- return addr;
19416+ if (TASK_SIZE - len >= addr) {
19417+ vma = find_vma(mm, addr);
19418+ if (check_heap_stack_gap(vma, addr, len))
19419+ return addr;
19420+ }
19421 }
19422
19423 /* check if free_area_cache is useful for us */
19424@@ -240,7 +248,7 @@ try_again:
19425 * return with success:
19426 */
19427 vma = find_vma(mm, addr);
19428- if (!vma || addr+len <= vma->vm_start)
19429+ if (check_heap_stack_gap(vma, addr, len))
19430 /* remember the address as a hint for next time */
19431 return mm->free_area_cache = addr;
19432
19433@@ -249,8 +257,8 @@ try_again:
19434 mm->cached_hole_size = vma->vm_start - addr;
19435
19436 /* try just below the current vma->vm_start */
19437- addr = vma->vm_start-len;
19438- } while (len < vma->vm_start);
19439+ addr = skip_heap_stack_gap(vma, len);
19440+ } while (!IS_ERR_VALUE(addr));
19441
19442 fail:
19443 /*
19444@@ -270,13 +278,21 @@ bottomup:
19445 * can happen with large stack limits and large mmap()
19446 * allocations.
19447 */
19448+ mm->mmap_base = TASK_UNMAPPED_BASE;
19449+
19450+#ifdef CONFIG_PAX_RANDMMAP
19451+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19452+ mm->mmap_base += mm->delta_mmap;
19453+#endif
19454+
19455+ mm->free_area_cache = mm->mmap_base;
19456 mm->cached_hole_size = ~0UL;
19457- mm->free_area_cache = TASK_UNMAPPED_BASE;
19458 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19459 /*
19460 * Restore the topdown base:
19461 */
19462- mm->free_area_cache = mm->mmap_base;
19463+ mm->mmap_base = base;
19464+ mm->free_area_cache = base;
19465 mm->cached_hole_size = ~0UL;
19466
19467 return addr;
19468diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19469index f84fe00..93fe08f 100644
19470--- a/arch/x86/kernel/tboot.c
19471+++ b/arch/x86/kernel/tboot.c
19472@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19473
19474 void tboot_shutdown(u32 shutdown_type)
19475 {
19476- void (*shutdown)(void);
19477+ void (* __noreturn shutdown)(void);
19478
19479 if (!tboot_enabled())
19480 return;
19481@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19482
19483 switch_to_tboot_pt();
19484
19485- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19486+ shutdown = (void *)tboot->shutdown_entry;
19487 shutdown();
19488
19489 /* should not reach here */
19490@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19491 return 0;
19492 }
19493
19494-static atomic_t ap_wfs_count;
19495+static atomic_unchecked_t ap_wfs_count;
19496
19497 static int tboot_wait_for_aps(int num_aps)
19498 {
19499@@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19500 {
19501 switch (action) {
19502 case CPU_DYING:
19503- atomic_inc(&ap_wfs_count);
19504+ atomic_inc_unchecked(&ap_wfs_count);
19505 if (num_online_cpus() == 1)
19506- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19507+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19508 return NOTIFY_BAD;
19509 break;
19510 }
19511@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19512
19513 tboot_create_trampoline();
19514
19515- atomic_set(&ap_wfs_count, 0);
19516+ atomic_set_unchecked(&ap_wfs_count, 0);
19517 register_hotcpu_notifier(&tboot_cpu_notifier);
19518
19519 acpi_os_set_prepare_sleep(&tboot_sleep);
19520diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19521index 24d3c91..d06b473 100644
19522--- a/arch/x86/kernel/time.c
19523+++ b/arch/x86/kernel/time.c
19524@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19525 {
19526 unsigned long pc = instruction_pointer(regs);
19527
19528- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19529+ if (!user_mode(regs) && in_lock_functions(pc)) {
19530 #ifdef CONFIG_FRAME_POINTER
19531- return *(unsigned long *)(regs->bp + sizeof(long));
19532+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19533 #else
19534 unsigned long *sp =
19535 (unsigned long *)kernel_stack_pointer(regs);
19536@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19537 * or above a saved flags. Eflags has bits 22-31 zero,
19538 * kernel addresses don't.
19539 */
19540+
19541+#ifdef CONFIG_PAX_KERNEXEC
19542+ return ktla_ktva(sp[0]);
19543+#else
19544 if (sp[0] >> 22)
19545 return sp[0];
19546 if (sp[1] >> 22)
19547 return sp[1];
19548 #endif
19549+
19550+#endif
19551 }
19552 return pc;
19553 }
19554diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19555index 9d9d2f9..ed344e4 100644
19556--- a/arch/x86/kernel/tls.c
19557+++ b/arch/x86/kernel/tls.c
19558@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19559 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19560 return -EINVAL;
19561
19562+#ifdef CONFIG_PAX_SEGMEXEC
19563+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19564+ return -EINVAL;
19565+#endif
19566+
19567 set_tls_desc(p, idx, &info, 1);
19568
19569 return 0;
19570diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19571index 05b31d9..501d3ba 100644
19572--- a/arch/x86/kernel/traps.c
19573+++ b/arch/x86/kernel/traps.c
19574@@ -67,12 +67,6 @@ asmlinkage int system_call(void);
19575
19576 /* Do we ignore FPU interrupts ? */
19577 char ignore_fpu_irq;
19578-
19579-/*
19580- * The IDT has to be page-aligned to simplify the Pentium
19581- * F0 0F bug workaround.
19582- */
19583-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19584 #endif
19585
19586 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19587@@ -105,13 +99,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19588 }
19589
19590 static void __kprobes
19591-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19592+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19593 long error_code, siginfo_t *info)
19594 {
19595 struct task_struct *tsk = current;
19596
19597 #ifdef CONFIG_X86_32
19598- if (regs->flags & X86_VM_MASK) {
19599+ if (v8086_mode(regs)) {
19600 /*
19601 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19602 * On nmi (interrupt 2), do_trap should not be called.
19603@@ -122,7 +116,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19604 }
19605 #endif
19606
19607- if (!user_mode(regs))
19608+ if (!user_mode_novm(regs))
19609 goto kernel_trap;
19610
19611 #ifdef CONFIG_X86_32
19612@@ -145,7 +139,7 @@ trap_signal:
19613 printk_ratelimit()) {
19614 printk(KERN_INFO
19615 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19616- tsk->comm, tsk->pid, str,
19617+ tsk->comm, task_pid_nr(tsk), str,
19618 regs->ip, regs->sp, error_code);
19619 print_vma_addr(" in ", regs->ip);
19620 printk("\n");
19621@@ -162,8 +156,20 @@ kernel_trap:
19622 if (!fixup_exception(regs)) {
19623 tsk->thread.error_code = error_code;
19624 tsk->thread.trap_nr = trapnr;
19625+
19626+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19627+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19628+ str = "PAX: suspicious stack segment fault";
19629+#endif
19630+
19631 die(str, regs, error_code);
19632 }
19633+
19634+#ifdef CONFIG_PAX_REFCOUNT
19635+ if (trapnr == 4)
19636+ pax_report_refcount_overflow(regs);
19637+#endif
19638+
19639 return;
19640
19641 #ifdef CONFIG_X86_32
19642@@ -256,14 +262,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19643 conditional_sti(regs);
19644
19645 #ifdef CONFIG_X86_32
19646- if (regs->flags & X86_VM_MASK)
19647+ if (v8086_mode(regs))
19648 goto gp_in_vm86;
19649 #endif
19650
19651 tsk = current;
19652- if (!user_mode(regs))
19653+ if (!user_mode_novm(regs))
19654 goto gp_in_kernel;
19655
19656+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19657+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19658+ struct mm_struct *mm = tsk->mm;
19659+ unsigned long limit;
19660+
19661+ down_write(&mm->mmap_sem);
19662+ limit = mm->context.user_cs_limit;
19663+ if (limit < TASK_SIZE) {
19664+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19665+ up_write(&mm->mmap_sem);
19666+ return;
19667+ }
19668+ up_write(&mm->mmap_sem);
19669+ }
19670+#endif
19671+
19672 tsk->thread.error_code = error_code;
19673 tsk->thread.trap_nr = X86_TRAP_GP;
19674
19675@@ -296,6 +318,13 @@ gp_in_kernel:
19676 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19677 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19678 return;
19679+
19680+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19681+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19682+ die("PAX: suspicious general protection fault", regs, error_code);
19683+ else
19684+#endif
19685+
19686 die("general protection fault", regs, error_code);
19687 }
19688
19689@@ -431,7 +460,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19690 /* It's safe to allow irq's after DR6 has been saved */
19691 preempt_conditional_sti(regs);
19692
19693- if (regs->flags & X86_VM_MASK) {
19694+ if (v8086_mode(regs)) {
19695 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19696 X86_TRAP_DB);
19697 preempt_conditional_cli(regs);
19698@@ -446,7 +475,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19699 * We already checked v86 mode above, so we can check for kernel mode
19700 * by just checking the CPL of CS.
19701 */
19702- if ((dr6 & DR_STEP) && !user_mode(regs)) {
19703+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19704 tsk->thread.debugreg6 &= ~DR_STEP;
19705 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19706 regs->flags &= ~X86_EFLAGS_TF;
19707@@ -477,7 +506,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19708 return;
19709 conditional_sti(regs);
19710
19711- if (!user_mode_vm(regs))
19712+ if (!user_mode(regs))
19713 {
19714 if (!fixup_exception(regs)) {
19715 task->thread.error_code = error_code;
19716diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19717index dc4e910..c9dedab 100644
19718--- a/arch/x86/kernel/uprobes.c
19719+++ b/arch/x86/kernel/uprobes.c
19720@@ -606,7 +606,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19721 int ret = NOTIFY_DONE;
19722
19723 /* We are only interested in userspace traps */
19724- if (regs && !user_mode_vm(regs))
19725+ if (regs && !user_mode(regs))
19726 return NOTIFY_DONE;
19727
19728 switch (val) {
19729diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19730index b9242ba..50c5edd 100644
19731--- a/arch/x86/kernel/verify_cpu.S
19732+++ b/arch/x86/kernel/verify_cpu.S
19733@@ -20,6 +20,7 @@
19734 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19735 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19736 * arch/x86/kernel/head_32.S: processor startup
19737+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19738 *
19739 * verify_cpu, returns the status of longmode and SSE in register %eax.
19740 * 0: Success 1: Failure
19741diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19742index 255f58a..5e91150 100644
19743--- a/arch/x86/kernel/vm86_32.c
19744+++ b/arch/x86/kernel/vm86_32.c
19745@@ -41,6 +41,7 @@
19746 #include <linux/ptrace.h>
19747 #include <linux/audit.h>
19748 #include <linux/stddef.h>
19749+#include <linux/grsecurity.h>
19750
19751 #include <asm/uaccess.h>
19752 #include <asm/io.h>
19753@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19754 do_exit(SIGSEGV);
19755 }
19756
19757- tss = &per_cpu(init_tss, get_cpu());
19758+ tss = init_tss + get_cpu();
19759 current->thread.sp0 = current->thread.saved_sp0;
19760 current->thread.sysenter_cs = __KERNEL_CS;
19761 load_sp0(tss, &current->thread);
19762@@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19763 struct task_struct *tsk;
19764 int tmp, ret = -EPERM;
19765
19766+#ifdef CONFIG_GRKERNSEC_VM86
19767+ if (!capable(CAP_SYS_RAWIO)) {
19768+ gr_handle_vm86();
19769+ goto out;
19770+ }
19771+#endif
19772+
19773 tsk = current;
19774 if (tsk->thread.saved_sp0)
19775 goto out;
19776@@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19777 int tmp, ret;
19778 struct vm86plus_struct __user *v86;
19779
19780+#ifdef CONFIG_GRKERNSEC_VM86
19781+ if (!capable(CAP_SYS_RAWIO)) {
19782+ gr_handle_vm86();
19783+ ret = -EPERM;
19784+ goto out;
19785+ }
19786+#endif
19787+
19788 tsk = current;
19789 switch (cmd) {
19790 case VM86_REQUEST_IRQ:
19791@@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19792 tsk->thread.saved_fs = info->regs32->fs;
19793 tsk->thread.saved_gs = get_user_gs(info->regs32);
19794
19795- tss = &per_cpu(init_tss, get_cpu());
19796+ tss = init_tss + get_cpu();
19797 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19798 if (cpu_has_sep)
19799 tsk->thread.sysenter_cs = 0;
19800@@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19801 goto cannot_handle;
19802 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19803 goto cannot_handle;
19804- intr_ptr = (unsigned long __user *) (i << 2);
19805+ intr_ptr = (__force unsigned long __user *) (i << 2);
19806 if (get_user(segoffs, intr_ptr))
19807 goto cannot_handle;
19808 if ((segoffs >> 16) == BIOSSEG)
19809diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19810index 22a1530..8fbaaad 100644
19811--- a/arch/x86/kernel/vmlinux.lds.S
19812+++ b/arch/x86/kernel/vmlinux.lds.S
19813@@ -26,6 +26,13 @@
19814 #include <asm/page_types.h>
19815 #include <asm/cache.h>
19816 #include <asm/boot.h>
19817+#include <asm/segment.h>
19818+
19819+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19820+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19821+#else
19822+#define __KERNEL_TEXT_OFFSET 0
19823+#endif
19824
19825 #undef i386 /* in case the preprocessor is a 32bit one */
19826
19827@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19828
19829 PHDRS {
19830 text PT_LOAD FLAGS(5); /* R_E */
19831+#ifdef CONFIG_X86_32
19832+ module PT_LOAD FLAGS(5); /* R_E */
19833+#endif
19834+#ifdef CONFIG_XEN
19835+ rodata PT_LOAD FLAGS(5); /* R_E */
19836+#else
19837+ rodata PT_LOAD FLAGS(4); /* R__ */
19838+#endif
19839 data PT_LOAD FLAGS(6); /* RW_ */
19840-#ifdef CONFIG_X86_64
19841+ init.begin PT_LOAD FLAGS(6); /* RW_ */
19842 #ifdef CONFIG_SMP
19843 percpu PT_LOAD FLAGS(6); /* RW_ */
19844 #endif
19845+ text.init PT_LOAD FLAGS(5); /* R_E */
19846+ text.exit PT_LOAD FLAGS(5); /* R_E */
19847 init PT_LOAD FLAGS(7); /* RWE */
19848-#endif
19849 note PT_NOTE FLAGS(0); /* ___ */
19850 }
19851
19852 SECTIONS
19853 {
19854 #ifdef CONFIG_X86_32
19855- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19856- phys_startup_32 = startup_32 - LOAD_OFFSET;
19857+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19858 #else
19859- . = __START_KERNEL;
19860- phys_startup_64 = startup_64 - LOAD_OFFSET;
19861+ . = __START_KERNEL;
19862 #endif
19863
19864 /* Text and read-only data */
19865- .text : AT(ADDR(.text) - LOAD_OFFSET) {
19866- _text = .;
19867+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19868 /* bootstrapping code */
19869+#ifdef CONFIG_X86_32
19870+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19871+#else
19872+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19873+#endif
19874+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19875+ _text = .;
19876 HEAD_TEXT
19877 #ifdef CONFIG_X86_32
19878 . = ALIGN(PAGE_SIZE);
19879@@ -108,13 +128,48 @@ SECTIONS
19880 IRQENTRY_TEXT
19881 *(.fixup)
19882 *(.gnu.warning)
19883- /* End of text section */
19884- _etext = .;
19885 } :text = 0x9090
19886
19887- NOTES :text :note
19888+ . += __KERNEL_TEXT_OFFSET;
19889
19890- EXCEPTION_TABLE(16) :text = 0x9090
19891+#ifdef CONFIG_X86_32
19892+ . = ALIGN(PAGE_SIZE);
19893+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19894+
19895+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19896+ MODULES_EXEC_VADDR = .;
19897+ BYTE(0)
19898+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19899+ . = ALIGN(HPAGE_SIZE) - 1;
19900+ MODULES_EXEC_END = .;
19901+#endif
19902+
19903+ } :module
19904+#endif
19905+
19906+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19907+ /* End of text section */
19908+ BYTE(0)
19909+ _etext = . - __KERNEL_TEXT_OFFSET;
19910+ }
19911+
19912+#ifdef CONFIG_X86_32
19913+ . = ALIGN(PAGE_SIZE);
19914+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19915+ *(.idt)
19916+ . = ALIGN(PAGE_SIZE);
19917+ *(.empty_zero_page)
19918+ *(.initial_pg_fixmap)
19919+ *(.initial_pg_pmd)
19920+ *(.initial_page_table)
19921+ *(.swapper_pg_dir)
19922+ } :rodata
19923+#endif
19924+
19925+ . = ALIGN(PAGE_SIZE);
19926+ NOTES :rodata :note
19927+
19928+ EXCEPTION_TABLE(16) :rodata
19929
19930 #if defined(CONFIG_DEBUG_RODATA)
19931 /* .text should occupy whole number of pages */
19932@@ -126,16 +181,20 @@ SECTIONS
19933
19934 /* Data */
19935 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19936+
19937+#ifdef CONFIG_PAX_KERNEXEC
19938+ . = ALIGN(HPAGE_SIZE);
19939+#else
19940+ . = ALIGN(PAGE_SIZE);
19941+#endif
19942+
19943 /* Start of data section */
19944 _sdata = .;
19945
19946 /* init_task */
19947 INIT_TASK_DATA(THREAD_SIZE)
19948
19949-#ifdef CONFIG_X86_32
19950- /* 32 bit has nosave before _edata */
19951 NOSAVE_DATA
19952-#endif
19953
19954 PAGE_ALIGNED_DATA(PAGE_SIZE)
19955
19956@@ -176,12 +235,19 @@ SECTIONS
19957 #endif /* CONFIG_X86_64 */
19958
19959 /* Init code and data - will be freed after init */
19960- . = ALIGN(PAGE_SIZE);
19961 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19962+ BYTE(0)
19963+
19964+#ifdef CONFIG_PAX_KERNEXEC
19965+ . = ALIGN(HPAGE_SIZE);
19966+#else
19967+ . = ALIGN(PAGE_SIZE);
19968+#endif
19969+
19970 __init_begin = .; /* paired with __init_end */
19971- }
19972+ } :init.begin
19973
19974-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19975+#ifdef CONFIG_SMP
19976 /*
19977 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19978 * output PHDR, so the next output section - .init.text - should
19979@@ -190,12 +256,27 @@ SECTIONS
19980 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
19981 #endif
19982
19983- INIT_TEXT_SECTION(PAGE_SIZE)
19984-#ifdef CONFIG_X86_64
19985- :init
19986-#endif
19987+ . = ALIGN(PAGE_SIZE);
19988+ init_begin = .;
19989+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
19990+ VMLINUX_SYMBOL(_sinittext) = .;
19991+ INIT_TEXT
19992+ VMLINUX_SYMBOL(_einittext) = .;
19993+ . = ALIGN(PAGE_SIZE);
19994+ } :text.init
19995
19996- INIT_DATA_SECTION(16)
19997+ /*
19998+ * .exit.text is discard at runtime, not link time, to deal with
19999+ * references from .altinstructions and .eh_frame
20000+ */
20001+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20002+ EXIT_TEXT
20003+ . = ALIGN(16);
20004+ } :text.exit
20005+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20006+
20007+ . = ALIGN(PAGE_SIZE);
20008+ INIT_DATA_SECTION(16) :init
20009
20010 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20011 __x86_cpu_dev_start = .;
20012@@ -257,19 +338,12 @@ SECTIONS
20013 }
20014
20015 . = ALIGN(8);
20016- /*
20017- * .exit.text is discard at runtime, not link time, to deal with
20018- * references from .altinstructions and .eh_frame
20019- */
20020- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20021- EXIT_TEXT
20022- }
20023
20024 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20025 EXIT_DATA
20026 }
20027
20028-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20029+#ifndef CONFIG_SMP
20030 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20031 #endif
20032
20033@@ -288,16 +362,10 @@ SECTIONS
20034 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20035 __smp_locks = .;
20036 *(.smp_locks)
20037- . = ALIGN(PAGE_SIZE);
20038 __smp_locks_end = .;
20039+ . = ALIGN(PAGE_SIZE);
20040 }
20041
20042-#ifdef CONFIG_X86_64
20043- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20044- NOSAVE_DATA
20045- }
20046-#endif
20047-
20048 /* BSS */
20049 . = ALIGN(PAGE_SIZE);
20050 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20051@@ -313,6 +381,7 @@ SECTIONS
20052 __brk_base = .;
20053 . += 64 * 1024; /* 64k alignment slop space */
20054 *(.brk_reservation) /* areas brk users have reserved */
20055+ . = ALIGN(HPAGE_SIZE);
20056 __brk_limit = .;
20057 }
20058
20059@@ -339,13 +408,12 @@ SECTIONS
20060 * for the boot processor.
20061 */
20062 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20063-INIT_PER_CPU(gdt_page);
20064 INIT_PER_CPU(irq_stack_union);
20065
20066 /*
20067 * Build-time check on the image size:
20068 */
20069-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20070+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20071 "kernel image bigger than KERNEL_IMAGE_SIZE");
20072
20073 #ifdef CONFIG_SMP
20074diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20075index 5db36ca..2938af9 100644
20076--- a/arch/x86/kernel/vsyscall_64.c
20077+++ b/arch/x86/kernel/vsyscall_64.c
20078@@ -54,15 +54,13 @@
20079 DEFINE_VVAR(int, vgetcpu_mode);
20080 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20081
20082-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20083+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20084
20085 static int __init vsyscall_setup(char *str)
20086 {
20087 if (str) {
20088 if (!strcmp("emulate", str))
20089 vsyscall_mode = EMULATE;
20090- else if (!strcmp("native", str))
20091- vsyscall_mode = NATIVE;
20092 else if (!strcmp("none", str))
20093 vsyscall_mode = NONE;
20094 else
20095@@ -309,8 +307,7 @@ done:
20096 return true;
20097
20098 sigsegv:
20099- force_sig(SIGSEGV, current);
20100- return true;
20101+ do_group_exit(SIGKILL);
20102 }
20103
20104 /*
20105@@ -363,10 +360,7 @@ void __init map_vsyscall(void)
20106 extern char __vvar_page;
20107 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20108
20109- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20110- vsyscall_mode == NATIVE
20111- ? PAGE_KERNEL_VSYSCALL
20112- : PAGE_KERNEL_VVAR);
20113+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20114 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20115 (unsigned long)VSYSCALL_START);
20116
20117diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20118index 9796c2f..f686fbf 100644
20119--- a/arch/x86/kernel/x8664_ksyms_64.c
20120+++ b/arch/x86/kernel/x8664_ksyms_64.c
20121@@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20122 EXPORT_SYMBOL(copy_user_generic_string);
20123 EXPORT_SYMBOL(copy_user_generic_unrolled);
20124 EXPORT_SYMBOL(__copy_user_nocache);
20125-EXPORT_SYMBOL(_copy_from_user);
20126-EXPORT_SYMBOL(_copy_to_user);
20127
20128 EXPORT_SYMBOL(copy_page);
20129 EXPORT_SYMBOL(clear_page);
20130diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20131index bd18149..2ea0183 100644
20132--- a/arch/x86/kernel/xsave.c
20133+++ b/arch/x86/kernel/xsave.c
20134@@ -129,7 +129,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20135 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20136 return -EINVAL;
20137
20138- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20139+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20140 fx_sw_user->extended_size -
20141 FP_XSTATE_MAGIC2_SIZE));
20142 if (err)
20143@@ -265,7 +265,7 @@ fx_only:
20144 * the other extended state.
20145 */
20146 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20147- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20148+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20149 }
20150
20151 /*
20152@@ -294,7 +294,7 @@ int restore_i387_xstate(void __user *buf)
20153 if (use_xsave())
20154 err = restore_user_xstate(buf);
20155 else
20156- err = fxrstor_checking((__force struct i387_fxsave_struct *)
20157+ err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20158 buf);
20159 if (unlikely(err)) {
20160 /*
20161diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20162index 7df1c6d..9ea7c79 100644
20163--- a/arch/x86/kvm/cpuid.c
20164+++ b/arch/x86/kvm/cpuid.c
20165@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20166 struct kvm_cpuid2 *cpuid,
20167 struct kvm_cpuid_entry2 __user *entries)
20168 {
20169- int r;
20170+ int r, i;
20171
20172 r = -E2BIG;
20173 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20174 goto out;
20175 r = -EFAULT;
20176- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20177- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20178+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20179 goto out;
20180+ for (i = 0; i < cpuid->nent; ++i) {
20181+ struct kvm_cpuid_entry2 cpuid_entry;
20182+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20183+ goto out;
20184+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
20185+ }
20186 vcpu->arch.cpuid_nent = cpuid->nent;
20187 kvm_apic_set_version(vcpu);
20188 kvm_x86_ops->cpuid_update(vcpu);
20189@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20190 struct kvm_cpuid2 *cpuid,
20191 struct kvm_cpuid_entry2 __user *entries)
20192 {
20193- int r;
20194+ int r, i;
20195
20196 r = -E2BIG;
20197 if (cpuid->nent < vcpu->arch.cpuid_nent)
20198 goto out;
20199 r = -EFAULT;
20200- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20201- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20202+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20203 goto out;
20204+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20205+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20206+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20207+ goto out;
20208+ }
20209 return 0;
20210
20211 out:
20212diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20213index f95d242..3b49a90 100644
20214--- a/arch/x86/kvm/emulate.c
20215+++ b/arch/x86/kvm/emulate.c
20216@@ -256,6 +256,7 @@ struct gprefix {
20217
20218 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20219 do { \
20220+ unsigned long _tmp; \
20221 __asm__ __volatile__ ( \
20222 _PRE_EFLAGS("0", "4", "2") \
20223 _op _suffix " %"_x"3,%1; " \
20224@@ -270,8 +271,6 @@ struct gprefix {
20225 /* Raw emulation: instruction has two explicit operands. */
20226 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20227 do { \
20228- unsigned long _tmp; \
20229- \
20230 switch ((ctxt)->dst.bytes) { \
20231 case 2: \
20232 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20233@@ -287,7 +286,6 @@ struct gprefix {
20234
20235 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20236 do { \
20237- unsigned long _tmp; \
20238 switch ((ctxt)->dst.bytes) { \
20239 case 1: \
20240 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20241diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20242index 93c1574..d6097dc 100644
20243--- a/arch/x86/kvm/lapic.c
20244+++ b/arch/x86/kvm/lapic.c
20245@@ -54,7 +54,7 @@
20246 #define APIC_BUS_CYCLE_NS 1
20247
20248 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20249-#define apic_debug(fmt, arg...)
20250+#define apic_debug(fmt, arg...) do {} while (0)
20251
20252 #define APIC_LVT_NUM 6
20253 /* 14 is the version for Xeon and Pentium 8.4.8*/
20254diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20255index 34f9709..8eca2d5 100644
20256--- a/arch/x86/kvm/paging_tmpl.h
20257+++ b/arch/x86/kvm/paging_tmpl.h
20258@@ -197,7 +197,7 @@ retry_walk:
20259 if (unlikely(kvm_is_error_hva(host_addr)))
20260 goto error;
20261
20262- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20263+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20264 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20265 goto error;
20266
20267diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20268index f75af40..285b18f 100644
20269--- a/arch/x86/kvm/svm.c
20270+++ b/arch/x86/kvm/svm.c
20271@@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20272 int cpu = raw_smp_processor_id();
20273
20274 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20275+
20276+ pax_open_kernel();
20277 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20278+ pax_close_kernel();
20279+
20280 load_TR_desc();
20281 }
20282
20283@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20284 #endif
20285 #endif
20286
20287+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20288+ __set_fs(current_thread_info()->addr_limit);
20289+#endif
20290+
20291 reload_tss(vcpu);
20292
20293 local_irq_disable();
20294diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20295index 32eb588..19c4fe3 100644
20296--- a/arch/x86/kvm/vmx.c
20297+++ b/arch/x86/kvm/vmx.c
20298@@ -1313,7 +1313,11 @@ static void reload_tss(void)
20299 struct desc_struct *descs;
20300
20301 descs = (void *)gdt->address;
20302+
20303+ pax_open_kernel();
20304 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20305+ pax_close_kernel();
20306+
20307 load_TR_desc();
20308 }
20309
20310@@ -1475,8 +1479,8 @@ static void __vmx_load_host_state(struct vcpu_vmx *vmx)
20311 * The sysexit path does not restore ds/es, so we must set them to
20312 * a reasonable value ourselves.
20313 */
20314- loadsegment(ds, __USER_DS);
20315- loadsegment(es, __USER_DS);
20316+ loadsegment(ds, __KERNEL_DS);
20317+ loadsegment(es, __KERNEL_DS);
20318 #endif
20319 reload_tss();
20320 #ifdef CONFIG_X86_64
20321@@ -2653,8 +2657,11 @@ static __init int hardware_setup(void)
20322 if (!cpu_has_vmx_flexpriority())
20323 flexpriority_enabled = 0;
20324
20325- if (!cpu_has_vmx_tpr_shadow())
20326- kvm_x86_ops->update_cr8_intercept = NULL;
20327+ if (!cpu_has_vmx_tpr_shadow()) {
20328+ pax_open_kernel();
20329+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20330+ pax_close_kernel();
20331+ }
20332
20333 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20334 kvm_disable_largepages();
20335@@ -3680,7 +3687,7 @@ static void vmx_set_constant_host_state(void)
20336 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20337
20338 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20339- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20340+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20341
20342 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20343 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20344@@ -6218,6 +6225,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20345 "jmp .Lkvm_vmx_return \n\t"
20346 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20347 ".Lkvm_vmx_return: "
20348+
20349+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20350+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20351+ ".Lkvm_vmx_return2: "
20352+#endif
20353+
20354 /* Save guest registers, load host registers, keep flags */
20355 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20356 "pop %0 \n\t"
20357@@ -6266,6 +6279,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20358 #endif
20359 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20360 [wordsize]"i"(sizeof(ulong))
20361+
20362+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20363+ ,[cs]"i"(__KERNEL_CS)
20364+#endif
20365+
20366 : "cc", "memory"
20367 , R"ax", R"bx", R"di", R"si"
20368 #ifdef CONFIG_X86_64
20369@@ -6294,6 +6312,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20370 }
20371 }
20372
20373+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20374+
20375+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20376+ loadsegment(fs, __KERNEL_PERCPU);
20377+#endif
20378+
20379+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20380+ __set_fs(current_thread_info()->addr_limit);
20381+#endif
20382+
20383 vmx->loaded_vmcs->launched = 1;
20384
20385 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20386diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20387index be6d549..b0ba2bf 100644
20388--- a/arch/x86/kvm/x86.c
20389+++ b/arch/x86/kvm/x86.c
20390@@ -1357,8 +1357,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20391 {
20392 struct kvm *kvm = vcpu->kvm;
20393 int lm = is_long_mode(vcpu);
20394- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20395- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20396+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20397+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20398 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20399 : kvm->arch.xen_hvm_config.blob_size_32;
20400 u32 page_num = data & ~PAGE_MASK;
20401@@ -2214,6 +2214,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20402 if (n < msr_list.nmsrs)
20403 goto out;
20404 r = -EFAULT;
20405+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20406+ goto out;
20407 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20408 num_msrs_to_save * sizeof(u32)))
20409 goto out;
20410@@ -2339,7 +2341,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20411 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20412 struct kvm_interrupt *irq)
20413 {
20414- if (irq->irq < 0 || irq->irq >= 256)
20415+ if (irq->irq >= 256)
20416 return -EINVAL;
20417 if (irqchip_in_kernel(vcpu->kvm))
20418 return -ENXIO;
20419@@ -4876,7 +4878,7 @@ static void kvm_set_mmio_spte_mask(void)
20420 kvm_mmu_set_mmio_spte_mask(mask);
20421 }
20422
20423-int kvm_arch_init(void *opaque)
20424+int kvm_arch_init(const void *opaque)
20425 {
20426 int r;
20427 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20428diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20429index 642d880..44e0f3f 100644
20430--- a/arch/x86/lguest/boot.c
20431+++ b/arch/x86/lguest/boot.c
20432@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20433 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20434 * Launcher to reboot us.
20435 */
20436-static void lguest_restart(char *reason)
20437+static __noreturn void lguest_restart(char *reason)
20438 {
20439 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20440+ BUG();
20441 }
20442
20443 /*G:050
20444diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20445index 00933d5..3a64af9 100644
20446--- a/arch/x86/lib/atomic64_386_32.S
20447+++ b/arch/x86/lib/atomic64_386_32.S
20448@@ -48,6 +48,10 @@ BEGIN(read)
20449 movl (v), %eax
20450 movl 4(v), %edx
20451 RET_ENDP
20452+BEGIN(read_unchecked)
20453+ movl (v), %eax
20454+ movl 4(v), %edx
20455+RET_ENDP
20456 #undef v
20457
20458 #define v %esi
20459@@ -55,6 +59,10 @@ BEGIN(set)
20460 movl %ebx, (v)
20461 movl %ecx, 4(v)
20462 RET_ENDP
20463+BEGIN(set_unchecked)
20464+ movl %ebx, (v)
20465+ movl %ecx, 4(v)
20466+RET_ENDP
20467 #undef v
20468
20469 #define v %esi
20470@@ -70,6 +78,20 @@ RET_ENDP
20471 BEGIN(add)
20472 addl %eax, (v)
20473 adcl %edx, 4(v)
20474+
20475+#ifdef CONFIG_PAX_REFCOUNT
20476+ jno 0f
20477+ subl %eax, (v)
20478+ sbbl %edx, 4(v)
20479+ int $4
20480+0:
20481+ _ASM_EXTABLE(0b, 0b)
20482+#endif
20483+
20484+RET_ENDP
20485+BEGIN(add_unchecked)
20486+ addl %eax, (v)
20487+ adcl %edx, 4(v)
20488 RET_ENDP
20489 #undef v
20490
20491@@ -77,6 +99,24 @@ RET_ENDP
20492 BEGIN(add_return)
20493 addl (v), %eax
20494 adcl 4(v), %edx
20495+
20496+#ifdef CONFIG_PAX_REFCOUNT
20497+ into
20498+1234:
20499+ _ASM_EXTABLE(1234b, 2f)
20500+#endif
20501+
20502+ movl %eax, (v)
20503+ movl %edx, 4(v)
20504+
20505+#ifdef CONFIG_PAX_REFCOUNT
20506+2:
20507+#endif
20508+
20509+RET_ENDP
20510+BEGIN(add_return_unchecked)
20511+ addl (v), %eax
20512+ adcl 4(v), %edx
20513 movl %eax, (v)
20514 movl %edx, 4(v)
20515 RET_ENDP
20516@@ -86,6 +126,20 @@ RET_ENDP
20517 BEGIN(sub)
20518 subl %eax, (v)
20519 sbbl %edx, 4(v)
20520+
20521+#ifdef CONFIG_PAX_REFCOUNT
20522+ jno 0f
20523+ addl %eax, (v)
20524+ adcl %edx, 4(v)
20525+ int $4
20526+0:
20527+ _ASM_EXTABLE(0b, 0b)
20528+#endif
20529+
20530+RET_ENDP
20531+BEGIN(sub_unchecked)
20532+ subl %eax, (v)
20533+ sbbl %edx, 4(v)
20534 RET_ENDP
20535 #undef v
20536
20537@@ -96,6 +150,27 @@ BEGIN(sub_return)
20538 sbbl $0, %edx
20539 addl (v), %eax
20540 adcl 4(v), %edx
20541+
20542+#ifdef CONFIG_PAX_REFCOUNT
20543+ into
20544+1234:
20545+ _ASM_EXTABLE(1234b, 2f)
20546+#endif
20547+
20548+ movl %eax, (v)
20549+ movl %edx, 4(v)
20550+
20551+#ifdef CONFIG_PAX_REFCOUNT
20552+2:
20553+#endif
20554+
20555+RET_ENDP
20556+BEGIN(sub_return_unchecked)
20557+ negl %edx
20558+ negl %eax
20559+ sbbl $0, %edx
20560+ addl (v), %eax
20561+ adcl 4(v), %edx
20562 movl %eax, (v)
20563 movl %edx, 4(v)
20564 RET_ENDP
20565@@ -105,6 +180,20 @@ RET_ENDP
20566 BEGIN(inc)
20567 addl $1, (v)
20568 adcl $0, 4(v)
20569+
20570+#ifdef CONFIG_PAX_REFCOUNT
20571+ jno 0f
20572+ subl $1, (v)
20573+ sbbl $0, 4(v)
20574+ int $4
20575+0:
20576+ _ASM_EXTABLE(0b, 0b)
20577+#endif
20578+
20579+RET_ENDP
20580+BEGIN(inc_unchecked)
20581+ addl $1, (v)
20582+ adcl $0, 4(v)
20583 RET_ENDP
20584 #undef v
20585
20586@@ -114,6 +203,26 @@ BEGIN(inc_return)
20587 movl 4(v), %edx
20588 addl $1, %eax
20589 adcl $0, %edx
20590+
20591+#ifdef CONFIG_PAX_REFCOUNT
20592+ into
20593+1234:
20594+ _ASM_EXTABLE(1234b, 2f)
20595+#endif
20596+
20597+ movl %eax, (v)
20598+ movl %edx, 4(v)
20599+
20600+#ifdef CONFIG_PAX_REFCOUNT
20601+2:
20602+#endif
20603+
20604+RET_ENDP
20605+BEGIN(inc_return_unchecked)
20606+ movl (v), %eax
20607+ movl 4(v), %edx
20608+ addl $1, %eax
20609+ adcl $0, %edx
20610 movl %eax, (v)
20611 movl %edx, 4(v)
20612 RET_ENDP
20613@@ -123,6 +232,20 @@ RET_ENDP
20614 BEGIN(dec)
20615 subl $1, (v)
20616 sbbl $0, 4(v)
20617+
20618+#ifdef CONFIG_PAX_REFCOUNT
20619+ jno 0f
20620+ addl $1, (v)
20621+ adcl $0, 4(v)
20622+ int $4
20623+0:
20624+ _ASM_EXTABLE(0b, 0b)
20625+#endif
20626+
20627+RET_ENDP
20628+BEGIN(dec_unchecked)
20629+ subl $1, (v)
20630+ sbbl $0, 4(v)
20631 RET_ENDP
20632 #undef v
20633
20634@@ -132,6 +255,26 @@ BEGIN(dec_return)
20635 movl 4(v), %edx
20636 subl $1, %eax
20637 sbbl $0, %edx
20638+
20639+#ifdef CONFIG_PAX_REFCOUNT
20640+ into
20641+1234:
20642+ _ASM_EXTABLE(1234b, 2f)
20643+#endif
20644+
20645+ movl %eax, (v)
20646+ movl %edx, 4(v)
20647+
20648+#ifdef CONFIG_PAX_REFCOUNT
20649+2:
20650+#endif
20651+
20652+RET_ENDP
20653+BEGIN(dec_return_unchecked)
20654+ movl (v), %eax
20655+ movl 4(v), %edx
20656+ subl $1, %eax
20657+ sbbl $0, %edx
20658 movl %eax, (v)
20659 movl %edx, 4(v)
20660 RET_ENDP
20661@@ -143,6 +286,13 @@ BEGIN(add_unless)
20662 adcl %edx, %edi
20663 addl (v), %eax
20664 adcl 4(v), %edx
20665+
20666+#ifdef CONFIG_PAX_REFCOUNT
20667+ into
20668+1234:
20669+ _ASM_EXTABLE(1234b, 2f)
20670+#endif
20671+
20672 cmpl %eax, %ecx
20673 je 3f
20674 1:
20675@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20676 1:
20677 addl $1, %eax
20678 adcl $0, %edx
20679+
20680+#ifdef CONFIG_PAX_REFCOUNT
20681+ into
20682+1234:
20683+ _ASM_EXTABLE(1234b, 2f)
20684+#endif
20685+
20686 movl %eax, (v)
20687 movl %edx, 4(v)
20688 movl $1, %eax
20689@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20690 movl 4(v), %edx
20691 subl $1, %eax
20692 sbbl $0, %edx
20693+
20694+#ifdef CONFIG_PAX_REFCOUNT
20695+ into
20696+1234:
20697+ _ASM_EXTABLE(1234b, 1f)
20698+#endif
20699+
20700 js 1f
20701 movl %eax, (v)
20702 movl %edx, 4(v)
20703diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20704index f5cc9eb..51fa319 100644
20705--- a/arch/x86/lib/atomic64_cx8_32.S
20706+++ b/arch/x86/lib/atomic64_cx8_32.S
20707@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20708 CFI_STARTPROC
20709
20710 read64 %ecx
20711+ pax_force_retaddr
20712 ret
20713 CFI_ENDPROC
20714 ENDPROC(atomic64_read_cx8)
20715
20716+ENTRY(atomic64_read_unchecked_cx8)
20717+ CFI_STARTPROC
20718+
20719+ read64 %ecx
20720+ pax_force_retaddr
20721+ ret
20722+ CFI_ENDPROC
20723+ENDPROC(atomic64_read_unchecked_cx8)
20724+
20725 ENTRY(atomic64_set_cx8)
20726 CFI_STARTPROC
20727
20728@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20729 cmpxchg8b (%esi)
20730 jne 1b
20731
20732+ pax_force_retaddr
20733 ret
20734 CFI_ENDPROC
20735 ENDPROC(atomic64_set_cx8)
20736
20737+ENTRY(atomic64_set_unchecked_cx8)
20738+ CFI_STARTPROC
20739+
20740+1:
20741+/* we don't need LOCK_PREFIX since aligned 64-bit writes
20742+ * are atomic on 586 and newer */
20743+ cmpxchg8b (%esi)
20744+ jne 1b
20745+
20746+ pax_force_retaddr
20747+ ret
20748+ CFI_ENDPROC
20749+ENDPROC(atomic64_set_unchecked_cx8)
20750+
20751 ENTRY(atomic64_xchg_cx8)
20752 CFI_STARTPROC
20753
20754@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20755 cmpxchg8b (%esi)
20756 jne 1b
20757
20758+ pax_force_retaddr
20759 ret
20760 CFI_ENDPROC
20761 ENDPROC(atomic64_xchg_cx8)
20762
20763-.macro addsub_return func ins insc
20764-ENTRY(atomic64_\func\()_return_cx8)
20765+.macro addsub_return func ins insc unchecked=""
20766+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20767 CFI_STARTPROC
20768 SAVE ebp
20769 SAVE ebx
20770@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20771 movl %edx, %ecx
20772 \ins\()l %esi, %ebx
20773 \insc\()l %edi, %ecx
20774+
20775+.ifb \unchecked
20776+#ifdef CONFIG_PAX_REFCOUNT
20777+ into
20778+2:
20779+ _ASM_EXTABLE(2b, 3f)
20780+#endif
20781+.endif
20782+
20783 LOCK_PREFIX
20784 cmpxchg8b (%ebp)
20785 jne 1b
20786-
20787-10:
20788 movl %ebx, %eax
20789 movl %ecx, %edx
20790+
20791+.ifb \unchecked
20792+#ifdef CONFIG_PAX_REFCOUNT
20793+3:
20794+#endif
20795+.endif
20796+
20797 RESTORE edi
20798 RESTORE esi
20799 RESTORE ebx
20800 RESTORE ebp
20801+ pax_force_retaddr
20802 ret
20803 CFI_ENDPROC
20804-ENDPROC(atomic64_\func\()_return_cx8)
20805+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20806 .endm
20807
20808 addsub_return add add adc
20809 addsub_return sub sub sbb
20810+addsub_return add add adc _unchecked
20811+addsub_return sub sub sbb _unchecked
20812
20813-.macro incdec_return func ins insc
20814-ENTRY(atomic64_\func\()_return_cx8)
20815+.macro incdec_return func ins insc unchecked=""
20816+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20817 CFI_STARTPROC
20818 SAVE ebx
20819
20820@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20821 movl %edx, %ecx
20822 \ins\()l $1, %ebx
20823 \insc\()l $0, %ecx
20824+
20825+.ifb \unchecked
20826+#ifdef CONFIG_PAX_REFCOUNT
20827+ into
20828+2:
20829+ _ASM_EXTABLE(2b, 3f)
20830+#endif
20831+.endif
20832+
20833 LOCK_PREFIX
20834 cmpxchg8b (%esi)
20835 jne 1b
20836
20837-10:
20838 movl %ebx, %eax
20839 movl %ecx, %edx
20840+
20841+.ifb \unchecked
20842+#ifdef CONFIG_PAX_REFCOUNT
20843+3:
20844+#endif
20845+.endif
20846+
20847 RESTORE ebx
20848+ pax_force_retaddr
20849 ret
20850 CFI_ENDPROC
20851-ENDPROC(atomic64_\func\()_return_cx8)
20852+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20853 .endm
20854
20855 incdec_return inc add adc
20856 incdec_return dec sub sbb
20857+incdec_return inc add adc _unchecked
20858+incdec_return dec sub sbb _unchecked
20859
20860 ENTRY(atomic64_dec_if_positive_cx8)
20861 CFI_STARTPROC
20862@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20863 movl %edx, %ecx
20864 subl $1, %ebx
20865 sbb $0, %ecx
20866+
20867+#ifdef CONFIG_PAX_REFCOUNT
20868+ into
20869+1234:
20870+ _ASM_EXTABLE(1234b, 2f)
20871+#endif
20872+
20873 js 2f
20874 LOCK_PREFIX
20875 cmpxchg8b (%esi)
20876@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20877 movl %ebx, %eax
20878 movl %ecx, %edx
20879 RESTORE ebx
20880+ pax_force_retaddr
20881 ret
20882 CFI_ENDPROC
20883 ENDPROC(atomic64_dec_if_positive_cx8)
20884@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
20885 movl %edx, %ecx
20886 addl %ebp, %ebx
20887 adcl %edi, %ecx
20888+
20889+#ifdef CONFIG_PAX_REFCOUNT
20890+ into
20891+1234:
20892+ _ASM_EXTABLE(1234b, 3f)
20893+#endif
20894+
20895 LOCK_PREFIX
20896 cmpxchg8b (%esi)
20897 jne 1b
20898@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
20899 CFI_ADJUST_CFA_OFFSET -8
20900 RESTORE ebx
20901 RESTORE ebp
20902+ pax_force_retaddr
20903 ret
20904 4:
20905 cmpl %edx, 4(%esp)
20906@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20907 xorl %ecx, %ecx
20908 addl $1, %ebx
20909 adcl %edx, %ecx
20910+
20911+#ifdef CONFIG_PAX_REFCOUNT
20912+ into
20913+1234:
20914+ _ASM_EXTABLE(1234b, 3f)
20915+#endif
20916+
20917 LOCK_PREFIX
20918 cmpxchg8b (%esi)
20919 jne 1b
20920@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
20921 movl $1, %eax
20922 3:
20923 RESTORE ebx
20924+ pax_force_retaddr
20925 ret
20926 CFI_ENDPROC
20927 ENDPROC(atomic64_inc_not_zero_cx8)
20928diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
20929index 2af5df3..62b1a5a 100644
20930--- a/arch/x86/lib/checksum_32.S
20931+++ b/arch/x86/lib/checksum_32.S
20932@@ -29,7 +29,8 @@
20933 #include <asm/dwarf2.h>
20934 #include <asm/errno.h>
20935 #include <asm/asm.h>
20936-
20937+#include <asm/segment.h>
20938+
20939 /*
20940 * computes a partial checksum, e.g. for TCP/UDP fragments
20941 */
20942@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
20943
20944 #define ARGBASE 16
20945 #define FP 12
20946-
20947-ENTRY(csum_partial_copy_generic)
20948+
20949+ENTRY(csum_partial_copy_generic_to_user)
20950 CFI_STARTPROC
20951+
20952+#ifdef CONFIG_PAX_MEMORY_UDEREF
20953+ pushl_cfi %gs
20954+ popl_cfi %es
20955+ jmp csum_partial_copy_generic
20956+#endif
20957+
20958+ENTRY(csum_partial_copy_generic_from_user)
20959+
20960+#ifdef CONFIG_PAX_MEMORY_UDEREF
20961+ pushl_cfi %gs
20962+ popl_cfi %ds
20963+#endif
20964+
20965+ENTRY(csum_partial_copy_generic)
20966 subl $4,%esp
20967 CFI_ADJUST_CFA_OFFSET 4
20968 pushl_cfi %edi
20969@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
20970 jmp 4f
20971 SRC(1: movw (%esi), %bx )
20972 addl $2, %esi
20973-DST( movw %bx, (%edi) )
20974+DST( movw %bx, %es:(%edi) )
20975 addl $2, %edi
20976 addw %bx, %ax
20977 adcl $0, %eax
20978@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
20979 SRC(1: movl (%esi), %ebx )
20980 SRC( movl 4(%esi), %edx )
20981 adcl %ebx, %eax
20982-DST( movl %ebx, (%edi) )
20983+DST( movl %ebx, %es:(%edi) )
20984 adcl %edx, %eax
20985-DST( movl %edx, 4(%edi) )
20986+DST( movl %edx, %es:4(%edi) )
20987
20988 SRC( movl 8(%esi), %ebx )
20989 SRC( movl 12(%esi), %edx )
20990 adcl %ebx, %eax
20991-DST( movl %ebx, 8(%edi) )
20992+DST( movl %ebx, %es:8(%edi) )
20993 adcl %edx, %eax
20994-DST( movl %edx, 12(%edi) )
20995+DST( movl %edx, %es:12(%edi) )
20996
20997 SRC( movl 16(%esi), %ebx )
20998 SRC( movl 20(%esi), %edx )
20999 adcl %ebx, %eax
21000-DST( movl %ebx, 16(%edi) )
21001+DST( movl %ebx, %es:16(%edi) )
21002 adcl %edx, %eax
21003-DST( movl %edx, 20(%edi) )
21004+DST( movl %edx, %es:20(%edi) )
21005
21006 SRC( movl 24(%esi), %ebx )
21007 SRC( movl 28(%esi), %edx )
21008 adcl %ebx, %eax
21009-DST( movl %ebx, 24(%edi) )
21010+DST( movl %ebx, %es:24(%edi) )
21011 adcl %edx, %eax
21012-DST( movl %edx, 28(%edi) )
21013+DST( movl %edx, %es:28(%edi) )
21014
21015 lea 32(%esi), %esi
21016 lea 32(%edi), %edi
21017@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21018 shrl $2, %edx # This clears CF
21019 SRC(3: movl (%esi), %ebx )
21020 adcl %ebx, %eax
21021-DST( movl %ebx, (%edi) )
21022+DST( movl %ebx, %es:(%edi) )
21023 lea 4(%esi), %esi
21024 lea 4(%edi), %edi
21025 dec %edx
21026@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21027 jb 5f
21028 SRC( movw (%esi), %cx )
21029 leal 2(%esi), %esi
21030-DST( movw %cx, (%edi) )
21031+DST( movw %cx, %es:(%edi) )
21032 leal 2(%edi), %edi
21033 je 6f
21034 shll $16,%ecx
21035 SRC(5: movb (%esi), %cl )
21036-DST( movb %cl, (%edi) )
21037+DST( movb %cl, %es:(%edi) )
21038 6: addl %ecx, %eax
21039 adcl $0, %eax
21040 7:
21041@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21042
21043 6001:
21044 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21045- movl $-EFAULT, (%ebx)
21046+ movl $-EFAULT, %ss:(%ebx)
21047
21048 # zero the complete destination - computing the rest
21049 # is too much work
21050@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21051
21052 6002:
21053 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21054- movl $-EFAULT,(%ebx)
21055+ movl $-EFAULT,%ss:(%ebx)
21056 jmp 5000b
21057
21058 .previous
21059
21060+ pushl_cfi %ss
21061+ popl_cfi %ds
21062+ pushl_cfi %ss
21063+ popl_cfi %es
21064 popl_cfi %ebx
21065 CFI_RESTORE ebx
21066 popl_cfi %esi
21067@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21068 popl_cfi %ecx # equivalent to addl $4,%esp
21069 ret
21070 CFI_ENDPROC
21071-ENDPROC(csum_partial_copy_generic)
21072+ENDPROC(csum_partial_copy_generic_to_user)
21073
21074 #else
21075
21076 /* Version for PentiumII/PPro */
21077
21078 #define ROUND1(x) \
21079+ nop; nop; nop; \
21080 SRC(movl x(%esi), %ebx ) ; \
21081 addl %ebx, %eax ; \
21082- DST(movl %ebx, x(%edi) ) ;
21083+ DST(movl %ebx, %es:x(%edi)) ;
21084
21085 #define ROUND(x) \
21086+ nop; nop; nop; \
21087 SRC(movl x(%esi), %ebx ) ; \
21088 adcl %ebx, %eax ; \
21089- DST(movl %ebx, x(%edi) ) ;
21090+ DST(movl %ebx, %es:x(%edi)) ;
21091
21092 #define ARGBASE 12
21093-
21094-ENTRY(csum_partial_copy_generic)
21095+
21096+ENTRY(csum_partial_copy_generic_to_user)
21097 CFI_STARTPROC
21098+
21099+#ifdef CONFIG_PAX_MEMORY_UDEREF
21100+ pushl_cfi %gs
21101+ popl_cfi %es
21102+ jmp csum_partial_copy_generic
21103+#endif
21104+
21105+ENTRY(csum_partial_copy_generic_from_user)
21106+
21107+#ifdef CONFIG_PAX_MEMORY_UDEREF
21108+ pushl_cfi %gs
21109+ popl_cfi %ds
21110+#endif
21111+
21112+ENTRY(csum_partial_copy_generic)
21113 pushl_cfi %ebx
21114 CFI_REL_OFFSET ebx, 0
21115 pushl_cfi %edi
21116@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21117 subl %ebx, %edi
21118 lea -1(%esi),%edx
21119 andl $-32,%edx
21120- lea 3f(%ebx,%ebx), %ebx
21121+ lea 3f(%ebx,%ebx,2), %ebx
21122 testl %esi, %esi
21123 jmp *%ebx
21124 1: addl $64,%esi
21125@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21126 jb 5f
21127 SRC( movw (%esi), %dx )
21128 leal 2(%esi), %esi
21129-DST( movw %dx, (%edi) )
21130+DST( movw %dx, %es:(%edi) )
21131 leal 2(%edi), %edi
21132 je 6f
21133 shll $16,%edx
21134 5:
21135 SRC( movb (%esi), %dl )
21136-DST( movb %dl, (%edi) )
21137+DST( movb %dl, %es:(%edi) )
21138 6: addl %edx, %eax
21139 adcl $0, %eax
21140 7:
21141 .section .fixup, "ax"
21142 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21143- movl $-EFAULT, (%ebx)
21144+ movl $-EFAULT, %ss:(%ebx)
21145 # zero the complete destination (computing the rest is too much work)
21146 movl ARGBASE+8(%esp),%edi # dst
21147 movl ARGBASE+12(%esp),%ecx # len
21148@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21149 rep; stosb
21150 jmp 7b
21151 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21152- movl $-EFAULT, (%ebx)
21153+ movl $-EFAULT, %ss:(%ebx)
21154 jmp 7b
21155 .previous
21156
21157+#ifdef CONFIG_PAX_MEMORY_UDEREF
21158+ pushl_cfi %ss
21159+ popl_cfi %ds
21160+ pushl_cfi %ss
21161+ popl_cfi %es
21162+#endif
21163+
21164 popl_cfi %esi
21165 CFI_RESTORE esi
21166 popl_cfi %edi
21167@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21168 CFI_RESTORE ebx
21169 ret
21170 CFI_ENDPROC
21171-ENDPROC(csum_partial_copy_generic)
21172+ENDPROC(csum_partial_copy_generic_to_user)
21173
21174 #undef ROUND
21175 #undef ROUND1
21176diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21177index f2145cf..cea889d 100644
21178--- a/arch/x86/lib/clear_page_64.S
21179+++ b/arch/x86/lib/clear_page_64.S
21180@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21181 movl $4096/8,%ecx
21182 xorl %eax,%eax
21183 rep stosq
21184+ pax_force_retaddr
21185 ret
21186 CFI_ENDPROC
21187 ENDPROC(clear_page_c)
21188@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21189 movl $4096,%ecx
21190 xorl %eax,%eax
21191 rep stosb
21192+ pax_force_retaddr
21193 ret
21194 CFI_ENDPROC
21195 ENDPROC(clear_page_c_e)
21196@@ -43,6 +45,7 @@ ENTRY(clear_page)
21197 leaq 64(%rdi),%rdi
21198 jnz .Lloop
21199 nop
21200+ pax_force_retaddr
21201 ret
21202 CFI_ENDPROC
21203 .Lclear_page_end:
21204@@ -58,7 +61,7 @@ ENDPROC(clear_page)
21205
21206 #include <asm/cpufeature.h>
21207
21208- .section .altinstr_replacement,"ax"
21209+ .section .altinstr_replacement,"a"
21210 1: .byte 0xeb /* jmp <disp8> */
21211 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21212 2: .byte 0xeb /* jmp <disp8> */
21213diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21214index 1e572c5..2a162cd 100644
21215--- a/arch/x86/lib/cmpxchg16b_emu.S
21216+++ b/arch/x86/lib/cmpxchg16b_emu.S
21217@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21218
21219 popf
21220 mov $1, %al
21221+ pax_force_retaddr
21222 ret
21223
21224 not_same:
21225 popf
21226 xor %al,%al
21227+ pax_force_retaddr
21228 ret
21229
21230 CFI_ENDPROC
21231diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21232index 6b34d04..dccb07f 100644
21233--- a/arch/x86/lib/copy_page_64.S
21234+++ b/arch/x86/lib/copy_page_64.S
21235@@ -9,6 +9,7 @@ copy_page_c:
21236 CFI_STARTPROC
21237 movl $4096/8,%ecx
21238 rep movsq
21239+ pax_force_retaddr
21240 ret
21241 CFI_ENDPROC
21242 ENDPROC(copy_page_c)
21243@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21244
21245 ENTRY(copy_page)
21246 CFI_STARTPROC
21247- subq $2*8,%rsp
21248- CFI_ADJUST_CFA_OFFSET 2*8
21249+ subq $3*8,%rsp
21250+ CFI_ADJUST_CFA_OFFSET 3*8
21251 movq %rbx,(%rsp)
21252 CFI_REL_OFFSET rbx, 0
21253 movq %r12,1*8(%rsp)
21254 CFI_REL_OFFSET r12, 1*8
21255+ movq %r13,2*8(%rsp)
21256+ CFI_REL_OFFSET r13, 2*8
21257
21258 movl $(4096/64)-5,%ecx
21259 .p2align 4
21260@@ -37,7 +40,7 @@ ENTRY(copy_page)
21261 movq 16 (%rsi), %rdx
21262 movq 24 (%rsi), %r8
21263 movq 32 (%rsi), %r9
21264- movq 40 (%rsi), %r10
21265+ movq 40 (%rsi), %r13
21266 movq 48 (%rsi), %r11
21267 movq 56 (%rsi), %r12
21268
21269@@ -48,7 +51,7 @@ ENTRY(copy_page)
21270 movq %rdx, 16 (%rdi)
21271 movq %r8, 24 (%rdi)
21272 movq %r9, 32 (%rdi)
21273- movq %r10, 40 (%rdi)
21274+ movq %r13, 40 (%rdi)
21275 movq %r11, 48 (%rdi)
21276 movq %r12, 56 (%rdi)
21277
21278@@ -67,7 +70,7 @@ ENTRY(copy_page)
21279 movq 16 (%rsi), %rdx
21280 movq 24 (%rsi), %r8
21281 movq 32 (%rsi), %r9
21282- movq 40 (%rsi), %r10
21283+ movq 40 (%rsi), %r13
21284 movq 48 (%rsi), %r11
21285 movq 56 (%rsi), %r12
21286
21287@@ -76,7 +79,7 @@ ENTRY(copy_page)
21288 movq %rdx, 16 (%rdi)
21289 movq %r8, 24 (%rdi)
21290 movq %r9, 32 (%rdi)
21291- movq %r10, 40 (%rdi)
21292+ movq %r13, 40 (%rdi)
21293 movq %r11, 48 (%rdi)
21294 movq %r12, 56 (%rdi)
21295
21296@@ -89,8 +92,11 @@ ENTRY(copy_page)
21297 CFI_RESTORE rbx
21298 movq 1*8(%rsp),%r12
21299 CFI_RESTORE r12
21300- addq $2*8,%rsp
21301- CFI_ADJUST_CFA_OFFSET -2*8
21302+ movq 2*8(%rsp),%r13
21303+ CFI_RESTORE r13
21304+ addq $3*8,%rsp
21305+ CFI_ADJUST_CFA_OFFSET -3*8
21306+ pax_force_retaddr
21307 ret
21308 .Lcopy_page_end:
21309 CFI_ENDPROC
21310@@ -101,7 +107,7 @@ ENDPROC(copy_page)
21311
21312 #include <asm/cpufeature.h>
21313
21314- .section .altinstr_replacement,"ax"
21315+ .section .altinstr_replacement,"a"
21316 1: .byte 0xeb /* jmp <disp8> */
21317 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21318 2:
21319diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21320index 5b2995f..78e7644 100644
21321--- a/arch/x86/lib/copy_user_64.S
21322+++ b/arch/x86/lib/copy_user_64.S
21323@@ -17,6 +17,7 @@
21324 #include <asm/cpufeature.h>
21325 #include <asm/alternative-asm.h>
21326 #include <asm/asm.h>
21327+#include <asm/pgtable.h>
21328
21329 /*
21330 * By placing feature2 after feature1 in altinstructions section, we logically
21331@@ -30,7 +31,7 @@
21332 .byte 0xe9 /* 32bit jump */
21333 .long \orig-1f /* by default jump to orig */
21334 1:
21335- .section .altinstr_replacement,"ax"
21336+ .section .altinstr_replacement,"a"
21337 2: .byte 0xe9 /* near jump with 32bit immediate */
21338 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21339 3: .byte 0xe9 /* near jump with 32bit immediate */
21340@@ -69,47 +70,20 @@
21341 #endif
21342 .endm
21343
21344-/* Standard copy_to_user with segment limit checking */
21345-ENTRY(_copy_to_user)
21346- CFI_STARTPROC
21347- GET_THREAD_INFO(%rax)
21348- movq %rdi,%rcx
21349- addq %rdx,%rcx
21350- jc bad_to_user
21351- cmpq TI_addr_limit(%rax),%rcx
21352- ja bad_to_user
21353- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21354- copy_user_generic_unrolled,copy_user_generic_string, \
21355- copy_user_enhanced_fast_string
21356- CFI_ENDPROC
21357-ENDPROC(_copy_to_user)
21358-
21359-/* Standard copy_from_user with segment limit checking */
21360-ENTRY(_copy_from_user)
21361- CFI_STARTPROC
21362- GET_THREAD_INFO(%rax)
21363- movq %rsi,%rcx
21364- addq %rdx,%rcx
21365- jc bad_from_user
21366- cmpq TI_addr_limit(%rax),%rcx
21367- ja bad_from_user
21368- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21369- copy_user_generic_unrolled,copy_user_generic_string, \
21370- copy_user_enhanced_fast_string
21371- CFI_ENDPROC
21372-ENDPROC(_copy_from_user)
21373-
21374 .section .fixup,"ax"
21375 /* must zero dest */
21376 ENTRY(bad_from_user)
21377 bad_from_user:
21378 CFI_STARTPROC
21379+ testl %edx,%edx
21380+ js bad_to_user
21381 movl %edx,%ecx
21382 xorl %eax,%eax
21383 rep
21384 stosb
21385 bad_to_user:
21386 movl %edx,%eax
21387+ pax_force_retaddr
21388 ret
21389 CFI_ENDPROC
21390 ENDPROC(bad_from_user)
21391@@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21392 jz 17f
21393 1: movq (%rsi),%r8
21394 2: movq 1*8(%rsi),%r9
21395-3: movq 2*8(%rsi),%r10
21396+3: movq 2*8(%rsi),%rax
21397 4: movq 3*8(%rsi),%r11
21398 5: movq %r8,(%rdi)
21399 6: movq %r9,1*8(%rdi)
21400-7: movq %r10,2*8(%rdi)
21401+7: movq %rax,2*8(%rdi)
21402 8: movq %r11,3*8(%rdi)
21403 9: movq 4*8(%rsi),%r8
21404 10: movq 5*8(%rsi),%r9
21405-11: movq 6*8(%rsi),%r10
21406+11: movq 6*8(%rsi),%rax
21407 12: movq 7*8(%rsi),%r11
21408 13: movq %r8,4*8(%rdi)
21409 14: movq %r9,5*8(%rdi)
21410-15: movq %r10,6*8(%rdi)
21411+15: movq %rax,6*8(%rdi)
21412 16: movq %r11,7*8(%rdi)
21413 leaq 64(%rsi),%rsi
21414 leaq 64(%rdi),%rdi
21415@@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21416 decl %ecx
21417 jnz 21b
21418 23: xor %eax,%eax
21419+ pax_force_retaddr
21420 ret
21421
21422 .section .fixup,"ax"
21423@@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21424 3: rep
21425 movsb
21426 4: xorl %eax,%eax
21427+ pax_force_retaddr
21428 ret
21429
21430 .section .fixup,"ax"
21431@@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21432 1: rep
21433 movsb
21434 2: xorl %eax,%eax
21435+ pax_force_retaddr
21436 ret
21437
21438 .section .fixup,"ax"
21439diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21440index cacddc7..09d49e4 100644
21441--- a/arch/x86/lib/copy_user_nocache_64.S
21442+++ b/arch/x86/lib/copy_user_nocache_64.S
21443@@ -8,6 +8,7 @@
21444
21445 #include <linux/linkage.h>
21446 #include <asm/dwarf2.h>
21447+#include <asm/alternative-asm.h>
21448
21449 #define FIX_ALIGNMENT 1
21450
21451@@ -15,6 +16,7 @@
21452 #include <asm/asm-offsets.h>
21453 #include <asm/thread_info.h>
21454 #include <asm/asm.h>
21455+#include <asm/pgtable.h>
21456
21457 .macro ALIGN_DESTINATION
21458 #ifdef FIX_ALIGNMENT
21459@@ -48,6 +50,15 @@
21460 */
21461 ENTRY(__copy_user_nocache)
21462 CFI_STARTPROC
21463+
21464+#ifdef CONFIG_PAX_MEMORY_UDEREF
21465+ mov $PAX_USER_SHADOW_BASE,%rcx
21466+ cmp %rcx,%rsi
21467+ jae 1f
21468+ add %rcx,%rsi
21469+1:
21470+#endif
21471+
21472 cmpl $8,%edx
21473 jb 20f /* less then 8 bytes, go to byte copy loop */
21474 ALIGN_DESTINATION
21475@@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21476 jz 17f
21477 1: movq (%rsi),%r8
21478 2: movq 1*8(%rsi),%r9
21479-3: movq 2*8(%rsi),%r10
21480+3: movq 2*8(%rsi),%rax
21481 4: movq 3*8(%rsi),%r11
21482 5: movnti %r8,(%rdi)
21483 6: movnti %r9,1*8(%rdi)
21484-7: movnti %r10,2*8(%rdi)
21485+7: movnti %rax,2*8(%rdi)
21486 8: movnti %r11,3*8(%rdi)
21487 9: movq 4*8(%rsi),%r8
21488 10: movq 5*8(%rsi),%r9
21489-11: movq 6*8(%rsi),%r10
21490+11: movq 6*8(%rsi),%rax
21491 12: movq 7*8(%rsi),%r11
21492 13: movnti %r8,4*8(%rdi)
21493 14: movnti %r9,5*8(%rdi)
21494-15: movnti %r10,6*8(%rdi)
21495+15: movnti %rax,6*8(%rdi)
21496 16: movnti %r11,7*8(%rdi)
21497 leaq 64(%rsi),%rsi
21498 leaq 64(%rdi),%rdi
21499@@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21500 jnz 21b
21501 23: xorl %eax,%eax
21502 sfence
21503+ pax_force_retaddr
21504 ret
21505
21506 .section .fixup,"ax"
21507diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21508index 2419d5f..953ee51 100644
21509--- a/arch/x86/lib/csum-copy_64.S
21510+++ b/arch/x86/lib/csum-copy_64.S
21511@@ -9,6 +9,7 @@
21512 #include <asm/dwarf2.h>
21513 #include <asm/errno.h>
21514 #include <asm/asm.h>
21515+#include <asm/alternative-asm.h>
21516
21517 /*
21518 * Checksum copy with exception handling.
21519@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21520 CFI_RESTORE rbp
21521 addq $7*8, %rsp
21522 CFI_ADJUST_CFA_OFFSET -7*8
21523+ pax_force_retaddr 0, 1
21524 ret
21525 CFI_RESTORE_STATE
21526
21527diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21528index 25b7ae8..3b52ccd 100644
21529--- a/arch/x86/lib/csum-wrappers_64.c
21530+++ b/arch/x86/lib/csum-wrappers_64.c
21531@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21532 len -= 2;
21533 }
21534 }
21535- isum = csum_partial_copy_generic((__force const void *)src,
21536+
21537+#ifdef CONFIG_PAX_MEMORY_UDEREF
21538+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21539+ src += PAX_USER_SHADOW_BASE;
21540+#endif
21541+
21542+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
21543 dst, len, isum, errp, NULL);
21544 if (unlikely(*errp))
21545 goto out_err;
21546@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21547 }
21548
21549 *errp = 0;
21550- return csum_partial_copy_generic(src, (void __force *)dst,
21551+
21552+#ifdef CONFIG_PAX_MEMORY_UDEREF
21553+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21554+ dst += PAX_USER_SHADOW_BASE;
21555+#endif
21556+
21557+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21558 len, isum, NULL, errp);
21559 }
21560 EXPORT_SYMBOL(csum_partial_copy_to_user);
21561diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21562index b33b1fb..219f389 100644
21563--- a/arch/x86/lib/getuser.S
21564+++ b/arch/x86/lib/getuser.S
21565@@ -33,15 +33,38 @@
21566 #include <asm/asm-offsets.h>
21567 #include <asm/thread_info.h>
21568 #include <asm/asm.h>
21569+#include <asm/segment.h>
21570+#include <asm/pgtable.h>
21571+#include <asm/alternative-asm.h>
21572+
21573+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21574+#define __copyuser_seg gs;
21575+#else
21576+#define __copyuser_seg
21577+#endif
21578
21579 .text
21580 ENTRY(__get_user_1)
21581 CFI_STARTPROC
21582+
21583+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21584 GET_THREAD_INFO(%_ASM_DX)
21585 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21586 jae bad_get_user
21587-1: movzb (%_ASM_AX),%edx
21588+
21589+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21590+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21591+ cmp %_ASM_DX,%_ASM_AX
21592+ jae 1234f
21593+ add %_ASM_DX,%_ASM_AX
21594+1234:
21595+#endif
21596+
21597+#endif
21598+
21599+1: __copyuser_seg movzb (%_ASM_AX),%edx
21600 xor %eax,%eax
21601+ pax_force_retaddr
21602 ret
21603 CFI_ENDPROC
21604 ENDPROC(__get_user_1)
21605@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21606 ENTRY(__get_user_2)
21607 CFI_STARTPROC
21608 add $1,%_ASM_AX
21609+
21610+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21611 jc bad_get_user
21612 GET_THREAD_INFO(%_ASM_DX)
21613 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21614 jae bad_get_user
21615-2: movzwl -1(%_ASM_AX),%edx
21616+
21617+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21618+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21619+ cmp %_ASM_DX,%_ASM_AX
21620+ jae 1234f
21621+ add %_ASM_DX,%_ASM_AX
21622+1234:
21623+#endif
21624+
21625+#endif
21626+
21627+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21628 xor %eax,%eax
21629+ pax_force_retaddr
21630 ret
21631 CFI_ENDPROC
21632 ENDPROC(__get_user_2)
21633@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21634 ENTRY(__get_user_4)
21635 CFI_STARTPROC
21636 add $3,%_ASM_AX
21637+
21638+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21639 jc bad_get_user
21640 GET_THREAD_INFO(%_ASM_DX)
21641 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21642 jae bad_get_user
21643-3: mov -3(%_ASM_AX),%edx
21644+
21645+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21646+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21647+ cmp %_ASM_DX,%_ASM_AX
21648+ jae 1234f
21649+ add %_ASM_DX,%_ASM_AX
21650+1234:
21651+#endif
21652+
21653+#endif
21654+
21655+3: __copyuser_seg mov -3(%_ASM_AX),%edx
21656 xor %eax,%eax
21657+ pax_force_retaddr
21658 ret
21659 CFI_ENDPROC
21660 ENDPROC(__get_user_4)
21661@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21662 GET_THREAD_INFO(%_ASM_DX)
21663 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21664 jae bad_get_user
21665+
21666+#ifdef CONFIG_PAX_MEMORY_UDEREF
21667+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21668+ cmp %_ASM_DX,%_ASM_AX
21669+ jae 1234f
21670+ add %_ASM_DX,%_ASM_AX
21671+1234:
21672+#endif
21673+
21674 4: movq -7(%_ASM_AX),%_ASM_DX
21675 xor %eax,%eax
21676+ pax_force_retaddr
21677 ret
21678 CFI_ENDPROC
21679 ENDPROC(__get_user_8)
21680@@ -91,6 +152,7 @@ bad_get_user:
21681 CFI_STARTPROC
21682 xor %edx,%edx
21683 mov $(-EFAULT),%_ASM_AX
21684+ pax_force_retaddr
21685 ret
21686 CFI_ENDPROC
21687 END(bad_get_user)
21688diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21689index b1e6c4b..21ae8fc 100644
21690--- a/arch/x86/lib/insn.c
21691+++ b/arch/x86/lib/insn.c
21692@@ -21,6 +21,11 @@
21693 #include <linux/string.h>
21694 #include <asm/inat.h>
21695 #include <asm/insn.h>
21696+#ifdef __KERNEL__
21697+#include <asm/pgtable_types.h>
21698+#else
21699+#define ktla_ktva(addr) addr
21700+#endif
21701
21702 /* Verify next sizeof(t) bytes can be on the same instruction */
21703 #define validate_next(t, insn, n) \
21704@@ -49,8 +54,8 @@
21705 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21706 {
21707 memset(insn, 0, sizeof(*insn));
21708- insn->kaddr = kaddr;
21709- insn->next_byte = kaddr;
21710+ insn->kaddr = ktla_ktva(kaddr);
21711+ insn->next_byte = ktla_ktva(kaddr);
21712 insn->x86_64 = x86_64 ? 1 : 0;
21713 insn->opnd_bytes = 4;
21714 if (x86_64)
21715diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21716index 05a95e7..326f2fa 100644
21717--- a/arch/x86/lib/iomap_copy_64.S
21718+++ b/arch/x86/lib/iomap_copy_64.S
21719@@ -17,6 +17,7 @@
21720
21721 #include <linux/linkage.h>
21722 #include <asm/dwarf2.h>
21723+#include <asm/alternative-asm.h>
21724
21725 /*
21726 * override generic version in lib/iomap_copy.c
21727@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21728 CFI_STARTPROC
21729 movl %edx,%ecx
21730 rep movsd
21731+ pax_force_retaddr
21732 ret
21733 CFI_ENDPROC
21734 ENDPROC(__iowrite32_copy)
21735diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21736index 1c273be..da9cc0e 100644
21737--- a/arch/x86/lib/memcpy_64.S
21738+++ b/arch/x86/lib/memcpy_64.S
21739@@ -33,6 +33,7 @@
21740 rep movsq
21741 movl %edx, %ecx
21742 rep movsb
21743+ pax_force_retaddr
21744 ret
21745 .Lmemcpy_e:
21746 .previous
21747@@ -49,6 +50,7 @@
21748 movq %rdi, %rax
21749 movq %rdx, %rcx
21750 rep movsb
21751+ pax_force_retaddr
21752 ret
21753 .Lmemcpy_e_e:
21754 .previous
21755@@ -76,13 +78,13 @@ ENTRY(memcpy)
21756 */
21757 movq 0*8(%rsi), %r8
21758 movq 1*8(%rsi), %r9
21759- movq 2*8(%rsi), %r10
21760+ movq 2*8(%rsi), %rcx
21761 movq 3*8(%rsi), %r11
21762 leaq 4*8(%rsi), %rsi
21763
21764 movq %r8, 0*8(%rdi)
21765 movq %r9, 1*8(%rdi)
21766- movq %r10, 2*8(%rdi)
21767+ movq %rcx, 2*8(%rdi)
21768 movq %r11, 3*8(%rdi)
21769 leaq 4*8(%rdi), %rdi
21770 jae .Lcopy_forward_loop
21771@@ -105,12 +107,12 @@ ENTRY(memcpy)
21772 subq $0x20, %rdx
21773 movq -1*8(%rsi), %r8
21774 movq -2*8(%rsi), %r9
21775- movq -3*8(%rsi), %r10
21776+ movq -3*8(%rsi), %rcx
21777 movq -4*8(%rsi), %r11
21778 leaq -4*8(%rsi), %rsi
21779 movq %r8, -1*8(%rdi)
21780 movq %r9, -2*8(%rdi)
21781- movq %r10, -3*8(%rdi)
21782+ movq %rcx, -3*8(%rdi)
21783 movq %r11, -4*8(%rdi)
21784 leaq -4*8(%rdi), %rdi
21785 jae .Lcopy_backward_loop
21786@@ -130,12 +132,13 @@ ENTRY(memcpy)
21787 */
21788 movq 0*8(%rsi), %r8
21789 movq 1*8(%rsi), %r9
21790- movq -2*8(%rsi, %rdx), %r10
21791+ movq -2*8(%rsi, %rdx), %rcx
21792 movq -1*8(%rsi, %rdx), %r11
21793 movq %r8, 0*8(%rdi)
21794 movq %r9, 1*8(%rdi)
21795- movq %r10, -2*8(%rdi, %rdx)
21796+ movq %rcx, -2*8(%rdi, %rdx)
21797 movq %r11, -1*8(%rdi, %rdx)
21798+ pax_force_retaddr
21799 retq
21800 .p2align 4
21801 .Lless_16bytes:
21802@@ -148,6 +151,7 @@ ENTRY(memcpy)
21803 movq -1*8(%rsi, %rdx), %r9
21804 movq %r8, 0*8(%rdi)
21805 movq %r9, -1*8(%rdi, %rdx)
21806+ pax_force_retaddr
21807 retq
21808 .p2align 4
21809 .Lless_8bytes:
21810@@ -161,6 +165,7 @@ ENTRY(memcpy)
21811 movl -4(%rsi, %rdx), %r8d
21812 movl %ecx, (%rdi)
21813 movl %r8d, -4(%rdi, %rdx)
21814+ pax_force_retaddr
21815 retq
21816 .p2align 4
21817 .Lless_3bytes:
21818@@ -179,6 +184,7 @@ ENTRY(memcpy)
21819 movb %cl, (%rdi)
21820
21821 .Lend:
21822+ pax_force_retaddr
21823 retq
21824 CFI_ENDPROC
21825 ENDPROC(memcpy)
21826diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21827index ee16461..c39c199 100644
21828--- a/arch/x86/lib/memmove_64.S
21829+++ b/arch/x86/lib/memmove_64.S
21830@@ -61,13 +61,13 @@ ENTRY(memmove)
21831 5:
21832 sub $0x20, %rdx
21833 movq 0*8(%rsi), %r11
21834- movq 1*8(%rsi), %r10
21835+ movq 1*8(%rsi), %rcx
21836 movq 2*8(%rsi), %r9
21837 movq 3*8(%rsi), %r8
21838 leaq 4*8(%rsi), %rsi
21839
21840 movq %r11, 0*8(%rdi)
21841- movq %r10, 1*8(%rdi)
21842+ movq %rcx, 1*8(%rdi)
21843 movq %r9, 2*8(%rdi)
21844 movq %r8, 3*8(%rdi)
21845 leaq 4*8(%rdi), %rdi
21846@@ -81,10 +81,10 @@ ENTRY(memmove)
21847 4:
21848 movq %rdx, %rcx
21849 movq -8(%rsi, %rdx), %r11
21850- lea -8(%rdi, %rdx), %r10
21851+ lea -8(%rdi, %rdx), %r9
21852 shrq $3, %rcx
21853 rep movsq
21854- movq %r11, (%r10)
21855+ movq %r11, (%r9)
21856 jmp 13f
21857 .Lmemmove_end_forward:
21858
21859@@ -95,14 +95,14 @@ ENTRY(memmove)
21860 7:
21861 movq %rdx, %rcx
21862 movq (%rsi), %r11
21863- movq %rdi, %r10
21864+ movq %rdi, %r9
21865 leaq -8(%rsi, %rdx), %rsi
21866 leaq -8(%rdi, %rdx), %rdi
21867 shrq $3, %rcx
21868 std
21869 rep movsq
21870 cld
21871- movq %r11, (%r10)
21872+ movq %r11, (%r9)
21873 jmp 13f
21874
21875 /*
21876@@ -127,13 +127,13 @@ ENTRY(memmove)
21877 8:
21878 subq $0x20, %rdx
21879 movq -1*8(%rsi), %r11
21880- movq -2*8(%rsi), %r10
21881+ movq -2*8(%rsi), %rcx
21882 movq -3*8(%rsi), %r9
21883 movq -4*8(%rsi), %r8
21884 leaq -4*8(%rsi), %rsi
21885
21886 movq %r11, -1*8(%rdi)
21887- movq %r10, -2*8(%rdi)
21888+ movq %rcx, -2*8(%rdi)
21889 movq %r9, -3*8(%rdi)
21890 movq %r8, -4*8(%rdi)
21891 leaq -4*8(%rdi), %rdi
21892@@ -151,11 +151,11 @@ ENTRY(memmove)
21893 * Move data from 16 bytes to 31 bytes.
21894 */
21895 movq 0*8(%rsi), %r11
21896- movq 1*8(%rsi), %r10
21897+ movq 1*8(%rsi), %rcx
21898 movq -2*8(%rsi, %rdx), %r9
21899 movq -1*8(%rsi, %rdx), %r8
21900 movq %r11, 0*8(%rdi)
21901- movq %r10, 1*8(%rdi)
21902+ movq %rcx, 1*8(%rdi)
21903 movq %r9, -2*8(%rdi, %rdx)
21904 movq %r8, -1*8(%rdi, %rdx)
21905 jmp 13f
21906@@ -167,9 +167,9 @@ ENTRY(memmove)
21907 * Move data from 8 bytes to 15 bytes.
21908 */
21909 movq 0*8(%rsi), %r11
21910- movq -1*8(%rsi, %rdx), %r10
21911+ movq -1*8(%rsi, %rdx), %r9
21912 movq %r11, 0*8(%rdi)
21913- movq %r10, -1*8(%rdi, %rdx)
21914+ movq %r9, -1*8(%rdi, %rdx)
21915 jmp 13f
21916 10:
21917 cmpq $4, %rdx
21918@@ -178,9 +178,9 @@ ENTRY(memmove)
21919 * Move data from 4 bytes to 7 bytes.
21920 */
21921 movl (%rsi), %r11d
21922- movl -4(%rsi, %rdx), %r10d
21923+ movl -4(%rsi, %rdx), %r9d
21924 movl %r11d, (%rdi)
21925- movl %r10d, -4(%rdi, %rdx)
21926+ movl %r9d, -4(%rdi, %rdx)
21927 jmp 13f
21928 11:
21929 cmp $2, %rdx
21930@@ -189,9 +189,9 @@ ENTRY(memmove)
21931 * Move data from 2 bytes to 3 bytes.
21932 */
21933 movw (%rsi), %r11w
21934- movw -2(%rsi, %rdx), %r10w
21935+ movw -2(%rsi, %rdx), %r9w
21936 movw %r11w, (%rdi)
21937- movw %r10w, -2(%rdi, %rdx)
21938+ movw %r9w, -2(%rdi, %rdx)
21939 jmp 13f
21940 12:
21941 cmp $1, %rdx
21942@@ -202,6 +202,7 @@ ENTRY(memmove)
21943 movb (%rsi), %r11b
21944 movb %r11b, (%rdi)
21945 13:
21946+ pax_force_retaddr
21947 retq
21948 CFI_ENDPROC
21949
21950@@ -210,6 +211,7 @@ ENTRY(memmove)
21951 /* Forward moving data. */
21952 movq %rdx, %rcx
21953 rep movsb
21954+ pax_force_retaddr
21955 retq
21956 .Lmemmove_end_forward_efs:
21957 .previous
21958diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
21959index 2dcb380..963660a 100644
21960--- a/arch/x86/lib/memset_64.S
21961+++ b/arch/x86/lib/memset_64.S
21962@@ -30,6 +30,7 @@
21963 movl %edx,%ecx
21964 rep stosb
21965 movq %r9,%rax
21966+ pax_force_retaddr
21967 ret
21968 .Lmemset_e:
21969 .previous
21970@@ -52,6 +53,7 @@
21971 movq %rdx,%rcx
21972 rep stosb
21973 movq %r9,%rax
21974+ pax_force_retaddr
21975 ret
21976 .Lmemset_e_e:
21977 .previous
21978@@ -59,7 +61,7 @@
21979 ENTRY(memset)
21980 ENTRY(__memset)
21981 CFI_STARTPROC
21982- movq %rdi,%r10
21983+ movq %rdi,%r11
21984
21985 /* expand byte value */
21986 movzbl %sil,%ecx
21987@@ -117,7 +119,8 @@ ENTRY(__memset)
21988 jnz .Lloop_1
21989
21990 .Lende:
21991- movq %r10,%rax
21992+ movq %r11,%rax
21993+ pax_force_retaddr
21994 ret
21995
21996 CFI_RESTORE_STATE
21997diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
21998index c9f2d9b..e7fd2c0 100644
21999--- a/arch/x86/lib/mmx_32.c
22000+++ b/arch/x86/lib/mmx_32.c
22001@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22002 {
22003 void *p;
22004 int i;
22005+ unsigned long cr0;
22006
22007 if (unlikely(in_interrupt()))
22008 return __memcpy(to, from, len);
22009@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22010 kernel_fpu_begin();
22011
22012 __asm__ __volatile__ (
22013- "1: prefetch (%0)\n" /* This set is 28 bytes */
22014- " prefetch 64(%0)\n"
22015- " prefetch 128(%0)\n"
22016- " prefetch 192(%0)\n"
22017- " prefetch 256(%0)\n"
22018+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22019+ " prefetch 64(%1)\n"
22020+ " prefetch 128(%1)\n"
22021+ " prefetch 192(%1)\n"
22022+ " prefetch 256(%1)\n"
22023 "2: \n"
22024 ".section .fixup, \"ax\"\n"
22025- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22026+ "3: \n"
22027+
22028+#ifdef CONFIG_PAX_KERNEXEC
22029+ " movl %%cr0, %0\n"
22030+ " movl %0, %%eax\n"
22031+ " andl $0xFFFEFFFF, %%eax\n"
22032+ " movl %%eax, %%cr0\n"
22033+#endif
22034+
22035+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22036+
22037+#ifdef CONFIG_PAX_KERNEXEC
22038+ " movl %0, %%cr0\n"
22039+#endif
22040+
22041 " jmp 2b\n"
22042 ".previous\n"
22043 _ASM_EXTABLE(1b, 3b)
22044- : : "r" (from));
22045+ : "=&r" (cr0) : "r" (from) : "ax");
22046
22047 for ( ; i > 5; i--) {
22048 __asm__ __volatile__ (
22049- "1: prefetch 320(%0)\n"
22050- "2: movq (%0), %%mm0\n"
22051- " movq 8(%0), %%mm1\n"
22052- " movq 16(%0), %%mm2\n"
22053- " movq 24(%0), %%mm3\n"
22054- " movq %%mm0, (%1)\n"
22055- " movq %%mm1, 8(%1)\n"
22056- " movq %%mm2, 16(%1)\n"
22057- " movq %%mm3, 24(%1)\n"
22058- " movq 32(%0), %%mm0\n"
22059- " movq 40(%0), %%mm1\n"
22060- " movq 48(%0), %%mm2\n"
22061- " movq 56(%0), %%mm3\n"
22062- " movq %%mm0, 32(%1)\n"
22063- " movq %%mm1, 40(%1)\n"
22064- " movq %%mm2, 48(%1)\n"
22065- " movq %%mm3, 56(%1)\n"
22066+ "1: prefetch 320(%1)\n"
22067+ "2: movq (%1), %%mm0\n"
22068+ " movq 8(%1), %%mm1\n"
22069+ " movq 16(%1), %%mm2\n"
22070+ " movq 24(%1), %%mm3\n"
22071+ " movq %%mm0, (%2)\n"
22072+ " movq %%mm1, 8(%2)\n"
22073+ " movq %%mm2, 16(%2)\n"
22074+ " movq %%mm3, 24(%2)\n"
22075+ " movq 32(%1), %%mm0\n"
22076+ " movq 40(%1), %%mm1\n"
22077+ " movq 48(%1), %%mm2\n"
22078+ " movq 56(%1), %%mm3\n"
22079+ " movq %%mm0, 32(%2)\n"
22080+ " movq %%mm1, 40(%2)\n"
22081+ " movq %%mm2, 48(%2)\n"
22082+ " movq %%mm3, 56(%2)\n"
22083 ".section .fixup, \"ax\"\n"
22084- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22085+ "3:\n"
22086+
22087+#ifdef CONFIG_PAX_KERNEXEC
22088+ " movl %%cr0, %0\n"
22089+ " movl %0, %%eax\n"
22090+ " andl $0xFFFEFFFF, %%eax\n"
22091+ " movl %%eax, %%cr0\n"
22092+#endif
22093+
22094+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22095+
22096+#ifdef CONFIG_PAX_KERNEXEC
22097+ " movl %0, %%cr0\n"
22098+#endif
22099+
22100 " jmp 2b\n"
22101 ".previous\n"
22102 _ASM_EXTABLE(1b, 3b)
22103- : : "r" (from), "r" (to) : "memory");
22104+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22105
22106 from += 64;
22107 to += 64;
22108@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22109 static void fast_copy_page(void *to, void *from)
22110 {
22111 int i;
22112+ unsigned long cr0;
22113
22114 kernel_fpu_begin();
22115
22116@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22117 * but that is for later. -AV
22118 */
22119 __asm__ __volatile__(
22120- "1: prefetch (%0)\n"
22121- " prefetch 64(%0)\n"
22122- " prefetch 128(%0)\n"
22123- " prefetch 192(%0)\n"
22124- " prefetch 256(%0)\n"
22125+ "1: prefetch (%1)\n"
22126+ " prefetch 64(%1)\n"
22127+ " prefetch 128(%1)\n"
22128+ " prefetch 192(%1)\n"
22129+ " prefetch 256(%1)\n"
22130 "2: \n"
22131 ".section .fixup, \"ax\"\n"
22132- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22133+ "3: \n"
22134+
22135+#ifdef CONFIG_PAX_KERNEXEC
22136+ " movl %%cr0, %0\n"
22137+ " movl %0, %%eax\n"
22138+ " andl $0xFFFEFFFF, %%eax\n"
22139+ " movl %%eax, %%cr0\n"
22140+#endif
22141+
22142+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22143+
22144+#ifdef CONFIG_PAX_KERNEXEC
22145+ " movl %0, %%cr0\n"
22146+#endif
22147+
22148 " jmp 2b\n"
22149 ".previous\n"
22150- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22151+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22152
22153 for (i = 0; i < (4096-320)/64; i++) {
22154 __asm__ __volatile__ (
22155- "1: prefetch 320(%0)\n"
22156- "2: movq (%0), %%mm0\n"
22157- " movntq %%mm0, (%1)\n"
22158- " movq 8(%0), %%mm1\n"
22159- " movntq %%mm1, 8(%1)\n"
22160- " movq 16(%0), %%mm2\n"
22161- " movntq %%mm2, 16(%1)\n"
22162- " movq 24(%0), %%mm3\n"
22163- " movntq %%mm3, 24(%1)\n"
22164- " movq 32(%0), %%mm4\n"
22165- " movntq %%mm4, 32(%1)\n"
22166- " movq 40(%0), %%mm5\n"
22167- " movntq %%mm5, 40(%1)\n"
22168- " movq 48(%0), %%mm6\n"
22169- " movntq %%mm6, 48(%1)\n"
22170- " movq 56(%0), %%mm7\n"
22171- " movntq %%mm7, 56(%1)\n"
22172+ "1: prefetch 320(%1)\n"
22173+ "2: movq (%1), %%mm0\n"
22174+ " movntq %%mm0, (%2)\n"
22175+ " movq 8(%1), %%mm1\n"
22176+ " movntq %%mm1, 8(%2)\n"
22177+ " movq 16(%1), %%mm2\n"
22178+ " movntq %%mm2, 16(%2)\n"
22179+ " movq 24(%1), %%mm3\n"
22180+ " movntq %%mm3, 24(%2)\n"
22181+ " movq 32(%1), %%mm4\n"
22182+ " movntq %%mm4, 32(%2)\n"
22183+ " movq 40(%1), %%mm5\n"
22184+ " movntq %%mm5, 40(%2)\n"
22185+ " movq 48(%1), %%mm6\n"
22186+ " movntq %%mm6, 48(%2)\n"
22187+ " movq 56(%1), %%mm7\n"
22188+ " movntq %%mm7, 56(%2)\n"
22189 ".section .fixup, \"ax\"\n"
22190- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22191+ "3:\n"
22192+
22193+#ifdef CONFIG_PAX_KERNEXEC
22194+ " movl %%cr0, %0\n"
22195+ " movl %0, %%eax\n"
22196+ " andl $0xFFFEFFFF, %%eax\n"
22197+ " movl %%eax, %%cr0\n"
22198+#endif
22199+
22200+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22201+
22202+#ifdef CONFIG_PAX_KERNEXEC
22203+ " movl %0, %%cr0\n"
22204+#endif
22205+
22206 " jmp 2b\n"
22207 ".previous\n"
22208- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22209+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22210
22211 from += 64;
22212 to += 64;
22213@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22214 static void fast_copy_page(void *to, void *from)
22215 {
22216 int i;
22217+ unsigned long cr0;
22218
22219 kernel_fpu_begin();
22220
22221 __asm__ __volatile__ (
22222- "1: prefetch (%0)\n"
22223- " prefetch 64(%0)\n"
22224- " prefetch 128(%0)\n"
22225- " prefetch 192(%0)\n"
22226- " prefetch 256(%0)\n"
22227+ "1: prefetch (%1)\n"
22228+ " prefetch 64(%1)\n"
22229+ " prefetch 128(%1)\n"
22230+ " prefetch 192(%1)\n"
22231+ " prefetch 256(%1)\n"
22232 "2: \n"
22233 ".section .fixup, \"ax\"\n"
22234- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22235+ "3: \n"
22236+
22237+#ifdef CONFIG_PAX_KERNEXEC
22238+ " movl %%cr0, %0\n"
22239+ " movl %0, %%eax\n"
22240+ " andl $0xFFFEFFFF, %%eax\n"
22241+ " movl %%eax, %%cr0\n"
22242+#endif
22243+
22244+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22245+
22246+#ifdef CONFIG_PAX_KERNEXEC
22247+ " movl %0, %%cr0\n"
22248+#endif
22249+
22250 " jmp 2b\n"
22251 ".previous\n"
22252- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22253+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22254
22255 for (i = 0; i < 4096/64; i++) {
22256 __asm__ __volatile__ (
22257- "1: prefetch 320(%0)\n"
22258- "2: movq (%0), %%mm0\n"
22259- " movq 8(%0), %%mm1\n"
22260- " movq 16(%0), %%mm2\n"
22261- " movq 24(%0), %%mm3\n"
22262- " movq %%mm0, (%1)\n"
22263- " movq %%mm1, 8(%1)\n"
22264- " movq %%mm2, 16(%1)\n"
22265- " movq %%mm3, 24(%1)\n"
22266- " movq 32(%0), %%mm0\n"
22267- " movq 40(%0), %%mm1\n"
22268- " movq 48(%0), %%mm2\n"
22269- " movq 56(%0), %%mm3\n"
22270- " movq %%mm0, 32(%1)\n"
22271- " movq %%mm1, 40(%1)\n"
22272- " movq %%mm2, 48(%1)\n"
22273- " movq %%mm3, 56(%1)\n"
22274+ "1: prefetch 320(%1)\n"
22275+ "2: movq (%1), %%mm0\n"
22276+ " movq 8(%1), %%mm1\n"
22277+ " movq 16(%1), %%mm2\n"
22278+ " movq 24(%1), %%mm3\n"
22279+ " movq %%mm0, (%2)\n"
22280+ " movq %%mm1, 8(%2)\n"
22281+ " movq %%mm2, 16(%2)\n"
22282+ " movq %%mm3, 24(%2)\n"
22283+ " movq 32(%1), %%mm0\n"
22284+ " movq 40(%1), %%mm1\n"
22285+ " movq 48(%1), %%mm2\n"
22286+ " movq 56(%1), %%mm3\n"
22287+ " movq %%mm0, 32(%2)\n"
22288+ " movq %%mm1, 40(%2)\n"
22289+ " movq %%mm2, 48(%2)\n"
22290+ " movq %%mm3, 56(%2)\n"
22291 ".section .fixup, \"ax\"\n"
22292- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22293+ "3:\n"
22294+
22295+#ifdef CONFIG_PAX_KERNEXEC
22296+ " movl %%cr0, %0\n"
22297+ " movl %0, %%eax\n"
22298+ " andl $0xFFFEFFFF, %%eax\n"
22299+ " movl %%eax, %%cr0\n"
22300+#endif
22301+
22302+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22303+
22304+#ifdef CONFIG_PAX_KERNEXEC
22305+ " movl %0, %%cr0\n"
22306+#endif
22307+
22308 " jmp 2b\n"
22309 ".previous\n"
22310 _ASM_EXTABLE(1b, 3b)
22311- : : "r" (from), "r" (to) : "memory");
22312+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22313
22314 from += 64;
22315 to += 64;
22316diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22317index 69fa106..adda88b 100644
22318--- a/arch/x86/lib/msr-reg.S
22319+++ b/arch/x86/lib/msr-reg.S
22320@@ -3,6 +3,7 @@
22321 #include <asm/dwarf2.h>
22322 #include <asm/asm.h>
22323 #include <asm/msr.h>
22324+#include <asm/alternative-asm.h>
22325
22326 #ifdef CONFIG_X86_64
22327 /*
22328@@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22329 CFI_STARTPROC
22330 pushq_cfi %rbx
22331 pushq_cfi %rbp
22332- movq %rdi, %r10 /* Save pointer */
22333+ movq %rdi, %r9 /* Save pointer */
22334 xorl %r11d, %r11d /* Return value */
22335 movl (%rdi), %eax
22336 movl 4(%rdi), %ecx
22337@@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22338 movl 28(%rdi), %edi
22339 CFI_REMEMBER_STATE
22340 1: \op
22341-2: movl %eax, (%r10)
22342+2: movl %eax, (%r9)
22343 movl %r11d, %eax /* Return value */
22344- movl %ecx, 4(%r10)
22345- movl %edx, 8(%r10)
22346- movl %ebx, 12(%r10)
22347- movl %ebp, 20(%r10)
22348- movl %esi, 24(%r10)
22349- movl %edi, 28(%r10)
22350+ movl %ecx, 4(%r9)
22351+ movl %edx, 8(%r9)
22352+ movl %ebx, 12(%r9)
22353+ movl %ebp, 20(%r9)
22354+ movl %esi, 24(%r9)
22355+ movl %edi, 28(%r9)
22356 popq_cfi %rbp
22357 popq_cfi %rbx
22358+ pax_force_retaddr
22359 ret
22360 3:
22361 CFI_RESTORE_STATE
22362diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22363index 7f951c8..ebd573a 100644
22364--- a/arch/x86/lib/putuser.S
22365+++ b/arch/x86/lib/putuser.S
22366@@ -15,7 +15,9 @@
22367 #include <asm/thread_info.h>
22368 #include <asm/errno.h>
22369 #include <asm/asm.h>
22370-
22371+#include <asm/segment.h>
22372+#include <asm/pgtable.h>
22373+#include <asm/alternative-asm.h>
22374
22375 /*
22376 * __put_user_X
22377@@ -29,52 +31,119 @@
22378 * as they get called from within inline assembly.
22379 */
22380
22381-#define ENTER CFI_STARTPROC ; \
22382- GET_THREAD_INFO(%_ASM_BX)
22383-#define EXIT ret ; \
22384+#define ENTER CFI_STARTPROC
22385+#define EXIT pax_force_retaddr; ret ; \
22386 CFI_ENDPROC
22387
22388+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22389+#define _DEST %_ASM_CX,%_ASM_BX
22390+#else
22391+#define _DEST %_ASM_CX
22392+#endif
22393+
22394+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22395+#define __copyuser_seg gs;
22396+#else
22397+#define __copyuser_seg
22398+#endif
22399+
22400 .text
22401 ENTRY(__put_user_1)
22402 ENTER
22403+
22404+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22405+ GET_THREAD_INFO(%_ASM_BX)
22406 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22407 jae bad_put_user
22408-1: movb %al,(%_ASM_CX)
22409+
22410+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22411+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22412+ cmp %_ASM_BX,%_ASM_CX
22413+ jb 1234f
22414+ xor %ebx,%ebx
22415+1234:
22416+#endif
22417+
22418+#endif
22419+
22420+1: __copyuser_seg movb %al,(_DEST)
22421 xor %eax,%eax
22422 EXIT
22423 ENDPROC(__put_user_1)
22424
22425 ENTRY(__put_user_2)
22426 ENTER
22427+
22428+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22429+ GET_THREAD_INFO(%_ASM_BX)
22430 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22431 sub $1,%_ASM_BX
22432 cmp %_ASM_BX,%_ASM_CX
22433 jae bad_put_user
22434-2: movw %ax,(%_ASM_CX)
22435+
22436+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22437+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22438+ cmp %_ASM_BX,%_ASM_CX
22439+ jb 1234f
22440+ xor %ebx,%ebx
22441+1234:
22442+#endif
22443+
22444+#endif
22445+
22446+2: __copyuser_seg movw %ax,(_DEST)
22447 xor %eax,%eax
22448 EXIT
22449 ENDPROC(__put_user_2)
22450
22451 ENTRY(__put_user_4)
22452 ENTER
22453+
22454+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22455+ GET_THREAD_INFO(%_ASM_BX)
22456 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22457 sub $3,%_ASM_BX
22458 cmp %_ASM_BX,%_ASM_CX
22459 jae bad_put_user
22460-3: movl %eax,(%_ASM_CX)
22461+
22462+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22463+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22464+ cmp %_ASM_BX,%_ASM_CX
22465+ jb 1234f
22466+ xor %ebx,%ebx
22467+1234:
22468+#endif
22469+
22470+#endif
22471+
22472+3: __copyuser_seg movl %eax,(_DEST)
22473 xor %eax,%eax
22474 EXIT
22475 ENDPROC(__put_user_4)
22476
22477 ENTRY(__put_user_8)
22478 ENTER
22479+
22480+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22481+ GET_THREAD_INFO(%_ASM_BX)
22482 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22483 sub $7,%_ASM_BX
22484 cmp %_ASM_BX,%_ASM_CX
22485 jae bad_put_user
22486-4: mov %_ASM_AX,(%_ASM_CX)
22487+
22488+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22489+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22490+ cmp %_ASM_BX,%_ASM_CX
22491+ jb 1234f
22492+ xor %ebx,%ebx
22493+1234:
22494+#endif
22495+
22496+#endif
22497+
22498+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22499 #ifdef CONFIG_X86_32
22500-5: movl %edx,4(%_ASM_CX)
22501+5: __copyuser_seg movl %edx,4(_DEST)
22502 #endif
22503 xor %eax,%eax
22504 EXIT
22505diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22506index 1cad221..de671ee 100644
22507--- a/arch/x86/lib/rwlock.S
22508+++ b/arch/x86/lib/rwlock.S
22509@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22510 FRAME
22511 0: LOCK_PREFIX
22512 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22513+
22514+#ifdef CONFIG_PAX_REFCOUNT
22515+ jno 1234f
22516+ LOCK_PREFIX
22517+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22518+ int $4
22519+1234:
22520+ _ASM_EXTABLE(1234b, 1234b)
22521+#endif
22522+
22523 1: rep; nop
22524 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22525 jne 1b
22526 LOCK_PREFIX
22527 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22528+
22529+#ifdef CONFIG_PAX_REFCOUNT
22530+ jno 1234f
22531+ LOCK_PREFIX
22532+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22533+ int $4
22534+1234:
22535+ _ASM_EXTABLE(1234b, 1234b)
22536+#endif
22537+
22538 jnz 0b
22539 ENDFRAME
22540+ pax_force_retaddr
22541 ret
22542 CFI_ENDPROC
22543 END(__write_lock_failed)
22544@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22545 FRAME
22546 0: LOCK_PREFIX
22547 READ_LOCK_SIZE(inc) (%__lock_ptr)
22548+
22549+#ifdef CONFIG_PAX_REFCOUNT
22550+ jno 1234f
22551+ LOCK_PREFIX
22552+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22553+ int $4
22554+1234:
22555+ _ASM_EXTABLE(1234b, 1234b)
22556+#endif
22557+
22558 1: rep; nop
22559 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22560 js 1b
22561 LOCK_PREFIX
22562 READ_LOCK_SIZE(dec) (%__lock_ptr)
22563+
22564+#ifdef CONFIG_PAX_REFCOUNT
22565+ jno 1234f
22566+ LOCK_PREFIX
22567+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22568+ int $4
22569+1234:
22570+ _ASM_EXTABLE(1234b, 1234b)
22571+#endif
22572+
22573 js 0b
22574 ENDFRAME
22575+ pax_force_retaddr
22576 ret
22577 CFI_ENDPROC
22578 END(__read_lock_failed)
22579diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22580index 5dff5f0..cadebf4 100644
22581--- a/arch/x86/lib/rwsem.S
22582+++ b/arch/x86/lib/rwsem.S
22583@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22584 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22585 CFI_RESTORE __ASM_REG(dx)
22586 restore_common_regs
22587+ pax_force_retaddr
22588 ret
22589 CFI_ENDPROC
22590 ENDPROC(call_rwsem_down_read_failed)
22591@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22592 movq %rax,%rdi
22593 call rwsem_down_write_failed
22594 restore_common_regs
22595+ pax_force_retaddr
22596 ret
22597 CFI_ENDPROC
22598 ENDPROC(call_rwsem_down_write_failed)
22599@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22600 movq %rax,%rdi
22601 call rwsem_wake
22602 restore_common_regs
22603-1: ret
22604+1: pax_force_retaddr
22605+ ret
22606 CFI_ENDPROC
22607 ENDPROC(call_rwsem_wake)
22608
22609@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22610 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22611 CFI_RESTORE __ASM_REG(dx)
22612 restore_common_regs
22613+ pax_force_retaddr
22614 ret
22615 CFI_ENDPROC
22616 ENDPROC(call_rwsem_downgrade_wake)
22617diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22618index a63efd6..ccecad8 100644
22619--- a/arch/x86/lib/thunk_64.S
22620+++ b/arch/x86/lib/thunk_64.S
22621@@ -8,6 +8,7 @@
22622 #include <linux/linkage.h>
22623 #include <asm/dwarf2.h>
22624 #include <asm/calling.h>
22625+#include <asm/alternative-asm.h>
22626
22627 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22628 .macro THUNK name, func, put_ret_addr_in_rdi=0
22629@@ -41,5 +42,6 @@
22630 SAVE_ARGS
22631 restore:
22632 RESTORE_ARGS
22633+ pax_force_retaddr
22634 ret
22635 CFI_ENDPROC
22636diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22637index 1781b2f..18e3040 100644
22638--- a/arch/x86/lib/usercopy_32.c
22639+++ b/arch/x86/lib/usercopy_32.c
22640@@ -42,10 +42,12 @@ do { \
22641 int __d0; \
22642 might_fault(); \
22643 __asm__ __volatile__( \
22644+ __COPYUSER_SET_ES \
22645 "0: rep; stosl\n" \
22646 " movl %2,%0\n" \
22647 "1: rep; stosb\n" \
22648 "2:\n" \
22649+ __COPYUSER_RESTORE_ES \
22650 ".section .fixup,\"ax\"\n" \
22651 "3: lea 0(%2,%0,4),%0\n" \
22652 " jmp 2b\n" \
22653@@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22654
22655 #ifdef CONFIG_X86_INTEL_USERCOPY
22656 static unsigned long
22657-__copy_user_intel(void __user *to, const void *from, unsigned long size)
22658+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22659 {
22660 int d0, d1;
22661 __asm__ __volatile__(
22662@@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22663 " .align 2,0x90\n"
22664 "3: movl 0(%4), %%eax\n"
22665 "4: movl 4(%4), %%edx\n"
22666- "5: movl %%eax, 0(%3)\n"
22667- "6: movl %%edx, 4(%3)\n"
22668+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22669+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22670 "7: movl 8(%4), %%eax\n"
22671 "8: movl 12(%4),%%edx\n"
22672- "9: movl %%eax, 8(%3)\n"
22673- "10: movl %%edx, 12(%3)\n"
22674+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22675+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22676 "11: movl 16(%4), %%eax\n"
22677 "12: movl 20(%4), %%edx\n"
22678- "13: movl %%eax, 16(%3)\n"
22679- "14: movl %%edx, 20(%3)\n"
22680+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22681+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22682 "15: movl 24(%4), %%eax\n"
22683 "16: movl 28(%4), %%edx\n"
22684- "17: movl %%eax, 24(%3)\n"
22685- "18: movl %%edx, 28(%3)\n"
22686+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22687+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22688 "19: movl 32(%4), %%eax\n"
22689 "20: movl 36(%4), %%edx\n"
22690- "21: movl %%eax, 32(%3)\n"
22691- "22: movl %%edx, 36(%3)\n"
22692+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22693+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22694 "23: movl 40(%4), %%eax\n"
22695 "24: movl 44(%4), %%edx\n"
22696- "25: movl %%eax, 40(%3)\n"
22697- "26: movl %%edx, 44(%3)\n"
22698+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22699+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22700 "27: movl 48(%4), %%eax\n"
22701 "28: movl 52(%4), %%edx\n"
22702- "29: movl %%eax, 48(%3)\n"
22703- "30: movl %%edx, 52(%3)\n"
22704+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22705+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22706 "31: movl 56(%4), %%eax\n"
22707 "32: movl 60(%4), %%edx\n"
22708- "33: movl %%eax, 56(%3)\n"
22709- "34: movl %%edx, 60(%3)\n"
22710+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22711+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22712 " addl $-64, %0\n"
22713 " addl $64, %4\n"
22714 " addl $64, %3\n"
22715@@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22716 " shrl $2, %0\n"
22717 " andl $3, %%eax\n"
22718 " cld\n"
22719+ __COPYUSER_SET_ES
22720 "99: rep; movsl\n"
22721 "36: movl %%eax, %0\n"
22722 "37: rep; movsb\n"
22723 "100:\n"
22724+ __COPYUSER_RESTORE_ES
22725 ".section .fixup,\"ax\"\n"
22726 "101: lea 0(%%eax,%0,4),%0\n"
22727 " jmp 100b\n"
22728@@ -201,46 +205,152 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22729 }
22730
22731 static unsigned long
22732+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22733+{
22734+ int d0, d1;
22735+ __asm__ __volatile__(
22736+ " .align 2,0x90\n"
22737+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22738+ " cmpl $67, %0\n"
22739+ " jbe 3f\n"
22740+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22741+ " .align 2,0x90\n"
22742+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22743+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22744+ "5: movl %%eax, 0(%3)\n"
22745+ "6: movl %%edx, 4(%3)\n"
22746+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22747+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22748+ "9: movl %%eax, 8(%3)\n"
22749+ "10: movl %%edx, 12(%3)\n"
22750+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22751+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22752+ "13: movl %%eax, 16(%3)\n"
22753+ "14: movl %%edx, 20(%3)\n"
22754+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22755+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22756+ "17: movl %%eax, 24(%3)\n"
22757+ "18: movl %%edx, 28(%3)\n"
22758+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22759+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22760+ "21: movl %%eax, 32(%3)\n"
22761+ "22: movl %%edx, 36(%3)\n"
22762+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22763+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22764+ "25: movl %%eax, 40(%3)\n"
22765+ "26: movl %%edx, 44(%3)\n"
22766+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22767+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22768+ "29: movl %%eax, 48(%3)\n"
22769+ "30: movl %%edx, 52(%3)\n"
22770+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22771+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22772+ "33: movl %%eax, 56(%3)\n"
22773+ "34: movl %%edx, 60(%3)\n"
22774+ " addl $-64, %0\n"
22775+ " addl $64, %4\n"
22776+ " addl $64, %3\n"
22777+ " cmpl $63, %0\n"
22778+ " ja 1b\n"
22779+ "35: movl %0, %%eax\n"
22780+ " shrl $2, %0\n"
22781+ " andl $3, %%eax\n"
22782+ " cld\n"
22783+ "99: rep; "__copyuser_seg" movsl\n"
22784+ "36: movl %%eax, %0\n"
22785+ "37: rep; "__copyuser_seg" movsb\n"
22786+ "100:\n"
22787+ ".section .fixup,\"ax\"\n"
22788+ "101: lea 0(%%eax,%0,4),%0\n"
22789+ " jmp 100b\n"
22790+ ".previous\n"
22791+ _ASM_EXTABLE(1b,100b)
22792+ _ASM_EXTABLE(2b,100b)
22793+ _ASM_EXTABLE(3b,100b)
22794+ _ASM_EXTABLE(4b,100b)
22795+ _ASM_EXTABLE(5b,100b)
22796+ _ASM_EXTABLE(6b,100b)
22797+ _ASM_EXTABLE(7b,100b)
22798+ _ASM_EXTABLE(8b,100b)
22799+ _ASM_EXTABLE(9b,100b)
22800+ _ASM_EXTABLE(10b,100b)
22801+ _ASM_EXTABLE(11b,100b)
22802+ _ASM_EXTABLE(12b,100b)
22803+ _ASM_EXTABLE(13b,100b)
22804+ _ASM_EXTABLE(14b,100b)
22805+ _ASM_EXTABLE(15b,100b)
22806+ _ASM_EXTABLE(16b,100b)
22807+ _ASM_EXTABLE(17b,100b)
22808+ _ASM_EXTABLE(18b,100b)
22809+ _ASM_EXTABLE(19b,100b)
22810+ _ASM_EXTABLE(20b,100b)
22811+ _ASM_EXTABLE(21b,100b)
22812+ _ASM_EXTABLE(22b,100b)
22813+ _ASM_EXTABLE(23b,100b)
22814+ _ASM_EXTABLE(24b,100b)
22815+ _ASM_EXTABLE(25b,100b)
22816+ _ASM_EXTABLE(26b,100b)
22817+ _ASM_EXTABLE(27b,100b)
22818+ _ASM_EXTABLE(28b,100b)
22819+ _ASM_EXTABLE(29b,100b)
22820+ _ASM_EXTABLE(30b,100b)
22821+ _ASM_EXTABLE(31b,100b)
22822+ _ASM_EXTABLE(32b,100b)
22823+ _ASM_EXTABLE(33b,100b)
22824+ _ASM_EXTABLE(34b,100b)
22825+ _ASM_EXTABLE(35b,100b)
22826+ _ASM_EXTABLE(36b,100b)
22827+ _ASM_EXTABLE(37b,100b)
22828+ _ASM_EXTABLE(99b,101b)
22829+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
22830+ : "1"(to), "2"(from), "0"(size)
22831+ : "eax", "edx", "memory");
22832+ return size;
22833+}
22834+
22835+static unsigned long
22836+__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
22837+static unsigned long
22838 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22839 {
22840 int d0, d1;
22841 __asm__ __volatile__(
22842 " .align 2,0x90\n"
22843- "0: movl 32(%4), %%eax\n"
22844+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22845 " cmpl $67, %0\n"
22846 " jbe 2f\n"
22847- "1: movl 64(%4), %%eax\n"
22848+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22849 " .align 2,0x90\n"
22850- "2: movl 0(%4), %%eax\n"
22851- "21: movl 4(%4), %%edx\n"
22852+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22853+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22854 " movl %%eax, 0(%3)\n"
22855 " movl %%edx, 4(%3)\n"
22856- "3: movl 8(%4), %%eax\n"
22857- "31: movl 12(%4),%%edx\n"
22858+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22859+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22860 " movl %%eax, 8(%3)\n"
22861 " movl %%edx, 12(%3)\n"
22862- "4: movl 16(%4), %%eax\n"
22863- "41: movl 20(%4), %%edx\n"
22864+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22865+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22866 " movl %%eax, 16(%3)\n"
22867 " movl %%edx, 20(%3)\n"
22868- "10: movl 24(%4), %%eax\n"
22869- "51: movl 28(%4), %%edx\n"
22870+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22871+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22872 " movl %%eax, 24(%3)\n"
22873 " movl %%edx, 28(%3)\n"
22874- "11: movl 32(%4), %%eax\n"
22875- "61: movl 36(%4), %%edx\n"
22876+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22877+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22878 " movl %%eax, 32(%3)\n"
22879 " movl %%edx, 36(%3)\n"
22880- "12: movl 40(%4), %%eax\n"
22881- "71: movl 44(%4), %%edx\n"
22882+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22883+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22884 " movl %%eax, 40(%3)\n"
22885 " movl %%edx, 44(%3)\n"
22886- "13: movl 48(%4), %%eax\n"
22887- "81: movl 52(%4), %%edx\n"
22888+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22889+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22890 " movl %%eax, 48(%3)\n"
22891 " movl %%edx, 52(%3)\n"
22892- "14: movl 56(%4), %%eax\n"
22893- "91: movl 60(%4), %%edx\n"
22894+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22895+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22896 " movl %%eax, 56(%3)\n"
22897 " movl %%edx, 60(%3)\n"
22898 " addl $-64, %0\n"
22899@@ -252,9 +362,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22900 " shrl $2, %0\n"
22901 " andl $3, %%eax\n"
22902 " cld\n"
22903- "6: rep; movsl\n"
22904+ "6: rep; "__copyuser_seg" movsl\n"
22905 " movl %%eax,%0\n"
22906- "7: rep; movsb\n"
22907+ "7: rep; "__copyuser_seg" movsb\n"
22908 "8:\n"
22909 ".section .fixup,\"ax\"\n"
22910 "9: lea 0(%%eax,%0,4),%0\n"
22911@@ -298,47 +408,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22912 */
22913
22914 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22915+ const void __user *from, unsigned long size) __size_overflow(3);
22916+static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22917 const void __user *from, unsigned long size)
22918 {
22919 int d0, d1;
22920
22921 __asm__ __volatile__(
22922 " .align 2,0x90\n"
22923- "0: movl 32(%4), %%eax\n"
22924+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22925 " cmpl $67, %0\n"
22926 " jbe 2f\n"
22927- "1: movl 64(%4), %%eax\n"
22928+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22929 " .align 2,0x90\n"
22930- "2: movl 0(%4), %%eax\n"
22931- "21: movl 4(%4), %%edx\n"
22932+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22933+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22934 " movnti %%eax, 0(%3)\n"
22935 " movnti %%edx, 4(%3)\n"
22936- "3: movl 8(%4), %%eax\n"
22937- "31: movl 12(%4),%%edx\n"
22938+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22939+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22940 " movnti %%eax, 8(%3)\n"
22941 " movnti %%edx, 12(%3)\n"
22942- "4: movl 16(%4), %%eax\n"
22943- "41: movl 20(%4), %%edx\n"
22944+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22945+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22946 " movnti %%eax, 16(%3)\n"
22947 " movnti %%edx, 20(%3)\n"
22948- "10: movl 24(%4), %%eax\n"
22949- "51: movl 28(%4), %%edx\n"
22950+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22951+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22952 " movnti %%eax, 24(%3)\n"
22953 " movnti %%edx, 28(%3)\n"
22954- "11: movl 32(%4), %%eax\n"
22955- "61: movl 36(%4), %%edx\n"
22956+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22957+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22958 " movnti %%eax, 32(%3)\n"
22959 " movnti %%edx, 36(%3)\n"
22960- "12: movl 40(%4), %%eax\n"
22961- "71: movl 44(%4), %%edx\n"
22962+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22963+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22964 " movnti %%eax, 40(%3)\n"
22965 " movnti %%edx, 44(%3)\n"
22966- "13: movl 48(%4), %%eax\n"
22967- "81: movl 52(%4), %%edx\n"
22968+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22969+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22970 " movnti %%eax, 48(%3)\n"
22971 " movnti %%edx, 52(%3)\n"
22972- "14: movl 56(%4), %%eax\n"
22973- "91: movl 60(%4), %%edx\n"
22974+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22975+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22976 " movnti %%eax, 56(%3)\n"
22977 " movnti %%edx, 60(%3)\n"
22978 " addl $-64, %0\n"
22979@@ -351,9 +463,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22980 " shrl $2, %0\n"
22981 " andl $3, %%eax\n"
22982 " cld\n"
22983- "6: rep; movsl\n"
22984+ "6: rep; "__copyuser_seg" movsl\n"
22985 " movl %%eax,%0\n"
22986- "7: rep; movsb\n"
22987+ "7: rep; "__copyuser_seg" movsb\n"
22988 "8:\n"
22989 ".section .fixup,\"ax\"\n"
22990 "9: lea 0(%%eax,%0,4),%0\n"
22991@@ -392,47 +504,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22992 }
22993
22994 static unsigned long __copy_user_intel_nocache(void *to,
22995+ const void __user *from, unsigned long size) __size_overflow(3);
22996+static unsigned long __copy_user_intel_nocache(void *to,
22997 const void __user *from, unsigned long size)
22998 {
22999 int d0, d1;
23000
23001 __asm__ __volatile__(
23002 " .align 2,0x90\n"
23003- "0: movl 32(%4), %%eax\n"
23004+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23005 " cmpl $67, %0\n"
23006 " jbe 2f\n"
23007- "1: movl 64(%4), %%eax\n"
23008+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23009 " .align 2,0x90\n"
23010- "2: movl 0(%4), %%eax\n"
23011- "21: movl 4(%4), %%edx\n"
23012+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23013+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23014 " movnti %%eax, 0(%3)\n"
23015 " movnti %%edx, 4(%3)\n"
23016- "3: movl 8(%4), %%eax\n"
23017- "31: movl 12(%4),%%edx\n"
23018+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23019+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23020 " movnti %%eax, 8(%3)\n"
23021 " movnti %%edx, 12(%3)\n"
23022- "4: movl 16(%4), %%eax\n"
23023- "41: movl 20(%4), %%edx\n"
23024+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23025+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23026 " movnti %%eax, 16(%3)\n"
23027 " movnti %%edx, 20(%3)\n"
23028- "10: movl 24(%4), %%eax\n"
23029- "51: movl 28(%4), %%edx\n"
23030+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23031+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23032 " movnti %%eax, 24(%3)\n"
23033 " movnti %%edx, 28(%3)\n"
23034- "11: movl 32(%4), %%eax\n"
23035- "61: movl 36(%4), %%edx\n"
23036+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23037+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23038 " movnti %%eax, 32(%3)\n"
23039 " movnti %%edx, 36(%3)\n"
23040- "12: movl 40(%4), %%eax\n"
23041- "71: movl 44(%4), %%edx\n"
23042+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23043+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23044 " movnti %%eax, 40(%3)\n"
23045 " movnti %%edx, 44(%3)\n"
23046- "13: movl 48(%4), %%eax\n"
23047- "81: movl 52(%4), %%edx\n"
23048+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23049+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23050 " movnti %%eax, 48(%3)\n"
23051 " movnti %%edx, 52(%3)\n"
23052- "14: movl 56(%4), %%eax\n"
23053- "91: movl 60(%4), %%edx\n"
23054+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23055+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23056 " movnti %%eax, 56(%3)\n"
23057 " movnti %%edx, 60(%3)\n"
23058 " addl $-64, %0\n"
23059@@ -445,9 +559,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23060 " shrl $2, %0\n"
23061 " andl $3, %%eax\n"
23062 " cld\n"
23063- "6: rep; movsl\n"
23064+ "6: rep; "__copyuser_seg" movsl\n"
23065 " movl %%eax,%0\n"
23066- "7: rep; movsb\n"
23067+ "7: rep; "__copyuser_seg" movsb\n"
23068 "8:\n"
23069 ".section .fixup,\"ax\"\n"
23070 "9: lea 0(%%eax,%0,4),%0\n"
23071@@ -487,32 +601,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23072 */
23073 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23074 unsigned long size);
23075-unsigned long __copy_user_intel(void __user *to, const void *from,
23076+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23077+ unsigned long size);
23078+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23079 unsigned long size);
23080 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23081 const void __user *from, unsigned long size);
23082 #endif /* CONFIG_X86_INTEL_USERCOPY */
23083
23084 /* Generic arbitrary sized copy. */
23085-#define __copy_user(to, from, size) \
23086+#define __copy_user(to, from, size, prefix, set, restore) \
23087 do { \
23088 int __d0, __d1, __d2; \
23089 __asm__ __volatile__( \
23090+ set \
23091 " cmp $7,%0\n" \
23092 " jbe 1f\n" \
23093 " movl %1,%0\n" \
23094 " negl %0\n" \
23095 " andl $7,%0\n" \
23096 " subl %0,%3\n" \
23097- "4: rep; movsb\n" \
23098+ "4: rep; "prefix"movsb\n" \
23099 " movl %3,%0\n" \
23100 " shrl $2,%0\n" \
23101 " andl $3,%3\n" \
23102 " .align 2,0x90\n" \
23103- "0: rep; movsl\n" \
23104+ "0: rep; "prefix"movsl\n" \
23105 " movl %3,%0\n" \
23106- "1: rep; movsb\n" \
23107+ "1: rep; "prefix"movsb\n" \
23108 "2:\n" \
23109+ restore \
23110 ".section .fixup,\"ax\"\n" \
23111 "5: addl %3,%0\n" \
23112 " jmp 2b\n" \
23113@@ -537,14 +655,14 @@ do { \
23114 " negl %0\n" \
23115 " andl $7,%0\n" \
23116 " subl %0,%3\n" \
23117- "4: rep; movsb\n" \
23118+ "4: rep; "__copyuser_seg"movsb\n" \
23119 " movl %3,%0\n" \
23120 " shrl $2,%0\n" \
23121 " andl $3,%3\n" \
23122 " .align 2,0x90\n" \
23123- "0: rep; movsl\n" \
23124+ "0: rep; "__copyuser_seg"movsl\n" \
23125 " movl %3,%0\n" \
23126- "1: rep; movsb\n" \
23127+ "1: rep; "__copyuser_seg"movsb\n" \
23128 "2:\n" \
23129 ".section .fixup,\"ax\"\n" \
23130 "5: addl %3,%0\n" \
23131@@ -627,9 +745,9 @@ survive:
23132 }
23133 #endif
23134 if (movsl_is_ok(to, from, n))
23135- __copy_user(to, from, n);
23136+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23137 else
23138- n = __copy_user_intel(to, from, n);
23139+ n = __generic_copy_to_user_intel(to, from, n);
23140 return n;
23141 }
23142 EXPORT_SYMBOL(__copy_to_user_ll);
23143@@ -649,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23144 unsigned long n)
23145 {
23146 if (movsl_is_ok(to, from, n))
23147- __copy_user(to, from, n);
23148+ __copy_user(to, from, n, __copyuser_seg, "", "");
23149 else
23150- n = __copy_user_intel((void __user *)to,
23151- (const void *)from, n);
23152+ n = __generic_copy_from_user_intel(to, from, n);
23153 return n;
23154 }
23155 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23156@@ -679,65 +796,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23157 if (n > 64 && cpu_has_xmm2)
23158 n = __copy_user_intel_nocache(to, from, n);
23159 else
23160- __copy_user(to, from, n);
23161+ __copy_user(to, from, n, __copyuser_seg, "", "");
23162 #else
23163- __copy_user(to, from, n);
23164+ __copy_user(to, from, n, __copyuser_seg, "", "");
23165 #endif
23166 return n;
23167 }
23168 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23169
23170-/**
23171- * copy_to_user: - Copy a block of data into user space.
23172- * @to: Destination address, in user space.
23173- * @from: Source address, in kernel space.
23174- * @n: Number of bytes to copy.
23175- *
23176- * Context: User context only. This function may sleep.
23177- *
23178- * Copy data from kernel space to user space.
23179- *
23180- * Returns number of bytes that could not be copied.
23181- * On success, this will be zero.
23182- */
23183-unsigned long
23184-copy_to_user(void __user *to, const void *from, unsigned long n)
23185-{
23186- if (access_ok(VERIFY_WRITE, to, n))
23187- n = __copy_to_user(to, from, n);
23188- return n;
23189-}
23190-EXPORT_SYMBOL(copy_to_user);
23191-
23192-/**
23193- * copy_from_user: - Copy a block of data from user space.
23194- * @to: Destination address, in kernel space.
23195- * @from: Source address, in user space.
23196- * @n: Number of bytes to copy.
23197- *
23198- * Context: User context only. This function may sleep.
23199- *
23200- * Copy data from user space to kernel space.
23201- *
23202- * Returns number of bytes that could not be copied.
23203- * On success, this will be zero.
23204- *
23205- * If some data could not be copied, this function will pad the copied
23206- * data to the requested size using zero bytes.
23207- */
23208-unsigned long
23209-_copy_from_user(void *to, const void __user *from, unsigned long n)
23210-{
23211- if (access_ok(VERIFY_READ, from, n))
23212- n = __copy_from_user(to, from, n);
23213- else
23214- memset(to, 0, n);
23215- return n;
23216-}
23217-EXPORT_SYMBOL(_copy_from_user);
23218-
23219 void copy_from_user_overflow(void)
23220 {
23221 WARN(1, "Buffer overflow detected!\n");
23222 }
23223 EXPORT_SYMBOL(copy_from_user_overflow);
23224+
23225+void copy_to_user_overflow(void)
23226+{
23227+ WARN(1, "Buffer overflow detected!\n");
23228+}
23229+EXPORT_SYMBOL(copy_to_user_overflow);
23230+
23231+#ifdef CONFIG_PAX_MEMORY_UDEREF
23232+void __set_fs(mm_segment_t x)
23233+{
23234+ switch (x.seg) {
23235+ case 0:
23236+ loadsegment(gs, 0);
23237+ break;
23238+ case TASK_SIZE_MAX:
23239+ loadsegment(gs, __USER_DS);
23240+ break;
23241+ case -1UL:
23242+ loadsegment(gs, __KERNEL_DS);
23243+ break;
23244+ default:
23245+ BUG();
23246+ }
23247+ return;
23248+}
23249+EXPORT_SYMBOL(__set_fs);
23250+
23251+void set_fs(mm_segment_t x)
23252+{
23253+ current_thread_info()->addr_limit = x;
23254+ __set_fs(x);
23255+}
23256+EXPORT_SYMBOL(set_fs);
23257+#endif
23258diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23259index e5b130b..6690d31 100644
23260--- a/arch/x86/lib/usercopy_64.c
23261+++ b/arch/x86/lib/usercopy_64.c
23262@@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23263 {
23264 long __d0;
23265 might_fault();
23266+
23267+#ifdef CONFIG_PAX_MEMORY_UDEREF
23268+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23269+ addr += PAX_USER_SHADOW_BASE;
23270+#endif
23271+
23272 /* no memory constraint because it doesn't change any memory gcc knows
23273 about */
23274 asm volatile(
23275@@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23276 }
23277 EXPORT_SYMBOL(clear_user);
23278
23279-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23280+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23281 {
23282- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23283- return copy_user_generic((__force void *)to, (__force void *)from, len);
23284- }
23285- return len;
23286+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23287+
23288+#ifdef CONFIG_PAX_MEMORY_UDEREF
23289+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23290+ to += PAX_USER_SHADOW_BASE;
23291+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23292+ from += PAX_USER_SHADOW_BASE;
23293+#endif
23294+
23295+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23296+ }
23297+ return len;
23298 }
23299 EXPORT_SYMBOL(copy_in_user);
23300
23301@@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23302 * it is not necessary to optimize tail handling.
23303 */
23304 unsigned long
23305-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23306+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23307 {
23308 char c;
23309 unsigned zero_len;
23310@@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23311 break;
23312 return len;
23313 }
23314+
23315+void copy_from_user_overflow(void)
23316+{
23317+ WARN(1, "Buffer overflow detected!\n");
23318+}
23319+EXPORT_SYMBOL(copy_from_user_overflow);
23320+
23321+void copy_to_user_overflow(void)
23322+{
23323+ WARN(1, "Buffer overflow detected!\n");
23324+}
23325+EXPORT_SYMBOL(copy_to_user_overflow);
23326diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23327index 903ec1e..833f340 100644
23328--- a/arch/x86/mm/extable.c
23329+++ b/arch/x86/mm/extable.c
23330@@ -6,12 +6,25 @@
23331 static inline unsigned long
23332 ex_insn_addr(const struct exception_table_entry *x)
23333 {
23334- return (unsigned long)&x->insn + x->insn;
23335+//printk(KERN_ERR "fixup %p insn:%x fixup:%x\n", x, x->insn, x->fixup);
23336+ unsigned long reloc = 0;
23337+
23338+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23339+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23340+#endif
23341+
23342+ return (unsigned long)&x->insn + x->insn + reloc;
23343 }
23344 static inline unsigned long
23345 ex_fixup_addr(const struct exception_table_entry *x)
23346 {
23347- return (unsigned long)&x->fixup + x->fixup;
23348+ unsigned long reloc = 0;
23349+
23350+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23351+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23352+#endif
23353+
23354+ return (unsigned long)&x->fixup + x->fixup + reloc;
23355 }
23356
23357 int fixup_exception(struct pt_regs *regs)
23358@@ -20,7 +33,7 @@ int fixup_exception(struct pt_regs *regs)
23359 unsigned long new_ip;
23360
23361 #ifdef CONFIG_PNPBIOS
23362- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23363+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23364 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23365 extern u32 pnp_bios_is_utter_crap;
23366 pnp_bios_is_utter_crap = 1;
23367@@ -34,6 +47,7 @@ int fixup_exception(struct pt_regs *regs)
23368 #endif
23369
23370 fixup = search_exception_tables(regs->ip);
23371+//printk(KERN_ERR "fixup %p %lx\n", fixup, regs->ip);
23372 if (fixup) {
23373 new_ip = ex_fixup_addr(fixup);
23374
23375diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23376index 76dcd9d..e9dffde 100644
23377--- a/arch/x86/mm/fault.c
23378+++ b/arch/x86/mm/fault.c
23379@@ -13,11 +13,18 @@
23380 #include <linux/perf_event.h> /* perf_sw_event */
23381 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23382 #include <linux/prefetch.h> /* prefetchw */
23383+#include <linux/unistd.h>
23384+#include <linux/compiler.h>
23385
23386 #include <asm/traps.h> /* dotraplinkage, ... */
23387 #include <asm/pgalloc.h> /* pgd_*(), ... */
23388 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23389 #include <asm/fixmap.h> /* VSYSCALL_START */
23390+#include <asm/tlbflush.h>
23391+
23392+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23393+#include <asm/stacktrace.h>
23394+#endif
23395
23396 /*
23397 * Page fault error code bits:
23398@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23399 int ret = 0;
23400
23401 /* kprobe_running() needs smp_processor_id() */
23402- if (kprobes_built_in() && !user_mode_vm(regs)) {
23403+ if (kprobes_built_in() && !user_mode(regs)) {
23404 preempt_disable();
23405 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23406 ret = 1;
23407@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23408 return !instr_lo || (instr_lo>>1) == 1;
23409 case 0x00:
23410 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23411- if (probe_kernel_address(instr, opcode))
23412+ if (user_mode(regs)) {
23413+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23414+ return 0;
23415+ } else if (probe_kernel_address(instr, opcode))
23416 return 0;
23417
23418 *prefetch = (instr_lo == 0xF) &&
23419@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23420 while (instr < max_instr) {
23421 unsigned char opcode;
23422
23423- if (probe_kernel_address(instr, opcode))
23424+ if (user_mode(regs)) {
23425+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23426+ break;
23427+ } else if (probe_kernel_address(instr, opcode))
23428 break;
23429
23430 instr++;
23431@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23432 force_sig_info(si_signo, &info, tsk);
23433 }
23434
23435+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23436+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23437+#endif
23438+
23439+#ifdef CONFIG_PAX_EMUTRAMP
23440+static int pax_handle_fetch_fault(struct pt_regs *regs);
23441+#endif
23442+
23443+#ifdef CONFIG_PAX_PAGEEXEC
23444+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23445+{
23446+ pgd_t *pgd;
23447+ pud_t *pud;
23448+ pmd_t *pmd;
23449+
23450+ pgd = pgd_offset(mm, address);
23451+ if (!pgd_present(*pgd))
23452+ return NULL;
23453+ pud = pud_offset(pgd, address);
23454+ if (!pud_present(*pud))
23455+ return NULL;
23456+ pmd = pmd_offset(pud, address);
23457+ if (!pmd_present(*pmd))
23458+ return NULL;
23459+ return pmd;
23460+}
23461+#endif
23462+
23463 DEFINE_SPINLOCK(pgd_lock);
23464 LIST_HEAD(pgd_list);
23465
23466@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23467 for (address = VMALLOC_START & PMD_MASK;
23468 address >= TASK_SIZE && address < FIXADDR_TOP;
23469 address += PMD_SIZE) {
23470+
23471+#ifdef CONFIG_PAX_PER_CPU_PGD
23472+ unsigned long cpu;
23473+#else
23474 struct page *page;
23475+#endif
23476
23477 spin_lock(&pgd_lock);
23478+
23479+#ifdef CONFIG_PAX_PER_CPU_PGD
23480+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23481+ pgd_t *pgd = get_cpu_pgd(cpu);
23482+ pmd_t *ret;
23483+#else
23484 list_for_each_entry(page, &pgd_list, lru) {
23485+ pgd_t *pgd = page_address(page);
23486 spinlock_t *pgt_lock;
23487 pmd_t *ret;
23488
23489@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23490 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23491
23492 spin_lock(pgt_lock);
23493- ret = vmalloc_sync_one(page_address(page), address);
23494+#endif
23495+
23496+ ret = vmalloc_sync_one(pgd, address);
23497+
23498+#ifndef CONFIG_PAX_PER_CPU_PGD
23499 spin_unlock(pgt_lock);
23500+#endif
23501
23502 if (!ret)
23503 break;
23504@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23505 * an interrupt in the middle of a task switch..
23506 */
23507 pgd_paddr = read_cr3();
23508+
23509+#ifdef CONFIG_PAX_PER_CPU_PGD
23510+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23511+#endif
23512+
23513 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23514 if (!pmd_k)
23515 return -1;
23516@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23517 * happen within a race in page table update. In the later
23518 * case just flush:
23519 */
23520+
23521+#ifdef CONFIG_PAX_PER_CPU_PGD
23522+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23523+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23524+#else
23525 pgd = pgd_offset(current->active_mm, address);
23526+#endif
23527+
23528 pgd_ref = pgd_offset_k(address);
23529 if (pgd_none(*pgd_ref))
23530 return -1;
23531@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23532 static int is_errata100(struct pt_regs *regs, unsigned long address)
23533 {
23534 #ifdef CONFIG_X86_64
23535- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23536+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23537 return 1;
23538 #endif
23539 return 0;
23540@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23541 }
23542
23543 static const char nx_warning[] = KERN_CRIT
23544-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23545+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23546
23547 static void
23548 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23549@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23550 if (!oops_may_print())
23551 return;
23552
23553- if (error_code & PF_INSTR) {
23554+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23555 unsigned int level;
23556
23557 pte_t *pte = lookup_address(address, &level);
23558
23559 if (pte && pte_present(*pte) && !pte_exec(*pte))
23560- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23561+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23562 }
23563
23564+#ifdef CONFIG_PAX_KERNEXEC
23565+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23566+ if (current->signal->curr_ip)
23567+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23568+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23569+ else
23570+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23571+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23572+ }
23573+#endif
23574+
23575 printk(KERN_ALERT "BUG: unable to handle kernel ");
23576 if (address < PAGE_SIZE)
23577 printk(KERN_CONT "NULL pointer dereference");
23578@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23579 }
23580 #endif
23581
23582+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23583+ if (pax_is_fetch_fault(regs, error_code, address)) {
23584+
23585+#ifdef CONFIG_PAX_EMUTRAMP
23586+ switch (pax_handle_fetch_fault(regs)) {
23587+ case 2:
23588+ return;
23589+ }
23590+#endif
23591+
23592+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23593+ do_group_exit(SIGKILL);
23594+ }
23595+#endif
23596+
23597 if (unlikely(show_unhandled_signals))
23598 show_signal_msg(regs, error_code, address, tsk);
23599
23600@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23601 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23602 printk(KERN_ERR
23603 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23604- tsk->comm, tsk->pid, address);
23605+ tsk->comm, task_pid_nr(tsk), address);
23606 code = BUS_MCEERR_AR;
23607 }
23608 #endif
23609@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23610 return 1;
23611 }
23612
23613+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23614+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23615+{
23616+ pte_t *pte;
23617+ pmd_t *pmd;
23618+ spinlock_t *ptl;
23619+ unsigned char pte_mask;
23620+
23621+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23622+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
23623+ return 0;
23624+
23625+ /* PaX: it's our fault, let's handle it if we can */
23626+
23627+ /* PaX: take a look at read faults before acquiring any locks */
23628+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23629+ /* instruction fetch attempt from a protected page in user mode */
23630+ up_read(&mm->mmap_sem);
23631+
23632+#ifdef CONFIG_PAX_EMUTRAMP
23633+ switch (pax_handle_fetch_fault(regs)) {
23634+ case 2:
23635+ return 1;
23636+ }
23637+#endif
23638+
23639+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23640+ do_group_exit(SIGKILL);
23641+ }
23642+
23643+ pmd = pax_get_pmd(mm, address);
23644+ if (unlikely(!pmd))
23645+ return 0;
23646+
23647+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23648+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23649+ pte_unmap_unlock(pte, ptl);
23650+ return 0;
23651+ }
23652+
23653+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23654+ /* write attempt to a protected page in user mode */
23655+ pte_unmap_unlock(pte, ptl);
23656+ return 0;
23657+ }
23658+
23659+#ifdef CONFIG_SMP
23660+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23661+#else
23662+ if (likely(address > get_limit(regs->cs)))
23663+#endif
23664+ {
23665+ set_pte(pte, pte_mkread(*pte));
23666+ __flush_tlb_one(address);
23667+ pte_unmap_unlock(pte, ptl);
23668+ up_read(&mm->mmap_sem);
23669+ return 1;
23670+ }
23671+
23672+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23673+
23674+ /*
23675+ * PaX: fill DTLB with user rights and retry
23676+ */
23677+ __asm__ __volatile__ (
23678+ "orb %2,(%1)\n"
23679+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23680+/*
23681+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23682+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23683+ * page fault when examined during a TLB load attempt. this is true not only
23684+ * for PTEs holding a non-present entry but also present entries that will
23685+ * raise a page fault (such as those set up by PaX, or the copy-on-write
23686+ * mechanism). in effect it means that we do *not* need to flush the TLBs
23687+ * for our target pages since their PTEs are simply not in the TLBs at all.
23688+
23689+ * the best thing in omitting it is that we gain around 15-20% speed in the
23690+ * fast path of the page fault handler and can get rid of tracing since we
23691+ * can no longer flush unintended entries.
23692+ */
23693+ "invlpg (%0)\n"
23694+#endif
23695+ __copyuser_seg"testb $0,(%0)\n"
23696+ "xorb %3,(%1)\n"
23697+ :
23698+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23699+ : "memory", "cc");
23700+ pte_unmap_unlock(pte, ptl);
23701+ up_read(&mm->mmap_sem);
23702+ return 1;
23703+}
23704+#endif
23705+
23706 /*
23707 * Handle a spurious fault caused by a stale TLB entry.
23708 *
23709@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23710 static inline int
23711 access_error(unsigned long error_code, struct vm_area_struct *vma)
23712 {
23713+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23714+ return 1;
23715+
23716 if (error_code & PF_WRITE) {
23717 /* write, present and write, not present: */
23718 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23719@@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23720 {
23721 struct vm_area_struct *vma;
23722 struct task_struct *tsk;
23723- unsigned long address;
23724 struct mm_struct *mm;
23725 int fault;
23726 int write = error_code & PF_WRITE;
23727 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23728 (write ? FAULT_FLAG_WRITE : 0);
23729
23730- tsk = current;
23731- mm = tsk->mm;
23732-
23733 /* Get the faulting address: */
23734- address = read_cr2();
23735+ unsigned long address = read_cr2();
23736+
23737+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23738+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23739+ if (!search_exception_tables(regs->ip)) {
23740+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23741+ bad_area_nosemaphore(regs, error_code, address);
23742+ return;
23743+ }
23744+ if (address < PAX_USER_SHADOW_BASE) {
23745+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23746+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23747+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23748+ } else
23749+ address -= PAX_USER_SHADOW_BASE;
23750+ }
23751+#endif
23752+
23753+ tsk = current;
23754+ mm = tsk->mm;
23755
23756 /*
23757 * Detect and handle instructions that would cause a page fault for
23758@@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23759 * User-mode registers count as a user access even for any
23760 * potential system fault or CPU buglet:
23761 */
23762- if (user_mode_vm(regs)) {
23763+ if (user_mode(regs)) {
23764 local_irq_enable();
23765 error_code |= PF_USER;
23766 } else {
23767@@ -1132,6 +1339,11 @@ retry:
23768 might_sleep();
23769 }
23770
23771+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23772+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23773+ return;
23774+#endif
23775+
23776 vma = find_vma(mm, address);
23777 if (unlikely(!vma)) {
23778 bad_area(regs, error_code, address);
23779@@ -1143,18 +1355,24 @@ retry:
23780 bad_area(regs, error_code, address);
23781 return;
23782 }
23783- if (error_code & PF_USER) {
23784- /*
23785- * Accessing the stack below %sp is always a bug.
23786- * The large cushion allows instructions like enter
23787- * and pusha to work. ("enter $65535, $31" pushes
23788- * 32 pointers and then decrements %sp by 65535.)
23789- */
23790- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23791- bad_area(regs, error_code, address);
23792- return;
23793- }
23794+ /*
23795+ * Accessing the stack below %sp is always a bug.
23796+ * The large cushion allows instructions like enter
23797+ * and pusha to work. ("enter $65535, $31" pushes
23798+ * 32 pointers and then decrements %sp by 65535.)
23799+ */
23800+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23801+ bad_area(regs, error_code, address);
23802+ return;
23803 }
23804+
23805+#ifdef CONFIG_PAX_SEGMEXEC
23806+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23807+ bad_area(regs, error_code, address);
23808+ return;
23809+ }
23810+#endif
23811+
23812 if (unlikely(expand_stack(vma, address))) {
23813 bad_area(regs, error_code, address);
23814 return;
23815@@ -1209,3 +1427,292 @@ good_area:
23816
23817 up_read(&mm->mmap_sem);
23818 }
23819+
23820+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23821+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23822+{
23823+ struct mm_struct *mm = current->mm;
23824+ unsigned long ip = regs->ip;
23825+
23826+ if (v8086_mode(regs))
23827+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23828+
23829+#ifdef CONFIG_PAX_PAGEEXEC
23830+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23831+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23832+ return true;
23833+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23834+ return true;
23835+ return false;
23836+ }
23837+#endif
23838+
23839+#ifdef CONFIG_PAX_SEGMEXEC
23840+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23841+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23842+ return true;
23843+ return false;
23844+ }
23845+#endif
23846+
23847+ return false;
23848+}
23849+#endif
23850+
23851+#ifdef CONFIG_PAX_EMUTRAMP
23852+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23853+{
23854+ int err;
23855+
23856+ do { /* PaX: libffi trampoline emulation */
23857+ unsigned char mov, jmp;
23858+ unsigned int addr1, addr2;
23859+
23860+#ifdef CONFIG_X86_64
23861+ if ((regs->ip + 9) >> 32)
23862+ break;
23863+#endif
23864+
23865+ err = get_user(mov, (unsigned char __user *)regs->ip);
23866+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23867+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23868+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23869+
23870+ if (err)
23871+ break;
23872+
23873+ if (mov == 0xB8 && jmp == 0xE9) {
23874+ regs->ax = addr1;
23875+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23876+ return 2;
23877+ }
23878+ } while (0);
23879+
23880+ do { /* PaX: gcc trampoline emulation #1 */
23881+ unsigned char mov1, mov2;
23882+ unsigned short jmp;
23883+ unsigned int addr1, addr2;
23884+
23885+#ifdef CONFIG_X86_64
23886+ if ((regs->ip + 11) >> 32)
23887+ break;
23888+#endif
23889+
23890+ err = get_user(mov1, (unsigned char __user *)regs->ip);
23891+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23892+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23893+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23894+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23895+
23896+ if (err)
23897+ break;
23898+
23899+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23900+ regs->cx = addr1;
23901+ regs->ax = addr2;
23902+ regs->ip = addr2;
23903+ return 2;
23904+ }
23905+ } while (0);
23906+
23907+ do { /* PaX: gcc trampoline emulation #2 */
23908+ unsigned char mov, jmp;
23909+ unsigned int addr1, addr2;
23910+
23911+#ifdef CONFIG_X86_64
23912+ if ((regs->ip + 9) >> 32)
23913+ break;
23914+#endif
23915+
23916+ err = get_user(mov, (unsigned char __user *)regs->ip);
23917+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23918+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23919+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23920+
23921+ if (err)
23922+ break;
23923+
23924+ if (mov == 0xB9 && jmp == 0xE9) {
23925+ regs->cx = addr1;
23926+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23927+ return 2;
23928+ }
23929+ } while (0);
23930+
23931+ return 1; /* PaX in action */
23932+}
23933+
23934+#ifdef CONFIG_X86_64
23935+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
23936+{
23937+ int err;
23938+
23939+ do { /* PaX: libffi trampoline emulation */
23940+ unsigned short mov1, mov2, jmp1;
23941+ unsigned char stcclc, jmp2;
23942+ unsigned long addr1, addr2;
23943+
23944+ err = get_user(mov1, (unsigned short __user *)regs->ip);
23945+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23946+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23947+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23948+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
23949+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
23950+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
23951+
23952+ if (err)
23953+ break;
23954+
23955+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23956+ regs->r11 = addr1;
23957+ regs->r10 = addr2;
23958+ if (stcclc == 0xF8)
23959+ regs->flags &= ~X86_EFLAGS_CF;
23960+ else
23961+ regs->flags |= X86_EFLAGS_CF;
23962+ regs->ip = addr1;
23963+ return 2;
23964+ }
23965+ } while (0);
23966+
23967+ do { /* PaX: gcc trampoline emulation #1 */
23968+ unsigned short mov1, mov2, jmp1;
23969+ unsigned char jmp2;
23970+ unsigned int addr1;
23971+ unsigned long addr2;
23972+
23973+ err = get_user(mov1, (unsigned short __user *)regs->ip);
23974+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
23975+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
23976+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
23977+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
23978+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
23979+
23980+ if (err)
23981+ break;
23982+
23983+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23984+ regs->r11 = addr1;
23985+ regs->r10 = addr2;
23986+ regs->ip = addr1;
23987+ return 2;
23988+ }
23989+ } while (0);
23990+
23991+ do { /* PaX: gcc trampoline emulation #2 */
23992+ unsigned short mov1, mov2, jmp1;
23993+ unsigned char jmp2;
23994+ unsigned long addr1, addr2;
23995+
23996+ err = get_user(mov1, (unsigned short __user *)regs->ip);
23997+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23998+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23999+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24000+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24001+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24002+
24003+ if (err)
24004+ break;
24005+
24006+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24007+ regs->r11 = addr1;
24008+ regs->r10 = addr2;
24009+ regs->ip = addr1;
24010+ return 2;
24011+ }
24012+ } while (0);
24013+
24014+ return 1; /* PaX in action */
24015+}
24016+#endif
24017+
24018+/*
24019+ * PaX: decide what to do with offenders (regs->ip = fault address)
24020+ *
24021+ * returns 1 when task should be killed
24022+ * 2 when gcc trampoline was detected
24023+ */
24024+static int pax_handle_fetch_fault(struct pt_regs *regs)
24025+{
24026+ if (v8086_mode(regs))
24027+ return 1;
24028+
24029+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24030+ return 1;
24031+
24032+#ifdef CONFIG_X86_32
24033+ return pax_handle_fetch_fault_32(regs);
24034+#else
24035+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24036+ return pax_handle_fetch_fault_32(regs);
24037+ else
24038+ return pax_handle_fetch_fault_64(regs);
24039+#endif
24040+}
24041+#endif
24042+
24043+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24044+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24045+{
24046+ long i;
24047+
24048+ printk(KERN_ERR "PAX: bytes at PC: ");
24049+ for (i = 0; i < 20; i++) {
24050+ unsigned char c;
24051+ if (get_user(c, (unsigned char __force_user *)pc+i))
24052+ printk(KERN_CONT "?? ");
24053+ else
24054+ printk(KERN_CONT "%02x ", c);
24055+ }
24056+ printk("\n");
24057+
24058+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24059+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24060+ unsigned long c;
24061+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24062+#ifdef CONFIG_X86_32
24063+ printk(KERN_CONT "???????? ");
24064+#else
24065+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24066+ printk(KERN_CONT "???????? ???????? ");
24067+ else
24068+ printk(KERN_CONT "???????????????? ");
24069+#endif
24070+ } else {
24071+#ifdef CONFIG_X86_64
24072+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24073+ printk(KERN_CONT "%08x ", (unsigned int)c);
24074+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24075+ } else
24076+#endif
24077+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24078+ }
24079+ }
24080+ printk("\n");
24081+}
24082+#endif
24083+
24084+/**
24085+ * probe_kernel_write(): safely attempt to write to a location
24086+ * @dst: address to write to
24087+ * @src: pointer to the data that shall be written
24088+ * @size: size of the data chunk
24089+ *
24090+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24091+ * happens, handle that and return -EFAULT.
24092+ */
24093+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24094+{
24095+ long ret;
24096+ mm_segment_t old_fs = get_fs();
24097+
24098+ set_fs(KERNEL_DS);
24099+ pagefault_disable();
24100+ pax_open_kernel();
24101+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24102+ pax_close_kernel();
24103+ pagefault_enable();
24104+ set_fs(old_fs);
24105+
24106+ return ret ? -EFAULT : 0;
24107+}
24108diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24109index dd74e46..7d26398 100644
24110--- a/arch/x86/mm/gup.c
24111+++ b/arch/x86/mm/gup.c
24112@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24113 addr = start;
24114 len = (unsigned long) nr_pages << PAGE_SHIFT;
24115 end = start + len;
24116- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24117+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24118 (void __user *)start, len)))
24119 return 0;
24120
24121diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24122index 6f31ee5..8ee4164 100644
24123--- a/arch/x86/mm/highmem_32.c
24124+++ b/arch/x86/mm/highmem_32.c
24125@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24126 idx = type + KM_TYPE_NR*smp_processor_id();
24127 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24128 BUG_ON(!pte_none(*(kmap_pte-idx)));
24129+
24130+ pax_open_kernel();
24131 set_pte(kmap_pte-idx, mk_pte(page, prot));
24132+ pax_close_kernel();
24133+
24134 arch_flush_lazy_mmu_mode();
24135
24136 return (void *)vaddr;
24137diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24138index f6679a7..8f795a3 100644
24139--- a/arch/x86/mm/hugetlbpage.c
24140+++ b/arch/x86/mm/hugetlbpage.c
24141@@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24142 struct hstate *h = hstate_file(file);
24143 struct mm_struct *mm = current->mm;
24144 struct vm_area_struct *vma;
24145- unsigned long start_addr;
24146+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24147+
24148+#ifdef CONFIG_PAX_SEGMEXEC
24149+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24150+ pax_task_size = SEGMEXEC_TASK_SIZE;
24151+#endif
24152+
24153+ pax_task_size -= PAGE_SIZE;
24154
24155 if (len > mm->cached_hole_size) {
24156- start_addr = mm->free_area_cache;
24157+ start_addr = mm->free_area_cache;
24158 } else {
24159- start_addr = TASK_UNMAPPED_BASE;
24160- mm->cached_hole_size = 0;
24161+ start_addr = mm->mmap_base;
24162+ mm->cached_hole_size = 0;
24163 }
24164
24165 full_search:
24166@@ -280,26 +287,27 @@ full_search:
24167
24168 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24169 /* At this point: (!vma || addr < vma->vm_end). */
24170- if (TASK_SIZE - len < addr) {
24171+ if (pax_task_size - len < addr) {
24172 /*
24173 * Start a new search - just in case we missed
24174 * some holes.
24175 */
24176- if (start_addr != TASK_UNMAPPED_BASE) {
24177- start_addr = TASK_UNMAPPED_BASE;
24178+ if (start_addr != mm->mmap_base) {
24179+ start_addr = mm->mmap_base;
24180 mm->cached_hole_size = 0;
24181 goto full_search;
24182 }
24183 return -ENOMEM;
24184 }
24185- if (!vma || addr + len <= vma->vm_start) {
24186- mm->free_area_cache = addr + len;
24187- return addr;
24188- }
24189+ if (check_heap_stack_gap(vma, addr, len))
24190+ break;
24191 if (addr + mm->cached_hole_size < vma->vm_start)
24192 mm->cached_hole_size = vma->vm_start - addr;
24193 addr = ALIGN(vma->vm_end, huge_page_size(h));
24194 }
24195+
24196+ mm->free_area_cache = addr + len;
24197+ return addr;
24198 }
24199
24200 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24201@@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24202 struct mm_struct *mm = current->mm;
24203 struct vm_area_struct *vma;
24204 unsigned long base = mm->mmap_base;
24205- unsigned long addr = addr0;
24206+ unsigned long addr;
24207 unsigned long largest_hole = mm->cached_hole_size;
24208- unsigned long start_addr;
24209
24210 /* don't allow allocations above current base */
24211 if (mm->free_area_cache > base)
24212@@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24213 largest_hole = 0;
24214 mm->free_area_cache = base;
24215 }
24216-try_again:
24217- start_addr = mm->free_area_cache;
24218
24219 /* make sure it can fit in the remaining address space */
24220 if (mm->free_area_cache < len)
24221 goto fail;
24222
24223 /* either no address requested or can't fit in requested address hole */
24224- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24225+ addr = mm->free_area_cache - len;
24226 do {
24227+ addr &= huge_page_mask(h);
24228 /*
24229 * Lookup failure means no vma is above this address,
24230 * i.e. return with success:
24231@@ -340,10 +346,10 @@ try_again:
24232 if (!vma)
24233 return addr;
24234
24235- if (addr + len <= vma->vm_start) {
24236+ if (check_heap_stack_gap(vma, addr, len)) {
24237 /* remember the address as a hint for next time */
24238- mm->cached_hole_size = largest_hole;
24239- return (mm->free_area_cache = addr);
24240+ mm->cached_hole_size = largest_hole;
24241+ return (mm->free_area_cache = addr);
24242 } else if (mm->free_area_cache == vma->vm_end) {
24243 /* pull free_area_cache down to the first hole */
24244 mm->free_area_cache = vma->vm_start;
24245@@ -352,29 +358,34 @@ try_again:
24246
24247 /* remember the largest hole we saw so far */
24248 if (addr + largest_hole < vma->vm_start)
24249- largest_hole = vma->vm_start - addr;
24250+ largest_hole = vma->vm_start - addr;
24251
24252 /* try just below the current vma->vm_start */
24253- addr = (vma->vm_start - len) & huge_page_mask(h);
24254- } while (len <= vma->vm_start);
24255+ addr = skip_heap_stack_gap(vma, len);
24256+ } while (!IS_ERR_VALUE(addr));
24257
24258 fail:
24259 /*
24260- * if hint left us with no space for the requested
24261- * mapping then try again:
24262- */
24263- if (start_addr != base) {
24264- mm->free_area_cache = base;
24265- largest_hole = 0;
24266- goto try_again;
24267- }
24268- /*
24269 * A failed mmap() very likely causes application failure,
24270 * so fall back to the bottom-up function here. This scenario
24271 * can happen with large stack limits and large mmap()
24272 * allocations.
24273 */
24274- mm->free_area_cache = TASK_UNMAPPED_BASE;
24275+
24276+#ifdef CONFIG_PAX_SEGMEXEC
24277+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24278+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24279+ else
24280+#endif
24281+
24282+ mm->mmap_base = TASK_UNMAPPED_BASE;
24283+
24284+#ifdef CONFIG_PAX_RANDMMAP
24285+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24286+ mm->mmap_base += mm->delta_mmap;
24287+#endif
24288+
24289+ mm->free_area_cache = mm->mmap_base;
24290 mm->cached_hole_size = ~0UL;
24291 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24292 len, pgoff, flags);
24293@@ -382,6 +393,7 @@ fail:
24294 /*
24295 * Restore the topdown base:
24296 */
24297+ mm->mmap_base = base;
24298 mm->free_area_cache = base;
24299 mm->cached_hole_size = ~0UL;
24300
24301@@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24302 struct hstate *h = hstate_file(file);
24303 struct mm_struct *mm = current->mm;
24304 struct vm_area_struct *vma;
24305+ unsigned long pax_task_size = TASK_SIZE;
24306
24307 if (len & ~huge_page_mask(h))
24308 return -EINVAL;
24309- if (len > TASK_SIZE)
24310+
24311+#ifdef CONFIG_PAX_SEGMEXEC
24312+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24313+ pax_task_size = SEGMEXEC_TASK_SIZE;
24314+#endif
24315+
24316+ pax_task_size -= PAGE_SIZE;
24317+
24318+ if (len > pax_task_size)
24319 return -ENOMEM;
24320
24321 if (flags & MAP_FIXED) {
24322@@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24323 if (addr) {
24324 addr = ALIGN(addr, huge_page_size(h));
24325 vma = find_vma(mm, addr);
24326- if (TASK_SIZE - len >= addr &&
24327- (!vma || addr + len <= vma->vm_start))
24328+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24329 return addr;
24330 }
24331 if (mm->get_unmapped_area == arch_get_unmapped_area)
24332diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24333index bc4e9d8..ca4c14b 100644
24334--- a/arch/x86/mm/init.c
24335+++ b/arch/x86/mm/init.c
24336@@ -16,6 +16,8 @@
24337 #include <asm/tlb.h>
24338 #include <asm/proto.h>
24339 #include <asm/dma.h> /* for MAX_DMA_PFN */
24340+#include <asm/desc.h>
24341+#include <asm/bios_ebda.h>
24342
24343 unsigned long __initdata pgt_buf_start;
24344 unsigned long __meminitdata pgt_buf_end;
24345@@ -38,7 +40,7 @@ struct map_range {
24346 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24347 int use_pse, int use_gbpages)
24348 {
24349- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24350+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24351 phys_addr_t base;
24352
24353 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24354@@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24355 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24356 * mmio resources as well as potential bios/acpi data regions.
24357 */
24358+
24359+#ifdef CONFIG_GRKERNSEC_KMEM
24360+static unsigned int ebda_start __read_only;
24361+static unsigned int ebda_end __read_only;
24362+#endif
24363+
24364 int devmem_is_allowed(unsigned long pagenr)
24365 {
24366+#ifdef CONFIG_GRKERNSEC_KMEM
24367+ /* allow BDA */
24368+ if (!pagenr)
24369+ return 1;
24370+ /* allow EBDA */
24371+ if (pagenr >= ebda_start && pagenr < ebda_end)
24372+ return 1;
24373+#else
24374+ if (!pagenr)
24375+ return 1;
24376+#ifdef CONFIG_VM86
24377+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24378+ return 1;
24379+#endif
24380+#endif
24381+
24382+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24383+ return 1;
24384+#ifdef CONFIG_GRKERNSEC_KMEM
24385+ /* throw out everything else below 1MB */
24386 if (pagenr <= 256)
24387- return 1;
24388+ return 0;
24389+#endif
24390 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24391 return 0;
24392 if (!page_is_ram(pagenr))
24393@@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24394 #endif
24395 }
24396
24397+#ifdef CONFIG_GRKERNSEC_KMEM
24398+static inline void gr_init_ebda(void)
24399+{
24400+ unsigned int ebda_addr;
24401+ unsigned int ebda_size = 0;
24402+
24403+ ebda_addr = get_bios_ebda();
24404+ if (ebda_addr) {
24405+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24406+ ebda_size <<= 10;
24407+ }
24408+ if (ebda_addr && ebda_size) {
24409+ ebda_start = ebda_addr >> PAGE_SHIFT;
24410+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24411+ } else {
24412+ ebda_start = 0x9f000 >> PAGE_SHIFT;
24413+ ebda_end = 0xa0000 >> PAGE_SHIFT;
24414+ }
24415+}
24416+#else
24417+static inline void gr_init_ebda(void) { }
24418+#endif
24419+
24420 void free_initmem(void)
24421 {
24422+#ifdef CONFIG_PAX_KERNEXEC
24423+#ifdef CONFIG_X86_32
24424+ /* PaX: limit KERNEL_CS to actual size */
24425+ unsigned long addr, limit;
24426+ struct desc_struct d;
24427+ int cpu;
24428+#else
24429+ pgd_t *pgd;
24430+ pud_t *pud;
24431+ pmd_t *pmd;
24432+ unsigned long addr, end;
24433+#endif
24434+#endif
24435+
24436+ gr_init_ebda();
24437+
24438+#ifdef CONFIG_PAX_KERNEXEC
24439+#ifdef CONFIG_X86_32
24440+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24441+ limit = (limit - 1UL) >> PAGE_SHIFT;
24442+
24443+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24444+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24445+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24446+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24447+ }
24448+
24449+ /* PaX: make KERNEL_CS read-only */
24450+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24451+ if (!paravirt_enabled())
24452+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24453+/*
24454+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24455+ pgd = pgd_offset_k(addr);
24456+ pud = pud_offset(pgd, addr);
24457+ pmd = pmd_offset(pud, addr);
24458+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24459+ }
24460+*/
24461+#ifdef CONFIG_X86_PAE
24462+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24463+/*
24464+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24465+ pgd = pgd_offset_k(addr);
24466+ pud = pud_offset(pgd, addr);
24467+ pmd = pmd_offset(pud, addr);
24468+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24469+ }
24470+*/
24471+#endif
24472+
24473+#ifdef CONFIG_MODULES
24474+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24475+#endif
24476+
24477+#else
24478+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24479+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24480+ pgd = pgd_offset_k(addr);
24481+ pud = pud_offset(pgd, addr);
24482+ pmd = pmd_offset(pud, addr);
24483+ if (!pmd_present(*pmd))
24484+ continue;
24485+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24486+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24487+ else
24488+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24489+ }
24490+
24491+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24492+ end = addr + KERNEL_IMAGE_SIZE;
24493+ for (; addr < end; addr += PMD_SIZE) {
24494+ pgd = pgd_offset_k(addr);
24495+ pud = pud_offset(pgd, addr);
24496+ pmd = pmd_offset(pud, addr);
24497+ if (!pmd_present(*pmd))
24498+ continue;
24499+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24500+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24501+ }
24502+#endif
24503+
24504+ flush_tlb_all();
24505+#endif
24506+
24507 free_init_pages("unused kernel memory",
24508 (unsigned long)(&__init_begin),
24509 (unsigned long)(&__init_end));
24510diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24511index 575d86f..4987469 100644
24512--- a/arch/x86/mm/init_32.c
24513+++ b/arch/x86/mm/init_32.c
24514@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24515 }
24516
24517 /*
24518- * Creates a middle page table and puts a pointer to it in the
24519- * given global directory entry. This only returns the gd entry
24520- * in non-PAE compilation mode, since the middle layer is folded.
24521- */
24522-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24523-{
24524- pud_t *pud;
24525- pmd_t *pmd_table;
24526-
24527-#ifdef CONFIG_X86_PAE
24528- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24529- if (after_bootmem)
24530- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24531- else
24532- pmd_table = (pmd_t *)alloc_low_page();
24533- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24534- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24535- pud = pud_offset(pgd, 0);
24536- BUG_ON(pmd_table != pmd_offset(pud, 0));
24537-
24538- return pmd_table;
24539- }
24540-#endif
24541- pud = pud_offset(pgd, 0);
24542- pmd_table = pmd_offset(pud, 0);
24543-
24544- return pmd_table;
24545-}
24546-
24547-/*
24548 * Create a page table and place a pointer to it in a middle page
24549 * directory entry:
24550 */
24551@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24552 page_table = (pte_t *)alloc_low_page();
24553
24554 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24555+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24556+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24557+#else
24558 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24559+#endif
24560 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24561 }
24562
24563 return pte_offset_kernel(pmd, 0);
24564 }
24565
24566+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24567+{
24568+ pud_t *pud;
24569+ pmd_t *pmd_table;
24570+
24571+ pud = pud_offset(pgd, 0);
24572+ pmd_table = pmd_offset(pud, 0);
24573+
24574+ return pmd_table;
24575+}
24576+
24577 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24578 {
24579 int pgd_idx = pgd_index(vaddr);
24580@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24581 int pgd_idx, pmd_idx;
24582 unsigned long vaddr;
24583 pgd_t *pgd;
24584+ pud_t *pud;
24585 pmd_t *pmd;
24586 pte_t *pte = NULL;
24587
24588@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24589 pgd = pgd_base + pgd_idx;
24590
24591 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24592- pmd = one_md_table_init(pgd);
24593- pmd = pmd + pmd_index(vaddr);
24594+ pud = pud_offset(pgd, vaddr);
24595+ pmd = pmd_offset(pud, vaddr);
24596+
24597+#ifdef CONFIG_X86_PAE
24598+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24599+#endif
24600+
24601 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24602 pmd++, pmd_idx++) {
24603 pte = page_table_kmap_check(one_page_table_init(pmd),
24604@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24605 }
24606 }
24607
24608-static inline int is_kernel_text(unsigned long addr)
24609+static inline int is_kernel_text(unsigned long start, unsigned long end)
24610 {
24611- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24612- return 1;
24613- return 0;
24614+ if ((start > ktla_ktva((unsigned long)_etext) ||
24615+ end <= ktla_ktva((unsigned long)_stext)) &&
24616+ (start > ktla_ktva((unsigned long)_einittext) ||
24617+ end <= ktla_ktva((unsigned long)_sinittext)) &&
24618+
24619+#ifdef CONFIG_ACPI_SLEEP
24620+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24621+#endif
24622+
24623+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24624+ return 0;
24625+ return 1;
24626 }
24627
24628 /*
24629@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24630 unsigned long last_map_addr = end;
24631 unsigned long start_pfn, end_pfn;
24632 pgd_t *pgd_base = swapper_pg_dir;
24633- int pgd_idx, pmd_idx, pte_ofs;
24634+ unsigned int pgd_idx, pmd_idx, pte_ofs;
24635 unsigned long pfn;
24636 pgd_t *pgd;
24637+ pud_t *pud;
24638 pmd_t *pmd;
24639 pte_t *pte;
24640 unsigned pages_2m, pages_4k;
24641@@ -280,8 +281,13 @@ repeat:
24642 pfn = start_pfn;
24643 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24644 pgd = pgd_base + pgd_idx;
24645- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24646- pmd = one_md_table_init(pgd);
24647+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24648+ pud = pud_offset(pgd, 0);
24649+ pmd = pmd_offset(pud, 0);
24650+
24651+#ifdef CONFIG_X86_PAE
24652+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24653+#endif
24654
24655 if (pfn >= end_pfn)
24656 continue;
24657@@ -293,14 +299,13 @@ repeat:
24658 #endif
24659 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24660 pmd++, pmd_idx++) {
24661- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24662+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24663
24664 /*
24665 * Map with big pages if possible, otherwise
24666 * create normal page tables:
24667 */
24668 if (use_pse) {
24669- unsigned int addr2;
24670 pgprot_t prot = PAGE_KERNEL_LARGE;
24671 /*
24672 * first pass will use the same initial
24673@@ -310,11 +315,7 @@ repeat:
24674 __pgprot(PTE_IDENT_ATTR |
24675 _PAGE_PSE);
24676
24677- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24678- PAGE_OFFSET + PAGE_SIZE-1;
24679-
24680- if (is_kernel_text(addr) ||
24681- is_kernel_text(addr2))
24682+ if (is_kernel_text(address, address + PMD_SIZE))
24683 prot = PAGE_KERNEL_LARGE_EXEC;
24684
24685 pages_2m++;
24686@@ -331,7 +332,7 @@ repeat:
24687 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24688 pte += pte_ofs;
24689 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24690- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24691+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24692 pgprot_t prot = PAGE_KERNEL;
24693 /*
24694 * first pass will use the same initial
24695@@ -339,7 +340,7 @@ repeat:
24696 */
24697 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24698
24699- if (is_kernel_text(addr))
24700+ if (is_kernel_text(address, address + PAGE_SIZE))
24701 prot = PAGE_KERNEL_EXEC;
24702
24703 pages_4k++;
24704@@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24705
24706 pud = pud_offset(pgd, va);
24707 pmd = pmd_offset(pud, va);
24708- if (!pmd_present(*pmd))
24709+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
24710 break;
24711
24712 pte = pte_offset_kernel(pmd, va);
24713@@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24714
24715 static void __init pagetable_init(void)
24716 {
24717- pgd_t *pgd_base = swapper_pg_dir;
24718-
24719- permanent_kmaps_init(pgd_base);
24720+ permanent_kmaps_init(swapper_pg_dir);
24721 }
24722
24723-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24724+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24725 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24726
24727 /* user-defined highmem size */
24728@@ -734,6 +733,12 @@ void __init mem_init(void)
24729
24730 pci_iommu_alloc();
24731
24732+#ifdef CONFIG_PAX_PER_CPU_PGD
24733+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24734+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24735+ KERNEL_PGD_PTRS);
24736+#endif
24737+
24738 #ifdef CONFIG_FLATMEM
24739 BUG_ON(!mem_map);
24740 #endif
24741@@ -760,7 +765,7 @@ void __init mem_init(void)
24742 reservedpages++;
24743
24744 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24745- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24746+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24747 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24748
24749 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24750@@ -801,10 +806,10 @@ void __init mem_init(void)
24751 ((unsigned long)&__init_end -
24752 (unsigned long)&__init_begin) >> 10,
24753
24754- (unsigned long)&_etext, (unsigned long)&_edata,
24755- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24756+ (unsigned long)&_sdata, (unsigned long)&_edata,
24757+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24758
24759- (unsigned long)&_text, (unsigned long)&_etext,
24760+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24761 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24762
24763 /*
24764@@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24765 if (!kernel_set_to_readonly)
24766 return;
24767
24768+ start = ktla_ktva(start);
24769 pr_debug("Set kernel text: %lx - %lx for read write\n",
24770 start, start+size);
24771
24772@@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24773 if (!kernel_set_to_readonly)
24774 return;
24775
24776+ start = ktla_ktva(start);
24777 pr_debug("Set kernel text: %lx - %lx for read only\n",
24778 start, start+size);
24779
24780@@ -924,6 +931,7 @@ void mark_rodata_ro(void)
24781 unsigned long start = PFN_ALIGN(_text);
24782 unsigned long size = PFN_ALIGN(_etext) - start;
24783
24784+ start = ktla_ktva(start);
24785 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24786 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24787 size >> 10);
24788diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24789index 2b6b4a3..c17210d 100644
24790--- a/arch/x86/mm/init_64.c
24791+++ b/arch/x86/mm/init_64.c
24792@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24793 * around without checking the pgd every time.
24794 */
24795
24796-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24797+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24798 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24799
24800 int force_personality32;
24801@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24802
24803 for (address = start; address <= end; address += PGDIR_SIZE) {
24804 const pgd_t *pgd_ref = pgd_offset_k(address);
24805+
24806+#ifdef CONFIG_PAX_PER_CPU_PGD
24807+ unsigned long cpu;
24808+#else
24809 struct page *page;
24810+#endif
24811
24812 if (pgd_none(*pgd_ref))
24813 continue;
24814
24815 spin_lock(&pgd_lock);
24816+
24817+#ifdef CONFIG_PAX_PER_CPU_PGD
24818+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24819+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
24820+#else
24821 list_for_each_entry(page, &pgd_list, lru) {
24822 pgd_t *pgd;
24823 spinlock_t *pgt_lock;
24824@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24825 /* the pgt_lock only for Xen */
24826 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24827 spin_lock(pgt_lock);
24828+#endif
24829
24830 if (pgd_none(*pgd))
24831 set_pgd(pgd, *pgd_ref);
24832@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24833 BUG_ON(pgd_page_vaddr(*pgd)
24834 != pgd_page_vaddr(*pgd_ref));
24835
24836+#ifndef CONFIG_PAX_PER_CPU_PGD
24837 spin_unlock(pgt_lock);
24838+#endif
24839+
24840 }
24841 spin_unlock(&pgd_lock);
24842 }
24843@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
24844 {
24845 if (pgd_none(*pgd)) {
24846 pud_t *pud = (pud_t *)spp_getpage();
24847- pgd_populate(&init_mm, pgd, pud);
24848+ pgd_populate_kernel(&init_mm, pgd, pud);
24849 if (pud != pud_offset(pgd, 0))
24850 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
24851 pud, pud_offset(pgd, 0));
24852@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
24853 {
24854 if (pud_none(*pud)) {
24855 pmd_t *pmd = (pmd_t *) spp_getpage();
24856- pud_populate(&init_mm, pud, pmd);
24857+ pud_populate_kernel(&init_mm, pud, pmd);
24858 if (pmd != pmd_offset(pud, 0))
24859 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
24860 pmd, pmd_offset(pud, 0));
24861@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24862 pmd = fill_pmd(pud, vaddr);
24863 pte = fill_pte(pmd, vaddr);
24864
24865+ pax_open_kernel();
24866 set_pte(pte, new_pte);
24867+ pax_close_kernel();
24868
24869 /*
24870 * It's enough to flush this one mapping.
24871@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24872 pgd = pgd_offset_k((unsigned long)__va(phys));
24873 if (pgd_none(*pgd)) {
24874 pud = (pud_t *) spp_getpage();
24875- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24876- _PAGE_USER));
24877+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24878 }
24879 pud = pud_offset(pgd, (unsigned long)__va(phys));
24880 if (pud_none(*pud)) {
24881 pmd = (pmd_t *) spp_getpage();
24882- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24883- _PAGE_USER));
24884+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24885 }
24886 pmd = pmd_offset(pud, phys);
24887 BUG_ON(!pmd_none(*pmd));
24888@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24889 if (pfn >= pgt_buf_top)
24890 panic("alloc_low_page: ran out of memory");
24891
24892- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24893+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24894 clear_page(adr);
24895 *phys = pfn * PAGE_SIZE;
24896 return adr;
24897@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
24898
24899 phys = __pa(virt);
24900 left = phys & (PAGE_SIZE - 1);
24901- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24902+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24903 adr = (void *)(((unsigned long)adr) | left);
24904
24905 return adr;
24906@@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
24907 unmap_low_page(pmd);
24908
24909 spin_lock(&init_mm.page_table_lock);
24910- pud_populate(&init_mm, pud, __va(pmd_phys));
24911+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
24912 spin_unlock(&init_mm.page_table_lock);
24913 }
24914 __flush_tlb_all();
24915@@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
24916 unmap_low_page(pud);
24917
24918 spin_lock(&init_mm.page_table_lock);
24919- pgd_populate(&init_mm, pgd, __va(pud_phys));
24920+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
24921 spin_unlock(&init_mm.page_table_lock);
24922 pgd_changed = true;
24923 }
24924@@ -686,6 +700,12 @@ void __init mem_init(void)
24925
24926 pci_iommu_alloc();
24927
24928+#ifdef CONFIG_PAX_PER_CPU_PGD
24929+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24930+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24931+ KERNEL_PGD_PTRS);
24932+#endif
24933+
24934 /* clear_bss() already clear the empty_zero_page */
24935
24936 reservedpages = 0;
24937@@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
24938 static struct vm_area_struct gate_vma = {
24939 .vm_start = VSYSCALL_START,
24940 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
24941- .vm_page_prot = PAGE_READONLY_EXEC,
24942- .vm_flags = VM_READ | VM_EXEC
24943+ .vm_page_prot = PAGE_READONLY,
24944+ .vm_flags = VM_READ
24945 };
24946
24947 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24948@@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
24949
24950 const char *arch_vma_name(struct vm_area_struct *vma)
24951 {
24952- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24953+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24954 return "[vdso]";
24955 if (vma == &gate_vma)
24956 return "[vsyscall]";
24957diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
24958index 7b179b4..6bd1777 100644
24959--- a/arch/x86/mm/iomap_32.c
24960+++ b/arch/x86/mm/iomap_32.c
24961@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
24962 type = kmap_atomic_idx_push();
24963 idx = type + KM_TYPE_NR * smp_processor_id();
24964 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24965+
24966+ pax_open_kernel();
24967 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
24968+ pax_close_kernel();
24969+
24970 arch_flush_lazy_mmu_mode();
24971
24972 return (void *)vaddr;
24973diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
24974index 78fe3f1..8293b6f 100644
24975--- a/arch/x86/mm/ioremap.c
24976+++ b/arch/x86/mm/ioremap.c
24977@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
24978 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
24979 int is_ram = page_is_ram(pfn);
24980
24981- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
24982+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
24983 return NULL;
24984 WARN_ON_ONCE(is_ram);
24985 }
24986@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
24987
24988 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
24989 if (page_is_ram(start >> PAGE_SHIFT))
24990+#ifdef CONFIG_HIGHMEM
24991+ if ((start >> PAGE_SHIFT) < max_low_pfn)
24992+#endif
24993 return __va(phys);
24994
24995 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
24996@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
24997 early_param("early_ioremap_debug", early_ioremap_debug_setup);
24998
24999 static __initdata int after_paging_init;
25000-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25001+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25002
25003 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25004 {
25005@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25006 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25007
25008 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25009- memset(bm_pte, 0, sizeof(bm_pte));
25010- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25011+ pmd_populate_user(&init_mm, pmd, bm_pte);
25012
25013 /*
25014 * The boot-ioremap range spans multiple pmds, for which
25015diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25016index d87dd6d..bf3fa66 100644
25017--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25018+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25019@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25020 * memory (e.g. tracked pages)? For now, we need this to avoid
25021 * invoking kmemcheck for PnP BIOS calls.
25022 */
25023- if (regs->flags & X86_VM_MASK)
25024+ if (v8086_mode(regs))
25025 return false;
25026- if (regs->cs != __KERNEL_CS)
25027+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25028 return false;
25029
25030 pte = kmemcheck_pte_lookup(address);
25031diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25032index 845df68..1d8d29f 100644
25033--- a/arch/x86/mm/mmap.c
25034+++ b/arch/x86/mm/mmap.c
25035@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25036 * Leave an at least ~128 MB hole with possible stack randomization.
25037 */
25038 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25039-#define MAX_GAP (TASK_SIZE/6*5)
25040+#define MAX_GAP (pax_task_size/6*5)
25041
25042 static int mmap_is_legacy(void)
25043 {
25044@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25045 return rnd << PAGE_SHIFT;
25046 }
25047
25048-static unsigned long mmap_base(void)
25049+static unsigned long mmap_base(struct mm_struct *mm)
25050 {
25051 unsigned long gap = rlimit(RLIMIT_STACK);
25052+ unsigned long pax_task_size = TASK_SIZE;
25053+
25054+#ifdef CONFIG_PAX_SEGMEXEC
25055+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25056+ pax_task_size = SEGMEXEC_TASK_SIZE;
25057+#endif
25058
25059 if (gap < MIN_GAP)
25060 gap = MIN_GAP;
25061 else if (gap > MAX_GAP)
25062 gap = MAX_GAP;
25063
25064- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25065+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25066 }
25067
25068 /*
25069 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25070 * does, but not when emulating X86_32
25071 */
25072-static unsigned long mmap_legacy_base(void)
25073+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25074 {
25075- if (mmap_is_ia32())
25076+ if (mmap_is_ia32()) {
25077+
25078+#ifdef CONFIG_PAX_SEGMEXEC
25079+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25080+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25081+ else
25082+#endif
25083+
25084 return TASK_UNMAPPED_BASE;
25085- else
25086+ } else
25087 return TASK_UNMAPPED_BASE + mmap_rnd();
25088 }
25089
25090@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25091 void arch_pick_mmap_layout(struct mm_struct *mm)
25092 {
25093 if (mmap_is_legacy()) {
25094- mm->mmap_base = mmap_legacy_base();
25095+ mm->mmap_base = mmap_legacy_base(mm);
25096+
25097+#ifdef CONFIG_PAX_RANDMMAP
25098+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25099+ mm->mmap_base += mm->delta_mmap;
25100+#endif
25101+
25102 mm->get_unmapped_area = arch_get_unmapped_area;
25103 mm->unmap_area = arch_unmap_area;
25104 } else {
25105- mm->mmap_base = mmap_base();
25106+ mm->mmap_base = mmap_base(mm);
25107+
25108+#ifdef CONFIG_PAX_RANDMMAP
25109+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25110+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25111+#endif
25112+
25113 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25114 mm->unmap_area = arch_unmap_area_topdown;
25115 }
25116diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25117index dc0b727..dc9d71a 100644
25118--- a/arch/x86/mm/mmio-mod.c
25119+++ b/arch/x86/mm/mmio-mod.c
25120@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25121 break;
25122 default:
25123 {
25124- unsigned char *ip = (unsigned char *)instptr;
25125+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25126 my_trace->opcode = MMIO_UNKNOWN_OP;
25127 my_trace->width = 0;
25128 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25129@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25130 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25131 void __iomem *addr)
25132 {
25133- static atomic_t next_id;
25134+ static atomic_unchecked_t next_id;
25135 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25136 /* These are page-unaligned. */
25137 struct mmiotrace_map map = {
25138@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25139 .private = trace
25140 },
25141 .phys = offset,
25142- .id = atomic_inc_return(&next_id)
25143+ .id = atomic_inc_return_unchecked(&next_id)
25144 };
25145 map.map_id = trace->id;
25146
25147diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25148index b008656..773eac2 100644
25149--- a/arch/x86/mm/pageattr-test.c
25150+++ b/arch/x86/mm/pageattr-test.c
25151@@ -36,7 +36,7 @@ enum {
25152
25153 static int pte_testbit(pte_t pte)
25154 {
25155- return pte_flags(pte) & _PAGE_UNUSED1;
25156+ return pte_flags(pte) & _PAGE_CPA_TEST;
25157 }
25158
25159 struct split_state {
25160diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25161index a718e0d..45efc32 100644
25162--- a/arch/x86/mm/pageattr.c
25163+++ b/arch/x86/mm/pageattr.c
25164@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25165 */
25166 #ifdef CONFIG_PCI_BIOS
25167 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25168- pgprot_val(forbidden) |= _PAGE_NX;
25169+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25170 #endif
25171
25172 /*
25173@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25174 * Does not cover __inittext since that is gone later on. On
25175 * 64bit we do not enforce !NX on the low mapping
25176 */
25177- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25178- pgprot_val(forbidden) |= _PAGE_NX;
25179+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25180+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25181
25182+#ifdef CONFIG_DEBUG_RODATA
25183 /*
25184 * The .rodata section needs to be read-only. Using the pfn
25185 * catches all aliases.
25186@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25187 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25188 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25189 pgprot_val(forbidden) |= _PAGE_RW;
25190+#endif
25191
25192 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25193 /*
25194@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25195 }
25196 #endif
25197
25198+#ifdef CONFIG_PAX_KERNEXEC
25199+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25200+ pgprot_val(forbidden) |= _PAGE_RW;
25201+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25202+ }
25203+#endif
25204+
25205 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25206
25207 return prot;
25208@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25209 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25210 {
25211 /* change init_mm */
25212+ pax_open_kernel();
25213 set_pte_atomic(kpte, pte);
25214+
25215 #ifdef CONFIG_X86_32
25216 if (!SHARED_KERNEL_PMD) {
25217+
25218+#ifdef CONFIG_PAX_PER_CPU_PGD
25219+ unsigned long cpu;
25220+#else
25221 struct page *page;
25222+#endif
25223
25224+#ifdef CONFIG_PAX_PER_CPU_PGD
25225+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25226+ pgd_t *pgd = get_cpu_pgd(cpu);
25227+#else
25228 list_for_each_entry(page, &pgd_list, lru) {
25229- pgd_t *pgd;
25230+ pgd_t *pgd = (pgd_t *)page_address(page);
25231+#endif
25232+
25233 pud_t *pud;
25234 pmd_t *pmd;
25235
25236- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25237+ pgd += pgd_index(address);
25238 pud = pud_offset(pgd, address);
25239 pmd = pmd_offset(pud, address);
25240 set_pte_atomic((pte_t *)pmd, pte);
25241 }
25242 }
25243 #endif
25244+ pax_close_kernel();
25245 }
25246
25247 static int
25248diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25249index 3d68ef6..7f69136 100644
25250--- a/arch/x86/mm/pat.c
25251+++ b/arch/x86/mm/pat.c
25252@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25253
25254 if (!entry) {
25255 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25256- current->comm, current->pid, start, end - 1);
25257+ current->comm, task_pid_nr(current), start, end - 1);
25258 return -EINVAL;
25259 }
25260
25261@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25262
25263 while (cursor < to) {
25264 if (!devmem_is_allowed(pfn)) {
25265- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25266- current->comm, from, to - 1);
25267+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25268+ current->comm, from, to - 1, cursor);
25269 return 0;
25270 }
25271 cursor += PAGE_SIZE;
25272@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25273 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25274 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25275 "for [mem %#010Lx-%#010Lx]\n",
25276- current->comm, current->pid,
25277+ current->comm, task_pid_nr(current),
25278 cattr_name(flags),
25279 base, (unsigned long long)(base + size-1));
25280 return -EINVAL;
25281@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25282 flags = lookup_memtype(paddr);
25283 if (want_flags != flags) {
25284 printk(KERN_WARNING "%s:%d map pfn RAM range req %s 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),
25290@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25291 free_memtype(paddr, paddr + size);
25292 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25293 " for [mem %#010Lx-%#010Lx], got %s\n",
25294- current->comm, current->pid,
25295+ current->comm, task_pid_nr(current),
25296 cattr_name(want_flags),
25297 (unsigned long long)paddr,
25298 (unsigned long long)(paddr + size - 1),
25299diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25300index 9f0614d..92ae64a 100644
25301--- a/arch/x86/mm/pf_in.c
25302+++ b/arch/x86/mm/pf_in.c
25303@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25304 int i;
25305 enum reason_type rv = OTHERS;
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@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_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@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
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
25330@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
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(reg_rop); i++)
25339@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25340 struct prefix_bits prf;
25341 int i;
25342
25343- p = (unsigned char *)ins_addr;
25344+ p = (unsigned char *)ktla_ktva(ins_addr);
25345 p += skip_prefix(p, &prf);
25346 p += get_opcode(p, &opcode);
25347 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25348diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25349index 8573b83..4f3ed7e 100644
25350--- a/arch/x86/mm/pgtable.c
25351+++ b/arch/x86/mm/pgtable.c
25352@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25353 list_del(&page->lru);
25354 }
25355
25356-#define UNSHARED_PTRS_PER_PGD \
25357- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25358+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25359+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25360
25361+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25362+{
25363+ unsigned int count = USER_PGD_PTRS;
25364
25365+ while (count--)
25366+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25367+}
25368+#endif
25369+
25370+#ifdef CONFIG_PAX_PER_CPU_PGD
25371+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25372+{
25373+ unsigned int count = USER_PGD_PTRS;
25374+
25375+ while (count--) {
25376+ pgd_t pgd;
25377+
25378+#ifdef CONFIG_X86_64
25379+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25380+#else
25381+ pgd = *src++;
25382+#endif
25383+
25384+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25385+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25386+#endif
25387+
25388+ *dst++ = pgd;
25389+ }
25390+
25391+}
25392+#endif
25393+
25394+#ifdef CONFIG_X86_64
25395+#define pxd_t pud_t
25396+#define pyd_t pgd_t
25397+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25398+#define pxd_free(mm, pud) pud_free((mm), (pud))
25399+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25400+#define pyd_offset(mm, address) pgd_offset((mm), (address))
25401+#define PYD_SIZE PGDIR_SIZE
25402+#else
25403+#define pxd_t pmd_t
25404+#define pyd_t pud_t
25405+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25406+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25407+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25408+#define pyd_offset(mm, address) pud_offset((mm), (address))
25409+#define PYD_SIZE PUD_SIZE
25410+#endif
25411+
25412+#ifdef CONFIG_PAX_PER_CPU_PGD
25413+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25414+static inline void pgd_dtor(pgd_t *pgd) {}
25415+#else
25416 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25417 {
25418 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25419@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25420 pgd_list_del(pgd);
25421 spin_unlock(&pgd_lock);
25422 }
25423+#endif
25424
25425 /*
25426 * List of all pgd's needed for non-PAE so it can invalidate entries
25427@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25428 * -- wli
25429 */
25430
25431-#ifdef CONFIG_X86_PAE
25432+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25433 /*
25434 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25435 * updating the top-level pagetable entries to guarantee the
25436@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25437 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25438 * and initialize the kernel pmds here.
25439 */
25440-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25441+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25442
25443 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25444 {
25445@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25446 */
25447 flush_tlb_mm(mm);
25448 }
25449+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25450+#define PREALLOCATED_PXDS USER_PGD_PTRS
25451 #else /* !CONFIG_X86_PAE */
25452
25453 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25454-#define PREALLOCATED_PMDS 0
25455+#define PREALLOCATED_PXDS 0
25456
25457 #endif /* CONFIG_X86_PAE */
25458
25459-static void free_pmds(pmd_t *pmds[])
25460+static void free_pxds(pxd_t *pxds[])
25461 {
25462 int i;
25463
25464- for(i = 0; i < PREALLOCATED_PMDS; i++)
25465- if (pmds[i])
25466- free_page((unsigned long)pmds[i]);
25467+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25468+ if (pxds[i])
25469+ free_page((unsigned long)pxds[i]);
25470 }
25471
25472-static int preallocate_pmds(pmd_t *pmds[])
25473+static int preallocate_pxds(pxd_t *pxds[])
25474 {
25475 int i;
25476 bool failed = false;
25477
25478- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25479- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25480- if (pmd == NULL)
25481+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25482+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25483+ if (pxd == NULL)
25484 failed = true;
25485- pmds[i] = pmd;
25486+ pxds[i] = pxd;
25487 }
25488
25489 if (failed) {
25490- free_pmds(pmds);
25491+ free_pxds(pxds);
25492 return -ENOMEM;
25493 }
25494
25495@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25496 * preallocate which never got a corresponding vma will need to be
25497 * freed manually.
25498 */
25499-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25500+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25501 {
25502 int i;
25503
25504- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25505+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25506 pgd_t pgd = pgdp[i];
25507
25508 if (pgd_val(pgd) != 0) {
25509- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25510+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25511
25512- pgdp[i] = native_make_pgd(0);
25513+ set_pgd(pgdp + i, native_make_pgd(0));
25514
25515- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25516- pmd_free(mm, pmd);
25517+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25518+ pxd_free(mm, pxd);
25519 }
25520 }
25521 }
25522
25523-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25524+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25525 {
25526- pud_t *pud;
25527+ pyd_t *pyd;
25528 unsigned long addr;
25529 int i;
25530
25531- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25532+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25533 return;
25534
25535- pud = pud_offset(pgd, 0);
25536+#ifdef CONFIG_X86_64
25537+ pyd = pyd_offset(mm, 0L);
25538+#else
25539+ pyd = pyd_offset(pgd, 0L);
25540+#endif
25541
25542- for (addr = i = 0; i < PREALLOCATED_PMDS;
25543- i++, pud++, addr += PUD_SIZE) {
25544- pmd_t *pmd = pmds[i];
25545+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25546+ i++, pyd++, addr += PYD_SIZE) {
25547+ pxd_t *pxd = pxds[i];
25548
25549 if (i >= KERNEL_PGD_BOUNDARY)
25550- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25551- sizeof(pmd_t) * PTRS_PER_PMD);
25552+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25553+ sizeof(pxd_t) * PTRS_PER_PMD);
25554
25555- pud_populate(mm, pud, pmd);
25556+ pyd_populate(mm, pyd, pxd);
25557 }
25558 }
25559
25560 pgd_t *pgd_alloc(struct mm_struct *mm)
25561 {
25562 pgd_t *pgd;
25563- pmd_t *pmds[PREALLOCATED_PMDS];
25564+ pxd_t *pxds[PREALLOCATED_PXDS];
25565
25566 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25567
25568@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25569
25570 mm->pgd = pgd;
25571
25572- if (preallocate_pmds(pmds) != 0)
25573+ if (preallocate_pxds(pxds) != 0)
25574 goto out_free_pgd;
25575
25576 if (paravirt_pgd_alloc(mm) != 0)
25577- goto out_free_pmds;
25578+ goto out_free_pxds;
25579
25580 /*
25581 * Make sure that pre-populating the pmds is atomic with
25582@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25583 spin_lock(&pgd_lock);
25584
25585 pgd_ctor(mm, pgd);
25586- pgd_prepopulate_pmd(mm, pgd, pmds);
25587+ pgd_prepopulate_pxd(mm, pgd, pxds);
25588
25589 spin_unlock(&pgd_lock);
25590
25591 return pgd;
25592
25593-out_free_pmds:
25594- free_pmds(pmds);
25595+out_free_pxds:
25596+ free_pxds(pxds);
25597 out_free_pgd:
25598 free_page((unsigned long)pgd);
25599 out:
25600@@ -295,7 +356,7 @@ out:
25601
25602 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25603 {
25604- pgd_mop_up_pmds(mm, pgd);
25605+ pgd_mop_up_pxds(mm, pgd);
25606 pgd_dtor(pgd);
25607 paravirt_pgd_free(mm, pgd);
25608 free_page((unsigned long)pgd);
25609diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25610index a69bcb8..19068ab 100644
25611--- a/arch/x86/mm/pgtable_32.c
25612+++ b/arch/x86/mm/pgtable_32.c
25613@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25614 return;
25615 }
25616 pte = pte_offset_kernel(pmd, vaddr);
25617+
25618+ pax_open_kernel();
25619 if (pte_val(pteval))
25620 set_pte_at(&init_mm, vaddr, pte, pteval);
25621 else
25622 pte_clear(&init_mm, vaddr, pte);
25623+ pax_close_kernel();
25624
25625 /*
25626 * It's enough to flush this one mapping.
25627diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25628index 410531d..0f16030 100644
25629--- a/arch/x86/mm/setup_nx.c
25630+++ b/arch/x86/mm/setup_nx.c
25631@@ -5,8 +5,10 @@
25632 #include <asm/pgtable.h>
25633 #include <asm/proto.h>
25634
25635+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25636 static int disable_nx __cpuinitdata;
25637
25638+#ifndef CONFIG_PAX_PAGEEXEC
25639 /*
25640 * noexec = on|off
25641 *
25642@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25643 return 0;
25644 }
25645 early_param("noexec", noexec_setup);
25646+#endif
25647+
25648+#endif
25649
25650 void __cpuinit x86_configure_nx(void)
25651 {
25652+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25653 if (cpu_has_nx && !disable_nx)
25654 __supported_pte_mask |= _PAGE_NX;
25655 else
25656+#endif
25657 __supported_pte_mask &= ~_PAGE_NX;
25658 }
25659
25660diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25661index 5e57e11..64874249 100644
25662--- a/arch/x86/mm/tlb.c
25663+++ b/arch/x86/mm/tlb.c
25664@@ -66,7 +66,11 @@ void leave_mm(int cpu)
25665 BUG();
25666 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25667 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25668+
25669+#ifndef CONFIG_PAX_PER_CPU_PGD
25670 load_cr3(swapper_pg_dir);
25671+#endif
25672+
25673 }
25674 }
25675 EXPORT_SYMBOL_GPL(leave_mm);
25676diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25677index 877b9a1..a8ecf42 100644
25678--- a/arch/x86/net/bpf_jit.S
25679+++ b/arch/x86/net/bpf_jit.S
25680@@ -9,6 +9,7 @@
25681 */
25682 #include <linux/linkage.h>
25683 #include <asm/dwarf2.h>
25684+#include <asm/alternative-asm.h>
25685
25686 /*
25687 * Calling convention :
25688@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25689 jle bpf_slow_path_word
25690 mov (SKBDATA,%rsi),%eax
25691 bswap %eax /* ntohl() */
25692+ pax_force_retaddr
25693 ret
25694
25695 sk_load_half:
25696@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25697 jle bpf_slow_path_half
25698 movzwl (SKBDATA,%rsi),%eax
25699 rol $8,%ax # ntohs()
25700+ pax_force_retaddr
25701 ret
25702
25703 sk_load_byte:
25704@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25705 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25706 jle bpf_slow_path_byte
25707 movzbl (SKBDATA,%rsi),%eax
25708+ pax_force_retaddr
25709 ret
25710
25711 /**
25712@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25713 movzbl (SKBDATA,%rsi),%ebx
25714 and $15,%bl
25715 shl $2,%bl
25716+ pax_force_retaddr
25717 ret
25718
25719 /* rsi contains offset and can be scratched */
25720@@ -109,6 +114,7 @@ bpf_slow_path_word:
25721 js bpf_error
25722 mov -12(%rbp),%eax
25723 bswap %eax
25724+ pax_force_retaddr
25725 ret
25726
25727 bpf_slow_path_half:
25728@@ -117,12 +123,14 @@ bpf_slow_path_half:
25729 mov -12(%rbp),%ax
25730 rol $8,%ax
25731 movzwl %ax,%eax
25732+ pax_force_retaddr
25733 ret
25734
25735 bpf_slow_path_byte:
25736 bpf_slow_path_common(1)
25737 js bpf_error
25738 movzbl -12(%rbp),%eax
25739+ pax_force_retaddr
25740 ret
25741
25742 bpf_slow_path_byte_msh:
25743@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25744 and $15,%al
25745 shl $2,%al
25746 xchg %eax,%ebx
25747+ pax_force_retaddr
25748 ret
25749
25750 #define sk_negative_common(SIZE) \
25751@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25752 sk_negative_common(4)
25753 mov (%rax), %eax
25754 bswap %eax
25755+ pax_force_retaddr
25756 ret
25757
25758 bpf_slow_path_half_neg:
25759@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25760 mov (%rax),%ax
25761 rol $8,%ax
25762 movzwl %ax,%eax
25763+ pax_force_retaddr
25764 ret
25765
25766 bpf_slow_path_byte_neg:
25767@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25768 .globl sk_load_byte_negative_offset
25769 sk_negative_common(1)
25770 movzbl (%rax), %eax
25771+ pax_force_retaddr
25772 ret
25773
25774 bpf_slow_path_byte_msh_neg:
25775@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
25776 and $15,%al
25777 shl $2,%al
25778 xchg %eax,%ebx
25779+ pax_force_retaddr
25780 ret
25781
25782 bpf_error:
25783@@ -197,4 +210,5 @@ bpf_error:
25784 xor %eax,%eax
25785 mov -8(%rbp),%rbx
25786 leaveq
25787+ pax_force_retaddr
25788 ret
25789diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25790index 0597f95..a12c36e 100644
25791--- a/arch/x86/net/bpf_jit_comp.c
25792+++ b/arch/x86/net/bpf_jit_comp.c
25793@@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
25794 set_fs(old_fs);
25795 }
25796
25797+struct bpf_jit_work {
25798+ struct work_struct work;
25799+ void *image;
25800+};
25801+
25802 #define CHOOSE_LOAD_FUNC(K, func) \
25803 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
25804
25805@@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25806 if (addrs == NULL)
25807 return;
25808
25809+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25810+ if (!fp->work)
25811+ goto out;
25812+
25813 /* Before first pass, make a rough estimation of addrs[]
25814 * each bpf instruction is translated to less than 64 bytes
25815 */
25816@@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25817 break;
25818 default:
25819 /* hmm, too complex filter, give up with jit compiler */
25820- goto out;
25821+ goto error;
25822 }
25823 ilen = prog - temp;
25824 if (image) {
25825 if (unlikely(proglen + ilen > oldproglen)) {
25826 pr_err("bpb_jit_compile fatal error\n");
25827- kfree(addrs);
25828- module_free(NULL, image);
25829- return;
25830+ module_free_exec(NULL, image);
25831+ goto error;
25832 }
25833+ pax_open_kernel();
25834 memcpy(image + proglen, temp, ilen);
25835+ pax_close_kernel();
25836 }
25837 proglen += ilen;
25838 addrs[i] = proglen;
25839@@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25840 break;
25841 }
25842 if (proglen == oldproglen) {
25843- image = module_alloc(max_t(unsigned int,
25844- proglen,
25845- sizeof(struct work_struct)));
25846+ image = module_alloc_exec(proglen);
25847 if (!image)
25848- goto out;
25849+ goto error;
25850 }
25851 oldproglen = proglen;
25852 }
25853@@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25854 bpf_flush_icache(image, image + proglen);
25855
25856 fp->bpf_func = (void *)image;
25857- }
25858+ } else
25859+error:
25860+ kfree(fp->work);
25861+
25862 out:
25863 kfree(addrs);
25864 return;
25865@@ -648,18 +659,20 @@ out:
25866
25867 static void jit_free_defer(struct work_struct *arg)
25868 {
25869- module_free(NULL, arg);
25870+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25871+ kfree(arg);
25872 }
25873
25874 /* run from softirq, we must use a work_struct to call
25875- * module_free() from process context
25876+ * module_free_exec() from process context
25877 */
25878 void bpf_jit_free(struct sk_filter *fp)
25879 {
25880 if (fp->bpf_func != sk_run_filter) {
25881- struct work_struct *work = (struct work_struct *)fp->bpf_func;
25882+ struct work_struct *work = &fp->work->work;
25883
25884 INIT_WORK(work, jit_free_defer);
25885+ fp->work->image = fp->bpf_func;
25886 schedule_work(work);
25887 }
25888 }
25889diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25890index d6aa6e8..266395a 100644
25891--- a/arch/x86/oprofile/backtrace.c
25892+++ b/arch/x86/oprofile/backtrace.c
25893@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25894 struct stack_frame_ia32 *fp;
25895 unsigned long bytes;
25896
25897- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25898+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25899 if (bytes != sizeof(bufhead))
25900 return NULL;
25901
25902- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25903+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25904
25905 oprofile_add_trace(bufhead[0].return_address);
25906
25907@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25908 struct stack_frame bufhead[2];
25909 unsigned long bytes;
25910
25911- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25912+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25913 if (bytes != sizeof(bufhead))
25914 return NULL;
25915
25916@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25917 {
25918 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25919
25920- if (!user_mode_vm(regs)) {
25921+ if (!user_mode(regs)) {
25922 unsigned long stack = kernel_stack_pointer(regs);
25923 if (depth)
25924 dump_trace(NULL, regs, (unsigned long *)stack, 0,
25925diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
25926index 140942f..8a5cc55 100644
25927--- a/arch/x86/pci/mrst.c
25928+++ b/arch/x86/pci/mrst.c
25929@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
25930 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
25931 pci_mmcfg_late_init();
25932 pcibios_enable_irq = mrst_pci_irq_enable;
25933- pci_root_ops = pci_mrst_ops;
25934+ pax_open_kernel();
25935+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
25936+ pax_close_kernel();
25937 pci_soc_mode = 1;
25938 /* Continue with standard init */
25939 return 1;
25940diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
25941index da8fe05..7ee6704 100644
25942--- a/arch/x86/pci/pcbios.c
25943+++ b/arch/x86/pci/pcbios.c
25944@@ -79,50 +79,93 @@ union bios32 {
25945 static struct {
25946 unsigned long address;
25947 unsigned short segment;
25948-} bios32_indirect = { 0, __KERNEL_CS };
25949+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
25950
25951 /*
25952 * Returns the entry point for the given service, NULL on error
25953 */
25954
25955-static unsigned long bios32_service(unsigned long service)
25956+static unsigned long __devinit bios32_service(unsigned long service)
25957 {
25958 unsigned char return_code; /* %al */
25959 unsigned long address; /* %ebx */
25960 unsigned long length; /* %ecx */
25961 unsigned long entry; /* %edx */
25962 unsigned long flags;
25963+ struct desc_struct d, *gdt;
25964
25965 local_irq_save(flags);
25966- __asm__("lcall *(%%edi); cld"
25967+
25968+ gdt = get_cpu_gdt_table(smp_processor_id());
25969+
25970+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
25971+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25972+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
25973+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25974+
25975+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
25976 : "=a" (return_code),
25977 "=b" (address),
25978 "=c" (length),
25979 "=d" (entry)
25980 : "0" (service),
25981 "1" (0),
25982- "D" (&bios32_indirect));
25983+ "D" (&bios32_indirect),
25984+ "r"(__PCIBIOS_DS)
25985+ : "memory");
25986+
25987+ pax_open_kernel();
25988+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
25989+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
25990+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
25991+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
25992+ pax_close_kernel();
25993+
25994 local_irq_restore(flags);
25995
25996 switch (return_code) {
25997- case 0:
25998- return address + entry;
25999- case 0x80: /* Not present */
26000- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26001- return 0;
26002- default: /* Shouldn't happen */
26003- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26004- service, return_code);
26005+ case 0: {
26006+ int cpu;
26007+ unsigned char flags;
26008+
26009+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26010+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26011+ printk(KERN_WARNING "bios32_service: not valid\n");
26012 return 0;
26013+ }
26014+ address = address + PAGE_OFFSET;
26015+ length += 16UL; /* some BIOSs underreport this... */
26016+ flags = 4;
26017+ if (length >= 64*1024*1024) {
26018+ length >>= PAGE_SHIFT;
26019+ flags |= 8;
26020+ }
26021+
26022+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26023+ gdt = get_cpu_gdt_table(cpu);
26024+ pack_descriptor(&d, address, length, 0x9b, flags);
26025+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26026+ pack_descriptor(&d, address, length, 0x93, flags);
26027+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26028+ }
26029+ return entry;
26030+ }
26031+ case 0x80: /* Not present */
26032+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26033+ return 0;
26034+ default: /* Shouldn't happen */
26035+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26036+ service, return_code);
26037+ return 0;
26038 }
26039 }
26040
26041 static struct {
26042 unsigned long address;
26043 unsigned short segment;
26044-} pci_indirect = { 0, __KERNEL_CS };
26045+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26046
26047-static int pci_bios_present;
26048+static int pci_bios_present __read_only;
26049
26050 static int __devinit check_pcibios(void)
26051 {
26052@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26053 unsigned long flags, pcibios_entry;
26054
26055 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26056- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26057+ pci_indirect.address = pcibios_entry;
26058
26059 local_irq_save(flags);
26060- __asm__(
26061- "lcall *(%%edi); cld\n\t"
26062+ __asm__("movw %w6, %%ds\n\t"
26063+ "lcall *%%ss:(%%edi); cld\n\t"
26064+ "push %%ss\n\t"
26065+ "pop %%ds\n\t"
26066 "jc 1f\n\t"
26067 "xor %%ah, %%ah\n"
26068 "1:"
26069@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26070 "=b" (ebx),
26071 "=c" (ecx)
26072 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26073- "D" (&pci_indirect)
26074+ "D" (&pci_indirect),
26075+ "r" (__PCIBIOS_DS)
26076 : "memory");
26077 local_irq_restore(flags);
26078
26079@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26080
26081 switch (len) {
26082 case 1:
26083- __asm__("lcall *(%%esi); cld\n\t"
26084+ __asm__("movw %w6, %%ds\n\t"
26085+ "lcall *%%ss:(%%esi); cld\n\t"
26086+ "push %%ss\n\t"
26087+ "pop %%ds\n\t"
26088 "jc 1f\n\t"
26089 "xor %%ah, %%ah\n"
26090 "1:"
26091@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26092 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26093 "b" (bx),
26094 "D" ((long)reg),
26095- "S" (&pci_indirect));
26096+ "S" (&pci_indirect),
26097+ "r" (__PCIBIOS_DS));
26098 /*
26099 * Zero-extend the result beyond 8 bits, do not trust the
26100 * BIOS having done it:
26101@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26102 *value &= 0xff;
26103 break;
26104 case 2:
26105- __asm__("lcall *(%%esi); cld\n\t"
26106+ __asm__("movw %w6, %%ds\n\t"
26107+ "lcall *%%ss:(%%esi); cld\n\t"
26108+ "push %%ss\n\t"
26109+ "pop %%ds\n\t"
26110 "jc 1f\n\t"
26111 "xor %%ah, %%ah\n"
26112 "1:"
26113@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26114 : "1" (PCIBIOS_READ_CONFIG_WORD),
26115 "b" (bx),
26116 "D" ((long)reg),
26117- "S" (&pci_indirect));
26118+ "S" (&pci_indirect),
26119+ "r" (__PCIBIOS_DS));
26120 /*
26121 * Zero-extend the result beyond 16 bits, do not trust the
26122 * BIOS having done it:
26123@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26124 *value &= 0xffff;
26125 break;
26126 case 4:
26127- __asm__("lcall *(%%esi); cld\n\t"
26128+ __asm__("movw %w6, %%ds\n\t"
26129+ "lcall *%%ss:(%%esi); cld\n\t"
26130+ "push %%ss\n\t"
26131+ "pop %%ds\n\t"
26132 "jc 1f\n\t"
26133 "xor %%ah, %%ah\n"
26134 "1:"
26135@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26136 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26137 "b" (bx),
26138 "D" ((long)reg),
26139- "S" (&pci_indirect));
26140+ "S" (&pci_indirect),
26141+ "r" (__PCIBIOS_DS));
26142 break;
26143 }
26144
26145@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26146
26147 switch (len) {
26148 case 1:
26149- __asm__("lcall *(%%esi); cld\n\t"
26150+ __asm__("movw %w6, %%ds\n\t"
26151+ "lcall *%%ss:(%%esi); cld\n\t"
26152+ "push %%ss\n\t"
26153+ "pop %%ds\n\t"
26154 "jc 1f\n\t"
26155 "xor %%ah, %%ah\n"
26156 "1:"
26157@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26158 "c" (value),
26159 "b" (bx),
26160 "D" ((long)reg),
26161- "S" (&pci_indirect));
26162+ "S" (&pci_indirect),
26163+ "r" (__PCIBIOS_DS));
26164 break;
26165 case 2:
26166- __asm__("lcall *(%%esi); cld\n\t"
26167+ __asm__("movw %w6, %%ds\n\t"
26168+ "lcall *%%ss:(%%esi); cld\n\t"
26169+ "push %%ss\n\t"
26170+ "pop %%ds\n\t"
26171 "jc 1f\n\t"
26172 "xor %%ah, %%ah\n"
26173 "1:"
26174@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26175 "c" (value),
26176 "b" (bx),
26177 "D" ((long)reg),
26178- "S" (&pci_indirect));
26179+ "S" (&pci_indirect),
26180+ "r" (__PCIBIOS_DS));
26181 break;
26182 case 4:
26183- __asm__("lcall *(%%esi); cld\n\t"
26184+ __asm__("movw %w6, %%ds\n\t"
26185+ "lcall *%%ss:(%%esi); cld\n\t"
26186+ "push %%ss\n\t"
26187+ "pop %%ds\n\t"
26188 "jc 1f\n\t"
26189 "xor %%ah, %%ah\n"
26190 "1:"
26191@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26192 "c" (value),
26193 "b" (bx),
26194 "D" ((long)reg),
26195- "S" (&pci_indirect));
26196+ "S" (&pci_indirect),
26197+ "r" (__PCIBIOS_DS));
26198 break;
26199 }
26200
26201@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26202
26203 DBG("PCI: Fetching IRQ routing table... ");
26204 __asm__("push %%es\n\t"
26205+ "movw %w8, %%ds\n\t"
26206 "push %%ds\n\t"
26207 "pop %%es\n\t"
26208- "lcall *(%%esi); cld\n\t"
26209+ "lcall *%%ss:(%%esi); cld\n\t"
26210 "pop %%es\n\t"
26211+ "push %%ss\n\t"
26212+ "pop %%ds\n"
26213 "jc 1f\n\t"
26214 "xor %%ah, %%ah\n"
26215 "1:"
26216@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26217 "1" (0),
26218 "D" ((long) &opt),
26219 "S" (&pci_indirect),
26220- "m" (opt)
26221+ "m" (opt),
26222+ "r" (__PCIBIOS_DS)
26223 : "memory");
26224 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26225 if (ret & 0xff00)
26226@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26227 {
26228 int ret;
26229
26230- __asm__("lcall *(%%esi); cld\n\t"
26231+ __asm__("movw %w5, %%ds\n\t"
26232+ "lcall *%%ss:(%%esi); cld\n\t"
26233+ "push %%ss\n\t"
26234+ "pop %%ds\n"
26235 "jc 1f\n\t"
26236 "xor %%ah, %%ah\n"
26237 "1:"
26238@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26239 : "0" (PCIBIOS_SET_PCI_HW_INT),
26240 "b" ((dev->bus->number << 8) | dev->devfn),
26241 "c" ((irq << 8) | (pin + 10)),
26242- "S" (&pci_indirect));
26243+ "S" (&pci_indirect),
26244+ "r" (__PCIBIOS_DS));
26245 return !(ret & 0xff00);
26246 }
26247 EXPORT_SYMBOL(pcibios_set_irq_routing);
26248diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26249index 40e4469..1ab536e 100644
26250--- a/arch/x86/platform/efi/efi_32.c
26251+++ b/arch/x86/platform/efi/efi_32.c
26252@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26253 {
26254 struct desc_ptr gdt_descr;
26255
26256+#ifdef CONFIG_PAX_KERNEXEC
26257+ struct desc_struct d;
26258+#endif
26259+
26260 local_irq_save(efi_rt_eflags);
26261
26262 load_cr3(initial_page_table);
26263 __flush_tlb_all();
26264
26265+#ifdef CONFIG_PAX_KERNEXEC
26266+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26267+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26268+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26269+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26270+#endif
26271+
26272 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26273 gdt_descr.size = GDT_SIZE - 1;
26274 load_gdt(&gdt_descr);
26275@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26276 {
26277 struct desc_ptr gdt_descr;
26278
26279+#ifdef CONFIG_PAX_KERNEXEC
26280+ struct desc_struct d;
26281+
26282+ memset(&d, 0, sizeof d);
26283+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26284+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26285+#endif
26286+
26287 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26288 gdt_descr.size = GDT_SIZE - 1;
26289 load_gdt(&gdt_descr);
26290diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26291index fbe66e6..eae5e38 100644
26292--- a/arch/x86/platform/efi/efi_stub_32.S
26293+++ b/arch/x86/platform/efi/efi_stub_32.S
26294@@ -6,7 +6,9 @@
26295 */
26296
26297 #include <linux/linkage.h>
26298+#include <linux/init.h>
26299 #include <asm/page_types.h>
26300+#include <asm/segment.h>
26301
26302 /*
26303 * efi_call_phys(void *, ...) is a function with variable parameters.
26304@@ -20,7 +22,7 @@
26305 * service functions will comply with gcc calling convention, too.
26306 */
26307
26308-.text
26309+__INIT
26310 ENTRY(efi_call_phys)
26311 /*
26312 * 0. The function can only be called in Linux kernel. So CS has been
26313@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26314 * The mapping of lower virtual memory has been created in prelog and
26315 * epilog.
26316 */
26317- movl $1f, %edx
26318- subl $__PAGE_OFFSET, %edx
26319- jmp *%edx
26320+#ifdef CONFIG_PAX_KERNEXEC
26321+ movl $(__KERNEXEC_EFI_DS), %edx
26322+ mov %edx, %ds
26323+ mov %edx, %es
26324+ mov %edx, %ss
26325+ addl $2f,(1f)
26326+ ljmp *(1f)
26327+
26328+__INITDATA
26329+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26330+.previous
26331+
26332+2:
26333+ subl $2b,(1b)
26334+#else
26335+ jmp 1f-__PAGE_OFFSET
26336 1:
26337+#endif
26338
26339 /*
26340 * 2. Now on the top of stack is the return
26341@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26342 * parameter 2, ..., param n. To make things easy, we save the return
26343 * address of efi_call_phys in a global variable.
26344 */
26345- popl %edx
26346- movl %edx, saved_return_addr
26347- /* get the function pointer into ECX*/
26348- popl %ecx
26349- movl %ecx, efi_rt_function_ptr
26350- movl $2f, %edx
26351- subl $__PAGE_OFFSET, %edx
26352- pushl %edx
26353+ popl (saved_return_addr)
26354+ popl (efi_rt_function_ptr)
26355
26356 /*
26357 * 3. Clear PG bit in %CR0.
26358@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26359 /*
26360 * 5. Call the physical function.
26361 */
26362- jmp *%ecx
26363+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
26364
26365-2:
26366 /*
26367 * 6. After EFI runtime service returns, control will return to
26368 * following instruction. We'd better readjust stack pointer first.
26369@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26370 movl %cr0, %edx
26371 orl $0x80000000, %edx
26372 movl %edx, %cr0
26373- jmp 1f
26374-1:
26375+
26376 /*
26377 * 8. Now restore the virtual mode from flat mode by
26378 * adding EIP with PAGE_OFFSET.
26379 */
26380- movl $1f, %edx
26381- jmp *%edx
26382+#ifdef CONFIG_PAX_KERNEXEC
26383+ movl $(__KERNEL_DS), %edx
26384+ mov %edx, %ds
26385+ mov %edx, %es
26386+ mov %edx, %ss
26387+ ljmp $(__KERNEL_CS),$1f
26388+#else
26389+ jmp 1f+__PAGE_OFFSET
26390+#endif
26391 1:
26392
26393 /*
26394 * 9. Balance the stack. And because EAX contain the return value,
26395 * we'd better not clobber it.
26396 */
26397- leal efi_rt_function_ptr, %edx
26398- movl (%edx), %ecx
26399- pushl %ecx
26400+ pushl (efi_rt_function_ptr)
26401
26402 /*
26403- * 10. Push the saved return address onto the stack and return.
26404+ * 10. Return to the saved return address.
26405 */
26406- leal saved_return_addr, %edx
26407- movl (%edx), %ecx
26408- pushl %ecx
26409- ret
26410+ jmpl *(saved_return_addr)
26411 ENDPROC(efi_call_phys)
26412 .previous
26413
26414-.data
26415+__INITDATA
26416 saved_return_addr:
26417 .long 0
26418 efi_rt_function_ptr:
26419diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26420index 4c07cca..2c8427d 100644
26421--- a/arch/x86/platform/efi/efi_stub_64.S
26422+++ b/arch/x86/platform/efi/efi_stub_64.S
26423@@ -7,6 +7,7 @@
26424 */
26425
26426 #include <linux/linkage.h>
26427+#include <asm/alternative-asm.h>
26428
26429 #define SAVE_XMM \
26430 mov %rsp, %rax; \
26431@@ -40,6 +41,7 @@ ENTRY(efi_call0)
26432 call *%rdi
26433 addq $32, %rsp
26434 RESTORE_XMM
26435+ pax_force_retaddr 0, 1
26436 ret
26437 ENDPROC(efi_call0)
26438
26439@@ -50,6 +52,7 @@ ENTRY(efi_call1)
26440 call *%rdi
26441 addq $32, %rsp
26442 RESTORE_XMM
26443+ pax_force_retaddr 0, 1
26444 ret
26445 ENDPROC(efi_call1)
26446
26447@@ -60,6 +63,7 @@ ENTRY(efi_call2)
26448 call *%rdi
26449 addq $32, %rsp
26450 RESTORE_XMM
26451+ pax_force_retaddr 0, 1
26452 ret
26453 ENDPROC(efi_call2)
26454
26455@@ -71,6 +75,7 @@ ENTRY(efi_call3)
26456 call *%rdi
26457 addq $32, %rsp
26458 RESTORE_XMM
26459+ pax_force_retaddr 0, 1
26460 ret
26461 ENDPROC(efi_call3)
26462
26463@@ -83,6 +88,7 @@ ENTRY(efi_call4)
26464 call *%rdi
26465 addq $32, %rsp
26466 RESTORE_XMM
26467+ pax_force_retaddr 0, 1
26468 ret
26469 ENDPROC(efi_call4)
26470
26471@@ -96,6 +102,7 @@ ENTRY(efi_call5)
26472 call *%rdi
26473 addq $48, %rsp
26474 RESTORE_XMM
26475+ pax_force_retaddr 0, 1
26476 ret
26477 ENDPROC(efi_call5)
26478
26479@@ -112,5 +119,6 @@ ENTRY(efi_call6)
26480 call *%rdi
26481 addq $48, %rsp
26482 RESTORE_XMM
26483+ pax_force_retaddr 0, 1
26484 ret
26485 ENDPROC(efi_call6)
26486diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26487index fd41a92..9c33628 100644
26488--- a/arch/x86/platform/mrst/mrst.c
26489+++ b/arch/x86/platform/mrst/mrst.c
26490@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26491 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26492 int sfi_mrtc_num;
26493
26494-static void mrst_power_off(void)
26495+static __noreturn void mrst_power_off(void)
26496 {
26497+ BUG();
26498 }
26499
26500-static void mrst_reboot(void)
26501+static __noreturn void mrst_reboot(void)
26502 {
26503 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26504+ BUG();
26505 }
26506
26507 /* parse all the mtimer info to a static mtimer array */
26508diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26509index 218cdb1..fd55c08 100644
26510--- a/arch/x86/power/cpu.c
26511+++ b/arch/x86/power/cpu.c
26512@@ -132,7 +132,7 @@ static void do_fpu_end(void)
26513 static void fix_processor_context(void)
26514 {
26515 int cpu = smp_processor_id();
26516- struct tss_struct *t = &per_cpu(init_tss, cpu);
26517+ struct tss_struct *t = init_tss + cpu;
26518
26519 set_tss_desc(cpu, t); /*
26520 * This just modifies memory; should not be
26521@@ -142,7 +142,9 @@ static void fix_processor_context(void)
26522 */
26523
26524 #ifdef CONFIG_X86_64
26525+ pax_open_kernel();
26526 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26527+ pax_close_kernel();
26528
26529 syscall_init(); /* This sets MSR_*STAR and related */
26530 #endif
26531diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26532index cbca565..35ce1d7 100644
26533--- a/arch/x86/realmode/init.c
26534+++ b/arch/x86/realmode/init.c
26535@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26536 __va(real_mode_header->trampoline_header);
26537
26538 #ifdef CONFIG_X86_32
26539- trampoline_header->start = __pa(startup_32_smp);
26540+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26541+
26542+#ifdef CONFIG_PAX_KERNEXEC
26543+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26544+#endif
26545+
26546+ trampoline_header->boot_cs = __BOOT_CS;
26547 trampoline_header->gdt_limit = __BOOT_DS + 7;
26548 trampoline_header->gdt_base = __pa(boot_gdt);
26549 #else
26550diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26551index 5b84a2d..a004393 100644
26552--- a/arch/x86/realmode/rm/Makefile
26553+++ b/arch/x86/realmode/rm/Makefile
26554@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26555 $(call cc-option, -fno-unit-at-a-time)) \
26556 $(call cc-option, -fno-stack-protector) \
26557 $(call cc-option, -mpreferred-stack-boundary=2)
26558+ifdef CONSTIFY_PLUGIN
26559+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
26560+endif
26561 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26562 GCOV_PROFILE := n
26563diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26564index c1b2791..f9e31c7 100644
26565--- a/arch/x86/realmode/rm/trampoline_32.S
26566+++ b/arch/x86/realmode/rm/trampoline_32.S
26567@@ -25,6 +25,12 @@
26568 #include <asm/page_types.h>
26569 #include "realmode.h"
26570
26571+#ifdef CONFIG_PAX_KERNEXEC
26572+#define ta(X) (X)
26573+#else
26574+#define ta(X) (pa_ ## X)
26575+#endif
26576+
26577 .text
26578 .code16
26579
26580@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26581
26582 cli # We should be safe anyway
26583
26584- movl tr_start, %eax # where we need to go
26585-
26586 movl $0xA5A5A5A5, trampoline_status
26587 # write marker for master knows we're running
26588
26589@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26590 movw $1, %dx # protected mode (PE) bit
26591 lmsw %dx # into protected mode
26592
26593- ljmpl $__BOOT_CS, $pa_startup_32
26594+ ljmpl *(trampoline_header)
26595
26596 .section ".text32","ax"
26597 .code32
26598@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26599 .balign 8
26600 GLOBAL(trampoline_header)
26601 tr_start: .space 4
26602- tr_gdt_pad: .space 2
26603+ tr_boot_cs: .space 2
26604 tr_gdt: .space 6
26605 END(trampoline_header)
26606
26607diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26608index bb360dc..3e5945f 100644
26609--- a/arch/x86/realmode/rm/trampoline_64.S
26610+++ b/arch/x86/realmode/rm/trampoline_64.S
26611@@ -107,7 +107,7 @@ ENTRY(startup_32)
26612 wrmsr
26613
26614 # Enable paging and in turn activate Long Mode
26615- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26616+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
26617 movl %eax, %cr0
26618
26619 /*
26620diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26621index 5a1847d..deccb30 100644
26622--- a/arch/x86/tools/relocs.c
26623+++ b/arch/x86/tools/relocs.c
26624@@ -12,10 +12,13 @@
26625 #include <regex.h>
26626 #include <tools/le_byteshift.h>
26627
26628+#include "../../../include/generated/autoconf.h"
26629+
26630 static void die(char *fmt, ...);
26631
26632 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26633 static Elf32_Ehdr ehdr;
26634+static Elf32_Phdr *phdr;
26635 static unsigned long reloc_count, reloc_idx;
26636 static unsigned long *relocs;
26637 static unsigned long reloc16_count, reloc16_idx;
26638@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26639 }
26640 }
26641
26642+static void read_phdrs(FILE *fp)
26643+{
26644+ unsigned int i;
26645+
26646+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26647+ if (!phdr) {
26648+ die("Unable to allocate %d program headers\n",
26649+ ehdr.e_phnum);
26650+ }
26651+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26652+ die("Seek to %d failed: %s\n",
26653+ ehdr.e_phoff, strerror(errno));
26654+ }
26655+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26656+ die("Cannot read ELF program headers: %s\n",
26657+ strerror(errno));
26658+ }
26659+ for(i = 0; i < ehdr.e_phnum; i++) {
26660+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26661+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26662+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26663+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26664+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26665+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26666+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26667+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26668+ }
26669+
26670+}
26671+
26672 static void read_shdrs(FILE *fp)
26673 {
26674- int i;
26675+ unsigned int i;
26676 Elf32_Shdr shdr;
26677
26678 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26679@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26680
26681 static void read_strtabs(FILE *fp)
26682 {
26683- int i;
26684+ unsigned int i;
26685 for (i = 0; i < ehdr.e_shnum; i++) {
26686 struct section *sec = &secs[i];
26687 if (sec->shdr.sh_type != SHT_STRTAB) {
26688@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26689
26690 static void read_symtabs(FILE *fp)
26691 {
26692- int i,j;
26693+ unsigned int i,j;
26694 for (i = 0; i < ehdr.e_shnum; i++) {
26695 struct section *sec = &secs[i];
26696 if (sec->shdr.sh_type != SHT_SYMTAB) {
26697@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26698 }
26699
26700
26701-static void read_relocs(FILE *fp)
26702+static void read_relocs(FILE *fp, int use_real_mode)
26703 {
26704- int i,j;
26705+ unsigned int i,j;
26706+ uint32_t base;
26707+
26708 for (i = 0; i < ehdr.e_shnum; i++) {
26709 struct section *sec = &secs[i];
26710 if (sec->shdr.sh_type != SHT_REL) {
26711@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26712 die("Cannot read symbol table: %s\n",
26713 strerror(errno));
26714 }
26715+ base = 0;
26716+
26717+#ifdef CONFIG_X86_32
26718+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26719+ if (phdr[j].p_type != PT_LOAD )
26720+ continue;
26721+ 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)
26722+ continue;
26723+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26724+ break;
26725+ }
26726+#endif
26727+
26728 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26729 Elf32_Rel *rel = &sec->reltab[j];
26730- rel->r_offset = elf32_to_cpu(rel->r_offset);
26731+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26732 rel->r_info = elf32_to_cpu(rel->r_info);
26733 }
26734 }
26735@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
26736
26737 static void print_absolute_symbols(void)
26738 {
26739- int i;
26740+ unsigned int i;
26741 printf("Absolute symbols\n");
26742 printf(" Num: Value Size Type Bind Visibility Name\n");
26743 for (i = 0; i < ehdr.e_shnum; i++) {
26744 struct section *sec = &secs[i];
26745 char *sym_strtab;
26746- int j;
26747+ unsigned int j;
26748
26749 if (sec->shdr.sh_type != SHT_SYMTAB) {
26750 continue;
26751@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
26752
26753 static void print_absolute_relocs(void)
26754 {
26755- int i, printed = 0;
26756+ unsigned int i, printed = 0;
26757
26758 for (i = 0; i < ehdr.e_shnum; i++) {
26759 struct section *sec = &secs[i];
26760 struct section *sec_applies, *sec_symtab;
26761 char *sym_strtab;
26762 Elf32_Sym *sh_symtab;
26763- int j;
26764+ unsigned int j;
26765 if (sec->shdr.sh_type != SHT_REL) {
26766 continue;
26767 }
26768@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
26769 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26770 int use_real_mode)
26771 {
26772- int i;
26773+ unsigned int i;
26774 /* Walk through the relocations */
26775 for (i = 0; i < ehdr.e_shnum; i++) {
26776 char *sym_strtab;
26777 Elf32_Sym *sh_symtab;
26778 struct section *sec_applies, *sec_symtab;
26779- int j;
26780+ unsigned int j;
26781 struct section *sec = &secs[i];
26782
26783 if (sec->shdr.sh_type != SHT_REL) {
26784@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26785 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26786 r_type = ELF32_R_TYPE(rel->r_info);
26787
26788+ if (!use_real_mode) {
26789+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26790+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26791+ continue;
26792+
26793+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26794+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26795+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26796+ continue;
26797+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26798+ continue;
26799+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26800+ continue;
26801+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26802+ continue;
26803+#endif
26804+ }
26805+
26806 shn_abs = sym->st_shndx == SHN_ABS;
26807
26808 switch (r_type) {
26809@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
26810
26811 static void emit_relocs(int as_text, int use_real_mode)
26812 {
26813- int i;
26814+ unsigned int i;
26815 /* Count how many relocations I have and allocate space for them. */
26816 reloc_count = 0;
26817 walk_relocs(count_reloc, use_real_mode);
26818@@ -808,10 +874,11 @@ int main(int argc, char **argv)
26819 fname, strerror(errno));
26820 }
26821 read_ehdr(fp);
26822+ read_phdrs(fp);
26823 read_shdrs(fp);
26824 read_strtabs(fp);
26825 read_symtabs(fp);
26826- read_relocs(fp);
26827+ read_relocs(fp, use_real_mode);
26828 if (show_absolute_syms) {
26829 print_absolute_symbols();
26830 return 0;
26831diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26832index fd14be1..e3c79c0 100644
26833--- a/arch/x86/vdso/Makefile
26834+++ b/arch/x86/vdso/Makefile
26835@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
26836 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26837 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26838
26839-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26840+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26841 GCOV_PROFILE := n
26842
26843 #
26844diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26845index 66e6d93..587f435 100644
26846--- a/arch/x86/vdso/vdso32-setup.c
26847+++ b/arch/x86/vdso/vdso32-setup.c
26848@@ -25,6 +25,7 @@
26849 #include <asm/tlbflush.h>
26850 #include <asm/vdso.h>
26851 #include <asm/proto.h>
26852+#include <asm/mman.h>
26853
26854 enum {
26855 VDSO_DISABLED = 0,
26856@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26857 void enable_sep_cpu(void)
26858 {
26859 int cpu = get_cpu();
26860- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26861+ struct tss_struct *tss = init_tss + cpu;
26862
26863 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26864 put_cpu();
26865@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26866 gate_vma.vm_start = FIXADDR_USER_START;
26867 gate_vma.vm_end = FIXADDR_USER_END;
26868 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26869- gate_vma.vm_page_prot = __P101;
26870+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26871
26872 return 0;
26873 }
26874@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26875 if (compat)
26876 addr = VDSO_HIGH_BASE;
26877 else {
26878- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26879+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26880 if (IS_ERR_VALUE(addr)) {
26881 ret = addr;
26882 goto up_fail;
26883 }
26884 }
26885
26886- current->mm->context.vdso = (void *)addr;
26887+ current->mm->context.vdso = addr;
26888
26889 if (compat_uses_vma || !compat) {
26890 /*
26891@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26892 }
26893
26894 current_thread_info()->sysenter_return =
26895- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26896+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26897
26898 up_fail:
26899 if (ret)
26900- current->mm->context.vdso = NULL;
26901+ current->mm->context.vdso = 0;
26902
26903 up_write(&mm->mmap_sem);
26904
26905@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
26906
26907 const char *arch_vma_name(struct vm_area_struct *vma)
26908 {
26909- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26910+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26911 return "[vdso]";
26912+
26913+#ifdef CONFIG_PAX_SEGMEXEC
26914+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26915+ return "[vdso]";
26916+#endif
26917+
26918 return NULL;
26919 }
26920
26921@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26922 * Check to see if the corresponding task was created in compat vdso
26923 * mode.
26924 */
26925- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26926+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26927 return &gate_vma;
26928 return NULL;
26929 }
26930diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26931index 00aaf04..4a26505 100644
26932--- a/arch/x86/vdso/vma.c
26933+++ b/arch/x86/vdso/vma.c
26934@@ -16,8 +16,6 @@
26935 #include <asm/vdso.h>
26936 #include <asm/page.h>
26937
26938-unsigned int __read_mostly vdso_enabled = 1;
26939-
26940 extern char vdso_start[], vdso_end[];
26941 extern unsigned short vdso_sync_cpuid;
26942
26943@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26944 * unaligned here as a result of stack start randomization.
26945 */
26946 addr = PAGE_ALIGN(addr);
26947- addr = align_addr(addr, NULL, ALIGN_VDSO);
26948
26949 return addr;
26950 }
26951@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
26952 unsigned size)
26953 {
26954 struct mm_struct *mm = current->mm;
26955- unsigned long addr;
26956+ unsigned long addr = 0;
26957 int ret;
26958
26959- if (!vdso_enabled)
26960- return 0;
26961-
26962 down_write(&mm->mmap_sem);
26963+
26964+#ifdef CONFIG_PAX_RANDMMAP
26965+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26966+#endif
26967+
26968 addr = vdso_addr(mm->start_stack, size);
26969+ addr = align_addr(addr, NULL, ALIGN_VDSO);
26970 addr = get_unmapped_area(NULL, addr, size, 0, 0);
26971 if (IS_ERR_VALUE(addr)) {
26972 ret = addr;
26973 goto up_fail;
26974 }
26975
26976- current->mm->context.vdso = (void *)addr;
26977+ mm->context.vdso = addr;
26978
26979 ret = install_special_mapping(mm, addr, size,
26980 VM_READ|VM_EXEC|
26981 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
26982 pages);
26983- if (ret) {
26984- current->mm->context.vdso = NULL;
26985- goto up_fail;
26986- }
26987+ if (ret)
26988+ mm->context.vdso = 0;
26989
26990 up_fail:
26991 up_write(&mm->mmap_sem);
26992@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26993 vdsox32_size);
26994 }
26995 #endif
26996-
26997-static __init int vdso_setup(char *s)
26998-{
26999- vdso_enabled = simple_strtoul(s, NULL, 0);
27000- return 0;
27001-}
27002-__setup("vdso=", vdso_setup);
27003diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27004index ff962d4..2bb5e83 100644
27005--- a/arch/x86/xen/enlighten.c
27006+++ b/arch/x86/xen/enlighten.c
27007@@ -97,8 +97,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27008
27009 struct shared_info xen_dummy_shared_info;
27010
27011-void *xen_initial_gdt;
27012-
27013 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27014 __read_mostly int xen_have_vector_callback;
27015 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27016@@ -1175,30 +1173,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27017 #endif
27018 };
27019
27020-static void xen_reboot(int reason)
27021+static __noreturn void xen_reboot(int reason)
27022 {
27023 struct sched_shutdown r = { .reason = reason };
27024
27025- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27026- BUG();
27027+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27028+ BUG();
27029 }
27030
27031-static void xen_restart(char *msg)
27032+static __noreturn void xen_restart(char *msg)
27033 {
27034 xen_reboot(SHUTDOWN_reboot);
27035 }
27036
27037-static void xen_emergency_restart(void)
27038+static __noreturn void xen_emergency_restart(void)
27039 {
27040 xen_reboot(SHUTDOWN_reboot);
27041 }
27042
27043-static void xen_machine_halt(void)
27044+static __noreturn void xen_machine_halt(void)
27045 {
27046 xen_reboot(SHUTDOWN_poweroff);
27047 }
27048
27049-static void xen_machine_power_off(void)
27050+static __noreturn void xen_machine_power_off(void)
27051 {
27052 if (pm_power_off)
27053 pm_power_off();
27054@@ -1301,7 +1299,17 @@ asmlinkage void __init xen_start_kernel(void)
27055 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27056
27057 /* Work out if we support NX */
27058- x86_configure_nx();
27059+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27060+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27061+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27062+ unsigned l, h;
27063+
27064+ __supported_pte_mask |= _PAGE_NX;
27065+ rdmsr(MSR_EFER, l, h);
27066+ l |= EFER_NX;
27067+ wrmsr(MSR_EFER, l, h);
27068+ }
27069+#endif
27070
27071 xen_setup_features();
27072
27073@@ -1332,13 +1340,6 @@ asmlinkage void __init xen_start_kernel(void)
27074
27075 machine_ops = xen_machine_ops;
27076
27077- /*
27078- * The only reliable way to retain the initial address of the
27079- * percpu gdt_page is to remember it here, so we can go and
27080- * mark it RW later, when the initial percpu area is freed.
27081- */
27082- xen_initial_gdt = &per_cpu(gdt_page, 0);
27083-
27084 xen_smp_init();
27085
27086 #ifdef CONFIG_ACPI_NUMA
27087diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27088index 3a73785..0d30df2 100644
27089--- a/arch/x86/xen/mmu.c
27090+++ b/arch/x86/xen/mmu.c
27091@@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27092 convert_pfn_mfn(init_level4_pgt);
27093 convert_pfn_mfn(level3_ident_pgt);
27094 convert_pfn_mfn(level3_kernel_pgt);
27095+ convert_pfn_mfn(level3_vmalloc_start_pgt);
27096+ convert_pfn_mfn(level3_vmalloc_end_pgt);
27097+ convert_pfn_mfn(level3_vmemmap_pgt);
27098
27099 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27100 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27101@@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27102 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27103 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27104 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27105+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27106+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27107+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27108 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27109+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27110 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27111 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27112
27113@@ -1940,6 +1947,7 @@ static void __init xen_post_allocator_init(void)
27114 pv_mmu_ops.set_pud = xen_set_pud;
27115 #if PAGETABLE_LEVELS == 4
27116 pv_mmu_ops.set_pgd = xen_set_pgd;
27117+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27118 #endif
27119
27120 /* This will work as long as patching hasn't happened yet
27121@@ -2021,6 +2029,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27122 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27123 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27124 .set_pgd = xen_set_pgd_hyper,
27125+ .set_pgd_batched = xen_set_pgd_hyper,
27126
27127 .alloc_pud = xen_alloc_pmd_init,
27128 .release_pud = xen_release_pmd_init,
27129diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27130index afb250d..627075f 100644
27131--- a/arch/x86/xen/smp.c
27132+++ b/arch/x86/xen/smp.c
27133@@ -231,11 +231,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27134 {
27135 BUG_ON(smp_processor_id() != 0);
27136 native_smp_prepare_boot_cpu();
27137-
27138- /* We've switched to the "real" per-cpu gdt, so make sure the
27139- old memory can be recycled */
27140- make_lowmem_page_readwrite(xen_initial_gdt);
27141-
27142 xen_filter_cpu_maps();
27143 xen_setup_vcpu_info_placement();
27144 }
27145@@ -302,12 +297,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27146 gdt = get_cpu_gdt_table(cpu);
27147
27148 ctxt->flags = VGCF_IN_KERNEL;
27149- ctxt->user_regs.ds = __USER_DS;
27150- ctxt->user_regs.es = __USER_DS;
27151+ ctxt->user_regs.ds = __KERNEL_DS;
27152+ ctxt->user_regs.es = __KERNEL_DS;
27153 ctxt->user_regs.ss = __KERNEL_DS;
27154 #ifdef CONFIG_X86_32
27155 ctxt->user_regs.fs = __KERNEL_PERCPU;
27156- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27157+ savesegment(gs, ctxt->user_regs.gs);
27158 #else
27159 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27160 #endif
27161@@ -357,13 +352,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27162 int rc;
27163
27164 per_cpu(current_task, cpu) = idle;
27165+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27166 #ifdef CONFIG_X86_32
27167 irq_ctx_init(cpu);
27168 #else
27169 clear_tsk_thread_flag(idle, TIF_FORK);
27170- per_cpu(kernel_stack, cpu) =
27171- (unsigned long)task_stack_page(idle) -
27172- KERNEL_STACK_OFFSET + THREAD_SIZE;
27173+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27174 #endif
27175 xen_setup_runstate_info(cpu);
27176 xen_setup_timer(cpu);
27177diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27178index f9643fc..602e8af 100644
27179--- a/arch/x86/xen/xen-asm_32.S
27180+++ b/arch/x86/xen/xen-asm_32.S
27181@@ -84,14 +84,14 @@ ENTRY(xen_iret)
27182 ESP_OFFSET=4 # bytes pushed onto stack
27183
27184 /*
27185- * Store vcpu_info pointer for easy access. Do it this way to
27186- * avoid having to reload %fs
27187+ * Store vcpu_info pointer for easy access.
27188 */
27189 #ifdef CONFIG_SMP
27190- GET_THREAD_INFO(%eax)
27191- movl TI_cpu(%eax), %eax
27192- movl __per_cpu_offset(,%eax,4), %eax
27193- mov xen_vcpu(%eax), %eax
27194+ push %fs
27195+ mov $(__KERNEL_PERCPU), %eax
27196+ mov %eax, %fs
27197+ mov PER_CPU_VAR(xen_vcpu), %eax
27198+ pop %fs
27199 #else
27200 movl xen_vcpu, %eax
27201 #endif
27202diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27203index aaa7291..3f77960 100644
27204--- a/arch/x86/xen/xen-head.S
27205+++ b/arch/x86/xen/xen-head.S
27206@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27207 #ifdef CONFIG_X86_32
27208 mov %esi,xen_start_info
27209 mov $init_thread_union+THREAD_SIZE,%esp
27210+#ifdef CONFIG_SMP
27211+ movl $cpu_gdt_table,%edi
27212+ movl $__per_cpu_load,%eax
27213+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27214+ rorl $16,%eax
27215+ movb %al,__KERNEL_PERCPU + 4(%edi)
27216+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27217+ movl $__per_cpu_end - 1,%eax
27218+ subl $__per_cpu_start,%eax
27219+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27220+#endif
27221 #else
27222 mov %rsi,xen_start_info
27223 mov $init_thread_union+THREAD_SIZE,%rsp
27224diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27225index 202d4c1..99b072a 100644
27226--- a/arch/x86/xen/xen-ops.h
27227+++ b/arch/x86/xen/xen-ops.h
27228@@ -10,8 +10,6 @@
27229 extern const char xen_hypervisor_callback[];
27230 extern const char xen_failsafe_callback[];
27231
27232-extern void *xen_initial_gdt;
27233-
27234 struct trap_info;
27235 void xen_copy_trap_info(struct trap_info *traps);
27236
27237diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27238index 525bd3d..ef888b1 100644
27239--- a/arch/xtensa/variants/dc232b/include/variant/core.h
27240+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27241@@ -119,9 +119,9 @@
27242 ----------------------------------------------------------------------*/
27243
27244 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27245-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27246 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27247 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27248+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27249
27250 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27251 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27252diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27253index 2f33760..835e50a 100644
27254--- a/arch/xtensa/variants/fsf/include/variant/core.h
27255+++ b/arch/xtensa/variants/fsf/include/variant/core.h
27256@@ -11,6 +11,7 @@
27257 #ifndef _XTENSA_CORE_H
27258 #define _XTENSA_CORE_H
27259
27260+#include <linux/const.h>
27261
27262 /****************************************************************************
27263 Parameters Useful for Any Code, USER or PRIVILEGED
27264@@ -112,9 +113,9 @@
27265 ----------------------------------------------------------------------*/
27266
27267 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27268-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27269 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27270 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27271+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27272
27273 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27274 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27275diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27276index af00795..2bb8105 100644
27277--- a/arch/xtensa/variants/s6000/include/variant/core.h
27278+++ b/arch/xtensa/variants/s6000/include/variant/core.h
27279@@ -11,6 +11,7 @@
27280 #ifndef _XTENSA_CORE_CONFIGURATION_H
27281 #define _XTENSA_CORE_CONFIGURATION_H
27282
27283+#include <linux/const.h>
27284
27285 /****************************************************************************
27286 Parameters Useful for Any Code, USER or PRIVILEGED
27287@@ -118,9 +119,9 @@
27288 ----------------------------------------------------------------------*/
27289
27290 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27291-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27292 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27293 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27294+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27295
27296 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27297 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27298diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27299index 58916af..9cb880b 100644
27300--- a/block/blk-iopoll.c
27301+++ b/block/blk-iopoll.c
27302@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27303 }
27304 EXPORT_SYMBOL(blk_iopoll_complete);
27305
27306-static void blk_iopoll_softirq(struct softirq_action *h)
27307+static void blk_iopoll_softirq(void)
27308 {
27309 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27310 int rearm = 0, budget = blk_iopoll_budget;
27311diff --git a/block/blk-map.c b/block/blk-map.c
27312index 623e1cd..ca1e109 100644
27313--- a/block/blk-map.c
27314+++ b/block/blk-map.c
27315@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27316 if (!len || !kbuf)
27317 return -EINVAL;
27318
27319- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27320+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27321 if (do_copy)
27322 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27323 else
27324diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27325index 467c8de..4bddc6d 100644
27326--- a/block/blk-softirq.c
27327+++ b/block/blk-softirq.c
27328@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27329 * Softirq action handler - move entries to local list and loop over them
27330 * while passing them to the queue registered handler.
27331 */
27332-static void blk_done_softirq(struct softirq_action *h)
27333+static void blk_done_softirq(void)
27334 {
27335 struct list_head *cpu_list, local_list;
27336
27337diff --git a/block/bsg.c b/block/bsg.c
27338index ff64ae3..593560c 100644
27339--- a/block/bsg.c
27340+++ b/block/bsg.c
27341@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27342 struct sg_io_v4 *hdr, struct bsg_device *bd,
27343 fmode_t has_write_perm)
27344 {
27345+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27346+ unsigned char *cmdptr;
27347+
27348 if (hdr->request_len > BLK_MAX_CDB) {
27349 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27350 if (!rq->cmd)
27351 return -ENOMEM;
27352- }
27353+ cmdptr = rq->cmd;
27354+ } else
27355+ cmdptr = tmpcmd;
27356
27357- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27358+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27359 hdr->request_len))
27360 return -EFAULT;
27361
27362+ if (cmdptr != rq->cmd)
27363+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27364+
27365 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27366 if (blk_verify_command(rq->cmd, has_write_perm))
27367 return -EPERM;
27368diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27369index 7c668c8..db3521c 100644
27370--- a/block/compat_ioctl.c
27371+++ b/block/compat_ioctl.c
27372@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27373 err |= __get_user(f->spec1, &uf->spec1);
27374 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27375 err |= __get_user(name, &uf->name);
27376- f->name = compat_ptr(name);
27377+ f->name = (void __force_kernel *)compat_ptr(name);
27378 if (err) {
27379 err = -EFAULT;
27380 goto out;
27381diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27382index 6296b40..417c00f 100644
27383--- a/block/partitions/efi.c
27384+++ b/block/partitions/efi.c
27385@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27386 if (!gpt)
27387 return NULL;
27388
27389+ if (!le32_to_cpu(gpt->num_partition_entries))
27390+ return NULL;
27391+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27392+ if (!pte)
27393+ return NULL;
27394+
27395 count = le32_to_cpu(gpt->num_partition_entries) *
27396 le32_to_cpu(gpt->sizeof_partition_entry);
27397- if (!count)
27398- return NULL;
27399- pte = kzalloc(count, GFP_KERNEL);
27400- if (!pte)
27401- return NULL;
27402-
27403 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27404 (u8 *) pte,
27405 count) < count) {
27406diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27407index 9a87daa..fb17486 100644
27408--- a/block/scsi_ioctl.c
27409+++ b/block/scsi_ioctl.c
27410@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27411 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27412 struct sg_io_hdr *hdr, fmode_t mode)
27413 {
27414- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27415+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27416+ unsigned char *cmdptr;
27417+
27418+ if (rq->cmd != rq->__cmd)
27419+ cmdptr = rq->cmd;
27420+ else
27421+ cmdptr = tmpcmd;
27422+
27423+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27424 return -EFAULT;
27425+
27426+ if (cmdptr != rq->cmd)
27427+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27428+
27429 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27430 return -EPERM;
27431
27432@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27433 int err;
27434 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27435 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27436+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27437+ unsigned char *cmdptr;
27438
27439 if (!sic)
27440 return -EINVAL;
27441@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27442 */
27443 err = -EFAULT;
27444 rq->cmd_len = cmdlen;
27445- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27446+
27447+ if (rq->cmd != rq->__cmd)
27448+ cmdptr = rq->cmd;
27449+ else
27450+ cmdptr = tmpcmd;
27451+
27452+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27453 goto error;
27454
27455+ if (rq->cmd != cmdptr)
27456+ memcpy(rq->cmd, cmdptr, cmdlen);
27457+
27458 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27459 goto error;
27460
27461diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27462index 671d4d6..5f24030 100644
27463--- a/crypto/cryptd.c
27464+++ b/crypto/cryptd.c
27465@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27466
27467 struct cryptd_blkcipher_request_ctx {
27468 crypto_completion_t complete;
27469-};
27470+} __no_const;
27471
27472 struct cryptd_hash_ctx {
27473 struct crypto_shash *child;
27474@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27475
27476 struct cryptd_aead_request_ctx {
27477 crypto_completion_t complete;
27478-};
27479+} __no_const;
27480
27481 static void cryptd_queue_worker(struct work_struct *work);
27482
27483diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27484index e6defd8..c26a225 100644
27485--- a/drivers/acpi/apei/cper.c
27486+++ b/drivers/acpi/apei/cper.c
27487@@ -38,12 +38,12 @@
27488 */
27489 u64 cper_next_record_id(void)
27490 {
27491- static atomic64_t seq;
27492+ static atomic64_unchecked_t seq;
27493
27494- if (!atomic64_read(&seq))
27495- atomic64_set(&seq, ((u64)get_seconds()) << 32);
27496+ if (!atomic64_read_unchecked(&seq))
27497+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27498
27499- return atomic64_inc_return(&seq);
27500+ return atomic64_inc_return_unchecked(&seq);
27501 }
27502 EXPORT_SYMBOL_GPL(cper_next_record_id);
27503
27504diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27505index 7586544..636a2f0 100644
27506--- a/drivers/acpi/ec_sys.c
27507+++ b/drivers/acpi/ec_sys.c
27508@@ -12,6 +12,7 @@
27509 #include <linux/acpi.h>
27510 #include <linux/debugfs.h>
27511 #include <linux/module.h>
27512+#include <linux/uaccess.h>
27513 #include "internal.h"
27514
27515 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27516@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27517 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27518 */
27519 unsigned int size = EC_SPACE_SIZE;
27520- u8 *data = (u8 *) buf;
27521+ u8 data;
27522 loff_t init_off = *off;
27523 int err = 0;
27524
27525@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27526 size = count;
27527
27528 while (size) {
27529- err = ec_read(*off, &data[*off - init_off]);
27530+ err = ec_read(*off, &data);
27531 if (err)
27532 return err;
27533+ if (put_user(data, &buf[*off - init_off]))
27534+ return -EFAULT;
27535 *off += 1;
27536 size--;
27537 }
27538@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27539
27540 unsigned int size = count;
27541 loff_t init_off = *off;
27542- u8 *data = (u8 *) buf;
27543 int err = 0;
27544
27545 if (*off >= EC_SPACE_SIZE)
27546@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27547 }
27548
27549 while (size) {
27550- u8 byte_write = data[*off - init_off];
27551+ u8 byte_write;
27552+ if (get_user(byte_write, &buf[*off - init_off]))
27553+ return -EFAULT;
27554 err = ec_write(*off, byte_write);
27555 if (err)
27556 return err;
27557diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27558index 251c7b62..000462d 100644
27559--- a/drivers/acpi/proc.c
27560+++ b/drivers/acpi/proc.c
27561@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27562 size_t count, loff_t * ppos)
27563 {
27564 struct list_head *node, *next;
27565- char strbuf[5];
27566- char str[5] = "";
27567- unsigned int len = count;
27568+ char strbuf[5] = {0};
27569
27570- if (len > 4)
27571- len = 4;
27572- if (len < 0)
27573+ if (count > 4)
27574+ count = 4;
27575+ if (copy_from_user(strbuf, buffer, count))
27576 return -EFAULT;
27577-
27578- if (copy_from_user(strbuf, buffer, len))
27579- return -EFAULT;
27580- strbuf[len] = '\0';
27581- sscanf(strbuf, "%s", str);
27582+ strbuf[count] = '\0';
27583
27584 mutex_lock(&acpi_device_lock);
27585 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27586@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27587 if (!dev->wakeup.flags.valid)
27588 continue;
27589
27590- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27591+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27592 if (device_can_wakeup(&dev->dev)) {
27593 bool enable = !device_may_wakeup(&dev->dev);
27594 device_set_wakeup_enable(&dev->dev, enable);
27595diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27596index 0734086..3ad3e4c 100644
27597--- a/drivers/acpi/processor_driver.c
27598+++ b/drivers/acpi/processor_driver.c
27599@@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27600 return 0;
27601 #endif
27602
27603- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27604+ BUG_ON(pr->id >= nr_cpu_ids);
27605
27606 /*
27607 * Buggy BIOS check
27608diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27609index cece3a4..0845256 100644
27610--- a/drivers/ata/libata-core.c
27611+++ b/drivers/ata/libata-core.c
27612@@ -4743,7 +4743,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27613 struct ata_port *ap;
27614 unsigned int tag;
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 ap = qc->ap;
27619
27620 qc->flags = 0;
27621@@ -4759,7 +4759,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27622 struct ata_port *ap;
27623 struct ata_link *link;
27624
27625- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27626+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27627 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27628 ap = qc->ap;
27629 link = qc->dev->link;
27630@@ -5823,6 +5823,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27631 return;
27632
27633 spin_lock(&lock);
27634+ pax_open_kernel();
27635
27636 for (cur = ops->inherits; cur; cur = cur->inherits) {
27637 void **inherit = (void **)cur;
27638@@ -5836,8 +5837,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27639 if (IS_ERR(*pp))
27640 *pp = NULL;
27641
27642- ops->inherits = NULL;
27643+ *(struct ata_port_operations **)&ops->inherits = NULL;
27644
27645+ pax_close_kernel();
27646 spin_unlock(&lock);
27647 }
27648
27649diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27650index ac6a5be..c7176b1 100644
27651--- a/drivers/ata/pata_arasan_cf.c
27652+++ b/drivers/ata/pata_arasan_cf.c
27653@@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27654 /* Handle platform specific quirks */
27655 if (pdata->quirk) {
27656 if (pdata->quirk & CF_BROKEN_PIO) {
27657- ap->ops->set_piomode = NULL;
27658+ pax_open_kernel();
27659+ *(void **)&ap->ops->set_piomode = NULL;
27660+ pax_close_kernel();
27661 ap->pio_mask = 0;
27662 }
27663 if (pdata->quirk & CF_BROKEN_MWDMA)
27664diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27665index f9b983a..887b9d8 100644
27666--- a/drivers/atm/adummy.c
27667+++ b/drivers/atm/adummy.c
27668@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27669 vcc->pop(vcc, skb);
27670 else
27671 dev_kfree_skb_any(skb);
27672- atomic_inc(&vcc->stats->tx);
27673+ atomic_inc_unchecked(&vcc->stats->tx);
27674
27675 return 0;
27676 }
27677diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27678index 89b30f3..7964211 100644
27679--- a/drivers/atm/ambassador.c
27680+++ b/drivers/atm/ambassador.c
27681@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27682 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27683
27684 // VC layer stats
27685- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27686+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27687
27688 // free the descriptor
27689 kfree (tx_descr);
27690@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27691 dump_skb ("<<<", vc, skb);
27692
27693 // VC layer stats
27694- atomic_inc(&atm_vcc->stats->rx);
27695+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27696 __net_timestamp(skb);
27697 // end of our responsibility
27698 atm_vcc->push (atm_vcc, skb);
27699@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27700 } else {
27701 PRINTK (KERN_INFO, "dropped over-size frame");
27702 // should we count this?
27703- atomic_inc(&atm_vcc->stats->rx_drop);
27704+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27705 }
27706
27707 } else {
27708@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27709 }
27710
27711 if (check_area (skb->data, skb->len)) {
27712- atomic_inc(&atm_vcc->stats->tx_err);
27713+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27714 return -ENOMEM; // ?
27715 }
27716
27717diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27718index b22d71c..d6e1049 100644
27719--- a/drivers/atm/atmtcp.c
27720+++ b/drivers/atm/atmtcp.c
27721@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27722 if (vcc->pop) vcc->pop(vcc,skb);
27723 else dev_kfree_skb(skb);
27724 if (dev_data) return 0;
27725- atomic_inc(&vcc->stats->tx_err);
27726+ atomic_inc_unchecked(&vcc->stats->tx_err);
27727 return -ENOLINK;
27728 }
27729 size = skb->len+sizeof(struct atmtcp_hdr);
27730@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27731 if (!new_skb) {
27732 if (vcc->pop) vcc->pop(vcc,skb);
27733 else dev_kfree_skb(skb);
27734- atomic_inc(&vcc->stats->tx_err);
27735+ atomic_inc_unchecked(&vcc->stats->tx_err);
27736 return -ENOBUFS;
27737 }
27738 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27739@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27740 if (vcc->pop) vcc->pop(vcc,skb);
27741 else dev_kfree_skb(skb);
27742 out_vcc->push(out_vcc,new_skb);
27743- atomic_inc(&vcc->stats->tx);
27744- atomic_inc(&out_vcc->stats->rx);
27745+ atomic_inc_unchecked(&vcc->stats->tx);
27746+ atomic_inc_unchecked(&out_vcc->stats->rx);
27747 return 0;
27748 }
27749
27750@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27751 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27752 read_unlock(&vcc_sklist_lock);
27753 if (!out_vcc) {
27754- atomic_inc(&vcc->stats->tx_err);
27755+ atomic_inc_unchecked(&vcc->stats->tx_err);
27756 goto done;
27757 }
27758 skb_pull(skb,sizeof(struct atmtcp_hdr));
27759@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27760 __net_timestamp(new_skb);
27761 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27762 out_vcc->push(out_vcc,new_skb);
27763- atomic_inc(&vcc->stats->tx);
27764- atomic_inc(&out_vcc->stats->rx);
27765+ atomic_inc_unchecked(&vcc->stats->tx);
27766+ atomic_inc_unchecked(&out_vcc->stats->rx);
27767 done:
27768 if (vcc->pop) vcc->pop(vcc,skb);
27769 else dev_kfree_skb(skb);
27770diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27771index 2059ee4..faf51c7 100644
27772--- a/drivers/atm/eni.c
27773+++ b/drivers/atm/eni.c
27774@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27775 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27776 vcc->dev->number);
27777 length = 0;
27778- atomic_inc(&vcc->stats->rx_err);
27779+ atomic_inc_unchecked(&vcc->stats->rx_err);
27780 }
27781 else {
27782 length = ATM_CELL_SIZE-1; /* no HEC */
27783@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27784 size);
27785 }
27786 eff = length = 0;
27787- atomic_inc(&vcc->stats->rx_err);
27788+ atomic_inc_unchecked(&vcc->stats->rx_err);
27789 }
27790 else {
27791 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27792@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27793 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27794 vcc->dev->number,vcc->vci,length,size << 2,descr);
27795 length = eff = 0;
27796- atomic_inc(&vcc->stats->rx_err);
27797+ atomic_inc_unchecked(&vcc->stats->rx_err);
27798 }
27799 }
27800 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27801@@ -767,7 +767,7 @@ rx_dequeued++;
27802 vcc->push(vcc,skb);
27803 pushed++;
27804 }
27805- atomic_inc(&vcc->stats->rx);
27806+ atomic_inc_unchecked(&vcc->stats->rx);
27807 }
27808 wake_up(&eni_dev->rx_wait);
27809 }
27810@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27811 PCI_DMA_TODEVICE);
27812 if (vcc->pop) vcc->pop(vcc,skb);
27813 else dev_kfree_skb_irq(skb);
27814- atomic_inc(&vcc->stats->tx);
27815+ atomic_inc_unchecked(&vcc->stats->tx);
27816 wake_up(&eni_dev->tx_wait);
27817 dma_complete++;
27818 }
27819@@ -1567,7 +1567,7 @@ tx_complete++;
27820 /*--------------------------------- entries ---------------------------------*/
27821
27822
27823-static const char *media_name[] __devinitdata = {
27824+static const char *media_name[] __devinitconst = {
27825 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27826 "UTP", "05?", "06?", "07?", /* 4- 7 */
27827 "TAXI","09?", "10?", "11?", /* 8-11 */
27828diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27829index 86fed1b..6dc4721 100644
27830--- a/drivers/atm/firestream.c
27831+++ b/drivers/atm/firestream.c
27832@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27833 }
27834 }
27835
27836- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27837+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27838
27839 fs_dprintk (FS_DEBUG_TXMEM, "i");
27840 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27841@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27842 #endif
27843 skb_put (skb, qe->p1 & 0xffff);
27844 ATM_SKB(skb)->vcc = atm_vcc;
27845- atomic_inc(&atm_vcc->stats->rx);
27846+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27847 __net_timestamp(skb);
27848 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27849 atm_vcc->push (atm_vcc, skb);
27850@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27851 kfree (pe);
27852 }
27853 if (atm_vcc)
27854- atomic_inc(&atm_vcc->stats->rx_drop);
27855+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27856 break;
27857 case 0x1f: /* Reassembly abort: no buffers. */
27858 /* Silently increment error counter. */
27859 if (atm_vcc)
27860- atomic_inc(&atm_vcc->stats->rx_drop);
27861+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27862 break;
27863 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27864 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27865diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27866index 361f5ae..7fc552d 100644
27867--- a/drivers/atm/fore200e.c
27868+++ b/drivers/atm/fore200e.c
27869@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27870 #endif
27871 /* check error condition */
27872 if (*entry->status & STATUS_ERROR)
27873- atomic_inc(&vcc->stats->tx_err);
27874+ atomic_inc_unchecked(&vcc->stats->tx_err);
27875 else
27876- atomic_inc(&vcc->stats->tx);
27877+ atomic_inc_unchecked(&vcc->stats->tx);
27878 }
27879 }
27880
27881@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27882 if (skb == NULL) {
27883 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27884
27885- atomic_inc(&vcc->stats->rx_drop);
27886+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27887 return -ENOMEM;
27888 }
27889
27890@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27891
27892 dev_kfree_skb_any(skb);
27893
27894- atomic_inc(&vcc->stats->rx_drop);
27895+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27896 return -ENOMEM;
27897 }
27898
27899 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27900
27901 vcc->push(vcc, skb);
27902- atomic_inc(&vcc->stats->rx);
27903+ atomic_inc_unchecked(&vcc->stats->rx);
27904
27905 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27906
27907@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27908 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27909 fore200e->atm_dev->number,
27910 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27911- atomic_inc(&vcc->stats->rx_err);
27912+ atomic_inc_unchecked(&vcc->stats->rx_err);
27913 }
27914 }
27915
27916@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27917 goto retry_here;
27918 }
27919
27920- atomic_inc(&vcc->stats->tx_err);
27921+ atomic_inc_unchecked(&vcc->stats->tx_err);
27922
27923 fore200e->tx_sat++;
27924 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27925diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27926index b182c2f..1c6fa8a 100644
27927--- a/drivers/atm/he.c
27928+++ b/drivers/atm/he.c
27929@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27930
27931 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27932 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27933- atomic_inc(&vcc->stats->rx_drop);
27934+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27935 goto return_host_buffers;
27936 }
27937
27938@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27939 RBRQ_LEN_ERR(he_dev->rbrq_head)
27940 ? "LEN_ERR" : "",
27941 vcc->vpi, vcc->vci);
27942- atomic_inc(&vcc->stats->rx_err);
27943+ atomic_inc_unchecked(&vcc->stats->rx_err);
27944 goto return_host_buffers;
27945 }
27946
27947@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27948 vcc->push(vcc, skb);
27949 spin_lock(&he_dev->global_lock);
27950
27951- atomic_inc(&vcc->stats->rx);
27952+ atomic_inc_unchecked(&vcc->stats->rx);
27953
27954 return_host_buffers:
27955 ++pdus_assembled;
27956@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27957 tpd->vcc->pop(tpd->vcc, tpd->skb);
27958 else
27959 dev_kfree_skb_any(tpd->skb);
27960- atomic_inc(&tpd->vcc->stats->tx_err);
27961+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27962 }
27963 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27964 return;
27965@@ -2526,7 +2526,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
27974@@ -2537,7 +2537,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 return -EINVAL;
27981 }
27982 #endif
27983@@ -2549,7 +2549,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@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27993 vcc->pop(vcc, skb);
27994 else
27995 dev_kfree_skb_any(skb);
27996- atomic_inc(&vcc->stats->tx_err);
27997+ atomic_inc_unchecked(&vcc->stats->tx_err);
27998 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27999 return -ENOMEM;
28000 }
28001@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28002 __enqueue_tpd(he_dev, tpd, cid);
28003 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28004
28005- atomic_inc(&vcc->stats->tx);
28006+ atomic_inc_unchecked(&vcc->stats->tx);
28007
28008 return 0;
28009 }
28010diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28011index 7d01c2a..4e3ac01 100644
28012--- a/drivers/atm/horizon.c
28013+++ b/drivers/atm/horizon.c
28014@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28015 {
28016 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28017 // VC layer stats
28018- atomic_inc(&vcc->stats->rx);
28019+ atomic_inc_unchecked(&vcc->stats->rx);
28020 __net_timestamp(skb);
28021 // end of our responsibility
28022 vcc->push (vcc, skb);
28023@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28024 dev->tx_iovec = NULL;
28025
28026 // VC layer stats
28027- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28028+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28029
28030 // free the skb
28031 hrz_kfree_skb (skb);
28032diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28033index 8974bd2..b856f85 100644
28034--- a/drivers/atm/idt77252.c
28035+++ b/drivers/atm/idt77252.c
28036@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28037 else
28038 dev_kfree_skb(skb);
28039
28040- atomic_inc(&vcc->stats->tx);
28041+ atomic_inc_unchecked(&vcc->stats->tx);
28042 }
28043
28044 atomic_dec(&scq->used);
28045@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28046 if ((sb = dev_alloc_skb(64)) == NULL) {
28047 printk("%s: Can't allocate buffers for aal0.\n",
28048 card->name);
28049- atomic_add(i, &vcc->stats->rx_drop);
28050+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28051 break;
28052 }
28053 if (!atm_charge(vcc, sb->truesize)) {
28054 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28055 card->name);
28056- atomic_add(i - 1, &vcc->stats->rx_drop);
28057+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28058 dev_kfree_skb(sb);
28059 break;
28060 }
28061@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28062 ATM_SKB(sb)->vcc = vcc;
28063 __net_timestamp(sb);
28064 vcc->push(vcc, sb);
28065- atomic_inc(&vcc->stats->rx);
28066+ atomic_inc_unchecked(&vcc->stats->rx);
28067
28068 cell += ATM_CELL_PAYLOAD;
28069 }
28070@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28071 "(CDC: %08x)\n",
28072 card->name, len, rpp->len, readl(SAR_REG_CDC));
28073 recycle_rx_pool_skb(card, rpp);
28074- atomic_inc(&vcc->stats->rx_err);
28075+ atomic_inc_unchecked(&vcc->stats->rx_err);
28076 return;
28077 }
28078 if (stat & SAR_RSQE_CRC) {
28079 RXPRINTK("%s: AAL5 CRC error.\n", 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 (skb_queue_len(&rpp->queue) > 1) {
28086@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28087 RXPRINTK("%s: Can't alloc RX skb.\n",
28088 card->name);
28089 recycle_rx_pool_skb(card, rpp);
28090- atomic_inc(&vcc->stats->rx_err);
28091+ atomic_inc_unchecked(&vcc->stats->rx_err);
28092 return;
28093 }
28094 if (!atm_charge(vcc, skb->truesize)) {
28095@@ -1171,7 +1171,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 return;
28103 }
28104@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28105 __net_timestamp(skb);
28106
28107 vcc->push(vcc, skb);
28108- atomic_inc(&vcc->stats->rx);
28109+ atomic_inc_unchecked(&vcc->stats->rx);
28110
28111 if (skb->truesize > SAR_FB_SIZE_3)
28112 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28113@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28114 if (vcc->qos.aal != ATM_AAL0) {
28115 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28116 card->name, vpi, vci);
28117- atomic_inc(&vcc->stats->rx_drop);
28118+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28119 goto drop;
28120 }
28121
28122 if ((sb = dev_alloc_skb(64)) == NULL) {
28123 printk("%s: Can't allocate buffers for AAL0.\n",
28124 card->name);
28125- atomic_inc(&vcc->stats->rx_err);
28126+ atomic_inc_unchecked(&vcc->stats->rx_err);
28127 goto drop;
28128 }
28129
28130@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28131 ATM_SKB(sb)->vcc = vcc;
28132 __net_timestamp(sb);
28133 vcc->push(vcc, sb);
28134- atomic_inc(&vcc->stats->rx);
28135+ atomic_inc_unchecked(&vcc->stats->rx);
28136
28137 drop:
28138 skb_pull(queue, 64);
28139@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28140
28141 if (vc == NULL) {
28142 printk("%s: NULL connection in send().\n", card->name);
28143- atomic_inc(&vcc->stats->tx_err);
28144+ atomic_inc_unchecked(&vcc->stats->tx_err);
28145 dev_kfree_skb(skb);
28146 return -EINVAL;
28147 }
28148 if (!test_bit(VCF_TX, &vc->flags)) {
28149 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
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@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28156 break;
28157 default:
28158 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28159- atomic_inc(&vcc->stats->tx_err);
28160+ atomic_inc_unchecked(&vcc->stats->tx_err);
28161 dev_kfree_skb(skb);
28162 return -EINVAL;
28163 }
28164
28165 if (skb_shinfo(skb)->nr_frags != 0) {
28166 printk("%s: No scatter-gather yet.\n", card->name);
28167- atomic_inc(&vcc->stats->tx_err);
28168+ atomic_inc_unchecked(&vcc->stats->tx_err);
28169 dev_kfree_skb(skb);
28170 return -EINVAL;
28171 }
28172@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28173
28174 err = queue_skb(card, vc, skb, oam);
28175 if (err) {
28176- atomic_inc(&vcc->stats->tx_err);
28177+ atomic_inc_unchecked(&vcc->stats->tx_err);
28178 dev_kfree_skb(skb);
28179 return err;
28180 }
28181@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28182 skb = dev_alloc_skb(64);
28183 if (!skb) {
28184 printk("%s: Out of memory in send_oam().\n", card->name);
28185- atomic_inc(&vcc->stats->tx_err);
28186+ atomic_inc_unchecked(&vcc->stats->tx_err);
28187 return -ENOMEM;
28188 }
28189 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28190diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28191index d438601..8b98495 100644
28192--- a/drivers/atm/iphase.c
28193+++ b/drivers/atm/iphase.c
28194@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28195 status = (u_short) (buf_desc_ptr->desc_mode);
28196 if (status & (RX_CER | RX_PTE | RX_OFL))
28197 {
28198- atomic_inc(&vcc->stats->rx_err);
28199+ atomic_inc_unchecked(&vcc->stats->rx_err);
28200 IF_ERR(printk("IA: bad packet, dropping it");)
28201 if (status & RX_CER) {
28202 IF_ERR(printk(" cause: packet CRC error\n");)
28203@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28204 len = dma_addr - buf_addr;
28205 if (len > iadev->rx_buf_sz) {
28206 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28207- atomic_inc(&vcc->stats->rx_err);
28208+ atomic_inc_unchecked(&vcc->stats->rx_err);
28209 goto out_free_desc;
28210 }
28211
28212@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28213 ia_vcc = INPH_IA_VCC(vcc);
28214 if (ia_vcc == NULL)
28215 {
28216- atomic_inc(&vcc->stats->rx_err);
28217+ atomic_inc_unchecked(&vcc->stats->rx_err);
28218 atm_return(vcc, skb->truesize);
28219 dev_kfree_skb_any(skb);
28220 goto INCR_DLE;
28221@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28222 if ((length > iadev->rx_buf_sz) || (length >
28223 (skb->len - sizeof(struct cpcs_trailer))))
28224 {
28225- atomic_inc(&vcc->stats->rx_err);
28226+ atomic_inc_unchecked(&vcc->stats->rx_err);
28227 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28228 length, skb->len);)
28229 atm_return(vcc, skb->truesize);
28230@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28231
28232 IF_RX(printk("rx_dle_intr: skb push");)
28233 vcc->push(vcc,skb);
28234- atomic_inc(&vcc->stats->rx);
28235+ atomic_inc_unchecked(&vcc->stats->rx);
28236 iadev->rx_pkt_cnt++;
28237 }
28238 INCR_DLE:
28239@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28240 {
28241 struct k_sonet_stats *stats;
28242 stats = &PRIV(_ia_dev[board])->sonet_stats;
28243- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28244- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28245- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28246- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28247- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28248- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28249- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28250- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28251- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28252+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28253+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28254+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28255+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28256+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28257+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28258+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28259+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28260+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28261 }
28262 ia_cmds.status = 0;
28263 break;
28264@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28265 if ((desc == 0) || (desc > iadev->num_tx_desc))
28266 {
28267 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28268- atomic_inc(&vcc->stats->tx);
28269+ atomic_inc_unchecked(&vcc->stats->tx);
28270 if (vcc->pop)
28271 vcc->pop(vcc, skb);
28272 else
28273@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28274 ATM_DESC(skb) = vcc->vci;
28275 skb_queue_tail(&iadev->tx_dma_q, skb);
28276
28277- atomic_inc(&vcc->stats->tx);
28278+ atomic_inc_unchecked(&vcc->stats->tx);
28279 iadev->tx_pkt_cnt++;
28280 /* Increment transaction counter */
28281 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28282
28283 #if 0
28284 /* add flow control logic */
28285- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28286+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28287 if (iavcc->vc_desc_cnt > 10) {
28288 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28289 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28290diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28291index 68c7588..7036683 100644
28292--- a/drivers/atm/lanai.c
28293+++ b/drivers/atm/lanai.c
28294@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28295 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28296 lanai_endtx(lanai, lvcc);
28297 lanai_free_skb(lvcc->tx.atmvcc, skb);
28298- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28299+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28300 }
28301
28302 /* Try to fill the buffer - don't call unless there is backlog */
28303@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28304 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28305 __net_timestamp(skb);
28306 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28307- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28308+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28309 out:
28310 lvcc->rx.buf.ptr = end;
28311 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28312@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28313 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28314 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28315 lanai->stats.service_rxnotaal5++;
28316- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28317+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28318 return 0;
28319 }
28320 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28321@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28322 int bytes;
28323 read_unlock(&vcc_sklist_lock);
28324 DPRINTK("got trashed rx pdu on vci %d\n", vci);
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_trash++;
28328 bytes = (SERVICE_GET_END(s) * 16) -
28329 (((unsigned long) lvcc->rx.buf.ptr) -
28330@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28331 }
28332 if (s & SERVICE_STREAM) {
28333 read_unlock(&vcc_sklist_lock);
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_stream++;
28337 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28338 "PDU on VCI %d!\n", lanai->number, vci);
28339@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28340 return 0;
28341 }
28342 DPRINTK("got rx crc error on vci %d\n", vci);
28343- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28344+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28345 lvcc->stats.x.aal5.service_rxcrc++;
28346 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28347 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28348diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28349index 1c70c45..300718d 100644
28350--- a/drivers/atm/nicstar.c
28351+++ b/drivers/atm/nicstar.c
28352@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28353 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28354 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\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@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28362 if (!vc->tx) {
28363 printk("nicstar%d: Trying to transmit on a non-tx VC.\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@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28371 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28372 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28373 card->index);
28374- atomic_inc(&vcc->stats->tx_err);
28375+ atomic_inc_unchecked(&vcc->stats->tx_err);
28376 dev_kfree_skb_any(skb);
28377 return -EINVAL;
28378 }
28379
28380 if (skb_shinfo(skb)->nr_frags != 0) {
28381 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28382- atomic_inc(&vcc->stats->tx_err);
28383+ atomic_inc_unchecked(&vcc->stats->tx_err);
28384 dev_kfree_skb_any(skb);
28385 return -EINVAL;
28386 }
28387@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28388 }
28389
28390 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28391- atomic_inc(&vcc->stats->tx_err);
28392+ atomic_inc_unchecked(&vcc->stats->tx_err);
28393 dev_kfree_skb_any(skb);
28394 return -EIO;
28395 }
28396- atomic_inc(&vcc->stats->tx);
28397+ atomic_inc_unchecked(&vcc->stats->tx);
28398
28399 return 0;
28400 }
28401@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28402 printk
28403 ("nicstar%d: Can't allocate buffers for aal0.\n",
28404 card->index);
28405- atomic_add(i, &vcc->stats->rx_drop);
28406+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28407 break;
28408 }
28409 if (!atm_charge(vcc, sb->truesize)) {
28410 RXPRINTK
28411 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28412 card->index);
28413- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28414+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28415 dev_kfree_skb_any(sb);
28416 break;
28417 }
28418@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28419 ATM_SKB(sb)->vcc = vcc;
28420 __net_timestamp(sb);
28421 vcc->push(vcc, sb);
28422- atomic_inc(&vcc->stats->rx);
28423+ atomic_inc_unchecked(&vcc->stats->rx);
28424 cell += ATM_CELL_PAYLOAD;
28425 }
28426
28427@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28428 if (iovb == NULL) {
28429 printk("nicstar%d: Out of iovec buffers.\n",
28430 card->index);
28431- atomic_inc(&vcc->stats->rx_drop);
28432+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28433 recycle_rx_buf(card, skb);
28434 return;
28435 }
28436@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28437 small or large buffer itself. */
28438 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28439 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28440- atomic_inc(&vcc->stats->rx_err);
28441+ atomic_inc_unchecked(&vcc->stats->rx_err);
28442 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28443 NS_MAX_IOVECS);
28444 NS_PRV_IOVCNT(iovb) = 0;
28445@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28446 ("nicstar%d: Expected a small 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_rx_buf(card, skb);
28452 vc->rx_iov = NULL;
28453 recycle_iov_buf(card, iovb);
28454@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28455 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28456 card->index);
28457 which_list(card, skb);
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@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28464 printk(" - PDU size mismatch.\n");
28465 else
28466 printk(".\n");
28467- atomic_inc(&vcc->stats->rx_err);
28468+ atomic_inc_unchecked(&vcc->stats->rx_err);
28469 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28470 NS_PRV_IOVCNT(iovb));
28471 vc->rx_iov = NULL;
28472@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28473 /* skb points to a small buffer */
28474 if (!atm_charge(vcc, skb->truesize)) {
28475 push_rxbufs(card, skb);
28476- atomic_inc(&vcc->stats->rx_drop);
28477+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28478 } else {
28479 skb_put(skb, len);
28480 dequeue_sm_buf(card, skb);
28481@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28482 ATM_SKB(skb)->vcc = vcc;
28483 __net_timestamp(skb);
28484 vcc->push(vcc, skb);
28485- atomic_inc(&vcc->stats->rx);
28486+ atomic_inc_unchecked(&vcc->stats->rx);
28487 }
28488 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28489 struct sk_buff *sb;
28490@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28491 if (len <= NS_SMBUFSIZE) {
28492 if (!atm_charge(vcc, sb->truesize)) {
28493 push_rxbufs(card, sb);
28494- atomic_inc(&vcc->stats->rx_drop);
28495+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28496 } else {
28497 skb_put(sb, len);
28498 dequeue_sm_buf(card, sb);
28499@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28500 ATM_SKB(sb)->vcc = vcc;
28501 __net_timestamp(sb);
28502 vcc->push(vcc, sb);
28503- atomic_inc(&vcc->stats->rx);
28504+ atomic_inc_unchecked(&vcc->stats->rx);
28505 }
28506
28507 push_rxbufs(card, skb);
28508@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28509
28510 if (!atm_charge(vcc, skb->truesize)) {
28511 push_rxbufs(card, skb);
28512- atomic_inc(&vcc->stats->rx_drop);
28513+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28514 } else {
28515 dequeue_lg_buf(card, skb);
28516 #ifdef NS_USE_DESTRUCTORS
28517@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28518 ATM_SKB(skb)->vcc = vcc;
28519 __net_timestamp(skb);
28520 vcc->push(vcc, skb);
28521- atomic_inc(&vcc->stats->rx);
28522+ atomic_inc_unchecked(&vcc->stats->rx);
28523 }
28524
28525 push_rxbufs(card, sb);
28526@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28527 printk
28528 ("nicstar%d: Out of huge buffers.\n",
28529 card->index);
28530- atomic_inc(&vcc->stats->rx_drop);
28531+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28532 recycle_iovec_rx_bufs(card,
28533 (struct iovec *)
28534 iovb->data,
28535@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28536 card->hbpool.count++;
28537 } else
28538 dev_kfree_skb_any(hb);
28539- atomic_inc(&vcc->stats->rx_drop);
28540+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28541 } else {
28542 /* Copy the small buffer to the huge buffer */
28543 sb = (struct sk_buff *)iov->iov_base;
28544@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28545 #endif /* NS_USE_DESTRUCTORS */
28546 __net_timestamp(hb);
28547 vcc->push(vcc, hb);
28548- atomic_inc(&vcc->stats->rx);
28549+ atomic_inc_unchecked(&vcc->stats->rx);
28550 }
28551 }
28552
28553diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28554index 9851093..adb2b1e 100644
28555--- a/drivers/atm/solos-pci.c
28556+++ b/drivers/atm/solos-pci.c
28557@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28558 }
28559 atm_charge(vcc, skb->truesize);
28560 vcc->push(vcc, skb);
28561- atomic_inc(&vcc->stats->rx);
28562+ atomic_inc_unchecked(&vcc->stats->rx);
28563 break;
28564
28565 case PKT_STATUS:
28566@@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28567 vcc = SKB_CB(oldskb)->vcc;
28568
28569 if (vcc) {
28570- atomic_inc(&vcc->stats->tx);
28571+ atomic_inc_unchecked(&vcc->stats->tx);
28572 solos_pop(vcc, oldskb);
28573 } else
28574 dev_kfree_skb_irq(oldskb);
28575diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28576index 0215934..ce9f5b1 100644
28577--- a/drivers/atm/suni.c
28578+++ b/drivers/atm/suni.c
28579@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28580
28581
28582 #define ADD_LIMITED(s,v) \
28583- atomic_add((v),&stats->s); \
28584- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28585+ atomic_add_unchecked((v),&stats->s); \
28586+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28587
28588
28589 static void suni_hz(unsigned long from_timer)
28590diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28591index 5120a96..e2572bd 100644
28592--- a/drivers/atm/uPD98402.c
28593+++ b/drivers/atm/uPD98402.c
28594@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28595 struct sonet_stats tmp;
28596 int error = 0;
28597
28598- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28599+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28600 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28601 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28602 if (zero && !error) {
28603@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28604
28605
28606 #define ADD_LIMITED(s,v) \
28607- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28608- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28609- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28610+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28611+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28612+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28613
28614
28615 static void stat_event(struct atm_dev *dev)
28616@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28617 if (reason & uPD98402_INT_PFM) stat_event(dev);
28618 if (reason & uPD98402_INT_PCO) {
28619 (void) GET(PCOCR); /* clear interrupt cause */
28620- atomic_add(GET(HECCT),
28621+ atomic_add_unchecked(GET(HECCT),
28622 &PRIV(dev)->sonet_stats.uncorr_hcs);
28623 }
28624 if ((reason & uPD98402_INT_RFO) &&
28625@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28626 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28627 uPD98402_INT_LOS),PIMR); /* enable them */
28628 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28629- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28630- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28631- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28632+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28633+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28634+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28635 return 0;
28636 }
28637
28638diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28639index abe4e20..83c4727 100644
28640--- a/drivers/atm/zatm.c
28641+++ b/drivers/atm/zatm.c
28642@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28643 }
28644 if (!size) {
28645 dev_kfree_skb_irq(skb);
28646- if (vcc) atomic_inc(&vcc->stats->rx_err);
28647+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28648 continue;
28649 }
28650 if (!atm_charge(vcc,skb->truesize)) {
28651@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28652 skb->len = size;
28653 ATM_SKB(skb)->vcc = vcc;
28654 vcc->push(vcc,skb);
28655- atomic_inc(&vcc->stats->rx);
28656+ atomic_inc_unchecked(&vcc->stats->rx);
28657 }
28658 zout(pos & 0xffff,MTA(mbx));
28659 #if 0 /* probably a stupid idea */
28660@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28661 skb_queue_head(&zatm_vcc->backlog,skb);
28662 break;
28663 }
28664- atomic_inc(&vcc->stats->tx);
28665+ atomic_inc_unchecked(&vcc->stats->tx);
28666 wake_up(&zatm_vcc->tx_wait);
28667 }
28668
28669diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28670index 765c3a2..771ace6 100644
28671--- a/drivers/base/devtmpfs.c
28672+++ b/drivers/base/devtmpfs.c
28673@@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28674 if (!thread)
28675 return 0;
28676
28677- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28678+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28679 if (err)
28680 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28681 else
28682diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28683index cbb463b..babe2cf 100644
28684--- a/drivers/base/power/wakeup.c
28685+++ b/drivers/base/power/wakeup.c
28686@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28687 * They need to be modified together atomically, so it's better to use one
28688 * atomic variable to hold them both.
28689 */
28690-static atomic_t combined_event_count = ATOMIC_INIT(0);
28691+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28692
28693 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28694 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28695
28696 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28697 {
28698- unsigned int comb = atomic_read(&combined_event_count);
28699+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
28700
28701 *cnt = (comb >> IN_PROGRESS_BITS);
28702 *inpr = comb & MAX_IN_PROGRESS;
28703@@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28704 ws->start_prevent_time = ws->last_time;
28705
28706 /* Increment the counter of events in progress. */
28707- cec = atomic_inc_return(&combined_event_count);
28708+ cec = atomic_inc_return_unchecked(&combined_event_count);
28709
28710 trace_wakeup_source_activate(ws->name, cec);
28711 }
28712@@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28713 * Increment the counter of registered wakeup events and decrement the
28714 * couter of wakeup events in progress simultaneously.
28715 */
28716- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
28717+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28718 trace_wakeup_source_deactivate(ws->name, cec);
28719
28720 split_counters(&cnt, &inpr);
28721diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28722index b0f553b..77b928b 100644
28723--- a/drivers/block/cciss.c
28724+++ b/drivers/block/cciss.c
28725@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28726 int err;
28727 u32 cp;
28728
28729+ memset(&arg64, 0, sizeof(arg64));
28730+
28731 err = 0;
28732 err |=
28733 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28734@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28735 while (!list_empty(&h->reqQ)) {
28736 c = list_entry(h->reqQ.next, CommandList_struct, list);
28737 /* can't do anything if fifo is full */
28738- if ((h->access.fifo_full(h))) {
28739+ if ((h->access->fifo_full(h))) {
28740 dev_warn(&h->pdev->dev, "fifo full\n");
28741 break;
28742 }
28743@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28744 h->Qdepth--;
28745
28746 /* Tell the controller execute command */
28747- h->access.submit_command(h, c);
28748+ h->access->submit_command(h, c);
28749
28750 /* Put job onto the completed Q */
28751 addQ(&h->cmpQ, c);
28752@@ -3443,17 +3445,17 @@ startio:
28753
28754 static inline unsigned long get_next_completion(ctlr_info_t *h)
28755 {
28756- return h->access.command_completed(h);
28757+ return h->access->command_completed(h);
28758 }
28759
28760 static inline int interrupt_pending(ctlr_info_t *h)
28761 {
28762- return h->access.intr_pending(h);
28763+ return h->access->intr_pending(h);
28764 }
28765
28766 static inline long interrupt_not_for_us(ctlr_info_t *h)
28767 {
28768- return ((h->access.intr_pending(h) == 0) ||
28769+ return ((h->access->intr_pending(h) == 0) ||
28770 (h->interrupts_enabled == 0));
28771 }
28772
28773@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28774 u32 a;
28775
28776 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28777- return h->access.command_completed(h);
28778+ return h->access->command_completed(h);
28779
28780 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28781 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28782@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28783 trans_support & CFGTBL_Trans_use_short_tags);
28784
28785 /* Change the access methods to the performant access methods */
28786- h->access = SA5_performant_access;
28787+ h->access = &SA5_performant_access;
28788 h->transMethod = CFGTBL_Trans_Performant;
28789
28790 return;
28791@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28792 if (prod_index < 0)
28793 return -ENODEV;
28794 h->product_name = products[prod_index].product_name;
28795- h->access = *(products[prod_index].access);
28796+ h->access = products[prod_index].access;
28797
28798 if (cciss_board_disabled(h)) {
28799 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28800@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28801 }
28802
28803 /* make sure the board interrupts are off */
28804- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28805+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28806 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28807 if (rc)
28808 goto clean2;
28809@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28810 * fake ones to scoop up any residual completions.
28811 */
28812 spin_lock_irqsave(&h->lock, flags);
28813- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28814+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28815 spin_unlock_irqrestore(&h->lock, flags);
28816 free_irq(h->intr[h->intr_mode], h);
28817 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28818@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28819 dev_info(&h->pdev->dev, "Board READY.\n");
28820 dev_info(&h->pdev->dev,
28821 "Waiting for stale completions to drain.\n");
28822- h->access.set_intr_mask(h, CCISS_INTR_ON);
28823+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28824 msleep(10000);
28825- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28826+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28827
28828 rc = controller_reset_failed(h->cfgtable);
28829 if (rc)
28830@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28831 cciss_scsi_setup(h);
28832
28833 /* Turn the interrupts on so we can service requests */
28834- h->access.set_intr_mask(h, CCISS_INTR_ON);
28835+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28836
28837 /* Get the firmware version */
28838 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28839@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28840 kfree(flush_buf);
28841 if (return_code != IO_OK)
28842 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28843- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28844+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28845 free_irq(h->intr[h->intr_mode], h);
28846 }
28847
28848diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28849index 7fda30e..eb5dfe0 100644
28850--- a/drivers/block/cciss.h
28851+++ b/drivers/block/cciss.h
28852@@ -101,7 +101,7 @@ struct ctlr_info
28853 /* information about each logical volume */
28854 drive_info_struct *drv[CISS_MAX_LUN];
28855
28856- struct access_method access;
28857+ struct access_method *access;
28858
28859 /* queue and queue Info */
28860 struct list_head reqQ;
28861diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28862index 9125bbe..eede5c8 100644
28863--- a/drivers/block/cpqarray.c
28864+++ b/drivers/block/cpqarray.c
28865@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28866 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28867 goto Enomem4;
28868 }
28869- hba[i]->access.set_intr_mask(hba[i], 0);
28870+ hba[i]->access->set_intr_mask(hba[i], 0);
28871 if (request_irq(hba[i]->intr, do_ida_intr,
28872 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28873 {
28874@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28875 add_timer(&hba[i]->timer);
28876
28877 /* Enable IRQ now that spinlock and rate limit timer are set up */
28878- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28879+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28880
28881 for(j=0; j<NWD; j++) {
28882 struct gendisk *disk = ida_gendisk[i][j];
28883@@ -694,7 +694,7 @@ DBGINFO(
28884 for(i=0; i<NR_PRODUCTS; i++) {
28885 if (board_id == products[i].board_id) {
28886 c->product_name = products[i].product_name;
28887- c->access = *(products[i].access);
28888+ c->access = products[i].access;
28889 break;
28890 }
28891 }
28892@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28893 hba[ctlr]->intr = intr;
28894 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28895 hba[ctlr]->product_name = products[j].product_name;
28896- hba[ctlr]->access = *(products[j].access);
28897+ hba[ctlr]->access = products[j].access;
28898 hba[ctlr]->ctlr = ctlr;
28899 hba[ctlr]->board_id = board_id;
28900 hba[ctlr]->pci_dev = NULL; /* not PCI */
28901@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28902
28903 while((c = h->reqQ) != NULL) {
28904 /* Can't do anything if we're busy */
28905- if (h->access.fifo_full(h) == 0)
28906+ if (h->access->fifo_full(h) == 0)
28907 return;
28908
28909 /* Get the first entry from the request Q */
28910@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28911 h->Qdepth--;
28912
28913 /* Tell the controller to do our bidding */
28914- h->access.submit_command(h, c);
28915+ h->access->submit_command(h, c);
28916
28917 /* Get onto the completion Q */
28918 addQ(&h->cmpQ, c);
28919@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28920 unsigned long flags;
28921 __u32 a,a1;
28922
28923- istat = h->access.intr_pending(h);
28924+ istat = h->access->intr_pending(h);
28925 /* Is this interrupt for us? */
28926 if (istat == 0)
28927 return IRQ_NONE;
28928@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28929 */
28930 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28931 if (istat & FIFO_NOT_EMPTY) {
28932- while((a = h->access.command_completed(h))) {
28933+ while((a = h->access->command_completed(h))) {
28934 a1 = a; a &= ~3;
28935 if ((c = h->cmpQ) == NULL)
28936 {
28937@@ -1449,11 +1449,11 @@ static int sendcmd(
28938 /*
28939 * Disable interrupt
28940 */
28941- info_p->access.set_intr_mask(info_p, 0);
28942+ info_p->access->set_intr_mask(info_p, 0);
28943 /* Make sure there is room in the command FIFO */
28944 /* Actually it should be completely empty at this time. */
28945 for (i = 200000; i > 0; i--) {
28946- temp = info_p->access.fifo_full(info_p);
28947+ temp = info_p->access->fifo_full(info_p);
28948 if (temp != 0) {
28949 break;
28950 }
28951@@ -1466,7 +1466,7 @@ DBG(
28952 /*
28953 * Send the cmd
28954 */
28955- info_p->access.submit_command(info_p, c);
28956+ info_p->access->submit_command(info_p, c);
28957 complete = pollcomplete(ctlr);
28958
28959 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28960@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
28961 * we check the new geometry. Then turn interrupts back on when
28962 * we're done.
28963 */
28964- host->access.set_intr_mask(host, 0);
28965+ host->access->set_intr_mask(host, 0);
28966 getgeometry(ctlr);
28967- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
28968+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
28969
28970 for(i=0; i<NWD; i++) {
28971 struct gendisk *disk = ida_gendisk[ctlr][i];
28972@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
28973 /* Wait (up to 2 seconds) for a command to complete */
28974
28975 for (i = 200000; i > 0; i--) {
28976- done = hba[ctlr]->access.command_completed(hba[ctlr]);
28977+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
28978 if (done == 0) {
28979 udelay(10); /* a short fixed delay */
28980 } else
28981diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
28982index be73e9d..7fbf140 100644
28983--- a/drivers/block/cpqarray.h
28984+++ b/drivers/block/cpqarray.h
28985@@ -99,7 +99,7 @@ struct ctlr_info {
28986 drv_info_t drv[NWD];
28987 struct proc_dir_entry *proc;
28988
28989- struct access_method access;
28990+ struct access_method *access;
28991
28992 cmdlist_t *reqQ;
28993 cmdlist_t *cmpQ;
28994diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
28995index 02f013a..afeba24 100644
28996--- a/drivers/block/drbd/drbd_int.h
28997+++ b/drivers/block/drbd/drbd_int.h
28998@@ -735,7 +735,7 @@ struct drbd_request;
28999 struct drbd_epoch {
29000 struct list_head list;
29001 unsigned int barrier_nr;
29002- atomic_t epoch_size; /* increased on every request added. */
29003+ atomic_unchecked_t epoch_size; /* increased on every request added. */
29004 atomic_t active; /* increased on every req. added, and dec on every finished. */
29005 unsigned long flags;
29006 };
29007@@ -1110,7 +1110,7 @@ struct drbd_conf {
29008 void *int_dig_in;
29009 void *int_dig_vv;
29010 wait_queue_head_t seq_wait;
29011- atomic_t packet_seq;
29012+ atomic_unchecked_t packet_seq;
29013 unsigned int peer_seq;
29014 spinlock_t peer_seq_lock;
29015 unsigned int minor;
29016@@ -1651,30 +1651,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29017
29018 static inline void drbd_tcp_cork(struct socket *sock)
29019 {
29020- int __user val = 1;
29021+ int val = 1;
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_uncork(struct socket *sock)
29028 {
29029- int __user val = 0;
29030+ int val = 0;
29031 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29032- (char __user *)&val, sizeof(val));
29033+ (char __force_user *)&val, sizeof(val));
29034 }
29035
29036 static inline void drbd_tcp_nodelay(struct socket *sock)
29037 {
29038- int __user val = 1;
29039+ int val = 1;
29040 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29041- (char __user *)&val, sizeof(val));
29042+ (char __force_user *)&val, sizeof(val));
29043 }
29044
29045 static inline void drbd_tcp_quickack(struct socket *sock)
29046 {
29047- int __user val = 2;
29048+ int val = 2;
29049 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29050- (char __user *)&val, sizeof(val));
29051+ (char __force_user *)&val, sizeof(val));
29052 }
29053
29054 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29055diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29056index 920ede2..cb827ba 100644
29057--- a/drivers/block/drbd/drbd_main.c
29058+++ b/drivers/block/drbd/drbd_main.c
29059@@ -2555,7 +2555,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29060 p.sector = sector;
29061 p.block_id = block_id;
29062 p.blksize = blksize;
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 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29067 return false;
29068@@ -2853,7 +2853,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29069
29070 p.sector = cpu_to_be64(req->sector);
29071 p.block_id = (unsigned long)req;
29072- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29073+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29074
29075 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29076
29077@@ -3138,7 +3138,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29078 atomic_set(&mdev->unacked_cnt, 0);
29079 atomic_set(&mdev->local_cnt, 0);
29080 atomic_set(&mdev->net_cnt, 0);
29081- atomic_set(&mdev->packet_seq, 0);
29082+ atomic_set_unchecked(&mdev->packet_seq, 0);
29083 atomic_set(&mdev->pp_in_use, 0);
29084 atomic_set(&mdev->pp_in_use_by_net, 0);
29085 atomic_set(&mdev->rs_sect_in, 0);
29086@@ -3220,8 +3220,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29087 mdev->receiver.t_state);
29088
29089 /* no need to lock it, I'm the only thread alive */
29090- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29091- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29092+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29093+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29094 mdev->al_writ_cnt =
29095 mdev->bm_writ_cnt =
29096 mdev->read_cnt =
29097diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29098index 6d4de6a..7b7ad4b 100644
29099--- a/drivers/block/drbd/drbd_nl.c
29100+++ b/drivers/block/drbd/drbd_nl.c
29101@@ -2387,7 +2387,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29102 module_put(THIS_MODULE);
29103 }
29104
29105-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29106+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29107
29108 static unsigned short *
29109 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29110@@ -2458,7 +2458,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
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@@ -2490,7 +2490,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
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@@ -2568,7 +2568,7 @@ void drbd_bcast_ee(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);
29137@@ -2607,7 +2607,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29138 cn_reply->id.idx = CN_IDX_DRBD;
29139 cn_reply->id.val = CN_VAL_DRBD;
29140
29141- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29142+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29143 cn_reply->ack = 0; /* not used here. */
29144 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29145 (int)((char *)tl - (char *)reply->tag_list);
29146diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29147index ea4836e..272d72a 100644
29148--- a/drivers/block/drbd/drbd_receiver.c
29149+++ b/drivers/block/drbd/drbd_receiver.c
29150@@ -893,7 +893,7 @@ retry:
29151 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29152 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29153
29154- atomic_set(&mdev->packet_seq, 0);
29155+ atomic_set_unchecked(&mdev->packet_seq, 0);
29156 mdev->peer_seq = 0;
29157
29158 if (drbd_send_protocol(mdev) == -1)
29159@@ -994,7 +994,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29160 do {
29161 next_epoch = NULL;
29162
29163- epoch_size = atomic_read(&epoch->epoch_size);
29164+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29165
29166 switch (ev & ~EV_CLEANUP) {
29167 case EV_PUT:
29168@@ -1030,7 +1030,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29169 rv = FE_DESTROYED;
29170 } else {
29171 epoch->flags = 0;
29172- atomic_set(&epoch->epoch_size, 0);
29173+ atomic_set_unchecked(&epoch->epoch_size, 0);
29174 /* atomic_set(&epoch->active, 0); is already zero */
29175 if (rv == FE_STILL_LIVE)
29176 rv = FE_RECYCLED;
29177@@ -1205,14 +1205,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29178 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29179 drbd_flush(mdev);
29180
29181- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29182+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29183 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29184 if (epoch)
29185 break;
29186 }
29187
29188 epoch = mdev->current_epoch;
29189- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29190+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29191
29192 D_ASSERT(atomic_read(&epoch->active) == 0);
29193 D_ASSERT(epoch->flags == 0);
29194@@ -1224,11 +1224,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29195 }
29196
29197 epoch->flags = 0;
29198- atomic_set(&epoch->epoch_size, 0);
29199+ atomic_set_unchecked(&epoch->epoch_size, 0);
29200 atomic_set(&epoch->active, 0);
29201
29202 spin_lock(&mdev->epoch_lock);
29203- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29204+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29205 list_add(&epoch->list, &mdev->current_epoch->list);
29206 mdev->current_epoch = epoch;
29207 mdev->epochs++;
29208@@ -1695,7 +1695,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29209 spin_unlock(&mdev->peer_seq_lock);
29210
29211 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29212- atomic_inc(&mdev->current_epoch->epoch_size);
29213+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29214 return drbd_drain_block(mdev, data_size);
29215 }
29216
29217@@ -1721,7 +1721,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29218
29219 spin_lock(&mdev->epoch_lock);
29220 e->epoch = mdev->current_epoch;
29221- atomic_inc(&e->epoch->epoch_size);
29222+ atomic_inc_unchecked(&e->epoch->epoch_size);
29223 atomic_inc(&e->epoch->active);
29224 spin_unlock(&mdev->epoch_lock);
29225
29226@@ -3936,7 +3936,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29227 D_ASSERT(list_empty(&mdev->done_ee));
29228
29229 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29230- atomic_set(&mdev->current_epoch->epoch_size, 0);
29231+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29232 D_ASSERT(list_empty(&mdev->current_epoch->list));
29233 }
29234
29235diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29236index 3bba655..6151b66 100644
29237--- a/drivers/block/loop.c
29238+++ b/drivers/block/loop.c
29239@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29240 mm_segment_t old_fs = get_fs();
29241
29242 set_fs(get_ds());
29243- bw = file->f_op->write(file, buf, len, &pos);
29244+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29245 set_fs(old_fs);
29246 if (likely(bw == len))
29247 return 0;
29248diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29249index ea6f632..eafb192 100644
29250--- a/drivers/char/Kconfig
29251+++ b/drivers/char/Kconfig
29252@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29253
29254 config DEVKMEM
29255 bool "/dev/kmem virtual device support"
29256- default y
29257+ default n
29258+ depends on !GRKERNSEC_KMEM
29259 help
29260 Say Y here if you want to support the /dev/kmem device. The
29261 /dev/kmem device is rarely used, but can be used for certain
29262@@ -581,6 +582,7 @@ config DEVPORT
29263 bool
29264 depends on !M68K
29265 depends on ISA || PCI
29266+ depends on !GRKERNSEC_KMEM
29267 default y
29268
29269 source "drivers/s390/char/Kconfig"
29270diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29271index 2e04433..22afc64 100644
29272--- a/drivers/char/agp/frontend.c
29273+++ b/drivers/char/agp/frontend.c
29274@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29275 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29276 return -EFAULT;
29277
29278- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29279+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29280 return -EFAULT;
29281
29282 client = agp_find_client_by_pid(reserve.pid);
29283diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29284index 21cb980..f15107c 100644
29285--- a/drivers/char/genrtc.c
29286+++ b/drivers/char/genrtc.c
29287@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29288 switch (cmd) {
29289
29290 case RTC_PLL_GET:
29291+ memset(&pll, 0, sizeof(pll));
29292 if (get_rtc_pll(&pll))
29293 return -EINVAL;
29294 else
29295diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29296index dfd7876..c0b0885 100644
29297--- a/drivers/char/hpet.c
29298+++ b/drivers/char/hpet.c
29299@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29300 }
29301
29302 static int
29303-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29304+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29305 struct hpet_info *info)
29306 {
29307 struct hpet_timer __iomem *timer;
29308diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29309index 2c29942..604c5ba 100644
29310--- a/drivers/char/ipmi/ipmi_msghandler.c
29311+++ b/drivers/char/ipmi/ipmi_msghandler.c
29312@@ -420,7 +420,7 @@ struct ipmi_smi {
29313 struct proc_dir_entry *proc_dir;
29314 char proc_dir_name[10];
29315
29316- atomic_t stats[IPMI_NUM_STATS];
29317+ atomic_unchecked_t stats[IPMI_NUM_STATS];
29318
29319 /*
29320 * run_to_completion duplicate of smb_info, smi_info
29321@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29322
29323
29324 #define ipmi_inc_stat(intf, stat) \
29325- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29326+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29327 #define ipmi_get_stat(intf, stat) \
29328- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29329+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29330
29331 static int is_lan_addr(struct ipmi_addr *addr)
29332 {
29333@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29334 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29335 init_waitqueue_head(&intf->waitq);
29336 for (i = 0; i < IPMI_NUM_STATS; i++)
29337- atomic_set(&intf->stats[i], 0);
29338+ atomic_set_unchecked(&intf->stats[i], 0);
29339
29340 intf->proc_dir = NULL;
29341
29342diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29343index 1e638ff..a869ef5 100644
29344--- a/drivers/char/ipmi/ipmi_si_intf.c
29345+++ b/drivers/char/ipmi/ipmi_si_intf.c
29346@@ -275,7 +275,7 @@ struct smi_info {
29347 unsigned char slave_addr;
29348
29349 /* Counters and things for the proc filesystem. */
29350- atomic_t stats[SI_NUM_STATS];
29351+ atomic_unchecked_t stats[SI_NUM_STATS];
29352
29353 struct task_struct *thread;
29354
29355@@ -284,9 +284,9 @@ struct smi_info {
29356 };
29357
29358 #define smi_inc_stat(smi, stat) \
29359- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29360+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29361 #define smi_get_stat(smi, stat) \
29362- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29363+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29364
29365 #define SI_MAX_PARMS 4
29366
29367@@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29368 atomic_set(&new_smi->req_events, 0);
29369 new_smi->run_to_completion = 0;
29370 for (i = 0; i < SI_NUM_STATS; i++)
29371- atomic_set(&new_smi->stats[i], 0);
29372+ atomic_set_unchecked(&new_smi->stats[i], 0);
29373
29374 new_smi->interrupt_disabled = 1;
29375 atomic_set(&new_smi->stop_operation, 0);
29376diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29377index 47ff7e4..0c7d340 100644
29378--- a/drivers/char/mbcs.c
29379+++ b/drivers/char/mbcs.c
29380@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29381 return 0;
29382 }
29383
29384-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29385+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29386 {
29387 .part_num = MBCS_PART_NUM,
29388 .mfg_num = MBCS_MFG_NUM,
29389diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29390index 67c3371..ba8429d 100644
29391--- a/drivers/char/mem.c
29392+++ b/drivers/char/mem.c
29393@@ -18,6 +18,7 @@
29394 #include <linux/raw.h>
29395 #include <linux/tty.h>
29396 #include <linux/capability.h>
29397+#include <linux/security.h>
29398 #include <linux/ptrace.h>
29399 #include <linux/device.h>
29400 #include <linux/highmem.h>
29401@@ -35,6 +36,10 @@
29402 # include <linux/efi.h>
29403 #endif
29404
29405+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29406+extern const struct file_operations grsec_fops;
29407+#endif
29408+
29409 static inline unsigned long size_inside_page(unsigned long start,
29410 unsigned long size)
29411 {
29412@@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29413
29414 while (cursor < to) {
29415 if (!devmem_is_allowed(pfn)) {
29416+#ifdef CONFIG_GRKERNSEC_KMEM
29417+ gr_handle_mem_readwrite(from, to);
29418+#else
29419 printk(KERN_INFO
29420 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29421 current->comm, from, to);
29422+#endif
29423 return 0;
29424 }
29425 cursor += PAGE_SIZE;
29426@@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29427 }
29428 return 1;
29429 }
29430+#elif defined(CONFIG_GRKERNSEC_KMEM)
29431+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29432+{
29433+ return 0;
29434+}
29435 #else
29436 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29437 {
29438@@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29439
29440 while (count > 0) {
29441 unsigned long remaining;
29442+ char *temp;
29443
29444 sz = size_inside_page(p, count);
29445
29446@@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29447 if (!ptr)
29448 return -EFAULT;
29449
29450- remaining = copy_to_user(buf, ptr, sz);
29451+#ifdef CONFIG_PAX_USERCOPY
29452+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29453+ if (!temp) {
29454+ unxlate_dev_mem_ptr(p, ptr);
29455+ return -ENOMEM;
29456+ }
29457+ memcpy(temp, ptr, sz);
29458+#else
29459+ temp = ptr;
29460+#endif
29461+
29462+ remaining = copy_to_user(buf, temp, sz);
29463+
29464+#ifdef CONFIG_PAX_USERCOPY
29465+ kfree(temp);
29466+#endif
29467+
29468 unxlate_dev_mem_ptr(p, ptr);
29469 if (remaining)
29470 return -EFAULT;
29471@@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29472 size_t count, loff_t *ppos)
29473 {
29474 unsigned long p = *ppos;
29475- ssize_t low_count, read, sz;
29476+ ssize_t low_count, read, sz, err = 0;
29477 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29478- int err = 0;
29479
29480 read = 0;
29481 if (p < (unsigned long) high_memory) {
29482@@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29483 }
29484 #endif
29485 while (low_count > 0) {
29486+ char *temp;
29487+
29488 sz = size_inside_page(p, low_count);
29489
29490 /*
29491@@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29492 */
29493 kbuf = xlate_dev_kmem_ptr((char *)p);
29494
29495- if (copy_to_user(buf, kbuf, sz))
29496+#ifdef CONFIG_PAX_USERCOPY
29497+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29498+ if (!temp)
29499+ return -ENOMEM;
29500+ memcpy(temp, kbuf, sz);
29501+#else
29502+ temp = kbuf;
29503+#endif
29504+
29505+ err = copy_to_user(buf, temp, sz);
29506+
29507+#ifdef CONFIG_PAX_USERCOPY
29508+ kfree(temp);
29509+#endif
29510+
29511+ if (err)
29512 return -EFAULT;
29513 buf += sz;
29514 p += sz;
29515@@ -831,6 +878,9 @@ static const struct memdev {
29516 #ifdef CONFIG_CRASH_DUMP
29517 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29518 #endif
29519+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29520+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29521+#endif
29522 };
29523
29524 static int memory_open(struct inode *inode, struct file *filp)
29525diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29526index 9df78e2..01ba9ae 100644
29527--- a/drivers/char/nvram.c
29528+++ b/drivers/char/nvram.c
29529@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29530
29531 spin_unlock_irq(&rtc_lock);
29532
29533- if (copy_to_user(buf, contents, tmp - contents))
29534+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29535 return -EFAULT;
29536
29537 *ppos = i;
29538diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29539index 0a484b4..f48ccd1 100644
29540--- a/drivers/char/pcmcia/synclink_cs.c
29541+++ b/drivers/char/pcmcia/synclink_cs.c
29542@@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29543
29544 if (debug_level >= DEBUG_LEVEL_INFO)
29545 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29546- __FILE__,__LINE__, info->device_name, port->count);
29547+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29548
29549- WARN_ON(!port->count);
29550+ WARN_ON(!atomic_read(&port->count));
29551
29552 if (tty_port_close_start(port, tty, filp) == 0)
29553 goto cleanup;
29554@@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29555 cleanup:
29556 if (debug_level >= DEBUG_LEVEL_INFO)
29557 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29558- tty->driver->name, port->count);
29559+ tty->driver->name, atomic_read(&port->count));
29560 }
29561
29562 /* Wait until the transmitter is empty.
29563@@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29564
29565 if (debug_level >= DEBUG_LEVEL_INFO)
29566 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29567- __FILE__,__LINE__,tty->driver->name, port->count);
29568+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29569
29570 /* If port is closing, signal caller to try again */
29571 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29572@@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29573 goto cleanup;
29574 }
29575 spin_lock(&port->lock);
29576- port->count++;
29577+ atomic_inc(&port->count);
29578 spin_unlock(&port->lock);
29579 spin_unlock_irqrestore(&info->netlock, flags);
29580
29581- if (port->count == 1) {
29582+ if (atomic_read(&port->count) == 1) {
29583 /* 1st open on this device, init hardware */
29584 retval = startup(info, tty);
29585 if (retval < 0)
29586@@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29587 unsigned short new_crctype;
29588
29589 /* return error if TTY interface open */
29590- if (info->port.count)
29591+ if (atomic_read(&info->port.count))
29592 return -EBUSY;
29593
29594 switch (encoding)
29595@@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29596
29597 /* arbitrate between network and tty opens */
29598 spin_lock_irqsave(&info->netlock, flags);
29599- if (info->port.count != 0 || info->netcount != 0) {
29600+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29601 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29602 spin_unlock_irqrestore(&info->netlock, flags);
29603 return -EBUSY;
29604@@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29605 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29606
29607 /* return error if TTY interface open */
29608- if (info->port.count)
29609+ if (atomic_read(&info->port.count))
29610 return -EBUSY;
29611
29612 if (cmd != SIOCWANDEV)
29613diff --git a/drivers/char/random.c b/drivers/char/random.c
29614index 4ec04a7..9918387 100644
29615--- a/drivers/char/random.c
29616+++ b/drivers/char/random.c
29617@@ -261,8 +261,13 @@
29618 /*
29619 * Configuration information
29620 */
29621+#ifdef CONFIG_GRKERNSEC_RANDNET
29622+#define INPUT_POOL_WORDS 512
29623+#define OUTPUT_POOL_WORDS 128
29624+#else
29625 #define INPUT_POOL_WORDS 128
29626 #define OUTPUT_POOL_WORDS 32
29627+#endif
29628 #define SEC_XFER_SIZE 512
29629 #define EXTRACT_SIZE 10
29630
29631@@ -300,10 +305,17 @@ static struct poolinfo {
29632 int poolwords;
29633 int tap1, tap2, tap3, tap4, tap5;
29634 } poolinfo_table[] = {
29635+#ifdef CONFIG_GRKERNSEC_RANDNET
29636+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29637+ { 512, 411, 308, 208, 104, 1 },
29638+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29639+ { 128, 103, 76, 51, 25, 1 },
29640+#else
29641 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29642 { 128, 103, 76, 51, 25, 1 },
29643 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29644 { 32, 26, 20, 14, 7, 1 },
29645+#endif
29646 #if 0
29647 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29648 { 2048, 1638, 1231, 819, 411, 1 },
29649@@ -726,6 +738,17 @@ void add_disk_randomness(struct gendisk *disk)
29650 }
29651 #endif
29652
29653+#ifdef CONFIG_PAX_LATENT_ENTROPY
29654+u64 latent_entropy;
29655+
29656+__init void transfer_latent_entropy(void)
29657+{
29658+ mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy));
29659+ mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy));
29660+// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29661+}
29662+#endif
29663+
29664 /*********************************************************************
29665 *
29666 * Entropy extraction routines
29667@@ -913,7 +936,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29668
29669 extract_buf(r, tmp);
29670 i = min_t(int, nbytes, EXTRACT_SIZE);
29671- if (copy_to_user(buf, tmp, i)) {
29672+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29673 ret = -EFAULT;
29674 break;
29675 }
29676@@ -1238,7 +1261,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29677 #include <linux/sysctl.h>
29678
29679 static int min_read_thresh = 8, min_write_thresh;
29680-static int max_read_thresh = INPUT_POOL_WORDS * 32;
29681+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29682 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29683 static char sysctl_bootid[16];
29684
29685diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29686index 45713f0..8286d21 100644
29687--- a/drivers/char/sonypi.c
29688+++ b/drivers/char/sonypi.c
29689@@ -54,6 +54,7 @@
29690
29691 #include <asm/uaccess.h>
29692 #include <asm/io.h>
29693+#include <asm/local.h>
29694
29695 #include <linux/sonypi.h>
29696
29697@@ -490,7 +491,7 @@ static struct sonypi_device {
29698 spinlock_t fifo_lock;
29699 wait_queue_head_t fifo_proc_list;
29700 struct fasync_struct *fifo_async;
29701- int open_count;
29702+ local_t open_count;
29703 int model;
29704 struct input_dev *input_jog_dev;
29705 struct input_dev *input_key_dev;
29706@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29707 static int sonypi_misc_release(struct inode *inode, struct file *file)
29708 {
29709 mutex_lock(&sonypi_device.lock);
29710- sonypi_device.open_count--;
29711+ local_dec(&sonypi_device.open_count);
29712 mutex_unlock(&sonypi_device.lock);
29713 return 0;
29714 }
29715@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29716 {
29717 mutex_lock(&sonypi_device.lock);
29718 /* Flush input queue on first open */
29719- if (!sonypi_device.open_count)
29720+ if (!local_read(&sonypi_device.open_count))
29721 kfifo_reset(&sonypi_device.fifo);
29722- sonypi_device.open_count++;
29723+ local_inc(&sonypi_device.open_count);
29724 mutex_unlock(&sonypi_device.lock);
29725
29726 return 0;
29727diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29728index ad7c732..5aa8054 100644
29729--- a/drivers/char/tpm/tpm.c
29730+++ b/drivers/char/tpm/tpm.c
29731@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29732 chip->vendor.req_complete_val)
29733 goto out_recv;
29734
29735- if ((status == chip->vendor.req_canceled)) {
29736+ if (status == chip->vendor.req_canceled) {
29737 dev_err(chip->dev, "Operation Canceled\n");
29738 rc = -ECANCELED;
29739 goto out;
29740diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29741index 0636520..169c1d0 100644
29742--- a/drivers/char/tpm/tpm_bios.c
29743+++ b/drivers/char/tpm/tpm_bios.c
29744@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29745 event = addr;
29746
29747 if ((event->event_type == 0 && event->event_size == 0) ||
29748- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29749+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29750 return NULL;
29751
29752 return addr;
29753@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29754 return NULL;
29755
29756 if ((event->event_type == 0 && event->event_size == 0) ||
29757- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29758+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29759 return NULL;
29760
29761 (*pos)++;
29762@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29763 int i;
29764
29765 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29766- seq_putc(m, data[i]);
29767+ if (!seq_putc(m, data[i]))
29768+ return -EFAULT;
29769
29770 return 0;
29771 }
29772@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29773 log->bios_event_log_end = log->bios_event_log + len;
29774
29775 virt = acpi_os_map_memory(start, len);
29776+ if (!virt) {
29777+ kfree(log->bios_event_log);
29778+ log->bios_event_log = NULL;
29779+ return -EFAULT;
29780+ }
29781
29782- memcpy(log->bios_event_log, virt, len);
29783+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29784
29785 acpi_os_unmap_memory(virt, len);
29786 return 0;
29787diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29788index cdf2f54..e55c197 100644
29789--- a/drivers/char/virtio_console.c
29790+++ b/drivers/char/virtio_console.c
29791@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29792 if (to_user) {
29793 ssize_t ret;
29794
29795- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29796+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29797 if (ret)
29798 return -EFAULT;
29799 } else {
29800@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29801 if (!port_has_data(port) && !port->host_connected)
29802 return 0;
29803
29804- return fill_readbuf(port, ubuf, count, true);
29805+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29806 }
29807
29808 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29809diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29810index 97f5064..202b6e6 100644
29811--- a/drivers/edac/edac_pci_sysfs.c
29812+++ b/drivers/edac/edac_pci_sysfs.c
29813@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29814 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29815 static int edac_pci_poll_msec = 1000; /* one second workq period */
29816
29817-static atomic_t pci_parity_count = ATOMIC_INIT(0);
29818-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29819+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29820+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29821
29822 static struct kobject *edac_pci_top_main_kobj;
29823 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29824@@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29825 edac_printk(KERN_CRIT, EDAC_PCI,
29826 "Signaled System Error on %s\n",
29827 pci_name(dev));
29828- atomic_inc(&pci_nonparity_count);
29829+ atomic_inc_unchecked(&pci_nonparity_count);
29830 }
29831
29832 if (status & (PCI_STATUS_PARITY)) {
29833@@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29834 "Master Data 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 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29842@@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29843 "Detected Parity Error on %s\n",
29844 pci_name(dev));
29845
29846- atomic_inc(&pci_parity_count);
29847+ atomic_inc_unchecked(&pci_parity_count);
29848 }
29849 }
29850
29851@@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29852 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29853 "Signaled System Error on %s\n",
29854 pci_name(dev));
29855- atomic_inc(&pci_nonparity_count);
29856+ atomic_inc_unchecked(&pci_nonparity_count);
29857 }
29858
29859 if (status & (PCI_STATUS_PARITY)) {
29860@@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29861 "Master Data Parity Error on "
29862 "%s\n", pci_name(dev));
29863
29864- atomic_inc(&pci_parity_count);
29865+ atomic_inc_unchecked(&pci_parity_count);
29866 }
29867
29868 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29869@@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29870 "Detected Parity Error on %s\n",
29871 pci_name(dev));
29872
29873- atomic_inc(&pci_parity_count);
29874+ atomic_inc_unchecked(&pci_parity_count);
29875 }
29876 }
29877 }
29878@@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29879 if (!check_pci_errors)
29880 return;
29881
29882- before_count = atomic_read(&pci_parity_count);
29883+ before_count = atomic_read_unchecked(&pci_parity_count);
29884
29885 /* scan all PCI devices looking for a Parity Error on devices and
29886 * bridges.
29887@@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29888 /* Only if operator has selected panic on PCI Error */
29889 if (edac_pci_get_panic_on_pe()) {
29890 /* If the count is different 'after' from 'before' */
29891- if (before_count != atomic_read(&pci_parity_count))
29892+ if (before_count != atomic_read_unchecked(&pci_parity_count))
29893 panic("EDAC: PCI Parity Error");
29894 }
29895 }
29896diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29897index 8c87a5e..a19cbd7 100644
29898--- a/drivers/edac/mce_amd.h
29899+++ b/drivers/edac/mce_amd.h
29900@@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
29901 struct amd_decoder_ops {
29902 bool (*dc_mce)(u16, u8);
29903 bool (*ic_mce)(u16, u8);
29904-};
29905+} __no_const;
29906
29907 void amd_report_gart_errors(bool);
29908 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29909diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29910index 57ea7f4..789e3c3 100644
29911--- a/drivers/firewire/core-card.c
29912+++ b/drivers/firewire/core-card.c
29913@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
29914
29915 void fw_core_remove_card(struct fw_card *card)
29916 {
29917- struct fw_card_driver dummy_driver = dummy_driver_template;
29918+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
29919
29920 card->driver->update_phy_reg(card, 4,
29921 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29922diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29923index 2783f69..9f4b0cc 100644
29924--- a/drivers/firewire/core-cdev.c
29925+++ b/drivers/firewire/core-cdev.c
29926@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
29927 int ret;
29928
29929 if ((request->channels == 0 && request->bandwidth == 0) ||
29930- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29931- request->bandwidth < 0)
29932+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29933 return -EINVAL;
29934
29935 r = kmalloc(sizeof(*r), GFP_KERNEL);
29936diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29937index 780708d..ad60a66 100644
29938--- a/drivers/firewire/core-transaction.c
29939+++ b/drivers/firewire/core-transaction.c
29940@@ -37,6 +37,7 @@
29941 #include <linux/timer.h>
29942 #include <linux/types.h>
29943 #include <linux/workqueue.h>
29944+#include <linux/sched.h>
29945
29946 #include <asm/byteorder.h>
29947
29948diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29949index 515a42c..5ecf3ba 100644
29950--- a/drivers/firewire/core.h
29951+++ b/drivers/firewire/core.h
29952@@ -111,6 +111,7 @@ struct fw_card_driver {
29953
29954 int (*stop_iso)(struct fw_iso_context *ctx);
29955 };
29956+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29957
29958 void fw_card_initialize(struct fw_card *card,
29959 const struct fw_card_driver *driver, struct device *device);
29960diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29961index 153980b..4b4d046 100644
29962--- a/drivers/firmware/dmi_scan.c
29963+++ b/drivers/firmware/dmi_scan.c
29964@@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29965 }
29966 }
29967 else {
29968- /*
29969- * no iounmap() for that ioremap(); it would be a no-op, but
29970- * it's so early in setup that sucker gets confused into doing
29971- * what it shouldn't if we actually call it.
29972- */
29973 p = dmi_ioremap(0xF0000, 0x10000);
29974 if (p == NULL)
29975 goto error;
29976@@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29977 if (buf == NULL)
29978 return -1;
29979
29980- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29981+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29982
29983 iounmap(buf);
29984 return 0;
29985diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29986index 82d5c20..44a7177 100644
29987--- a/drivers/gpio/gpio-vr41xx.c
29988+++ b/drivers/gpio/gpio-vr41xx.c
29989@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
29990 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
29991 maskl, pendl, maskh, pendh);
29992
29993- atomic_inc(&irq_err_count);
29994+ atomic_inc_unchecked(&irq_err_count);
29995
29996 return -EINVAL;
29997 }
29998diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
29999index 3252e70..b5314ace 100644
30000--- a/drivers/gpu/drm/drm_crtc_helper.c
30001+++ b/drivers/gpu/drm/drm_crtc_helper.c
30002@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30003 struct drm_crtc *tmp;
30004 int crtc_mask = 1;
30005
30006- WARN(!crtc, "checking null crtc?\n");
30007+ BUG_ON(!crtc);
30008
30009 dev = crtc->dev;
30010
30011diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30012index 8a9d079..606cdd5 100644
30013--- a/drivers/gpu/drm/drm_drv.c
30014+++ b/drivers/gpu/drm/drm_drv.c
30015@@ -318,7 +318,7 @@ module_exit(drm_core_exit);
30016 /**
30017 * Copy and IOCTL return string to user space
30018 */
30019-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30020+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30021 {
30022 int len;
30023
30024@@ -401,7 +401,7 @@ long drm_ioctl(struct file *filp,
30025 return -ENODEV;
30026
30027 atomic_inc(&dev->ioctl_count);
30028- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30029+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30030 ++file_priv->ioctl_count;
30031
30032 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30033diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30034index 123de28..43a0897 100644
30035--- a/drivers/gpu/drm/drm_fops.c
30036+++ b/drivers/gpu/drm/drm_fops.c
30037@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30038 }
30039
30040 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30041- atomic_set(&dev->counts[i], 0);
30042+ atomic_set_unchecked(&dev->counts[i], 0);
30043
30044 dev->sigdata.lock = NULL;
30045
30046@@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30047
30048 retcode = drm_open_helper(inode, filp, dev);
30049 if (!retcode) {
30050- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30051- if (!dev->open_count++)
30052+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30053+ if (local_inc_return(&dev->open_count) == 1)
30054 retcode = drm_setup(dev);
30055 }
30056 if (!retcode) {
30057@@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30058
30059 mutex_lock(&drm_global_mutex);
30060
30061- DRM_DEBUG("open_count = %d\n", dev->open_count);
30062+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30063
30064 if (dev->driver->preclose)
30065 dev->driver->preclose(dev, file_priv);
30066@@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30067 * Begin inline drm_release
30068 */
30069
30070- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30071+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30072 task_pid_nr(current),
30073 (long)old_encode_dev(file_priv->minor->device),
30074- dev->open_count);
30075+ local_read(&dev->open_count));
30076
30077 /* Release any auth tokens that might point to this file_priv,
30078 (do that under the drm_global_mutex) */
30079@@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30080 * End inline drm_release
30081 */
30082
30083- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30084- if (!--dev->open_count) {
30085+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30086+ if (local_dec_and_test(&dev->open_count)) {
30087 if (atomic_read(&dev->ioctl_count)) {
30088 DRM_ERROR("Device busy: %d\n",
30089 atomic_read(&dev->ioctl_count));
30090diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30091index c87dc96..326055d 100644
30092--- a/drivers/gpu/drm/drm_global.c
30093+++ b/drivers/gpu/drm/drm_global.c
30094@@ -36,7 +36,7 @@
30095 struct drm_global_item {
30096 struct mutex mutex;
30097 void *object;
30098- int refcount;
30099+ atomic_t refcount;
30100 };
30101
30102 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30103@@ -49,7 +49,7 @@ void drm_global_init(void)
30104 struct drm_global_item *item = &glob[i];
30105 mutex_init(&item->mutex);
30106 item->object = NULL;
30107- item->refcount = 0;
30108+ atomic_set(&item->refcount, 0);
30109 }
30110 }
30111
30112@@ -59,7 +59,7 @@ void drm_global_release(void)
30113 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30114 struct drm_global_item *item = &glob[i];
30115 BUG_ON(item->object != NULL);
30116- BUG_ON(item->refcount != 0);
30117+ BUG_ON(atomic_read(&item->refcount) != 0);
30118 }
30119 }
30120
30121@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30122 void *object;
30123
30124 mutex_lock(&item->mutex);
30125- if (item->refcount == 0) {
30126+ if (atomic_read(&item->refcount) == 0) {
30127 item->object = kzalloc(ref->size, GFP_KERNEL);
30128 if (unlikely(item->object == NULL)) {
30129 ret = -ENOMEM;
30130@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30131 goto out_err;
30132
30133 }
30134- ++item->refcount;
30135+ atomic_inc(&item->refcount);
30136 ref->object = item->object;
30137 object = item->object;
30138 mutex_unlock(&item->mutex);
30139@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30140 struct drm_global_item *item = &glob[ref->global_type];
30141
30142 mutex_lock(&item->mutex);
30143- BUG_ON(item->refcount == 0);
30144+ BUG_ON(atomic_read(&item->refcount) == 0);
30145 BUG_ON(ref->object != item->object);
30146- if (--item->refcount == 0) {
30147+ if (atomic_dec_and_test(&item->refcount)) {
30148 ref->release(ref);
30149 item->object = NULL;
30150 }
30151diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30152index ab1162d..42587b2 100644
30153--- a/drivers/gpu/drm/drm_info.c
30154+++ b/drivers/gpu/drm/drm_info.c
30155@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30156 struct drm_local_map *map;
30157 struct drm_map_list *r_list;
30158
30159- /* Hardcoded from _DRM_FRAME_BUFFER,
30160- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30161- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30162- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30163+ static const char * const types[] = {
30164+ [_DRM_FRAME_BUFFER] = "FB",
30165+ [_DRM_REGISTERS] = "REG",
30166+ [_DRM_SHM] = "SHM",
30167+ [_DRM_AGP] = "AGP",
30168+ [_DRM_SCATTER_GATHER] = "SG",
30169+ [_DRM_CONSISTENT] = "PCI",
30170+ [_DRM_GEM] = "GEM" };
30171 const char *type;
30172 int i;
30173
30174@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30175 map = r_list->map;
30176 if (!map)
30177 continue;
30178- if (map->type < 0 || map->type > 5)
30179+ if (map->type >= ARRAY_SIZE(types))
30180 type = "??";
30181 else
30182 type = types[map->type];
30183@@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30184 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30185 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30186 vma->vm_flags & VM_IO ? 'i' : '-',
30187+#ifdef CONFIG_GRKERNSEC_HIDESYM
30188+ 0);
30189+#else
30190 vma->vm_pgoff);
30191+#endif
30192
30193 #if defined(__i386__)
30194 pgprot = pgprot_val(vma->vm_page_prot);
30195diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30196index 637fcc3..e890b33 100644
30197--- a/drivers/gpu/drm/drm_ioc32.c
30198+++ b/drivers/gpu/drm/drm_ioc32.c
30199@@ -457,7 +457,7 @@ static int compat_drm_infobufs(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_desc *) (request + 1);
30204+ list = (struct drm_buf_desc __user *) (request + 1);
30205
30206 if (__put_user(count, &request->count)
30207 || __put_user(list, &request->list))
30208@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30209 request = compat_alloc_user_space(nbytes);
30210 if (!access_ok(VERIFY_WRITE, request, nbytes))
30211 return -EFAULT;
30212- list = (struct drm_buf_pub *) (request + 1);
30213+ list = (struct drm_buf_pub __user *) (request + 1);
30214
30215 if (__put_user(count, &request->count)
30216 || __put_user(list, &request->list))
30217diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30218index 64a62c6..ceab35e 100644
30219--- a/drivers/gpu/drm/drm_ioctl.c
30220+++ b/drivers/gpu/drm/drm_ioctl.c
30221@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30222 stats->data[i].value =
30223 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30224 else
30225- stats->data[i].value = atomic_read(&dev->counts[i]);
30226+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30227 stats->data[i].type = dev->types[i];
30228 }
30229
30230diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30231index 5211520..c744d85 100644
30232--- a/drivers/gpu/drm/drm_lock.c
30233+++ b/drivers/gpu/drm/drm_lock.c
30234@@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30235 if (drm_lock_take(&master->lock, lock->context)) {
30236 master->lock.file_priv = file_priv;
30237 master->lock.lock_time = jiffies;
30238- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30239+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30240 break; /* Got lock */
30241 }
30242
30243@@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30244 return -EINVAL;
30245 }
30246
30247- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30248+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30249
30250 if (drm_lock_free(&master->lock, lock->context)) {
30251 /* FIXME: Should really bail out here. */
30252diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30253index 21bcd4a..8e074e0 100644
30254--- a/drivers/gpu/drm/drm_stub.c
30255+++ b/drivers/gpu/drm/drm_stub.c
30256@@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30257
30258 drm_device_set_unplugged(dev);
30259
30260- if (dev->open_count == 0) {
30261+ if (local_read(&dev->open_count) == 0) {
30262 drm_put_dev(dev);
30263 }
30264 mutex_unlock(&drm_global_mutex);
30265diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30266index fa94391..ed26ec8 100644
30267--- a/drivers/gpu/drm/i810/i810_dma.c
30268+++ b/drivers/gpu/drm/i810/i810_dma.c
30269@@ -943,8 +943,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30270 dma->buflist[vertex->idx],
30271 vertex->discard, vertex->used);
30272
30273- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30274- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30275+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30276+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30277 sarea_priv->last_enqueue = dev_priv->counter - 1;
30278 sarea_priv->last_dispatch = (int)hw_status[5];
30279
30280@@ -1104,8 +1104,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30281 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30282 mc->last_render);
30283
30284- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30285- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30286+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30287+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30288 sarea_priv->last_enqueue = dev_priv->counter - 1;
30289 sarea_priv->last_dispatch = (int)hw_status[5];
30290
30291diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30292index c9339f4..f5e1b9d 100644
30293--- a/drivers/gpu/drm/i810/i810_drv.h
30294+++ b/drivers/gpu/drm/i810/i810_drv.h
30295@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30296 int page_flipping;
30297
30298 wait_queue_head_t irq_queue;
30299- atomic_t irq_received;
30300- atomic_t irq_emitted;
30301+ atomic_unchecked_t irq_received;
30302+ atomic_unchecked_t irq_emitted;
30303
30304 int front_offset;
30305 } drm_i810_private_t;
30306diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30307index 5363e9c..59360d1 100644
30308--- a/drivers/gpu/drm/i915/i915_debugfs.c
30309+++ b/drivers/gpu/drm/i915/i915_debugfs.c
30310@@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30311 I915_READ(GTIMR));
30312 }
30313 seq_printf(m, "Interrupts received: %d\n",
30314- atomic_read(&dev_priv->irq_received));
30315+ atomic_read_unchecked(&dev_priv->irq_received));
30316 for (i = 0; i < I915_NUM_RINGS; i++) {
30317 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30318 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30319diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30320index 36822b9..b725e1b 100644
30321--- a/drivers/gpu/drm/i915/i915_dma.c
30322+++ b/drivers/gpu/drm/i915/i915_dma.c
30323@@ -1266,7 +1266,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30324 bool can_switch;
30325
30326 spin_lock(&dev->count_lock);
30327- can_switch = (dev->open_count == 0);
30328+ can_switch = (local_read(&dev->open_count) == 0);
30329 spin_unlock(&dev->count_lock);
30330 return can_switch;
30331 }
30332diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30333index b0b676a..d107105 100644
30334--- a/drivers/gpu/drm/i915/i915_drv.h
30335+++ b/drivers/gpu/drm/i915/i915_drv.h
30336@@ -268,7 +268,7 @@ struct drm_i915_display_funcs {
30337 /* render clock increase/decrease */
30338 /* display clock increase/decrease */
30339 /* pll clock increase/decrease */
30340-};
30341+} __no_const;
30342
30343 struct intel_device_info {
30344 u8 gen;
30345@@ -386,7 +386,7 @@ typedef struct drm_i915_private {
30346 int current_page;
30347 int page_flipping;
30348
30349- atomic_t irq_received;
30350+ atomic_unchecked_t irq_received;
30351
30352 /* protects the irq masks */
30353 spinlock_t irq_lock;
30354@@ -985,7 +985,7 @@ struct drm_i915_gem_object {
30355 * will be page flipped away on the next vblank. When it
30356 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30357 */
30358- atomic_t pending_flip;
30359+ atomic_unchecked_t pending_flip;
30360 };
30361
30362 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30363@@ -1434,7 +1434,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30364 struct drm_i915_private *dev_priv, unsigned port);
30365 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30366 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30367-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30368+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30369 {
30370 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30371 }
30372diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30373index 974a9f1..b3ebd45 100644
30374--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30375+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30376@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30377 i915_gem_clflush_object(obj);
30378
30379 if (obj->base.pending_write_domain)
30380- cd->flips |= atomic_read(&obj->pending_flip);
30381+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30382
30383 /* The actual obj->write_domain will be updated with
30384 * pending_write_domain after we emit the accumulated flush for all
30385@@ -916,9 +916,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30386
30387 static int
30388 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30389- int count)
30390+ unsigned int count)
30391 {
30392- int i;
30393+ unsigned int i;
30394
30395 for (i = 0; i < count; i++) {
30396 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30397diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30398index ed3224c..6618589 100644
30399--- a/drivers/gpu/drm/i915/i915_irq.c
30400+++ b/drivers/gpu/drm/i915/i915_irq.c
30401@@ -433,7 +433,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30402 int vblank = 0;
30403 bool blc_event;
30404
30405- atomic_inc(&dev_priv->irq_received);
30406+ atomic_inc_unchecked(&dev_priv->irq_received);
30407
30408 vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS |
30409 PIPE_VBLANK_INTERRUPT_STATUS;
30410@@ -586,7 +586,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30411 irqreturn_t ret = IRQ_NONE;
30412 int i;
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@@ -661,7 +661,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30420 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30421 u32 hotplug_mask;
30422
30423- atomic_inc(&dev_priv->irq_received);
30424+ atomic_inc_unchecked(&dev_priv->irq_received);
30425
30426 /* disable master interrupt before clearing iir */
30427 de_ier = I915_READ(DEIER);
30428@@ -1646,7 +1646,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30429 {
30430 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30431
30432- atomic_set(&dev_priv->irq_received, 0);
30433+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30434
30435
30436 I915_WRITE(HWSTAM, 0xeffe);
30437@@ -1673,7 +1673,7 @@ static void valleyview_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 /* VLV magic */
30445 I915_WRITE(VLV_IMR, 0);
30446@@ -1969,7 +1969,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30447 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30448 int pipe;
30449
30450- atomic_set(&dev_priv->irq_received, 0);
30451+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30452
30453 for_each_pipe(pipe)
30454 I915_WRITE(PIPESTAT(pipe), 0);
30455@@ -2020,7 +2020,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30456 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30457 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30458
30459- atomic_inc(&dev_priv->irq_received);
30460+ atomic_inc_unchecked(&dev_priv->irq_received);
30461
30462 iir = I915_READ16(IIR);
30463 if (iir == 0)
30464@@ -2105,7 +2105,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30465 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30466 int pipe;
30467
30468- atomic_set(&dev_priv->irq_received, 0);
30469+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30470
30471 if (I915_HAS_HOTPLUG(dev)) {
30472 I915_WRITE(PORT_HOTPLUG_EN, 0);
30473@@ -2200,7 +2200,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30474 };
30475 int pipe, ret = IRQ_NONE;
30476
30477- atomic_inc(&dev_priv->irq_received);
30478+ atomic_inc_unchecked(&dev_priv->irq_received);
30479
30480 iir = I915_READ(IIR);
30481 do {
30482@@ -2326,7 +2326,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30483 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30484 int pipe;
30485
30486- atomic_set(&dev_priv->irq_received, 0);
30487+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30488
30489 if (I915_HAS_HOTPLUG(dev)) {
30490 I915_WRITE(PORT_HOTPLUG_EN, 0);
30491@@ -2436,7 +2436,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30492 int irq_received;
30493 int ret = IRQ_NONE, pipe;
30494
30495- atomic_inc(&dev_priv->irq_received);
30496+ atomic_inc_unchecked(&dev_priv->irq_received);
30497
30498 iir = I915_READ(IIR);
30499
30500diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30501index a8538ac..4868a05 100644
30502--- a/drivers/gpu/drm/i915/intel_display.c
30503+++ b/drivers/gpu/drm/i915/intel_display.c
30504@@ -2000,7 +2000,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30505
30506 wait_event(dev_priv->pending_flip_queue,
30507 atomic_read(&dev_priv->mm.wedged) ||
30508- atomic_read(&obj->pending_flip) == 0);
30509+ atomic_read_unchecked(&obj->pending_flip) == 0);
30510
30511 /* Big Hammer, we also need to ensure that any pending
30512 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30513@@ -5925,9 +5925,8 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30514
30515 obj = work->old_fb_obj;
30516
30517- atomic_clear_mask(1 << intel_crtc->plane,
30518- &obj->pending_flip.counter);
30519- if (atomic_read(&obj->pending_flip) == 0)
30520+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30521+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
30522 wake_up(&dev_priv->pending_flip_queue);
30523
30524 schedule_work(&work->work);
30525@@ -6264,7 +6263,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30526 /* Block clients from rendering to the new back buffer until
30527 * the flip occurs and the object is no longer visible.
30528 */
30529- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30530+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30531
30532 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30533 if (ret)
30534@@ -6279,7 +6278,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30535 return 0;
30536
30537 cleanup_pending:
30538- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30539+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30540 drm_gem_object_unreference(&work->old_fb_obj->base);
30541 drm_gem_object_unreference(&obj->base);
30542 mutex_unlock(&dev->struct_mutex);
30543diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30544index 54558a0..2d97005 100644
30545--- a/drivers/gpu/drm/mga/mga_drv.h
30546+++ b/drivers/gpu/drm/mga/mga_drv.h
30547@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30548 u32 clear_cmd;
30549 u32 maccess;
30550
30551- atomic_t vbl_received; /**< Number of vblanks received. */
30552+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30553 wait_queue_head_t fence_queue;
30554- atomic_t last_fence_retired;
30555+ atomic_unchecked_t last_fence_retired;
30556 u32 next_fence_to_post;
30557
30558 unsigned int fb_cpp;
30559diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30560index 2581202..f230a8d9 100644
30561--- a/drivers/gpu/drm/mga/mga_irq.c
30562+++ b/drivers/gpu/drm/mga/mga_irq.c
30563@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30564 if (crtc != 0)
30565 return 0;
30566
30567- return atomic_read(&dev_priv->vbl_received);
30568+ return atomic_read_unchecked(&dev_priv->vbl_received);
30569 }
30570
30571
30572@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30573 /* VBLANK interrupt */
30574 if (status & MGA_VLINEPEN) {
30575 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30576- atomic_inc(&dev_priv->vbl_received);
30577+ atomic_inc_unchecked(&dev_priv->vbl_received);
30578 drm_handle_vblank(dev, 0);
30579 handled = 1;
30580 }
30581@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30582 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30583 MGA_WRITE(MGA_PRIMEND, prim_end);
30584
30585- atomic_inc(&dev_priv->last_fence_retired);
30586+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
30587 DRM_WAKEUP(&dev_priv->fence_queue);
30588 handled = 1;
30589 }
30590@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30591 * using fences.
30592 */
30593 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30594- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30595+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30596 - *sequence) <= (1 << 23)));
30597
30598 *sequence = cur_fence;
30599diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30600index 2f11e16..191267e 100644
30601--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30602+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30603@@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30604 struct bit_table {
30605 const char id;
30606 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30607-};
30608+} __no_const;
30609
30610 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30611
30612diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30613index 8613cb2..ea038e7 100644
30614--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30615+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30616@@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30617 u32 handle, u16 class);
30618 void (*set_tile_region)(struct drm_device *dev, int i);
30619 void (*tlb_flush)(struct drm_device *, int engine);
30620-};
30621+} __no_const;
30622
30623 struct nouveau_instmem_engine {
30624 void *priv;
30625@@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30626 struct nouveau_mc_engine {
30627 int (*init)(struct drm_device *dev);
30628 void (*takedown)(struct drm_device *dev);
30629-};
30630+} __no_const;
30631
30632 struct nouveau_timer_engine {
30633 int (*init)(struct drm_device *dev);
30634 void (*takedown)(struct drm_device *dev);
30635 uint64_t (*read)(struct drm_device *dev);
30636-};
30637+} __no_const;
30638
30639 struct nouveau_fb_engine {
30640 int num_tiles;
30641@@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30642 void (*put)(struct drm_device *, struct nouveau_mem **);
30643
30644 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30645-};
30646+} __no_const;
30647
30648 struct nouveau_engine {
30649 struct nouveau_instmem_engine instmem;
30650@@ -695,7 +695,7 @@ struct drm_nouveau_private {
30651 struct drm_global_reference mem_global_ref;
30652 struct ttm_bo_global_ref bo_global_ref;
30653 struct ttm_bo_device bdev;
30654- atomic_t validate_sequence;
30655+ atomic_unchecked_t validate_sequence;
30656 int (*move)(struct nouveau_channel *,
30657 struct ttm_buffer_object *,
30658 struct ttm_mem_reg *, struct ttm_mem_reg *);
30659diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30660index 30f5423..abca136 100644
30661--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30662+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30663@@ -319,7 +319,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30664 int trycnt = 0;
30665 int ret, i;
30666
30667- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30668+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30669 retry:
30670 if (++trycnt > 100000) {
30671 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30672diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30673index 19706f0..f257368 100644
30674--- a/drivers/gpu/drm/nouveau/nouveau_state.c
30675+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30676@@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30677 bool can_switch;
30678
30679 spin_lock(&dev->count_lock);
30680- can_switch = (dev->open_count == 0);
30681+ can_switch = (local_read(&dev->open_count) == 0);
30682 spin_unlock(&dev->count_lock);
30683 return can_switch;
30684 }
30685diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30686index a9514ea..369d511 100644
30687--- a/drivers/gpu/drm/nouveau/nv50_sor.c
30688+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30689@@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30690 }
30691
30692 if (nv_encoder->dcb->type == OUTPUT_DP) {
30693- struct dp_train_func func = {
30694+ static struct dp_train_func func = {
30695 .link_set = nv50_sor_dp_link_set,
30696 .train_set = nv50_sor_dp_train_set,
30697 .train_adj = nv50_sor_dp_train_adj
30698diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30699index c486d3c..3a7d6f4 100644
30700--- a/drivers/gpu/drm/nouveau/nvd0_display.c
30701+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30702@@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30703 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30704
30705 if (nv_encoder->dcb->type == OUTPUT_DP) {
30706- struct dp_train_func func = {
30707+ static struct dp_train_func func = {
30708 .link_set = nvd0_sor_dp_link_set,
30709 .train_set = nvd0_sor_dp_train_set,
30710 .train_adj = nvd0_sor_dp_train_adj
30711diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30712index bcac90b..53bfc76 100644
30713--- a/drivers/gpu/drm/r128/r128_cce.c
30714+++ b/drivers/gpu/drm/r128/r128_cce.c
30715@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30716
30717 /* GH: Simple idle check.
30718 */
30719- atomic_set(&dev_priv->idle_count, 0);
30720+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30721
30722 /* We don't support anything other than bus-mastering ring mode,
30723 * but the ring can be in either AGP or PCI space for the ring
30724diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30725index 930c71b..499aded 100644
30726--- a/drivers/gpu/drm/r128/r128_drv.h
30727+++ b/drivers/gpu/drm/r128/r128_drv.h
30728@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30729 int is_pci;
30730 unsigned long cce_buffers_offset;
30731
30732- atomic_t idle_count;
30733+ atomic_unchecked_t idle_count;
30734
30735 int page_flipping;
30736 int current_page;
30737 u32 crtc_offset;
30738 u32 crtc_offset_cntl;
30739
30740- atomic_t vbl_received;
30741+ atomic_unchecked_t vbl_received;
30742
30743 u32 color_fmt;
30744 unsigned int front_offset;
30745diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30746index 429d5a0..7e899ed 100644
30747--- a/drivers/gpu/drm/r128/r128_irq.c
30748+++ b/drivers/gpu/drm/r128/r128_irq.c
30749@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30750 if (crtc != 0)
30751 return 0;
30752
30753- return atomic_read(&dev_priv->vbl_received);
30754+ return atomic_read_unchecked(&dev_priv->vbl_received);
30755 }
30756
30757 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30758@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30759 /* VBLANK interrupt */
30760 if (status & R128_CRTC_VBLANK_INT) {
30761 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30762- atomic_inc(&dev_priv->vbl_received);
30763+ atomic_inc_unchecked(&dev_priv->vbl_received);
30764 drm_handle_vblank(dev, 0);
30765 return IRQ_HANDLED;
30766 }
30767diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30768index a9e33ce..09edd4b 100644
30769--- a/drivers/gpu/drm/r128/r128_state.c
30770+++ b/drivers/gpu/drm/r128/r128_state.c
30771@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30772
30773 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30774 {
30775- if (atomic_read(&dev_priv->idle_count) == 0)
30776+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30777 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30778 else
30779- atomic_set(&dev_priv->idle_count, 0);
30780+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30781 }
30782
30783 #endif
30784diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30785index 5a82b6b..9e69c73 100644
30786--- a/drivers/gpu/drm/radeon/mkregtable.c
30787+++ b/drivers/gpu/drm/radeon/mkregtable.c
30788@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30789 regex_t mask_rex;
30790 regmatch_t match[4];
30791 char buf[1024];
30792- size_t end;
30793+ long end;
30794 int len;
30795 int done = 0;
30796 int r;
30797 unsigned o;
30798 struct offset *offset;
30799 char last_reg_s[10];
30800- int last_reg;
30801+ unsigned long last_reg;
30802
30803 if (regcomp
30804 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30805diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30806index fefcca5..20a5b90 100644
30807--- a/drivers/gpu/drm/radeon/radeon.h
30808+++ b/drivers/gpu/drm/radeon/radeon.h
30809@@ -743,7 +743,7 @@ struct r600_blit_cp_primitives {
30810 int x2, int y2);
30811 void (*draw_auto)(struct radeon_device *rdev);
30812 void (*set_default_state)(struct radeon_device *rdev);
30813-};
30814+} __no_const;
30815
30816 struct r600_blit {
30817 struct radeon_bo *shader_obj;
30818@@ -1244,7 +1244,7 @@ struct radeon_asic {
30819 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30820 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30821 } pflip;
30822-};
30823+} __no_const;
30824
30825 /*
30826 * Asic structures
30827diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30828index 066c98b..96ab858 100644
30829--- a/drivers/gpu/drm/radeon/radeon_device.c
30830+++ b/drivers/gpu/drm/radeon/radeon_device.c
30831@@ -692,7 +692,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30832 bool can_switch;
30833
30834 spin_lock(&dev->count_lock);
30835- can_switch = (dev->open_count == 0);
30836+ can_switch = (local_read(&dev->open_count) == 0);
30837 spin_unlock(&dev->count_lock);
30838 return can_switch;
30839 }
30840diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30841index a1b59ca..86f2d44 100644
30842--- a/drivers/gpu/drm/radeon/radeon_drv.h
30843+++ b/drivers/gpu/drm/radeon/radeon_drv.h
30844@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30845
30846 /* SW interrupt */
30847 wait_queue_head_t swi_queue;
30848- atomic_t swi_emitted;
30849+ atomic_unchecked_t swi_emitted;
30850 int vblank_crtc;
30851 uint32_t irq_enable_reg;
30852 uint32_t r500_disp_irq_reg;
30853diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30854index 48b7cea..342236f 100644
30855--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30856+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30857@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30858 request = compat_alloc_user_space(sizeof(*request));
30859 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30860 || __put_user(req32.param, &request->param)
30861- || __put_user((void __user *)(unsigned long)req32.value,
30862+ || __put_user((unsigned long)req32.value,
30863 &request->value))
30864 return -EFAULT;
30865
30866diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30867index 00da384..32f972d 100644
30868--- a/drivers/gpu/drm/radeon/radeon_irq.c
30869+++ b/drivers/gpu/drm/radeon/radeon_irq.c
30870@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30871 unsigned int ret;
30872 RING_LOCALS;
30873
30874- atomic_inc(&dev_priv->swi_emitted);
30875- ret = atomic_read(&dev_priv->swi_emitted);
30876+ atomic_inc_unchecked(&dev_priv->swi_emitted);
30877+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30878
30879 BEGIN_RING(4);
30880 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30881@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30882 drm_radeon_private_t *dev_priv =
30883 (drm_radeon_private_t *) dev->dev_private;
30884
30885- atomic_set(&dev_priv->swi_emitted, 0);
30886+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30887 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30888
30889 dev->max_vblank_count = 0x001fffff;
30890diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30891index e8422ae..d22d4a8 100644
30892--- a/drivers/gpu/drm/radeon/radeon_state.c
30893+++ b/drivers/gpu/drm/radeon/radeon_state.c
30894@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30895 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30896 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30897
30898- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30899+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30900 sarea_priv->nbox * sizeof(depth_boxes[0])))
30901 return -EFAULT;
30902
30903@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30904 {
30905 drm_radeon_private_t *dev_priv = dev->dev_private;
30906 drm_radeon_getparam_t *param = data;
30907- int value;
30908+ int value = 0;
30909
30910 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30911
30912diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30913index c94a225..5795d34 100644
30914--- a/drivers/gpu/drm/radeon/radeon_ttm.c
30915+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30916@@ -852,8 +852,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30917 }
30918 if (unlikely(ttm_vm_ops == NULL)) {
30919 ttm_vm_ops = vma->vm_ops;
30920- radeon_ttm_vm_ops = *ttm_vm_ops;
30921- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30922+ pax_open_kernel();
30923+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30924+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30925+ pax_close_kernel();
30926 }
30927 vma->vm_ops = &radeon_ttm_vm_ops;
30928 return 0;
30929diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30930index 159b6a4..fa82487 100644
30931--- a/drivers/gpu/drm/radeon/rs690.c
30932+++ b/drivers/gpu/drm/radeon/rs690.c
30933@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30934 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30935 rdev->pm.sideport_bandwidth.full)
30936 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30937- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30938+ read_delay_latency.full = dfixed_const(800 * 1000);
30939 read_delay_latency.full = dfixed_div(read_delay_latency,
30940 rdev->pm.igp_sideport_mclk);
30941+ a.full = dfixed_const(370);
30942+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30943 } else {
30944 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30945 rdev->pm.k8_bandwidth.full)
30946diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30947index ebc6fac..a8313ed 100644
30948--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30949+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30950@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
30951 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30952 struct shrink_control *sc)
30953 {
30954- static atomic_t start_pool = ATOMIC_INIT(0);
30955+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30956 unsigned i;
30957- unsigned pool_offset = atomic_add_return(1, &start_pool);
30958+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30959 struct ttm_page_pool *pool;
30960 int shrink_pages = sc->nr_to_scan;
30961
30962diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30963index 88edacc..1e5412b 100644
30964--- a/drivers/gpu/drm/via/via_drv.h
30965+++ b/drivers/gpu/drm/via/via_drv.h
30966@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
30967 typedef uint32_t maskarray_t[5];
30968
30969 typedef struct drm_via_irq {
30970- atomic_t irq_received;
30971+ atomic_unchecked_t irq_received;
30972 uint32_t pending_mask;
30973 uint32_t enable_mask;
30974 wait_queue_head_t irq_queue;
30975@@ -75,7 +75,7 @@ typedef struct drm_via_private {
30976 struct timeval last_vblank;
30977 int last_vblank_valid;
30978 unsigned usec_per_vblank;
30979- atomic_t vbl_received;
30980+ atomic_unchecked_t vbl_received;
30981 drm_via_state_t hc_state;
30982 char pci_buf[VIA_PCI_BUF_SIZE];
30983 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
30984diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
30985index d391f48..10c8ca3 100644
30986--- a/drivers/gpu/drm/via/via_irq.c
30987+++ b/drivers/gpu/drm/via/via_irq.c
30988@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
30989 if (crtc != 0)
30990 return 0;
30991
30992- return atomic_read(&dev_priv->vbl_received);
30993+ return atomic_read_unchecked(&dev_priv->vbl_received);
30994 }
30995
30996 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30997@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30998
30999 status = VIA_READ(VIA_REG_INTERRUPT);
31000 if (status & VIA_IRQ_VBLANK_PENDING) {
31001- atomic_inc(&dev_priv->vbl_received);
31002- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31003+ atomic_inc_unchecked(&dev_priv->vbl_received);
31004+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31005 do_gettimeofday(&cur_vblank);
31006 if (dev_priv->last_vblank_valid) {
31007 dev_priv->usec_per_vblank =
31008@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31009 dev_priv->last_vblank = cur_vblank;
31010 dev_priv->last_vblank_valid = 1;
31011 }
31012- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31013+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31014 DRM_DEBUG("US per vblank is: %u\n",
31015 dev_priv->usec_per_vblank);
31016 }
31017@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31018
31019 for (i = 0; i < dev_priv->num_irqs; ++i) {
31020 if (status & cur_irq->pending_mask) {
31021- atomic_inc(&cur_irq->irq_received);
31022+ atomic_inc_unchecked(&cur_irq->irq_received);
31023 DRM_WAKEUP(&cur_irq->irq_queue);
31024 handled = 1;
31025 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31026@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31027 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31028 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31029 masks[irq][4]));
31030- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31031+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31032 } else {
31033 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31034 (((cur_irq_sequence =
31035- atomic_read(&cur_irq->irq_received)) -
31036+ atomic_read_unchecked(&cur_irq->irq_received)) -
31037 *sequence) <= (1 << 23)));
31038 }
31039 *sequence = cur_irq_sequence;
31040@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31041 }
31042
31043 for (i = 0; i < dev_priv->num_irqs; ++i) {
31044- atomic_set(&cur_irq->irq_received, 0);
31045+ atomic_set_unchecked(&cur_irq->irq_received, 0);
31046 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31047 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31048 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31049@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31050 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31051 case VIA_IRQ_RELATIVE:
31052 irqwait->request.sequence +=
31053- atomic_read(&cur_irq->irq_received);
31054+ atomic_read_unchecked(&cur_irq->irq_received);
31055 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31056 case VIA_IRQ_ABSOLUTE:
31057 break;
31058diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31059index d0f2c07..9ebd9c3 100644
31060--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31061+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31062@@ -263,7 +263,7 @@ struct vmw_private {
31063 * Fencing and IRQs.
31064 */
31065
31066- atomic_t marker_seq;
31067+ atomic_unchecked_t marker_seq;
31068 wait_queue_head_t fence_queue;
31069 wait_queue_head_t fifo_queue;
31070 int fence_queue_waiters; /* Protected by hw_mutex */
31071diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31072index a0c2f12..68ae6cb 100644
31073--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31074+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31075@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31076 (unsigned int) min,
31077 (unsigned int) fifo->capabilities);
31078
31079- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31080+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31081 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31082 vmw_marker_queue_init(&fifo->marker_queue);
31083 return vmw_fifo_send_fence(dev_priv, &dummy);
31084@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31085 if (reserveable)
31086 iowrite32(bytes, fifo_mem +
31087 SVGA_FIFO_RESERVED);
31088- return fifo_mem + (next_cmd >> 2);
31089+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31090 } else {
31091 need_bounce = true;
31092 }
31093@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31094
31095 fm = vmw_fifo_reserve(dev_priv, bytes);
31096 if (unlikely(fm == NULL)) {
31097- *seqno = atomic_read(&dev_priv->marker_seq);
31098+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31099 ret = -ENOMEM;
31100 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31101 false, 3*HZ);
31102@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31103 }
31104
31105 do {
31106- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31107+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31108 } while (*seqno == 0);
31109
31110 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31111diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31112index cabc95f..14b3d77 100644
31113--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31114+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31115@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31116 * emitted. Then the fence is stale and signaled.
31117 */
31118
31119- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31120+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31121 > VMW_FENCE_WRAP);
31122
31123 return ret;
31124@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31125
31126 if (fifo_idle)
31127 down_read(&fifo_state->rwsem);
31128- signal_seq = atomic_read(&dev_priv->marker_seq);
31129+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31130 ret = 0;
31131
31132 for (;;) {
31133diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31134index 8a8725c..afed796 100644
31135--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31136+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31137@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31138 while (!vmw_lag_lt(queue, us)) {
31139 spin_lock(&queue->lock);
31140 if (list_empty(&queue->head))
31141- seqno = atomic_read(&dev_priv->marker_seq);
31142+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31143 else {
31144 marker = list_first_entry(&queue->head,
31145 struct vmw_marker, head);
31146diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31147index 4c87276..9ecc3c7 100644
31148--- a/drivers/hid/hid-core.c
31149+++ b/drivers/hid/hid-core.c
31150@@ -2151,7 +2151,7 @@ static bool hid_ignore(struct hid_device *hdev)
31151
31152 int hid_add_device(struct hid_device *hdev)
31153 {
31154- static atomic_t id = ATOMIC_INIT(0);
31155+ static atomic_unchecked_t id = ATOMIC_INIT(0);
31156 int ret;
31157
31158 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31159@@ -2186,7 +2186,7 @@ int hid_add_device(struct hid_device *hdev)
31160 /* XXX hack, any other cleaner solution after the driver core
31161 * is converted to allow more than 20 bytes as the device name? */
31162 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31163- hdev->vendor, hdev->product, atomic_inc_return(&id));
31164+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31165
31166 hid_debug_register(hdev, dev_name(&hdev->dev));
31167 ret = device_add(&hdev->dev);
31168diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31169index eec3291..8ed706b 100644
31170--- a/drivers/hid/hid-wiimote-debug.c
31171+++ b/drivers/hid/hid-wiimote-debug.c
31172@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31173 else if (size == 0)
31174 return -EIO;
31175
31176- if (copy_to_user(u, buf, size))
31177+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
31178 return -EFAULT;
31179
31180 *off += size;
31181diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31182index 14599e2..711c965 100644
31183--- a/drivers/hid/usbhid/hiddev.c
31184+++ b/drivers/hid/usbhid/hiddev.c
31185@@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31186 break;
31187
31188 case HIDIOCAPPLICATION:
31189- if (arg < 0 || arg >= hid->maxapplication)
31190+ if (arg >= hid->maxapplication)
31191 break;
31192
31193 for (i = 0; i < hid->maxcollection; i++)
31194diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31195index 4065374..10ed7dc 100644
31196--- a/drivers/hv/channel.c
31197+++ b/drivers/hv/channel.c
31198@@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31199 int ret = 0;
31200 int t;
31201
31202- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31203- atomic_inc(&vmbus_connection.next_gpadl_handle);
31204+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31205+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31206
31207 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31208 if (ret)
31209diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31210index 86f8885..ab9cb2b 100644
31211--- a/drivers/hv/hv.c
31212+++ b/drivers/hv/hv.c
31213@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31214 u64 output_address = (output) ? virt_to_phys(output) : 0;
31215 u32 output_address_hi = output_address >> 32;
31216 u32 output_address_lo = output_address & 0xFFFFFFFF;
31217- void *hypercall_page = hv_context.hypercall_page;
31218+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31219
31220 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31221 "=a"(hv_status_lo) : "d" (control_hi),
31222diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31223index b9426a6..677ce34 100644
31224--- a/drivers/hv/hyperv_vmbus.h
31225+++ b/drivers/hv/hyperv_vmbus.h
31226@@ -555,7 +555,7 @@ enum vmbus_connect_state {
31227 struct vmbus_connection {
31228 enum vmbus_connect_state conn_state;
31229
31230- atomic_t next_gpadl_handle;
31231+ atomic_unchecked_t next_gpadl_handle;
31232
31233 /*
31234 * Represents channel interrupts. Each bit position represents a
31235diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31236index a220e57..428f54d 100644
31237--- a/drivers/hv/vmbus_drv.c
31238+++ b/drivers/hv/vmbus_drv.c
31239@@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31240 {
31241 int ret = 0;
31242
31243- static atomic_t device_num = ATOMIC_INIT(0);
31244+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31245
31246 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31247- atomic_inc_return(&device_num));
31248+ atomic_inc_return_unchecked(&device_num));
31249
31250 child_device_obj->device.bus = &hv_bus;
31251 child_device_obj->device.parent = &hv_acpi_dev->dev;
31252diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31253index 34ad5a2..e2b0ae8 100644
31254--- a/drivers/hwmon/acpi_power_meter.c
31255+++ b/drivers/hwmon/acpi_power_meter.c
31256@@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31257 return res;
31258
31259 temp /= 1000;
31260- if (temp < 0)
31261- return -EINVAL;
31262
31263 mutex_lock(&resource->lock);
31264 resource->trip[attr->index - 7] = temp;
31265diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31266index 8b011d0..3de24a1 100644
31267--- a/drivers/hwmon/sht15.c
31268+++ b/drivers/hwmon/sht15.c
31269@@ -166,7 +166,7 @@ struct sht15_data {
31270 int supply_uV;
31271 bool supply_uV_valid;
31272 struct work_struct update_supply_work;
31273- atomic_t interrupt_handled;
31274+ atomic_unchecked_t interrupt_handled;
31275 };
31276
31277 /**
31278@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31279 return ret;
31280
31281 gpio_direction_input(data->pdata->gpio_data);
31282- atomic_set(&data->interrupt_handled, 0);
31283+ atomic_set_unchecked(&data->interrupt_handled, 0);
31284
31285 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31286 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31287 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31288 /* Only relevant if the interrupt hasn't occurred. */
31289- if (!atomic_read(&data->interrupt_handled))
31290+ if (!atomic_read_unchecked(&data->interrupt_handled))
31291 schedule_work(&data->read_work);
31292 }
31293 ret = wait_event_timeout(data->wait_queue,
31294@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31295
31296 /* First disable the interrupt */
31297 disable_irq_nosync(irq);
31298- atomic_inc(&data->interrupt_handled);
31299+ atomic_inc_unchecked(&data->interrupt_handled);
31300 /* Then schedule a reading work struct */
31301 if (data->state != SHT15_READING_NOTHING)
31302 schedule_work(&data->read_work);
31303@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31304 * If not, then start the interrupt again - care here as could
31305 * have gone low in meantime so verify it hasn't!
31306 */
31307- atomic_set(&data->interrupt_handled, 0);
31308+ atomic_set_unchecked(&data->interrupt_handled, 0);
31309 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31310 /* If still not occurred or another handler was scheduled */
31311 if (gpio_get_value(data->pdata->gpio_data)
31312- || atomic_read(&data->interrupt_handled))
31313+ || atomic_read_unchecked(&data->interrupt_handled))
31314 return;
31315 }
31316
31317diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31318index 378fcb5..5e91fa8 100644
31319--- a/drivers/i2c/busses/i2c-amd756-s4882.c
31320+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31321@@ -43,7 +43,7 @@
31322 extern struct i2c_adapter amd756_smbus;
31323
31324 static struct i2c_adapter *s4882_adapter;
31325-static struct i2c_algorithm *s4882_algo;
31326+static i2c_algorithm_no_const *s4882_algo;
31327
31328 /* Wrapper access functions for multiplexed SMBus */
31329 static DEFINE_MUTEX(amd756_lock);
31330diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31331index 29015eb..af2d8e9 100644
31332--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31333+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31334@@ -41,7 +41,7 @@
31335 extern struct i2c_adapter *nforce2_smbus;
31336
31337 static struct i2c_adapter *s4985_adapter;
31338-static struct i2c_algorithm *s4985_algo;
31339+static i2c_algorithm_no_const *s4985_algo;
31340
31341 /* Wrapper access functions for multiplexed SMBus */
31342 static DEFINE_MUTEX(nforce2_lock);
31343diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31344index 1038c38..eb92f51 100644
31345--- a/drivers/i2c/i2c-mux.c
31346+++ b/drivers/i2c/i2c-mux.c
31347@@ -30,7 +30,7 @@
31348 /* multiplexer per channel data */
31349 struct i2c_mux_priv {
31350 struct i2c_adapter adap;
31351- struct i2c_algorithm algo;
31352+ i2c_algorithm_no_const algo;
31353
31354 struct i2c_adapter *parent;
31355 void *mux_priv; /* the mux chip/device */
31356diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31357index 57d00ca..0145194 100644
31358--- a/drivers/ide/aec62xx.c
31359+++ b/drivers/ide/aec62xx.c
31360@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31361 .cable_detect = atp86x_cable_detect,
31362 };
31363
31364-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31365+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31366 { /* 0: AEC6210 */
31367 .name = DRV_NAME,
31368 .init_chipset = init_chipset_aec62xx,
31369diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31370index 2c8016a..911a27c 100644
31371--- a/drivers/ide/alim15x3.c
31372+++ b/drivers/ide/alim15x3.c
31373@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31374 .dma_sff_read_status = ide_dma_sff_read_status,
31375 };
31376
31377-static const struct ide_port_info ali15x3_chipset __devinitdata = {
31378+static const struct ide_port_info ali15x3_chipset __devinitconst = {
31379 .name = DRV_NAME,
31380 .init_chipset = init_chipset_ali15x3,
31381 .init_hwif = init_hwif_ali15x3,
31382diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31383index 3747b25..56fc995 100644
31384--- a/drivers/ide/amd74xx.c
31385+++ b/drivers/ide/amd74xx.c
31386@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31387 .udma_mask = udma, \
31388 }
31389
31390-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31391+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31392 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31393 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31394 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31395diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31396index 15f0ead..cb43480 100644
31397--- a/drivers/ide/atiixp.c
31398+++ b/drivers/ide/atiixp.c
31399@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31400 .cable_detect = atiixp_cable_detect,
31401 };
31402
31403-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31404+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31405 { /* 0: IXP200/300/400/700 */
31406 .name = DRV_NAME,
31407 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31408diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31409index 5f80312..d1fc438 100644
31410--- a/drivers/ide/cmd64x.c
31411+++ b/drivers/ide/cmd64x.c
31412@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31413 .dma_sff_read_status = ide_dma_sff_read_status,
31414 };
31415
31416-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31417+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31418 { /* 0: CMD643 */
31419 .name = DRV_NAME,
31420 .init_chipset = init_chipset_cmd64x,
31421diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31422index 2c1e5f7..1444762 100644
31423--- a/drivers/ide/cs5520.c
31424+++ b/drivers/ide/cs5520.c
31425@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31426 .set_dma_mode = cs5520_set_dma_mode,
31427 };
31428
31429-static const struct ide_port_info cyrix_chipset __devinitdata = {
31430+static const struct ide_port_info cyrix_chipset __devinitconst = {
31431 .name = DRV_NAME,
31432 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31433 .port_ops = &cs5520_port_ops,
31434diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31435index 4dc4eb9..49b40ad 100644
31436--- a/drivers/ide/cs5530.c
31437+++ b/drivers/ide/cs5530.c
31438@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31439 .udma_filter = cs5530_udma_filter,
31440 };
31441
31442-static const struct ide_port_info cs5530_chipset __devinitdata = {
31443+static const struct ide_port_info cs5530_chipset __devinitconst = {
31444 .name = DRV_NAME,
31445 .init_chipset = init_chipset_cs5530,
31446 .init_hwif = init_hwif_cs5530,
31447diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31448index 5059faf..18d4c85 100644
31449--- a/drivers/ide/cs5535.c
31450+++ b/drivers/ide/cs5535.c
31451@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31452 .cable_detect = cs5535_cable_detect,
31453 };
31454
31455-static const struct ide_port_info cs5535_chipset __devinitdata = {
31456+static const struct ide_port_info cs5535_chipset __devinitconst = {
31457 .name = DRV_NAME,
31458 .port_ops = &cs5535_port_ops,
31459 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31460diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31461index 847553f..3ffb49d 100644
31462--- a/drivers/ide/cy82c693.c
31463+++ b/drivers/ide/cy82c693.c
31464@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31465 .set_dma_mode = cy82c693_set_dma_mode,
31466 };
31467
31468-static const struct ide_port_info cy82c693_chipset __devinitdata = {
31469+static const struct ide_port_info cy82c693_chipset __devinitconst = {
31470 .name = DRV_NAME,
31471 .init_iops = init_iops_cy82c693,
31472 .port_ops = &cy82c693_port_ops,
31473diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31474index 58c51cd..4aec3b8 100644
31475--- a/drivers/ide/hpt366.c
31476+++ b/drivers/ide/hpt366.c
31477@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31478 }
31479 };
31480
31481-static const struct hpt_info hpt36x __devinitdata = {
31482+static const struct hpt_info hpt36x __devinitconst = {
31483 .chip_name = "HPT36x",
31484 .chip_type = HPT36x,
31485 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31486@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31487 .timings = &hpt36x_timings
31488 };
31489
31490-static const struct hpt_info hpt370 __devinitdata = {
31491+static const struct hpt_info hpt370 __devinitconst = {
31492 .chip_name = "HPT370",
31493 .chip_type = HPT370,
31494 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31495@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31496 .timings = &hpt37x_timings
31497 };
31498
31499-static const struct hpt_info hpt370a __devinitdata = {
31500+static const struct hpt_info hpt370a __devinitconst = {
31501 .chip_name = "HPT370A",
31502 .chip_type = HPT370A,
31503 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31504@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31505 .timings = &hpt37x_timings
31506 };
31507
31508-static const struct hpt_info hpt374 __devinitdata = {
31509+static const struct hpt_info hpt374 __devinitconst = {
31510 .chip_name = "HPT374",
31511 .chip_type = HPT374,
31512 .udma_mask = ATA_UDMA5,
31513@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31514 .timings = &hpt37x_timings
31515 };
31516
31517-static const struct hpt_info hpt372 __devinitdata = {
31518+static const struct hpt_info hpt372 __devinitconst = {
31519 .chip_name = "HPT372",
31520 .chip_type = HPT372,
31521 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31522@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31523 .timings = &hpt37x_timings
31524 };
31525
31526-static const struct hpt_info hpt372a __devinitdata = {
31527+static const struct hpt_info hpt372a __devinitconst = {
31528 .chip_name = "HPT372A",
31529 .chip_type = HPT372A,
31530 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31531@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31532 .timings = &hpt37x_timings
31533 };
31534
31535-static const struct hpt_info hpt302 __devinitdata = {
31536+static const struct hpt_info hpt302 __devinitconst = {
31537 .chip_name = "HPT302",
31538 .chip_type = HPT302,
31539 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31540@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31541 .timings = &hpt37x_timings
31542 };
31543
31544-static const struct hpt_info hpt371 __devinitdata = {
31545+static const struct hpt_info hpt371 __devinitconst = {
31546 .chip_name = "HPT371",
31547 .chip_type = HPT371,
31548 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31549@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31550 .timings = &hpt37x_timings
31551 };
31552
31553-static const struct hpt_info hpt372n __devinitdata = {
31554+static const struct hpt_info hpt372n __devinitconst = {
31555 .chip_name = "HPT372N",
31556 .chip_type = HPT372N,
31557 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31558@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31559 .timings = &hpt37x_timings
31560 };
31561
31562-static const struct hpt_info hpt302n __devinitdata = {
31563+static const struct hpt_info hpt302n __devinitconst = {
31564 .chip_name = "HPT302N",
31565 .chip_type = HPT302N,
31566 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31567@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31568 .timings = &hpt37x_timings
31569 };
31570
31571-static const struct hpt_info hpt371n __devinitdata = {
31572+static const struct hpt_info hpt371n __devinitconst = {
31573 .chip_name = "HPT371N",
31574 .chip_type = HPT371N,
31575 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31576@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31577 .dma_sff_read_status = ide_dma_sff_read_status,
31578 };
31579
31580-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31581+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31582 { /* 0: HPT36x */
31583 .name = DRV_NAME,
31584 .init_chipset = init_chipset_hpt366,
31585diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31586index 8126824..55a2798 100644
31587--- a/drivers/ide/ide-cd.c
31588+++ b/drivers/ide/ide-cd.c
31589@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31590 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31591 if ((unsigned long)buf & alignment
31592 || blk_rq_bytes(rq) & q->dma_pad_mask
31593- || object_is_on_stack(buf))
31594+ || object_starts_on_stack(buf))
31595 drive->dma = 0;
31596 }
31597 }
31598diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31599index 7f56b73..dab5b67 100644
31600--- a/drivers/ide/ide-pci-generic.c
31601+++ b/drivers/ide/ide-pci-generic.c
31602@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31603 .udma_mask = ATA_UDMA6, \
31604 }
31605
31606-static const struct ide_port_info generic_chipsets[] __devinitdata = {
31607+static const struct ide_port_info generic_chipsets[] __devinitconst = {
31608 /* 0: Unknown */
31609 DECLARE_GENERIC_PCI_DEV(0),
31610
31611diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31612index 560e66d..d5dd180 100644
31613--- a/drivers/ide/it8172.c
31614+++ b/drivers/ide/it8172.c
31615@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31616 .set_dma_mode = it8172_set_dma_mode,
31617 };
31618
31619-static const struct ide_port_info it8172_port_info __devinitdata = {
31620+static const struct ide_port_info it8172_port_info __devinitconst = {
31621 .name = DRV_NAME,
31622 .port_ops = &it8172_port_ops,
31623 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31624diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31625index 46816ba..1847aeb 100644
31626--- a/drivers/ide/it8213.c
31627+++ b/drivers/ide/it8213.c
31628@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31629 .cable_detect = it8213_cable_detect,
31630 };
31631
31632-static const struct ide_port_info it8213_chipset __devinitdata = {
31633+static const struct ide_port_info it8213_chipset __devinitconst = {
31634 .name = DRV_NAME,
31635 .enablebits = { {0x41, 0x80, 0x80} },
31636 .port_ops = &it8213_port_ops,
31637diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31638index 2e3169f..c5611db 100644
31639--- a/drivers/ide/it821x.c
31640+++ b/drivers/ide/it821x.c
31641@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31642 .cable_detect = it821x_cable_detect,
31643 };
31644
31645-static const struct ide_port_info it821x_chipset __devinitdata = {
31646+static const struct ide_port_info it821x_chipset __devinitconst = {
31647 .name = DRV_NAME,
31648 .init_chipset = init_chipset_it821x,
31649 .init_hwif = init_hwif_it821x,
31650diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31651index 74c2c4a..efddd7d 100644
31652--- a/drivers/ide/jmicron.c
31653+++ b/drivers/ide/jmicron.c
31654@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31655 .cable_detect = jmicron_cable_detect,
31656 };
31657
31658-static const struct ide_port_info jmicron_chipset __devinitdata = {
31659+static const struct ide_port_info jmicron_chipset __devinitconst = {
31660 .name = DRV_NAME,
31661 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31662 .port_ops = &jmicron_port_ops,
31663diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31664index 95327a2..73f78d8 100644
31665--- a/drivers/ide/ns87415.c
31666+++ b/drivers/ide/ns87415.c
31667@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31668 .dma_sff_read_status = superio_dma_sff_read_status,
31669 };
31670
31671-static const struct ide_port_info ns87415_chipset __devinitdata = {
31672+static const struct ide_port_info ns87415_chipset __devinitconst = {
31673 .name = DRV_NAME,
31674 .init_hwif = init_hwif_ns87415,
31675 .tp_ops = &ns87415_tp_ops,
31676diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31677index 1a53a4c..39edc66 100644
31678--- a/drivers/ide/opti621.c
31679+++ b/drivers/ide/opti621.c
31680@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31681 .set_pio_mode = opti621_set_pio_mode,
31682 };
31683
31684-static const struct ide_port_info opti621_chipset __devinitdata = {
31685+static const struct ide_port_info opti621_chipset __devinitconst = {
31686 .name = DRV_NAME,
31687 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31688 .port_ops = &opti621_port_ops,
31689diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31690index 9546fe2..2e5ceb6 100644
31691--- a/drivers/ide/pdc202xx_new.c
31692+++ b/drivers/ide/pdc202xx_new.c
31693@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31694 .udma_mask = udma, \
31695 }
31696
31697-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31698+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31699 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31700 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31701 };
31702diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31703index 3a35ec6..5634510 100644
31704--- a/drivers/ide/pdc202xx_old.c
31705+++ b/drivers/ide/pdc202xx_old.c
31706@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31707 .max_sectors = sectors, \
31708 }
31709
31710-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31711+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31712 { /* 0: PDC20246 */
31713 .name = DRV_NAME,
31714 .init_chipset = init_chipset_pdc202xx,
31715diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31716index 1892e81..fe0fd60 100644
31717--- a/drivers/ide/piix.c
31718+++ b/drivers/ide/piix.c
31719@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31720 .udma_mask = udma, \
31721 }
31722
31723-static const struct ide_port_info piix_pci_info[] __devinitdata = {
31724+static const struct ide_port_info piix_pci_info[] __devinitconst = {
31725 /* 0: MPIIX */
31726 { /*
31727 * MPIIX actually has only a single IDE channel mapped to
31728diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31729index a6414a8..c04173e 100644
31730--- a/drivers/ide/rz1000.c
31731+++ b/drivers/ide/rz1000.c
31732@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31733 }
31734 }
31735
31736-static const struct ide_port_info rz1000_chipset __devinitdata = {
31737+static const struct ide_port_info rz1000_chipset __devinitconst = {
31738 .name = DRV_NAME,
31739 .host_flags = IDE_HFLAG_NO_DMA,
31740 };
31741diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31742index 356b9b5..d4758eb 100644
31743--- a/drivers/ide/sc1200.c
31744+++ b/drivers/ide/sc1200.c
31745@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31746 .dma_sff_read_status = ide_dma_sff_read_status,
31747 };
31748
31749-static const struct ide_port_info sc1200_chipset __devinitdata = {
31750+static const struct ide_port_info sc1200_chipset __devinitconst = {
31751 .name = DRV_NAME,
31752 .port_ops = &sc1200_port_ops,
31753 .dma_ops = &sc1200_dma_ops,
31754diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31755index b7f5b0c..9701038 100644
31756--- a/drivers/ide/scc_pata.c
31757+++ b/drivers/ide/scc_pata.c
31758@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31759 .dma_sff_read_status = scc_dma_sff_read_status,
31760 };
31761
31762-static const struct ide_port_info scc_chipset __devinitdata = {
31763+static const struct ide_port_info scc_chipset __devinitconst = {
31764 .name = "sccIDE",
31765 .init_iops = init_iops_scc,
31766 .init_dma = scc_init_dma,
31767diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31768index 35fb8da..24d72ef 100644
31769--- a/drivers/ide/serverworks.c
31770+++ b/drivers/ide/serverworks.c
31771@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31772 .cable_detect = svwks_cable_detect,
31773 };
31774
31775-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31776+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31777 { /* 0: OSB4 */
31778 .name = DRV_NAME,
31779 .init_chipset = init_chipset_svwks,
31780diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31781index ddeda44..46f7e30 100644
31782--- a/drivers/ide/siimage.c
31783+++ b/drivers/ide/siimage.c
31784@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31785 .udma_mask = ATA_UDMA6, \
31786 }
31787
31788-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31789+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31790 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31791 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31792 };
31793diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31794index 4a00225..09e61b4 100644
31795--- a/drivers/ide/sis5513.c
31796+++ b/drivers/ide/sis5513.c
31797@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31798 .cable_detect = sis_cable_detect,
31799 };
31800
31801-static const struct ide_port_info sis5513_chipset __devinitdata = {
31802+static const struct ide_port_info sis5513_chipset __devinitconst = {
31803 .name = DRV_NAME,
31804 .init_chipset = init_chipset_sis5513,
31805 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31806diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31807index f21dc2a..d051cd2 100644
31808--- a/drivers/ide/sl82c105.c
31809+++ b/drivers/ide/sl82c105.c
31810@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31811 .dma_sff_read_status = ide_dma_sff_read_status,
31812 };
31813
31814-static const struct ide_port_info sl82c105_chipset __devinitdata = {
31815+static const struct ide_port_info sl82c105_chipset __devinitconst = {
31816 .name = DRV_NAME,
31817 .init_chipset = init_chipset_sl82c105,
31818 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31819diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31820index 864ffe0..863a5e9 100644
31821--- a/drivers/ide/slc90e66.c
31822+++ b/drivers/ide/slc90e66.c
31823@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31824 .cable_detect = slc90e66_cable_detect,
31825 };
31826
31827-static const struct ide_port_info slc90e66_chipset __devinitdata = {
31828+static const struct ide_port_info slc90e66_chipset __devinitconst = {
31829 .name = DRV_NAME,
31830 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31831 .port_ops = &slc90e66_port_ops,
31832diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31833index 4799d5c..1794678 100644
31834--- a/drivers/ide/tc86c001.c
31835+++ b/drivers/ide/tc86c001.c
31836@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31837 .dma_sff_read_status = ide_dma_sff_read_status,
31838 };
31839
31840-static const struct ide_port_info tc86c001_chipset __devinitdata = {
31841+static const struct ide_port_info tc86c001_chipset __devinitconst = {
31842 .name = DRV_NAME,
31843 .init_hwif = init_hwif_tc86c001,
31844 .port_ops = &tc86c001_port_ops,
31845diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31846index 281c914..55ce1b8 100644
31847--- a/drivers/ide/triflex.c
31848+++ b/drivers/ide/triflex.c
31849@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31850 .set_dma_mode = triflex_set_mode,
31851 };
31852
31853-static const struct ide_port_info triflex_device __devinitdata = {
31854+static const struct ide_port_info triflex_device __devinitconst = {
31855 .name = DRV_NAME,
31856 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31857 .port_ops = &triflex_port_ops,
31858diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31859index 4b42ca0..e494a98 100644
31860--- a/drivers/ide/trm290.c
31861+++ b/drivers/ide/trm290.c
31862@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31863 .dma_check = trm290_dma_check,
31864 };
31865
31866-static const struct ide_port_info trm290_chipset __devinitdata = {
31867+static const struct ide_port_info trm290_chipset __devinitconst = {
31868 .name = DRV_NAME,
31869 .init_hwif = init_hwif_trm290,
31870 .tp_ops = &trm290_tp_ops,
31871diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31872index f46f49c..eb77678 100644
31873--- a/drivers/ide/via82cxxx.c
31874+++ b/drivers/ide/via82cxxx.c
31875@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31876 .cable_detect = via82cxxx_cable_detect,
31877 };
31878
31879-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31880+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31881 .name = DRV_NAME,
31882 .init_chipset = init_chipset_via82cxxx,
31883 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31884diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31885index 73d4531..c90cd2d 100644
31886--- a/drivers/ieee802154/fakehard.c
31887+++ b/drivers/ieee802154/fakehard.c
31888@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31889 phy->transmit_power = 0xbf;
31890
31891 dev->netdev_ops = &fake_ops;
31892- dev->ml_priv = &fake_mlme;
31893+ dev->ml_priv = (void *)&fake_mlme;
31894
31895 priv = netdev_priv(dev);
31896 priv->phy = phy;
31897diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31898index c889aae..6cf5aa7 100644
31899--- a/drivers/infiniband/core/cm.c
31900+++ b/drivers/infiniband/core/cm.c
31901@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31902
31903 struct cm_counter_group {
31904 struct kobject obj;
31905- atomic_long_t counter[CM_ATTR_COUNT];
31906+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31907 };
31908
31909 struct cm_counter_attribute {
31910@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31911 struct ib_mad_send_buf *msg = NULL;
31912 int ret;
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_REQ_COUNTER]);
31917
31918 /* Quick state check to discard duplicate REQs. */
31919@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31920 if (!cm_id_priv)
31921 return;
31922
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_REP_COUNTER]);
31926 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31927 if (ret)
31928@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31929 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31930 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31931 spin_unlock_irq(&cm_id_priv->lock);
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_RTU_COUNTER]);
31935 goto out;
31936 }
31937@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31938 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31939 dreq_msg->local_comm_id);
31940 if (!cm_id_priv) {
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 cm_issue_drep(work->port, work->mad_recv_wc);
31945 return -EINVAL;
31946@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31947 case IB_CM_MRA_REP_RCVD:
31948 break;
31949 case IB_CM_TIMEWAIT:
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 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31954 goto unlock;
31955@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31956 cm_free_msg(msg);
31957 goto deref;
31958 case IB_CM_DREQ_RCVD:
31959- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31960+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31961 counter[CM_DREQ_COUNTER]);
31962 goto unlock;
31963 default:
31964@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31965 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31966 cm_id_priv->msg, timeout)) {
31967 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
31968- atomic_long_inc(&work->port->
31969+ atomic_long_inc_unchecked(&work->port->
31970 counter_group[CM_RECV_DUPLICATES].
31971 counter[CM_MRA_COUNTER]);
31972 goto out;
31973@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
31974 break;
31975 case IB_CM_MRA_REQ_RCVD:
31976 case IB_CM_MRA_REP_RCVD:
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_MRA_COUNTER]);
31980 /* fall through */
31981 default:
31982@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
31983 case IB_CM_LAP_IDLE:
31984 break;
31985 case IB_CM_MRA_LAP_SENT:
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 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31990 goto unlock;
31991@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
31992 cm_free_msg(msg);
31993 goto deref;
31994 case IB_CM_LAP_RCVD:
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_LAP_COUNTER]);
31998 goto unlock;
31999 default:
32000@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32001 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32002 if (cur_cm_id_priv) {
32003 spin_unlock_irq(&cm.lock);
32004- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32005+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32006 counter[CM_SIDR_REQ_COUNTER]);
32007 goto out; /* Duplicate message. */
32008 }
32009@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32010 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32011 msg->retries = 1;
32012
32013- atomic_long_add(1 + msg->retries,
32014+ atomic_long_add_unchecked(1 + msg->retries,
32015 &port->counter_group[CM_XMIT].counter[attr_index]);
32016 if (msg->retries)
32017- atomic_long_add(msg->retries,
32018+ atomic_long_add_unchecked(msg->retries,
32019 &port->counter_group[CM_XMIT_RETRIES].
32020 counter[attr_index]);
32021
32022@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32023 }
32024
32025 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32026- atomic_long_inc(&port->counter_group[CM_RECV].
32027+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32028 counter[attr_id - CM_ATTR_ID_OFFSET]);
32029
32030 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32031@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32032 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32033
32034 return sprintf(buf, "%ld\n",
32035- atomic_long_read(&group->counter[cm_attr->index]));
32036+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32037 }
32038
32039 static const struct sysfs_ops cm_counter_ops = {
32040diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32041index 176c8f9..2627b62 100644
32042--- a/drivers/infiniband/core/fmr_pool.c
32043+++ b/drivers/infiniband/core/fmr_pool.c
32044@@ -98,8 +98,8 @@ struct ib_fmr_pool {
32045
32046 struct task_struct *thread;
32047
32048- atomic_t req_ser;
32049- atomic_t flush_ser;
32050+ atomic_unchecked_t req_ser;
32051+ atomic_unchecked_t flush_ser;
32052
32053 wait_queue_head_t force_wait;
32054 };
32055@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32056 struct ib_fmr_pool *pool = pool_ptr;
32057
32058 do {
32059- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32060+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32061 ib_fmr_batch_release(pool);
32062
32063- atomic_inc(&pool->flush_ser);
32064+ atomic_inc_unchecked(&pool->flush_ser);
32065 wake_up_interruptible(&pool->force_wait);
32066
32067 if (pool->flush_function)
32068@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32069 }
32070
32071 set_current_state(TASK_INTERRUPTIBLE);
32072- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32073+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32074 !kthread_should_stop())
32075 schedule();
32076 __set_current_state(TASK_RUNNING);
32077@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32078 pool->dirty_watermark = params->dirty_watermark;
32079 pool->dirty_len = 0;
32080 spin_lock_init(&pool->pool_lock);
32081- atomic_set(&pool->req_ser, 0);
32082- atomic_set(&pool->flush_ser, 0);
32083+ atomic_set_unchecked(&pool->req_ser, 0);
32084+ atomic_set_unchecked(&pool->flush_ser, 0);
32085 init_waitqueue_head(&pool->force_wait);
32086
32087 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32088@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32089 }
32090 spin_unlock_irq(&pool->pool_lock);
32091
32092- serial = atomic_inc_return(&pool->req_ser);
32093+ serial = atomic_inc_return_unchecked(&pool->req_ser);
32094 wake_up_process(pool->thread);
32095
32096 if (wait_event_interruptible(pool->force_wait,
32097- atomic_read(&pool->flush_ser) - serial >= 0))
32098+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32099 return -EINTR;
32100
32101 return 0;
32102@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32103 } else {
32104 list_add_tail(&fmr->list, &pool->dirty_list);
32105 if (++pool->dirty_len >= pool->dirty_watermark) {
32106- atomic_inc(&pool->req_ser);
32107+ atomic_inc_unchecked(&pool->req_ser);
32108 wake_up_process(pool->thread);
32109 }
32110 }
32111diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32112index 57e07c6..56d09d4 100644
32113--- a/drivers/infiniband/hw/cxgb4/mem.c
32114+++ b/drivers/infiniband/hw/cxgb4/mem.c
32115@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32116 int err;
32117 struct fw_ri_tpte tpt;
32118 u32 stag_idx;
32119- static atomic_t key;
32120+ static atomic_unchecked_t key;
32121
32122 if (c4iw_fatal_error(rdev))
32123 return -EIO;
32124@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32125 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32126 rdev->stats.stag.max = rdev->stats.stag.cur;
32127 mutex_unlock(&rdev->stats.lock);
32128- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32129+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32130 }
32131 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32132 __func__, stag_state, type, pdid, stag_idx);
32133diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32134index 79b3dbc..96e5fcc 100644
32135--- a/drivers/infiniband/hw/ipath/ipath_rc.c
32136+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32137@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32138 struct ib_atomic_eth *ateth;
32139 struct ipath_ack_entry *e;
32140 u64 vaddr;
32141- atomic64_t *maddr;
32142+ atomic64_unchecked_t *maddr;
32143 u64 sdata;
32144 u32 rkey;
32145 u8 next;
32146@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32147 IB_ACCESS_REMOTE_ATOMIC)))
32148 goto nack_acc_unlck;
32149 /* Perform atomic OP and save result. */
32150- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32151+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32152 sdata = be64_to_cpu(ateth->swap_data);
32153 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32154 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32155- (u64) atomic64_add_return(sdata, maddr) - sdata :
32156+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32157 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32158 be64_to_cpu(ateth->compare_data),
32159 sdata);
32160diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32161index 1f95bba..9530f87 100644
32162--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32163+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32164@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32165 unsigned long flags;
32166 struct ib_wc wc;
32167 u64 sdata;
32168- atomic64_t *maddr;
32169+ atomic64_unchecked_t *maddr;
32170 enum ib_wc_status send_status;
32171
32172 /*
32173@@ -382,11 +382,11 @@ again:
32174 IB_ACCESS_REMOTE_ATOMIC)))
32175 goto acc_err;
32176 /* Perform atomic OP and save result. */
32177- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32178+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32179 sdata = wqe->wr.wr.atomic.compare_add;
32180 *(u64 *) sqp->s_sge.sge.vaddr =
32181 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32182- (u64) atomic64_add_return(sdata, maddr) - sdata :
32183+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32184 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32185 sdata, wqe->wr.wr.atomic.swap);
32186 goto send_comp;
32187diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32188index 7140199..da60063 100644
32189--- a/drivers/infiniband/hw/nes/nes.c
32190+++ b/drivers/infiniband/hw/nes/nes.c
32191@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32192 LIST_HEAD(nes_adapter_list);
32193 static LIST_HEAD(nes_dev_list);
32194
32195-atomic_t qps_destroyed;
32196+atomic_unchecked_t qps_destroyed;
32197
32198 static unsigned int ee_flsh_adapter;
32199 static unsigned int sysfs_nonidx_addr;
32200@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32201 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32202 struct nes_adapter *nesadapter = nesdev->nesadapter;
32203
32204- atomic_inc(&qps_destroyed);
32205+ atomic_inc_unchecked(&qps_destroyed);
32206
32207 /* Free the control structures */
32208
32209diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32210index c438e46..ca30356 100644
32211--- a/drivers/infiniband/hw/nes/nes.h
32212+++ b/drivers/infiniband/hw/nes/nes.h
32213@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32214 extern unsigned int wqm_quanta;
32215 extern struct list_head nes_adapter_list;
32216
32217-extern atomic_t cm_connects;
32218-extern atomic_t cm_accepts;
32219-extern atomic_t cm_disconnects;
32220-extern atomic_t cm_closes;
32221-extern atomic_t cm_connecteds;
32222-extern atomic_t cm_connect_reqs;
32223-extern atomic_t cm_rejects;
32224-extern atomic_t mod_qp_timouts;
32225-extern atomic_t qps_created;
32226-extern atomic_t qps_destroyed;
32227-extern atomic_t sw_qps_destroyed;
32228+extern atomic_unchecked_t cm_connects;
32229+extern atomic_unchecked_t cm_accepts;
32230+extern atomic_unchecked_t cm_disconnects;
32231+extern atomic_unchecked_t cm_closes;
32232+extern atomic_unchecked_t cm_connecteds;
32233+extern atomic_unchecked_t cm_connect_reqs;
32234+extern atomic_unchecked_t cm_rejects;
32235+extern atomic_unchecked_t mod_qp_timouts;
32236+extern atomic_unchecked_t qps_created;
32237+extern atomic_unchecked_t qps_destroyed;
32238+extern atomic_unchecked_t sw_qps_destroyed;
32239 extern u32 mh_detected;
32240 extern u32 mh_pauses_sent;
32241 extern u32 cm_packets_sent;
32242@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32243 extern u32 cm_packets_received;
32244 extern u32 cm_packets_dropped;
32245 extern u32 cm_packets_retrans;
32246-extern atomic_t cm_listens_created;
32247-extern atomic_t cm_listens_destroyed;
32248+extern atomic_unchecked_t cm_listens_created;
32249+extern atomic_unchecked_t cm_listens_destroyed;
32250 extern u32 cm_backlog_drops;
32251-extern atomic_t cm_loopbacks;
32252-extern atomic_t cm_nodes_created;
32253-extern atomic_t cm_nodes_destroyed;
32254-extern atomic_t cm_accel_dropped_pkts;
32255-extern atomic_t cm_resets_recvd;
32256-extern atomic_t pau_qps_created;
32257-extern atomic_t pau_qps_destroyed;
32258+extern atomic_unchecked_t cm_loopbacks;
32259+extern atomic_unchecked_t cm_nodes_created;
32260+extern atomic_unchecked_t cm_nodes_destroyed;
32261+extern atomic_unchecked_t cm_accel_dropped_pkts;
32262+extern atomic_unchecked_t cm_resets_recvd;
32263+extern atomic_unchecked_t pau_qps_created;
32264+extern atomic_unchecked_t pau_qps_destroyed;
32265
32266 extern u32 int_mod_timer_init;
32267 extern u32 int_mod_cq_depth_256;
32268diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32269index 020e95c..fbb3450 100644
32270--- a/drivers/infiniband/hw/nes/nes_cm.c
32271+++ b/drivers/infiniband/hw/nes/nes_cm.c
32272@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32273 u32 cm_packets_retrans;
32274 u32 cm_packets_created;
32275 u32 cm_packets_received;
32276-atomic_t cm_listens_created;
32277-atomic_t cm_listens_destroyed;
32278+atomic_unchecked_t cm_listens_created;
32279+atomic_unchecked_t cm_listens_destroyed;
32280 u32 cm_backlog_drops;
32281-atomic_t cm_loopbacks;
32282-atomic_t cm_nodes_created;
32283-atomic_t cm_nodes_destroyed;
32284-atomic_t cm_accel_dropped_pkts;
32285-atomic_t cm_resets_recvd;
32286+atomic_unchecked_t cm_loopbacks;
32287+atomic_unchecked_t cm_nodes_created;
32288+atomic_unchecked_t cm_nodes_destroyed;
32289+atomic_unchecked_t cm_accel_dropped_pkts;
32290+atomic_unchecked_t cm_resets_recvd;
32291
32292 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32293 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32294@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32295
32296 static struct nes_cm_core *g_cm_core;
32297
32298-atomic_t cm_connects;
32299-atomic_t cm_accepts;
32300-atomic_t cm_disconnects;
32301-atomic_t cm_closes;
32302-atomic_t cm_connecteds;
32303-atomic_t cm_connect_reqs;
32304-atomic_t cm_rejects;
32305+atomic_unchecked_t cm_connects;
32306+atomic_unchecked_t cm_accepts;
32307+atomic_unchecked_t cm_disconnects;
32308+atomic_unchecked_t cm_closes;
32309+atomic_unchecked_t cm_connecteds;
32310+atomic_unchecked_t cm_connect_reqs;
32311+atomic_unchecked_t cm_rejects;
32312
32313 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32314 {
32315@@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32316 kfree(listener);
32317 listener = NULL;
32318 ret = 0;
32319- atomic_inc(&cm_listens_destroyed);
32320+ atomic_inc_unchecked(&cm_listens_destroyed);
32321 } else {
32322 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32323 }
32324@@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32325 cm_node->rem_mac);
32326
32327 add_hte_node(cm_core, cm_node);
32328- atomic_inc(&cm_nodes_created);
32329+ atomic_inc_unchecked(&cm_nodes_created);
32330
32331 return cm_node;
32332 }
32333@@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32334 }
32335
32336 atomic_dec(&cm_core->node_cnt);
32337- atomic_inc(&cm_nodes_destroyed);
32338+ atomic_inc_unchecked(&cm_nodes_destroyed);
32339 nesqp = cm_node->nesqp;
32340 if (nesqp) {
32341 nesqp->cm_node = NULL;
32342@@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32343
32344 static void drop_packet(struct sk_buff *skb)
32345 {
32346- atomic_inc(&cm_accel_dropped_pkts);
32347+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32348 dev_kfree_skb_any(skb);
32349 }
32350
32351@@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32352 {
32353
32354 int reset = 0; /* whether to send reset in case of err.. */
32355- atomic_inc(&cm_resets_recvd);
32356+ atomic_inc_unchecked(&cm_resets_recvd);
32357 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32358 " refcnt=%d\n", cm_node, cm_node->state,
32359 atomic_read(&cm_node->ref_count));
32360@@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32361 rem_ref_cm_node(cm_node->cm_core, cm_node);
32362 return NULL;
32363 }
32364- atomic_inc(&cm_loopbacks);
32365+ atomic_inc_unchecked(&cm_loopbacks);
32366 loopbackremotenode->loopbackpartner = cm_node;
32367 loopbackremotenode->tcp_cntxt.rcv_wscale =
32368 NES_CM_DEFAULT_RCV_WND_SCALE;
32369@@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32370 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32371 else {
32372 rem_ref_cm_node(cm_core, cm_node);
32373- atomic_inc(&cm_accel_dropped_pkts);
32374+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32375 dev_kfree_skb_any(skb);
32376 }
32377 break;
32378@@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32379
32380 if ((cm_id) && (cm_id->event_handler)) {
32381 if (issue_disconn) {
32382- atomic_inc(&cm_disconnects);
32383+ atomic_inc_unchecked(&cm_disconnects);
32384 cm_event.event = IW_CM_EVENT_DISCONNECT;
32385 cm_event.status = disconn_status;
32386 cm_event.local_addr = cm_id->local_addr;
32387@@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32388 }
32389
32390 if (issue_close) {
32391- atomic_inc(&cm_closes);
32392+ atomic_inc_unchecked(&cm_closes);
32393 nes_disconnect(nesqp, 1);
32394
32395 cm_id->provider_data = nesqp;
32396@@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32397
32398 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32399 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32400- atomic_inc(&cm_accepts);
32401+ atomic_inc_unchecked(&cm_accepts);
32402
32403 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32404 netdev_refcnt_read(nesvnic->netdev));
32405@@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32406 struct nes_cm_core *cm_core;
32407 u8 *start_buff;
32408
32409- atomic_inc(&cm_rejects);
32410+ atomic_inc_unchecked(&cm_rejects);
32411 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32412 loopback = cm_node->loopbackpartner;
32413 cm_core = cm_node->cm_core;
32414@@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32415 ntohl(cm_id->local_addr.sin_addr.s_addr),
32416 ntohs(cm_id->local_addr.sin_port));
32417
32418- atomic_inc(&cm_connects);
32419+ atomic_inc_unchecked(&cm_connects);
32420 nesqp->active_conn = 1;
32421
32422 /* cache the cm_id in the qp */
32423@@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32424 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32425 return err;
32426 }
32427- atomic_inc(&cm_listens_created);
32428+ atomic_inc_unchecked(&cm_listens_created);
32429 }
32430
32431 cm_id->add_ref(cm_id);
32432@@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32433
32434 if (nesqp->destroyed)
32435 return;
32436- atomic_inc(&cm_connecteds);
32437+ atomic_inc_unchecked(&cm_connecteds);
32438 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32439 " local port 0x%04X. jiffies = %lu.\n",
32440 nesqp->hwqp.qp_id,
32441@@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32442
32443 cm_id->add_ref(cm_id);
32444 ret = cm_id->event_handler(cm_id, &cm_event);
32445- atomic_inc(&cm_closes);
32446+ atomic_inc_unchecked(&cm_closes);
32447 cm_event.event = IW_CM_EVENT_CLOSE;
32448 cm_event.status = 0;
32449 cm_event.provider_data = cm_id->provider_data;
32450@@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(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
32459@@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32460 return;
32461 cm_id = cm_node->cm_id;
32462
32463- atomic_inc(&cm_connect_reqs);
32464+ atomic_inc_unchecked(&cm_connect_reqs);
32465 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32466 cm_node, cm_id, jiffies);
32467
32468diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32469index 3ba7be3..c81f6ff 100644
32470--- a/drivers/infiniband/hw/nes/nes_mgt.c
32471+++ b/drivers/infiniband/hw/nes/nes_mgt.c
32472@@ -40,8 +40,8 @@
32473 #include "nes.h"
32474 #include "nes_mgt.h"
32475
32476-atomic_t pau_qps_created;
32477-atomic_t pau_qps_destroyed;
32478+atomic_unchecked_t pau_qps_created;
32479+atomic_unchecked_t pau_qps_destroyed;
32480
32481 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32482 {
32483@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32484 {
32485 struct sk_buff *skb;
32486 unsigned long flags;
32487- atomic_inc(&pau_qps_destroyed);
32488+ atomic_inc_unchecked(&pau_qps_destroyed);
32489
32490 /* Free packets that have not yet been forwarded */
32491 /* Lock is acquired by skb_dequeue when removing the skb */
32492@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32493 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32494 skb_queue_head_init(&nesqp->pau_list);
32495 spin_lock_init(&nesqp->pau_lock);
32496- atomic_inc(&pau_qps_created);
32497+ atomic_inc_unchecked(&pau_qps_created);
32498 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32499 }
32500
32501diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32502index f3a3ecf..57d311d 100644
32503--- a/drivers/infiniband/hw/nes/nes_nic.c
32504+++ b/drivers/infiniband/hw/nes/nes_nic.c
32505@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32506 target_stat_values[++index] = mh_detected;
32507 target_stat_values[++index] = mh_pauses_sent;
32508 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32509- target_stat_values[++index] = atomic_read(&cm_connects);
32510- target_stat_values[++index] = atomic_read(&cm_accepts);
32511- target_stat_values[++index] = atomic_read(&cm_disconnects);
32512- target_stat_values[++index] = atomic_read(&cm_connecteds);
32513- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32514- target_stat_values[++index] = atomic_read(&cm_rejects);
32515- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32516- target_stat_values[++index] = atomic_read(&qps_created);
32517- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32518- target_stat_values[++index] = atomic_read(&qps_destroyed);
32519- target_stat_values[++index] = atomic_read(&cm_closes);
32520+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32521+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32522+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32523+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32524+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32525+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32526+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32527+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32528+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32529+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32530+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32531 target_stat_values[++index] = cm_packets_sent;
32532 target_stat_values[++index] = cm_packets_bounced;
32533 target_stat_values[++index] = cm_packets_created;
32534 target_stat_values[++index] = cm_packets_received;
32535 target_stat_values[++index] = cm_packets_dropped;
32536 target_stat_values[++index] = cm_packets_retrans;
32537- target_stat_values[++index] = atomic_read(&cm_listens_created);
32538- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32539+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32540+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32541 target_stat_values[++index] = cm_backlog_drops;
32542- target_stat_values[++index] = atomic_read(&cm_loopbacks);
32543- target_stat_values[++index] = atomic_read(&cm_nodes_created);
32544- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32545- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32546- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32547+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32548+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32549+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32550+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32551+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32552 target_stat_values[++index] = nesadapter->free_4kpbl;
32553 target_stat_values[++index] = nesadapter->free_256pbl;
32554 target_stat_values[++index] = int_mod_timer_init;
32555 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32556 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32557 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32558- target_stat_values[++index] = atomic_read(&pau_qps_created);
32559- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32560+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32561+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32562 }
32563
32564 /**
32565diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32566index 8b8812d..a5e1133 100644
32567--- a/drivers/infiniband/hw/nes/nes_verbs.c
32568+++ b/drivers/infiniband/hw/nes/nes_verbs.c
32569@@ -46,9 +46,9 @@
32570
32571 #include <rdma/ib_umem.h>
32572
32573-atomic_t mod_qp_timouts;
32574-atomic_t qps_created;
32575-atomic_t sw_qps_destroyed;
32576+atomic_unchecked_t mod_qp_timouts;
32577+atomic_unchecked_t qps_created;
32578+atomic_unchecked_t sw_qps_destroyed;
32579
32580 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32581
32582@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32583 if (init_attr->create_flags)
32584 return ERR_PTR(-EINVAL);
32585
32586- atomic_inc(&qps_created);
32587+ atomic_inc_unchecked(&qps_created);
32588 switch (init_attr->qp_type) {
32589 case IB_QPT_RC:
32590 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32591@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32592 struct iw_cm_event cm_event;
32593 int ret = 0;
32594
32595- atomic_inc(&sw_qps_destroyed);
32596+ atomic_inc_unchecked(&sw_qps_destroyed);
32597 nesqp->destroyed = 1;
32598
32599 /* Blow away the connection if it exists. */
32600diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32601index 7e62f41..4c2b8e2 100644
32602--- a/drivers/infiniband/hw/qib/qib.h
32603+++ b/drivers/infiniband/hw/qib/qib.h
32604@@ -51,6 +51,7 @@
32605 #include <linux/completion.h>
32606 #include <linux/kref.h>
32607 #include <linux/sched.h>
32608+#include <linux/slab.h>
32609
32610 #include "qib_common.h"
32611 #include "qib_verbs.h"
32612diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32613index da739d9..da1c7f4 100644
32614--- a/drivers/input/gameport/gameport.c
32615+++ b/drivers/input/gameport/gameport.c
32616@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32617 */
32618 static void gameport_init_port(struct gameport *gameport)
32619 {
32620- static atomic_t gameport_no = ATOMIC_INIT(0);
32621+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32622
32623 __module_get(THIS_MODULE);
32624
32625 mutex_init(&gameport->drv_mutex);
32626 device_initialize(&gameport->dev);
32627 dev_set_name(&gameport->dev, "gameport%lu",
32628- (unsigned long)atomic_inc_return(&gameport_no) - 1);
32629+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32630 gameport->dev.bus = &gameport_bus;
32631 gameport->dev.release = gameport_release_port;
32632 if (gameport->parent)
32633diff --git a/drivers/input/input.c b/drivers/input/input.c
32634index 8921c61..f5cd63d 100644
32635--- a/drivers/input/input.c
32636+++ b/drivers/input/input.c
32637@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32638 */
32639 int input_register_device(struct input_dev *dev)
32640 {
32641- static atomic_t input_no = ATOMIC_INIT(0);
32642+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32643 struct input_handler *handler;
32644 const char *path;
32645 int error;
32646@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32647 dev->setkeycode = input_default_setkeycode;
32648
32649 dev_set_name(&dev->dev, "input%ld",
32650- (unsigned long) atomic_inc_return(&input_no) - 1);
32651+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32652
32653 error = device_add(&dev->dev);
32654 if (error)
32655diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32656index 04c69af..5f92d00 100644
32657--- a/drivers/input/joystick/sidewinder.c
32658+++ b/drivers/input/joystick/sidewinder.c
32659@@ -30,6 +30,7 @@
32660 #include <linux/kernel.h>
32661 #include <linux/module.h>
32662 #include <linux/slab.h>
32663+#include <linux/sched.h>
32664 #include <linux/init.h>
32665 #include <linux/input.h>
32666 #include <linux/gameport.h>
32667diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32668index 83811e4..0822b90 100644
32669--- a/drivers/input/joystick/xpad.c
32670+++ b/drivers/input/joystick/xpad.c
32671@@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32672
32673 static int xpad_led_probe(struct usb_xpad *xpad)
32674 {
32675- static atomic_t led_seq = ATOMIC_INIT(0);
32676+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32677 long led_no;
32678 struct xpad_led *led;
32679 struct led_classdev *led_cdev;
32680@@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32681 if (!led)
32682 return -ENOMEM;
32683
32684- led_no = (long)atomic_inc_return(&led_seq) - 1;
32685+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32686
32687 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32688 led->xpad = xpad;
32689diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32690index 0110b5a..d3ad144 100644
32691--- a/drivers/input/mousedev.c
32692+++ b/drivers/input/mousedev.c
32693@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32694
32695 spin_unlock_irq(&client->packet_lock);
32696
32697- if (copy_to_user(buffer, data, count))
32698+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
32699 return -EFAULT;
32700
32701 return count;
32702diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32703index d0f7533..fb8215b 100644
32704--- a/drivers/input/serio/serio.c
32705+++ b/drivers/input/serio/serio.c
32706@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32707 */
32708 static void serio_init_port(struct serio *serio)
32709 {
32710- static atomic_t serio_no = ATOMIC_INIT(0);
32711+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32712
32713 __module_get(THIS_MODULE);
32714
32715@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32716 mutex_init(&serio->drv_mutex);
32717 device_initialize(&serio->dev);
32718 dev_set_name(&serio->dev, "serio%ld",
32719- (long)atomic_inc_return(&serio_no) - 1);
32720+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
32721 serio->dev.bus = &serio_bus;
32722 serio->dev.release = serio_release_port;
32723 serio->dev.groups = serio_device_attr_groups;
32724diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32725index 38c4bd8..58965d9 100644
32726--- a/drivers/isdn/capi/capi.c
32727+++ b/drivers/isdn/capi/capi.c
32728@@ -83,8 +83,8 @@ struct capiminor {
32729
32730 struct capi20_appl *ap;
32731 u32 ncci;
32732- atomic_t datahandle;
32733- atomic_t msgid;
32734+ atomic_unchecked_t datahandle;
32735+ atomic_unchecked_t msgid;
32736
32737 struct tty_port port;
32738 int ttyinstop;
32739@@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32740 capimsg_setu16(s, 2, mp->ap->applid);
32741 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32742 capimsg_setu8 (s, 5, CAPI_RESP);
32743- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32744+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32745 capimsg_setu32(s, 8, mp->ncci);
32746 capimsg_setu16(s, 12, datahandle);
32747 }
32748@@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
32749 mp->outbytes -= len;
32750 spin_unlock_bh(&mp->outlock);
32751
32752- datahandle = atomic_inc_return(&mp->datahandle);
32753+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32754 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32755 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32756 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32757 capimsg_setu16(skb->data, 2, mp->ap->applid);
32758 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32759 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32760- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32761+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32762 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32763 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32764 capimsg_setu16(skb->data, 16, len); /* Data length */
32765diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32766index a6d9fd2..afdb8a3 100644
32767--- a/drivers/isdn/gigaset/interface.c
32768+++ b/drivers/isdn/gigaset/interface.c
32769@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32770 }
32771 tty->driver_data = cs;
32772
32773- ++cs->port.count;
32774+ atomic_inc(&cs->port.count);
32775
32776- if (cs->port.count == 1) {
32777+ if (atomic_read(&cs->port.count) == 1) {
32778 tty_port_tty_set(&cs->port, tty);
32779 tty->low_latency = 1;
32780 }
32781@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32782
32783 if (!cs->connected)
32784 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32785- else if (!cs->port.count)
32786+ else if (!atomic_read(&cs->port.count))
32787 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32788- else if (!--cs->port.count)
32789+ else if (!atomic_dec_return(&cs->port.count))
32790 tty_port_tty_set(&cs->port, NULL);
32791
32792 mutex_unlock(&cs->mutex);
32793diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32794index 821f7ac..28d4030 100644
32795--- a/drivers/isdn/hardware/avm/b1.c
32796+++ b/drivers/isdn/hardware/avm/b1.c
32797@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32798 }
32799 if (left) {
32800 if (t4file->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);
32806@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32807 }
32808 if (left) {
32809 if (config->user) {
32810- if (copy_from_user(buf, dp, left))
32811+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32812 return -EFAULT;
32813 } else {
32814 memcpy(buf, dp, left);
32815diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32816index dd6b53a..19d9ee6 100644
32817--- a/drivers/isdn/hardware/eicon/divasync.h
32818+++ b/drivers/isdn/hardware/eicon/divasync.h
32819@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32820 } diva_didd_add_adapter_t;
32821 typedef struct _diva_didd_remove_adapter {
32822 IDI_CALL p_request;
32823-} diva_didd_remove_adapter_t;
32824+} __no_const diva_didd_remove_adapter_t;
32825 typedef struct _diva_didd_read_adapter_array {
32826 void *buffer;
32827 dword length;
32828diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32829index d303e65..28bcb7b 100644
32830--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32831+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32832@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32833 typedef struct _diva_os_idi_adapter_interface {
32834 diva_init_card_proc_t cleanup_adapter_proc;
32835 diva_cmd_card_proc_t cmd_proc;
32836-} diva_os_idi_adapter_interface_t;
32837+} __no_const diva_os_idi_adapter_interface_t;
32838
32839 typedef struct _diva_os_xdi_adapter {
32840 struct list_head link;
32841diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
32842index 7bc5067..fd36232 100644
32843--- a/drivers/isdn/i4l/isdn_tty.c
32844+++ b/drivers/isdn/i4l/isdn_tty.c
32845@@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
32846 port = &info->port;
32847 #ifdef ISDN_DEBUG_MODEM_OPEN
32848 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
32849- port->count);
32850+ atomic_read(&port->count))
32851 #endif
32852- port->count++;
32853+ atomic_inc(&port->count);
32854 tty->driver_data = info;
32855 port->tty = tty;
32856 tty->port = port;
32857@@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32858 #endif
32859 return;
32860 }
32861- if ((tty->count == 1) && (port->count != 1)) {
32862+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
32863 /*
32864 * Uh, oh. tty->count is 1, which means that the tty
32865 * structure will be freed. Info->count should always
32866@@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32867 * serial port won't be shutdown.
32868 */
32869 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
32870- "info->count is %d\n", port->count);
32871- port->count = 1;
32872+ "info->count is %d\n", atomic_read(&port->count));
32873+ atomic_set(&port->count, 1);
32874 }
32875- if (--port->count < 0) {
32876+ if (atomic_dec_return(&port->count) < 0) {
32877 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
32878- info->line, port->count);
32879- port->count = 0;
32880+ info->line, atomic_read(&port->count));
32881+ atomic_set(&port->count, 0);
32882 }
32883- if (port->count) {
32884+ if (atomic_read(&port->count)) {
32885 #ifdef ISDN_DEBUG_MODEM_OPEN
32886 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
32887 #endif
32888@@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
32889 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
32890 return;
32891 isdn_tty_shutdown(info);
32892- port->count = 0;
32893+ atomic_set(&port->count, 0);
32894 port->flags &= ~ASYNC_NORMAL_ACTIVE;
32895 port->tty = NULL;
32896 wake_up_interruptible(&port->open_wait);
32897@@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
32898 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
32899 modem_info *info = &dev->mdm.info[i];
32900
32901- if (info->port.count == 0)
32902+ if (atomic_read(&info->port.count) == 0)
32903 continue;
32904 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
32905 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
32906diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32907index e74df7c..03a03ba 100644
32908--- a/drivers/isdn/icn/icn.c
32909+++ b/drivers/isdn/icn/icn.c
32910@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
32911 if (count > len)
32912 count = len;
32913 if (user) {
32914- if (copy_from_user(msg, buf, count))
32915+ if (count > sizeof msg || copy_from_user(msg, buf, count))
32916 return -EFAULT;
32917 } else
32918 memcpy(msg, buf, count);
32919diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32920index b5fdcb7..5b6c59f 100644
32921--- a/drivers/lguest/core.c
32922+++ b/drivers/lguest/core.c
32923@@ -92,9 +92,17 @@ static __init int map_switcher(void)
32924 * it's worked so far. The end address needs +1 because __get_vm_area
32925 * allocates an extra guard page, so we need space for that.
32926 */
32927+
32928+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32929+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32930+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32931+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32932+#else
32933 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32934 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32935 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32936+#endif
32937+
32938 if (!switcher_vma) {
32939 err = -ENOMEM;
32940 printk("lguest: could not map switcher pages high\n");
32941@@ -119,7 +127,7 @@ static __init int map_switcher(void)
32942 * Now the Switcher is mapped at the right address, we can't fail!
32943 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32944 */
32945- memcpy(switcher_vma->addr, start_switcher_text,
32946+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32947 end_switcher_text - start_switcher_text);
32948
32949 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32950diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32951index 39809035..ce25c5e 100644
32952--- a/drivers/lguest/x86/core.c
32953+++ b/drivers/lguest/x86/core.c
32954@@ -59,7 +59,7 @@ static struct {
32955 /* Offset from where switcher.S was compiled to where we've copied it */
32956 static unsigned long switcher_offset(void)
32957 {
32958- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32959+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32960 }
32961
32962 /* This cpu's struct lguest_pages. */
32963@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32964 * These copies are pretty cheap, so we do them unconditionally: */
32965 /* Save the current Host top-level page directory.
32966 */
32967+
32968+#ifdef CONFIG_PAX_PER_CPU_PGD
32969+ pages->state.host_cr3 = read_cr3();
32970+#else
32971 pages->state.host_cr3 = __pa(current->mm->pgd);
32972+#endif
32973+
32974 /*
32975 * Set up the Guest's page tables to see this CPU's pages (and no
32976 * other CPU's pages).
32977@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32978 * compiled-in switcher code and the high-mapped copy we just made.
32979 */
32980 for (i = 0; i < IDT_ENTRIES; i++)
32981- default_idt_entries[i] += switcher_offset();
32982+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32983
32984 /*
32985 * Set up the Switcher's per-cpu areas.
32986@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
32987 * it will be undisturbed when we switch. To change %cs and jump we
32988 * need this structure to feed to Intel's "lcall" instruction.
32989 */
32990- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
32991+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
32992 lguest_entry.segment = LGUEST_CS;
32993
32994 /*
32995diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
32996index 40634b0..4f5855e 100644
32997--- a/drivers/lguest/x86/switcher_32.S
32998+++ b/drivers/lguest/x86/switcher_32.S
32999@@ -87,6 +87,7 @@
33000 #include <asm/page.h>
33001 #include <asm/segment.h>
33002 #include <asm/lguest.h>
33003+#include <asm/processor-flags.h>
33004
33005 // We mark the start of the code to copy
33006 // It's placed in .text tho it's never run here
33007@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33008 // Changes type when we load it: damn Intel!
33009 // For after we switch over our page tables
33010 // That entry will be read-only: we'd crash.
33011+
33012+#ifdef CONFIG_PAX_KERNEXEC
33013+ mov %cr0, %edx
33014+ xor $X86_CR0_WP, %edx
33015+ mov %edx, %cr0
33016+#endif
33017+
33018 movl $(GDT_ENTRY_TSS*8), %edx
33019 ltr %dx
33020
33021@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33022 // Let's clear it again for our return.
33023 // The GDT descriptor of the Host
33024 // Points to the table after two "size" bytes
33025- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33026+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33027 // Clear "used" from type field (byte 5, bit 2)
33028- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33029+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33030+
33031+#ifdef CONFIG_PAX_KERNEXEC
33032+ mov %cr0, %eax
33033+ xor $X86_CR0_WP, %eax
33034+ mov %eax, %cr0
33035+#endif
33036
33037 // Once our page table's switched, the Guest is live!
33038 // The Host fades as we run this final step.
33039@@ -295,13 +309,12 @@ deliver_to_host:
33040 // I consulted gcc, and it gave
33041 // These instructions, which I gladly credit:
33042 leal (%edx,%ebx,8), %eax
33043- movzwl (%eax),%edx
33044- movl 4(%eax), %eax
33045- xorw %ax, %ax
33046- orl %eax, %edx
33047+ movl 4(%eax), %edx
33048+ movw (%eax), %dx
33049 // Now the address of the handler's in %edx
33050 // We call it now: its "iret" drops us home.
33051- jmp *%edx
33052+ ljmp $__KERNEL_CS, $1f
33053+1: jmp *%edx
33054
33055 // Every interrupt can come to us here
33056 // But we must truly tell each apart.
33057diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33058index 20e5c2c..9e849a9 100644
33059--- a/drivers/macintosh/macio_asic.c
33060+++ b/drivers/macintosh/macio_asic.c
33061@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33062 * MacIO is matched against any Apple ID, it's probe() function
33063 * will then decide wether it applies or not
33064 */
33065-static const struct pci_device_id __devinitdata pci_ids [] = { {
33066+static const struct pci_device_id __devinitconst pci_ids [] = { {
33067 .vendor = PCI_VENDOR_ID_APPLE,
33068 .device = PCI_ANY_ID,
33069 .subvendor = PCI_ANY_ID,
33070diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33071index 15dbe03..743fc65 100644
33072--- a/drivers/md/bitmap.c
33073+++ b/drivers/md/bitmap.c
33074@@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33075 chunk_kb ? "KB" : "B");
33076 if (bitmap->storage.file) {
33077 seq_printf(seq, ", file: ");
33078- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33079+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33080 }
33081
33082 seq_printf(seq, "\n");
33083diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33084index a1a3e6d..1918bfc 100644
33085--- a/drivers/md/dm-ioctl.c
33086+++ b/drivers/md/dm-ioctl.c
33087@@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33088 cmd == DM_LIST_VERSIONS_CMD)
33089 return 0;
33090
33091- if ((cmd == DM_DEV_CREATE_CMD)) {
33092+ if (cmd == DM_DEV_CREATE_CMD) {
33093 if (!*param->name) {
33094 DMWARN("name not supplied when creating device");
33095 return -EINVAL;
33096diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33097index b58b7a3..8018b19 100644
33098--- a/drivers/md/dm-raid1.c
33099+++ b/drivers/md/dm-raid1.c
33100@@ -40,7 +40,7 @@ enum dm_raid1_error {
33101
33102 struct mirror {
33103 struct mirror_set *ms;
33104- atomic_t error_count;
33105+ atomic_unchecked_t error_count;
33106 unsigned long error_type;
33107 struct dm_dev *dev;
33108 sector_t offset;
33109@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33110 struct mirror *m;
33111
33112 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33113- if (!atomic_read(&m->error_count))
33114+ if (!atomic_read_unchecked(&m->error_count))
33115 return m;
33116
33117 return NULL;
33118@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33119 * simple way to tell if a device has encountered
33120 * errors.
33121 */
33122- atomic_inc(&m->error_count);
33123+ atomic_inc_unchecked(&m->error_count);
33124
33125 if (test_and_set_bit(error_type, &m->error_type))
33126 return;
33127@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33128 struct mirror *m = get_default_mirror(ms);
33129
33130 do {
33131- if (likely(!atomic_read(&m->error_count)))
33132+ if (likely(!atomic_read_unchecked(&m->error_count)))
33133 return m;
33134
33135 if (m-- == ms->mirror)
33136@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33137 {
33138 struct mirror *default_mirror = get_default_mirror(m->ms);
33139
33140- return !atomic_read(&default_mirror->error_count);
33141+ return !atomic_read_unchecked(&default_mirror->error_count);
33142 }
33143
33144 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33145@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33146 */
33147 if (likely(region_in_sync(ms, region, 1)))
33148 m = choose_mirror(ms, bio->bi_sector);
33149- else if (m && atomic_read(&m->error_count))
33150+ else if (m && atomic_read_unchecked(&m->error_count))
33151 m = NULL;
33152
33153 if (likely(m))
33154@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33155 }
33156
33157 ms->mirror[mirror].ms = ms;
33158- atomic_set(&(ms->mirror[mirror].error_count), 0);
33159+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33160 ms->mirror[mirror].error_type = 0;
33161 ms->mirror[mirror].offset = offset;
33162
33163@@ -1352,7 +1352,7 @@ static void mirror_resume(struct dm_target *ti)
33164 */
33165 static char device_status_char(struct mirror *m)
33166 {
33167- if (!atomic_read(&(m->error_count)))
33168+ if (!atomic_read_unchecked(&(m->error_count)))
33169 return 'A';
33170
33171 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33172diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33173index 35c94ff..20d4c17 100644
33174--- a/drivers/md/dm-stripe.c
33175+++ b/drivers/md/dm-stripe.c
33176@@ -20,7 +20,7 @@ struct stripe {
33177 struct dm_dev *dev;
33178 sector_t physical_start;
33179
33180- atomic_t error_count;
33181+ atomic_unchecked_t error_count;
33182 };
33183
33184 struct stripe_c {
33185@@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33186 kfree(sc);
33187 return r;
33188 }
33189- atomic_set(&(sc->stripe[i].error_count), 0);
33190+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33191 }
33192
33193 ti->private = sc;
33194@@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33195 DMEMIT("%d ", sc->stripes);
33196 for (i = 0; i < sc->stripes; i++) {
33197 DMEMIT("%s ", sc->stripe[i].dev->name);
33198- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33199+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33200 'D' : 'A';
33201 }
33202 buffer[i] = '\0';
33203@@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33204 */
33205 for (i = 0; i < sc->stripes; i++)
33206 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33207- atomic_inc(&(sc->stripe[i].error_count));
33208- if (atomic_read(&(sc->stripe[i].error_count)) <
33209+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
33210+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33211 DM_IO_ERROR_THRESHOLD)
33212 schedule_work(&sc->trigger_event);
33213 }
33214diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33215index 2e227fb..44ead1f 100644
33216--- a/drivers/md/dm-table.c
33217+++ b/drivers/md/dm-table.c
33218@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33219 if (!dev_size)
33220 return 0;
33221
33222- if ((start >= dev_size) || (start + len > dev_size)) {
33223+ if ((start >= dev_size) || (len > dev_size - start)) {
33224 DMWARN("%s: %s too small for target: "
33225 "start=%llu, len=%llu, dev_size=%llu",
33226 dm_device_name(ti->table->md), bdevname(bdev, b),
33227diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33228index 3e2907f..c28851a 100644
33229--- a/drivers/md/dm-thin-metadata.c
33230+++ b/drivers/md/dm-thin-metadata.c
33231@@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33232
33233 pmd->info.tm = tm;
33234 pmd->info.levels = 2;
33235- pmd->info.value_type.context = pmd->data_sm;
33236+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33237 pmd->info.value_type.size = sizeof(__le64);
33238 pmd->info.value_type.inc = data_block_inc;
33239 pmd->info.value_type.dec = data_block_dec;
33240@@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33241
33242 pmd->bl_info.tm = tm;
33243 pmd->bl_info.levels = 1;
33244- pmd->bl_info.value_type.context = pmd->data_sm;
33245+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33246 pmd->bl_info.value_type.size = sizeof(__le64);
33247 pmd->bl_info.value_type.inc = data_block_inc;
33248 pmd->bl_info.value_type.dec = data_block_dec;
33249diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33250index e24143c..ce2f21a1 100644
33251--- a/drivers/md/dm.c
33252+++ b/drivers/md/dm.c
33253@@ -176,9 +176,9 @@ struct mapped_device {
33254 /*
33255 * Event handling.
33256 */
33257- atomic_t event_nr;
33258+ atomic_unchecked_t event_nr;
33259 wait_queue_head_t eventq;
33260- atomic_t uevent_seq;
33261+ atomic_unchecked_t uevent_seq;
33262 struct list_head uevent_list;
33263 spinlock_t uevent_lock; /* Protect access to uevent_list */
33264
33265@@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33266 rwlock_init(&md->map_lock);
33267 atomic_set(&md->holders, 1);
33268 atomic_set(&md->open_count, 0);
33269- atomic_set(&md->event_nr, 0);
33270- atomic_set(&md->uevent_seq, 0);
33271+ atomic_set_unchecked(&md->event_nr, 0);
33272+ atomic_set_unchecked(&md->uevent_seq, 0);
33273 INIT_LIST_HEAD(&md->uevent_list);
33274 spin_lock_init(&md->uevent_lock);
33275
33276@@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33277
33278 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33279
33280- atomic_inc(&md->event_nr);
33281+ atomic_inc_unchecked(&md->event_nr);
33282 wake_up(&md->eventq);
33283 }
33284
33285@@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33286
33287 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33288 {
33289- return atomic_add_return(1, &md->uevent_seq);
33290+ return atomic_add_return_unchecked(1, &md->uevent_seq);
33291 }
33292
33293 uint32_t dm_get_event_nr(struct mapped_device *md)
33294 {
33295- return atomic_read(&md->event_nr);
33296+ return atomic_read_unchecked(&md->event_nr);
33297 }
33298
33299 int dm_wait_event(struct mapped_device *md, int event_nr)
33300 {
33301 return wait_event_interruptible(md->eventq,
33302- (event_nr != atomic_read(&md->event_nr)));
33303+ (event_nr != atomic_read_unchecked(&md->event_nr)));
33304 }
33305
33306 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33307diff --git a/drivers/md/md.c b/drivers/md/md.c
33308index d5ab449..7e9ed7b 100644
33309--- a/drivers/md/md.c
33310+++ b/drivers/md/md.c
33311@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33312 * start build, activate spare
33313 */
33314 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33315-static atomic_t md_event_count;
33316+static atomic_unchecked_t md_event_count;
33317 void md_new_event(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 EXPORT_SYMBOL_GPL(md_new_event);
33324@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33325 */
33326 static void md_new_event_inintr(struct mddev *mddev)
33327 {
33328- atomic_inc(&md_event_count);
33329+ atomic_inc_unchecked(&md_event_count);
33330 wake_up(&md_event_waiters);
33331 }
33332
33333@@ -1565,7 +1565,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33334 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33335 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33336 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33337- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33338+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33339
33340 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33341 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33342@@ -1809,7 +1809,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33343 else
33344 sb->resync_offset = cpu_to_le64(0);
33345
33346- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33347+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33348
33349 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33350 sb->size = cpu_to_le64(mddev->dev_sectors);
33351@@ -2803,7 +2803,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33352 static ssize_t
33353 errors_show(struct md_rdev *rdev, char *page)
33354 {
33355- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33356+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33357 }
33358
33359 static ssize_t
33360@@ -2812,7 +2812,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33361 char *e;
33362 unsigned long n = simple_strtoul(buf, &e, 10);
33363 if (*buf && (*e == 0 || *e == '\n')) {
33364- atomic_set(&rdev->corrected_errors, n);
33365+ atomic_set_unchecked(&rdev->corrected_errors, n);
33366 return len;
33367 }
33368 return -EINVAL;
33369@@ -3259,8 +3259,8 @@ int md_rdev_init(struct md_rdev *rdev)
33370 rdev->sb_loaded = 0;
33371 rdev->bb_page = NULL;
33372 atomic_set(&rdev->nr_pending, 0);
33373- atomic_set(&rdev->read_errors, 0);
33374- atomic_set(&rdev->corrected_errors, 0);
33375+ atomic_set_unchecked(&rdev->read_errors, 0);
33376+ atomic_set_unchecked(&rdev->corrected_errors, 0);
33377
33378 INIT_LIST_HEAD(&rdev->same_set);
33379 init_waitqueue_head(&rdev->blocked_wait);
33380@@ -6997,7 +6997,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33381
33382 spin_unlock(&pers_lock);
33383 seq_printf(seq, "\n");
33384- seq->poll_event = atomic_read(&md_event_count);
33385+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33386 return 0;
33387 }
33388 if (v == (void*)2) {
33389@@ -7100,7 +7100,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33390 return error;
33391
33392 seq = file->private_data;
33393- seq->poll_event = atomic_read(&md_event_count);
33394+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33395 return error;
33396 }
33397
33398@@ -7114,7 +7114,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33399 /* always allow read */
33400 mask = POLLIN | POLLRDNORM;
33401
33402- if (seq->poll_event != atomic_read(&md_event_count))
33403+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33404 mask |= POLLERR | POLLPRI;
33405 return mask;
33406 }
33407@@ -7158,7 +7158,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33408 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33409 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33410 (int)part_stat_read(&disk->part0, sectors[1]) -
33411- atomic_read(&disk->sync_io);
33412+ atomic_read_unchecked(&disk->sync_io);
33413 /* sync IO will cause sync_io to increase before the disk_stats
33414 * as sync_io is counted when a request starts, and
33415 * disk_stats is counted when it completes.
33416diff --git a/drivers/md/md.h b/drivers/md/md.h
33417index 7b4a3c3..994ad4f 100644
33418--- a/drivers/md/md.h
33419+++ b/drivers/md/md.h
33420@@ -94,13 +94,13 @@ struct md_rdev {
33421 * only maintained for arrays that
33422 * support hot removal
33423 */
33424- atomic_t read_errors; /* number of consecutive read errors that
33425+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
33426 * we have tried to ignore.
33427 */
33428 struct timespec last_read_error; /* monotonic time since our
33429 * last read error
33430 */
33431- atomic_t corrected_errors; /* number of corrected read errors,
33432+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33433 * for reporting to userspace and storing
33434 * in superblock.
33435 */
33436@@ -435,7 +435,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33437
33438 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33439 {
33440- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33441+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33442 }
33443
33444 struct md_personality
33445diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33446index fc90c11..c8cd9a9 100644
33447--- a/drivers/md/persistent-data/dm-space-map-checker.c
33448+++ b/drivers/md/persistent-data/dm-space-map-checker.c
33449@@ -167,7 +167,7 @@ static int ca_commit(struct count_array *old, struct count_array *new)
33450 /*----------------------------------------------------------------*/
33451
33452 struct sm_checker {
33453- struct dm_space_map sm;
33454+ dm_space_map_no_const sm;
33455
33456 struct count_array old_counts;
33457 struct count_array counts;
33458diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33459index 3d0ed53..35dc592 100644
33460--- a/drivers/md/persistent-data/dm-space-map-disk.c
33461+++ b/drivers/md/persistent-data/dm-space-map-disk.c
33462@@ -23,7 +23,7 @@
33463 * Space map interface.
33464 */
33465 struct sm_disk {
33466- struct dm_space_map sm;
33467+ dm_space_map_no_const sm;
33468
33469 struct ll_disk ll;
33470 struct ll_disk old_ll;
33471diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33472index e89ae5e..062e4c2 100644
33473--- a/drivers/md/persistent-data/dm-space-map-metadata.c
33474+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33475@@ -43,7 +43,7 @@ struct block_op {
33476 };
33477
33478 struct sm_metadata {
33479- struct dm_space_map sm;
33480+ dm_space_map_no_const sm;
33481
33482 struct ll_disk ll;
33483 struct ll_disk old_ll;
33484diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33485index 1cbfc6b..56e1dbb 100644
33486--- a/drivers/md/persistent-data/dm-space-map.h
33487+++ b/drivers/md/persistent-data/dm-space-map.h
33488@@ -60,6 +60,7 @@ struct dm_space_map {
33489 int (*root_size)(struct dm_space_map *sm, size_t *result);
33490 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33491 };
33492+typedef struct dm_space_map __no_const dm_space_map_no_const;
33493
33494 /*----------------------------------------------------------------*/
33495
33496diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33497index cacd008..2823610 100644
33498--- a/drivers/md/raid1.c
33499+++ b/drivers/md/raid1.c
33500@@ -1685,7 +1685,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33501 if (r1_sync_page_io(rdev, sect, s,
33502 bio->bi_io_vec[idx].bv_page,
33503 READ) != 0)
33504- atomic_add(s, &rdev->corrected_errors);
33505+ atomic_add_unchecked(s, &rdev->corrected_errors);
33506 }
33507 sectors -= s;
33508 sect += s;
33509@@ -1907,7 +1907,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33510 test_bit(In_sync, &rdev->flags)) {
33511 if (r1_sync_page_io(rdev, sect, s,
33512 conf->tmppage, READ)) {
33513- atomic_add(s, &rdev->corrected_errors);
33514+ atomic_add_unchecked(s, &rdev->corrected_errors);
33515 printk(KERN_INFO
33516 "md/raid1:%s: read error corrected "
33517 "(%d sectors at %llu on %s)\n",
33518diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33519index 8da6282..8ec7103 100644
33520--- a/drivers/md/raid10.c
33521+++ b/drivers/md/raid10.c
33522@@ -1784,7 +1784,7 @@ static void end_sync_read(struct bio *bio, int error)
33523 /* The write handler will notice the lack of
33524 * R10BIO_Uptodate and record any errors etc
33525 */
33526- atomic_add(r10_bio->sectors,
33527+ atomic_add_unchecked(r10_bio->sectors,
33528 &conf->mirrors[d].rdev->corrected_errors);
33529
33530 /* for reconstruct, we always reschedule after a read.
33531@@ -2133,7 +2133,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33532 {
33533 struct timespec cur_time_mon;
33534 unsigned long hours_since_last;
33535- unsigned int read_errors = atomic_read(&rdev->read_errors);
33536+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33537
33538 ktime_get_ts(&cur_time_mon);
33539
33540@@ -2155,9 +2155,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33541 * overflowing the shift of read_errors by hours_since_last.
33542 */
33543 if (hours_since_last >= 8 * sizeof(read_errors))
33544- atomic_set(&rdev->read_errors, 0);
33545+ atomic_set_unchecked(&rdev->read_errors, 0);
33546 else
33547- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33548+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33549 }
33550
33551 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33552@@ -2211,8 +2211,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33553 return;
33554
33555 check_decay_read_errors(mddev, rdev);
33556- atomic_inc(&rdev->read_errors);
33557- if (atomic_read(&rdev->read_errors) > max_read_errors) {
33558+ atomic_inc_unchecked(&rdev->read_errors);
33559+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33560 char b[BDEVNAME_SIZE];
33561 bdevname(rdev->bdev, b);
33562
33563@@ -2220,7 +2220,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33564 "md/raid10:%s: %s: Raid device exceeded "
33565 "read_error threshold [cur %d:max %d]\n",
33566 mdname(mddev), b,
33567- atomic_read(&rdev->read_errors), max_read_errors);
33568+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33569 printk(KERN_NOTICE
33570 "md/raid10:%s: %s: Failing raid device\n",
33571 mdname(mddev), b);
33572@@ -2375,7 +2375,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33573 sect +
33574 choose_data_offset(r10_bio, rdev)),
33575 bdevname(rdev->bdev, b));
33576- atomic_add(s, &rdev->corrected_errors);
33577+ atomic_add_unchecked(s, &rdev->corrected_errors);
33578 }
33579
33580 rdev_dec_pending(rdev, mddev);
33581diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33582index 04348d7..62a4b9b 100644
33583--- a/drivers/md/raid5.c
33584+++ b/drivers/md/raid5.c
33585@@ -1736,19 +1736,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
33586 mdname(conf->mddev), STRIPE_SECTORS,
33587 (unsigned long long)s,
33588 bdevname(rdev->bdev, b));
33589- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33590+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33591 clear_bit(R5_ReadError, &sh->dev[i].flags);
33592 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33593 }
33594- if (atomic_read(&rdev->read_errors))
33595- atomic_set(&rdev->read_errors, 0);
33596+ if (atomic_read_unchecked(&rdev->read_errors))
33597+ atomic_set_unchecked(&rdev->read_errors, 0);
33598 } else {
33599 const char *bdn = bdevname(rdev->bdev, b);
33600 int retry = 0;
33601 int set_bad = 0;
33602
33603 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33604- atomic_inc(&rdev->read_errors);
33605+ atomic_inc_unchecked(&rdev->read_errors);
33606 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33607 printk_ratelimited(
33608 KERN_WARNING
33609@@ -1776,7 +1776,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33610 mdname(conf->mddev),
33611 (unsigned long long)s,
33612 bdn);
33613- } else if (atomic_read(&rdev->read_errors)
33614+ } else if (atomic_read_unchecked(&rdev->read_errors)
33615 > conf->max_nr_stripes)
33616 printk(KERN_WARNING
33617 "md/raid:%s: Too many read errors, failing device %s.\n",
33618diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33619index 131b938..8572ed1 100644
33620--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33621+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33622@@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33623 .subvendor = _subvend, .subdevice = _subdev, \
33624 .driver_data = (unsigned long)&_driverdata }
33625
33626-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33627+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33628 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33629 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33630 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33631diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33632index fa7188a..04a045e 100644
33633--- a/drivers/media/dvb/dvb-core/dvb_demux.h
33634+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33635@@ -73,7 +73,7 @@ struct dvb_demux_feed {
33636 union {
33637 dmx_ts_cb ts;
33638 dmx_section_cb sec;
33639- } cb;
33640+ } __no_const cb;
33641
33642 struct dvb_demux *demux;
33643 void *priv;
33644diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33645index 39eab73..60033e7 100644
33646--- a/drivers/media/dvb/dvb-core/dvbdev.c
33647+++ b/drivers/media/dvb/dvb-core/dvbdev.c
33648@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33649 const struct dvb_device *template, void *priv, int type)
33650 {
33651 struct dvb_device *dvbdev;
33652- struct file_operations *dvbdevfops;
33653+ file_operations_no_const *dvbdevfops;
33654 struct device *clsdev;
33655 int minor;
33656 int id;
33657diff --git a/drivers/media/dvb/dvb-usb/az6007.c b/drivers/media/dvb/dvb-usb/az6007.c
33658index 4008b9c..ce714f5 100644
33659--- a/drivers/media/dvb/dvb-usb/az6007.c
33660+++ b/drivers/media/dvb/dvb-usb/az6007.c
33661@@ -590,7 +590,7 @@ static int az6007_read_mac_addr(struct dvb_usb_device *d, u8 mac[6])
33662 int ret;
33663
33664 ret = az6007_read(d, AZ6007_READ_DATA, 6, 0, st->data, 6);
33665- memcpy(mac, st->data, sizeof(mac));
33666+ memcpy(mac, st->data, 6);
33667
33668 if (ret > 0)
33669 deb_info("%s: mac is %02x:%02x:%02x:%02x:%02x:%02x\n",
33670diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33671index 3940bb0..fb3952a 100644
33672--- a/drivers/media/dvb/dvb-usb/cxusb.c
33673+++ b/drivers/media/dvb/dvb-usb/cxusb.c
33674@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33675
33676 struct dib0700_adapter_state {
33677 int (*set_param_save) (struct dvb_frontend *);
33678-};
33679+} __no_const;
33680
33681 static int dib7070_set_param_override(struct dvb_frontend *fe)
33682 {
33683diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33684index 9382895..ac8093c 100644
33685--- a/drivers/media/dvb/dvb-usb/dw2102.c
33686+++ b/drivers/media/dvb/dvb-usb/dw2102.c
33687@@ -95,7 +95,7 @@ struct su3000_state {
33688
33689 struct s6x0_state {
33690 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33691-};
33692+} __no_const;
33693
33694 /* debug */
33695 static int dvb_usb_dw2102_debug;
33696diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33697index 404f63a..4796533 100644
33698--- a/drivers/media/dvb/frontends/dib3000.h
33699+++ b/drivers/media/dvb/frontends/dib3000.h
33700@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33701 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33702 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33703 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33704-};
33705+} __no_const;
33706
33707 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33708 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33709diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33710index 7539a5d..06531a6 100644
33711--- a/drivers/media/dvb/ngene/ngene-cards.c
33712+++ b/drivers/media/dvb/ngene/ngene-cards.c
33713@@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33714
33715 /****************************************************************************/
33716
33717-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33718+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33719 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33720 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33721 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33722diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33723index 16a089f..1661b11 100644
33724--- a/drivers/media/radio/radio-cadet.c
33725+++ b/drivers/media/radio/radio-cadet.c
33726@@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33727 unsigned char readbuf[RDS_BUFFER];
33728 int i = 0;
33729
33730+ if (count > RDS_BUFFER)
33731+ return -EFAULT;
33732 mutex_lock(&dev->lock);
33733 if (dev->rdsstat == 0) {
33734 dev->rdsstat = 1;
33735@@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33736 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33737 mutex_unlock(&dev->lock);
33738
33739- if (copy_to_user(data, readbuf, i))
33740+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33741 return -EFAULT;
33742 return i;
33743 }
33744diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33745index 9cde353..8c6a1c3 100644
33746--- a/drivers/media/video/au0828/au0828.h
33747+++ b/drivers/media/video/au0828/au0828.h
33748@@ -191,7 +191,7 @@ struct au0828_dev {
33749
33750 /* I2C */
33751 struct i2c_adapter i2c_adap;
33752- struct i2c_algorithm i2c_algo;
33753+ i2c_algorithm_no_const i2c_algo;
33754 struct i2c_client i2c_client;
33755 u32 i2c_rc;
33756
33757diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33758index 04bf662..e0ac026 100644
33759--- a/drivers/media/video/cx88/cx88-alsa.c
33760+++ b/drivers/media/video/cx88/cx88-alsa.c
33761@@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33762 * Only boards with eeprom and byte 1 at eeprom=1 have it
33763 */
33764
33765-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33766+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33767 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33768 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33769 {0, }
33770diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33771index 88cf9d9..bbc4b2c 100644
33772--- a/drivers/media/video/omap/omap_vout.c
33773+++ b/drivers/media/video/omap/omap_vout.c
33774@@ -64,7 +64,6 @@ enum omap_vout_channels {
33775 OMAP_VIDEO2,
33776 };
33777
33778-static struct videobuf_queue_ops video_vbq_ops;
33779 /* Variables configurable through module params*/
33780 static u32 video1_numbuffers = 3;
33781 static u32 video2_numbuffers = 3;
33782@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33783 {
33784 struct videobuf_queue *q;
33785 struct omap_vout_device *vout = NULL;
33786+ static struct videobuf_queue_ops video_vbq_ops = {
33787+ .buf_setup = omap_vout_buffer_setup,
33788+ .buf_prepare = omap_vout_buffer_prepare,
33789+ .buf_release = omap_vout_buffer_release,
33790+ .buf_queue = omap_vout_buffer_queue,
33791+ };
33792
33793 vout = video_drvdata(file);
33794 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33795@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33796 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33797
33798 q = &vout->vbq;
33799- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33800- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33801- video_vbq_ops.buf_release = omap_vout_buffer_release;
33802- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33803 spin_lock_init(&vout->vbq_lock);
33804
33805 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33806diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33807index 036952f..80d356d 100644
33808--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33809+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33810@@ -196,7 +196,7 @@ struct pvr2_hdw {
33811
33812 /* I2C stuff */
33813 struct i2c_adapter i2c_adap;
33814- struct i2c_algorithm i2c_algo;
33815+ i2c_algorithm_no_const i2c_algo;
33816 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33817 int i2c_cx25840_hack_state;
33818 int i2c_linked;
33819diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33820index 02194c0..091733b 100644
33821--- a/drivers/media/video/timblogiw.c
33822+++ b/drivers/media/video/timblogiw.c
33823@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33824
33825 /* Platform device functions */
33826
33827-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33828+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33829 .vidioc_querycap = timblogiw_querycap,
33830 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33831 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33832@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33833 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33834 };
33835
33836-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33837+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33838 .owner = THIS_MODULE,
33839 .open = timblogiw_open,
33840 .release = timblogiw_close,
33841diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33842index d99db56..a16b959 100644
33843--- a/drivers/message/fusion/mptbase.c
33844+++ b/drivers/message/fusion/mptbase.c
33845@@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33846 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33847 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33848
33849+#ifdef CONFIG_GRKERNSEC_HIDESYM
33850+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33851+#else
33852 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33853 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33854+#endif
33855+
33856 /*
33857 * Rounding UP to nearest 4-kB boundary here...
33858 */
33859diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33860index 551262e..7551198 100644
33861--- a/drivers/message/fusion/mptsas.c
33862+++ b/drivers/message/fusion/mptsas.c
33863@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33864 return 0;
33865 }
33866
33867+static inline void
33868+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33869+{
33870+ if (phy_info->port_details) {
33871+ phy_info->port_details->rphy = rphy;
33872+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33873+ ioc->name, rphy));
33874+ }
33875+
33876+ if (rphy) {
33877+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33878+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33879+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33880+ ioc->name, rphy, rphy->dev.release));
33881+ }
33882+}
33883+
33884 /* no mutex */
33885 static void
33886 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33887@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33888 return NULL;
33889 }
33890
33891-static inline void
33892-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33893-{
33894- if (phy_info->port_details) {
33895- phy_info->port_details->rphy = rphy;
33896- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33897- ioc->name, rphy));
33898- }
33899-
33900- if (rphy) {
33901- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33902- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33903- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33904- ioc->name, rphy, rphy->dev.release));
33905- }
33906-}
33907-
33908 static inline struct sas_port *
33909 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33910 {
33911diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33912index 0c3ced7..1fe34ec 100644
33913--- a/drivers/message/fusion/mptscsih.c
33914+++ b/drivers/message/fusion/mptscsih.c
33915@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33916
33917 h = shost_priv(SChost);
33918
33919- if (h) {
33920- if (h->info_kbuf == NULL)
33921- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33922- return h->info_kbuf;
33923- h->info_kbuf[0] = '\0';
33924+ if (!h)
33925+ return NULL;
33926
33927- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33928- h->info_kbuf[size-1] = '\0';
33929- }
33930+ if (h->info_kbuf == NULL)
33931+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33932+ return h->info_kbuf;
33933+ h->info_kbuf[0] = '\0';
33934+
33935+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33936+ h->info_kbuf[size-1] = '\0';
33937
33938 return h->info_kbuf;
33939 }
33940diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
33941index 506c36f..b137580 100644
33942--- a/drivers/message/i2o/i2o_proc.c
33943+++ b/drivers/message/i2o/i2o_proc.c
33944@@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33945 "Array Controller Device"
33946 };
33947
33948-static char *chtostr(u8 * chars, int n)
33949-{
33950- char tmp[256];
33951- tmp[0] = 0;
33952- return strncat(tmp, (char *)chars, n);
33953-}
33954-
33955 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33956 char *group)
33957 {
33958@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
33959
33960 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33961 seq_printf(seq, "%-#8x", ddm_table.module_id);
33962- seq_printf(seq, "%-29s",
33963- chtostr(ddm_table.module_name_version, 28));
33964+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33965 seq_printf(seq, "%9d ", ddm_table.data_size);
33966 seq_printf(seq, "%8d", ddm_table.code_size);
33967
33968@@ -927,8 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
33969
33970 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33971 seq_printf(seq, "%-#8x", dst->module_id);
33972- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33973- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33974+ seq_printf(seq, "%-.28s", dst->module_name_version);
33975+ seq_printf(seq, "%-.8s", dst->date);
33976 seq_printf(seq, "%8d ", dst->module_size);
33977 seq_printf(seq, "%8d ", dst->mpb_size);
33978 seq_printf(seq, "0x%04x", dst->module_flags);
33979@@ -1259,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
33980 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33981 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33982 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33983- seq_printf(seq, "Vendor info : %s\n",
33984- chtostr((u8 *) (work32 + 2), 16));
33985- seq_printf(seq, "Product info : %s\n",
33986- chtostr((u8 *) (work32 + 6), 16));
33987- seq_printf(seq, "Description : %s\n",
33988- chtostr((u8 *) (work32 + 10), 16));
33989- seq_printf(seq, "Product rev. : %s\n",
33990- chtostr((u8 *) (work32 + 14), 8));
33991+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33992+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33993+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33994+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33995
33996 seq_printf(seq, "Serial number : ");
33997 print_serial_number(seq, (u8 *) (work32 + 16),
33998@@ -1311,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
33999 }
34000
34001 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34002- seq_printf(seq, "Module name : %s\n",
34003- chtostr(result.module_name, 24));
34004- seq_printf(seq, "Module revision : %s\n",
34005- chtostr(result.module_rev, 8));
34006+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
34007+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34008
34009 seq_printf(seq, "Serial number : ");
34010 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34011@@ -1345,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34012 return 0;
34013 }
34014
34015- seq_printf(seq, "Device name : %s\n",
34016- chtostr(result.device_name, 64));
34017- seq_printf(seq, "Service name : %s\n",
34018- chtostr(result.service_name, 64));
34019- seq_printf(seq, "Physical name : %s\n",
34020- chtostr(result.physical_location, 64));
34021- seq_printf(seq, "Instance number : %s\n",
34022- chtostr(result.instance_number, 4));
34023+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
34024+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
34025+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34026+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34027
34028 return 0;
34029 }
34030diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34031index a8c08f3..155fe3d 100644
34032--- a/drivers/message/i2o/iop.c
34033+++ b/drivers/message/i2o/iop.c
34034@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34035
34036 spin_lock_irqsave(&c->context_list_lock, flags);
34037
34038- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34039- atomic_inc(&c->context_list_counter);
34040+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34041+ atomic_inc_unchecked(&c->context_list_counter);
34042
34043- entry->context = atomic_read(&c->context_list_counter);
34044+ entry->context = atomic_read_unchecked(&c->context_list_counter);
34045
34046 list_add(&entry->list, &c->context_list);
34047
34048@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34049
34050 #if BITS_PER_LONG == 64
34051 spin_lock_init(&c->context_list_lock);
34052- atomic_set(&c->context_list_counter, 0);
34053+ atomic_set_unchecked(&c->context_list_counter, 0);
34054 INIT_LIST_HEAD(&c->context_list);
34055 #endif
34056
34057diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34058index 7ce65f4..e66e9bc 100644
34059--- a/drivers/mfd/abx500-core.c
34060+++ b/drivers/mfd/abx500-core.c
34061@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34062
34063 struct abx500_device_entry {
34064 struct list_head list;
34065- struct abx500_ops ops;
34066+ abx500_ops_no_const ops;
34067 struct device *dev;
34068 };
34069
34070diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34071index 2ea9998..51dabee 100644
34072--- a/drivers/mfd/janz-cmodio.c
34073+++ b/drivers/mfd/janz-cmodio.c
34074@@ -13,6 +13,7 @@
34075
34076 #include <linux/kernel.h>
34077 #include <linux/module.h>
34078+#include <linux/slab.h>
34079 #include <linux/init.h>
34080 #include <linux/pci.h>
34081 #include <linux/interrupt.h>
34082diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34083index a981e2a..5ca0c8b 100644
34084--- a/drivers/misc/lis3lv02d/lis3lv02d.c
34085+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34086@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34087 * the lid is closed. This leads to interrupts as soon as a little move
34088 * is done.
34089 */
34090- atomic_inc(&lis3->count);
34091+ atomic_inc_unchecked(&lis3->count);
34092
34093 wake_up_interruptible(&lis3->misc_wait);
34094 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34095@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34096 if (lis3->pm_dev)
34097 pm_runtime_get_sync(lis3->pm_dev);
34098
34099- atomic_set(&lis3->count, 0);
34100+ atomic_set_unchecked(&lis3->count, 0);
34101 return 0;
34102 }
34103
34104@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34105 add_wait_queue(&lis3->misc_wait, &wait);
34106 while (true) {
34107 set_current_state(TASK_INTERRUPTIBLE);
34108- data = atomic_xchg(&lis3->count, 0);
34109+ data = atomic_xchg_unchecked(&lis3->count, 0);
34110 if (data)
34111 break;
34112
34113@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34114 struct lis3lv02d, miscdev);
34115
34116 poll_wait(file, &lis3->misc_wait, wait);
34117- if (atomic_read(&lis3->count))
34118+ if (atomic_read_unchecked(&lis3->count))
34119 return POLLIN | POLLRDNORM;
34120 return 0;
34121 }
34122diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34123index 2b1482a..5d33616 100644
34124--- a/drivers/misc/lis3lv02d/lis3lv02d.h
34125+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34126@@ -266,7 +266,7 @@ struct lis3lv02d {
34127 struct input_polled_dev *idev; /* input device */
34128 struct platform_device *pdev; /* platform device */
34129 struct regulator_bulk_data regulators[2];
34130- atomic_t count; /* interrupt count after last read */
34131+ atomic_unchecked_t count; /* interrupt count after last read */
34132 union axis_conversion ac; /* hw -> logical axis */
34133 int mapped_btns[3];
34134
34135diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
34136index 28adefe..08aad69 100644
34137--- a/drivers/misc/lkdtm.c
34138+++ b/drivers/misc/lkdtm.c
34139@@ -477,6 +477,8 @@ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
34140 int i, n, out;
34141
34142 buf = (char *)__get_free_page(GFP_KERNEL);
34143+ if (buf == NULL)
34144+ return -ENOMEM;
34145
34146 n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
34147 for (i = 0; i < ARRAY_SIZE(cp_type); i++)
34148diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34149index 2f30bad..c4c13d0 100644
34150--- a/drivers/misc/sgi-gru/gruhandles.c
34151+++ b/drivers/misc/sgi-gru/gruhandles.c
34152@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34153 unsigned long nsec;
34154
34155 nsec = CLKS2NSEC(clks);
34156- atomic_long_inc(&mcs_op_statistics[op].count);
34157- atomic_long_add(nsec, &mcs_op_statistics[op].total);
34158+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34159+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34160 if (mcs_op_statistics[op].max < nsec)
34161 mcs_op_statistics[op].max = nsec;
34162 }
34163diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34164index 950dbe9..eeef0f8 100644
34165--- a/drivers/misc/sgi-gru/gruprocfs.c
34166+++ b/drivers/misc/sgi-gru/gruprocfs.c
34167@@ -32,9 +32,9 @@
34168
34169 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34170
34171-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34172+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34173 {
34174- unsigned long val = atomic_long_read(v);
34175+ unsigned long val = atomic_long_read_unchecked(v);
34176
34177 seq_printf(s, "%16lu %s\n", val, id);
34178 }
34179@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34180
34181 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34182 for (op = 0; op < mcsop_last; op++) {
34183- count = atomic_long_read(&mcs_op_statistics[op].count);
34184- total = atomic_long_read(&mcs_op_statistics[op].total);
34185+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34186+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34187 max = mcs_op_statistics[op].max;
34188 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34189 count ? total / count : 0, max);
34190diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34191index 5c3ce24..4915ccb 100644
34192--- a/drivers/misc/sgi-gru/grutables.h
34193+++ b/drivers/misc/sgi-gru/grutables.h
34194@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34195 * GRU statistics.
34196 */
34197 struct gru_stats_s {
34198- atomic_long_t vdata_alloc;
34199- atomic_long_t vdata_free;
34200- atomic_long_t gts_alloc;
34201- atomic_long_t gts_free;
34202- atomic_long_t gms_alloc;
34203- atomic_long_t gms_free;
34204- atomic_long_t gts_double_allocate;
34205- atomic_long_t assign_context;
34206- atomic_long_t assign_context_failed;
34207- atomic_long_t free_context;
34208- atomic_long_t load_user_context;
34209- atomic_long_t load_kernel_context;
34210- atomic_long_t lock_kernel_context;
34211- atomic_long_t unlock_kernel_context;
34212- atomic_long_t steal_user_context;
34213- atomic_long_t steal_kernel_context;
34214- atomic_long_t steal_context_failed;
34215- atomic_long_t nopfn;
34216- atomic_long_t asid_new;
34217- atomic_long_t asid_next;
34218- atomic_long_t asid_wrap;
34219- atomic_long_t asid_reuse;
34220- atomic_long_t intr;
34221- atomic_long_t intr_cbr;
34222- atomic_long_t intr_tfh;
34223- atomic_long_t intr_spurious;
34224- atomic_long_t intr_mm_lock_failed;
34225- atomic_long_t call_os;
34226- atomic_long_t call_os_wait_queue;
34227- atomic_long_t user_flush_tlb;
34228- atomic_long_t user_unload_context;
34229- atomic_long_t user_exception;
34230- atomic_long_t set_context_option;
34231- atomic_long_t check_context_retarget_intr;
34232- atomic_long_t check_context_unload;
34233- atomic_long_t tlb_dropin;
34234- atomic_long_t tlb_preload_page;
34235- atomic_long_t tlb_dropin_fail_no_asid;
34236- atomic_long_t tlb_dropin_fail_upm;
34237- atomic_long_t tlb_dropin_fail_invalid;
34238- atomic_long_t tlb_dropin_fail_range_active;
34239- atomic_long_t tlb_dropin_fail_idle;
34240- atomic_long_t tlb_dropin_fail_fmm;
34241- atomic_long_t tlb_dropin_fail_no_exception;
34242- atomic_long_t tfh_stale_on_fault;
34243- atomic_long_t mmu_invalidate_range;
34244- atomic_long_t mmu_invalidate_page;
34245- atomic_long_t flush_tlb;
34246- atomic_long_t flush_tlb_gru;
34247- atomic_long_t flush_tlb_gru_tgh;
34248- atomic_long_t flush_tlb_gru_zero_asid;
34249+ atomic_long_unchecked_t vdata_alloc;
34250+ atomic_long_unchecked_t vdata_free;
34251+ atomic_long_unchecked_t gts_alloc;
34252+ atomic_long_unchecked_t gts_free;
34253+ atomic_long_unchecked_t gms_alloc;
34254+ atomic_long_unchecked_t gms_free;
34255+ atomic_long_unchecked_t gts_double_allocate;
34256+ atomic_long_unchecked_t assign_context;
34257+ atomic_long_unchecked_t assign_context_failed;
34258+ atomic_long_unchecked_t free_context;
34259+ atomic_long_unchecked_t load_user_context;
34260+ atomic_long_unchecked_t load_kernel_context;
34261+ atomic_long_unchecked_t lock_kernel_context;
34262+ atomic_long_unchecked_t unlock_kernel_context;
34263+ atomic_long_unchecked_t steal_user_context;
34264+ atomic_long_unchecked_t steal_kernel_context;
34265+ atomic_long_unchecked_t steal_context_failed;
34266+ atomic_long_unchecked_t nopfn;
34267+ atomic_long_unchecked_t asid_new;
34268+ atomic_long_unchecked_t asid_next;
34269+ atomic_long_unchecked_t asid_wrap;
34270+ atomic_long_unchecked_t asid_reuse;
34271+ atomic_long_unchecked_t intr;
34272+ atomic_long_unchecked_t intr_cbr;
34273+ atomic_long_unchecked_t intr_tfh;
34274+ atomic_long_unchecked_t intr_spurious;
34275+ atomic_long_unchecked_t intr_mm_lock_failed;
34276+ atomic_long_unchecked_t call_os;
34277+ atomic_long_unchecked_t call_os_wait_queue;
34278+ atomic_long_unchecked_t user_flush_tlb;
34279+ atomic_long_unchecked_t user_unload_context;
34280+ atomic_long_unchecked_t user_exception;
34281+ atomic_long_unchecked_t set_context_option;
34282+ atomic_long_unchecked_t check_context_retarget_intr;
34283+ atomic_long_unchecked_t check_context_unload;
34284+ atomic_long_unchecked_t tlb_dropin;
34285+ atomic_long_unchecked_t tlb_preload_page;
34286+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34287+ atomic_long_unchecked_t tlb_dropin_fail_upm;
34288+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
34289+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
34290+ atomic_long_unchecked_t tlb_dropin_fail_idle;
34291+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
34292+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34293+ atomic_long_unchecked_t tfh_stale_on_fault;
34294+ atomic_long_unchecked_t mmu_invalidate_range;
34295+ atomic_long_unchecked_t mmu_invalidate_page;
34296+ atomic_long_unchecked_t flush_tlb;
34297+ atomic_long_unchecked_t flush_tlb_gru;
34298+ atomic_long_unchecked_t flush_tlb_gru_tgh;
34299+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34300
34301- atomic_long_t copy_gpa;
34302- atomic_long_t read_gpa;
34303+ atomic_long_unchecked_t copy_gpa;
34304+ atomic_long_unchecked_t read_gpa;
34305
34306- atomic_long_t mesq_receive;
34307- atomic_long_t mesq_receive_none;
34308- atomic_long_t mesq_send;
34309- atomic_long_t mesq_send_failed;
34310- atomic_long_t mesq_noop;
34311- atomic_long_t mesq_send_unexpected_error;
34312- atomic_long_t mesq_send_lb_overflow;
34313- atomic_long_t mesq_send_qlimit_reached;
34314- atomic_long_t mesq_send_amo_nacked;
34315- atomic_long_t mesq_send_put_nacked;
34316- atomic_long_t mesq_page_overflow;
34317- atomic_long_t mesq_qf_locked;
34318- atomic_long_t mesq_qf_noop_not_full;
34319- atomic_long_t mesq_qf_switch_head_failed;
34320- atomic_long_t mesq_qf_unexpected_error;
34321- atomic_long_t mesq_noop_unexpected_error;
34322- atomic_long_t mesq_noop_lb_overflow;
34323- atomic_long_t mesq_noop_qlimit_reached;
34324- atomic_long_t mesq_noop_amo_nacked;
34325- atomic_long_t mesq_noop_put_nacked;
34326- atomic_long_t mesq_noop_page_overflow;
34327+ atomic_long_unchecked_t mesq_receive;
34328+ atomic_long_unchecked_t mesq_receive_none;
34329+ atomic_long_unchecked_t mesq_send;
34330+ atomic_long_unchecked_t mesq_send_failed;
34331+ atomic_long_unchecked_t mesq_noop;
34332+ atomic_long_unchecked_t mesq_send_unexpected_error;
34333+ atomic_long_unchecked_t mesq_send_lb_overflow;
34334+ atomic_long_unchecked_t mesq_send_qlimit_reached;
34335+ atomic_long_unchecked_t mesq_send_amo_nacked;
34336+ atomic_long_unchecked_t mesq_send_put_nacked;
34337+ atomic_long_unchecked_t mesq_page_overflow;
34338+ atomic_long_unchecked_t mesq_qf_locked;
34339+ atomic_long_unchecked_t mesq_qf_noop_not_full;
34340+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
34341+ atomic_long_unchecked_t mesq_qf_unexpected_error;
34342+ atomic_long_unchecked_t mesq_noop_unexpected_error;
34343+ atomic_long_unchecked_t mesq_noop_lb_overflow;
34344+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
34345+ atomic_long_unchecked_t mesq_noop_amo_nacked;
34346+ atomic_long_unchecked_t mesq_noop_put_nacked;
34347+ atomic_long_unchecked_t mesq_noop_page_overflow;
34348
34349 };
34350
34351@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34352 tghop_invalidate, mcsop_last};
34353
34354 struct mcs_op_statistic {
34355- atomic_long_t count;
34356- atomic_long_t total;
34357+ atomic_long_unchecked_t count;
34358+ atomic_long_unchecked_t total;
34359 unsigned long max;
34360 };
34361
34362@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34363
34364 #define STAT(id) do { \
34365 if (gru_options & OPT_STATS) \
34366- atomic_long_inc(&gru_stats.id); \
34367+ atomic_long_inc_unchecked(&gru_stats.id); \
34368 } while (0)
34369
34370 #ifdef CONFIG_SGI_GRU_DEBUG
34371diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34372index c862cd4..0d176fe 100644
34373--- a/drivers/misc/sgi-xp/xp.h
34374+++ b/drivers/misc/sgi-xp/xp.h
34375@@ -288,7 +288,7 @@ struct xpc_interface {
34376 xpc_notify_func, void *);
34377 void (*received) (short, int, void *);
34378 enum xp_retval (*partid_to_nasids) (short, void *);
34379-};
34380+} __no_const;
34381
34382 extern struct xpc_interface xpc_interface;
34383
34384diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34385index b94d5f7..7f494c5 100644
34386--- a/drivers/misc/sgi-xp/xpc.h
34387+++ b/drivers/misc/sgi-xp/xpc.h
34388@@ -835,6 +835,7 @@ struct xpc_arch_operations {
34389 void (*received_payload) (struct xpc_channel *, void *);
34390 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34391 };
34392+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34393
34394 /* struct xpc_partition act_state values (for XPC HB) */
34395
34396@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34397 /* found in xpc_main.c */
34398 extern struct device *xpc_part;
34399 extern struct device *xpc_chan;
34400-extern struct xpc_arch_operations xpc_arch_ops;
34401+extern xpc_arch_operations_no_const xpc_arch_ops;
34402 extern int xpc_disengage_timelimit;
34403 extern int xpc_disengage_timedout;
34404 extern int xpc_activate_IRQ_rcvd;
34405diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34406index 8d082b4..aa749ae 100644
34407--- a/drivers/misc/sgi-xp/xpc_main.c
34408+++ b/drivers/misc/sgi-xp/xpc_main.c
34409@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34410 .notifier_call = xpc_system_die,
34411 };
34412
34413-struct xpc_arch_operations xpc_arch_ops;
34414+xpc_arch_operations_no_const xpc_arch_ops;
34415
34416 /*
34417 * Timer function to enforce the timelimit on the partition disengage.
34418diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
34419index 2b62232..acfaeeb 100644
34420--- a/drivers/misc/ti-st/st_core.c
34421+++ b/drivers/misc/ti-st/st_core.c
34422@@ -349,6 +349,11 @@ void st_int_recv(void *disc_data,
34423 st_gdata->rx_skb = alloc_skb(
34424 st_gdata->list[type]->max_frame_size,
34425 GFP_ATOMIC);
34426+ if (st_gdata->rx_skb == NULL) {
34427+ pr_err("out of memory: dropping\n");
34428+ goto done;
34429+ }
34430+
34431 skb_reserve(st_gdata->rx_skb,
34432 st_gdata->list[type]->reserve);
34433 /* next 2 required for BT only */
34434diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34435index 69ef0be..f3ef91e 100644
34436--- a/drivers/mmc/host/sdhci-pci.c
34437+++ b/drivers/mmc/host/sdhci-pci.c
34438@@ -652,7 +652,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34439 .probe = via_probe,
34440 };
34441
34442-static const struct pci_device_id pci_ids[] __devinitdata = {
34443+static const struct pci_device_id pci_ids[] __devinitconst = {
34444 {
34445 .vendor = PCI_VENDOR_ID_RICOH,
34446 .device = PCI_DEVICE_ID_RICOH_R5C822,
34447diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34448index a4eb8b5..8c0628f 100644
34449--- a/drivers/mtd/devices/doc2000.c
34450+++ b/drivers/mtd/devices/doc2000.c
34451@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34452
34453 /* The ECC will not be calculated correctly if less than 512 is written */
34454 /* DBB-
34455- if (len != 0x200 && eccbuf)
34456+ if (len != 0x200)
34457 printk(KERN_WARNING
34458 "ECC needs a full sector write (adr: %lx size %lx)\n",
34459 (long) to, (long) len);
34460diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34461index 0650aaf..7718762 100644
34462--- a/drivers/mtd/nand/denali.c
34463+++ b/drivers/mtd/nand/denali.c
34464@@ -26,6 +26,7 @@
34465 #include <linux/pci.h>
34466 #include <linux/mtd/mtd.h>
34467 #include <linux/module.h>
34468+#include <linux/slab.h>
34469
34470 #include "denali.h"
34471
34472diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34473index 51b9d6a..52af9a7 100644
34474--- a/drivers/mtd/nftlmount.c
34475+++ b/drivers/mtd/nftlmount.c
34476@@ -24,6 +24,7 @@
34477 #include <asm/errno.h>
34478 #include <linux/delay.h>
34479 #include <linux/slab.h>
34480+#include <linux/sched.h>
34481 #include <linux/mtd/mtd.h>
34482 #include <linux/mtd/nand.h>
34483 #include <linux/mtd/nftl.h>
34484diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34485index 6762dc4..9956862 100644
34486--- a/drivers/net/ethernet/atheros/atlx/atl2.c
34487+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34488@@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34489 */
34490
34491 #define ATL2_PARAM(X, desc) \
34492- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34493+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34494 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34495 MODULE_PARM_DESC(X, desc);
34496 #else
34497diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34498index efd80bd..21fcff0 100644
34499--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34500+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34501@@ -487,7 +487,7 @@ struct bnx2x_rx_mode_obj {
34502
34503 int (*wait_comp)(struct bnx2x *bp,
34504 struct bnx2x_rx_mode_ramrod_params *p);
34505-};
34506+} __no_const;
34507
34508 /********************** Set multicast group ***********************************/
34509
34510diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34511index 93865f8..5448741 100644
34512--- a/drivers/net/ethernet/broadcom/tg3.h
34513+++ b/drivers/net/ethernet/broadcom/tg3.h
34514@@ -140,6 +140,7 @@
34515 #define CHIPREV_ID_5750_A0 0x4000
34516 #define CHIPREV_ID_5750_A1 0x4001
34517 #define CHIPREV_ID_5750_A3 0x4003
34518+#define CHIPREV_ID_5750_C1 0x4201
34519 #define CHIPREV_ID_5750_C2 0x4202
34520 #define CHIPREV_ID_5752_A0_HW 0x5000
34521 #define CHIPREV_ID_5752_A0 0x6000
34522diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34523index c4e8643..0979484 100644
34524--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34525+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34526@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34527 */
34528 struct l2t_skb_cb {
34529 arp_failure_handler_func arp_failure_handler;
34530-};
34531+} __no_const;
34532
34533 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34534
34535diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34536index d3cd489..0fd52dd 100644
34537--- a/drivers/net/ethernet/dec/tulip/de4x5.c
34538+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34539@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34540 for (i=0; i<ETH_ALEN; i++) {
34541 tmp.addr[i] = dev->dev_addr[i];
34542 }
34543- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34544+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34545 break;
34546
34547 case DE4X5_SET_HWADDR: /* Set the hardware address */
34548@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34549 spin_lock_irqsave(&lp->lock, flags);
34550 memcpy(&statbuf, &lp->pktStats, ioc->len);
34551 spin_unlock_irqrestore(&lp->lock, flags);
34552- if (copy_to_user(ioc->data, &statbuf, ioc->len))
34553+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34554 return -EFAULT;
34555 break;
34556 }
34557diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34558index ed7d1dc..d426748 100644
34559--- a/drivers/net/ethernet/dec/tulip/eeprom.c
34560+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34561@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34562 {NULL}};
34563
34564
34565-static const char *block_name[] __devinitdata = {
34566+static const char *block_name[] __devinitconst = {
34567 "21140 non-MII",
34568 "21140 MII PHY",
34569 "21142 Serial PHY",
34570diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34571index 75d45f8..3d9c55b 100644
34572--- a/drivers/net/ethernet/dec/tulip/uli526x.c
34573+++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34574@@ -129,7 +129,7 @@ struct uli526x_board_info {
34575 struct uli_phy_ops {
34576 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34577 u16 (*read)(struct uli526x_board_info *, u8, u8);
34578- } phy;
34579+ } __no_const phy;
34580 struct net_device *next_dev; /* next device */
34581 struct pci_dev *pdev; /* PCI device */
34582 spinlock_t lock;
34583diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34584index 4d1ffca..7c1ec4d 100644
34585--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34586+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34587@@ -236,7 +236,7 @@ struct pci_id_info {
34588 int drv_flags; /* Driver use, intended as capability flags. */
34589 };
34590
34591-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34592+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34593 { /* Sometime a Level-One switch card. */
34594 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34595 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34596diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34597index d7bb52a..3b83588 100644
34598--- a/drivers/net/ethernet/dlink/sundance.c
34599+++ b/drivers/net/ethernet/dlink/sundance.c
34600@@ -218,7 +218,7 @@ enum {
34601 struct pci_id_info {
34602 const char *name;
34603 };
34604-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34605+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34606 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34607 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34608 {"D-Link DFE-580TX 4 port Server Adapter"},
34609diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34610index 501dfa9..aa9ec11 100644
34611--- a/drivers/net/ethernet/emulex/benet/be_main.c
34612+++ b/drivers/net/ethernet/emulex/benet/be_main.c
34613@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34614
34615 if (wrapped)
34616 newacc += 65536;
34617- ACCESS_ONCE(*acc) = newacc;
34618+ ACCESS_ONCE_RW(*acc) = newacc;
34619 }
34620
34621 void be_parse_stats(struct be_adapter *adapter)
34622diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34623index 16b0704..d2c07d7 100644
34624--- a/drivers/net/ethernet/faraday/ftgmac100.c
34625+++ b/drivers/net/ethernet/faraday/ftgmac100.c
34626@@ -31,6 +31,8 @@
34627 #include <linux/netdevice.h>
34628 #include <linux/phy.h>
34629 #include <linux/platform_device.h>
34630+#include <linux/interrupt.h>
34631+#include <linux/irqreturn.h>
34632 #include <net/ip.h>
34633
34634 #include "ftgmac100.h"
34635diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34636index 829b109..4ae5f6a 100644
34637--- a/drivers/net/ethernet/faraday/ftmac100.c
34638+++ b/drivers/net/ethernet/faraday/ftmac100.c
34639@@ -31,6 +31,8 @@
34640 #include <linux/module.h>
34641 #include <linux/netdevice.h>
34642 #include <linux/platform_device.h>
34643+#include <linux/interrupt.h>
34644+#include <linux/irqreturn.h>
34645
34646 #include "ftmac100.h"
34647
34648diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34649index 9d71c9c..0e4a0ac 100644
34650--- a/drivers/net/ethernet/fealnx.c
34651+++ b/drivers/net/ethernet/fealnx.c
34652@@ -150,7 +150,7 @@ struct chip_info {
34653 int flags;
34654 };
34655
34656-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34657+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34658 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34659 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34660 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34661diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34662index 6e6fffb..588f361 100644
34663--- a/drivers/net/ethernet/intel/e1000e/e1000.h
34664+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34665@@ -181,7 +181,7 @@ struct e1000_info;
34666 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34667 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34668 E1000_TXDCTL_COUNT_DESC | \
34669- (5 << 16) | /* wthresh must be +1 more than desired */\
34670+ (1 << 16) | /* wthresh must be +1 more than desired */\
34671 (1 << 8) | /* hthresh */ \
34672 0x1f) /* pthresh */
34673
34674diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34675index ed5b409..ec37828 100644
34676--- a/drivers/net/ethernet/intel/e1000e/hw.h
34677+++ b/drivers/net/ethernet/intel/e1000e/hw.h
34678@@ -797,6 +797,7 @@ struct e1000_mac_operations {
34679 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34680 s32 (*read_mac_addr)(struct e1000_hw *);
34681 };
34682+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34683
34684 /*
34685 * When to use various PHY register access functions:
34686@@ -837,6 +838,7 @@ struct e1000_phy_operations {
34687 void (*power_up)(struct e1000_hw *);
34688 void (*power_down)(struct e1000_hw *);
34689 };
34690+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34691
34692 /* Function pointers for the NVM. */
34693 struct e1000_nvm_operations {
34694@@ -849,9 +851,10 @@ struct e1000_nvm_operations {
34695 s32 (*validate)(struct e1000_hw *);
34696 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34697 };
34698+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34699
34700 struct e1000_mac_info {
34701- struct e1000_mac_operations ops;
34702+ e1000_mac_operations_no_const ops;
34703 u8 addr[ETH_ALEN];
34704 u8 perm_addr[ETH_ALEN];
34705
34706@@ -892,7 +895,7 @@ struct e1000_mac_info {
34707 };
34708
34709 struct e1000_phy_info {
34710- struct e1000_phy_operations ops;
34711+ e1000_phy_operations_no_const ops;
34712
34713 enum e1000_phy_type type;
34714
34715@@ -926,7 +929,7 @@ struct e1000_phy_info {
34716 };
34717
34718 struct e1000_nvm_info {
34719- struct e1000_nvm_operations ops;
34720+ e1000_nvm_operations_no_const ops;
34721
34722 enum e1000_nvm_type type;
34723 enum e1000_nvm_override override;
34724diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34725index c2a51dc..c2bd262 100644
34726--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34727+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34728@@ -327,6 +327,7 @@ struct e1000_mac_operations {
34729 void (*release_swfw_sync)(struct e1000_hw *, u16);
34730
34731 };
34732+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34733
34734 struct e1000_phy_operations {
34735 s32 (*acquire)(struct e1000_hw *);
34736@@ -343,6 +344,7 @@ struct e1000_phy_operations {
34737 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34738 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34739 };
34740+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34741
34742 struct e1000_nvm_operations {
34743 s32 (*acquire)(struct e1000_hw *);
34744@@ -353,6 +355,7 @@ struct e1000_nvm_operations {
34745 s32 (*validate)(struct e1000_hw *);
34746 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
34747 };
34748+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34749
34750 struct e1000_info {
34751 s32 (*get_invariants)(struct e1000_hw *);
34752@@ -364,7 +367,7 @@ struct e1000_info {
34753 extern const struct e1000_info e1000_82575_info;
34754
34755 struct e1000_mac_info {
34756- struct e1000_mac_operations ops;
34757+ e1000_mac_operations_no_const ops;
34758
34759 u8 addr[6];
34760 u8 perm_addr[6];
34761@@ -402,7 +405,7 @@ struct e1000_mac_info {
34762 };
34763
34764 struct e1000_phy_info {
34765- struct e1000_phy_operations ops;
34766+ e1000_phy_operations_no_const ops;
34767
34768 enum e1000_phy_type type;
34769
34770@@ -437,7 +440,7 @@ struct e1000_phy_info {
34771 };
34772
34773 struct e1000_nvm_info {
34774- struct e1000_nvm_operations ops;
34775+ e1000_nvm_operations_no_const ops;
34776 enum e1000_nvm_type type;
34777 enum e1000_nvm_override override;
34778
34779@@ -482,6 +485,7 @@ struct e1000_mbx_operations {
34780 s32 (*check_for_ack)(struct e1000_hw *, u16);
34781 s32 (*check_for_rst)(struct e1000_hw *, u16);
34782 };
34783+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34784
34785 struct e1000_mbx_stats {
34786 u32 msgs_tx;
34787@@ -493,7 +497,7 @@ struct e1000_mbx_stats {
34788 };
34789
34790 struct e1000_mbx_info {
34791- struct e1000_mbx_operations ops;
34792+ e1000_mbx_operations_no_const ops;
34793 struct e1000_mbx_stats stats;
34794 u32 timeout;
34795 u32 usec_delay;
34796diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34797index 57db3c6..aa825fc 100644
34798--- a/drivers/net/ethernet/intel/igbvf/vf.h
34799+++ b/drivers/net/ethernet/intel/igbvf/vf.h
34800@@ -189,9 +189,10 @@ struct e1000_mac_operations {
34801 s32 (*read_mac_addr)(struct e1000_hw *);
34802 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34803 };
34804+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34805
34806 struct e1000_mac_info {
34807- struct e1000_mac_operations ops;
34808+ e1000_mac_operations_no_const ops;
34809 u8 addr[6];
34810 u8 perm_addr[6];
34811
34812@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34813 s32 (*check_for_ack)(struct e1000_hw *);
34814 s32 (*check_for_rst)(struct e1000_hw *);
34815 };
34816+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34817
34818 struct e1000_mbx_stats {
34819 u32 msgs_tx;
34820@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34821 };
34822
34823 struct e1000_mbx_info {
34824- struct e1000_mbx_operations ops;
34825+ e1000_mbx_operations_no_const ops;
34826 struct e1000_mbx_stats stats;
34827 u32 timeout;
34828 u32 usec_delay;
34829diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34830index dcebd12..c1fe8be 100644
34831--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34832+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34833@@ -805,7 +805,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
34834 /* store the new cycle speed */
34835 adapter->cycle_speed = cycle_speed;
34836
34837- ACCESS_ONCE(adapter->base_incval) = incval;
34838+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
34839 smp_mb();
34840
34841 /* grab the ptp lock */
34842diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34843index 204848d..d8aeaec 100644
34844--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34845+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34846@@ -2791,6 +2791,7 @@ struct ixgbe_eeprom_operations {
34847 s32 (*update_checksum)(struct ixgbe_hw *);
34848 u16 (*calc_checksum)(struct ixgbe_hw *);
34849 };
34850+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34851
34852 struct ixgbe_mac_operations {
34853 s32 (*init_hw)(struct ixgbe_hw *);
34854@@ -2856,6 +2857,7 @@ struct ixgbe_mac_operations {
34855 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
34856 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
34857 };
34858+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34859
34860 struct ixgbe_phy_operations {
34861 s32 (*identify)(struct ixgbe_hw *);
34862@@ -2875,9 +2877,10 @@ struct ixgbe_phy_operations {
34863 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34864 s32 (*check_overtemp)(struct ixgbe_hw *);
34865 };
34866+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34867
34868 struct ixgbe_eeprom_info {
34869- struct ixgbe_eeprom_operations ops;
34870+ ixgbe_eeprom_operations_no_const ops;
34871 enum ixgbe_eeprom_type type;
34872 u32 semaphore_delay;
34873 u16 word_size;
34874@@ -2887,7 +2890,7 @@ struct ixgbe_eeprom_info {
34875
34876 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34877 struct ixgbe_mac_info {
34878- struct ixgbe_mac_operations ops;
34879+ ixgbe_mac_operations_no_const ops;
34880 enum ixgbe_mac_type type;
34881 u8 addr[ETH_ALEN];
34882 u8 perm_addr[ETH_ALEN];
34883@@ -2916,7 +2919,7 @@ struct ixgbe_mac_info {
34884 };
34885
34886 struct ixgbe_phy_info {
34887- struct ixgbe_phy_operations ops;
34888+ ixgbe_phy_operations_no_const ops;
34889 struct mdio_if_info mdio;
34890 enum ixgbe_phy_type type;
34891 u32 id;
34892@@ -2944,6 +2947,7 @@ struct ixgbe_mbx_operations {
34893 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34894 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34895 };
34896+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34897
34898 struct ixgbe_mbx_stats {
34899 u32 msgs_tx;
34900@@ -2955,7 +2959,7 @@ struct ixgbe_mbx_stats {
34901 };
34902
34903 struct ixgbe_mbx_info {
34904- struct ixgbe_mbx_operations ops;
34905+ ixgbe_mbx_operations_no_const ops;
34906 struct ixgbe_mbx_stats stats;
34907 u32 timeout;
34908 u32 usec_delay;
34909diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34910index 25c951d..cc7cf33 100644
34911--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34912+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34913@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34914 s32 (*clear_vfta)(struct ixgbe_hw *);
34915 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34916 };
34917+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34918
34919 enum ixgbe_mac_type {
34920 ixgbe_mac_unknown = 0,
34921@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34922 };
34923
34924 struct ixgbe_mac_info {
34925- struct ixgbe_mac_operations ops;
34926+ ixgbe_mac_operations_no_const ops;
34927 u8 addr[6];
34928 u8 perm_addr[6];
34929
34930@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
34931 s32 (*check_for_ack)(struct ixgbe_hw *);
34932 s32 (*check_for_rst)(struct ixgbe_hw *);
34933 };
34934+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34935
34936 struct ixgbe_mbx_stats {
34937 u32 msgs_tx;
34938@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
34939 };
34940
34941 struct ixgbe_mbx_info {
34942- struct ixgbe_mbx_operations ops;
34943+ ixgbe_mbx_operations_no_const ops;
34944 struct ixgbe_mbx_stats stats;
34945 u32 timeout;
34946 u32 udelay;
34947diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
34948index a0313de..e83a572 100644
34949--- a/drivers/net/ethernet/mellanox/mlx4/main.c
34950+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
34951@@ -41,6 +41,7 @@
34952 #include <linux/slab.h>
34953 #include <linux/io-mapping.h>
34954 #include <linux/delay.h>
34955+#include <linux/sched.h>
34956
34957 #include <linux/mlx4/device.h>
34958 #include <linux/mlx4/doorbell.h>
34959diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34960index 5046a64..71ca936 100644
34961--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
34962+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34963@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34964 void (*link_down)(struct __vxge_hw_device *devh);
34965 void (*crit_err)(struct __vxge_hw_device *devh,
34966 enum vxge_hw_event type, u64 ext_data);
34967-};
34968+} __no_const;
34969
34970 /*
34971 * struct __vxge_hw_blockpool_entry - Block private data structure
34972diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34973index 4a518a3..936b334 100644
34974--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34975+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34976@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
34977 struct vxge_hw_mempool_dma *dma_object,
34978 u32 index,
34979 u32 is_last);
34980-};
34981+} __no_const;
34982
34983 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
34984 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
34985diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
34986index d7a04e0..76d0431 100644
34987--- a/drivers/net/ethernet/realtek/r8169.c
34988+++ b/drivers/net/ethernet/realtek/r8169.c
34989@@ -723,22 +723,22 @@ struct rtl8169_private {
34990 struct mdio_ops {
34991 void (*write)(void __iomem *, int, int);
34992 int (*read)(void __iomem *, int);
34993- } mdio_ops;
34994+ } __no_const mdio_ops;
34995
34996 struct pll_power_ops {
34997 void (*down)(struct rtl8169_private *);
34998 void (*up)(struct rtl8169_private *);
34999- } pll_power_ops;
35000+ } __no_const pll_power_ops;
35001
35002 struct jumbo_ops {
35003 void (*enable)(struct rtl8169_private *);
35004 void (*disable)(struct rtl8169_private *);
35005- } jumbo_ops;
35006+ } __no_const jumbo_ops;
35007
35008 struct csi_ops {
35009 void (*write)(void __iomem *, int, int);
35010 u32 (*read)(void __iomem *, int);
35011- } csi_ops;
35012+ } __no_const csi_ops;
35013
35014 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35015 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35016diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35017index 4613591..d816601 100644
35018--- a/drivers/net/ethernet/sis/sis190.c
35019+++ b/drivers/net/ethernet/sis/sis190.c
35020@@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35021 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35022 struct net_device *dev)
35023 {
35024- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35025+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35026 struct sis190_private *tp = netdev_priv(dev);
35027 struct pci_dev *isa_bridge;
35028 u8 reg, tmp8;
35029diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35030index c07cfe9..81cbf7e 100644
35031--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35032+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35033@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35034
35035 writel(value, ioaddr + MMC_CNTRL);
35036
35037- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35038- MMC_CNTRL, value);
35039+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35040+// MMC_CNTRL, value);
35041 }
35042
35043 /* To mask all all interrupts.*/
35044diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35045index 2857ab0..9a1f9b0 100644
35046--- a/drivers/net/hyperv/hyperv_net.h
35047+++ b/drivers/net/hyperv/hyperv_net.h
35048@@ -99,7 +99,7 @@ struct rndis_device {
35049
35050 enum rndis_device_state state;
35051 bool link_state;
35052- atomic_t new_req_id;
35053+ atomic_unchecked_t new_req_id;
35054
35055 spinlock_t request_lock;
35056 struct list_head req_list;
35057diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35058index 981ebb1..b34959b 100644
35059--- a/drivers/net/hyperv/rndis_filter.c
35060+++ b/drivers/net/hyperv/rndis_filter.c
35061@@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35062 * template
35063 */
35064 set = &rndis_msg->msg.set_req;
35065- set->req_id = atomic_inc_return(&dev->new_req_id);
35066+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35067
35068 /* Add to the request list */
35069 spin_lock_irqsave(&dev->request_lock, flags);
35070@@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35071
35072 /* Setup the rndis set */
35073 halt = &request->request_msg.msg.halt_req;
35074- halt->req_id = atomic_inc_return(&dev->new_req_id);
35075+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35076
35077 /* Ignore return since this msg is optional. */
35078 rndis_filter_send_request(dev, request);
35079diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35080index 5c05572..389610b 100644
35081--- a/drivers/net/ppp/ppp_generic.c
35082+++ b/drivers/net/ppp/ppp_generic.c
35083@@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35084 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35085 struct ppp_stats stats;
35086 struct ppp_comp_stats cstats;
35087- char *vers;
35088
35089 switch (cmd) {
35090 case SIOCGPPPSTATS:
35091@@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35092 break;
35093
35094 case SIOCGPPPVER:
35095- vers = PPP_VERSION;
35096- if (copy_to_user(addr, vers, strlen(vers) + 1))
35097+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35098 break;
35099 err = 0;
35100 break;
35101diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35102index 62f30b4..ff99dfd 100644
35103--- a/drivers/net/usb/hso.c
35104+++ b/drivers/net/usb/hso.c
35105@@ -71,7 +71,7 @@
35106 #include <asm/byteorder.h>
35107 #include <linux/serial_core.h>
35108 #include <linux/serial.h>
35109-
35110+#include <asm/local.h>
35111
35112 #define MOD_AUTHOR "Option Wireless"
35113 #define MOD_DESCRIPTION "USB High Speed Option driver"
35114@@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35115 struct urb *urb;
35116
35117 urb = serial->rx_urb[0];
35118- if (serial->port.count > 0) {
35119+ if (atomic_read(&serial->port.count) > 0) {
35120 count = put_rxbuf_data(urb, serial);
35121 if (count == -1)
35122 return;
35123@@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35124 DUMP1(urb->transfer_buffer, urb->actual_length);
35125
35126 /* Anyone listening? */
35127- if (serial->port.count == 0)
35128+ if (atomic_read(&serial->port.count) == 0)
35129 return;
35130
35131 if (status == 0) {
35132@@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35133 tty_port_tty_set(&serial->port, tty);
35134
35135 /* check for port already opened, if not set the termios */
35136- serial->port.count++;
35137- if (serial->port.count == 1) {
35138+ if (atomic_inc_return(&serial->port.count) == 1) {
35139 serial->rx_state = RX_IDLE;
35140 /* Force default termio settings */
35141 _hso_serial_set_termios(tty, NULL);
35142@@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35143 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35144 if (result) {
35145 hso_stop_serial_device(serial->parent);
35146- serial->port.count--;
35147+ atomic_dec(&serial->port.count);
35148 kref_put(&serial->parent->ref, hso_serial_ref_free);
35149 }
35150 } else {
35151@@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35152
35153 /* reset the rts and dtr */
35154 /* do the actual close */
35155- serial->port.count--;
35156+ atomic_dec(&serial->port.count);
35157
35158- if (serial->port.count <= 0) {
35159- serial->port.count = 0;
35160+ if (atomic_read(&serial->port.count) <= 0) {
35161+ atomic_set(&serial->port.count, 0);
35162 tty_port_tty_set(&serial->port, NULL);
35163 if (!usb_gone)
35164 hso_stop_serial_device(serial->parent);
35165@@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35166
35167 /* the actual setup */
35168 spin_lock_irqsave(&serial->serial_lock, flags);
35169- if (serial->port.count)
35170+ if (atomic_read(&serial->port.count))
35171 _hso_serial_set_termios(tty, old);
35172 else
35173 tty->termios = old;
35174@@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35175 D1("Pending read interrupt on port %d\n", i);
35176 spin_lock(&serial->serial_lock);
35177 if (serial->rx_state == RX_IDLE &&
35178- serial->port.count > 0) {
35179+ atomic_read(&serial->port.count) > 0) {
35180 /* Setup and send a ctrl req read on
35181 * port i */
35182 if (!serial->rx_urb_filled[0]) {
35183@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35184 /* Start all serial ports */
35185 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35186 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35187- if (dev2ser(serial_table[i])->port.count) {
35188+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35189 result =
35190 hso_start_serial_device(serial_table[i], GFP_NOIO);
35191 hso_kick_transmit(dev2ser(serial_table[i]));
35192diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35193index 420d69b..74f90a2 100644
35194--- a/drivers/net/wireless/ath/ath.h
35195+++ b/drivers/net/wireless/ath/ath.h
35196@@ -119,6 +119,7 @@ struct ath_ops {
35197 void (*write_flush) (void *);
35198 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35199 };
35200+typedef struct ath_ops __no_const ath_ops_no_const;
35201
35202 struct ath_common;
35203 struct ath_bus_ops;
35204diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35205index 8d78253..bebbb68 100644
35206--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35207+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35208@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35209 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35210 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35211
35212- ACCESS_ONCE(ads->ds_link) = i->link;
35213- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35214+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
35215+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35216
35217 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35218 ctl6 = SM(i->keytype, AR_EncrType);
35219@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35220
35221 if ((i->is_first || i->is_last) &&
35222 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35223- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35224+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35225 | set11nTries(i->rates, 1)
35226 | set11nTries(i->rates, 2)
35227 | set11nTries(i->rates, 3)
35228 | (i->dur_update ? AR_DurUpdateEna : 0)
35229 | SM(0, AR_BurstDur);
35230
35231- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35232+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35233 | set11nRate(i->rates, 1)
35234 | set11nRate(i->rates, 2)
35235 | set11nRate(i->rates, 3);
35236 } else {
35237- ACCESS_ONCE(ads->ds_ctl2) = 0;
35238- ACCESS_ONCE(ads->ds_ctl3) = 0;
35239+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35240+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35241 }
35242
35243 if (!i->is_first) {
35244- ACCESS_ONCE(ads->ds_ctl0) = 0;
35245- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35246- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35247+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35248+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35249+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35250 return;
35251 }
35252
35253@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35254 break;
35255 }
35256
35257- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35258+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35259 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35260 | SM(i->txpower, AR_XmitPower)
35261 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35262@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35263 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35264 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35265
35266- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35267- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35268+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35269+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35270
35271 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35272 return;
35273
35274- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35275+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35276 | set11nPktDurRTSCTS(i->rates, 1);
35277
35278- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35279+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35280 | set11nPktDurRTSCTS(i->rates, 3);
35281
35282- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35283+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35284 | set11nRateFlags(i->rates, 1)
35285 | set11nRateFlags(i->rates, 2)
35286 | set11nRateFlags(i->rates, 3)
35287diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35288index d9e0824..1a874e7 100644
35289--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35290+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35291@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35292 (i->qcu << AR_TxQcuNum_S) | desc_len;
35293
35294 checksum += val;
35295- ACCESS_ONCE(ads->info) = val;
35296+ ACCESS_ONCE_RW(ads->info) = val;
35297
35298 checksum += i->link;
35299- ACCESS_ONCE(ads->link) = i->link;
35300+ ACCESS_ONCE_RW(ads->link) = i->link;
35301
35302 checksum += i->buf_addr[0];
35303- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35304+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35305 checksum += i->buf_addr[1];
35306- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35307+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35308 checksum += i->buf_addr[2];
35309- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35310+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35311 checksum += i->buf_addr[3];
35312- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35313+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35314
35315 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35316- ACCESS_ONCE(ads->ctl3) = val;
35317+ ACCESS_ONCE_RW(ads->ctl3) = val;
35318 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35319- ACCESS_ONCE(ads->ctl5) = val;
35320+ ACCESS_ONCE_RW(ads->ctl5) = val;
35321 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35322- ACCESS_ONCE(ads->ctl7) = val;
35323+ ACCESS_ONCE_RW(ads->ctl7) = val;
35324 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35325- ACCESS_ONCE(ads->ctl9) = val;
35326+ ACCESS_ONCE_RW(ads->ctl9) = val;
35327
35328 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35329- ACCESS_ONCE(ads->ctl10) = checksum;
35330+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
35331
35332 if (i->is_first || i->is_last) {
35333- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35334+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35335 | set11nTries(i->rates, 1)
35336 | set11nTries(i->rates, 2)
35337 | set11nTries(i->rates, 3)
35338 | (i->dur_update ? AR_DurUpdateEna : 0)
35339 | SM(0, AR_BurstDur);
35340
35341- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35342+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35343 | set11nRate(i->rates, 1)
35344 | set11nRate(i->rates, 2)
35345 | set11nRate(i->rates, 3);
35346 } else {
35347- ACCESS_ONCE(ads->ctl13) = 0;
35348- ACCESS_ONCE(ads->ctl14) = 0;
35349+ ACCESS_ONCE_RW(ads->ctl13) = 0;
35350+ ACCESS_ONCE_RW(ads->ctl14) = 0;
35351 }
35352
35353 ads->ctl20 = 0;
35354@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35355
35356 ctl17 = SM(i->keytype, AR_EncrType);
35357 if (!i->is_first) {
35358- ACCESS_ONCE(ads->ctl11) = 0;
35359- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35360- ACCESS_ONCE(ads->ctl15) = 0;
35361- ACCESS_ONCE(ads->ctl16) = 0;
35362- ACCESS_ONCE(ads->ctl17) = ctl17;
35363- ACCESS_ONCE(ads->ctl18) = 0;
35364- ACCESS_ONCE(ads->ctl19) = 0;
35365+ ACCESS_ONCE_RW(ads->ctl11) = 0;
35366+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35367+ ACCESS_ONCE_RW(ads->ctl15) = 0;
35368+ ACCESS_ONCE_RW(ads->ctl16) = 0;
35369+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35370+ ACCESS_ONCE_RW(ads->ctl18) = 0;
35371+ ACCESS_ONCE_RW(ads->ctl19) = 0;
35372 return;
35373 }
35374
35375- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35376+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35377 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35378 | SM(i->txpower, AR_XmitPower)
35379 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35380@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35381 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35382 ctl12 |= SM(val, AR_PAPRDChainMask);
35383
35384- ACCESS_ONCE(ads->ctl12) = ctl12;
35385- ACCESS_ONCE(ads->ctl17) = ctl17;
35386+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35387+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35388
35389- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35390+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35391 | set11nPktDurRTSCTS(i->rates, 1);
35392
35393- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35394+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35395 | set11nPktDurRTSCTS(i->rates, 3);
35396
35397- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35398+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35399 | set11nRateFlags(i->rates, 1)
35400 | set11nRateFlags(i->rates, 2)
35401 | set11nRateFlags(i->rates, 3)
35402 | SM(i->rtscts_rate, AR_RTSCTSRate);
35403
35404- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35405+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35406 }
35407
35408 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35409diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35410index b620c55..a76cd49 100644
35411--- a/drivers/net/wireless/ath/ath9k/hw.h
35412+++ b/drivers/net/wireless/ath/ath9k/hw.h
35413@@ -609,7 +609,7 @@ struct ath_hw_private_ops {
35414
35415 /* ANI */
35416 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35417-};
35418+} __no_const;
35419
35420 /**
35421 * struct ath_hw_ops - callbacks used by hardware code and driver code
35422@@ -639,7 +639,7 @@ struct ath_hw_ops {
35423 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35424 struct ath_hw_antcomb_conf *antconf);
35425
35426-};
35427+} __no_const;
35428
35429 struct ath_nf_limits {
35430 s16 max;
35431@@ -659,7 +659,7 @@ enum ath_cal_list {
35432 #define AH_FASTCC 0x4
35433
35434 struct ath_hw {
35435- struct ath_ops reg_ops;
35436+ ath_ops_no_const reg_ops;
35437
35438 struct ieee80211_hw *hw;
35439 struct ath_common common;
35440diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35441index af00e2c..ab04d34 100644
35442--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35443+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35444@@ -545,7 +545,7 @@ struct phy_func_ptr {
35445 void (*carrsuppr)(struct brcms_phy *);
35446 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35447 void (*detach)(struct brcms_phy *);
35448-};
35449+} __no_const;
35450
35451 struct brcms_phy {
35452 struct brcms_phy_pub pubpi_ro;
35453diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35454index faec404..a5277f1 100644
35455--- a/drivers/net/wireless/iwlegacy/3945-mac.c
35456+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35457@@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35458 */
35459 if (il3945_mod_params.disable_hw_scan) {
35460 D_INFO("Disabling hw_scan\n");
35461- il3945_mac_ops.hw_scan = NULL;
35462+ pax_open_kernel();
35463+ *(void **)&il3945_mac_ops.hw_scan = NULL;
35464+ pax_close_kernel();
35465 }
35466
35467 D_INFO("*** LOAD DRIVER ***\n");
35468diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35469index a0b7cfd..20b49f7 100644
35470--- a/drivers/net/wireless/mac80211_hwsim.c
35471+++ b/drivers/net/wireless/mac80211_hwsim.c
35472@@ -1752,9 +1752,11 @@ static int __init init_mac80211_hwsim(void)
35473 return -EINVAL;
35474
35475 if (fake_hw_scan) {
35476- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35477- mac80211_hwsim_ops.sw_scan_start = NULL;
35478- mac80211_hwsim_ops.sw_scan_complete = NULL;
35479+ pax_open_kernel();
35480+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35481+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35482+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35483+ pax_close_kernel();
35484 }
35485
35486 spin_lock_init(&hwsim_radio_lock);
35487diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35488index bd3b0bf..f9db92a 100644
35489--- a/drivers/net/wireless/mwifiex/main.h
35490+++ b/drivers/net/wireless/mwifiex/main.h
35491@@ -567,7 +567,7 @@ struct mwifiex_if_ops {
35492 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35493 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35494 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35495-};
35496+} __no_const;
35497
35498 struct mwifiex_adapter {
35499 u8 iface_type;
35500diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35501index dfcd02a..a42a59d 100644
35502--- a/drivers/net/wireless/rndis_wlan.c
35503+++ b/drivers/net/wireless/rndis_wlan.c
35504@@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35505
35506 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35507
35508- if (rts_threshold < 0 || rts_threshold > 2347)
35509+ if (rts_threshold > 2347)
35510 rts_threshold = 2347;
35511
35512 tmp = cpu_to_le32(rts_threshold);
35513diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35514index 8f75402..eed109d 100644
35515--- a/drivers/net/wireless/rt2x00/rt2x00.h
35516+++ b/drivers/net/wireless/rt2x00/rt2x00.h
35517@@ -396,7 +396,7 @@ struct rt2x00_intf {
35518 * for hardware which doesn't support hardware
35519 * sequence counting.
35520 */
35521- atomic_t seqno;
35522+ atomic_unchecked_t seqno;
35523 };
35524
35525 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35526diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35527index 2fd8301..9767e8c 100644
35528--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35529+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35530@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35531 * sequence counter given by mac80211.
35532 */
35533 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35534- seqno = atomic_add_return(0x10, &intf->seqno);
35535+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35536 else
35537- seqno = atomic_read(&intf->seqno);
35538+ seqno = atomic_read_unchecked(&intf->seqno);
35539
35540 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35541 hdr->seq_ctrl |= cpu_to_le16(seqno);
35542diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35543index 9d8f581..0f6589e 100644
35544--- a/drivers/net/wireless/ti/wl1251/wl1251.h
35545+++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35546@@ -266,7 +266,7 @@ struct wl1251_if_operations {
35547 void (*reset)(struct wl1251 *wl);
35548 void (*enable_irq)(struct wl1251 *wl);
35549 void (*disable_irq)(struct wl1251 *wl);
35550-};
35551+} __no_const;
35552
35553 struct wl1251 {
35554 struct ieee80211_hw *hw;
35555diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35556index 0b3f0b5..62f68bd 100644
35557--- a/drivers/net/wireless/ti/wlcore/wlcore.h
35558+++ b/drivers/net/wireless/ti/wlcore/wlcore.h
35559@@ -61,7 +61,7 @@ struct wlcore_ops {
35560 struct wl12xx_vif *wlvif);
35561 s8 (*get_pg_ver)(struct wl1271 *wl);
35562 void (*get_mac)(struct wl1271 *wl);
35563-};
35564+} __no_const;
35565
35566 enum wlcore_partitions {
35567 PART_DOWN,
35568diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35569index f34b5b2..b5abb9f 100644
35570--- a/drivers/oprofile/buffer_sync.c
35571+++ b/drivers/oprofile/buffer_sync.c
35572@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35573 if (cookie == NO_COOKIE)
35574 offset = pc;
35575 if (cookie == INVALID_COOKIE) {
35576- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35577+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35578 offset = pc;
35579 }
35580 if (cookie != last_cookie) {
35581@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35582 /* add userspace sample */
35583
35584 if (!mm) {
35585- atomic_inc(&oprofile_stats.sample_lost_no_mm);
35586+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35587 return 0;
35588 }
35589
35590 cookie = lookup_dcookie(mm, s->eip, &offset);
35591
35592 if (cookie == INVALID_COOKIE) {
35593- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35594+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35595 return 0;
35596 }
35597
35598@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35599 /* ignore backtraces if failed to add a sample */
35600 if (state == sb_bt_start) {
35601 state = sb_bt_ignore;
35602- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35603+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35604 }
35605 }
35606 release_mm(mm);
35607diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35608index c0cc4e7..44d4e54 100644
35609--- a/drivers/oprofile/event_buffer.c
35610+++ b/drivers/oprofile/event_buffer.c
35611@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35612 }
35613
35614 if (buffer_pos == buffer_size) {
35615- atomic_inc(&oprofile_stats.event_lost_overflow);
35616+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35617 return;
35618 }
35619
35620diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35621index ed2c3ec..deda85a 100644
35622--- a/drivers/oprofile/oprof.c
35623+++ b/drivers/oprofile/oprof.c
35624@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35625 if (oprofile_ops.switch_events())
35626 return;
35627
35628- atomic_inc(&oprofile_stats.multiplex_counter);
35629+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35630 start_switch_worker();
35631 }
35632
35633diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35634index 917d28e..d62d981 100644
35635--- a/drivers/oprofile/oprofile_stats.c
35636+++ b/drivers/oprofile/oprofile_stats.c
35637@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35638 cpu_buf->sample_invalid_eip = 0;
35639 }
35640
35641- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35642- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35643- atomic_set(&oprofile_stats.event_lost_overflow, 0);
35644- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35645- atomic_set(&oprofile_stats.multiplex_counter, 0);
35646+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35647+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35648+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35649+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35650+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35651 }
35652
35653
35654diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35655index 38b6fc0..b5cbfce 100644
35656--- a/drivers/oprofile/oprofile_stats.h
35657+++ b/drivers/oprofile/oprofile_stats.h
35658@@ -13,11 +13,11 @@
35659 #include <linux/atomic.h>
35660
35661 struct oprofile_stat_struct {
35662- atomic_t sample_lost_no_mm;
35663- atomic_t sample_lost_no_mapping;
35664- atomic_t bt_lost_no_mapping;
35665- atomic_t event_lost_overflow;
35666- atomic_t multiplex_counter;
35667+ atomic_unchecked_t sample_lost_no_mm;
35668+ atomic_unchecked_t sample_lost_no_mapping;
35669+ atomic_unchecked_t bt_lost_no_mapping;
35670+ atomic_unchecked_t event_lost_overflow;
35671+ atomic_unchecked_t multiplex_counter;
35672 };
35673
35674 extern struct oprofile_stat_struct oprofile_stats;
35675diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35676index 849357c..b83c1e0 100644
35677--- a/drivers/oprofile/oprofilefs.c
35678+++ b/drivers/oprofile/oprofilefs.c
35679@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35680
35681
35682 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35683- char const *name, atomic_t *val)
35684+ char const *name, atomic_unchecked_t *val)
35685 {
35686 return __oprofilefs_create_file(sb, root, name,
35687 &atomic_ro_fops, 0444, val);
35688diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35689index 3f56bc0..707d642 100644
35690--- a/drivers/parport/procfs.c
35691+++ b/drivers/parport/procfs.c
35692@@ -64,7 +64,7 @@ static int do_active_device(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
35700 #ifdef CONFIG_PARPORT_1284
35701@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35702
35703 *ppos += len;
35704
35705- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35706+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35707 }
35708 #endif /* IEEE1284.3 support. */
35709
35710diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35711index 9fff878..ad0ad53 100644
35712--- a/drivers/pci/hotplug/cpci_hotplug.h
35713+++ b/drivers/pci/hotplug/cpci_hotplug.h
35714@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35715 int (*hardware_test) (struct slot* slot, u32 value);
35716 u8 (*get_power) (struct slot* slot);
35717 int (*set_power) (struct slot* slot, int value);
35718-};
35719+} __no_const;
35720
35721 struct cpci_hp_controller {
35722 unsigned int irq;
35723diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35724index 76ba8a1..20ca857 100644
35725--- a/drivers/pci/hotplug/cpqphp_nvram.c
35726+++ b/drivers/pci/hotplug/cpqphp_nvram.c
35727@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35728
35729 void compaq_nvram_init (void __iomem *rom_start)
35730 {
35731+
35732+#ifndef CONFIG_PAX_KERNEXEC
35733 if (rom_start) {
35734 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35735 }
35736+#endif
35737+
35738 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35739
35740 /* initialize our int15 lock */
35741diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35742index b500840..d7159d3 100644
35743--- a/drivers/pci/pcie/aspm.c
35744+++ b/drivers/pci/pcie/aspm.c
35745@@ -27,9 +27,9 @@
35746 #define MODULE_PARAM_PREFIX "pcie_aspm."
35747
35748 /* Note: those are not register definitions */
35749-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35750-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35751-#define ASPM_STATE_L1 (4) /* L1 state */
35752+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35753+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35754+#define ASPM_STATE_L1 (4U) /* L1 state */
35755 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35756 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35757
35758diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35759index 658ac97..05e1b90 100644
35760--- a/drivers/pci/probe.c
35761+++ b/drivers/pci/probe.c
35762@@ -137,7 +137,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35763 u16 orig_cmd;
35764 struct pci_bus_region region;
35765
35766- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35767+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35768
35769 if (!dev->mmio_always_on) {
35770 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35771diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35772index 27911b5..5b6db88 100644
35773--- a/drivers/pci/proc.c
35774+++ b/drivers/pci/proc.c
35775@@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35776 static int __init pci_proc_init(void)
35777 {
35778 struct pci_dev *dev = NULL;
35779+
35780+#ifdef CONFIG_GRKERNSEC_PROC_ADD
35781+#ifdef CONFIG_GRKERNSEC_PROC_USER
35782+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35783+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35784+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35785+#endif
35786+#else
35787 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35788+#endif
35789 proc_create("devices", 0, proc_bus_pci_dir,
35790 &proc_bus_pci_dev_operations);
35791 proc_initialized = 1;
35792diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35793index 8b5610d..a4c22bb 100644
35794--- a/drivers/platform/x86/thinkpad_acpi.c
35795+++ b/drivers/platform/x86/thinkpad_acpi.c
35796@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35797 return 0;
35798 }
35799
35800-void static hotkey_mask_warn_incomplete_mask(void)
35801+static void hotkey_mask_warn_incomplete_mask(void)
35802 {
35803 /* log only what the user can fix... */
35804 const u32 wantedmask = hotkey_driver_mask &
35805@@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35806 }
35807 }
35808
35809-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35810- struct tp_nvram_state *newn,
35811- const u32 event_mask)
35812-{
35813-
35814 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35815 do { \
35816 if ((event_mask & (1 << __scancode)) && \
35817@@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35818 tpacpi_hotkey_send_key(__scancode); \
35819 } while (0)
35820
35821- void issue_volchange(const unsigned int oldvol,
35822- const unsigned int newvol)
35823- {
35824- unsigned int i = oldvol;
35825+static void issue_volchange(const unsigned int oldvol,
35826+ const unsigned int newvol,
35827+ const u32 event_mask)
35828+{
35829+ unsigned int i = oldvol;
35830
35831- while (i > newvol) {
35832- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35833- i--;
35834- }
35835- while (i < newvol) {
35836- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35837- i++;
35838- }
35839+ while (i > newvol) {
35840+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35841+ i--;
35842 }
35843+ while (i < newvol) {
35844+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35845+ i++;
35846+ }
35847+}
35848
35849- void issue_brightnesschange(const unsigned int oldbrt,
35850- const unsigned int newbrt)
35851- {
35852- unsigned int i = oldbrt;
35853+static void issue_brightnesschange(const unsigned int oldbrt,
35854+ const unsigned int newbrt,
35855+ const u32 event_mask)
35856+{
35857+ unsigned int i = oldbrt;
35858
35859- while (i > newbrt) {
35860- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35861- i--;
35862- }
35863- while (i < newbrt) {
35864- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35865- i++;
35866- }
35867+ while (i > newbrt) {
35868+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35869+ i--;
35870+ }
35871+ while (i < newbrt) {
35872+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35873+ i++;
35874 }
35875+}
35876
35877+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35878+ struct tp_nvram_state *newn,
35879+ const u32 event_mask)
35880+{
35881 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35882 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35883 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35884@@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35885 oldn->volume_level != newn->volume_level) {
35886 /* recently muted, or repeated mute keypress, or
35887 * multiple presses ending in mute */
35888- issue_volchange(oldn->volume_level, newn->volume_level);
35889+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35890 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35891 }
35892 } else {
35893@@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35894 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35895 }
35896 if (oldn->volume_level != newn->volume_level) {
35897- issue_volchange(oldn->volume_level, newn->volume_level);
35898+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35899 } else if (oldn->volume_toggle != newn->volume_toggle) {
35900 /* repeated vol up/down keypress at end of scale ? */
35901 if (newn->volume_level == 0)
35902@@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35903 /* handle brightness */
35904 if (oldn->brightness_level != newn->brightness_level) {
35905 issue_brightnesschange(oldn->brightness_level,
35906- newn->brightness_level);
35907+ newn->brightness_level,
35908+ event_mask);
35909 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35910 /* repeated key presses that didn't change state */
35911 if (newn->brightness_level == 0)
35912@@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35913 && !tp_features.bright_unkfw)
35914 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35915 }
35916+}
35917
35918 #undef TPACPI_COMPARE_KEY
35919 #undef TPACPI_MAY_SEND_KEY
35920-}
35921
35922 /*
35923 * Polling driver
35924diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35925index 769d265..a3a05ca 100644
35926--- a/drivers/pnp/pnpbios/bioscalls.c
35927+++ b/drivers/pnp/pnpbios/bioscalls.c
35928@@ -58,7 +58,7 @@ do { \
35929 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35930 } while(0)
35931
35932-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35933+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35934 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35935
35936 /*
35937@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35938
35939 cpu = get_cpu();
35940 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35941+
35942+ pax_open_kernel();
35943 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35944+ pax_close_kernel();
35945
35946 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35947 spin_lock_irqsave(&pnp_bios_lock, flags);
35948@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35949 :"memory");
35950 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35951
35952+ pax_open_kernel();
35953 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35954+ pax_close_kernel();
35955+
35956 put_cpu();
35957
35958 /* If we get here and this is set then the PnP BIOS faulted on us. */
35959@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
35960 return status;
35961 }
35962
35963-void pnpbios_calls_init(union pnp_bios_install_struct *header)
35964+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
35965 {
35966 int i;
35967
35968@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35969 pnp_bios_callpoint.offset = header->fields.pm16offset;
35970 pnp_bios_callpoint.segment = PNP_CS16;
35971
35972+ pax_open_kernel();
35973+
35974 for_each_possible_cpu(i) {
35975 struct desc_struct *gdt = get_cpu_gdt_table(i);
35976 if (!gdt)
35977@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35978 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
35979 (unsigned long)__va(header->fields.pm16dseg));
35980 }
35981+
35982+ pax_close_kernel();
35983 }
35984diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
35985index b0ecacb..7c9da2e 100644
35986--- a/drivers/pnp/resource.c
35987+++ b/drivers/pnp/resource.c
35988@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
35989 return 1;
35990
35991 /* check if the resource is valid */
35992- if (*irq < 0 || *irq > 15)
35993+ if (*irq > 15)
35994 return 0;
35995
35996 /* check if the resource is reserved */
35997@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
35998 return 1;
35999
36000 /* check if the resource is valid */
36001- if (*dma < 0 || *dma == 4 || *dma > 7)
36002+ if (*dma == 4 || *dma > 7)
36003 return 0;
36004
36005 /* check if the resource is reserved */
36006diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36007index f5d6d37..739f6a9 100644
36008--- a/drivers/power/bq27x00_battery.c
36009+++ b/drivers/power/bq27x00_battery.c
36010@@ -72,7 +72,7 @@
36011 struct bq27x00_device_info;
36012 struct bq27x00_access_methods {
36013 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36014-};
36015+} __no_const;
36016
36017 enum bq27x00_chip { BQ27000, BQ27500 };
36018
36019diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36020index 8d53174..04c65de 100644
36021--- a/drivers/regulator/max8660.c
36022+++ b/drivers/regulator/max8660.c
36023@@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36024 max8660->shadow_regs[MAX8660_OVER1] = 5;
36025 } else {
36026 /* Otherwise devices can be toggled via software */
36027- max8660_dcdc_ops.enable = max8660_dcdc_enable;
36028- max8660_dcdc_ops.disable = max8660_dcdc_disable;
36029+ pax_open_kernel();
36030+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36031+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36032+ pax_close_kernel();
36033 }
36034
36035 /*
36036diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36037index 970a233..ee1f241 100644
36038--- a/drivers/regulator/mc13892-regulator.c
36039+++ b/drivers/regulator/mc13892-regulator.c
36040@@ -566,10 +566,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36041 }
36042 mc13xxx_unlock(mc13892);
36043
36044- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36045+ pax_open_kernel();
36046+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36047 = mc13892_vcam_set_mode;
36048- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36049+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36050 = mc13892_vcam_get_mode;
36051+ pax_close_kernel();
36052
36053 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36054 ARRAY_SIZE(mc13892_regulators));
36055diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36056index cace6d3..f623fda 100644
36057--- a/drivers/rtc/rtc-dev.c
36058+++ b/drivers/rtc/rtc-dev.c
36059@@ -14,6 +14,7 @@
36060 #include <linux/module.h>
36061 #include <linux/rtc.h>
36062 #include <linux/sched.h>
36063+#include <linux/grsecurity.h>
36064 #include "rtc-core.h"
36065
36066 static dev_t rtc_devt;
36067@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36068 if (copy_from_user(&tm, uarg, sizeof(tm)))
36069 return -EFAULT;
36070
36071+ gr_log_timechange();
36072+
36073 return rtc_set_time(rtc, &tm);
36074
36075 case RTC_PIE_ON:
36076diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36077index 3fcf627..f334910 100644
36078--- a/drivers/scsi/aacraid/aacraid.h
36079+++ b/drivers/scsi/aacraid/aacraid.h
36080@@ -492,7 +492,7 @@ struct adapter_ops
36081 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36082 /* Administrative operations */
36083 int (*adapter_comm)(struct aac_dev * dev, int comm);
36084-};
36085+} __no_const;
36086
36087 /*
36088 * Define which interrupt handler needs to be installed
36089diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36090index 0d279c44..3d25a97 100644
36091--- a/drivers/scsi/aacraid/linit.c
36092+++ b/drivers/scsi/aacraid/linit.c
36093@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36094 #elif defined(__devinitconst)
36095 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36096 #else
36097-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36098+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36099 #endif
36100 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36101 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36102diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36103index ff80552..1c4120c 100644
36104--- a/drivers/scsi/aic94xx/aic94xx_init.c
36105+++ b/drivers/scsi/aic94xx/aic94xx_init.c
36106@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36107 .lldd_ata_set_dmamode = asd_set_dmamode,
36108 };
36109
36110-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36111+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36112 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36113 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36114 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36115diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36116index 4ad7e36..d004679 100644
36117--- a/drivers/scsi/bfa/bfa.h
36118+++ b/drivers/scsi/bfa/bfa.h
36119@@ -196,7 +196,7 @@ struct bfa_hwif_s {
36120 u32 *end);
36121 int cpe_vec_q0;
36122 int rme_vec_q0;
36123-};
36124+} __no_const;
36125 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36126
36127 struct bfa_faa_cbfn_s {
36128diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36129index f0f80e2..8ec946b 100644
36130--- a/drivers/scsi/bfa/bfa_fcpim.c
36131+++ b/drivers/scsi/bfa/bfa_fcpim.c
36132@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36133
36134 bfa_iotag_attach(fcp);
36135
36136- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36137+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36138 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36139 (fcp->num_itns * sizeof(struct bfa_itn_s));
36140 memset(fcp->itn_arr, 0,
36141@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36142 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36143 {
36144 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36145- struct bfa_itn_s *itn;
36146+ bfa_itn_s_no_const *itn;
36147
36148 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36149 itn->isr = isr;
36150diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36151index 36f26da..38a34a8 100644
36152--- a/drivers/scsi/bfa/bfa_fcpim.h
36153+++ b/drivers/scsi/bfa/bfa_fcpim.h
36154@@ -37,6 +37,7 @@ struct bfa_iotag_s {
36155 struct bfa_itn_s {
36156 bfa_isr_func_t isr;
36157 };
36158+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36159
36160 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36161 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36162@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36163 struct list_head iotag_tio_free_q; /* free IO resources */
36164 struct list_head iotag_unused_q; /* unused IO resources*/
36165 struct bfa_iotag_s *iotag_arr;
36166- struct bfa_itn_s *itn_arr;
36167+ bfa_itn_s_no_const *itn_arr;
36168 int num_ioim_reqs;
36169 int num_fwtio_reqs;
36170 int num_itns;
36171diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36172index 1a99d4b..e85d64b 100644
36173--- a/drivers/scsi/bfa/bfa_ioc.h
36174+++ b/drivers/scsi/bfa/bfa_ioc.h
36175@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36176 bfa_ioc_disable_cbfn_t disable_cbfn;
36177 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36178 bfa_ioc_reset_cbfn_t reset_cbfn;
36179-};
36180+} __no_const;
36181
36182 /*
36183 * IOC event notification mechanism.
36184@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36185 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36186 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36187 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36188-};
36189+} __no_const;
36190
36191 /*
36192 * Queue element to wait for room in request queue. FIFO order is
36193diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36194index a3a056a..b9bbc2f 100644
36195--- a/drivers/scsi/hosts.c
36196+++ b/drivers/scsi/hosts.c
36197@@ -42,7 +42,7 @@
36198 #include "scsi_logging.h"
36199
36200
36201-static atomic_t scsi_host_next_hn; /* host_no for next new host */
36202+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36203
36204
36205 static void scsi_host_cls_release(struct device *dev)
36206@@ -360,7 +360,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36207 * subtract one because we increment first then return, but we need to
36208 * know what the next host number was before increment
36209 */
36210- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36211+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36212 shost->dma_channel = 0xff;
36213
36214 /* These three are default values which can be overridden */
36215diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36216index 796482b..d08435c 100644
36217--- a/drivers/scsi/hpsa.c
36218+++ b/drivers/scsi/hpsa.c
36219@@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36220 unsigned long flags;
36221
36222 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36223- return h->access.command_completed(h, q);
36224+ return h->access->command_completed(h, q);
36225
36226 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36227 a = rq->head[rq->current_entry];
36228@@ -3354,7 +3354,7 @@ static void start_io(struct ctlr_info *h)
36229 while (!list_empty(&h->reqQ)) {
36230 c = list_entry(h->reqQ.next, struct CommandList, list);
36231 /* can't do anything if fifo is full */
36232- if ((h->access.fifo_full(h))) {
36233+ if ((h->access->fifo_full(h))) {
36234 dev_warn(&h->pdev->dev, "fifo full\n");
36235 break;
36236 }
36237@@ -3376,7 +3376,7 @@ static void start_io(struct ctlr_info *h)
36238
36239 /* Tell the controller execute command */
36240 spin_unlock_irqrestore(&h->lock, flags);
36241- h->access.submit_command(h, c);
36242+ h->access->submit_command(h, c);
36243 spin_lock_irqsave(&h->lock, flags);
36244 }
36245 spin_unlock_irqrestore(&h->lock, flags);
36246@@ -3384,17 +3384,17 @@ static void start_io(struct ctlr_info *h)
36247
36248 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36249 {
36250- return h->access.command_completed(h, q);
36251+ return h->access->command_completed(h, q);
36252 }
36253
36254 static inline bool interrupt_pending(struct ctlr_info *h)
36255 {
36256- return h->access.intr_pending(h);
36257+ return h->access->intr_pending(h);
36258 }
36259
36260 static inline long interrupt_not_for_us(struct ctlr_info *h)
36261 {
36262- return (h->access.intr_pending(h) == 0) ||
36263+ return (h->access->intr_pending(h) == 0) ||
36264 (h->interrupts_enabled == 0);
36265 }
36266
36267@@ -4298,7 +4298,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36268 if (prod_index < 0)
36269 return -ENODEV;
36270 h->product_name = products[prod_index].product_name;
36271- h->access = *(products[prod_index].access);
36272+ h->access = products[prod_index].access;
36273
36274 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36275 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36276@@ -4580,7 +4580,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36277
36278 assert_spin_locked(&lockup_detector_lock);
36279 remove_ctlr_from_lockup_detector_list(h);
36280- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36281+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36282 spin_lock_irqsave(&h->lock, flags);
36283 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36284 spin_unlock_irqrestore(&h->lock, flags);
36285@@ -4758,7 +4758,7 @@ reinit_after_soft_reset:
36286 }
36287
36288 /* make sure the board interrupts are off */
36289- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36290+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36291
36292 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36293 goto clean2;
36294@@ -4792,7 +4792,7 @@ reinit_after_soft_reset:
36295 * fake ones to scoop up any residual completions.
36296 */
36297 spin_lock_irqsave(&h->lock, flags);
36298- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36299+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36300 spin_unlock_irqrestore(&h->lock, flags);
36301 free_irqs(h);
36302 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36303@@ -4811,9 +4811,9 @@ reinit_after_soft_reset:
36304 dev_info(&h->pdev->dev, "Board READY.\n");
36305 dev_info(&h->pdev->dev,
36306 "Waiting for stale completions to drain.\n");
36307- h->access.set_intr_mask(h, HPSA_INTR_ON);
36308+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36309 msleep(10000);
36310- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36311+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36312
36313 rc = controller_reset_failed(h->cfgtable);
36314 if (rc)
36315@@ -4834,7 +4834,7 @@ reinit_after_soft_reset:
36316 }
36317
36318 /* Turn the interrupts on so we can service requests */
36319- h->access.set_intr_mask(h, HPSA_INTR_ON);
36320+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36321
36322 hpsa_hba_inquiry(h);
36323 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36324@@ -4886,7 +4886,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36325 * To write all data in the battery backed cache to disks
36326 */
36327 hpsa_flush_cache(h);
36328- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36329+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36330 hpsa_free_irqs_and_disable_msix(h);
36331 }
36332
36333@@ -5055,7 +5055,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36334 return;
36335 }
36336 /* Change the access methods to the performant access methods */
36337- h->access = SA5_performant_access;
36338+ h->access = &SA5_performant_access;
36339 h->transMethod = CFGTBL_Trans_Performant;
36340 }
36341
36342diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36343index 9816479..c5d4e97 100644
36344--- a/drivers/scsi/hpsa.h
36345+++ b/drivers/scsi/hpsa.h
36346@@ -79,7 +79,7 @@ struct ctlr_info {
36347 unsigned int msix_vector;
36348 unsigned int msi_vector;
36349 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36350- struct access_method access;
36351+ struct access_method *access;
36352
36353 /* queue and queue Info */
36354 struct list_head reqQ;
36355diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36356index f2df059..a3a9930 100644
36357--- a/drivers/scsi/ips.h
36358+++ b/drivers/scsi/ips.h
36359@@ -1027,7 +1027,7 @@ typedef struct {
36360 int (*intr)(struct ips_ha *);
36361 void (*enableint)(struct ips_ha *);
36362 uint32_t (*statupd)(struct ips_ha *);
36363-} ips_hw_func_t;
36364+} __no_const ips_hw_func_t;
36365
36366 typedef struct ips_ha {
36367 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36368diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36369index aceffad..c35c08d 100644
36370--- a/drivers/scsi/libfc/fc_exch.c
36371+++ b/drivers/scsi/libfc/fc_exch.c
36372@@ -105,12 +105,12 @@ struct fc_exch_mgr {
36373 * all together if not used XXX
36374 */
36375 struct {
36376- atomic_t no_free_exch;
36377- atomic_t no_free_exch_xid;
36378- atomic_t xid_not_found;
36379- atomic_t xid_busy;
36380- atomic_t seq_not_found;
36381- atomic_t non_bls_resp;
36382+ atomic_unchecked_t no_free_exch;
36383+ atomic_unchecked_t no_free_exch_xid;
36384+ atomic_unchecked_t xid_not_found;
36385+ atomic_unchecked_t xid_busy;
36386+ atomic_unchecked_t seq_not_found;
36387+ atomic_unchecked_t non_bls_resp;
36388 } stats;
36389 };
36390
36391@@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36392 /* allocate memory for exchange */
36393 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36394 if (!ep) {
36395- atomic_inc(&mp->stats.no_free_exch);
36396+ atomic_inc_unchecked(&mp->stats.no_free_exch);
36397 goto out;
36398 }
36399 memset(ep, 0, sizeof(*ep));
36400@@ -780,7 +780,7 @@ out:
36401 return ep;
36402 err:
36403 spin_unlock_bh(&pool->lock);
36404- atomic_inc(&mp->stats.no_free_exch_xid);
36405+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36406 mempool_free(ep, mp->ep_pool);
36407 return NULL;
36408 }
36409@@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36410 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36411 ep = fc_exch_find(mp, xid);
36412 if (!ep) {
36413- atomic_inc(&mp->stats.xid_not_found);
36414+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36415 reject = FC_RJT_OX_ID;
36416 goto out;
36417 }
36418@@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36419 ep = fc_exch_find(mp, xid);
36420 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36421 if (ep) {
36422- atomic_inc(&mp->stats.xid_busy);
36423+ atomic_inc_unchecked(&mp->stats.xid_busy);
36424 reject = FC_RJT_RX_ID;
36425 goto rel;
36426 }
36427@@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36428 }
36429 xid = ep->xid; /* get our XID */
36430 } else if (!ep) {
36431- atomic_inc(&mp->stats.xid_not_found);
36432+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36433 reject = FC_RJT_RX_ID; /* XID not found */
36434 goto out;
36435 }
36436@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36437 } else {
36438 sp = &ep->seq;
36439 if (sp->id != fh->fh_seq_id) {
36440- atomic_inc(&mp->stats.seq_not_found);
36441+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36442 if (f_ctl & FC_FC_END_SEQ) {
36443 /*
36444 * Update sequence_id based on incoming last
36445@@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36446
36447 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36448 if (!ep) {
36449- atomic_inc(&mp->stats.xid_not_found);
36450+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36451 goto out;
36452 }
36453 if (ep->esb_stat & ESB_ST_COMPLETE) {
36454- atomic_inc(&mp->stats.xid_not_found);
36455+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36456 goto rel;
36457 }
36458 if (ep->rxid == FC_XID_UNKNOWN)
36459 ep->rxid = ntohs(fh->fh_rx_id);
36460 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36461- atomic_inc(&mp->stats.xid_not_found);
36462+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36463 goto rel;
36464 }
36465 if (ep->did != ntoh24(fh->fh_s_id) &&
36466 ep->did != FC_FID_FLOGI) {
36467- atomic_inc(&mp->stats.xid_not_found);
36468+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36469 goto rel;
36470 }
36471 sof = fr_sof(fp);
36472@@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36473 sp->ssb_stat |= SSB_ST_RESP;
36474 sp->id = fh->fh_seq_id;
36475 } else if (sp->id != fh->fh_seq_id) {
36476- atomic_inc(&mp->stats.seq_not_found);
36477+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36478 goto rel;
36479 }
36480
36481@@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36482 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36483
36484 if (!sp)
36485- atomic_inc(&mp->stats.xid_not_found);
36486+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36487 else
36488- atomic_inc(&mp->stats.non_bls_resp);
36489+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
36490
36491 fc_frame_free(fp);
36492 }
36493diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36494index d109cc3..09f4e7d 100644
36495--- a/drivers/scsi/libsas/sas_ata.c
36496+++ b/drivers/scsi/libsas/sas_ata.c
36497@@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36498 .postreset = ata_std_postreset,
36499 .error_handler = ata_std_error_handler,
36500 .post_internal_cmd = sas_ata_post_internal,
36501- .qc_defer = ata_std_qc_defer,
36502+ .qc_defer = ata_std_qc_defer,
36503 .qc_prep = ata_noop_qc_prep,
36504 .qc_issue = sas_ata_qc_issue,
36505 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36506diff --git a/drivers/scsi/lpfc/Makefile b/drivers/scsi/lpfc/Makefile
36507index fe5d396..e93d526 100644
36508--- a/drivers/scsi/lpfc/Makefile
36509+++ b/drivers/scsi/lpfc/Makefile
36510@@ -22,7 +22,7 @@
36511 ccflags-$(GCOV) := -fprofile-arcs -ftest-coverage
36512 ccflags-$(GCOV) += -O0
36513
36514-ccflags-y += -Werror
36515+#ccflags-y += -Werror
36516
36517 obj-$(CONFIG_SCSI_LPFC) := lpfc.o
36518
36519diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36520index e5da6da..c888d48 100644
36521--- a/drivers/scsi/lpfc/lpfc.h
36522+++ b/drivers/scsi/lpfc/lpfc.h
36523@@ -416,7 +416,7 @@ struct lpfc_vport {
36524 struct dentry *debug_nodelist;
36525 struct dentry *vport_debugfs_root;
36526 struct lpfc_debugfs_trc *disc_trc;
36527- atomic_t disc_trc_cnt;
36528+ atomic_unchecked_t disc_trc_cnt;
36529 #endif
36530 uint8_t stat_data_enabled;
36531 uint8_t stat_data_blocked;
36532@@ -830,8 +830,8 @@ struct lpfc_hba {
36533 struct timer_list fabric_block_timer;
36534 unsigned long bit_flags;
36535 #define FABRIC_COMANDS_BLOCKED 0
36536- atomic_t num_rsrc_err;
36537- atomic_t num_cmd_success;
36538+ atomic_unchecked_t num_rsrc_err;
36539+ atomic_unchecked_t num_cmd_success;
36540 unsigned long last_rsrc_error_time;
36541 unsigned long last_ramp_down_time;
36542 unsigned long last_ramp_up_time;
36543@@ -867,7 +867,7 @@ struct lpfc_hba {
36544
36545 struct dentry *debug_slow_ring_trc;
36546 struct lpfc_debugfs_trc *slow_ring_trc;
36547- atomic_t slow_ring_trc_cnt;
36548+ atomic_unchecked_t slow_ring_trc_cnt;
36549 /* iDiag debugfs sub-directory */
36550 struct dentry *idiag_root;
36551 struct dentry *idiag_pci_cfg;
36552diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36553index 3217d63..c417981 100644
36554--- a/drivers/scsi/lpfc/lpfc_debugfs.c
36555+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36556@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36557
36558 #include <linux/debugfs.h>
36559
36560-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36561+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36562 static unsigned long lpfc_debugfs_start_time = 0L;
36563
36564 /* iDiag */
36565@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36566 lpfc_debugfs_enable = 0;
36567
36568 len = 0;
36569- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36570+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36571 (lpfc_debugfs_max_disc_trc - 1);
36572 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36573 dtp = vport->disc_trc + i;
36574@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36575 lpfc_debugfs_enable = 0;
36576
36577 len = 0;
36578- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36579+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36580 (lpfc_debugfs_max_slow_ring_trc - 1);
36581 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36582 dtp = phba->slow_ring_trc + i;
36583@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36584 !vport || !vport->disc_trc)
36585 return;
36586
36587- index = atomic_inc_return(&vport->disc_trc_cnt) &
36588+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36589 (lpfc_debugfs_max_disc_trc - 1);
36590 dtp = vport->disc_trc + index;
36591 dtp->fmt = fmt;
36592 dtp->data1 = data1;
36593 dtp->data2 = data2;
36594 dtp->data3 = data3;
36595- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36596+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36597 dtp->jif = jiffies;
36598 #endif
36599 return;
36600@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36601 !phba || !phba->slow_ring_trc)
36602 return;
36603
36604- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36605+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36606 (lpfc_debugfs_max_slow_ring_trc - 1);
36607 dtp = phba->slow_ring_trc + index;
36608 dtp->fmt = fmt;
36609 dtp->data1 = data1;
36610 dtp->data2 = data2;
36611 dtp->data3 = data3;
36612- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36613+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36614 dtp->jif = jiffies;
36615 #endif
36616 return;
36617@@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36618 "slow_ring buffer\n");
36619 goto debug_failed;
36620 }
36621- atomic_set(&phba->slow_ring_trc_cnt, 0);
36622+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36623 memset(phba->slow_ring_trc, 0,
36624 (sizeof(struct lpfc_debugfs_trc) *
36625 lpfc_debugfs_max_slow_ring_trc));
36626@@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36627 "buffer\n");
36628 goto debug_failed;
36629 }
36630- atomic_set(&vport->disc_trc_cnt, 0);
36631+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36632
36633 snprintf(name, sizeof(name), "discovery_trace");
36634 vport->debug_disc_trc =
36635diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36636index 411ed48..967f553 100644
36637--- a/drivers/scsi/lpfc/lpfc_init.c
36638+++ b/drivers/scsi/lpfc/lpfc_init.c
36639@@ -10341,8 +10341,10 @@ lpfc_init(void)
36640 "misc_register returned with status %d", error);
36641
36642 if (lpfc_enable_npiv) {
36643- lpfc_transport_functions.vport_create = lpfc_vport_create;
36644- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36645+ pax_open_kernel();
36646+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36647+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36648+ pax_close_kernel();
36649 }
36650 lpfc_transport_template =
36651 fc_attach_transport(&lpfc_transport_functions);
36652diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36653index 66e0906..1620281 100644
36654--- a/drivers/scsi/lpfc/lpfc_scsi.c
36655+++ b/drivers/scsi/lpfc/lpfc_scsi.c
36656@@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36657 uint32_t evt_posted;
36658
36659 spin_lock_irqsave(&phba->hbalock, flags);
36660- atomic_inc(&phba->num_rsrc_err);
36661+ atomic_inc_unchecked(&phba->num_rsrc_err);
36662 phba->last_rsrc_error_time = jiffies;
36663
36664 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36665@@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36666 unsigned long flags;
36667 struct lpfc_hba *phba = vport->phba;
36668 uint32_t evt_posted;
36669- atomic_inc(&phba->num_cmd_success);
36670+ atomic_inc_unchecked(&phba->num_cmd_success);
36671
36672 if (vport->cfg_lun_queue_depth <= queue_depth)
36673 return;
36674@@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36675 unsigned long num_rsrc_err, num_cmd_success;
36676 int i;
36677
36678- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36679- num_cmd_success = atomic_read(&phba->num_cmd_success);
36680+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36681+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36682
36683 /*
36684 * The error and success command counters are global per
36685@@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36686 }
36687 }
36688 lpfc_destroy_vport_work_array(phba, vports);
36689- atomic_set(&phba->num_rsrc_err, 0);
36690- atomic_set(&phba->num_cmd_success, 0);
36691+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36692+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36693 }
36694
36695 /**
36696@@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36697 }
36698 }
36699 lpfc_destroy_vport_work_array(phba, vports);
36700- atomic_set(&phba->num_rsrc_err, 0);
36701- atomic_set(&phba->num_cmd_success, 0);
36702+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36703+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36704 }
36705
36706 /**
36707diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36708index ea8a0b4..812a124 100644
36709--- a/drivers/scsi/pmcraid.c
36710+++ b/drivers/scsi/pmcraid.c
36711@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36712 res->scsi_dev = scsi_dev;
36713 scsi_dev->hostdata = res;
36714 res->change_detected = 0;
36715- atomic_set(&res->read_failures, 0);
36716- atomic_set(&res->write_failures, 0);
36717+ atomic_set_unchecked(&res->read_failures, 0);
36718+ atomic_set_unchecked(&res->write_failures, 0);
36719 rc = 0;
36720 }
36721 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36722@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36723
36724 /* If this was a SCSI read/write command keep count of errors */
36725 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36726- atomic_inc(&res->read_failures);
36727+ atomic_inc_unchecked(&res->read_failures);
36728 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36729- atomic_inc(&res->write_failures);
36730+ atomic_inc_unchecked(&res->write_failures);
36731
36732 if (!RES_IS_GSCSI(res->cfg_entry) &&
36733 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36734@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
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 cmd->cmd_done = pmcraid_io_done;
36742
36743@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36744 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36745 * hrrq_id assigned here in queuecommand
36746 */
36747- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36748+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36749 pinstance->num_hrrq;
36750
36751 if (request_size) {
36752@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36753
36754 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36755 /* add resources only after host is added into system */
36756- if (!atomic_read(&pinstance->expose_resources))
36757+ if (!atomic_read_unchecked(&pinstance->expose_resources))
36758 return;
36759
36760 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36761@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36762 init_waitqueue_head(&pinstance->reset_wait_q);
36763
36764 atomic_set(&pinstance->outstanding_cmds, 0);
36765- atomic_set(&pinstance->last_message_id, 0);
36766- atomic_set(&pinstance->expose_resources, 0);
36767+ atomic_set_unchecked(&pinstance->last_message_id, 0);
36768+ atomic_set_unchecked(&pinstance->expose_resources, 0);
36769
36770 INIT_LIST_HEAD(&pinstance->free_res_q);
36771 INIT_LIST_HEAD(&pinstance->used_res_q);
36772@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36773 /* Schedule worker thread to handle CCN and take care of adding and
36774 * removing devices to OS
36775 */
36776- atomic_set(&pinstance->expose_resources, 1);
36777+ atomic_set_unchecked(&pinstance->expose_resources, 1);
36778 schedule_work(&pinstance->worker_q);
36779 return rc;
36780
36781diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36782index e1d150f..6c6df44 100644
36783--- a/drivers/scsi/pmcraid.h
36784+++ b/drivers/scsi/pmcraid.h
36785@@ -748,7 +748,7 @@ struct pmcraid_instance {
36786 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36787
36788 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36789- atomic_t last_message_id;
36790+ atomic_unchecked_t last_message_id;
36791
36792 /* configuration table */
36793 struct pmcraid_config_table *cfg_table;
36794@@ -777,7 +777,7 @@ struct pmcraid_instance {
36795 atomic_t outstanding_cmds;
36796
36797 /* should add/delete resources to mid-layer now ?*/
36798- atomic_t expose_resources;
36799+ atomic_unchecked_t expose_resources;
36800
36801
36802
36803@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36804 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36805 };
36806 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36807- atomic_t read_failures; /* count of failed READ commands */
36808- atomic_t write_failures; /* count of failed WRITE commands */
36809+ atomic_unchecked_t read_failures; /* count of failed READ commands */
36810+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36811
36812 /* To indicate add/delete/modify during CCN */
36813 u8 change_detected;
36814diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
36815index 5ab9530..2dd80f7 100644
36816--- a/drivers/scsi/qla2xxx/qla_attr.c
36817+++ b/drivers/scsi/qla2xxx/qla_attr.c
36818@@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
36819 return 0;
36820 }
36821
36822-struct fc_function_template qla2xxx_transport_functions = {
36823+fc_function_template_no_const qla2xxx_transport_functions = {
36824
36825 .show_host_node_name = 1,
36826 .show_host_port_name = 1,
36827@@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
36828 .bsg_timeout = qla24xx_bsg_timeout,
36829 };
36830
36831-struct fc_function_template qla2xxx_transport_vport_functions = {
36832+fc_function_template_no_const qla2xxx_transport_vport_functions = {
36833
36834 .show_host_node_name = 1,
36835 .show_host_port_name = 1,
36836diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36837index 39007f5..7fafc64 100644
36838--- a/drivers/scsi/qla2xxx/qla_def.h
36839+++ b/drivers/scsi/qla2xxx/qla_def.h
36840@@ -2284,7 +2284,7 @@ struct isp_operations {
36841 int (*start_scsi) (srb_t *);
36842 int (*abort_isp) (struct scsi_qla_host *);
36843 int (*iospace_config)(struct qla_hw_data*);
36844-};
36845+} __no_const;
36846
36847 /* MSI-X Support *************************************************************/
36848
36849diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
36850index 9eacd2d..d79629c 100644
36851--- a/drivers/scsi/qla2xxx/qla_gbl.h
36852+++ b/drivers/scsi/qla2xxx/qla_gbl.h
36853@@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
36854 struct device_attribute;
36855 extern struct device_attribute *qla2x00_host_attrs[];
36856 struct fc_function_template;
36857-extern struct fc_function_template qla2xxx_transport_functions;
36858-extern struct fc_function_template qla2xxx_transport_vport_functions;
36859+extern fc_function_template_no_const qla2xxx_transport_functions;
36860+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
36861 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
36862 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
36863 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
36864diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36865index 96a5616..eeb185a 100644
36866--- a/drivers/scsi/qla4xxx/ql4_def.h
36867+++ b/drivers/scsi/qla4xxx/ql4_def.h
36868@@ -268,7 +268,7 @@ struct ddb_entry {
36869 * (4000 only) */
36870 atomic_t relogin_timer; /* Max Time to wait for
36871 * relogin to complete */
36872- atomic_t relogin_retry_count; /* Num of times relogin has been
36873+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36874 * retried */
36875 uint32_t default_time2wait; /* Default Min time between
36876 * relogins (+aens) */
36877diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36878index cd15678..f7e6846 100644
36879--- a/drivers/scsi/qla4xxx/ql4_os.c
36880+++ b/drivers/scsi/qla4xxx/ql4_os.c
36881@@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36882 */
36883 if (!iscsi_is_session_online(cls_sess)) {
36884 /* Reset retry relogin timer */
36885- atomic_inc(&ddb_entry->relogin_retry_count);
36886+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36887 DEBUG2(ql4_printk(KERN_INFO, ha,
36888 "%s: index[%d] relogin timed out-retrying"
36889 " relogin (%d), retry (%d)\n", __func__,
36890 ddb_entry->fw_ddb_index,
36891- atomic_read(&ddb_entry->relogin_retry_count),
36892+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36893 ddb_entry->default_time2wait + 4));
36894 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36895 atomic_set(&ddb_entry->retry_relogin_timer,
36896@@ -4517,7 +4517,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36897
36898 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36899 atomic_set(&ddb_entry->relogin_timer, 0);
36900- atomic_set(&ddb_entry->relogin_retry_count, 0);
36901+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36902 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36903 ddb_entry->default_relogin_timeout =
36904 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
36905diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36906index bbbc9c9..ce22f77 100644
36907--- a/drivers/scsi/scsi.c
36908+++ b/drivers/scsi/scsi.c
36909@@ -659,7 +659,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36910 unsigned long timeout;
36911 int rtn = 0;
36912
36913- atomic_inc(&cmd->device->iorequest_cnt);
36914+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36915
36916 /* check if the device is still usable */
36917 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36918diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36919index 6dfb978..ddc470e 100644
36920--- a/drivers/scsi/scsi_lib.c
36921+++ b/drivers/scsi/scsi_lib.c
36922@@ -1415,7 +1415,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36923 shost = sdev->host;
36924 scsi_init_cmd_errh(cmd);
36925 cmd->result = DID_NO_CONNECT << 16;
36926- atomic_inc(&cmd->device->iorequest_cnt);
36927+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36928
36929 /*
36930 * SCSI request completion path will do scsi_device_unbusy(),
36931@@ -1441,9 +1441,9 @@ static void scsi_softirq_done(struct request *rq)
36932
36933 INIT_LIST_HEAD(&cmd->eh_entry);
36934
36935- atomic_inc(&cmd->device->iodone_cnt);
36936+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
36937 if (cmd->result)
36938- atomic_inc(&cmd->device->ioerr_cnt);
36939+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36940
36941 disposition = scsi_decide_disposition(cmd);
36942 if (disposition != SUCCESS &&
36943diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36944index 04c2a27..9d8bd66 100644
36945--- a/drivers/scsi/scsi_sysfs.c
36946+++ b/drivers/scsi/scsi_sysfs.c
36947@@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36948 char *buf) \
36949 { \
36950 struct scsi_device *sdev = to_scsi_device(dev); \
36951- unsigned long long count = atomic_read(&sdev->field); \
36952+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
36953 return snprintf(buf, 20, "0x%llx\n", count); \
36954 } \
36955 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36956diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36957index 84a1fdf..693b0d6 100644
36958--- a/drivers/scsi/scsi_tgt_lib.c
36959+++ b/drivers/scsi/scsi_tgt_lib.c
36960@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36961 int err;
36962
36963 dprintk("%lx %u\n", uaddr, len);
36964- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36965+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36966 if (err) {
36967 /*
36968 * TODO: need to fixup sg_tablesize, max_segment_size,
36969diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36970index 5797604..289a5b5 100644
36971--- a/drivers/scsi/scsi_transport_fc.c
36972+++ b/drivers/scsi/scsi_transport_fc.c
36973@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36974 * Netlink Infrastructure
36975 */
36976
36977-static atomic_t fc_event_seq;
36978+static atomic_unchecked_t fc_event_seq;
36979
36980 /**
36981 * fc_get_event_number - Obtain the next sequential FC event number
36982@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
36983 u32
36984 fc_get_event_number(void)
36985 {
36986- return atomic_add_return(1, &fc_event_seq);
36987+ return atomic_add_return_unchecked(1, &fc_event_seq);
36988 }
36989 EXPORT_SYMBOL(fc_get_event_number);
36990
36991@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
36992 {
36993 int error;
36994
36995- atomic_set(&fc_event_seq, 0);
36996+ atomic_set_unchecked(&fc_event_seq, 0);
36997
36998 error = transport_class_register(&fc_host_class);
36999 if (error)
37000@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37001 char *cp;
37002
37003 *val = simple_strtoul(buf, &cp, 0);
37004- if ((*cp && (*cp != '\n')) || (*val < 0))
37005+ if (*cp && (*cp != '\n'))
37006 return -EINVAL;
37007 /*
37008 * Check for overflow; dev_loss_tmo is u32
37009diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37010index 1cf640e..78e9014 100644
37011--- a/drivers/scsi/scsi_transport_iscsi.c
37012+++ b/drivers/scsi/scsi_transport_iscsi.c
37013@@ -79,7 +79,7 @@ struct iscsi_internal {
37014 struct transport_container session_cont;
37015 };
37016
37017-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37018+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37019 static struct workqueue_struct *iscsi_eh_timer_workq;
37020
37021 static DEFINE_IDA(iscsi_sess_ida);
37022@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37023 int err;
37024
37025 ihost = shost->shost_data;
37026- session->sid = atomic_add_return(1, &iscsi_session_nr);
37027+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37028
37029 if (target_id == ISCSI_MAX_TARGET) {
37030 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37031@@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37032 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37033 ISCSI_TRANSPORT_VERSION);
37034
37035- atomic_set(&iscsi_session_nr, 0);
37036+ atomic_set_unchecked(&iscsi_session_nr, 0);
37037
37038 err = class_register(&iscsi_transport_class);
37039 if (err)
37040diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37041index 21a045e..ec89e03 100644
37042--- a/drivers/scsi/scsi_transport_srp.c
37043+++ b/drivers/scsi/scsi_transport_srp.c
37044@@ -33,7 +33,7 @@
37045 #include "scsi_transport_srp_internal.h"
37046
37047 struct srp_host_attrs {
37048- atomic_t next_port_id;
37049+ atomic_unchecked_t next_port_id;
37050 };
37051 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37052
37053@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37054 struct Scsi_Host *shost = dev_to_shost(dev);
37055 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37056
37057- atomic_set(&srp_host->next_port_id, 0);
37058+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37059 return 0;
37060 }
37061
37062@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37063 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37064 rport->roles = ids->roles;
37065
37066- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37067+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37068 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37069
37070 transport_setup_device(&rport->dev);
37071diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37072index 9c5c5f2..8414557 100644
37073--- a/drivers/scsi/sg.c
37074+++ b/drivers/scsi/sg.c
37075@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37076 sdp->disk->disk_name,
37077 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37078 NULL,
37079- (char *)arg);
37080+ (char __user *)arg);
37081 case BLKTRACESTART:
37082 return blk_trace_startstop(sdp->device->request_queue, 1);
37083 case BLKTRACESTOP:
37084diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37085index 1041cb8..4a946fa 100644
37086--- a/drivers/spi/spi.c
37087+++ b/drivers/spi/spi.c
37088@@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37089 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37090
37091 /* portable code must never pass more than 32 bytes */
37092-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37093+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37094
37095 static u8 *buf;
37096
37097diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37098index 34afc16..ffe44dd 100644
37099--- a/drivers/staging/octeon/ethernet-rx.c
37100+++ b/drivers/staging/octeon/ethernet-rx.c
37101@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37102 /* Increment RX stats for virtual ports */
37103 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37104 #ifdef CONFIG_64BIT
37105- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37106- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37107+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37108+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37109 #else
37110- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37111- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37112+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37113+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37114 #endif
37115 }
37116 netif_receive_skb(skb);
37117@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37118 dev->name);
37119 */
37120 #ifdef CONFIG_64BIT
37121- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37122+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37123 #else
37124- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37125+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37126 #endif
37127 dev_kfree_skb_irq(skb);
37128 }
37129diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37130index 18f7a79..cc3bc24 100644
37131--- a/drivers/staging/octeon/ethernet.c
37132+++ b/drivers/staging/octeon/ethernet.c
37133@@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37134 * since the RX tasklet also increments it.
37135 */
37136 #ifdef CONFIG_64BIT
37137- atomic64_add(rx_status.dropped_packets,
37138- (atomic64_t *)&priv->stats.rx_dropped);
37139+ atomic64_add_unchecked(rx_status.dropped_packets,
37140+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37141 #else
37142- atomic_add(rx_status.dropped_packets,
37143- (atomic_t *)&priv->stats.rx_dropped);
37144+ atomic_add_unchecked(rx_status.dropped_packets,
37145+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37146 #endif
37147 }
37148
37149diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37150index dc23395..cf7e9b1 100644
37151--- a/drivers/staging/rtl8712/rtl871x_io.h
37152+++ b/drivers/staging/rtl8712/rtl871x_io.h
37153@@ -108,7 +108,7 @@ struct _io_ops {
37154 u8 *pmem);
37155 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37156 u8 *pmem);
37157-};
37158+} __no_const;
37159
37160 struct io_req {
37161 struct list_head list;
37162diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37163index c7b5e8b..783d6cb 100644
37164--- a/drivers/staging/sbe-2t3e3/netdev.c
37165+++ b/drivers/staging/sbe-2t3e3/netdev.c
37166@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37167 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37168
37169 if (rlen)
37170- if (copy_to_user(data, &resp, rlen))
37171+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37172 return -EFAULT;
37173
37174 return 0;
37175diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37176index 42cdafe..2769103 100644
37177--- a/drivers/staging/speakup/speakup_soft.c
37178+++ b/drivers/staging/speakup/speakup_soft.c
37179@@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37180 break;
37181 } else if (!initialized) {
37182 if (*init) {
37183- ch = *init;
37184 init++;
37185 } else {
37186 initialized = 1;
37187 }
37188+ ch = *init;
37189 } else {
37190 ch = synth_buffer_getc();
37191 }
37192diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37193index 5d89c0f..9261317 100644
37194--- a/drivers/staging/usbip/usbip_common.h
37195+++ b/drivers/staging/usbip/usbip_common.h
37196@@ -289,7 +289,7 @@ struct usbip_device {
37197 void (*shutdown)(struct usbip_device *);
37198 void (*reset)(struct usbip_device *);
37199 void (*unusable)(struct usbip_device *);
37200- } eh_ops;
37201+ } __no_const eh_ops;
37202 };
37203
37204 #define kthread_get_run(threadfn, data, namefmt, ...) \
37205diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37206index 88b3298..3783eee 100644
37207--- a/drivers/staging/usbip/vhci.h
37208+++ b/drivers/staging/usbip/vhci.h
37209@@ -88,7 +88,7 @@ struct vhci_hcd {
37210 unsigned resuming:1;
37211 unsigned long re_timeout;
37212
37213- atomic_t seqnum;
37214+ atomic_unchecked_t seqnum;
37215
37216 /*
37217 * NOTE:
37218diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37219index f708cba..2de6d72 100644
37220--- a/drivers/staging/usbip/vhci_hcd.c
37221+++ b/drivers/staging/usbip/vhci_hcd.c
37222@@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37223 return;
37224 }
37225
37226- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37227+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37228 if (priv->seqnum == 0xffff)
37229 dev_info(&urb->dev->dev, "seqnum max\n");
37230
37231@@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37232 return -ENOMEM;
37233 }
37234
37235- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37236+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37237 if (unlink->seqnum == 0xffff)
37238 pr_info("seqnum max\n");
37239
37240@@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37241 vdev->rhport = rhport;
37242 }
37243
37244- atomic_set(&vhci->seqnum, 0);
37245+ atomic_set_unchecked(&vhci->seqnum, 0);
37246 spin_lock_init(&vhci->lock);
37247
37248 hcd->power_budget = 0; /* no limit */
37249diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37250index f0eaf04..5a82e06 100644
37251--- a/drivers/staging/usbip/vhci_rx.c
37252+++ b/drivers/staging/usbip/vhci_rx.c
37253@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37254 if (!urb) {
37255 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37256 pr_info("max seqnum %d\n",
37257- atomic_read(&the_controller->seqnum));
37258+ atomic_read_unchecked(&the_controller->seqnum));
37259 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37260 return;
37261 }
37262diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37263index 7735027..30eed13 100644
37264--- a/drivers/staging/vt6655/hostap.c
37265+++ b/drivers/staging/vt6655/hostap.c
37266@@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37267 *
37268 */
37269
37270+static net_device_ops_no_const apdev_netdev_ops;
37271+
37272 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37273 {
37274 PSDevice apdev_priv;
37275 struct net_device *dev = pDevice->dev;
37276 int ret;
37277- const struct net_device_ops apdev_netdev_ops = {
37278- .ndo_start_xmit = pDevice->tx_80211,
37279- };
37280
37281 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37282
37283@@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37284 *apdev_priv = *pDevice;
37285 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37286
37287+ /* only half broken now */
37288+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37289 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37290
37291 pDevice->apdev->type = ARPHRD_IEEE80211;
37292diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37293index 51b5adf..098e320 100644
37294--- a/drivers/staging/vt6656/hostap.c
37295+++ b/drivers/staging/vt6656/hostap.c
37296@@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37297 *
37298 */
37299
37300+static net_device_ops_no_const apdev_netdev_ops;
37301+
37302 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37303 {
37304 PSDevice apdev_priv;
37305 struct net_device *dev = pDevice->dev;
37306 int ret;
37307- const struct net_device_ops apdev_netdev_ops = {
37308- .ndo_start_xmit = pDevice->tx_80211,
37309- };
37310
37311 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37312
37313@@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37314 *apdev_priv = *pDevice;
37315 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37316
37317+ /* only half broken now */
37318+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37319 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37320
37321 pDevice->apdev->type = ARPHRD_IEEE80211;
37322diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37323index 7843dfd..3db105f 100644
37324--- a/drivers/staging/wlan-ng/hfa384x_usb.c
37325+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37326@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37327
37328 struct usbctlx_completor {
37329 int (*complete) (struct usbctlx_completor *);
37330-};
37331+} __no_const;
37332
37333 static int
37334 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37335diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37336index 1ca66ea..76f1343 100644
37337--- a/drivers/staging/zcache/tmem.c
37338+++ b/drivers/staging/zcache/tmem.c
37339@@ -39,7 +39,7 @@
37340 * A tmem host implementation must use this function to register callbacks
37341 * for memory allocation.
37342 */
37343-static struct tmem_hostops tmem_hostops;
37344+static tmem_hostops_no_const tmem_hostops;
37345
37346 static void tmem_objnode_tree_init(void);
37347
37348@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37349 * A tmem host implementation must use this function to register
37350 * callbacks for a page-accessible memory (PAM) implementation
37351 */
37352-static struct tmem_pamops tmem_pamops;
37353+static tmem_pamops_no_const tmem_pamops;
37354
37355 void tmem_register_pamops(struct tmem_pamops *m)
37356 {
37357diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37358index 0d4aa82..f7832d4 100644
37359--- a/drivers/staging/zcache/tmem.h
37360+++ b/drivers/staging/zcache/tmem.h
37361@@ -180,6 +180,7 @@ struct tmem_pamops {
37362 void (*new_obj)(struct tmem_obj *);
37363 int (*replace_in_obj)(void *, struct tmem_obj *);
37364 };
37365+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37366 extern void tmem_register_pamops(struct tmem_pamops *m);
37367
37368 /* memory allocation methods provided by the host implementation */
37369@@ -189,6 +190,7 @@ struct tmem_hostops {
37370 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37371 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37372 };
37373+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37374 extern void tmem_register_hostops(struct tmem_hostops *m);
37375
37376 /* core tmem accessor functions */
37377diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37378index 634d0f3..efff61f 100644
37379--- a/drivers/target/target_core_transport.c
37380+++ b/drivers/target/target_core_transport.c
37381@@ -1233,7 +1233,7 @@ struct se_device *transport_add_device_to_core_hba(
37382 spin_lock_init(&dev->se_port_lock);
37383 spin_lock_init(&dev->se_tmr_lock);
37384 spin_lock_init(&dev->qf_cmd_lock);
37385- atomic_set(&dev->dev_ordered_id, 0);
37386+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
37387
37388 se_dev_set_default_attribs(dev, dev_limits);
37389
37390@@ -1402,7 +1402,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37391 * Used to determine when ORDERED commands should go from
37392 * Dormant to Active status.
37393 */
37394- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37395+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37396 smp_mb__after_atomic_inc();
37397 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37398 cmd->se_ordered_id, cmd->sam_task_attr,
37399diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37400index e61cabd..7617d26 100644
37401--- a/drivers/tty/cyclades.c
37402+++ b/drivers/tty/cyclades.c
37403@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37404 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37405 info->port.count);
37406 #endif
37407- info->port.count++;
37408+ atomic_inc(&info->port.count);
37409 #ifdef CY_DEBUG_COUNT
37410 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37411- current->pid, info->port.count);
37412+ current->pid, atomic_read(&info->port.count));
37413 #endif
37414
37415 /*
37416@@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37417 for (j = 0; j < cy_card[i].nports; j++) {
37418 info = &cy_card[i].ports[j];
37419
37420- if (info->port.count) {
37421+ if (atomic_read(&info->port.count)) {
37422 /* XXX is the ldisc num worth this? */
37423 struct tty_struct *tty;
37424 struct tty_ldisc *ld;
37425diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37426index 2d691eb..be02ebd 100644
37427--- a/drivers/tty/hvc/hvc_console.c
37428+++ b/drivers/tty/hvc/hvc_console.c
37429@@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37430
37431 spin_lock_irqsave(&hp->port.lock, flags);
37432 /* Check and then increment for fast path open. */
37433- if (hp->port.count++ > 0) {
37434+ if (atomic_inc_return(&hp->port.count) > 1) {
37435 spin_unlock_irqrestore(&hp->port.lock, flags);
37436 hvc_kick();
37437 return 0;
37438@@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37439
37440 spin_lock_irqsave(&hp->port.lock, flags);
37441
37442- if (--hp->port.count == 0) {
37443+ if (atomic_dec_return(&hp->port.count) == 0) {
37444 spin_unlock_irqrestore(&hp->port.lock, flags);
37445 /* We are done with the tty pointer now. */
37446 tty_port_tty_set(&hp->port, NULL);
37447@@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37448 */
37449 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37450 } else {
37451- if (hp->port.count < 0)
37452+ if (atomic_read(&hp->port.count) < 0)
37453 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37454- hp->vtermno, hp->port.count);
37455+ hp->vtermno, atomic_read(&hp->port.count));
37456 spin_unlock_irqrestore(&hp->port.lock, flags);
37457 }
37458
37459@@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37460 * open->hangup case this can be called after the final close so prevent
37461 * that from happening for now.
37462 */
37463- if (hp->port.count <= 0) {
37464+ if (atomic_read(&hp->port.count) <= 0) {
37465 spin_unlock_irqrestore(&hp->port.lock, flags);
37466 return;
37467 }
37468
37469- temp_open_count = hp->port.count;
37470- hp->port.count = 0;
37471+ temp_open_count = atomic_read(&hp->port.count);
37472+ atomic_set(&hp->port.count, 0);
37473 spin_unlock_irqrestore(&hp->port.lock, flags);
37474 tty_port_tty_set(&hp->port, NULL);
37475
37476@@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37477 return -EPIPE;
37478
37479 /* FIXME what's this (unprotected) check for? */
37480- if (hp->port.count <= 0)
37481+ if (atomic_read(&hp->port.count) <= 0)
37482 return -EIO;
37483
37484 spin_lock_irqsave(&hp->lock, flags);
37485diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37486index d56788c..12d8f85 100644
37487--- a/drivers/tty/hvc/hvcs.c
37488+++ b/drivers/tty/hvc/hvcs.c
37489@@ -83,6 +83,7 @@
37490 #include <asm/hvcserver.h>
37491 #include <asm/uaccess.h>
37492 #include <asm/vio.h>
37493+#include <asm/local.h>
37494
37495 /*
37496 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37497@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37498
37499 spin_lock_irqsave(&hvcsd->lock, flags);
37500
37501- if (hvcsd->port.count > 0) {
37502+ if (atomic_read(&hvcsd->port.count) > 0) {
37503 spin_unlock_irqrestore(&hvcsd->lock, flags);
37504 printk(KERN_INFO "HVCS: vterm state unchanged. "
37505 "The hvcs device node is still in use.\n");
37506@@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37507 if ((retval = hvcs_partner_connect(hvcsd)))
37508 goto error_release;
37509
37510- hvcsd->port.count = 1;
37511+ atomic_set(&hvcsd->port.count, 1);
37512 hvcsd->port.tty = tty;
37513 tty->driver_data = hvcsd;
37514
37515@@ -1168,7 +1169,7 @@ fast_open:
37516
37517 spin_lock_irqsave(&hvcsd->lock, flags);
37518 tty_port_get(&hvcsd->port);
37519- hvcsd->port.count++;
37520+ atomic_inc(&hvcsd->port.count);
37521 hvcsd->todo_mask |= HVCS_SCHED_READ;
37522 spin_unlock_irqrestore(&hvcsd->lock, flags);
37523
37524@@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37525 hvcsd = tty->driver_data;
37526
37527 spin_lock_irqsave(&hvcsd->lock, flags);
37528- if (--hvcsd->port.count == 0) {
37529+ if (atomic_dec_and_test(&hvcsd->port.count)) {
37530
37531 vio_disable_interrupts(hvcsd->vdev);
37532
37533@@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37534 free_irq(irq, hvcsd);
37535 tty_port_put(&hvcsd->port);
37536 return;
37537- } else if (hvcsd->port.count < 0) {
37538+ } else if (atomic_read(&hvcsd->port.count) < 0) {
37539 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37540 " is missmanaged.\n",
37541- hvcsd->vdev->unit_address, hvcsd->port.count);
37542+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37543 }
37544
37545 spin_unlock_irqrestore(&hvcsd->lock, flags);
37546@@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37547
37548 spin_lock_irqsave(&hvcsd->lock, flags);
37549 /* Preserve this so that we know how many kref refs to put */
37550- temp_open_count = hvcsd->port.count;
37551+ temp_open_count = atomic_read(&hvcsd->port.count);
37552
37553 /*
37554 * Don't kref put inside the spinlock because the destruction
37555@@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37556 tty->driver_data = NULL;
37557 hvcsd->port.tty = NULL;
37558
37559- hvcsd->port.count = 0;
37560+ atomic_set(&hvcsd->port.count, 0);
37561
37562 /* This will drop any buffered data on the floor which is OK in a hangup
37563 * scenario. */
37564@@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
37565 * the middle of a write operation? This is a crummy place to do this
37566 * but we want to keep it all in the spinlock.
37567 */
37568- if (hvcsd->port.count <= 0) {
37569+ if (atomic_read(&hvcsd->port.count) <= 0) {
37570 spin_unlock_irqrestore(&hvcsd->lock, flags);
37571 return -ENODEV;
37572 }
37573@@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37574 {
37575 struct hvcs_struct *hvcsd = tty->driver_data;
37576
37577- if (!hvcsd || hvcsd->port.count <= 0)
37578+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
37579 return 0;
37580
37581 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37582diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37583index f8b5fa0..4ba9f89 100644
37584--- a/drivers/tty/ipwireless/tty.c
37585+++ b/drivers/tty/ipwireless/tty.c
37586@@ -29,6 +29,7 @@
37587 #include <linux/tty_driver.h>
37588 #include <linux/tty_flip.h>
37589 #include <linux/uaccess.h>
37590+#include <asm/local.h>
37591
37592 #include "tty.h"
37593 #include "network.h"
37594@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37595 mutex_unlock(&tty->ipw_tty_mutex);
37596 return -ENODEV;
37597 }
37598- if (tty->port.count == 0)
37599+ if (atomic_read(&tty->port.count) == 0)
37600 tty->tx_bytes_queued = 0;
37601
37602- tty->port.count++;
37603+ atomic_inc(&tty->port.count);
37604
37605 tty->port.tty = linux_tty;
37606 linux_tty->driver_data = tty;
37607@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37608
37609 static void do_ipw_close(struct ipw_tty *tty)
37610 {
37611- tty->port.count--;
37612-
37613- if (tty->port.count == 0) {
37614+ if (atomic_dec_return(&tty->port.count) == 0) {
37615 struct tty_struct *linux_tty = tty->port.tty;
37616
37617 if (linux_tty != NULL) {
37618@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37619 return;
37620
37621 mutex_lock(&tty->ipw_tty_mutex);
37622- if (tty->port.count == 0) {
37623+ if (atomic_read(&tty->port.count) == 0) {
37624 mutex_unlock(&tty->ipw_tty_mutex);
37625 return;
37626 }
37627@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37628 return;
37629 }
37630
37631- if (!tty->port.count) {
37632+ if (!atomic_read(&tty->port.count)) {
37633 mutex_unlock(&tty->ipw_tty_mutex);
37634 return;
37635 }
37636@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37637 return -ENODEV;
37638
37639 mutex_lock(&tty->ipw_tty_mutex);
37640- if (!tty->port.count) {
37641+ if (!atomic_read(&tty->port.count)) {
37642 mutex_unlock(&tty->ipw_tty_mutex);
37643 return -EINVAL;
37644 }
37645@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37646 if (!tty)
37647 return -ENODEV;
37648
37649- if (!tty->port.count)
37650+ if (!atomic_read(&tty->port.count))
37651 return -EINVAL;
37652
37653 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37654@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37655 if (!tty)
37656 return 0;
37657
37658- if (!tty->port.count)
37659+ if (!atomic_read(&tty->port.count))
37660 return 0;
37661
37662 return tty->tx_bytes_queued;
37663@@ -375,7 +374,7 @@ static int ipw_tiocmget(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 get_control_lines(tty);
37672@@ -391,7 +390,7 @@ ipw_tiocmset(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 return set_control_lines(tty, set, clear);
37681@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37682 if (!tty)
37683 return -ENODEV;
37684
37685- if (!tty->port.count)
37686+ if (!atomic_read(&tty->port.count))
37687 return -EINVAL;
37688
37689 /* FIXME: Exactly how is the tty object locked here .. */
37690@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37691 * are gone */
37692 mutex_lock(&ttyj->ipw_tty_mutex);
37693 }
37694- while (ttyj->port.count)
37695+ while (atomic_read(&ttyj->port.count))
37696 do_ipw_close(ttyj);
37697 ipwireless_disassociate_network_ttys(network,
37698 ttyj->channel_idx);
37699diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
37700index 324467d..504cc25 100644
37701--- a/drivers/tty/moxa.c
37702+++ b/drivers/tty/moxa.c
37703@@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
37704 }
37705
37706 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
37707- ch->port.count++;
37708+ atomic_inc(&ch->port.count);
37709 tty->driver_data = ch;
37710 tty_port_tty_set(&ch->port, tty);
37711 mutex_lock(&ch->port.mutex);
37712diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37713index c43b683..4dab83e 100644
37714--- a/drivers/tty/n_gsm.c
37715+++ b/drivers/tty/n_gsm.c
37716@@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37717 kref_init(&dlci->ref);
37718 mutex_init(&dlci->mutex);
37719 dlci->fifo = &dlci->_fifo;
37720- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37721+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37722 kfree(dlci);
37723 return NULL;
37724 }
37725@@ -2895,7 +2895,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
37726 if (dlci == NULL)
37727 return -ENOMEM;
37728 port = &dlci->port;
37729- port->count++;
37730+ atomic_inc(&port->count);
37731 tty->driver_data = dlci;
37732 dlci_get(dlci);
37733 dlci_get(dlci->gsm->dlci[0]);
37734diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37735index ee1c268..0e97caf 100644
37736--- a/drivers/tty/n_tty.c
37737+++ b/drivers/tty/n_tty.c
37738@@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37739 {
37740 *ops = tty_ldisc_N_TTY;
37741 ops->owner = NULL;
37742- ops->refcount = ops->flags = 0;
37743+ atomic_set(&ops->refcount, 0);
37744+ ops->flags = 0;
37745 }
37746 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37747diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37748index 5505ffc..7affff9 100644
37749--- a/drivers/tty/pty.c
37750+++ b/drivers/tty/pty.c
37751@@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
37752 panic("Couldn't register Unix98 pts driver");
37753
37754 /* Now create the /dev/ptmx special device */
37755+ pax_open_kernel();
37756 tty_default_fops(&ptmx_fops);
37757- ptmx_fops.open = ptmx_open;
37758+ *(void **)&ptmx_fops.open = ptmx_open;
37759+ pax_close_kernel();
37760
37761 cdev_init(&ptmx_cdev, &ptmx_fops);
37762 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37763diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
37764index 777d5f9..56d67ca 100644
37765--- a/drivers/tty/rocket.c
37766+++ b/drivers/tty/rocket.c
37767@@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37768 tty->driver_data = info;
37769 tty_port_tty_set(port, tty);
37770
37771- if (port->count++ == 0) {
37772+ if (atomic_inc_return(&port->count) == 1) {
37773 atomic_inc(&rp_num_ports_open);
37774
37775 #ifdef ROCKET_DEBUG_OPEN
37776@@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37777 #endif
37778 }
37779 #ifdef ROCKET_DEBUG_OPEN
37780- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
37781+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
37782 #endif
37783
37784 /*
37785@@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
37786 spin_unlock_irqrestore(&info->port.lock, flags);
37787 return;
37788 }
37789- if (info->port.count)
37790+ if (atomic_read(&info->port.count))
37791 atomic_dec(&rp_num_ports_open);
37792 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
37793 spin_unlock_irqrestore(&info->port.lock, flags);
37794diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37795index 2b42a01..32a2ed3 100644
37796--- a/drivers/tty/serial/kgdboc.c
37797+++ b/drivers/tty/serial/kgdboc.c
37798@@ -24,8 +24,9 @@
37799 #define MAX_CONFIG_LEN 40
37800
37801 static struct kgdb_io kgdboc_io_ops;
37802+static struct kgdb_io kgdboc_io_ops_console;
37803
37804-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37805+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37806 static int configured = -1;
37807
37808 static char config[MAX_CONFIG_LEN];
37809@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37810 kgdboc_unregister_kbd();
37811 if (configured == 1)
37812 kgdb_unregister_io_module(&kgdboc_io_ops);
37813+ else if (configured == 2)
37814+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
37815 }
37816
37817 static int configure_kgdboc(void)
37818@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37819 int err;
37820 char *cptr = config;
37821 struct console *cons;
37822+ int is_console = 0;
37823
37824 err = kgdboc_option_setup(config);
37825 if (err || !strlen(config) || isspace(config[0]))
37826 goto noconfig;
37827
37828 err = -ENODEV;
37829- kgdboc_io_ops.is_console = 0;
37830 kgdb_tty_driver = NULL;
37831
37832 kgdboc_use_kms = 0;
37833@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37834 int idx;
37835 if (cons->device && cons->device(cons, &idx) == p &&
37836 idx == tty_line) {
37837- kgdboc_io_ops.is_console = 1;
37838+ is_console = 1;
37839 break;
37840 }
37841 cons = cons->next;
37842@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37843 kgdb_tty_line = tty_line;
37844
37845 do_register:
37846- err = kgdb_register_io_module(&kgdboc_io_ops);
37847+ if (is_console) {
37848+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
37849+ configured = 2;
37850+ } else {
37851+ err = kgdb_register_io_module(&kgdboc_io_ops);
37852+ configured = 1;
37853+ }
37854 if (err)
37855 goto noconfig;
37856
37857- configured = 1;
37858-
37859 return 0;
37860
37861 noconfig:
37862@@ -213,7 +220,7 @@ noconfig:
37863 static int __init init_kgdboc(void)
37864 {
37865 /* Already configured? */
37866- if (configured == 1)
37867+ if (configured >= 1)
37868 return 0;
37869
37870 return configure_kgdboc();
37871@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37872 if (config[len - 1] == '\n')
37873 config[len - 1] = '\0';
37874
37875- if (configured == 1)
37876+ if (configured >= 1)
37877 cleanup_kgdboc();
37878
37879 /* Go and configure with the new params. */
37880@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37881 .post_exception = kgdboc_post_exp_handler,
37882 };
37883
37884+static struct kgdb_io kgdboc_io_ops_console = {
37885+ .name = "kgdboc",
37886+ .read_char = kgdboc_get_char,
37887+ .write_char = kgdboc_put_char,
37888+ .pre_exception = kgdboc_pre_exp_handler,
37889+ .post_exception = kgdboc_post_exp_handler,
37890+ .is_console = 1
37891+};
37892+
37893 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37894 /* This is only available if kgdboc is a built in for early debugging */
37895 static int __init kgdboc_early_init(char *opt)
37896diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
37897index 246b823..9e0db76 100644
37898--- a/drivers/tty/serial/serial_core.c
37899+++ b/drivers/tty/serial/serial_core.c
37900@@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
37901 uart_flush_buffer(tty);
37902 uart_shutdown(tty, state);
37903 spin_lock_irqsave(&port->lock, flags);
37904- port->count = 0;
37905+ atomic_set(&port->count, 0);
37906 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
37907 spin_unlock_irqrestore(&port->lock, flags);
37908 tty_port_tty_set(port, NULL);
37909@@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37910 goto end;
37911 }
37912
37913- port->count++;
37914+ atomic_inc(&port->count);
37915 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
37916 retval = -ENXIO;
37917 goto err_dec_count;
37918@@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37919 /*
37920 * Make sure the device is in D0 state.
37921 */
37922- if (port->count == 1)
37923+ if (atomic_read(&port->count) == 1)
37924 uart_change_pm(state, 0);
37925
37926 /*
37927@@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37928 end:
37929 return retval;
37930 err_dec_count:
37931- port->count--;
37932+ atomic_inc(&port->count);
37933 mutex_unlock(&port->mutex);
37934 goto end;
37935 }
37936diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
37937index 593d40a..bdc61f3 100644
37938--- a/drivers/tty/synclink.c
37939+++ b/drivers/tty/synclink.c
37940@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
37941
37942 if (debug_level >= DEBUG_LEVEL_INFO)
37943 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
37944- __FILE__,__LINE__, info->device_name, info->port.count);
37945+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
37946
37947 if (tty_port_close_start(&info->port, tty, filp) == 0)
37948 goto cleanup;
37949@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
37950 cleanup:
37951 if (debug_level >= DEBUG_LEVEL_INFO)
37952 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
37953- tty->driver->name, info->port.count);
37954+ tty->driver->name, atomic_read(&info->port.count));
37955
37956 } /* end of mgsl_close() */
37957
37958@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
37959
37960 mgsl_flush_buffer(tty);
37961 shutdown(info);
37962-
37963- info->port.count = 0;
37964+
37965+ atomic_set(&info->port.count, 0);
37966 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
37967 info->port.tty = NULL;
37968
37969@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
37970
37971 if (debug_level >= DEBUG_LEVEL_INFO)
37972 printk("%s(%d):block_til_ready before block on %s count=%d\n",
37973- __FILE__,__LINE__, tty->driver->name, port->count );
37974+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
37975
37976 spin_lock_irqsave(&info->irq_spinlock, flags);
37977 if (!tty_hung_up_p(filp)) {
37978 extra_count = true;
37979- port->count--;
37980+ atomic_dec(&port->count);
37981 }
37982 spin_unlock_irqrestore(&info->irq_spinlock, flags);
37983 port->blocked_open++;
37984@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
37985
37986 if (debug_level >= DEBUG_LEVEL_INFO)
37987 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
37988- __FILE__,__LINE__, tty->driver->name, port->count );
37989+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
37990
37991 tty_unlock();
37992 schedule();
37993@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
37994
37995 /* FIXME: Racy on hangup during close wait */
37996 if (extra_count)
37997- port->count++;
37998+ atomic_inc(&port->count);
37999 port->blocked_open--;
38000
38001 if (debug_level >= DEBUG_LEVEL_INFO)
38002 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38003- __FILE__,__LINE__, tty->driver->name, port->count );
38004+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38005
38006 if (!retval)
38007 port->flags |= ASYNC_NORMAL_ACTIVE;
38008@@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38009
38010 if (debug_level >= DEBUG_LEVEL_INFO)
38011 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38012- __FILE__,__LINE__,tty->driver->name, info->port.count);
38013+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38014
38015 /* If port is closing, signal caller to try again */
38016 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38017@@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38018 spin_unlock_irqrestore(&info->netlock, flags);
38019 goto cleanup;
38020 }
38021- info->port.count++;
38022+ atomic_inc(&info->port.count);
38023 spin_unlock_irqrestore(&info->netlock, flags);
38024
38025- if (info->port.count == 1) {
38026+ if (atomic_read(&info->port.count) == 1) {
38027 /* 1st open on this device, init hardware */
38028 retval = startup(info);
38029 if (retval < 0)
38030@@ -3444,8 +3444,8 @@ cleanup:
38031 if (retval) {
38032 if (tty->count == 1)
38033 info->port.tty = NULL; /* tty layer will release tty struct */
38034- if(info->port.count)
38035- info->port.count--;
38036+ if (atomic_read(&info->port.count))
38037+ atomic_dec(&info->port.count);
38038 }
38039
38040 return retval;
38041@@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38042 unsigned short new_crctype;
38043
38044 /* return error if TTY interface open */
38045- if (info->port.count)
38046+ if (atomic_read(&info->port.count))
38047 return -EBUSY;
38048
38049 switch (encoding)
38050@@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38051
38052 /* arbitrate between network and tty opens */
38053 spin_lock_irqsave(&info->netlock, flags);
38054- if (info->port.count != 0 || info->netcount != 0) {
38055+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38056 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38057 spin_unlock_irqrestore(&info->netlock, flags);
38058 return -EBUSY;
38059@@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38060 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38061
38062 /* return error if TTY interface open */
38063- if (info->port.count)
38064+ if (atomic_read(&info->port.count))
38065 return -EBUSY;
38066
38067 if (cmd != SIOCWANDEV)
38068diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38069index aa1debf..9297a16 100644
38070--- a/drivers/tty/synclink_gt.c
38071+++ b/drivers/tty/synclink_gt.c
38072@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38073 tty->driver_data = info;
38074 info->port.tty = tty;
38075
38076- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38077+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38078
38079 /* If port is closing, signal caller to try again */
38080 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38081@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38082 mutex_unlock(&info->port.mutex);
38083 goto cleanup;
38084 }
38085- info->port.count++;
38086+ atomic_inc(&info->port.count);
38087 spin_unlock_irqrestore(&info->netlock, flags);
38088
38089- if (info->port.count == 1) {
38090+ if (atomic_read(&info->port.count) == 1) {
38091 /* 1st open on this device, init hardware */
38092 retval = startup(info);
38093 if (retval < 0) {
38094@@ -716,8 +716,8 @@ cleanup:
38095 if (retval) {
38096 if (tty->count == 1)
38097 info->port.tty = NULL; /* tty layer will release tty struct */
38098- if(info->port.count)
38099- info->port.count--;
38100+ if(atomic_read(&info->port.count))
38101+ atomic_dec(&info->port.count);
38102 }
38103
38104 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38105@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38106
38107 if (sanity_check(info, tty->name, "close"))
38108 return;
38109- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38110+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38111
38112 if (tty_port_close_start(&info->port, tty, filp) == 0)
38113 goto cleanup;
38114@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38115 tty_port_close_end(&info->port, tty);
38116 info->port.tty = NULL;
38117 cleanup:
38118- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38119+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38120 }
38121
38122 static void hangup(struct tty_struct *tty)
38123@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38124 shutdown(info);
38125
38126 spin_lock_irqsave(&info->port.lock, flags);
38127- info->port.count = 0;
38128+ atomic_set(&info->port.count, 0);
38129 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38130 info->port.tty = NULL;
38131 spin_unlock_irqrestore(&info->port.lock, flags);
38132@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38133 unsigned short new_crctype;
38134
38135 /* return error if TTY interface open */
38136- if (info->port.count)
38137+ if (atomic_read(&info->port.count))
38138 return -EBUSY;
38139
38140 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38141@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38142
38143 /* arbitrate between network and tty opens */
38144 spin_lock_irqsave(&info->netlock, flags);
38145- if (info->port.count != 0 || info->netcount != 0) {
38146+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38147 DBGINFO(("%s hdlc_open busy\n", dev->name));
38148 spin_unlock_irqrestore(&info->netlock, flags);
38149 return -EBUSY;
38150@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38151 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38152
38153 /* return error if TTY interface open */
38154- if (info->port.count)
38155+ if (atomic_read(&info->port.count))
38156 return -EBUSY;
38157
38158 if (cmd != SIOCWANDEV)
38159@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38160 if (port == NULL)
38161 continue;
38162 spin_lock(&port->lock);
38163- if ((port->port.count || port->netcount) &&
38164+ if ((atomic_read(&port->port.count) || port->netcount) &&
38165 port->pending_bh && !port->bh_running &&
38166 !port->bh_requested) {
38167 DBGISR(("%s bh queued\n", port->device_name));
38168@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38169 spin_lock_irqsave(&info->lock, flags);
38170 if (!tty_hung_up_p(filp)) {
38171 extra_count = true;
38172- port->count--;
38173+ atomic_dec(&port->count);
38174 }
38175 spin_unlock_irqrestore(&info->lock, flags);
38176 port->blocked_open++;
38177@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38178 remove_wait_queue(&port->open_wait, &wait);
38179
38180 if (extra_count)
38181- port->count++;
38182+ atomic_inc(&port->count);
38183 port->blocked_open--;
38184
38185 if (!retval)
38186diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38187index a3dddc1..8905ab2 100644
38188--- a/drivers/tty/synclinkmp.c
38189+++ b/drivers/tty/synclinkmp.c
38190@@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38191
38192 if (debug_level >= DEBUG_LEVEL_INFO)
38193 printk("%s(%d):%s open(), old ref count = %d\n",
38194- __FILE__,__LINE__,tty->driver->name, info->port.count);
38195+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38196
38197 /* If port is closing, signal caller to try again */
38198 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38199@@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38200 spin_unlock_irqrestore(&info->netlock, flags);
38201 goto cleanup;
38202 }
38203- info->port.count++;
38204+ atomic_inc(&info->port.count);
38205 spin_unlock_irqrestore(&info->netlock, flags);
38206
38207- if (info->port.count == 1) {
38208+ if (atomic_read(&info->port.count) == 1) {
38209 /* 1st open on this device, init hardware */
38210 retval = startup(info);
38211 if (retval < 0)
38212@@ -788,8 +788,8 @@ cleanup:
38213 if (retval) {
38214 if (tty->count == 1)
38215 info->port.tty = NULL; /* tty layer will release tty struct */
38216- if(info->port.count)
38217- info->port.count--;
38218+ if(atomic_read(&info->port.count))
38219+ atomic_dec(&info->port.count);
38220 }
38221
38222 return retval;
38223@@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38224
38225 if (debug_level >= DEBUG_LEVEL_INFO)
38226 printk("%s(%d):%s close() entry, count=%d\n",
38227- __FILE__,__LINE__, info->device_name, info->port.count);
38228+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38229
38230 if (tty_port_close_start(&info->port, tty, filp) == 0)
38231 goto cleanup;
38232@@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38233 cleanup:
38234 if (debug_level >= DEBUG_LEVEL_INFO)
38235 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38236- tty->driver->name, info->port.count);
38237+ tty->driver->name, atomic_read(&info->port.count));
38238 }
38239
38240 /* Called by tty_hangup() when a hangup is signaled.
38241@@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38242 shutdown(info);
38243
38244 spin_lock_irqsave(&info->port.lock, flags);
38245- info->port.count = 0;
38246+ atomic_set(&info->port.count, 0);
38247 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38248 info->port.tty = NULL;
38249 spin_unlock_irqrestore(&info->port.lock, flags);
38250@@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38251 unsigned short new_crctype;
38252
38253 /* return error if TTY interface open */
38254- if (info->port.count)
38255+ if (atomic_read(&info->port.count))
38256 return -EBUSY;
38257
38258 switch (encoding)
38259@@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38260
38261 /* arbitrate between network and tty opens */
38262 spin_lock_irqsave(&info->netlock, flags);
38263- if (info->port.count != 0 || info->netcount != 0) {
38264+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38265 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38266 spin_unlock_irqrestore(&info->netlock, flags);
38267 return -EBUSY;
38268@@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38269 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38270
38271 /* return error if TTY interface open */
38272- if (info->port.count)
38273+ if (atomic_read(&info->port.count))
38274 return -EBUSY;
38275
38276 if (cmd != SIOCWANDEV)
38277@@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38278 * do not request bottom half processing if the
38279 * device is not open in a normal mode.
38280 */
38281- if ( port && (port->port.count || port->netcount) &&
38282+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38283 port->pending_bh && !port->bh_running &&
38284 !port->bh_requested ) {
38285 if ( debug_level >= DEBUG_LEVEL_ISR )
38286@@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38287
38288 if (debug_level >= DEBUG_LEVEL_INFO)
38289 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38290- __FILE__,__LINE__, tty->driver->name, port->count );
38291+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38292
38293 spin_lock_irqsave(&info->lock, flags);
38294 if (!tty_hung_up_p(filp)) {
38295 extra_count = true;
38296- port->count--;
38297+ atomic_dec(&port->count);
38298 }
38299 spin_unlock_irqrestore(&info->lock, flags);
38300 port->blocked_open++;
38301@@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38302
38303 if (debug_level >= DEBUG_LEVEL_INFO)
38304 printk("%s(%d):%s block_til_ready() count=%d\n",
38305- __FILE__,__LINE__, tty->driver->name, port->count );
38306+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38307
38308 tty_unlock();
38309 schedule();
38310@@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38311 remove_wait_queue(&port->open_wait, &wait);
38312
38313 if (extra_count)
38314- port->count++;
38315+ atomic_inc(&port->count);
38316 port->blocked_open--;
38317
38318 if (debug_level >= DEBUG_LEVEL_INFO)
38319 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38320- __FILE__,__LINE__, tty->driver->name, port->count );
38321+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38322
38323 if (!retval)
38324 port->flags |= ASYNC_NORMAL_ACTIVE;
38325diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38326index 05728894..b9d44c6 100644
38327--- a/drivers/tty/sysrq.c
38328+++ b/drivers/tty/sysrq.c
38329@@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38330 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38331 size_t count, loff_t *ppos)
38332 {
38333- if (count) {
38334+ if (count && capable(CAP_SYS_ADMIN)) {
38335 char c;
38336
38337 if (get_user(c, buf))
38338diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38339index b425c79..08a3f06 100644
38340--- a/drivers/tty/tty_io.c
38341+++ b/drivers/tty/tty_io.c
38342@@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38343
38344 void tty_default_fops(struct file_operations *fops)
38345 {
38346- *fops = tty_fops;
38347+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38348 }
38349
38350 /*
38351diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38352index 9911eb6..5abe0e1 100644
38353--- a/drivers/tty/tty_ldisc.c
38354+++ b/drivers/tty/tty_ldisc.c
38355@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38356 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38357 struct tty_ldisc_ops *ldo = ld->ops;
38358
38359- ldo->refcount--;
38360+ atomic_dec(&ldo->refcount);
38361 module_put(ldo->owner);
38362 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38363
38364@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38365 spin_lock_irqsave(&tty_ldisc_lock, flags);
38366 tty_ldiscs[disc] = new_ldisc;
38367 new_ldisc->num = disc;
38368- new_ldisc->refcount = 0;
38369+ atomic_set(&new_ldisc->refcount, 0);
38370 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38371
38372 return ret;
38373@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38374 return -EINVAL;
38375
38376 spin_lock_irqsave(&tty_ldisc_lock, flags);
38377- if (tty_ldiscs[disc]->refcount)
38378+ if (atomic_read(&tty_ldiscs[disc]->refcount))
38379 ret = -EBUSY;
38380 else
38381 tty_ldiscs[disc] = NULL;
38382@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38383 if (ldops) {
38384 ret = ERR_PTR(-EAGAIN);
38385 if (try_module_get(ldops->owner)) {
38386- ldops->refcount++;
38387+ atomic_inc(&ldops->refcount);
38388 ret = ldops;
38389 }
38390 }
38391@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38392 unsigned long flags;
38393
38394 spin_lock_irqsave(&tty_ldisc_lock, flags);
38395- ldops->refcount--;
38396+ atomic_dec(&ldops->refcount);
38397 module_put(ldops->owner);
38398 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38399 }
38400diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38401index bf6e238..d401c04 100644
38402--- a/drivers/tty/tty_port.c
38403+++ b/drivers/tty/tty_port.c
38404@@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38405 unsigned long flags;
38406
38407 spin_lock_irqsave(&port->lock, flags);
38408- port->count = 0;
38409+ atomic_set(&port->count, 0);
38410 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38411 if (port->tty) {
38412 set_bit(TTY_IO_ERROR, &port->tty->flags);
38413@@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38414 /* The port lock protects the port counts */
38415 spin_lock_irqsave(&port->lock, flags);
38416 if (!tty_hung_up_p(filp))
38417- port->count--;
38418+ atomic_dec(&port->count);
38419 port->blocked_open++;
38420 spin_unlock_irqrestore(&port->lock, flags);
38421
38422@@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38423 we must not mess that up further */
38424 spin_lock_irqsave(&port->lock, flags);
38425 if (!tty_hung_up_p(filp))
38426- port->count++;
38427+ atomic_inc(&port->count);
38428 port->blocked_open--;
38429 if (retval == 0)
38430 port->flags |= ASYNC_NORMAL_ACTIVE;
38431@@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38432 return 0;
38433 }
38434
38435- if (tty->count == 1 && port->count != 1) {
38436+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
38437 printk(KERN_WARNING
38438 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38439- port->count);
38440- port->count = 1;
38441+ atomic_read(&port->count));
38442+ atomic_set(&port->count, 1);
38443 }
38444- if (--port->count < 0) {
38445+ if (atomic_dec_return(&port->count) < 0) {
38446 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38447- port->count);
38448- port->count = 0;
38449+ atomic_read(&port->count));
38450+ atomic_set(&port->count, 0);
38451 }
38452
38453- if (port->count) {
38454+ if (atomic_read(&port->count)) {
38455 spin_unlock_irqrestore(&port->lock, flags);
38456 if (port->ops->drop)
38457 port->ops->drop(port);
38458@@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38459 {
38460 spin_lock_irq(&port->lock);
38461 if (!tty_hung_up_p(filp))
38462- ++port->count;
38463+ atomic_inc(&port->count);
38464 spin_unlock_irq(&port->lock);
38465 tty_port_tty_set(port, tty);
38466
38467diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38468index 48cc6f2..85584dd 100644
38469--- a/drivers/tty/vt/keyboard.c
38470+++ b/drivers/tty/vt/keyboard.c
38471@@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38472 kbd->kbdmode == VC_OFF) &&
38473 value != KVAL(K_SAK))
38474 return; /* SAK is allowed even in raw mode */
38475+
38476+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38477+ {
38478+ void *func = fn_handler[value];
38479+ if (func == fn_show_state || func == fn_show_ptregs ||
38480+ func == fn_show_mem)
38481+ return;
38482+ }
38483+#endif
38484+
38485 fn_handler[value](vc);
38486 }
38487
38488@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38489 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38490 return -EFAULT;
38491
38492- if (!capable(CAP_SYS_TTY_CONFIG))
38493- perm = 0;
38494-
38495 switch (cmd) {
38496 case KDGKBENT:
38497 /* Ensure another thread doesn't free it under us */
38498@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38499 spin_unlock_irqrestore(&kbd_event_lock, flags);
38500 return put_user(val, &user_kbe->kb_value);
38501 case KDSKBENT:
38502+ if (!capable(CAP_SYS_TTY_CONFIG))
38503+ perm = 0;
38504+
38505 if (!perm)
38506 return -EPERM;
38507 if (!i && v == K_NOSUCHMAP) {
38508@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38509 int i, j, k;
38510 int ret;
38511
38512- if (!capable(CAP_SYS_TTY_CONFIG))
38513- perm = 0;
38514-
38515 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38516 if (!kbs) {
38517 ret = -ENOMEM;
38518@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38519 kfree(kbs);
38520 return ((p && *p) ? -EOVERFLOW : 0);
38521 case KDSKBSENT:
38522+ if (!capable(CAP_SYS_TTY_CONFIG))
38523+ perm = 0;
38524+
38525 if (!perm) {
38526 ret = -EPERM;
38527 goto reterr;
38528diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38529index a783d53..cb30d94 100644
38530--- a/drivers/uio/uio.c
38531+++ b/drivers/uio/uio.c
38532@@ -25,6 +25,7 @@
38533 #include <linux/kobject.h>
38534 #include <linux/cdev.h>
38535 #include <linux/uio_driver.h>
38536+#include <asm/local.h>
38537
38538 #define UIO_MAX_DEVICES (1U << MINORBITS)
38539
38540@@ -32,10 +33,10 @@ struct uio_device {
38541 struct module *owner;
38542 struct device *dev;
38543 int minor;
38544- atomic_t event;
38545+ atomic_unchecked_t event;
38546 struct fasync_struct *async_queue;
38547 wait_queue_head_t wait;
38548- int vma_count;
38549+ local_t vma_count;
38550 struct uio_info *info;
38551 struct kobject *map_dir;
38552 struct kobject *portio_dir;
38553@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38554 struct device_attribute *attr, char *buf)
38555 {
38556 struct uio_device *idev = dev_get_drvdata(dev);
38557- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38558+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38559 }
38560
38561 static struct device_attribute uio_class_attributes[] = {
38562@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38563 {
38564 struct uio_device *idev = info->uio_dev;
38565
38566- atomic_inc(&idev->event);
38567+ atomic_inc_unchecked(&idev->event);
38568 wake_up_interruptible(&idev->wait);
38569 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38570 }
38571@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38572 }
38573
38574 listener->dev = idev;
38575- listener->event_count = atomic_read(&idev->event);
38576+ listener->event_count = atomic_read_unchecked(&idev->event);
38577 filep->private_data = listener;
38578
38579 if (idev->info->open) {
38580@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38581 return -EIO;
38582
38583 poll_wait(filep, &idev->wait, wait);
38584- if (listener->event_count != atomic_read(&idev->event))
38585+ if (listener->event_count != atomic_read_unchecked(&idev->event))
38586 return POLLIN | POLLRDNORM;
38587 return 0;
38588 }
38589@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38590 do {
38591 set_current_state(TASK_INTERRUPTIBLE);
38592
38593- event_count = atomic_read(&idev->event);
38594+ event_count = atomic_read_unchecked(&idev->event);
38595 if (event_count != listener->event_count) {
38596 if (copy_to_user(buf, &event_count, count))
38597 retval = -EFAULT;
38598@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38599 static void uio_vma_open(struct vm_area_struct *vma)
38600 {
38601 struct uio_device *idev = vma->vm_private_data;
38602- idev->vma_count++;
38603+ local_inc(&idev->vma_count);
38604 }
38605
38606 static void uio_vma_close(struct vm_area_struct *vma)
38607 {
38608 struct uio_device *idev = vma->vm_private_data;
38609- idev->vma_count--;
38610+ local_dec(&idev->vma_count);
38611 }
38612
38613 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38614@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38615 idev->owner = owner;
38616 idev->info = info;
38617 init_waitqueue_head(&idev->wait);
38618- atomic_set(&idev->event, 0);
38619+ atomic_set_unchecked(&idev->event, 0);
38620
38621 ret = uio_get_minor(idev);
38622 if (ret)
38623diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38624index b7eb86a..36d28af 100644
38625--- a/drivers/usb/atm/cxacru.c
38626+++ b/drivers/usb/atm/cxacru.c
38627@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38628 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38629 if (ret < 2)
38630 return -EINVAL;
38631- if (index < 0 || index > 0x7f)
38632+ if (index > 0x7f)
38633 return -EINVAL;
38634 pos += tmp;
38635
38636diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38637index ee62b35..b663594 100644
38638--- a/drivers/usb/atm/usbatm.c
38639+++ b/drivers/usb/atm/usbatm.c
38640@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38641 if (printk_ratelimit())
38642 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38643 __func__, vpi, vci);
38644- atomic_inc(&vcc->stats->rx_err);
38645+ atomic_inc_unchecked(&vcc->stats->rx_err);
38646 return;
38647 }
38648
38649@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38650 if (length > ATM_MAX_AAL5_PDU) {
38651 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38652 __func__, length, vcc);
38653- atomic_inc(&vcc->stats->rx_err);
38654+ atomic_inc_unchecked(&vcc->stats->rx_err);
38655 goto out;
38656 }
38657
38658@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38659 if (sarb->len < pdu_length) {
38660 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38661 __func__, pdu_length, sarb->len, vcc);
38662- atomic_inc(&vcc->stats->rx_err);
38663+ atomic_inc_unchecked(&vcc->stats->rx_err);
38664 goto out;
38665 }
38666
38667 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38668 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38669 __func__, vcc);
38670- atomic_inc(&vcc->stats->rx_err);
38671+ atomic_inc_unchecked(&vcc->stats->rx_err);
38672 goto out;
38673 }
38674
38675@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38676 if (printk_ratelimit())
38677 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38678 __func__, length);
38679- atomic_inc(&vcc->stats->rx_drop);
38680+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38681 goto out;
38682 }
38683
38684@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38685
38686 vcc->push(vcc, skb);
38687
38688- atomic_inc(&vcc->stats->rx);
38689+ atomic_inc_unchecked(&vcc->stats->rx);
38690 out:
38691 skb_trim(sarb, 0);
38692 }
38693@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38694 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38695
38696 usbatm_pop(vcc, skb);
38697- atomic_inc(&vcc->stats->tx);
38698+ atomic_inc_unchecked(&vcc->stats->tx);
38699
38700 skb = skb_dequeue(&instance->sndqueue);
38701 }
38702@@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38703 if (!left--)
38704 return sprintf(page,
38705 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38706- atomic_read(&atm_dev->stats.aal5.tx),
38707- atomic_read(&atm_dev->stats.aal5.tx_err),
38708- atomic_read(&atm_dev->stats.aal5.rx),
38709- atomic_read(&atm_dev->stats.aal5.rx_err),
38710- atomic_read(&atm_dev->stats.aal5.rx_drop));
38711+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38712+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38713+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38714+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38715+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38716
38717 if (!left--) {
38718 if (instance->disconnected)
38719diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38720index d956965..4179a77 100644
38721--- a/drivers/usb/core/devices.c
38722+++ b/drivers/usb/core/devices.c
38723@@ -126,7 +126,7 @@ static const char format_endpt[] =
38724 * time it gets called.
38725 */
38726 static struct device_connect_event {
38727- atomic_t count;
38728+ atomic_unchecked_t count;
38729 wait_queue_head_t wait;
38730 } device_event = {
38731 .count = ATOMIC_INIT(1),
38732@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38733
38734 void usbfs_conn_disc_event(void)
38735 {
38736- atomic_add(2, &device_event.count);
38737+ atomic_add_unchecked(2, &device_event.count);
38738 wake_up(&device_event.wait);
38739 }
38740
38741@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38742
38743 poll_wait(file, &device_event.wait, wait);
38744
38745- event_count = atomic_read(&device_event.count);
38746+ event_count = atomic_read_unchecked(&device_event.count);
38747 if (file->f_version != event_count) {
38748 file->f_version = event_count;
38749 return POLLIN | POLLRDNORM;
38750diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38751index 1fc8f12..20647c1 100644
38752--- a/drivers/usb/early/ehci-dbgp.c
38753+++ b/drivers/usb/early/ehci-dbgp.c
38754@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38755
38756 #ifdef CONFIG_KGDB
38757 static struct kgdb_io kgdbdbgp_io_ops;
38758-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38759+static struct kgdb_io kgdbdbgp_io_ops_console;
38760+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38761 #else
38762 #define dbgp_kgdb_mode (0)
38763 #endif
38764@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38765 .write_char = kgdbdbgp_write_char,
38766 };
38767
38768+static struct kgdb_io kgdbdbgp_io_ops_console = {
38769+ .name = "kgdbdbgp",
38770+ .read_char = kgdbdbgp_read_char,
38771+ .write_char = kgdbdbgp_write_char,
38772+ .is_console = 1
38773+};
38774+
38775 static int kgdbdbgp_wait_time;
38776
38777 static int __init kgdbdbgp_parse_config(char *str)
38778@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38779 ptr++;
38780 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38781 }
38782- kgdb_register_io_module(&kgdbdbgp_io_ops);
38783- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38784+ if (early_dbgp_console.index != -1)
38785+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38786+ else
38787+ kgdb_register_io_module(&kgdbdbgp_io_ops);
38788
38789 return 0;
38790 }
38791diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
38792index 5b3f5ff..6e00893 100644
38793--- a/drivers/usb/gadget/u_serial.c
38794+++ b/drivers/usb/gadget/u_serial.c
38795@@ -731,9 +731,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38796 spin_lock_irq(&port->port_lock);
38797
38798 /* already open? Great. */
38799- if (port->port.count) {
38800+ if (atomic_read(&port->port.count)) {
38801 status = 0;
38802- port->port.count++;
38803+ atomic_inc(&port->port.count);
38804
38805 /* currently opening/closing? wait ... */
38806 } else if (port->openclose) {
38807@@ -792,7 +792,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38808 tty->driver_data = port;
38809 port->port.tty = tty;
38810
38811- port->port.count = 1;
38812+ atomic_set(&port->port.count, 1);
38813 port->openclose = false;
38814
38815 /* if connected, start the I/O stream */
38816@@ -834,11 +834,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38817
38818 spin_lock_irq(&port->port_lock);
38819
38820- if (port->port.count != 1) {
38821- if (port->port.count == 0)
38822+ if (atomic_read(&port->port.count) != 1) {
38823+ if (atomic_read(&port->port.count) == 0)
38824 WARN_ON(1);
38825 else
38826- --port->port.count;
38827+ atomic_dec(&port->port.count);
38828 goto exit;
38829 }
38830
38831@@ -848,7 +848,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38832 * and sleep if necessary
38833 */
38834 port->openclose = true;
38835- port->port.count = 0;
38836+ atomic_set(&port->port.count, 0);
38837
38838 gser = port->port_usb;
38839 if (gser && gser->disconnect)
38840@@ -1152,7 +1152,7 @@ static int gs_closed(struct gs_port *port)
38841 int cond;
38842
38843 spin_lock_irq(&port->port_lock);
38844- cond = (port->port.count == 0) && !port->openclose;
38845+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
38846 spin_unlock_irq(&port->port_lock);
38847 return cond;
38848 }
38849@@ -1265,7 +1265,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
38850 /* if it's already open, start I/O ... and notify the serial
38851 * protocol about open/close status (connect/disconnect).
38852 */
38853- if (port->port.count) {
38854+ if (atomic_read(&port->port.count)) {
38855 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
38856 gs_start_io(port);
38857 if (gser->connect)
38858@@ -1312,7 +1312,7 @@ void gserial_disconnect(struct gserial *gser)
38859
38860 port->port_usb = NULL;
38861 gser->ioport = NULL;
38862- if (port->port.count > 0 || port->openclose) {
38863+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
38864 wake_up_interruptible(&port->drain_wait);
38865 if (port->port.tty)
38866 tty_hangup(port->port.tty);
38867@@ -1328,7 +1328,7 @@ void gserial_disconnect(struct gserial *gser)
38868
38869 /* finally, free any unused/unusable I/O buffers */
38870 spin_lock_irqsave(&port->port_lock, flags);
38871- if (port->port.count == 0 && !port->openclose)
38872+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
38873 gs_buf_free(&port->port_write_buf);
38874 gs_free_requests(gser->out, &port->read_pool, NULL);
38875 gs_free_requests(gser->out, &port->read_queue, NULL);
38876diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
38877index b9cca6d..75c75df 100644
38878--- a/drivers/usb/serial/console.c
38879+++ b/drivers/usb/serial/console.c
38880@@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
38881
38882 info->port = port;
38883
38884- ++port->port.count;
38885+ atomic_inc(&port->port.count);
38886 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
38887 if (serial->type->set_termios) {
38888 /*
38889@@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
38890 }
38891 /* Now that any required fake tty operations are completed restore
38892 * the tty port count */
38893- --port->port.count;
38894+ atomic_dec(&port->port.count);
38895 /* The console is special in terms of closing the device so
38896 * indicate this port is now acting as a system console. */
38897 port->port.console = 1;
38898@@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
38899 free_tty:
38900 kfree(tty);
38901 reset_open_count:
38902- port->port.count = 0;
38903+ atomic_set(&port->port.count, 0);
38904 usb_autopm_put_interface(serial->interface);
38905 error_get_interface:
38906 usb_serial_put(serial);
38907diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38908index d6bea3e..60b250e 100644
38909--- a/drivers/usb/wusbcore/wa-hc.h
38910+++ b/drivers/usb/wusbcore/wa-hc.h
38911@@ -192,7 +192,7 @@ struct wahc {
38912 struct list_head xfer_delayed_list;
38913 spinlock_t xfer_list_lock;
38914 struct work_struct xfer_work;
38915- atomic_t xfer_id_count;
38916+ atomic_unchecked_t xfer_id_count;
38917 };
38918
38919
38920@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38921 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38922 spin_lock_init(&wa->xfer_list_lock);
38923 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38924- atomic_set(&wa->xfer_id_count, 1);
38925+ atomic_set_unchecked(&wa->xfer_id_count, 1);
38926 }
38927
38928 /**
38929diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38930index 57c01ab..8a05959 100644
38931--- a/drivers/usb/wusbcore/wa-xfer.c
38932+++ b/drivers/usb/wusbcore/wa-xfer.c
38933@@ -296,7 +296,7 @@ out:
38934 */
38935 static void wa_xfer_id_init(struct wa_xfer *xfer)
38936 {
38937- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38938+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38939 }
38940
38941 /*
38942diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38943index 112156f..eb81154 100644
38944--- a/drivers/vhost/vhost.c
38945+++ b/drivers/vhost/vhost.c
38946@@ -635,7 +635,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38947 return 0;
38948 }
38949
38950-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38951+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38952 {
38953 struct file *eventfp, *filep = NULL,
38954 *pollstart = NULL, *pollstop = NULL;
38955diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38956index b0b2ac3..89a4399 100644
38957--- a/drivers/video/aty/aty128fb.c
38958+++ b/drivers/video/aty/aty128fb.c
38959@@ -148,7 +148,7 @@ enum {
38960 };
38961
38962 /* Must match above enum */
38963-static const char *r128_family[] __devinitdata = {
38964+static const char *r128_family[] __devinitconst = {
38965 "AGP",
38966 "PCI",
38967 "PRO AGP",
38968diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38969index 5c3960d..15cf8fc 100644
38970--- a/drivers/video/fbcmap.c
38971+++ b/drivers/video/fbcmap.c
38972@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38973 rc = -ENODEV;
38974 goto out;
38975 }
38976- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38977- !info->fbops->fb_setcmap)) {
38978+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38979 rc = -EINVAL;
38980 goto out1;
38981 }
38982diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38983index 0dff12a..2ef47b3 100644
38984--- a/drivers/video/fbmem.c
38985+++ b/drivers/video/fbmem.c
38986@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38987 image->dx += image->width + 8;
38988 }
38989 } else if (rotate == FB_ROTATE_UD) {
38990- for (x = 0; x < num && image->dx >= 0; x++) {
38991+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38992 info->fbops->fb_imageblit(info, image);
38993 image->dx -= image->width + 8;
38994 }
38995@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38996 image->dy += image->height + 8;
38997 }
38998 } else if (rotate == FB_ROTATE_CCW) {
38999- for (x = 0; x < num && image->dy >= 0; x++) {
39000+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39001 info->fbops->fb_imageblit(info, image);
39002 image->dy -= image->height + 8;
39003 }
39004@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39005 return -EFAULT;
39006 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39007 return -EINVAL;
39008- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39009+ if (con2fb.framebuffer >= FB_MAX)
39010 return -EINVAL;
39011 if (!registered_fb[con2fb.framebuffer])
39012 request_module("fb%d", con2fb.framebuffer);
39013diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39014index 5a5d092..265c5ed 100644
39015--- a/drivers/video/geode/gx1fb_core.c
39016+++ b/drivers/video/geode/gx1fb_core.c
39017@@ -29,7 +29,7 @@ static int crt_option = 1;
39018 static char panel_option[32] = "";
39019
39020 /* Modes relevant to the GX1 (taken from modedb.c) */
39021-static const struct fb_videomode __devinitdata gx1_modedb[] = {
39022+static const struct fb_videomode __devinitconst gx1_modedb[] = {
39023 /* 640x480-60 VESA */
39024 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39025 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39026diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39027index 0fad23f..0e9afa4 100644
39028--- a/drivers/video/gxt4500.c
39029+++ b/drivers/video/gxt4500.c
39030@@ -156,7 +156,7 @@ struct gxt4500_par {
39031 static char *mode_option;
39032
39033 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39034-static const struct fb_videomode defaultmode __devinitdata = {
39035+static const struct fb_videomode defaultmode __devinitconst = {
39036 .refresh = 60,
39037 .xres = 1280,
39038 .yres = 1024,
39039@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39040 return 0;
39041 }
39042
39043-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39044+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39045 .id = "IBM GXT4500P",
39046 .type = FB_TYPE_PACKED_PIXELS,
39047 .visual = FB_VISUAL_PSEUDOCOLOR,
39048diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39049index 7672d2e..b56437f 100644
39050--- a/drivers/video/i810/i810_accel.c
39051+++ b/drivers/video/i810/i810_accel.c
39052@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39053 }
39054 }
39055 printk("ringbuffer lockup!!!\n");
39056+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39057 i810_report_error(mmio);
39058 par->dev_flags |= LOCKUP;
39059 info->pixmap.scan_align = 1;
39060diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39061index b83f361..2b05a91 100644
39062--- a/drivers/video/i810/i810_main.c
39063+++ b/drivers/video/i810/i810_main.c
39064@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39065 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39066
39067 /* PCI */
39068-static const char *i810_pci_list[] __devinitdata = {
39069+static const char *i810_pci_list[] __devinitconst = {
39070 "Intel(R) 810 Framebuffer Device" ,
39071 "Intel(R) 810-DC100 Framebuffer Device" ,
39072 "Intel(R) 810E Framebuffer Device" ,
39073diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39074index de36693..3c63fc2 100644
39075--- a/drivers/video/jz4740_fb.c
39076+++ b/drivers/video/jz4740_fb.c
39077@@ -136,7 +136,7 @@ struct jzfb {
39078 uint32_t pseudo_palette[16];
39079 };
39080
39081-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39082+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39083 .id = "JZ4740 FB",
39084 .type = FB_TYPE_PACKED_PIXELS,
39085 .visual = FB_VISUAL_TRUECOLOR,
39086diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39087index 3c14e43..eafa544 100644
39088--- a/drivers/video/logo/logo_linux_clut224.ppm
39089+++ b/drivers/video/logo/logo_linux_clut224.ppm
39090@@ -1,1604 +1,1123 @@
39091 P3
39092-# Standard 224-color Linux logo
39093 80 80
39094 255
39095- 0 0 0 0 0 0 0 0 0 0 0 0
39096- 0 0 0 0 0 0 0 0 0 0 0 0
39097- 0 0 0 0 0 0 0 0 0 0 0 0
39098- 0 0 0 0 0 0 0 0 0 0 0 0
39099- 0 0 0 0 0 0 0 0 0 0 0 0
39100- 0 0 0 0 0 0 0 0 0 0 0 0
39101- 0 0 0 0 0 0 0 0 0 0 0 0
39102- 0 0 0 0 0 0 0 0 0 0 0 0
39103- 0 0 0 0 0 0 0 0 0 0 0 0
39104- 6 6 6 6 6 6 10 10 10 10 10 10
39105- 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0 0 0 0
39115- 0 0 0 0 0 0 0 0 0 0 0 0
39116- 0 0 0 0 0 0 0 0 0 0 0 0
39117- 0 0 0 0 0 0 0 0 0 0 0 0
39118- 0 0 0 0 0 0 0 0 0 0 0 0
39119- 0 0 0 0 0 0 0 0 0 0 0 0
39120- 0 0 0 0 0 0 0 0 0 0 0 0
39121- 0 0 0 0 0 0 0 0 0 0 0 0
39122- 0 0 0 0 0 0 0 0 0 0 0 0
39123- 0 0 0 6 6 6 10 10 10 14 14 14
39124- 22 22 22 26 26 26 30 30 30 34 34 34
39125- 30 30 30 30 30 30 26 26 26 18 18 18
39126- 14 14 14 10 10 10 6 6 6 0 0 0
39127- 0 0 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
39135- 0 0 0 0 0 0 0 0 0 0 0 0
39136- 0 0 0 0 0 1 0 0 1 0 0 0
39137- 0 0 0 0 0 0 0 0 0 0 0 0
39138- 0 0 0 0 0 0 0 0 0 0 0 0
39139- 0 0 0 0 0 0 0 0 0 0 0 0
39140- 0 0 0 0 0 0 0 0 0 0 0 0
39141- 0 0 0 0 0 0 0 0 0 0 0 0
39142- 0 0 0 0 0 0 0 0 0 0 0 0
39143- 6 6 6 14 14 14 26 26 26 42 42 42
39144- 54 54 54 66 66 66 78 78 78 78 78 78
39145- 78 78 78 74 74 74 66 66 66 54 54 54
39146- 42 42 42 26 26 26 18 18 18 10 10 10
39147- 6 6 6 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 0 0 0
39154- 0 0 0 0 0 0 0 0 0 0 0 0
39155- 0 0 0 0 0 0 0 0 0 0 0 0
39156- 0 0 1 0 0 0 0 0 0 0 0 0
39157- 0 0 0 0 0 0 0 0 0 0 0 0
39158- 0 0 0 0 0 0 0 0 0 0 0 0
39159- 0 0 0 0 0 0 0 0 0 0 0 0
39160- 0 0 0 0 0 0 0 0 0 0 0 0
39161- 0 0 0 0 0 0 0 0 0 0 0 0
39162- 0 0 0 0 0 0 0 0 0 10 10 10
39163- 22 22 22 42 42 42 66 66 66 86 86 86
39164- 66 66 66 38 38 38 38 38 38 22 22 22
39165- 26 26 26 34 34 34 54 54 54 66 66 66
39166- 86 86 86 70 70 70 46 46 46 26 26 26
39167- 14 14 14 6 6 6 0 0 0 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 0 0 0 0 0 0
39174- 0 0 0 0 0 0 0 0 0 0 0 0
39175- 0 0 0 0 0 0 0 0 0 0 0 0
39176- 0 0 1 0 0 1 0 0 1 0 0 0
39177- 0 0 0 0 0 0 0 0 0 0 0 0
39178- 0 0 0 0 0 0 0 0 0 0 0 0
39179- 0 0 0 0 0 0 0 0 0 0 0 0
39180- 0 0 0 0 0 0 0 0 0 0 0 0
39181- 0 0 0 0 0 0 0 0 0 0 0 0
39182- 0 0 0 0 0 0 10 10 10 26 26 26
39183- 50 50 50 82 82 82 58 58 58 6 6 6
39184- 2 2 6 2 2 6 2 2 6 2 2 6
39185- 2 2 6 2 2 6 2 2 6 2 2 6
39186- 6 6 6 54 54 54 86 86 86 66 66 66
39187- 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
39194- 0 0 0 0 0 0 0 0 0 0 0 0
39195- 0 0 0 0 0 0 0 0 0 0 0 0
39196- 0 0 0 0 0 0 0 0 0 0 0 0
39197- 0 0 0 0 0 0 0 0 0 0 0 0
39198- 0 0 0 0 0 0 0 0 0 0 0 0
39199- 0 0 0 0 0 0 0 0 0 0 0 0
39200- 0 0 0 0 0 0 0 0 0 0 0 0
39201- 0 0 0 0 0 0 0 0 0 0 0 0
39202- 0 0 0 6 6 6 22 22 22 50 50 50
39203- 78 78 78 34 34 34 2 2 6 2 2 6
39204- 2 2 6 2 2 6 2 2 6 2 2 6
39205- 2 2 6 2 2 6 2 2 6 2 2 6
39206- 2 2 6 2 2 6 6 6 6 70 70 70
39207- 78 78 78 46 46 46 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
39214- 0 0 0 0 0 0 0 0 0 0 0 0
39215- 0 0 0 0 0 0 0 0 0 0 0 0
39216- 0 0 1 0 0 1 0 0 1 0 0 0
39217- 0 0 0 0 0 0 0 0 0 0 0 0
39218- 0 0 0 0 0 0 0 0 0 0 0 0
39219- 0 0 0 0 0 0 0 0 0 0 0 0
39220- 0 0 0 0 0 0 0 0 0 0 0 0
39221- 0 0 0 0 0 0 0 0 0 0 0 0
39222- 6 6 6 18 18 18 42 42 42 82 82 82
39223- 26 26 26 2 2 6 2 2 6 2 2 6
39224- 2 2 6 2 2 6 2 2 6 2 2 6
39225- 2 2 6 2 2 6 2 2 6 14 14 14
39226- 46 46 46 34 34 34 6 6 6 2 2 6
39227- 42 42 42 78 78 78 42 42 42 18 18 18
39228- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
39234- 0 0 0 0 0 0 0 0 0 0 0 0
39235- 0 0 0 0 0 0 0 0 0 0 0 0
39236- 0 0 1 0 0 0 0 0 1 0 0 0
39237- 0 0 0 0 0 0 0 0 0 0 0 0
39238- 0 0 0 0 0 0 0 0 0 0 0 0
39239- 0 0 0 0 0 0 0 0 0 0 0 0
39240- 0 0 0 0 0 0 0 0 0 0 0 0
39241- 0 0 0 0 0 0 0 0 0 0 0 0
39242- 10 10 10 30 30 30 66 66 66 58 58 58
39243- 2 2 6 2 2 6 2 2 6 2 2 6
39244- 2 2 6 2 2 6 2 2 6 2 2 6
39245- 2 2 6 2 2 6 2 2 6 26 26 26
39246- 86 86 86 101 101 101 46 46 46 10 10 10
39247- 2 2 6 58 58 58 70 70 70 34 34 34
39248- 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
39254- 0 0 0 0 0 0 0 0 0 0 0 0
39255- 0 0 0 0 0 0 0 0 0 0 0 0
39256- 0 0 1 0 0 1 0 0 1 0 0 0
39257- 0 0 0 0 0 0 0 0 0 0 0 0
39258- 0 0 0 0 0 0 0 0 0 0 0 0
39259- 0 0 0 0 0 0 0 0 0 0 0 0
39260- 0 0 0 0 0 0 0 0 0 0 0 0
39261- 0 0 0 0 0 0 0 0 0 0 0 0
39262- 14 14 14 42 42 42 86 86 86 10 10 10
39263- 2 2 6 2 2 6 2 2 6 2 2 6
39264- 2 2 6 2 2 6 2 2 6 2 2 6
39265- 2 2 6 2 2 6 2 2 6 30 30 30
39266- 94 94 94 94 94 94 58 58 58 26 26 26
39267- 2 2 6 6 6 6 78 78 78 54 54 54
39268- 22 22 22 6 6 6 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 0 0 0
39273- 0 0 0 0 0 0 0 0 0 0 0 0
39274- 0 0 0 0 0 0 0 0 0 0 0 0
39275- 0 0 0 0 0 0 0 0 0 0 0 0
39276- 0 0 0 0 0 0 0 0 0 0 0 0
39277- 0 0 0 0 0 0 0 0 0 0 0 0
39278- 0 0 0 0 0 0 0 0 0 0 0 0
39279- 0 0 0 0 0 0 0 0 0 0 0 0
39280- 0 0 0 0 0 0 0 0 0 0 0 0
39281- 0 0 0 0 0 0 0 0 0 6 6 6
39282- 22 22 22 62 62 62 62 62 62 2 2 6
39283- 2 2 6 2 2 6 2 2 6 2 2 6
39284- 2 2 6 2 2 6 2 2 6 2 2 6
39285- 2 2 6 2 2 6 2 2 6 26 26 26
39286- 54 54 54 38 38 38 18 18 18 10 10 10
39287- 2 2 6 2 2 6 34 34 34 82 82 82
39288- 38 38 38 14 14 14 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 0 0 0
39293- 0 0 0 0 0 0 0 0 0 0 0 0
39294- 0 0 0 0 0 0 0 0 0 0 0 0
39295- 0 0 0 0 0 0 0 0 0 0 0 0
39296- 0 0 0 0 0 1 0 0 1 0 0 0
39297- 0 0 0 0 0 0 0 0 0 0 0 0
39298- 0 0 0 0 0 0 0 0 0 0 0 0
39299- 0 0 0 0 0 0 0 0 0 0 0 0
39300- 0 0 0 0 0 0 0 0 0 0 0 0
39301- 0 0 0 0 0 0 0 0 0 6 6 6
39302- 30 30 30 78 78 78 30 30 30 2 2 6
39303- 2 2 6 2 2 6 2 2 6 2 2 6
39304- 2 2 6 2 2 6 2 2 6 2 2 6
39305- 2 2 6 2 2 6 2 2 6 10 10 10
39306- 10 10 10 2 2 6 2 2 6 2 2 6
39307- 2 2 6 2 2 6 2 2 6 78 78 78
39308- 50 50 50 18 18 18 6 6 6 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 0 0 0
39313- 0 0 0 0 0 0 0 0 0 0 0 0
39314- 0 0 0 0 0 0 0 0 0 0 0 0
39315- 0 0 0 0 0 0 0 0 0 0 0 0
39316- 0 0 1 0 0 0 0 0 0 0 0 0
39317- 0 0 0 0 0 0 0 0 0 0 0 0
39318- 0 0 0 0 0 0 0 0 0 0 0 0
39319- 0 0 0 0 0 0 0 0 0 0 0 0
39320- 0 0 0 0 0 0 0 0 0 0 0 0
39321- 0 0 0 0 0 0 0 0 0 10 10 10
39322- 38 38 38 86 86 86 14 14 14 2 2 6
39323- 2 2 6 2 2 6 2 2 6 2 2 6
39324- 2 2 6 2 2 6 2 2 6 2 2 6
39325- 2 2 6 2 2 6 2 2 6 2 2 6
39326- 2 2 6 2 2 6 2 2 6 2 2 6
39327- 2 2 6 2 2 6 2 2 6 54 54 54
39328- 66 66 66 26 26 26 6 6 6 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 0 0 0
39333- 0 0 0 0 0 0 0 0 0 0 0 0
39334- 0 0 0 0 0 0 0 0 0 0 0 0
39335- 0 0 0 0 0 0 0 0 0 0 0 0
39336- 0 0 0 0 0 1 0 0 1 0 0 0
39337- 0 0 0 0 0 0 0 0 0 0 0 0
39338- 0 0 0 0 0 0 0 0 0 0 0 0
39339- 0 0 0 0 0 0 0 0 0 0 0 0
39340- 0 0 0 0 0 0 0 0 0 0 0 0
39341- 0 0 0 0 0 0 0 0 0 14 14 14
39342- 42 42 42 82 82 82 2 2 6 2 2 6
39343- 2 2 6 6 6 6 10 10 10 2 2 6
39344- 2 2 6 2 2 6 2 2 6 2 2 6
39345- 2 2 6 2 2 6 2 2 6 6 6 6
39346- 14 14 14 10 10 10 2 2 6 2 2 6
39347- 2 2 6 2 2 6 2 2 6 18 18 18
39348- 82 82 82 34 34 34 10 10 10 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 0 0 0
39353- 0 0 0 0 0 0 0 0 0 0 0 0
39354- 0 0 0 0 0 0 0 0 0 0 0 0
39355- 0 0 0 0 0 0 0 0 0 0 0 0
39356- 0 0 1 0 0 0 0 0 0 0 0 0
39357- 0 0 0 0 0 0 0 0 0 0 0 0
39358- 0 0 0 0 0 0 0 0 0 0 0 0
39359- 0 0 0 0 0 0 0 0 0 0 0 0
39360- 0 0 0 0 0 0 0 0 0 0 0 0
39361- 0 0 0 0 0 0 0 0 0 14 14 14
39362- 46 46 46 86 86 86 2 2 6 2 2 6
39363- 6 6 6 6 6 6 22 22 22 34 34 34
39364- 6 6 6 2 2 6 2 2 6 2 2 6
39365- 2 2 6 2 2 6 18 18 18 34 34 34
39366- 10 10 10 50 50 50 22 22 22 2 2 6
39367- 2 2 6 2 2 6 2 2 6 10 10 10
39368- 86 86 86 42 42 42 14 14 14 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 0 0 0
39373- 0 0 0 0 0 0 0 0 0 0 0 0
39374- 0 0 0 0 0 0 0 0 0 0 0 0
39375- 0 0 0 0 0 0 0 0 0 0 0 0
39376- 0 0 1 0 0 1 0 0 1 0 0 0
39377- 0 0 0 0 0 0 0 0 0 0 0 0
39378- 0 0 0 0 0 0 0 0 0 0 0 0
39379- 0 0 0 0 0 0 0 0 0 0 0 0
39380- 0 0 0 0 0 0 0 0 0 0 0 0
39381- 0 0 0 0 0 0 0 0 0 14 14 14
39382- 46 46 46 86 86 86 2 2 6 2 2 6
39383- 38 38 38 116 116 116 94 94 94 22 22 22
39384- 22 22 22 2 2 6 2 2 6 2 2 6
39385- 14 14 14 86 86 86 138 138 138 162 162 162
39386-154 154 154 38 38 38 26 26 26 6 6 6
39387- 2 2 6 2 2 6 2 2 6 2 2 6
39388- 86 86 86 46 46 46 14 14 14 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 0 0 0
39393- 0 0 0 0 0 0 0 0 0 0 0 0
39394- 0 0 0 0 0 0 0 0 0 0 0 0
39395- 0 0 0 0 0 0 0 0 0 0 0 0
39396- 0 0 0 0 0 0 0 0 0 0 0 0
39397- 0 0 0 0 0 0 0 0 0 0 0 0
39398- 0 0 0 0 0 0 0 0 0 0 0 0
39399- 0 0 0 0 0 0 0 0 0 0 0 0
39400- 0 0 0 0 0 0 0 0 0 0 0 0
39401- 0 0 0 0 0 0 0 0 0 14 14 14
39402- 46 46 46 86 86 86 2 2 6 14 14 14
39403-134 134 134 198 198 198 195 195 195 116 116 116
39404- 10 10 10 2 2 6 2 2 6 6 6 6
39405-101 98 89 187 187 187 210 210 210 218 218 218
39406-214 214 214 134 134 134 14 14 14 6 6 6
39407- 2 2 6 2 2 6 2 2 6 2 2 6
39408- 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0
39413- 0 0 0 0 0 0 0 0 0 0 0 0
39414- 0 0 0 0 0 0 0 0 0 0 0 0
39415- 0 0 0 0 0 0 0 0 1 0 0 0
39416- 0 0 1 0 0 1 0 0 1 0 0 0
39417- 0 0 0 0 0 0 0 0 0 0 0 0
39418- 0 0 0 0 0 0 0 0 0 0 0 0
39419- 0 0 0 0 0 0 0 0 0 0 0 0
39420- 0 0 0 0 0 0 0 0 0 0 0 0
39421- 0 0 0 0 0 0 0 0 0 14 14 14
39422- 46 46 46 86 86 86 2 2 6 54 54 54
39423-218 218 218 195 195 195 226 226 226 246 246 246
39424- 58 58 58 2 2 6 2 2 6 30 30 30
39425-210 210 210 253 253 253 174 174 174 123 123 123
39426-221 221 221 234 234 234 74 74 74 2 2 6
39427- 2 2 6 2 2 6 2 2 6 2 2 6
39428- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
39433- 0 0 0 0 0 0 0 0 0 0 0 0
39434- 0 0 0 0 0 0 0 0 0 0 0 0
39435- 0 0 0 0 0 0 0 0 0 0 0 0
39436- 0 0 0 0 0 0 0 0 0 0 0 0
39437- 0 0 0 0 0 0 0 0 0 0 0 0
39438- 0 0 0 0 0 0 0 0 0 0 0 0
39439- 0 0 0 0 0 0 0 0 0 0 0 0
39440- 0 0 0 0 0 0 0 0 0 0 0 0
39441- 0 0 0 0 0 0 0 0 0 14 14 14
39442- 46 46 46 82 82 82 2 2 6 106 106 106
39443-170 170 170 26 26 26 86 86 86 226 226 226
39444-123 123 123 10 10 10 14 14 14 46 46 46
39445-231 231 231 190 190 190 6 6 6 70 70 70
39446- 90 90 90 238 238 238 158 158 158 2 2 6
39447- 2 2 6 2 2 6 2 2 6 2 2 6
39448- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
39453- 0 0 0 0 0 0 0 0 0 0 0 0
39454- 0 0 0 0 0 0 0 0 0 0 0 0
39455- 0 0 0 0 0 0 0 0 1 0 0 0
39456- 0 0 1 0 0 1 0 0 1 0 0 0
39457- 0 0 0 0 0 0 0 0 0 0 0 0
39458- 0 0 0 0 0 0 0 0 0 0 0 0
39459- 0 0 0 0 0 0 0 0 0 0 0 0
39460- 0 0 0 0 0 0 0 0 0 0 0 0
39461- 0 0 0 0 0 0 0 0 0 14 14 14
39462- 42 42 42 86 86 86 6 6 6 116 116 116
39463-106 106 106 6 6 6 70 70 70 149 149 149
39464-128 128 128 18 18 18 38 38 38 54 54 54
39465-221 221 221 106 106 106 2 2 6 14 14 14
39466- 46 46 46 190 190 190 198 198 198 2 2 6
39467- 2 2 6 2 2 6 2 2 6 2 2 6
39468- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
39473- 0 0 0 0 0 0 0 0 0 0 0 0
39474- 0 0 0 0 0 0 0 0 0 0 0 0
39475- 0 0 0 0 0 0 0 0 1 0 0 0
39476- 0 0 1 0 0 0 0 0 1 0 0 0
39477- 0 0 0 0 0 0 0 0 0 0 0 0
39478- 0 0 0 0 0 0 0 0 0 0 0 0
39479- 0 0 0 0 0 0 0 0 0 0 0 0
39480- 0 0 0 0 0 0 0 0 0 0 0 0
39481- 0 0 0 0 0 0 0 0 0 14 14 14
39482- 42 42 42 94 94 94 14 14 14 101 101 101
39483-128 128 128 2 2 6 18 18 18 116 116 116
39484-118 98 46 121 92 8 121 92 8 98 78 10
39485-162 162 162 106 106 106 2 2 6 2 2 6
39486- 2 2 6 195 195 195 195 195 195 6 6 6
39487- 2 2 6 2 2 6 2 2 6 2 2 6
39488- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
39493- 0 0 0 0 0 0 0 0 0 0 0 0
39494- 0 0 0 0 0 0 0 0 0 0 0 0
39495- 0 0 0 0 0 0 0 0 1 0 0 1
39496- 0 0 1 0 0 0 0 0 1 0 0 0
39497- 0 0 0 0 0 0 0 0 0 0 0 0
39498- 0 0 0 0 0 0 0 0 0 0 0 0
39499- 0 0 0 0 0 0 0 0 0 0 0 0
39500- 0 0 0 0 0 0 0 0 0 0 0 0
39501- 0 0 0 0 0 0 0 0 0 10 10 10
39502- 38 38 38 90 90 90 14 14 14 58 58 58
39503-210 210 210 26 26 26 54 38 6 154 114 10
39504-226 170 11 236 186 11 225 175 15 184 144 12
39505-215 174 15 175 146 61 37 26 9 2 2 6
39506- 70 70 70 246 246 246 138 138 138 2 2 6
39507- 2 2 6 2 2 6 2 2 6 2 2 6
39508- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
39513- 0 0 0 0 0 0 0 0 0 0 0 0
39514- 0 0 0 0 0 0 0 0 0 0 0 0
39515- 0 0 0 0 0 0 0 0 0 0 0 0
39516- 0 0 0 0 0 0 0 0 0 0 0 0
39517- 0 0 0 0 0 0 0 0 0 0 0 0
39518- 0 0 0 0 0 0 0 0 0 0 0 0
39519- 0 0 0 0 0 0 0 0 0 0 0 0
39520- 0 0 0 0 0 0 0 0 0 0 0 0
39521- 0 0 0 0 0 0 0 0 0 10 10 10
39522- 38 38 38 86 86 86 14 14 14 10 10 10
39523-195 195 195 188 164 115 192 133 9 225 175 15
39524-239 182 13 234 190 10 232 195 16 232 200 30
39525-245 207 45 241 208 19 232 195 16 184 144 12
39526-218 194 134 211 206 186 42 42 42 2 2 6
39527- 2 2 6 2 2 6 2 2 6 2 2 6
39528- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
39533- 0 0 0 0 0 0 0 0 0 0 0 0
39534- 0 0 0 0 0 0 0 0 0 0 0 0
39535- 0 0 0 0 0 0 0 0 0 0 0 0
39536- 0 0 0 0 0 0 0 0 0 0 0 0
39537- 0 0 0 0 0 0 0 0 0 0 0 0
39538- 0 0 0 0 0 0 0 0 0 0 0 0
39539- 0 0 0 0 0 0 0 0 0 0 0 0
39540- 0 0 0 0 0 0 0 0 0 0 0 0
39541- 0 0 0 0 0 0 0 0 0 10 10 10
39542- 34 34 34 86 86 86 14 14 14 2 2 6
39543-121 87 25 192 133 9 219 162 10 239 182 13
39544-236 186 11 232 195 16 241 208 19 244 214 54
39545-246 218 60 246 218 38 246 215 20 241 208 19
39546-241 208 19 226 184 13 121 87 25 2 2 6
39547- 2 2 6 2 2 6 2 2 6 2 2 6
39548- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
39553- 0 0 0 0 0 0 0 0 0 0 0 0
39554- 0 0 0 0 0 0 0 0 0 0 0 0
39555- 0 0 0 0 0 0 0 0 0 0 0 0
39556- 0 0 0 0 0 0 0 0 0 0 0 0
39557- 0 0 0 0 0 0 0 0 0 0 0 0
39558- 0 0 0 0 0 0 0 0 0 0 0 0
39559- 0 0 0 0 0 0 0 0 0 0 0 0
39560- 0 0 0 0 0 0 0 0 0 0 0 0
39561- 0 0 0 0 0 0 0 0 0 10 10 10
39562- 34 34 34 82 82 82 30 30 30 61 42 6
39563-180 123 7 206 145 10 230 174 11 239 182 13
39564-234 190 10 238 202 15 241 208 19 246 218 74
39565-246 218 38 246 215 20 246 215 20 246 215 20
39566-226 184 13 215 174 15 184 144 12 6 6 6
39567- 2 2 6 2 2 6 2 2 6 2 2 6
39568- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
39573- 0 0 0 0 0 0 0 0 0 0 0 0
39574- 0 0 0 0 0 0 0 0 0 0 0 0
39575- 0 0 0 0 0 0 0 0 0 0 0 0
39576- 0 0 0 0 0 0 0 0 0 0 0 0
39577- 0 0 0 0 0 0 0 0 0 0 0 0
39578- 0 0 0 0 0 0 0 0 0 0 0 0
39579- 0 0 0 0 0 0 0 0 0 0 0 0
39580- 0 0 0 0 0 0 0 0 0 0 0 0
39581- 0 0 0 0 0 0 0 0 0 10 10 10
39582- 30 30 30 78 78 78 50 50 50 104 69 6
39583-192 133 9 216 158 10 236 178 12 236 186 11
39584-232 195 16 241 208 19 244 214 54 245 215 43
39585-246 215 20 246 215 20 241 208 19 198 155 10
39586-200 144 11 216 158 10 156 118 10 2 2 6
39587- 2 2 6 2 2 6 2 2 6 2 2 6
39588- 6 6 6 90 90 90 54 54 54 18 18 18
39589- 6 6 6 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 0 0 0
39593- 0 0 0 0 0 0 0 0 0 0 0 0
39594- 0 0 0 0 0 0 0 0 0 0 0 0
39595- 0 0 0 0 0 0 0 0 0 0 0 0
39596- 0 0 0 0 0 0 0 0 0 0 0 0
39597- 0 0 0 0 0 0 0 0 0 0 0 0
39598- 0 0 0 0 0 0 0 0 0 0 0 0
39599- 0 0 0 0 0 0 0 0 0 0 0 0
39600- 0 0 0 0 0 0 0 0 0 0 0 0
39601- 0 0 0 0 0 0 0 0 0 10 10 10
39602- 30 30 30 78 78 78 46 46 46 22 22 22
39603-137 92 6 210 162 10 239 182 13 238 190 10
39604-238 202 15 241 208 19 246 215 20 246 215 20
39605-241 208 19 203 166 17 185 133 11 210 150 10
39606-216 158 10 210 150 10 102 78 10 2 2 6
39607- 6 6 6 54 54 54 14 14 14 2 2 6
39608- 2 2 6 62 62 62 74 74 74 30 30 30
39609- 10 10 10 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 0 0 0
39613- 0 0 0 0 0 0 0 0 0 0 0 0
39614- 0 0 0 0 0 0 0 0 0 0 0 0
39615- 0 0 0 0 0 0 0 0 0 0 0 0
39616- 0 0 0 0 0 0 0 0 0 0 0 0
39617- 0 0 0 0 0 0 0 0 0 0 0 0
39618- 0 0 0 0 0 0 0 0 0 0 0 0
39619- 0 0 0 0 0 0 0 0 0 0 0 0
39620- 0 0 0 0 0 0 0 0 0 0 0 0
39621- 0 0 0 0 0 0 0 0 0 10 10 10
39622- 34 34 34 78 78 78 50 50 50 6 6 6
39623- 94 70 30 139 102 15 190 146 13 226 184 13
39624-232 200 30 232 195 16 215 174 15 190 146 13
39625-168 122 10 192 133 9 210 150 10 213 154 11
39626-202 150 34 182 157 106 101 98 89 2 2 6
39627- 2 2 6 78 78 78 116 116 116 58 58 58
39628- 2 2 6 22 22 22 90 90 90 46 46 46
39629- 18 18 18 6 6 6 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 0 0 0
39633- 0 0 0 0 0 0 0 0 0 0 0 0
39634- 0 0 0 0 0 0 0 0 0 0 0 0
39635- 0 0 0 0 0 0 0 0 0 0 0 0
39636- 0 0 0 0 0 0 0 0 0 0 0 0
39637- 0 0 0 0 0 0 0 0 0 0 0 0
39638- 0 0 0 0 0 0 0 0 0 0 0 0
39639- 0 0 0 0 0 0 0 0 0 0 0 0
39640- 0 0 0 0 0 0 0 0 0 0 0 0
39641- 0 0 0 0 0 0 0 0 0 10 10 10
39642- 38 38 38 86 86 86 50 50 50 6 6 6
39643-128 128 128 174 154 114 156 107 11 168 122 10
39644-198 155 10 184 144 12 197 138 11 200 144 11
39645-206 145 10 206 145 10 197 138 11 188 164 115
39646-195 195 195 198 198 198 174 174 174 14 14 14
39647- 2 2 6 22 22 22 116 116 116 116 116 116
39648- 22 22 22 2 2 6 74 74 74 70 70 70
39649- 30 30 30 10 10 10 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 0 0 0 0 0 0
39653- 0 0 0 0 0 0 0 0 0 0 0 0
39654- 0 0 0 0 0 0 0 0 0 0 0 0
39655- 0 0 0 0 0 0 0 0 0 0 0 0
39656- 0 0 0 0 0 0 0 0 0 0 0 0
39657- 0 0 0 0 0 0 0 0 0 0 0 0
39658- 0 0 0 0 0 0 0 0 0 0 0 0
39659- 0 0 0 0 0 0 0 0 0 0 0 0
39660- 0 0 0 0 0 0 0 0 0 0 0 0
39661- 0 0 0 0 0 0 6 6 6 18 18 18
39662- 50 50 50 101 101 101 26 26 26 10 10 10
39663-138 138 138 190 190 190 174 154 114 156 107 11
39664-197 138 11 200 144 11 197 138 11 192 133 9
39665-180 123 7 190 142 34 190 178 144 187 187 187
39666-202 202 202 221 221 221 214 214 214 66 66 66
39667- 2 2 6 2 2 6 50 50 50 62 62 62
39668- 6 6 6 2 2 6 10 10 10 90 90 90
39669- 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0
39673- 0 0 0 0 0 0 0 0 0 0 0 0
39674- 0 0 0 0 0 0 0 0 0 0 0 0
39675- 0 0 0 0 0 0 0 0 0 0 0 0
39676- 0 0 0 0 0 0 0 0 0 0 0 0
39677- 0 0 0 0 0 0 0 0 0 0 0 0
39678- 0 0 0 0 0 0 0 0 0 0 0 0
39679- 0 0 0 0 0 0 0 0 0 0 0 0
39680- 0 0 0 0 0 0 0 0 0 0 0 0
39681- 0 0 0 0 0 0 10 10 10 34 34 34
39682- 74 74 74 74 74 74 2 2 6 6 6 6
39683-144 144 144 198 198 198 190 190 190 178 166 146
39684-154 121 60 156 107 11 156 107 11 168 124 44
39685-174 154 114 187 187 187 190 190 190 210 210 210
39686-246 246 246 253 253 253 253 253 253 182 182 182
39687- 6 6 6 2 2 6 2 2 6 2 2 6
39688- 2 2 6 2 2 6 2 2 6 62 62 62
39689- 74 74 74 34 34 34 14 14 14 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 0 0 0 0 0 0 0 0 0
39693- 0 0 0 0 0 0 0 0 0 0 0 0
39694- 0 0 0 0 0 0 0 0 0 0 0 0
39695- 0 0 0 0 0 0 0 0 0 0 0 0
39696- 0 0 0 0 0 0 0 0 0 0 0 0
39697- 0 0 0 0 0 0 0 0 0 0 0 0
39698- 0 0 0 0 0 0 0 0 0 0 0 0
39699- 0 0 0 0 0 0 0 0 0 0 0 0
39700- 0 0 0 0 0 0 0 0 0 0 0 0
39701- 0 0 0 10 10 10 22 22 22 54 54 54
39702- 94 94 94 18 18 18 2 2 6 46 46 46
39703-234 234 234 221 221 221 190 190 190 190 190 190
39704-190 190 190 187 187 187 187 187 187 190 190 190
39705-190 190 190 195 195 195 214 214 214 242 242 242
39706-253 253 253 253 253 253 253 253 253 253 253 253
39707- 82 82 82 2 2 6 2 2 6 2 2 6
39708- 2 2 6 2 2 6 2 2 6 14 14 14
39709- 86 86 86 54 54 54 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
39713- 0 0 0 0 0 0 0 0 0 0 0 0
39714- 0 0 0 0 0 0 0 0 0 0 0 0
39715- 0 0 0 0 0 0 0 0 0 0 0 0
39716- 0 0 0 0 0 0 0 0 0 0 0 0
39717- 0 0 0 0 0 0 0 0 0 0 0 0
39718- 0 0 0 0 0 0 0 0 0 0 0 0
39719- 0 0 0 0 0 0 0 0 0 0 0 0
39720- 0 0 0 0 0 0 0 0 0 0 0 0
39721- 6 6 6 18 18 18 46 46 46 90 90 90
39722- 46 46 46 18 18 18 6 6 6 182 182 182
39723-253 253 253 246 246 246 206 206 206 190 190 190
39724-190 190 190 190 190 190 190 190 190 190 190 190
39725-206 206 206 231 231 231 250 250 250 253 253 253
39726-253 253 253 253 253 253 253 253 253 253 253 253
39727-202 202 202 14 14 14 2 2 6 2 2 6
39728- 2 2 6 2 2 6 2 2 6 2 2 6
39729- 42 42 42 86 86 86 42 42 42 18 18 18
39730- 6 6 6 0 0 0 0 0 0 0 0 0
39731- 0 0 0 0 0 0 0 0 0 0 0 0
39732- 0 0 0 0 0 0 0 0 0 0 0 0
39733- 0 0 0 0 0 0 0 0 0 0 0 0
39734- 0 0 0 0 0 0 0 0 0 0 0 0
39735- 0 0 0 0 0 0 0 0 0 0 0 0
39736- 0 0 0 0 0 0 0 0 0 0 0 0
39737- 0 0 0 0 0 0 0 0 0 0 0 0
39738- 0 0 0 0 0 0 0 0 0 0 0 0
39739- 0 0 0 0 0 0 0 0 0 0 0 0
39740- 0 0 0 0 0 0 0 0 0 6 6 6
39741- 14 14 14 38 38 38 74 74 74 66 66 66
39742- 2 2 6 6 6 6 90 90 90 250 250 250
39743-253 253 253 253 253 253 238 238 238 198 198 198
39744-190 190 190 190 190 190 195 195 195 221 221 221
39745-246 246 246 253 253 253 253 253 253 253 253 253
39746-253 253 253 253 253 253 253 253 253 253 253 253
39747-253 253 253 82 82 82 2 2 6 2 2 6
39748- 2 2 6 2 2 6 2 2 6 2 2 6
39749- 2 2 6 78 78 78 70 70 70 34 34 34
39750- 14 14 14 6 6 6 0 0 0 0 0 0
39751- 0 0 0 0 0 0 0 0 0 0 0 0
39752- 0 0 0 0 0 0 0 0 0 0 0 0
39753- 0 0 0 0 0 0 0 0 0 0 0 0
39754- 0 0 0 0 0 0 0 0 0 0 0 0
39755- 0 0 0 0 0 0 0 0 0 0 0 0
39756- 0 0 0 0 0 0 0 0 0 0 0 0
39757- 0 0 0 0 0 0 0 0 0 0 0 0
39758- 0 0 0 0 0 0 0 0 0 0 0 0
39759- 0 0 0 0 0 0 0 0 0 0 0 0
39760- 0 0 0 0 0 0 0 0 0 14 14 14
39761- 34 34 34 66 66 66 78 78 78 6 6 6
39762- 2 2 6 18 18 18 218 218 218 253 253 253
39763-253 253 253 253 253 253 253 253 253 246 246 246
39764-226 226 226 231 231 231 246 246 246 253 253 253
39765-253 253 253 253 253 253 253 253 253 253 253 253
39766-253 253 253 253 253 253 253 253 253 253 253 253
39767-253 253 253 178 178 178 2 2 6 2 2 6
39768- 2 2 6 2 2 6 2 2 6 2 2 6
39769- 2 2 6 18 18 18 90 90 90 62 62 62
39770- 30 30 30 10 10 10 0 0 0 0 0 0
39771- 0 0 0 0 0 0 0 0 0 0 0 0
39772- 0 0 0 0 0 0 0 0 0 0 0 0
39773- 0 0 0 0 0 0 0 0 0 0 0 0
39774- 0 0 0 0 0 0 0 0 0 0 0 0
39775- 0 0 0 0 0 0 0 0 0 0 0 0
39776- 0 0 0 0 0 0 0 0 0 0 0 0
39777- 0 0 0 0 0 0 0 0 0 0 0 0
39778- 0 0 0 0 0 0 0 0 0 0 0 0
39779- 0 0 0 0 0 0 0 0 0 0 0 0
39780- 0 0 0 0 0 0 10 10 10 26 26 26
39781- 58 58 58 90 90 90 18 18 18 2 2 6
39782- 2 2 6 110 110 110 253 253 253 253 253 253
39783-253 253 253 253 253 253 253 253 253 253 253 253
39784-250 250 250 253 253 253 253 253 253 253 253 253
39785-253 253 253 253 253 253 253 253 253 253 253 253
39786-253 253 253 253 253 253 253 253 253 253 253 253
39787-253 253 253 231 231 231 18 18 18 2 2 6
39788- 2 2 6 2 2 6 2 2 6 2 2 6
39789- 2 2 6 2 2 6 18 18 18 94 94 94
39790- 54 54 54 26 26 26 10 10 10 0 0 0
39791- 0 0 0 0 0 0 0 0 0 0 0 0
39792- 0 0 0 0 0 0 0 0 0 0 0 0
39793- 0 0 0 0 0 0 0 0 0 0 0 0
39794- 0 0 0 0 0 0 0 0 0 0 0 0
39795- 0 0 0 0 0 0 0 0 0 0 0 0
39796- 0 0 0 0 0 0 0 0 0 0 0 0
39797- 0 0 0 0 0 0 0 0 0 0 0 0
39798- 0 0 0 0 0 0 0 0 0 0 0 0
39799- 0 0 0 0 0 0 0 0 0 0 0 0
39800- 0 0 0 6 6 6 22 22 22 50 50 50
39801- 90 90 90 26 26 26 2 2 6 2 2 6
39802- 14 14 14 195 195 195 250 250 250 253 253 253
39803-253 253 253 253 253 253 253 253 253 253 253 253
39804-253 253 253 253 253 253 253 253 253 253 253 253
39805-253 253 253 253 253 253 253 253 253 253 253 253
39806-253 253 253 253 253 253 253 253 253 253 253 253
39807-250 250 250 242 242 242 54 54 54 2 2 6
39808- 2 2 6 2 2 6 2 2 6 2 2 6
39809- 2 2 6 2 2 6 2 2 6 38 38 38
39810- 86 86 86 50 50 50 22 22 22 6 6 6
39811- 0 0 0 0 0 0 0 0 0 0 0 0
39812- 0 0 0 0 0 0 0 0 0 0 0 0
39813- 0 0 0 0 0 0 0 0 0 0 0 0
39814- 0 0 0 0 0 0 0 0 0 0 0 0
39815- 0 0 0 0 0 0 0 0 0 0 0 0
39816- 0 0 0 0 0 0 0 0 0 0 0 0
39817- 0 0 0 0 0 0 0 0 0 0 0 0
39818- 0 0 0 0 0 0 0 0 0 0 0 0
39819- 0 0 0 0 0 0 0 0 0 0 0 0
39820- 6 6 6 14 14 14 38 38 38 82 82 82
39821- 34 34 34 2 2 6 2 2 6 2 2 6
39822- 42 42 42 195 195 195 246 246 246 253 253 253
39823-253 253 253 253 253 253 253 253 253 250 250 250
39824-242 242 242 242 242 242 250 250 250 253 253 253
39825-253 253 253 253 253 253 253 253 253 253 253 253
39826-253 253 253 250 250 250 246 246 246 238 238 238
39827-226 226 226 231 231 231 101 101 101 6 6 6
39828- 2 2 6 2 2 6 2 2 6 2 2 6
39829- 2 2 6 2 2 6 2 2 6 2 2 6
39830- 38 38 38 82 82 82 42 42 42 14 14 14
39831- 6 6 6 0 0 0 0 0 0 0 0 0
39832- 0 0 0 0 0 0 0 0 0 0 0 0
39833- 0 0 0 0 0 0 0 0 0 0 0 0
39834- 0 0 0 0 0 0 0 0 0 0 0 0
39835- 0 0 0 0 0 0 0 0 0 0 0 0
39836- 0 0 0 0 0 0 0 0 0 0 0 0
39837- 0 0 0 0 0 0 0 0 0 0 0 0
39838- 0 0 0 0 0 0 0 0 0 0 0 0
39839- 0 0 0 0 0 0 0 0 0 0 0 0
39840- 10 10 10 26 26 26 62 62 62 66 66 66
39841- 2 2 6 2 2 6 2 2 6 6 6 6
39842- 70 70 70 170 170 170 206 206 206 234 234 234
39843-246 246 246 250 250 250 250 250 250 238 238 238
39844-226 226 226 231 231 231 238 238 238 250 250 250
39845-250 250 250 250 250 250 246 246 246 231 231 231
39846-214 214 214 206 206 206 202 202 202 202 202 202
39847-198 198 198 202 202 202 182 182 182 18 18 18
39848- 2 2 6 2 2 6 2 2 6 2 2 6
39849- 2 2 6 2 2 6 2 2 6 2 2 6
39850- 2 2 6 62 62 62 66 66 66 30 30 30
39851- 10 10 10 0 0 0 0 0 0 0 0 0
39852- 0 0 0 0 0 0 0 0 0 0 0 0
39853- 0 0 0 0 0 0 0 0 0 0 0 0
39854- 0 0 0 0 0 0 0 0 0 0 0 0
39855- 0 0 0 0 0 0 0 0 0 0 0 0
39856- 0 0 0 0 0 0 0 0 0 0 0 0
39857- 0 0 0 0 0 0 0 0 0 0 0 0
39858- 0 0 0 0 0 0 0 0 0 0 0 0
39859- 0 0 0 0 0 0 0 0 0 0 0 0
39860- 14 14 14 42 42 42 82 82 82 18 18 18
39861- 2 2 6 2 2 6 2 2 6 10 10 10
39862- 94 94 94 182 182 182 218 218 218 242 242 242
39863-250 250 250 253 253 253 253 253 253 250 250 250
39864-234 234 234 253 253 253 253 253 253 253 253 253
39865-253 253 253 253 253 253 253 253 253 246 246 246
39866-238 238 238 226 226 226 210 210 210 202 202 202
39867-195 195 195 195 195 195 210 210 210 158 158 158
39868- 6 6 6 14 14 14 50 50 50 14 14 14
39869- 2 2 6 2 2 6 2 2 6 2 2 6
39870- 2 2 6 6 6 6 86 86 86 46 46 46
39871- 18 18 18 6 6 6 0 0 0 0 0 0
39872- 0 0 0 0 0 0 0 0 0 0 0 0
39873- 0 0 0 0 0 0 0 0 0 0 0 0
39874- 0 0 0 0 0 0 0 0 0 0 0 0
39875- 0 0 0 0 0 0 0 0 0 0 0 0
39876- 0 0 0 0 0 0 0 0 0 0 0 0
39877- 0 0 0 0 0 0 0 0 0 0 0 0
39878- 0 0 0 0 0 0 0 0 0 0 0 0
39879- 0 0 0 0 0 0 0 0 0 6 6 6
39880- 22 22 22 54 54 54 70 70 70 2 2 6
39881- 2 2 6 10 10 10 2 2 6 22 22 22
39882-166 166 166 231 231 231 250 250 250 253 253 253
39883-253 253 253 253 253 253 253 253 253 250 250 250
39884-242 242 242 253 253 253 253 253 253 253 253 253
39885-253 253 253 253 253 253 253 253 253 253 253 253
39886-253 253 253 253 253 253 253 253 253 246 246 246
39887-231 231 231 206 206 206 198 198 198 226 226 226
39888- 94 94 94 2 2 6 6 6 6 38 38 38
39889- 30 30 30 2 2 6 2 2 6 2 2 6
39890- 2 2 6 2 2 6 62 62 62 66 66 66
39891- 26 26 26 10 10 10 0 0 0 0 0 0
39892- 0 0 0 0 0 0 0 0 0 0 0 0
39893- 0 0 0 0 0 0 0 0 0 0 0 0
39894- 0 0 0 0 0 0 0 0 0 0 0 0
39895- 0 0 0 0 0 0 0 0 0 0 0 0
39896- 0 0 0 0 0 0 0 0 0 0 0 0
39897- 0 0 0 0 0 0 0 0 0 0 0 0
39898- 0 0 0 0 0 0 0 0 0 0 0 0
39899- 0 0 0 0 0 0 0 0 0 10 10 10
39900- 30 30 30 74 74 74 50 50 50 2 2 6
39901- 26 26 26 26 26 26 2 2 6 106 106 106
39902-238 238 238 253 253 253 253 253 253 253 253 253
39903-253 253 253 253 253 253 253 253 253 253 253 253
39904-253 253 253 253 253 253 253 253 253 253 253 253
39905-253 253 253 253 253 253 253 253 253 253 253 253
39906-253 253 253 253 253 253 253 253 253 253 253 253
39907-253 253 253 246 246 246 218 218 218 202 202 202
39908-210 210 210 14 14 14 2 2 6 2 2 6
39909- 30 30 30 22 22 22 2 2 6 2 2 6
39910- 2 2 6 2 2 6 18 18 18 86 86 86
39911- 42 42 42 14 14 14 0 0 0 0 0 0
39912- 0 0 0 0 0 0 0 0 0 0 0 0
39913- 0 0 0 0 0 0 0 0 0 0 0 0
39914- 0 0 0 0 0 0 0 0 0 0 0 0
39915- 0 0 0 0 0 0 0 0 0 0 0 0
39916- 0 0 0 0 0 0 0 0 0 0 0 0
39917- 0 0 0 0 0 0 0 0 0 0 0 0
39918- 0 0 0 0 0 0 0 0 0 0 0 0
39919- 0 0 0 0 0 0 0 0 0 14 14 14
39920- 42 42 42 90 90 90 22 22 22 2 2 6
39921- 42 42 42 2 2 6 18 18 18 218 218 218
39922-253 253 253 253 253 253 253 253 253 253 253 253
39923-253 253 253 253 253 253 253 253 253 253 253 253
39924-253 253 253 253 253 253 253 253 253 253 253 253
39925-253 253 253 253 253 253 253 253 253 253 253 253
39926-253 253 253 253 253 253 253 253 253 253 253 253
39927-253 253 253 253 253 253 250 250 250 221 221 221
39928-218 218 218 101 101 101 2 2 6 14 14 14
39929- 18 18 18 38 38 38 10 10 10 2 2 6
39930- 2 2 6 2 2 6 2 2 6 78 78 78
39931- 58 58 58 22 22 22 6 6 6 0 0 0
39932- 0 0 0 0 0 0 0 0 0 0 0 0
39933- 0 0 0 0 0 0 0 0 0 0 0 0
39934- 0 0 0 0 0 0 0 0 0 0 0 0
39935- 0 0 0 0 0 0 0 0 0 0 0 0
39936- 0 0 0 0 0 0 0 0 0 0 0 0
39937- 0 0 0 0 0 0 0 0 0 0 0 0
39938- 0 0 0 0 0 0 0 0 0 0 0 0
39939- 0 0 0 0 0 0 6 6 6 18 18 18
39940- 54 54 54 82 82 82 2 2 6 26 26 26
39941- 22 22 22 2 2 6 123 123 123 253 253 253
39942-253 253 253 253 253 253 253 253 253 253 253 253
39943-253 253 253 253 253 253 253 253 253 253 253 253
39944-253 253 253 253 253 253 253 253 253 253 253 253
39945-253 253 253 253 253 253 253 253 253 253 253 253
39946-253 253 253 253 253 253 253 253 253 253 253 253
39947-253 253 253 253 253 253 253 253 253 250 250 250
39948-238 238 238 198 198 198 6 6 6 38 38 38
39949- 58 58 58 26 26 26 38 38 38 2 2 6
39950- 2 2 6 2 2 6 2 2 6 46 46 46
39951- 78 78 78 30 30 30 10 10 10 0 0 0
39952- 0 0 0 0 0 0 0 0 0 0 0 0
39953- 0 0 0 0 0 0 0 0 0 0 0 0
39954- 0 0 0 0 0 0 0 0 0 0 0 0
39955- 0 0 0 0 0 0 0 0 0 0 0 0
39956- 0 0 0 0 0 0 0 0 0 0 0 0
39957- 0 0 0 0 0 0 0 0 0 0 0 0
39958- 0 0 0 0 0 0 0 0 0 0 0 0
39959- 0 0 0 0 0 0 10 10 10 30 30 30
39960- 74 74 74 58 58 58 2 2 6 42 42 42
39961- 2 2 6 22 22 22 231 231 231 253 253 253
39962-253 253 253 253 253 253 253 253 253 253 253 253
39963-253 253 253 253 253 253 253 253 253 250 250 250
39964-253 253 253 253 253 253 253 253 253 253 253 253
39965-253 253 253 253 253 253 253 253 253 253 253 253
39966-253 253 253 253 253 253 253 253 253 253 253 253
39967-253 253 253 253 253 253 253 253 253 253 253 253
39968-253 253 253 246 246 246 46 46 46 38 38 38
39969- 42 42 42 14 14 14 38 38 38 14 14 14
39970- 2 2 6 2 2 6 2 2 6 6 6 6
39971- 86 86 86 46 46 46 14 14 14 0 0 0
39972- 0 0 0 0 0 0 0 0 0 0 0 0
39973- 0 0 0 0 0 0 0 0 0 0 0 0
39974- 0 0 0 0 0 0 0 0 0 0 0 0
39975- 0 0 0 0 0 0 0 0 0 0 0 0
39976- 0 0 0 0 0 0 0 0 0 0 0 0
39977- 0 0 0 0 0 0 0 0 0 0 0 0
39978- 0 0 0 0 0 0 0 0 0 0 0 0
39979- 0 0 0 6 6 6 14 14 14 42 42 42
39980- 90 90 90 18 18 18 18 18 18 26 26 26
39981- 2 2 6 116 116 116 253 253 253 253 253 253
39982-253 253 253 253 253 253 253 253 253 253 253 253
39983-253 253 253 253 253 253 250 250 250 238 238 238
39984-253 253 253 253 253 253 253 253 253 253 253 253
39985-253 253 253 253 253 253 253 253 253 253 253 253
39986-253 253 253 253 253 253 253 253 253 253 253 253
39987-253 253 253 253 253 253 253 253 253 253 253 253
39988-253 253 253 253 253 253 94 94 94 6 6 6
39989- 2 2 6 2 2 6 10 10 10 34 34 34
39990- 2 2 6 2 2 6 2 2 6 2 2 6
39991- 74 74 74 58 58 58 22 22 22 6 6 6
39992- 0 0 0 0 0 0 0 0 0 0 0 0
39993- 0 0 0 0 0 0 0 0 0 0 0 0
39994- 0 0 0 0 0 0 0 0 0 0 0 0
39995- 0 0 0 0 0 0 0 0 0 0 0 0
39996- 0 0 0 0 0 0 0 0 0 0 0 0
39997- 0 0 0 0 0 0 0 0 0 0 0 0
39998- 0 0 0 0 0 0 0 0 0 0 0 0
39999- 0 0 0 10 10 10 26 26 26 66 66 66
40000- 82 82 82 2 2 6 38 38 38 6 6 6
40001- 14 14 14 210 210 210 253 253 253 253 253 253
40002-253 253 253 253 253 253 253 253 253 253 253 253
40003-253 253 253 253 253 253 246 246 246 242 242 242
40004-253 253 253 253 253 253 253 253 253 253 253 253
40005-253 253 253 253 253 253 253 253 253 253 253 253
40006-253 253 253 253 253 253 253 253 253 253 253 253
40007-253 253 253 253 253 253 253 253 253 253 253 253
40008-253 253 253 253 253 253 144 144 144 2 2 6
40009- 2 2 6 2 2 6 2 2 6 46 46 46
40010- 2 2 6 2 2 6 2 2 6 2 2 6
40011- 42 42 42 74 74 74 30 30 30 10 10 10
40012- 0 0 0 0 0 0 0 0 0 0 0 0
40013- 0 0 0 0 0 0 0 0 0 0 0 0
40014- 0 0 0 0 0 0 0 0 0 0 0 0
40015- 0 0 0 0 0 0 0 0 0 0 0 0
40016- 0 0 0 0 0 0 0 0 0 0 0 0
40017- 0 0 0 0 0 0 0 0 0 0 0 0
40018- 0 0 0 0 0 0 0 0 0 0 0 0
40019- 6 6 6 14 14 14 42 42 42 90 90 90
40020- 26 26 26 6 6 6 42 42 42 2 2 6
40021- 74 74 74 250 250 250 253 253 253 253 253 253
40022-253 253 253 253 253 253 253 253 253 253 253 253
40023-253 253 253 253 253 253 242 242 242 242 242 242
40024-253 253 253 253 253 253 253 253 253 253 253 253
40025-253 253 253 253 253 253 253 253 253 253 253 253
40026-253 253 253 253 253 253 253 253 253 253 253 253
40027-253 253 253 253 253 253 253 253 253 253 253 253
40028-253 253 253 253 253 253 182 182 182 2 2 6
40029- 2 2 6 2 2 6 2 2 6 46 46 46
40030- 2 2 6 2 2 6 2 2 6 2 2 6
40031- 10 10 10 86 86 86 38 38 38 10 10 10
40032- 0 0 0 0 0 0 0 0 0 0 0 0
40033- 0 0 0 0 0 0 0 0 0 0 0 0
40034- 0 0 0 0 0 0 0 0 0 0 0 0
40035- 0 0 0 0 0 0 0 0 0 0 0 0
40036- 0 0 0 0 0 0 0 0 0 0 0 0
40037- 0 0 0 0 0 0 0 0 0 0 0 0
40038- 0 0 0 0 0 0 0 0 0 0 0 0
40039- 10 10 10 26 26 26 66 66 66 82 82 82
40040- 2 2 6 22 22 22 18 18 18 2 2 6
40041-149 149 149 253 253 253 253 253 253 253 253 253
40042-253 253 253 253 253 253 253 253 253 253 253 253
40043-253 253 253 253 253 253 234 234 234 242 242 242
40044-253 253 253 253 253 253 253 253 253 253 253 253
40045-253 253 253 253 253 253 253 253 253 253 253 253
40046-253 253 253 253 253 253 253 253 253 253 253 253
40047-253 253 253 253 253 253 253 253 253 253 253 253
40048-253 253 253 253 253 253 206 206 206 2 2 6
40049- 2 2 6 2 2 6 2 2 6 38 38 38
40050- 2 2 6 2 2 6 2 2 6 2 2 6
40051- 6 6 6 86 86 86 46 46 46 14 14 14
40052- 0 0 0 0 0 0 0 0 0 0 0 0
40053- 0 0 0 0 0 0 0 0 0 0 0 0
40054- 0 0 0 0 0 0 0 0 0 0 0 0
40055- 0 0 0 0 0 0 0 0 0 0 0 0
40056- 0 0 0 0 0 0 0 0 0 0 0 0
40057- 0 0 0 0 0 0 0 0 0 0 0 0
40058- 0 0 0 0 0 0 0 0 0 6 6 6
40059- 18 18 18 46 46 46 86 86 86 18 18 18
40060- 2 2 6 34 34 34 10 10 10 6 6 6
40061-210 210 210 253 253 253 253 253 253 253 253 253
40062-253 253 253 253 253 253 253 253 253 253 253 253
40063-253 253 253 253 253 253 234 234 234 242 242 242
40064-253 253 253 253 253 253 253 253 253 253 253 253
40065-253 253 253 253 253 253 253 253 253 253 253 253
40066-253 253 253 253 253 253 253 253 253 253 253 253
40067-253 253 253 253 253 253 253 253 253 253 253 253
40068-253 253 253 253 253 253 221 221 221 6 6 6
40069- 2 2 6 2 2 6 6 6 6 30 30 30
40070- 2 2 6 2 2 6 2 2 6 2 2 6
40071- 2 2 6 82 82 82 54 54 54 18 18 18
40072- 6 6 6 0 0 0 0 0 0 0 0 0
40073- 0 0 0 0 0 0 0 0 0 0 0 0
40074- 0 0 0 0 0 0 0 0 0 0 0 0
40075- 0 0 0 0 0 0 0 0 0 0 0 0
40076- 0 0 0 0 0 0 0 0 0 0 0 0
40077- 0 0 0 0 0 0 0 0 0 0 0 0
40078- 0 0 0 0 0 0 0 0 0 10 10 10
40079- 26 26 26 66 66 66 62 62 62 2 2 6
40080- 2 2 6 38 38 38 10 10 10 26 26 26
40081-238 238 238 253 253 253 253 253 253 253 253 253
40082-253 253 253 253 253 253 253 253 253 253 253 253
40083-253 253 253 253 253 253 231 231 231 238 238 238
40084-253 253 253 253 253 253 253 253 253 253 253 253
40085-253 253 253 253 253 253 253 253 253 253 253 253
40086-253 253 253 253 253 253 253 253 253 253 253 253
40087-253 253 253 253 253 253 253 253 253 253 253 253
40088-253 253 253 253 253 253 231 231 231 6 6 6
40089- 2 2 6 2 2 6 10 10 10 30 30 30
40090- 2 2 6 2 2 6 2 2 6 2 2 6
40091- 2 2 6 66 66 66 58 58 58 22 22 22
40092- 6 6 6 0 0 0 0 0 0 0 0 0
40093- 0 0 0 0 0 0 0 0 0 0 0 0
40094- 0 0 0 0 0 0 0 0 0 0 0 0
40095- 0 0 0 0 0 0 0 0 0 0 0 0
40096- 0 0 0 0 0 0 0 0 0 0 0 0
40097- 0 0 0 0 0 0 0 0 0 0 0 0
40098- 0 0 0 0 0 0 0 0 0 10 10 10
40099- 38 38 38 78 78 78 6 6 6 2 2 6
40100- 2 2 6 46 46 46 14 14 14 42 42 42
40101-246 246 246 253 253 253 253 253 253 253 253 253
40102-253 253 253 253 253 253 253 253 253 253 253 253
40103-253 253 253 253 253 253 231 231 231 242 242 242
40104-253 253 253 253 253 253 253 253 253 253 253 253
40105-253 253 253 253 253 253 253 253 253 253 253 253
40106-253 253 253 253 253 253 253 253 253 253 253 253
40107-253 253 253 253 253 253 253 253 253 253 253 253
40108-253 253 253 253 253 253 234 234 234 10 10 10
40109- 2 2 6 2 2 6 22 22 22 14 14 14
40110- 2 2 6 2 2 6 2 2 6 2 2 6
40111- 2 2 6 66 66 66 62 62 62 22 22 22
40112- 6 6 6 0 0 0 0 0 0 0 0 0
40113- 0 0 0 0 0 0 0 0 0 0 0 0
40114- 0 0 0 0 0 0 0 0 0 0 0 0
40115- 0 0 0 0 0 0 0 0 0 0 0 0
40116- 0 0 0 0 0 0 0 0 0 0 0 0
40117- 0 0 0 0 0 0 0 0 0 0 0 0
40118- 0 0 0 0 0 0 6 6 6 18 18 18
40119- 50 50 50 74 74 74 2 2 6 2 2 6
40120- 14 14 14 70 70 70 34 34 34 62 62 62
40121-250 250 250 253 253 253 253 253 253 253 253 253
40122-253 253 253 253 253 253 253 253 253 253 253 253
40123-253 253 253 253 253 253 231 231 231 246 246 246
40124-253 253 253 253 253 253 253 253 253 253 253 253
40125-253 253 253 253 253 253 253 253 253 253 253 253
40126-253 253 253 253 253 253 253 253 253 253 253 253
40127-253 253 253 253 253 253 253 253 253 253 253 253
40128-253 253 253 253 253 253 234 234 234 14 14 14
40129- 2 2 6 2 2 6 30 30 30 2 2 6
40130- 2 2 6 2 2 6 2 2 6 2 2 6
40131- 2 2 6 66 66 66 62 62 62 22 22 22
40132- 6 6 6 0 0 0 0 0 0 0 0 0
40133- 0 0 0 0 0 0 0 0 0 0 0 0
40134- 0 0 0 0 0 0 0 0 0 0 0 0
40135- 0 0 0 0 0 0 0 0 0 0 0 0
40136- 0 0 0 0 0 0 0 0 0 0 0 0
40137- 0 0 0 0 0 0 0 0 0 0 0 0
40138- 0 0 0 0 0 0 6 6 6 18 18 18
40139- 54 54 54 62 62 62 2 2 6 2 2 6
40140- 2 2 6 30 30 30 46 46 46 70 70 70
40141-250 250 250 253 253 253 253 253 253 253 253 253
40142-253 253 253 253 253 253 253 253 253 253 253 253
40143-253 253 253 253 253 253 231 231 231 246 246 246
40144-253 253 253 253 253 253 253 253 253 253 253 253
40145-253 253 253 253 253 253 253 253 253 253 253 253
40146-253 253 253 253 253 253 253 253 253 253 253 253
40147-253 253 253 253 253 253 253 253 253 253 253 253
40148-253 253 253 253 253 253 226 226 226 10 10 10
40149- 2 2 6 6 6 6 30 30 30 2 2 6
40150- 2 2 6 2 2 6 2 2 6 2 2 6
40151- 2 2 6 66 66 66 58 58 58 22 22 22
40152- 6 6 6 0 0 0 0 0 0 0 0 0
40153- 0 0 0 0 0 0 0 0 0 0 0 0
40154- 0 0 0 0 0 0 0 0 0 0 0 0
40155- 0 0 0 0 0 0 0 0 0 0 0 0
40156- 0 0 0 0 0 0 0 0 0 0 0 0
40157- 0 0 0 0 0 0 0 0 0 0 0 0
40158- 0 0 0 0 0 0 6 6 6 22 22 22
40159- 58 58 58 62 62 62 2 2 6 2 2 6
40160- 2 2 6 2 2 6 30 30 30 78 78 78
40161-250 250 250 253 253 253 253 253 253 253 253 253
40162-253 253 253 253 253 253 253 253 253 253 253 253
40163-253 253 253 253 253 253 231 231 231 246 246 246
40164-253 253 253 253 253 253 253 253 253 253 253 253
40165-253 253 253 253 253 253 253 253 253 253 253 253
40166-253 253 253 253 253 253 253 253 253 253 253 253
40167-253 253 253 253 253 253 253 253 253 253 253 253
40168-253 253 253 253 253 253 206 206 206 2 2 6
40169- 22 22 22 34 34 34 18 14 6 22 22 22
40170- 26 26 26 18 18 18 6 6 6 2 2 6
40171- 2 2 6 82 82 82 54 54 54 18 18 18
40172- 6 6 6 0 0 0 0 0 0 0 0 0
40173- 0 0 0 0 0 0 0 0 0 0 0 0
40174- 0 0 0 0 0 0 0 0 0 0 0 0
40175- 0 0 0 0 0 0 0 0 0 0 0 0
40176- 0 0 0 0 0 0 0 0 0 0 0 0
40177- 0 0 0 0 0 0 0 0 0 0 0 0
40178- 0 0 0 0 0 0 6 6 6 26 26 26
40179- 62 62 62 106 106 106 74 54 14 185 133 11
40180-210 162 10 121 92 8 6 6 6 62 62 62
40181-238 238 238 253 253 253 253 253 253 253 253 253
40182-253 253 253 253 253 253 253 253 253 253 253 253
40183-253 253 253 253 253 253 231 231 231 246 246 246
40184-253 253 253 253 253 253 253 253 253 253 253 253
40185-253 253 253 253 253 253 253 253 253 253 253 253
40186-253 253 253 253 253 253 253 253 253 253 253 253
40187-253 253 253 253 253 253 253 253 253 253 253 253
40188-253 253 253 253 253 253 158 158 158 18 18 18
40189- 14 14 14 2 2 6 2 2 6 2 2 6
40190- 6 6 6 18 18 18 66 66 66 38 38 38
40191- 6 6 6 94 94 94 50 50 50 18 18 18
40192- 6 6 6 0 0 0 0 0 0 0 0 0
40193- 0 0 0 0 0 0 0 0 0 0 0 0
40194- 0 0 0 0 0 0 0 0 0 0 0 0
40195- 0 0 0 0 0 0 0 0 0 0 0 0
40196- 0 0 0 0 0 0 0 0 0 0 0 0
40197- 0 0 0 0 0 0 0 0 0 6 6 6
40198- 10 10 10 10 10 10 18 18 18 38 38 38
40199- 78 78 78 142 134 106 216 158 10 242 186 14
40200-246 190 14 246 190 14 156 118 10 10 10 10
40201- 90 90 90 238 238 238 253 253 253 253 253 253
40202-253 253 253 253 253 253 253 253 253 253 253 253
40203-253 253 253 253 253 253 231 231 231 250 250 250
40204-253 253 253 253 253 253 253 253 253 253 253 253
40205-253 253 253 253 253 253 253 253 253 253 253 253
40206-253 253 253 253 253 253 253 253 253 253 253 253
40207-253 253 253 253 253 253 253 253 253 246 230 190
40208-238 204 91 238 204 91 181 142 44 37 26 9
40209- 2 2 6 2 2 6 2 2 6 2 2 6
40210- 2 2 6 2 2 6 38 38 38 46 46 46
40211- 26 26 26 106 106 106 54 54 54 18 18 18
40212- 6 6 6 0 0 0 0 0 0 0 0 0
40213- 0 0 0 0 0 0 0 0 0 0 0 0
40214- 0 0 0 0 0 0 0 0 0 0 0 0
40215- 0 0 0 0 0 0 0 0 0 0 0 0
40216- 0 0 0 0 0 0 0 0 0 0 0 0
40217- 0 0 0 6 6 6 14 14 14 22 22 22
40218- 30 30 30 38 38 38 50 50 50 70 70 70
40219-106 106 106 190 142 34 226 170 11 242 186 14
40220-246 190 14 246 190 14 246 190 14 154 114 10
40221- 6 6 6 74 74 74 226 226 226 253 253 253
40222-253 253 253 253 253 253 253 253 253 253 253 253
40223-253 253 253 253 253 253 231 231 231 250 250 250
40224-253 253 253 253 253 253 253 253 253 253 253 253
40225-253 253 253 253 253 253 253 253 253 253 253 253
40226-253 253 253 253 253 253 253 253 253 253 253 253
40227-253 253 253 253 253 253 253 253 253 228 184 62
40228-241 196 14 241 208 19 232 195 16 38 30 10
40229- 2 2 6 2 2 6 2 2 6 2 2 6
40230- 2 2 6 6 6 6 30 30 30 26 26 26
40231-203 166 17 154 142 90 66 66 66 26 26 26
40232- 6 6 6 0 0 0 0 0 0 0 0 0
40233- 0 0 0 0 0 0 0 0 0 0 0 0
40234- 0 0 0 0 0 0 0 0 0 0 0 0
40235- 0 0 0 0 0 0 0 0 0 0 0 0
40236- 0 0 0 0 0 0 0 0 0 0 0 0
40237- 6 6 6 18 18 18 38 38 38 58 58 58
40238- 78 78 78 86 86 86 101 101 101 123 123 123
40239-175 146 61 210 150 10 234 174 13 246 186 14
40240-246 190 14 246 190 14 246 190 14 238 190 10
40241-102 78 10 2 2 6 46 46 46 198 198 198
40242-253 253 253 253 253 253 253 253 253 253 253 253
40243-253 253 253 253 253 253 234 234 234 242 242 242
40244-253 253 253 253 253 253 253 253 253 253 253 253
40245-253 253 253 253 253 253 253 253 253 253 253 253
40246-253 253 253 253 253 253 253 253 253 253 253 253
40247-253 253 253 253 253 253 253 253 253 224 178 62
40248-242 186 14 241 196 14 210 166 10 22 18 6
40249- 2 2 6 2 2 6 2 2 6 2 2 6
40250- 2 2 6 2 2 6 6 6 6 121 92 8
40251-238 202 15 232 195 16 82 82 82 34 34 34
40252- 10 10 10 0 0 0 0 0 0 0 0 0
40253- 0 0 0 0 0 0 0 0 0 0 0 0
40254- 0 0 0 0 0 0 0 0 0 0 0 0
40255- 0 0 0 0 0 0 0 0 0 0 0 0
40256- 0 0 0 0 0 0 0 0 0 0 0 0
40257- 14 14 14 38 38 38 70 70 70 154 122 46
40258-190 142 34 200 144 11 197 138 11 197 138 11
40259-213 154 11 226 170 11 242 186 14 246 190 14
40260-246 190 14 246 190 14 246 190 14 246 190 14
40261-225 175 15 46 32 6 2 2 6 22 22 22
40262-158 158 158 250 250 250 253 253 253 253 253 253
40263-253 253 253 253 253 253 253 253 253 253 253 253
40264-253 253 253 253 253 253 253 253 253 253 253 253
40265-253 253 253 253 253 253 253 253 253 253 253 253
40266-253 253 253 253 253 253 253 253 253 253 253 253
40267-253 253 253 250 250 250 242 242 242 224 178 62
40268-239 182 13 236 186 11 213 154 11 46 32 6
40269- 2 2 6 2 2 6 2 2 6 2 2 6
40270- 2 2 6 2 2 6 61 42 6 225 175 15
40271-238 190 10 236 186 11 112 100 78 42 42 42
40272- 14 14 14 0 0 0 0 0 0 0 0 0
40273- 0 0 0 0 0 0 0 0 0 0 0 0
40274- 0 0 0 0 0 0 0 0 0 0 0 0
40275- 0 0 0 0 0 0 0 0 0 0 0 0
40276- 0 0 0 0 0 0 0 0 0 6 6 6
40277- 22 22 22 54 54 54 154 122 46 213 154 11
40278-226 170 11 230 174 11 226 170 11 226 170 11
40279-236 178 12 242 186 14 246 190 14 246 190 14
40280-246 190 14 246 190 14 246 190 14 246 190 14
40281-241 196 14 184 144 12 10 10 10 2 2 6
40282- 6 6 6 116 116 116 242 242 242 253 253 253
40283-253 253 253 253 253 253 253 253 253 253 253 253
40284-253 253 253 253 253 253 253 253 253 253 253 253
40285-253 253 253 253 253 253 253 253 253 253 253 253
40286-253 253 253 253 253 253 253 253 253 253 253 253
40287-253 253 253 231 231 231 198 198 198 214 170 54
40288-236 178 12 236 178 12 210 150 10 137 92 6
40289- 18 14 6 2 2 6 2 2 6 2 2 6
40290- 6 6 6 70 47 6 200 144 11 236 178 12
40291-239 182 13 239 182 13 124 112 88 58 58 58
40292- 22 22 22 6 6 6 0 0 0 0 0 0
40293- 0 0 0 0 0 0 0 0 0 0 0 0
40294- 0 0 0 0 0 0 0 0 0 0 0 0
40295- 0 0 0 0 0 0 0 0 0 0 0 0
40296- 0 0 0 0 0 0 0 0 0 10 10 10
40297- 30 30 30 70 70 70 180 133 36 226 170 11
40298-239 182 13 242 186 14 242 186 14 246 186 14
40299-246 190 14 246 190 14 246 190 14 246 190 14
40300-246 190 14 246 190 14 246 190 14 246 190 14
40301-246 190 14 232 195 16 98 70 6 2 2 6
40302- 2 2 6 2 2 6 66 66 66 221 221 221
40303-253 253 253 253 253 253 253 253 253 253 253 253
40304-253 253 253 253 253 253 253 253 253 253 253 253
40305-253 253 253 253 253 253 253 253 253 253 253 253
40306-253 253 253 253 253 253 253 253 253 253 253 253
40307-253 253 253 206 206 206 198 198 198 214 166 58
40308-230 174 11 230 174 11 216 158 10 192 133 9
40309-163 110 8 116 81 8 102 78 10 116 81 8
40310-167 114 7 197 138 11 226 170 11 239 182 13
40311-242 186 14 242 186 14 162 146 94 78 78 78
40312- 34 34 34 14 14 14 6 6 6 0 0 0
40313- 0 0 0 0 0 0 0 0 0 0 0 0
40314- 0 0 0 0 0 0 0 0 0 0 0 0
40315- 0 0 0 0 0 0 0 0 0 0 0 0
40316- 0 0 0 0 0 0 0 0 0 6 6 6
40317- 30 30 30 78 78 78 190 142 34 226 170 11
40318-239 182 13 246 190 14 246 190 14 246 190 14
40319-246 190 14 246 190 14 246 190 14 246 190 14
40320-246 190 14 246 190 14 246 190 14 246 190 14
40321-246 190 14 241 196 14 203 166 17 22 18 6
40322- 2 2 6 2 2 6 2 2 6 38 38 38
40323-218 218 218 253 253 253 253 253 253 253 253 253
40324-253 253 253 253 253 253 253 253 253 253 253 253
40325-253 253 253 253 253 253 253 253 253 253 253 253
40326-253 253 253 253 253 253 253 253 253 253 253 253
40327-250 250 250 206 206 206 198 198 198 202 162 69
40328-226 170 11 236 178 12 224 166 10 210 150 10
40329-200 144 11 197 138 11 192 133 9 197 138 11
40330-210 150 10 226 170 11 242 186 14 246 190 14
40331-246 190 14 246 186 14 225 175 15 124 112 88
40332- 62 62 62 30 30 30 14 14 14 6 6 6
40333- 0 0 0 0 0 0 0 0 0 0 0 0
40334- 0 0 0 0 0 0 0 0 0 0 0 0
40335- 0 0 0 0 0 0 0 0 0 0 0 0
40336- 0 0 0 0 0 0 0 0 0 10 10 10
40337- 30 30 30 78 78 78 174 135 50 224 166 10
40338-239 182 13 246 190 14 246 190 14 246 190 14
40339-246 190 14 246 190 14 246 190 14 246 190 14
40340-246 190 14 246 190 14 246 190 14 246 190 14
40341-246 190 14 246 190 14 241 196 14 139 102 15
40342- 2 2 6 2 2 6 2 2 6 2 2 6
40343- 78 78 78 250 250 250 253 253 253 253 253 253
40344-253 253 253 253 253 253 253 253 253 253 253 253
40345-253 253 253 253 253 253 253 253 253 253 253 253
40346-253 253 253 253 253 253 253 253 253 253 253 253
40347-250 250 250 214 214 214 198 198 198 190 150 46
40348-219 162 10 236 178 12 234 174 13 224 166 10
40349-216 158 10 213 154 11 213 154 11 216 158 10
40350-226 170 11 239 182 13 246 190 14 246 190 14
40351-246 190 14 246 190 14 242 186 14 206 162 42
40352-101 101 101 58 58 58 30 30 30 14 14 14
40353- 6 6 6 0 0 0 0 0 0 0 0 0
40354- 0 0 0 0 0 0 0 0 0 0 0 0
40355- 0 0 0 0 0 0 0 0 0 0 0 0
40356- 0 0 0 0 0 0 0 0 0 10 10 10
40357- 30 30 30 74 74 74 174 135 50 216 158 10
40358-236 178 12 246 190 14 246 190 14 246 190 14
40359-246 190 14 246 190 14 246 190 14 246 190 14
40360-246 190 14 246 190 14 246 190 14 246 190 14
40361-246 190 14 246 190 14 241 196 14 226 184 13
40362- 61 42 6 2 2 6 2 2 6 2 2 6
40363- 22 22 22 238 238 238 253 253 253 253 253 253
40364-253 253 253 253 253 253 253 253 253 253 253 253
40365-253 253 253 253 253 253 253 253 253 253 253 253
40366-253 253 253 253 253 253 253 253 253 253 253 253
40367-253 253 253 226 226 226 187 187 187 180 133 36
40368-216 158 10 236 178 12 239 182 13 236 178 12
40369-230 174 11 226 170 11 226 170 11 230 174 11
40370-236 178 12 242 186 14 246 190 14 246 190 14
40371-246 190 14 246 190 14 246 186 14 239 182 13
40372-206 162 42 106 106 106 66 66 66 34 34 34
40373- 14 14 14 6 6 6 0 0 0 0 0 0
40374- 0 0 0 0 0 0 0 0 0 0 0 0
40375- 0 0 0 0 0 0 0 0 0 0 0 0
40376- 0 0 0 0 0 0 0 0 0 6 6 6
40377- 26 26 26 70 70 70 163 133 67 213 154 11
40378-236 178 12 246 190 14 246 190 14 246 190 14
40379-246 190 14 246 190 14 246 190 14 246 190 14
40380-246 190 14 246 190 14 246 190 14 246 190 14
40381-246 190 14 246 190 14 246 190 14 241 196 14
40382-190 146 13 18 14 6 2 2 6 2 2 6
40383- 46 46 46 246 246 246 253 253 253 253 253 253
40384-253 253 253 253 253 253 253 253 253 253 253 253
40385-253 253 253 253 253 253 253 253 253 253 253 253
40386-253 253 253 253 253 253 253 253 253 253 253 253
40387-253 253 253 221 221 221 86 86 86 156 107 11
40388-216 158 10 236 178 12 242 186 14 246 186 14
40389-242 186 14 239 182 13 239 182 13 242 186 14
40390-242 186 14 246 186 14 246 190 14 246 190 14
40391-246 190 14 246 190 14 246 190 14 246 190 14
40392-242 186 14 225 175 15 142 122 72 66 66 66
40393- 30 30 30 10 10 10 0 0 0 0 0 0
40394- 0 0 0 0 0 0 0 0 0 0 0 0
40395- 0 0 0 0 0 0 0 0 0 0 0 0
40396- 0 0 0 0 0 0 0 0 0 6 6 6
40397- 26 26 26 70 70 70 163 133 67 210 150 10
40398-236 178 12 246 190 14 246 190 14 246 190 14
40399-246 190 14 246 190 14 246 190 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-232 195 16 121 92 8 34 34 34 106 106 106
40403-221 221 221 253 253 253 253 253 253 253 253 253
40404-253 253 253 253 253 253 253 253 253 253 253 253
40405-253 253 253 253 253 253 253 253 253 253 253 253
40406-253 253 253 253 253 253 253 253 253 253 253 253
40407-242 242 242 82 82 82 18 14 6 163 110 8
40408-216 158 10 236 178 12 242 186 14 246 190 14
40409-246 190 14 246 190 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 242 186 14 163 133 67
40413- 46 46 46 18 18 18 6 6 6 0 0 0
40414- 0 0 0 0 0 0 0 0 0 0 0 0
40415- 0 0 0 0 0 0 0 0 0 0 0 0
40416- 0 0 0 0 0 0 0 0 0 10 10 10
40417- 30 30 30 78 78 78 163 133 67 210 150 10
40418-236 178 12 246 186 14 246 190 14 246 190 14
40419-246 190 14 246 190 14 246 190 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-241 196 14 215 174 15 190 178 144 253 253 253
40423-253 253 253 253 253 253 253 253 253 253 253 253
40424-253 253 253 253 253 253 253 253 253 253 253 253
40425-253 253 253 253 253 253 253 253 253 253 253 253
40426-253 253 253 253 253 253 253 253 253 218 218 218
40427- 58 58 58 2 2 6 22 18 6 167 114 7
40428-216 158 10 236 178 12 246 186 14 246 190 14
40429-246 190 14 246 190 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 186 14 242 186 14 190 150 46
40433- 54 54 54 22 22 22 6 6 6 0 0 0
40434- 0 0 0 0 0 0 0 0 0 0 0 0
40435- 0 0 0 0 0 0 0 0 0 0 0 0
40436- 0 0 0 0 0 0 0 0 0 14 14 14
40437- 38 38 38 86 86 86 180 133 36 213 154 11
40438-236 178 12 246 186 14 246 190 14 246 190 14
40439-246 190 14 246 190 14 246 190 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 232 195 16 190 146 13 214 214 214
40443-253 253 253 253 253 253 253 253 253 253 253 253
40444-253 253 253 253 253 253 253 253 253 253 253 253
40445-253 253 253 253 253 253 253 253 253 253 253 253
40446-253 253 253 250 250 250 170 170 170 26 26 26
40447- 2 2 6 2 2 6 37 26 9 163 110 8
40448-219 162 10 239 182 13 246 186 14 246 190 14
40449-246 190 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 186 14 236 178 12 224 166 10 142 122 72
40453- 46 46 46 18 18 18 6 6 6 0 0 0
40454- 0 0 0 0 0 0 0 0 0 0 0 0
40455- 0 0 0 0 0 0 0 0 0 0 0 0
40456- 0 0 0 0 0 0 6 6 6 18 18 18
40457- 50 50 50 109 106 95 192 133 9 224 166 10
40458-242 186 14 246 190 14 246 190 14 246 190 14
40459-246 190 14 246 190 14 246 190 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-242 186 14 226 184 13 210 162 10 142 110 46
40463-226 226 226 253 253 253 253 253 253 253 253 253
40464-253 253 253 253 253 253 253 253 253 253 253 253
40465-253 253 253 253 253 253 253 253 253 253 253 253
40466-198 198 198 66 66 66 2 2 6 2 2 6
40467- 2 2 6 2 2 6 50 34 6 156 107 11
40468-219 162 10 239 182 13 246 186 14 246 190 14
40469-246 190 14 246 190 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 242 186 14
40472-234 174 13 213 154 11 154 122 46 66 66 66
40473- 30 30 30 10 10 10 0 0 0 0 0 0
40474- 0 0 0 0 0 0 0 0 0 0 0 0
40475- 0 0 0 0 0 0 0 0 0 0 0 0
40476- 0 0 0 0 0 0 6 6 6 22 22 22
40477- 58 58 58 154 121 60 206 145 10 234 174 13
40478-242 186 14 246 186 14 246 190 14 246 190 14
40479-246 190 14 246 190 14 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 186 14 236 178 12 210 162 10 163 110 8
40483- 61 42 6 138 138 138 218 218 218 250 250 250
40484-253 253 253 253 253 253 253 253 253 250 250 250
40485-242 242 242 210 210 210 144 144 144 66 66 66
40486- 6 6 6 2 2 6 2 2 6 2 2 6
40487- 2 2 6 2 2 6 61 42 6 163 110 8
40488-216 158 10 236 178 12 246 190 14 246 190 14
40489-246 190 14 246 190 14 246 190 14 246 190 14
40490-246 190 14 246 190 14 246 190 14 246 190 14
40491-246 190 14 239 182 13 230 174 11 216 158 10
40492-190 142 34 124 112 88 70 70 70 38 38 38
40493- 18 18 18 6 6 6 0 0 0 0 0 0
40494- 0 0 0 0 0 0 0 0 0 0 0 0
40495- 0 0 0 0 0 0 0 0 0 0 0 0
40496- 0 0 0 0 0 0 6 6 6 22 22 22
40497- 62 62 62 168 124 44 206 145 10 224 166 10
40498-236 178 12 239 182 13 242 186 14 242 186 14
40499-246 186 14 246 190 14 246 190 14 246 190 14
40500-246 190 14 246 190 14 246 190 14 246 190 14
40501-246 190 14 246 190 14 246 190 14 246 190 14
40502-246 190 14 236 178 12 216 158 10 175 118 6
40503- 80 54 7 2 2 6 6 6 6 30 30 30
40504- 54 54 54 62 62 62 50 50 50 38 38 38
40505- 14 14 14 2 2 6 2 2 6 2 2 6
40506- 2 2 6 2 2 6 2 2 6 2 2 6
40507- 2 2 6 6 6 6 80 54 7 167 114 7
40508-213 154 11 236 178 12 246 190 14 246 190 14
40509-246 190 14 246 190 14 246 190 14 246 190 14
40510-246 190 14 242 186 14 239 182 13 239 182 13
40511-230 174 11 210 150 10 174 135 50 124 112 88
40512- 82 82 82 54 54 54 34 34 34 18 18 18
40513- 6 6 6 0 0 0 0 0 0 0 0 0
40514- 0 0 0 0 0 0 0 0 0 0 0 0
40515- 0 0 0 0 0 0 0 0 0 0 0 0
40516- 0 0 0 0 0 0 6 6 6 18 18 18
40517- 50 50 50 158 118 36 192 133 9 200 144 11
40518-216 158 10 219 162 10 224 166 10 226 170 11
40519-230 174 11 236 178 12 239 182 13 239 182 13
40520-242 186 14 246 186 14 246 190 14 246 190 14
40521-246 190 14 246 190 14 246 190 14 246 190 14
40522-246 186 14 230 174 11 210 150 10 163 110 8
40523-104 69 6 10 10 10 2 2 6 2 2 6
40524- 2 2 6 2 2 6 2 2 6 2 2 6
40525- 2 2 6 2 2 6 2 2 6 2 2 6
40526- 2 2 6 2 2 6 2 2 6 2 2 6
40527- 2 2 6 6 6 6 91 60 6 167 114 7
40528-206 145 10 230 174 11 242 186 14 246 190 14
40529-246 190 14 246 190 14 246 186 14 242 186 14
40530-239 182 13 230 174 11 224 166 10 213 154 11
40531-180 133 36 124 112 88 86 86 86 58 58 58
40532- 38 38 38 22 22 22 10 10 10 6 6 6
40533- 0 0 0 0 0 0 0 0 0 0 0 0
40534- 0 0 0 0 0 0 0 0 0 0 0 0
40535- 0 0 0 0 0 0 0 0 0 0 0 0
40536- 0 0 0 0 0 0 0 0 0 14 14 14
40537- 34 34 34 70 70 70 138 110 50 158 118 36
40538-167 114 7 180 123 7 192 133 9 197 138 11
40539-200 144 11 206 145 10 213 154 11 219 162 10
40540-224 166 10 230 174 11 239 182 13 242 186 14
40541-246 186 14 246 186 14 246 186 14 246 186 14
40542-239 182 13 216 158 10 185 133 11 152 99 6
40543-104 69 6 18 14 6 2 2 6 2 2 6
40544- 2 2 6 2 2 6 2 2 6 2 2 6
40545- 2 2 6 2 2 6 2 2 6 2 2 6
40546- 2 2 6 2 2 6 2 2 6 2 2 6
40547- 2 2 6 6 6 6 80 54 7 152 99 6
40548-192 133 9 219 162 10 236 178 12 239 182 13
40549-246 186 14 242 186 14 239 182 13 236 178 12
40550-224 166 10 206 145 10 192 133 9 154 121 60
40551- 94 94 94 62 62 62 42 42 42 22 22 22
40552- 14 14 14 6 6 6 0 0 0 0 0 0
40553- 0 0 0 0 0 0 0 0 0 0 0 0
40554- 0 0 0 0 0 0 0 0 0 0 0 0
40555- 0 0 0 0 0 0 0 0 0 0 0 0
40556- 0 0 0 0 0 0 0 0 0 6 6 6
40557- 18 18 18 34 34 34 58 58 58 78 78 78
40558-101 98 89 124 112 88 142 110 46 156 107 11
40559-163 110 8 167 114 7 175 118 6 180 123 7
40560-185 133 11 197 138 11 210 150 10 219 162 10
40561-226 170 11 236 178 12 236 178 12 234 174 13
40562-219 162 10 197 138 11 163 110 8 130 83 6
40563- 91 60 6 10 10 10 2 2 6 2 2 6
40564- 18 18 18 38 38 38 38 38 38 38 38 38
40565- 38 38 38 38 38 38 38 38 38 38 38 38
40566- 38 38 38 38 38 38 26 26 26 2 2 6
40567- 2 2 6 6 6 6 70 47 6 137 92 6
40568-175 118 6 200 144 11 219 162 10 230 174 11
40569-234 174 13 230 174 11 219 162 10 210 150 10
40570-192 133 9 163 110 8 124 112 88 82 82 82
40571- 50 50 50 30 30 30 14 14 14 6 6 6
40572- 0 0 0 0 0 0 0 0 0 0 0 0
40573- 0 0 0 0 0 0 0 0 0 0 0 0
40574- 0 0 0 0 0 0 0 0 0 0 0 0
40575- 0 0 0 0 0 0 0 0 0 0 0 0
40576- 0 0 0 0 0 0 0 0 0 0 0 0
40577- 6 6 6 14 14 14 22 22 22 34 34 34
40578- 42 42 42 58 58 58 74 74 74 86 86 86
40579-101 98 89 122 102 70 130 98 46 121 87 25
40580-137 92 6 152 99 6 163 110 8 180 123 7
40581-185 133 11 197 138 11 206 145 10 200 144 11
40582-180 123 7 156 107 11 130 83 6 104 69 6
40583- 50 34 6 54 54 54 110 110 110 101 98 89
40584- 86 86 86 82 82 82 78 78 78 78 78 78
40585- 78 78 78 78 78 78 78 78 78 78 78 78
40586- 78 78 78 82 82 82 86 86 86 94 94 94
40587-106 106 106 101 101 101 86 66 34 124 80 6
40588-156 107 11 180 123 7 192 133 9 200 144 11
40589-206 145 10 200 144 11 192 133 9 175 118 6
40590-139 102 15 109 106 95 70 70 70 42 42 42
40591- 22 22 22 10 10 10 0 0 0 0 0 0
40592- 0 0 0 0 0 0 0 0 0 0 0 0
40593- 0 0 0 0 0 0 0 0 0 0 0 0
40594- 0 0 0 0 0 0 0 0 0 0 0 0
40595- 0 0 0 0 0 0 0 0 0 0 0 0
40596- 0 0 0 0 0 0 0 0 0 0 0 0
40597- 0 0 0 0 0 0 6 6 6 10 10 10
40598- 14 14 14 22 22 22 30 30 30 38 38 38
40599- 50 50 50 62 62 62 74 74 74 90 90 90
40600-101 98 89 112 100 78 121 87 25 124 80 6
40601-137 92 6 152 99 6 152 99 6 152 99 6
40602-138 86 6 124 80 6 98 70 6 86 66 30
40603-101 98 89 82 82 82 58 58 58 46 46 46
40604- 38 38 38 34 34 34 34 34 34 34 34 34
40605- 34 34 34 34 34 34 34 34 34 34 34 34
40606- 34 34 34 34 34 34 38 38 38 42 42 42
40607- 54 54 54 82 82 82 94 86 76 91 60 6
40608-134 86 6 156 107 11 167 114 7 175 118 6
40609-175 118 6 167 114 7 152 99 6 121 87 25
40610-101 98 89 62 62 62 34 34 34 18 18 18
40611- 6 6 6 0 0 0 0 0 0 0 0 0
40612- 0 0 0 0 0 0 0 0 0 0 0 0
40613- 0 0 0 0 0 0 0 0 0 0 0 0
40614- 0 0 0 0 0 0 0 0 0 0 0 0
40615- 0 0 0 0 0 0 0 0 0 0 0 0
40616- 0 0 0 0 0 0 0 0 0 0 0 0
40617- 0 0 0 0 0 0 0 0 0 0 0 0
40618- 0 0 0 6 6 6 6 6 6 10 10 10
40619- 18 18 18 22 22 22 30 30 30 42 42 42
40620- 50 50 50 66 66 66 86 86 86 101 98 89
40621-106 86 58 98 70 6 104 69 6 104 69 6
40622-104 69 6 91 60 6 82 62 34 90 90 90
40623- 62 62 62 38 38 38 22 22 22 14 14 14
40624- 10 10 10 10 10 10 10 10 10 10 10 10
40625- 10 10 10 10 10 10 6 6 6 10 10 10
40626- 10 10 10 10 10 10 10 10 10 14 14 14
40627- 22 22 22 42 42 42 70 70 70 89 81 66
40628- 80 54 7 104 69 6 124 80 6 137 92 6
40629-134 86 6 116 81 8 100 82 52 86 86 86
40630- 58 58 58 30 30 30 14 14 14 6 6 6
40631- 0 0 0 0 0 0 0 0 0 0 0 0
40632- 0 0 0 0 0 0 0 0 0 0 0 0
40633- 0 0 0 0 0 0 0 0 0 0 0 0
40634- 0 0 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
40639- 0 0 0 6 6 6 10 10 10 14 14 14
40640- 18 18 18 26 26 26 38 38 38 54 54 54
40641- 70 70 70 86 86 86 94 86 76 89 81 66
40642- 89 81 66 86 86 86 74 74 74 50 50 50
40643- 30 30 30 14 14 14 6 6 6 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- 6 6 6 18 18 18 34 34 34 58 58 58
40648- 82 82 82 89 81 66 89 81 66 89 81 66
40649- 94 86 66 94 86 76 74 74 74 50 50 50
40650- 26 26 26 14 14 14 6 6 6 0 0 0
40651- 0 0 0 0 0 0 0 0 0 0 0 0
40652- 0 0 0 0 0 0 0 0 0 0 0 0
40653- 0 0 0 0 0 0 0 0 0 0 0 0
40654- 0 0 0 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 0 0 0 0 0 0 0 0 0
40659- 0 0 0 0 0 0 0 0 0 0 0 0
40660- 6 6 6 6 6 6 14 14 14 18 18 18
40661- 30 30 30 38 38 38 46 46 46 54 54 54
40662- 50 50 50 42 42 42 30 30 30 18 18 18
40663- 10 10 10 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 6 6 6 14 14 14 26 26 26
40668- 38 38 38 50 50 50 58 58 58 58 58 58
40669- 54 54 54 42 42 42 30 30 30 18 18 18
40670- 10 10 10 0 0 0 0 0 0 0 0 0
40671- 0 0 0 0 0 0 0 0 0 0 0 0
40672- 0 0 0 0 0 0 0 0 0 0 0 0
40673- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0
40679- 0 0 0 0 0 0 0 0 0 0 0 0
40680- 0 0 0 0 0 0 0 0 0 6 6 6
40681- 6 6 6 10 10 10 14 14 14 18 18 18
40682- 18 18 18 14 14 14 10 10 10 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
40687- 0 0 0 0 0 0 0 0 0 6 6 6
40688- 14 14 14 18 18 18 22 22 22 22 22 22
40689- 18 18 18 14 14 14 10 10 10 6 6 6
40690- 0 0 0 0 0 0 0 0 0 0 0 0
40691- 0 0 0 0 0 0 0 0 0 0 0 0
40692- 0 0 0 0 0 0 0 0 0 0 0 0
40693- 0 0 0 0 0 0 0 0 0 0 0 0
40694- 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
40775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
40779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 3 3 3 0 0 0 0 0 0
40784+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4 1 1 1 0 0 0
40789+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40790+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
40793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40797+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40798+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40799+5 5 5 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+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40803+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40804+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40805+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40806+4 4 4 4 4 4
40807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40811+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40812+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40813+0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
40816+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40817+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40818+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40819+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40820+4 4 4 4 4 4
40821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40824+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40825+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40826+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40827+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40830+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40831+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40832+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40833+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40834+4 4 4 4 4 4
40835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40838+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40839+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40840+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40841+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40842+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40843+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40844+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40845+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40846+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40847+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40848+4 4 4 4 4 4
40849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40852+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40853+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40854+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40855+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40856+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40857+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40858+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40859+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40860+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40861+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40862+4 4 4 4 4 4
40863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40865+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40866+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40867+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40868+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40869+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40870+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40871+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40872+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40873+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40874+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40875+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40876+4 4 4 4 4 4
40877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40879+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40880+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40881+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40882+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40883+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40884+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40885+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40886+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40887+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40888+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40889+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40890+4 4 4 4 4 4
40891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40893+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40894+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40895+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40896+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40897+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40898+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40899+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40900+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40901+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40902+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40903+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40904+4 4 4 4 4 4
40905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40907+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40908+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40909+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40910+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40911+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40912+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40913+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40914+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40915+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40916+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40917+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40918+4 4 4 4 4 4
40919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40920+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40921+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40922+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40923+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40924+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40925+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40926+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40927+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40928+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40929+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40930+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40931+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40932+4 4 4 4 4 4
40933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40934+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40935+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40936+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40937+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40938+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40939+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40940+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40941+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40942+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40943+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40944+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40945+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40946+0 0 0 4 4 4
40947+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40948+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40949+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40950+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40951+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40952+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40953+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40954+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40955+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40956+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40957+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40958+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40959+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40960+2 0 0 0 0 0
40961+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40962+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40963+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40964+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40965+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40966+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40967+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40968+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40969+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40970+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40971+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40972+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40973+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40974+37 38 37 0 0 0
40975+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40976+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40977+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40978+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40979+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40980+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40981+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40982+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40983+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40984+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40985+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40986+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40987+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40988+85 115 134 4 0 0
40989+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40990+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40991+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40992+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40993+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40994+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40995+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40996+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40997+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40998+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40999+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41000+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41001+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41002+60 73 81 4 0 0
41003+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41004+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41005+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41006+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41007+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41008+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41009+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41010+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41011+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41012+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41013+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41014+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41015+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41016+16 19 21 4 0 0
41017+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41018+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41019+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41020+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41021+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41022+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41023+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41024+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41025+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41026+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41027+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41028+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41029+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41030+4 0 0 4 3 3
41031+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41032+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41033+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41035+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41036+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41037+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41038+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41039+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41040+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41041+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41042+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41043+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41044+3 2 2 4 4 4
41045+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41046+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41047+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41048+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41049+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41050+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41051+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41052+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41053+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41054+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41055+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41056+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41057+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41058+4 4 4 4 4 4
41059+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41060+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41061+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41062+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41063+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41064+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41065+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41066+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41067+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41068+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41069+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41070+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41071+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41072+4 4 4 4 4 4
41073+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41074+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41075+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41076+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41077+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41078+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41079+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41080+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41081+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41082+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41083+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41084+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41085+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41086+5 5 5 5 5 5
41087+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41088+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41089+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41090+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41091+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41092+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41093+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41094+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41095+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41096+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41097+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41098+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41099+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41100+5 5 5 4 4 4
41101+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41102+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41103+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41104+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41105+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41106+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41107+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41108+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41109+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41110+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41111+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41112+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41114+4 4 4 4 4 4
41115+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41116+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41117+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41118+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41119+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41120+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41121+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41122+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41123+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41124+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41125+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41126+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41128+4 4 4 4 4 4
41129+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41130+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41131+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41132+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41133+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41134+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41135+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41136+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41137+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41138+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41139+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41142+4 4 4 4 4 4
41143+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41144+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41145+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41146+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41147+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41148+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41149+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41150+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41151+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41152+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41153+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41156+4 4 4 4 4 4
41157+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41158+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41159+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41160+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41161+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41162+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41163+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41164+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41165+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41166+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41167+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41170+4 4 4 4 4 4
41171+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41172+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41173+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41174+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41175+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41176+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41177+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41178+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41179+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41180+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41181+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41184+4 4 4 4 4 4
41185+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41186+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41187+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41188+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41189+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41190+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41191+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41192+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41193+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41194+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41195+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41198+4 4 4 4 4 4
41199+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41200+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41201+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41202+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41203+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41204+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41205+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41206+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41207+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41208+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41209+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41212+4 4 4 4 4 4
41213+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41214+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41215+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41216+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41217+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41218+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41219+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41220+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41221+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41222+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41223+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41226+4 4 4 4 4 4
41227+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41228+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41229+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41230+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41231+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41232+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41233+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41234+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41235+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41236+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41237+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41240+4 4 4 4 4 4
41241+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41242+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41243+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41244+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41245+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41246+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41247+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41248+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41249+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41250+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41251+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41254+4 4 4 4 4 4
41255+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41256+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41257+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41258+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41259+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41260+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41261+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41262+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41263+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41264+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41265+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41268+4 4 4 4 4 4
41269+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41270+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41271+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41272+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41273+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41274+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41275+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41276+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41277+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41278+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41279+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41282+4 4 4 4 4 4
41283+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41284+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41285+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41286+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41287+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41288+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41289+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41290+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41291+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41292+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41293+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41296+4 4 4 4 4 4
41297+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41298+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41299+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41300+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41301+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41302+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41303+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41304+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41305+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41306+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41307+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41310+4 4 4 4 4 4
41311+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41312+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41313+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41314+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41315+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41316+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41317+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41318+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41319+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41320+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41321+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41324+4 4 4 4 4 4
41325+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41326+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41327+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41328+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41329+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41330+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41331+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41332+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41333+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41334+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41335+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41338+4 4 4 4 4 4
41339+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41340+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41341+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41342+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41343+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41344+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41345+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41346+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41347+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41348+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41349+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41352+4 4 4 4 4 4
41353+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41354+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41355+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41356+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41357+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41358+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41359+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41360+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41361+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41362+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41363+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41366+4 4 4 4 4 4
41367+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41368+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41369+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41370+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41371+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41372+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41373+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41374+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41375+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41376+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41377+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41380+4 4 4 4 4 4
41381+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41382+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41383+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41384+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41385+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41386+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41387+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41388+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41389+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41390+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41391+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41392+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41394+4 4 4 4 4 4
41395+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41396+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41397+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41398+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41399+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41400+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41401+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41402+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41403+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41404+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41405+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41408+4 4 4 4 4 4
41409+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41410+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41411+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41412+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41413+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41414+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41415+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41416+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41417+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41418+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41419+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41422+4 4 4 4 4 4
41423+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41424+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41425+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41426+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41427+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41428+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41429+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41430+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41431+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41432+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41433+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41436+4 4 4 4 4 4
41437+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41438+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41439+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41440+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41441+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41442+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41443+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41444+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41445+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41446+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41447+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41450+4 4 4 4 4 4
41451+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41452+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41453+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41454+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41455+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41456+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41457+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41458+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41459+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41460+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41461+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41462+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41464+4 4 4 4 4 4
41465+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41466+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41467+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41468+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41469+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41470+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41471+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41472+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41473+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41474+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41475+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41478+4 4 4 4 4 4
41479+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41480+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41481+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41482+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41483+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41484+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41485+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41486+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41487+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41488+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41489+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41492+4 4 4 4 4 4
41493+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41494+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41495+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41496+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41497+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41498+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41499+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41500+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41501+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41502+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41503+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41506+4 4 4 4 4 4
41507+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41508+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41509+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41510+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41511+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41512+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41513+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41514+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41515+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41516+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41517+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41520+4 4 4 4 4 4
41521+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41522+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41523+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41524+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41525+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41526+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41527+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41528+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41529+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41530+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41531+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41533+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41534+4 4 4 4 4 4
41535+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41536+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41537+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41538+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41539+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41540+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41541+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41542+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41543+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41544+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41545+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41548+4 4 4 4 4 4
41549+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41550+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41551+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41552+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41553+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41554+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41555+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41556+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41557+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41558+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41559+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41562+4 4 4 4 4 4
41563+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41564+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41565+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41566+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41567+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41568+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41569+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41570+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41571+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41573+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41576+4 4 4 4 4 4
41577+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41578+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41579+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41580+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41581+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41582+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41583+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41584+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41585+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41587+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41590+4 4 4 4 4 4
41591+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41592+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41593+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41594+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41595+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41596+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41597+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41598+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41599+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41604+4 4 4 4 4 4
41605+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41606+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41607+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41608+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41609+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41610+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41611+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41612+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41618+4 4 4 4 4 4
41619+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41620+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41621+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41622+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41623+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41624+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41625+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41626+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41632+4 4 4 4 4 4
41633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41634+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41635+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41636+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41637+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41638+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41639+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41640+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41646+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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41649+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41650+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41651+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41652+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41653+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41654+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41660+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 5 5 5 5 5 5 5 5 5
41663+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41664+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41665+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41666+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41667+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41668+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41674+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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41678+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41679+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41680+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41681+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41682+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 5 5 5
41692+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41693+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41694+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41695+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41707+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41708+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41709+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
41712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
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 5 5 5 4 3 3 5 5 5 6 6 6
41721+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41722+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41723+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4
41726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
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 5 5 5 4 3 3 5 5 5
41735+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41736+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41737+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4
41740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41742+4 4 4 4 4 4 4 4 4 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
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 5 5 5
41749+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41750+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41751+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41756+4 4 4 4 4 4 4 4 4 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
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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41764+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41765+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41770+4 4 4 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
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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41778+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41779+5 5 5 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 4 4 4 4 4 4 4 4 4
41783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 5 5 5 4 3 3 6 6 6
41792+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4
41797+4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 5 5 5 4 3 3
41806+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41814+4 4 4 4 4 4
41815diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41816index 8af6414..658c030 100644
41817--- a/drivers/video/udlfb.c
41818+++ b/drivers/video/udlfb.c
41819@@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41820 dlfb_urb_completion(urb);
41821
41822 error:
41823- atomic_add(bytes_sent, &dev->bytes_sent);
41824- atomic_add(bytes_identical, &dev->bytes_identical);
41825- atomic_add(width*height*2, &dev->bytes_rendered);
41826+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41827+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41828+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41829 end_cycles = get_cycles();
41830- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41831+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41832 >> 10)), /* Kcycles */
41833 &dev->cpu_kcycles_used);
41834
41835@@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41836 dlfb_urb_completion(urb);
41837
41838 error:
41839- atomic_add(bytes_sent, &dev->bytes_sent);
41840- atomic_add(bytes_identical, &dev->bytes_identical);
41841- atomic_add(bytes_rendered, &dev->bytes_rendered);
41842+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41843+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41844+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41845 end_cycles = get_cycles();
41846- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41847+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41848 >> 10)), /* Kcycles */
41849 &dev->cpu_kcycles_used);
41850 }
41851@@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_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_rendered));
41856+ atomic_read_unchecked(&dev->bytes_rendered));
41857 }
41858
41859 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41860@@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_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_identical));
41865+ atomic_read_unchecked(&dev->bytes_identical));
41866 }
41867
41868 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41869@@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_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->bytes_sent));
41874+ atomic_read_unchecked(&dev->bytes_sent));
41875 }
41876
41877 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41878@@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41879 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41880 struct dlfb_data *dev = fb_info->par;
41881 return snprintf(buf, PAGE_SIZE, "%u\n",
41882- atomic_read(&dev->cpu_kcycles_used));
41883+ atomic_read_unchecked(&dev->cpu_kcycles_used));
41884 }
41885
41886 static ssize_t edid_show(
41887@@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41888 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41889 struct dlfb_data *dev = fb_info->par;
41890
41891- atomic_set(&dev->bytes_rendered, 0);
41892- atomic_set(&dev->bytes_identical, 0);
41893- atomic_set(&dev->bytes_sent, 0);
41894- atomic_set(&dev->cpu_kcycles_used, 0);
41895+ atomic_set_unchecked(&dev->bytes_rendered, 0);
41896+ atomic_set_unchecked(&dev->bytes_identical, 0);
41897+ atomic_set_unchecked(&dev->bytes_sent, 0);
41898+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41899
41900 return count;
41901 }
41902diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41903index b0e2a42..e2df3ad 100644
41904--- a/drivers/video/uvesafb.c
41905+++ b/drivers/video/uvesafb.c
41906@@ -19,6 +19,7 @@
41907 #include <linux/io.h>
41908 #include <linux/mutex.h>
41909 #include <linux/slab.h>
41910+#include <linux/moduleloader.h>
41911 #include <video/edid.h>
41912 #include <video/uvesafb.h>
41913 #ifdef CONFIG_X86
41914@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41915 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41916 par->pmi_setpal = par->ypan = 0;
41917 } else {
41918+
41919+#ifdef CONFIG_PAX_KERNEXEC
41920+#ifdef CONFIG_MODULES
41921+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41922+#endif
41923+ if (!par->pmi_code) {
41924+ par->pmi_setpal = par->ypan = 0;
41925+ return 0;
41926+ }
41927+#endif
41928+
41929 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41930 + task->t.regs.edi);
41931+
41932+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41933+ pax_open_kernel();
41934+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41935+ pax_close_kernel();
41936+
41937+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41938+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41939+#else
41940 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41941 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41942+#endif
41943+
41944 printk(KERN_INFO "uvesafb: protected mode interface info at "
41945 "%04x:%04x\n",
41946 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41947@@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
41948 par->ypan = ypan;
41949
41950 if (par->pmi_setpal || par->ypan) {
41951+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
41952 if (__supported_pte_mask & _PAGE_NX) {
41953 par->pmi_setpal = par->ypan = 0;
41954 printk(KERN_WARNING "uvesafb: NX protection is actively."
41955 "We have better not to use the PMI.\n");
41956- } else {
41957+ } else
41958+#endif
41959 uvesafb_vbe_getpmi(task, par);
41960- }
41961 }
41962 #else
41963 /* The protected mode interface is not available on non-x86. */
41964@@ -1836,6 +1860,11 @@ out:
41965 if (par->vbe_modes)
41966 kfree(par->vbe_modes);
41967
41968+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41969+ if (par->pmi_code)
41970+ module_free_exec(NULL, par->pmi_code);
41971+#endif
41972+
41973 framebuffer_release(info);
41974 return err;
41975 }
41976@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
41977 kfree(par->vbe_state_orig);
41978 if (par->vbe_state_saved)
41979 kfree(par->vbe_state_saved);
41980+
41981+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41982+ if (par->pmi_code)
41983+ module_free_exec(NULL, par->pmi_code);
41984+#endif
41985+
41986 }
41987
41988 framebuffer_release(info);
41989diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41990index 501b340..86bd4cf 100644
41991--- a/drivers/video/vesafb.c
41992+++ b/drivers/video/vesafb.c
41993@@ -9,6 +9,7 @@
41994 */
41995
41996 #include <linux/module.h>
41997+#include <linux/moduleloader.h>
41998 #include <linux/kernel.h>
41999 #include <linux/errno.h>
42000 #include <linux/string.h>
42001@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42002 static int vram_total __initdata; /* Set total amount of memory */
42003 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42004 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42005-static void (*pmi_start)(void) __read_mostly;
42006-static void (*pmi_pal) (void) __read_mostly;
42007+static void (*pmi_start)(void) __read_only;
42008+static void (*pmi_pal) (void) __read_only;
42009 static int depth __read_mostly;
42010 static int vga_compat __read_mostly;
42011 /* --------------------------------------------------------------------- */
42012@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42013 unsigned int size_vmode;
42014 unsigned int size_remap;
42015 unsigned int size_total;
42016+ void *pmi_code = NULL;
42017
42018 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42019 return -ENODEV;
42020@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42021 size_remap = size_total;
42022 vesafb_fix.smem_len = size_remap;
42023
42024-#ifndef __i386__
42025- screen_info.vesapm_seg = 0;
42026-#endif
42027-
42028 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42029 printk(KERN_WARNING
42030 "vesafb: cannot reserve video memory at 0x%lx\n",
42031@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42032 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42033 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42034
42035+#ifdef __i386__
42036+
42037+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42038+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
42039+ if (!pmi_code)
42040+#elif !defined(CONFIG_PAX_KERNEXEC)
42041+ if (0)
42042+#endif
42043+
42044+#endif
42045+ screen_info.vesapm_seg = 0;
42046+
42047 if (screen_info.vesapm_seg) {
42048- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42049- screen_info.vesapm_seg,screen_info.vesapm_off);
42050+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42051+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42052 }
42053
42054 if (screen_info.vesapm_seg < 0xc000)
42055@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42056
42057 if (ypan || pmi_setpal) {
42058 unsigned short *pmi_base;
42059+
42060 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42061- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42062- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42063+
42064+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42065+ pax_open_kernel();
42066+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42067+#else
42068+ pmi_code = pmi_base;
42069+#endif
42070+
42071+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42072+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42073+
42074+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42075+ pmi_start = ktva_ktla(pmi_start);
42076+ pmi_pal = ktva_ktla(pmi_pal);
42077+ pax_close_kernel();
42078+#endif
42079+
42080 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42081 if (pmi_base[3]) {
42082 printk(KERN_INFO "vesafb: pmi: ports = ");
42083@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42084 info->node, info->fix.id);
42085 return 0;
42086 err:
42087+
42088+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42089+ module_free_exec(NULL, pmi_code);
42090+#endif
42091+
42092 if (info->screen_base)
42093 iounmap(info->screen_base);
42094 framebuffer_release(info);
42095diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42096index 88714ae..16c2e11 100644
42097--- a/drivers/video/via/via_clock.h
42098+++ b/drivers/video/via/via_clock.h
42099@@ -56,7 +56,7 @@ struct via_clock {
42100
42101 void (*set_engine_pll_state)(u8 state);
42102 void (*set_engine_pll)(struct via_pll_config config);
42103-};
42104+} __no_const;
42105
42106
42107 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42108diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42109index e56c934..fc22f4b 100644
42110--- a/drivers/xen/xen-pciback/conf_space.h
42111+++ b/drivers/xen/xen-pciback/conf_space.h
42112@@ -44,15 +44,15 @@ struct config_field {
42113 struct {
42114 conf_dword_write write;
42115 conf_dword_read read;
42116- } dw;
42117+ } __no_const dw;
42118 struct {
42119 conf_word_write write;
42120 conf_word_read read;
42121- } w;
42122+ } __no_const w;
42123 struct {
42124 conf_byte_write write;
42125 conf_byte_read read;
42126- } b;
42127+ } __no_const b;
42128 } u;
42129 struct list_head list;
42130 };
42131diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42132index 57ccb75..f6d05f8 100644
42133--- a/fs/9p/vfs_inode.c
42134+++ b/fs/9p/vfs_inode.c
42135@@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42136 void
42137 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42138 {
42139- char *s = nd_get_link(nd);
42140+ const char *s = nd_get_link(nd);
42141
42142 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42143 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42144diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42145index 0225742..1cd4732 100644
42146--- a/fs/Kconfig.binfmt
42147+++ b/fs/Kconfig.binfmt
42148@@ -89,7 +89,7 @@ config HAVE_AOUT
42149
42150 config BINFMT_AOUT
42151 tristate "Kernel support for a.out and ECOFF binaries"
42152- depends on HAVE_AOUT
42153+ depends on HAVE_AOUT && BROKEN
42154 ---help---
42155 A.out (Assembler.OUTput) is a set of formats for libraries and
42156 executables used in the earliest versions of UNIX. Linux used
42157diff --git a/fs/aio.c b/fs/aio.c
42158index 55c4c76..11aee6f 100644
42159--- a/fs/aio.c
42160+++ b/fs/aio.c
42161@@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42162 size += sizeof(struct io_event) * nr_events;
42163 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42164
42165- if (nr_pages < 0)
42166+ if (nr_pages <= 0)
42167 return -EINVAL;
42168
42169 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42170@@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42171 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42172 {
42173 ssize_t ret;
42174+ struct iovec iovstack;
42175
42176 #ifdef CONFIG_COMPAT
42177 if (compat)
42178 ret = compat_rw_copy_check_uvector(type,
42179 (struct compat_iovec __user *)kiocb->ki_buf,
42180- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42181+ kiocb->ki_nbytes, 1, &iovstack,
42182 &kiocb->ki_iovec);
42183 else
42184 #endif
42185 ret = rw_copy_check_uvector(type,
42186 (struct iovec __user *)kiocb->ki_buf,
42187- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42188+ kiocb->ki_nbytes, 1, &iovstack,
42189 &kiocb->ki_iovec);
42190 if (ret < 0)
42191 goto out;
42192@@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42193 if (ret < 0)
42194 goto out;
42195
42196+ if (kiocb->ki_iovec == &iovstack) {
42197+ kiocb->ki_inline_vec = iovstack;
42198+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
42199+ }
42200 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42201 kiocb->ki_cur_seg = 0;
42202 /* ki_nbytes/left now reflect bytes instead of segs */
42203diff --git a/fs/attr.c b/fs/attr.c
42204index 0da9095..1386693 100644
42205--- a/fs/attr.c
42206+++ b/fs/attr.c
42207@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42208 unsigned long limit;
42209
42210 limit = rlimit(RLIMIT_FSIZE);
42211+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42212 if (limit != RLIM_INFINITY && offset > limit)
42213 goto out_sig;
42214 if (offset > inode->i_sb->s_maxbytes)
42215diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42216index da8876d..9f3e6d8 100644
42217--- a/fs/autofs4/waitq.c
42218+++ b/fs/autofs4/waitq.c
42219@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42220 {
42221 unsigned long sigpipe, flags;
42222 mm_segment_t fs;
42223- const char *data = (const char *)addr;
42224+ const char __user *data = (const char __force_user *)addr;
42225 ssize_t wr = 0;
42226
42227 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42228diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42229index e18da23..affc30e 100644
42230--- a/fs/befs/linuxvfs.c
42231+++ b/fs/befs/linuxvfs.c
42232@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42233 {
42234 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42235 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42236- char *link = nd_get_link(nd);
42237+ const char *link = nd_get_link(nd);
42238 if (!IS_ERR(link))
42239 kfree(link);
42240 }
42241diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42242index d146e18..12d1bd1 100644
42243--- a/fs/binfmt_aout.c
42244+++ b/fs/binfmt_aout.c
42245@@ -16,6 +16,7 @@
42246 #include <linux/string.h>
42247 #include <linux/fs.h>
42248 #include <linux/file.h>
42249+#include <linux/security.h>
42250 #include <linux/stat.h>
42251 #include <linux/fcntl.h>
42252 #include <linux/ptrace.h>
42253@@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42254 #endif
42255 # define START_STACK(u) ((void __user *)u.start_stack)
42256
42257+ memset(&dump, 0, sizeof(dump));
42258+
42259 fs = get_fs();
42260 set_fs(KERNEL_DS);
42261 has_dumped = 1;
42262@@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42263
42264 /* If the size of the dump file exceeds the rlimit, then see what would happen
42265 if we wrote the stack, but not the data area. */
42266+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42267 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42268 dump.u_dsize = 0;
42269
42270 /* Make sure we have enough room to write the stack and data areas. */
42271+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42272 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42273 dump.u_ssize = 0;
42274
42275@@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42276 rlim = rlimit(RLIMIT_DATA);
42277 if (rlim >= RLIM_INFINITY)
42278 rlim = ~0;
42279+
42280+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42281 if (ex.a_data + ex.a_bss > rlim)
42282 return -ENOMEM;
42283
42284@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42285
42286 install_exec_creds(bprm);
42287
42288+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42289+ current->mm->pax_flags = 0UL;
42290+#endif
42291+
42292+#ifdef CONFIG_PAX_PAGEEXEC
42293+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42294+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42295+
42296+#ifdef CONFIG_PAX_EMUTRAMP
42297+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42298+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42299+#endif
42300+
42301+#ifdef CONFIG_PAX_MPROTECT
42302+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42303+ current->mm->pax_flags |= MF_PAX_MPROTECT;
42304+#endif
42305+
42306+ }
42307+#endif
42308+
42309 if (N_MAGIC(ex) == OMAGIC) {
42310 unsigned long text_addr, map_size;
42311 loff_t pos;
42312@@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42313 }
42314
42315 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42316- PROT_READ | PROT_WRITE | PROT_EXEC,
42317+ PROT_READ | PROT_WRITE,
42318 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42319 fd_offset + ex.a_text);
42320 if (error != N_DATADDR(ex)) {
42321diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42322index 1b52956..271266e 100644
42323--- a/fs/binfmt_elf.c
42324+++ b/fs/binfmt_elf.c
42325@@ -32,6 +32,7 @@
42326 #include <linux/elf.h>
42327 #include <linux/utsname.h>
42328 #include <linux/coredump.h>
42329+#include <linux/xattr.h>
42330 #include <asm/uaccess.h>
42331 #include <asm/param.h>
42332 #include <asm/page.h>
42333@@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42334 #define elf_core_dump NULL
42335 #endif
42336
42337+#ifdef CONFIG_PAX_MPROTECT
42338+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42339+#endif
42340+
42341 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42342 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42343 #else
42344@@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42345 .load_binary = load_elf_binary,
42346 .load_shlib = load_elf_library,
42347 .core_dump = elf_core_dump,
42348+
42349+#ifdef CONFIG_PAX_MPROTECT
42350+ .handle_mprotect= elf_handle_mprotect,
42351+#endif
42352+
42353 .min_coredump = ELF_EXEC_PAGESIZE,
42354 };
42355
42356@@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42357
42358 static int set_brk(unsigned long start, unsigned long end)
42359 {
42360+ unsigned long e = end;
42361+
42362 start = ELF_PAGEALIGN(start);
42363 end = ELF_PAGEALIGN(end);
42364 if (end > start) {
42365@@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42366 if (BAD_ADDR(addr))
42367 return addr;
42368 }
42369- current->mm->start_brk = current->mm->brk = end;
42370+ current->mm->start_brk = current->mm->brk = e;
42371 return 0;
42372 }
42373
42374@@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42375 elf_addr_t __user *u_rand_bytes;
42376 const char *k_platform = ELF_PLATFORM;
42377 const char *k_base_platform = ELF_BASE_PLATFORM;
42378- unsigned char k_rand_bytes[16];
42379+ u32 k_rand_bytes[4];
42380 int items;
42381 elf_addr_t *elf_info;
42382 int ei_index = 0;
42383 const struct cred *cred = current_cred();
42384 struct vm_area_struct *vma;
42385+ unsigned long saved_auxv[AT_VECTOR_SIZE];
42386
42387 /*
42388 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42389@@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42390 * Generate 16 random bytes for userspace PRNG seeding.
42391 */
42392 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42393- u_rand_bytes = (elf_addr_t __user *)
42394- STACK_ALLOC(p, sizeof(k_rand_bytes));
42395+ srandom32(k_rand_bytes[0] ^ random32());
42396+ srandom32(k_rand_bytes[1] ^ random32());
42397+ srandom32(k_rand_bytes[2] ^ random32());
42398+ srandom32(k_rand_bytes[3] ^ random32());
42399+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
42400+ u_rand_bytes = (elf_addr_t __user *) p;
42401 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42402 return -EFAULT;
42403
42404@@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42405 return -EFAULT;
42406 current->mm->env_end = p;
42407
42408+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42409+
42410 /* Put the elf_info on the stack in the right place. */
42411 sp = (elf_addr_t __user *)envp + 1;
42412- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42413+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42414 return -EFAULT;
42415 return 0;
42416 }
42417@@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42418 {
42419 struct elf_phdr *elf_phdata;
42420 struct elf_phdr *eppnt;
42421- unsigned long load_addr = 0;
42422+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42423 int load_addr_set = 0;
42424 unsigned long last_bss = 0, elf_bss = 0;
42425- unsigned long error = ~0UL;
42426+ unsigned long error = -EINVAL;
42427 unsigned long total_size;
42428 int retval, i, size;
42429
42430@@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42431 goto out_close;
42432 }
42433
42434+#ifdef CONFIG_PAX_SEGMEXEC
42435+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42436+ pax_task_size = SEGMEXEC_TASK_SIZE;
42437+#endif
42438+
42439 eppnt = elf_phdata;
42440 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42441 if (eppnt->p_type == PT_LOAD) {
42442@@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42443 k = load_addr + eppnt->p_vaddr;
42444 if (BAD_ADDR(k) ||
42445 eppnt->p_filesz > eppnt->p_memsz ||
42446- eppnt->p_memsz > TASK_SIZE ||
42447- TASK_SIZE - eppnt->p_memsz < k) {
42448+ eppnt->p_memsz > pax_task_size ||
42449+ pax_task_size - eppnt->p_memsz < k) {
42450 error = -ENOMEM;
42451 goto out_close;
42452 }
42453@@ -523,6 +547,311 @@ out:
42454 return error;
42455 }
42456
42457+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42458+#ifdef CONFIG_PAX_SOFTMODE
42459+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42460+{
42461+ unsigned long pax_flags = 0UL;
42462+
42463+#ifdef CONFIG_PAX_PAGEEXEC
42464+ if (elf_phdata->p_flags & PF_PAGEEXEC)
42465+ pax_flags |= MF_PAX_PAGEEXEC;
42466+#endif
42467+
42468+#ifdef CONFIG_PAX_SEGMEXEC
42469+ if (elf_phdata->p_flags & PF_SEGMEXEC)
42470+ pax_flags |= MF_PAX_SEGMEXEC;
42471+#endif
42472+
42473+#ifdef CONFIG_PAX_EMUTRAMP
42474+ if (elf_phdata->p_flags & PF_EMUTRAMP)
42475+ pax_flags |= MF_PAX_EMUTRAMP;
42476+#endif
42477+
42478+#ifdef CONFIG_PAX_MPROTECT
42479+ if (elf_phdata->p_flags & PF_MPROTECT)
42480+ pax_flags |= MF_PAX_MPROTECT;
42481+#endif
42482+
42483+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42484+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42485+ pax_flags |= MF_PAX_RANDMMAP;
42486+#endif
42487+
42488+ return pax_flags;
42489+}
42490+#endif
42491+
42492+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42493+{
42494+ unsigned long pax_flags = 0UL;
42495+
42496+#ifdef CONFIG_PAX_PAGEEXEC
42497+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42498+ pax_flags |= MF_PAX_PAGEEXEC;
42499+#endif
42500+
42501+#ifdef CONFIG_PAX_SEGMEXEC
42502+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42503+ pax_flags |= MF_PAX_SEGMEXEC;
42504+#endif
42505+
42506+#ifdef CONFIG_PAX_EMUTRAMP
42507+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42508+ pax_flags |= MF_PAX_EMUTRAMP;
42509+#endif
42510+
42511+#ifdef CONFIG_PAX_MPROTECT
42512+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42513+ pax_flags |= MF_PAX_MPROTECT;
42514+#endif
42515+
42516+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42517+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42518+ pax_flags |= MF_PAX_RANDMMAP;
42519+#endif
42520+
42521+ return pax_flags;
42522+}
42523+#endif
42524+
42525+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42526+#ifdef CONFIG_PAX_SOFTMODE
42527+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42528+{
42529+ unsigned long pax_flags = 0UL;
42530+
42531+#ifdef CONFIG_PAX_PAGEEXEC
42532+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42533+ pax_flags |= MF_PAX_PAGEEXEC;
42534+#endif
42535+
42536+#ifdef CONFIG_PAX_SEGMEXEC
42537+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42538+ pax_flags |= MF_PAX_SEGMEXEC;
42539+#endif
42540+
42541+#ifdef CONFIG_PAX_EMUTRAMP
42542+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42543+ pax_flags |= MF_PAX_EMUTRAMP;
42544+#endif
42545+
42546+#ifdef CONFIG_PAX_MPROTECT
42547+ if (pax_flags_softmode & MF_PAX_MPROTECT)
42548+ pax_flags |= MF_PAX_MPROTECT;
42549+#endif
42550+
42551+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42552+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42553+ pax_flags |= MF_PAX_RANDMMAP;
42554+#endif
42555+
42556+ return pax_flags;
42557+}
42558+#endif
42559+
42560+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42561+{
42562+ unsigned long pax_flags = 0UL;
42563+
42564+#ifdef CONFIG_PAX_PAGEEXEC
42565+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42566+ pax_flags |= MF_PAX_PAGEEXEC;
42567+#endif
42568+
42569+#ifdef CONFIG_PAX_SEGMEXEC
42570+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42571+ pax_flags |= MF_PAX_SEGMEXEC;
42572+#endif
42573+
42574+#ifdef CONFIG_PAX_EMUTRAMP
42575+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42576+ pax_flags |= MF_PAX_EMUTRAMP;
42577+#endif
42578+
42579+#ifdef CONFIG_PAX_MPROTECT
42580+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42581+ pax_flags |= MF_PAX_MPROTECT;
42582+#endif
42583+
42584+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42585+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42586+ pax_flags |= MF_PAX_RANDMMAP;
42587+#endif
42588+
42589+ return pax_flags;
42590+}
42591+#endif
42592+
42593+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42594+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42595+{
42596+ unsigned long pax_flags = 0UL;
42597+
42598+#ifdef CONFIG_PAX_EI_PAX
42599+
42600+#ifdef CONFIG_PAX_PAGEEXEC
42601+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42602+ pax_flags |= MF_PAX_PAGEEXEC;
42603+#endif
42604+
42605+#ifdef CONFIG_PAX_SEGMEXEC
42606+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42607+ pax_flags |= MF_PAX_SEGMEXEC;
42608+#endif
42609+
42610+#ifdef CONFIG_PAX_EMUTRAMP
42611+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42612+ pax_flags |= MF_PAX_EMUTRAMP;
42613+#endif
42614+
42615+#ifdef CONFIG_PAX_MPROTECT
42616+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42617+ pax_flags |= MF_PAX_MPROTECT;
42618+#endif
42619+
42620+#ifdef CONFIG_PAX_ASLR
42621+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42622+ pax_flags |= MF_PAX_RANDMMAP;
42623+#endif
42624+
42625+#else
42626+
42627+#ifdef CONFIG_PAX_PAGEEXEC
42628+ pax_flags |= MF_PAX_PAGEEXEC;
42629+#endif
42630+
42631+#ifdef CONFIG_PAX_SEGMEXEC
42632+ pax_flags |= MF_PAX_SEGMEXEC;
42633+#endif
42634+
42635+#ifdef CONFIG_PAX_MPROTECT
42636+ pax_flags |= MF_PAX_MPROTECT;
42637+#endif
42638+
42639+#ifdef CONFIG_PAX_RANDMMAP
42640+ if (randomize_va_space)
42641+ pax_flags |= MF_PAX_RANDMMAP;
42642+#endif
42643+
42644+#endif
42645+
42646+ return pax_flags;
42647+}
42648+
42649+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42650+{
42651+
42652+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42653+ unsigned long i;
42654+
42655+ for (i = 0UL; i < elf_ex->e_phnum; i++)
42656+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42657+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42658+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42659+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42660+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42661+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42662+ return ~0UL;
42663+
42664+#ifdef CONFIG_PAX_SOFTMODE
42665+ if (pax_softmode)
42666+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42667+ else
42668+#endif
42669+
42670+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42671+ break;
42672+ }
42673+#endif
42674+
42675+ return ~0UL;
42676+}
42677+
42678+static unsigned long pax_parse_xattr_pax(struct file * const file)
42679+{
42680+
42681+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42682+ ssize_t xattr_size, i;
42683+ unsigned char xattr_value[5];
42684+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42685+
42686+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42687+ if (xattr_size <= 0)
42688+ return ~0UL;
42689+
42690+ for (i = 0; i < xattr_size; i++)
42691+ switch (xattr_value[i]) {
42692+ default:
42693+ return ~0UL;
42694+
42695+#define parse_flag(option1, option2, flag) \
42696+ case option1: \
42697+ pax_flags_hardmode |= MF_PAX_##flag; \
42698+ break; \
42699+ case option2: \
42700+ pax_flags_softmode |= MF_PAX_##flag; \
42701+ break;
42702+
42703+ parse_flag('p', 'P', PAGEEXEC);
42704+ parse_flag('e', 'E', EMUTRAMP);
42705+ parse_flag('m', 'M', MPROTECT);
42706+ parse_flag('r', 'R', RANDMMAP);
42707+ parse_flag('s', 'S', SEGMEXEC);
42708+
42709+#undef parse_flag
42710+ }
42711+
42712+ if (pax_flags_hardmode & pax_flags_softmode)
42713+ return ~0UL;
42714+
42715+#ifdef CONFIG_PAX_SOFTMODE
42716+ if (pax_softmode)
42717+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42718+ else
42719+#endif
42720+
42721+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42722+#else
42723+ return ~0UL;
42724+#endif
42725+
42726+}
42727+
42728+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42729+{
42730+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42731+
42732+ pax_flags = pax_parse_ei_pax(elf_ex);
42733+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42734+ xattr_pax_flags = pax_parse_xattr_pax(file);
42735+
42736+ if (pt_pax_flags == ~0UL)
42737+ pt_pax_flags = xattr_pax_flags;
42738+ else if (xattr_pax_flags == ~0UL)
42739+ xattr_pax_flags = pt_pax_flags;
42740+ if (pt_pax_flags != xattr_pax_flags)
42741+ return -EINVAL;
42742+ if (pt_pax_flags != ~0UL)
42743+ pax_flags = pt_pax_flags;
42744+
42745+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42746+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42747+ if ((__supported_pte_mask & _PAGE_NX))
42748+ pax_flags &= ~MF_PAX_SEGMEXEC;
42749+ else
42750+ pax_flags &= ~MF_PAX_PAGEEXEC;
42751+ }
42752+#endif
42753+
42754+ if (0 > pax_check_flags(&pax_flags))
42755+ return -EINVAL;
42756+
42757+ current->mm->pax_flags = pax_flags;
42758+ return 0;
42759+}
42760+#endif
42761+
42762 /*
42763 * These are the functions used to load ELF style executables and shared
42764 * libraries. There is no binary dependent code anywhere else.
42765@@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42766 {
42767 unsigned int random_variable = 0;
42768
42769+#ifdef CONFIG_PAX_RANDUSTACK
42770+ if (randomize_va_space)
42771+ return stack_top - current->mm->delta_stack;
42772+#endif
42773+
42774 if ((current->flags & PF_RANDOMIZE) &&
42775 !(current->personality & ADDR_NO_RANDOMIZE)) {
42776 random_variable = get_random_int() & STACK_RND_MASK;
42777@@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42778 unsigned long load_addr = 0, load_bias = 0;
42779 int load_addr_set = 0;
42780 char * elf_interpreter = NULL;
42781- unsigned long error;
42782+ unsigned long error = 0;
42783 struct elf_phdr *elf_ppnt, *elf_phdata;
42784 unsigned long elf_bss, elf_brk;
42785 int retval, i;
42786@@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42787 unsigned long start_code, end_code, start_data, end_data;
42788 unsigned long reloc_func_desc __maybe_unused = 0;
42789 int executable_stack = EXSTACK_DEFAULT;
42790- unsigned long def_flags = 0;
42791 struct {
42792 struct elfhdr elf_ex;
42793 struct elfhdr interp_elf_ex;
42794 } *loc;
42795+ unsigned long pax_task_size = TASK_SIZE;
42796
42797 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42798 if (!loc) {
42799@@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42800 goto out_free_dentry;
42801
42802 /* OK, This is the point of no return */
42803- current->mm->def_flags = def_flags;
42804+
42805+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42806+ current->mm->pax_flags = 0UL;
42807+#endif
42808+
42809+#ifdef CONFIG_PAX_DLRESOLVE
42810+ current->mm->call_dl_resolve = 0UL;
42811+#endif
42812+
42813+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42814+ current->mm->call_syscall = 0UL;
42815+#endif
42816+
42817+#ifdef CONFIG_PAX_ASLR
42818+ current->mm->delta_mmap = 0UL;
42819+ current->mm->delta_stack = 0UL;
42820+#endif
42821+
42822+ current->mm->def_flags = 0;
42823+
42824+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42825+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42826+ send_sig(SIGKILL, current, 0);
42827+ goto out_free_dentry;
42828+ }
42829+#endif
42830+
42831+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42832+ pax_set_initial_flags(bprm);
42833+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42834+ if (pax_set_initial_flags_func)
42835+ (pax_set_initial_flags_func)(bprm);
42836+#endif
42837+
42838+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42839+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42840+ current->mm->context.user_cs_limit = PAGE_SIZE;
42841+ current->mm->def_flags |= VM_PAGEEXEC;
42842+ }
42843+#endif
42844+
42845+#ifdef CONFIG_PAX_SEGMEXEC
42846+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42847+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42848+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42849+ pax_task_size = SEGMEXEC_TASK_SIZE;
42850+ current->mm->def_flags |= VM_NOHUGEPAGE;
42851+ }
42852+#endif
42853+
42854+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42855+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42856+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42857+ put_cpu();
42858+ }
42859+#endif
42860
42861 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42862 may depend on the personality. */
42863 SET_PERSONALITY(loc->elf_ex);
42864+
42865+#ifdef CONFIG_PAX_ASLR
42866+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42867+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42868+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42869+ }
42870+#endif
42871+
42872+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42873+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42874+ executable_stack = EXSTACK_DISABLE_X;
42875+ current->personality &= ~READ_IMPLIES_EXEC;
42876+ } else
42877+#endif
42878+
42879 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42880 current->personality |= READ_IMPLIES_EXEC;
42881
42882@@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42883 #else
42884 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42885 #endif
42886+
42887+#ifdef CONFIG_PAX_RANDMMAP
42888+ /* PaX: randomize base address at the default exe base if requested */
42889+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42890+#ifdef CONFIG_SPARC64
42891+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42892+#else
42893+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42894+#endif
42895+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42896+ elf_flags |= MAP_FIXED;
42897+ }
42898+#endif
42899+
42900 }
42901
42902 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42903@@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42904 * allowed task size. Note that p_filesz must always be
42905 * <= p_memsz so it is only necessary to check p_memsz.
42906 */
42907- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42908- elf_ppnt->p_memsz > TASK_SIZE ||
42909- TASK_SIZE - elf_ppnt->p_memsz < k) {
42910+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42911+ elf_ppnt->p_memsz > pax_task_size ||
42912+ pax_task_size - elf_ppnt->p_memsz < k) {
42913 /* set_brk can never work. Avoid overflows. */
42914 send_sig(SIGKILL, current, 0);
42915 retval = -EINVAL;
42916@@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42917 goto out_free_dentry;
42918 }
42919 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42920- send_sig(SIGSEGV, current, 0);
42921- retval = -EFAULT; /* Nobody gets to see this, but.. */
42922- goto out_free_dentry;
42923+ /*
42924+ * This bss-zeroing can fail if the ELF
42925+ * file specifies odd protections. So
42926+ * we don't check the return value
42927+ */
42928 }
42929
42930+#ifdef CONFIG_PAX_RANDMMAP
42931+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42932+ unsigned long start, size;
42933+
42934+ start = ELF_PAGEALIGN(elf_brk);
42935+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42936+ down_read(&current->mm->mmap_sem);
42937+ retval = -ENOMEM;
42938+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42939+ unsigned long prot = PROT_NONE;
42940+
42941+ up_read(&current->mm->mmap_sem);
42942+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42943+// if (current->personality & ADDR_NO_RANDOMIZE)
42944+// prot = PROT_READ;
42945+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42946+ retval = IS_ERR_VALUE(start) ? start : 0;
42947+ } else
42948+ up_read(&current->mm->mmap_sem);
42949+ if (retval == 0)
42950+ retval = set_brk(start + size, start + size + PAGE_SIZE);
42951+ if (retval < 0) {
42952+ send_sig(SIGKILL, current, 0);
42953+ goto out_free_dentry;
42954+ }
42955+ }
42956+#endif
42957+
42958 if (elf_interpreter) {
42959 unsigned long uninitialized_var(interp_map_addr);
42960
42961@@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
42962 * Decide what to dump of a segment, part, all or none.
42963 */
42964 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42965- unsigned long mm_flags)
42966+ unsigned long mm_flags, long signr)
42967 {
42968 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42969
42970@@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42971 if (vma->vm_file == NULL)
42972 return 0;
42973
42974- if (FILTER(MAPPED_PRIVATE))
42975+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42976 goto whole;
42977
42978 /*
42979@@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42980 {
42981 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42982 int i = 0;
42983- do
42984+ do {
42985 i += 2;
42986- while (auxv[i - 2] != AT_NULL);
42987+ } while (auxv[i - 2] != AT_NULL);
42988 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42989 }
42990
42991@@ -1890,14 +2338,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42992 }
42993
42994 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42995- unsigned long mm_flags)
42996+ struct coredump_params *cprm)
42997 {
42998 struct vm_area_struct *vma;
42999 size_t size = 0;
43000
43001 for (vma = first_vma(current, gate_vma); vma != NULL;
43002 vma = next_vma(vma, gate_vma))
43003- size += vma_dump_size(vma, mm_flags);
43004+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43005 return size;
43006 }
43007
43008@@ -1991,7 +2439,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43009
43010 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43011
43012- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43013+ offset += elf_core_vma_data_size(gate_vma, cprm);
43014 offset += elf_core_extra_data_size();
43015 e_shoff = offset;
43016
43017@@ -2005,10 +2453,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43018 offset = dataoff;
43019
43020 size += sizeof(*elf);
43021+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43022 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43023 goto end_coredump;
43024
43025 size += sizeof(*phdr4note);
43026+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43027 if (size > cprm->limit
43028 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43029 goto end_coredump;
43030@@ -2022,7 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43031 phdr.p_offset = offset;
43032 phdr.p_vaddr = vma->vm_start;
43033 phdr.p_paddr = 0;
43034- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43035+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43036 phdr.p_memsz = vma->vm_end - vma->vm_start;
43037 offset += phdr.p_filesz;
43038 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43039@@ -2033,6 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43040 phdr.p_align = ELF_EXEC_PAGESIZE;
43041
43042 size += sizeof(phdr);
43043+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43044 if (size > cprm->limit
43045 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43046 goto end_coredump;
43047@@ -2057,7 +2508,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43048 unsigned long addr;
43049 unsigned long end;
43050
43051- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43052+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43053
43054 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43055 struct page *page;
43056@@ -2066,6 +2517,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43057 page = get_dump_page(addr);
43058 if (page) {
43059 void *kaddr = kmap(page);
43060+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43061 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43062 !dump_write(cprm->file, kaddr,
43063 PAGE_SIZE);
43064@@ -2083,6 +2535,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43065
43066 if (e_phnum == PN_XNUM) {
43067 size += sizeof(*shdr4extnum);
43068+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43069 if (size > cprm->limit
43070 || !dump_write(cprm->file, shdr4extnum,
43071 sizeof(*shdr4extnum)))
43072@@ -2103,6 +2556,97 @@ out:
43073
43074 #endif /* CONFIG_ELF_CORE */
43075
43076+#ifdef CONFIG_PAX_MPROTECT
43077+/* PaX: non-PIC ELF libraries need relocations on their executable segments
43078+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43079+ * we'll remove VM_MAYWRITE for good on RELRO segments.
43080+ *
43081+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43082+ * basis because we want to allow the common case and not the special ones.
43083+ */
43084+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43085+{
43086+ struct elfhdr elf_h;
43087+ struct elf_phdr elf_p;
43088+ unsigned long i;
43089+ unsigned long oldflags;
43090+ bool is_textrel_rw, is_textrel_rx, is_relro;
43091+
43092+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43093+ return;
43094+
43095+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43096+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43097+
43098+#ifdef CONFIG_PAX_ELFRELOCS
43099+ /* possible TEXTREL */
43100+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43101+ 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);
43102+#else
43103+ is_textrel_rw = false;
43104+ is_textrel_rx = false;
43105+#endif
43106+
43107+ /* possible RELRO */
43108+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43109+
43110+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43111+ return;
43112+
43113+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43114+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43115+
43116+#ifdef CONFIG_PAX_ETEXECRELOCS
43117+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43118+#else
43119+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43120+#endif
43121+
43122+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43123+ !elf_check_arch(&elf_h) ||
43124+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43125+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43126+ return;
43127+
43128+ for (i = 0UL; i < elf_h.e_phnum; i++) {
43129+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43130+ return;
43131+ switch (elf_p.p_type) {
43132+ case PT_DYNAMIC:
43133+ if (!is_textrel_rw && !is_textrel_rx)
43134+ continue;
43135+ i = 0UL;
43136+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43137+ elf_dyn dyn;
43138+
43139+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43140+ return;
43141+ if (dyn.d_tag == DT_NULL)
43142+ return;
43143+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43144+ gr_log_textrel(vma);
43145+ if (is_textrel_rw)
43146+ vma->vm_flags |= VM_MAYWRITE;
43147+ else
43148+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43149+ vma->vm_flags &= ~VM_MAYWRITE;
43150+ return;
43151+ }
43152+ i++;
43153+ }
43154+ return;
43155+
43156+ case PT_GNU_RELRO:
43157+ if (!is_relro)
43158+ continue;
43159+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43160+ vma->vm_flags &= ~VM_MAYWRITE;
43161+ return;
43162+ }
43163+ }
43164+}
43165+#endif
43166+
43167 static int __init init_elf_binfmt(void)
43168 {
43169 register_binfmt(&elf_format);
43170diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43171index 178cb70..8972997 100644
43172--- a/fs/binfmt_flat.c
43173+++ b/fs/binfmt_flat.c
43174@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43175 realdatastart = (unsigned long) -ENOMEM;
43176 printk("Unable to allocate RAM for process data, errno %d\n",
43177 (int)-realdatastart);
43178+ down_write(&current->mm->mmap_sem);
43179 vm_munmap(textpos, text_len);
43180+ up_write(&current->mm->mmap_sem);
43181 ret = realdatastart;
43182 goto err;
43183 }
43184@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43185 }
43186 if (IS_ERR_VALUE(result)) {
43187 printk("Unable to read data+bss, errno %d\n", (int)-result);
43188+ down_write(&current->mm->mmap_sem);
43189 vm_munmap(textpos, text_len);
43190 vm_munmap(realdatastart, len);
43191+ up_write(&current->mm->mmap_sem);
43192 ret = result;
43193 goto err;
43194 }
43195@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43196 }
43197 if (IS_ERR_VALUE(result)) {
43198 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43199+ down_write(&current->mm->mmap_sem);
43200 vm_munmap(textpos, text_len + data_len + extra +
43201 MAX_SHARED_LIBS * sizeof(unsigned long));
43202+ up_write(&current->mm->mmap_sem);
43203 ret = result;
43204 goto err;
43205 }
43206diff --git a/fs/bio.c b/fs/bio.c
43207index 73922ab..16642dd 100644
43208--- a/fs/bio.c
43209+++ b/fs/bio.c
43210@@ -841,7 +841,7 @@ struct bio *bio_copy_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@@ -975,7 +975,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43220 /*
43221 * Overflow, abort
43222 */
43223- if (end < start)
43224+ if (end < start || end - start > INT_MAX - nr_pages)
43225 return ERR_PTR(-EINVAL);
43226
43227 nr_pages += end - start;
43228@@ -1237,7 +1237,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43229 const int read = bio_data_dir(bio) == READ;
43230 struct bio_map_data *bmd = bio->bi_private;
43231 int i;
43232- char *p = bmd->sgvecs[0].iov_base;
43233+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43234
43235 __bio_for_each_segment(bvec, bio, i, 0) {
43236 char *addr = page_address(bvec->bv_page);
43237diff --git a/fs/block_dev.c b/fs/block_dev.c
43238index c2bbe1f..9dfbc23 100644
43239--- a/fs/block_dev.c
43240+++ b/fs/block_dev.c
43241@@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43242 else if (bdev->bd_contains == bdev)
43243 return true; /* is a whole device which isn't held */
43244
43245- else if (whole->bd_holder == bd_may_claim)
43246+ else if (whole->bd_holder == (void *)bd_may_claim)
43247 return true; /* is a partition of a device that is being partitioned */
43248 else if (whole->bd_holder != NULL)
43249 return false; /* is a partition of a held device */
43250diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43251index da6e936..1598dd0 100644
43252--- a/fs/btrfs/check-integrity.c
43253+++ b/fs/btrfs/check-integrity.c
43254@@ -155,7 +155,7 @@ struct btrfsic_block {
43255 union {
43256 bio_end_io_t *bio;
43257 bh_end_io_t *bh;
43258- } orig_bio_bh_end_io;
43259+ } __no_const orig_bio_bh_end_io;
43260 int submit_bio_bh_rw;
43261 u64 flush_gen; /* only valid if !never_written */
43262 };
43263diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43264index 8206b39..06d5654 100644
43265--- a/fs/btrfs/ctree.c
43266+++ b/fs/btrfs/ctree.c
43267@@ -973,9 +973,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43268 free_extent_buffer(buf);
43269 add_root_to_dirty_list(root);
43270 } else {
43271- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43272- parent_start = parent->start;
43273- else
43274+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43275+ if (parent)
43276+ parent_start = parent->start;
43277+ else
43278+ parent_start = 0;
43279+ } else
43280 parent_start = 0;
43281
43282 WARN_ON(trans->transid != btrfs_header_generation(parent));
43283diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43284index a7d1921..a32dba2 100644
43285--- a/fs/btrfs/inode.c
43286+++ b/fs/btrfs/inode.c
43287@@ -7111,7 +7111,7 @@ fail:
43288 return -ENOMEM;
43289 }
43290
43291-static int btrfs_getattr(struct vfsmount *mnt,
43292+int btrfs_getattr(struct vfsmount *mnt,
43293 struct dentry *dentry, struct kstat *stat)
43294 {
43295 struct inode *inode = dentry->d_inode;
43296@@ -7125,6 +7125,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43297 return 0;
43298 }
43299
43300+EXPORT_SYMBOL(btrfs_getattr);
43301+
43302+dev_t get_btrfs_dev_from_inode(struct inode *inode)
43303+{
43304+ return BTRFS_I(inode)->root->anon_dev;
43305+}
43306+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43307+
43308 /*
43309 * If a file is moved, it will inherit the cow and compression flags of the new
43310 * directory.
43311diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43312index 0e92e57..8b560de 100644
43313--- a/fs/btrfs/ioctl.c
43314+++ b/fs/btrfs/ioctl.c
43315@@ -2902,9 +2902,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43316 for (i = 0; i < num_types; i++) {
43317 struct btrfs_space_info *tmp;
43318
43319+ /* Don't copy in more than we allocated */
43320 if (!slot_count)
43321 break;
43322
43323+ slot_count--;
43324+
43325 info = NULL;
43326 rcu_read_lock();
43327 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43328@@ -2926,10 +2929,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43329 memcpy(dest, &space, sizeof(space));
43330 dest++;
43331 space_args.total_spaces++;
43332- slot_count--;
43333 }
43334- if (!slot_count)
43335- break;
43336 }
43337 up_read(&info->groups_sem);
43338 }
43339diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43340index 646ee21..f020f87 100644
43341--- a/fs/btrfs/relocation.c
43342+++ b/fs/btrfs/relocation.c
43343@@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43344 }
43345 spin_unlock(&rc->reloc_root_tree.lock);
43346
43347- BUG_ON((struct btrfs_root *)node->data != root);
43348+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
43349
43350 if (!del) {
43351 spin_lock(&rc->reloc_root_tree.lock);
43352diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43353index 622f469..e8d2d55 100644
43354--- a/fs/cachefiles/bind.c
43355+++ b/fs/cachefiles/bind.c
43356@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43357 args);
43358
43359 /* start by checking things over */
43360- ASSERT(cache->fstop_percent >= 0 &&
43361- cache->fstop_percent < cache->fcull_percent &&
43362+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
43363 cache->fcull_percent < cache->frun_percent &&
43364 cache->frun_percent < 100);
43365
43366- ASSERT(cache->bstop_percent >= 0 &&
43367- cache->bstop_percent < cache->bcull_percent &&
43368+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
43369 cache->bcull_percent < cache->brun_percent &&
43370 cache->brun_percent < 100);
43371
43372diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43373index 0a1467b..6a53245 100644
43374--- a/fs/cachefiles/daemon.c
43375+++ b/fs/cachefiles/daemon.c
43376@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43377 if (n > buflen)
43378 return -EMSGSIZE;
43379
43380- if (copy_to_user(_buffer, buffer, n) != 0)
43381+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43382 return -EFAULT;
43383
43384 return n;
43385@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43386 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43387 return -EIO;
43388
43389- if (datalen < 0 || datalen > PAGE_SIZE - 1)
43390+ if (datalen > PAGE_SIZE - 1)
43391 return -EOPNOTSUPP;
43392
43393 /* drag the command string into the kernel so we can parse it */
43394@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43395 if (args[0] != '%' || args[1] != '\0')
43396 return -EINVAL;
43397
43398- if (fstop < 0 || fstop >= cache->fcull_percent)
43399+ if (fstop >= cache->fcull_percent)
43400 return cachefiles_daemon_range_error(cache, args);
43401
43402 cache->fstop_percent = fstop;
43403@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43404 if (args[0] != '%' || args[1] != '\0')
43405 return -EINVAL;
43406
43407- if (bstop < 0 || bstop >= cache->bcull_percent)
43408+ if (bstop >= cache->bcull_percent)
43409 return cachefiles_daemon_range_error(cache, args);
43410
43411 cache->bstop_percent = bstop;
43412diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43413index bd6bc1b..b627b53 100644
43414--- a/fs/cachefiles/internal.h
43415+++ b/fs/cachefiles/internal.h
43416@@ -57,7 +57,7 @@ struct cachefiles_cache {
43417 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43418 struct rb_root active_nodes; /* active nodes (can't be culled) */
43419 rwlock_t active_lock; /* lock for active_nodes */
43420- atomic_t gravecounter; /* graveyard uniquifier */
43421+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43422 unsigned frun_percent; /* when to stop culling (% files) */
43423 unsigned fcull_percent; /* when to start culling (% files) */
43424 unsigned fstop_percent; /* when to stop allocating (% files) */
43425@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43426 * proc.c
43427 */
43428 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43429-extern atomic_t cachefiles_lookup_histogram[HZ];
43430-extern atomic_t cachefiles_mkdir_histogram[HZ];
43431-extern atomic_t cachefiles_create_histogram[HZ];
43432+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43433+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43434+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43435
43436 extern int __init cachefiles_proc_init(void);
43437 extern void cachefiles_proc_cleanup(void);
43438 static inline
43439-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43440+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43441 {
43442 unsigned long jif = jiffies - start_jif;
43443 if (jif >= HZ)
43444 jif = HZ - 1;
43445- atomic_inc(&histogram[jif]);
43446+ atomic_inc_unchecked(&histogram[jif]);
43447 }
43448
43449 #else
43450diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43451index 7f0771d..87d4f36 100644
43452--- a/fs/cachefiles/namei.c
43453+++ b/fs/cachefiles/namei.c
43454@@ -318,7 +318,7 @@ try_again:
43455 /* first step is to make up a grave dentry in the graveyard */
43456 sprintf(nbuffer, "%08x%08x",
43457 (uint32_t) get_seconds(),
43458- (uint32_t) atomic_inc_return(&cache->gravecounter));
43459+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43460
43461 /* do the multiway lock magic */
43462 trap = lock_rename(cache->graveyard, dir);
43463diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43464index eccd339..4c1d995 100644
43465--- a/fs/cachefiles/proc.c
43466+++ b/fs/cachefiles/proc.c
43467@@ -14,9 +14,9 @@
43468 #include <linux/seq_file.h>
43469 #include "internal.h"
43470
43471-atomic_t cachefiles_lookup_histogram[HZ];
43472-atomic_t cachefiles_mkdir_histogram[HZ];
43473-atomic_t cachefiles_create_histogram[HZ];
43474+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43475+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43476+atomic_unchecked_t cachefiles_create_histogram[HZ];
43477
43478 /*
43479 * display the latency histogram
43480@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43481 return 0;
43482 default:
43483 index = (unsigned long) v - 3;
43484- x = atomic_read(&cachefiles_lookup_histogram[index]);
43485- y = atomic_read(&cachefiles_mkdir_histogram[index]);
43486- z = atomic_read(&cachefiles_create_histogram[index]);
43487+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43488+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43489+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43490 if (x == 0 && y == 0 && z == 0)
43491 return 0;
43492
43493diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43494index 0e3c092..818480e 100644
43495--- a/fs/cachefiles/rdwr.c
43496+++ b/fs/cachefiles/rdwr.c
43497@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43498 old_fs = get_fs();
43499 set_fs(KERNEL_DS);
43500 ret = file->f_op->write(
43501- file, (const void __user *) data, len, &pos);
43502+ file, (const void __force_user *) data, len, &pos);
43503 set_fs(old_fs);
43504 kunmap(page);
43505 if (ret != len)
43506diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43507index 3e8094b..cb3ff3d 100644
43508--- a/fs/ceph/dir.c
43509+++ b/fs/ceph/dir.c
43510@@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43511 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43512 struct ceph_mds_client *mdsc = fsc->mdsc;
43513 unsigned frag = fpos_frag(filp->f_pos);
43514- int off = fpos_off(filp->f_pos);
43515+ unsigned int off = fpos_off(filp->f_pos);
43516 int err;
43517 u32 ftype;
43518 struct ceph_mds_reply_info_parsed *rinfo;
43519@@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43520 if (nd &&
43521 (nd->flags & LOOKUP_OPEN) &&
43522 !(nd->intent.open.flags & O_CREAT)) {
43523- int mode = nd->intent.open.create_mode & ~current->fs->umask;
43524+ int mode = nd->intent.open.create_mode & ~current_umask();
43525 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43526 }
43527
43528diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43529index e814052..28dcdf7 100644
43530--- a/fs/cifs/cifs_debug.c
43531+++ b/fs/cifs/cifs_debug.c
43532@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43533
43534 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43535 #ifdef CONFIG_CIFS_STATS2
43536- atomic_set(&totBufAllocCount, 0);
43537- atomic_set(&totSmBufAllocCount, 0);
43538+ atomic_set_unchecked(&totBufAllocCount, 0);
43539+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43540 #endif /* CONFIG_CIFS_STATS2 */
43541 spin_lock(&cifs_tcp_ses_lock);
43542 list_for_each(tmp1, &cifs_tcp_ses_list) {
43543@@ -281,25 +281,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43544 tcon = list_entry(tmp3,
43545 struct cifs_tcon,
43546 tcon_list);
43547- atomic_set(&tcon->num_smbs_sent, 0);
43548- atomic_set(&tcon->num_writes, 0);
43549- atomic_set(&tcon->num_reads, 0);
43550- atomic_set(&tcon->num_oplock_brks, 0);
43551- atomic_set(&tcon->num_opens, 0);
43552- atomic_set(&tcon->num_posixopens, 0);
43553- atomic_set(&tcon->num_posixmkdirs, 0);
43554- atomic_set(&tcon->num_closes, 0);
43555- atomic_set(&tcon->num_deletes, 0);
43556- atomic_set(&tcon->num_mkdirs, 0);
43557- atomic_set(&tcon->num_rmdirs, 0);
43558- atomic_set(&tcon->num_renames, 0);
43559- atomic_set(&tcon->num_t2renames, 0);
43560- atomic_set(&tcon->num_ffirst, 0);
43561- atomic_set(&tcon->num_fnext, 0);
43562- atomic_set(&tcon->num_fclose, 0);
43563- atomic_set(&tcon->num_hardlinks, 0);
43564- atomic_set(&tcon->num_symlinks, 0);
43565- atomic_set(&tcon->num_locks, 0);
43566+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43567+ atomic_set_unchecked(&tcon->num_writes, 0);
43568+ atomic_set_unchecked(&tcon->num_reads, 0);
43569+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43570+ atomic_set_unchecked(&tcon->num_opens, 0);
43571+ atomic_set_unchecked(&tcon->num_posixopens, 0);
43572+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43573+ atomic_set_unchecked(&tcon->num_closes, 0);
43574+ atomic_set_unchecked(&tcon->num_deletes, 0);
43575+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
43576+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
43577+ atomic_set_unchecked(&tcon->num_renames, 0);
43578+ atomic_set_unchecked(&tcon->num_t2renames, 0);
43579+ atomic_set_unchecked(&tcon->num_ffirst, 0);
43580+ atomic_set_unchecked(&tcon->num_fnext, 0);
43581+ atomic_set_unchecked(&tcon->num_fclose, 0);
43582+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
43583+ atomic_set_unchecked(&tcon->num_symlinks, 0);
43584+ atomic_set_unchecked(&tcon->num_locks, 0);
43585 }
43586 }
43587 }
43588@@ -329,8 +329,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43589 smBufAllocCount.counter, cifs_min_small);
43590 #ifdef CONFIG_CIFS_STATS2
43591 seq_printf(m, "Total Large %d Small %d Allocations\n",
43592- atomic_read(&totBufAllocCount),
43593- atomic_read(&totSmBufAllocCount));
43594+ atomic_read_unchecked(&totBufAllocCount),
43595+ atomic_read_unchecked(&totSmBufAllocCount));
43596 #endif /* CONFIG_CIFS_STATS2 */
43597
43598 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43599@@ -359,41 +359,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43600 if (tcon->need_reconnect)
43601 seq_puts(m, "\tDISCONNECTED ");
43602 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43603- atomic_read(&tcon->num_smbs_sent),
43604- atomic_read(&tcon->num_oplock_brks));
43605+ atomic_read_unchecked(&tcon->num_smbs_sent),
43606+ atomic_read_unchecked(&tcon->num_oplock_brks));
43607 seq_printf(m, "\nReads: %d Bytes: %lld",
43608- atomic_read(&tcon->num_reads),
43609+ atomic_read_unchecked(&tcon->num_reads),
43610 (long long)(tcon->bytes_read));
43611 seq_printf(m, "\nWrites: %d Bytes: %lld",
43612- atomic_read(&tcon->num_writes),
43613+ atomic_read_unchecked(&tcon->num_writes),
43614 (long long)(tcon->bytes_written));
43615 seq_printf(m, "\nFlushes: %d",
43616- atomic_read(&tcon->num_flushes));
43617+ atomic_read_unchecked(&tcon->num_flushes));
43618 seq_printf(m, "\nLocks: %d HardLinks: %d "
43619 "Symlinks: %d",
43620- atomic_read(&tcon->num_locks),
43621- atomic_read(&tcon->num_hardlinks),
43622- atomic_read(&tcon->num_symlinks));
43623+ atomic_read_unchecked(&tcon->num_locks),
43624+ atomic_read_unchecked(&tcon->num_hardlinks),
43625+ atomic_read_unchecked(&tcon->num_symlinks));
43626 seq_printf(m, "\nOpens: %d Closes: %d "
43627 "Deletes: %d",
43628- atomic_read(&tcon->num_opens),
43629- atomic_read(&tcon->num_closes),
43630- atomic_read(&tcon->num_deletes));
43631+ atomic_read_unchecked(&tcon->num_opens),
43632+ atomic_read_unchecked(&tcon->num_closes),
43633+ atomic_read_unchecked(&tcon->num_deletes));
43634 seq_printf(m, "\nPosix Opens: %d "
43635 "Posix Mkdirs: %d",
43636- atomic_read(&tcon->num_posixopens),
43637- atomic_read(&tcon->num_posixmkdirs));
43638+ atomic_read_unchecked(&tcon->num_posixopens),
43639+ atomic_read_unchecked(&tcon->num_posixmkdirs));
43640 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43641- atomic_read(&tcon->num_mkdirs),
43642- atomic_read(&tcon->num_rmdirs));
43643+ atomic_read_unchecked(&tcon->num_mkdirs),
43644+ atomic_read_unchecked(&tcon->num_rmdirs));
43645 seq_printf(m, "\nRenames: %d T2 Renames %d",
43646- atomic_read(&tcon->num_renames),
43647- atomic_read(&tcon->num_t2renames));
43648+ atomic_read_unchecked(&tcon->num_renames),
43649+ atomic_read_unchecked(&tcon->num_t2renames));
43650 seq_printf(m, "\nFindFirst: %d FNext %d "
43651 "FClose %d",
43652- atomic_read(&tcon->num_ffirst),
43653- atomic_read(&tcon->num_fnext),
43654- atomic_read(&tcon->num_fclose));
43655+ atomic_read_unchecked(&tcon->num_ffirst),
43656+ atomic_read_unchecked(&tcon->num_fnext),
43657+ atomic_read_unchecked(&tcon->num_fclose));
43658 }
43659 }
43660 }
43661diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43662index 8b6e344..303a662 100644
43663--- a/fs/cifs/cifsfs.c
43664+++ b/fs/cifs/cifsfs.c
43665@@ -994,7 +994,7 @@ cifs_init_request_bufs(void)
43666 cifs_req_cachep = kmem_cache_create("cifs_request",
43667 CIFSMaxBufSize +
43668 MAX_CIFS_HDR_SIZE, 0,
43669- SLAB_HWCACHE_ALIGN, NULL);
43670+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43671 if (cifs_req_cachep == NULL)
43672 return -ENOMEM;
43673
43674@@ -1021,7 +1021,7 @@ cifs_init_request_bufs(void)
43675 efficient to alloc 1 per page off the slab compared to 17K (5page)
43676 alloc of large cifs buffers even when page debugging is on */
43677 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43678- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43679+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43680 NULL);
43681 if (cifs_sm_req_cachep == NULL) {
43682 mempool_destroy(cifs_req_poolp);
43683@@ -1106,8 +1106,8 @@ init_cifs(void)
43684 atomic_set(&bufAllocCount, 0);
43685 atomic_set(&smBufAllocCount, 0);
43686 #ifdef CONFIG_CIFS_STATS2
43687- atomic_set(&totBufAllocCount, 0);
43688- atomic_set(&totSmBufAllocCount, 0);
43689+ atomic_set_unchecked(&totBufAllocCount, 0);
43690+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43691 #endif /* CONFIG_CIFS_STATS2 */
43692
43693 atomic_set(&midCount, 0);
43694diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43695index 6df0cbe..eb7ecbb 100644
43696--- a/fs/cifs/cifsglob.h
43697+++ b/fs/cifs/cifsglob.h
43698@@ -491,28 +491,28 @@ struct cifs_tcon {
43699 __u16 Flags; /* optional support bits */
43700 enum statusEnum tidStatus;
43701 #ifdef CONFIG_CIFS_STATS
43702- atomic_t num_smbs_sent;
43703- atomic_t num_writes;
43704- atomic_t num_reads;
43705- atomic_t num_flushes;
43706- atomic_t num_oplock_brks;
43707- atomic_t num_opens;
43708- atomic_t num_closes;
43709- atomic_t num_deletes;
43710- atomic_t num_mkdirs;
43711- atomic_t num_posixopens;
43712- atomic_t num_posixmkdirs;
43713- atomic_t num_rmdirs;
43714- atomic_t num_renames;
43715- atomic_t num_t2renames;
43716- atomic_t num_ffirst;
43717- atomic_t num_fnext;
43718- atomic_t num_fclose;
43719- atomic_t num_hardlinks;
43720- atomic_t num_symlinks;
43721- atomic_t num_locks;
43722- atomic_t num_acl_get;
43723- atomic_t num_acl_set;
43724+ atomic_unchecked_t num_smbs_sent;
43725+ atomic_unchecked_t num_writes;
43726+ atomic_unchecked_t num_reads;
43727+ atomic_unchecked_t num_flushes;
43728+ atomic_unchecked_t num_oplock_brks;
43729+ atomic_unchecked_t num_opens;
43730+ atomic_unchecked_t num_closes;
43731+ atomic_unchecked_t num_deletes;
43732+ atomic_unchecked_t num_mkdirs;
43733+ atomic_unchecked_t num_posixopens;
43734+ atomic_unchecked_t num_posixmkdirs;
43735+ atomic_unchecked_t num_rmdirs;
43736+ atomic_unchecked_t num_renames;
43737+ atomic_unchecked_t num_t2renames;
43738+ atomic_unchecked_t num_ffirst;
43739+ atomic_unchecked_t num_fnext;
43740+ atomic_unchecked_t num_fclose;
43741+ atomic_unchecked_t num_hardlinks;
43742+ atomic_unchecked_t num_symlinks;
43743+ atomic_unchecked_t num_locks;
43744+ atomic_unchecked_t num_acl_get;
43745+ atomic_unchecked_t num_acl_set;
43746 #ifdef CONFIG_CIFS_STATS2
43747 unsigned long long time_writes;
43748 unsigned long long time_reads;
43749@@ -735,7 +735,7 @@ convert_delimiter(char *path, char delim)
43750 }
43751
43752 #ifdef CONFIG_CIFS_STATS
43753-#define cifs_stats_inc atomic_inc
43754+#define cifs_stats_inc atomic_inc_unchecked
43755
43756 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43757 unsigned int bytes)
43758@@ -1093,8 +1093,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43759 /* Various Debug counters */
43760 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43761 #ifdef CONFIG_CIFS_STATS2
43762-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43763-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43764+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43765+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43766 #endif
43767 GLOBAL_EXTERN atomic_t smBufAllocCount;
43768 GLOBAL_EXTERN atomic_t midCount;
43769diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43770index 6b0e064..94e6c3c 100644
43771--- a/fs/cifs/link.c
43772+++ b/fs/cifs/link.c
43773@@ -600,7 +600,7 @@ symlink_exit:
43774
43775 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43776 {
43777- char *p = nd_get_link(nd);
43778+ const char *p = nd_get_link(nd);
43779 if (!IS_ERR(p))
43780 kfree(p);
43781 }
43782diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43783index 557506a..2fd3816 100644
43784--- a/fs/cifs/misc.c
43785+++ b/fs/cifs/misc.c
43786@@ -156,7 +156,7 @@ cifs_buf_get(void)
43787 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43788 atomic_inc(&bufAllocCount);
43789 #ifdef CONFIG_CIFS_STATS2
43790- atomic_inc(&totBufAllocCount);
43791+ atomic_inc_unchecked(&totBufAllocCount);
43792 #endif /* CONFIG_CIFS_STATS2 */
43793 }
43794
43795@@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43796 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43797 atomic_inc(&smBufAllocCount);
43798 #ifdef CONFIG_CIFS_STATS2
43799- atomic_inc(&totSmBufAllocCount);
43800+ atomic_inc_unchecked(&totSmBufAllocCount);
43801 #endif /* CONFIG_CIFS_STATS2 */
43802
43803 }
43804diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43805index 6901578..d402eb5 100644
43806--- a/fs/coda/cache.c
43807+++ b/fs/coda/cache.c
43808@@ -24,7 +24,7 @@
43809 #include "coda_linux.h"
43810 #include "coda_cache.h"
43811
43812-static atomic_t permission_epoch = ATOMIC_INIT(0);
43813+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43814
43815 /* replace or extend an acl cache hit */
43816 void coda_cache_enter(struct inode *inode, int mask)
43817@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43818 struct coda_inode_info *cii = ITOC(inode);
43819
43820 spin_lock(&cii->c_lock);
43821- cii->c_cached_epoch = atomic_read(&permission_epoch);
43822+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43823 if (cii->c_uid != current_fsuid()) {
43824 cii->c_uid = current_fsuid();
43825 cii->c_cached_perm = mask;
43826@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43827 {
43828 struct coda_inode_info *cii = ITOC(inode);
43829 spin_lock(&cii->c_lock);
43830- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43831+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43832 spin_unlock(&cii->c_lock);
43833 }
43834
43835 /* remove all acl caches */
43836 void coda_cache_clear_all(struct super_block *sb)
43837 {
43838- atomic_inc(&permission_epoch);
43839+ atomic_inc_unchecked(&permission_epoch);
43840 }
43841
43842
43843@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43844 spin_lock(&cii->c_lock);
43845 hit = (mask & cii->c_cached_perm) == mask &&
43846 cii->c_uid == current_fsuid() &&
43847- cii->c_cached_epoch == atomic_read(&permission_epoch);
43848+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43849 spin_unlock(&cii->c_lock);
43850
43851 return hit;
43852diff --git a/fs/compat.c b/fs/compat.c
43853index 6161255..512b1a1 100644
43854--- a/fs/compat.c
43855+++ b/fs/compat.c
43856@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43857
43858 set_fs(KERNEL_DS);
43859 /* The __user pointer cast is valid because of the set_fs() */
43860- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43861+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43862 set_fs(oldfs);
43863 /* truncating is ok because it's a user address */
43864 if (!ret)
43865@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43866 goto out;
43867
43868 ret = -EINVAL;
43869- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43870+ if (nr_segs > UIO_MAXIOV)
43871 goto out;
43872 if (nr_segs > fast_segs) {
43873 ret = -ENOMEM;
43874@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
43875
43876 struct compat_readdir_callback {
43877 struct compat_old_linux_dirent __user *dirent;
43878+ struct file * file;
43879 int result;
43880 };
43881
43882@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43883 buf->result = -EOVERFLOW;
43884 return -EOVERFLOW;
43885 }
43886+
43887+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43888+ return 0;
43889+
43890 buf->result++;
43891 dirent = buf->dirent;
43892 if (!access_ok(VERIFY_WRITE, dirent,
43893@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43894
43895 buf.result = 0;
43896 buf.dirent = dirent;
43897+ buf.file = file;
43898
43899 error = vfs_readdir(file, compat_fillonedir, &buf);
43900 if (buf.result)
43901@@ -899,6 +905,7 @@ struct compat_linux_dirent {
43902 struct compat_getdents_callback {
43903 struct compat_linux_dirent __user *current_dir;
43904 struct compat_linux_dirent __user *previous;
43905+ struct file * file;
43906 int count;
43907 int error;
43908 };
43909@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43910 buf->error = -EOVERFLOW;
43911 return -EOVERFLOW;
43912 }
43913+
43914+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43915+ return 0;
43916+
43917 dirent = buf->previous;
43918 if (dirent) {
43919 if (__put_user(offset, &dirent->d_off))
43920@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43921 buf.previous = NULL;
43922 buf.count = count;
43923 buf.error = 0;
43924+ buf.file = file;
43925
43926 error = vfs_readdir(file, compat_filldir, &buf);
43927 if (error >= 0)
43928@@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43929 struct compat_getdents_callback64 {
43930 struct linux_dirent64 __user *current_dir;
43931 struct linux_dirent64 __user *previous;
43932+ struct file * file;
43933 int count;
43934 int error;
43935 };
43936@@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43937 buf->error = -EINVAL; /* only used if we fail.. */
43938 if (reclen > buf->count)
43939 return -EINVAL;
43940+
43941+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43942+ return 0;
43943+
43944 dirent = buf->previous;
43945
43946 if (dirent) {
43947@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43948 buf.previous = NULL;
43949 buf.count = count;
43950 buf.error = 0;
43951+ buf.file = file;
43952
43953 error = vfs_readdir(file, compat_filldir64, &buf);
43954 if (error >= 0)
43955 error = buf.error;
43956 lastdirent = buf.previous;
43957 if (lastdirent) {
43958- typeof(lastdirent->d_off) d_off = file->f_pos;
43959+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43960 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43961 error = -EFAULT;
43962 else
43963diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43964index 112e45a..b59845b 100644
43965--- a/fs/compat_binfmt_elf.c
43966+++ b/fs/compat_binfmt_elf.c
43967@@ -30,11 +30,13 @@
43968 #undef elf_phdr
43969 #undef elf_shdr
43970 #undef elf_note
43971+#undef elf_dyn
43972 #undef elf_addr_t
43973 #define elfhdr elf32_hdr
43974 #define elf_phdr elf32_phdr
43975 #define elf_shdr elf32_shdr
43976 #define elf_note elf32_note
43977+#define elf_dyn Elf32_Dyn
43978 #define elf_addr_t Elf32_Addr
43979
43980 /*
43981diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43982index debdfe0..75d31d4 100644
43983--- a/fs/compat_ioctl.c
43984+++ b/fs/compat_ioctl.c
43985@@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43986
43987 err = get_user(palp, &up->palette);
43988 err |= get_user(length, &up->length);
43989+ if (err)
43990+ return -EFAULT;
43991
43992 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43993 err = put_user(compat_ptr(palp), &up_native->palette);
43994@@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43995 return -EFAULT;
43996 if (__get_user(udata, &ss32->iomem_base))
43997 return -EFAULT;
43998- ss.iomem_base = compat_ptr(udata);
43999+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44000 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44001 __get_user(ss.port_high, &ss32->port_high))
44002 return -EFAULT;
44003@@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44004 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44005 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44006 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44007- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44008+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44009 return -EFAULT;
44010
44011 return ioctl_preallocate(file, p);
44012@@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44013 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44014 {
44015 unsigned int a, b;
44016- a = *(unsigned int *)p;
44017- b = *(unsigned int *)q;
44018+ a = *(const unsigned int *)p;
44019+ b = *(const unsigned int *)q;
44020 if (a > b)
44021 return 1;
44022 if (a < b)
44023diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44024index 7e6c52d..94bc756 100644
44025--- a/fs/configfs/dir.c
44026+++ b/fs/configfs/dir.c
44027@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44028 }
44029 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44030 struct configfs_dirent *next;
44031- const char * name;
44032+ const unsigned char * name;
44033+ char d_name[sizeof(next->s_dentry->d_iname)];
44034 int len;
44035 struct inode *inode = NULL;
44036
44037@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44038 continue;
44039
44040 name = configfs_get_name(next);
44041- len = strlen(name);
44042+ if (next->s_dentry && name == next->s_dentry->d_iname) {
44043+ len = next->s_dentry->d_name.len;
44044+ memcpy(d_name, name, len);
44045+ name = d_name;
44046+ } else
44047+ len = strlen(name);
44048
44049 /*
44050 * We'll have a dentry and an inode for
44051diff --git a/fs/dcache.c b/fs/dcache.c
44052index 4046904..5e31505 100644
44053--- a/fs/dcache.c
44054+++ b/fs/dcache.c
44055@@ -3154,7 +3154,7 @@ void __init vfs_caches_init(unsigned long mempages)
44056 mempages -= reserve;
44057
44058 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44059- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44060+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44061
44062 dcache_init();
44063 inode_init();
44064diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44065index b80bc84..0d46d1a 100644
44066--- a/fs/debugfs/inode.c
44067+++ b/fs/debugfs/inode.c
44068@@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44069 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44070 {
44071 return debugfs_create_file(name,
44072+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44073+ S_IFDIR | S_IRWXU,
44074+#else
44075 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44076+#endif
44077 parent, NULL, NULL);
44078 }
44079 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44080diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44081index a07441a..046fc0d 100644
44082--- a/fs/ecryptfs/inode.c
44083+++ b/fs/ecryptfs/inode.c
44084@@ -671,7 +671,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44085 old_fs = get_fs();
44086 set_fs(get_ds());
44087 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44088- (char __user *)lower_buf,
44089+ (char __force_user *)lower_buf,
44090 PATH_MAX);
44091 set_fs(old_fs);
44092 if (rc < 0)
44093@@ -703,7 +703,7 @@ out:
44094 static void
44095 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44096 {
44097- char *buf = nd_get_link(nd);
44098+ const char *buf = nd_get_link(nd);
44099 if (!IS_ERR(buf)) {
44100 /* Free the char* */
44101 kfree(buf);
44102diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44103index c0038f6..47ab347 100644
44104--- a/fs/ecryptfs/miscdev.c
44105+++ b/fs/ecryptfs/miscdev.c
44106@@ -355,7 +355,7 @@ check_list:
44107 goto out_unlock_msg_ctx;
44108 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44109 if (msg_ctx->msg) {
44110- if (copy_to_user(&buf[i], packet_length, packet_length_size))
44111+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44112 goto out_unlock_msg_ctx;
44113 i += packet_length_size;
44114 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44115diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44116index b2a34a1..162fa69 100644
44117--- a/fs/ecryptfs/read_write.c
44118+++ b/fs/ecryptfs/read_write.c
44119@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44120 return -EIO;
44121 fs_save = get_fs();
44122 set_fs(get_ds());
44123- rc = vfs_write(lower_file, data, size, &offset);
44124+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44125 set_fs(fs_save);
44126 mark_inode_dirty_sync(ecryptfs_inode);
44127 return rc;
44128@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44129 return -EIO;
44130 fs_save = get_fs();
44131 set_fs(get_ds());
44132- rc = vfs_read(lower_file, data, size, &offset);
44133+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44134 set_fs(fs_save);
44135 return rc;
44136 }
44137diff --git a/fs/exec.c b/fs/exec.c
44138index da27b91..5a05624 100644
44139--- a/fs/exec.c
44140+++ b/fs/exec.c
44141@@ -55,6 +55,15 @@
44142 #include <linux/pipe_fs_i.h>
44143 #include <linux/oom.h>
44144 #include <linux/compat.h>
44145+#include <linux/random.h>
44146+#include <linux/seq_file.h>
44147+
44148+#ifdef CONFIG_PAX_REFCOUNT
44149+#include <linux/kallsyms.h>
44150+#include <linux/kdebug.h>
44151+#endif
44152+
44153+#include <trace/events/fs.h>
44154
44155 #include <asm/uaccess.h>
44156 #include <asm/mmu_context.h>
44157@@ -66,6 +75,18 @@
44158
44159 #include <trace/events/sched.h>
44160
44161+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44162+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44163+{
44164+ 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");
44165+}
44166+#endif
44167+
44168+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44169+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44170+EXPORT_SYMBOL(pax_set_initial_flags_func);
44171+#endif
44172+
44173 int core_uses_pid;
44174 char core_pattern[CORENAME_MAX_SIZE] = "core";
44175 unsigned int core_pipe_limit;
44176@@ -75,7 +96,7 @@ struct core_name {
44177 char *corename;
44178 int used, size;
44179 };
44180-static atomic_t call_count = ATOMIC_INIT(1);
44181+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44182
44183 /* The maximal length of core_pattern is also specified in sysctl.c */
44184
44185@@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44186 int write)
44187 {
44188 struct page *page;
44189- int ret;
44190
44191-#ifdef CONFIG_STACK_GROWSUP
44192- if (write) {
44193- ret = expand_downwards(bprm->vma, pos);
44194- if (ret < 0)
44195- return NULL;
44196- }
44197-#endif
44198- ret = get_user_pages(current, bprm->mm, pos,
44199- 1, write, 1, &page, NULL);
44200- if (ret <= 0)
44201+ if (0 > expand_downwards(bprm->vma, pos))
44202+ return NULL;
44203+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44204 return NULL;
44205
44206 if (write) {
44207@@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44208 if (size <= ARG_MAX)
44209 return page;
44210
44211+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44212+ // only allow 512KB for argv+env on suid/sgid binaries
44213+ // to prevent easy ASLR exhaustion
44214+ if (((bprm->cred->euid != current_euid()) ||
44215+ (bprm->cred->egid != current_egid())) &&
44216+ (size > (512 * 1024))) {
44217+ put_page(page);
44218+ return NULL;
44219+ }
44220+#endif
44221+
44222 /*
44223 * Limit to 1/4-th the stack size for the argv+env strings.
44224 * This ensures that:
44225@@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44226 vma->vm_end = STACK_TOP_MAX;
44227 vma->vm_start = vma->vm_end - PAGE_SIZE;
44228 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44229+
44230+#ifdef CONFIG_PAX_SEGMEXEC
44231+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44232+#endif
44233+
44234 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44235 INIT_LIST_HEAD(&vma->anon_vma_chain);
44236
44237@@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44238 mm->stack_vm = mm->total_vm = 1;
44239 up_write(&mm->mmap_sem);
44240 bprm->p = vma->vm_end - sizeof(void *);
44241+
44242+#ifdef CONFIG_PAX_RANDUSTACK
44243+ if (randomize_va_space)
44244+ bprm->p ^= random32() & ~PAGE_MASK;
44245+#endif
44246+
44247 return 0;
44248 err:
44249 up_write(&mm->mmap_sem);
44250@@ -395,19 +430,7 @@ err:
44251 return err;
44252 }
44253
44254-struct user_arg_ptr {
44255-#ifdef CONFIG_COMPAT
44256- bool is_compat;
44257-#endif
44258- union {
44259- const char __user *const __user *native;
44260-#ifdef CONFIG_COMPAT
44261- compat_uptr_t __user *compat;
44262-#endif
44263- } ptr;
44264-};
44265-
44266-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44267+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44268 {
44269 const char __user *native;
44270
44271@@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44272 compat_uptr_t compat;
44273
44274 if (get_user(compat, argv.ptr.compat + nr))
44275- return ERR_PTR(-EFAULT);
44276+ return (const char __force_user *)ERR_PTR(-EFAULT);
44277
44278 return compat_ptr(compat);
44279 }
44280 #endif
44281
44282 if (get_user(native, argv.ptr.native + nr))
44283- return ERR_PTR(-EFAULT);
44284+ return (const char __force_user *)ERR_PTR(-EFAULT);
44285
44286 return native;
44287 }
44288@@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44289 if (!p)
44290 break;
44291
44292- if (IS_ERR(p))
44293+ if (IS_ERR((const char __force_kernel *)p))
44294 return -EFAULT;
44295
44296 if (i++ >= max)
44297@@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44298
44299 ret = -EFAULT;
44300 str = get_user_arg_ptr(argv, argc);
44301- if (IS_ERR(str))
44302+ if (IS_ERR((const char __force_kernel *)str))
44303 goto out;
44304
44305 len = strnlen_user(str, MAX_ARG_STRLEN);
44306@@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44307 int r;
44308 mm_segment_t oldfs = get_fs();
44309 struct user_arg_ptr argv = {
44310- .ptr.native = (const char __user *const __user *)__argv,
44311+ .ptr.native = (const char __force_user *const __force_user *)__argv,
44312 };
44313
44314 set_fs(KERNEL_DS);
44315@@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44316 unsigned long new_end = old_end - shift;
44317 struct mmu_gather tlb;
44318
44319- BUG_ON(new_start > new_end);
44320+ if (new_start >= new_end || new_start < mmap_min_addr)
44321+ return -ENOMEM;
44322
44323 /*
44324 * ensure there are no vmas between where we want to go
44325@@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44326 if (vma != find_vma(mm, new_start))
44327 return -EFAULT;
44328
44329+#ifdef CONFIG_PAX_SEGMEXEC
44330+ BUG_ON(pax_find_mirror_vma(vma));
44331+#endif
44332+
44333 /*
44334 * cover the whole range: [new_start, old_end)
44335 */
44336@@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44337 stack_top = arch_align_stack(stack_top);
44338 stack_top = PAGE_ALIGN(stack_top);
44339
44340- if (unlikely(stack_top < mmap_min_addr) ||
44341- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44342- return -ENOMEM;
44343-
44344 stack_shift = vma->vm_end - stack_top;
44345
44346 bprm->p -= stack_shift;
44347@@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44348 bprm->exec -= stack_shift;
44349
44350 down_write(&mm->mmap_sem);
44351+
44352+ /* Move stack pages down in memory. */
44353+ if (stack_shift) {
44354+ ret = shift_arg_pages(vma, stack_shift);
44355+ if (ret)
44356+ goto out_unlock;
44357+ }
44358+
44359 vm_flags = VM_STACK_FLAGS;
44360
44361+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44362+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44363+ vm_flags &= ~VM_EXEC;
44364+
44365+#ifdef CONFIG_PAX_MPROTECT
44366+ if (mm->pax_flags & MF_PAX_MPROTECT)
44367+ vm_flags &= ~VM_MAYEXEC;
44368+#endif
44369+
44370+ }
44371+#endif
44372+
44373 /*
44374 * Adjust stack execute permissions; explicitly enable for
44375 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44376@@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44377 goto out_unlock;
44378 BUG_ON(prev != vma);
44379
44380- /* Move stack pages down in memory. */
44381- if (stack_shift) {
44382- ret = shift_arg_pages(vma, stack_shift);
44383- if (ret)
44384- goto out_unlock;
44385- }
44386-
44387 /* mprotect_fixup is overkill to remove the temporary stack flags */
44388 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44389
44390@@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
44391
44392 fsnotify_open(file);
44393
44394+ trace_open_exec(name);
44395+
44396 err = deny_write_access(file);
44397 if (err)
44398 goto exit;
44399@@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
44400 old_fs = get_fs();
44401 set_fs(get_ds());
44402 /* The cast to a user pointer is valid due to the set_fs() */
44403- result = vfs_read(file, (void __user *)addr, count, &pos);
44404+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
44405 set_fs(old_fs);
44406 return result;
44407 }
44408@@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44409 }
44410 rcu_read_unlock();
44411
44412- if (p->fs->users > n_fs) {
44413+ if (atomic_read(&p->fs->users) > n_fs) {
44414 bprm->unsafe |= LSM_UNSAFE_SHARE;
44415 } else {
44416 res = -EAGAIN;
44417@@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44418
44419 EXPORT_SYMBOL(search_binary_handler);
44420
44421+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44422+static DEFINE_PER_CPU(u64, exec_counter);
44423+static int __init init_exec_counters(void)
44424+{
44425+ unsigned int cpu;
44426+
44427+ for_each_possible_cpu(cpu) {
44428+ per_cpu(exec_counter, cpu) = (u64)cpu;
44429+ }
44430+
44431+ return 0;
44432+}
44433+early_initcall(init_exec_counters);
44434+static inline void increment_exec_counter(void)
44435+{
44436+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
44437+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44438+}
44439+#else
44440+static inline void increment_exec_counter(void) {}
44441+#endif
44442+
44443 /*
44444 * sys_execve() executes a new program.
44445 */
44446@@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
44447 struct user_arg_ptr envp,
44448 struct pt_regs *regs)
44449 {
44450+#ifdef CONFIG_GRKERNSEC
44451+ struct file *old_exec_file;
44452+ struct acl_subject_label *old_acl;
44453+ struct rlimit old_rlim[RLIM_NLIMITS];
44454+#endif
44455 struct linux_binprm *bprm;
44456 struct file *file;
44457 struct files_struct *displaced;
44458@@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
44459 int retval;
44460 const struct cred *cred = current_cred();
44461
44462+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44463+
44464 /*
44465 * We move the actual failure in case of RLIMIT_NPROC excess from
44466 * set*uid() to execve() because too many poorly written programs
44467@@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
44468 if (IS_ERR(file))
44469 goto out_unmark;
44470
44471+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
44472+ retval = -EPERM;
44473+ goto out_file;
44474+ }
44475+
44476 sched_exec();
44477
44478 bprm->file = file;
44479 bprm->filename = filename;
44480 bprm->interp = filename;
44481
44482+ if (gr_process_user_ban()) {
44483+ retval = -EPERM;
44484+ goto out_file;
44485+ }
44486+
44487+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44488+ retval = -EACCES;
44489+ goto out_file;
44490+ }
44491+
44492 retval = bprm_mm_init(bprm);
44493 if (retval)
44494 goto out_file;
44495@@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
44496 if (retval < 0)
44497 goto out;
44498
44499+#ifdef CONFIG_GRKERNSEC
44500+ old_acl = current->acl;
44501+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44502+ old_exec_file = current->exec_file;
44503+ get_file(file);
44504+ current->exec_file = file;
44505+#endif
44506+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44507+ /* limit suid stack to 8MB
44508+ we saved the old limits above and will restore them if this exec fails
44509+ */
44510+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44511+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44512+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44513+#endif
44514+
44515+ if (!gr_tpe_allow(file)) {
44516+ retval = -EACCES;
44517+ goto out_fail;
44518+ }
44519+
44520+ if (gr_check_crash_exec(file)) {
44521+ retval = -EACCES;
44522+ goto out_fail;
44523+ }
44524+
44525+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44526+ bprm->unsafe);
44527+ if (retval < 0)
44528+ goto out_fail;
44529+
44530 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44531 if (retval < 0)
44532- goto out;
44533+ goto out_fail;
44534
44535 bprm->exec = bprm->p;
44536 retval = copy_strings(bprm->envc, envp, bprm);
44537 if (retval < 0)
44538- goto out;
44539+ goto out_fail;
44540
44541 retval = copy_strings(bprm->argc, argv, bprm);
44542 if (retval < 0)
44543- goto out;
44544+ goto out_fail;
44545+
44546+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44547+
44548+ gr_handle_exec_args(bprm, argv);
44549
44550 retval = search_binary_handler(bprm,regs);
44551 if (retval < 0)
44552- goto out;
44553+ goto out_fail;
44554+#ifdef CONFIG_GRKERNSEC
44555+ if (old_exec_file)
44556+ fput(old_exec_file);
44557+#endif
44558
44559 /* execve succeeded */
44560+
44561+ increment_exec_counter();
44562 current->fs->in_exec = 0;
44563 current->in_execve = 0;
44564 acct_update_integrals(current);
44565@@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
44566 put_files_struct(displaced);
44567 return retval;
44568
44569+out_fail:
44570+#ifdef CONFIG_GRKERNSEC
44571+ current->acl = old_acl;
44572+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44573+ fput(current->exec_file);
44574+ current->exec_file = old_exec_file;
44575+#endif
44576+
44577 out:
44578 if (bprm->mm) {
44579 acct_arg_size(bprm, 0);
44580@@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
44581 {
44582 char *old_corename = cn->corename;
44583
44584- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44585+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44586 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44587
44588 if (!cn->corename) {
44589@@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
44590 int pid_in_pattern = 0;
44591 int err = 0;
44592
44593- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44594+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44595 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44596 cn->used = 0;
44597
44598@@ -1830,6 +1962,250 @@ out:
44599 return ispipe;
44600 }
44601
44602+int pax_check_flags(unsigned long *flags)
44603+{
44604+ int retval = 0;
44605+
44606+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44607+ if (*flags & MF_PAX_SEGMEXEC)
44608+ {
44609+ *flags &= ~MF_PAX_SEGMEXEC;
44610+ retval = -EINVAL;
44611+ }
44612+#endif
44613+
44614+ if ((*flags & MF_PAX_PAGEEXEC)
44615+
44616+#ifdef CONFIG_PAX_PAGEEXEC
44617+ && (*flags & MF_PAX_SEGMEXEC)
44618+#endif
44619+
44620+ )
44621+ {
44622+ *flags &= ~MF_PAX_PAGEEXEC;
44623+ retval = -EINVAL;
44624+ }
44625+
44626+ if ((*flags & MF_PAX_MPROTECT)
44627+
44628+#ifdef CONFIG_PAX_MPROTECT
44629+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44630+#endif
44631+
44632+ )
44633+ {
44634+ *flags &= ~MF_PAX_MPROTECT;
44635+ retval = -EINVAL;
44636+ }
44637+
44638+ if ((*flags & MF_PAX_EMUTRAMP)
44639+
44640+#ifdef CONFIG_PAX_EMUTRAMP
44641+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44642+#endif
44643+
44644+ )
44645+ {
44646+ *flags &= ~MF_PAX_EMUTRAMP;
44647+ retval = -EINVAL;
44648+ }
44649+
44650+ return retval;
44651+}
44652+
44653+EXPORT_SYMBOL(pax_check_flags);
44654+
44655+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44656+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44657+{
44658+ struct task_struct *tsk = current;
44659+ struct mm_struct *mm = current->mm;
44660+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44661+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44662+ char *path_exec = NULL;
44663+ char *path_fault = NULL;
44664+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
44665+
44666+ if (buffer_exec && buffer_fault) {
44667+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44668+
44669+ down_read(&mm->mmap_sem);
44670+ vma = mm->mmap;
44671+ while (vma && (!vma_exec || !vma_fault)) {
44672+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44673+ vma_exec = vma;
44674+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44675+ vma_fault = vma;
44676+ vma = vma->vm_next;
44677+ }
44678+ if (vma_exec) {
44679+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44680+ if (IS_ERR(path_exec))
44681+ path_exec = "<path too long>";
44682+ else {
44683+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44684+ if (path_exec) {
44685+ *path_exec = 0;
44686+ path_exec = buffer_exec;
44687+ } else
44688+ path_exec = "<path too long>";
44689+ }
44690+ }
44691+ if (vma_fault) {
44692+ start = vma_fault->vm_start;
44693+ end = vma_fault->vm_end;
44694+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44695+ if (vma_fault->vm_file) {
44696+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44697+ if (IS_ERR(path_fault))
44698+ path_fault = "<path too long>";
44699+ else {
44700+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44701+ if (path_fault) {
44702+ *path_fault = 0;
44703+ path_fault = buffer_fault;
44704+ } else
44705+ path_fault = "<path too long>";
44706+ }
44707+ } else
44708+ path_fault = "<anonymous mapping>";
44709+ }
44710+ up_read(&mm->mmap_sem);
44711+ }
44712+ if (tsk->signal->curr_ip)
44713+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44714+ else
44715+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44716+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44717+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44718+ task_uid(tsk), task_euid(tsk), pc, sp);
44719+ free_page((unsigned long)buffer_exec);
44720+ free_page((unsigned long)buffer_fault);
44721+ pax_report_insns(regs, pc, sp);
44722+ do_coredump(SIGKILL, SIGKILL, regs);
44723+}
44724+#endif
44725+
44726+#ifdef CONFIG_PAX_REFCOUNT
44727+void pax_report_refcount_overflow(struct pt_regs *regs)
44728+{
44729+ if (current->signal->curr_ip)
44730+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44731+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44732+ else
44733+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44734+ current->comm, task_pid_nr(current), current_uid(), current_euid());
44735+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44736+ show_regs(regs);
44737+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44738+}
44739+#endif
44740+
44741+#ifdef CONFIG_PAX_USERCOPY
44742+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44743+static noinline int check_stack_object(const void *obj, unsigned long len)
44744+{
44745+ const void * const stack = task_stack_page(current);
44746+ const void * const stackend = stack + THREAD_SIZE;
44747+
44748+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44749+ const void *frame = NULL;
44750+ const void *oldframe;
44751+#endif
44752+
44753+ if (obj + len < obj)
44754+ return -1;
44755+
44756+ if (obj + len <= stack || stackend <= obj)
44757+ return 0;
44758+
44759+ if (obj < stack || stackend < obj + len)
44760+ return -1;
44761+
44762+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44763+ oldframe = __builtin_frame_address(1);
44764+ if (oldframe)
44765+ frame = __builtin_frame_address(2);
44766+ /*
44767+ low ----------------------------------------------> high
44768+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
44769+ ^----------------^
44770+ allow copies only within here
44771+ */
44772+ while (stack <= frame && frame < stackend) {
44773+ /* if obj + len extends past the last frame, this
44774+ check won't pass and the next frame will be 0,
44775+ causing us to bail out and correctly report
44776+ the copy as invalid
44777+ */
44778+ if (obj + len <= frame)
44779+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44780+ oldframe = frame;
44781+ frame = *(const void * const *)frame;
44782+ }
44783+ return -1;
44784+#else
44785+ return 1;
44786+#endif
44787+}
44788+
44789+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44790+{
44791+ if (current->signal->curr_ip)
44792+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44793+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44794+ else
44795+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44796+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44797+ dump_stack();
44798+ gr_handle_kernel_exploit();
44799+ do_group_exit(SIGKILL);
44800+}
44801+#endif
44802+
44803+void check_object_size(const void *ptr, unsigned long n, bool to)
44804+{
44805+
44806+#ifdef CONFIG_PAX_USERCOPY
44807+ const char *type;
44808+
44809+ if (!n)
44810+ return;
44811+
44812+ type = check_heap_object(ptr, n, to);
44813+ if (!type) {
44814+ if (check_stack_object(ptr, n) != -1)
44815+ return;
44816+ type = "<process stack>";
44817+ }
44818+
44819+ pax_report_usercopy(ptr, n, to, type);
44820+#endif
44821+
44822+}
44823+EXPORT_SYMBOL(check_object_size);
44824+
44825+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44826+void pax_track_stack(void)
44827+{
44828+ unsigned long sp = (unsigned long)&sp;
44829+ if (sp < current_thread_info()->lowest_stack &&
44830+ sp > (unsigned long)task_stack_page(current))
44831+ current_thread_info()->lowest_stack = sp;
44832+}
44833+EXPORT_SYMBOL(pax_track_stack);
44834+#endif
44835+
44836+#ifdef CONFIG_PAX_SIZE_OVERFLOW
44837+void report_size_overflow(const char *file, unsigned int line, const char *func)
44838+{
44839+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44840+ dump_stack();
44841+ do_group_exit(SIGKILL);
44842+}
44843+EXPORT_SYMBOL(report_size_overflow);
44844+#endif
44845+
44846 static int zap_process(struct task_struct *start, int exit_code)
44847 {
44848 struct task_struct *t;
44849@@ -2002,17 +2378,17 @@ static void coredump_finish(struct mm_struct *mm)
44850 void set_dumpable(struct mm_struct *mm, int value)
44851 {
44852 switch (value) {
44853- case 0:
44854+ case SUID_DUMPABLE_DISABLED:
44855 clear_bit(MMF_DUMPABLE, &mm->flags);
44856 smp_wmb();
44857 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44858 break;
44859- case 1:
44860+ case SUID_DUMPABLE_ENABLED:
44861 set_bit(MMF_DUMPABLE, &mm->flags);
44862 smp_wmb();
44863 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44864 break;
44865- case 2:
44866+ case SUID_DUMPABLE_SAFE:
44867 set_bit(MMF_DUMP_SECURELY, &mm->flags);
44868 smp_wmb();
44869 set_bit(MMF_DUMPABLE, &mm->flags);
44870@@ -2025,7 +2401,7 @@ static int __get_dumpable(unsigned long mm_flags)
44871 int ret;
44872
44873 ret = mm_flags & MMF_DUMPABLE_MASK;
44874- return (ret >= 2) ? 2 : ret;
44875+ return (ret > SUID_DUMPABLE_ENABLED) ? SUID_DUMPABLE_SAFE : ret;
44876 }
44877
44878 int get_dumpable(struct mm_struct *mm)
44879@@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
44880 pipe = file->f_path.dentry->d_inode->i_pipe;
44881
44882 pipe_lock(pipe);
44883- pipe->readers++;
44884- pipe->writers--;
44885+ atomic_inc(&pipe->readers);
44886+ atomic_dec(&pipe->writers);
44887
44888- while ((pipe->readers > 1) && (!signal_pending(current))) {
44889+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44890 wake_up_interruptible_sync(&pipe->wait);
44891 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44892 pipe_wait(pipe);
44893 }
44894
44895- pipe->readers--;
44896- pipe->writers++;
44897+ atomic_dec(&pipe->readers);
44898+ atomic_inc(&pipe->writers);
44899 pipe_unlock(pipe);
44900
44901 }
44902@@ -2111,7 +2487,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44903 int retval = 0;
44904 int flag = 0;
44905 int ispipe;
44906- static atomic_t core_dump_count = ATOMIC_INIT(0);
44907+ bool need_nonrelative = false;
44908+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44909 struct coredump_params cprm = {
44910 .signr = signr,
44911 .regs = regs,
44912@@ -2126,6 +2503,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44913
44914 audit_core_dumps(signr);
44915
44916+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44917+ gr_handle_brute_attach(current, cprm.mm_flags);
44918+
44919 binfmt = mm->binfmt;
44920 if (!binfmt || !binfmt->core_dump)
44921 goto fail;
44922@@ -2136,14 +2516,16 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44923 if (!cred)
44924 goto fail;
44925 /*
44926- * We cannot trust fsuid as being the "true" uid of the
44927- * process nor do we know its entire history. We only know it
44928- * was tainted so we dump it as root in mode 2.
44929+ * We cannot trust fsuid as being the "true" uid of the process
44930+ * nor do we know its entire history. We only know it was tainted
44931+ * so we dump it as root in mode 2, and only into a controlled
44932+ * environment (pipe handler or fully qualified path).
44933 */
44934- if (__get_dumpable(cprm.mm_flags) == 2) {
44935+ if (__get_dumpable(cprm.mm_flags) == SUID_DUMPABLE_SAFE) {
44936 /* Setuid core dump mode */
44937 flag = O_EXCL; /* Stop rewrite attacks */
44938 cred->fsuid = GLOBAL_ROOT_UID; /* Dump root private */
44939+ need_nonrelative = true;
44940 }
44941
44942 retval = coredump_wait(exit_code, &core_state);
44943@@ -2193,7 +2575,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44944 }
44945 cprm.limit = RLIM_INFINITY;
44946
44947- dump_count = atomic_inc_return(&core_dump_count);
44948+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
44949 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44950 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44951 task_tgid_vnr(current), current->comm);
44952@@ -2220,9 +2602,19 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44953 } else {
44954 struct inode *inode;
44955
44956+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44957+
44958 if (cprm.limit < binfmt->min_coredump)
44959 goto fail_unlock;
44960
44961+ if (need_nonrelative && cn.corename[0] != '/') {
44962+ printk(KERN_WARNING "Pid %d(%s) can only dump core "\
44963+ "to fully qualified path!\n",
44964+ task_tgid_vnr(current), current->comm);
44965+ printk(KERN_WARNING "Skipping core dump\n");
44966+ goto fail_unlock;
44967+ }
44968+
44969 cprm.file = filp_open(cn.corename,
44970 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
44971 0600);
44972@@ -2263,7 +2655,7 @@ close_fail:
44973 filp_close(cprm.file, NULL);
44974 fail_dropcount:
44975 if (ispipe)
44976- atomic_dec(&core_dump_count);
44977+ atomic_dec_unchecked(&core_dump_count);
44978 fail_unlock:
44979 kfree(cn.corename);
44980 fail_corename:
44981@@ -2282,7 +2674,7 @@ fail:
44982 */
44983 int dump_write(struct file *file, const void *addr, int nr)
44984 {
44985- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44986+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44987 }
44988 EXPORT_SYMBOL(dump_write);
44989
44990diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44991index 1c36139..cf6b350 100644
44992--- a/fs/ext2/balloc.c
44993+++ b/fs/ext2/balloc.c
44994@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44995
44996 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44997 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44998- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44999+ if (free_blocks < root_blocks + 1 &&
45000 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45001 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45002- !in_group_p (sbi->s_resgid))) {
45003+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45004 return 0;
45005 }
45006 return 1;
45007diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45008index 25cd608..9ed5294 100644
45009--- a/fs/ext3/balloc.c
45010+++ b/fs/ext3/balloc.c
45011@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45012
45013 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45014 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45015- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45016+ if (free_blocks < root_blocks + 1 &&
45017 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45018 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45019- !in_group_p (sbi->s_resgid))) {
45020+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45021 return 0;
45022 }
45023 return 1;
45024diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45025index cee7812..0e8e65c 100644
45026--- a/fs/ext4/balloc.c
45027+++ b/fs/ext4/balloc.c
45028@@ -488,8 +488,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45029 /* Hm, nope. Are (enough) root reserved clusters available? */
45030 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45031 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45032- capable(CAP_SYS_RESOURCE) ||
45033- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45034+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45035+ capable_nolog(CAP_SYS_RESOURCE)) {
45036
45037 if (free_clusters >= (nclusters + dirty_clusters))
45038 return 1;
45039diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45040index cfc4e01..2f3fd3c 100644
45041--- a/fs/ext4/ext4.h
45042+++ b/fs/ext4/ext4.h
45043@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
45044 unsigned long s_mb_last_start;
45045
45046 /* stats for buddy allocator */
45047- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45048- atomic_t s_bal_success; /* we found long enough chunks */
45049- atomic_t s_bal_allocated; /* in blocks */
45050- atomic_t s_bal_ex_scanned; /* total extents scanned */
45051- atomic_t s_bal_goals; /* goal hits */
45052- atomic_t s_bal_breaks; /* too long searches */
45053- atomic_t s_bal_2orders; /* 2^order hits */
45054+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45055+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45056+ atomic_unchecked_t s_bal_allocated; /* in blocks */
45057+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45058+ atomic_unchecked_t s_bal_goals; /* goal hits */
45059+ atomic_unchecked_t s_bal_breaks; /* too long searches */
45060+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45061 spinlock_t s_bal_lock;
45062 unsigned long s_mb_buddies_generated;
45063 unsigned long long s_mb_generation_time;
45064- atomic_t s_mb_lost_chunks;
45065- atomic_t s_mb_preallocated;
45066- atomic_t s_mb_discarded;
45067+ atomic_unchecked_t s_mb_lost_chunks;
45068+ atomic_unchecked_t s_mb_preallocated;
45069+ atomic_unchecked_t s_mb_discarded;
45070 atomic_t s_lock_busy;
45071
45072 /* locality groups */
45073diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45074index 1cd6994..5799d45 100644
45075--- a/fs/ext4/mballoc.c
45076+++ b/fs/ext4/mballoc.c
45077@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45078 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45079
45080 if (EXT4_SB(sb)->s_mb_stats)
45081- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45082+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45083
45084 break;
45085 }
45086@@ -2041,7 +2041,7 @@ repeat:
45087 ac->ac_status = AC_STATUS_CONTINUE;
45088 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45089 cr = 3;
45090- atomic_inc(&sbi->s_mb_lost_chunks);
45091+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45092 goto repeat;
45093 }
45094 }
45095@@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
45096 if (sbi->s_mb_stats) {
45097 ext4_msg(sb, KERN_INFO,
45098 "mballoc: %u blocks %u reqs (%u success)",
45099- atomic_read(&sbi->s_bal_allocated),
45100- atomic_read(&sbi->s_bal_reqs),
45101- atomic_read(&sbi->s_bal_success));
45102+ atomic_read_unchecked(&sbi->s_bal_allocated),
45103+ atomic_read_unchecked(&sbi->s_bal_reqs),
45104+ atomic_read_unchecked(&sbi->s_bal_success));
45105 ext4_msg(sb, KERN_INFO,
45106 "mballoc: %u extents scanned, %u goal hits, "
45107 "%u 2^N hits, %u breaks, %u lost",
45108- atomic_read(&sbi->s_bal_ex_scanned),
45109- atomic_read(&sbi->s_bal_goals),
45110- atomic_read(&sbi->s_bal_2orders),
45111- atomic_read(&sbi->s_bal_breaks),
45112- atomic_read(&sbi->s_mb_lost_chunks));
45113+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45114+ atomic_read_unchecked(&sbi->s_bal_goals),
45115+ atomic_read_unchecked(&sbi->s_bal_2orders),
45116+ atomic_read_unchecked(&sbi->s_bal_breaks),
45117+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45118 ext4_msg(sb, KERN_INFO,
45119 "mballoc: %lu generated and it took %Lu",
45120 sbi->s_mb_buddies_generated,
45121 sbi->s_mb_generation_time);
45122 ext4_msg(sb, KERN_INFO,
45123 "mballoc: %u preallocated, %u discarded",
45124- atomic_read(&sbi->s_mb_preallocated),
45125- atomic_read(&sbi->s_mb_discarded));
45126+ atomic_read_unchecked(&sbi->s_mb_preallocated),
45127+ atomic_read_unchecked(&sbi->s_mb_discarded));
45128 }
45129
45130 free_percpu(sbi->s_locality_groups);
45131@@ -3047,16 +3047,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45132 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45133
45134 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45135- atomic_inc(&sbi->s_bal_reqs);
45136- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45137+ atomic_inc_unchecked(&sbi->s_bal_reqs);
45138+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45139 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45140- atomic_inc(&sbi->s_bal_success);
45141- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45142+ atomic_inc_unchecked(&sbi->s_bal_success);
45143+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45144 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45145 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45146- atomic_inc(&sbi->s_bal_goals);
45147+ atomic_inc_unchecked(&sbi->s_bal_goals);
45148 if (ac->ac_found > sbi->s_mb_max_to_scan)
45149- atomic_inc(&sbi->s_bal_breaks);
45150+ atomic_inc_unchecked(&sbi->s_bal_breaks);
45151 }
45152
45153 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45154@@ -3456,7 +3456,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45155 trace_ext4_mb_new_inode_pa(ac, pa);
45156
45157 ext4_mb_use_inode_pa(ac, pa);
45158- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45159+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45160
45161 ei = EXT4_I(ac->ac_inode);
45162 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45163@@ -3516,7 +3516,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45164 trace_ext4_mb_new_group_pa(ac, pa);
45165
45166 ext4_mb_use_group_pa(ac, pa);
45167- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45168+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45169
45170 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45171 lg = ac->ac_lg;
45172@@ -3605,7 +3605,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45173 * from the bitmap and continue.
45174 */
45175 }
45176- atomic_add(free, &sbi->s_mb_discarded);
45177+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
45178
45179 return err;
45180 }
45181@@ -3623,7 +3623,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45182 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45183 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45184 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45185- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45186+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45187 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45188
45189 return 0;
45190diff --git a/fs/fcntl.c b/fs/fcntl.c
45191index 81b70e6..d9ae6cf 100644
45192--- a/fs/fcntl.c
45193+++ b/fs/fcntl.c
45194@@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45195 if (err)
45196 return err;
45197
45198+ if (gr_handle_chroot_fowner(pid, type))
45199+ return -ENOENT;
45200+ if (gr_check_protected_task_fowner(pid, type))
45201+ return -EACCES;
45202+
45203 f_modown(filp, pid, type, force);
45204 return 0;
45205 }
45206@@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
45207
45208 static int f_setown_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 struct pid *pid;
45214 int type;
45215@@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45216
45217 static int f_getown_ex(struct file *filp, unsigned long arg)
45218 {
45219- struct f_owner_ex * __user owner_p = (void * __user)arg;
45220+ struct f_owner_ex __user *owner_p = (void __user *)arg;
45221 struct f_owner_ex owner;
45222 int ret = 0;
45223
45224@@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45225 switch (cmd) {
45226 case F_DUPFD:
45227 case F_DUPFD_CLOEXEC:
45228+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45229 if (arg >= rlimit(RLIMIT_NOFILE))
45230 break;
45231 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45232diff --git a/fs/fifo.c b/fs/fifo.c
45233index cf6f434..3d7942c 100644
45234--- a/fs/fifo.c
45235+++ b/fs/fifo.c
45236@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45237 */
45238 filp->f_op = &read_pipefifo_fops;
45239 pipe->r_counter++;
45240- if (pipe->readers++ == 0)
45241+ if (atomic_inc_return(&pipe->readers) == 1)
45242 wake_up_partner(inode);
45243
45244- if (!pipe->writers) {
45245+ if (!atomic_read(&pipe->writers)) {
45246 if ((filp->f_flags & O_NONBLOCK)) {
45247 /* suppress POLLHUP until we have
45248 * seen a writer */
45249@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45250 * errno=ENXIO when there is no process reading the FIFO.
45251 */
45252 ret = -ENXIO;
45253- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45254+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45255 goto err;
45256
45257 filp->f_op = &write_pipefifo_fops;
45258 pipe->w_counter++;
45259- if (!pipe->writers++)
45260+ if (atomic_inc_return(&pipe->writers) == 1)
45261 wake_up_partner(inode);
45262
45263- if (!pipe->readers) {
45264+ if (!atomic_read(&pipe->readers)) {
45265 if (wait_for_partner(inode, &pipe->r_counter))
45266 goto err_wr;
45267 }
45268@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45269 */
45270 filp->f_op = &rdwr_pipefifo_fops;
45271
45272- pipe->readers++;
45273- pipe->writers++;
45274+ atomic_inc(&pipe->readers);
45275+ atomic_inc(&pipe->writers);
45276 pipe->r_counter++;
45277 pipe->w_counter++;
45278- if (pipe->readers == 1 || pipe->writers == 1)
45279+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45280 wake_up_partner(inode);
45281 break;
45282
45283@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45284 return 0;
45285
45286 err_rd:
45287- if (!--pipe->readers)
45288+ if (atomic_dec_and_test(&pipe->readers))
45289 wake_up_interruptible(&pipe->wait);
45290 ret = -ERESTARTSYS;
45291 goto err;
45292
45293 err_wr:
45294- if (!--pipe->writers)
45295+ if (atomic_dec_and_test(&pipe->writers))
45296 wake_up_interruptible(&pipe->wait);
45297 ret = -ERESTARTSYS;
45298 goto err;
45299
45300 err:
45301- if (!pipe->readers && !pipe->writers)
45302+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45303 free_pipe_info(inode);
45304
45305 err_nocleanup:
45306diff --git a/fs/file.c b/fs/file.c
45307index ba3f605..fade102 100644
45308--- a/fs/file.c
45309+++ b/fs/file.c
45310@@ -15,6 +15,7 @@
45311 #include <linux/slab.h>
45312 #include <linux/vmalloc.h>
45313 #include <linux/file.h>
45314+#include <linux/security.h>
45315 #include <linux/fdtable.h>
45316 #include <linux/bitops.h>
45317 #include <linux/interrupt.h>
45318@@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45319 * N.B. For clone tasks sharing a files structure, this test
45320 * will limit the total number of files that can be opened.
45321 */
45322+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45323 if (nr >= rlimit(RLIMIT_NOFILE))
45324 return -EMFILE;
45325
45326diff --git a/fs/filesystems.c b/fs/filesystems.c
45327index 96f2428..f5eeb8e 100644
45328--- a/fs/filesystems.c
45329+++ b/fs/filesystems.c
45330@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45331 int len = dot ? dot - name : strlen(name);
45332
45333 fs = __get_fs_type(name, len);
45334+
45335+#ifdef CONFIG_GRKERNSEC_MODHARDEN
45336+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45337+#else
45338 if (!fs && (request_module("%.*s", len, name) == 0))
45339+#endif
45340 fs = __get_fs_type(name, len);
45341
45342 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45343diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45344index e159e68..e7d2a6f 100644
45345--- a/fs/fs_struct.c
45346+++ b/fs/fs_struct.c
45347@@ -4,6 +4,7 @@
45348 #include <linux/path.h>
45349 #include <linux/slab.h>
45350 #include <linux/fs_struct.h>
45351+#include <linux/grsecurity.h>
45352 #include "internal.h"
45353
45354 static inline void path_get_longterm(struct path *path)
45355@@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45356 write_seqcount_begin(&fs->seq);
45357 old_root = fs->root;
45358 fs->root = *path;
45359+ gr_set_chroot_entries(current, path);
45360 write_seqcount_end(&fs->seq);
45361 spin_unlock(&fs->lock);
45362 if (old_root.dentry)
45363@@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45364 return 1;
45365 }
45366
45367+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45368+{
45369+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45370+ return 0;
45371+ *p = *new;
45372+
45373+ gr_set_chroot_entries(task, new);
45374+
45375+ return 1;
45376+}
45377+
45378 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45379 {
45380 struct task_struct *g, *p;
45381@@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45382 int hits = 0;
45383 spin_lock(&fs->lock);
45384 write_seqcount_begin(&fs->seq);
45385- hits += replace_path(&fs->root, old_root, new_root);
45386+ hits += replace_root_path(p, &fs->root, old_root, new_root);
45387 hits += replace_path(&fs->pwd, old_root, new_root);
45388 write_seqcount_end(&fs->seq);
45389 while (hits--) {
45390@@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
45391 task_lock(tsk);
45392 spin_lock(&fs->lock);
45393 tsk->fs = NULL;
45394- kill = !--fs->users;
45395+ gr_clear_chroot_entries(tsk);
45396+ kill = !atomic_dec_return(&fs->users);
45397 spin_unlock(&fs->lock);
45398 task_unlock(tsk);
45399 if (kill)
45400@@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45401 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45402 /* We don't need to lock fs - think why ;-) */
45403 if (fs) {
45404- fs->users = 1;
45405+ atomic_set(&fs->users, 1);
45406 fs->in_exec = 0;
45407 spin_lock_init(&fs->lock);
45408 seqcount_init(&fs->seq);
45409@@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45410 spin_lock(&old->lock);
45411 fs->root = old->root;
45412 path_get_longterm(&fs->root);
45413+ /* instead of calling gr_set_chroot_entries here,
45414+ we call it from every caller of this function
45415+ */
45416 fs->pwd = old->pwd;
45417 path_get_longterm(&fs->pwd);
45418 spin_unlock(&old->lock);
45419@@ -151,8 +168,9 @@ int unshare_fs_struct(void)
45420
45421 task_lock(current);
45422 spin_lock(&fs->lock);
45423- kill = !--fs->users;
45424+ kill = !atomic_dec_return(&fs->users);
45425 current->fs = new_fs;
45426+ gr_set_chroot_entries(current, &new_fs->root);
45427 spin_unlock(&fs->lock);
45428 task_unlock(current);
45429
45430@@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45431
45432 int current_umask(void)
45433 {
45434- return current->fs->umask;
45435+ return current->fs->umask | gr_acl_umask();
45436 }
45437 EXPORT_SYMBOL(current_umask);
45438
45439 /* to be mentioned only in INIT_TASK */
45440 struct fs_struct init_fs = {
45441- .users = 1,
45442+ .users = ATOMIC_INIT(1),
45443 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45444 .seq = SEQCNT_ZERO,
45445 .umask = 0022,
45446@@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
45447 task_lock(current);
45448
45449 spin_lock(&init_fs.lock);
45450- init_fs.users++;
45451+ atomic_inc(&init_fs.users);
45452 spin_unlock(&init_fs.lock);
45453
45454 spin_lock(&fs->lock);
45455 current->fs = &init_fs;
45456- kill = !--fs->users;
45457+ gr_set_chroot_entries(current, &current->fs->root);
45458+ kill = !atomic_dec_return(&fs->users);
45459 spin_unlock(&fs->lock);
45460
45461 task_unlock(current);
45462diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45463index 9905350..02eaec4 100644
45464--- a/fs/fscache/cookie.c
45465+++ b/fs/fscache/cookie.c
45466@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45467 parent ? (char *) parent->def->name : "<no-parent>",
45468 def->name, netfs_data);
45469
45470- fscache_stat(&fscache_n_acquires);
45471+ fscache_stat_unchecked(&fscache_n_acquires);
45472
45473 /* if there's no parent cookie, then we don't create one here either */
45474 if (!parent) {
45475- fscache_stat(&fscache_n_acquires_null);
45476+ fscache_stat_unchecked(&fscache_n_acquires_null);
45477 _leave(" [no parent]");
45478 return NULL;
45479 }
45480@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45481 /* allocate and initialise a cookie */
45482 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45483 if (!cookie) {
45484- fscache_stat(&fscache_n_acquires_oom);
45485+ fscache_stat_unchecked(&fscache_n_acquires_oom);
45486 _leave(" [ENOMEM]");
45487 return NULL;
45488 }
45489@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45490
45491 switch (cookie->def->type) {
45492 case FSCACHE_COOKIE_TYPE_INDEX:
45493- fscache_stat(&fscache_n_cookie_index);
45494+ fscache_stat_unchecked(&fscache_n_cookie_index);
45495 break;
45496 case FSCACHE_COOKIE_TYPE_DATAFILE:
45497- fscache_stat(&fscache_n_cookie_data);
45498+ fscache_stat_unchecked(&fscache_n_cookie_data);
45499 break;
45500 default:
45501- fscache_stat(&fscache_n_cookie_special);
45502+ fscache_stat_unchecked(&fscache_n_cookie_special);
45503 break;
45504 }
45505
45506@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45507 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45508 atomic_dec(&parent->n_children);
45509 __fscache_cookie_put(cookie);
45510- fscache_stat(&fscache_n_acquires_nobufs);
45511+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45512 _leave(" = NULL");
45513 return NULL;
45514 }
45515 }
45516
45517- fscache_stat(&fscache_n_acquires_ok);
45518+ fscache_stat_unchecked(&fscache_n_acquires_ok);
45519 _leave(" = %p", cookie);
45520 return cookie;
45521 }
45522@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45523 cache = fscache_select_cache_for_object(cookie->parent);
45524 if (!cache) {
45525 up_read(&fscache_addremove_sem);
45526- fscache_stat(&fscache_n_acquires_no_cache);
45527+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45528 _leave(" = -ENOMEDIUM [no cache]");
45529 return -ENOMEDIUM;
45530 }
45531@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45532 object = cache->ops->alloc_object(cache, cookie);
45533 fscache_stat_d(&fscache_n_cop_alloc_object);
45534 if (IS_ERR(object)) {
45535- fscache_stat(&fscache_n_object_no_alloc);
45536+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
45537 ret = PTR_ERR(object);
45538 goto error;
45539 }
45540
45541- fscache_stat(&fscache_n_object_alloc);
45542+ fscache_stat_unchecked(&fscache_n_object_alloc);
45543
45544 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45545
45546@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45547 struct fscache_object *object;
45548 struct hlist_node *_p;
45549
45550- fscache_stat(&fscache_n_updates);
45551+ fscache_stat_unchecked(&fscache_n_updates);
45552
45553 if (!cookie) {
45554- fscache_stat(&fscache_n_updates_null);
45555+ fscache_stat_unchecked(&fscache_n_updates_null);
45556 _leave(" [no cookie]");
45557 return;
45558 }
45559@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45560 struct fscache_object *object;
45561 unsigned long event;
45562
45563- fscache_stat(&fscache_n_relinquishes);
45564+ fscache_stat_unchecked(&fscache_n_relinquishes);
45565 if (retire)
45566- fscache_stat(&fscache_n_relinquishes_retire);
45567+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45568
45569 if (!cookie) {
45570- fscache_stat(&fscache_n_relinquishes_null);
45571+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
45572 _leave(" [no cookie]");
45573 return;
45574 }
45575@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45576
45577 /* wait for the cookie to finish being instantiated (or to fail) */
45578 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45579- fscache_stat(&fscache_n_relinquishes_waitcrt);
45580+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45581 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45582 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45583 }
45584diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45585index f6aad48..88dcf26 100644
45586--- a/fs/fscache/internal.h
45587+++ b/fs/fscache/internal.h
45588@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45589 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45590 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45591
45592-extern atomic_t fscache_n_op_pend;
45593-extern atomic_t fscache_n_op_run;
45594-extern atomic_t fscache_n_op_enqueue;
45595-extern atomic_t fscache_n_op_deferred_release;
45596-extern atomic_t fscache_n_op_release;
45597-extern atomic_t fscache_n_op_gc;
45598-extern atomic_t fscache_n_op_cancelled;
45599-extern atomic_t fscache_n_op_rejected;
45600+extern atomic_unchecked_t fscache_n_op_pend;
45601+extern atomic_unchecked_t fscache_n_op_run;
45602+extern atomic_unchecked_t fscache_n_op_enqueue;
45603+extern atomic_unchecked_t fscache_n_op_deferred_release;
45604+extern atomic_unchecked_t fscache_n_op_release;
45605+extern atomic_unchecked_t fscache_n_op_gc;
45606+extern atomic_unchecked_t fscache_n_op_cancelled;
45607+extern atomic_unchecked_t fscache_n_op_rejected;
45608
45609-extern atomic_t fscache_n_attr_changed;
45610-extern atomic_t fscache_n_attr_changed_ok;
45611-extern atomic_t fscache_n_attr_changed_nobufs;
45612-extern atomic_t fscache_n_attr_changed_nomem;
45613-extern atomic_t fscache_n_attr_changed_calls;
45614+extern atomic_unchecked_t fscache_n_attr_changed;
45615+extern atomic_unchecked_t fscache_n_attr_changed_ok;
45616+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45617+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45618+extern atomic_unchecked_t fscache_n_attr_changed_calls;
45619
45620-extern atomic_t fscache_n_allocs;
45621-extern atomic_t fscache_n_allocs_ok;
45622-extern atomic_t fscache_n_allocs_wait;
45623-extern atomic_t fscache_n_allocs_nobufs;
45624-extern atomic_t fscache_n_allocs_intr;
45625-extern atomic_t fscache_n_allocs_object_dead;
45626-extern atomic_t fscache_n_alloc_ops;
45627-extern atomic_t fscache_n_alloc_op_waits;
45628+extern atomic_unchecked_t fscache_n_allocs;
45629+extern atomic_unchecked_t fscache_n_allocs_ok;
45630+extern atomic_unchecked_t fscache_n_allocs_wait;
45631+extern atomic_unchecked_t fscache_n_allocs_nobufs;
45632+extern atomic_unchecked_t fscache_n_allocs_intr;
45633+extern atomic_unchecked_t fscache_n_allocs_object_dead;
45634+extern atomic_unchecked_t fscache_n_alloc_ops;
45635+extern atomic_unchecked_t fscache_n_alloc_op_waits;
45636
45637-extern atomic_t fscache_n_retrievals;
45638-extern atomic_t fscache_n_retrievals_ok;
45639-extern atomic_t fscache_n_retrievals_wait;
45640-extern atomic_t fscache_n_retrievals_nodata;
45641-extern atomic_t fscache_n_retrievals_nobufs;
45642-extern atomic_t fscache_n_retrievals_intr;
45643-extern atomic_t fscache_n_retrievals_nomem;
45644-extern atomic_t fscache_n_retrievals_object_dead;
45645-extern atomic_t fscache_n_retrieval_ops;
45646-extern atomic_t fscache_n_retrieval_op_waits;
45647+extern atomic_unchecked_t fscache_n_retrievals;
45648+extern atomic_unchecked_t fscache_n_retrievals_ok;
45649+extern atomic_unchecked_t fscache_n_retrievals_wait;
45650+extern atomic_unchecked_t fscache_n_retrievals_nodata;
45651+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45652+extern atomic_unchecked_t fscache_n_retrievals_intr;
45653+extern atomic_unchecked_t fscache_n_retrievals_nomem;
45654+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45655+extern atomic_unchecked_t fscache_n_retrieval_ops;
45656+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45657
45658-extern atomic_t fscache_n_stores;
45659-extern atomic_t fscache_n_stores_ok;
45660-extern atomic_t fscache_n_stores_again;
45661-extern atomic_t fscache_n_stores_nobufs;
45662-extern atomic_t fscache_n_stores_oom;
45663-extern atomic_t fscache_n_store_ops;
45664-extern atomic_t fscache_n_store_calls;
45665-extern atomic_t fscache_n_store_pages;
45666-extern atomic_t fscache_n_store_radix_deletes;
45667-extern atomic_t fscache_n_store_pages_over_limit;
45668+extern atomic_unchecked_t fscache_n_stores;
45669+extern atomic_unchecked_t fscache_n_stores_ok;
45670+extern atomic_unchecked_t fscache_n_stores_again;
45671+extern atomic_unchecked_t fscache_n_stores_nobufs;
45672+extern atomic_unchecked_t fscache_n_stores_oom;
45673+extern atomic_unchecked_t fscache_n_store_ops;
45674+extern atomic_unchecked_t fscache_n_store_calls;
45675+extern atomic_unchecked_t fscache_n_store_pages;
45676+extern atomic_unchecked_t fscache_n_store_radix_deletes;
45677+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45678
45679-extern atomic_t fscache_n_store_vmscan_not_storing;
45680-extern atomic_t fscache_n_store_vmscan_gone;
45681-extern atomic_t fscache_n_store_vmscan_busy;
45682-extern atomic_t fscache_n_store_vmscan_cancelled;
45683+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45684+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45685+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45686+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45687
45688-extern atomic_t fscache_n_marks;
45689-extern atomic_t fscache_n_uncaches;
45690+extern atomic_unchecked_t fscache_n_marks;
45691+extern atomic_unchecked_t fscache_n_uncaches;
45692
45693-extern atomic_t fscache_n_acquires;
45694-extern atomic_t fscache_n_acquires_null;
45695-extern atomic_t fscache_n_acquires_no_cache;
45696-extern atomic_t fscache_n_acquires_ok;
45697-extern atomic_t fscache_n_acquires_nobufs;
45698-extern atomic_t fscache_n_acquires_oom;
45699+extern atomic_unchecked_t fscache_n_acquires;
45700+extern atomic_unchecked_t fscache_n_acquires_null;
45701+extern atomic_unchecked_t fscache_n_acquires_no_cache;
45702+extern atomic_unchecked_t fscache_n_acquires_ok;
45703+extern atomic_unchecked_t fscache_n_acquires_nobufs;
45704+extern atomic_unchecked_t fscache_n_acquires_oom;
45705
45706-extern atomic_t fscache_n_updates;
45707-extern atomic_t fscache_n_updates_null;
45708-extern atomic_t fscache_n_updates_run;
45709+extern atomic_unchecked_t fscache_n_updates;
45710+extern atomic_unchecked_t fscache_n_updates_null;
45711+extern atomic_unchecked_t fscache_n_updates_run;
45712
45713-extern atomic_t fscache_n_relinquishes;
45714-extern atomic_t fscache_n_relinquishes_null;
45715-extern atomic_t fscache_n_relinquishes_waitcrt;
45716-extern atomic_t fscache_n_relinquishes_retire;
45717+extern atomic_unchecked_t fscache_n_relinquishes;
45718+extern atomic_unchecked_t fscache_n_relinquishes_null;
45719+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45720+extern atomic_unchecked_t fscache_n_relinquishes_retire;
45721
45722-extern atomic_t fscache_n_cookie_index;
45723-extern atomic_t fscache_n_cookie_data;
45724-extern atomic_t fscache_n_cookie_special;
45725+extern atomic_unchecked_t fscache_n_cookie_index;
45726+extern atomic_unchecked_t fscache_n_cookie_data;
45727+extern atomic_unchecked_t fscache_n_cookie_special;
45728
45729-extern atomic_t fscache_n_object_alloc;
45730-extern atomic_t fscache_n_object_no_alloc;
45731-extern atomic_t fscache_n_object_lookups;
45732-extern atomic_t fscache_n_object_lookups_negative;
45733-extern atomic_t fscache_n_object_lookups_positive;
45734-extern atomic_t fscache_n_object_lookups_timed_out;
45735-extern atomic_t fscache_n_object_created;
45736-extern atomic_t fscache_n_object_avail;
45737-extern atomic_t fscache_n_object_dead;
45738+extern atomic_unchecked_t fscache_n_object_alloc;
45739+extern atomic_unchecked_t fscache_n_object_no_alloc;
45740+extern atomic_unchecked_t fscache_n_object_lookups;
45741+extern atomic_unchecked_t fscache_n_object_lookups_negative;
45742+extern atomic_unchecked_t fscache_n_object_lookups_positive;
45743+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45744+extern atomic_unchecked_t fscache_n_object_created;
45745+extern atomic_unchecked_t fscache_n_object_avail;
45746+extern atomic_unchecked_t fscache_n_object_dead;
45747
45748-extern atomic_t fscache_n_checkaux_none;
45749-extern atomic_t fscache_n_checkaux_okay;
45750-extern atomic_t fscache_n_checkaux_update;
45751-extern atomic_t fscache_n_checkaux_obsolete;
45752+extern atomic_unchecked_t fscache_n_checkaux_none;
45753+extern atomic_unchecked_t fscache_n_checkaux_okay;
45754+extern atomic_unchecked_t fscache_n_checkaux_update;
45755+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45756
45757 extern atomic_t fscache_n_cop_alloc_object;
45758 extern atomic_t fscache_n_cop_lookup_object;
45759@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45760 atomic_inc(stat);
45761 }
45762
45763+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45764+{
45765+ atomic_inc_unchecked(stat);
45766+}
45767+
45768 static inline void fscache_stat_d(atomic_t *stat)
45769 {
45770 atomic_dec(stat);
45771@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45772
45773 #define __fscache_stat(stat) (NULL)
45774 #define fscache_stat(stat) do {} while (0)
45775+#define fscache_stat_unchecked(stat) do {} while (0)
45776 #define fscache_stat_d(stat) do {} while (0)
45777 #endif
45778
45779diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45780index b6b897c..0ffff9c 100644
45781--- a/fs/fscache/object.c
45782+++ b/fs/fscache/object.c
45783@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45784 /* update the object metadata on disk */
45785 case FSCACHE_OBJECT_UPDATING:
45786 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45787- fscache_stat(&fscache_n_updates_run);
45788+ fscache_stat_unchecked(&fscache_n_updates_run);
45789 fscache_stat(&fscache_n_cop_update_object);
45790 object->cache->ops->update_object(object);
45791 fscache_stat_d(&fscache_n_cop_update_object);
45792@@ -217,7 +217,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 /* handle the parent cache of this object being withdrawn from
45801@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45802 spin_lock(&object->lock);
45803 object->state = FSCACHE_OBJECT_DEAD;
45804 spin_unlock(&object->lock);
45805- fscache_stat(&fscache_n_object_dead);
45806+ fscache_stat_unchecked(&fscache_n_object_dead);
45807 goto terminal_transit;
45808
45809 /* complain about the object being woken up once it is
45810@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45811 parent->cookie->def->name, cookie->def->name,
45812 object->cache->tag->name);
45813
45814- fscache_stat(&fscache_n_object_lookups);
45815+ fscache_stat_unchecked(&fscache_n_object_lookups);
45816 fscache_stat(&fscache_n_cop_lookup_object);
45817 ret = object->cache->ops->lookup_object(object);
45818 fscache_stat_d(&fscache_n_cop_lookup_object);
45819@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45820 if (ret == -ETIMEDOUT) {
45821 /* probably stuck behind another object, so move this one to
45822 * the back of the queue */
45823- fscache_stat(&fscache_n_object_lookups_timed_out);
45824+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45825 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45826 }
45827
45828@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45829
45830 spin_lock(&object->lock);
45831 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45832- fscache_stat(&fscache_n_object_lookups_negative);
45833+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45834
45835 /* transit here to allow write requests to begin stacking up
45836 * and read requests to begin returning ENODATA */
45837@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45838 * result, in which case there may be data available */
45839 spin_lock(&object->lock);
45840 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45841- fscache_stat(&fscache_n_object_lookups_positive);
45842+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45843
45844 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45845
45846@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45847 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45848 } else {
45849 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45850- fscache_stat(&fscache_n_object_created);
45851+ fscache_stat_unchecked(&fscache_n_object_created);
45852
45853 object->state = FSCACHE_OBJECT_AVAILABLE;
45854 spin_unlock(&object->lock);
45855@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45856 fscache_enqueue_dependents(object);
45857
45858 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45859- fscache_stat(&fscache_n_object_avail);
45860+ fscache_stat_unchecked(&fscache_n_object_avail);
45861
45862 _leave("");
45863 }
45864@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45865 enum fscache_checkaux result;
45866
45867 if (!object->cookie->def->check_aux) {
45868- fscache_stat(&fscache_n_checkaux_none);
45869+ fscache_stat_unchecked(&fscache_n_checkaux_none);
45870 return FSCACHE_CHECKAUX_OKAY;
45871 }
45872
45873@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45874 switch (result) {
45875 /* entry okay as is */
45876 case FSCACHE_CHECKAUX_OKAY:
45877- fscache_stat(&fscache_n_checkaux_okay);
45878+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
45879 break;
45880
45881 /* entry requires update */
45882 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45883- fscache_stat(&fscache_n_checkaux_update);
45884+ fscache_stat_unchecked(&fscache_n_checkaux_update);
45885 break;
45886
45887 /* entry requires deletion */
45888 case FSCACHE_CHECKAUX_OBSOLETE:
45889- fscache_stat(&fscache_n_checkaux_obsolete);
45890+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45891 break;
45892
45893 default:
45894diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45895index 30afdfa..2256596 100644
45896--- a/fs/fscache/operation.c
45897+++ b/fs/fscache/operation.c
45898@@ -17,7 +17,7 @@
45899 #include <linux/slab.h>
45900 #include "internal.h"
45901
45902-atomic_t fscache_op_debug_id;
45903+atomic_unchecked_t fscache_op_debug_id;
45904 EXPORT_SYMBOL(fscache_op_debug_id);
45905
45906 /**
45907@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45908 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45909 ASSERTCMP(atomic_read(&op->usage), >, 0);
45910
45911- fscache_stat(&fscache_n_op_enqueue);
45912+ fscache_stat_unchecked(&fscache_n_op_enqueue);
45913 switch (op->flags & FSCACHE_OP_TYPE) {
45914 case FSCACHE_OP_ASYNC:
45915 _debug("queue async");
45916@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45917 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45918 if (op->processor)
45919 fscache_enqueue_operation(op);
45920- fscache_stat(&fscache_n_op_run);
45921+ fscache_stat_unchecked(&fscache_n_op_run);
45922 }
45923
45924 /*
45925@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45926 if (object->n_ops > 1) {
45927 atomic_inc(&op->usage);
45928 list_add_tail(&op->pend_link, &object->pending_ops);
45929- fscache_stat(&fscache_n_op_pend);
45930+ fscache_stat_unchecked(&fscache_n_op_pend);
45931 } else if (!list_empty(&object->pending_ops)) {
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 fscache_start_operations(object);
45937 } else {
45938 ASSERTCMP(object->n_in_progress, ==, 0);
45939@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45940 object->n_exclusive++; /* reads and writes must wait */
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 ret = 0;
45946 } else {
45947 /* not allowed to submit ops in any other state */
45948@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45949 if (object->n_exclusive > 0) {
45950 atomic_inc(&op->usage);
45951 list_add_tail(&op->pend_link, &object->pending_ops);
45952- fscache_stat(&fscache_n_op_pend);
45953+ fscache_stat_unchecked(&fscache_n_op_pend);
45954 } else if (!list_empty(&object->pending_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 fscache_start_operations(object);
45960 } else {
45961 ASSERTCMP(object->n_exclusive, ==, 0);
45962@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45963 object->n_ops++;
45964 atomic_inc(&op->usage);
45965 list_add_tail(&op->pend_link, &object->pending_ops);
45966- fscache_stat(&fscache_n_op_pend);
45967+ fscache_stat_unchecked(&fscache_n_op_pend);
45968 ret = 0;
45969 } else if (object->state == FSCACHE_OBJECT_DYING ||
45970 object->state == FSCACHE_OBJECT_LC_DYING ||
45971 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45972- fscache_stat(&fscache_n_op_rejected);
45973+ fscache_stat_unchecked(&fscache_n_op_rejected);
45974 ret = -ENOBUFS;
45975 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45976 fscache_report_unexpected_submission(object, op, ostate);
45977@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45978
45979 ret = -EBUSY;
45980 if (!list_empty(&op->pend_link)) {
45981- fscache_stat(&fscache_n_op_cancelled);
45982+ fscache_stat_unchecked(&fscache_n_op_cancelled);
45983 list_del_init(&op->pend_link);
45984 object->n_ops--;
45985 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45986@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45987 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45988 BUG();
45989
45990- fscache_stat(&fscache_n_op_release);
45991+ fscache_stat_unchecked(&fscache_n_op_release);
45992
45993 if (op->release) {
45994 op->release(op);
45995@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45996 * lock, and defer it otherwise */
45997 if (!spin_trylock(&object->lock)) {
45998 _debug("defer put");
45999- fscache_stat(&fscache_n_op_deferred_release);
46000+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
46001
46002 cache = object->cache;
46003 spin_lock(&cache->op_gc_list_lock);
46004@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46005
46006 _debug("GC DEFERRED REL OBJ%x OP%x",
46007 object->debug_id, op->debug_id);
46008- fscache_stat(&fscache_n_op_gc);
46009+ fscache_stat_unchecked(&fscache_n_op_gc);
46010
46011 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46012
46013diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46014index 3f7a59b..cf196cc 100644
46015--- a/fs/fscache/page.c
46016+++ b/fs/fscache/page.c
46017@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46018 val = radix_tree_lookup(&cookie->stores, page->index);
46019 if (!val) {
46020 rcu_read_unlock();
46021- fscache_stat(&fscache_n_store_vmscan_not_storing);
46022+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46023 __fscache_uncache_page(cookie, page);
46024 return true;
46025 }
46026@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46027 spin_unlock(&cookie->stores_lock);
46028
46029 if (xpage) {
46030- fscache_stat(&fscache_n_store_vmscan_cancelled);
46031- fscache_stat(&fscache_n_store_radix_deletes);
46032+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46033+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46034 ASSERTCMP(xpage, ==, page);
46035 } else {
46036- fscache_stat(&fscache_n_store_vmscan_gone);
46037+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46038 }
46039
46040 wake_up_bit(&cookie->flags, 0);
46041@@ -107,7 +107,7 @@ page_busy:
46042 /* we might want to wait here, but that could deadlock the allocator as
46043 * the work threads writing to the cache may all end up sleeping
46044 * on memory allocation */
46045- fscache_stat(&fscache_n_store_vmscan_busy);
46046+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46047 return false;
46048 }
46049 EXPORT_SYMBOL(__fscache_maybe_release_page);
46050@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46051 FSCACHE_COOKIE_STORING_TAG);
46052 if (!radix_tree_tag_get(&cookie->stores, page->index,
46053 FSCACHE_COOKIE_PENDING_TAG)) {
46054- fscache_stat(&fscache_n_store_radix_deletes);
46055+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46056 xpage = radix_tree_delete(&cookie->stores, page->index);
46057 }
46058 spin_unlock(&cookie->stores_lock);
46059@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46060
46061 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46062
46063- fscache_stat(&fscache_n_attr_changed_calls);
46064+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46065
46066 if (fscache_object_is_active(object)) {
46067 fscache_stat(&fscache_n_cop_attr_changed);
46068@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46069
46070 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46071
46072- fscache_stat(&fscache_n_attr_changed);
46073+ fscache_stat_unchecked(&fscache_n_attr_changed);
46074
46075 op = kzalloc(sizeof(*op), GFP_KERNEL);
46076 if (!op) {
46077- fscache_stat(&fscache_n_attr_changed_nomem);
46078+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46079 _leave(" = -ENOMEM");
46080 return -ENOMEM;
46081 }
46082@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46083 if (fscache_submit_exclusive_op(object, op) < 0)
46084 goto nobufs;
46085 spin_unlock(&cookie->lock);
46086- fscache_stat(&fscache_n_attr_changed_ok);
46087+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46088 fscache_put_operation(op);
46089 _leave(" = 0");
46090 return 0;
46091@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46092 nobufs:
46093 spin_unlock(&cookie->lock);
46094 kfree(op);
46095- fscache_stat(&fscache_n_attr_changed_nobufs);
46096+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46097 _leave(" = %d", -ENOBUFS);
46098 return -ENOBUFS;
46099 }
46100@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46101 /* allocate a retrieval operation and attempt to submit it */
46102 op = kzalloc(sizeof(*op), GFP_NOIO);
46103 if (!op) {
46104- fscache_stat(&fscache_n_retrievals_nomem);
46105+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46106 return NULL;
46107 }
46108
46109@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46110 return 0;
46111 }
46112
46113- fscache_stat(&fscache_n_retrievals_wait);
46114+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
46115
46116 jif = jiffies;
46117 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46118 fscache_wait_bit_interruptible,
46119 TASK_INTERRUPTIBLE) != 0) {
46120- fscache_stat(&fscache_n_retrievals_intr);
46121+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46122 _leave(" = -ERESTARTSYS");
46123 return -ERESTARTSYS;
46124 }
46125@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46126 */
46127 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46128 struct fscache_retrieval *op,
46129- atomic_t *stat_op_waits,
46130- atomic_t *stat_object_dead)
46131+ atomic_unchecked_t *stat_op_waits,
46132+ atomic_unchecked_t *stat_object_dead)
46133 {
46134 int ret;
46135
46136@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46137 goto check_if_dead;
46138
46139 _debug(">>> WT");
46140- fscache_stat(stat_op_waits);
46141+ fscache_stat_unchecked(stat_op_waits);
46142 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46143 fscache_wait_bit_interruptible,
46144 TASK_INTERRUPTIBLE) < 0) {
46145@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46146
46147 check_if_dead:
46148 if (unlikely(fscache_object_is_dead(object))) {
46149- fscache_stat(stat_object_dead);
46150+ fscache_stat_unchecked(stat_object_dead);
46151 return -ENOBUFS;
46152 }
46153 return 0;
46154@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46155
46156 _enter("%p,%p,,,", cookie, page);
46157
46158- fscache_stat(&fscache_n_retrievals);
46159+ fscache_stat_unchecked(&fscache_n_retrievals);
46160
46161 if (hlist_empty(&cookie->backing_objects))
46162 goto nobufs;
46163@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46164 goto nobufs_unlock;
46165 spin_unlock(&cookie->lock);
46166
46167- fscache_stat(&fscache_n_retrieval_ops);
46168+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46169
46170 /* pin the netfs read context in case we need to do the actual netfs
46171 * read because we've encountered a cache read failure */
46172@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46173
46174 error:
46175 if (ret == -ENOMEM)
46176- fscache_stat(&fscache_n_retrievals_nomem);
46177+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46178 else if (ret == -ERESTARTSYS)
46179- fscache_stat(&fscache_n_retrievals_intr);
46180+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46181 else if (ret == -ENODATA)
46182- fscache_stat(&fscache_n_retrievals_nodata);
46183+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46184 else if (ret < 0)
46185- fscache_stat(&fscache_n_retrievals_nobufs);
46186+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46187 else
46188- fscache_stat(&fscache_n_retrievals_ok);
46189+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46190
46191 fscache_put_retrieval(op);
46192 _leave(" = %d", ret);
46193@@ -429,7 +429,7 @@ nobufs_unlock:
46194 spin_unlock(&cookie->lock);
46195 kfree(op);
46196 nobufs:
46197- fscache_stat(&fscache_n_retrievals_nobufs);
46198+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46199 _leave(" = -ENOBUFS");
46200 return -ENOBUFS;
46201 }
46202@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46203
46204 _enter("%p,,%d,,,", cookie, *nr_pages);
46205
46206- fscache_stat(&fscache_n_retrievals);
46207+ fscache_stat_unchecked(&fscache_n_retrievals);
46208
46209 if (hlist_empty(&cookie->backing_objects))
46210 goto nobufs;
46211@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46212 goto nobufs_unlock;
46213 spin_unlock(&cookie->lock);
46214
46215- fscache_stat(&fscache_n_retrieval_ops);
46216+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46217
46218 /* pin the netfs read context in case we need to do the actual netfs
46219 * read because we've encountered a cache read failure */
46220@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46221
46222 error:
46223 if (ret == -ENOMEM)
46224- fscache_stat(&fscache_n_retrievals_nomem);
46225+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46226 else if (ret == -ERESTARTSYS)
46227- fscache_stat(&fscache_n_retrievals_intr);
46228+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46229 else if (ret == -ENODATA)
46230- fscache_stat(&fscache_n_retrievals_nodata);
46231+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46232 else if (ret < 0)
46233- fscache_stat(&fscache_n_retrievals_nobufs);
46234+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46235 else
46236- fscache_stat(&fscache_n_retrievals_ok);
46237+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46238
46239 fscache_put_retrieval(op);
46240 _leave(" = %d", ret);
46241@@ -545,7 +545,7 @@ nobufs_unlock:
46242 spin_unlock(&cookie->lock);
46243 kfree(op);
46244 nobufs:
46245- fscache_stat(&fscache_n_retrievals_nobufs);
46246+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46247 _leave(" = -ENOBUFS");
46248 return -ENOBUFS;
46249 }
46250@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46251
46252 _enter("%p,%p,,,", cookie, page);
46253
46254- fscache_stat(&fscache_n_allocs);
46255+ fscache_stat_unchecked(&fscache_n_allocs);
46256
46257 if (hlist_empty(&cookie->backing_objects))
46258 goto nobufs;
46259@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46260 goto nobufs_unlock;
46261 spin_unlock(&cookie->lock);
46262
46263- fscache_stat(&fscache_n_alloc_ops);
46264+ fscache_stat_unchecked(&fscache_n_alloc_ops);
46265
46266 ret = fscache_wait_for_retrieval_activation(
46267 object, op,
46268@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46269
46270 error:
46271 if (ret == -ERESTARTSYS)
46272- fscache_stat(&fscache_n_allocs_intr);
46273+ fscache_stat_unchecked(&fscache_n_allocs_intr);
46274 else if (ret < 0)
46275- fscache_stat(&fscache_n_allocs_nobufs);
46276+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46277 else
46278- fscache_stat(&fscache_n_allocs_ok);
46279+ fscache_stat_unchecked(&fscache_n_allocs_ok);
46280
46281 fscache_put_retrieval(op);
46282 _leave(" = %d", ret);
46283@@ -625,7 +625,7 @@ nobufs_unlock:
46284 spin_unlock(&cookie->lock);
46285 kfree(op);
46286 nobufs:
46287- fscache_stat(&fscache_n_allocs_nobufs);
46288+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46289 _leave(" = -ENOBUFS");
46290 return -ENOBUFS;
46291 }
46292@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46293
46294 spin_lock(&cookie->stores_lock);
46295
46296- fscache_stat(&fscache_n_store_calls);
46297+ fscache_stat_unchecked(&fscache_n_store_calls);
46298
46299 /* find a page to store */
46300 page = NULL;
46301@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46302 page = results[0];
46303 _debug("gang %d [%lx]", n, page->index);
46304 if (page->index > op->store_limit) {
46305- fscache_stat(&fscache_n_store_pages_over_limit);
46306+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46307 goto superseded;
46308 }
46309
46310@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46311 spin_unlock(&cookie->stores_lock);
46312 spin_unlock(&object->lock);
46313
46314- fscache_stat(&fscache_n_store_pages);
46315+ fscache_stat_unchecked(&fscache_n_store_pages);
46316 fscache_stat(&fscache_n_cop_write_page);
46317 ret = object->cache->ops->write_page(op, page);
46318 fscache_stat_d(&fscache_n_cop_write_page);
46319@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46320 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46321 ASSERT(PageFsCache(page));
46322
46323- fscache_stat(&fscache_n_stores);
46324+ fscache_stat_unchecked(&fscache_n_stores);
46325
46326 op = kzalloc(sizeof(*op), GFP_NOIO);
46327 if (!op)
46328@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46329 spin_unlock(&cookie->stores_lock);
46330 spin_unlock(&object->lock);
46331
46332- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46333+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46334 op->store_limit = object->store_limit;
46335
46336 if (fscache_submit_op(object, &op->op) < 0)
46337@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46338
46339 spin_unlock(&cookie->lock);
46340 radix_tree_preload_end();
46341- fscache_stat(&fscache_n_store_ops);
46342- fscache_stat(&fscache_n_stores_ok);
46343+ fscache_stat_unchecked(&fscache_n_store_ops);
46344+ fscache_stat_unchecked(&fscache_n_stores_ok);
46345
46346 /* the work queue now carries its own ref on the object */
46347 fscache_put_operation(&op->op);
46348@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46349 return 0;
46350
46351 already_queued:
46352- fscache_stat(&fscache_n_stores_again);
46353+ fscache_stat_unchecked(&fscache_n_stores_again);
46354 already_pending:
46355 spin_unlock(&cookie->stores_lock);
46356 spin_unlock(&object->lock);
46357 spin_unlock(&cookie->lock);
46358 radix_tree_preload_end();
46359 kfree(op);
46360- fscache_stat(&fscache_n_stores_ok);
46361+ fscache_stat_unchecked(&fscache_n_stores_ok);
46362 _leave(" = 0");
46363 return 0;
46364
46365@@ -851,14 +851,14 @@ nobufs:
46366 spin_unlock(&cookie->lock);
46367 radix_tree_preload_end();
46368 kfree(op);
46369- fscache_stat(&fscache_n_stores_nobufs);
46370+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
46371 _leave(" = -ENOBUFS");
46372 return -ENOBUFS;
46373
46374 nomem_free:
46375 kfree(op);
46376 nomem:
46377- fscache_stat(&fscache_n_stores_oom);
46378+ fscache_stat_unchecked(&fscache_n_stores_oom);
46379 _leave(" = -ENOMEM");
46380 return -ENOMEM;
46381 }
46382@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46383 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46384 ASSERTCMP(page, !=, NULL);
46385
46386- fscache_stat(&fscache_n_uncaches);
46387+ fscache_stat_unchecked(&fscache_n_uncaches);
46388
46389 /* cache withdrawal may beat us to it */
46390 if (!PageFsCache(page))
46391@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46392 unsigned long loop;
46393
46394 #ifdef CONFIG_FSCACHE_STATS
46395- atomic_add(pagevec->nr, &fscache_n_marks);
46396+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46397 #endif
46398
46399 for (loop = 0; loop < pagevec->nr; loop++) {
46400diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46401index 4765190..2a067f2 100644
46402--- a/fs/fscache/stats.c
46403+++ b/fs/fscache/stats.c
46404@@ -18,95 +18,95 @@
46405 /*
46406 * operation counters
46407 */
46408-atomic_t fscache_n_op_pend;
46409-atomic_t fscache_n_op_run;
46410-atomic_t fscache_n_op_enqueue;
46411-atomic_t fscache_n_op_requeue;
46412-atomic_t fscache_n_op_deferred_release;
46413-atomic_t fscache_n_op_release;
46414-atomic_t fscache_n_op_gc;
46415-atomic_t fscache_n_op_cancelled;
46416-atomic_t fscache_n_op_rejected;
46417+atomic_unchecked_t fscache_n_op_pend;
46418+atomic_unchecked_t fscache_n_op_run;
46419+atomic_unchecked_t fscache_n_op_enqueue;
46420+atomic_unchecked_t fscache_n_op_requeue;
46421+atomic_unchecked_t fscache_n_op_deferred_release;
46422+atomic_unchecked_t fscache_n_op_release;
46423+atomic_unchecked_t fscache_n_op_gc;
46424+atomic_unchecked_t fscache_n_op_cancelled;
46425+atomic_unchecked_t fscache_n_op_rejected;
46426
46427-atomic_t fscache_n_attr_changed;
46428-atomic_t fscache_n_attr_changed_ok;
46429-atomic_t fscache_n_attr_changed_nobufs;
46430-atomic_t fscache_n_attr_changed_nomem;
46431-atomic_t fscache_n_attr_changed_calls;
46432+atomic_unchecked_t fscache_n_attr_changed;
46433+atomic_unchecked_t fscache_n_attr_changed_ok;
46434+atomic_unchecked_t fscache_n_attr_changed_nobufs;
46435+atomic_unchecked_t fscache_n_attr_changed_nomem;
46436+atomic_unchecked_t fscache_n_attr_changed_calls;
46437
46438-atomic_t fscache_n_allocs;
46439-atomic_t fscache_n_allocs_ok;
46440-atomic_t fscache_n_allocs_wait;
46441-atomic_t fscache_n_allocs_nobufs;
46442-atomic_t fscache_n_allocs_intr;
46443-atomic_t fscache_n_allocs_object_dead;
46444-atomic_t fscache_n_alloc_ops;
46445-atomic_t fscache_n_alloc_op_waits;
46446+atomic_unchecked_t fscache_n_allocs;
46447+atomic_unchecked_t fscache_n_allocs_ok;
46448+atomic_unchecked_t fscache_n_allocs_wait;
46449+atomic_unchecked_t fscache_n_allocs_nobufs;
46450+atomic_unchecked_t fscache_n_allocs_intr;
46451+atomic_unchecked_t fscache_n_allocs_object_dead;
46452+atomic_unchecked_t fscache_n_alloc_ops;
46453+atomic_unchecked_t fscache_n_alloc_op_waits;
46454
46455-atomic_t fscache_n_retrievals;
46456-atomic_t fscache_n_retrievals_ok;
46457-atomic_t fscache_n_retrievals_wait;
46458-atomic_t fscache_n_retrievals_nodata;
46459-atomic_t fscache_n_retrievals_nobufs;
46460-atomic_t fscache_n_retrievals_intr;
46461-atomic_t fscache_n_retrievals_nomem;
46462-atomic_t fscache_n_retrievals_object_dead;
46463-atomic_t fscache_n_retrieval_ops;
46464-atomic_t fscache_n_retrieval_op_waits;
46465+atomic_unchecked_t fscache_n_retrievals;
46466+atomic_unchecked_t fscache_n_retrievals_ok;
46467+atomic_unchecked_t fscache_n_retrievals_wait;
46468+atomic_unchecked_t fscache_n_retrievals_nodata;
46469+atomic_unchecked_t fscache_n_retrievals_nobufs;
46470+atomic_unchecked_t fscache_n_retrievals_intr;
46471+atomic_unchecked_t fscache_n_retrievals_nomem;
46472+atomic_unchecked_t fscache_n_retrievals_object_dead;
46473+atomic_unchecked_t fscache_n_retrieval_ops;
46474+atomic_unchecked_t fscache_n_retrieval_op_waits;
46475
46476-atomic_t fscache_n_stores;
46477-atomic_t fscache_n_stores_ok;
46478-atomic_t fscache_n_stores_again;
46479-atomic_t fscache_n_stores_nobufs;
46480-atomic_t fscache_n_stores_oom;
46481-atomic_t fscache_n_store_ops;
46482-atomic_t fscache_n_store_calls;
46483-atomic_t fscache_n_store_pages;
46484-atomic_t fscache_n_store_radix_deletes;
46485-atomic_t fscache_n_store_pages_over_limit;
46486+atomic_unchecked_t fscache_n_stores;
46487+atomic_unchecked_t fscache_n_stores_ok;
46488+atomic_unchecked_t fscache_n_stores_again;
46489+atomic_unchecked_t fscache_n_stores_nobufs;
46490+atomic_unchecked_t fscache_n_stores_oom;
46491+atomic_unchecked_t fscache_n_store_ops;
46492+atomic_unchecked_t fscache_n_store_calls;
46493+atomic_unchecked_t fscache_n_store_pages;
46494+atomic_unchecked_t fscache_n_store_radix_deletes;
46495+atomic_unchecked_t fscache_n_store_pages_over_limit;
46496
46497-atomic_t fscache_n_store_vmscan_not_storing;
46498-atomic_t fscache_n_store_vmscan_gone;
46499-atomic_t fscache_n_store_vmscan_busy;
46500-atomic_t fscache_n_store_vmscan_cancelled;
46501+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46502+atomic_unchecked_t fscache_n_store_vmscan_gone;
46503+atomic_unchecked_t fscache_n_store_vmscan_busy;
46504+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46505
46506-atomic_t fscache_n_marks;
46507-atomic_t fscache_n_uncaches;
46508+atomic_unchecked_t fscache_n_marks;
46509+atomic_unchecked_t fscache_n_uncaches;
46510
46511-atomic_t fscache_n_acquires;
46512-atomic_t fscache_n_acquires_null;
46513-atomic_t fscache_n_acquires_no_cache;
46514-atomic_t fscache_n_acquires_ok;
46515-atomic_t fscache_n_acquires_nobufs;
46516-atomic_t fscache_n_acquires_oom;
46517+atomic_unchecked_t fscache_n_acquires;
46518+atomic_unchecked_t fscache_n_acquires_null;
46519+atomic_unchecked_t fscache_n_acquires_no_cache;
46520+atomic_unchecked_t fscache_n_acquires_ok;
46521+atomic_unchecked_t fscache_n_acquires_nobufs;
46522+atomic_unchecked_t fscache_n_acquires_oom;
46523
46524-atomic_t fscache_n_updates;
46525-atomic_t fscache_n_updates_null;
46526-atomic_t fscache_n_updates_run;
46527+atomic_unchecked_t fscache_n_updates;
46528+atomic_unchecked_t fscache_n_updates_null;
46529+atomic_unchecked_t fscache_n_updates_run;
46530
46531-atomic_t fscache_n_relinquishes;
46532-atomic_t fscache_n_relinquishes_null;
46533-atomic_t fscache_n_relinquishes_waitcrt;
46534-atomic_t fscache_n_relinquishes_retire;
46535+atomic_unchecked_t fscache_n_relinquishes;
46536+atomic_unchecked_t fscache_n_relinquishes_null;
46537+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46538+atomic_unchecked_t fscache_n_relinquishes_retire;
46539
46540-atomic_t fscache_n_cookie_index;
46541-atomic_t fscache_n_cookie_data;
46542-atomic_t fscache_n_cookie_special;
46543+atomic_unchecked_t fscache_n_cookie_index;
46544+atomic_unchecked_t fscache_n_cookie_data;
46545+atomic_unchecked_t fscache_n_cookie_special;
46546
46547-atomic_t fscache_n_object_alloc;
46548-atomic_t fscache_n_object_no_alloc;
46549-atomic_t fscache_n_object_lookups;
46550-atomic_t fscache_n_object_lookups_negative;
46551-atomic_t fscache_n_object_lookups_positive;
46552-atomic_t fscache_n_object_lookups_timed_out;
46553-atomic_t fscache_n_object_created;
46554-atomic_t fscache_n_object_avail;
46555-atomic_t fscache_n_object_dead;
46556+atomic_unchecked_t fscache_n_object_alloc;
46557+atomic_unchecked_t fscache_n_object_no_alloc;
46558+atomic_unchecked_t fscache_n_object_lookups;
46559+atomic_unchecked_t fscache_n_object_lookups_negative;
46560+atomic_unchecked_t fscache_n_object_lookups_positive;
46561+atomic_unchecked_t fscache_n_object_lookups_timed_out;
46562+atomic_unchecked_t fscache_n_object_created;
46563+atomic_unchecked_t fscache_n_object_avail;
46564+atomic_unchecked_t fscache_n_object_dead;
46565
46566-atomic_t fscache_n_checkaux_none;
46567-atomic_t fscache_n_checkaux_okay;
46568-atomic_t fscache_n_checkaux_update;
46569-atomic_t fscache_n_checkaux_obsolete;
46570+atomic_unchecked_t fscache_n_checkaux_none;
46571+atomic_unchecked_t fscache_n_checkaux_okay;
46572+atomic_unchecked_t fscache_n_checkaux_update;
46573+atomic_unchecked_t fscache_n_checkaux_obsolete;
46574
46575 atomic_t fscache_n_cop_alloc_object;
46576 atomic_t fscache_n_cop_lookup_object;
46577@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46578 seq_puts(m, "FS-Cache statistics\n");
46579
46580 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46581- atomic_read(&fscache_n_cookie_index),
46582- atomic_read(&fscache_n_cookie_data),
46583- atomic_read(&fscache_n_cookie_special));
46584+ atomic_read_unchecked(&fscache_n_cookie_index),
46585+ atomic_read_unchecked(&fscache_n_cookie_data),
46586+ atomic_read_unchecked(&fscache_n_cookie_special));
46587
46588 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46589- atomic_read(&fscache_n_object_alloc),
46590- atomic_read(&fscache_n_object_no_alloc),
46591- atomic_read(&fscache_n_object_avail),
46592- atomic_read(&fscache_n_object_dead));
46593+ atomic_read_unchecked(&fscache_n_object_alloc),
46594+ atomic_read_unchecked(&fscache_n_object_no_alloc),
46595+ atomic_read_unchecked(&fscache_n_object_avail),
46596+ atomic_read_unchecked(&fscache_n_object_dead));
46597 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46598- atomic_read(&fscache_n_checkaux_none),
46599- atomic_read(&fscache_n_checkaux_okay),
46600- atomic_read(&fscache_n_checkaux_update),
46601- atomic_read(&fscache_n_checkaux_obsolete));
46602+ atomic_read_unchecked(&fscache_n_checkaux_none),
46603+ atomic_read_unchecked(&fscache_n_checkaux_okay),
46604+ atomic_read_unchecked(&fscache_n_checkaux_update),
46605+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46606
46607 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46608- atomic_read(&fscache_n_marks),
46609- atomic_read(&fscache_n_uncaches));
46610+ atomic_read_unchecked(&fscache_n_marks),
46611+ atomic_read_unchecked(&fscache_n_uncaches));
46612
46613 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46614 " oom=%u\n",
46615- atomic_read(&fscache_n_acquires),
46616- atomic_read(&fscache_n_acquires_null),
46617- atomic_read(&fscache_n_acquires_no_cache),
46618- atomic_read(&fscache_n_acquires_ok),
46619- atomic_read(&fscache_n_acquires_nobufs),
46620- atomic_read(&fscache_n_acquires_oom));
46621+ atomic_read_unchecked(&fscache_n_acquires),
46622+ atomic_read_unchecked(&fscache_n_acquires_null),
46623+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
46624+ atomic_read_unchecked(&fscache_n_acquires_ok),
46625+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
46626+ atomic_read_unchecked(&fscache_n_acquires_oom));
46627
46628 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46629- atomic_read(&fscache_n_object_lookups),
46630- atomic_read(&fscache_n_object_lookups_negative),
46631- atomic_read(&fscache_n_object_lookups_positive),
46632- atomic_read(&fscache_n_object_created),
46633- atomic_read(&fscache_n_object_lookups_timed_out));
46634+ atomic_read_unchecked(&fscache_n_object_lookups),
46635+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
46636+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
46637+ atomic_read_unchecked(&fscache_n_object_created),
46638+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46639
46640 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46641- atomic_read(&fscache_n_updates),
46642- atomic_read(&fscache_n_updates_null),
46643- atomic_read(&fscache_n_updates_run));
46644+ atomic_read_unchecked(&fscache_n_updates),
46645+ atomic_read_unchecked(&fscache_n_updates_null),
46646+ atomic_read_unchecked(&fscache_n_updates_run));
46647
46648 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46649- atomic_read(&fscache_n_relinquishes),
46650- atomic_read(&fscache_n_relinquishes_null),
46651- atomic_read(&fscache_n_relinquishes_waitcrt),
46652- atomic_read(&fscache_n_relinquishes_retire));
46653+ atomic_read_unchecked(&fscache_n_relinquishes),
46654+ atomic_read_unchecked(&fscache_n_relinquishes_null),
46655+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46656+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
46657
46658 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46659- atomic_read(&fscache_n_attr_changed),
46660- atomic_read(&fscache_n_attr_changed_ok),
46661- atomic_read(&fscache_n_attr_changed_nobufs),
46662- atomic_read(&fscache_n_attr_changed_nomem),
46663- atomic_read(&fscache_n_attr_changed_calls));
46664+ atomic_read_unchecked(&fscache_n_attr_changed),
46665+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
46666+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46667+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46668+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
46669
46670 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46671- atomic_read(&fscache_n_allocs),
46672- atomic_read(&fscache_n_allocs_ok),
46673- atomic_read(&fscache_n_allocs_wait),
46674- atomic_read(&fscache_n_allocs_nobufs),
46675- atomic_read(&fscache_n_allocs_intr));
46676+ atomic_read_unchecked(&fscache_n_allocs),
46677+ atomic_read_unchecked(&fscache_n_allocs_ok),
46678+ atomic_read_unchecked(&fscache_n_allocs_wait),
46679+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
46680+ atomic_read_unchecked(&fscache_n_allocs_intr));
46681 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46682- atomic_read(&fscache_n_alloc_ops),
46683- atomic_read(&fscache_n_alloc_op_waits),
46684- atomic_read(&fscache_n_allocs_object_dead));
46685+ atomic_read_unchecked(&fscache_n_alloc_ops),
46686+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
46687+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
46688
46689 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46690 " int=%u oom=%u\n",
46691- atomic_read(&fscache_n_retrievals),
46692- atomic_read(&fscache_n_retrievals_ok),
46693- atomic_read(&fscache_n_retrievals_wait),
46694- atomic_read(&fscache_n_retrievals_nodata),
46695- atomic_read(&fscache_n_retrievals_nobufs),
46696- atomic_read(&fscache_n_retrievals_intr),
46697- atomic_read(&fscache_n_retrievals_nomem));
46698+ atomic_read_unchecked(&fscache_n_retrievals),
46699+ atomic_read_unchecked(&fscache_n_retrievals_ok),
46700+ atomic_read_unchecked(&fscache_n_retrievals_wait),
46701+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
46702+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46703+ atomic_read_unchecked(&fscache_n_retrievals_intr),
46704+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
46705 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46706- atomic_read(&fscache_n_retrieval_ops),
46707- atomic_read(&fscache_n_retrieval_op_waits),
46708- atomic_read(&fscache_n_retrievals_object_dead));
46709+ atomic_read_unchecked(&fscache_n_retrieval_ops),
46710+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46711+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46712
46713 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46714- atomic_read(&fscache_n_stores),
46715- atomic_read(&fscache_n_stores_ok),
46716- atomic_read(&fscache_n_stores_again),
46717- atomic_read(&fscache_n_stores_nobufs),
46718- atomic_read(&fscache_n_stores_oom));
46719+ atomic_read_unchecked(&fscache_n_stores),
46720+ atomic_read_unchecked(&fscache_n_stores_ok),
46721+ atomic_read_unchecked(&fscache_n_stores_again),
46722+ atomic_read_unchecked(&fscache_n_stores_nobufs),
46723+ atomic_read_unchecked(&fscache_n_stores_oom));
46724 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46725- atomic_read(&fscache_n_store_ops),
46726- atomic_read(&fscache_n_store_calls),
46727- atomic_read(&fscache_n_store_pages),
46728- atomic_read(&fscache_n_store_radix_deletes),
46729- atomic_read(&fscache_n_store_pages_over_limit));
46730+ atomic_read_unchecked(&fscache_n_store_ops),
46731+ atomic_read_unchecked(&fscache_n_store_calls),
46732+ atomic_read_unchecked(&fscache_n_store_pages),
46733+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
46734+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46735
46736 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46737- atomic_read(&fscache_n_store_vmscan_not_storing),
46738- atomic_read(&fscache_n_store_vmscan_gone),
46739- atomic_read(&fscache_n_store_vmscan_busy),
46740- atomic_read(&fscache_n_store_vmscan_cancelled));
46741+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46742+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46743+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46744+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46745
46746 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46747- atomic_read(&fscache_n_op_pend),
46748- atomic_read(&fscache_n_op_run),
46749- atomic_read(&fscache_n_op_enqueue),
46750- atomic_read(&fscache_n_op_cancelled),
46751- atomic_read(&fscache_n_op_rejected));
46752+ atomic_read_unchecked(&fscache_n_op_pend),
46753+ atomic_read_unchecked(&fscache_n_op_run),
46754+ atomic_read_unchecked(&fscache_n_op_enqueue),
46755+ atomic_read_unchecked(&fscache_n_op_cancelled),
46756+ atomic_read_unchecked(&fscache_n_op_rejected));
46757 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46758- atomic_read(&fscache_n_op_deferred_release),
46759- atomic_read(&fscache_n_op_release),
46760- atomic_read(&fscache_n_op_gc));
46761+ atomic_read_unchecked(&fscache_n_op_deferred_release),
46762+ atomic_read_unchecked(&fscache_n_op_release),
46763+ atomic_read_unchecked(&fscache_n_op_gc));
46764
46765 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46766 atomic_read(&fscache_n_cop_alloc_object),
46767diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46768index 3426521..3b75162 100644
46769--- a/fs/fuse/cuse.c
46770+++ b/fs/fuse/cuse.c
46771@@ -587,10 +587,12 @@ static int __init cuse_init(void)
46772 INIT_LIST_HEAD(&cuse_conntbl[i]);
46773
46774 /* inherit and extend fuse_dev_operations */
46775- cuse_channel_fops = fuse_dev_operations;
46776- cuse_channel_fops.owner = THIS_MODULE;
46777- cuse_channel_fops.open = cuse_channel_open;
46778- cuse_channel_fops.release = cuse_channel_release;
46779+ pax_open_kernel();
46780+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46781+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46782+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
46783+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
46784+ pax_close_kernel();
46785
46786 cuse_class = class_create(THIS_MODULE, "cuse");
46787 if (IS_ERR(cuse_class))
46788diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46789index 7df2b5e..5804aa7 100644
46790--- a/fs/fuse/dev.c
46791+++ b/fs/fuse/dev.c
46792@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46793 ret = 0;
46794 pipe_lock(pipe);
46795
46796- if (!pipe->readers) {
46797+ if (!atomic_read(&pipe->readers)) {
46798 send_sig(SIGPIPE, current, 0);
46799 if (!ret)
46800 ret = -EPIPE;
46801diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46802index 334e0b1..fc571e8 100644
46803--- a/fs/fuse/dir.c
46804+++ b/fs/fuse/dir.c
46805@@ -1189,7 +1189,7 @@ static char *read_link(struct dentry *dentry)
46806 return link;
46807 }
46808
46809-static void free_link(char *link)
46810+static void free_link(const char *link)
46811 {
46812 if (!IS_ERR(link))
46813 free_page((unsigned long) link);
46814diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46815index a9ba244..d9df391 100644
46816--- a/fs/gfs2/inode.c
46817+++ b/fs/gfs2/inode.c
46818@@ -1496,7 +1496,7 @@ out:
46819
46820 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46821 {
46822- char *s = nd_get_link(nd);
46823+ const char *s = nd_get_link(nd);
46824 if (!IS_ERR(s))
46825 kfree(s);
46826 }
46827diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46828index cc9281b..58996fb 100644
46829--- a/fs/hugetlbfs/inode.c
46830+++ b/fs/hugetlbfs/inode.c
46831@@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46832 .kill_sb = kill_litter_super,
46833 };
46834
46835-static struct vfsmount *hugetlbfs_vfsmount;
46836+struct vfsmount *hugetlbfs_vfsmount;
46837
46838 static int can_do_hugetlb_shm(void)
46839 {
46840diff --git a/fs/inode.c b/fs/inode.c
46841index c99163b..a11ad40 100644
46842--- a/fs/inode.c
46843+++ b/fs/inode.c
46844@@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
46845
46846 #ifdef CONFIG_SMP
46847 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46848- static atomic_t shared_last_ino;
46849- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46850+ static atomic_unchecked_t shared_last_ino;
46851+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46852
46853 res = next - LAST_INO_BATCH;
46854 }
46855diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46856index 4a6cf28..d3a29d3 100644
46857--- a/fs/jffs2/erase.c
46858+++ b/fs/jffs2/erase.c
46859@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46860 struct jffs2_unknown_node marker = {
46861 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46862 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46863- .totlen = cpu_to_je32(c->cleanmarker_size)
46864+ .totlen = cpu_to_je32(c->cleanmarker_size),
46865+ .hdr_crc = cpu_to_je32(0)
46866 };
46867
46868 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46869diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46870index 6f4529d..bf12806 100644
46871--- a/fs/jffs2/wbuf.c
46872+++ b/fs/jffs2/wbuf.c
46873@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46874 {
46875 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46876 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46877- .totlen = constant_cpu_to_je32(8)
46878+ .totlen = constant_cpu_to_je32(8),
46879+ .hdr_crc = constant_cpu_to_je32(0)
46880 };
46881
46882 /*
46883diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46884index 4a82950..bcaa0cb 100644
46885--- a/fs/jfs/super.c
46886+++ b/fs/jfs/super.c
46887@@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46888
46889 jfs_inode_cachep =
46890 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46891- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46892+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46893 init_once);
46894 if (jfs_inode_cachep == NULL)
46895 return -ENOMEM;
46896diff --git a/fs/libfs.c b/fs/libfs.c
46897index f86ec27..4734776 100644
46898--- a/fs/libfs.c
46899+++ b/fs/libfs.c
46900@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46901
46902 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46903 struct dentry *next;
46904+ char d_name[sizeof(next->d_iname)];
46905+ const unsigned char *name;
46906+
46907 next = list_entry(p, struct dentry, d_u.d_child);
46908 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46909 if (!simple_positive(next)) {
46910@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46911
46912 spin_unlock(&next->d_lock);
46913 spin_unlock(&dentry->d_lock);
46914- if (filldir(dirent, next->d_name.name,
46915+ name = next->d_name.name;
46916+ if (name == next->d_iname) {
46917+ memcpy(d_name, name, next->d_name.len);
46918+ name = d_name;
46919+ }
46920+ if (filldir(dirent, name,
46921 next->d_name.len, filp->f_pos,
46922 next->d_inode->i_ino,
46923 dt_type(next->d_inode)) < 0)
46924diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46925index 8392cb8..80d6193 100644
46926--- a/fs/lockd/clntproc.c
46927+++ b/fs/lockd/clntproc.c
46928@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46929 /*
46930 * Cookie counter for NLM requests
46931 */
46932-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46933+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46934
46935 void nlmclnt_next_cookie(struct nlm_cookie *c)
46936 {
46937- u32 cookie = atomic_inc_return(&nlm_cookie);
46938+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46939
46940 memcpy(c->data, &cookie, 4);
46941 c->len=4;
46942diff --git a/fs/locks.c b/fs/locks.c
46943index fce6238..34e929c 100644
46944--- a/fs/locks.c
46945+++ b/fs/locks.c
46946@@ -308,7 +308,7 @@ static int flock_make_lock(struct file *filp, struct file_lock **lock,
46947 return 0;
46948 }
46949
46950-static int assign_type(struct file_lock *fl, int type)
46951+static int assign_type(struct file_lock *fl, long type)
46952 {
46953 switch (type) {
46954 case F_RDLCK:
46955@@ -445,7 +445,7 @@ static const struct lock_manager_operations lease_manager_ops = {
46956 /*
46957 * Initialize a lease, use the default lock manager operations
46958 */
46959-static int lease_init(struct file *filp, int type, struct file_lock *fl)
46960+static int lease_init(struct file *filp, long type, struct file_lock *fl)
46961 {
46962 if (assign_type(fl, type) != 0)
46963 return -EINVAL;
46964@@ -463,7 +463,7 @@ static int lease_init(struct file *filp, int type, struct file_lock *fl)
46965 }
46966
46967 /* Allocate a file_lock initialised to this type of lease */
46968-static struct file_lock *lease_alloc(struct file *filp, int type)
46969+static struct file_lock *lease_alloc(struct file *filp, long type)
46970 {
46971 struct file_lock *fl = locks_alloc_lock();
46972 int error = -ENOMEM;
46973@@ -2076,16 +2076,16 @@ void locks_remove_flock(struct file *filp)
46974 return;
46975
46976 if (filp->f_op && filp->f_op->flock) {
46977- struct file_lock fl = {
46978+ struct file_lock flock = {
46979 .fl_pid = current->tgid,
46980 .fl_file = filp,
46981 .fl_flags = FL_FLOCK,
46982 .fl_type = F_UNLCK,
46983 .fl_end = OFFSET_MAX,
46984 };
46985- filp->f_op->flock(filp, F_SETLKW, &fl);
46986- if (fl.fl_ops && fl.fl_ops->fl_release_private)
46987- fl.fl_ops->fl_release_private(&fl);
46988+ filp->f_op->flock(filp, F_SETLKW, &flock);
46989+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
46990+ flock.fl_ops->fl_release_private(&flock);
46991 }
46992
46993 lock_flocks();
46994diff --git a/fs/namei.c b/fs/namei.c
46995index 7d69419..1487852 100644
46996--- a/fs/namei.c
46997+++ b/fs/namei.c
46998@@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
46999 if (ret != -EACCES)
47000 return ret;
47001
47002+#ifdef CONFIG_GRKERNSEC
47003+ /* we'll block if we have to log due to a denied capability use */
47004+ if (mask & MAY_NOT_BLOCK)
47005+ return -ECHILD;
47006+#endif
47007+
47008 if (S_ISDIR(inode->i_mode)) {
47009 /* DACs are overridable for directories */
47010- if (inode_capable(inode, CAP_DAC_OVERRIDE))
47011- return 0;
47012 if (!(mask & MAY_WRITE))
47013- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47014+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47015+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47016 return 0;
47017+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
47018+ return 0;
47019 return -EACCES;
47020 }
47021 /*
47022+ * Searching includes executable on directories, else just read.
47023+ */
47024+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47025+ if (mask == MAY_READ)
47026+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47027+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47028+ return 0;
47029+
47030+ /*
47031 * Read/write DACs are always overridable.
47032 * Executable DACs are overridable when there is
47033 * at least one exec bit set.
47034@@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47035 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47036 return 0;
47037
47038- /*
47039- * Searching includes executable on directories, else just read.
47040- */
47041- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47042- if (mask == MAY_READ)
47043- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47044- return 0;
47045-
47046 return -EACCES;
47047 }
47048
47049@@ -639,11 +647,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47050 return error;
47051 }
47052
47053+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
47054+ dentry->d_inode, dentry, nd->path.mnt)) {
47055+ error = -EACCES;
47056+ *p = ERR_PTR(error); /* no ->put_link(), please */
47057+ path_put(&nd->path);
47058+ return error;
47059+ }
47060+
47061 nd->last_type = LAST_BIND;
47062 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47063 error = PTR_ERR(*p);
47064 if (!IS_ERR(*p)) {
47065- char *s = nd_get_link(nd);
47066+ const char *s = nd_get_link(nd);
47067 error = 0;
47068 if (s)
47069 error = __vfs_follow_link(nd, s);
47070@@ -1386,6 +1402,9 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47071 if (!res)
47072 res = walk_component(nd, path, &nd->last,
47073 nd->last_type, LOOKUP_FOLLOW);
47074+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode)) {
47075+ res = -EACCES;
47076+ }
47077 put_link(nd, &link, cookie);
47078 } while (res > 0);
47079
47080@@ -1779,6 +1798,9 @@ static int path_lookupat(int dfd, const char *name,
47081 err = follow_link(&link, nd, &cookie);
47082 if (!err)
47083 err = lookup_last(nd, &path);
47084+ if (!err && gr_handle_symlink_owner(&link, nd->inode)) {
47085+ err = -EACCES;
47086+ }
47087 put_link(nd, &link, cookie);
47088 }
47089 }
47090@@ -1786,6 +1808,21 @@ static int path_lookupat(int dfd, const char *name,
47091 if (!err)
47092 err = complete_walk(nd);
47093
47094+ if (!(nd->flags & LOOKUP_PARENT)) {
47095+#ifdef CONFIG_GRKERNSEC
47096+ if (flags & LOOKUP_RCU) {
47097+ if (!err)
47098+ path_put(&nd->path);
47099+ err = -ECHILD;
47100+ } else
47101+#endif
47102+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47103+ if (!err)
47104+ path_put(&nd->path);
47105+ err = -ENOENT;
47106+ }
47107+ }
47108+
47109 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47110 if (!nd->inode->i_op->lookup) {
47111 path_put(&nd->path);
47112@@ -1813,6 +1850,15 @@ static int do_path_lookup(int dfd, const char *name,
47113 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47114
47115 if (likely(!retval)) {
47116+ if (*name != '/' && nd->path.dentry && nd->inode) {
47117+#ifdef CONFIG_GRKERNSEC
47118+ if (flags & LOOKUP_RCU)
47119+ return -ECHILD;
47120+#endif
47121+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47122+ return -ENOENT;
47123+ }
47124+
47125 if (unlikely(!audit_dummy_context())) {
47126 if (nd->path.dentry && nd->inode)
47127 audit_inode(name, nd->path.dentry);
47128@@ -2155,6 +2201,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47129 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47130 return -EPERM;
47131
47132+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47133+ return -EPERM;
47134+ if (gr_handle_rawio(inode))
47135+ return -EPERM;
47136+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47137+ return -EACCES;
47138+
47139 return 0;
47140 }
47141
47142@@ -2220,6 +2273,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47143 error = complete_walk(nd);
47144 if (error)
47145 return ERR_PTR(error);
47146+#ifdef CONFIG_GRKERNSEC
47147+ if (nd->flags & LOOKUP_RCU) {
47148+ error = -ECHILD;
47149+ goto exit;
47150+ }
47151+#endif
47152+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47153+ error = -ENOENT;
47154+ goto exit;
47155+ }
47156 audit_inode(pathname, nd->path.dentry);
47157 if (open_flag & O_CREAT) {
47158 error = -EISDIR;
47159@@ -2230,6 +2293,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47160 error = complete_walk(nd);
47161 if (error)
47162 return ERR_PTR(error);
47163+#ifdef CONFIG_GRKERNSEC
47164+ if (nd->flags & LOOKUP_RCU) {
47165+ error = -ECHILD;
47166+ goto exit;
47167+ }
47168+#endif
47169+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47170+ error = -ENOENT;
47171+ goto exit;
47172+ }
47173 audit_inode(pathname, dir);
47174 goto ok;
47175 }
47176@@ -2285,6 +2358,12 @@ retry_lookup:
47177 /* Negative dentry, just create the file */
47178 if (!dentry->d_inode) {
47179 umode_t mode = op->mode;
47180+
47181+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47182+ error = -EACCES;
47183+ goto exit_mutex_unlock;
47184+ }
47185+
47186 if (!IS_POSIXACL(dir->d_inode))
47187 mode &= ~current_umask();
47188 /*
47189@@ -2308,6 +2387,8 @@ retry_lookup:
47190 error = vfs_create(dir->d_inode, dentry, mode, nd);
47191 if (error)
47192 goto exit_mutex_unlock;
47193+ else
47194+ gr_handle_create(path->dentry, path->mnt);
47195 mutex_unlock(&dir->d_inode->i_mutex);
47196 dput(nd->path.dentry);
47197 nd->path.dentry = dentry;
47198@@ -2317,6 +2398,19 @@ retry_lookup:
47199 /*
47200 * It already exists.
47201 */
47202+
47203+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47204+ error = -ENOENT;
47205+ goto exit_mutex_unlock;
47206+ }
47207+
47208+ /* only check if O_CREAT is specified, all other checks need to go
47209+ into may_open */
47210+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47211+ error = -EACCES;
47212+ goto exit_mutex_unlock;
47213+ }
47214+
47215 mutex_unlock(&dir->d_inode->i_mutex);
47216 audit_inode(pathname, path->dentry);
47217
47218@@ -2367,6 +2461,16 @@ finish_lookup:
47219 path_put(&save_parent);
47220 return ERR_PTR(error);
47221 }
47222+#ifdef CONFIG_GRKERNSEC
47223+ if (nd->flags & LOOKUP_RCU) {
47224+ error = -ECHILD;
47225+ goto exit;
47226+ }
47227+#endif
47228+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47229+ error = -ENOENT;
47230+ goto exit;
47231+ }
47232 error = -EISDIR;
47233 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47234 goto exit;
47235@@ -2476,8 +2580,14 @@ static struct file *path_openat(int dfd, const char *pathname,
47236 error = follow_link(&link, nd, &cookie);
47237 if (unlikely(error))
47238 filp = ERR_PTR(error);
47239- else
47240+ else {
47241 filp = do_last(nd, &path, op, pathname);
47242+ if (!IS_ERR(filp) && gr_handle_symlink_owner(&link, nd->inode)) {
47243+ if (filp)
47244+ fput(filp);
47245+ filp = ERR_PTR(-EACCES);
47246+ }
47247+ }
47248 put_link(nd, &link, cookie);
47249 }
47250 out:
47251@@ -2577,6 +2687,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47252 *path = nd.path;
47253 return dentry;
47254 eexist:
47255+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47256+ dput(dentry);
47257+ dentry = ERR_PTR(-ENOENT);
47258+ goto fail;
47259+ }
47260 dput(dentry);
47261 dentry = ERR_PTR(-EEXIST);
47262 fail:
47263@@ -2599,6 +2714,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47264 }
47265 EXPORT_SYMBOL(user_path_create);
47266
47267+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47268+{
47269+ char *tmp = getname(pathname);
47270+ struct dentry *res;
47271+ if (IS_ERR(tmp))
47272+ return ERR_CAST(tmp);
47273+ res = kern_path_create(dfd, tmp, path, is_dir);
47274+ if (IS_ERR(res))
47275+ putname(tmp);
47276+ else
47277+ *to = tmp;
47278+ return res;
47279+}
47280+
47281 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47282 {
47283 int error = may_create(dir, dentry);
47284@@ -2665,6 +2794,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47285 error = mnt_want_write(path.mnt);
47286 if (error)
47287 goto out_dput;
47288+
47289+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47290+ error = -EPERM;
47291+ goto out_drop_write;
47292+ }
47293+
47294+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47295+ error = -EACCES;
47296+ goto out_drop_write;
47297+ }
47298+
47299 error = security_path_mknod(&path, dentry, mode, dev);
47300 if (error)
47301 goto out_drop_write;
47302@@ -2682,6 +2822,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47303 }
47304 out_drop_write:
47305 mnt_drop_write(path.mnt);
47306+
47307+ if (!error)
47308+ gr_handle_create(dentry, path.mnt);
47309 out_dput:
47310 dput(dentry);
47311 mutex_unlock(&path.dentry->d_inode->i_mutex);
47312@@ -2735,12 +2878,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47313 error = mnt_want_write(path.mnt);
47314 if (error)
47315 goto out_dput;
47316+
47317+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47318+ error = -EACCES;
47319+ goto out_drop_write;
47320+ }
47321+
47322 error = security_path_mkdir(&path, dentry, mode);
47323 if (error)
47324 goto out_drop_write;
47325 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47326 out_drop_write:
47327 mnt_drop_write(path.mnt);
47328+
47329+ if (!error)
47330+ gr_handle_create(dentry, path.mnt);
47331 out_dput:
47332 dput(dentry);
47333 mutex_unlock(&path.dentry->d_inode->i_mutex);
47334@@ -2820,6 +2972,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47335 char * name;
47336 struct dentry *dentry;
47337 struct nameidata nd;
47338+ ino_t saved_ino = 0;
47339+ dev_t saved_dev = 0;
47340
47341 error = user_path_parent(dfd, pathname, &nd, &name);
47342 if (error)
47343@@ -2848,6 +3002,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47344 error = -ENOENT;
47345 goto exit3;
47346 }
47347+
47348+ saved_ino = dentry->d_inode->i_ino;
47349+ saved_dev = gr_get_dev_from_dentry(dentry);
47350+
47351+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47352+ error = -EACCES;
47353+ goto exit3;
47354+ }
47355+
47356 error = mnt_want_write(nd.path.mnt);
47357 if (error)
47358 goto exit3;
47359@@ -2855,6 +3018,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47360 if (error)
47361 goto exit4;
47362 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47363+ if (!error && (saved_dev || saved_ino))
47364+ gr_handle_delete(saved_ino, saved_dev);
47365 exit4:
47366 mnt_drop_write(nd.path.mnt);
47367 exit3:
47368@@ -2917,6 +3082,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47369 struct dentry *dentry;
47370 struct nameidata nd;
47371 struct inode *inode = NULL;
47372+ ino_t saved_ino = 0;
47373+ dev_t saved_dev = 0;
47374
47375 error = user_path_parent(dfd, pathname, &nd, &name);
47376 if (error)
47377@@ -2939,6 +3106,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47378 if (!inode)
47379 goto slashes;
47380 ihold(inode);
47381+
47382+ if (inode->i_nlink <= 1) {
47383+ saved_ino = inode->i_ino;
47384+ saved_dev = gr_get_dev_from_dentry(dentry);
47385+ }
47386+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47387+ error = -EACCES;
47388+ goto exit2;
47389+ }
47390+
47391 error = mnt_want_write(nd.path.mnt);
47392 if (error)
47393 goto exit2;
47394@@ -2946,6 +3123,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47395 if (error)
47396 goto exit3;
47397 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47398+ if (!error && (saved_ino || saved_dev))
47399+ gr_handle_delete(saved_ino, saved_dev);
47400 exit3:
47401 mnt_drop_write(nd.path.mnt);
47402 exit2:
47403@@ -3021,10 +3200,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47404 error = mnt_want_write(path.mnt);
47405 if (error)
47406 goto out_dput;
47407+
47408+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47409+ error = -EACCES;
47410+ goto out_drop_write;
47411+ }
47412+
47413 error = security_path_symlink(&path, dentry, from);
47414 if (error)
47415 goto out_drop_write;
47416 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47417+ if (!error)
47418+ gr_handle_create(dentry, path.mnt);
47419 out_drop_write:
47420 mnt_drop_write(path.mnt);
47421 out_dput:
47422@@ -3099,6 +3286,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47423 {
47424 struct dentry *new_dentry;
47425 struct path old_path, new_path;
47426+ char *to = NULL;
47427 int how = 0;
47428 int error;
47429
47430@@ -3122,7 +3310,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47431 if (error)
47432 return error;
47433
47434- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47435+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47436 error = PTR_ERR(new_dentry);
47437 if (IS_ERR(new_dentry))
47438 goto out;
47439@@ -3133,13 +3321,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47440 error = mnt_want_write(new_path.mnt);
47441 if (error)
47442 goto out_dput;
47443+
47444+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47445+ old_path.dentry->d_inode,
47446+ old_path.dentry->d_inode->i_mode, to)) {
47447+ error = -EACCES;
47448+ goto out_drop_write;
47449+ }
47450+
47451+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47452+ old_path.dentry, old_path.mnt, to)) {
47453+ error = -EACCES;
47454+ goto out_drop_write;
47455+ }
47456+
47457 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47458 if (error)
47459 goto out_drop_write;
47460 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47461+ if (!error)
47462+ gr_handle_create(new_dentry, new_path.mnt);
47463 out_drop_write:
47464 mnt_drop_write(new_path.mnt);
47465 out_dput:
47466+ putname(to);
47467 dput(new_dentry);
47468 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47469 path_put(&new_path);
47470@@ -3373,6 +3578,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47471 if (new_dentry == trap)
47472 goto exit5;
47473
47474+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47475+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
47476+ to);
47477+ if (error)
47478+ goto exit5;
47479+
47480 error = mnt_want_write(oldnd.path.mnt);
47481 if (error)
47482 goto exit5;
47483@@ -3382,6 +3593,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47484 goto exit6;
47485 error = vfs_rename(old_dir->d_inode, old_dentry,
47486 new_dir->d_inode, new_dentry);
47487+ if (!error)
47488+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47489+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47490 exit6:
47491 mnt_drop_write(oldnd.path.mnt);
47492 exit5:
47493@@ -3407,6 +3621,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47494
47495 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47496 {
47497+ char tmpbuf[64];
47498+ const char *newlink;
47499 int len;
47500
47501 len = PTR_ERR(link);
47502@@ -3416,7 +3632,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47503 len = strlen(link);
47504 if (len > (unsigned) buflen)
47505 len = buflen;
47506- if (copy_to_user(buffer, link, len))
47507+
47508+ if (len < sizeof(tmpbuf)) {
47509+ memcpy(tmpbuf, link, len);
47510+ newlink = tmpbuf;
47511+ } else
47512+ newlink = link;
47513+
47514+ if (copy_to_user(buffer, newlink, len))
47515 len = -EFAULT;
47516 out:
47517 return len;
47518diff --git a/fs/namespace.c b/fs/namespace.c
47519index 1e4a5fe..a5ce747 100644
47520--- a/fs/namespace.c
47521+++ b/fs/namespace.c
47522@@ -1157,6 +1157,9 @@ static int do_umount(struct mount *mnt, int flags)
47523 if (!(sb->s_flags & MS_RDONLY))
47524 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47525 up_write(&sb->s_umount);
47526+
47527+ gr_log_remount(mnt->mnt_devname, retval);
47528+
47529 return retval;
47530 }
47531
47532@@ -1176,6 +1179,9 @@ static int do_umount(struct mount *mnt, int flags)
47533 br_write_unlock(&vfsmount_lock);
47534 up_write(&namespace_sem);
47535 release_mounts(&umount_list);
47536+
47537+ gr_log_unmount(mnt->mnt_devname, retval);
47538+
47539 return retval;
47540 }
47541
47542@@ -2177,6 +2183,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47543 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47544 MS_STRICTATIME);
47545
47546+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47547+ retval = -EPERM;
47548+ goto dput_out;
47549+ }
47550+
47551+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47552+ retval = -EPERM;
47553+ goto dput_out;
47554+ }
47555+
47556 if (flags & MS_REMOUNT)
47557 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47558 data_page);
47559@@ -2191,6 +2207,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47560 dev_name, data_page);
47561 dput_out:
47562 path_put(&path);
47563+
47564+ gr_log_mount(dev_name, dir_name, retval);
47565+
47566 return retval;
47567 }
47568
47569@@ -2472,6 +2491,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47570 if (error)
47571 goto out2;
47572
47573+ if (gr_handle_chroot_pivot()) {
47574+ error = -EPERM;
47575+ goto out2;
47576+ }
47577+
47578 get_fs_root(current->fs, &root);
47579 error = lock_mount(&old);
47580 if (error)
47581diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47582index f729698..2bac081 100644
47583--- a/fs/nfs/inode.c
47584+++ b/fs/nfs/inode.c
47585@@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47586 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47587 nfsi->attrtimeo_timestamp = jiffies;
47588
47589- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47590+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47591 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47592 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47593 else
47594@@ -1008,16 +1008,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47595 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47596 }
47597
47598-static atomic_long_t nfs_attr_generation_counter;
47599+static atomic_long_unchecked_t nfs_attr_generation_counter;
47600
47601 static unsigned long nfs_read_attr_generation_counter(void)
47602 {
47603- return atomic_long_read(&nfs_attr_generation_counter);
47604+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47605 }
47606
47607 unsigned long nfs_inc_attr_generation_counter(void)
47608 {
47609- return atomic_long_inc_return(&nfs_attr_generation_counter);
47610+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47611 }
47612
47613 void nfs_fattr_init(struct nfs_fattr *fattr)
47614diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47615index c8bd9c3..4f83416 100644
47616--- a/fs/nfsd/vfs.c
47617+++ b/fs/nfsd/vfs.c
47618@@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47619 } else {
47620 oldfs = get_fs();
47621 set_fs(KERNEL_DS);
47622- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47623+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47624 set_fs(oldfs);
47625 }
47626
47627@@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47628
47629 /* Write the data. */
47630 oldfs = get_fs(); set_fs(KERNEL_DS);
47631- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47632+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47633 set_fs(oldfs);
47634 if (host_err < 0)
47635 goto out_nfserr;
47636@@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47637 */
47638
47639 oldfs = get_fs(); set_fs(KERNEL_DS);
47640- host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
47641+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
47642 set_fs(oldfs);
47643
47644 if (host_err < 0)
47645diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47646index 3568c8a..e0240d8 100644
47647--- a/fs/notify/fanotify/fanotify_user.c
47648+++ b/fs/notify/fanotify/fanotify_user.c
47649@@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47650 goto out_close_fd;
47651
47652 ret = -EFAULT;
47653- if (copy_to_user(buf, &fanotify_event_metadata,
47654+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47655+ copy_to_user(buf, &fanotify_event_metadata,
47656 fanotify_event_metadata.event_len))
47657 goto out_kill_access_response;
47658
47659diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47660index c887b13..0fdf472 100644
47661--- a/fs/notify/notification.c
47662+++ b/fs/notify/notification.c
47663@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47664 * get set to 0 so it will never get 'freed'
47665 */
47666 static struct fsnotify_event *q_overflow_event;
47667-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47668+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47669
47670 /**
47671 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47672@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47673 */
47674 u32 fsnotify_get_cookie(void)
47675 {
47676- return atomic_inc_return(&fsnotify_sync_cookie);
47677+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47678 }
47679 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47680
47681diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47682index 99e3610..02c1068 100644
47683--- a/fs/ntfs/dir.c
47684+++ b/fs/ntfs/dir.c
47685@@ -1329,7 +1329,7 @@ find_next_index_buffer:
47686 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47687 ~(s64)(ndir->itype.index.block_size - 1)));
47688 /* Bounds checks. */
47689- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47690+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47691 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47692 "inode 0x%lx or driver bug.", vdir->i_ino);
47693 goto err_out;
47694diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47695index 7389d2d..dfd5dbe 100644
47696--- a/fs/ntfs/file.c
47697+++ b/fs/ntfs/file.c
47698@@ -2231,6 +2231,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47699 #endif /* NTFS_RW */
47700 };
47701
47702-const struct file_operations ntfs_empty_file_ops = {};
47703+const struct file_operations ntfs_empty_file_ops __read_only;
47704
47705-const struct inode_operations ntfs_empty_inode_ops = {};
47706+const struct inode_operations ntfs_empty_inode_ops __read_only;
47707diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47708index 210c352..a174f83 100644
47709--- a/fs/ocfs2/localalloc.c
47710+++ b/fs/ocfs2/localalloc.c
47711@@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47712 goto bail;
47713 }
47714
47715- atomic_inc(&osb->alloc_stats.moves);
47716+ atomic_inc_unchecked(&osb->alloc_stats.moves);
47717
47718 bail:
47719 if (handle)
47720diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47721index d355e6e..578d905 100644
47722--- a/fs/ocfs2/ocfs2.h
47723+++ b/fs/ocfs2/ocfs2.h
47724@@ -235,11 +235,11 @@ enum ocfs2_vol_state
47725
47726 struct ocfs2_alloc_stats
47727 {
47728- atomic_t moves;
47729- atomic_t local_data;
47730- atomic_t bitmap_data;
47731- atomic_t bg_allocs;
47732- atomic_t bg_extends;
47733+ atomic_unchecked_t moves;
47734+ atomic_unchecked_t local_data;
47735+ atomic_unchecked_t bitmap_data;
47736+ atomic_unchecked_t bg_allocs;
47737+ atomic_unchecked_t bg_extends;
47738 };
47739
47740 enum ocfs2_local_alloc_state
47741diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47742index f169da4..9112253 100644
47743--- a/fs/ocfs2/suballoc.c
47744+++ b/fs/ocfs2/suballoc.c
47745@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47746 mlog_errno(status);
47747 goto bail;
47748 }
47749- atomic_inc(&osb->alloc_stats.bg_extends);
47750+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47751
47752 /* You should never ask for this much metadata */
47753 BUG_ON(bits_wanted >
47754@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47755 mlog_errno(status);
47756 goto bail;
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 *suballoc_loc = res.sr_bg_blkno;
47762 *suballoc_bit_start = res.sr_bit_offset;
47763@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47764 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47765 res->sr_bits);
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@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47773 mlog_errno(status);
47774 goto bail;
47775 }
47776- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47777+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47778
47779 BUG_ON(res.sr_bits != 1);
47780
47781@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47782 cluster_start,
47783 num_clusters);
47784 if (!status)
47785- atomic_inc(&osb->alloc_stats.local_data);
47786+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
47787 } else {
47788 if (min_clusters > (osb->bitmap_cpg - 1)) {
47789 /* The only paths asking for contiguousness
47790@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47791 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47792 res.sr_bg_blkno,
47793 res.sr_bit_offset);
47794- atomic_inc(&osb->alloc_stats.bitmap_data);
47795+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47796 *num_clusters = res.sr_bits;
47797 }
47798 }
47799diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47800index 68f4541..89cfe6a 100644
47801--- a/fs/ocfs2/super.c
47802+++ b/fs/ocfs2/super.c
47803@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47804 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47805 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47806 "Stats",
47807- atomic_read(&osb->alloc_stats.bitmap_data),
47808- atomic_read(&osb->alloc_stats.local_data),
47809- atomic_read(&osb->alloc_stats.bg_allocs),
47810- atomic_read(&osb->alloc_stats.moves),
47811- atomic_read(&osb->alloc_stats.bg_extends));
47812+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47813+ atomic_read_unchecked(&osb->alloc_stats.local_data),
47814+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47815+ atomic_read_unchecked(&osb->alloc_stats.moves),
47816+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47817
47818 out += snprintf(buf + out, len - out,
47819 "%10s => State: %u Descriptor: %llu Size: %u bits "
47820@@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47821 spin_lock_init(&osb->osb_xattr_lock);
47822 ocfs2_init_steal_slots(osb);
47823
47824- atomic_set(&osb->alloc_stats.moves, 0);
47825- atomic_set(&osb->alloc_stats.local_data, 0);
47826- atomic_set(&osb->alloc_stats.bitmap_data, 0);
47827- atomic_set(&osb->alloc_stats.bg_allocs, 0);
47828- atomic_set(&osb->alloc_stats.bg_extends, 0);
47829+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47830+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47831+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47832+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47833+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47834
47835 /* Copy the blockcheck stats from the superblock probe */
47836 osb->osb_ecc_stats = *stats;
47837diff --git a/fs/open.c b/fs/open.c
47838index 1540632..79d7242 100644
47839--- a/fs/open.c
47840+++ b/fs/open.c
47841@@ -31,6 +31,8 @@
47842 #include <linux/ima.h>
47843 #include <linux/dnotify.h>
47844
47845+#define CREATE_TRACE_POINTS
47846+#include <trace/events/fs.h>
47847 #include "internal.h"
47848
47849 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
47850@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47851 error = locks_verify_truncate(inode, NULL, length);
47852 if (!error)
47853 error = security_path_truncate(&path);
47854+
47855+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47856+ error = -EACCES;
47857+
47858 if (!error)
47859 error = do_truncate(path.dentry, length, 0, NULL);
47860
47861@@ -359,6 +365,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47862 if (__mnt_is_readonly(path.mnt))
47863 res = -EROFS;
47864
47865+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47866+ res = -EACCES;
47867+
47868 out_path_release:
47869 path_put(&path);
47870 out:
47871@@ -385,6 +394,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47872 if (error)
47873 goto dput_and_out;
47874
47875+ gr_log_chdir(path.dentry, path.mnt);
47876+
47877 set_fs_pwd(current->fs, &path);
47878
47879 dput_and_out:
47880@@ -411,6 +422,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47881 goto out_putf;
47882
47883 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47884+
47885+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47886+ error = -EPERM;
47887+
47888+ if (!error)
47889+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47890+
47891 if (!error)
47892 set_fs_pwd(current->fs, &file->f_path);
47893 out_putf:
47894@@ -439,7 +457,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47895 if (error)
47896 goto dput_and_out;
47897
47898+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47899+ goto dput_and_out;
47900+
47901 set_fs_root(current->fs, &path);
47902+
47903+ gr_handle_chroot_chdir(&path);
47904+
47905 error = 0;
47906 dput_and_out:
47907 path_put(&path);
47908@@ -457,6 +481,16 @@ static int chmod_common(struct path *path, umode_t mode)
47909 if (error)
47910 return error;
47911 mutex_lock(&inode->i_mutex);
47912+
47913+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47914+ error = -EACCES;
47915+ goto out_unlock;
47916+ }
47917+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47918+ error = -EACCES;
47919+ goto out_unlock;
47920+ }
47921+
47922 error = security_path_chmod(path, mode);
47923 if (error)
47924 goto out_unlock;
47925@@ -512,6 +546,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47926 uid = make_kuid(current_user_ns(), user);
47927 gid = make_kgid(current_user_ns(), group);
47928
47929+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
47930+ return -EACCES;
47931+
47932 newattrs.ia_valid = ATTR_CTIME;
47933 if (user != (uid_t) -1) {
47934 if (!uid_valid(uid))
47935@@ -1035,6 +1072,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
47936 } else {
47937 fsnotify_open(f);
47938 fd_install(fd, f);
47939+ trace_do_sys_open(tmp, flags, mode);
47940 }
47941 }
47942 putname(tmp);
47943diff --git a/fs/pipe.c b/fs/pipe.c
47944index 49c1065..13b9e12 100644
47945--- a/fs/pipe.c
47946+++ b/fs/pipe.c
47947@@ -438,9 +438,9 @@ redo:
47948 }
47949 if (bufs) /* More to do? */
47950 continue;
47951- if (!pipe->writers)
47952+ if (!atomic_read(&pipe->writers))
47953 break;
47954- if (!pipe->waiting_writers) {
47955+ if (!atomic_read(&pipe->waiting_writers)) {
47956 /* syscall merging: Usually we must not sleep
47957 * if O_NONBLOCK is set, or if we got some data.
47958 * But if a writer sleeps in kernel space, then
47959@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47960 mutex_lock(&inode->i_mutex);
47961 pipe = inode->i_pipe;
47962
47963- if (!pipe->readers) {
47964+ if (!atomic_read(&pipe->readers)) {
47965 send_sig(SIGPIPE, current, 0);
47966 ret = -EPIPE;
47967 goto out;
47968@@ -553,7 +553,7 @@ redo1:
47969 for (;;) {
47970 int bufs;
47971
47972- if (!pipe->readers) {
47973+ if (!atomic_read(&pipe->readers)) {
47974 send_sig(SIGPIPE, current, 0);
47975 if (!ret)
47976 ret = -EPIPE;
47977@@ -644,9 +644,9 @@ redo2:
47978 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47979 do_wakeup = 0;
47980 }
47981- pipe->waiting_writers++;
47982+ atomic_inc(&pipe->waiting_writers);
47983 pipe_wait(pipe);
47984- pipe->waiting_writers--;
47985+ atomic_dec(&pipe->waiting_writers);
47986 }
47987 out:
47988 mutex_unlock(&inode->i_mutex);
47989@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47990 mask = 0;
47991 if (filp->f_mode & FMODE_READ) {
47992 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47993- if (!pipe->writers && filp->f_version != pipe->w_counter)
47994+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47995 mask |= POLLHUP;
47996 }
47997
47998@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47999 * Most Unices do not set POLLERR for FIFOs but on Linux they
48000 * behave exactly like pipes for poll().
48001 */
48002- if (!pipe->readers)
48003+ if (!atomic_read(&pipe->readers))
48004 mask |= POLLERR;
48005 }
48006
48007@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48008
48009 mutex_lock(&inode->i_mutex);
48010 pipe = inode->i_pipe;
48011- pipe->readers -= decr;
48012- pipe->writers -= decw;
48013+ atomic_sub(decr, &pipe->readers);
48014+ atomic_sub(decw, &pipe->writers);
48015
48016- if (!pipe->readers && !pipe->writers) {
48017+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48018 free_pipe_info(inode);
48019 } else {
48020 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48021@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48022
48023 if (inode->i_pipe) {
48024 ret = 0;
48025- inode->i_pipe->readers++;
48026+ atomic_inc(&inode->i_pipe->readers);
48027 }
48028
48029 mutex_unlock(&inode->i_mutex);
48030@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48031
48032 if (inode->i_pipe) {
48033 ret = 0;
48034- inode->i_pipe->writers++;
48035+ atomic_inc(&inode->i_pipe->writers);
48036 }
48037
48038 mutex_unlock(&inode->i_mutex);
48039@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48040 if (inode->i_pipe) {
48041 ret = 0;
48042 if (filp->f_mode & FMODE_READ)
48043- inode->i_pipe->readers++;
48044+ atomic_inc(&inode->i_pipe->readers);
48045 if (filp->f_mode & FMODE_WRITE)
48046- inode->i_pipe->writers++;
48047+ atomic_inc(&inode->i_pipe->writers);
48048 }
48049
48050 mutex_unlock(&inode->i_mutex);
48051@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48052 inode->i_pipe = NULL;
48053 }
48054
48055-static struct vfsmount *pipe_mnt __read_mostly;
48056+struct vfsmount *pipe_mnt __read_mostly;
48057
48058 /*
48059 * pipefs_dname() is called from d_path().
48060@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48061 goto fail_iput;
48062 inode->i_pipe = pipe;
48063
48064- pipe->readers = pipe->writers = 1;
48065+ atomic_set(&pipe->readers, 1);
48066+ atomic_set(&pipe->writers, 1);
48067 inode->i_fop = &rdwr_pipefifo_fops;
48068
48069 /*
48070diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48071index 15af622..0e9f4467 100644
48072--- a/fs/proc/Kconfig
48073+++ b/fs/proc/Kconfig
48074@@ -30,12 +30,12 @@ config PROC_FS
48075
48076 config PROC_KCORE
48077 bool "/proc/kcore support" if !ARM
48078- depends on PROC_FS && MMU
48079+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48080
48081 config PROC_VMCORE
48082 bool "/proc/vmcore support"
48083- depends on PROC_FS && CRASH_DUMP
48084- default y
48085+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48086+ default n
48087 help
48088 Exports the dump image of crashed kernel in ELF format.
48089
48090@@ -59,8 +59,8 @@ config PROC_SYSCTL
48091 limited in memory.
48092
48093 config PROC_PAGE_MONITOR
48094- default y
48095- depends on PROC_FS && MMU
48096+ default n
48097+ depends on PROC_FS && MMU && !GRKERNSEC
48098 bool "Enable /proc page monitoring" if EXPERT
48099 help
48100 Various /proc files exist to monitor process memory utilization:
48101diff --git a/fs/proc/array.c b/fs/proc/array.c
48102index c1c207c..5179411 100644
48103--- a/fs/proc/array.c
48104+++ b/fs/proc/array.c
48105@@ -60,6 +60,7 @@
48106 #include <linux/tty.h>
48107 #include <linux/string.h>
48108 #include <linux/mman.h>
48109+#include <linux/grsecurity.h>
48110 #include <linux/proc_fs.h>
48111 #include <linux/ioport.h>
48112 #include <linux/uaccess.h>
48113@@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48114 seq_putc(m, '\n');
48115 }
48116
48117+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48118+static inline void task_pax(struct seq_file *m, struct task_struct *p)
48119+{
48120+ if (p->mm)
48121+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48122+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48123+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48124+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48125+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48126+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48127+ else
48128+ seq_printf(m, "PaX:\t-----\n");
48129+}
48130+#endif
48131+
48132 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48133 struct pid *pid, struct task_struct *task)
48134 {
48135@@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48136 task_cpus_allowed(m, task);
48137 cpuset_task_status_allowed(m, task);
48138 task_context_switch_counts(m, task);
48139+
48140+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48141+ task_pax(m, task);
48142+#endif
48143+
48144+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48145+ task_grsec_rbac(m, task);
48146+#endif
48147+
48148 return 0;
48149 }
48150
48151+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48152+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48153+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48154+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48155+#endif
48156+
48157 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48158 struct pid *pid, struct task_struct *task, int whole)
48159 {
48160@@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48161 char tcomm[sizeof(task->comm)];
48162 unsigned long flags;
48163
48164+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48165+ if (current->exec_id != m->exec_id) {
48166+ gr_log_badprocpid("stat");
48167+ return 0;
48168+ }
48169+#endif
48170+
48171 state = *get_task_state(task);
48172 vsize = eip = esp = 0;
48173 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48174@@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48175 gtime = task->gtime;
48176 }
48177
48178+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48179+ if (PAX_RAND_FLAGS(mm)) {
48180+ eip = 0;
48181+ esp = 0;
48182+ wchan = 0;
48183+ }
48184+#endif
48185+#ifdef CONFIG_GRKERNSEC_HIDESYM
48186+ wchan = 0;
48187+ eip =0;
48188+ esp =0;
48189+#endif
48190+
48191 /* scale priority and nice values from timeslices to -20..20 */
48192 /* to make it look like a "normal" Unix priority/nice value */
48193 priority = task_prio(task);
48194@@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48195 seq_put_decimal_ull(m, ' ', vsize);
48196 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48197 seq_put_decimal_ull(m, ' ', rsslim);
48198+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48199+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48200+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48201+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48202+#else
48203 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48204 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48205 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48206+#endif
48207 seq_put_decimal_ull(m, ' ', esp);
48208 seq_put_decimal_ull(m, ' ', eip);
48209 /* The signal information here is obsolete.
48210@@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48211 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48212 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48213
48214- if (mm && permitted) {
48215+ if (mm && permitted
48216+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48217+ && !PAX_RAND_FLAGS(mm)
48218+#endif
48219+ ) {
48220 seq_put_decimal_ull(m, ' ', mm->start_data);
48221 seq_put_decimal_ull(m, ' ', mm->end_data);
48222 seq_put_decimal_ull(m, ' ', mm->start_brk);
48223@@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48224 struct pid *pid, struct task_struct *task)
48225 {
48226 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48227- struct mm_struct *mm = get_task_mm(task);
48228+ struct mm_struct *mm;
48229
48230+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48231+ if (current->exec_id != m->exec_id) {
48232+ gr_log_badprocpid("statm");
48233+ return 0;
48234+ }
48235+#endif
48236+ mm = get_task_mm(task);
48237 if (mm) {
48238 size = task_statm(mm, &shared, &text, &data, &resident);
48239 mmput(mm);
48240@@ -580,6 +648,21 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48241 return 0;
48242 }
48243
48244+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48245+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48246+{
48247+ u32 curr_ip = 0;
48248+ unsigned long flags;
48249+
48250+ if (lock_task_sighand(task, &flags)) {
48251+ curr_ip = task->signal->curr_ip;
48252+ unlock_task_sighand(task, &flags);
48253+ }
48254+
48255+ return sprintf(buffer, "%pI4\n", &curr_ip);
48256+}
48257+#endif
48258+
48259 #ifdef CONFIG_CHECKPOINT_RESTORE
48260 static struct pid *
48261 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48262diff --git a/fs/proc/base.c b/fs/proc/base.c
48263index 437195f..cd2210d 100644
48264--- a/fs/proc/base.c
48265+++ b/fs/proc/base.c
48266@@ -110,6 +110,14 @@ struct pid_entry {
48267 union proc_op op;
48268 };
48269
48270+struct getdents_callback {
48271+ struct linux_dirent __user * current_dir;
48272+ struct linux_dirent __user * previous;
48273+ struct file * file;
48274+ int count;
48275+ int error;
48276+};
48277+
48278 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48279 .name = (NAME), \
48280 .len = sizeof(NAME) - 1, \
48281@@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48282 if (!mm->arg_end)
48283 goto out_mm; /* Shh! No looking before we're done */
48284
48285+ if (gr_acl_handle_procpidmem(task))
48286+ goto out_mm;
48287+
48288 len = mm->arg_end - mm->arg_start;
48289
48290 if (len > PAGE_SIZE)
48291@@ -236,12 +247,28 @@ out:
48292 return res;
48293 }
48294
48295+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48296+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48297+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48298+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48299+#endif
48300+
48301 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48302 {
48303 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48304 int res = PTR_ERR(mm);
48305 if (mm && !IS_ERR(mm)) {
48306 unsigned int nwords = 0;
48307+
48308+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48309+ /* allow if we're currently ptracing this task */
48310+ if (PAX_RAND_FLAGS(mm) &&
48311+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48312+ mmput(mm);
48313+ return 0;
48314+ }
48315+#endif
48316+
48317 do {
48318 nwords += 2;
48319 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48320@@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48321 }
48322
48323
48324-#ifdef CONFIG_KALLSYMS
48325+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48326 /*
48327 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48328 * Returns the resolved symbol. If that fails, simply return the address.
48329@@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48330 mutex_unlock(&task->signal->cred_guard_mutex);
48331 }
48332
48333-#ifdef CONFIG_STACKTRACE
48334+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48335
48336 #define MAX_STACK_TRACE_DEPTH 64
48337
48338@@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48339 return count;
48340 }
48341
48342-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48343+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48344 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48345 {
48346 long nr;
48347@@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48348 /************************************************************************/
48349
48350 /* permission checks */
48351-static int proc_fd_access_allowed(struct inode *inode)
48352+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48353 {
48354 struct task_struct *task;
48355 int allowed = 0;
48356@@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48357 */
48358 task = get_proc_task(inode);
48359 if (task) {
48360- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48361+ if (log)
48362+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48363+ else
48364+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48365 put_task_struct(task);
48366 }
48367 return allowed;
48368@@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48369 struct task_struct *task,
48370 int hide_pid_min)
48371 {
48372+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48373+ return false;
48374+
48375+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48376+ rcu_read_lock();
48377+ {
48378+ const struct cred *tmpcred = current_cred();
48379+ const struct cred *cred = __task_cred(task);
48380+
48381+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48382+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48383+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48384+#endif
48385+ ) {
48386+ rcu_read_unlock();
48387+ return true;
48388+ }
48389+ }
48390+ rcu_read_unlock();
48391+
48392+ if (!pid->hide_pid)
48393+ return false;
48394+#endif
48395+
48396 if (pid->hide_pid < hide_pid_min)
48397 return true;
48398 if (in_group_p(pid->pid_gid))
48399 return true;
48400+
48401 return ptrace_may_access(task, PTRACE_MODE_READ);
48402 }
48403
48404@@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48405 put_task_struct(task);
48406
48407 if (!has_perms) {
48408+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48409+ {
48410+#else
48411 if (pid->hide_pid == 2) {
48412+#endif
48413 /*
48414 * Let's make getdents(), stat(), and open()
48415 * consistent with each other. If a process
48416@@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48417 if (!task)
48418 return -ESRCH;
48419
48420+ if (gr_acl_handle_procpidmem(task)) {
48421+ put_task_struct(task);
48422+ return -EPERM;
48423+ }
48424+
48425 mm = mm_access(task, mode);
48426 put_task_struct(task);
48427
48428@@ -695,16 +759,24 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48429 mmput(mm);
48430 }
48431
48432- /* OK to pass negative loff_t, we can catch out-of-range */
48433- file->f_mode |= FMODE_UNSIGNED_OFFSET;
48434 file->private_data = mm;
48435
48436+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48437+ file->f_version = current->exec_id;
48438+#endif
48439+
48440 return 0;
48441 }
48442
48443 static int mem_open(struct inode *inode, struct file *file)
48444 {
48445- return __mem_open(inode, file, PTRACE_MODE_ATTACH);
48446+ int ret;
48447+ ret = __mem_open(inode, file, PTRACE_MODE_ATTACH);
48448+
48449+ /* OK to pass negative loff_t, we can catch out-of-range */
48450+ file->f_mode |= FMODE_UNSIGNED_OFFSET;
48451+
48452+ return ret;
48453 }
48454
48455 static ssize_t mem_rw(struct file *file, char __user *buf,
48456@@ -715,6 +787,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48457 ssize_t copied;
48458 char *page;
48459
48460+#ifdef CONFIG_GRKERNSEC
48461+ if (write)
48462+ return -EPERM;
48463+#endif
48464+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48465+ if (file->f_version != current->exec_id) {
48466+ gr_log_badprocpid("mem");
48467+ return 0;
48468+ }
48469+#endif
48470+
48471 if (!mm)
48472 return 0;
48473
48474@@ -819,6 +902,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48475 if (!mm)
48476 return 0;
48477
48478+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48479+ if (file->f_version != current->exec_id) {
48480+ gr_log_badprocpid("environ");
48481+ return 0;
48482+ }
48483+#endif
48484+
48485 page = (char *)__get_free_page(GFP_TEMPORARY);
48486 if (!page)
48487 return -ENOMEM;
48488@@ -827,15 +917,17 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48489 if (!atomic_inc_not_zero(&mm->mm_users))
48490 goto free;
48491 while (count > 0) {
48492- int this_len, retval, max_len;
48493+ size_t this_len, max_len;
48494+ int retval;
48495+
48496+ if (src >= (mm->env_end - mm->env_start))
48497+ break;
48498
48499 this_len = mm->env_end - (mm->env_start + src);
48500
48501- if (this_len <= 0)
48502- break;
48503
48504- max_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
48505- this_len = (this_len > max_len) ? max_len : this_len;
48506+ max_len = min_t(size_t, PAGE_SIZE, count);
48507+ this_len = min(max_len, this_len);
48508
48509 retval = access_remote_vm(mm, (mm->env_start + src),
48510 page, this_len, 0);
48511@@ -1433,7 +1525,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48512 path_put(&nd->path);
48513
48514 /* Are we allowed to snoop on the tasks file descriptors? */
48515- if (!proc_fd_access_allowed(inode))
48516+ if (!proc_fd_access_allowed(inode, 0))
48517 goto out;
48518
48519 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48520@@ -1472,8 +1564,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48521 struct path path;
48522
48523 /* Are we allowed to snoop on the tasks file descriptors? */
48524- if (!proc_fd_access_allowed(inode))
48525- goto out;
48526+ /* logging this is needed for learning on chromium to work properly,
48527+ but we don't want to flood the logs from 'ps' which does a readlink
48528+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48529+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
48530+ */
48531+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48532+ if (!proc_fd_access_allowed(inode,0))
48533+ goto out;
48534+ } else {
48535+ if (!proc_fd_access_allowed(inode,1))
48536+ goto out;
48537+ }
48538
48539 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48540 if (error)
48541@@ -1538,7 +1640,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48542 rcu_read_lock();
48543 cred = __task_cred(task);
48544 inode->i_uid = cred->euid;
48545+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48546+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48547+#else
48548 inode->i_gid = cred->egid;
48549+#endif
48550 rcu_read_unlock();
48551 }
48552 security_task_to_inode(task, inode);
48553@@ -1574,10 +1680,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48554 return -ENOENT;
48555 }
48556 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48557+#ifdef CONFIG_GRKERNSEC_PROC_USER
48558+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48559+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48560+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48561+#endif
48562 task_dumpable(task)) {
48563 cred = __task_cred(task);
48564 stat->uid = cred->euid;
48565+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48566+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48567+#else
48568 stat->gid = cred->egid;
48569+#endif
48570 }
48571 }
48572 rcu_read_unlock();
48573@@ -1615,11 +1730,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48574
48575 if (task) {
48576 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48577+#ifdef CONFIG_GRKERNSEC_PROC_USER
48578+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48579+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48580+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48581+#endif
48582 task_dumpable(task)) {
48583 rcu_read_lock();
48584 cred = __task_cred(task);
48585 inode->i_uid = cred->euid;
48586+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48587+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48588+#else
48589 inode->i_gid = cred->egid;
48590+#endif
48591 rcu_read_unlock();
48592 } else {
48593 inode->i_uid = GLOBAL_ROOT_UID;
48594@@ -1737,7 +1861,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48595 int fd = proc_fd(inode);
48596
48597 if (task) {
48598- files = get_files_struct(task);
48599+ if (!gr_acl_handle_procpidmem(task))
48600+ files = get_files_struct(task);
48601 put_task_struct(task);
48602 }
48603 if (files) {
48604@@ -2336,11 +2461,21 @@ static const struct file_operations proc_map_files_operations = {
48605 */
48606 static int proc_fd_permission(struct inode *inode, int mask)
48607 {
48608+ struct task_struct *task;
48609 int rv = generic_permission(inode, mask);
48610- if (rv == 0)
48611- return 0;
48612+
48613 if (task_pid(current) == proc_pid(inode))
48614 rv = 0;
48615+
48616+ task = get_proc_task(inode);
48617+ if (task == NULL)
48618+ return rv;
48619+
48620+ if (gr_acl_handle_procpidmem(task))
48621+ rv = -EACCES;
48622+
48623+ put_task_struct(task);
48624+
48625 return rv;
48626 }
48627
48628@@ -2450,6 +2585,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48629 if (!task)
48630 goto out_no_task;
48631
48632+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48633+ goto out;
48634+
48635 /*
48636 * Yes, it does not scale. And it should not. Don't add
48637 * new entries into /proc/<tgid>/ without very good reasons.
48638@@ -2494,6 +2632,9 @@ static int proc_pident_readdir(struct file *filp,
48639 if (!task)
48640 goto out_no_task;
48641
48642+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48643+ goto out;
48644+
48645 ret = 0;
48646 i = filp->f_pos;
48647 switch (i) {
48648@@ -2764,7 +2905,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48649 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48650 void *cookie)
48651 {
48652- char *s = nd_get_link(nd);
48653+ const char *s = nd_get_link(nd);
48654 if (!IS_ERR(s))
48655 __putname(s);
48656 }
48657@@ -3033,7 +3174,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48658 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48659 #endif
48660 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48661-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48662+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48663 INF("syscall", S_IRUGO, proc_pid_syscall),
48664 #endif
48665 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48666@@ -3058,10 +3199,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48667 #ifdef CONFIG_SECURITY
48668 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48669 #endif
48670-#ifdef CONFIG_KALLSYMS
48671+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48672 INF("wchan", S_IRUGO, proc_pid_wchan),
48673 #endif
48674-#ifdef CONFIG_STACKTRACE
48675+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48676 ONE("stack", S_IRUGO, proc_pid_stack),
48677 #endif
48678 #ifdef CONFIG_SCHEDSTATS
48679@@ -3095,6 +3236,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48680 #ifdef CONFIG_HARDWALL
48681 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48682 #endif
48683+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48684+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48685+#endif
48686 #ifdef CONFIG_USER_NS
48687 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
48688 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
48689@@ -3225,7 +3369,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48690 if (!inode)
48691 goto out;
48692
48693+#ifdef CONFIG_GRKERNSEC_PROC_USER
48694+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48695+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48696+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48697+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48698+#else
48699 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48700+#endif
48701 inode->i_op = &proc_tgid_base_inode_operations;
48702 inode->i_fop = &proc_tgid_base_operations;
48703 inode->i_flags|=S_IMMUTABLE;
48704@@ -3267,7 +3418,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48705 if (!task)
48706 goto out;
48707
48708+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48709+ goto out_put_task;
48710+
48711 result = proc_pid_instantiate(dir, dentry, task, NULL);
48712+out_put_task:
48713 put_task_struct(task);
48714 out:
48715 return result;
48716@@ -3330,6 +3485,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48717 static int fake_filldir(void *buf, const char *name, int namelen,
48718 loff_t offset, u64 ino, unsigned d_type)
48719 {
48720+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
48721+ __buf->error = -EINVAL;
48722 return 0;
48723 }
48724
48725@@ -3396,7 +3553,7 @@ static const struct pid_entry tid_base_stuff[] = {
48726 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48727 #endif
48728 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48729-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48730+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48731 INF("syscall", S_IRUGO, proc_pid_syscall),
48732 #endif
48733 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48734@@ -3423,10 +3580,10 @@ static const struct pid_entry tid_base_stuff[] = {
48735 #ifdef CONFIG_SECURITY
48736 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48737 #endif
48738-#ifdef CONFIG_KALLSYMS
48739+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48740 INF("wchan", S_IRUGO, proc_pid_wchan),
48741 #endif
48742-#ifdef CONFIG_STACKTRACE
48743+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48744 ONE("stack", S_IRUGO, proc_pid_stack),
48745 #endif
48746 #ifdef CONFIG_SCHEDSTATS
48747diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48748index 82676e3..5f8518a 100644
48749--- a/fs/proc/cmdline.c
48750+++ b/fs/proc/cmdline.c
48751@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48752
48753 static int __init proc_cmdline_init(void)
48754 {
48755+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48756+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48757+#else
48758 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48759+#endif
48760 return 0;
48761 }
48762 module_init(proc_cmdline_init);
48763diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48764index b143471..bb105e5 100644
48765--- a/fs/proc/devices.c
48766+++ b/fs/proc/devices.c
48767@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48768
48769 static int __init proc_devices_init(void)
48770 {
48771+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48772+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48773+#else
48774 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48775+#endif
48776 return 0;
48777 }
48778 module_init(proc_devices_init);
48779diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48780index 7ac817b..abab1a5 100644
48781--- a/fs/proc/inode.c
48782+++ b/fs/proc/inode.c
48783@@ -21,11 +21,17 @@
48784 #include <linux/seq_file.h>
48785 #include <linux/slab.h>
48786 #include <linux/mount.h>
48787+#include <linux/grsecurity.h>
48788
48789 #include <asm/uaccess.h>
48790
48791 #include "internal.h"
48792
48793+#ifdef CONFIG_PROC_SYSCTL
48794+extern const struct inode_operations proc_sys_inode_operations;
48795+extern const struct inode_operations proc_sys_dir_operations;
48796+#endif
48797+
48798 static void proc_evict_inode(struct inode *inode)
48799 {
48800 struct proc_dir_entry *de;
48801@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
48802 ns_ops = PROC_I(inode)->ns_ops;
48803 if (ns_ops && ns_ops->put)
48804 ns_ops->put(PROC_I(inode)->ns);
48805+
48806+#ifdef CONFIG_PROC_SYSCTL
48807+ if (inode->i_op == &proc_sys_inode_operations ||
48808+ inode->i_op == &proc_sys_dir_operations)
48809+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48810+#endif
48811+
48812 }
48813
48814 static struct kmem_cache * proc_inode_cachep;
48815@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48816 if (de->mode) {
48817 inode->i_mode = de->mode;
48818 inode->i_uid = de->uid;
48819+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48820+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48821+#else
48822 inode->i_gid = de->gid;
48823+#endif
48824 }
48825 if (de->size)
48826 inode->i_size = de->size;
48827diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48828index eca4aca..19166b2 100644
48829--- a/fs/proc/internal.h
48830+++ b/fs/proc/internal.h
48831@@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48832 struct pid *pid, struct task_struct *task);
48833 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48834 struct pid *pid, struct task_struct *task);
48835+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48836+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48837+#endif
48838 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48839
48840 extern const struct file_operations proc_tid_children_operations;
48841diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48842index 86c67ee..cdca321 100644
48843--- a/fs/proc/kcore.c
48844+++ b/fs/proc/kcore.c
48845@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48846 * the addresses in the elf_phdr on our list.
48847 */
48848 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48849- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48850+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48851+ if (tsz > buflen)
48852 tsz = buflen;
48853-
48854+
48855 while (buflen) {
48856 struct kcore_list *m;
48857
48858@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48859 kfree(elf_buf);
48860 } else {
48861 if (kern_addr_valid(start)) {
48862- unsigned long n;
48863+ char *elf_buf;
48864+ mm_segment_t oldfs;
48865
48866- n = copy_to_user(buffer, (char *)start, tsz);
48867- /*
48868- * We cannot distinguish between fault on source
48869- * and fault on destination. When this happens
48870- * we clear too and hope it will trigger the
48871- * EFAULT again.
48872- */
48873- if (n) {
48874- if (clear_user(buffer + tsz - n,
48875- n))
48876+ elf_buf = kmalloc(tsz, GFP_KERNEL);
48877+ if (!elf_buf)
48878+ return -ENOMEM;
48879+ oldfs = get_fs();
48880+ set_fs(KERNEL_DS);
48881+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48882+ set_fs(oldfs);
48883+ if (copy_to_user(buffer, elf_buf, tsz)) {
48884+ kfree(elf_buf);
48885 return -EFAULT;
48886+ }
48887 }
48888+ set_fs(oldfs);
48889+ kfree(elf_buf);
48890 } else {
48891 if (clear_user(buffer, tsz))
48892 return -EFAULT;
48893@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48894
48895 static int open_kcore(struct inode *inode, struct file *filp)
48896 {
48897+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48898+ return -EPERM;
48899+#endif
48900 if (!capable(CAP_SYS_RAWIO))
48901 return -EPERM;
48902 if (kcore_need_update)
48903diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48904index 80e4645..53e5fcf 100644
48905--- a/fs/proc/meminfo.c
48906+++ b/fs/proc/meminfo.c
48907@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48908 vmi.used >> 10,
48909 vmi.largest_chunk >> 10
48910 #ifdef CONFIG_MEMORY_FAILURE
48911- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48912+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48913 #endif
48914 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48915 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48916diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48917index b1822dd..df622cb 100644
48918--- a/fs/proc/nommu.c
48919+++ b/fs/proc/nommu.c
48920@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48921 if (len < 1)
48922 len = 1;
48923 seq_printf(m, "%*c", len, ' ');
48924- seq_path(m, &file->f_path, "");
48925+ seq_path(m, &file->f_path, "\n\\");
48926 }
48927
48928 seq_putc(m, '\n');
48929diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48930index 06e1cc1..177cd98 100644
48931--- a/fs/proc/proc_net.c
48932+++ b/fs/proc/proc_net.c
48933@@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48934 struct task_struct *task;
48935 struct nsproxy *ns;
48936 struct net *net = NULL;
48937+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48938+ const struct cred *cred = current_cred();
48939+#endif
48940+
48941+#ifdef CONFIG_GRKERNSEC_PROC_USER
48942+ if (cred->fsuid)
48943+ return net;
48944+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48945+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48946+ return net;
48947+#endif
48948
48949 rcu_read_lock();
48950 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48951diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48952index 3476bca..cb6d86a 100644
48953--- a/fs/proc/proc_sysctl.c
48954+++ b/fs/proc/proc_sysctl.c
48955@@ -12,11 +12,15 @@
48956 #include <linux/module.h>
48957 #include "internal.h"
48958
48959+extern int gr_handle_chroot_sysctl(const int op);
48960+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
48961+ const int op);
48962+
48963 static const struct dentry_operations proc_sys_dentry_operations;
48964 static const struct file_operations proc_sys_file_operations;
48965-static const struct inode_operations proc_sys_inode_operations;
48966+const struct inode_operations proc_sys_inode_operations;
48967 static const struct file_operations proc_sys_dir_file_operations;
48968-static const struct inode_operations proc_sys_dir_operations;
48969+const struct inode_operations proc_sys_dir_operations;
48970
48971 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48972 {
48973@@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48974
48975 err = NULL;
48976 d_set_d_op(dentry, &proc_sys_dentry_operations);
48977+
48978+ gr_handle_proc_create(dentry, inode);
48979+
48980 d_add(dentry, inode);
48981
48982+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
48983+ err = ERR_PTR(-ENOENT);
48984+
48985 out:
48986 sysctl_head_finish(head);
48987 return err;
48988@@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48989 struct inode *inode = filp->f_path.dentry->d_inode;
48990 struct ctl_table_header *head = grab_header(inode);
48991 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
48992+ int op = write ? MAY_WRITE : MAY_READ;
48993 ssize_t error;
48994 size_t res;
48995
48996 if (IS_ERR(head))
48997 return PTR_ERR(head);
48998
48999+
49000 /*
49001 * At this point we know that the sysctl was not unregistered
49002 * and won't be until we finish.
49003 */
49004 error = -EPERM;
49005- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49006+ if (sysctl_perm(head->root, table, op))
49007 goto out;
49008
49009 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49010@@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49011 if (!table->proc_handler)
49012 goto out;
49013
49014+#ifdef CONFIG_GRKERNSEC
49015+ error = -EPERM;
49016+ if (gr_handle_chroot_sysctl(op))
49017+ goto out;
49018+ dget(filp->f_path.dentry);
49019+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49020+ dput(filp->f_path.dentry);
49021+ goto out;
49022+ }
49023+ dput(filp->f_path.dentry);
49024+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49025+ goto out;
49026+ if (write && !capable(CAP_SYS_ADMIN))
49027+ goto out;
49028+#endif
49029+
49030 /* careful: calling conventions are nasty here */
49031 res = count;
49032 error = table->proc_handler(table, write, buf, &res, ppos);
49033@@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49034 return -ENOMEM;
49035 } else {
49036 d_set_d_op(child, &proc_sys_dentry_operations);
49037+
49038+ gr_handle_proc_create(child, inode);
49039+
49040 d_add(child, inode);
49041 }
49042 } else {
49043@@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49044 if ((*pos)++ < file->f_pos)
49045 return 0;
49046
49047+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49048+ return 0;
49049+
49050 if (unlikely(S_ISLNK(table->mode)))
49051 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49052 else
49053@@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49054 if (IS_ERR(head))
49055 return PTR_ERR(head);
49056
49057+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49058+ return -ENOENT;
49059+
49060 generic_fillattr(inode, stat);
49061 if (table)
49062 stat->mode = (stat->mode & S_IFMT) | table->mode;
49063@@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49064 .llseek = generic_file_llseek,
49065 };
49066
49067-static const struct inode_operations proc_sys_inode_operations = {
49068+const struct inode_operations proc_sys_inode_operations = {
49069 .permission = proc_sys_permission,
49070 .setattr = proc_sys_setattr,
49071 .getattr = proc_sys_getattr,
49072 };
49073
49074-static const struct inode_operations proc_sys_dir_operations = {
49075+const struct inode_operations proc_sys_dir_operations = {
49076 .lookup = proc_sys_lookup,
49077 .permission = proc_sys_permission,
49078 .setattr = proc_sys_setattr,
49079diff --git a/fs/proc/root.c b/fs/proc/root.c
49080index 7c30fce..b3d3aa2 100644
49081--- a/fs/proc/root.c
49082+++ b/fs/proc/root.c
49083@@ -188,7 +188,15 @@ void __init proc_root_init(void)
49084 #ifdef CONFIG_PROC_DEVICETREE
49085 proc_device_tree_init();
49086 #endif
49087+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49088+#ifdef CONFIG_GRKERNSEC_PROC_USER
49089+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49090+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49091+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49092+#endif
49093+#else
49094 proc_mkdir("bus", NULL);
49095+#endif
49096 proc_sys_init();
49097 }
49098
49099diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49100index 4540b8f..1b9772f 100644
49101--- a/fs/proc/task_mmu.c
49102+++ b/fs/proc/task_mmu.c
49103@@ -11,12 +11,19 @@
49104 #include <linux/rmap.h>
49105 #include <linux/swap.h>
49106 #include <linux/swapops.h>
49107+#include <linux/grsecurity.h>
49108
49109 #include <asm/elf.h>
49110 #include <asm/uaccess.h>
49111 #include <asm/tlbflush.h>
49112 #include "internal.h"
49113
49114+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49115+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49116+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49117+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49118+#endif
49119+
49120 void task_mem(struct seq_file *m, struct mm_struct *mm)
49121 {
49122 unsigned long data, text, lib, swap;
49123@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49124 "VmExe:\t%8lu kB\n"
49125 "VmLib:\t%8lu kB\n"
49126 "VmPTE:\t%8lu kB\n"
49127- "VmSwap:\t%8lu kB\n",
49128- hiwater_vm << (PAGE_SHIFT-10),
49129+ "VmSwap:\t%8lu kB\n"
49130+
49131+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49132+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49133+#endif
49134+
49135+ ,hiwater_vm << (PAGE_SHIFT-10),
49136 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49137 mm->locked_vm << (PAGE_SHIFT-10),
49138 mm->pinned_vm << (PAGE_SHIFT-10),
49139@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49140 data << (PAGE_SHIFT-10),
49141 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49142 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49143- swap << (PAGE_SHIFT-10));
49144+ swap << (PAGE_SHIFT-10)
49145+
49146+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49147+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49148+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49149+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49150+#else
49151+ , mm->context.user_cs_base
49152+ , mm->context.user_cs_limit
49153+#endif
49154+#endif
49155+
49156+ );
49157 }
49158
49159 unsigned long task_vsize(struct mm_struct *mm)
49160@@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49161 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49162 }
49163
49164- /* We don't show the stack guard page in /proc/maps */
49165+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49166+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49167+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49168+#else
49169 start = vma->vm_start;
49170- if (stack_guard_page_start(vma, start))
49171- start += PAGE_SIZE;
49172 end = vma->vm_end;
49173- if (stack_guard_page_end(vma, end))
49174- end -= PAGE_SIZE;
49175+#endif
49176
49177 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49178 start,
49179@@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49180 flags & VM_WRITE ? 'w' : '-',
49181 flags & VM_EXEC ? 'x' : '-',
49182 flags & VM_MAYSHARE ? 's' : 'p',
49183+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49184+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49185+#else
49186 pgoff,
49187+#endif
49188 MAJOR(dev), MINOR(dev), ino, &len);
49189
49190 /*
49191@@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49192 */
49193 if (file) {
49194 pad_len_spaces(m, len);
49195- seq_path(m, &file->f_path, "\n");
49196+ seq_path(m, &file->f_path, "\n\\");
49197 goto done;
49198 }
49199
49200@@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49201 * Thread stack in /proc/PID/task/TID/maps or
49202 * the main process stack.
49203 */
49204- if (!is_pid || (vma->vm_start <= mm->start_stack &&
49205- vma->vm_end >= mm->start_stack)) {
49206+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49207+ (vma->vm_start <= mm->start_stack &&
49208+ vma->vm_end >= mm->start_stack)) {
49209 name = "[stack]";
49210 } else {
49211 /* Thread stack in /proc/PID/maps */
49212@@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49213 struct proc_maps_private *priv = m->private;
49214 struct task_struct *task = priv->task;
49215
49216+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49217+ if (current->exec_id != m->exec_id) {
49218+ gr_log_badprocpid("maps");
49219+ return 0;
49220+ }
49221+#endif
49222+
49223 show_map_vma(m, vma, is_pid);
49224
49225 if (m->count < m->size) /* vma is copied successfully */
49226@@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49227 .private = &mss,
49228 };
49229
49230+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49231+ if (current->exec_id != m->exec_id) {
49232+ gr_log_badprocpid("smaps");
49233+ return 0;
49234+ }
49235+#endif
49236 memset(&mss, 0, sizeof mss);
49237- mss.vma = vma;
49238- /* mmap_sem is held in m_start */
49239- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49240- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49241-
49242+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49243+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49244+#endif
49245+ mss.vma = vma;
49246+ /* mmap_sem is held in m_start */
49247+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49248+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49249+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49250+ }
49251+#endif
49252 show_map_vma(m, vma, is_pid);
49253
49254 seq_printf(m,
49255@@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49256 "KernelPageSize: %8lu kB\n"
49257 "MMUPageSize: %8lu kB\n"
49258 "Locked: %8lu kB\n",
49259+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49260+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49261+#else
49262 (vma->vm_end - vma->vm_start) >> 10,
49263+#endif
49264 mss.resident >> 10,
49265 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49266 mss.shared_clean >> 10,
49267@@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49268 int n;
49269 char buffer[50];
49270
49271+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49272+ if (current->exec_id != m->exec_id) {
49273+ gr_log_badprocpid("numa_maps");
49274+ return 0;
49275+ }
49276+#endif
49277+
49278 if (!mm)
49279 return 0;
49280
49281@@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49282 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49283 mpol_cond_put(pol);
49284
49285+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49286+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49287+#else
49288 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49289+#endif
49290
49291 if (file) {
49292 seq_printf(m, " file=");
49293- seq_path(m, &file->f_path, "\n\t= ");
49294+ seq_path(m, &file->f_path, "\n\t\\= ");
49295 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49296 seq_printf(m, " heap");
49297 } else {
49298diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49299index 1ccfa53..0848f95 100644
49300--- a/fs/proc/task_nommu.c
49301+++ b/fs/proc/task_nommu.c
49302@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49303 else
49304 bytes += kobjsize(mm);
49305
49306- if (current->fs && current->fs->users > 1)
49307+ if (current->fs && atomic_read(&current->fs->users) > 1)
49308 sbytes += kobjsize(current->fs);
49309 else
49310 bytes += kobjsize(current->fs);
49311@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49312
49313 if (file) {
49314 pad_len_spaces(m, len);
49315- seq_path(m, &file->f_path, "");
49316+ seq_path(m, &file->f_path, "\n\\");
49317 } else if (mm) {
49318 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49319
49320diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49321index d67908b..d13f6a6 100644
49322--- a/fs/quota/netlink.c
49323+++ b/fs/quota/netlink.c
49324@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49325 void quota_send_warning(short type, unsigned int id, dev_t dev,
49326 const char warntype)
49327 {
49328- static atomic_t seq;
49329+ static atomic_unchecked_t seq;
49330 struct sk_buff *skb;
49331 void *msg_head;
49332 int ret;
49333@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49334 "VFS: Not enough memory to send quota warning.\n");
49335 return;
49336 }
49337- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49338+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49339 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49340 if (!msg_head) {
49341 printk(KERN_ERR
49342diff --git a/fs/readdir.c b/fs/readdir.c
49343index 39e3370..20d446d 100644
49344--- a/fs/readdir.c
49345+++ b/fs/readdir.c
49346@@ -17,6 +17,7 @@
49347 #include <linux/security.h>
49348 #include <linux/syscalls.h>
49349 #include <linux/unistd.h>
49350+#include <linux/namei.h>
49351
49352 #include <asm/uaccess.h>
49353
49354@@ -67,6 +68,7 @@ struct old_linux_dirent {
49355
49356 struct readdir_callback {
49357 struct old_linux_dirent __user * dirent;
49358+ struct file * file;
49359 int result;
49360 };
49361
49362@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49363 buf->result = -EOVERFLOW;
49364 return -EOVERFLOW;
49365 }
49366+
49367+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49368+ return 0;
49369+
49370 buf->result++;
49371 dirent = buf->dirent;
49372 if (!access_ok(VERIFY_WRITE, dirent,
49373@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49374
49375 buf.result = 0;
49376 buf.dirent = dirent;
49377+ buf.file = file;
49378
49379 error = vfs_readdir(file, fillonedir, &buf);
49380 if (buf.result)
49381@@ -141,6 +148,7 @@ struct linux_dirent {
49382 struct getdents_callback {
49383 struct linux_dirent __user * current_dir;
49384 struct linux_dirent __user * previous;
49385+ struct file * file;
49386 int count;
49387 int error;
49388 };
49389@@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49390 buf->error = -EOVERFLOW;
49391 return -EOVERFLOW;
49392 }
49393+
49394+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49395+ return 0;
49396+
49397 dirent = buf->previous;
49398 if (dirent) {
49399 if (__put_user(offset, &dirent->d_off))
49400@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49401 buf.previous = NULL;
49402 buf.count = count;
49403 buf.error = 0;
49404+ buf.file = file;
49405
49406 error = vfs_readdir(file, filldir, &buf);
49407 if (error >= 0)
49408@@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49409 struct getdents_callback64 {
49410 struct linux_dirent64 __user * current_dir;
49411 struct linux_dirent64 __user * previous;
49412+ struct file *file;
49413 int count;
49414 int error;
49415 };
49416@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49417 buf->error = -EINVAL; /* only used if we fail.. */
49418 if (reclen > buf->count)
49419 return -EINVAL;
49420+
49421+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49422+ return 0;
49423+
49424 dirent = buf->previous;
49425 if (dirent) {
49426 if (__put_user(offset, &dirent->d_off))
49427@@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49428
49429 buf.current_dir = dirent;
49430 buf.previous = NULL;
49431+ buf.file = file;
49432 buf.count = count;
49433 buf.error = 0;
49434
49435@@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49436 error = buf.error;
49437 lastdirent = buf.previous;
49438 if (lastdirent) {
49439- typeof(lastdirent->d_off) d_off = file->f_pos;
49440+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49441 if (__put_user(d_off, &lastdirent->d_off))
49442 error = -EFAULT;
49443 else
49444diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49445index 2b7882b..1c5ef48 100644
49446--- a/fs/reiserfs/do_balan.c
49447+++ b/fs/reiserfs/do_balan.c
49448@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49449 return;
49450 }
49451
49452- atomic_inc(&(fs_generation(tb->tb_sb)));
49453+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49454 do_balance_starts(tb);
49455
49456 /* balance leaf returns 0 except if combining L R and S into
49457diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49458index 2c1ade6..8c59d8d 100644
49459--- a/fs/reiserfs/procfs.c
49460+++ b/fs/reiserfs/procfs.c
49461@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49462 "SMALL_TAILS " : "NO_TAILS ",
49463 replay_only(sb) ? "REPLAY_ONLY " : "",
49464 convert_reiserfs(sb) ? "CONV " : "",
49465- atomic_read(&r->s_generation_counter),
49466+ atomic_read_unchecked(&r->s_generation_counter),
49467 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49468 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49469 SF(s_good_search_by_key_reada), SF(s_bmaps),
49470diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
49471index 33215f5..c5d427a 100644
49472--- a/fs/reiserfs/reiserfs.h
49473+++ b/fs/reiserfs/reiserfs.h
49474@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
49475 /* Comment? -Hans */
49476 wait_queue_head_t s_wait;
49477 /* To be obsoleted soon by per buffer seals.. -Hans */
49478- atomic_t s_generation_counter; // increased by one every time the
49479+ atomic_unchecked_t s_generation_counter; // increased by one every time the
49480 // tree gets re-balanced
49481 unsigned long s_properties; /* File system properties. Currently holds
49482 on-disk FS format */
49483@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
49484 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
49485
49486 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
49487-#define get_generation(s) atomic_read (&fs_generation(s))
49488+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
49489 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
49490 #define __fs_changed(gen,s) (gen != get_generation (s))
49491 #define fs_changed(gen,s) \
49492diff --git a/fs/select.c b/fs/select.c
49493index bae3215..06b4707 100644
49494--- a/fs/select.c
49495+++ b/fs/select.c
49496@@ -20,6 +20,7 @@
49497 #include <linux/export.h>
49498 #include <linux/slab.h>
49499 #include <linux/poll.h>
49500+#include <linux/security.h>
49501 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49502 #include <linux/file.h>
49503 #include <linux/fdtable.h>
49504@@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49505 struct poll_list *walk = head;
49506 unsigned long todo = nfds;
49507
49508+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49509 if (nfds > rlimit(RLIMIT_NOFILE))
49510 return -EINVAL;
49511
49512diff --git a/fs/seq_file.c b/fs/seq_file.c
49513index 0cbd049..64e705c 100644
49514--- a/fs/seq_file.c
49515+++ b/fs/seq_file.c
49516@@ -9,6 +9,7 @@
49517 #include <linux/export.h>
49518 #include <linux/seq_file.h>
49519 #include <linux/slab.h>
49520+#include <linux/sched.h>
49521
49522 #include <asm/uaccess.h>
49523 #include <asm/page.h>
49524@@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49525 memset(p, 0, sizeof(*p));
49526 mutex_init(&p->lock);
49527 p->op = op;
49528+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49529+ p->exec_id = current->exec_id;
49530+#endif
49531
49532 /*
49533 * Wrappers around seq_open(e.g. swaps_open) need to be
49534@@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49535 return 0;
49536 }
49537 if (!m->buf) {
49538- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49539+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49540 if (!m->buf)
49541 return -ENOMEM;
49542 }
49543@@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49544 Eoverflow:
49545 m->op->stop(m, p);
49546 kfree(m->buf);
49547- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49548+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49549 return !m->buf ? -ENOMEM : -EAGAIN;
49550 }
49551
49552@@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49553
49554 /* grab buffer if we didn't have one */
49555 if (!m->buf) {
49556- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49557+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49558 if (!m->buf)
49559 goto Enomem;
49560 }
49561@@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49562 goto Fill;
49563 m->op->stop(m, p);
49564 kfree(m->buf);
49565- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49566+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49567 if (!m->buf)
49568 goto Enomem;
49569 m->count = 0;
49570@@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
49571 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49572 void *data)
49573 {
49574- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49575+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49576 int res = -ENOMEM;
49577
49578 if (op) {
49579diff --git a/fs/splice.c b/fs/splice.c
49580index 7bf08fa..eb35c2f 100644
49581--- a/fs/splice.c
49582+++ b/fs/splice.c
49583@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49584 pipe_lock(pipe);
49585
49586 for (;;) {
49587- if (!pipe->readers) {
49588+ if (!atomic_read(&pipe->readers)) {
49589 send_sig(SIGPIPE, current, 0);
49590 if (!ret)
49591 ret = -EPIPE;
49592@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49593 do_wakeup = 0;
49594 }
49595
49596- pipe->waiting_writers++;
49597+ atomic_inc(&pipe->waiting_writers);
49598 pipe_wait(pipe);
49599- pipe->waiting_writers--;
49600+ atomic_dec(&pipe->waiting_writers);
49601 }
49602
49603 pipe_unlock(pipe);
49604@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
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_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49609+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49610 set_fs(old_fs);
49611
49612 return res;
49613@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49614 old_fs = get_fs();
49615 set_fs(get_ds());
49616 /* The cast to a user pointer is valid due to the set_fs() */
49617- res = vfs_write(file, (const char __user *)buf, count, &pos);
49618+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49619 set_fs(old_fs);
49620
49621 return res;
49622@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49623 goto err;
49624
49625 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49626- vec[i].iov_base = (void __user *) page_address(page);
49627+ vec[i].iov_base = (void __force_user *) page_address(page);
49628 vec[i].iov_len = this_len;
49629 spd.pages[i] = page;
49630 spd.nr_pages++;
49631@@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49632 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49633 {
49634 while (!pipe->nrbufs) {
49635- if (!pipe->writers)
49636+ if (!atomic_read(&pipe->writers))
49637 return 0;
49638
49639- if (!pipe->waiting_writers && sd->num_spliced)
49640+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49641 return 0;
49642
49643 if (sd->flags & SPLICE_F_NONBLOCK)
49644@@ -1187,7 +1187,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49645 * out of the pipe right after the splice_to_pipe(). So set
49646 * PIPE_READERS appropriately.
49647 */
49648- pipe->readers = 1;
49649+ atomic_set(&pipe->readers, 1);
49650
49651 current->splice_pipe = pipe;
49652 }
49653@@ -1740,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49654 ret = -ERESTARTSYS;
49655 break;
49656 }
49657- if (!pipe->writers)
49658+ if (!atomic_read(&pipe->writers))
49659 break;
49660- if (!pipe->waiting_writers) {
49661+ if (!atomic_read(&pipe->waiting_writers)) {
49662 if (flags & SPLICE_F_NONBLOCK) {
49663 ret = -EAGAIN;
49664 break;
49665@@ -1774,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49666 pipe_lock(pipe);
49667
49668 while (pipe->nrbufs >= pipe->buffers) {
49669- if (!pipe->readers) {
49670+ if (!atomic_read(&pipe->readers)) {
49671 send_sig(SIGPIPE, current, 0);
49672 ret = -EPIPE;
49673 break;
49674@@ -1787,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49675 ret = -ERESTARTSYS;
49676 break;
49677 }
49678- pipe->waiting_writers++;
49679+ atomic_inc(&pipe->waiting_writers);
49680 pipe_wait(pipe);
49681- pipe->waiting_writers--;
49682+ atomic_dec(&pipe->waiting_writers);
49683 }
49684
49685 pipe_unlock(pipe);
49686@@ -1825,14 +1825,14 @@ retry:
49687 pipe_double_lock(ipipe, opipe);
49688
49689 do {
49690- if (!opipe->readers) {
49691+ if (!atomic_read(&opipe->readers)) {
49692 send_sig(SIGPIPE, current, 0);
49693 if (!ret)
49694 ret = -EPIPE;
49695 break;
49696 }
49697
49698- if (!ipipe->nrbufs && !ipipe->writers)
49699+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49700 break;
49701
49702 /*
49703@@ -1929,7 +1929,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49704 pipe_double_lock(ipipe, opipe);
49705
49706 do {
49707- if (!opipe->readers) {
49708+ if (!atomic_read(&opipe->readers)) {
49709 send_sig(SIGPIPE, current, 0);
49710 if (!ret)
49711 ret = -EPIPE;
49712@@ -1974,7 +1974,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49713 * return EAGAIN if we have the potential of some data in the
49714 * future, otherwise just return 0
49715 */
49716- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49717+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49718 ret = -EAGAIN;
49719
49720 pipe_unlock(ipipe);
49721diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49722index e6bb9b2..d8e3951 100644
49723--- a/fs/sysfs/dir.c
49724+++ b/fs/sysfs/dir.c
49725@@ -678,6 +678,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49726 struct sysfs_dirent *sd;
49727 int rc;
49728
49729+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49730+ const char *parent_name = parent_sd->s_name;
49731+
49732+ mode = S_IFDIR | S_IRWXU;
49733+
49734+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49735+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49736+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49737+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49738+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49739+#endif
49740+
49741 /* allocate */
49742 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49743 if (!sd)
49744diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49745index 00012e3..8392349 100644
49746--- a/fs/sysfs/file.c
49747+++ b/fs/sysfs/file.c
49748@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49749
49750 struct sysfs_open_dirent {
49751 atomic_t refcnt;
49752- atomic_t event;
49753+ atomic_unchecked_t event;
49754 wait_queue_head_t poll;
49755 struct list_head buffers; /* goes through sysfs_buffer.list */
49756 };
49757@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49758 if (!sysfs_get_active(attr_sd))
49759 return -ENODEV;
49760
49761- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49762+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49763 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49764
49765 sysfs_put_active(attr_sd);
49766@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49767 return -ENOMEM;
49768
49769 atomic_set(&new_od->refcnt, 0);
49770- atomic_set(&new_od->event, 1);
49771+ atomic_set_unchecked(&new_od->event, 1);
49772 init_waitqueue_head(&new_od->poll);
49773 INIT_LIST_HEAD(&new_od->buffers);
49774 goto retry;
49775@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49776
49777 sysfs_put_active(attr_sd);
49778
49779- if (buffer->event != atomic_read(&od->event))
49780+ if (buffer->event != atomic_read_unchecked(&od->event))
49781 goto trigger;
49782
49783 return DEFAULT_POLLMASK;
49784@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49785
49786 od = sd->s_attr.open;
49787 if (od) {
49788- atomic_inc(&od->event);
49789+ atomic_inc_unchecked(&od->event);
49790 wake_up_interruptible(&od->poll);
49791 }
49792
49793diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49794index a7ac78f..02158e1 100644
49795--- a/fs/sysfs/symlink.c
49796+++ b/fs/sysfs/symlink.c
49797@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49798
49799 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49800 {
49801- char *page = nd_get_link(nd);
49802+ const char *page = nd_get_link(nd);
49803 if (!IS_ERR(page))
49804 free_page((unsigned long)page);
49805 }
49806diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49807index c175b4d..8f36a16 100644
49808--- a/fs/udf/misc.c
49809+++ b/fs/udf/misc.c
49810@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49811
49812 u8 udf_tag_checksum(const struct tag *t)
49813 {
49814- u8 *data = (u8 *)t;
49815+ const u8 *data = (const u8 *)t;
49816 u8 checksum = 0;
49817 int i;
49818 for (i = 0; i < sizeof(struct tag); ++i)
49819diff --git a/fs/utimes.c b/fs/utimes.c
49820index fa4dbe4..e12d1b9 100644
49821--- a/fs/utimes.c
49822+++ b/fs/utimes.c
49823@@ -1,6 +1,7 @@
49824 #include <linux/compiler.h>
49825 #include <linux/file.h>
49826 #include <linux/fs.h>
49827+#include <linux/security.h>
49828 #include <linux/linkage.h>
49829 #include <linux/mount.h>
49830 #include <linux/namei.h>
49831@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49832 goto mnt_drop_write_and_out;
49833 }
49834 }
49835+
49836+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49837+ error = -EACCES;
49838+ goto mnt_drop_write_and_out;
49839+ }
49840+
49841 mutex_lock(&inode->i_mutex);
49842 error = notify_change(path->dentry, &newattrs);
49843 mutex_unlock(&inode->i_mutex);
49844diff --git a/fs/xattr.c b/fs/xattr.c
49845index 1d7ac37..23cb9ec 100644
49846--- a/fs/xattr.c
49847+++ b/fs/xattr.c
49848@@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49849 * Extended attribute SET operations
49850 */
49851 static long
49852-setxattr(struct dentry *d, const char __user *name, const void __user *value,
49853+setxattr(struct path *path, const char __user *name, const void __user *value,
49854 size_t size, int flags)
49855 {
49856 int error;
49857@@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49858 }
49859 }
49860
49861- error = vfs_setxattr(d, kname, kvalue, size, flags);
49862+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49863+ error = -EACCES;
49864+ goto out;
49865+ }
49866+
49867+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49868 out:
49869 if (vvalue)
49870 vfree(vvalue);
49871@@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, 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@@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49881 return error;
49882 error = mnt_want_write(path.mnt);
49883 if (!error) {
49884- error = setxattr(path.dentry, name, value, size, flags);
49885+ error = setxattr(&path, name, value, size, flags);
49886 mnt_drop_write(path.mnt);
49887 }
49888 path_put(&path);
49889@@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49890 {
49891 int fput_needed;
49892 struct file *f;
49893- struct dentry *dentry;
49894 int error = -EBADF;
49895
49896 f = fget_light(fd, &fput_needed);
49897 if (!f)
49898 return error;
49899- dentry = f->f_path.dentry;
49900- audit_inode(NULL, dentry);
49901+ audit_inode(NULL, f->f_path.dentry);
49902 error = mnt_want_write_file(f);
49903 if (!error) {
49904- error = setxattr(dentry, name, value, size, flags);
49905+ error = setxattr(&f->f_path, name, value, size, flags);
49906 mnt_drop_write_file(f);
49907 }
49908 fput_light(f, fput_needed);
49909diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49910index 69d06b0..c0996e5 100644
49911--- a/fs/xattr_acl.c
49912+++ b/fs/xattr_acl.c
49913@@ -17,8 +17,8 @@
49914 struct posix_acl *
49915 posix_acl_from_xattr(const void *value, size_t size)
49916 {
49917- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49918- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49919+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49920+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49921 int count;
49922 struct posix_acl *acl;
49923 struct posix_acl_entry *acl_e;
49924diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49925index 58b815e..595ddee 100644
49926--- a/fs/xfs/xfs_bmap.c
49927+++ b/fs/xfs/xfs_bmap.c
49928@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
49929 int nmap,
49930 int ret_nmap);
49931 #else
49932-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49933+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49934 #endif /* DEBUG */
49935
49936 STATIC int
49937diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49938index 19bf0c5..9f26b02 100644
49939--- a/fs/xfs/xfs_dir2_sf.c
49940+++ b/fs/xfs/xfs_dir2_sf.c
49941@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
49942 }
49943
49944 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49945- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49946+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49947+ char name[sfep->namelen];
49948+ memcpy(name, sfep->name, sfep->namelen);
49949+ if (filldir(dirent, name, sfep->namelen,
49950+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
49951+ *offset = off & 0x7fffffff;
49952+ return 0;
49953+ }
49954+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49955 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49956 *offset = off & 0x7fffffff;
49957 return 0;
49958diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49959index 3a05a41..320bec6 100644
49960--- a/fs/xfs/xfs_ioctl.c
49961+++ b/fs/xfs/xfs_ioctl.c
49962@@ -126,7 +126,7 @@ xfs_find_handle(
49963 }
49964
49965 error = -EFAULT;
49966- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49967+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49968 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49969 goto out_put;
49970
49971diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49972index 1a25fd8..e935581 100644
49973--- a/fs/xfs/xfs_iops.c
49974+++ b/fs/xfs/xfs_iops.c
49975@@ -394,7 +394,7 @@ xfs_vn_put_link(
49976 struct nameidata *nd,
49977 void *p)
49978 {
49979- char *s = nd_get_link(nd);
49980+ const char *s = nd_get_link(nd);
49981
49982 if (!IS_ERR(s))
49983 kfree(s);
49984diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49985new file mode 100644
49986index 0000000..4d533f1
49987--- /dev/null
49988+++ b/grsecurity/Kconfig
49989@@ -0,0 +1,941 @@
49990+#
49991+# grecurity configuration
49992+#
49993+menu "Memory Protections"
49994+depends on GRKERNSEC
49995+
49996+config GRKERNSEC_KMEM
49997+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49998+ default y if GRKERNSEC_CONFIG_AUTO
49999+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50000+ help
50001+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50002+ be written to or read from to modify or leak the contents of the running
50003+ kernel. /dev/port will also not be allowed to be opened. If you have module
50004+ support disabled, enabling this will close up four ways that are
50005+ currently used to insert malicious code into the running kernel.
50006+ Even with all these features enabled, we still highly recommend that
50007+ you use the RBAC system, as it is still possible for an attacker to
50008+ modify the running kernel through privileged I/O granted by ioperm/iopl.
50009+ If you are not using XFree86, you may be able to stop this additional
50010+ case by enabling the 'Disable privileged I/O' option. Though nothing
50011+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50012+ but only to video memory, which is the only writing we allow in this
50013+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50014+ not be allowed to mprotect it with PROT_WRITE later.
50015+ It is highly recommended that you say Y here if you meet all the
50016+ conditions above.
50017+
50018+config GRKERNSEC_VM86
50019+ bool "Restrict VM86 mode"
50020+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50021+ depends on X86_32
50022+
50023+ help
50024+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50025+ make use of a special execution mode on 32bit x86 processors called
50026+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50027+ video cards and will still work with this option enabled. The purpose
50028+ of the option is to prevent exploitation of emulation errors in
50029+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
50030+ Nearly all users should be able to enable this option.
50031+
50032+config GRKERNSEC_IO
50033+ bool "Disable privileged I/O"
50034+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50035+ depends on X86
50036+ select RTC_CLASS
50037+ select RTC_INTF_DEV
50038+ select RTC_DRV_CMOS
50039+
50040+ help
50041+ If you say Y here, all ioperm and iopl calls will return an error.
50042+ Ioperm and iopl can be used to modify the running kernel.
50043+ Unfortunately, some programs need this access to operate properly,
50044+ the most notable of which are XFree86 and hwclock. hwclock can be
50045+ remedied by having RTC support in the kernel, so real-time
50046+ clock support is enabled if this option is enabled, to ensure
50047+ that hwclock operates correctly. XFree86 still will not
50048+ operate correctly with this option enabled, so DO NOT CHOOSE Y
50049+ IF YOU USE XFree86. If you use XFree86 and you still want to
50050+ protect your kernel against modification, use the RBAC system.
50051+
50052+config GRKERNSEC_PROC_MEMMAP
50053+ bool "Harden ASLR against information leaks and entropy reduction"
50054+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50055+ depends on PAX_NOEXEC || PAX_ASLR
50056+ help
50057+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50058+ give no information about the addresses of its mappings if
50059+ PaX features that rely on random addresses are enabled on the task.
50060+ In addition to sanitizing this information and disabling other
50061+ dangerous sources of information, this option causes reads of sensitive
50062+ /proc/<pid> entries where the file descriptor was opened in a different
50063+ task than the one performing the read. Such attempts are logged.
50064+ This option also limits argv/env strings for suid/sgid binaries
50065+ to 512KB to prevent a complete exhaustion of the stack entropy provided
50066+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50067+ binaries to prevent alternative mmap layouts from being abused.
50068+
50069+ If you use PaX it is essential that you say Y here as it closes up
50070+ several holes that make full ASLR useless locally.
50071+
50072+config GRKERNSEC_BRUTE
50073+ bool "Deter exploit bruteforcing"
50074+ default y if GRKERNSEC_CONFIG_AUTO
50075+ help
50076+ If you say Y here, attempts to bruteforce exploits against forking
50077+ daemons such as apache or sshd, as well as against suid/sgid binaries
50078+ will be deterred. When a child of a forking daemon is killed by PaX
50079+ or crashes due to an illegal instruction or other suspicious signal,
50080+ the parent process will be delayed 30 seconds upon every subsequent
50081+ fork until the administrator is able to assess the situation and
50082+ restart the daemon.
50083+ In the suid/sgid case, the attempt is logged, the user has all their
50084+ processes terminated, and they are prevented from executing any further
50085+ processes for 15 minutes.
50086+ It is recommended that you also enable signal logging in the auditing
50087+ section so that logs are generated when a process triggers a suspicious
50088+ signal.
50089+ If the sysctl option is enabled, a sysctl option with name
50090+ "deter_bruteforce" is created.
50091+
50092+
50093+config GRKERNSEC_MODHARDEN
50094+ bool "Harden module auto-loading"
50095+ default y if GRKERNSEC_CONFIG_AUTO
50096+ depends on MODULES
50097+ help
50098+ If you say Y here, module auto-loading in response to use of some
50099+ feature implemented by an unloaded module will be restricted to
50100+ root users. Enabling this option helps defend against attacks
50101+ by unprivileged users who abuse the auto-loading behavior to
50102+ cause a vulnerable module to load that is then exploited.
50103+
50104+ If this option prevents a legitimate use of auto-loading for a
50105+ non-root user, the administrator can execute modprobe manually
50106+ with the exact name of the module mentioned in the alert log.
50107+ Alternatively, the administrator can add the module to the list
50108+ of modules loaded at boot by modifying init scripts.
50109+
50110+ Modification of init scripts will most likely be needed on
50111+ Ubuntu servers with encrypted home directory support enabled,
50112+ as the first non-root user logging in will cause the ecb(aes),
50113+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50114+
50115+config GRKERNSEC_HIDESYM
50116+ bool "Hide kernel symbols"
50117+ default y if GRKERNSEC_CONFIG_AUTO
50118+ select PAX_USERCOPY_SLABS
50119+ help
50120+ If you say Y here, getting information on loaded modules, and
50121+ displaying all kernel symbols through a syscall will be restricted
50122+ to users with CAP_SYS_MODULE. For software compatibility reasons,
50123+ /proc/kallsyms will be restricted to the root user. The RBAC
50124+ system can hide that entry even from root.
50125+
50126+ This option also prevents leaking of kernel addresses through
50127+ several /proc entries.
50128+
50129+ Note that this option is only effective provided the following
50130+ conditions are met:
50131+ 1) The kernel using grsecurity is not precompiled by some distribution
50132+ 2) You have also enabled GRKERNSEC_DMESG
50133+ 3) You are using the RBAC system and hiding other files such as your
50134+ kernel image and System.map. Alternatively, enabling this option
50135+ causes the permissions on /boot, /lib/modules, and the kernel
50136+ source directory to change at compile time to prevent
50137+ reading by non-root users.
50138+ If the above conditions are met, this option will aid in providing a
50139+ useful protection against local kernel exploitation of overflows
50140+ and arbitrary read/write vulnerabilities.
50141+
50142+config GRKERNSEC_KERN_LOCKOUT
50143+ bool "Active kernel exploit response"
50144+ default y if GRKERNSEC_CONFIG_AUTO
50145+ depends on X86 || ARM || PPC || SPARC
50146+ help
50147+ If you say Y here, when a PaX alert is triggered due to suspicious
50148+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50149+ or an OOPS occurs due to bad memory accesses, instead of just
50150+ terminating the offending process (and potentially allowing
50151+ a subsequent exploit from the same user), we will take one of two
50152+ actions:
50153+ If the user was root, we will panic the system
50154+ If the user was non-root, we will log the attempt, terminate
50155+ all processes owned by the user, then prevent them from creating
50156+ any new processes until the system is restarted
50157+ This deters repeated kernel exploitation/bruteforcing attempts
50158+ and is useful for later forensics.
50159+
50160+endmenu
50161+menu "Role Based Access Control Options"
50162+depends on GRKERNSEC
50163+
50164+config GRKERNSEC_RBAC_DEBUG
50165+ bool
50166+
50167+config GRKERNSEC_NO_RBAC
50168+ bool "Disable RBAC system"
50169+ help
50170+ If you say Y here, the /dev/grsec device will be removed from the kernel,
50171+ preventing the RBAC system from being enabled. You should only say Y
50172+ here if you have no intention of using the RBAC system, so as to prevent
50173+ an attacker with root access from misusing the RBAC system to hide files
50174+ and processes when loadable module support and /dev/[k]mem have been
50175+ locked down.
50176+
50177+config GRKERNSEC_ACL_HIDEKERN
50178+ bool "Hide kernel processes"
50179+ help
50180+ If you say Y here, all kernel threads will be hidden to all
50181+ processes but those whose subject has the "view hidden processes"
50182+ flag.
50183+
50184+config GRKERNSEC_ACL_MAXTRIES
50185+ int "Maximum tries before password lockout"
50186+ default 3
50187+ help
50188+ This option enforces the maximum number of times a user can attempt
50189+ to authorize themselves with the grsecurity RBAC system before being
50190+ denied the ability to attempt authorization again for a specified time.
50191+ The lower the number, the harder it will be to brute-force a password.
50192+
50193+config GRKERNSEC_ACL_TIMEOUT
50194+ int "Time to wait after max password tries, in seconds"
50195+ default 30
50196+ help
50197+ This option specifies the time the user must wait after attempting to
50198+ authorize to the RBAC system with the maximum number of invalid
50199+ passwords. The higher the number, the harder it will be to brute-force
50200+ a password.
50201+
50202+endmenu
50203+menu "Filesystem Protections"
50204+depends on GRKERNSEC
50205+
50206+config GRKERNSEC_PROC
50207+ bool "Proc restrictions"
50208+ default y if GRKERNSEC_CONFIG_AUTO
50209+ help
50210+ If you say Y here, the permissions of the /proc filesystem
50211+ will be altered to enhance system security and privacy. You MUST
50212+ choose either a user only restriction or a user and group restriction.
50213+ Depending upon the option you choose, you can either restrict users to
50214+ see only the processes they themselves run, or choose a group that can
50215+ view all processes and files normally restricted to root if you choose
50216+ the "restrict to user only" option. NOTE: If you're running identd or
50217+ ntpd as a non-root user, you will have to run it as the group you
50218+ specify here.
50219+
50220+config GRKERNSEC_PROC_USER
50221+ bool "Restrict /proc to user only"
50222+ depends on GRKERNSEC_PROC
50223+ help
50224+ If you say Y here, non-root users will only be able to view their own
50225+ processes, and restricts them from viewing network-related information,
50226+ and viewing kernel symbol and module information.
50227+
50228+config GRKERNSEC_PROC_USERGROUP
50229+ bool "Allow special group"
50230+ default y if GRKERNSEC_CONFIG_AUTO
50231+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50232+ help
50233+ If you say Y here, you will be able to select a group that will be
50234+ able to view all processes and network-related information. If you've
50235+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50236+ remain hidden. This option is useful if you want to run identd as
50237+ a non-root user.
50238+
50239+config GRKERNSEC_PROC_GID
50240+ int "GID for special group"
50241+ depends on GRKERNSEC_PROC_USERGROUP
50242+ default 1001
50243+
50244+config GRKERNSEC_PROC_ADD
50245+ bool "Additional restrictions"
50246+ default y if GRKERNSEC_CONFIG_AUTO
50247+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50248+ help
50249+ If you say Y here, additional restrictions will be placed on
50250+ /proc that keep normal users from viewing device information and
50251+ slabinfo information that could be useful for exploits.
50252+
50253+config GRKERNSEC_LINK
50254+ bool "Linking restrictions"
50255+ default y if GRKERNSEC_CONFIG_AUTO
50256+ help
50257+ If you say Y here, /tmp race exploits will be prevented, since users
50258+ will no longer be able to follow symlinks owned by other users in
50259+ world-writable +t directories (e.g. /tmp), unless the owner of the
50260+ symlink is the owner of the directory. users will also not be
50261+ able to hardlink to files they do not own. If the sysctl option is
50262+ enabled, a sysctl option with name "linking_restrictions" is created.
50263+
50264+config GRKERNSEC_SYMLINKOWN
50265+ bool "Kernel-enforced SymlinksIfOwnerMatch"
50266+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50267+ help
50268+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
50269+ that prevents it from being used as a security feature. As Apache
50270+ verifies the symlink by performing a stat() against the target of
50271+ the symlink before it is followed, an attacker can setup a symlink
50272+ to point to a same-owned file, then replace the symlink with one
50273+ that targets another user's file just after Apache "validates" the
50274+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
50275+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50276+ will be in place for the group you specify. If the sysctl option
50277+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
50278+ created.
50279+
50280+config GRKERNSEC_SYMLINKOWN_GID
50281+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50282+ depends on GRKERNSEC_SYMLINKOWN
50283+ default 1006
50284+ help
50285+ Setting this GID determines what group kernel-enforced
50286+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50287+ is enabled, a sysctl option with name "symlinkown_gid" is created.
50288+
50289+config GRKERNSEC_FIFO
50290+ bool "FIFO restrictions"
50291+ default y if GRKERNSEC_CONFIG_AUTO
50292+ help
50293+ If you say Y here, users will not be able to write to FIFOs they don't
50294+ own in world-writable +t directories (e.g. /tmp), unless the owner of
50295+ the FIFO is the same owner of the directory it's held in. If the sysctl
50296+ option is enabled, a sysctl option with name "fifo_restrictions" is
50297+ created.
50298+
50299+config GRKERNSEC_SYSFS_RESTRICT
50300+ bool "Sysfs/debugfs restriction"
50301+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50302+ depends on SYSFS
50303+ help
50304+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50305+ any filesystem normally mounted under it (e.g. debugfs) will be
50306+ mostly accessible only by root. These filesystems generally provide access
50307+ to hardware and debug information that isn't appropriate for unprivileged
50308+ users of the system. Sysfs and debugfs have also become a large source
50309+ of new vulnerabilities, ranging from infoleaks to local compromise.
50310+ There has been very little oversight with an eye toward security involved
50311+ in adding new exporters of information to these filesystems, so their
50312+ use is discouraged.
50313+ For reasons of compatibility, a few directories have been whitelisted
50314+ for access by non-root users:
50315+ /sys/fs/selinux
50316+ /sys/fs/fuse
50317+ /sys/devices/system/cpu
50318+
50319+config GRKERNSEC_ROFS
50320+ bool "Runtime read-only mount protection"
50321+ help
50322+ If you say Y here, a sysctl option with name "romount_protect" will
50323+ be created. By setting this option to 1 at runtime, filesystems
50324+ will be protected in the following ways:
50325+ * No new writable mounts will be allowed
50326+ * Existing read-only mounts won't be able to be remounted read/write
50327+ * Write operations will be denied on all block devices
50328+ This option acts independently of grsec_lock: once it is set to 1,
50329+ it cannot be turned off. Therefore, please be mindful of the resulting
50330+ behavior if this option is enabled in an init script on a read-only
50331+ filesystem. This feature is mainly intended for secure embedded systems.
50332+
50333+config GRKERNSEC_CHROOT
50334+ bool "Chroot jail restrictions"
50335+ default y if GRKERNSEC_CONFIG_AUTO
50336+ help
50337+ If you say Y here, you will be able to choose several options that will
50338+ make breaking out of a chrooted jail much more difficult. If you
50339+ encounter no software incompatibilities with the following options, it
50340+ is recommended that you enable each one.
50341+
50342+config GRKERNSEC_CHROOT_MOUNT
50343+ bool "Deny mounts"
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
50348+ mount or remount filesystems. If the sysctl option is enabled, a
50349+ sysctl option with name "chroot_deny_mount" is created.
50350+
50351+config GRKERNSEC_CHROOT_DOUBLE
50352+ bool "Deny double-chroots"
50353+ default y if GRKERNSEC_CONFIG_AUTO
50354+ depends on GRKERNSEC_CHROOT
50355+ help
50356+ If you say Y here, processes inside a chroot will not be able to chroot
50357+ again outside the chroot. This is a widely used method of breaking
50358+ out of a chroot jail and should not be allowed. If the sysctl
50359+ option is enabled, a sysctl option with name
50360+ "chroot_deny_chroot" is created.
50361+
50362+config GRKERNSEC_CHROOT_PIVOT
50363+ bool "Deny pivot_root in chroot"
50364+ default y if GRKERNSEC_CONFIG_AUTO
50365+ depends on GRKERNSEC_CHROOT
50366+ help
50367+ If you say Y here, processes inside a chroot will not be able to use
50368+ a function called pivot_root() that was introduced in Linux 2.3.41. It
50369+ works similar to chroot in that it changes the root filesystem. This
50370+ function could be misused in a chrooted process to attempt to break out
50371+ of the chroot, and therefore should not be allowed. If the sysctl
50372+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
50373+ created.
50374+
50375+config GRKERNSEC_CHROOT_CHDIR
50376+ bool "Enforce chdir(\"/\") on all chroots"
50377+ default y if GRKERNSEC_CONFIG_AUTO
50378+ depends on GRKERNSEC_CHROOT
50379+ help
50380+ If you say Y here, the current working directory of all newly-chrooted
50381+ applications will be set to the the root directory of the chroot.
50382+ The man page on chroot(2) states:
50383+ Note that this call does not change the current working
50384+ directory, so that `.' can be outside the tree rooted at
50385+ `/'. In particular, the super-user can escape from a
50386+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50387+
50388+ It is recommended that you say Y here, since it's not known to break
50389+ any software. If the sysctl option is enabled, a sysctl option with
50390+ name "chroot_enforce_chdir" is created.
50391+
50392+config GRKERNSEC_CHROOT_CHMOD
50393+ bool "Deny (f)chmod +s"
50394+ default y if GRKERNSEC_CONFIG_AUTO
50395+ depends on GRKERNSEC_CHROOT
50396+ help
50397+ If you say Y here, processes inside a chroot will not be able to chmod
50398+ or fchmod files to make them have suid or sgid bits. This protects
50399+ against another published method of breaking a chroot. If the sysctl
50400+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
50401+ created.
50402+
50403+config GRKERNSEC_CHROOT_FCHDIR
50404+ bool "Deny fchdir out of chroot"
50405+ default y if GRKERNSEC_CONFIG_AUTO
50406+ depends on GRKERNSEC_CHROOT
50407+ help
50408+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
50409+ to a file descriptor of the chrooting process that points to a directory
50410+ outside the filesystem will be stopped. If the sysctl option
50411+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50412+
50413+config GRKERNSEC_CHROOT_MKNOD
50414+ bool "Deny mknod"
50415+ default y if GRKERNSEC_CONFIG_AUTO
50416+ depends on GRKERNSEC_CHROOT
50417+ help
50418+ If you say Y here, processes inside a chroot will not be allowed to
50419+ mknod. The problem with using mknod inside a chroot is that it
50420+ would allow an attacker to create a device entry that is the same
50421+ as one on the physical root of your system, which could range from
50422+ anything from the console device to a device for your harddrive (which
50423+ they could then use to wipe the drive or steal data). It is recommended
50424+ that you say Y here, unless you run into software incompatibilities.
50425+ If the sysctl option is enabled, a sysctl option with name
50426+ "chroot_deny_mknod" is created.
50427+
50428+config GRKERNSEC_CHROOT_SHMAT
50429+ bool "Deny shmat() out of chroot"
50430+ default y if GRKERNSEC_CONFIG_AUTO
50431+ depends on GRKERNSEC_CHROOT
50432+ help
50433+ If you say Y here, processes inside a chroot will not be able to attach
50434+ to shared memory segments that were created outside of the chroot jail.
50435+ It is recommended that you say Y here. If the sysctl option is enabled,
50436+ a sysctl option with name "chroot_deny_shmat" is created.
50437+
50438+config GRKERNSEC_CHROOT_UNIX
50439+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
50440+ default y if GRKERNSEC_CONFIG_AUTO
50441+ depends on GRKERNSEC_CHROOT
50442+ help
50443+ If you say Y here, processes inside a chroot will not be able to
50444+ connect to abstract (meaning not belonging to a filesystem) Unix
50445+ domain sockets that were bound outside of a chroot. It is recommended
50446+ that you say Y here. If the sysctl option is enabled, a sysctl option
50447+ with name "chroot_deny_unix" is created.
50448+
50449+config GRKERNSEC_CHROOT_FINDTASK
50450+ bool "Protect outside processes"
50451+ default y if GRKERNSEC_CONFIG_AUTO
50452+ depends on GRKERNSEC_CHROOT
50453+ help
50454+ If you say Y here, processes inside a chroot will not be able to
50455+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50456+ getsid, or view any process outside of the chroot. If the sysctl
50457+ option is enabled, a sysctl option with name "chroot_findtask" is
50458+ created.
50459+
50460+config GRKERNSEC_CHROOT_NICE
50461+ bool "Restrict priority changes"
50462+ default y if GRKERNSEC_CONFIG_AUTO
50463+ depends on GRKERNSEC_CHROOT
50464+ help
50465+ If you say Y here, processes inside a chroot will not be able to raise
50466+ the priority of processes in the chroot, or alter the priority of
50467+ processes outside the chroot. This provides more security than simply
50468+ removing CAP_SYS_NICE from the process' capability set. If the
50469+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50470+ is created.
50471+
50472+config GRKERNSEC_CHROOT_SYSCTL
50473+ bool "Deny sysctl writes"
50474+ default y if GRKERNSEC_CONFIG_AUTO
50475+ depends on GRKERNSEC_CHROOT
50476+ help
50477+ If you say Y here, an attacker in a chroot will not be able to
50478+ write to sysctl entries, either by sysctl(2) or through a /proc
50479+ interface. It is strongly recommended that you say Y here. If the
50480+ sysctl option is enabled, a sysctl option with name
50481+ "chroot_deny_sysctl" is created.
50482+
50483+config GRKERNSEC_CHROOT_CAPS
50484+ bool "Capability restrictions"
50485+ default y if GRKERNSEC_CONFIG_AUTO
50486+ depends on GRKERNSEC_CHROOT
50487+ help
50488+ If you say Y here, the capabilities on all processes within a
50489+ chroot jail will be lowered to stop module insertion, raw i/o,
50490+ system and net admin tasks, rebooting the system, modifying immutable
50491+ files, modifying IPC owned by another, and changing the system time.
50492+ This is left an option because it can break some apps. Disable this
50493+ if your chrooted apps are having problems performing those kinds of
50494+ tasks. If the sysctl option is enabled, a sysctl option with
50495+ name "chroot_caps" is created.
50496+
50497+endmenu
50498+menu "Kernel Auditing"
50499+depends on GRKERNSEC
50500+
50501+config GRKERNSEC_AUDIT_GROUP
50502+ bool "Single group for auditing"
50503+ help
50504+ If you say Y here, the exec, chdir, and (un)mount logging features
50505+ will only operate on a group you specify. This option is recommended
50506+ if you only want to watch certain users instead of having a large
50507+ amount of logs from the entire system. If the sysctl option is enabled,
50508+ a sysctl option with name "audit_group" is created.
50509+
50510+config GRKERNSEC_AUDIT_GID
50511+ int "GID for auditing"
50512+ depends on GRKERNSEC_AUDIT_GROUP
50513+ default 1007
50514+
50515+config GRKERNSEC_EXECLOG
50516+ bool "Exec logging"
50517+ help
50518+ If you say Y here, all execve() calls will be logged (since the
50519+ other exec*() calls are frontends to execve(), all execution
50520+ will be logged). Useful for shell-servers that like to keep track
50521+ of their users. If the sysctl option is enabled, a sysctl option with
50522+ name "exec_logging" is created.
50523+ WARNING: This option when enabled will produce a LOT of logs, especially
50524+ on an active system.
50525+
50526+config GRKERNSEC_RESLOG
50527+ bool "Resource logging"
50528+ default y if GRKERNSEC_CONFIG_AUTO
50529+ help
50530+ If you say Y here, all attempts to overstep resource limits will
50531+ be logged with the resource name, the requested size, and the current
50532+ limit. It is highly recommended that you say Y here. If the sysctl
50533+ option is enabled, a sysctl option with name "resource_logging" is
50534+ created. If the RBAC system is enabled, the sysctl value is ignored.
50535+
50536+config GRKERNSEC_CHROOT_EXECLOG
50537+ bool "Log execs within chroot"
50538+ help
50539+ If you say Y here, all executions inside a chroot jail will be logged
50540+ to syslog. This can cause a large amount of logs if certain
50541+ applications (eg. djb's daemontools) are installed on the system, and
50542+ is therefore left as an option. If the sysctl option is enabled, a
50543+ sysctl option with name "chroot_execlog" is created.
50544+
50545+config GRKERNSEC_AUDIT_PTRACE
50546+ bool "Ptrace logging"
50547+ help
50548+ If you say Y here, all attempts to attach to a process via ptrace
50549+ will be logged. If the sysctl option is enabled, a sysctl option
50550+ with name "audit_ptrace" is created.
50551+
50552+config GRKERNSEC_AUDIT_CHDIR
50553+ bool "Chdir logging"
50554+ help
50555+ If you say Y here, all chdir() calls will be logged. If the sysctl
50556+ option is enabled, a sysctl option with name "audit_chdir" is created.
50557+
50558+config GRKERNSEC_AUDIT_MOUNT
50559+ bool "(Un)Mount logging"
50560+ help
50561+ If you say Y here, all mounts and unmounts will be logged. If the
50562+ sysctl option is enabled, a sysctl option with name "audit_mount" is
50563+ created.
50564+
50565+config GRKERNSEC_SIGNAL
50566+ bool "Signal logging"
50567+ default y if GRKERNSEC_CONFIG_AUTO
50568+ help
50569+ If you say Y here, certain important signals will be logged, such as
50570+ SIGSEGV, which will as a result inform you of when a error in a program
50571+ occurred, which in some cases could mean a possible exploit attempt.
50572+ If the sysctl option is enabled, a sysctl option with name
50573+ "signal_logging" is created.
50574+
50575+config GRKERNSEC_FORKFAIL
50576+ bool "Fork failure logging"
50577+ help
50578+ If you say Y here, all failed fork() attempts will be logged.
50579+ This could suggest a fork bomb, or someone attempting to overstep
50580+ their process limit. If the sysctl option is enabled, a sysctl option
50581+ with name "forkfail_logging" is created.
50582+
50583+config GRKERNSEC_TIME
50584+ bool "Time change logging"
50585+ default y if GRKERNSEC_CONFIG_AUTO
50586+ help
50587+ If you say Y here, any changes of the system clock will be logged.
50588+ If the sysctl option is enabled, a sysctl option with name
50589+ "timechange_logging" is created.
50590+
50591+config GRKERNSEC_PROC_IPADDR
50592+ bool "/proc/<pid>/ipaddr support"
50593+ default y if GRKERNSEC_CONFIG_AUTO
50594+ help
50595+ If you say Y here, a new entry will be added to each /proc/<pid>
50596+ directory that contains the IP address of the person using the task.
50597+ The IP is carried across local TCP and AF_UNIX stream sockets.
50598+ This information can be useful for IDS/IPSes to perform remote response
50599+ to a local attack. The entry is readable by only the owner of the
50600+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50601+ the RBAC system), and thus does not create privacy concerns.
50602+
50603+config GRKERNSEC_RWXMAP_LOG
50604+ bool 'Denied RWX mmap/mprotect logging'
50605+ default y if GRKERNSEC_CONFIG_AUTO
50606+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50607+ help
50608+ If you say Y here, calls to mmap() and mprotect() with explicit
50609+ usage of PROT_WRITE and PROT_EXEC together will be logged when
50610+ denied by the PAX_MPROTECT feature. If the sysctl option is
50611+ enabled, a sysctl option with name "rwxmap_logging" is created.
50612+
50613+config GRKERNSEC_AUDIT_TEXTREL
50614+ bool 'ELF text relocations logging (READ HELP)'
50615+ depends on PAX_MPROTECT
50616+ help
50617+ If you say Y here, text relocations will be logged with the filename
50618+ of the offending library or binary. The purpose of the feature is
50619+ to help Linux distribution developers get rid of libraries and
50620+ binaries that need text relocations which hinder the future progress
50621+ of PaX. Only Linux distribution developers should say Y here, and
50622+ never on a production machine, as this option creates an information
50623+ leak that could aid an attacker in defeating the randomization of
50624+ a single memory region. If the sysctl option is enabled, a sysctl
50625+ option with name "audit_textrel" is created.
50626+
50627+endmenu
50628+
50629+menu "Executable Protections"
50630+depends on GRKERNSEC
50631+
50632+config GRKERNSEC_DMESG
50633+ bool "Dmesg(8) restriction"
50634+ default y if GRKERNSEC_CONFIG_AUTO
50635+ help
50636+ If you say Y here, non-root users will not be able to use dmesg(8)
50637+ to view up to the last 4kb of messages in the kernel's log buffer.
50638+ The kernel's log buffer often contains kernel addresses and other
50639+ identifying information useful to an attacker in fingerprinting a
50640+ system for a targeted exploit.
50641+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
50642+ created.
50643+
50644+config GRKERNSEC_HARDEN_PTRACE
50645+ bool "Deter ptrace-based process snooping"
50646+ default y if GRKERNSEC_CONFIG_AUTO
50647+ help
50648+ If you say Y here, TTY sniffers and other malicious monitoring
50649+ programs implemented through ptrace will be defeated. If you
50650+ have been using the RBAC system, this option has already been
50651+ enabled for several years for all users, with the ability to make
50652+ fine-grained exceptions.
50653+
50654+ This option only affects the ability of non-root users to ptrace
50655+ processes that are not a descendent of the ptracing process.
50656+ This means that strace ./binary and gdb ./binary will still work,
50657+ but attaching to arbitrary processes will not. If the sysctl
50658+ option is enabled, a sysctl option with name "harden_ptrace" is
50659+ created.
50660+
50661+config GRKERNSEC_PTRACE_READEXEC
50662+ bool "Require read access to ptrace sensitive binaries"
50663+ default y if GRKERNSEC_CONFIG_AUTO
50664+ help
50665+ If you say Y here, unprivileged users will not be able to ptrace unreadable
50666+ binaries. This option is useful in environments that
50667+ remove the read bits (e.g. file mode 4711) from suid binaries to
50668+ prevent infoleaking of their contents. This option adds
50669+ consistency to the use of that file mode, as the binary could normally
50670+ be read out when run without privileges while ptracing.
50671+
50672+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50673+ is created.
50674+
50675+config GRKERNSEC_SETXID
50676+ bool "Enforce consistent multithreaded privileges"
50677+ default y if GRKERNSEC_CONFIG_AUTO
50678+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
50679+ help
50680+ If you say Y here, a change from a root uid to a non-root uid
50681+ in a multithreaded application will cause the resulting uids,
50682+ gids, supplementary groups, and capabilities in that thread
50683+ to be propagated to the other threads of the process. In most
50684+ cases this is unnecessary, as glibc will emulate this behavior
50685+ on behalf of the application. Other libcs do not act in the
50686+ same way, allowing the other threads of the process to continue
50687+ running with root privileges. If the sysctl option is enabled,
50688+ a sysctl option with name "consistent_setxid" is created.
50689+
50690+config GRKERNSEC_TPE
50691+ bool "Trusted Path Execution (TPE)"
50692+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50693+ help
50694+ If you say Y here, you will be able to choose a gid to add to the
50695+ supplementary groups of users you want to mark as "untrusted."
50696+ These users will not be able to execute any files that are not in
50697+ root-owned directories writable only by root. If the sysctl option
50698+ is enabled, a sysctl option with name "tpe" is created.
50699+
50700+config GRKERNSEC_TPE_ALL
50701+ bool "Partially restrict all non-root users"
50702+ depends on GRKERNSEC_TPE
50703+ help
50704+ If you say Y here, all non-root users will be covered under
50705+ a weaker TPE restriction. This is separate from, and in addition to,
50706+ the main TPE options that you have selected elsewhere. Thus, if a
50707+ "trusted" GID is chosen, this restriction applies to even that GID.
50708+ Under this restriction, all non-root users will only be allowed to
50709+ execute files in directories they own that are not group or
50710+ world-writable, or in directories owned by root and writable only by
50711+ root. If the sysctl option is enabled, a sysctl option with name
50712+ "tpe_restrict_all" is created.
50713+
50714+config GRKERNSEC_TPE_INVERT
50715+ bool "Invert GID option"
50716+ depends on GRKERNSEC_TPE
50717+ help
50718+ If you say Y here, the group you specify in the TPE configuration will
50719+ decide what group TPE restrictions will be *disabled* for. This
50720+ option is useful if you want TPE restrictions to be applied to most
50721+ users on the system. If the sysctl option is enabled, a sysctl option
50722+ with name "tpe_invert" is created. Unlike other sysctl options, this
50723+ entry will default to on for backward-compatibility.
50724+
50725+config GRKERNSEC_TPE_GID
50726+ int "GID for untrusted 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+ *enabled* for. If the sysctl option is enabled, a sysctl option
50732+ with name "tpe_gid" is created.
50733+
50734+config GRKERNSEC_TPE_GID
50735+ int "GID for trusted users"
50736+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50737+ default 1005
50738+ help
50739+ Setting this GID determines what group TPE restrictions will be
50740+ *disabled* for. If the sysctl option is enabled, a sysctl option
50741+ with name "tpe_gid" is created.
50742+
50743+endmenu
50744+menu "Network Protections"
50745+depends on GRKERNSEC
50746+
50747+config GRKERNSEC_RANDNET
50748+ bool "Larger entropy pools"
50749+ default y if GRKERNSEC_CONFIG_AUTO
50750+ help
50751+ If you say Y here, the entropy pools used for many features of Linux
50752+ and grsecurity will be doubled in size. Since several grsecurity
50753+ features use additional randomness, it is recommended that you say Y
50754+ here. Saying Y here has a similar effect as modifying
50755+ /proc/sys/kernel/random/poolsize.
50756+
50757+config GRKERNSEC_BLACKHOLE
50758+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50759+ default y if GRKERNSEC_CONFIG_AUTO
50760+ depends on NET
50761+ help
50762+ If you say Y here, neither TCP resets nor ICMP
50763+ destination-unreachable packets will be sent in response to packets
50764+ sent to ports for which no associated listening process exists.
50765+ This feature supports both IPV4 and IPV6 and exempts the
50766+ loopback interface from blackholing. Enabling this feature
50767+ makes a host more resilient to DoS attacks and reduces network
50768+ visibility against scanners.
50769+
50770+ The blackhole feature as-implemented is equivalent to the FreeBSD
50771+ blackhole feature, as it prevents RST responses to all packets, not
50772+ just SYNs. Under most application behavior this causes no
50773+ problems, but applications (like haproxy) may not close certain
50774+ connections in a way that cleanly terminates them on the remote
50775+ end, leaving the remote host in LAST_ACK state. Because of this
50776+ side-effect and to prevent intentional LAST_ACK DoSes, this
50777+ feature also adds automatic mitigation against such attacks.
50778+ The mitigation drastically reduces the amount of time a socket
50779+ can spend in LAST_ACK state. If you're using haproxy and not
50780+ all servers it connects to have this option enabled, consider
50781+ disabling this feature on the haproxy host.
50782+
50783+ If the sysctl option is enabled, two sysctl options with names
50784+ "ip_blackhole" and "lastack_retries" will be created.
50785+ While "ip_blackhole" takes the standard zero/non-zero on/off
50786+ toggle, "lastack_retries" uses the same kinds of values as
50787+ "tcp_retries1" and "tcp_retries2". The default value of 4
50788+ prevents a socket from lasting more than 45 seconds in LAST_ACK
50789+ state.
50790+
50791+config GRKERNSEC_SOCKET
50792+ bool "Socket restrictions"
50793+ depends on NET
50794+ help
50795+ If you say Y here, you will be able to choose from several options.
50796+ If you assign a GID on your system and add it to the supplementary
50797+ groups of users you want to restrict socket access to, this patch
50798+ will perform up to three things, based on the option(s) you choose.
50799+
50800+config GRKERNSEC_SOCKET_ALL
50801+ bool "Deny any sockets to group"
50802+ depends on GRKERNSEC_SOCKET
50803+ help
50804+ If you say Y here, you will be able to choose a GID of whose users will
50805+ be unable to connect to other hosts from your machine or run server
50806+ applications from your machine. If the sysctl option is enabled, a
50807+ sysctl option with name "socket_all" is created.
50808+
50809+config GRKERNSEC_SOCKET_ALL_GID
50810+ int "GID to deny all sockets for"
50811+ depends on GRKERNSEC_SOCKET_ALL
50812+ default 1004
50813+ help
50814+ Here you can choose the GID to disable socket access for. Remember to
50815+ add the users you want socket access disabled for to the GID
50816+ specified here. If the sysctl option is enabled, a sysctl option
50817+ with name "socket_all_gid" is created.
50818+
50819+config GRKERNSEC_SOCKET_CLIENT
50820+ bool "Deny client sockets to group"
50821+ depends on GRKERNSEC_SOCKET
50822+ help
50823+ If you say Y here, you will be able to choose a GID of whose users will
50824+ be unable to connect to other hosts from your machine, but will be
50825+ able to run servers. If this option is enabled, all users in the group
50826+ you specify will have to use passive mode when initiating ftp transfers
50827+ from the shell on your machine. If the sysctl option is enabled, a
50828+ sysctl option with name "socket_client" is created.
50829+
50830+config GRKERNSEC_SOCKET_CLIENT_GID
50831+ int "GID to deny client sockets for"
50832+ depends on GRKERNSEC_SOCKET_CLIENT
50833+ default 1003
50834+ help
50835+ Here you can choose the GID to disable client socket access for.
50836+ Remember to add the users you want client socket access disabled for to
50837+ the GID specified here. If the sysctl option is enabled, a sysctl
50838+ option with name "socket_client_gid" is created.
50839+
50840+config GRKERNSEC_SOCKET_SERVER
50841+ bool "Deny server sockets to group"
50842+ depends on GRKERNSEC_SOCKET
50843+ help
50844+ If you say Y here, you will be able to choose a GID of whose users will
50845+ be unable to run server applications from your machine. If the sysctl
50846+ option is enabled, a sysctl option with name "socket_server" is created.
50847+
50848+config GRKERNSEC_SOCKET_SERVER_GID
50849+ int "GID to deny server sockets for"
50850+ depends on GRKERNSEC_SOCKET_SERVER
50851+ default 1002
50852+ help
50853+ Here you can choose the GID to disable server socket access for.
50854+ Remember to add the users you want server socket access disabled for to
50855+ the GID specified here. If the sysctl option is enabled, a sysctl
50856+ option with name "socket_server_gid" is created.
50857+
50858+endmenu
50859+menu "Sysctl Support"
50860+depends on GRKERNSEC && SYSCTL
50861+
50862+config GRKERNSEC_SYSCTL
50863+ bool "Sysctl support"
50864+ default y if GRKERNSEC_CONFIG_AUTO
50865+ help
50866+ If you say Y here, you will be able to change the options that
50867+ grsecurity runs with at bootup, without having to recompile your
50868+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50869+ to enable (1) or disable (0) various features. All the sysctl entries
50870+ are mutable until the "grsec_lock" entry is set to a non-zero value.
50871+ All features enabled in the kernel configuration are disabled at boot
50872+ if you do not say Y to the "Turn on features by default" option.
50873+ All options should be set at startup, and the grsec_lock entry should
50874+ be set to a non-zero value after all the options are set.
50875+ *THIS IS EXTREMELY IMPORTANT*
50876+
50877+config GRKERNSEC_SYSCTL_DISTRO
50878+ bool "Extra sysctl support for distro makers (READ HELP)"
50879+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50880+ help
50881+ If you say Y here, additional sysctl options will be created
50882+ for features that affect processes running as root. Therefore,
50883+ it is critical when using this option that the grsec_lock entry be
50884+ enabled after boot. Only distros with prebuilt kernel packages
50885+ with this option enabled that can ensure grsec_lock is enabled
50886+ after boot should use this option.
50887+ *Failure to set grsec_lock after boot makes all grsec features
50888+ this option covers useless*
50889+
50890+ Currently this option creates the following sysctl entries:
50891+ "Disable Privileged I/O": "disable_priv_io"
50892+
50893+config GRKERNSEC_SYSCTL_ON
50894+ bool "Turn on features by default"
50895+ default y if GRKERNSEC_CONFIG_AUTO
50896+ depends on GRKERNSEC_SYSCTL
50897+ help
50898+ If you say Y here, instead of having all features enabled in the
50899+ kernel configuration disabled at boot time, the features will be
50900+ enabled at boot time. It is recommended you say Y here unless
50901+ there is some reason you would want all sysctl-tunable features to
50902+ be disabled by default. As mentioned elsewhere, it is important
50903+ to enable the grsec_lock entry once you have finished modifying
50904+ the sysctl entries.
50905+
50906+endmenu
50907+menu "Logging Options"
50908+depends on GRKERNSEC
50909+
50910+config GRKERNSEC_FLOODTIME
50911+ int "Seconds in between log messages (minimum)"
50912+ default 10
50913+ help
50914+ This option allows you to enforce the number of seconds between
50915+ grsecurity log messages. The default should be suitable for most
50916+ people, however, if you choose to change it, choose a value small enough
50917+ to allow informative logs to be produced, but large enough to
50918+ prevent flooding.
50919+
50920+config GRKERNSEC_FLOODBURST
50921+ int "Number of messages in a burst (maximum)"
50922+ default 6
50923+ help
50924+ This option allows you to choose the maximum number of messages allowed
50925+ within the flood time interval you chose in a separate option. The
50926+ default should be suitable for most people, however if you find that
50927+ many of your logs are being interpreted as flooding, you may want to
50928+ raise this value.
50929+
50930+endmenu
50931diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50932new file mode 100644
50933index 0000000..1b9afa9
50934--- /dev/null
50935+++ b/grsecurity/Makefile
50936@@ -0,0 +1,38 @@
50937+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50938+# during 2001-2009 it has been completely redesigned by Brad Spengler
50939+# into an RBAC system
50940+#
50941+# All code in this directory and various hooks inserted throughout the kernel
50942+# are copyright Brad Spengler - Open Source Security, Inc., and released
50943+# under the GPL v2 or higher
50944+
50945+KBUILD_CFLAGS += -Werror
50946+
50947+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50948+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
50949+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50950+
50951+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50952+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50953+ gracl_learn.o grsec_log.o
50954+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50955+
50956+ifdef CONFIG_NET
50957+obj-y += grsec_sock.o
50958+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50959+endif
50960+
50961+ifndef CONFIG_GRKERNSEC
50962+obj-y += grsec_disabled.o
50963+endif
50964+
50965+ifdef CONFIG_GRKERNSEC_HIDESYM
50966+extra-y := grsec_hidesym.o
50967+$(obj)/grsec_hidesym.o:
50968+ @-chmod -f 500 /boot
50969+ @-chmod -f 500 /lib/modules
50970+ @-chmod -f 500 /lib64/modules
50971+ @-chmod -f 500 /lib32/modules
50972+ @-chmod -f 700 .
50973+ @echo ' grsec: protected kernel image paths'
50974+endif
50975diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50976new file mode 100644
50977index 0000000..bda2a91
50978--- /dev/null
50979+++ b/grsecurity/gracl.c
50980@@ -0,0 +1,4017 @@
50981+#include <linux/kernel.h>
50982+#include <linux/module.h>
50983+#include <linux/sched.h>
50984+#include <linux/mm.h>
50985+#include <linux/file.h>
50986+#include <linux/fs.h>
50987+#include <linux/namei.h>
50988+#include <linux/mount.h>
50989+#include <linux/tty.h>
50990+#include <linux/proc_fs.h>
50991+#include <linux/lglock.h>
50992+#include <linux/slab.h>
50993+#include <linux/vmalloc.h>
50994+#include <linux/types.h>
50995+#include <linux/sysctl.h>
50996+#include <linux/netdevice.h>
50997+#include <linux/ptrace.h>
50998+#include <linux/gracl.h>
50999+#include <linux/gralloc.h>
51000+#include <linux/security.h>
51001+#include <linux/grinternal.h>
51002+#include <linux/pid_namespace.h>
51003+#include <linux/stop_machine.h>
51004+#include <linux/fdtable.h>
51005+#include <linux/percpu.h>
51006+#include <linux/lglock.h>
51007+#include "../fs/mount.h"
51008+
51009+#include <asm/uaccess.h>
51010+#include <asm/errno.h>
51011+#include <asm/mman.h>
51012+
51013+extern struct lglock vfsmount_lock;
51014+
51015+static struct acl_role_db acl_role_set;
51016+static struct name_db name_set;
51017+static struct inodev_db inodev_set;
51018+
51019+/* for keeping track of userspace pointers used for subjects, so we
51020+ can share references in the kernel as well
51021+*/
51022+
51023+static struct path real_root;
51024+
51025+static struct acl_subj_map_db subj_map_set;
51026+
51027+static struct acl_role_label *default_role;
51028+
51029+static struct acl_role_label *role_list;
51030+
51031+static u16 acl_sp_role_value;
51032+
51033+extern char *gr_shared_page[4];
51034+static DEFINE_MUTEX(gr_dev_mutex);
51035+DEFINE_RWLOCK(gr_inode_lock);
51036+
51037+struct gr_arg *gr_usermode;
51038+
51039+static unsigned int gr_status __read_only = GR_STATUS_INIT;
51040+
51041+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51042+extern void gr_clear_learn_entries(void);
51043+
51044+#ifdef CONFIG_GRKERNSEC_RESLOG
51045+extern void gr_log_resource(const struct task_struct *task,
51046+ const int res, const unsigned long wanted, const int gt);
51047+#endif
51048+
51049+unsigned char *gr_system_salt;
51050+unsigned char *gr_system_sum;
51051+
51052+static struct sprole_pw **acl_special_roles = NULL;
51053+static __u16 num_sprole_pws = 0;
51054+
51055+static struct acl_role_label *kernel_role = NULL;
51056+
51057+static unsigned int gr_auth_attempts = 0;
51058+static unsigned long gr_auth_expires = 0UL;
51059+
51060+#ifdef CONFIG_NET
51061+extern struct vfsmount *sock_mnt;
51062+#endif
51063+
51064+extern struct vfsmount *pipe_mnt;
51065+extern struct vfsmount *shm_mnt;
51066+#ifdef CONFIG_HUGETLBFS
51067+extern struct vfsmount *hugetlbfs_vfsmount;
51068+#endif
51069+
51070+static struct acl_object_label *fakefs_obj_rw;
51071+static struct acl_object_label *fakefs_obj_rwx;
51072+
51073+extern int gr_init_uidset(void);
51074+extern void gr_free_uidset(void);
51075+extern void gr_remove_uid(uid_t uid);
51076+extern int gr_find_uid(uid_t uid);
51077+
51078+__inline__ int
51079+gr_acl_is_enabled(void)
51080+{
51081+ return (gr_status & GR_READY);
51082+}
51083+
51084+#ifdef CONFIG_BTRFS_FS
51085+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51086+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51087+#endif
51088+
51089+static inline dev_t __get_dev(const struct dentry *dentry)
51090+{
51091+#ifdef CONFIG_BTRFS_FS
51092+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51093+ return get_btrfs_dev_from_inode(dentry->d_inode);
51094+ else
51095+#endif
51096+ return dentry->d_inode->i_sb->s_dev;
51097+}
51098+
51099+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51100+{
51101+ return __get_dev(dentry);
51102+}
51103+
51104+static char gr_task_roletype_to_char(struct task_struct *task)
51105+{
51106+ switch (task->role->roletype &
51107+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51108+ GR_ROLE_SPECIAL)) {
51109+ case GR_ROLE_DEFAULT:
51110+ return 'D';
51111+ case GR_ROLE_USER:
51112+ return 'U';
51113+ case GR_ROLE_GROUP:
51114+ return 'G';
51115+ case GR_ROLE_SPECIAL:
51116+ return 'S';
51117+ }
51118+
51119+ return 'X';
51120+}
51121+
51122+char gr_roletype_to_char(void)
51123+{
51124+ return gr_task_roletype_to_char(current);
51125+}
51126+
51127+__inline__ int
51128+gr_acl_tpe_check(void)
51129+{
51130+ if (unlikely(!(gr_status & GR_READY)))
51131+ return 0;
51132+ if (current->role->roletype & GR_ROLE_TPE)
51133+ return 1;
51134+ else
51135+ return 0;
51136+}
51137+
51138+int
51139+gr_handle_rawio(const struct inode *inode)
51140+{
51141+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51142+ if (inode && S_ISBLK(inode->i_mode) &&
51143+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51144+ !capable(CAP_SYS_RAWIO))
51145+ return 1;
51146+#endif
51147+ return 0;
51148+}
51149+
51150+static int
51151+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51152+{
51153+ if (likely(lena != lenb))
51154+ return 0;
51155+
51156+ return !memcmp(a, b, lena);
51157+}
51158+
51159+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51160+{
51161+ *buflen -= namelen;
51162+ if (*buflen < 0)
51163+ return -ENAMETOOLONG;
51164+ *buffer -= namelen;
51165+ memcpy(*buffer, str, namelen);
51166+ return 0;
51167+}
51168+
51169+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51170+{
51171+ return prepend(buffer, buflen, name->name, name->len);
51172+}
51173+
51174+static int prepend_path(const struct path *path, struct path *root,
51175+ char **buffer, int *buflen)
51176+{
51177+ struct dentry *dentry = path->dentry;
51178+ struct vfsmount *vfsmnt = path->mnt;
51179+ struct mount *mnt = real_mount(vfsmnt);
51180+ bool slash = false;
51181+ int error = 0;
51182+
51183+ while (dentry != root->dentry || vfsmnt != root->mnt) {
51184+ struct dentry * parent;
51185+
51186+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51187+ /* Global root? */
51188+ if (!mnt_has_parent(mnt)) {
51189+ goto out;
51190+ }
51191+ dentry = mnt->mnt_mountpoint;
51192+ mnt = mnt->mnt_parent;
51193+ vfsmnt = &mnt->mnt;
51194+ continue;
51195+ }
51196+ parent = dentry->d_parent;
51197+ prefetch(parent);
51198+ spin_lock(&dentry->d_lock);
51199+ error = prepend_name(buffer, buflen, &dentry->d_name);
51200+ spin_unlock(&dentry->d_lock);
51201+ if (!error)
51202+ error = prepend(buffer, buflen, "/", 1);
51203+ if (error)
51204+ break;
51205+
51206+ slash = true;
51207+ dentry = parent;
51208+ }
51209+
51210+out:
51211+ if (!error && !slash)
51212+ error = prepend(buffer, buflen, "/", 1);
51213+
51214+ return error;
51215+}
51216+
51217+/* this must be called with vfsmount_lock and rename_lock held */
51218+
51219+static char *__our_d_path(const struct path *path, struct path *root,
51220+ char *buf, int buflen)
51221+{
51222+ char *res = buf + buflen;
51223+ int error;
51224+
51225+ prepend(&res, &buflen, "\0", 1);
51226+ error = prepend_path(path, root, &res, &buflen);
51227+ if (error)
51228+ return ERR_PTR(error);
51229+
51230+ return res;
51231+}
51232+
51233+static char *
51234+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51235+{
51236+ char *retval;
51237+
51238+ retval = __our_d_path(path, root, buf, buflen);
51239+ if (unlikely(IS_ERR(retval)))
51240+ retval = strcpy(buf, "<path too long>");
51241+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51242+ retval[1] = '\0';
51243+
51244+ return retval;
51245+}
51246+
51247+static char *
51248+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51249+ char *buf, int buflen)
51250+{
51251+ struct path path;
51252+ char *res;
51253+
51254+ path.dentry = (struct dentry *)dentry;
51255+ path.mnt = (struct vfsmount *)vfsmnt;
51256+
51257+ /* we can use real_root.dentry, real_root.mnt, because this is only called
51258+ by the RBAC system */
51259+ res = gen_full_path(&path, &real_root, buf, buflen);
51260+
51261+ return res;
51262+}
51263+
51264+static char *
51265+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51266+ char *buf, int buflen)
51267+{
51268+ char *res;
51269+ struct path path;
51270+ struct path root;
51271+ struct task_struct *reaper = init_pid_ns.child_reaper;
51272+
51273+ path.dentry = (struct dentry *)dentry;
51274+ path.mnt = (struct vfsmount *)vfsmnt;
51275+
51276+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51277+ get_fs_root(reaper->fs, &root);
51278+
51279+ write_seqlock(&rename_lock);
51280+ br_read_lock(&vfsmount_lock);
51281+ res = gen_full_path(&path, &root, buf, buflen);
51282+ br_read_unlock(&vfsmount_lock);
51283+ write_sequnlock(&rename_lock);
51284+
51285+ path_put(&root);
51286+ return res;
51287+}
51288+
51289+static char *
51290+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51291+{
51292+ char *ret;
51293+ write_seqlock(&rename_lock);
51294+ br_read_lock(&vfsmount_lock);
51295+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51296+ PAGE_SIZE);
51297+ br_read_unlock(&vfsmount_lock);
51298+ write_sequnlock(&rename_lock);
51299+ return ret;
51300+}
51301+
51302+static char *
51303+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51304+{
51305+ char *ret;
51306+ char *buf;
51307+ int buflen;
51308+
51309+ write_seqlock(&rename_lock);
51310+ br_read_lock(&vfsmount_lock);
51311+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51312+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51313+ buflen = (int)(ret - buf);
51314+ if (buflen >= 5)
51315+ prepend(&ret, &buflen, "/proc", 5);
51316+ else
51317+ ret = strcpy(buf, "<path too long>");
51318+ br_read_unlock(&vfsmount_lock);
51319+ write_sequnlock(&rename_lock);
51320+ return ret;
51321+}
51322+
51323+char *
51324+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51325+{
51326+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51327+ PAGE_SIZE);
51328+}
51329+
51330+char *
51331+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51332+{
51333+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51334+ PAGE_SIZE);
51335+}
51336+
51337+char *
51338+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51339+{
51340+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51341+ PAGE_SIZE);
51342+}
51343+
51344+char *
51345+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51346+{
51347+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51348+ PAGE_SIZE);
51349+}
51350+
51351+char *
51352+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51353+{
51354+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51355+ PAGE_SIZE);
51356+}
51357+
51358+__inline__ __u32
51359+to_gr_audit(const __u32 reqmode)
51360+{
51361+ /* masks off auditable permission flags, then shifts them to create
51362+ auditing flags, and adds the special case of append auditing if
51363+ we're requesting write */
51364+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51365+}
51366+
51367+struct acl_subject_label *
51368+lookup_subject_map(const struct acl_subject_label *userp)
51369+{
51370+ unsigned int index = shash(userp, subj_map_set.s_size);
51371+ struct subject_map *match;
51372+
51373+ match = subj_map_set.s_hash[index];
51374+
51375+ while (match && match->user != userp)
51376+ match = match->next;
51377+
51378+ if (match != NULL)
51379+ return match->kernel;
51380+ else
51381+ return NULL;
51382+}
51383+
51384+static void
51385+insert_subj_map_entry(struct subject_map *subjmap)
51386+{
51387+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51388+ struct subject_map **curr;
51389+
51390+ subjmap->prev = NULL;
51391+
51392+ curr = &subj_map_set.s_hash[index];
51393+ if (*curr != NULL)
51394+ (*curr)->prev = subjmap;
51395+
51396+ subjmap->next = *curr;
51397+ *curr = subjmap;
51398+
51399+ return;
51400+}
51401+
51402+static struct acl_role_label *
51403+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51404+ const gid_t gid)
51405+{
51406+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51407+ struct acl_role_label *match;
51408+ struct role_allowed_ip *ipp;
51409+ unsigned int x;
51410+ u32 curr_ip = task->signal->curr_ip;
51411+
51412+ task->signal->saved_ip = curr_ip;
51413+
51414+ match = acl_role_set.r_hash[index];
51415+
51416+ while (match) {
51417+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51418+ for (x = 0; x < match->domain_child_num; x++) {
51419+ if (match->domain_children[x] == uid)
51420+ goto found;
51421+ }
51422+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51423+ break;
51424+ match = match->next;
51425+ }
51426+found:
51427+ if (match == NULL) {
51428+ try_group:
51429+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51430+ match = acl_role_set.r_hash[index];
51431+
51432+ while (match) {
51433+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51434+ for (x = 0; x < match->domain_child_num; x++) {
51435+ if (match->domain_children[x] == gid)
51436+ goto found2;
51437+ }
51438+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51439+ break;
51440+ match = match->next;
51441+ }
51442+found2:
51443+ if (match == NULL)
51444+ match = default_role;
51445+ if (match->allowed_ips == NULL)
51446+ return match;
51447+ else {
51448+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51449+ if (likely
51450+ ((ntohl(curr_ip) & ipp->netmask) ==
51451+ (ntohl(ipp->addr) & ipp->netmask)))
51452+ return match;
51453+ }
51454+ match = default_role;
51455+ }
51456+ } else if (match->allowed_ips == NULL) {
51457+ return match;
51458+ } else {
51459+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51460+ if (likely
51461+ ((ntohl(curr_ip) & ipp->netmask) ==
51462+ (ntohl(ipp->addr) & ipp->netmask)))
51463+ return match;
51464+ }
51465+ goto try_group;
51466+ }
51467+
51468+ return match;
51469+}
51470+
51471+struct acl_subject_label *
51472+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51473+ const struct acl_role_label *role)
51474+{
51475+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51476+ struct acl_subject_label *match;
51477+
51478+ match = role->subj_hash[index];
51479+
51480+ while (match && (match->inode != ino || match->device != dev ||
51481+ (match->mode & GR_DELETED))) {
51482+ match = match->next;
51483+ }
51484+
51485+ if (match && !(match->mode & GR_DELETED))
51486+ return match;
51487+ else
51488+ return NULL;
51489+}
51490+
51491+struct acl_subject_label *
51492+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51493+ const struct acl_role_label *role)
51494+{
51495+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51496+ struct acl_subject_label *match;
51497+
51498+ match = role->subj_hash[index];
51499+
51500+ while (match && (match->inode != ino || match->device != dev ||
51501+ !(match->mode & GR_DELETED))) {
51502+ match = match->next;
51503+ }
51504+
51505+ if (match && (match->mode & GR_DELETED))
51506+ return match;
51507+ else
51508+ return NULL;
51509+}
51510+
51511+static struct acl_object_label *
51512+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51513+ const struct acl_subject_label *subj)
51514+{
51515+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51516+ struct acl_object_label *match;
51517+
51518+ match = subj->obj_hash[index];
51519+
51520+ while (match && (match->inode != ino || match->device != dev ||
51521+ (match->mode & GR_DELETED))) {
51522+ match = match->next;
51523+ }
51524+
51525+ if (match && !(match->mode & GR_DELETED))
51526+ return match;
51527+ else
51528+ return NULL;
51529+}
51530+
51531+static struct acl_object_label *
51532+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51533+ const struct acl_subject_label *subj)
51534+{
51535+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51536+ struct acl_object_label *match;
51537+
51538+ match = subj->obj_hash[index];
51539+
51540+ while (match && (match->inode != ino || match->device != dev ||
51541+ !(match->mode & GR_DELETED))) {
51542+ match = match->next;
51543+ }
51544+
51545+ if (match && (match->mode & GR_DELETED))
51546+ return match;
51547+
51548+ match = subj->obj_hash[index];
51549+
51550+ while (match && (match->inode != ino || match->device != dev ||
51551+ (match->mode & GR_DELETED))) {
51552+ match = match->next;
51553+ }
51554+
51555+ if (match && !(match->mode & GR_DELETED))
51556+ return match;
51557+ else
51558+ return NULL;
51559+}
51560+
51561+static struct name_entry *
51562+lookup_name_entry(const char *name)
51563+{
51564+ unsigned int len = strlen(name);
51565+ unsigned int key = full_name_hash(name, len);
51566+ unsigned int index = key % name_set.n_size;
51567+ struct name_entry *match;
51568+
51569+ match = name_set.n_hash[index];
51570+
51571+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51572+ match = match->next;
51573+
51574+ return match;
51575+}
51576+
51577+static struct name_entry *
51578+lookup_name_entry_create(const char *name)
51579+{
51580+ unsigned int len = strlen(name);
51581+ unsigned int key = full_name_hash(name, len);
51582+ unsigned int index = key % name_set.n_size;
51583+ struct name_entry *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+
51594+ match = name_set.n_hash[index];
51595+
51596+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51597+ match->deleted))
51598+ match = match->next;
51599+
51600+ if (match && !match->deleted)
51601+ return match;
51602+ else
51603+ return NULL;
51604+}
51605+
51606+static struct inodev_entry *
51607+lookup_inodev_entry(const ino_t ino, const dev_t dev)
51608+{
51609+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
51610+ struct inodev_entry *match;
51611+
51612+ match = inodev_set.i_hash[index];
51613+
51614+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51615+ match = match->next;
51616+
51617+ return match;
51618+}
51619+
51620+static void
51621+insert_inodev_entry(struct inodev_entry *entry)
51622+{
51623+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51624+ inodev_set.i_size);
51625+ struct inodev_entry **curr;
51626+
51627+ entry->prev = NULL;
51628+
51629+ curr = &inodev_set.i_hash[index];
51630+ if (*curr != NULL)
51631+ (*curr)->prev = entry;
51632+
51633+ entry->next = *curr;
51634+ *curr = entry;
51635+
51636+ return;
51637+}
51638+
51639+static void
51640+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51641+{
51642+ unsigned int index =
51643+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51644+ struct acl_role_label **curr;
51645+ struct acl_role_label *tmp, *tmp2;
51646+
51647+ curr = &acl_role_set.r_hash[index];
51648+
51649+ /* simple case, slot is empty, just set it to our role */
51650+ if (*curr == NULL) {
51651+ *curr = role;
51652+ } else {
51653+ /* example:
51654+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
51655+ 2 -> 3
51656+ */
51657+ /* first check to see if we can already be reached via this slot */
51658+ tmp = *curr;
51659+ while (tmp && tmp != role)
51660+ tmp = tmp->next;
51661+ if (tmp == role) {
51662+ /* we don't need to add ourselves to this slot's chain */
51663+ return;
51664+ }
51665+ /* we need to add ourselves to this chain, two cases */
51666+ if (role->next == NULL) {
51667+ /* simple case, append the current chain to our role */
51668+ role->next = *curr;
51669+ *curr = role;
51670+ } else {
51671+ /* 1 -> 2 -> 3 -> 4
51672+ 2 -> 3 -> 4
51673+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51674+ */
51675+ /* trickier case: walk our role's chain until we find
51676+ the role for the start of the current slot's chain */
51677+ tmp = role;
51678+ tmp2 = *curr;
51679+ while (tmp->next && tmp->next != tmp2)
51680+ tmp = tmp->next;
51681+ if (tmp->next == tmp2) {
51682+ /* from example above, we found 3, so just
51683+ replace this slot's chain with ours */
51684+ *curr = role;
51685+ } else {
51686+ /* we didn't find a subset of our role's chain
51687+ in the current slot's chain, so append their
51688+ chain to ours, and set us as the first role in
51689+ the slot's chain
51690+
51691+ we could fold this case with the case above,
51692+ but making it explicit for clarity
51693+ */
51694+ tmp->next = tmp2;
51695+ *curr = role;
51696+ }
51697+ }
51698+ }
51699+
51700+ return;
51701+}
51702+
51703+static void
51704+insert_acl_role_label(struct acl_role_label *role)
51705+{
51706+ int i;
51707+
51708+ if (role_list == NULL) {
51709+ role_list = role;
51710+ role->prev = NULL;
51711+ } else {
51712+ role->prev = role_list;
51713+ role_list = role;
51714+ }
51715+
51716+ /* used for hash chains */
51717+ role->next = NULL;
51718+
51719+ if (role->roletype & GR_ROLE_DOMAIN) {
51720+ for (i = 0; i < role->domain_child_num; i++)
51721+ __insert_acl_role_label(role, role->domain_children[i]);
51722+ } else
51723+ __insert_acl_role_label(role, role->uidgid);
51724+}
51725+
51726+static int
51727+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51728+{
51729+ struct name_entry **curr, *nentry;
51730+ struct inodev_entry *ientry;
51731+ unsigned int len = strlen(name);
51732+ unsigned int key = full_name_hash(name, len);
51733+ unsigned int index = key % name_set.n_size;
51734+
51735+ curr = &name_set.n_hash[index];
51736+
51737+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51738+ curr = &((*curr)->next);
51739+
51740+ if (*curr != NULL)
51741+ return 1;
51742+
51743+ nentry = acl_alloc(sizeof (struct name_entry));
51744+ if (nentry == NULL)
51745+ return 0;
51746+ ientry = acl_alloc(sizeof (struct inodev_entry));
51747+ if (ientry == NULL)
51748+ return 0;
51749+ ientry->nentry = nentry;
51750+
51751+ nentry->key = key;
51752+ nentry->name = name;
51753+ nentry->inode = inode;
51754+ nentry->device = device;
51755+ nentry->len = len;
51756+ nentry->deleted = deleted;
51757+
51758+ nentry->prev = NULL;
51759+ curr = &name_set.n_hash[index];
51760+ if (*curr != NULL)
51761+ (*curr)->prev = nentry;
51762+ nentry->next = *curr;
51763+ *curr = nentry;
51764+
51765+ /* insert us into the table searchable by inode/dev */
51766+ insert_inodev_entry(ientry);
51767+
51768+ return 1;
51769+}
51770+
51771+static void
51772+insert_acl_obj_label(struct acl_object_label *obj,
51773+ struct acl_subject_label *subj)
51774+{
51775+ unsigned int index =
51776+ fhash(obj->inode, obj->device, subj->obj_hash_size);
51777+ struct acl_object_label **curr;
51778+
51779+
51780+ obj->prev = NULL;
51781+
51782+ curr = &subj->obj_hash[index];
51783+ if (*curr != NULL)
51784+ (*curr)->prev = obj;
51785+
51786+ obj->next = *curr;
51787+ *curr = obj;
51788+
51789+ return;
51790+}
51791+
51792+static void
51793+insert_acl_subj_label(struct acl_subject_label *obj,
51794+ struct acl_role_label *role)
51795+{
51796+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51797+ struct acl_subject_label **curr;
51798+
51799+ obj->prev = NULL;
51800+
51801+ curr = &role->subj_hash[index];
51802+ if (*curr != NULL)
51803+ (*curr)->prev = obj;
51804+
51805+ obj->next = *curr;
51806+ *curr = obj;
51807+
51808+ return;
51809+}
51810+
51811+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51812+
51813+static void *
51814+create_table(__u32 * len, int elementsize)
51815+{
51816+ unsigned int table_sizes[] = {
51817+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51818+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51819+ 4194301, 8388593, 16777213, 33554393, 67108859
51820+ };
51821+ void *newtable = NULL;
51822+ unsigned int pwr = 0;
51823+
51824+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51825+ table_sizes[pwr] <= *len)
51826+ pwr++;
51827+
51828+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51829+ return newtable;
51830+
51831+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51832+ newtable =
51833+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51834+ else
51835+ newtable = vmalloc(table_sizes[pwr] * elementsize);
51836+
51837+ *len = table_sizes[pwr];
51838+
51839+ return newtable;
51840+}
51841+
51842+static int
51843+init_variables(const struct gr_arg *arg)
51844+{
51845+ struct task_struct *reaper = init_pid_ns.child_reaper;
51846+ unsigned int stacksize;
51847+
51848+ subj_map_set.s_size = arg->role_db.num_subjects;
51849+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51850+ name_set.n_size = arg->role_db.num_objects;
51851+ inodev_set.i_size = arg->role_db.num_objects;
51852+
51853+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
51854+ !name_set.n_size || !inodev_set.i_size)
51855+ return 1;
51856+
51857+ if (!gr_init_uidset())
51858+ return 1;
51859+
51860+ /* set up the stack that holds allocation info */
51861+
51862+ stacksize = arg->role_db.num_pointers + 5;
51863+
51864+ if (!acl_alloc_stack_init(stacksize))
51865+ return 1;
51866+
51867+ /* grab reference for the real root dentry and vfsmount */
51868+ get_fs_root(reaper->fs, &real_root);
51869+
51870+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51871+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51872+#endif
51873+
51874+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51875+ if (fakefs_obj_rw == NULL)
51876+ return 1;
51877+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51878+
51879+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51880+ if (fakefs_obj_rwx == NULL)
51881+ return 1;
51882+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51883+
51884+ subj_map_set.s_hash =
51885+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51886+ acl_role_set.r_hash =
51887+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51888+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51889+ inodev_set.i_hash =
51890+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51891+
51892+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51893+ !name_set.n_hash || !inodev_set.i_hash)
51894+ return 1;
51895+
51896+ memset(subj_map_set.s_hash, 0,
51897+ sizeof(struct subject_map *) * subj_map_set.s_size);
51898+ memset(acl_role_set.r_hash, 0,
51899+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
51900+ memset(name_set.n_hash, 0,
51901+ sizeof (struct name_entry *) * name_set.n_size);
51902+ memset(inodev_set.i_hash, 0,
51903+ sizeof (struct inodev_entry *) * inodev_set.i_size);
51904+
51905+ return 0;
51906+}
51907+
51908+/* free information not needed after startup
51909+ currently contains user->kernel pointer mappings for subjects
51910+*/
51911+
51912+static void
51913+free_init_variables(void)
51914+{
51915+ __u32 i;
51916+
51917+ if (subj_map_set.s_hash) {
51918+ for (i = 0; i < subj_map_set.s_size; i++) {
51919+ if (subj_map_set.s_hash[i]) {
51920+ kfree(subj_map_set.s_hash[i]);
51921+ subj_map_set.s_hash[i] = NULL;
51922+ }
51923+ }
51924+
51925+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51926+ PAGE_SIZE)
51927+ kfree(subj_map_set.s_hash);
51928+ else
51929+ vfree(subj_map_set.s_hash);
51930+ }
51931+
51932+ return;
51933+}
51934+
51935+static void
51936+free_variables(void)
51937+{
51938+ struct acl_subject_label *s;
51939+ struct acl_role_label *r;
51940+ struct task_struct *task, *task2;
51941+ unsigned int x;
51942+
51943+ gr_clear_learn_entries();
51944+
51945+ read_lock(&tasklist_lock);
51946+ do_each_thread(task2, task) {
51947+ task->acl_sp_role = 0;
51948+ task->acl_role_id = 0;
51949+ task->acl = NULL;
51950+ task->role = NULL;
51951+ } while_each_thread(task2, task);
51952+ read_unlock(&tasklist_lock);
51953+
51954+ /* release the reference to the real root dentry and vfsmount */
51955+ path_put(&real_root);
51956+ memset(&real_root, 0, sizeof(real_root));
51957+
51958+ /* free all object hash tables */
51959+
51960+ FOR_EACH_ROLE_START(r)
51961+ if (r->subj_hash == NULL)
51962+ goto next_role;
51963+ FOR_EACH_SUBJECT_START(r, s, x)
51964+ if (s->obj_hash == NULL)
51965+ break;
51966+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51967+ kfree(s->obj_hash);
51968+ else
51969+ vfree(s->obj_hash);
51970+ FOR_EACH_SUBJECT_END(s, x)
51971+ FOR_EACH_NESTED_SUBJECT_START(r, s)
51972+ if (s->obj_hash == NULL)
51973+ break;
51974+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51975+ kfree(s->obj_hash);
51976+ else
51977+ vfree(s->obj_hash);
51978+ FOR_EACH_NESTED_SUBJECT_END(s)
51979+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51980+ kfree(r->subj_hash);
51981+ else
51982+ vfree(r->subj_hash);
51983+ r->subj_hash = NULL;
51984+next_role:
51985+ FOR_EACH_ROLE_END(r)
51986+
51987+ acl_free_all();
51988+
51989+ if (acl_role_set.r_hash) {
51990+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51991+ PAGE_SIZE)
51992+ kfree(acl_role_set.r_hash);
51993+ else
51994+ vfree(acl_role_set.r_hash);
51995+ }
51996+ if (name_set.n_hash) {
51997+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
51998+ PAGE_SIZE)
51999+ kfree(name_set.n_hash);
52000+ else
52001+ vfree(name_set.n_hash);
52002+ }
52003+
52004+ if (inodev_set.i_hash) {
52005+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52006+ PAGE_SIZE)
52007+ kfree(inodev_set.i_hash);
52008+ else
52009+ vfree(inodev_set.i_hash);
52010+ }
52011+
52012+ gr_free_uidset();
52013+
52014+ memset(&name_set, 0, sizeof (struct name_db));
52015+ memset(&inodev_set, 0, sizeof (struct inodev_db));
52016+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52017+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52018+
52019+ default_role = NULL;
52020+ kernel_role = NULL;
52021+ role_list = NULL;
52022+
52023+ return;
52024+}
52025+
52026+static __u32
52027+count_user_objs(struct acl_object_label *userp)
52028+{
52029+ struct acl_object_label o_tmp;
52030+ __u32 num = 0;
52031+
52032+ while (userp) {
52033+ if (copy_from_user(&o_tmp, userp,
52034+ sizeof (struct acl_object_label)))
52035+ break;
52036+
52037+ userp = o_tmp.prev;
52038+ num++;
52039+ }
52040+
52041+ return num;
52042+}
52043+
52044+static struct acl_subject_label *
52045+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52046+
52047+static int
52048+copy_user_glob(struct acl_object_label *obj)
52049+{
52050+ struct acl_object_label *g_tmp, **guser;
52051+ unsigned int len;
52052+ char *tmp;
52053+
52054+ if (obj->globbed == NULL)
52055+ return 0;
52056+
52057+ guser = &obj->globbed;
52058+ while (*guser) {
52059+ g_tmp = (struct acl_object_label *)
52060+ acl_alloc(sizeof (struct acl_object_label));
52061+ if (g_tmp == NULL)
52062+ return -ENOMEM;
52063+
52064+ if (copy_from_user(g_tmp, *guser,
52065+ sizeof (struct acl_object_label)))
52066+ return -EFAULT;
52067+
52068+ len = strnlen_user(g_tmp->filename, PATH_MAX);
52069+
52070+ if (!len || len >= PATH_MAX)
52071+ return -EINVAL;
52072+
52073+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52074+ return -ENOMEM;
52075+
52076+ if (copy_from_user(tmp, g_tmp->filename, len))
52077+ return -EFAULT;
52078+ tmp[len-1] = '\0';
52079+ g_tmp->filename = tmp;
52080+
52081+ *guser = g_tmp;
52082+ guser = &(g_tmp->next);
52083+ }
52084+
52085+ return 0;
52086+}
52087+
52088+static int
52089+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52090+ struct acl_role_label *role)
52091+{
52092+ struct acl_object_label *o_tmp;
52093+ unsigned int len;
52094+ int ret;
52095+ char *tmp;
52096+
52097+ while (userp) {
52098+ if ((o_tmp = (struct acl_object_label *)
52099+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
52100+ return -ENOMEM;
52101+
52102+ if (copy_from_user(o_tmp, userp,
52103+ sizeof (struct acl_object_label)))
52104+ return -EFAULT;
52105+
52106+ userp = o_tmp->prev;
52107+
52108+ len = strnlen_user(o_tmp->filename, PATH_MAX);
52109+
52110+ if (!len || len >= PATH_MAX)
52111+ return -EINVAL;
52112+
52113+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52114+ return -ENOMEM;
52115+
52116+ if (copy_from_user(tmp, o_tmp->filename, len))
52117+ return -EFAULT;
52118+ tmp[len-1] = '\0';
52119+ o_tmp->filename = tmp;
52120+
52121+ insert_acl_obj_label(o_tmp, subj);
52122+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52123+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52124+ return -ENOMEM;
52125+
52126+ ret = copy_user_glob(o_tmp);
52127+ if (ret)
52128+ return ret;
52129+
52130+ if (o_tmp->nested) {
52131+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52132+ if (IS_ERR(o_tmp->nested))
52133+ return PTR_ERR(o_tmp->nested);
52134+
52135+ /* insert into nested subject list */
52136+ o_tmp->nested->next = role->hash->first;
52137+ role->hash->first = o_tmp->nested;
52138+ }
52139+ }
52140+
52141+ return 0;
52142+}
52143+
52144+static __u32
52145+count_user_subjs(struct acl_subject_label *userp)
52146+{
52147+ struct acl_subject_label s_tmp;
52148+ __u32 num = 0;
52149+
52150+ while (userp) {
52151+ if (copy_from_user(&s_tmp, userp,
52152+ sizeof (struct acl_subject_label)))
52153+ break;
52154+
52155+ userp = s_tmp.prev;
52156+ /* do not count nested subjects against this count, since
52157+ they are not included in the hash table, but are
52158+ attached to objects. We have already counted
52159+ the subjects in userspace for the allocation
52160+ stack
52161+ */
52162+ if (!(s_tmp.mode & GR_NESTED))
52163+ num++;
52164+ }
52165+
52166+ return num;
52167+}
52168+
52169+static int
52170+copy_user_allowedips(struct acl_role_label *rolep)
52171+{
52172+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52173+
52174+ ruserip = rolep->allowed_ips;
52175+
52176+ while (ruserip) {
52177+ rlast = rtmp;
52178+
52179+ if ((rtmp = (struct role_allowed_ip *)
52180+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52181+ return -ENOMEM;
52182+
52183+ if (copy_from_user(rtmp, ruserip,
52184+ sizeof (struct role_allowed_ip)))
52185+ return -EFAULT;
52186+
52187+ ruserip = rtmp->prev;
52188+
52189+ if (!rlast) {
52190+ rtmp->prev = NULL;
52191+ rolep->allowed_ips = rtmp;
52192+ } else {
52193+ rlast->next = rtmp;
52194+ rtmp->prev = rlast;
52195+ }
52196+
52197+ if (!ruserip)
52198+ rtmp->next = NULL;
52199+ }
52200+
52201+ return 0;
52202+}
52203+
52204+static int
52205+copy_user_transitions(struct acl_role_label *rolep)
52206+{
52207+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
52208+
52209+ unsigned int len;
52210+ char *tmp;
52211+
52212+ rusertp = rolep->transitions;
52213+
52214+ while (rusertp) {
52215+ rlast = rtmp;
52216+
52217+ if ((rtmp = (struct role_transition *)
52218+ acl_alloc(sizeof (struct role_transition))) == NULL)
52219+ return -ENOMEM;
52220+
52221+ if (copy_from_user(rtmp, rusertp,
52222+ sizeof (struct role_transition)))
52223+ return -EFAULT;
52224+
52225+ rusertp = rtmp->prev;
52226+
52227+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52228+
52229+ if (!len || len >= GR_SPROLE_LEN)
52230+ return -EINVAL;
52231+
52232+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52233+ return -ENOMEM;
52234+
52235+ if (copy_from_user(tmp, rtmp->rolename, len))
52236+ return -EFAULT;
52237+ tmp[len-1] = '\0';
52238+ rtmp->rolename = tmp;
52239+
52240+ if (!rlast) {
52241+ rtmp->prev = NULL;
52242+ rolep->transitions = rtmp;
52243+ } else {
52244+ rlast->next = rtmp;
52245+ rtmp->prev = rlast;
52246+ }
52247+
52248+ if (!rusertp)
52249+ rtmp->next = NULL;
52250+ }
52251+
52252+ return 0;
52253+}
52254+
52255+static struct acl_subject_label *
52256+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52257+{
52258+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52259+ unsigned int len;
52260+ char *tmp;
52261+ __u32 num_objs;
52262+ struct acl_ip_label **i_tmp, *i_utmp2;
52263+ struct gr_hash_struct ghash;
52264+ struct subject_map *subjmap;
52265+ unsigned int i_num;
52266+ int err;
52267+
52268+ s_tmp = lookup_subject_map(userp);
52269+
52270+ /* we've already copied this subject into the kernel, just return
52271+ the reference to it, and don't copy it over again
52272+ */
52273+ if (s_tmp)
52274+ return(s_tmp);
52275+
52276+ if ((s_tmp = (struct acl_subject_label *)
52277+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52278+ return ERR_PTR(-ENOMEM);
52279+
52280+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52281+ if (subjmap == NULL)
52282+ return ERR_PTR(-ENOMEM);
52283+
52284+ subjmap->user = userp;
52285+ subjmap->kernel = s_tmp;
52286+ insert_subj_map_entry(subjmap);
52287+
52288+ if (copy_from_user(s_tmp, userp,
52289+ sizeof (struct acl_subject_label)))
52290+ return ERR_PTR(-EFAULT);
52291+
52292+ len = strnlen_user(s_tmp->filename, PATH_MAX);
52293+
52294+ if (!len || len >= PATH_MAX)
52295+ return ERR_PTR(-EINVAL);
52296+
52297+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52298+ return ERR_PTR(-ENOMEM);
52299+
52300+ if (copy_from_user(tmp, s_tmp->filename, len))
52301+ return ERR_PTR(-EFAULT);
52302+ tmp[len-1] = '\0';
52303+ s_tmp->filename = tmp;
52304+
52305+ if (!strcmp(s_tmp->filename, "/"))
52306+ role->root_label = s_tmp;
52307+
52308+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52309+ return ERR_PTR(-EFAULT);
52310+
52311+ /* copy user and group transition tables */
52312+
52313+ if (s_tmp->user_trans_num) {
52314+ uid_t *uidlist;
52315+
52316+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52317+ if (uidlist == NULL)
52318+ return ERR_PTR(-ENOMEM);
52319+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52320+ return ERR_PTR(-EFAULT);
52321+
52322+ s_tmp->user_transitions = uidlist;
52323+ }
52324+
52325+ if (s_tmp->group_trans_num) {
52326+ gid_t *gidlist;
52327+
52328+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52329+ if (gidlist == NULL)
52330+ return ERR_PTR(-ENOMEM);
52331+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52332+ return ERR_PTR(-EFAULT);
52333+
52334+ s_tmp->group_transitions = gidlist;
52335+ }
52336+
52337+ /* set up object hash table */
52338+ num_objs = count_user_objs(ghash.first);
52339+
52340+ s_tmp->obj_hash_size = num_objs;
52341+ s_tmp->obj_hash =
52342+ (struct acl_object_label **)
52343+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52344+
52345+ if (!s_tmp->obj_hash)
52346+ return ERR_PTR(-ENOMEM);
52347+
52348+ memset(s_tmp->obj_hash, 0,
52349+ s_tmp->obj_hash_size *
52350+ sizeof (struct acl_object_label *));
52351+
52352+ /* add in objects */
52353+ err = copy_user_objs(ghash.first, s_tmp, role);
52354+
52355+ if (err)
52356+ return ERR_PTR(err);
52357+
52358+ /* set pointer for parent subject */
52359+ if (s_tmp->parent_subject) {
52360+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52361+
52362+ if (IS_ERR(s_tmp2))
52363+ return s_tmp2;
52364+
52365+ s_tmp->parent_subject = s_tmp2;
52366+ }
52367+
52368+ /* add in ip acls */
52369+
52370+ if (!s_tmp->ip_num) {
52371+ s_tmp->ips = NULL;
52372+ goto insert;
52373+ }
52374+
52375+ i_tmp =
52376+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52377+ sizeof (struct acl_ip_label *));
52378+
52379+ if (!i_tmp)
52380+ return ERR_PTR(-ENOMEM);
52381+
52382+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52383+ *(i_tmp + i_num) =
52384+ (struct acl_ip_label *)
52385+ acl_alloc(sizeof (struct acl_ip_label));
52386+ if (!*(i_tmp + i_num))
52387+ return ERR_PTR(-ENOMEM);
52388+
52389+ if (copy_from_user
52390+ (&i_utmp2, s_tmp->ips + i_num,
52391+ sizeof (struct acl_ip_label *)))
52392+ return ERR_PTR(-EFAULT);
52393+
52394+ if (copy_from_user
52395+ (*(i_tmp + i_num), i_utmp2,
52396+ sizeof (struct acl_ip_label)))
52397+ return ERR_PTR(-EFAULT);
52398+
52399+ if ((*(i_tmp + i_num))->iface == NULL)
52400+ continue;
52401+
52402+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52403+ if (!len || len >= IFNAMSIZ)
52404+ return ERR_PTR(-EINVAL);
52405+ tmp = acl_alloc(len);
52406+ if (tmp == NULL)
52407+ return ERR_PTR(-ENOMEM);
52408+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52409+ return ERR_PTR(-EFAULT);
52410+ (*(i_tmp + i_num))->iface = tmp;
52411+ }
52412+
52413+ s_tmp->ips = i_tmp;
52414+
52415+insert:
52416+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52417+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52418+ return ERR_PTR(-ENOMEM);
52419+
52420+ return s_tmp;
52421+}
52422+
52423+static int
52424+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52425+{
52426+ struct acl_subject_label s_pre;
52427+ struct acl_subject_label * ret;
52428+ int err;
52429+
52430+ while (userp) {
52431+ if (copy_from_user(&s_pre, userp,
52432+ sizeof (struct acl_subject_label)))
52433+ return -EFAULT;
52434+
52435+ /* do not add nested subjects here, add
52436+ while parsing objects
52437+ */
52438+
52439+ if (s_pre.mode & GR_NESTED) {
52440+ userp = s_pre.prev;
52441+ continue;
52442+ }
52443+
52444+ ret = do_copy_user_subj(userp, role);
52445+
52446+ err = PTR_ERR(ret);
52447+ if (IS_ERR(ret))
52448+ return err;
52449+
52450+ insert_acl_subj_label(ret, role);
52451+
52452+ userp = s_pre.prev;
52453+ }
52454+
52455+ return 0;
52456+}
52457+
52458+static int
52459+copy_user_acl(struct gr_arg *arg)
52460+{
52461+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52462+ struct sprole_pw *sptmp;
52463+ struct gr_hash_struct *ghash;
52464+ uid_t *domainlist;
52465+ unsigned int r_num;
52466+ unsigned int len;
52467+ char *tmp;
52468+ int err = 0;
52469+ __u16 i;
52470+ __u32 num_subjs;
52471+
52472+ /* we need a default and kernel role */
52473+ if (arg->role_db.num_roles < 2)
52474+ return -EINVAL;
52475+
52476+ /* copy special role authentication info from userspace */
52477+
52478+ num_sprole_pws = arg->num_sprole_pws;
52479+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52480+
52481+ if (!acl_special_roles && num_sprole_pws)
52482+ return -ENOMEM;
52483+
52484+ for (i = 0; i < num_sprole_pws; i++) {
52485+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52486+ if (!sptmp)
52487+ return -ENOMEM;
52488+ if (copy_from_user(sptmp, arg->sprole_pws + i,
52489+ sizeof (struct sprole_pw)))
52490+ return -EFAULT;
52491+
52492+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52493+
52494+ if (!len || len >= GR_SPROLE_LEN)
52495+ return -EINVAL;
52496+
52497+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52498+ return -ENOMEM;
52499+
52500+ if (copy_from_user(tmp, sptmp->rolename, len))
52501+ return -EFAULT;
52502+
52503+ tmp[len-1] = '\0';
52504+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52505+ printk(KERN_ALERT "Copying special role %s\n", tmp);
52506+#endif
52507+ sptmp->rolename = tmp;
52508+ acl_special_roles[i] = sptmp;
52509+ }
52510+
52511+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52512+
52513+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52514+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
52515+
52516+ if (!r_tmp)
52517+ return -ENOMEM;
52518+
52519+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
52520+ sizeof (struct acl_role_label *)))
52521+ return -EFAULT;
52522+
52523+ if (copy_from_user(r_tmp, r_utmp2,
52524+ sizeof (struct acl_role_label)))
52525+ return -EFAULT;
52526+
52527+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52528+
52529+ if (!len || len >= PATH_MAX)
52530+ return -EINVAL;
52531+
52532+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52533+ return -ENOMEM;
52534+
52535+ if (copy_from_user(tmp, r_tmp->rolename, len))
52536+ return -EFAULT;
52537+
52538+ tmp[len-1] = '\0';
52539+ r_tmp->rolename = tmp;
52540+
52541+ if (!strcmp(r_tmp->rolename, "default")
52542+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52543+ default_role = r_tmp;
52544+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52545+ kernel_role = r_tmp;
52546+ }
52547+
52548+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52549+ return -ENOMEM;
52550+
52551+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52552+ return -EFAULT;
52553+
52554+ r_tmp->hash = ghash;
52555+
52556+ num_subjs = count_user_subjs(r_tmp->hash->first);
52557+
52558+ r_tmp->subj_hash_size = num_subjs;
52559+ r_tmp->subj_hash =
52560+ (struct acl_subject_label **)
52561+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52562+
52563+ if (!r_tmp->subj_hash)
52564+ return -ENOMEM;
52565+
52566+ err = copy_user_allowedips(r_tmp);
52567+ if (err)
52568+ return err;
52569+
52570+ /* copy domain info */
52571+ if (r_tmp->domain_children != NULL) {
52572+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52573+ if (domainlist == NULL)
52574+ return -ENOMEM;
52575+
52576+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52577+ return -EFAULT;
52578+
52579+ r_tmp->domain_children = domainlist;
52580+ }
52581+
52582+ err = copy_user_transitions(r_tmp);
52583+ if (err)
52584+ return err;
52585+
52586+ memset(r_tmp->subj_hash, 0,
52587+ r_tmp->subj_hash_size *
52588+ sizeof (struct acl_subject_label *));
52589+
52590+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52591+
52592+ if (err)
52593+ return err;
52594+
52595+ /* set nested subject list to null */
52596+ r_tmp->hash->first = NULL;
52597+
52598+ insert_acl_role_label(r_tmp);
52599+ }
52600+
52601+ if (default_role == NULL || kernel_role == NULL)
52602+ return -EINVAL;
52603+
52604+ return err;
52605+}
52606+
52607+static int
52608+gracl_init(struct gr_arg *args)
52609+{
52610+ int error = 0;
52611+
52612+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52613+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52614+
52615+ if (init_variables(args)) {
52616+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52617+ error = -ENOMEM;
52618+ free_variables();
52619+ goto out;
52620+ }
52621+
52622+ error = copy_user_acl(args);
52623+ free_init_variables();
52624+ if (error) {
52625+ free_variables();
52626+ goto out;
52627+ }
52628+
52629+ if ((error = gr_set_acls(0))) {
52630+ free_variables();
52631+ goto out;
52632+ }
52633+
52634+ pax_open_kernel();
52635+ gr_status |= GR_READY;
52636+ pax_close_kernel();
52637+
52638+ out:
52639+ return error;
52640+}
52641+
52642+/* derived from glibc fnmatch() 0: match, 1: no match*/
52643+
52644+static int
52645+glob_match(const char *p, const char *n)
52646+{
52647+ char c;
52648+
52649+ while ((c = *p++) != '\0') {
52650+ switch (c) {
52651+ case '?':
52652+ if (*n == '\0')
52653+ return 1;
52654+ else if (*n == '/')
52655+ return 1;
52656+ break;
52657+ case '\\':
52658+ if (*n != c)
52659+ return 1;
52660+ break;
52661+ case '*':
52662+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
52663+ if (*n == '/')
52664+ return 1;
52665+ else if (c == '?') {
52666+ if (*n == '\0')
52667+ return 1;
52668+ else
52669+ ++n;
52670+ }
52671+ }
52672+ if (c == '\0') {
52673+ return 0;
52674+ } else {
52675+ const char *endp;
52676+
52677+ if ((endp = strchr(n, '/')) == NULL)
52678+ endp = n + strlen(n);
52679+
52680+ if (c == '[') {
52681+ for (--p; n < endp; ++n)
52682+ if (!glob_match(p, n))
52683+ return 0;
52684+ } else if (c == '/') {
52685+ while (*n != '\0' && *n != '/')
52686+ ++n;
52687+ if (*n == '/' && !glob_match(p, n + 1))
52688+ return 0;
52689+ } else {
52690+ for (--p; n < endp; ++n)
52691+ if (*n == c && !glob_match(p, n))
52692+ return 0;
52693+ }
52694+
52695+ return 1;
52696+ }
52697+ case '[':
52698+ {
52699+ int not;
52700+ char cold;
52701+
52702+ if (*n == '\0' || *n == '/')
52703+ return 1;
52704+
52705+ not = (*p == '!' || *p == '^');
52706+ if (not)
52707+ ++p;
52708+
52709+ c = *p++;
52710+ for (;;) {
52711+ unsigned char fn = (unsigned char)*n;
52712+
52713+ if (c == '\0')
52714+ return 1;
52715+ else {
52716+ if (c == fn)
52717+ goto matched;
52718+ cold = c;
52719+ c = *p++;
52720+
52721+ if (c == '-' && *p != ']') {
52722+ unsigned char cend = *p++;
52723+
52724+ if (cend == '\0')
52725+ return 1;
52726+
52727+ if (cold <= fn && fn <= cend)
52728+ goto matched;
52729+
52730+ c = *p++;
52731+ }
52732+ }
52733+
52734+ if (c == ']')
52735+ break;
52736+ }
52737+ if (!not)
52738+ return 1;
52739+ break;
52740+ matched:
52741+ while (c != ']') {
52742+ if (c == '\0')
52743+ return 1;
52744+
52745+ c = *p++;
52746+ }
52747+ if (not)
52748+ return 1;
52749+ }
52750+ break;
52751+ default:
52752+ if (c != *n)
52753+ return 1;
52754+ }
52755+
52756+ ++n;
52757+ }
52758+
52759+ if (*n == '\0')
52760+ return 0;
52761+
52762+ if (*n == '/')
52763+ return 0;
52764+
52765+ return 1;
52766+}
52767+
52768+static struct acl_object_label *
52769+chk_glob_label(struct acl_object_label *globbed,
52770+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52771+{
52772+ struct acl_object_label *tmp;
52773+
52774+ if (*path == NULL)
52775+ *path = gr_to_filename_nolock(dentry, mnt);
52776+
52777+ tmp = globbed;
52778+
52779+ while (tmp) {
52780+ if (!glob_match(tmp->filename, *path))
52781+ return tmp;
52782+ tmp = tmp->next;
52783+ }
52784+
52785+ return NULL;
52786+}
52787+
52788+static struct acl_object_label *
52789+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52790+ const ino_t curr_ino, const dev_t curr_dev,
52791+ const struct acl_subject_label *subj, char **path, const int checkglob)
52792+{
52793+ struct acl_subject_label *tmpsubj;
52794+ struct acl_object_label *retval;
52795+ struct acl_object_label *retval2;
52796+
52797+ tmpsubj = (struct acl_subject_label *) subj;
52798+ read_lock(&gr_inode_lock);
52799+ do {
52800+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52801+ if (retval) {
52802+ if (checkglob && retval->globbed) {
52803+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52804+ if (retval2)
52805+ retval = retval2;
52806+ }
52807+ break;
52808+ }
52809+ } while ((tmpsubj = tmpsubj->parent_subject));
52810+ read_unlock(&gr_inode_lock);
52811+
52812+ return retval;
52813+}
52814+
52815+static __inline__ struct acl_object_label *
52816+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52817+ struct dentry *curr_dentry,
52818+ const struct acl_subject_label *subj, char **path, const int checkglob)
52819+{
52820+ int newglob = checkglob;
52821+ ino_t inode;
52822+ dev_t device;
52823+
52824+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52825+ as we don't want a / * rule to match instead of the / object
52826+ don't do this for create lookups that call this function though, since they're looking up
52827+ on the parent and thus need globbing checks on all paths
52828+ */
52829+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52830+ newglob = GR_NO_GLOB;
52831+
52832+ spin_lock(&curr_dentry->d_lock);
52833+ inode = curr_dentry->d_inode->i_ino;
52834+ device = __get_dev(curr_dentry);
52835+ spin_unlock(&curr_dentry->d_lock);
52836+
52837+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52838+}
52839+
52840+static struct acl_object_label *
52841+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52842+ const struct acl_subject_label *subj, char *path, const int checkglob)
52843+{
52844+ struct dentry *dentry = (struct dentry *) l_dentry;
52845+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52846+ struct mount *real_mnt = real_mount(mnt);
52847+ struct acl_object_label *retval;
52848+ struct dentry *parent;
52849+
52850+ write_seqlock(&rename_lock);
52851+ br_read_lock(&vfsmount_lock);
52852+
52853+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52854+#ifdef CONFIG_NET
52855+ mnt == sock_mnt ||
52856+#endif
52857+#ifdef CONFIG_HUGETLBFS
52858+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52859+#endif
52860+ /* ignore Eric Biederman */
52861+ IS_PRIVATE(l_dentry->d_inode))) {
52862+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52863+ goto out;
52864+ }
52865+
52866+ for (;;) {
52867+ if (dentry == real_root.dentry && mnt == real_root.mnt)
52868+ break;
52869+
52870+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52871+ if (!mnt_has_parent(real_mnt))
52872+ break;
52873+
52874+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52875+ if (retval != NULL)
52876+ goto out;
52877+
52878+ dentry = real_mnt->mnt_mountpoint;
52879+ real_mnt = real_mnt->mnt_parent;
52880+ mnt = &real_mnt->mnt;
52881+ continue;
52882+ }
52883+
52884+ parent = dentry->d_parent;
52885+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52886+ if (retval != NULL)
52887+ goto out;
52888+
52889+ dentry = parent;
52890+ }
52891+
52892+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52893+
52894+ /* real_root is pinned so we don't have to hold a reference */
52895+ if (retval == NULL)
52896+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52897+out:
52898+ br_read_unlock(&vfsmount_lock);
52899+ write_sequnlock(&rename_lock);
52900+
52901+ BUG_ON(retval == NULL);
52902+
52903+ return retval;
52904+}
52905+
52906+static __inline__ struct acl_object_label *
52907+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52908+ const struct acl_subject_label *subj)
52909+{
52910+ char *path = NULL;
52911+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52912+}
52913+
52914+static __inline__ struct acl_object_label *
52915+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52916+ const struct acl_subject_label *subj)
52917+{
52918+ char *path = NULL;
52919+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52920+}
52921+
52922+static __inline__ struct acl_object_label *
52923+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52924+ const struct acl_subject_label *subj, char *path)
52925+{
52926+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52927+}
52928+
52929+static struct acl_subject_label *
52930+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52931+ const struct acl_role_label *role)
52932+{
52933+ struct dentry *dentry = (struct dentry *) l_dentry;
52934+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52935+ struct mount *real_mnt = real_mount(mnt);
52936+ struct acl_subject_label *retval;
52937+ struct dentry *parent;
52938+
52939+ write_seqlock(&rename_lock);
52940+ br_read_lock(&vfsmount_lock);
52941+
52942+ for (;;) {
52943+ if (dentry == real_root.dentry && mnt == real_root.mnt)
52944+ break;
52945+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52946+ if (!mnt_has_parent(real_mnt))
52947+ break;
52948+
52949+ spin_lock(&dentry->d_lock);
52950+ read_lock(&gr_inode_lock);
52951+ retval =
52952+ lookup_acl_subj_label(dentry->d_inode->i_ino,
52953+ __get_dev(dentry), role);
52954+ read_unlock(&gr_inode_lock);
52955+ spin_unlock(&dentry->d_lock);
52956+ if (retval != NULL)
52957+ goto out;
52958+
52959+ dentry = real_mnt->mnt_mountpoint;
52960+ real_mnt = real_mnt->mnt_parent;
52961+ mnt = &real_mnt->mnt;
52962+ continue;
52963+ }
52964+
52965+ spin_lock(&dentry->d_lock);
52966+ read_lock(&gr_inode_lock);
52967+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52968+ __get_dev(dentry), role);
52969+ read_unlock(&gr_inode_lock);
52970+ parent = dentry->d_parent;
52971+ spin_unlock(&dentry->d_lock);
52972+
52973+ if (retval != NULL)
52974+ goto out;
52975+
52976+ dentry = parent;
52977+ }
52978+
52979+ spin_lock(&dentry->d_lock);
52980+ read_lock(&gr_inode_lock);
52981+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52982+ __get_dev(dentry), role);
52983+ read_unlock(&gr_inode_lock);
52984+ spin_unlock(&dentry->d_lock);
52985+
52986+ if (unlikely(retval == NULL)) {
52987+ /* real_root is pinned, we don't need to hold a reference */
52988+ read_lock(&gr_inode_lock);
52989+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52990+ __get_dev(real_root.dentry), role);
52991+ read_unlock(&gr_inode_lock);
52992+ }
52993+out:
52994+ br_read_unlock(&vfsmount_lock);
52995+ write_sequnlock(&rename_lock);
52996+
52997+ BUG_ON(retval == NULL);
52998+
52999+ return retval;
53000+}
53001+
53002+static void
53003+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53004+{
53005+ struct task_struct *task = current;
53006+ const struct cred *cred = current_cred();
53007+
53008+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53009+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53010+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53011+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53012+
53013+ return;
53014+}
53015+
53016+static void
53017+gr_log_learn_id_change(const char type, const unsigned int real,
53018+ const unsigned int effective, const unsigned int fs)
53019+{
53020+ struct task_struct *task = current;
53021+ const struct cred *cred = current_cred();
53022+
53023+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53024+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53025+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53026+ type, real, effective, fs, &task->signal->saved_ip);
53027+
53028+ return;
53029+}
53030+
53031+__u32
53032+gr_search_file(const struct dentry * dentry, const __u32 mode,
53033+ const struct vfsmount * mnt)
53034+{
53035+ __u32 retval = mode;
53036+ struct acl_subject_label *curracl;
53037+ struct acl_object_label *currobj;
53038+
53039+ if (unlikely(!(gr_status & GR_READY)))
53040+ return (mode & ~GR_AUDITS);
53041+
53042+ curracl = current->acl;
53043+
53044+ currobj = chk_obj_label(dentry, mnt, curracl);
53045+ retval = currobj->mode & mode;
53046+
53047+ /* if we're opening a specified transfer file for writing
53048+ (e.g. /dev/initctl), then transfer our role to init
53049+ */
53050+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53051+ current->role->roletype & GR_ROLE_PERSIST)) {
53052+ struct task_struct *task = init_pid_ns.child_reaper;
53053+
53054+ if (task->role != current->role) {
53055+ task->acl_sp_role = 0;
53056+ task->acl_role_id = current->acl_role_id;
53057+ task->role = current->role;
53058+ rcu_read_lock();
53059+ read_lock(&grsec_exec_file_lock);
53060+ gr_apply_subject_to_task(task);
53061+ read_unlock(&grsec_exec_file_lock);
53062+ rcu_read_unlock();
53063+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53064+ }
53065+ }
53066+
53067+ if (unlikely
53068+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53069+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53070+ __u32 new_mode = mode;
53071+
53072+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53073+
53074+ retval = new_mode;
53075+
53076+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53077+ new_mode |= GR_INHERIT;
53078+
53079+ if (!(mode & GR_NOLEARN))
53080+ gr_log_learn(dentry, mnt, new_mode);
53081+ }
53082+
53083+ return retval;
53084+}
53085+
53086+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53087+ const struct dentry *parent,
53088+ const struct vfsmount *mnt)
53089+{
53090+ struct name_entry *match;
53091+ struct acl_object_label *matchpo;
53092+ struct acl_subject_label *curracl;
53093+ char *path;
53094+
53095+ if (unlikely(!(gr_status & GR_READY)))
53096+ return NULL;
53097+
53098+ preempt_disable();
53099+ path = gr_to_filename_rbac(new_dentry, mnt);
53100+ match = lookup_name_entry_create(path);
53101+
53102+ curracl = current->acl;
53103+
53104+ if (match) {
53105+ read_lock(&gr_inode_lock);
53106+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53107+ read_unlock(&gr_inode_lock);
53108+
53109+ if (matchpo) {
53110+ preempt_enable();
53111+ return matchpo;
53112+ }
53113+ }
53114+
53115+ // lookup parent
53116+
53117+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53118+
53119+ preempt_enable();
53120+ return matchpo;
53121+}
53122+
53123+__u32
53124+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53125+ const struct vfsmount * mnt, const __u32 mode)
53126+{
53127+ struct acl_object_label *matchpo;
53128+ __u32 retval;
53129+
53130+ if (unlikely(!(gr_status & GR_READY)))
53131+ return (mode & ~GR_AUDITS);
53132+
53133+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
53134+
53135+ retval = matchpo->mode & mode;
53136+
53137+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53138+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53139+ __u32 new_mode = mode;
53140+
53141+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53142+
53143+ gr_log_learn(new_dentry, mnt, new_mode);
53144+ return new_mode;
53145+ }
53146+
53147+ return retval;
53148+}
53149+
53150+__u32
53151+gr_check_link(const struct dentry * new_dentry,
53152+ const struct dentry * parent_dentry,
53153+ const struct vfsmount * parent_mnt,
53154+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53155+{
53156+ struct acl_object_label *obj;
53157+ __u32 oldmode, newmode;
53158+ __u32 needmode;
53159+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53160+ GR_DELETE | GR_INHERIT;
53161+
53162+ if (unlikely(!(gr_status & GR_READY)))
53163+ return (GR_CREATE | GR_LINK);
53164+
53165+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53166+ oldmode = obj->mode;
53167+
53168+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53169+ newmode = obj->mode;
53170+
53171+ needmode = newmode & checkmodes;
53172+
53173+ // old name for hardlink must have at least the permissions of the new name
53174+ if ((oldmode & needmode) != needmode)
53175+ goto bad;
53176+
53177+ // if old name had restrictions/auditing, make sure the new name does as well
53178+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53179+
53180+ // don't allow hardlinking of suid/sgid files without permission
53181+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53182+ needmode |= GR_SETID;
53183+
53184+ if ((newmode & needmode) != needmode)
53185+ goto bad;
53186+
53187+ // enforce minimum permissions
53188+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53189+ return newmode;
53190+bad:
53191+ needmode = oldmode;
53192+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53193+ needmode |= GR_SETID;
53194+
53195+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53196+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53197+ return (GR_CREATE | GR_LINK);
53198+ } else if (newmode & GR_SUPPRESS)
53199+ return GR_SUPPRESS;
53200+ else
53201+ return 0;
53202+}
53203+
53204+int
53205+gr_check_hidden_task(const struct task_struct *task)
53206+{
53207+ if (unlikely(!(gr_status & GR_READY)))
53208+ return 0;
53209+
53210+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53211+ return 1;
53212+
53213+ return 0;
53214+}
53215+
53216+int
53217+gr_check_protected_task(const struct task_struct *task)
53218+{
53219+ if (unlikely(!(gr_status & GR_READY) || !task))
53220+ return 0;
53221+
53222+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53223+ task->acl != current->acl)
53224+ return 1;
53225+
53226+ return 0;
53227+}
53228+
53229+int
53230+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53231+{
53232+ struct task_struct *p;
53233+ int ret = 0;
53234+
53235+ if (unlikely(!(gr_status & GR_READY) || !pid))
53236+ return ret;
53237+
53238+ read_lock(&tasklist_lock);
53239+ do_each_pid_task(pid, type, p) {
53240+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53241+ p->acl != current->acl) {
53242+ ret = 1;
53243+ goto out;
53244+ }
53245+ } while_each_pid_task(pid, type, p);
53246+out:
53247+ read_unlock(&tasklist_lock);
53248+
53249+ return ret;
53250+}
53251+
53252+void
53253+gr_copy_label(struct task_struct *tsk)
53254+{
53255+ tsk->signal->used_accept = 0;
53256+ tsk->acl_sp_role = 0;
53257+ tsk->acl_role_id = current->acl_role_id;
53258+ tsk->acl = current->acl;
53259+ tsk->role = current->role;
53260+ tsk->signal->curr_ip = current->signal->curr_ip;
53261+ tsk->signal->saved_ip = current->signal->saved_ip;
53262+ if (current->exec_file)
53263+ get_file(current->exec_file);
53264+ tsk->exec_file = current->exec_file;
53265+ tsk->is_writable = current->is_writable;
53266+ if (unlikely(current->signal->used_accept)) {
53267+ current->signal->curr_ip = 0;
53268+ current->signal->saved_ip = 0;
53269+ }
53270+
53271+ return;
53272+}
53273+
53274+static void
53275+gr_set_proc_res(struct task_struct *task)
53276+{
53277+ struct acl_subject_label *proc;
53278+ unsigned short i;
53279+
53280+ proc = task->acl;
53281+
53282+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53283+ return;
53284+
53285+ for (i = 0; i < RLIM_NLIMITS; i++) {
53286+ if (!(proc->resmask & (1 << i)))
53287+ continue;
53288+
53289+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53290+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53291+ }
53292+
53293+ return;
53294+}
53295+
53296+extern int __gr_process_user_ban(struct user_struct *user);
53297+
53298+int
53299+gr_check_user_change(int real, int effective, int fs)
53300+{
53301+ unsigned int i;
53302+ __u16 num;
53303+ uid_t *uidlist;
53304+ int curuid;
53305+ int realok = 0;
53306+ int effectiveok = 0;
53307+ int fsok = 0;
53308+
53309+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53310+ struct user_struct *user;
53311+
53312+ if (real == -1)
53313+ goto skipit;
53314+
53315+ user = find_user(real);
53316+ if (user == NULL)
53317+ goto skipit;
53318+
53319+ if (__gr_process_user_ban(user)) {
53320+ /* for find_user */
53321+ free_uid(user);
53322+ return 1;
53323+ }
53324+
53325+ /* for find_user */
53326+ free_uid(user);
53327+
53328+skipit:
53329+#endif
53330+
53331+ if (unlikely(!(gr_status & GR_READY)))
53332+ return 0;
53333+
53334+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53335+ gr_log_learn_id_change('u', real, effective, fs);
53336+
53337+ num = current->acl->user_trans_num;
53338+ uidlist = current->acl->user_transitions;
53339+
53340+ if (uidlist == NULL)
53341+ return 0;
53342+
53343+ if (real == -1)
53344+ realok = 1;
53345+ if (effective == -1)
53346+ effectiveok = 1;
53347+ if (fs == -1)
53348+ fsok = 1;
53349+
53350+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
53351+ for (i = 0; i < num; i++) {
53352+ curuid = (int)uidlist[i];
53353+ if (real == curuid)
53354+ realok = 1;
53355+ if (effective == curuid)
53356+ effectiveok = 1;
53357+ if (fs == curuid)
53358+ fsok = 1;
53359+ }
53360+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
53361+ for (i = 0; i < num; i++) {
53362+ curuid = (int)uidlist[i];
53363+ if (real == curuid)
53364+ break;
53365+ if (effective == curuid)
53366+ break;
53367+ if (fs == curuid)
53368+ break;
53369+ }
53370+ /* not in deny list */
53371+ if (i == num) {
53372+ realok = 1;
53373+ effectiveok = 1;
53374+ fsok = 1;
53375+ }
53376+ }
53377+
53378+ if (realok && effectiveok && fsok)
53379+ return 0;
53380+ else {
53381+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53382+ return 1;
53383+ }
53384+}
53385+
53386+int
53387+gr_check_group_change(int real, int effective, int fs)
53388+{
53389+ unsigned int i;
53390+ __u16 num;
53391+ gid_t *gidlist;
53392+ int curgid;
53393+ int realok = 0;
53394+ int effectiveok = 0;
53395+ int fsok = 0;
53396+
53397+ if (unlikely(!(gr_status & GR_READY)))
53398+ return 0;
53399+
53400+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53401+ gr_log_learn_id_change('g', real, effective, fs);
53402+
53403+ num = current->acl->group_trans_num;
53404+ gidlist = current->acl->group_transitions;
53405+
53406+ if (gidlist == NULL)
53407+ return 0;
53408+
53409+ if (real == -1)
53410+ realok = 1;
53411+ if (effective == -1)
53412+ effectiveok = 1;
53413+ if (fs == -1)
53414+ fsok = 1;
53415+
53416+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
53417+ for (i = 0; i < num; i++) {
53418+ curgid = (int)gidlist[i];
53419+ if (real == curgid)
53420+ realok = 1;
53421+ if (effective == curgid)
53422+ effectiveok = 1;
53423+ if (fs == curgid)
53424+ fsok = 1;
53425+ }
53426+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
53427+ for (i = 0; i < num; i++) {
53428+ curgid = (int)gidlist[i];
53429+ if (real == curgid)
53430+ break;
53431+ if (effective == curgid)
53432+ break;
53433+ if (fs == curgid)
53434+ break;
53435+ }
53436+ /* not in deny list */
53437+ if (i == num) {
53438+ realok = 1;
53439+ effectiveok = 1;
53440+ fsok = 1;
53441+ }
53442+ }
53443+
53444+ if (realok && effectiveok && fsok)
53445+ return 0;
53446+ else {
53447+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53448+ return 1;
53449+ }
53450+}
53451+
53452+extern int gr_acl_is_capable(const int cap);
53453+
53454+void
53455+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53456+{
53457+ struct acl_role_label *role = task->role;
53458+ struct acl_subject_label *subj = NULL;
53459+ struct acl_object_label *obj;
53460+ struct file *filp;
53461+
53462+ if (unlikely(!(gr_status & GR_READY)))
53463+ return;
53464+
53465+ filp = task->exec_file;
53466+
53467+ /* kernel process, we'll give them the kernel role */
53468+ if (unlikely(!filp)) {
53469+ task->role = kernel_role;
53470+ task->acl = kernel_role->root_label;
53471+ return;
53472+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53473+ role = lookup_acl_role_label(task, uid, gid);
53474+
53475+ /* don't change the role if we're not a privileged process */
53476+ if (role && task->role != role &&
53477+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53478+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53479+ return;
53480+
53481+ /* perform subject lookup in possibly new role
53482+ we can use this result below in the case where role == task->role
53483+ */
53484+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53485+
53486+ /* if we changed uid/gid, but result in the same role
53487+ and are using inheritance, don't lose the inherited subject
53488+ if current subject is other than what normal lookup
53489+ would result in, we arrived via inheritance, don't
53490+ lose subject
53491+ */
53492+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53493+ (subj == task->acl)))
53494+ task->acl = subj;
53495+
53496+ task->role = role;
53497+
53498+ task->is_writable = 0;
53499+
53500+ /* ignore additional mmap checks for processes that are writable
53501+ by the default ACL */
53502+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53503+ if (unlikely(obj->mode & GR_WRITE))
53504+ task->is_writable = 1;
53505+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53506+ if (unlikely(obj->mode & GR_WRITE))
53507+ task->is_writable = 1;
53508+
53509+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53510+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53511+#endif
53512+
53513+ gr_set_proc_res(task);
53514+
53515+ return;
53516+}
53517+
53518+int
53519+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53520+ const int unsafe_flags)
53521+{
53522+ struct task_struct *task = current;
53523+ struct acl_subject_label *newacl;
53524+ struct acl_object_label *obj;
53525+ __u32 retmode;
53526+
53527+ if (unlikely(!(gr_status & GR_READY)))
53528+ return 0;
53529+
53530+ newacl = chk_subj_label(dentry, mnt, task->role);
53531+
53532+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53533+ did an exec
53534+ */
53535+ rcu_read_lock();
53536+ read_lock(&tasklist_lock);
53537+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53538+ (task->parent->acl->mode & GR_POVERRIDE))) {
53539+ read_unlock(&tasklist_lock);
53540+ rcu_read_unlock();
53541+ goto skip_check;
53542+ }
53543+ read_unlock(&tasklist_lock);
53544+ rcu_read_unlock();
53545+
53546+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53547+ !(task->role->roletype & GR_ROLE_GOD) &&
53548+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53549+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53550+ if (unsafe_flags & LSM_UNSAFE_SHARE)
53551+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53552+ else
53553+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53554+ return -EACCES;
53555+ }
53556+
53557+skip_check:
53558+
53559+ obj = chk_obj_label(dentry, mnt, task->acl);
53560+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53561+
53562+ if (!(task->acl->mode & GR_INHERITLEARN) &&
53563+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53564+ if (obj->nested)
53565+ task->acl = obj->nested;
53566+ else
53567+ task->acl = newacl;
53568+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53569+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53570+
53571+ task->is_writable = 0;
53572+
53573+ /* ignore additional mmap checks for processes that are writable
53574+ by the default ACL */
53575+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
53576+ if (unlikely(obj->mode & GR_WRITE))
53577+ task->is_writable = 1;
53578+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
53579+ if (unlikely(obj->mode & GR_WRITE))
53580+ task->is_writable = 1;
53581+
53582+ gr_set_proc_res(task);
53583+
53584+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53585+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53586+#endif
53587+ return 0;
53588+}
53589+
53590+/* always called with valid inodev ptr */
53591+static void
53592+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53593+{
53594+ struct acl_object_label *matchpo;
53595+ struct acl_subject_label *matchps;
53596+ struct acl_subject_label *subj;
53597+ struct acl_role_label *role;
53598+ unsigned int x;
53599+
53600+ FOR_EACH_ROLE_START(role)
53601+ FOR_EACH_SUBJECT_START(role, subj, x)
53602+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53603+ matchpo->mode |= GR_DELETED;
53604+ FOR_EACH_SUBJECT_END(subj,x)
53605+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53606+ if (subj->inode == ino && subj->device == dev)
53607+ subj->mode |= GR_DELETED;
53608+ FOR_EACH_NESTED_SUBJECT_END(subj)
53609+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53610+ matchps->mode |= GR_DELETED;
53611+ FOR_EACH_ROLE_END(role)
53612+
53613+ inodev->nentry->deleted = 1;
53614+
53615+ return;
53616+}
53617+
53618+void
53619+gr_handle_delete(const ino_t ino, const dev_t dev)
53620+{
53621+ struct inodev_entry *inodev;
53622+
53623+ if (unlikely(!(gr_status & GR_READY)))
53624+ return;
53625+
53626+ write_lock(&gr_inode_lock);
53627+ inodev = lookup_inodev_entry(ino, dev);
53628+ if (inodev != NULL)
53629+ do_handle_delete(inodev, ino, dev);
53630+ write_unlock(&gr_inode_lock);
53631+
53632+ return;
53633+}
53634+
53635+static void
53636+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53637+ const ino_t newinode, const dev_t newdevice,
53638+ struct acl_subject_label *subj)
53639+{
53640+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53641+ struct acl_object_label *match;
53642+
53643+ match = subj->obj_hash[index];
53644+
53645+ while (match && (match->inode != oldinode ||
53646+ match->device != olddevice ||
53647+ !(match->mode & GR_DELETED)))
53648+ match = match->next;
53649+
53650+ if (match && (match->inode == oldinode)
53651+ && (match->device == olddevice)
53652+ && (match->mode & GR_DELETED)) {
53653+ if (match->prev == NULL) {
53654+ subj->obj_hash[index] = match->next;
53655+ if (match->next != NULL)
53656+ match->next->prev = NULL;
53657+ } else {
53658+ match->prev->next = match->next;
53659+ if (match->next != NULL)
53660+ match->next->prev = match->prev;
53661+ }
53662+ match->prev = NULL;
53663+ match->next = NULL;
53664+ match->inode = newinode;
53665+ match->device = newdevice;
53666+ match->mode &= ~GR_DELETED;
53667+
53668+ insert_acl_obj_label(match, subj);
53669+ }
53670+
53671+ return;
53672+}
53673+
53674+static void
53675+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53676+ const ino_t newinode, const dev_t newdevice,
53677+ struct acl_role_label *role)
53678+{
53679+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53680+ struct acl_subject_label *match;
53681+
53682+ match = role->subj_hash[index];
53683+
53684+ while (match && (match->inode != oldinode ||
53685+ match->device != olddevice ||
53686+ !(match->mode & GR_DELETED)))
53687+ match = match->next;
53688+
53689+ if (match && (match->inode == oldinode)
53690+ && (match->device == olddevice)
53691+ && (match->mode & GR_DELETED)) {
53692+ if (match->prev == NULL) {
53693+ role->subj_hash[index] = match->next;
53694+ if (match->next != NULL)
53695+ match->next->prev = NULL;
53696+ } else {
53697+ match->prev->next = match->next;
53698+ if (match->next != NULL)
53699+ match->next->prev = match->prev;
53700+ }
53701+ match->prev = NULL;
53702+ match->next = NULL;
53703+ match->inode = newinode;
53704+ match->device = newdevice;
53705+ match->mode &= ~GR_DELETED;
53706+
53707+ insert_acl_subj_label(match, role);
53708+ }
53709+
53710+ return;
53711+}
53712+
53713+static void
53714+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53715+ const ino_t newinode, const dev_t newdevice)
53716+{
53717+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53718+ struct inodev_entry *match;
53719+
53720+ match = inodev_set.i_hash[index];
53721+
53722+ while (match && (match->nentry->inode != oldinode ||
53723+ match->nentry->device != olddevice || !match->nentry->deleted))
53724+ match = match->next;
53725+
53726+ if (match && (match->nentry->inode == oldinode)
53727+ && (match->nentry->device == olddevice) &&
53728+ match->nentry->deleted) {
53729+ if (match->prev == NULL) {
53730+ inodev_set.i_hash[index] = match->next;
53731+ if (match->next != NULL)
53732+ match->next->prev = NULL;
53733+ } else {
53734+ match->prev->next = match->next;
53735+ if (match->next != NULL)
53736+ match->next->prev = match->prev;
53737+ }
53738+ match->prev = NULL;
53739+ match->next = NULL;
53740+ match->nentry->inode = newinode;
53741+ match->nentry->device = newdevice;
53742+ match->nentry->deleted = 0;
53743+
53744+ insert_inodev_entry(match);
53745+ }
53746+
53747+ return;
53748+}
53749+
53750+static void
53751+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53752+{
53753+ struct acl_subject_label *subj;
53754+ struct acl_role_label *role;
53755+ unsigned int x;
53756+
53757+ FOR_EACH_ROLE_START(role)
53758+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53759+
53760+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53761+ if ((subj->inode == ino) && (subj->device == dev)) {
53762+ subj->inode = ino;
53763+ subj->device = dev;
53764+ }
53765+ FOR_EACH_NESTED_SUBJECT_END(subj)
53766+ FOR_EACH_SUBJECT_START(role, subj, x)
53767+ update_acl_obj_label(matchn->inode, matchn->device,
53768+ ino, dev, subj);
53769+ FOR_EACH_SUBJECT_END(subj,x)
53770+ FOR_EACH_ROLE_END(role)
53771+
53772+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53773+
53774+ return;
53775+}
53776+
53777+static void
53778+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53779+ const struct vfsmount *mnt)
53780+{
53781+ ino_t ino = dentry->d_inode->i_ino;
53782+ dev_t dev = __get_dev(dentry);
53783+
53784+ __do_handle_create(matchn, ino, dev);
53785+
53786+ return;
53787+}
53788+
53789+void
53790+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53791+{
53792+ struct name_entry *matchn;
53793+
53794+ if (unlikely(!(gr_status & GR_READY)))
53795+ return;
53796+
53797+ preempt_disable();
53798+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53799+
53800+ if (unlikely((unsigned long)matchn)) {
53801+ write_lock(&gr_inode_lock);
53802+ do_handle_create(matchn, dentry, mnt);
53803+ write_unlock(&gr_inode_lock);
53804+ }
53805+ preempt_enable();
53806+
53807+ return;
53808+}
53809+
53810+void
53811+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53812+{
53813+ struct name_entry *matchn;
53814+
53815+ if (unlikely(!(gr_status & GR_READY)))
53816+ return;
53817+
53818+ preempt_disable();
53819+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53820+
53821+ if (unlikely((unsigned long)matchn)) {
53822+ write_lock(&gr_inode_lock);
53823+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53824+ write_unlock(&gr_inode_lock);
53825+ }
53826+ preempt_enable();
53827+
53828+ return;
53829+}
53830+
53831+void
53832+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53833+ struct dentry *old_dentry,
53834+ struct dentry *new_dentry,
53835+ struct vfsmount *mnt, const __u8 replace)
53836+{
53837+ struct name_entry *matchn;
53838+ struct inodev_entry *inodev;
53839+ struct inode *inode = new_dentry->d_inode;
53840+ ino_t old_ino = old_dentry->d_inode->i_ino;
53841+ dev_t old_dev = __get_dev(old_dentry);
53842+
53843+ /* vfs_rename swaps the name and parent link for old_dentry and
53844+ new_dentry
53845+ at this point, old_dentry has the new name, parent link, and inode
53846+ for the renamed file
53847+ if a file is being replaced by a rename, new_dentry has the inode
53848+ and name for the replaced file
53849+ */
53850+
53851+ if (unlikely(!(gr_status & GR_READY)))
53852+ return;
53853+
53854+ preempt_disable();
53855+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53856+
53857+ /* we wouldn't have to check d_inode if it weren't for
53858+ NFS silly-renaming
53859+ */
53860+
53861+ write_lock(&gr_inode_lock);
53862+ if (unlikely(replace && inode)) {
53863+ ino_t new_ino = inode->i_ino;
53864+ dev_t new_dev = __get_dev(new_dentry);
53865+
53866+ inodev = lookup_inodev_entry(new_ino, new_dev);
53867+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53868+ do_handle_delete(inodev, new_ino, new_dev);
53869+ }
53870+
53871+ inodev = lookup_inodev_entry(old_ino, old_dev);
53872+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53873+ do_handle_delete(inodev, old_ino, old_dev);
53874+
53875+ if (unlikely((unsigned long)matchn))
53876+ do_handle_create(matchn, old_dentry, mnt);
53877+
53878+ write_unlock(&gr_inode_lock);
53879+ preempt_enable();
53880+
53881+ return;
53882+}
53883+
53884+static int
53885+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53886+ unsigned char **sum)
53887+{
53888+ struct acl_role_label *r;
53889+ struct role_allowed_ip *ipp;
53890+ struct role_transition *trans;
53891+ unsigned int i;
53892+ int found = 0;
53893+ u32 curr_ip = current->signal->curr_ip;
53894+
53895+ current->signal->saved_ip = curr_ip;
53896+
53897+ /* check transition table */
53898+
53899+ for (trans = current->role->transitions; trans; trans = trans->next) {
53900+ if (!strcmp(rolename, trans->rolename)) {
53901+ found = 1;
53902+ break;
53903+ }
53904+ }
53905+
53906+ if (!found)
53907+ return 0;
53908+
53909+ /* handle special roles that do not require authentication
53910+ and check ip */
53911+
53912+ FOR_EACH_ROLE_START(r)
53913+ if (!strcmp(rolename, r->rolename) &&
53914+ (r->roletype & GR_ROLE_SPECIAL)) {
53915+ found = 0;
53916+ if (r->allowed_ips != NULL) {
53917+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53918+ if ((ntohl(curr_ip) & ipp->netmask) ==
53919+ (ntohl(ipp->addr) & ipp->netmask))
53920+ found = 1;
53921+ }
53922+ } else
53923+ found = 2;
53924+ if (!found)
53925+ return 0;
53926+
53927+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53928+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53929+ *salt = NULL;
53930+ *sum = NULL;
53931+ return 1;
53932+ }
53933+ }
53934+ FOR_EACH_ROLE_END(r)
53935+
53936+ for (i = 0; i < num_sprole_pws; i++) {
53937+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53938+ *salt = acl_special_roles[i]->salt;
53939+ *sum = acl_special_roles[i]->sum;
53940+ return 1;
53941+ }
53942+ }
53943+
53944+ return 0;
53945+}
53946+
53947+static void
53948+assign_special_role(char *rolename)
53949+{
53950+ struct acl_object_label *obj;
53951+ struct acl_role_label *r;
53952+ struct acl_role_label *assigned = NULL;
53953+ struct task_struct *tsk;
53954+ struct file *filp;
53955+
53956+ FOR_EACH_ROLE_START(r)
53957+ if (!strcmp(rolename, r->rolename) &&
53958+ (r->roletype & GR_ROLE_SPECIAL)) {
53959+ assigned = r;
53960+ break;
53961+ }
53962+ FOR_EACH_ROLE_END(r)
53963+
53964+ if (!assigned)
53965+ return;
53966+
53967+ read_lock(&tasklist_lock);
53968+ read_lock(&grsec_exec_file_lock);
53969+
53970+ tsk = current->real_parent;
53971+ if (tsk == NULL)
53972+ goto out_unlock;
53973+
53974+ filp = tsk->exec_file;
53975+ if (filp == NULL)
53976+ goto out_unlock;
53977+
53978+ tsk->is_writable = 0;
53979+
53980+ tsk->acl_sp_role = 1;
53981+ tsk->acl_role_id = ++acl_sp_role_value;
53982+ tsk->role = assigned;
53983+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53984+
53985+ /* ignore additional mmap checks for processes that are writable
53986+ by the default ACL */
53987+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53988+ if (unlikely(obj->mode & GR_WRITE))
53989+ tsk->is_writable = 1;
53990+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53991+ if (unlikely(obj->mode & GR_WRITE))
53992+ tsk->is_writable = 1;
53993+
53994+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53995+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53996+#endif
53997+
53998+out_unlock:
53999+ read_unlock(&grsec_exec_file_lock);
54000+ read_unlock(&tasklist_lock);
54001+ return;
54002+}
54003+
54004+int gr_check_secure_terminal(struct task_struct *task)
54005+{
54006+ struct task_struct *p, *p2, *p3;
54007+ struct files_struct *files;
54008+ struct fdtable *fdt;
54009+ struct file *our_file = NULL, *file;
54010+ int i;
54011+
54012+ if (task->signal->tty == NULL)
54013+ return 1;
54014+
54015+ files = get_files_struct(task);
54016+ if (files != NULL) {
54017+ rcu_read_lock();
54018+ fdt = files_fdtable(files);
54019+ for (i=0; i < fdt->max_fds; i++) {
54020+ file = fcheck_files(files, i);
54021+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54022+ get_file(file);
54023+ our_file = file;
54024+ }
54025+ }
54026+ rcu_read_unlock();
54027+ put_files_struct(files);
54028+ }
54029+
54030+ if (our_file == NULL)
54031+ return 1;
54032+
54033+ read_lock(&tasklist_lock);
54034+ do_each_thread(p2, p) {
54035+ files = get_files_struct(p);
54036+ if (files == NULL ||
54037+ (p->signal && p->signal->tty == task->signal->tty)) {
54038+ if (files != NULL)
54039+ put_files_struct(files);
54040+ continue;
54041+ }
54042+ rcu_read_lock();
54043+ fdt = files_fdtable(files);
54044+ for (i=0; i < fdt->max_fds; i++) {
54045+ file = fcheck_files(files, i);
54046+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54047+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54048+ p3 = task;
54049+ while (p3->pid > 0) {
54050+ if (p3 == p)
54051+ break;
54052+ p3 = p3->real_parent;
54053+ }
54054+ if (p3 == p)
54055+ break;
54056+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54057+ gr_handle_alertkill(p);
54058+ rcu_read_unlock();
54059+ put_files_struct(files);
54060+ read_unlock(&tasklist_lock);
54061+ fput(our_file);
54062+ return 0;
54063+ }
54064+ }
54065+ rcu_read_unlock();
54066+ put_files_struct(files);
54067+ } while_each_thread(p2, p);
54068+ read_unlock(&tasklist_lock);
54069+
54070+ fput(our_file);
54071+ return 1;
54072+}
54073+
54074+static int gr_rbac_disable(void *unused)
54075+{
54076+ pax_open_kernel();
54077+ gr_status &= ~GR_READY;
54078+ pax_close_kernel();
54079+
54080+ return 0;
54081+}
54082+
54083+ssize_t
54084+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54085+{
54086+ struct gr_arg_wrapper uwrap;
54087+ unsigned char *sprole_salt = NULL;
54088+ unsigned char *sprole_sum = NULL;
54089+ int error = sizeof (struct gr_arg_wrapper);
54090+ int error2 = 0;
54091+
54092+ mutex_lock(&gr_dev_mutex);
54093+
54094+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54095+ error = -EPERM;
54096+ goto out;
54097+ }
54098+
54099+ if (count != sizeof (struct gr_arg_wrapper)) {
54100+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54101+ error = -EINVAL;
54102+ goto out;
54103+ }
54104+
54105+
54106+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54107+ gr_auth_expires = 0;
54108+ gr_auth_attempts = 0;
54109+ }
54110+
54111+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54112+ error = -EFAULT;
54113+ goto out;
54114+ }
54115+
54116+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54117+ error = -EINVAL;
54118+ goto out;
54119+ }
54120+
54121+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54122+ error = -EFAULT;
54123+ goto out;
54124+ }
54125+
54126+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54127+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54128+ time_after(gr_auth_expires, get_seconds())) {
54129+ error = -EBUSY;
54130+ goto out;
54131+ }
54132+
54133+ /* if non-root trying to do anything other than use a special role,
54134+ do not attempt authentication, do not count towards authentication
54135+ locking
54136+ */
54137+
54138+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54139+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54140+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54141+ error = -EPERM;
54142+ goto out;
54143+ }
54144+
54145+ /* ensure pw and special role name are null terminated */
54146+
54147+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54148+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54149+
54150+ /* Okay.
54151+ * We have our enough of the argument structure..(we have yet
54152+ * to copy_from_user the tables themselves) . Copy the tables
54153+ * only if we need them, i.e. for loading operations. */
54154+
54155+ switch (gr_usermode->mode) {
54156+ case GR_STATUS:
54157+ if (gr_status & GR_READY) {
54158+ error = 1;
54159+ if (!gr_check_secure_terminal(current))
54160+ error = 3;
54161+ } else
54162+ error = 2;
54163+ goto out;
54164+ case GR_SHUTDOWN:
54165+ if ((gr_status & GR_READY)
54166+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54167+ stop_machine(gr_rbac_disable, NULL, NULL);
54168+ free_variables();
54169+ memset(gr_usermode, 0, sizeof (struct gr_arg));
54170+ memset(gr_system_salt, 0, GR_SALT_LEN);
54171+ memset(gr_system_sum, 0, GR_SHA_LEN);
54172+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54173+ } else if (gr_status & GR_READY) {
54174+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54175+ error = -EPERM;
54176+ } else {
54177+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54178+ error = -EAGAIN;
54179+ }
54180+ break;
54181+ case GR_ENABLE:
54182+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54183+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54184+ else {
54185+ if (gr_status & GR_READY)
54186+ error = -EAGAIN;
54187+ else
54188+ error = error2;
54189+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54190+ }
54191+ break;
54192+ case GR_RELOAD:
54193+ if (!(gr_status & GR_READY)) {
54194+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54195+ error = -EAGAIN;
54196+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54197+ stop_machine(gr_rbac_disable, NULL, NULL);
54198+ free_variables();
54199+ error2 = gracl_init(gr_usermode);
54200+ if (!error2)
54201+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54202+ else {
54203+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54204+ error = error2;
54205+ }
54206+ } else {
54207+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54208+ error = -EPERM;
54209+ }
54210+ break;
54211+ case GR_SEGVMOD:
54212+ if (unlikely(!(gr_status & GR_READY))) {
54213+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54214+ error = -EAGAIN;
54215+ break;
54216+ }
54217+
54218+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54219+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54220+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54221+ struct acl_subject_label *segvacl;
54222+ segvacl =
54223+ lookup_acl_subj_label(gr_usermode->segv_inode,
54224+ gr_usermode->segv_device,
54225+ current->role);
54226+ if (segvacl) {
54227+ segvacl->crashes = 0;
54228+ segvacl->expires = 0;
54229+ }
54230+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54231+ gr_remove_uid(gr_usermode->segv_uid);
54232+ }
54233+ } else {
54234+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54235+ error = -EPERM;
54236+ }
54237+ break;
54238+ case GR_SPROLE:
54239+ case GR_SPROLEPAM:
54240+ if (unlikely(!(gr_status & GR_READY))) {
54241+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54242+ error = -EAGAIN;
54243+ break;
54244+ }
54245+
54246+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54247+ current->role->expires = 0;
54248+ current->role->auth_attempts = 0;
54249+ }
54250+
54251+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54252+ time_after(current->role->expires, get_seconds())) {
54253+ error = -EBUSY;
54254+ goto out;
54255+ }
54256+
54257+ if (lookup_special_role_auth
54258+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54259+ && ((!sprole_salt && !sprole_sum)
54260+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54261+ char *p = "";
54262+ assign_special_role(gr_usermode->sp_role);
54263+ read_lock(&tasklist_lock);
54264+ if (current->real_parent)
54265+ p = current->real_parent->role->rolename;
54266+ read_unlock(&tasklist_lock);
54267+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54268+ p, acl_sp_role_value);
54269+ } else {
54270+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54271+ error = -EPERM;
54272+ if(!(current->role->auth_attempts++))
54273+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54274+
54275+ goto out;
54276+ }
54277+ break;
54278+ case GR_UNSPROLE:
54279+ if (unlikely(!(gr_status & GR_READY))) {
54280+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54281+ error = -EAGAIN;
54282+ break;
54283+ }
54284+
54285+ if (current->role->roletype & GR_ROLE_SPECIAL) {
54286+ char *p = "";
54287+ int i = 0;
54288+
54289+ read_lock(&tasklist_lock);
54290+ if (current->real_parent) {
54291+ p = current->real_parent->role->rolename;
54292+ i = current->real_parent->acl_role_id;
54293+ }
54294+ read_unlock(&tasklist_lock);
54295+
54296+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54297+ gr_set_acls(1);
54298+ } else {
54299+ error = -EPERM;
54300+ goto out;
54301+ }
54302+ break;
54303+ default:
54304+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54305+ error = -EINVAL;
54306+ break;
54307+ }
54308+
54309+ if (error != -EPERM)
54310+ goto out;
54311+
54312+ if(!(gr_auth_attempts++))
54313+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54314+
54315+ out:
54316+ mutex_unlock(&gr_dev_mutex);
54317+ return error;
54318+}
54319+
54320+/* must be called with
54321+ rcu_read_lock();
54322+ read_lock(&tasklist_lock);
54323+ read_lock(&grsec_exec_file_lock);
54324+*/
54325+int gr_apply_subject_to_task(struct task_struct *task)
54326+{
54327+ struct acl_object_label *obj;
54328+ char *tmpname;
54329+ struct acl_subject_label *tmpsubj;
54330+ struct file *filp;
54331+ struct name_entry *nmatch;
54332+
54333+ filp = task->exec_file;
54334+ if (filp == NULL)
54335+ return 0;
54336+
54337+ /* the following is to apply the correct subject
54338+ on binaries running when the RBAC system
54339+ is enabled, when the binaries have been
54340+ replaced or deleted since their execution
54341+ -----
54342+ when the RBAC system starts, the inode/dev
54343+ from exec_file will be one the RBAC system
54344+ is unaware of. It only knows the inode/dev
54345+ of the present file on disk, or the absence
54346+ of it.
54347+ */
54348+ preempt_disable();
54349+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54350+
54351+ nmatch = lookup_name_entry(tmpname);
54352+ preempt_enable();
54353+ tmpsubj = NULL;
54354+ if (nmatch) {
54355+ if (nmatch->deleted)
54356+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54357+ else
54358+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54359+ if (tmpsubj != NULL)
54360+ task->acl = tmpsubj;
54361+ }
54362+ if (tmpsubj == NULL)
54363+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54364+ task->role);
54365+ if (task->acl) {
54366+ task->is_writable = 0;
54367+ /* ignore additional mmap checks for processes that are writable
54368+ by the default ACL */
54369+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54370+ if (unlikely(obj->mode & GR_WRITE))
54371+ task->is_writable = 1;
54372+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54373+ if (unlikely(obj->mode & GR_WRITE))
54374+ task->is_writable = 1;
54375+
54376+ gr_set_proc_res(task);
54377+
54378+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54379+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54380+#endif
54381+ } else {
54382+ return 1;
54383+ }
54384+
54385+ return 0;
54386+}
54387+
54388+int
54389+gr_set_acls(const int type)
54390+{
54391+ struct task_struct *task, *task2;
54392+ struct acl_role_label *role = current->role;
54393+ __u16 acl_role_id = current->acl_role_id;
54394+ const struct cred *cred;
54395+ int ret;
54396+
54397+ rcu_read_lock();
54398+ read_lock(&tasklist_lock);
54399+ read_lock(&grsec_exec_file_lock);
54400+ do_each_thread(task2, task) {
54401+ /* check to see if we're called from the exit handler,
54402+ if so, only replace ACLs that have inherited the admin
54403+ ACL */
54404+
54405+ if (type && (task->role != role ||
54406+ task->acl_role_id != acl_role_id))
54407+ continue;
54408+
54409+ task->acl_role_id = 0;
54410+ task->acl_sp_role = 0;
54411+
54412+ if (task->exec_file) {
54413+ cred = __task_cred(task);
54414+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54415+ ret = gr_apply_subject_to_task(task);
54416+ if (ret) {
54417+ read_unlock(&grsec_exec_file_lock);
54418+ read_unlock(&tasklist_lock);
54419+ rcu_read_unlock();
54420+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54421+ return ret;
54422+ }
54423+ } else {
54424+ // it's a kernel process
54425+ task->role = kernel_role;
54426+ task->acl = kernel_role->root_label;
54427+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54428+ task->acl->mode &= ~GR_PROCFIND;
54429+#endif
54430+ }
54431+ } while_each_thread(task2, task);
54432+ read_unlock(&grsec_exec_file_lock);
54433+ read_unlock(&tasklist_lock);
54434+ rcu_read_unlock();
54435+
54436+ return 0;
54437+}
54438+
54439+void
54440+gr_learn_resource(const struct task_struct *task,
54441+ const int res, const unsigned long wanted, const int gt)
54442+{
54443+ struct acl_subject_label *acl;
54444+ const struct cred *cred;
54445+
54446+ if (unlikely((gr_status & GR_READY) &&
54447+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54448+ goto skip_reslog;
54449+
54450+#ifdef CONFIG_GRKERNSEC_RESLOG
54451+ gr_log_resource(task, res, wanted, gt);
54452+#endif
54453+ skip_reslog:
54454+
54455+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54456+ return;
54457+
54458+ acl = task->acl;
54459+
54460+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54461+ !(acl->resmask & (1 << (unsigned short) res))))
54462+ return;
54463+
54464+ if (wanted >= acl->res[res].rlim_cur) {
54465+ unsigned long res_add;
54466+
54467+ res_add = wanted;
54468+ switch (res) {
54469+ case RLIMIT_CPU:
54470+ res_add += GR_RLIM_CPU_BUMP;
54471+ break;
54472+ case RLIMIT_FSIZE:
54473+ res_add += GR_RLIM_FSIZE_BUMP;
54474+ break;
54475+ case RLIMIT_DATA:
54476+ res_add += GR_RLIM_DATA_BUMP;
54477+ break;
54478+ case RLIMIT_STACK:
54479+ res_add += GR_RLIM_STACK_BUMP;
54480+ break;
54481+ case RLIMIT_CORE:
54482+ res_add += GR_RLIM_CORE_BUMP;
54483+ break;
54484+ case RLIMIT_RSS:
54485+ res_add += GR_RLIM_RSS_BUMP;
54486+ break;
54487+ case RLIMIT_NPROC:
54488+ res_add += GR_RLIM_NPROC_BUMP;
54489+ break;
54490+ case RLIMIT_NOFILE:
54491+ res_add += GR_RLIM_NOFILE_BUMP;
54492+ break;
54493+ case RLIMIT_MEMLOCK:
54494+ res_add += GR_RLIM_MEMLOCK_BUMP;
54495+ break;
54496+ case RLIMIT_AS:
54497+ res_add += GR_RLIM_AS_BUMP;
54498+ break;
54499+ case RLIMIT_LOCKS:
54500+ res_add += GR_RLIM_LOCKS_BUMP;
54501+ break;
54502+ case RLIMIT_SIGPENDING:
54503+ res_add += GR_RLIM_SIGPENDING_BUMP;
54504+ break;
54505+ case RLIMIT_MSGQUEUE:
54506+ res_add += GR_RLIM_MSGQUEUE_BUMP;
54507+ break;
54508+ case RLIMIT_NICE:
54509+ res_add += GR_RLIM_NICE_BUMP;
54510+ break;
54511+ case RLIMIT_RTPRIO:
54512+ res_add += GR_RLIM_RTPRIO_BUMP;
54513+ break;
54514+ case RLIMIT_RTTIME:
54515+ res_add += GR_RLIM_RTTIME_BUMP;
54516+ break;
54517+ }
54518+
54519+ acl->res[res].rlim_cur = res_add;
54520+
54521+ if (wanted > acl->res[res].rlim_max)
54522+ acl->res[res].rlim_max = res_add;
54523+
54524+ /* only log the subject filename, since resource logging is supported for
54525+ single-subject learning only */
54526+ rcu_read_lock();
54527+ cred = __task_cred(task);
54528+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54529+ task->role->roletype, cred->uid, cred->gid, acl->filename,
54530+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54531+ "", (unsigned long) res, &task->signal->saved_ip);
54532+ rcu_read_unlock();
54533+ }
54534+
54535+ return;
54536+}
54537+
54538+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54539+void
54540+pax_set_initial_flags(struct linux_binprm *bprm)
54541+{
54542+ struct task_struct *task = current;
54543+ struct acl_subject_label *proc;
54544+ unsigned long flags;
54545+
54546+ if (unlikely(!(gr_status & GR_READY)))
54547+ return;
54548+
54549+ flags = pax_get_flags(task);
54550+
54551+ proc = task->acl;
54552+
54553+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54554+ flags &= ~MF_PAX_PAGEEXEC;
54555+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54556+ flags &= ~MF_PAX_SEGMEXEC;
54557+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54558+ flags &= ~MF_PAX_RANDMMAP;
54559+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54560+ flags &= ~MF_PAX_EMUTRAMP;
54561+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54562+ flags &= ~MF_PAX_MPROTECT;
54563+
54564+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54565+ flags |= MF_PAX_PAGEEXEC;
54566+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54567+ flags |= MF_PAX_SEGMEXEC;
54568+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54569+ flags |= MF_PAX_RANDMMAP;
54570+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54571+ flags |= MF_PAX_EMUTRAMP;
54572+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54573+ flags |= MF_PAX_MPROTECT;
54574+
54575+ pax_set_flags(task, flags);
54576+
54577+ return;
54578+}
54579+#endif
54580+
54581+int
54582+gr_handle_proc_ptrace(struct task_struct *task)
54583+{
54584+ struct file *filp;
54585+ struct task_struct *tmp = task;
54586+ struct task_struct *curtemp = current;
54587+ __u32 retmode;
54588+
54589+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54590+ if (unlikely(!(gr_status & GR_READY)))
54591+ return 0;
54592+#endif
54593+
54594+ read_lock(&tasklist_lock);
54595+ read_lock(&grsec_exec_file_lock);
54596+ filp = task->exec_file;
54597+
54598+ while (tmp->pid > 0) {
54599+ if (tmp == curtemp)
54600+ break;
54601+ tmp = tmp->real_parent;
54602+ }
54603+
54604+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54605+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54606+ read_unlock(&grsec_exec_file_lock);
54607+ read_unlock(&tasklist_lock);
54608+ return 1;
54609+ }
54610+
54611+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54612+ if (!(gr_status & GR_READY)) {
54613+ read_unlock(&grsec_exec_file_lock);
54614+ read_unlock(&tasklist_lock);
54615+ return 0;
54616+ }
54617+#endif
54618+
54619+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54620+ read_unlock(&grsec_exec_file_lock);
54621+ read_unlock(&tasklist_lock);
54622+
54623+ if (retmode & GR_NOPTRACE)
54624+ return 1;
54625+
54626+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54627+ && (current->acl != task->acl || (current->acl != current->role->root_label
54628+ && current->pid != task->pid)))
54629+ return 1;
54630+
54631+ return 0;
54632+}
54633+
54634+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54635+{
54636+ if (unlikely(!(gr_status & GR_READY)))
54637+ return;
54638+
54639+ if (!(current->role->roletype & GR_ROLE_GOD))
54640+ return;
54641+
54642+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54643+ p->role->rolename, gr_task_roletype_to_char(p),
54644+ p->acl->filename);
54645+}
54646+
54647+int
54648+gr_handle_ptrace(struct task_struct *task, const long request)
54649+{
54650+ struct task_struct *tmp = task;
54651+ struct task_struct *curtemp = current;
54652+ __u32 retmode;
54653+
54654+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54655+ if (unlikely(!(gr_status & GR_READY)))
54656+ return 0;
54657+#endif
54658+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
54659+ read_lock(&tasklist_lock);
54660+ while (tmp->pid > 0) {
54661+ if (tmp == curtemp)
54662+ break;
54663+ tmp = tmp->real_parent;
54664+ }
54665+
54666+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54667+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54668+ read_unlock(&tasklist_lock);
54669+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54670+ return 1;
54671+ }
54672+ read_unlock(&tasklist_lock);
54673+ }
54674+
54675+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54676+ if (!(gr_status & GR_READY))
54677+ return 0;
54678+#endif
54679+
54680+ read_lock(&grsec_exec_file_lock);
54681+ if (unlikely(!task->exec_file)) {
54682+ read_unlock(&grsec_exec_file_lock);
54683+ return 0;
54684+ }
54685+
54686+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54687+ read_unlock(&grsec_exec_file_lock);
54688+
54689+ if (retmode & GR_NOPTRACE) {
54690+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54691+ return 1;
54692+ }
54693+
54694+ if (retmode & GR_PTRACERD) {
54695+ switch (request) {
54696+ case PTRACE_SEIZE:
54697+ case PTRACE_POKETEXT:
54698+ case PTRACE_POKEDATA:
54699+ case PTRACE_POKEUSR:
54700+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54701+ case PTRACE_SETREGS:
54702+ case PTRACE_SETFPREGS:
54703+#endif
54704+#ifdef CONFIG_X86
54705+ case PTRACE_SETFPXREGS:
54706+#endif
54707+#ifdef CONFIG_ALTIVEC
54708+ case PTRACE_SETVRREGS:
54709+#endif
54710+ return 1;
54711+ default:
54712+ return 0;
54713+ }
54714+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
54715+ !(current->role->roletype & GR_ROLE_GOD) &&
54716+ (current->acl != task->acl)) {
54717+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54718+ return 1;
54719+ }
54720+
54721+ return 0;
54722+}
54723+
54724+static int is_writable_mmap(const struct file *filp)
54725+{
54726+ struct task_struct *task = current;
54727+ struct acl_object_label *obj, *obj2;
54728+
54729+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54730+ !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))) {
54731+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54732+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54733+ task->role->root_label);
54734+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54735+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54736+ return 1;
54737+ }
54738+ }
54739+ return 0;
54740+}
54741+
54742+int
54743+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54744+{
54745+ __u32 mode;
54746+
54747+ if (unlikely(!file || !(prot & PROT_EXEC)))
54748+ return 1;
54749+
54750+ if (is_writable_mmap(file))
54751+ return 0;
54752+
54753+ mode =
54754+ gr_search_file(file->f_path.dentry,
54755+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54756+ file->f_path.mnt);
54757+
54758+ if (!gr_tpe_allow(file))
54759+ return 0;
54760+
54761+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54762+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54763+ return 0;
54764+ } else if (unlikely(!(mode & GR_EXEC))) {
54765+ return 0;
54766+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54767+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54768+ return 1;
54769+ }
54770+
54771+ return 1;
54772+}
54773+
54774+int
54775+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54776+{
54777+ __u32 mode;
54778+
54779+ if (unlikely(!file || !(prot & PROT_EXEC)))
54780+ return 1;
54781+
54782+ if (is_writable_mmap(file))
54783+ return 0;
54784+
54785+ mode =
54786+ gr_search_file(file->f_path.dentry,
54787+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54788+ file->f_path.mnt);
54789+
54790+ if (!gr_tpe_allow(file))
54791+ return 0;
54792+
54793+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54794+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54795+ return 0;
54796+ } else if (unlikely(!(mode & GR_EXEC))) {
54797+ return 0;
54798+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54799+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54800+ return 1;
54801+ }
54802+
54803+ return 1;
54804+}
54805+
54806+void
54807+gr_acl_handle_psacct(struct task_struct *task, const long code)
54808+{
54809+ unsigned long runtime;
54810+ unsigned long cputime;
54811+ unsigned int wday, cday;
54812+ __u8 whr, chr;
54813+ __u8 wmin, cmin;
54814+ __u8 wsec, csec;
54815+ struct timespec timeval;
54816+
54817+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54818+ !(task->acl->mode & GR_PROCACCT)))
54819+ return;
54820+
54821+ do_posix_clock_monotonic_gettime(&timeval);
54822+ runtime = timeval.tv_sec - task->start_time.tv_sec;
54823+ wday = runtime / (3600 * 24);
54824+ runtime -= wday * (3600 * 24);
54825+ whr = runtime / 3600;
54826+ runtime -= whr * 3600;
54827+ wmin = runtime / 60;
54828+ runtime -= wmin * 60;
54829+ wsec = runtime;
54830+
54831+ cputime = (task->utime + task->stime) / HZ;
54832+ cday = cputime / (3600 * 24);
54833+ cputime -= cday * (3600 * 24);
54834+ chr = cputime / 3600;
54835+ cputime -= chr * 3600;
54836+ cmin = cputime / 60;
54837+ cputime -= cmin * 60;
54838+ csec = cputime;
54839+
54840+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54841+
54842+ return;
54843+}
54844+
54845+void gr_set_kernel_label(struct task_struct *task)
54846+{
54847+ if (gr_status & GR_READY) {
54848+ task->role = kernel_role;
54849+ task->acl = kernel_role->root_label;
54850+ }
54851+ return;
54852+}
54853+
54854+#ifdef CONFIG_TASKSTATS
54855+int gr_is_taskstats_denied(int pid)
54856+{
54857+ struct task_struct *task;
54858+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54859+ const struct cred *cred;
54860+#endif
54861+ int ret = 0;
54862+
54863+ /* restrict taskstats viewing to un-chrooted root users
54864+ who have the 'view' subject flag if the RBAC system is enabled
54865+ */
54866+
54867+ rcu_read_lock();
54868+ read_lock(&tasklist_lock);
54869+ task = find_task_by_vpid(pid);
54870+ if (task) {
54871+#ifdef CONFIG_GRKERNSEC_CHROOT
54872+ if (proc_is_chrooted(task))
54873+ ret = -EACCES;
54874+#endif
54875+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54876+ cred = __task_cred(task);
54877+#ifdef CONFIG_GRKERNSEC_PROC_USER
54878+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
54879+ ret = -EACCES;
54880+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54881+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54882+ ret = -EACCES;
54883+#endif
54884+#endif
54885+ if (gr_status & GR_READY) {
54886+ if (!(task->acl->mode & GR_VIEW))
54887+ ret = -EACCES;
54888+ }
54889+ } else
54890+ ret = -ENOENT;
54891+
54892+ read_unlock(&tasklist_lock);
54893+ rcu_read_unlock();
54894+
54895+ return ret;
54896+}
54897+#endif
54898+
54899+/* AUXV entries are filled via a descendant of search_binary_handler
54900+ after we've already applied the subject for the target
54901+*/
54902+int gr_acl_enable_at_secure(void)
54903+{
54904+ if (unlikely(!(gr_status & GR_READY)))
54905+ return 0;
54906+
54907+ if (current->acl->mode & GR_ATSECURE)
54908+ return 1;
54909+
54910+ return 0;
54911+}
54912+
54913+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54914+{
54915+ struct task_struct *task = current;
54916+ struct dentry *dentry = file->f_path.dentry;
54917+ struct vfsmount *mnt = file->f_path.mnt;
54918+ struct acl_object_label *obj, *tmp;
54919+ struct acl_subject_label *subj;
54920+ unsigned int bufsize;
54921+ int is_not_root;
54922+ char *path;
54923+ dev_t dev = __get_dev(dentry);
54924+
54925+ if (unlikely(!(gr_status & GR_READY)))
54926+ return 1;
54927+
54928+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54929+ return 1;
54930+
54931+ /* ignore Eric Biederman */
54932+ if (IS_PRIVATE(dentry->d_inode))
54933+ return 1;
54934+
54935+ subj = task->acl;
54936+ read_lock(&gr_inode_lock);
54937+ do {
54938+ obj = lookup_acl_obj_label(ino, dev, subj);
54939+ if (obj != NULL) {
54940+ read_unlock(&gr_inode_lock);
54941+ return (obj->mode & GR_FIND) ? 1 : 0;
54942+ }
54943+ } while ((subj = subj->parent_subject));
54944+ read_unlock(&gr_inode_lock);
54945+
54946+ /* this is purely an optimization since we're looking for an object
54947+ for the directory we're doing a readdir on
54948+ if it's possible for any globbed object to match the entry we're
54949+ filling into the directory, then the object we find here will be
54950+ an anchor point with attached globbed objects
54951+ */
54952+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54953+ if (obj->globbed == NULL)
54954+ return (obj->mode & GR_FIND) ? 1 : 0;
54955+
54956+ is_not_root = ((obj->filename[0] == '/') &&
54957+ (obj->filename[1] == '\0')) ? 0 : 1;
54958+ bufsize = PAGE_SIZE - namelen - is_not_root;
54959+
54960+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
54961+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54962+ return 1;
54963+
54964+ preempt_disable();
54965+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54966+ bufsize);
54967+
54968+ bufsize = strlen(path);
54969+
54970+ /* if base is "/", don't append an additional slash */
54971+ if (is_not_root)
54972+ *(path + bufsize) = '/';
54973+ memcpy(path + bufsize + is_not_root, name, namelen);
54974+ *(path + bufsize + namelen + is_not_root) = '\0';
54975+
54976+ tmp = obj->globbed;
54977+ while (tmp) {
54978+ if (!glob_match(tmp->filename, path)) {
54979+ preempt_enable();
54980+ return (tmp->mode & GR_FIND) ? 1 : 0;
54981+ }
54982+ tmp = tmp->next;
54983+ }
54984+ preempt_enable();
54985+ return (obj->mode & GR_FIND) ? 1 : 0;
54986+}
54987+
54988+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54989+EXPORT_SYMBOL(gr_acl_is_enabled);
54990+#endif
54991+EXPORT_SYMBOL(gr_learn_resource);
54992+EXPORT_SYMBOL(gr_set_kernel_label);
54993+#ifdef CONFIG_SECURITY
54994+EXPORT_SYMBOL(gr_check_user_change);
54995+EXPORT_SYMBOL(gr_check_group_change);
54996+#endif
54997+
54998diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54999new file mode 100644
55000index 0000000..34fefda
55001--- /dev/null
55002+++ b/grsecurity/gracl_alloc.c
55003@@ -0,0 +1,105 @@
55004+#include <linux/kernel.h>
55005+#include <linux/mm.h>
55006+#include <linux/slab.h>
55007+#include <linux/vmalloc.h>
55008+#include <linux/gracl.h>
55009+#include <linux/grsecurity.h>
55010+
55011+static unsigned long alloc_stack_next = 1;
55012+static unsigned long alloc_stack_size = 1;
55013+static void **alloc_stack;
55014+
55015+static __inline__ int
55016+alloc_pop(void)
55017+{
55018+ if (alloc_stack_next == 1)
55019+ return 0;
55020+
55021+ kfree(alloc_stack[alloc_stack_next - 2]);
55022+
55023+ alloc_stack_next--;
55024+
55025+ return 1;
55026+}
55027+
55028+static __inline__ int
55029+alloc_push(void *buf)
55030+{
55031+ if (alloc_stack_next >= alloc_stack_size)
55032+ return 1;
55033+
55034+ alloc_stack[alloc_stack_next - 1] = buf;
55035+
55036+ alloc_stack_next++;
55037+
55038+ return 0;
55039+}
55040+
55041+void *
55042+acl_alloc(unsigned long len)
55043+{
55044+ void *ret = NULL;
55045+
55046+ if (!len || len > PAGE_SIZE)
55047+ goto out;
55048+
55049+ ret = kmalloc(len, GFP_KERNEL);
55050+
55051+ if (ret) {
55052+ if (alloc_push(ret)) {
55053+ kfree(ret);
55054+ ret = NULL;
55055+ }
55056+ }
55057+
55058+out:
55059+ return ret;
55060+}
55061+
55062+void *
55063+acl_alloc_num(unsigned long num, unsigned long len)
55064+{
55065+ if (!len || (num > (PAGE_SIZE / len)))
55066+ return NULL;
55067+
55068+ return acl_alloc(num * len);
55069+}
55070+
55071+void
55072+acl_free_all(void)
55073+{
55074+ if (gr_acl_is_enabled() || !alloc_stack)
55075+ return;
55076+
55077+ while (alloc_pop()) ;
55078+
55079+ if (alloc_stack) {
55080+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55081+ kfree(alloc_stack);
55082+ else
55083+ vfree(alloc_stack);
55084+ }
55085+
55086+ alloc_stack = NULL;
55087+ alloc_stack_size = 1;
55088+ alloc_stack_next = 1;
55089+
55090+ return;
55091+}
55092+
55093+int
55094+acl_alloc_stack_init(unsigned long size)
55095+{
55096+ if ((size * sizeof (void *)) <= PAGE_SIZE)
55097+ alloc_stack =
55098+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55099+ else
55100+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
55101+
55102+ alloc_stack_size = size;
55103+
55104+ if (!alloc_stack)
55105+ return 0;
55106+ else
55107+ return 1;
55108+}
55109diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55110new file mode 100644
55111index 0000000..6d21049
55112--- /dev/null
55113+++ b/grsecurity/gracl_cap.c
55114@@ -0,0 +1,110 @@
55115+#include <linux/kernel.h>
55116+#include <linux/module.h>
55117+#include <linux/sched.h>
55118+#include <linux/gracl.h>
55119+#include <linux/grsecurity.h>
55120+#include <linux/grinternal.h>
55121+
55122+extern const char *captab_log[];
55123+extern int captab_log_entries;
55124+
55125+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55126+{
55127+ struct acl_subject_label *curracl;
55128+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55129+ kernel_cap_t cap_audit = __cap_empty_set;
55130+
55131+ if (!gr_acl_is_enabled())
55132+ return 1;
55133+
55134+ curracl = task->acl;
55135+
55136+ cap_drop = curracl->cap_lower;
55137+ cap_mask = curracl->cap_mask;
55138+ cap_audit = curracl->cap_invert_audit;
55139+
55140+ while ((curracl = curracl->parent_subject)) {
55141+ /* if the cap isn't specified in the current computed mask but is specified in the
55142+ current level subject, and is lowered in the current level subject, then add
55143+ it to the set of dropped capabilities
55144+ otherwise, add the current level subject's mask to the current computed mask
55145+ */
55146+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55147+ cap_raise(cap_mask, cap);
55148+ if (cap_raised(curracl->cap_lower, cap))
55149+ cap_raise(cap_drop, cap);
55150+ if (cap_raised(curracl->cap_invert_audit, cap))
55151+ cap_raise(cap_audit, cap);
55152+ }
55153+ }
55154+
55155+ if (!cap_raised(cap_drop, cap)) {
55156+ if (cap_raised(cap_audit, cap))
55157+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55158+ return 1;
55159+ }
55160+
55161+ curracl = task->acl;
55162+
55163+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55164+ && cap_raised(cred->cap_effective, cap)) {
55165+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55166+ task->role->roletype, cred->uid,
55167+ cred->gid, task->exec_file ?
55168+ gr_to_filename(task->exec_file->f_path.dentry,
55169+ task->exec_file->f_path.mnt) : curracl->filename,
55170+ curracl->filename, 0UL,
55171+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55172+ return 1;
55173+ }
55174+
55175+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55176+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55177+
55178+ return 0;
55179+}
55180+
55181+int
55182+gr_acl_is_capable(const int cap)
55183+{
55184+ return gr_task_acl_is_capable(current, current_cred(), cap);
55185+}
55186+
55187+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55188+{
55189+ struct acl_subject_label *curracl;
55190+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55191+
55192+ if (!gr_acl_is_enabled())
55193+ return 1;
55194+
55195+ curracl = task->acl;
55196+
55197+ cap_drop = curracl->cap_lower;
55198+ cap_mask = curracl->cap_mask;
55199+
55200+ while ((curracl = curracl->parent_subject)) {
55201+ /* if the cap isn't specified in the current computed mask but is specified in the
55202+ current level subject, and is lowered in the current level subject, then add
55203+ it to the set of dropped capabilities
55204+ otherwise, add the current level subject's mask to the current computed mask
55205+ */
55206+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55207+ cap_raise(cap_mask, cap);
55208+ if (cap_raised(curracl->cap_lower, cap))
55209+ cap_raise(cap_drop, cap);
55210+ }
55211+ }
55212+
55213+ if (!cap_raised(cap_drop, cap))
55214+ return 1;
55215+
55216+ return 0;
55217+}
55218+
55219+int
55220+gr_acl_is_capable_nolog(const int cap)
55221+{
55222+ return gr_task_acl_is_capable_nolog(current, cap);
55223+}
55224+
55225diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55226new file mode 100644
55227index 0000000..88d0e87
55228--- /dev/null
55229+++ b/grsecurity/gracl_fs.c
55230@@ -0,0 +1,435 @@
55231+#include <linux/kernel.h>
55232+#include <linux/sched.h>
55233+#include <linux/types.h>
55234+#include <linux/fs.h>
55235+#include <linux/file.h>
55236+#include <linux/stat.h>
55237+#include <linux/grsecurity.h>
55238+#include <linux/grinternal.h>
55239+#include <linux/gracl.h>
55240+
55241+umode_t
55242+gr_acl_umask(void)
55243+{
55244+ if (unlikely(!gr_acl_is_enabled()))
55245+ return 0;
55246+
55247+ return current->role->umask;
55248+}
55249+
55250+__u32
55251+gr_acl_handle_hidden_file(const struct dentry * dentry,
55252+ const struct vfsmount * mnt)
55253+{
55254+ __u32 mode;
55255+
55256+ if (unlikely(!dentry->d_inode))
55257+ return GR_FIND;
55258+
55259+ mode =
55260+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55261+
55262+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55263+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55264+ return mode;
55265+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55266+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55267+ return 0;
55268+ } else if (unlikely(!(mode & GR_FIND)))
55269+ return 0;
55270+
55271+ return GR_FIND;
55272+}
55273+
55274+__u32
55275+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55276+ int acc_mode)
55277+{
55278+ __u32 reqmode = GR_FIND;
55279+ __u32 mode;
55280+
55281+ if (unlikely(!dentry->d_inode))
55282+ return reqmode;
55283+
55284+ if (acc_mode & MAY_APPEND)
55285+ reqmode |= GR_APPEND;
55286+ else if (acc_mode & MAY_WRITE)
55287+ reqmode |= GR_WRITE;
55288+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55289+ reqmode |= GR_READ;
55290+
55291+ mode =
55292+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55293+ mnt);
55294+
55295+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55296+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55297+ reqmode & GR_READ ? " reading" : "",
55298+ reqmode & GR_WRITE ? " writing" : reqmode &
55299+ GR_APPEND ? " appending" : "");
55300+ return reqmode;
55301+ } else
55302+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55303+ {
55304+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55305+ reqmode & GR_READ ? " reading" : "",
55306+ reqmode & GR_WRITE ? " writing" : reqmode &
55307+ GR_APPEND ? " appending" : "");
55308+ return 0;
55309+ } else if (unlikely((mode & reqmode) != reqmode))
55310+ return 0;
55311+
55312+ return reqmode;
55313+}
55314+
55315+__u32
55316+gr_acl_handle_creat(const struct dentry * dentry,
55317+ const struct dentry * p_dentry,
55318+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55319+ const int imode)
55320+{
55321+ __u32 reqmode = GR_WRITE | GR_CREATE;
55322+ __u32 mode;
55323+
55324+ if (acc_mode & MAY_APPEND)
55325+ reqmode |= GR_APPEND;
55326+ // if a directory was required or the directory already exists, then
55327+ // don't count this open as a read
55328+ if ((acc_mode & MAY_READ) &&
55329+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55330+ reqmode |= GR_READ;
55331+ if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
55332+ reqmode |= GR_SETID;
55333+
55334+ mode =
55335+ gr_check_create(dentry, p_dentry, p_mnt,
55336+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55337+
55338+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55339+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55340+ reqmode & GR_READ ? " reading" : "",
55341+ reqmode & GR_WRITE ? " writing" : reqmode &
55342+ GR_APPEND ? " appending" : "");
55343+ return reqmode;
55344+ } else
55345+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55346+ {
55347+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55348+ reqmode & GR_READ ? " reading" : "",
55349+ reqmode & GR_WRITE ? " writing" : reqmode &
55350+ GR_APPEND ? " appending" : "");
55351+ return 0;
55352+ } else if (unlikely((mode & reqmode) != reqmode))
55353+ return 0;
55354+
55355+ return reqmode;
55356+}
55357+
55358+__u32
55359+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55360+ const int fmode)
55361+{
55362+ __u32 mode, reqmode = GR_FIND;
55363+
55364+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55365+ reqmode |= GR_EXEC;
55366+ if (fmode & S_IWOTH)
55367+ reqmode |= GR_WRITE;
55368+ if (fmode & S_IROTH)
55369+ reqmode |= GR_READ;
55370+
55371+ mode =
55372+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55373+ mnt);
55374+
55375+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55376+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55377+ reqmode & GR_READ ? " reading" : "",
55378+ reqmode & GR_WRITE ? " writing" : "",
55379+ reqmode & GR_EXEC ? " executing" : "");
55380+ return reqmode;
55381+ } else
55382+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55383+ {
55384+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55385+ reqmode & GR_READ ? " reading" : "",
55386+ reqmode & GR_WRITE ? " writing" : "",
55387+ reqmode & GR_EXEC ? " executing" : "");
55388+ return 0;
55389+ } else if (unlikely((mode & reqmode) != reqmode))
55390+ return 0;
55391+
55392+ return reqmode;
55393+}
55394+
55395+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55396+{
55397+ __u32 mode;
55398+
55399+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55400+
55401+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55402+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55403+ return mode;
55404+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55405+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55406+ return 0;
55407+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55408+ return 0;
55409+
55410+ return (reqmode);
55411+}
55412+
55413+__u32
55414+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55415+{
55416+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55417+}
55418+
55419+__u32
55420+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55421+{
55422+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55423+}
55424+
55425+__u32
55426+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55427+{
55428+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55429+}
55430+
55431+__u32
55432+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55433+{
55434+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55435+}
55436+
55437+__u32
55438+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55439+ umode_t *modeptr)
55440+{
55441+ umode_t mode;
55442+
55443+ *modeptr &= ~gr_acl_umask();
55444+ mode = *modeptr;
55445+
55446+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55447+ return 1;
55448+
55449+ if (unlikely(mode & (S_ISUID | S_ISGID))) {
55450+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55451+ GR_CHMOD_ACL_MSG);
55452+ } else {
55453+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55454+ }
55455+}
55456+
55457+__u32
55458+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55459+{
55460+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55461+}
55462+
55463+__u32
55464+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55465+{
55466+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55467+}
55468+
55469+__u32
55470+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55471+{
55472+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55473+}
55474+
55475+__u32
55476+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55477+{
55478+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55479+ GR_UNIXCONNECT_ACL_MSG);
55480+}
55481+
55482+/* hardlinks require at minimum create and link permission,
55483+ any additional privilege required is based on the
55484+ privilege of the file being linked to
55485+*/
55486+__u32
55487+gr_acl_handle_link(const struct dentry * new_dentry,
55488+ const struct dentry * parent_dentry,
55489+ const struct vfsmount * parent_mnt,
55490+ const struct dentry * old_dentry,
55491+ const struct vfsmount * old_mnt, const char *to)
55492+{
55493+ __u32 mode;
55494+ __u32 needmode = GR_CREATE | GR_LINK;
55495+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55496+
55497+ mode =
55498+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55499+ old_mnt);
55500+
55501+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55502+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55503+ return mode;
55504+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55505+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55506+ return 0;
55507+ } else if (unlikely((mode & needmode) != needmode))
55508+ return 0;
55509+
55510+ return 1;
55511+}
55512+
55513+__u32
55514+gr_acl_handle_symlink(const struct dentry * new_dentry,
55515+ const struct dentry * parent_dentry,
55516+ const struct vfsmount * parent_mnt, const char *from)
55517+{
55518+ __u32 needmode = GR_WRITE | GR_CREATE;
55519+ __u32 mode;
55520+
55521+ mode =
55522+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
55523+ GR_CREATE | GR_AUDIT_CREATE |
55524+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55525+
55526+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55527+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55528+ return mode;
55529+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55530+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55531+ return 0;
55532+ } else if (unlikely((mode & needmode) != needmode))
55533+ return 0;
55534+
55535+ return (GR_WRITE | GR_CREATE);
55536+}
55537+
55538+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)
55539+{
55540+ __u32 mode;
55541+
55542+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55543+
55544+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55545+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55546+ return mode;
55547+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55548+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55549+ return 0;
55550+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55551+ return 0;
55552+
55553+ return (reqmode);
55554+}
55555+
55556+__u32
55557+gr_acl_handle_mknod(const struct dentry * new_dentry,
55558+ const struct dentry * parent_dentry,
55559+ const struct vfsmount * parent_mnt,
55560+ const int mode)
55561+{
55562+ __u32 reqmode = GR_WRITE | GR_CREATE;
55563+ if (unlikely(mode & (S_ISUID | S_ISGID)))
55564+ reqmode |= GR_SETID;
55565+
55566+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55567+ reqmode, GR_MKNOD_ACL_MSG);
55568+}
55569+
55570+__u32
55571+gr_acl_handle_mkdir(const struct dentry *new_dentry,
55572+ const struct dentry *parent_dentry,
55573+ const struct vfsmount *parent_mnt)
55574+{
55575+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55576+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55577+}
55578+
55579+#define RENAME_CHECK_SUCCESS(old, new) \
55580+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55581+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55582+
55583+int
55584+gr_acl_handle_rename(struct dentry *new_dentry,
55585+ struct dentry *parent_dentry,
55586+ const struct vfsmount *parent_mnt,
55587+ struct dentry *old_dentry,
55588+ struct inode *old_parent_inode,
55589+ struct vfsmount *old_mnt, const char *newname)
55590+{
55591+ __u32 comp1, comp2;
55592+ int error = 0;
55593+
55594+ if (unlikely(!gr_acl_is_enabled()))
55595+ return 0;
55596+
55597+ if (!new_dentry->d_inode) {
55598+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55599+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55600+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55601+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55602+ GR_DELETE | GR_AUDIT_DELETE |
55603+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55604+ GR_SUPPRESS, old_mnt);
55605+ } else {
55606+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55607+ GR_CREATE | GR_DELETE |
55608+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55609+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55610+ GR_SUPPRESS, parent_mnt);
55611+ comp2 =
55612+ gr_search_file(old_dentry,
55613+ GR_READ | GR_WRITE | GR_AUDIT_READ |
55614+ GR_DELETE | GR_AUDIT_DELETE |
55615+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55616+ }
55617+
55618+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55619+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55620+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55621+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55622+ && !(comp2 & GR_SUPPRESS)) {
55623+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55624+ error = -EACCES;
55625+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55626+ error = -EACCES;
55627+
55628+ return error;
55629+}
55630+
55631+void
55632+gr_acl_handle_exit(void)
55633+{
55634+ u16 id;
55635+ char *rolename;
55636+ struct file *exec_file;
55637+
55638+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55639+ !(current->role->roletype & GR_ROLE_PERSIST))) {
55640+ id = current->acl_role_id;
55641+ rolename = current->role->rolename;
55642+ gr_set_acls(1);
55643+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55644+ }
55645+
55646+ write_lock(&grsec_exec_file_lock);
55647+ exec_file = current->exec_file;
55648+ current->exec_file = NULL;
55649+ write_unlock(&grsec_exec_file_lock);
55650+
55651+ if (exec_file)
55652+ fput(exec_file);
55653+}
55654+
55655+int
55656+gr_acl_handle_procpidmem(const struct task_struct *task)
55657+{
55658+ if (unlikely(!gr_acl_is_enabled()))
55659+ return 0;
55660+
55661+ if (task != current && task->acl->mode & GR_PROTPROCFD)
55662+ return -EACCES;
55663+
55664+ return 0;
55665+}
55666diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55667new file mode 100644
55668index 0000000..58800a7
55669--- /dev/null
55670+++ b/grsecurity/gracl_ip.c
55671@@ -0,0 +1,384 @@
55672+#include <linux/kernel.h>
55673+#include <asm/uaccess.h>
55674+#include <asm/errno.h>
55675+#include <net/sock.h>
55676+#include <linux/file.h>
55677+#include <linux/fs.h>
55678+#include <linux/net.h>
55679+#include <linux/in.h>
55680+#include <linux/skbuff.h>
55681+#include <linux/ip.h>
55682+#include <linux/udp.h>
55683+#include <linux/types.h>
55684+#include <linux/sched.h>
55685+#include <linux/netdevice.h>
55686+#include <linux/inetdevice.h>
55687+#include <linux/gracl.h>
55688+#include <linux/grsecurity.h>
55689+#include <linux/grinternal.h>
55690+
55691+#define GR_BIND 0x01
55692+#define GR_CONNECT 0x02
55693+#define GR_INVERT 0x04
55694+#define GR_BINDOVERRIDE 0x08
55695+#define GR_CONNECTOVERRIDE 0x10
55696+#define GR_SOCK_FAMILY 0x20
55697+
55698+static const char * gr_protocols[IPPROTO_MAX] = {
55699+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55700+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55701+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55702+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55703+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55704+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55705+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55706+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55707+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55708+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55709+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55710+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55711+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55712+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55713+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55714+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55715+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55716+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55717+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55718+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55719+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55720+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55721+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55722+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55723+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55724+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55725+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55726+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55727+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55728+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55729+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55730+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55731+ };
55732+
55733+static const char * gr_socktypes[SOCK_MAX] = {
55734+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55735+ "unknown:7", "unknown:8", "unknown:9", "packet"
55736+ };
55737+
55738+static const char * gr_sockfamilies[AF_MAX+1] = {
55739+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55740+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55741+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55742+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55743+ };
55744+
55745+const char *
55746+gr_proto_to_name(unsigned char proto)
55747+{
55748+ return gr_protocols[proto];
55749+}
55750+
55751+const char *
55752+gr_socktype_to_name(unsigned char type)
55753+{
55754+ return gr_socktypes[type];
55755+}
55756+
55757+const char *
55758+gr_sockfamily_to_name(unsigned char family)
55759+{
55760+ return gr_sockfamilies[family];
55761+}
55762+
55763+int
55764+gr_search_socket(const int domain, const int type, const int protocol)
55765+{
55766+ struct acl_subject_label *curr;
55767+ const struct cred *cred = current_cred();
55768+
55769+ if (unlikely(!gr_acl_is_enabled()))
55770+ goto exit;
55771+
55772+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
55773+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55774+ goto exit; // let the kernel handle it
55775+
55776+ curr = current->acl;
55777+
55778+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55779+ /* the family is allowed, if this is PF_INET allow it only if
55780+ the extra sock type/protocol checks pass */
55781+ if (domain == PF_INET)
55782+ goto inet_check;
55783+ goto exit;
55784+ } else {
55785+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55786+ __u32 fakeip = 0;
55787+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55788+ current->role->roletype, cred->uid,
55789+ cred->gid, current->exec_file ?
55790+ gr_to_filename(current->exec_file->f_path.dentry,
55791+ current->exec_file->f_path.mnt) :
55792+ curr->filename, curr->filename,
55793+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55794+ &current->signal->saved_ip);
55795+ goto exit;
55796+ }
55797+ goto exit_fail;
55798+ }
55799+
55800+inet_check:
55801+ /* the rest of this checking is for IPv4 only */
55802+ if (!curr->ips)
55803+ goto exit;
55804+
55805+ if ((curr->ip_type & (1 << type)) &&
55806+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55807+ goto exit;
55808+
55809+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55810+ /* we don't place acls on raw sockets , and sometimes
55811+ dgram/ip sockets are opened for ioctl and not
55812+ bind/connect, so we'll fake a bind learn log */
55813+ if (type == SOCK_RAW || type == SOCK_PACKET) {
55814+ __u32 fakeip = 0;
55815+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55816+ current->role->roletype, cred->uid,
55817+ cred->gid, current->exec_file ?
55818+ gr_to_filename(current->exec_file->f_path.dentry,
55819+ current->exec_file->f_path.mnt) :
55820+ curr->filename, curr->filename,
55821+ &fakeip, 0, type,
55822+ protocol, GR_CONNECT, &current->signal->saved_ip);
55823+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55824+ __u32 fakeip = 0;
55825+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55826+ current->role->roletype, cred->uid,
55827+ cred->gid, current->exec_file ?
55828+ gr_to_filename(current->exec_file->f_path.dentry,
55829+ current->exec_file->f_path.mnt) :
55830+ curr->filename, curr->filename,
55831+ &fakeip, 0, type,
55832+ protocol, GR_BIND, &current->signal->saved_ip);
55833+ }
55834+ /* we'll log when they use connect or bind */
55835+ goto exit;
55836+ }
55837+
55838+exit_fail:
55839+ if (domain == PF_INET)
55840+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55841+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
55842+ else
55843+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55844+ gr_socktype_to_name(type), protocol);
55845+
55846+ return 0;
55847+exit:
55848+ return 1;
55849+}
55850+
55851+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)
55852+{
55853+ if ((ip->mode & mode) &&
55854+ (ip_port >= ip->low) &&
55855+ (ip_port <= ip->high) &&
55856+ ((ntohl(ip_addr) & our_netmask) ==
55857+ (ntohl(our_addr) & our_netmask))
55858+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55859+ && (ip->type & (1 << type))) {
55860+ if (ip->mode & GR_INVERT)
55861+ return 2; // specifically denied
55862+ else
55863+ return 1; // allowed
55864+ }
55865+
55866+ return 0; // not specifically allowed, may continue parsing
55867+}
55868+
55869+static int
55870+gr_search_connectbind(const int full_mode, struct sock *sk,
55871+ struct sockaddr_in *addr, const int type)
55872+{
55873+ char iface[IFNAMSIZ] = {0};
55874+ struct acl_subject_label *curr;
55875+ struct acl_ip_label *ip;
55876+ struct inet_sock *isk;
55877+ struct net_device *dev;
55878+ struct in_device *idev;
55879+ unsigned long i;
55880+ int ret;
55881+ int mode = full_mode & (GR_BIND | GR_CONNECT);
55882+ __u32 ip_addr = 0;
55883+ __u32 our_addr;
55884+ __u32 our_netmask;
55885+ char *p;
55886+ __u16 ip_port = 0;
55887+ const struct cred *cred = current_cred();
55888+
55889+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55890+ return 0;
55891+
55892+ curr = current->acl;
55893+ isk = inet_sk(sk);
55894+
55895+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55896+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55897+ addr->sin_addr.s_addr = curr->inaddr_any_override;
55898+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55899+ struct sockaddr_in saddr;
55900+ int err;
55901+
55902+ saddr.sin_family = AF_INET;
55903+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
55904+ saddr.sin_port = isk->inet_sport;
55905+
55906+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55907+ if (err)
55908+ return err;
55909+
55910+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55911+ if (err)
55912+ return err;
55913+ }
55914+
55915+ if (!curr->ips)
55916+ return 0;
55917+
55918+ ip_addr = addr->sin_addr.s_addr;
55919+ ip_port = ntohs(addr->sin_port);
55920+
55921+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55922+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55923+ current->role->roletype, cred->uid,
55924+ cred->gid, current->exec_file ?
55925+ gr_to_filename(current->exec_file->f_path.dentry,
55926+ current->exec_file->f_path.mnt) :
55927+ curr->filename, curr->filename,
55928+ &ip_addr, ip_port, type,
55929+ sk->sk_protocol, mode, &current->signal->saved_ip);
55930+ return 0;
55931+ }
55932+
55933+ for (i = 0; i < curr->ip_num; i++) {
55934+ ip = *(curr->ips + i);
55935+ if (ip->iface != NULL) {
55936+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
55937+ p = strchr(iface, ':');
55938+ if (p != NULL)
55939+ *p = '\0';
55940+ dev = dev_get_by_name(sock_net(sk), iface);
55941+ if (dev == NULL)
55942+ continue;
55943+ idev = in_dev_get(dev);
55944+ if (idev == NULL) {
55945+ dev_put(dev);
55946+ continue;
55947+ }
55948+ rcu_read_lock();
55949+ for_ifa(idev) {
55950+ if (!strcmp(ip->iface, ifa->ifa_label)) {
55951+ our_addr = ifa->ifa_address;
55952+ our_netmask = 0xffffffff;
55953+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55954+ if (ret == 1) {
55955+ rcu_read_unlock();
55956+ in_dev_put(idev);
55957+ dev_put(dev);
55958+ return 0;
55959+ } else if (ret == 2) {
55960+ rcu_read_unlock();
55961+ in_dev_put(idev);
55962+ dev_put(dev);
55963+ goto denied;
55964+ }
55965+ }
55966+ } endfor_ifa(idev);
55967+ rcu_read_unlock();
55968+ in_dev_put(idev);
55969+ dev_put(dev);
55970+ } else {
55971+ our_addr = ip->addr;
55972+ our_netmask = ip->netmask;
55973+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55974+ if (ret == 1)
55975+ return 0;
55976+ else if (ret == 2)
55977+ goto denied;
55978+ }
55979+ }
55980+
55981+denied:
55982+ if (mode == GR_BIND)
55983+ 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));
55984+ else if (mode == GR_CONNECT)
55985+ 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));
55986+
55987+ return -EACCES;
55988+}
55989+
55990+int
55991+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55992+{
55993+ /* always allow disconnection of dgram sockets with connect */
55994+ if (addr->sin_family == AF_UNSPEC)
55995+ return 0;
55996+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55997+}
55998+
55999+int
56000+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56001+{
56002+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56003+}
56004+
56005+int gr_search_listen(struct socket *sock)
56006+{
56007+ struct sock *sk = sock->sk;
56008+ struct sockaddr_in addr;
56009+
56010+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56011+ addr.sin_port = inet_sk(sk)->inet_sport;
56012+
56013+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56014+}
56015+
56016+int gr_search_accept(struct socket *sock)
56017+{
56018+ struct sock *sk = sock->sk;
56019+ struct sockaddr_in addr;
56020+
56021+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56022+ addr.sin_port = inet_sk(sk)->inet_sport;
56023+
56024+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56025+}
56026+
56027+int
56028+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56029+{
56030+ if (addr)
56031+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56032+ else {
56033+ struct sockaddr_in sin;
56034+ const struct inet_sock *inet = inet_sk(sk);
56035+
56036+ sin.sin_addr.s_addr = inet->inet_daddr;
56037+ sin.sin_port = inet->inet_dport;
56038+
56039+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56040+ }
56041+}
56042+
56043+int
56044+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56045+{
56046+ struct sockaddr_in sin;
56047+
56048+ if (unlikely(skb->len < sizeof (struct udphdr)))
56049+ return 0; // skip this packet
56050+
56051+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56052+ sin.sin_port = udp_hdr(skb)->source;
56053+
56054+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56055+}
56056diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56057new file mode 100644
56058index 0000000..25f54ef
56059--- /dev/null
56060+++ b/grsecurity/gracl_learn.c
56061@@ -0,0 +1,207 @@
56062+#include <linux/kernel.h>
56063+#include <linux/mm.h>
56064+#include <linux/sched.h>
56065+#include <linux/poll.h>
56066+#include <linux/string.h>
56067+#include <linux/file.h>
56068+#include <linux/types.h>
56069+#include <linux/vmalloc.h>
56070+#include <linux/grinternal.h>
56071+
56072+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56073+ size_t count, loff_t *ppos);
56074+extern int gr_acl_is_enabled(void);
56075+
56076+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56077+static int gr_learn_attached;
56078+
56079+/* use a 512k buffer */
56080+#define LEARN_BUFFER_SIZE (512 * 1024)
56081+
56082+static DEFINE_SPINLOCK(gr_learn_lock);
56083+static DEFINE_MUTEX(gr_learn_user_mutex);
56084+
56085+/* we need to maintain two buffers, so that the kernel context of grlearn
56086+ uses a semaphore around the userspace copying, and the other kernel contexts
56087+ use a spinlock when copying into the buffer, since they cannot sleep
56088+*/
56089+static char *learn_buffer;
56090+static char *learn_buffer_user;
56091+static int learn_buffer_len;
56092+static int learn_buffer_user_len;
56093+
56094+static ssize_t
56095+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56096+{
56097+ DECLARE_WAITQUEUE(wait, current);
56098+ ssize_t retval = 0;
56099+
56100+ add_wait_queue(&learn_wait, &wait);
56101+ set_current_state(TASK_INTERRUPTIBLE);
56102+ do {
56103+ mutex_lock(&gr_learn_user_mutex);
56104+ spin_lock(&gr_learn_lock);
56105+ if (learn_buffer_len)
56106+ break;
56107+ spin_unlock(&gr_learn_lock);
56108+ mutex_unlock(&gr_learn_user_mutex);
56109+ if (file->f_flags & O_NONBLOCK) {
56110+ retval = -EAGAIN;
56111+ goto out;
56112+ }
56113+ if (signal_pending(current)) {
56114+ retval = -ERESTARTSYS;
56115+ goto out;
56116+ }
56117+
56118+ schedule();
56119+ } while (1);
56120+
56121+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56122+ learn_buffer_user_len = learn_buffer_len;
56123+ retval = learn_buffer_len;
56124+ learn_buffer_len = 0;
56125+
56126+ spin_unlock(&gr_learn_lock);
56127+
56128+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56129+ retval = -EFAULT;
56130+
56131+ mutex_unlock(&gr_learn_user_mutex);
56132+out:
56133+ set_current_state(TASK_RUNNING);
56134+ remove_wait_queue(&learn_wait, &wait);
56135+ return retval;
56136+}
56137+
56138+static unsigned int
56139+poll_learn(struct file * file, poll_table * wait)
56140+{
56141+ poll_wait(file, &learn_wait, wait);
56142+
56143+ if (learn_buffer_len)
56144+ return (POLLIN | POLLRDNORM);
56145+
56146+ return 0;
56147+}
56148+
56149+void
56150+gr_clear_learn_entries(void)
56151+{
56152+ char *tmp;
56153+
56154+ mutex_lock(&gr_learn_user_mutex);
56155+ spin_lock(&gr_learn_lock);
56156+ tmp = learn_buffer;
56157+ learn_buffer = NULL;
56158+ spin_unlock(&gr_learn_lock);
56159+ if (tmp)
56160+ vfree(tmp);
56161+ if (learn_buffer_user != NULL) {
56162+ vfree(learn_buffer_user);
56163+ learn_buffer_user = NULL;
56164+ }
56165+ learn_buffer_len = 0;
56166+ mutex_unlock(&gr_learn_user_mutex);
56167+
56168+ return;
56169+}
56170+
56171+void
56172+gr_add_learn_entry(const char *fmt, ...)
56173+{
56174+ va_list args;
56175+ unsigned int len;
56176+
56177+ if (!gr_learn_attached)
56178+ return;
56179+
56180+ spin_lock(&gr_learn_lock);
56181+
56182+ /* leave a gap at the end so we know when it's "full" but don't have to
56183+ compute the exact length of the string we're trying to append
56184+ */
56185+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56186+ spin_unlock(&gr_learn_lock);
56187+ wake_up_interruptible(&learn_wait);
56188+ return;
56189+ }
56190+ if (learn_buffer == NULL) {
56191+ spin_unlock(&gr_learn_lock);
56192+ return;
56193+ }
56194+
56195+ va_start(args, fmt);
56196+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56197+ va_end(args);
56198+
56199+ learn_buffer_len += len + 1;
56200+
56201+ spin_unlock(&gr_learn_lock);
56202+ wake_up_interruptible(&learn_wait);
56203+
56204+ return;
56205+}
56206+
56207+static int
56208+open_learn(struct inode *inode, struct file *file)
56209+{
56210+ if (file->f_mode & FMODE_READ && gr_learn_attached)
56211+ return -EBUSY;
56212+ if (file->f_mode & FMODE_READ) {
56213+ int retval = 0;
56214+ mutex_lock(&gr_learn_user_mutex);
56215+ if (learn_buffer == NULL)
56216+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56217+ if (learn_buffer_user == NULL)
56218+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56219+ if (learn_buffer == NULL) {
56220+ retval = -ENOMEM;
56221+ goto out_error;
56222+ }
56223+ if (learn_buffer_user == NULL) {
56224+ retval = -ENOMEM;
56225+ goto out_error;
56226+ }
56227+ learn_buffer_len = 0;
56228+ learn_buffer_user_len = 0;
56229+ gr_learn_attached = 1;
56230+out_error:
56231+ mutex_unlock(&gr_learn_user_mutex);
56232+ return retval;
56233+ }
56234+ return 0;
56235+}
56236+
56237+static int
56238+close_learn(struct inode *inode, struct file *file)
56239+{
56240+ if (file->f_mode & FMODE_READ) {
56241+ char *tmp = NULL;
56242+ mutex_lock(&gr_learn_user_mutex);
56243+ spin_lock(&gr_learn_lock);
56244+ tmp = learn_buffer;
56245+ learn_buffer = NULL;
56246+ spin_unlock(&gr_learn_lock);
56247+ if (tmp)
56248+ vfree(tmp);
56249+ if (learn_buffer_user != NULL) {
56250+ vfree(learn_buffer_user);
56251+ learn_buffer_user = NULL;
56252+ }
56253+ learn_buffer_len = 0;
56254+ learn_buffer_user_len = 0;
56255+ gr_learn_attached = 0;
56256+ mutex_unlock(&gr_learn_user_mutex);
56257+ }
56258+
56259+ return 0;
56260+}
56261+
56262+const struct file_operations grsec_fops = {
56263+ .read = read_learn,
56264+ .write = write_grsec_handler,
56265+ .open = open_learn,
56266+ .release = close_learn,
56267+ .poll = poll_learn,
56268+};
56269diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56270new file mode 100644
56271index 0000000..39645c9
56272--- /dev/null
56273+++ b/grsecurity/gracl_res.c
56274@@ -0,0 +1,68 @@
56275+#include <linux/kernel.h>
56276+#include <linux/sched.h>
56277+#include <linux/gracl.h>
56278+#include <linux/grinternal.h>
56279+
56280+static const char *restab_log[] = {
56281+ [RLIMIT_CPU] = "RLIMIT_CPU",
56282+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56283+ [RLIMIT_DATA] = "RLIMIT_DATA",
56284+ [RLIMIT_STACK] = "RLIMIT_STACK",
56285+ [RLIMIT_CORE] = "RLIMIT_CORE",
56286+ [RLIMIT_RSS] = "RLIMIT_RSS",
56287+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
56288+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56289+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56290+ [RLIMIT_AS] = "RLIMIT_AS",
56291+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56292+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56293+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56294+ [RLIMIT_NICE] = "RLIMIT_NICE",
56295+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56296+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56297+ [GR_CRASH_RES] = "RLIMIT_CRASH"
56298+};
56299+
56300+void
56301+gr_log_resource(const struct task_struct *task,
56302+ const int res, const unsigned long wanted, const int gt)
56303+{
56304+ const struct cred *cred;
56305+ unsigned long rlim;
56306+
56307+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
56308+ return;
56309+
56310+ // not yet supported resource
56311+ if (unlikely(!restab_log[res]))
56312+ return;
56313+
56314+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56315+ rlim = task_rlimit_max(task, res);
56316+ else
56317+ rlim = task_rlimit(task, res);
56318+
56319+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56320+ return;
56321+
56322+ rcu_read_lock();
56323+ cred = __task_cred(task);
56324+
56325+ if (res == RLIMIT_NPROC &&
56326+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56327+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56328+ goto out_rcu_unlock;
56329+ else if (res == RLIMIT_MEMLOCK &&
56330+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56331+ goto out_rcu_unlock;
56332+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56333+ goto out_rcu_unlock;
56334+ rcu_read_unlock();
56335+
56336+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56337+
56338+ return;
56339+out_rcu_unlock:
56340+ rcu_read_unlock();
56341+ return;
56342+}
56343diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56344new file mode 100644
56345index 0000000..25197e9
56346--- /dev/null
56347+++ b/grsecurity/gracl_segv.c
56348@@ -0,0 +1,299 @@
56349+#include <linux/kernel.h>
56350+#include <linux/mm.h>
56351+#include <asm/uaccess.h>
56352+#include <asm/errno.h>
56353+#include <asm/mman.h>
56354+#include <net/sock.h>
56355+#include <linux/file.h>
56356+#include <linux/fs.h>
56357+#include <linux/net.h>
56358+#include <linux/in.h>
56359+#include <linux/slab.h>
56360+#include <linux/types.h>
56361+#include <linux/sched.h>
56362+#include <linux/timer.h>
56363+#include <linux/gracl.h>
56364+#include <linux/grsecurity.h>
56365+#include <linux/grinternal.h>
56366+
56367+static struct crash_uid *uid_set;
56368+static unsigned short uid_used;
56369+static DEFINE_SPINLOCK(gr_uid_lock);
56370+extern rwlock_t gr_inode_lock;
56371+extern struct acl_subject_label *
56372+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56373+ struct acl_role_label *role);
56374+
56375+#ifdef CONFIG_BTRFS_FS
56376+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56377+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56378+#endif
56379+
56380+static inline dev_t __get_dev(const struct dentry *dentry)
56381+{
56382+#ifdef CONFIG_BTRFS_FS
56383+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56384+ return get_btrfs_dev_from_inode(dentry->d_inode);
56385+ else
56386+#endif
56387+ return dentry->d_inode->i_sb->s_dev;
56388+}
56389+
56390+int
56391+gr_init_uidset(void)
56392+{
56393+ uid_set =
56394+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56395+ uid_used = 0;
56396+
56397+ return uid_set ? 1 : 0;
56398+}
56399+
56400+void
56401+gr_free_uidset(void)
56402+{
56403+ if (uid_set)
56404+ kfree(uid_set);
56405+
56406+ return;
56407+}
56408+
56409+int
56410+gr_find_uid(const uid_t uid)
56411+{
56412+ struct crash_uid *tmp = uid_set;
56413+ uid_t buid;
56414+ int low = 0, high = uid_used - 1, mid;
56415+
56416+ while (high >= low) {
56417+ mid = (low + high) >> 1;
56418+ buid = tmp[mid].uid;
56419+ if (buid == uid)
56420+ return mid;
56421+ if (buid > uid)
56422+ high = mid - 1;
56423+ if (buid < uid)
56424+ low = mid + 1;
56425+ }
56426+
56427+ return -1;
56428+}
56429+
56430+static __inline__ void
56431+gr_insertsort(void)
56432+{
56433+ unsigned short i, j;
56434+ struct crash_uid index;
56435+
56436+ for (i = 1; i < uid_used; i++) {
56437+ index = uid_set[i];
56438+ j = i;
56439+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56440+ uid_set[j] = uid_set[j - 1];
56441+ j--;
56442+ }
56443+ uid_set[j] = index;
56444+ }
56445+
56446+ return;
56447+}
56448+
56449+static __inline__ void
56450+gr_insert_uid(const uid_t uid, const unsigned long expires)
56451+{
56452+ int loc;
56453+
56454+ if (uid_used == GR_UIDTABLE_MAX)
56455+ return;
56456+
56457+ loc = gr_find_uid(uid);
56458+
56459+ if (loc >= 0) {
56460+ uid_set[loc].expires = expires;
56461+ return;
56462+ }
56463+
56464+ uid_set[uid_used].uid = uid;
56465+ uid_set[uid_used].expires = expires;
56466+ uid_used++;
56467+
56468+ gr_insertsort();
56469+
56470+ return;
56471+}
56472+
56473+void
56474+gr_remove_uid(const unsigned short loc)
56475+{
56476+ unsigned short i;
56477+
56478+ for (i = loc + 1; i < uid_used; i++)
56479+ uid_set[i - 1] = uid_set[i];
56480+
56481+ uid_used--;
56482+
56483+ return;
56484+}
56485+
56486+int
56487+gr_check_crash_uid(const uid_t uid)
56488+{
56489+ int loc;
56490+ int ret = 0;
56491+
56492+ if (unlikely(!gr_acl_is_enabled()))
56493+ return 0;
56494+
56495+ spin_lock(&gr_uid_lock);
56496+ loc = gr_find_uid(uid);
56497+
56498+ if (loc < 0)
56499+ goto out_unlock;
56500+
56501+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
56502+ gr_remove_uid(loc);
56503+ else
56504+ ret = 1;
56505+
56506+out_unlock:
56507+ spin_unlock(&gr_uid_lock);
56508+ return ret;
56509+}
56510+
56511+static __inline__ int
56512+proc_is_setxid(const struct cred *cred)
56513+{
56514+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
56515+ !uid_eq(cred->uid, cred->fsuid))
56516+ return 1;
56517+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
56518+ !uid_eq(cred->gid, cred->fsgid))
56519+ return 1;
56520+
56521+ return 0;
56522+}
56523+
56524+extern int gr_fake_force_sig(int sig, struct task_struct *t);
56525+
56526+void
56527+gr_handle_crash(struct task_struct *task, const int sig)
56528+{
56529+ struct acl_subject_label *curr;
56530+ struct task_struct *tsk, *tsk2;
56531+ const struct cred *cred;
56532+ const struct cred *cred2;
56533+
56534+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56535+ return;
56536+
56537+ if (unlikely(!gr_acl_is_enabled()))
56538+ return;
56539+
56540+ curr = task->acl;
56541+
56542+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
56543+ return;
56544+
56545+ if (time_before_eq(curr->expires, get_seconds())) {
56546+ curr->expires = 0;
56547+ curr->crashes = 0;
56548+ }
56549+
56550+ curr->crashes++;
56551+
56552+ if (!curr->expires)
56553+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56554+
56555+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56556+ time_after(curr->expires, get_seconds())) {
56557+ rcu_read_lock();
56558+ cred = __task_cred(task);
56559+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
56560+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56561+ spin_lock(&gr_uid_lock);
56562+ gr_insert_uid(cred->uid, curr->expires);
56563+ spin_unlock(&gr_uid_lock);
56564+ curr->expires = 0;
56565+ curr->crashes = 0;
56566+ read_lock(&tasklist_lock);
56567+ do_each_thread(tsk2, tsk) {
56568+ cred2 = __task_cred(tsk);
56569+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
56570+ gr_fake_force_sig(SIGKILL, tsk);
56571+ } while_each_thread(tsk2, tsk);
56572+ read_unlock(&tasklist_lock);
56573+ } else {
56574+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56575+ read_lock(&tasklist_lock);
56576+ read_lock(&grsec_exec_file_lock);
56577+ do_each_thread(tsk2, tsk) {
56578+ if (likely(tsk != task)) {
56579+ // if this thread has the same subject as the one that triggered
56580+ // RES_CRASH and it's the same binary, kill it
56581+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56582+ gr_fake_force_sig(SIGKILL, tsk);
56583+ }
56584+ } while_each_thread(tsk2, tsk);
56585+ read_unlock(&grsec_exec_file_lock);
56586+ read_unlock(&tasklist_lock);
56587+ }
56588+ rcu_read_unlock();
56589+ }
56590+
56591+ return;
56592+}
56593+
56594+int
56595+gr_check_crash_exec(const struct file *filp)
56596+{
56597+ struct acl_subject_label *curr;
56598+
56599+ if (unlikely(!gr_acl_is_enabled()))
56600+ return 0;
56601+
56602+ read_lock(&gr_inode_lock);
56603+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56604+ __get_dev(filp->f_path.dentry),
56605+ current->role);
56606+ read_unlock(&gr_inode_lock);
56607+
56608+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56609+ (!curr->crashes && !curr->expires))
56610+ return 0;
56611+
56612+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56613+ time_after(curr->expires, get_seconds()))
56614+ return 1;
56615+ else if (time_before_eq(curr->expires, get_seconds())) {
56616+ curr->crashes = 0;
56617+ curr->expires = 0;
56618+ }
56619+
56620+ return 0;
56621+}
56622+
56623+void
56624+gr_handle_alertkill(struct task_struct *task)
56625+{
56626+ struct acl_subject_label *curracl;
56627+ __u32 curr_ip;
56628+ struct task_struct *p, *p2;
56629+
56630+ if (unlikely(!gr_acl_is_enabled()))
56631+ return;
56632+
56633+ curracl = task->acl;
56634+ curr_ip = task->signal->curr_ip;
56635+
56636+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56637+ read_lock(&tasklist_lock);
56638+ do_each_thread(p2, p) {
56639+ if (p->signal->curr_ip == curr_ip)
56640+ gr_fake_force_sig(SIGKILL, p);
56641+ } while_each_thread(p2, p);
56642+ read_unlock(&tasklist_lock);
56643+ } else if (curracl->mode & GR_KILLPROC)
56644+ gr_fake_force_sig(SIGKILL, task);
56645+
56646+ return;
56647+}
56648diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56649new file mode 100644
56650index 0000000..9d83a69
56651--- /dev/null
56652+++ b/grsecurity/gracl_shm.c
56653@@ -0,0 +1,40 @@
56654+#include <linux/kernel.h>
56655+#include <linux/mm.h>
56656+#include <linux/sched.h>
56657+#include <linux/file.h>
56658+#include <linux/ipc.h>
56659+#include <linux/gracl.h>
56660+#include <linux/grsecurity.h>
56661+#include <linux/grinternal.h>
56662+
56663+int
56664+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56665+ const time_t shm_createtime, const uid_t cuid, const int shmid)
56666+{
56667+ struct task_struct *task;
56668+
56669+ if (!gr_acl_is_enabled())
56670+ return 1;
56671+
56672+ rcu_read_lock();
56673+ read_lock(&tasklist_lock);
56674+
56675+ task = find_task_by_vpid(shm_cprid);
56676+
56677+ if (unlikely(!task))
56678+ task = find_task_by_vpid(shm_lapid);
56679+
56680+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56681+ (task->pid == shm_lapid)) &&
56682+ (task->acl->mode & GR_PROTSHM) &&
56683+ (task->acl != current->acl))) {
56684+ read_unlock(&tasklist_lock);
56685+ rcu_read_unlock();
56686+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56687+ return 0;
56688+ }
56689+ read_unlock(&tasklist_lock);
56690+ rcu_read_unlock();
56691+
56692+ return 1;
56693+}
56694diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56695new file mode 100644
56696index 0000000..bc0be01
56697--- /dev/null
56698+++ b/grsecurity/grsec_chdir.c
56699@@ -0,0 +1,19 @@
56700+#include <linux/kernel.h>
56701+#include <linux/sched.h>
56702+#include <linux/fs.h>
56703+#include <linux/file.h>
56704+#include <linux/grsecurity.h>
56705+#include <linux/grinternal.h>
56706+
56707+void
56708+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56709+{
56710+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56711+ if ((grsec_enable_chdir && grsec_enable_group &&
56712+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56713+ !grsec_enable_group)) {
56714+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56715+ }
56716+#endif
56717+ return;
56718+}
56719diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56720new file mode 100644
56721index 0000000..9807ee2
56722--- /dev/null
56723+++ b/grsecurity/grsec_chroot.c
56724@@ -0,0 +1,368 @@
56725+#include <linux/kernel.h>
56726+#include <linux/module.h>
56727+#include <linux/sched.h>
56728+#include <linux/file.h>
56729+#include <linux/fs.h>
56730+#include <linux/mount.h>
56731+#include <linux/types.h>
56732+#include "../fs/mount.h"
56733+#include <linux/grsecurity.h>
56734+#include <linux/grinternal.h>
56735+
56736+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56737+{
56738+#ifdef CONFIG_GRKERNSEC
56739+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56740+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56741+ task->gr_is_chrooted = 1;
56742+ else
56743+ task->gr_is_chrooted = 0;
56744+
56745+ task->gr_chroot_dentry = path->dentry;
56746+#endif
56747+ return;
56748+}
56749+
56750+void gr_clear_chroot_entries(struct task_struct *task)
56751+{
56752+#ifdef CONFIG_GRKERNSEC
56753+ task->gr_is_chrooted = 0;
56754+ task->gr_chroot_dentry = NULL;
56755+#endif
56756+ return;
56757+}
56758+
56759+int
56760+gr_handle_chroot_unix(const pid_t pid)
56761+{
56762+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56763+ struct task_struct *p;
56764+
56765+ if (unlikely(!grsec_enable_chroot_unix))
56766+ return 1;
56767+
56768+ if (likely(!proc_is_chrooted(current)))
56769+ return 1;
56770+
56771+ rcu_read_lock();
56772+ read_lock(&tasklist_lock);
56773+ p = find_task_by_vpid_unrestricted(pid);
56774+ if (unlikely(p && !have_same_root(current, p))) {
56775+ read_unlock(&tasklist_lock);
56776+ rcu_read_unlock();
56777+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56778+ return 0;
56779+ }
56780+ read_unlock(&tasklist_lock);
56781+ rcu_read_unlock();
56782+#endif
56783+ return 1;
56784+}
56785+
56786+int
56787+gr_handle_chroot_nice(void)
56788+{
56789+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56790+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56791+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56792+ return -EPERM;
56793+ }
56794+#endif
56795+ return 0;
56796+}
56797+
56798+int
56799+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56800+{
56801+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56802+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56803+ && proc_is_chrooted(current)) {
56804+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56805+ return -EACCES;
56806+ }
56807+#endif
56808+ return 0;
56809+}
56810+
56811+int
56812+gr_handle_chroot_rawio(const struct inode *inode)
56813+{
56814+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56815+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56816+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56817+ return 1;
56818+#endif
56819+ return 0;
56820+}
56821+
56822+int
56823+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56824+{
56825+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56826+ struct task_struct *p;
56827+ int ret = 0;
56828+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56829+ return ret;
56830+
56831+ read_lock(&tasklist_lock);
56832+ do_each_pid_task(pid, type, p) {
56833+ if (!have_same_root(current, p)) {
56834+ ret = 1;
56835+ goto out;
56836+ }
56837+ } while_each_pid_task(pid, type, p);
56838+out:
56839+ read_unlock(&tasklist_lock);
56840+ return ret;
56841+#endif
56842+ return 0;
56843+}
56844+
56845+int
56846+gr_pid_is_chrooted(struct task_struct *p)
56847+{
56848+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56849+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56850+ return 0;
56851+
56852+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56853+ !have_same_root(current, p)) {
56854+ return 1;
56855+ }
56856+#endif
56857+ return 0;
56858+}
56859+
56860+EXPORT_SYMBOL(gr_pid_is_chrooted);
56861+
56862+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56863+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56864+{
56865+ struct path path, currentroot;
56866+ int ret = 0;
56867+
56868+ path.dentry = (struct dentry *)u_dentry;
56869+ path.mnt = (struct vfsmount *)u_mnt;
56870+ get_fs_root(current->fs, &currentroot);
56871+ if (path_is_under(&path, &currentroot))
56872+ ret = 1;
56873+ path_put(&currentroot);
56874+
56875+ return ret;
56876+}
56877+#endif
56878+
56879+int
56880+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56881+{
56882+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56883+ if (!grsec_enable_chroot_fchdir)
56884+ return 1;
56885+
56886+ if (!proc_is_chrooted(current))
56887+ return 1;
56888+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56889+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56890+ return 0;
56891+ }
56892+#endif
56893+ return 1;
56894+}
56895+
56896+int
56897+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56898+ const time_t shm_createtime)
56899+{
56900+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56901+ struct task_struct *p;
56902+ time_t starttime;
56903+
56904+ if (unlikely(!grsec_enable_chroot_shmat))
56905+ return 1;
56906+
56907+ if (likely(!proc_is_chrooted(current)))
56908+ return 1;
56909+
56910+ rcu_read_lock();
56911+ read_lock(&tasklist_lock);
56912+
56913+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56914+ starttime = p->start_time.tv_sec;
56915+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56916+ if (have_same_root(current, p)) {
56917+ goto allow;
56918+ } else {
56919+ read_unlock(&tasklist_lock);
56920+ rcu_read_unlock();
56921+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56922+ return 0;
56923+ }
56924+ }
56925+ /* creator exited, pid reuse, fall through to next check */
56926+ }
56927+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56928+ if (unlikely(!have_same_root(current, p))) {
56929+ read_unlock(&tasklist_lock);
56930+ rcu_read_unlock();
56931+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56932+ return 0;
56933+ }
56934+ }
56935+
56936+allow:
56937+ read_unlock(&tasklist_lock);
56938+ rcu_read_unlock();
56939+#endif
56940+ return 1;
56941+}
56942+
56943+void
56944+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56945+{
56946+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56947+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56948+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56949+#endif
56950+ return;
56951+}
56952+
56953+int
56954+gr_handle_chroot_mknod(const struct dentry *dentry,
56955+ const struct vfsmount *mnt, const int mode)
56956+{
56957+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56958+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56959+ proc_is_chrooted(current)) {
56960+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56961+ return -EPERM;
56962+ }
56963+#endif
56964+ return 0;
56965+}
56966+
56967+int
56968+gr_handle_chroot_mount(const struct dentry *dentry,
56969+ const struct vfsmount *mnt, const char *dev_name)
56970+{
56971+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56972+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56973+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56974+ return -EPERM;
56975+ }
56976+#endif
56977+ return 0;
56978+}
56979+
56980+int
56981+gr_handle_chroot_pivot(void)
56982+{
56983+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56984+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56985+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56986+ return -EPERM;
56987+ }
56988+#endif
56989+ return 0;
56990+}
56991+
56992+int
56993+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56994+{
56995+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56996+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56997+ !gr_is_outside_chroot(dentry, mnt)) {
56998+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56999+ return -EPERM;
57000+ }
57001+#endif
57002+ return 0;
57003+}
57004+
57005+extern const char *captab_log[];
57006+extern int captab_log_entries;
57007+
57008+int
57009+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57010+{
57011+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57012+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57013+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57014+ if (cap_raised(chroot_caps, cap)) {
57015+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57016+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57017+ }
57018+ return 0;
57019+ }
57020+ }
57021+#endif
57022+ return 1;
57023+}
57024+
57025+int
57026+gr_chroot_is_capable(const int cap)
57027+{
57028+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57029+ return gr_task_chroot_is_capable(current, current_cred(), cap);
57030+#endif
57031+ return 1;
57032+}
57033+
57034+int
57035+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57036+{
57037+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57038+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57039+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57040+ if (cap_raised(chroot_caps, cap)) {
57041+ return 0;
57042+ }
57043+ }
57044+#endif
57045+ return 1;
57046+}
57047+
57048+int
57049+gr_chroot_is_capable_nolog(const int cap)
57050+{
57051+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57052+ return gr_task_chroot_is_capable_nolog(current, cap);
57053+#endif
57054+ return 1;
57055+}
57056+
57057+int
57058+gr_handle_chroot_sysctl(const int op)
57059+{
57060+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57061+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57062+ proc_is_chrooted(current))
57063+ return -EACCES;
57064+#endif
57065+ return 0;
57066+}
57067+
57068+void
57069+gr_handle_chroot_chdir(struct path *path)
57070+{
57071+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57072+ if (grsec_enable_chroot_chdir)
57073+ set_fs_pwd(current->fs, path);
57074+#endif
57075+ return;
57076+}
57077+
57078+int
57079+gr_handle_chroot_chmod(const struct dentry *dentry,
57080+ const struct vfsmount *mnt, const int mode)
57081+{
57082+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57083+ /* allow chmod +s on directories, but not files */
57084+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57085+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57086+ proc_is_chrooted(current)) {
57087+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57088+ return -EPERM;
57089+ }
57090+#endif
57091+ return 0;
57092+}
57093diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57094new file mode 100644
57095index 0000000..213ad8b
57096--- /dev/null
57097+++ b/grsecurity/grsec_disabled.c
57098@@ -0,0 +1,437 @@
57099+#include <linux/kernel.h>
57100+#include <linux/module.h>
57101+#include <linux/sched.h>
57102+#include <linux/file.h>
57103+#include <linux/fs.h>
57104+#include <linux/kdev_t.h>
57105+#include <linux/net.h>
57106+#include <linux/in.h>
57107+#include <linux/ip.h>
57108+#include <linux/skbuff.h>
57109+#include <linux/sysctl.h>
57110+
57111+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57112+void
57113+pax_set_initial_flags(struct linux_binprm *bprm)
57114+{
57115+ return;
57116+}
57117+#endif
57118+
57119+#ifdef CONFIG_SYSCTL
57120+__u32
57121+gr_handle_sysctl(const struct ctl_table * table, const int op)
57122+{
57123+ return 0;
57124+}
57125+#endif
57126+
57127+#ifdef CONFIG_TASKSTATS
57128+int gr_is_taskstats_denied(int pid)
57129+{
57130+ return 0;
57131+}
57132+#endif
57133+
57134+int
57135+gr_acl_is_enabled(void)
57136+{
57137+ return 0;
57138+}
57139+
57140+void
57141+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57142+{
57143+ return;
57144+}
57145+
57146+int
57147+gr_handle_rawio(const struct inode *inode)
57148+{
57149+ return 0;
57150+}
57151+
57152+void
57153+gr_acl_handle_psacct(struct task_struct *task, const long code)
57154+{
57155+ return;
57156+}
57157+
57158+int
57159+gr_handle_ptrace(struct task_struct *task, const long request)
57160+{
57161+ return 0;
57162+}
57163+
57164+int
57165+gr_handle_proc_ptrace(struct task_struct *task)
57166+{
57167+ return 0;
57168+}
57169+
57170+void
57171+gr_learn_resource(const struct task_struct *task,
57172+ const int res, const unsigned long wanted, const int gt)
57173+{
57174+ return;
57175+}
57176+
57177+int
57178+gr_set_acls(const int type)
57179+{
57180+ return 0;
57181+}
57182+
57183+int
57184+gr_check_hidden_task(const struct task_struct *tsk)
57185+{
57186+ return 0;
57187+}
57188+
57189+int
57190+gr_check_protected_task(const struct task_struct *task)
57191+{
57192+ return 0;
57193+}
57194+
57195+int
57196+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57197+{
57198+ return 0;
57199+}
57200+
57201+void
57202+gr_copy_label(struct task_struct *tsk)
57203+{
57204+ return;
57205+}
57206+
57207+void
57208+gr_set_pax_flags(struct task_struct *task)
57209+{
57210+ return;
57211+}
57212+
57213+int
57214+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57215+ const int unsafe_share)
57216+{
57217+ return 0;
57218+}
57219+
57220+void
57221+gr_handle_delete(const ino_t ino, const dev_t dev)
57222+{
57223+ return;
57224+}
57225+
57226+void
57227+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57228+{
57229+ return;
57230+}
57231+
57232+void
57233+gr_handle_crash(struct task_struct *task, const int sig)
57234+{
57235+ return;
57236+}
57237+
57238+int
57239+gr_check_crash_exec(const struct file *filp)
57240+{
57241+ return 0;
57242+}
57243+
57244+int
57245+gr_check_crash_uid(const uid_t uid)
57246+{
57247+ return 0;
57248+}
57249+
57250+void
57251+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57252+ struct dentry *old_dentry,
57253+ struct dentry *new_dentry,
57254+ struct vfsmount *mnt, const __u8 replace)
57255+{
57256+ return;
57257+}
57258+
57259+int
57260+gr_search_socket(const int family, const int type, const int protocol)
57261+{
57262+ return 1;
57263+}
57264+
57265+int
57266+gr_search_connectbind(const int mode, const struct socket *sock,
57267+ const struct sockaddr_in *addr)
57268+{
57269+ return 0;
57270+}
57271+
57272+void
57273+gr_handle_alertkill(struct task_struct *task)
57274+{
57275+ return;
57276+}
57277+
57278+__u32
57279+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57280+{
57281+ return 1;
57282+}
57283+
57284+__u32
57285+gr_acl_handle_hidden_file(const struct dentry * dentry,
57286+ const struct vfsmount * mnt)
57287+{
57288+ return 1;
57289+}
57290+
57291+__u32
57292+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57293+ int acc_mode)
57294+{
57295+ return 1;
57296+}
57297+
57298+__u32
57299+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57300+{
57301+ return 1;
57302+}
57303+
57304+__u32
57305+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57306+{
57307+ return 1;
57308+}
57309+
57310+int
57311+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57312+ unsigned int *vm_flags)
57313+{
57314+ return 1;
57315+}
57316+
57317+__u32
57318+gr_acl_handle_truncate(const struct dentry * dentry,
57319+ const struct vfsmount * mnt)
57320+{
57321+ return 1;
57322+}
57323+
57324+__u32
57325+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57326+{
57327+ return 1;
57328+}
57329+
57330+__u32
57331+gr_acl_handle_access(const struct dentry * dentry,
57332+ const struct vfsmount * mnt, const int fmode)
57333+{
57334+ return 1;
57335+}
57336+
57337+__u32
57338+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57339+ umode_t *mode)
57340+{
57341+ return 1;
57342+}
57343+
57344+__u32
57345+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57346+{
57347+ return 1;
57348+}
57349+
57350+__u32
57351+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57352+{
57353+ return 1;
57354+}
57355+
57356+void
57357+grsecurity_init(void)
57358+{
57359+ return;
57360+}
57361+
57362+umode_t gr_acl_umask(void)
57363+{
57364+ return 0;
57365+}
57366+
57367+__u32
57368+gr_acl_handle_mknod(const struct dentry * new_dentry,
57369+ const struct dentry * parent_dentry,
57370+ const struct vfsmount * parent_mnt,
57371+ const int mode)
57372+{
57373+ return 1;
57374+}
57375+
57376+__u32
57377+gr_acl_handle_mkdir(const struct dentry * new_dentry,
57378+ const struct dentry * parent_dentry,
57379+ const struct vfsmount * parent_mnt)
57380+{
57381+ return 1;
57382+}
57383+
57384+__u32
57385+gr_acl_handle_symlink(const struct dentry * new_dentry,
57386+ const struct dentry * parent_dentry,
57387+ const struct vfsmount * parent_mnt, const char *from)
57388+{
57389+ return 1;
57390+}
57391+
57392+__u32
57393+gr_acl_handle_link(const struct dentry * new_dentry,
57394+ const struct dentry * parent_dentry,
57395+ const struct vfsmount * parent_mnt,
57396+ const struct dentry * old_dentry,
57397+ const struct vfsmount * old_mnt, const char *to)
57398+{
57399+ return 1;
57400+}
57401+
57402+int
57403+gr_acl_handle_rename(const struct dentry *new_dentry,
57404+ const struct dentry *parent_dentry,
57405+ const struct vfsmount *parent_mnt,
57406+ const struct dentry *old_dentry,
57407+ const struct inode *old_parent_inode,
57408+ const struct vfsmount *old_mnt, const char *newname)
57409+{
57410+ return 0;
57411+}
57412+
57413+int
57414+gr_acl_handle_filldir(const struct file *file, const char *name,
57415+ const int namelen, const ino_t ino)
57416+{
57417+ return 1;
57418+}
57419+
57420+int
57421+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57422+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57423+{
57424+ return 1;
57425+}
57426+
57427+int
57428+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57429+{
57430+ return 0;
57431+}
57432+
57433+int
57434+gr_search_accept(const struct socket *sock)
57435+{
57436+ return 0;
57437+}
57438+
57439+int
57440+gr_search_listen(const struct socket *sock)
57441+{
57442+ return 0;
57443+}
57444+
57445+int
57446+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57447+{
57448+ return 0;
57449+}
57450+
57451+__u32
57452+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57453+{
57454+ return 1;
57455+}
57456+
57457+__u32
57458+gr_acl_handle_creat(const struct dentry * dentry,
57459+ const struct dentry * p_dentry,
57460+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57461+ const int imode)
57462+{
57463+ return 1;
57464+}
57465+
57466+void
57467+gr_acl_handle_exit(void)
57468+{
57469+ return;
57470+}
57471+
57472+int
57473+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57474+{
57475+ return 1;
57476+}
57477+
57478+void
57479+gr_set_role_label(const uid_t uid, const gid_t gid)
57480+{
57481+ return;
57482+}
57483+
57484+int
57485+gr_acl_handle_procpidmem(const struct task_struct *task)
57486+{
57487+ return 0;
57488+}
57489+
57490+int
57491+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57492+{
57493+ return 0;
57494+}
57495+
57496+int
57497+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57498+{
57499+ return 0;
57500+}
57501+
57502+void
57503+gr_set_kernel_label(struct task_struct *task)
57504+{
57505+ return;
57506+}
57507+
57508+int
57509+gr_check_user_change(int real, int effective, int fs)
57510+{
57511+ return 0;
57512+}
57513+
57514+int
57515+gr_check_group_change(int real, int effective, int fs)
57516+{
57517+ return 0;
57518+}
57519+
57520+int gr_acl_enable_at_secure(void)
57521+{
57522+ return 0;
57523+}
57524+
57525+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57526+{
57527+ return dentry->d_inode->i_sb->s_dev;
57528+}
57529+
57530+EXPORT_SYMBOL(gr_learn_resource);
57531+EXPORT_SYMBOL(gr_set_kernel_label);
57532+#ifdef CONFIG_SECURITY
57533+EXPORT_SYMBOL(gr_check_user_change);
57534+EXPORT_SYMBOL(gr_check_group_change);
57535+#endif
57536diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57537new file mode 100644
57538index 0000000..abfa971
57539--- /dev/null
57540+++ b/grsecurity/grsec_exec.c
57541@@ -0,0 +1,174 @@
57542+#include <linux/kernel.h>
57543+#include <linux/sched.h>
57544+#include <linux/file.h>
57545+#include <linux/binfmts.h>
57546+#include <linux/fs.h>
57547+#include <linux/types.h>
57548+#include <linux/grdefs.h>
57549+#include <linux/grsecurity.h>
57550+#include <linux/grinternal.h>
57551+#include <linux/capability.h>
57552+#include <linux/module.h>
57553+
57554+#include <asm/uaccess.h>
57555+
57556+#ifdef CONFIG_GRKERNSEC_EXECLOG
57557+static char gr_exec_arg_buf[132];
57558+static DEFINE_MUTEX(gr_exec_arg_mutex);
57559+#endif
57560+
57561+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57562+
57563+void
57564+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57565+{
57566+#ifdef CONFIG_GRKERNSEC_EXECLOG
57567+ char *grarg = gr_exec_arg_buf;
57568+ unsigned int i, x, execlen = 0;
57569+ char c;
57570+
57571+ if (!((grsec_enable_execlog && grsec_enable_group &&
57572+ in_group_p(grsec_audit_gid))
57573+ || (grsec_enable_execlog && !grsec_enable_group)))
57574+ return;
57575+
57576+ mutex_lock(&gr_exec_arg_mutex);
57577+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
57578+
57579+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
57580+ const char __user *p;
57581+ unsigned int len;
57582+
57583+ p = get_user_arg_ptr(argv, i);
57584+ if (IS_ERR(p))
57585+ goto log;
57586+
57587+ len = strnlen_user(p, 128 - execlen);
57588+ if (len > 128 - execlen)
57589+ len = 128 - execlen;
57590+ else if (len > 0)
57591+ len--;
57592+ if (copy_from_user(grarg + execlen, p, len))
57593+ goto log;
57594+
57595+ /* rewrite unprintable characters */
57596+ for (x = 0; x < len; x++) {
57597+ c = *(grarg + execlen + x);
57598+ if (c < 32 || c > 126)
57599+ *(grarg + execlen + x) = ' ';
57600+ }
57601+
57602+ execlen += len;
57603+ *(grarg + execlen) = ' ';
57604+ *(grarg + execlen + 1) = '\0';
57605+ execlen++;
57606+ }
57607+
57608+ log:
57609+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57610+ bprm->file->f_path.mnt, grarg);
57611+ mutex_unlock(&gr_exec_arg_mutex);
57612+#endif
57613+ return;
57614+}
57615+
57616+#ifdef CONFIG_GRKERNSEC
57617+extern int gr_acl_is_capable(const int cap);
57618+extern int gr_acl_is_capable_nolog(const int cap);
57619+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57620+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57621+extern int gr_chroot_is_capable(const int cap);
57622+extern int gr_chroot_is_capable_nolog(const int cap);
57623+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57624+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57625+#endif
57626+
57627+const char *captab_log[] = {
57628+ "CAP_CHOWN",
57629+ "CAP_DAC_OVERRIDE",
57630+ "CAP_DAC_READ_SEARCH",
57631+ "CAP_FOWNER",
57632+ "CAP_FSETID",
57633+ "CAP_KILL",
57634+ "CAP_SETGID",
57635+ "CAP_SETUID",
57636+ "CAP_SETPCAP",
57637+ "CAP_LINUX_IMMUTABLE",
57638+ "CAP_NET_BIND_SERVICE",
57639+ "CAP_NET_BROADCAST",
57640+ "CAP_NET_ADMIN",
57641+ "CAP_NET_RAW",
57642+ "CAP_IPC_LOCK",
57643+ "CAP_IPC_OWNER",
57644+ "CAP_SYS_MODULE",
57645+ "CAP_SYS_RAWIO",
57646+ "CAP_SYS_CHROOT",
57647+ "CAP_SYS_PTRACE",
57648+ "CAP_SYS_PACCT",
57649+ "CAP_SYS_ADMIN",
57650+ "CAP_SYS_BOOT",
57651+ "CAP_SYS_NICE",
57652+ "CAP_SYS_RESOURCE",
57653+ "CAP_SYS_TIME",
57654+ "CAP_SYS_TTY_CONFIG",
57655+ "CAP_MKNOD",
57656+ "CAP_LEASE",
57657+ "CAP_AUDIT_WRITE",
57658+ "CAP_AUDIT_CONTROL",
57659+ "CAP_SETFCAP",
57660+ "CAP_MAC_OVERRIDE",
57661+ "CAP_MAC_ADMIN",
57662+ "CAP_SYSLOG",
57663+ "CAP_WAKE_ALARM"
57664+};
57665+
57666+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57667+
57668+int gr_is_capable(const int cap)
57669+{
57670+#ifdef CONFIG_GRKERNSEC
57671+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57672+ return 1;
57673+ return 0;
57674+#else
57675+ return 1;
57676+#endif
57677+}
57678+
57679+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57680+{
57681+#ifdef CONFIG_GRKERNSEC
57682+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57683+ return 1;
57684+ return 0;
57685+#else
57686+ return 1;
57687+#endif
57688+}
57689+
57690+int gr_is_capable_nolog(const int cap)
57691+{
57692+#ifdef CONFIG_GRKERNSEC
57693+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57694+ return 1;
57695+ return 0;
57696+#else
57697+ return 1;
57698+#endif
57699+}
57700+
57701+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57702+{
57703+#ifdef CONFIG_GRKERNSEC
57704+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57705+ return 1;
57706+ return 0;
57707+#else
57708+ return 1;
57709+#endif
57710+}
57711+
57712+EXPORT_SYMBOL(gr_is_capable);
57713+EXPORT_SYMBOL(gr_is_capable_nolog);
57714+EXPORT_SYMBOL(gr_task_is_capable);
57715+EXPORT_SYMBOL(gr_task_is_capable_nolog);
57716diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57717new file mode 100644
57718index 0000000..d3ee748
57719--- /dev/null
57720+++ b/grsecurity/grsec_fifo.c
57721@@ -0,0 +1,24 @@
57722+#include <linux/kernel.h>
57723+#include <linux/sched.h>
57724+#include <linux/fs.h>
57725+#include <linux/file.h>
57726+#include <linux/grinternal.h>
57727+
57728+int
57729+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57730+ const struct dentry *dir, const int flag, const int acc_mode)
57731+{
57732+#ifdef CONFIG_GRKERNSEC_FIFO
57733+ const struct cred *cred = current_cred();
57734+
57735+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57736+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57737+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57738+ (cred->fsuid != dentry->d_inode->i_uid)) {
57739+ if (!inode_permission(dentry->d_inode, acc_mode))
57740+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57741+ return -EACCES;
57742+ }
57743+#endif
57744+ return 0;
57745+}
57746diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57747new file mode 100644
57748index 0000000..8ca18bf
57749--- /dev/null
57750+++ b/grsecurity/grsec_fork.c
57751@@ -0,0 +1,23 @@
57752+#include <linux/kernel.h>
57753+#include <linux/sched.h>
57754+#include <linux/grsecurity.h>
57755+#include <linux/grinternal.h>
57756+#include <linux/errno.h>
57757+
57758+void
57759+gr_log_forkfail(const int retval)
57760+{
57761+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57762+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57763+ switch (retval) {
57764+ case -EAGAIN:
57765+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57766+ break;
57767+ case -ENOMEM:
57768+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57769+ break;
57770+ }
57771+ }
57772+#endif
57773+ return;
57774+}
57775diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57776new file mode 100644
57777index 0000000..05a6015
57778--- /dev/null
57779+++ b/grsecurity/grsec_init.c
57780@@ -0,0 +1,283 @@
57781+#include <linux/kernel.h>
57782+#include <linux/sched.h>
57783+#include <linux/mm.h>
57784+#include <linux/gracl.h>
57785+#include <linux/slab.h>
57786+#include <linux/vmalloc.h>
57787+#include <linux/percpu.h>
57788+#include <linux/module.h>
57789+
57790+int grsec_enable_ptrace_readexec;
57791+int grsec_enable_setxid;
57792+int grsec_enable_symlinkown;
57793+int grsec_symlinkown_gid;
57794+int grsec_enable_brute;
57795+int grsec_enable_link;
57796+int grsec_enable_dmesg;
57797+int grsec_enable_harden_ptrace;
57798+int grsec_enable_fifo;
57799+int grsec_enable_execlog;
57800+int grsec_enable_signal;
57801+int grsec_enable_forkfail;
57802+int grsec_enable_audit_ptrace;
57803+int grsec_enable_time;
57804+int grsec_enable_audit_textrel;
57805+int grsec_enable_group;
57806+int grsec_audit_gid;
57807+int grsec_enable_chdir;
57808+int grsec_enable_mount;
57809+int grsec_enable_rofs;
57810+int grsec_enable_chroot_findtask;
57811+int grsec_enable_chroot_mount;
57812+int grsec_enable_chroot_shmat;
57813+int grsec_enable_chroot_fchdir;
57814+int grsec_enable_chroot_double;
57815+int grsec_enable_chroot_pivot;
57816+int grsec_enable_chroot_chdir;
57817+int grsec_enable_chroot_chmod;
57818+int grsec_enable_chroot_mknod;
57819+int grsec_enable_chroot_nice;
57820+int grsec_enable_chroot_execlog;
57821+int grsec_enable_chroot_caps;
57822+int grsec_enable_chroot_sysctl;
57823+int grsec_enable_chroot_unix;
57824+int grsec_enable_tpe;
57825+int grsec_tpe_gid;
57826+int grsec_enable_blackhole;
57827+#ifdef CONFIG_IPV6_MODULE
57828+EXPORT_SYMBOL(grsec_enable_blackhole);
57829+#endif
57830+int grsec_lastack_retries;
57831+int grsec_enable_tpe_all;
57832+int grsec_enable_tpe_invert;
57833+int grsec_enable_socket_all;
57834+int grsec_socket_all_gid;
57835+int grsec_enable_socket_client;
57836+int grsec_socket_client_gid;
57837+int grsec_enable_socket_server;
57838+int grsec_socket_server_gid;
57839+int grsec_resource_logging;
57840+int grsec_disable_privio;
57841+int grsec_enable_log_rwxmaps;
57842+int grsec_lock;
57843+
57844+DEFINE_SPINLOCK(grsec_alert_lock);
57845+unsigned long grsec_alert_wtime = 0;
57846+unsigned long grsec_alert_fyet = 0;
57847+
57848+DEFINE_SPINLOCK(grsec_audit_lock);
57849+
57850+DEFINE_RWLOCK(grsec_exec_file_lock);
57851+
57852+char *gr_shared_page[4];
57853+
57854+char *gr_alert_log_fmt;
57855+char *gr_audit_log_fmt;
57856+char *gr_alert_log_buf;
57857+char *gr_audit_log_buf;
57858+
57859+extern struct gr_arg *gr_usermode;
57860+extern unsigned char *gr_system_salt;
57861+extern unsigned char *gr_system_sum;
57862+
57863+void __init
57864+grsecurity_init(void)
57865+{
57866+ int j;
57867+ /* create the per-cpu shared pages */
57868+
57869+#ifdef CONFIG_X86
57870+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57871+#endif
57872+
57873+ for (j = 0; j < 4; j++) {
57874+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57875+ if (gr_shared_page[j] == NULL) {
57876+ panic("Unable to allocate grsecurity shared page");
57877+ return;
57878+ }
57879+ }
57880+
57881+ /* allocate log buffers */
57882+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57883+ if (!gr_alert_log_fmt) {
57884+ panic("Unable to allocate grsecurity alert log format buffer");
57885+ return;
57886+ }
57887+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57888+ if (!gr_audit_log_fmt) {
57889+ panic("Unable to allocate grsecurity audit log format buffer");
57890+ return;
57891+ }
57892+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57893+ if (!gr_alert_log_buf) {
57894+ panic("Unable to allocate grsecurity alert log buffer");
57895+ return;
57896+ }
57897+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57898+ if (!gr_audit_log_buf) {
57899+ panic("Unable to allocate grsecurity audit log buffer");
57900+ return;
57901+ }
57902+
57903+ /* allocate memory for authentication structure */
57904+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57905+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57906+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57907+
57908+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57909+ panic("Unable to allocate grsecurity authentication structure");
57910+ return;
57911+ }
57912+
57913+
57914+#ifdef CONFIG_GRKERNSEC_IO
57915+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57916+ grsec_disable_privio = 1;
57917+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57918+ grsec_disable_privio = 1;
57919+#else
57920+ grsec_disable_privio = 0;
57921+#endif
57922+#endif
57923+
57924+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57925+ /* for backward compatibility, tpe_invert always defaults to on if
57926+ enabled in the kernel
57927+ */
57928+ grsec_enable_tpe_invert = 1;
57929+#endif
57930+
57931+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57932+#ifndef CONFIG_GRKERNSEC_SYSCTL
57933+ grsec_lock = 1;
57934+#endif
57935+
57936+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57937+ grsec_enable_audit_textrel = 1;
57938+#endif
57939+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57940+ grsec_enable_log_rwxmaps = 1;
57941+#endif
57942+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57943+ grsec_enable_group = 1;
57944+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57945+#endif
57946+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57947+ grsec_enable_ptrace_readexec = 1;
57948+#endif
57949+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57950+ grsec_enable_chdir = 1;
57951+#endif
57952+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57953+ grsec_enable_harden_ptrace = 1;
57954+#endif
57955+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57956+ grsec_enable_mount = 1;
57957+#endif
57958+#ifdef CONFIG_GRKERNSEC_LINK
57959+ grsec_enable_link = 1;
57960+#endif
57961+#ifdef CONFIG_GRKERNSEC_BRUTE
57962+ grsec_enable_brute = 1;
57963+#endif
57964+#ifdef CONFIG_GRKERNSEC_DMESG
57965+ grsec_enable_dmesg = 1;
57966+#endif
57967+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57968+ grsec_enable_blackhole = 1;
57969+ grsec_lastack_retries = 4;
57970+#endif
57971+#ifdef CONFIG_GRKERNSEC_FIFO
57972+ grsec_enable_fifo = 1;
57973+#endif
57974+#ifdef CONFIG_GRKERNSEC_EXECLOG
57975+ grsec_enable_execlog = 1;
57976+#endif
57977+#ifdef CONFIG_GRKERNSEC_SETXID
57978+ grsec_enable_setxid = 1;
57979+#endif
57980+#ifdef CONFIG_GRKERNSEC_SIGNAL
57981+ grsec_enable_signal = 1;
57982+#endif
57983+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57984+ grsec_enable_forkfail = 1;
57985+#endif
57986+#ifdef CONFIG_GRKERNSEC_TIME
57987+ grsec_enable_time = 1;
57988+#endif
57989+#ifdef CONFIG_GRKERNSEC_RESLOG
57990+ grsec_resource_logging = 1;
57991+#endif
57992+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57993+ grsec_enable_chroot_findtask = 1;
57994+#endif
57995+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57996+ grsec_enable_chroot_unix = 1;
57997+#endif
57998+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57999+ grsec_enable_chroot_mount = 1;
58000+#endif
58001+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58002+ grsec_enable_chroot_fchdir = 1;
58003+#endif
58004+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58005+ grsec_enable_chroot_shmat = 1;
58006+#endif
58007+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58008+ grsec_enable_audit_ptrace = 1;
58009+#endif
58010+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58011+ grsec_enable_chroot_double = 1;
58012+#endif
58013+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58014+ grsec_enable_chroot_pivot = 1;
58015+#endif
58016+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58017+ grsec_enable_chroot_chdir = 1;
58018+#endif
58019+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58020+ grsec_enable_chroot_chmod = 1;
58021+#endif
58022+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58023+ grsec_enable_chroot_mknod = 1;
58024+#endif
58025+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58026+ grsec_enable_chroot_nice = 1;
58027+#endif
58028+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58029+ grsec_enable_chroot_execlog = 1;
58030+#endif
58031+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58032+ grsec_enable_chroot_caps = 1;
58033+#endif
58034+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58035+ grsec_enable_chroot_sysctl = 1;
58036+#endif
58037+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58038+ grsec_enable_symlinkown = 1;
58039+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58040+#endif
58041+#ifdef CONFIG_GRKERNSEC_TPE
58042+ grsec_enable_tpe = 1;
58043+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58044+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58045+ grsec_enable_tpe_all = 1;
58046+#endif
58047+#endif
58048+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58049+ grsec_enable_socket_all = 1;
58050+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58051+#endif
58052+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58053+ grsec_enable_socket_client = 1;
58054+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58055+#endif
58056+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58057+ grsec_enable_socket_server = 1;
58058+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58059+#endif
58060+#endif
58061+
58062+ return;
58063+}
58064diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58065new file mode 100644
58066index 0000000..551a2e7
58067--- /dev/null
58068+++ b/grsecurity/grsec_link.c
58069@@ -0,0 +1,59 @@
58070+#include <linux/kernel.h>
58071+#include <linux/sched.h>
58072+#include <linux/fs.h>
58073+#include <linux/file.h>
58074+#include <linux/grinternal.h>
58075+
58076+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58077+{
58078+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58079+ const struct inode *link_inode = link->dentry->d_inode;
58080+
58081+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58082+ /* ignore root-owned links, e.g. /proc/self */
58083+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) &&
58084+ !uid_eq(link_inode->i_uid, target->i_uid)) {
58085+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58086+ return 1;
58087+ }
58088+#endif
58089+ return 0;
58090+}
58091+
58092+int
58093+gr_handle_follow_link(const struct inode *parent,
58094+ const struct inode *inode,
58095+ const struct dentry *dentry, const struct vfsmount *mnt)
58096+{
58097+#ifdef CONFIG_GRKERNSEC_LINK
58098+ const struct cred *cred = current_cred();
58099+
58100+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58101+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58102+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58103+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58104+ return -EACCES;
58105+ }
58106+#endif
58107+ return 0;
58108+}
58109+
58110+int
58111+gr_handle_hardlink(const struct dentry *dentry,
58112+ const struct vfsmount *mnt,
58113+ struct inode *inode, const int mode, const char *to)
58114+{
58115+#ifdef CONFIG_GRKERNSEC_LINK
58116+ const struct cred *cred = current_cred();
58117+
58118+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58119+ (!S_ISREG(mode) || (mode & S_ISUID) ||
58120+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
58121+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58122+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58123+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58124+ return -EPERM;
58125+ }
58126+#endif
58127+ return 0;
58128+}
58129diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58130new file mode 100644
58131index 0000000..a45d2e9
58132--- /dev/null
58133+++ b/grsecurity/grsec_log.c
58134@@ -0,0 +1,322 @@
58135+#include <linux/kernel.h>
58136+#include <linux/sched.h>
58137+#include <linux/file.h>
58138+#include <linux/tty.h>
58139+#include <linux/fs.h>
58140+#include <linux/grinternal.h>
58141+
58142+#ifdef CONFIG_TREE_PREEMPT_RCU
58143+#define DISABLE_PREEMPT() preempt_disable()
58144+#define ENABLE_PREEMPT() preempt_enable()
58145+#else
58146+#define DISABLE_PREEMPT()
58147+#define ENABLE_PREEMPT()
58148+#endif
58149+
58150+#define BEGIN_LOCKS(x) \
58151+ DISABLE_PREEMPT(); \
58152+ rcu_read_lock(); \
58153+ read_lock(&tasklist_lock); \
58154+ read_lock(&grsec_exec_file_lock); \
58155+ if (x != GR_DO_AUDIT) \
58156+ spin_lock(&grsec_alert_lock); \
58157+ else \
58158+ spin_lock(&grsec_audit_lock)
58159+
58160+#define END_LOCKS(x) \
58161+ if (x != GR_DO_AUDIT) \
58162+ spin_unlock(&grsec_alert_lock); \
58163+ else \
58164+ spin_unlock(&grsec_audit_lock); \
58165+ read_unlock(&grsec_exec_file_lock); \
58166+ read_unlock(&tasklist_lock); \
58167+ rcu_read_unlock(); \
58168+ ENABLE_PREEMPT(); \
58169+ if (x == GR_DONT_AUDIT) \
58170+ gr_handle_alertkill(current)
58171+
58172+enum {
58173+ FLOODING,
58174+ NO_FLOODING
58175+};
58176+
58177+extern char *gr_alert_log_fmt;
58178+extern char *gr_audit_log_fmt;
58179+extern char *gr_alert_log_buf;
58180+extern char *gr_audit_log_buf;
58181+
58182+static int gr_log_start(int audit)
58183+{
58184+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58185+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58186+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58187+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58188+ unsigned long curr_secs = get_seconds();
58189+
58190+ if (audit == GR_DO_AUDIT)
58191+ goto set_fmt;
58192+
58193+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58194+ grsec_alert_wtime = curr_secs;
58195+ grsec_alert_fyet = 0;
58196+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58197+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58198+ grsec_alert_fyet++;
58199+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58200+ grsec_alert_wtime = curr_secs;
58201+ grsec_alert_fyet++;
58202+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58203+ return FLOODING;
58204+ }
58205+ else return FLOODING;
58206+
58207+set_fmt:
58208+#endif
58209+ memset(buf, 0, PAGE_SIZE);
58210+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
58211+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58212+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58213+ } else if (current->signal->curr_ip) {
58214+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58215+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58216+ } else if (gr_acl_is_enabled()) {
58217+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58218+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58219+ } else {
58220+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
58221+ strcpy(buf, fmt);
58222+ }
58223+
58224+ return NO_FLOODING;
58225+}
58226+
58227+static void gr_log_middle(int audit, const char *msg, va_list ap)
58228+ __attribute__ ((format (printf, 2, 0)));
58229+
58230+static void gr_log_middle(int audit, const char *msg, va_list ap)
58231+{
58232+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58233+ unsigned int len = strlen(buf);
58234+
58235+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58236+
58237+ return;
58238+}
58239+
58240+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58241+ __attribute__ ((format (printf, 2, 3)));
58242+
58243+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58244+{
58245+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58246+ unsigned int len = strlen(buf);
58247+ va_list ap;
58248+
58249+ va_start(ap, msg);
58250+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58251+ va_end(ap);
58252+
58253+ return;
58254+}
58255+
58256+static void gr_log_end(int audit, int append_default)
58257+{
58258+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58259+
58260+ if (append_default) {
58261+ unsigned int len = strlen(buf);
58262+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58263+ }
58264+
58265+ printk("%s\n", buf);
58266+
58267+ return;
58268+}
58269+
58270+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58271+{
58272+ int logtype;
58273+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58274+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58275+ void *voidptr = NULL;
58276+ int num1 = 0, num2 = 0;
58277+ unsigned long ulong1 = 0, ulong2 = 0;
58278+ struct dentry *dentry = NULL;
58279+ struct vfsmount *mnt = NULL;
58280+ struct file *file = NULL;
58281+ struct task_struct *task = NULL;
58282+ const struct cred *cred, *pcred;
58283+ va_list ap;
58284+
58285+ BEGIN_LOCKS(audit);
58286+ logtype = gr_log_start(audit);
58287+ if (logtype == FLOODING) {
58288+ END_LOCKS(audit);
58289+ return;
58290+ }
58291+ va_start(ap, argtypes);
58292+ switch (argtypes) {
58293+ case GR_TTYSNIFF:
58294+ task = va_arg(ap, struct task_struct *);
58295+ 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);
58296+ break;
58297+ case GR_SYSCTL_HIDDEN:
58298+ str1 = va_arg(ap, char *);
58299+ gr_log_middle_varargs(audit, msg, result, str1);
58300+ break;
58301+ case GR_RBAC:
58302+ dentry = va_arg(ap, struct dentry *);
58303+ mnt = va_arg(ap, struct vfsmount *);
58304+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58305+ break;
58306+ case GR_RBAC_STR:
58307+ dentry = va_arg(ap, struct dentry *);
58308+ mnt = va_arg(ap, struct vfsmount *);
58309+ str1 = va_arg(ap, char *);
58310+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58311+ break;
58312+ case GR_STR_RBAC:
58313+ str1 = va_arg(ap, char *);
58314+ dentry = va_arg(ap, struct dentry *);
58315+ mnt = va_arg(ap, struct vfsmount *);
58316+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58317+ break;
58318+ case GR_RBAC_MODE2:
58319+ dentry = va_arg(ap, struct dentry *);
58320+ mnt = va_arg(ap, struct vfsmount *);
58321+ str1 = va_arg(ap, char *);
58322+ str2 = va_arg(ap, char *);
58323+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58324+ break;
58325+ case GR_RBAC_MODE3:
58326+ dentry = va_arg(ap, struct dentry *);
58327+ mnt = va_arg(ap, struct vfsmount *);
58328+ str1 = va_arg(ap, char *);
58329+ str2 = va_arg(ap, char *);
58330+ str3 = va_arg(ap, char *);
58331+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58332+ break;
58333+ case GR_FILENAME:
58334+ dentry = va_arg(ap, struct dentry *);
58335+ mnt = va_arg(ap, struct vfsmount *);
58336+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58337+ break;
58338+ case GR_STR_FILENAME:
58339+ str1 = va_arg(ap, char *);
58340+ dentry = va_arg(ap, struct dentry *);
58341+ mnt = va_arg(ap, struct vfsmount *);
58342+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58343+ break;
58344+ case GR_FILENAME_STR:
58345+ dentry = va_arg(ap, struct dentry *);
58346+ mnt = va_arg(ap, struct vfsmount *);
58347+ str1 = va_arg(ap, char *);
58348+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58349+ break;
58350+ case GR_FILENAME_TWO_INT:
58351+ dentry = va_arg(ap, struct dentry *);
58352+ mnt = va_arg(ap, struct vfsmount *);
58353+ num1 = va_arg(ap, int);
58354+ num2 = va_arg(ap, int);
58355+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58356+ break;
58357+ case GR_FILENAME_TWO_INT_STR:
58358+ dentry = va_arg(ap, struct dentry *);
58359+ mnt = va_arg(ap, struct vfsmount *);
58360+ num1 = va_arg(ap, int);
58361+ num2 = va_arg(ap, int);
58362+ str1 = va_arg(ap, char *);
58363+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58364+ break;
58365+ case GR_TEXTREL:
58366+ file = va_arg(ap, struct file *);
58367+ ulong1 = va_arg(ap, unsigned long);
58368+ ulong2 = va_arg(ap, unsigned long);
58369+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58370+ break;
58371+ case GR_PTRACE:
58372+ task = va_arg(ap, struct task_struct *);
58373+ 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);
58374+ break;
58375+ case GR_RESOURCE:
58376+ task = va_arg(ap, struct task_struct *);
58377+ cred = __task_cred(task);
58378+ pcred = __task_cred(task->real_parent);
58379+ ulong1 = va_arg(ap, unsigned long);
58380+ str1 = va_arg(ap, char *);
58381+ ulong2 = va_arg(ap, unsigned long);
58382+ 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);
58383+ break;
58384+ case GR_CAP:
58385+ task = va_arg(ap, struct task_struct *);
58386+ cred = __task_cred(task);
58387+ pcred = __task_cred(task->real_parent);
58388+ str1 = va_arg(ap, char *);
58389+ 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);
58390+ break;
58391+ case GR_SIG:
58392+ str1 = va_arg(ap, char *);
58393+ voidptr = va_arg(ap, void *);
58394+ gr_log_middle_varargs(audit, msg, str1, voidptr);
58395+ break;
58396+ case GR_SIG2:
58397+ task = va_arg(ap, struct task_struct *);
58398+ cred = __task_cred(task);
58399+ pcred = __task_cred(task->real_parent);
58400+ num1 = va_arg(ap, int);
58401+ 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);
58402+ break;
58403+ case GR_CRASH1:
58404+ task = va_arg(ap, struct task_struct *);
58405+ cred = __task_cred(task);
58406+ pcred = __task_cred(task->real_parent);
58407+ ulong1 = va_arg(ap, unsigned long);
58408+ 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);
58409+ break;
58410+ case GR_CRASH2:
58411+ task = va_arg(ap, struct task_struct *);
58412+ cred = __task_cred(task);
58413+ pcred = __task_cred(task->real_parent);
58414+ ulong1 = va_arg(ap, unsigned long);
58415+ 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);
58416+ break;
58417+ case GR_RWXMAP:
58418+ file = va_arg(ap, struct file *);
58419+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58420+ break;
58421+ case GR_PSACCT:
58422+ {
58423+ unsigned int wday, cday;
58424+ __u8 whr, chr;
58425+ __u8 wmin, cmin;
58426+ __u8 wsec, csec;
58427+ char cur_tty[64] = { 0 };
58428+ char parent_tty[64] = { 0 };
58429+
58430+ task = va_arg(ap, struct task_struct *);
58431+ wday = va_arg(ap, unsigned int);
58432+ cday = va_arg(ap, unsigned int);
58433+ whr = va_arg(ap, int);
58434+ chr = va_arg(ap, int);
58435+ wmin = va_arg(ap, int);
58436+ cmin = va_arg(ap, int);
58437+ wsec = va_arg(ap, int);
58438+ csec = va_arg(ap, int);
58439+ ulong1 = va_arg(ap, unsigned long);
58440+ cred = __task_cred(task);
58441+ pcred = __task_cred(task->real_parent);
58442+
58443+ 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);
58444+ }
58445+ break;
58446+ default:
58447+ gr_log_middle(audit, msg, ap);
58448+ }
58449+ va_end(ap);
58450+ // these don't need DEFAULTSECARGS printed on the end
58451+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58452+ gr_log_end(audit, 0);
58453+ else
58454+ gr_log_end(audit, 1);
58455+ END_LOCKS(audit);
58456+}
58457diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58458new file mode 100644
58459index 0000000..f536303
58460--- /dev/null
58461+++ b/grsecurity/grsec_mem.c
58462@@ -0,0 +1,40 @@
58463+#include <linux/kernel.h>
58464+#include <linux/sched.h>
58465+#include <linux/mm.h>
58466+#include <linux/mman.h>
58467+#include <linux/grinternal.h>
58468+
58469+void
58470+gr_handle_ioperm(void)
58471+{
58472+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58473+ return;
58474+}
58475+
58476+void
58477+gr_handle_iopl(void)
58478+{
58479+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58480+ return;
58481+}
58482+
58483+void
58484+gr_handle_mem_readwrite(u64 from, u64 to)
58485+{
58486+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58487+ return;
58488+}
58489+
58490+void
58491+gr_handle_vm86(void)
58492+{
58493+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58494+ return;
58495+}
58496+
58497+void
58498+gr_log_badprocpid(const char *entry)
58499+{
58500+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58501+ return;
58502+}
58503diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58504new file mode 100644
58505index 0000000..2131422
58506--- /dev/null
58507+++ b/grsecurity/grsec_mount.c
58508@@ -0,0 +1,62 @@
58509+#include <linux/kernel.h>
58510+#include <linux/sched.h>
58511+#include <linux/mount.h>
58512+#include <linux/grsecurity.h>
58513+#include <linux/grinternal.h>
58514+
58515+void
58516+gr_log_remount(const char *devname, const int retval)
58517+{
58518+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58519+ if (grsec_enable_mount && (retval >= 0))
58520+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58521+#endif
58522+ return;
58523+}
58524+
58525+void
58526+gr_log_unmount(const char *devname, const int retval)
58527+{
58528+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58529+ if (grsec_enable_mount && (retval >= 0))
58530+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58531+#endif
58532+ return;
58533+}
58534+
58535+void
58536+gr_log_mount(const char *from, const char *to, const int retval)
58537+{
58538+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58539+ if (grsec_enable_mount && (retval >= 0))
58540+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58541+#endif
58542+ return;
58543+}
58544+
58545+int
58546+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58547+{
58548+#ifdef CONFIG_GRKERNSEC_ROFS
58549+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58550+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58551+ return -EPERM;
58552+ } else
58553+ return 0;
58554+#endif
58555+ return 0;
58556+}
58557+
58558+int
58559+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58560+{
58561+#ifdef CONFIG_GRKERNSEC_ROFS
58562+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58563+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58564+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58565+ return -EPERM;
58566+ } else
58567+ return 0;
58568+#endif
58569+ return 0;
58570+}
58571diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58572new file mode 100644
58573index 0000000..a3b12a0
58574--- /dev/null
58575+++ b/grsecurity/grsec_pax.c
58576@@ -0,0 +1,36 @@
58577+#include <linux/kernel.h>
58578+#include <linux/sched.h>
58579+#include <linux/mm.h>
58580+#include <linux/file.h>
58581+#include <linux/grinternal.h>
58582+#include <linux/grsecurity.h>
58583+
58584+void
58585+gr_log_textrel(struct vm_area_struct * vma)
58586+{
58587+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58588+ if (grsec_enable_audit_textrel)
58589+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58590+#endif
58591+ return;
58592+}
58593+
58594+void
58595+gr_log_rwxmmap(struct file *file)
58596+{
58597+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58598+ if (grsec_enable_log_rwxmaps)
58599+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58600+#endif
58601+ return;
58602+}
58603+
58604+void
58605+gr_log_rwxmprotect(struct file *file)
58606+{
58607+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58608+ if (grsec_enable_log_rwxmaps)
58609+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58610+#endif
58611+ return;
58612+}
58613diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58614new file mode 100644
58615index 0000000..f7f29aa
58616--- /dev/null
58617+++ b/grsecurity/grsec_ptrace.c
58618@@ -0,0 +1,30 @@
58619+#include <linux/kernel.h>
58620+#include <linux/sched.h>
58621+#include <linux/grinternal.h>
58622+#include <linux/security.h>
58623+
58624+void
58625+gr_audit_ptrace(struct task_struct *task)
58626+{
58627+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58628+ if (grsec_enable_audit_ptrace)
58629+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58630+#endif
58631+ return;
58632+}
58633+
58634+int
58635+gr_ptrace_readexec(struct file *file, int unsafe_flags)
58636+{
58637+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58638+ const struct dentry *dentry = file->f_path.dentry;
58639+ const struct vfsmount *mnt = file->f_path.mnt;
58640+
58641+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58642+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58643+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58644+ return -EACCES;
58645+ }
58646+#endif
58647+ return 0;
58648+}
58649diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58650new file mode 100644
58651index 0000000..b4ac94c
58652--- /dev/null
58653+++ b/grsecurity/grsec_sig.c
58654@@ -0,0 +1,209 @@
58655+#include <linux/kernel.h>
58656+#include <linux/sched.h>
58657+#include <linux/delay.h>
58658+#include <linux/grsecurity.h>
58659+#include <linux/grinternal.h>
58660+#include <linux/hardirq.h>
58661+
58662+char *signames[] = {
58663+ [SIGSEGV] = "Segmentation fault",
58664+ [SIGILL] = "Illegal instruction",
58665+ [SIGABRT] = "Abort",
58666+ [SIGBUS] = "Invalid alignment/Bus error"
58667+};
58668+
58669+void
58670+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58671+{
58672+#ifdef CONFIG_GRKERNSEC_SIGNAL
58673+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58674+ (sig == SIGABRT) || (sig == SIGBUS))) {
58675+ if (t->pid == current->pid) {
58676+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58677+ } else {
58678+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58679+ }
58680+ }
58681+#endif
58682+ return;
58683+}
58684+
58685+int
58686+gr_handle_signal(const struct task_struct *p, const int sig)
58687+{
58688+#ifdef CONFIG_GRKERNSEC
58689+ /* ignore the 0 signal for protected task checks */
58690+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58691+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58692+ return -EPERM;
58693+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58694+ return -EPERM;
58695+ }
58696+#endif
58697+ return 0;
58698+}
58699+
58700+#ifdef CONFIG_GRKERNSEC
58701+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58702+
58703+int gr_fake_force_sig(int sig, struct task_struct *t)
58704+{
58705+ unsigned long int flags;
58706+ int ret, blocked, ignored;
58707+ struct k_sigaction *action;
58708+
58709+ spin_lock_irqsave(&t->sighand->siglock, flags);
58710+ action = &t->sighand->action[sig-1];
58711+ ignored = action->sa.sa_handler == SIG_IGN;
58712+ blocked = sigismember(&t->blocked, sig);
58713+ if (blocked || ignored) {
58714+ action->sa.sa_handler = SIG_DFL;
58715+ if (blocked) {
58716+ sigdelset(&t->blocked, sig);
58717+ recalc_sigpending_and_wake(t);
58718+ }
58719+ }
58720+ if (action->sa.sa_handler == SIG_DFL)
58721+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
58722+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58723+
58724+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
58725+
58726+ return ret;
58727+}
58728+#endif
58729+
58730+#ifdef CONFIG_GRKERNSEC_BRUTE
58731+#define GR_USER_BAN_TIME (15 * 60)
58732+
58733+static int __get_dumpable(unsigned long mm_flags)
58734+{
58735+ int ret;
58736+
58737+ ret = mm_flags & MMF_DUMPABLE_MASK;
58738+ return (ret >= 2) ? 2 : ret;
58739+}
58740+#endif
58741+
58742+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58743+{
58744+#ifdef CONFIG_GRKERNSEC_BRUTE
58745+ kuid_t uid = GLOBAL_ROOT_UID;
58746+
58747+ if (!grsec_enable_brute)
58748+ return;
58749+
58750+ rcu_read_lock();
58751+ read_lock(&tasklist_lock);
58752+ read_lock(&grsec_exec_file_lock);
58753+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58754+ p->real_parent->brute = 1;
58755+ else {
58756+ const struct cred *cred = __task_cred(p), *cred2;
58757+ struct task_struct *tsk, *tsk2;
58758+
58759+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58760+ struct user_struct *user;
58761+
58762+ uid = cred->uid;
58763+
58764+ /* this is put upon execution past expiration */
58765+ user = find_user(uid);
58766+ if (user == NULL)
58767+ goto unlock;
58768+ user->banned = 1;
58769+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58770+ if (user->ban_expires == ~0UL)
58771+ user->ban_expires--;
58772+
58773+ do_each_thread(tsk2, tsk) {
58774+ cred2 = __task_cred(tsk);
58775+ if (tsk != p && uid_eq(cred2->uid, uid))
58776+ gr_fake_force_sig(SIGKILL, tsk);
58777+ } while_each_thread(tsk2, tsk);
58778+ }
58779+ }
58780+unlock:
58781+ read_unlock(&grsec_exec_file_lock);
58782+ read_unlock(&tasklist_lock);
58783+ rcu_read_unlock();
58784+
58785+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
58786+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
58787+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
58788+
58789+#endif
58790+ return;
58791+}
58792+
58793+void gr_handle_brute_check(void)
58794+{
58795+#ifdef CONFIG_GRKERNSEC_BRUTE
58796+ if (current->brute)
58797+ msleep(30 * 1000);
58798+#endif
58799+ return;
58800+}
58801+
58802+void gr_handle_kernel_exploit(void)
58803+{
58804+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58805+ const struct cred *cred;
58806+ struct task_struct *tsk, *tsk2;
58807+ struct user_struct *user;
58808+ kuid_t uid;
58809+
58810+ if (in_irq() || in_serving_softirq() || in_nmi())
58811+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58812+
58813+ uid = current_uid();
58814+
58815+ if (uid_eq(uid, GLOBAL_ROOT_UID))
58816+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
58817+ else {
58818+ /* kill all the processes of this user, hold a reference
58819+ to their creds struct, and prevent them from creating
58820+ another process until system reset
58821+ */
58822+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
58823+ from_kuid_munged(&init_user_ns, uid));
58824+ /* we intentionally leak this ref */
58825+ user = get_uid(current->cred->user);
58826+ if (user) {
58827+ user->banned = 1;
58828+ user->ban_expires = ~0UL;
58829+ }
58830+
58831+ read_lock(&tasklist_lock);
58832+ do_each_thread(tsk2, tsk) {
58833+ cred = __task_cred(tsk);
58834+ if (uid_eq(cred->uid, uid))
58835+ gr_fake_force_sig(SIGKILL, tsk);
58836+ } while_each_thread(tsk2, tsk);
58837+ read_unlock(&tasklist_lock);
58838+ }
58839+#endif
58840+}
58841+
58842+int __gr_process_user_ban(struct user_struct *user)
58843+{
58844+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58845+ if (unlikely(user->banned)) {
58846+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58847+ user->banned = 0;
58848+ user->ban_expires = 0;
58849+ free_uid(user);
58850+ } else
58851+ return -EPERM;
58852+ }
58853+#endif
58854+ return 0;
58855+}
58856+
58857+int gr_process_user_ban(void)
58858+{
58859+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58860+ return __gr_process_user_ban(current->cred->user);
58861+#endif
58862+ return 0;
58863+}
58864diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58865new file mode 100644
58866index 0000000..4030d57
58867--- /dev/null
58868+++ b/grsecurity/grsec_sock.c
58869@@ -0,0 +1,244 @@
58870+#include <linux/kernel.h>
58871+#include <linux/module.h>
58872+#include <linux/sched.h>
58873+#include <linux/file.h>
58874+#include <linux/net.h>
58875+#include <linux/in.h>
58876+#include <linux/ip.h>
58877+#include <net/sock.h>
58878+#include <net/inet_sock.h>
58879+#include <linux/grsecurity.h>
58880+#include <linux/grinternal.h>
58881+#include <linux/gracl.h>
58882+
58883+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58884+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58885+
58886+EXPORT_SYMBOL(gr_search_udp_recvmsg);
58887+EXPORT_SYMBOL(gr_search_udp_sendmsg);
58888+
58889+#ifdef CONFIG_UNIX_MODULE
58890+EXPORT_SYMBOL(gr_acl_handle_unix);
58891+EXPORT_SYMBOL(gr_acl_handle_mknod);
58892+EXPORT_SYMBOL(gr_handle_chroot_unix);
58893+EXPORT_SYMBOL(gr_handle_create);
58894+#endif
58895+
58896+#ifdef CONFIG_GRKERNSEC
58897+#define gr_conn_table_size 32749
58898+struct conn_table_entry {
58899+ struct conn_table_entry *next;
58900+ struct signal_struct *sig;
58901+};
58902+
58903+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58904+DEFINE_SPINLOCK(gr_conn_table_lock);
58905+
58906+extern const char * gr_socktype_to_name(unsigned char type);
58907+extern const char * gr_proto_to_name(unsigned char proto);
58908+extern const char * gr_sockfamily_to_name(unsigned char family);
58909+
58910+static __inline__ int
58911+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58912+{
58913+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58914+}
58915+
58916+static __inline__ int
58917+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58918+ __u16 sport, __u16 dport)
58919+{
58920+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58921+ sig->gr_sport == sport && sig->gr_dport == dport))
58922+ return 1;
58923+ else
58924+ return 0;
58925+}
58926+
58927+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58928+{
58929+ struct conn_table_entry **match;
58930+ unsigned int index;
58931+
58932+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58933+ sig->gr_sport, sig->gr_dport,
58934+ gr_conn_table_size);
58935+
58936+ newent->sig = sig;
58937+
58938+ match = &gr_conn_table[index];
58939+ newent->next = *match;
58940+ *match = newent;
58941+
58942+ return;
58943+}
58944+
58945+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58946+{
58947+ struct conn_table_entry *match, *last = NULL;
58948+ unsigned int index;
58949+
58950+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58951+ sig->gr_sport, sig->gr_dport,
58952+ gr_conn_table_size);
58953+
58954+ match = gr_conn_table[index];
58955+ while (match && !conn_match(match->sig,
58956+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58957+ sig->gr_dport)) {
58958+ last = match;
58959+ match = match->next;
58960+ }
58961+
58962+ if (match) {
58963+ if (last)
58964+ last->next = match->next;
58965+ else
58966+ gr_conn_table[index] = NULL;
58967+ kfree(match);
58968+ }
58969+
58970+ return;
58971+}
58972+
58973+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58974+ __u16 sport, __u16 dport)
58975+{
58976+ struct conn_table_entry *match;
58977+ unsigned int index;
58978+
58979+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58980+
58981+ match = gr_conn_table[index];
58982+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58983+ match = match->next;
58984+
58985+ if (match)
58986+ return match->sig;
58987+ else
58988+ return NULL;
58989+}
58990+
58991+#endif
58992+
58993+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58994+{
58995+#ifdef CONFIG_GRKERNSEC
58996+ struct signal_struct *sig = task->signal;
58997+ struct conn_table_entry *newent;
58998+
58999+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59000+ if (newent == NULL)
59001+ return;
59002+ /* no bh lock needed since we are called with bh disabled */
59003+ spin_lock(&gr_conn_table_lock);
59004+ gr_del_task_from_ip_table_nolock(sig);
59005+ sig->gr_saddr = inet->inet_rcv_saddr;
59006+ sig->gr_daddr = inet->inet_daddr;
59007+ sig->gr_sport = inet->inet_sport;
59008+ sig->gr_dport = inet->inet_dport;
59009+ gr_add_to_task_ip_table_nolock(sig, newent);
59010+ spin_unlock(&gr_conn_table_lock);
59011+#endif
59012+ return;
59013+}
59014+
59015+void gr_del_task_from_ip_table(struct task_struct *task)
59016+{
59017+#ifdef CONFIG_GRKERNSEC
59018+ spin_lock_bh(&gr_conn_table_lock);
59019+ gr_del_task_from_ip_table_nolock(task->signal);
59020+ spin_unlock_bh(&gr_conn_table_lock);
59021+#endif
59022+ return;
59023+}
59024+
59025+void
59026+gr_attach_curr_ip(const struct sock *sk)
59027+{
59028+#ifdef CONFIG_GRKERNSEC
59029+ struct signal_struct *p, *set;
59030+ const struct inet_sock *inet = inet_sk(sk);
59031+
59032+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59033+ return;
59034+
59035+ set = current->signal;
59036+
59037+ spin_lock_bh(&gr_conn_table_lock);
59038+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59039+ inet->inet_dport, inet->inet_sport);
59040+ if (unlikely(p != NULL)) {
59041+ set->curr_ip = p->curr_ip;
59042+ set->used_accept = 1;
59043+ gr_del_task_from_ip_table_nolock(p);
59044+ spin_unlock_bh(&gr_conn_table_lock);
59045+ return;
59046+ }
59047+ spin_unlock_bh(&gr_conn_table_lock);
59048+
59049+ set->curr_ip = inet->inet_daddr;
59050+ set->used_accept = 1;
59051+#endif
59052+ return;
59053+}
59054+
59055+int
59056+gr_handle_sock_all(const int family, const int type, const int protocol)
59057+{
59058+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59059+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59060+ (family != AF_UNIX)) {
59061+ if (family == AF_INET)
59062+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59063+ else
59064+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59065+ return -EACCES;
59066+ }
59067+#endif
59068+ return 0;
59069+}
59070+
59071+int
59072+gr_handle_sock_server(const struct sockaddr *sck)
59073+{
59074+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59075+ if (grsec_enable_socket_server &&
59076+ in_group_p(grsec_socket_server_gid) &&
59077+ sck && (sck->sa_family != AF_UNIX) &&
59078+ (sck->sa_family != AF_LOCAL)) {
59079+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59080+ return -EACCES;
59081+ }
59082+#endif
59083+ return 0;
59084+}
59085+
59086+int
59087+gr_handle_sock_server_other(const struct sock *sck)
59088+{
59089+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59090+ if (grsec_enable_socket_server &&
59091+ in_group_p(grsec_socket_server_gid) &&
59092+ sck && (sck->sk_family != AF_UNIX) &&
59093+ (sck->sk_family != AF_LOCAL)) {
59094+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59095+ return -EACCES;
59096+ }
59097+#endif
59098+ return 0;
59099+}
59100+
59101+int
59102+gr_handle_sock_client(const struct sockaddr *sck)
59103+{
59104+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59105+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59106+ sck && (sck->sa_family != AF_UNIX) &&
59107+ (sck->sa_family != AF_LOCAL)) {
59108+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59109+ return -EACCES;
59110+ }
59111+#endif
59112+ return 0;
59113+}
59114diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59115new file mode 100644
59116index 0000000..f55ef0f
59117--- /dev/null
59118+++ b/grsecurity/grsec_sysctl.c
59119@@ -0,0 +1,469 @@
59120+#include <linux/kernel.h>
59121+#include <linux/sched.h>
59122+#include <linux/sysctl.h>
59123+#include <linux/grsecurity.h>
59124+#include <linux/grinternal.h>
59125+
59126+int
59127+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59128+{
59129+#ifdef CONFIG_GRKERNSEC_SYSCTL
59130+ if (dirname == NULL || name == NULL)
59131+ return 0;
59132+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59133+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59134+ return -EACCES;
59135+ }
59136+#endif
59137+ return 0;
59138+}
59139+
59140+#ifdef CONFIG_GRKERNSEC_ROFS
59141+static int __maybe_unused one = 1;
59142+#endif
59143+
59144+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59145+struct ctl_table grsecurity_table[] = {
59146+#ifdef CONFIG_GRKERNSEC_SYSCTL
59147+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59148+#ifdef CONFIG_GRKERNSEC_IO
59149+ {
59150+ .procname = "disable_priv_io",
59151+ .data = &grsec_disable_privio,
59152+ .maxlen = sizeof(int),
59153+ .mode = 0600,
59154+ .proc_handler = &proc_dointvec,
59155+ },
59156+#endif
59157+#endif
59158+#ifdef CONFIG_GRKERNSEC_LINK
59159+ {
59160+ .procname = "linking_restrictions",
59161+ .data = &grsec_enable_link,
59162+ .maxlen = sizeof(int),
59163+ .mode = 0600,
59164+ .proc_handler = &proc_dointvec,
59165+ },
59166+#endif
59167+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59168+ {
59169+ .procname = "enforce_symlinksifowner",
59170+ .data = &grsec_enable_symlinkown,
59171+ .maxlen = sizeof(int),
59172+ .mode = 0600,
59173+ .proc_handler = &proc_dointvec,
59174+ },
59175+ {
59176+ .procname = "symlinkown_gid",
59177+ .data = &grsec_symlinkown_gid,
59178+ .maxlen = sizeof(int),
59179+ .mode = 0600,
59180+ .proc_handler = &proc_dointvec,
59181+ },
59182+#endif
59183+#ifdef CONFIG_GRKERNSEC_BRUTE
59184+ {
59185+ .procname = "deter_bruteforce",
59186+ .data = &grsec_enable_brute,
59187+ .maxlen = sizeof(int),
59188+ .mode = 0600,
59189+ .proc_handler = &proc_dointvec,
59190+ },
59191+#endif
59192+#ifdef CONFIG_GRKERNSEC_FIFO
59193+ {
59194+ .procname = "fifo_restrictions",
59195+ .data = &grsec_enable_fifo,
59196+ .maxlen = sizeof(int),
59197+ .mode = 0600,
59198+ .proc_handler = &proc_dointvec,
59199+ },
59200+#endif
59201+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59202+ {
59203+ .procname = "ptrace_readexec",
59204+ .data = &grsec_enable_ptrace_readexec,
59205+ .maxlen = sizeof(int),
59206+ .mode = 0600,
59207+ .proc_handler = &proc_dointvec,
59208+ },
59209+#endif
59210+#ifdef CONFIG_GRKERNSEC_SETXID
59211+ {
59212+ .procname = "consistent_setxid",
59213+ .data = &grsec_enable_setxid,
59214+ .maxlen = sizeof(int),
59215+ .mode = 0600,
59216+ .proc_handler = &proc_dointvec,
59217+ },
59218+#endif
59219+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59220+ {
59221+ .procname = "ip_blackhole",
59222+ .data = &grsec_enable_blackhole,
59223+ .maxlen = sizeof(int),
59224+ .mode = 0600,
59225+ .proc_handler = &proc_dointvec,
59226+ },
59227+ {
59228+ .procname = "lastack_retries",
59229+ .data = &grsec_lastack_retries,
59230+ .maxlen = sizeof(int),
59231+ .mode = 0600,
59232+ .proc_handler = &proc_dointvec,
59233+ },
59234+#endif
59235+#ifdef CONFIG_GRKERNSEC_EXECLOG
59236+ {
59237+ .procname = "exec_logging",
59238+ .data = &grsec_enable_execlog,
59239+ .maxlen = sizeof(int),
59240+ .mode = 0600,
59241+ .proc_handler = &proc_dointvec,
59242+ },
59243+#endif
59244+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59245+ {
59246+ .procname = "rwxmap_logging",
59247+ .data = &grsec_enable_log_rwxmaps,
59248+ .maxlen = sizeof(int),
59249+ .mode = 0600,
59250+ .proc_handler = &proc_dointvec,
59251+ },
59252+#endif
59253+#ifdef CONFIG_GRKERNSEC_SIGNAL
59254+ {
59255+ .procname = "signal_logging",
59256+ .data = &grsec_enable_signal,
59257+ .maxlen = sizeof(int),
59258+ .mode = 0600,
59259+ .proc_handler = &proc_dointvec,
59260+ },
59261+#endif
59262+#ifdef CONFIG_GRKERNSEC_FORKFAIL
59263+ {
59264+ .procname = "forkfail_logging",
59265+ .data = &grsec_enable_forkfail,
59266+ .maxlen = sizeof(int),
59267+ .mode = 0600,
59268+ .proc_handler = &proc_dointvec,
59269+ },
59270+#endif
59271+#ifdef CONFIG_GRKERNSEC_TIME
59272+ {
59273+ .procname = "timechange_logging",
59274+ .data = &grsec_enable_time,
59275+ .maxlen = sizeof(int),
59276+ .mode = 0600,
59277+ .proc_handler = &proc_dointvec,
59278+ },
59279+#endif
59280+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59281+ {
59282+ .procname = "chroot_deny_shmat",
59283+ .data = &grsec_enable_chroot_shmat,
59284+ .maxlen = sizeof(int),
59285+ .mode = 0600,
59286+ .proc_handler = &proc_dointvec,
59287+ },
59288+#endif
59289+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59290+ {
59291+ .procname = "chroot_deny_unix",
59292+ .data = &grsec_enable_chroot_unix,
59293+ .maxlen = sizeof(int),
59294+ .mode = 0600,
59295+ .proc_handler = &proc_dointvec,
59296+ },
59297+#endif
59298+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59299+ {
59300+ .procname = "chroot_deny_mount",
59301+ .data = &grsec_enable_chroot_mount,
59302+ .maxlen = sizeof(int),
59303+ .mode = 0600,
59304+ .proc_handler = &proc_dointvec,
59305+ },
59306+#endif
59307+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59308+ {
59309+ .procname = "chroot_deny_fchdir",
59310+ .data = &grsec_enable_chroot_fchdir,
59311+ .maxlen = sizeof(int),
59312+ .mode = 0600,
59313+ .proc_handler = &proc_dointvec,
59314+ },
59315+#endif
59316+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59317+ {
59318+ .procname = "chroot_deny_chroot",
59319+ .data = &grsec_enable_chroot_double,
59320+ .maxlen = sizeof(int),
59321+ .mode = 0600,
59322+ .proc_handler = &proc_dointvec,
59323+ },
59324+#endif
59325+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59326+ {
59327+ .procname = "chroot_deny_pivot",
59328+ .data = &grsec_enable_chroot_pivot,
59329+ .maxlen = sizeof(int),
59330+ .mode = 0600,
59331+ .proc_handler = &proc_dointvec,
59332+ },
59333+#endif
59334+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59335+ {
59336+ .procname = "chroot_enforce_chdir",
59337+ .data = &grsec_enable_chroot_chdir,
59338+ .maxlen = sizeof(int),
59339+ .mode = 0600,
59340+ .proc_handler = &proc_dointvec,
59341+ },
59342+#endif
59343+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59344+ {
59345+ .procname = "chroot_deny_chmod",
59346+ .data = &grsec_enable_chroot_chmod,
59347+ .maxlen = sizeof(int),
59348+ .mode = 0600,
59349+ .proc_handler = &proc_dointvec,
59350+ },
59351+#endif
59352+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59353+ {
59354+ .procname = "chroot_deny_mknod",
59355+ .data = &grsec_enable_chroot_mknod,
59356+ .maxlen = sizeof(int),
59357+ .mode = 0600,
59358+ .proc_handler = &proc_dointvec,
59359+ },
59360+#endif
59361+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59362+ {
59363+ .procname = "chroot_restrict_nice",
59364+ .data = &grsec_enable_chroot_nice,
59365+ .maxlen = sizeof(int),
59366+ .mode = 0600,
59367+ .proc_handler = &proc_dointvec,
59368+ },
59369+#endif
59370+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59371+ {
59372+ .procname = "chroot_execlog",
59373+ .data = &grsec_enable_chroot_execlog,
59374+ .maxlen = sizeof(int),
59375+ .mode = 0600,
59376+ .proc_handler = &proc_dointvec,
59377+ },
59378+#endif
59379+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59380+ {
59381+ .procname = "chroot_caps",
59382+ .data = &grsec_enable_chroot_caps,
59383+ .maxlen = sizeof(int),
59384+ .mode = 0600,
59385+ .proc_handler = &proc_dointvec,
59386+ },
59387+#endif
59388+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59389+ {
59390+ .procname = "chroot_deny_sysctl",
59391+ .data = &grsec_enable_chroot_sysctl,
59392+ .maxlen = sizeof(int),
59393+ .mode = 0600,
59394+ .proc_handler = &proc_dointvec,
59395+ },
59396+#endif
59397+#ifdef CONFIG_GRKERNSEC_TPE
59398+ {
59399+ .procname = "tpe",
59400+ .data = &grsec_enable_tpe,
59401+ .maxlen = sizeof(int),
59402+ .mode = 0600,
59403+ .proc_handler = &proc_dointvec,
59404+ },
59405+ {
59406+ .procname = "tpe_gid",
59407+ .data = &grsec_tpe_gid,
59408+ .maxlen = sizeof(int),
59409+ .mode = 0600,
59410+ .proc_handler = &proc_dointvec,
59411+ },
59412+#endif
59413+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59414+ {
59415+ .procname = "tpe_invert",
59416+ .data = &grsec_enable_tpe_invert,
59417+ .maxlen = sizeof(int),
59418+ .mode = 0600,
59419+ .proc_handler = &proc_dointvec,
59420+ },
59421+#endif
59422+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59423+ {
59424+ .procname = "tpe_restrict_all",
59425+ .data = &grsec_enable_tpe_all,
59426+ .maxlen = sizeof(int),
59427+ .mode = 0600,
59428+ .proc_handler = &proc_dointvec,
59429+ },
59430+#endif
59431+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59432+ {
59433+ .procname = "socket_all",
59434+ .data = &grsec_enable_socket_all,
59435+ .maxlen = sizeof(int),
59436+ .mode = 0600,
59437+ .proc_handler = &proc_dointvec,
59438+ },
59439+ {
59440+ .procname = "socket_all_gid",
59441+ .data = &grsec_socket_all_gid,
59442+ .maxlen = sizeof(int),
59443+ .mode = 0600,
59444+ .proc_handler = &proc_dointvec,
59445+ },
59446+#endif
59447+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59448+ {
59449+ .procname = "socket_client",
59450+ .data = &grsec_enable_socket_client,
59451+ .maxlen = sizeof(int),
59452+ .mode = 0600,
59453+ .proc_handler = &proc_dointvec,
59454+ },
59455+ {
59456+ .procname = "socket_client_gid",
59457+ .data = &grsec_socket_client_gid,
59458+ .maxlen = sizeof(int),
59459+ .mode = 0600,
59460+ .proc_handler = &proc_dointvec,
59461+ },
59462+#endif
59463+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59464+ {
59465+ .procname = "socket_server",
59466+ .data = &grsec_enable_socket_server,
59467+ .maxlen = sizeof(int),
59468+ .mode = 0600,
59469+ .proc_handler = &proc_dointvec,
59470+ },
59471+ {
59472+ .procname = "socket_server_gid",
59473+ .data = &grsec_socket_server_gid,
59474+ .maxlen = sizeof(int),
59475+ .mode = 0600,
59476+ .proc_handler = &proc_dointvec,
59477+ },
59478+#endif
59479+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59480+ {
59481+ .procname = "audit_group",
59482+ .data = &grsec_enable_group,
59483+ .maxlen = sizeof(int),
59484+ .mode = 0600,
59485+ .proc_handler = &proc_dointvec,
59486+ },
59487+ {
59488+ .procname = "audit_gid",
59489+ .data = &grsec_audit_gid,
59490+ .maxlen = sizeof(int),
59491+ .mode = 0600,
59492+ .proc_handler = &proc_dointvec,
59493+ },
59494+#endif
59495+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59496+ {
59497+ .procname = "audit_chdir",
59498+ .data = &grsec_enable_chdir,
59499+ .maxlen = sizeof(int),
59500+ .mode = 0600,
59501+ .proc_handler = &proc_dointvec,
59502+ },
59503+#endif
59504+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59505+ {
59506+ .procname = "audit_mount",
59507+ .data = &grsec_enable_mount,
59508+ .maxlen = sizeof(int),
59509+ .mode = 0600,
59510+ .proc_handler = &proc_dointvec,
59511+ },
59512+#endif
59513+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59514+ {
59515+ .procname = "audit_textrel",
59516+ .data = &grsec_enable_audit_textrel,
59517+ .maxlen = sizeof(int),
59518+ .mode = 0600,
59519+ .proc_handler = &proc_dointvec,
59520+ },
59521+#endif
59522+#ifdef CONFIG_GRKERNSEC_DMESG
59523+ {
59524+ .procname = "dmesg",
59525+ .data = &grsec_enable_dmesg,
59526+ .maxlen = sizeof(int),
59527+ .mode = 0600,
59528+ .proc_handler = &proc_dointvec,
59529+ },
59530+#endif
59531+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59532+ {
59533+ .procname = "chroot_findtask",
59534+ .data = &grsec_enable_chroot_findtask,
59535+ .maxlen = sizeof(int),
59536+ .mode = 0600,
59537+ .proc_handler = &proc_dointvec,
59538+ },
59539+#endif
59540+#ifdef CONFIG_GRKERNSEC_RESLOG
59541+ {
59542+ .procname = "resource_logging",
59543+ .data = &grsec_resource_logging,
59544+ .maxlen = sizeof(int),
59545+ .mode = 0600,
59546+ .proc_handler = &proc_dointvec,
59547+ },
59548+#endif
59549+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59550+ {
59551+ .procname = "audit_ptrace",
59552+ .data = &grsec_enable_audit_ptrace,
59553+ .maxlen = sizeof(int),
59554+ .mode = 0600,
59555+ .proc_handler = &proc_dointvec,
59556+ },
59557+#endif
59558+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59559+ {
59560+ .procname = "harden_ptrace",
59561+ .data = &grsec_enable_harden_ptrace,
59562+ .maxlen = sizeof(int),
59563+ .mode = 0600,
59564+ .proc_handler = &proc_dointvec,
59565+ },
59566+#endif
59567+ {
59568+ .procname = "grsec_lock",
59569+ .data = &grsec_lock,
59570+ .maxlen = sizeof(int),
59571+ .mode = 0600,
59572+ .proc_handler = &proc_dointvec,
59573+ },
59574+#endif
59575+#ifdef CONFIG_GRKERNSEC_ROFS
59576+ {
59577+ .procname = "romount_protect",
59578+ .data = &grsec_enable_rofs,
59579+ .maxlen = sizeof(int),
59580+ .mode = 0600,
59581+ .proc_handler = &proc_dointvec_minmax,
59582+ .extra1 = &one,
59583+ .extra2 = &one,
59584+ },
59585+#endif
59586+ { }
59587+};
59588+#endif
59589diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59590new file mode 100644
59591index 0000000..0dc13c3
59592--- /dev/null
59593+++ b/grsecurity/grsec_time.c
59594@@ -0,0 +1,16 @@
59595+#include <linux/kernel.h>
59596+#include <linux/sched.h>
59597+#include <linux/grinternal.h>
59598+#include <linux/module.h>
59599+
59600+void
59601+gr_log_timechange(void)
59602+{
59603+#ifdef CONFIG_GRKERNSEC_TIME
59604+ if (grsec_enable_time)
59605+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59606+#endif
59607+ return;
59608+}
59609+
59610+EXPORT_SYMBOL(gr_log_timechange);
59611diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59612new file mode 100644
59613index 0000000..07e0dc0
59614--- /dev/null
59615+++ b/grsecurity/grsec_tpe.c
59616@@ -0,0 +1,73 @@
59617+#include <linux/kernel.h>
59618+#include <linux/sched.h>
59619+#include <linux/file.h>
59620+#include <linux/fs.h>
59621+#include <linux/grinternal.h>
59622+
59623+extern int gr_acl_tpe_check(void);
59624+
59625+int
59626+gr_tpe_allow(const struct file *file)
59627+{
59628+#ifdef CONFIG_GRKERNSEC
59629+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59630+ const struct cred *cred = current_cred();
59631+ char *msg = NULL;
59632+ char *msg2 = NULL;
59633+
59634+ // never restrict root
59635+ if (!cred->uid)
59636+ return 1;
59637+
59638+ if (grsec_enable_tpe) {
59639+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59640+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59641+ msg = "not being in trusted group";
59642+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59643+ msg = "being in untrusted group";
59644+#else
59645+ if (in_group_p(grsec_tpe_gid))
59646+ msg = "being in untrusted group";
59647+#endif
59648+ }
59649+ if (!msg && gr_acl_tpe_check())
59650+ msg = "being in untrusted role";
59651+
59652+ // not in any affected group/role
59653+ if (!msg)
59654+ goto next_check;
59655+
59656+ if (inode->i_uid)
59657+ msg2 = "file in non-root-owned directory";
59658+ else if (inode->i_mode & S_IWOTH)
59659+ msg2 = "file in world-writable directory";
59660+ else if (inode->i_mode & S_IWGRP)
59661+ msg2 = "file in group-writable directory";
59662+
59663+ if (msg && msg2) {
59664+ char fullmsg[70] = {0};
59665+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59666+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59667+ return 0;
59668+ }
59669+ msg = NULL;
59670+next_check:
59671+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59672+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59673+ return 1;
59674+
59675+ if (inode->i_uid && (inode->i_uid != cred->uid))
59676+ msg = "directory not owned by user";
59677+ else if (inode->i_mode & S_IWOTH)
59678+ msg = "file in world-writable directory";
59679+ else if (inode->i_mode & S_IWGRP)
59680+ msg = "file in group-writable directory";
59681+
59682+ if (msg) {
59683+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59684+ return 0;
59685+ }
59686+#endif
59687+#endif
59688+ return 1;
59689+}
59690diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59691new file mode 100644
59692index 0000000..9f7b1ac
59693--- /dev/null
59694+++ b/grsecurity/grsum.c
59695@@ -0,0 +1,61 @@
59696+#include <linux/err.h>
59697+#include <linux/kernel.h>
59698+#include <linux/sched.h>
59699+#include <linux/mm.h>
59700+#include <linux/scatterlist.h>
59701+#include <linux/crypto.h>
59702+#include <linux/gracl.h>
59703+
59704+
59705+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59706+#error "crypto and sha256 must be built into the kernel"
59707+#endif
59708+
59709+int
59710+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59711+{
59712+ char *p;
59713+ struct crypto_hash *tfm;
59714+ struct hash_desc desc;
59715+ struct scatterlist sg;
59716+ unsigned char temp_sum[GR_SHA_LEN];
59717+ volatile int retval = 0;
59718+ volatile int dummy = 0;
59719+ unsigned int i;
59720+
59721+ sg_init_table(&sg, 1);
59722+
59723+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59724+ if (IS_ERR(tfm)) {
59725+ /* should never happen, since sha256 should be built in */
59726+ return 1;
59727+ }
59728+
59729+ desc.tfm = tfm;
59730+ desc.flags = 0;
59731+
59732+ crypto_hash_init(&desc);
59733+
59734+ p = salt;
59735+ sg_set_buf(&sg, p, GR_SALT_LEN);
59736+ crypto_hash_update(&desc, &sg, sg.length);
59737+
59738+ p = entry->pw;
59739+ sg_set_buf(&sg, p, strlen(p));
59740+
59741+ crypto_hash_update(&desc, &sg, sg.length);
59742+
59743+ crypto_hash_final(&desc, temp_sum);
59744+
59745+ memset(entry->pw, 0, GR_PW_LEN);
59746+
59747+ for (i = 0; i < GR_SHA_LEN; i++)
59748+ if (sum[i] != temp_sum[i])
59749+ retval = 1;
59750+ else
59751+ dummy = 1; // waste a cycle
59752+
59753+ crypto_free_hash(tfm);
59754+
59755+ return retval;
59756+}
59757diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59758index 9e6e1c6..d47b906 100644
59759--- a/include/acpi/acpi_bus.h
59760+++ b/include/acpi/acpi_bus.h
59761@@ -138,7 +138,7 @@ struct acpi_device_ops {
59762 acpi_op_bind bind;
59763 acpi_op_unbind unbind;
59764 acpi_op_notify notify;
59765-};
59766+} __no_const;
59767
59768 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59769
59770diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59771index b7babf0..3ba8aee 100644
59772--- a/include/asm-generic/atomic-long.h
59773+++ b/include/asm-generic/atomic-long.h
59774@@ -22,6 +22,12 @@
59775
59776 typedef atomic64_t atomic_long_t;
59777
59778+#ifdef CONFIG_PAX_REFCOUNT
59779+typedef atomic64_unchecked_t atomic_long_unchecked_t;
59780+#else
59781+typedef atomic64_t atomic_long_unchecked_t;
59782+#endif
59783+
59784 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59785
59786 static inline long atomic_long_read(atomic_long_t *l)
59787@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59788 return (long)atomic64_read(v);
59789 }
59790
59791+#ifdef CONFIG_PAX_REFCOUNT
59792+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59793+{
59794+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59795+
59796+ return (long)atomic64_read_unchecked(v);
59797+}
59798+#endif
59799+
59800 static inline void atomic_long_set(atomic_long_t *l, long i)
59801 {
59802 atomic64_t *v = (atomic64_t *)l;
59803@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59804 atomic64_set(v, i);
59805 }
59806
59807+#ifdef CONFIG_PAX_REFCOUNT
59808+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59809+{
59810+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59811+
59812+ atomic64_set_unchecked(v, i);
59813+}
59814+#endif
59815+
59816 static inline void atomic_long_inc(atomic_long_t *l)
59817 {
59818 atomic64_t *v = (atomic64_t *)l;
59819@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59820 atomic64_inc(v);
59821 }
59822
59823+#ifdef CONFIG_PAX_REFCOUNT
59824+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59825+{
59826+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59827+
59828+ atomic64_inc_unchecked(v);
59829+}
59830+#endif
59831+
59832 static inline void atomic_long_dec(atomic_long_t *l)
59833 {
59834 atomic64_t *v = (atomic64_t *)l;
59835@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59836 atomic64_dec(v);
59837 }
59838
59839+#ifdef CONFIG_PAX_REFCOUNT
59840+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59841+{
59842+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59843+
59844+ atomic64_dec_unchecked(v);
59845+}
59846+#endif
59847+
59848 static inline void atomic_long_add(long i, atomic_long_t *l)
59849 {
59850 atomic64_t *v = (atomic64_t *)l;
59851@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59852 atomic64_add(i, v);
59853 }
59854
59855+#ifdef CONFIG_PAX_REFCOUNT
59856+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59857+{
59858+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59859+
59860+ atomic64_add_unchecked(i, v);
59861+}
59862+#endif
59863+
59864 static inline void atomic_long_sub(long i, atomic_long_t *l)
59865 {
59866 atomic64_t *v = (atomic64_t *)l;
59867@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59868 atomic64_sub(i, v);
59869 }
59870
59871+#ifdef CONFIG_PAX_REFCOUNT
59872+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59873+{
59874+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59875+
59876+ atomic64_sub_unchecked(i, v);
59877+}
59878+#endif
59879+
59880 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59881 {
59882 atomic64_t *v = (atomic64_t *)l;
59883@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59884 return (long)atomic64_inc_return(v);
59885 }
59886
59887+#ifdef CONFIG_PAX_REFCOUNT
59888+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59889+{
59890+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59891+
59892+ return (long)atomic64_inc_return_unchecked(v);
59893+}
59894+#endif
59895+
59896 static inline long atomic_long_dec_return(atomic_long_t *l)
59897 {
59898 atomic64_t *v = (atomic64_t *)l;
59899@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59900
59901 typedef atomic_t atomic_long_t;
59902
59903+#ifdef CONFIG_PAX_REFCOUNT
59904+typedef atomic_unchecked_t atomic_long_unchecked_t;
59905+#else
59906+typedef atomic_t atomic_long_unchecked_t;
59907+#endif
59908+
59909 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59910 static inline long atomic_long_read(atomic_long_t *l)
59911 {
59912@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59913 return (long)atomic_read(v);
59914 }
59915
59916+#ifdef CONFIG_PAX_REFCOUNT
59917+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59918+{
59919+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59920+
59921+ return (long)atomic_read_unchecked(v);
59922+}
59923+#endif
59924+
59925 static inline void atomic_long_set(atomic_long_t *l, long i)
59926 {
59927 atomic_t *v = (atomic_t *)l;
59928@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59929 atomic_set(v, i);
59930 }
59931
59932+#ifdef CONFIG_PAX_REFCOUNT
59933+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59934+{
59935+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59936+
59937+ atomic_set_unchecked(v, i);
59938+}
59939+#endif
59940+
59941 static inline void atomic_long_inc(atomic_long_t *l)
59942 {
59943 atomic_t *v = (atomic_t *)l;
59944@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59945 atomic_inc(v);
59946 }
59947
59948+#ifdef CONFIG_PAX_REFCOUNT
59949+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59950+{
59951+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59952+
59953+ atomic_inc_unchecked(v);
59954+}
59955+#endif
59956+
59957 static inline void atomic_long_dec(atomic_long_t *l)
59958 {
59959 atomic_t *v = (atomic_t *)l;
59960@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59961 atomic_dec(v);
59962 }
59963
59964+#ifdef CONFIG_PAX_REFCOUNT
59965+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59966+{
59967+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59968+
59969+ atomic_dec_unchecked(v);
59970+}
59971+#endif
59972+
59973 static inline void atomic_long_add(long i, atomic_long_t *l)
59974 {
59975 atomic_t *v = (atomic_t *)l;
59976@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59977 atomic_add(i, v);
59978 }
59979
59980+#ifdef CONFIG_PAX_REFCOUNT
59981+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59982+{
59983+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59984+
59985+ atomic_add_unchecked(i, v);
59986+}
59987+#endif
59988+
59989 static inline void atomic_long_sub(long i, atomic_long_t *l)
59990 {
59991 atomic_t *v = (atomic_t *)l;
59992@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59993 atomic_sub(i, v);
59994 }
59995
59996+#ifdef CONFIG_PAX_REFCOUNT
59997+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59998+{
59999+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60000+
60001+ atomic_sub_unchecked(i, v);
60002+}
60003+#endif
60004+
60005 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60006 {
60007 atomic_t *v = (atomic_t *)l;
60008@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60009 return (long)atomic_inc_return(v);
60010 }
60011
60012+#ifdef CONFIG_PAX_REFCOUNT
60013+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60014+{
60015+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60016+
60017+ return (long)atomic_inc_return_unchecked(v);
60018+}
60019+#endif
60020+
60021 static inline long atomic_long_dec_return(atomic_long_t *l)
60022 {
60023 atomic_t *v = (atomic_t *)l;
60024@@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60025
60026 #endif /* BITS_PER_LONG == 64 */
60027
60028+#ifdef CONFIG_PAX_REFCOUNT
60029+static inline void pax_refcount_needs_these_functions(void)
60030+{
60031+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
60032+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60033+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60034+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60035+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60036+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60037+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60038+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60039+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60040+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60041+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60042+#ifdef CONFIG_X86
60043+ atomic_clear_mask_unchecked(0, NULL);
60044+ atomic_set_mask_unchecked(0, NULL);
60045+#endif
60046+
60047+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60048+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60049+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60050+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60051+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60052+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60053+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60054+}
60055+#else
60056+#define atomic_read_unchecked(v) atomic_read(v)
60057+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60058+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60059+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60060+#define atomic_inc_unchecked(v) atomic_inc(v)
60061+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60062+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60063+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60064+#define atomic_dec_unchecked(v) atomic_dec(v)
60065+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60066+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60067+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60068+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60069+
60070+#define atomic_long_read_unchecked(v) atomic_long_read(v)
60071+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60072+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60073+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60074+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60075+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60076+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60077+#endif
60078+
60079 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60080diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60081index 1ced641..c896ee8 100644
60082--- a/include/asm-generic/atomic.h
60083+++ b/include/asm-generic/atomic.h
60084@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60085 * Atomically clears the bits set in @mask from @v
60086 */
60087 #ifndef atomic_clear_mask
60088-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60089+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60090 {
60091 unsigned long flags;
60092
60093diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60094index b18ce4f..2ee2843 100644
60095--- a/include/asm-generic/atomic64.h
60096+++ b/include/asm-generic/atomic64.h
60097@@ -16,6 +16,8 @@ typedef struct {
60098 long long counter;
60099 } atomic64_t;
60100
60101+typedef atomic64_t atomic64_unchecked_t;
60102+
60103 #define ATOMIC64_INIT(i) { (i) }
60104
60105 extern long long atomic64_read(const atomic64_t *v);
60106@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60107 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60108 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60109
60110+#define atomic64_read_unchecked(v) atomic64_read(v)
60111+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60112+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60113+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60114+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60115+#define atomic64_inc_unchecked(v) atomic64_inc(v)
60116+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60117+#define atomic64_dec_unchecked(v) atomic64_dec(v)
60118+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60119+
60120 #endif /* _ASM_GENERIC_ATOMIC64_H */
60121diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60122index 1bfcfe5..e04c5c9 100644
60123--- a/include/asm-generic/cache.h
60124+++ b/include/asm-generic/cache.h
60125@@ -6,7 +6,7 @@
60126 * cache lines need to provide their own cache.h.
60127 */
60128
60129-#define L1_CACHE_SHIFT 5
60130-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60131+#define L1_CACHE_SHIFT 5UL
60132+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60133
60134 #endif /* __ASM_GENERIC_CACHE_H */
60135diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60136index 0d68a1e..b74a761 100644
60137--- a/include/asm-generic/emergency-restart.h
60138+++ b/include/asm-generic/emergency-restart.h
60139@@ -1,7 +1,7 @@
60140 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60141 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60142
60143-static inline void machine_emergency_restart(void)
60144+static inline __noreturn void machine_emergency_restart(void)
60145 {
60146 machine_restart(NULL);
60147 }
60148diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60149index 0232ccb..13d9165 100644
60150--- a/include/asm-generic/kmap_types.h
60151+++ b/include/asm-generic/kmap_types.h
60152@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60153 KMAP_D(17) KM_NMI,
60154 KMAP_D(18) KM_NMI_PTE,
60155 KMAP_D(19) KM_KDB,
60156+KMAP_D(20) KM_CLEARPAGE,
60157 /*
60158 * Remember to update debug_kmap_atomic() when adding new kmap types!
60159 */
60160-KMAP_D(20) KM_TYPE_NR
60161+KMAP_D(21) KM_TYPE_NR
60162 };
60163
60164 #undef KMAP_D
60165diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60166index 9ceb03b..2efbcbd 100644
60167--- a/include/asm-generic/local.h
60168+++ b/include/asm-generic/local.h
60169@@ -39,6 +39,7 @@ typedef struct
60170 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60171 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60172 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60173+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60174
60175 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60176 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60177diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60178index 725612b..9cc513a 100644
60179--- a/include/asm-generic/pgtable-nopmd.h
60180+++ b/include/asm-generic/pgtable-nopmd.h
60181@@ -1,14 +1,19 @@
60182 #ifndef _PGTABLE_NOPMD_H
60183 #define _PGTABLE_NOPMD_H
60184
60185-#ifndef __ASSEMBLY__
60186-
60187 #include <asm-generic/pgtable-nopud.h>
60188
60189-struct mm_struct;
60190-
60191 #define __PAGETABLE_PMD_FOLDED
60192
60193+#define PMD_SHIFT PUD_SHIFT
60194+#define PTRS_PER_PMD 1
60195+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60196+#define PMD_MASK (~(PMD_SIZE-1))
60197+
60198+#ifndef __ASSEMBLY__
60199+
60200+struct mm_struct;
60201+
60202 /*
60203 * Having the pmd type consist of a pud gets the size right, and allows
60204 * us to conceptually access the pud entry that this pmd is folded into
60205@@ -16,11 +21,6 @@ struct mm_struct;
60206 */
60207 typedef struct { pud_t pud; } pmd_t;
60208
60209-#define PMD_SHIFT PUD_SHIFT
60210-#define PTRS_PER_PMD 1
60211-#define PMD_SIZE (1UL << PMD_SHIFT)
60212-#define PMD_MASK (~(PMD_SIZE-1))
60213-
60214 /*
60215 * The "pud_xxx()" functions here are trivial for a folded two-level
60216 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60217diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60218index 810431d..0ec4804f 100644
60219--- a/include/asm-generic/pgtable-nopud.h
60220+++ b/include/asm-generic/pgtable-nopud.h
60221@@ -1,10 +1,15 @@
60222 #ifndef _PGTABLE_NOPUD_H
60223 #define _PGTABLE_NOPUD_H
60224
60225-#ifndef __ASSEMBLY__
60226-
60227 #define __PAGETABLE_PUD_FOLDED
60228
60229+#define PUD_SHIFT PGDIR_SHIFT
60230+#define PTRS_PER_PUD 1
60231+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60232+#define PUD_MASK (~(PUD_SIZE-1))
60233+
60234+#ifndef __ASSEMBLY__
60235+
60236 /*
60237 * Having the pud type consist of a pgd gets the size right, and allows
60238 * us to conceptually access the pgd entry that this pud is folded into
60239@@ -12,11 +17,6 @@
60240 */
60241 typedef struct { pgd_t pgd; } pud_t;
60242
60243-#define PUD_SHIFT PGDIR_SHIFT
60244-#define PTRS_PER_PUD 1
60245-#define PUD_SIZE (1UL << PUD_SHIFT)
60246-#define PUD_MASK (~(PUD_SIZE-1))
60247-
60248 /*
60249 * The "pgd_xxx()" functions here are trivial for a folded two-level
60250 * setup: the pud is never bad, and a pud always exists (as it's folded
60251@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60252 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60253
60254 #define pgd_populate(mm, pgd, pud) do { } while (0)
60255+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60256 /*
60257 * (puds are folded into pgds so this doesn't get actually called,
60258 * but the define is needed for a generic inline function.)
60259diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60260index ff4947b..f48183f 100644
60261--- a/include/asm-generic/pgtable.h
60262+++ b/include/asm-generic/pgtable.h
60263@@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60264 #endif
60265 }
60266
60267+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60268+static inline unsigned long pax_open_kernel(void) { return 0; }
60269+#endif
60270+
60271+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60272+static inline unsigned long pax_close_kernel(void) { return 0; }
60273+#endif
60274+
60275 #endif /* CONFIG_MMU */
60276
60277 #endif /* !__ASSEMBLY__ */
60278diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60279index 4e2e1cc..12c266b 100644
60280--- a/include/asm-generic/vmlinux.lds.h
60281+++ b/include/asm-generic/vmlinux.lds.h
60282@@ -218,6 +218,7 @@
60283 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60284 VMLINUX_SYMBOL(__start_rodata) = .; \
60285 *(.rodata) *(.rodata.*) \
60286+ *(.data..read_only) \
60287 *(__vermagic) /* Kernel version magic */ \
60288 . = ALIGN(8); \
60289 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60290@@ -716,17 +717,18 @@
60291 * section in the linker script will go there too. @phdr should have
60292 * a leading colon.
60293 *
60294- * Note that this macros defines __per_cpu_load as an absolute symbol.
60295+ * Note that this macros defines per_cpu_load as an absolute symbol.
60296 * If there is no need to put the percpu section at a predetermined
60297 * address, use PERCPU_SECTION.
60298 */
60299 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60300- VMLINUX_SYMBOL(__per_cpu_load) = .; \
60301- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60302+ per_cpu_load = .; \
60303+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60304 - LOAD_OFFSET) { \
60305+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60306 PERCPU_INPUT(cacheline) \
60307 } phdr \
60308- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60309+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60310
60311 /**
60312 * PERCPU_SECTION - define output section for percpu area, simple version
60313diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60314index 31ad880..4e79884 100644
60315--- a/include/drm/drmP.h
60316+++ b/include/drm/drmP.h
60317@@ -72,6 +72,7 @@
60318 #include <linux/workqueue.h>
60319 #include <linux/poll.h>
60320 #include <asm/pgalloc.h>
60321+#include <asm/local.h>
60322 #include "drm.h"
60323
60324 #include <linux/idr.h>
60325@@ -1074,7 +1075,7 @@ struct drm_device {
60326
60327 /** \name Usage Counters */
60328 /*@{ */
60329- int open_count; /**< Outstanding files open */
60330+ local_t open_count; /**< Outstanding files open */
60331 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60332 atomic_t vma_count; /**< Outstanding vma areas open */
60333 int buf_use; /**< Buffers in use -- cannot alloc */
60334@@ -1085,7 +1086,7 @@ struct drm_device {
60335 /*@{ */
60336 unsigned long counters;
60337 enum drm_stat_type types[15];
60338- atomic_t counts[15];
60339+ atomic_unchecked_t counts[15];
60340 /*@} */
60341
60342 struct list_head filelist;
60343diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60344index 7988e55..ec974c9 100644
60345--- a/include/drm/drm_crtc_helper.h
60346+++ b/include/drm/drm_crtc_helper.h
60347@@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60348
60349 /* disable crtc when not in use - more explicit than dpms off */
60350 void (*disable)(struct drm_crtc *crtc);
60351-};
60352+} __no_const;
60353
60354 /**
60355 * drm_encoder_helper_funcs - helper operations for encoders
60356@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60357 struct drm_connector *connector);
60358 /* disable encoder when not in use - more explicit than dpms off */
60359 void (*disable)(struct drm_encoder *encoder);
60360-};
60361+} __no_const;
60362
60363 /**
60364 * drm_connector_helper_funcs - helper operations for connectors
60365diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60366index d6d1da4..fdd1ac5 100644
60367--- a/include/drm/ttm/ttm_memory.h
60368+++ b/include/drm/ttm/ttm_memory.h
60369@@ -48,7 +48,7 @@
60370
60371 struct ttm_mem_shrink {
60372 int (*do_shrink) (struct ttm_mem_shrink *);
60373-};
60374+} __no_const;
60375
60376 /**
60377 * struct ttm_mem_global - Global memory accounting structure.
60378diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60379index e86dfca..40cc55f 100644
60380--- a/include/linux/a.out.h
60381+++ b/include/linux/a.out.h
60382@@ -39,6 +39,14 @@ enum machine_type {
60383 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60384 };
60385
60386+/* Constants for the N_FLAGS field */
60387+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60388+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60389+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60390+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60391+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60392+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60393+
60394 #if !defined (N_MAGIC)
60395 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60396 #endif
60397diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60398index 06fd4bb..1caec0d 100644
60399--- a/include/linux/atmdev.h
60400+++ b/include/linux/atmdev.h
60401@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60402 #endif
60403
60404 struct k_atm_aal_stats {
60405-#define __HANDLE_ITEM(i) atomic_t i
60406+#define __HANDLE_ITEM(i) atomic_unchecked_t i
60407 __AAL_STAT_ITEMS
60408 #undef __HANDLE_ITEM
60409 };
60410diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60411index 366422b..1fa7f84 100644
60412--- a/include/linux/binfmts.h
60413+++ b/include/linux/binfmts.h
60414@@ -89,6 +89,7 @@ struct linux_binfmt {
60415 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60416 int (*load_shlib)(struct file *);
60417 int (*core_dump)(struct coredump_params *cprm);
60418+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60419 unsigned long min_coredump; /* minimal dump size */
60420 };
60421
60422diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60423index 07954b0..cb2ae71 100644
60424--- a/include/linux/blkdev.h
60425+++ b/include/linux/blkdev.h
60426@@ -1393,7 +1393,7 @@ struct block_device_operations {
60427 /* this callback is with swap_lock and sometimes page table lock held */
60428 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60429 struct module *owner;
60430-};
60431+} __do_const;
60432
60433 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60434 unsigned long);
60435diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60436index 4d1a074..88f929a 100644
60437--- a/include/linux/blktrace_api.h
60438+++ b/include/linux/blktrace_api.h
60439@@ -162,7 +162,7 @@ struct blk_trace {
60440 struct dentry *dir;
60441 struct dentry *dropped_file;
60442 struct dentry *msg_file;
60443- atomic_t dropped;
60444+ atomic_unchecked_t dropped;
60445 };
60446
60447 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60448diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60449index 83195fb..0b0f77d 100644
60450--- a/include/linux/byteorder/little_endian.h
60451+++ b/include/linux/byteorder/little_endian.h
60452@@ -42,51 +42,51 @@
60453
60454 static inline __le64 __cpu_to_le64p(const __u64 *p)
60455 {
60456- return (__force __le64)*p;
60457+ return (__force const __le64)*p;
60458 }
60459 static inline __u64 __le64_to_cpup(const __le64 *p)
60460 {
60461- return (__force __u64)*p;
60462+ return (__force const __u64)*p;
60463 }
60464 static inline __le32 __cpu_to_le32p(const __u32 *p)
60465 {
60466- return (__force __le32)*p;
60467+ return (__force const __le32)*p;
60468 }
60469 static inline __u32 __le32_to_cpup(const __le32 *p)
60470 {
60471- return (__force __u32)*p;
60472+ return (__force const __u32)*p;
60473 }
60474 static inline __le16 __cpu_to_le16p(const __u16 *p)
60475 {
60476- return (__force __le16)*p;
60477+ return (__force const __le16)*p;
60478 }
60479 static inline __u16 __le16_to_cpup(const __le16 *p)
60480 {
60481- return (__force __u16)*p;
60482+ return (__force const __u16)*p;
60483 }
60484 static inline __be64 __cpu_to_be64p(const __u64 *p)
60485 {
60486- return (__force __be64)__swab64p(p);
60487+ return (__force const __be64)__swab64p(p);
60488 }
60489 static inline __u64 __be64_to_cpup(const __be64 *p)
60490 {
60491- return __swab64p((__u64 *)p);
60492+ return __swab64p((const __u64 *)p);
60493 }
60494 static inline __be32 __cpu_to_be32p(const __u32 *p)
60495 {
60496- return (__force __be32)__swab32p(p);
60497+ return (__force const __be32)__swab32p(p);
60498 }
60499 static inline __u32 __be32_to_cpup(const __be32 *p)
60500 {
60501- return __swab32p((__u32 *)p);
60502+ return __swab32p((const __u32 *)p);
60503 }
60504 static inline __be16 __cpu_to_be16p(const __u16 *p)
60505 {
60506- return (__force __be16)__swab16p(p);
60507+ return (__force const __be16)__swab16p(p);
60508 }
60509 static inline __u16 __be16_to_cpup(const __be16 *p)
60510 {
60511- return __swab16p((__u16 *)p);
60512+ return __swab16p((const __u16 *)p);
60513 }
60514 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60515 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60516diff --git a/include/linux/cache.h b/include/linux/cache.h
60517index 4c57065..4307975 100644
60518--- a/include/linux/cache.h
60519+++ b/include/linux/cache.h
60520@@ -16,6 +16,10 @@
60521 #define __read_mostly
60522 #endif
60523
60524+#ifndef __read_only
60525+#define __read_only __read_mostly
60526+#endif
60527+
60528 #ifndef ____cacheline_aligned
60529 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60530 #endif
60531diff --git a/include/linux/capability.h b/include/linux/capability.h
60532index d10b7ed..11390a1 100644
60533--- a/include/linux/capability.h
60534+++ b/include/linux/capability.h
60535@@ -553,6 +553,9 @@ extern bool capable(int cap);
60536 extern bool ns_capable(struct user_namespace *ns, int cap);
60537 extern bool nsown_capable(int cap);
60538 extern bool inode_capable(const struct inode *inode, int cap);
60539+extern bool capable_nolog(int cap);
60540+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60541+extern bool inode_capable_nolog(const struct inode *inode, int cap);
60542
60543 /* audit system wants to get cap info from files as well */
60544 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60545diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60546index 42e55de..1cd0e66 100644
60547--- a/include/linux/cleancache.h
60548+++ b/include/linux/cleancache.h
60549@@ -31,7 +31,7 @@ struct cleancache_ops {
60550 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
60551 void (*invalidate_inode)(int, struct cleancache_filekey);
60552 void (*invalidate_fs)(int);
60553-};
60554+} __no_const;
60555
60556 extern struct cleancache_ops
60557 cleancache_register_ops(struct cleancache_ops *ops);
60558diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60559index 2f40791..9c9e13c 100644
60560--- a/include/linux/compiler-gcc4.h
60561+++ b/include/linux/compiler-gcc4.h
60562@@ -32,6 +32,20 @@
60563 #define __linktime_error(message) __attribute__((__error__(message)))
60564
60565 #if __GNUC_MINOR__ >= 5
60566+
60567+#ifdef CONSTIFY_PLUGIN
60568+#define __no_const __attribute__((no_const))
60569+#define __do_const __attribute__((do_const))
60570+#endif
60571+
60572+#ifdef SIZE_OVERFLOW_PLUGIN
60573+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60574+#endif
60575+
60576+#ifdef LATENT_ENTROPY_PLUGIN
60577+#define __latent_entropy __attribute__((latent_entropy))
60578+#endif
60579+
60580 /*
60581 * Mark a position in code as unreachable. This can be used to
60582 * suppress control flow warnings after asm blocks that transfer
60583@@ -47,6 +61,11 @@
60584 #define __noclone __attribute__((__noclone__))
60585
60586 #endif
60587+
60588+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60589+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60590+#define __bos0(ptr) __bos((ptr), 0)
60591+#define __bos1(ptr) __bos((ptr), 1)
60592 #endif
60593
60594 #if __GNUC_MINOR__ > 0
60595diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60596index 923d093..1fef491 100644
60597--- a/include/linux/compiler.h
60598+++ b/include/linux/compiler.h
60599@@ -5,31 +5,62 @@
60600
60601 #ifdef __CHECKER__
60602 # define __user __attribute__((noderef, address_space(1)))
60603+# define __force_user __force __user
60604 # define __kernel __attribute__((address_space(0)))
60605+# define __force_kernel __force __kernel
60606 # define __safe __attribute__((safe))
60607 # define __force __attribute__((force))
60608 # define __nocast __attribute__((nocast))
60609 # define __iomem __attribute__((noderef, address_space(2)))
60610+# define __force_iomem __force __iomem
60611 # define __acquires(x) __attribute__((context(x,0,1)))
60612 # define __releases(x) __attribute__((context(x,1,0)))
60613 # define __acquire(x) __context__(x,1)
60614 # define __release(x) __context__(x,-1)
60615 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60616 # define __percpu __attribute__((noderef, address_space(3)))
60617+# define __force_percpu __force __percpu
60618 #ifdef CONFIG_SPARSE_RCU_POINTER
60619 # define __rcu __attribute__((noderef, address_space(4)))
60620+# define __force_rcu __force __rcu
60621 #else
60622 # define __rcu
60623+# define __force_rcu
60624 #endif
60625 extern void __chk_user_ptr(const volatile void __user *);
60626 extern void __chk_io_ptr(const volatile void __iomem *);
60627+#elif defined(CHECKER_PLUGIN)
60628+//# define __user
60629+//# define __force_user
60630+//# define __kernel
60631+//# define __force_kernel
60632+# define __safe
60633+# define __force
60634+# define __nocast
60635+# define __iomem
60636+# define __force_iomem
60637+# define __chk_user_ptr(x) (void)0
60638+# define __chk_io_ptr(x) (void)0
60639+# define __builtin_warning(x, y...) (1)
60640+# define __acquires(x)
60641+# define __releases(x)
60642+# define __acquire(x) (void)0
60643+# define __release(x) (void)0
60644+# define __cond_lock(x,c) (c)
60645+# define __percpu
60646+# define __force_percpu
60647+# define __rcu
60648+# define __force_rcu
60649 #else
60650 # define __user
60651+# define __force_user
60652 # define __kernel
60653+# define __force_kernel
60654 # define __safe
60655 # define __force
60656 # define __nocast
60657 # define __iomem
60658+# define __force_iomem
60659 # define __chk_user_ptr(x) (void)0
60660 # define __chk_io_ptr(x) (void)0
60661 # define __builtin_warning(x, y...) (1)
60662@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60663 # define __release(x) (void)0
60664 # define __cond_lock(x,c) (c)
60665 # define __percpu
60666+# define __force_percpu
60667 # define __rcu
60668+# define __force_rcu
60669 #endif
60670
60671 #ifdef __KERNEL__
60672@@ -264,6 +297,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60673 # define __attribute_const__ /* unimplemented */
60674 #endif
60675
60676+#ifndef __no_const
60677+# define __no_const
60678+#endif
60679+
60680+#ifndef __do_const
60681+# define __do_const
60682+#endif
60683+
60684+#ifndef __size_overflow
60685+# define __size_overflow(...)
60686+#endif
60687+
60688+#ifndef __latent_entropy
60689+# define __latent_entropy
60690+#endif
60691+
60692 /*
60693 * Tell gcc if a function is cold. The compiler will assume any path
60694 * directly leading to the call is unlikely.
60695@@ -273,6 +322,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60696 #define __cold
60697 #endif
60698
60699+#ifndef __alloc_size
60700+#define __alloc_size(...)
60701+#endif
60702+
60703+#ifndef __bos
60704+#define __bos(ptr, arg)
60705+#endif
60706+
60707+#ifndef __bos0
60708+#define __bos0(ptr)
60709+#endif
60710+
60711+#ifndef __bos1
60712+#define __bos1(ptr)
60713+#endif
60714+
60715 /* Simple shorthand for a section definition */
60716 #ifndef __section
60717 # define __section(S) __attribute__ ((__section__(#S)))
60718@@ -308,6 +373,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60719 * use is to mediate communication between process-level code and irq/NMI
60720 * handlers, all running on the same CPU.
60721 */
60722-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60723+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60724+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60725
60726 #endif /* __LINUX_COMPILER_H */
60727diff --git a/include/linux/cred.h b/include/linux/cred.h
60728index ebbed2c..908cc2c 100644
60729--- a/include/linux/cred.h
60730+++ b/include/linux/cred.h
60731@@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60732 static inline void validate_process_creds(void)
60733 {
60734 }
60735+static inline void validate_task_creds(struct task_struct *task)
60736+{
60737+}
60738 #endif
60739
60740 /**
60741diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60742index b92eadf..b4ecdc1 100644
60743--- a/include/linux/crypto.h
60744+++ b/include/linux/crypto.h
60745@@ -373,7 +373,7 @@ struct cipher_tfm {
60746 const u8 *key, unsigned int keylen);
60747 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60748 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60749-};
60750+} __no_const;
60751
60752 struct hash_tfm {
60753 int (*init)(struct hash_desc *desc);
60754@@ -394,13 +394,13 @@ struct compress_tfm {
60755 int (*cot_decompress)(struct crypto_tfm *tfm,
60756 const u8 *src, unsigned int slen,
60757 u8 *dst, unsigned int *dlen);
60758-};
60759+} __no_const;
60760
60761 struct rng_tfm {
60762 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60763 unsigned int dlen);
60764 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60765-};
60766+} __no_const;
60767
60768 #define crt_ablkcipher crt_u.ablkcipher
60769 #define crt_aead crt_u.aead
60770diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60771index 7925bf0..d5143d2 100644
60772--- a/include/linux/decompress/mm.h
60773+++ b/include/linux/decompress/mm.h
60774@@ -77,7 +77,7 @@ static void free(void *where)
60775 * warnings when not needed (indeed large_malloc / large_free are not
60776 * needed by inflate */
60777
60778-#define malloc(a) kmalloc(a, GFP_KERNEL)
60779+#define malloc(a) kmalloc((a), GFP_KERNEL)
60780 #define free(a) kfree(a)
60781
60782 #define large_malloc(a) vmalloc(a)
60783diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60784index dfc099e..e583e66 100644
60785--- a/include/linux/dma-mapping.h
60786+++ b/include/linux/dma-mapping.h
60787@@ -51,7 +51,7 @@ struct dma_map_ops {
60788 u64 (*get_required_mask)(struct device *dev);
60789 #endif
60790 int is_phys;
60791-};
60792+} __do_const;
60793
60794 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60795
60796diff --git a/include/linux/efi.h b/include/linux/efi.h
60797index ec45ccd..9923c32 100644
60798--- a/include/linux/efi.h
60799+++ b/include/linux/efi.h
60800@@ -635,7 +635,7 @@ struct efivar_operations {
60801 efi_get_variable_t *get_variable;
60802 efi_get_next_variable_t *get_next_variable;
60803 efi_set_variable_t *set_variable;
60804-};
60805+} __no_const;
60806
60807 struct efivars {
60808 /*
60809diff --git a/include/linux/elf.h b/include/linux/elf.h
60810index 999b4f5..57753b4 100644
60811--- a/include/linux/elf.h
60812+++ b/include/linux/elf.h
60813@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60814 #define PT_GNU_EH_FRAME 0x6474e550
60815
60816 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60817+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60818+
60819+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60820+
60821+/* Constants for the e_flags field */
60822+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60823+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60824+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60825+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60826+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60827+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60828
60829 /*
60830 * Extended Numbering
60831@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60832 #define DT_DEBUG 21
60833 #define DT_TEXTREL 22
60834 #define DT_JMPREL 23
60835+#define DT_FLAGS 30
60836+ #define DF_TEXTREL 0x00000004
60837 #define DT_ENCODING 32
60838 #define OLD_DT_LOOS 0x60000000
60839 #define DT_LOOS 0x6000000d
60840@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60841 #define PF_W 0x2
60842 #define PF_X 0x1
60843
60844+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60845+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60846+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60847+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60848+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60849+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60850+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60851+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60852+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60853+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60854+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60855+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60856+
60857 typedef struct elf32_phdr{
60858 Elf32_Word p_type;
60859 Elf32_Off p_offset;
60860@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60861 #define EI_OSABI 7
60862 #define EI_PAD 8
60863
60864+#define EI_PAX 14
60865+
60866 #define ELFMAG0 0x7f /* EI_MAG */
60867 #define ELFMAG1 'E'
60868 #define ELFMAG2 'L'
60869@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60870 #define elf_note elf32_note
60871 #define elf_addr_t Elf32_Off
60872 #define Elf_Half Elf32_Half
60873+#define elf_dyn Elf32_Dyn
60874
60875 #else
60876
60877@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60878 #define elf_note elf64_note
60879 #define elf_addr_t Elf64_Off
60880 #define Elf_Half Elf64_Half
60881+#define elf_dyn Elf64_Dyn
60882
60883 #endif
60884
60885diff --git a/include/linux/filter.h b/include/linux/filter.h
60886index 82b0135..917914d 100644
60887--- a/include/linux/filter.h
60888+++ b/include/linux/filter.h
60889@@ -146,6 +146,7 @@ struct compat_sock_fprog {
60890
60891 struct sk_buff;
60892 struct sock;
60893+struct bpf_jit_work;
60894
60895 struct sk_filter
60896 {
60897@@ -153,6 +154,9 @@ struct sk_filter
60898 unsigned int len; /* Number of filter blocks */
60899 unsigned int (*bpf_func)(const struct sk_buff *skb,
60900 const struct sock_filter *filter);
60901+#ifdef CONFIG_BPF_JIT
60902+ struct bpf_jit_work *work;
60903+#endif
60904 struct rcu_head rcu;
60905 struct sock_filter insns[0];
60906 };
60907diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60908index 7edcf10..714d5e8 100644
60909--- a/include/linux/firewire.h
60910+++ b/include/linux/firewire.h
60911@@ -430,7 +430,7 @@ struct fw_iso_context {
60912 union {
60913 fw_iso_callback_t sc;
60914 fw_iso_mc_callback_t mc;
60915- } callback;
60916+ } __no_const callback;
60917 void *callback_data;
60918 };
60919
60920diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
60921index 0e4e2ee..4ff4312 100644
60922--- a/include/linux/frontswap.h
60923+++ b/include/linux/frontswap.h
60924@@ -11,7 +11,7 @@ struct frontswap_ops {
60925 int (*load)(unsigned, pgoff_t, struct page *);
60926 void (*invalidate_page)(unsigned, pgoff_t);
60927 void (*invalidate_area)(unsigned);
60928-};
60929+} __no_const;
60930
60931 extern bool frontswap_enabled;
60932 extern struct frontswap_ops
60933diff --git a/include/linux/fs.h b/include/linux/fs.h
60934index 17fd887..8eebca0 100644
60935--- a/include/linux/fs.h
60936+++ b/include/linux/fs.h
60937@@ -1663,7 +1663,8 @@ struct file_operations {
60938 int (*setlease)(struct file *, long, struct file_lock **);
60939 long (*fallocate)(struct file *file, int mode, loff_t offset,
60940 loff_t len);
60941-};
60942+} __do_const;
60943+typedef struct file_operations __no_const file_operations_no_const;
60944
60945 struct inode_operations {
60946 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60947diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60948index 003dc0f..3c4ea97 100644
60949--- a/include/linux/fs_struct.h
60950+++ b/include/linux/fs_struct.h
60951@@ -6,7 +6,7 @@
60952 #include <linux/seqlock.h>
60953
60954 struct fs_struct {
60955- int users;
60956+ atomic_t users;
60957 spinlock_t lock;
60958 seqcount_t seq;
60959 int umask;
60960diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60961index ce31408..b1ad003 100644
60962--- a/include/linux/fscache-cache.h
60963+++ b/include/linux/fscache-cache.h
60964@@ -102,7 +102,7 @@ struct fscache_operation {
60965 fscache_operation_release_t release;
60966 };
60967
60968-extern atomic_t fscache_op_debug_id;
60969+extern atomic_unchecked_t fscache_op_debug_id;
60970 extern void fscache_op_work_func(struct work_struct *work);
60971
60972 extern void fscache_enqueue_operation(struct fscache_operation *);
60973@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60974 {
60975 INIT_WORK(&op->work, fscache_op_work_func);
60976 atomic_set(&op->usage, 1);
60977- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60978+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60979 op->processor = processor;
60980 op->release = release;
60981 INIT_LIST_HEAD(&op->pend_link);
60982diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60983index a6dfe69..569586df 100644
60984--- a/include/linux/fsnotify.h
60985+++ b/include/linux/fsnotify.h
60986@@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60987 */
60988 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60989 {
60990- return kstrdup(name, GFP_KERNEL);
60991+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60992 }
60993
60994 /*
60995diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60996index 63d966d..cdcb717 100644
60997--- a/include/linux/fsnotify_backend.h
60998+++ b/include/linux/fsnotify_backend.h
60999@@ -105,6 +105,7 @@ struct fsnotify_ops {
61000 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61001 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61002 };
61003+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61004
61005 /*
61006 * A group is a "thing" that wants to receive notification about filesystem
61007diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61008index 176a939..1462211 100644
61009--- a/include/linux/ftrace_event.h
61010+++ b/include/linux/ftrace_event.h
61011@@ -97,7 +97,7 @@ struct trace_event_functions {
61012 trace_print_func raw;
61013 trace_print_func hex;
61014 trace_print_func binary;
61015-};
61016+} __no_const;
61017
61018 struct trace_event {
61019 struct hlist_node node;
61020@@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61021 extern int trace_add_event_call(struct ftrace_event_call *call);
61022 extern void trace_remove_event_call(struct ftrace_event_call *call);
61023
61024-#define is_signed_type(type) (((type)(-1)) < 0)
61025+#define is_signed_type(type) (((type)(-1)) < (type)1)
61026
61027 int trace_set_clr_event(const char *system, const char *event, int set);
61028
61029diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61030index 017a7fb..33a8507 100644
61031--- a/include/linux/genhd.h
61032+++ b/include/linux/genhd.h
61033@@ -185,7 +185,7 @@ struct gendisk {
61034 struct kobject *slave_dir;
61035
61036 struct timer_rand_state *random;
61037- atomic_t sync_io; /* RAID */
61038+ atomic_unchecked_t sync_io; /* RAID */
61039 struct disk_events *ev;
61040 #ifdef CONFIG_BLK_DEV_INTEGRITY
61041 struct blk_integrity *integrity;
61042diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61043index 1e49be4..b8a9305 100644
61044--- a/include/linux/gfp.h
61045+++ b/include/linux/gfp.h
61046@@ -38,6 +38,12 @@ struct vm_area_struct;
61047 #define ___GFP_OTHER_NODE 0x800000u
61048 #define ___GFP_WRITE 0x1000000u
61049
61050+#ifdef CONFIG_PAX_USERCOPY_SLABS
61051+#define ___GFP_USERCOPY 0x2000000u
61052+#else
61053+#define ___GFP_USERCOPY 0
61054+#endif
61055+
61056 /*
61057 * GFP bitmasks..
61058 *
61059@@ -87,6 +93,7 @@ struct vm_area_struct;
61060 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61061 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61062 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61063+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61064
61065 /*
61066 * This may seem redundant, but it's a way of annotating false positives vs.
61067@@ -94,7 +101,7 @@ struct vm_area_struct;
61068 */
61069 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61070
61071-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61072+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61073 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61074
61075 /* This equals 0, but use constants in case they ever change */
61076@@ -148,6 +155,8 @@ struct vm_area_struct;
61077 /* 4GB DMA on some platforms */
61078 #define GFP_DMA32 __GFP_DMA32
61079
61080+#define GFP_USERCOPY __GFP_USERCOPY
61081+
61082 /* Convert GFP flags to their corresponding migrate type */
61083 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61084 {
61085diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61086new file mode 100644
61087index 0000000..c938b1f
61088--- /dev/null
61089+++ b/include/linux/gracl.h
61090@@ -0,0 +1,319 @@
61091+#ifndef GR_ACL_H
61092+#define GR_ACL_H
61093+
61094+#include <linux/grdefs.h>
61095+#include <linux/resource.h>
61096+#include <linux/capability.h>
61097+#include <linux/dcache.h>
61098+#include <asm/resource.h>
61099+
61100+/* Major status information */
61101+
61102+#define GR_VERSION "grsecurity 2.9.1"
61103+#define GRSECURITY_VERSION 0x2901
61104+
61105+enum {
61106+ GR_SHUTDOWN = 0,
61107+ GR_ENABLE = 1,
61108+ GR_SPROLE = 2,
61109+ GR_RELOAD = 3,
61110+ GR_SEGVMOD = 4,
61111+ GR_STATUS = 5,
61112+ GR_UNSPROLE = 6,
61113+ GR_PASSSET = 7,
61114+ GR_SPROLEPAM = 8,
61115+};
61116+
61117+/* Password setup definitions
61118+ * kernel/grhash.c */
61119+enum {
61120+ GR_PW_LEN = 128,
61121+ GR_SALT_LEN = 16,
61122+ GR_SHA_LEN = 32,
61123+};
61124+
61125+enum {
61126+ GR_SPROLE_LEN = 64,
61127+};
61128+
61129+enum {
61130+ GR_NO_GLOB = 0,
61131+ GR_REG_GLOB,
61132+ GR_CREATE_GLOB
61133+};
61134+
61135+#define GR_NLIMITS 32
61136+
61137+/* Begin Data Structures */
61138+
61139+struct sprole_pw {
61140+ unsigned char *rolename;
61141+ unsigned char salt[GR_SALT_LEN];
61142+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61143+};
61144+
61145+struct name_entry {
61146+ __u32 key;
61147+ ino_t inode;
61148+ dev_t device;
61149+ char *name;
61150+ __u16 len;
61151+ __u8 deleted;
61152+ struct name_entry *prev;
61153+ struct name_entry *next;
61154+};
61155+
61156+struct inodev_entry {
61157+ struct name_entry *nentry;
61158+ struct inodev_entry *prev;
61159+ struct inodev_entry *next;
61160+};
61161+
61162+struct acl_role_db {
61163+ struct acl_role_label **r_hash;
61164+ __u32 r_size;
61165+};
61166+
61167+struct inodev_db {
61168+ struct inodev_entry **i_hash;
61169+ __u32 i_size;
61170+};
61171+
61172+struct name_db {
61173+ struct name_entry **n_hash;
61174+ __u32 n_size;
61175+};
61176+
61177+struct crash_uid {
61178+ uid_t uid;
61179+ unsigned long expires;
61180+};
61181+
61182+struct gr_hash_struct {
61183+ void **table;
61184+ void **nametable;
61185+ void *first;
61186+ __u32 table_size;
61187+ __u32 used_size;
61188+ int type;
61189+};
61190+
61191+/* Userspace Grsecurity ACL data structures */
61192+
61193+struct acl_subject_label {
61194+ char *filename;
61195+ ino_t inode;
61196+ dev_t device;
61197+ __u32 mode;
61198+ kernel_cap_t cap_mask;
61199+ kernel_cap_t cap_lower;
61200+ kernel_cap_t cap_invert_audit;
61201+
61202+ struct rlimit res[GR_NLIMITS];
61203+ __u32 resmask;
61204+
61205+ __u8 user_trans_type;
61206+ __u8 group_trans_type;
61207+ uid_t *user_transitions;
61208+ gid_t *group_transitions;
61209+ __u16 user_trans_num;
61210+ __u16 group_trans_num;
61211+
61212+ __u32 sock_families[2];
61213+ __u32 ip_proto[8];
61214+ __u32 ip_type;
61215+ struct acl_ip_label **ips;
61216+ __u32 ip_num;
61217+ __u32 inaddr_any_override;
61218+
61219+ __u32 crashes;
61220+ unsigned long expires;
61221+
61222+ struct acl_subject_label *parent_subject;
61223+ struct gr_hash_struct *hash;
61224+ struct acl_subject_label *prev;
61225+ struct acl_subject_label *next;
61226+
61227+ struct acl_object_label **obj_hash;
61228+ __u32 obj_hash_size;
61229+ __u16 pax_flags;
61230+};
61231+
61232+struct role_allowed_ip {
61233+ __u32 addr;
61234+ __u32 netmask;
61235+
61236+ struct role_allowed_ip *prev;
61237+ struct role_allowed_ip *next;
61238+};
61239+
61240+struct role_transition {
61241+ char *rolename;
61242+
61243+ struct role_transition *prev;
61244+ struct role_transition *next;
61245+};
61246+
61247+struct acl_role_label {
61248+ char *rolename;
61249+ uid_t uidgid;
61250+ __u16 roletype;
61251+
61252+ __u16 auth_attempts;
61253+ unsigned long expires;
61254+
61255+ struct acl_subject_label *root_label;
61256+ struct gr_hash_struct *hash;
61257+
61258+ struct acl_role_label *prev;
61259+ struct acl_role_label *next;
61260+
61261+ struct role_transition *transitions;
61262+ struct role_allowed_ip *allowed_ips;
61263+ uid_t *domain_children;
61264+ __u16 domain_child_num;
61265+
61266+ umode_t umask;
61267+
61268+ struct acl_subject_label **subj_hash;
61269+ __u32 subj_hash_size;
61270+};
61271+
61272+struct user_acl_role_db {
61273+ struct acl_role_label **r_table;
61274+ __u32 num_pointers; /* Number of allocations to track */
61275+ __u32 num_roles; /* Number of roles */
61276+ __u32 num_domain_children; /* Number of domain children */
61277+ __u32 num_subjects; /* Number of subjects */
61278+ __u32 num_objects; /* Number of objects */
61279+};
61280+
61281+struct acl_object_label {
61282+ char *filename;
61283+ ino_t inode;
61284+ dev_t device;
61285+ __u32 mode;
61286+
61287+ struct acl_subject_label *nested;
61288+ struct acl_object_label *globbed;
61289+
61290+ /* next two structures not used */
61291+
61292+ struct acl_object_label *prev;
61293+ struct acl_object_label *next;
61294+};
61295+
61296+struct acl_ip_label {
61297+ char *iface;
61298+ __u32 addr;
61299+ __u32 netmask;
61300+ __u16 low, high;
61301+ __u8 mode;
61302+ __u32 type;
61303+ __u32 proto[8];
61304+
61305+ /* next two structures not used */
61306+
61307+ struct acl_ip_label *prev;
61308+ struct acl_ip_label *next;
61309+};
61310+
61311+struct gr_arg {
61312+ struct user_acl_role_db role_db;
61313+ unsigned char pw[GR_PW_LEN];
61314+ unsigned char salt[GR_SALT_LEN];
61315+ unsigned char sum[GR_SHA_LEN];
61316+ unsigned char sp_role[GR_SPROLE_LEN];
61317+ struct sprole_pw *sprole_pws;
61318+ dev_t segv_device;
61319+ ino_t segv_inode;
61320+ uid_t segv_uid;
61321+ __u16 num_sprole_pws;
61322+ __u16 mode;
61323+};
61324+
61325+struct gr_arg_wrapper {
61326+ struct gr_arg *arg;
61327+ __u32 version;
61328+ __u32 size;
61329+};
61330+
61331+struct subject_map {
61332+ struct acl_subject_label *user;
61333+ struct acl_subject_label *kernel;
61334+ struct subject_map *prev;
61335+ struct subject_map *next;
61336+};
61337+
61338+struct acl_subj_map_db {
61339+ struct subject_map **s_hash;
61340+ __u32 s_size;
61341+};
61342+
61343+/* End Data Structures Section */
61344+
61345+/* Hash functions generated by empirical testing by Brad Spengler
61346+ Makes good use of the low bits of the inode. Generally 0-1 times
61347+ in loop for successful match. 0-3 for unsuccessful match.
61348+ Shift/add algorithm with modulus of table size and an XOR*/
61349+
61350+static __inline__ unsigned int
61351+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61352+{
61353+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
61354+}
61355+
61356+ static __inline__ unsigned int
61357+shash(const struct acl_subject_label *userp, const unsigned int sz)
61358+{
61359+ return ((const unsigned long)userp % sz);
61360+}
61361+
61362+static __inline__ unsigned int
61363+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61364+{
61365+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61366+}
61367+
61368+static __inline__ unsigned int
61369+nhash(const char *name, const __u16 len, const unsigned int sz)
61370+{
61371+ return full_name_hash((const unsigned char *)name, len) % sz;
61372+}
61373+
61374+#define FOR_EACH_ROLE_START(role) \
61375+ role = role_list; \
61376+ while (role) {
61377+
61378+#define FOR_EACH_ROLE_END(role) \
61379+ role = role->prev; \
61380+ }
61381+
61382+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61383+ subj = NULL; \
61384+ iter = 0; \
61385+ while (iter < role->subj_hash_size) { \
61386+ if (subj == NULL) \
61387+ subj = role->subj_hash[iter]; \
61388+ if (subj == NULL) { \
61389+ iter++; \
61390+ continue; \
61391+ }
61392+
61393+#define FOR_EACH_SUBJECT_END(subj,iter) \
61394+ subj = subj->next; \
61395+ if (subj == NULL) \
61396+ iter++; \
61397+ }
61398+
61399+
61400+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61401+ subj = role->hash->first; \
61402+ while (subj != NULL) {
61403+
61404+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61405+ subj = subj->next; \
61406+ }
61407+
61408+#endif
61409+
61410diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61411new file mode 100644
61412index 0000000..323ecf2
61413--- /dev/null
61414+++ b/include/linux/gralloc.h
61415@@ -0,0 +1,9 @@
61416+#ifndef __GRALLOC_H
61417+#define __GRALLOC_H
61418+
61419+void acl_free_all(void);
61420+int acl_alloc_stack_init(unsigned long size);
61421+void *acl_alloc(unsigned long len);
61422+void *acl_alloc_num(unsigned long num, unsigned long len);
61423+
61424+#endif
61425diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61426new file mode 100644
61427index 0000000..b30e9bc
61428--- /dev/null
61429+++ b/include/linux/grdefs.h
61430@@ -0,0 +1,140 @@
61431+#ifndef GRDEFS_H
61432+#define GRDEFS_H
61433+
61434+/* Begin grsecurity status declarations */
61435+
61436+enum {
61437+ GR_READY = 0x01,
61438+ GR_STATUS_INIT = 0x00 // disabled state
61439+};
61440+
61441+/* Begin ACL declarations */
61442+
61443+/* Role flags */
61444+
61445+enum {
61446+ GR_ROLE_USER = 0x0001,
61447+ GR_ROLE_GROUP = 0x0002,
61448+ GR_ROLE_DEFAULT = 0x0004,
61449+ GR_ROLE_SPECIAL = 0x0008,
61450+ GR_ROLE_AUTH = 0x0010,
61451+ GR_ROLE_NOPW = 0x0020,
61452+ GR_ROLE_GOD = 0x0040,
61453+ GR_ROLE_LEARN = 0x0080,
61454+ GR_ROLE_TPE = 0x0100,
61455+ GR_ROLE_DOMAIN = 0x0200,
61456+ GR_ROLE_PAM = 0x0400,
61457+ GR_ROLE_PERSIST = 0x0800
61458+};
61459+
61460+/* ACL Subject and Object mode flags */
61461+enum {
61462+ GR_DELETED = 0x80000000
61463+};
61464+
61465+/* ACL Object-only mode flags */
61466+enum {
61467+ GR_READ = 0x00000001,
61468+ GR_APPEND = 0x00000002,
61469+ GR_WRITE = 0x00000004,
61470+ GR_EXEC = 0x00000008,
61471+ GR_FIND = 0x00000010,
61472+ GR_INHERIT = 0x00000020,
61473+ GR_SETID = 0x00000040,
61474+ GR_CREATE = 0x00000080,
61475+ GR_DELETE = 0x00000100,
61476+ GR_LINK = 0x00000200,
61477+ GR_AUDIT_READ = 0x00000400,
61478+ GR_AUDIT_APPEND = 0x00000800,
61479+ GR_AUDIT_WRITE = 0x00001000,
61480+ GR_AUDIT_EXEC = 0x00002000,
61481+ GR_AUDIT_FIND = 0x00004000,
61482+ GR_AUDIT_INHERIT= 0x00008000,
61483+ GR_AUDIT_SETID = 0x00010000,
61484+ GR_AUDIT_CREATE = 0x00020000,
61485+ GR_AUDIT_DELETE = 0x00040000,
61486+ GR_AUDIT_LINK = 0x00080000,
61487+ GR_PTRACERD = 0x00100000,
61488+ GR_NOPTRACE = 0x00200000,
61489+ GR_SUPPRESS = 0x00400000,
61490+ GR_NOLEARN = 0x00800000,
61491+ GR_INIT_TRANSFER= 0x01000000
61492+};
61493+
61494+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61495+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61496+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61497+
61498+/* ACL subject-only mode flags */
61499+enum {
61500+ GR_KILL = 0x00000001,
61501+ GR_VIEW = 0x00000002,
61502+ GR_PROTECTED = 0x00000004,
61503+ GR_LEARN = 0x00000008,
61504+ GR_OVERRIDE = 0x00000010,
61505+ /* just a placeholder, this mode is only used in userspace */
61506+ GR_DUMMY = 0x00000020,
61507+ GR_PROTSHM = 0x00000040,
61508+ GR_KILLPROC = 0x00000080,
61509+ GR_KILLIPPROC = 0x00000100,
61510+ /* just a placeholder, this mode is only used in userspace */
61511+ GR_NOTROJAN = 0x00000200,
61512+ GR_PROTPROCFD = 0x00000400,
61513+ GR_PROCACCT = 0x00000800,
61514+ GR_RELAXPTRACE = 0x00001000,
61515+ GR_NESTED = 0x00002000,
61516+ GR_INHERITLEARN = 0x00004000,
61517+ GR_PROCFIND = 0x00008000,
61518+ GR_POVERRIDE = 0x00010000,
61519+ GR_KERNELAUTH = 0x00020000,
61520+ GR_ATSECURE = 0x00040000,
61521+ GR_SHMEXEC = 0x00080000
61522+};
61523+
61524+enum {
61525+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61526+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61527+ GR_PAX_ENABLE_MPROTECT = 0x0004,
61528+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
61529+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61530+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61531+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61532+ GR_PAX_DISABLE_MPROTECT = 0x0400,
61533+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
61534+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61535+};
61536+
61537+enum {
61538+ GR_ID_USER = 0x01,
61539+ GR_ID_GROUP = 0x02,
61540+};
61541+
61542+enum {
61543+ GR_ID_ALLOW = 0x01,
61544+ GR_ID_DENY = 0x02,
61545+};
61546+
61547+#define GR_CRASH_RES 31
61548+#define GR_UIDTABLE_MAX 500
61549+
61550+/* begin resource learning section */
61551+enum {
61552+ GR_RLIM_CPU_BUMP = 60,
61553+ GR_RLIM_FSIZE_BUMP = 50000,
61554+ GR_RLIM_DATA_BUMP = 10000,
61555+ GR_RLIM_STACK_BUMP = 1000,
61556+ GR_RLIM_CORE_BUMP = 10000,
61557+ GR_RLIM_RSS_BUMP = 500000,
61558+ GR_RLIM_NPROC_BUMP = 1,
61559+ GR_RLIM_NOFILE_BUMP = 5,
61560+ GR_RLIM_MEMLOCK_BUMP = 50000,
61561+ GR_RLIM_AS_BUMP = 500000,
61562+ GR_RLIM_LOCKS_BUMP = 2,
61563+ GR_RLIM_SIGPENDING_BUMP = 5,
61564+ GR_RLIM_MSGQUEUE_BUMP = 10000,
61565+ GR_RLIM_NICE_BUMP = 1,
61566+ GR_RLIM_RTPRIO_BUMP = 1,
61567+ GR_RLIM_RTTIME_BUMP = 1000000
61568+};
61569+
61570+#endif
61571diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61572new file mode 100644
61573index 0000000..c9292f7
61574--- /dev/null
61575+++ b/include/linux/grinternal.h
61576@@ -0,0 +1,223 @@
61577+#ifndef __GRINTERNAL_H
61578+#define __GRINTERNAL_H
61579+
61580+#ifdef CONFIG_GRKERNSEC
61581+
61582+#include <linux/fs.h>
61583+#include <linux/mnt_namespace.h>
61584+#include <linux/nsproxy.h>
61585+#include <linux/gracl.h>
61586+#include <linux/grdefs.h>
61587+#include <linux/grmsg.h>
61588+
61589+void gr_add_learn_entry(const char *fmt, ...)
61590+ __attribute__ ((format (printf, 1, 2)));
61591+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61592+ const struct vfsmount *mnt);
61593+__u32 gr_check_create(const struct dentry *new_dentry,
61594+ const struct dentry *parent,
61595+ const struct vfsmount *mnt, const __u32 mode);
61596+int gr_check_protected_task(const struct task_struct *task);
61597+__u32 to_gr_audit(const __u32 reqmode);
61598+int gr_set_acls(const int type);
61599+int gr_apply_subject_to_task(struct task_struct *task);
61600+int gr_acl_is_enabled(void);
61601+char gr_roletype_to_char(void);
61602+
61603+void gr_handle_alertkill(struct task_struct *task);
61604+char *gr_to_filename(const struct dentry *dentry,
61605+ const struct vfsmount *mnt);
61606+char *gr_to_filename1(const struct dentry *dentry,
61607+ const struct vfsmount *mnt);
61608+char *gr_to_filename2(const struct dentry *dentry,
61609+ const struct vfsmount *mnt);
61610+char *gr_to_filename3(const struct dentry *dentry,
61611+ const struct vfsmount *mnt);
61612+
61613+extern int grsec_enable_ptrace_readexec;
61614+extern int grsec_enable_harden_ptrace;
61615+extern int grsec_enable_link;
61616+extern int grsec_enable_fifo;
61617+extern int grsec_enable_execve;
61618+extern int grsec_enable_shm;
61619+extern int grsec_enable_execlog;
61620+extern int grsec_enable_signal;
61621+extern int grsec_enable_audit_ptrace;
61622+extern int grsec_enable_forkfail;
61623+extern int grsec_enable_time;
61624+extern int grsec_enable_rofs;
61625+extern int grsec_enable_chroot_shmat;
61626+extern int grsec_enable_chroot_mount;
61627+extern int grsec_enable_chroot_double;
61628+extern int grsec_enable_chroot_pivot;
61629+extern int grsec_enable_chroot_chdir;
61630+extern int grsec_enable_chroot_chmod;
61631+extern int grsec_enable_chroot_mknod;
61632+extern int grsec_enable_chroot_fchdir;
61633+extern int grsec_enable_chroot_nice;
61634+extern int grsec_enable_chroot_execlog;
61635+extern int grsec_enable_chroot_caps;
61636+extern int grsec_enable_chroot_sysctl;
61637+extern int grsec_enable_chroot_unix;
61638+extern int grsec_enable_symlinkown;
61639+extern int grsec_symlinkown_gid;
61640+extern int grsec_enable_tpe;
61641+extern int grsec_tpe_gid;
61642+extern int grsec_enable_tpe_all;
61643+extern int grsec_enable_tpe_invert;
61644+extern int grsec_enable_socket_all;
61645+extern int grsec_socket_all_gid;
61646+extern int grsec_enable_socket_client;
61647+extern int grsec_socket_client_gid;
61648+extern int grsec_enable_socket_server;
61649+extern int grsec_socket_server_gid;
61650+extern int grsec_audit_gid;
61651+extern int grsec_enable_group;
61652+extern int grsec_enable_audit_textrel;
61653+extern int grsec_enable_log_rwxmaps;
61654+extern int grsec_enable_mount;
61655+extern int grsec_enable_chdir;
61656+extern int grsec_resource_logging;
61657+extern int grsec_enable_blackhole;
61658+extern int grsec_lastack_retries;
61659+extern int grsec_enable_brute;
61660+extern int grsec_lock;
61661+
61662+extern spinlock_t grsec_alert_lock;
61663+extern unsigned long grsec_alert_wtime;
61664+extern unsigned long grsec_alert_fyet;
61665+
61666+extern spinlock_t grsec_audit_lock;
61667+
61668+extern rwlock_t grsec_exec_file_lock;
61669+
61670+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61671+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61672+ (tsk)->exec_file->f_vfsmnt) : "/")
61673+
61674+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61675+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61676+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61677+
61678+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61679+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
61680+ (tsk)->exec_file->f_vfsmnt) : "/")
61681+
61682+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61683+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61684+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61685+
61686+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61687+
61688+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61689+
61690+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61691+ (task)->pid, (cred)->uid, \
61692+ (cred)->euid, (cred)->gid, (cred)->egid, \
61693+ gr_parent_task_fullpath(task), \
61694+ (task)->real_parent->comm, (task)->real_parent->pid, \
61695+ (pcred)->uid, (pcred)->euid, \
61696+ (pcred)->gid, (pcred)->egid
61697+
61698+#define GR_CHROOT_CAPS {{ \
61699+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61700+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61701+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61702+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61703+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61704+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61705+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61706+
61707+#define security_learn(normal_msg,args...) \
61708+({ \
61709+ read_lock(&grsec_exec_file_lock); \
61710+ gr_add_learn_entry(normal_msg "\n", ## args); \
61711+ read_unlock(&grsec_exec_file_lock); \
61712+})
61713+
61714+enum {
61715+ GR_DO_AUDIT,
61716+ GR_DONT_AUDIT,
61717+ /* used for non-audit messages that we shouldn't kill the task on */
61718+ GR_DONT_AUDIT_GOOD
61719+};
61720+
61721+enum {
61722+ GR_TTYSNIFF,
61723+ GR_RBAC,
61724+ GR_RBAC_STR,
61725+ GR_STR_RBAC,
61726+ GR_RBAC_MODE2,
61727+ GR_RBAC_MODE3,
61728+ GR_FILENAME,
61729+ GR_SYSCTL_HIDDEN,
61730+ GR_NOARGS,
61731+ GR_ONE_INT,
61732+ GR_ONE_INT_TWO_STR,
61733+ GR_ONE_STR,
61734+ GR_STR_INT,
61735+ GR_TWO_STR_INT,
61736+ GR_TWO_INT,
61737+ GR_TWO_U64,
61738+ GR_THREE_INT,
61739+ GR_FIVE_INT_TWO_STR,
61740+ GR_TWO_STR,
61741+ GR_THREE_STR,
61742+ GR_FOUR_STR,
61743+ GR_STR_FILENAME,
61744+ GR_FILENAME_STR,
61745+ GR_FILENAME_TWO_INT,
61746+ GR_FILENAME_TWO_INT_STR,
61747+ GR_TEXTREL,
61748+ GR_PTRACE,
61749+ GR_RESOURCE,
61750+ GR_CAP,
61751+ GR_SIG,
61752+ GR_SIG2,
61753+ GR_CRASH1,
61754+ GR_CRASH2,
61755+ GR_PSACCT,
61756+ GR_RWXMAP
61757+};
61758+
61759+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61760+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61761+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61762+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61763+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61764+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61765+#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)
61766+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61767+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61768+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61769+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61770+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61771+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61772+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61773+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61774+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61775+#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)
61776+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61777+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61778+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61779+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61780+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61781+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61782+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61783+#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)
61784+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61785+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61786+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61787+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61788+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61789+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61790+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61791+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61792+#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)
61793+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61794+
61795+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61796+
61797+#endif
61798+
61799+#endif
61800diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61801new file mode 100644
61802index 0000000..54f4e85
61803--- /dev/null
61804+++ b/include/linux/grmsg.h
61805@@ -0,0 +1,110 @@
61806+#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"
61807+#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"
61808+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61809+#define GR_STOPMOD_MSG "denied modification of module state by "
61810+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61811+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61812+#define GR_IOPERM_MSG "denied use of ioperm() by "
61813+#define GR_IOPL_MSG "denied use of iopl() by "
61814+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61815+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61816+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61817+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61818+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61819+#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"
61820+#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"
61821+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61822+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61823+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61824+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61825+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61826+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61827+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61828+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61829+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61830+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61831+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61832+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61833+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61834+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61835+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61836+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61837+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61838+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61839+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61840+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61841+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61842+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61843+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61844+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61845+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61846+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61847+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61848+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61849+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61850+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61851+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61852+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61853+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61854+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61855+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61856+#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"
61857+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61858+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61859+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61860+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61861+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61862+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61863+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61864+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61865+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61866+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61867+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61868+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61869+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61870+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61871+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61872+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61873+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61874+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61875+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61876+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61877+#define GR_FAILFORK_MSG "failed fork with errno %s by "
61878+#define GR_NICE_CHROOT_MSG "denied priority change by "
61879+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61880+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61881+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61882+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61883+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61884+#define GR_TIME_MSG "time set by "
61885+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61886+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61887+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61888+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61889+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61890+#define GR_BIND_MSG "denied bind() by "
61891+#define GR_CONNECT_MSG "denied connect() by "
61892+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61893+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61894+#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"
61895+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61896+#define GR_CAP_ACL_MSG "use of %s denied for "
61897+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61898+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61899+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61900+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61901+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61902+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61903+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61904+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61905+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61906+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61907+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61908+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61909+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61910+#define GR_VM86_MSG "denied use of vm86 by "
61911+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61912+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61913+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61914+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61915+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
61916diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61917new file mode 100644
61918index 0000000..38bfb04
61919--- /dev/null
61920+++ b/include/linux/grsecurity.h
61921@@ -0,0 +1,233 @@
61922+#ifndef GR_SECURITY_H
61923+#define GR_SECURITY_H
61924+#include <linux/fs.h>
61925+#include <linux/fs_struct.h>
61926+#include <linux/binfmts.h>
61927+#include <linux/gracl.h>
61928+
61929+/* notify of brain-dead configs */
61930+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61931+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61932+#endif
61933+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61934+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61935+#endif
61936+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61937+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61938+#endif
61939+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61940+#error "CONFIG_PAX enabled, but no PaX options are enabled."
61941+#endif
61942+
61943+#include <linux/compat.h>
61944+
61945+struct user_arg_ptr {
61946+#ifdef CONFIG_COMPAT
61947+ bool is_compat;
61948+#endif
61949+ union {
61950+ const char __user *const __user *native;
61951+#ifdef CONFIG_COMPAT
61952+ compat_uptr_t __user *compat;
61953+#endif
61954+ } ptr;
61955+};
61956+
61957+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61958+void gr_handle_brute_check(void);
61959+void gr_handle_kernel_exploit(void);
61960+int gr_process_user_ban(void);
61961+
61962+char gr_roletype_to_char(void);
61963+
61964+int gr_acl_enable_at_secure(void);
61965+
61966+int gr_check_user_change(int real, int effective, int fs);
61967+int gr_check_group_change(int real, int effective, int fs);
61968+
61969+void gr_del_task_from_ip_table(struct task_struct *p);
61970+
61971+int gr_pid_is_chrooted(struct task_struct *p);
61972+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61973+int gr_handle_chroot_nice(void);
61974+int gr_handle_chroot_sysctl(const int op);
61975+int gr_handle_chroot_setpriority(struct task_struct *p,
61976+ const int niceval);
61977+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61978+int gr_handle_chroot_chroot(const struct dentry *dentry,
61979+ const struct vfsmount *mnt);
61980+void gr_handle_chroot_chdir(struct path *path);
61981+int gr_handle_chroot_chmod(const struct dentry *dentry,
61982+ const struct vfsmount *mnt, const int mode);
61983+int gr_handle_chroot_mknod(const struct dentry *dentry,
61984+ const struct vfsmount *mnt, const int mode);
61985+int gr_handle_chroot_mount(const struct dentry *dentry,
61986+ const struct vfsmount *mnt,
61987+ const char *dev_name);
61988+int gr_handle_chroot_pivot(void);
61989+int gr_handle_chroot_unix(const pid_t pid);
61990+
61991+int gr_handle_rawio(const struct inode *inode);
61992+
61993+void gr_handle_ioperm(void);
61994+void gr_handle_iopl(void);
61995+
61996+umode_t gr_acl_umask(void);
61997+
61998+int gr_tpe_allow(const struct file *file);
61999+
62000+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62001+void gr_clear_chroot_entries(struct task_struct *task);
62002+
62003+void gr_log_forkfail(const int retval);
62004+void gr_log_timechange(void);
62005+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62006+void gr_log_chdir(const struct dentry *dentry,
62007+ const struct vfsmount *mnt);
62008+void gr_log_chroot_exec(const struct dentry *dentry,
62009+ const struct vfsmount *mnt);
62010+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62011+void gr_log_remount(const char *devname, const int retval);
62012+void gr_log_unmount(const char *devname, const int retval);
62013+void gr_log_mount(const char *from, const char *to, const int retval);
62014+void gr_log_textrel(struct vm_area_struct *vma);
62015+void gr_log_rwxmmap(struct file *file);
62016+void gr_log_rwxmprotect(struct file *file);
62017+
62018+int gr_handle_follow_link(const struct inode *parent,
62019+ const struct inode *inode,
62020+ const struct dentry *dentry,
62021+ const struct vfsmount *mnt);
62022+int gr_handle_fifo(const struct dentry *dentry,
62023+ const struct vfsmount *mnt,
62024+ const struct dentry *dir, const int flag,
62025+ const int acc_mode);
62026+int gr_handle_hardlink(const struct dentry *dentry,
62027+ const struct vfsmount *mnt,
62028+ struct inode *inode,
62029+ const int mode, const char *to);
62030+
62031+int gr_is_capable(const int cap);
62032+int gr_is_capable_nolog(const int cap);
62033+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62034+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62035+
62036+void gr_learn_resource(const struct task_struct *task, const int limit,
62037+ const unsigned long wanted, const int gt);
62038+void gr_copy_label(struct task_struct *tsk);
62039+void gr_handle_crash(struct task_struct *task, const int sig);
62040+int gr_handle_signal(const struct task_struct *p, const int sig);
62041+int gr_check_crash_uid(const uid_t uid);
62042+int gr_check_protected_task(const struct task_struct *task);
62043+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62044+int gr_acl_handle_mmap(const struct file *file,
62045+ const unsigned long prot);
62046+int gr_acl_handle_mprotect(const struct file *file,
62047+ const unsigned long prot);
62048+int gr_check_hidden_task(const struct task_struct *tsk);
62049+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62050+ const struct vfsmount *mnt);
62051+__u32 gr_acl_handle_utime(const struct dentry *dentry,
62052+ const struct vfsmount *mnt);
62053+__u32 gr_acl_handle_access(const struct dentry *dentry,
62054+ const struct vfsmount *mnt, const int fmode);
62055+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62056+ const struct vfsmount *mnt, umode_t *mode);
62057+__u32 gr_acl_handle_chown(const struct dentry *dentry,
62058+ const struct vfsmount *mnt);
62059+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62060+ const struct vfsmount *mnt);
62061+int gr_handle_ptrace(struct task_struct *task, const long request);
62062+int gr_handle_proc_ptrace(struct task_struct *task);
62063+__u32 gr_acl_handle_execve(const struct dentry *dentry,
62064+ const struct vfsmount *mnt);
62065+int gr_check_crash_exec(const struct file *filp);
62066+int gr_acl_is_enabled(void);
62067+void gr_set_kernel_label(struct task_struct *task);
62068+void gr_set_role_label(struct task_struct *task, const uid_t uid,
62069+ const gid_t gid);
62070+int gr_set_proc_label(const struct dentry *dentry,
62071+ const struct vfsmount *mnt,
62072+ const int unsafe_flags);
62073+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62074+ const struct vfsmount *mnt);
62075+__u32 gr_acl_handle_open(const struct dentry *dentry,
62076+ const struct vfsmount *mnt, int acc_mode);
62077+__u32 gr_acl_handle_creat(const struct dentry *dentry,
62078+ const struct dentry *p_dentry,
62079+ const struct vfsmount *p_mnt,
62080+ int open_flags, int acc_mode, const int imode);
62081+void gr_handle_create(const struct dentry *dentry,
62082+ const struct vfsmount *mnt);
62083+void gr_handle_proc_create(const struct dentry *dentry,
62084+ const struct inode *inode);
62085+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62086+ const struct dentry *parent_dentry,
62087+ const struct vfsmount *parent_mnt,
62088+ const int mode);
62089+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62090+ const struct dentry *parent_dentry,
62091+ const struct vfsmount *parent_mnt);
62092+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62093+ const struct vfsmount *mnt);
62094+void gr_handle_delete(const ino_t ino, const dev_t dev);
62095+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62096+ const struct vfsmount *mnt);
62097+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62098+ const struct dentry *parent_dentry,
62099+ const struct vfsmount *parent_mnt,
62100+ const char *from);
62101+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62102+ const struct dentry *parent_dentry,
62103+ const struct vfsmount *parent_mnt,
62104+ const struct dentry *old_dentry,
62105+ const struct vfsmount *old_mnt, const char *to);
62106+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62107+int gr_acl_handle_rename(struct dentry *new_dentry,
62108+ struct dentry *parent_dentry,
62109+ const struct vfsmount *parent_mnt,
62110+ struct dentry *old_dentry,
62111+ struct inode *old_parent_inode,
62112+ struct vfsmount *old_mnt, const char *newname);
62113+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62114+ struct dentry *old_dentry,
62115+ struct dentry *new_dentry,
62116+ struct vfsmount *mnt, const __u8 replace);
62117+__u32 gr_check_link(const struct dentry *new_dentry,
62118+ const struct dentry *parent_dentry,
62119+ const struct vfsmount *parent_mnt,
62120+ const struct dentry *old_dentry,
62121+ const struct vfsmount *old_mnt);
62122+int gr_acl_handle_filldir(const struct file *file, const char *name,
62123+ const unsigned int namelen, const ino_t ino);
62124+
62125+__u32 gr_acl_handle_unix(const struct dentry *dentry,
62126+ const struct vfsmount *mnt);
62127+void gr_acl_handle_exit(void);
62128+void gr_acl_handle_psacct(struct task_struct *task, const long code);
62129+int gr_acl_handle_procpidmem(const struct task_struct *task);
62130+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62131+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62132+void gr_audit_ptrace(struct task_struct *task);
62133+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62134+
62135+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62136+
62137+#ifdef CONFIG_GRKERNSEC
62138+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62139+void gr_handle_vm86(void);
62140+void gr_handle_mem_readwrite(u64 from, u64 to);
62141+
62142+void gr_log_badprocpid(const char *entry);
62143+
62144+extern int grsec_enable_dmesg;
62145+extern int grsec_disable_privio;
62146+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62147+extern int grsec_enable_chroot_findtask;
62148+#endif
62149+#ifdef CONFIG_GRKERNSEC_SETXID
62150+extern int grsec_enable_setxid;
62151+#endif
62152+#endif
62153+
62154+#endif
62155diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62156new file mode 100644
62157index 0000000..e7ffaaf
62158--- /dev/null
62159+++ b/include/linux/grsock.h
62160@@ -0,0 +1,19 @@
62161+#ifndef __GRSOCK_H
62162+#define __GRSOCK_H
62163+
62164+extern void gr_attach_curr_ip(const struct sock *sk);
62165+extern int gr_handle_sock_all(const int family, const int type,
62166+ const int protocol);
62167+extern int gr_handle_sock_server(const struct sockaddr *sck);
62168+extern int gr_handle_sock_server_other(const struct sock *sck);
62169+extern int gr_handle_sock_client(const struct sockaddr *sck);
62170+extern int gr_search_connect(struct socket * sock,
62171+ struct sockaddr_in * addr);
62172+extern int gr_search_bind(struct socket * sock,
62173+ struct sockaddr_in * addr);
62174+extern int gr_search_listen(struct socket * sock);
62175+extern int gr_search_accept(struct socket * sock);
62176+extern int gr_search_socket(const int domain, const int type,
62177+ const int protocol);
62178+
62179+#endif
62180diff --git a/include/linux/hid.h b/include/linux/hid.h
62181index 449fa38..b37c8cc 100644
62182--- a/include/linux/hid.h
62183+++ b/include/linux/hid.h
62184@@ -704,7 +704,7 @@ struct hid_ll_driver {
62185 unsigned int code, int value);
62186
62187 int (*parse)(struct hid_device *hdev);
62188-};
62189+} __no_const;
62190
62191 #define PM_HINT_FULLON 1<<5
62192 #define PM_HINT_NORMAL 1<<1
62193diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62194index d3999b4..1304cb4 100644
62195--- a/include/linux/highmem.h
62196+++ b/include/linux/highmem.h
62197@@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
62198 kunmap_atomic(kaddr);
62199 }
62200
62201+static inline void sanitize_highpage(struct page *page)
62202+{
62203+ void *kaddr;
62204+ unsigned long flags;
62205+
62206+ local_irq_save(flags);
62207+ kaddr = kmap_atomic(page);
62208+ clear_page(kaddr);
62209+ kunmap_atomic(kaddr);
62210+ local_irq_restore(flags);
62211+}
62212+
62213 static inline void zero_user_segments(struct page *page,
62214 unsigned start1, unsigned end1,
62215 unsigned start2, unsigned end2)
62216diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62217index ddfa041..a44cfff 100644
62218--- a/include/linux/i2c.h
62219+++ b/include/linux/i2c.h
62220@@ -366,6 +366,7 @@ struct i2c_algorithm {
62221 /* To determine what the adapter supports */
62222 u32 (*functionality) (struct i2c_adapter *);
62223 };
62224+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62225
62226 /*
62227 * i2c_adapter is the structure used to identify a physical i2c bus along
62228diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62229index d23c3c2..eb63c81 100644
62230--- a/include/linux/i2o.h
62231+++ b/include/linux/i2o.h
62232@@ -565,7 +565,7 @@ struct i2o_controller {
62233 struct i2o_device *exec; /* Executive */
62234 #if BITS_PER_LONG == 64
62235 spinlock_t context_list_lock; /* lock for context_list */
62236- atomic_t context_list_counter; /* needed for unique contexts */
62237+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62238 struct list_head context_list; /* list of context id's
62239 and pointers */
62240 #endif
62241diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62242index 8185f57..7b2d222 100644
62243--- a/include/linux/if_team.h
62244+++ b/include/linux/if_team.h
62245@@ -74,6 +74,7 @@ struct team_mode_ops {
62246 void (*port_leave)(struct team *team, struct team_port *port);
62247 void (*port_change_mac)(struct team *team, struct team_port *port);
62248 };
62249+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62250
62251 enum team_option_type {
62252 TEAM_OPTION_TYPE_U32,
62253@@ -136,7 +137,7 @@ struct team {
62254 struct list_head option_inst_list; /* list of option instances */
62255
62256 const struct team_mode *mode;
62257- struct team_mode_ops ops;
62258+ team_mode_ops_no_const ops;
62259 long mode_priv[TEAM_MODE_PRIV_LONGS];
62260 };
62261
62262diff --git a/include/linux/init.h b/include/linux/init.h
62263index 6b95109..bcbdd68 100644
62264--- a/include/linux/init.h
62265+++ b/include/linux/init.h
62266@@ -39,9 +39,15 @@
62267 * Also note, that this data cannot be "const".
62268 */
62269
62270+#ifdef MODULE
62271+#define add_latent_entropy
62272+#else
62273+#define add_latent_entropy __latent_entropy
62274+#endif
62275+
62276 /* These are for everybody (although not all archs will actually
62277 discard it in modules) */
62278-#define __init __section(.init.text) __cold notrace
62279+#define __init __section(.init.text) __cold notrace add_latent_entropy
62280 #define __initdata __section(.init.data)
62281 #define __initconst __section(.init.rodata)
62282 #define __exitdata __section(.exit.data)
62283@@ -83,7 +89,7 @@
62284 #define __exit __section(.exit.text) __exitused __cold notrace
62285
62286 /* Used for HOTPLUG */
62287-#define __devinit __section(.devinit.text) __cold notrace
62288+#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62289 #define __devinitdata __section(.devinit.data)
62290 #define __devinitconst __section(.devinit.rodata)
62291 #define __devexit __section(.devexit.text) __exitused __cold notrace
62292@@ -91,7 +97,7 @@
62293 #define __devexitconst __section(.devexit.rodata)
62294
62295 /* Used for HOTPLUG_CPU */
62296-#define __cpuinit __section(.cpuinit.text) __cold notrace
62297+#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62298 #define __cpuinitdata __section(.cpuinit.data)
62299 #define __cpuinitconst __section(.cpuinit.rodata)
62300 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62301@@ -99,7 +105,7 @@
62302 #define __cpuexitconst __section(.cpuexit.rodata)
62303
62304 /* Used for MEMORY_HOTPLUG */
62305-#define __meminit __section(.meminit.text) __cold notrace
62306+#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62307 #define __meminitdata __section(.meminit.data)
62308 #define __meminitconst __section(.meminit.rodata)
62309 #define __memexit __section(.memexit.text) __exitused __cold notrace
62310@@ -294,13 +300,13 @@ void __init parse_early_options(char *cmdline);
62311
62312 /* Each module must use one module_init(). */
62313 #define module_init(initfn) \
62314- static inline initcall_t __inittest(void) \
62315+ static inline __used initcall_t __inittest(void) \
62316 { return initfn; } \
62317 int init_module(void) __attribute__((alias(#initfn)));
62318
62319 /* This is only required if you want to be unloadable. */
62320 #define module_exit(exitfn) \
62321- static inline exitcall_t __exittest(void) \
62322+ static inline __used exitcall_t __exittest(void) \
62323 { return exitfn; } \
62324 void cleanup_module(void) __attribute__((alias(#exitfn)));
62325
62326diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62327index 9e65eff..b131e8b 100644
62328--- a/include/linux/init_task.h
62329+++ b/include/linux/init_task.h
62330@@ -134,6 +134,12 @@ extern struct cred init_cred;
62331
62332 #define INIT_TASK_COMM "swapper"
62333
62334+#ifdef CONFIG_X86
62335+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62336+#else
62337+#define INIT_TASK_THREAD_INFO
62338+#endif
62339+
62340 /*
62341 * INIT_TASK is used to set up the first task table, touch at
62342 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62343@@ -172,6 +178,7 @@ extern struct cred init_cred;
62344 RCU_INIT_POINTER(.cred, &init_cred), \
62345 .comm = INIT_TASK_COMM, \
62346 .thread = INIT_THREAD, \
62347+ INIT_TASK_THREAD_INFO \
62348 .fs = &init_fs, \
62349 .files = &init_files, \
62350 .signal = &init_signals, \
62351diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62352index e6ca56d..8583707 100644
62353--- a/include/linux/intel-iommu.h
62354+++ b/include/linux/intel-iommu.h
62355@@ -296,7 +296,7 @@ struct iommu_flush {
62356 u8 fm, u64 type);
62357 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62358 unsigned int size_order, u64 type);
62359-};
62360+} __no_const;
62361
62362 enum {
62363 SR_DMAR_FECTL_REG,
62364diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62365index e68a8e5..811b9af 100644
62366--- a/include/linux/interrupt.h
62367+++ b/include/linux/interrupt.h
62368@@ -435,7 +435,7 @@ enum
62369 /* map softirq index to softirq name. update 'softirq_to_name' in
62370 * kernel/softirq.c when adding a new softirq.
62371 */
62372-extern char *softirq_to_name[NR_SOFTIRQS];
62373+extern const char * const softirq_to_name[NR_SOFTIRQS];
62374
62375 /* softirq mask and active fields moved to irq_cpustat_t in
62376 * asm/hardirq.h to get better cache usage. KAO
62377@@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62378
62379 struct softirq_action
62380 {
62381- void (*action)(struct softirq_action *);
62382+ void (*action)(void);
62383 };
62384
62385 asmlinkage void do_softirq(void);
62386 asmlinkage void __do_softirq(void);
62387-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62388+extern void open_softirq(int nr, void (*action)(void));
62389 extern void softirq_init(void);
62390 extern void __raise_softirq_irqoff(unsigned int nr);
62391
62392diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62393index 6883e19..06992b1 100644
62394--- a/include/linux/kallsyms.h
62395+++ b/include/linux/kallsyms.h
62396@@ -15,7 +15,8 @@
62397
62398 struct module;
62399
62400-#ifdef CONFIG_KALLSYMS
62401+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62402+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62403 /* Lookup the address for a symbol. Returns 0 if not found. */
62404 unsigned long kallsyms_lookup_name(const char *name);
62405
62406@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62407 /* Stupid that this does nothing, but I didn't create this mess. */
62408 #define __print_symbol(fmt, addr)
62409 #endif /*CONFIG_KALLSYMS*/
62410+#else /* when included by kallsyms.c, vsnprintf.c, or
62411+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62412+extern void __print_symbol(const char *fmt, unsigned long address);
62413+extern int sprint_backtrace(char *buffer, unsigned long address);
62414+extern int sprint_symbol(char *buffer, unsigned long address);
62415+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
62416+const char *kallsyms_lookup(unsigned long addr,
62417+ unsigned long *symbolsize,
62418+ unsigned long *offset,
62419+ char **modname, char *namebuf);
62420+#endif
62421
62422 /* This macro allows us to keep printk typechecking */
62423 static __printf(1, 2)
62424diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62425index c4d2fc1..5df9c19 100644
62426--- a/include/linux/kgdb.h
62427+++ b/include/linux/kgdb.h
62428@@ -53,7 +53,7 @@ extern int kgdb_connected;
62429 extern int kgdb_io_module_registered;
62430
62431 extern atomic_t kgdb_setting_breakpoint;
62432-extern atomic_t kgdb_cpu_doing_single_step;
62433+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62434
62435 extern struct task_struct *kgdb_usethread;
62436 extern struct task_struct *kgdb_contthread;
62437@@ -252,7 +252,7 @@ struct kgdb_arch {
62438 void (*disable_hw_break)(struct pt_regs *regs);
62439 void (*remove_all_hw_break)(void);
62440 void (*correct_hw_break)(void);
62441-};
62442+} __do_const;
62443
62444 /**
62445 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62446@@ -277,7 +277,7 @@ struct kgdb_io {
62447 void (*pre_exception) (void);
62448 void (*post_exception) (void);
62449 int is_console;
62450-};
62451+} __do_const;
62452
62453 extern struct kgdb_arch arch_kgdb_ops;
62454
62455diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62456index 5398d58..5883a34 100644
62457--- a/include/linux/kmod.h
62458+++ b/include/linux/kmod.h
62459@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62460 * usually useless though. */
62461 extern __printf(2, 3)
62462 int __request_module(bool wait, const char *name, ...);
62463+extern __printf(3, 4)
62464+int ___request_module(bool wait, char *param_name, const char *name, ...);
62465 #define request_module(mod...) __request_module(true, mod)
62466 #define request_module_nowait(mod...) __request_module(false, mod)
62467 #define try_then_request_module(x, mod...) \
62468diff --git a/include/linux/kref.h b/include/linux/kref.h
62469index 9c07dce..a92fa71 100644
62470--- a/include/linux/kref.h
62471+++ b/include/linux/kref.h
62472@@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62473 static inline int kref_sub(struct kref *kref, unsigned int count,
62474 void (*release)(struct kref *kref))
62475 {
62476- WARN_ON(release == NULL);
62477+ BUG_ON(release == NULL);
62478
62479 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62480 release(kref);
62481diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62482index 96c158a..1864db5 100644
62483--- a/include/linux/kvm_host.h
62484+++ b/include/linux/kvm_host.h
62485@@ -345,7 +345,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62486 void vcpu_load(struct kvm_vcpu *vcpu);
62487 void vcpu_put(struct kvm_vcpu *vcpu);
62488
62489-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62490+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62491 struct module *module);
62492 void kvm_exit(void);
62493
62494@@ -511,7 +511,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62495 struct kvm_guest_debug *dbg);
62496 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62497
62498-int kvm_arch_init(void *opaque);
62499+int kvm_arch_init(const void *opaque);
62500 void kvm_arch_exit(void);
62501
62502 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62503diff --git a/include/linux/libata.h b/include/linux/libata.h
62504index 6e887c7..4539601 100644
62505--- a/include/linux/libata.h
62506+++ b/include/linux/libata.h
62507@@ -910,7 +910,7 @@ struct ata_port_operations {
62508 * fields must be pointers.
62509 */
62510 const struct ata_port_operations *inherits;
62511-};
62512+} __do_const;
62513
62514 struct ata_port_info {
62515 unsigned long flags;
62516diff --git a/include/linux/memory.h b/include/linux/memory.h
62517index 1ac7f6e..a5794d0 100644
62518--- a/include/linux/memory.h
62519+++ b/include/linux/memory.h
62520@@ -143,7 +143,7 @@ struct memory_accessor {
62521 size_t count);
62522 ssize_t (*write)(struct memory_accessor *, const char *buf,
62523 off_t offset, size_t count);
62524-};
62525+} __no_const;
62526
62527 /*
62528 * Kernel text modification mutex, used for code patching. Users of this lock
62529diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62530index 1318ca6..7521340 100644
62531--- a/include/linux/mfd/abx500.h
62532+++ b/include/linux/mfd/abx500.h
62533@@ -452,6 +452,7 @@ struct abx500_ops {
62534 int (*event_registers_startup_state_get) (struct device *, u8 *);
62535 int (*startup_irq_enabled) (struct device *, unsigned int);
62536 };
62537+typedef struct abx500_ops __no_const abx500_ops_no_const;
62538
62539 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62540 void abx500_remove_ops(struct device *dev);
62541diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
62542index 9b07725..3d55001 100644
62543--- a/include/linux/mfd/abx500/ux500_chargalg.h
62544+++ b/include/linux/mfd/abx500/ux500_chargalg.h
62545@@ -19,7 +19,7 @@ struct ux500_charger_ops {
62546 int (*enable) (struct ux500_charger *, int, int, int);
62547 int (*kick_wd) (struct ux500_charger *);
62548 int (*update_curr) (struct ux500_charger *, int);
62549-};
62550+} __no_const;
62551
62552 /**
62553 * struct ux500_charger - power supply ux500 charger sub class
62554diff --git a/include/linux/mm.h b/include/linux/mm.h
62555index b36d08c..410ee7c 100644
62556--- a/include/linux/mm.h
62557+++ b/include/linux/mm.h
62558@@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
62559
62560 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62561 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62562+
62563+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62564+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62565+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62566+#else
62567 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62568+#endif
62569+
62570 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62571 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62572
62573@@ -1009,34 +1016,6 @@ int set_page_dirty(struct page *page);
62574 int set_page_dirty_lock(struct page *page);
62575 int clear_page_dirty_for_io(struct page *page);
62576
62577-/* Is the vma a continuation of the stack vma above it? */
62578-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62579-{
62580- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62581-}
62582-
62583-static inline int stack_guard_page_start(struct vm_area_struct *vma,
62584- unsigned long addr)
62585-{
62586- return (vma->vm_flags & VM_GROWSDOWN) &&
62587- (vma->vm_start == addr) &&
62588- !vma_growsdown(vma->vm_prev, addr);
62589-}
62590-
62591-/* Is the vma a continuation of the stack vma below it? */
62592-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62593-{
62594- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62595-}
62596-
62597-static inline int stack_guard_page_end(struct vm_area_struct *vma,
62598- unsigned long addr)
62599-{
62600- return (vma->vm_flags & VM_GROWSUP) &&
62601- (vma->vm_end == addr) &&
62602- !vma_growsup(vma->vm_next, addr);
62603-}
62604-
62605 extern pid_t
62606 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
62607
62608@@ -1135,6 +1114,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
62609 }
62610 #endif
62611
62612+#ifdef CONFIG_MMU
62613+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62614+#else
62615+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62616+{
62617+ return __pgprot(0);
62618+}
62619+#endif
62620+
62621 int vma_wants_writenotify(struct vm_area_struct *vma);
62622
62623 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62624@@ -1153,8 +1141,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
62625 {
62626 return 0;
62627 }
62628+
62629+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
62630+ unsigned long address)
62631+{
62632+ return 0;
62633+}
62634 #else
62635 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62636+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62637 #endif
62638
62639 #ifdef __PAGETABLE_PMD_FOLDED
62640@@ -1163,8 +1158,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
62641 {
62642 return 0;
62643 }
62644+
62645+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
62646+ unsigned long address)
62647+{
62648+ return 0;
62649+}
62650 #else
62651 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
62652+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
62653 #endif
62654
62655 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
62656@@ -1182,11 +1184,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
62657 NULL: pud_offset(pgd, address);
62658 }
62659
62660+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
62661+{
62662+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
62663+ NULL: pud_offset(pgd, address);
62664+}
62665+
62666 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
62667 {
62668 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
62669 NULL: pmd_offset(pud, address);
62670 }
62671+
62672+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
62673+{
62674+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
62675+ NULL: pmd_offset(pud, address);
62676+}
62677 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
62678
62679 #if USE_SPLIT_PTLOCKS
62680@@ -1396,6 +1410,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
62681 unsigned long, unsigned long,
62682 unsigned long, unsigned long);
62683 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62684+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62685
62686 /* These take the mm semaphore themselves */
62687 extern unsigned long vm_brk(unsigned long, unsigned long);
62688@@ -1458,6 +1473,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62689 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62690 struct vm_area_struct **pprev);
62691
62692+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62693+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62694+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62695+
62696 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62697 NULL if none. Assume start_addr < end_addr. */
62698 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62699@@ -1486,15 +1505,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62700 return vma;
62701 }
62702
62703-#ifdef CONFIG_MMU
62704-pgprot_t vm_get_page_prot(unsigned long vm_flags);
62705-#else
62706-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62707-{
62708- return __pgprot(0);
62709-}
62710-#endif
62711-
62712 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62713 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62714 unsigned long pfn, unsigned long size, pgprot_t);
62715@@ -1598,7 +1608,7 @@ extern int unpoison_memory(unsigned long pfn);
62716 extern int sysctl_memory_failure_early_kill;
62717 extern int sysctl_memory_failure_recovery;
62718 extern void shake_page(struct page *p, int access);
62719-extern atomic_long_t mce_bad_pages;
62720+extern atomic_long_unchecked_t mce_bad_pages;
62721 extern int soft_offline_page(struct page *page, int flags);
62722
62723 extern void dump_page(struct page *page);
62724@@ -1629,5 +1639,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62725 static inline bool page_is_guard(struct page *page) { return false; }
62726 #endif /* CONFIG_DEBUG_PAGEALLOC */
62727
62728+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62729+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62730+#else
62731+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62732+#endif
62733+
62734 #endif /* __KERNEL__ */
62735 #endif /* _LINUX_MM_H */
62736diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62737index 704a626..bb0705a 100644
62738--- a/include/linux/mm_types.h
62739+++ b/include/linux/mm_types.h
62740@@ -263,6 +263,8 @@ struct vm_area_struct {
62741 #ifdef CONFIG_NUMA
62742 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62743 #endif
62744+
62745+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62746 };
62747
62748 struct core_thread {
62749@@ -337,7 +339,7 @@ struct mm_struct {
62750 unsigned long def_flags;
62751 unsigned long nr_ptes; /* Page table pages */
62752 unsigned long start_code, end_code, start_data, end_data;
62753- unsigned long start_brk, brk, start_stack;
62754+ unsigned long brk_gap, start_brk, brk, start_stack;
62755 unsigned long arg_start, arg_end, env_start, env_end;
62756
62757 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62758@@ -389,6 +391,24 @@ struct mm_struct {
62759 struct cpumask cpumask_allocation;
62760 #endif
62761 struct uprobes_state uprobes_state;
62762+
62763+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62764+ unsigned long pax_flags;
62765+#endif
62766+
62767+#ifdef CONFIG_PAX_DLRESOLVE
62768+ unsigned long call_dl_resolve;
62769+#endif
62770+
62771+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62772+ unsigned long call_syscall;
62773+#endif
62774+
62775+#ifdef CONFIG_PAX_ASLR
62776+ unsigned long delta_mmap; /* randomized offset */
62777+ unsigned long delta_stack; /* randomized offset */
62778+#endif
62779+
62780 };
62781
62782 static inline void mm_init_cpumask(struct mm_struct *mm)
62783diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62784index 1d1b1e1..2a13c78 100644
62785--- a/include/linux/mmu_notifier.h
62786+++ b/include/linux/mmu_notifier.h
62787@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62788 */
62789 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62790 ({ \
62791- pte_t __pte; \
62792+ pte_t ___pte; \
62793 struct vm_area_struct *___vma = __vma; \
62794 unsigned long ___address = __address; \
62795- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62796+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62797 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62798- __pte; \
62799+ ___pte; \
62800 })
62801
62802 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62803diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62804index 68c569f..5f43753 100644
62805--- a/include/linux/mmzone.h
62806+++ b/include/linux/mmzone.h
62807@@ -411,7 +411,7 @@ struct zone {
62808 unsigned long flags; /* zone flags, see below */
62809
62810 /* Zone statistics */
62811- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62812+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62813
62814 /*
62815 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62816diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62817index 5db9382..50e801d 100644
62818--- a/include/linux/mod_devicetable.h
62819+++ b/include/linux/mod_devicetable.h
62820@@ -12,7 +12,7 @@
62821 typedef unsigned long kernel_ulong_t;
62822 #endif
62823
62824-#define PCI_ANY_ID (~0)
62825+#define PCI_ANY_ID ((__u16)~0)
62826
62827 struct pci_device_id {
62828 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62829@@ -131,7 +131,7 @@ struct usb_device_id {
62830 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62831 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62832
62833-#define HID_ANY_ID (~0)
62834+#define HID_ANY_ID (~0U)
62835 #define HID_BUS_ANY 0xffff
62836 #define HID_GROUP_ANY 0x0000
62837
62838diff --git a/include/linux/module.h b/include/linux/module.h
62839index fbcafe2..e5d9587 100644
62840--- a/include/linux/module.h
62841+++ b/include/linux/module.h
62842@@ -17,6 +17,7 @@
62843 #include <linux/moduleparam.h>
62844 #include <linux/tracepoint.h>
62845 #include <linux/export.h>
62846+#include <linux/fs.h>
62847
62848 #include <linux/percpu.h>
62849 #include <asm/module.h>
62850@@ -273,19 +274,16 @@ struct module
62851 int (*init)(void);
62852
62853 /* If this is non-NULL, vfree after init() returns */
62854- void *module_init;
62855+ void *module_init_rx, *module_init_rw;
62856
62857 /* Here is the actual code + data, vfree'd on unload. */
62858- void *module_core;
62859+ void *module_core_rx, *module_core_rw;
62860
62861 /* Here are the sizes of the init and core sections */
62862- unsigned int init_size, core_size;
62863+ unsigned int init_size_rw, core_size_rw;
62864
62865 /* The size of the executable code in each section. */
62866- unsigned int init_text_size, core_text_size;
62867-
62868- /* Size of RO sections of the module (text+rodata) */
62869- unsigned int init_ro_size, core_ro_size;
62870+ unsigned int init_size_rx, core_size_rx;
62871
62872 /* Arch-specific module values */
62873 struct mod_arch_specific arch;
62874@@ -341,6 +339,10 @@ struct module
62875 #ifdef CONFIG_EVENT_TRACING
62876 struct ftrace_event_call **trace_events;
62877 unsigned int num_trace_events;
62878+ struct file_operations trace_id;
62879+ struct file_operations trace_enable;
62880+ struct file_operations trace_format;
62881+ struct file_operations trace_filter;
62882 #endif
62883 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62884 unsigned int num_ftrace_callsites;
62885@@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
62886 bool is_module_percpu_address(unsigned long addr);
62887 bool is_module_text_address(unsigned long addr);
62888
62889+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62890+{
62891+
62892+#ifdef CONFIG_PAX_KERNEXEC
62893+ if (ktla_ktva(addr) >= (unsigned long)start &&
62894+ ktla_ktva(addr) < (unsigned long)start + size)
62895+ return 1;
62896+#endif
62897+
62898+ return ((void *)addr >= start && (void *)addr < start + size);
62899+}
62900+
62901+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62902+{
62903+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62904+}
62905+
62906+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62907+{
62908+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62909+}
62910+
62911+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62912+{
62913+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62914+}
62915+
62916+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62917+{
62918+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62919+}
62920+
62921 static inline int within_module_core(unsigned long addr, struct module *mod)
62922 {
62923- return (unsigned long)mod->module_core <= addr &&
62924- addr < (unsigned long)mod->module_core + mod->core_size;
62925+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62926 }
62927
62928 static inline int within_module_init(unsigned long addr, struct module *mod)
62929 {
62930- return (unsigned long)mod->module_init <= addr &&
62931- addr < (unsigned long)mod->module_init + mod->init_size;
62932+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62933 }
62934
62935 /* Search for module by name: must hold module_mutex. */
62936diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62937index b2be02e..72d2f78 100644
62938--- a/include/linux/moduleloader.h
62939+++ b/include/linux/moduleloader.h
62940@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62941
62942 /* Allocator used for allocating struct module, core sections and init
62943 sections. Returns NULL on failure. */
62944-void *module_alloc(unsigned long size);
62945+void *module_alloc(unsigned long size) __size_overflow(1);
62946+
62947+#ifdef CONFIG_PAX_KERNEXEC
62948+void *module_alloc_exec(unsigned long size) __size_overflow(1);
62949+#else
62950+#define module_alloc_exec(x) module_alloc(x)
62951+#endif
62952
62953 /* Free memory returned from module_alloc. */
62954 void module_free(struct module *mod, void *module_region);
62955
62956+#ifdef CONFIG_PAX_KERNEXEC
62957+void module_free_exec(struct module *mod, void *module_region);
62958+#else
62959+#define module_free_exec(x, y) module_free((x), (y))
62960+#endif
62961+
62962 /* Apply the given relocation to the (simplified) ELF. Return -error
62963 or 0. */
62964 int apply_relocate(Elf_Shdr *sechdrs,
62965diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62966index d6a5806..7c13347 100644
62967--- a/include/linux/moduleparam.h
62968+++ b/include/linux/moduleparam.h
62969@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
62970 * @len is usually just sizeof(string).
62971 */
62972 #define module_param_string(name, string, len, perm) \
62973- static const struct kparam_string __param_string_##name \
62974+ static const struct kparam_string __param_string_##name __used \
62975 = { len, string }; \
62976 __module_param_call(MODULE_PARAM_PREFIX, name, \
62977 &param_ops_string, \
62978@@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62979 */
62980 #define module_param_array_named(name, array, type, nump, perm) \
62981 param_check_##type(name, &(array)[0]); \
62982- static const struct kparam_array __param_arr_##name \
62983+ static const struct kparam_array __param_arr_##name __used \
62984 = { .max = ARRAY_SIZE(array), .num = nump, \
62985 .ops = &param_ops_##type, \
62986 .elemsize = sizeof(array[0]), .elem = array }; \
62987diff --git a/include/linux/namei.h b/include/linux/namei.h
62988index ffc0213..2c1f2cb 100644
62989--- a/include/linux/namei.h
62990+++ b/include/linux/namei.h
62991@@ -24,7 +24,7 @@ struct nameidata {
62992 unsigned seq;
62993 int last_type;
62994 unsigned depth;
62995- char *saved_names[MAX_NESTED_LINKS + 1];
62996+ const char *saved_names[MAX_NESTED_LINKS + 1];
62997
62998 /* Intent data */
62999 union {
63000@@ -94,12 +94,12 @@ extern int follow_up(struct path *);
63001 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
63002 extern void unlock_rename(struct dentry *, struct dentry *);
63003
63004-static inline void nd_set_link(struct nameidata *nd, char *path)
63005+static inline void nd_set_link(struct nameidata *nd, const char *path)
63006 {
63007 nd->saved_names[nd->depth] = path;
63008 }
63009
63010-static inline char *nd_get_link(struct nameidata *nd)
63011+static inline const char *nd_get_link(const struct nameidata *nd)
63012 {
63013 return nd->saved_names[nd->depth];
63014 }
63015diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63016index d94cb14..e64c951 100644
63017--- a/include/linux/netdevice.h
63018+++ b/include/linux/netdevice.h
63019@@ -1026,6 +1026,7 @@ struct net_device_ops {
63020 struct net_device *dev,
63021 int idx);
63022 };
63023+typedef struct net_device_ops __no_const net_device_ops_no_const;
63024
63025 /*
63026 * The DEVICE structure.
63027@@ -1087,7 +1088,7 @@ struct net_device {
63028 int iflink;
63029
63030 struct net_device_stats stats;
63031- atomic_long_t rx_dropped; /* dropped packets by core network
63032+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63033 * Do not use this in drivers.
63034 */
63035
63036diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63037new file mode 100644
63038index 0000000..33f4af8
63039--- /dev/null
63040+++ b/include/linux/netfilter/xt_gradm.h
63041@@ -0,0 +1,9 @@
63042+#ifndef _LINUX_NETFILTER_XT_GRADM_H
63043+#define _LINUX_NETFILTER_XT_GRADM_H 1
63044+
63045+struct xt_gradm_mtinfo {
63046+ __u16 flags;
63047+ __u16 invflags;
63048+};
63049+
63050+#endif
63051diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63052index c65a18a..0c05f3a 100644
63053--- a/include/linux/of_pdt.h
63054+++ b/include/linux/of_pdt.h
63055@@ -32,7 +32,7 @@ struct of_pdt_ops {
63056
63057 /* return 0 on success; fill in 'len' with number of bytes in path */
63058 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63059-};
63060+} __no_const;
63061
63062 extern void *prom_early_alloc(unsigned long size);
63063
63064diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63065index a4c5624..79d6d88 100644
63066--- a/include/linux/oprofile.h
63067+++ b/include/linux/oprofile.h
63068@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63069 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63070 char const * name, ulong * val);
63071
63072-/** Create a file for read-only access to an atomic_t. */
63073+/** Create a file for read-only access to an atomic_unchecked_t. */
63074 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63075- char const * name, atomic_t * val);
63076+ char const * name, atomic_unchecked_t * val);
63077
63078 /** create a directory */
63079 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63080diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63081index 45db49f..386788e 100644
63082--- a/include/linux/perf_event.h
63083+++ b/include/linux/perf_event.h
63084@@ -879,8 +879,8 @@ struct perf_event {
63085
63086 enum perf_event_active_state state;
63087 unsigned int attach_state;
63088- local64_t count;
63089- atomic64_t child_count;
63090+ local64_t count; /* PaX: fix it one day */
63091+ atomic64_unchecked_t child_count;
63092
63093 /*
63094 * These are the total time in nanoseconds that the event
63095@@ -931,8 +931,8 @@ struct perf_event {
63096 * These accumulate total time (in nanoseconds) that children
63097 * events have been enabled and running, respectively.
63098 */
63099- atomic64_t child_total_time_enabled;
63100- atomic64_t child_total_time_running;
63101+ atomic64_unchecked_t child_total_time_enabled;
63102+ atomic64_unchecked_t child_total_time_running;
63103
63104 /*
63105 * Protect attach/detach and child_list:
63106diff --git a/include/linux/personality.h b/include/linux/personality.h
63107index 8fc7dd1a..c19d89e 100644
63108--- a/include/linux/personality.h
63109+++ b/include/linux/personality.h
63110@@ -44,6 +44,7 @@ enum {
63111 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63112 ADDR_NO_RANDOMIZE | \
63113 ADDR_COMPAT_LAYOUT | \
63114+ ADDR_LIMIT_3GB | \
63115 MMAP_PAGE_ZERO)
63116
63117 /*
63118diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63119index e1ac1ce..0675fed 100644
63120--- a/include/linux/pipe_fs_i.h
63121+++ b/include/linux/pipe_fs_i.h
63122@@ -45,9 +45,9 @@ struct pipe_buffer {
63123 struct pipe_inode_info {
63124 wait_queue_head_t wait;
63125 unsigned int nrbufs, curbuf, buffers;
63126- unsigned int readers;
63127- unsigned int writers;
63128- unsigned int waiting_writers;
63129+ atomic_t readers;
63130+ atomic_t writers;
63131+ atomic_t waiting_writers;
63132 unsigned int r_counter;
63133 unsigned int w_counter;
63134 struct page *tmp_page;
63135diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63136index f271860..6b3bec5 100644
63137--- a/include/linux/pm_runtime.h
63138+++ b/include/linux/pm_runtime.h
63139@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63140
63141 static inline void pm_runtime_mark_last_busy(struct device *dev)
63142 {
63143- ACCESS_ONCE(dev->power.last_busy) = jiffies;
63144+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63145 }
63146
63147 #else /* !CONFIG_PM_RUNTIME */
63148diff --git a/include/linux/poison.h b/include/linux/poison.h
63149index 2110a81..13a11bb 100644
63150--- a/include/linux/poison.h
63151+++ b/include/linux/poison.h
63152@@ -19,8 +19,8 @@
63153 * under normal circumstances, used to verify that nobody uses
63154 * non-initialized list entries.
63155 */
63156-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63157-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63158+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63159+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63160
63161 /********** include/linux/timer.h **********/
63162 /*
63163diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63164index 5a710b9..0b0dab9 100644
63165--- a/include/linux/preempt.h
63166+++ b/include/linux/preempt.h
63167@@ -126,7 +126,7 @@ struct preempt_ops {
63168 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63169 void (*sched_out)(struct preempt_notifier *notifier,
63170 struct task_struct *next);
63171-};
63172+} __no_const;
63173
63174 /**
63175 * preempt_notifier - key for installing preemption notifiers
63176diff --git a/include/linux/printk.h b/include/linux/printk.h
63177index 1bec2f7..b66e833 100644
63178--- a/include/linux/printk.h
63179+++ b/include/linux/printk.h
63180@@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
63181 extern int printk_needs_cpu(int cpu);
63182 extern void printk_tick(void);
63183
63184+extern int kptr_restrict;
63185+
63186 #ifdef CONFIG_PRINTK
63187 asmlinkage __printf(5, 0)
63188 int vprintk_emit(int facility, int level,
63189@@ -128,7 +130,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63190
63191 extern int printk_delay_msec;
63192 extern int dmesg_restrict;
63193-extern int kptr_restrict;
63194
63195 void log_buf_kexec_setup(void);
63196 void __init setup_log_buf(int early);
63197diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63198index 3fd2e87..d93a721 100644
63199--- a/include/linux/proc_fs.h
63200+++ b/include/linux/proc_fs.h
63201@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63202 return proc_create_data(name, mode, parent, proc_fops, NULL);
63203 }
63204
63205+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63206+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63207+{
63208+#ifdef CONFIG_GRKERNSEC_PROC_USER
63209+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63210+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63211+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63212+#else
63213+ return proc_create_data(name, mode, parent, proc_fops, NULL);
63214+#endif
63215+}
63216+
63217 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63218 umode_t mode, struct proc_dir_entry *base,
63219 read_proc_t *read_proc, void * data)
63220@@ -258,7 +270,7 @@ union proc_op {
63221 int (*proc_show)(struct seq_file *m,
63222 struct pid_namespace *ns, struct pid *pid,
63223 struct task_struct *task);
63224-};
63225+} __no_const;
63226
63227 struct ctl_table_header;
63228 struct ctl_table;
63229diff --git a/include/linux/random.h b/include/linux/random.h
63230index 8f74538..de61694 100644
63231--- a/include/linux/random.h
63232+++ b/include/linux/random.h
63233@@ -54,6 +54,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63234 unsigned int value);
63235 extern void add_interrupt_randomness(int irq);
63236
63237+#ifdef CONFIG_PAX_LATENT_ENTROPY
63238+extern void transfer_latent_entropy(void);
63239+#endif
63240+
63241 extern void get_random_bytes(void *buf, int nbytes);
63242 void generate_random_uuid(unsigned char uuid_out[16]);
63243
63244@@ -69,12 +73,17 @@ void srandom32(u32 seed);
63245
63246 u32 prandom32(struct rnd_state *);
63247
63248+static inline unsigned long pax_get_random_long(void)
63249+{
63250+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63251+}
63252+
63253 /*
63254 * Handle minimum values for seeds
63255 */
63256 static inline u32 __seed(u32 x, u32 m)
63257 {
63258- return (x < m) ? x + m : x;
63259+ return (x <= m) ? x + m + 1 : x;
63260 }
63261
63262 /**
63263diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63264index e0879a7..a12f962 100644
63265--- a/include/linux/reboot.h
63266+++ b/include/linux/reboot.h
63267@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63268 * Architecture-specific implementations of sys_reboot commands.
63269 */
63270
63271-extern void machine_restart(char *cmd);
63272-extern void machine_halt(void);
63273-extern void machine_power_off(void);
63274+extern void machine_restart(char *cmd) __noreturn;
63275+extern void machine_halt(void) __noreturn;
63276+extern void machine_power_off(void) __noreturn;
63277
63278 extern void machine_shutdown(void);
63279 struct pt_regs;
63280@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63281 */
63282
63283 extern void kernel_restart_prepare(char *cmd);
63284-extern void kernel_restart(char *cmd);
63285-extern void kernel_halt(void);
63286-extern void kernel_power_off(void);
63287+extern void kernel_restart(char *cmd) __noreturn;
63288+extern void kernel_halt(void) __noreturn;
63289+extern void kernel_power_off(void) __noreturn;
63290
63291 extern int C_A_D; /* for sysctl */
63292 void ctrl_alt_del(void);
63293@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63294 * Emergency restart, callable from an interrupt handler.
63295 */
63296
63297-extern void emergency_restart(void);
63298+extern void emergency_restart(void) __noreturn;
63299 #include <asm/emergency-restart.h>
63300
63301 #endif
63302diff --git a/include/linux/relay.h b/include/linux/relay.h
63303index 91cacc3..b55ff74 100644
63304--- a/include/linux/relay.h
63305+++ b/include/linux/relay.h
63306@@ -160,7 +160,7 @@ struct rchan_callbacks
63307 * The callback should return 0 if successful, negative if not.
63308 */
63309 int (*remove_buf_file)(struct dentry *dentry);
63310-};
63311+} __no_const;
63312
63313 /*
63314 * CONFIG_RELAY kernel API, kernel/relay.c
63315diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63316index 6fdf027..ff72610 100644
63317--- a/include/linux/rfkill.h
63318+++ b/include/linux/rfkill.h
63319@@ -147,6 +147,7 @@ struct rfkill_ops {
63320 void (*query)(struct rfkill *rfkill, void *data);
63321 int (*set_block)(void *data, bool blocked);
63322 };
63323+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63324
63325 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63326 /**
63327diff --git a/include/linux/rio.h b/include/linux/rio.h
63328index a90ebad..fd87b5d 100644
63329--- a/include/linux/rio.h
63330+++ b/include/linux/rio.h
63331@@ -321,7 +321,7 @@ struct rio_ops {
63332 int mbox, void *buffer, size_t len);
63333 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63334 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63335-};
63336+} __no_const;
63337
63338 #define RIO_RESOURCE_MEM 0x00000100
63339 #define RIO_RESOURCE_DOORBELL 0x00000200
63340diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63341index 3fce545..b4fed6e 100644
63342--- a/include/linux/rmap.h
63343+++ b/include/linux/rmap.h
63344@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63345 void anon_vma_init(void); /* create anon_vma_cachep */
63346 int anon_vma_prepare(struct vm_area_struct *);
63347 void unlink_anon_vmas(struct vm_area_struct *);
63348-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63349+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63350 void anon_vma_moveto_tail(struct vm_area_struct *);
63351-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63352+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63353
63354 static inline void anon_vma_merge(struct vm_area_struct *vma,
63355 struct vm_area_struct *next)
63356diff --git a/include/linux/sched.h b/include/linux/sched.h
63357index 4a1f493..5812aeb 100644
63358--- a/include/linux/sched.h
63359+++ b/include/linux/sched.h
63360@@ -101,6 +101,7 @@ struct bio_list;
63361 struct fs_struct;
63362 struct perf_event_context;
63363 struct blk_plug;
63364+struct linux_binprm;
63365
63366 /*
63367 * List of flags we want to share for kernel threads,
63368@@ -384,10 +385,13 @@ struct user_namespace;
63369 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63370
63371 extern int sysctl_max_map_count;
63372+extern unsigned long sysctl_heap_stack_gap;
63373
63374 #include <linux/aio.h>
63375
63376 #ifdef CONFIG_MMU
63377+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63378+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63379 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63380 extern unsigned long
63381 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63382@@ -406,6 +410,11 @@ static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
63383 extern void set_dumpable(struct mm_struct *mm, int value);
63384 extern int get_dumpable(struct mm_struct *mm);
63385
63386+/* get/set_dumpable() values */
63387+#define SUID_DUMPABLE_DISABLED 0
63388+#define SUID_DUMPABLE_ENABLED 1
63389+#define SUID_DUMPABLE_SAFE 2
63390+
63391 /* mm flags */
63392 /* dumpable bits */
63393 #define MMF_DUMPABLE 0 /* core dump is permitted */
63394@@ -646,6 +655,17 @@ struct signal_struct {
63395 #ifdef CONFIG_TASKSTATS
63396 struct taskstats *stats;
63397 #endif
63398+
63399+#ifdef CONFIG_GRKERNSEC
63400+ u32 curr_ip;
63401+ u32 saved_ip;
63402+ u32 gr_saddr;
63403+ u32 gr_daddr;
63404+ u16 gr_sport;
63405+ u16 gr_dport;
63406+ u8 used_accept:1;
63407+#endif
63408+
63409 #ifdef CONFIG_AUDIT
63410 unsigned audit_tty;
63411 struct tty_audit_buf *tty_audit_buf;
63412@@ -729,6 +749,11 @@ struct user_struct {
63413 struct key *session_keyring; /* UID's default session keyring */
63414 #endif
63415
63416+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63417+ unsigned int banned;
63418+ unsigned long ban_expires;
63419+#endif
63420+
63421 /* Hash table maintenance information */
63422 struct hlist_node uidhash_node;
63423 kuid_t uid;
63424@@ -1348,8 +1373,8 @@ struct task_struct {
63425 struct list_head thread_group;
63426
63427 struct completion *vfork_done; /* for vfork() */
63428- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63429- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63430+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63431+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63432
63433 cputime_t utime, stime, utimescaled, stimescaled;
63434 cputime_t gtime;
63435@@ -1365,11 +1390,6 @@ struct task_struct {
63436 struct task_cputime cputime_expires;
63437 struct list_head cpu_timers[3];
63438
63439-/* process credentials */
63440- const struct cred __rcu *real_cred; /* objective and real subjective task
63441- * credentials (COW) */
63442- const struct cred __rcu *cred; /* effective (overridable) subjective task
63443- * credentials (COW) */
63444 char comm[TASK_COMM_LEN]; /* executable name excluding path
63445 - access with [gs]et_task_comm (which lock
63446 it with task_lock())
63447@@ -1386,8 +1406,16 @@ struct task_struct {
63448 #endif
63449 /* CPU-specific state of this task */
63450 struct thread_struct thread;
63451+/* thread_info moved to task_struct */
63452+#ifdef CONFIG_X86
63453+ struct thread_info tinfo;
63454+#endif
63455 /* filesystem information */
63456 struct fs_struct *fs;
63457+
63458+ const struct cred __rcu *cred; /* effective (overridable) subjective task
63459+ * credentials (COW) */
63460+
63461 /* open file information */
63462 struct files_struct *files;
63463 /* namespaces */
63464@@ -1431,6 +1459,11 @@ struct task_struct {
63465 struct rt_mutex_waiter *pi_blocked_on;
63466 #endif
63467
63468+/* process credentials */
63469+ const struct cred __rcu *real_cred; /* objective and real subjective task
63470+ * credentials (COW) */
63471+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63472+
63473 #ifdef CONFIG_DEBUG_MUTEXES
63474 /* mutex deadlock detection */
63475 struct mutex_waiter *blocked_on;
63476@@ -1547,6 +1580,27 @@ struct task_struct {
63477 unsigned long default_timer_slack_ns;
63478
63479 struct list_head *scm_work_list;
63480+
63481+#ifdef CONFIG_GRKERNSEC
63482+ /* grsecurity */
63483+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63484+ u64 exec_id;
63485+#endif
63486+#ifdef CONFIG_GRKERNSEC_SETXID
63487+ const struct cred *delayed_cred;
63488+#endif
63489+ struct dentry *gr_chroot_dentry;
63490+ struct acl_subject_label *acl;
63491+ struct acl_role_label *role;
63492+ struct file *exec_file;
63493+ u16 acl_role_id;
63494+ /* is this the task that authenticated to the special role */
63495+ u8 acl_sp_role;
63496+ u8 is_writable;
63497+ u8 brute;
63498+ u8 gr_is_chrooted;
63499+#endif
63500+
63501 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63502 /* Index of current stored address in ret_stack */
63503 int curr_ret_stack;
63504@@ -1585,6 +1639,51 @@ struct task_struct {
63505 #endif
63506 };
63507
63508+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63509+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63510+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63511+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63512+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63513+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63514+
63515+#ifdef CONFIG_PAX_SOFTMODE
63516+extern int pax_softmode;
63517+#endif
63518+
63519+extern int pax_check_flags(unsigned long *);
63520+
63521+/* if tsk != current then task_lock must be held on it */
63522+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63523+static inline unsigned long pax_get_flags(struct task_struct *tsk)
63524+{
63525+ if (likely(tsk->mm))
63526+ return tsk->mm->pax_flags;
63527+ else
63528+ return 0UL;
63529+}
63530+
63531+/* if tsk != current then task_lock must be held on it */
63532+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63533+{
63534+ if (likely(tsk->mm)) {
63535+ tsk->mm->pax_flags = flags;
63536+ return 0;
63537+ }
63538+ return -EINVAL;
63539+}
63540+#endif
63541+
63542+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63543+extern void pax_set_initial_flags(struct linux_binprm *bprm);
63544+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63545+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63546+#endif
63547+
63548+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63549+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63550+extern void pax_report_refcount_overflow(struct pt_regs *regs);
63551+extern void check_object_size(const void *ptr, unsigned long n, bool to);
63552+
63553 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63554 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63555
63556@@ -2112,7 +2211,9 @@ void yield(void);
63557 extern struct exec_domain default_exec_domain;
63558
63559 union thread_union {
63560+#ifndef CONFIG_X86
63561 struct thread_info thread_info;
63562+#endif
63563 unsigned long stack[THREAD_SIZE/sizeof(long)];
63564 };
63565
63566@@ -2145,6 +2246,7 @@ extern struct pid_namespace init_pid_ns;
63567 */
63568
63569 extern struct task_struct *find_task_by_vpid(pid_t nr);
63570+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63571 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63572 struct pid_namespace *ns);
63573
63574@@ -2301,7 +2403,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63575 extern void exit_itimers(struct signal_struct *);
63576 extern void flush_itimer_signals(void);
63577
63578-extern void do_group_exit(int);
63579+extern __noreturn void do_group_exit(int);
63580
63581 extern void daemonize(const char *, ...);
63582 extern int allow_signal(int);
63583@@ -2502,9 +2604,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63584
63585 #endif
63586
63587-static inline int object_is_on_stack(void *obj)
63588+static inline int object_starts_on_stack(void *obj)
63589 {
63590- void *stack = task_stack_page(current);
63591+ const void *stack = task_stack_page(current);
63592
63593 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63594 }
63595diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63596index 899fbb4..1cb4138 100644
63597--- a/include/linux/screen_info.h
63598+++ b/include/linux/screen_info.h
63599@@ -43,7 +43,8 @@ struct screen_info {
63600 __u16 pages; /* 0x32 */
63601 __u16 vesa_attributes; /* 0x34 */
63602 __u32 capabilities; /* 0x36 */
63603- __u8 _reserved[6]; /* 0x3a */
63604+ __u16 vesapm_size; /* 0x3a */
63605+ __u8 _reserved[4]; /* 0x3c */
63606 } __attribute__((packed));
63607
63608 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63609diff --git a/include/linux/security.h b/include/linux/security.h
63610index 4e5a73c..a5784a1 100644
63611--- a/include/linux/security.h
63612+++ b/include/linux/security.h
63613@@ -26,6 +26,7 @@
63614 #include <linux/capability.h>
63615 #include <linux/slab.h>
63616 #include <linux/err.h>
63617+#include <linux/grsecurity.h>
63618
63619 struct linux_binprm;
63620 struct cred;
63621diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63622index fc61854..d7c490b 100644
63623--- a/include/linux/seq_file.h
63624+++ b/include/linux/seq_file.h
63625@@ -25,6 +25,9 @@ struct seq_file {
63626 struct mutex lock;
63627 const struct seq_operations *op;
63628 int poll_event;
63629+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63630+ u64 exec_id;
63631+#endif
63632 void *private;
63633 };
63634
63635@@ -34,6 +37,7 @@ struct seq_operations {
63636 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63637 int (*show) (struct seq_file *m, void *v);
63638 };
63639+typedef struct seq_operations __no_const seq_operations_no_const;
63640
63641 #define SEQ_SKIP 1
63642
63643diff --git a/include/linux/shm.h b/include/linux/shm.h
63644index 92808b8..c28cac4 100644
63645--- a/include/linux/shm.h
63646+++ b/include/linux/shm.h
63647@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63648
63649 /* The task created the shm object. NULL if the task is dead. */
63650 struct task_struct *shm_creator;
63651+#ifdef CONFIG_GRKERNSEC
63652+ time_t shm_createtime;
63653+ pid_t shm_lapid;
63654+#endif
63655 };
63656
63657 /* shm_mode upper byte flags */
63658diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63659index 642cb73..7ff7f9f 100644
63660--- a/include/linux/skbuff.h
63661+++ b/include/linux/skbuff.h
63662@@ -680,7 +680,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63663 */
63664 static inline int skb_queue_empty(const struct sk_buff_head *list)
63665 {
63666- return list->next == (struct sk_buff *)list;
63667+ return list->next == (const struct sk_buff *)list;
63668 }
63669
63670 /**
63671@@ -693,7 +693,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63672 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63673 const struct sk_buff *skb)
63674 {
63675- return skb->next == (struct sk_buff *)list;
63676+ return skb->next == (const struct sk_buff *)list;
63677 }
63678
63679 /**
63680@@ -706,7 +706,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63681 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63682 const struct sk_buff *skb)
63683 {
63684- return skb->prev == (struct sk_buff *)list;
63685+ return skb->prev == (const struct sk_buff *)list;
63686 }
63687
63688 /**
63689@@ -1605,7 +1605,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63690 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63691 */
63692 #ifndef NET_SKB_PAD
63693-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63694+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63695 #endif
63696
63697 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63698diff --git a/include/linux/slab.h b/include/linux/slab.h
63699index 67d5d94..371d9a7 100644
63700--- a/include/linux/slab.h
63701+++ b/include/linux/slab.h
63702@@ -11,12 +11,20 @@
63703
63704 #include <linux/gfp.h>
63705 #include <linux/types.h>
63706+#include <linux/err.h>
63707
63708 /*
63709 * Flags to pass to kmem_cache_create().
63710 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63711 */
63712 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63713+
63714+#ifdef CONFIG_PAX_USERCOPY_SLABS
63715+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63716+#else
63717+#define SLAB_USERCOPY 0x00000000UL
63718+#endif
63719+
63720 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63721 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63722 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63723@@ -87,10 +95,13 @@
63724 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63725 * Both make kfree a no-op.
63726 */
63727-#define ZERO_SIZE_PTR ((void *)16)
63728+#define ZERO_SIZE_PTR \
63729+({ \
63730+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63731+ (void *)(-MAX_ERRNO-1L); \
63732+})
63733
63734-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63735- (unsigned long)ZERO_SIZE_PTR)
63736+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63737
63738 /*
63739 * struct kmem_cache related prototypes
63740@@ -161,6 +172,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
63741 void kfree(const void *);
63742 void kzfree(const void *);
63743 size_t ksize(const void *);
63744+const char *check_heap_object(const void *ptr, unsigned long n, bool to);
63745+bool is_usercopy_object(const void *ptr);
63746
63747 /*
63748 * Allocator specific definitions. These are mainly used to establish optimized
63749@@ -240,6 +253,7 @@ size_t ksize(const void *);
63750 * for general use, and so are not documented here. For a full list of
63751 * potential flags, always refer to linux/gfp.h.
63752 */
63753+static void *kmalloc_array(size_t n, size_t size, gfp_t flags) __size_overflow(1, 2);
63754 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
63755 {
63756 if (size != 0 && n > SIZE_MAX / size)
63757@@ -298,7 +312,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63758 */
63759 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63760 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63761-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63762+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63763 #define kmalloc_track_caller(size, flags) \
63764 __kmalloc_track_caller(size, flags, _RET_IP_)
63765 #else
63766@@ -317,7 +331,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63767 */
63768 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63769 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63770-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63771+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63772 #define kmalloc_node_track_caller(size, flags, node) \
63773 __kmalloc_node_track_caller(size, flags, node, \
63774 _RET_IP_)
63775diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63776index fbd1117..0a3d314 100644
63777--- a/include/linux/slab_def.h
63778+++ b/include/linux/slab_def.h
63779@@ -66,10 +66,10 @@ struct kmem_cache {
63780 unsigned long node_allocs;
63781 unsigned long node_frees;
63782 unsigned long node_overflow;
63783- atomic_t allochit;
63784- atomic_t allocmiss;
63785- atomic_t freehit;
63786- atomic_t freemiss;
63787+ atomic_unchecked_t allochit;
63788+ atomic_unchecked_t allocmiss;
63789+ atomic_unchecked_t freehit;
63790+ atomic_unchecked_t freemiss;
63791
63792 /*
63793 * If debugging is enabled, then the allocator can add additional
63794@@ -103,11 +103,16 @@ struct cache_sizes {
63795 #ifdef CONFIG_ZONE_DMA
63796 struct kmem_cache *cs_dmacachep;
63797 #endif
63798+
63799+#ifdef CONFIG_PAX_USERCOPY_SLABS
63800+ struct kmem_cache *cs_usercopycachep;
63801+#endif
63802+
63803 };
63804 extern struct cache_sizes malloc_sizes[];
63805
63806 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63807-void *__kmalloc(size_t size, gfp_t flags);
63808+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63809
63810 #ifdef CONFIG_TRACING
63811 extern void *kmem_cache_alloc_trace(size_t size,
63812@@ -150,6 +155,13 @@ found:
63813 cachep = malloc_sizes[i].cs_dmacachep;
63814 else
63815 #endif
63816+
63817+#ifdef CONFIG_PAX_USERCOPY_SLABS
63818+ if (flags & GFP_USERCOPY)
63819+ cachep = malloc_sizes[i].cs_usercopycachep;
63820+ else
63821+#endif
63822+
63823 cachep = malloc_sizes[i].cs_cachep;
63824
63825 ret = kmem_cache_alloc_trace(size, cachep, flags);
63826@@ -160,7 +172,7 @@ found:
63827 }
63828
63829 #ifdef CONFIG_NUMA
63830-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63831+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63832 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63833
63834 #ifdef CONFIG_TRACING
63835@@ -203,6 +215,13 @@ found:
63836 cachep = malloc_sizes[i].cs_dmacachep;
63837 else
63838 #endif
63839+
63840+#ifdef CONFIG_PAX_USERCOPY_SLABS
63841+ if (flags & GFP_USERCOPY)
63842+ cachep = malloc_sizes[i].cs_usercopycachep;
63843+ else
63844+#endif
63845+
63846 cachep = malloc_sizes[i].cs_cachep;
63847
63848 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
63849diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63850index 0ec00b3..39cb7fc 100644
63851--- a/include/linux/slob_def.h
63852+++ b/include/linux/slob_def.h
63853@@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63854 return kmem_cache_alloc_node(cachep, flags, -1);
63855 }
63856
63857-void *__kmalloc_node(size_t size, gfp_t flags, int node);
63858+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63859
63860 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63861 {
63862@@ -29,6 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63863 return __kmalloc_node(size, flags, -1);
63864 }
63865
63866+static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63867 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63868 {
63869 return kmalloc(size, flags);
63870diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63871index c2f8c8b..be9e036 100644
63872--- a/include/linux/slub_def.h
63873+++ b/include/linux/slub_def.h
63874@@ -92,7 +92,7 @@ struct kmem_cache {
63875 struct kmem_cache_order_objects max;
63876 struct kmem_cache_order_objects min;
63877 gfp_t allocflags; /* gfp flags to use on each alloc */
63878- int refcount; /* Refcount for slab cache destroy */
63879+ atomic_t refcount; /* Refcount for slab cache destroy */
63880 void (*ctor)(void *);
63881 int inuse; /* Offset to metadata */
63882 int align; /* Alignment */
63883@@ -153,6 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
63884 * Sorry that the following has to be that ugly but some versions of GCC
63885 * have trouble with constant propagation and loops.
63886 */
63887+static __always_inline int kmalloc_index(size_t size) __size_overflow(1);
63888 static __always_inline int kmalloc_index(size_t size)
63889 {
63890 if (!size)
63891@@ -218,7 +219,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63892 }
63893
63894 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63895-void *__kmalloc(size_t size, gfp_t flags);
63896+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
63897
63898 static __always_inline void *
63899 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63900@@ -259,6 +260,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
63901 }
63902 #endif
63903
63904+static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
63905 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
63906 {
63907 unsigned int order = get_order(size);
63908@@ -284,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63909 }
63910
63911 #ifdef CONFIG_NUMA
63912-void *__kmalloc_node(size_t size, gfp_t flags, int node);
63913+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63914 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63915
63916 #ifdef CONFIG_TRACING
63917diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63918index de8832d..0147b46 100644
63919--- a/include/linux/sonet.h
63920+++ b/include/linux/sonet.h
63921@@ -61,7 +61,7 @@ struct sonet_stats {
63922 #include <linux/atomic.h>
63923
63924 struct k_sonet_stats {
63925-#define __HANDLE_ITEM(i) atomic_t i
63926+#define __HANDLE_ITEM(i) atomic_unchecked_t i
63927 __SONET_ITEMS
63928 #undef __HANDLE_ITEM
63929 };
63930diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63931index 523547e..2cb7140 100644
63932--- a/include/linux/sunrpc/clnt.h
63933+++ b/include/linux/sunrpc/clnt.h
63934@@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63935 {
63936 switch (sap->sa_family) {
63937 case AF_INET:
63938- return ntohs(((struct sockaddr_in *)sap)->sin_port);
63939+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63940 case AF_INET6:
63941- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63942+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63943 }
63944 return 0;
63945 }
63946@@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63947 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63948 const struct sockaddr *src)
63949 {
63950- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63951+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63952 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63953
63954 dsin->sin_family = ssin->sin_family;
63955@@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63956 if (sa->sa_family != AF_INET6)
63957 return 0;
63958
63959- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63960+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63961 }
63962
63963 #endif /* __KERNEL__ */
63964diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63965index dc0c3cc..8503fb6 100644
63966--- a/include/linux/sunrpc/sched.h
63967+++ b/include/linux/sunrpc/sched.h
63968@@ -106,6 +106,7 @@ struct rpc_call_ops {
63969 void (*rpc_count_stats)(struct rpc_task *, void *);
63970 void (*rpc_release)(void *);
63971 };
63972+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63973
63974 struct rpc_task_setup {
63975 struct rpc_task *task;
63976diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63977index 0b8e3e6..33e0a01 100644
63978--- a/include/linux/sunrpc/svc_rdma.h
63979+++ b/include/linux/sunrpc/svc_rdma.h
63980@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63981 extern unsigned int svcrdma_max_requests;
63982 extern unsigned int svcrdma_max_req_size;
63983
63984-extern atomic_t rdma_stat_recv;
63985-extern atomic_t rdma_stat_read;
63986-extern atomic_t rdma_stat_write;
63987-extern atomic_t rdma_stat_sq_starve;
63988-extern atomic_t rdma_stat_rq_starve;
63989-extern atomic_t rdma_stat_rq_poll;
63990-extern atomic_t rdma_stat_rq_prod;
63991-extern atomic_t rdma_stat_sq_poll;
63992-extern atomic_t rdma_stat_sq_prod;
63993+extern atomic_unchecked_t rdma_stat_recv;
63994+extern atomic_unchecked_t rdma_stat_read;
63995+extern atomic_unchecked_t rdma_stat_write;
63996+extern atomic_unchecked_t rdma_stat_sq_starve;
63997+extern atomic_unchecked_t rdma_stat_rq_starve;
63998+extern atomic_unchecked_t rdma_stat_rq_poll;
63999+extern atomic_unchecked_t rdma_stat_rq_prod;
64000+extern atomic_unchecked_t rdma_stat_sq_poll;
64001+extern atomic_unchecked_t rdma_stat_sq_prod;
64002
64003 #define RPCRDMA_VERSION 1
64004
64005diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64006index c34b4c8..a65b67d 100644
64007--- a/include/linux/sysctl.h
64008+++ b/include/linux/sysctl.h
64009@@ -155,7 +155,11 @@ enum
64010 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64011 };
64012
64013-
64014+#ifdef CONFIG_PAX_SOFTMODE
64015+enum {
64016+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64017+};
64018+#endif
64019
64020 /* CTL_VM names: */
64021 enum
64022@@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64023
64024 extern int proc_dostring(struct ctl_table *, int,
64025 void __user *, size_t *, loff_t *);
64026+extern int proc_dostring_modpriv(struct ctl_table *, int,
64027+ void __user *, size_t *, loff_t *);
64028 extern int proc_dointvec(struct ctl_table *, int,
64029 void __user *, size_t *, loff_t *);
64030 extern int proc_dointvec_minmax(struct ctl_table *, int,
64031diff --git a/include/linux/tty.h b/include/linux/tty.h
64032index 9f47ab5..73da944 100644
64033--- a/include/linux/tty.h
64034+++ b/include/linux/tty.h
64035@@ -225,7 +225,7 @@ struct tty_port {
64036 const struct tty_port_operations *ops; /* Port operations */
64037 spinlock_t lock; /* Lock protecting tty field */
64038 int blocked_open; /* Waiting to open */
64039- int count; /* Usage count */
64040+ atomic_t count; /* Usage count */
64041 wait_queue_head_t open_wait; /* Open waiters */
64042 wait_queue_head_t close_wait; /* Close waiters */
64043 wait_queue_head_t delta_msr_wait; /* Modem status change */
64044@@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64045 struct tty_struct *tty, struct file *filp);
64046 static inline int tty_port_users(struct tty_port *port)
64047 {
64048- return port->count + port->blocked_open;
64049+ return atomic_read(&port->count) + port->blocked_open;
64050 }
64051
64052 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64053diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64054index fb79dd8d..07d4773 100644
64055--- a/include/linux/tty_ldisc.h
64056+++ b/include/linux/tty_ldisc.h
64057@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64058
64059 struct module *owner;
64060
64061- int refcount;
64062+ atomic_t refcount;
64063 };
64064
64065 struct tty_ldisc {
64066diff --git a/include/linux/types.h b/include/linux/types.h
64067index 9c1bd53..c2370f6 100644
64068--- a/include/linux/types.h
64069+++ b/include/linux/types.h
64070@@ -220,10 +220,26 @@ typedef struct {
64071 int counter;
64072 } atomic_t;
64073
64074+#ifdef CONFIG_PAX_REFCOUNT
64075+typedef struct {
64076+ int counter;
64077+} atomic_unchecked_t;
64078+#else
64079+typedef atomic_t atomic_unchecked_t;
64080+#endif
64081+
64082 #ifdef CONFIG_64BIT
64083 typedef struct {
64084 long counter;
64085 } atomic64_t;
64086+
64087+#ifdef CONFIG_PAX_REFCOUNT
64088+typedef struct {
64089+ long counter;
64090+} atomic64_unchecked_t;
64091+#else
64092+typedef atomic64_t atomic64_unchecked_t;
64093+#endif
64094 #endif
64095
64096 struct list_head {
64097diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64098index 5ca0951..ab496a5 100644
64099--- a/include/linux/uaccess.h
64100+++ b/include/linux/uaccess.h
64101@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64102 long ret; \
64103 mm_segment_t old_fs = get_fs(); \
64104 \
64105- set_fs(KERNEL_DS); \
64106 pagefault_disable(); \
64107- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64108- pagefault_enable(); \
64109+ set_fs(KERNEL_DS); \
64110+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64111 set_fs(old_fs); \
64112+ pagefault_enable(); \
64113 ret; \
64114 })
64115
64116diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64117index 99c1b4d..bb94261 100644
64118--- a/include/linux/unaligned/access_ok.h
64119+++ b/include/linux/unaligned/access_ok.h
64120@@ -6,32 +6,32 @@
64121
64122 static inline u16 get_unaligned_le16(const void *p)
64123 {
64124- return le16_to_cpup((__le16 *)p);
64125+ return le16_to_cpup((const __le16 *)p);
64126 }
64127
64128 static inline u32 get_unaligned_le32(const void *p)
64129 {
64130- return le32_to_cpup((__le32 *)p);
64131+ return le32_to_cpup((const __le32 *)p);
64132 }
64133
64134 static inline u64 get_unaligned_le64(const void *p)
64135 {
64136- return le64_to_cpup((__le64 *)p);
64137+ return le64_to_cpup((const __le64 *)p);
64138 }
64139
64140 static inline u16 get_unaligned_be16(const void *p)
64141 {
64142- return be16_to_cpup((__be16 *)p);
64143+ return be16_to_cpup((const __be16 *)p);
64144 }
64145
64146 static inline u32 get_unaligned_be32(const void *p)
64147 {
64148- return be32_to_cpup((__be32 *)p);
64149+ return be32_to_cpup((const __be32 *)p);
64150 }
64151
64152 static inline u64 get_unaligned_be64(const void *p)
64153 {
64154- return be64_to_cpup((__be64 *)p);
64155+ return be64_to_cpup((const __be64 *)p);
64156 }
64157
64158 static inline void put_unaligned_le16(u16 val, void *p)
64159diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64160index 547e59c..db6ad19 100644
64161--- a/include/linux/usb/renesas_usbhs.h
64162+++ b/include/linux/usb/renesas_usbhs.h
64163@@ -39,7 +39,7 @@ enum {
64164 */
64165 struct renesas_usbhs_driver_callback {
64166 int (*notify_hotplug)(struct platform_device *pdev);
64167-};
64168+} __no_const;
64169
64170 /*
64171 * callback functions for platform
64172@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64173 * VBUS control is needed for Host
64174 */
64175 int (*set_vbus)(struct platform_device *pdev, int enable);
64176-};
64177+} __no_const;
64178
64179 /*
64180 * parameters for renesas usbhs
64181diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64182index 6f8fbcf..8259001 100644
64183--- a/include/linux/vermagic.h
64184+++ b/include/linux/vermagic.h
64185@@ -25,9 +25,35 @@
64186 #define MODULE_ARCH_VERMAGIC ""
64187 #endif
64188
64189+#ifdef CONFIG_PAX_REFCOUNT
64190+#define MODULE_PAX_REFCOUNT "REFCOUNT "
64191+#else
64192+#define MODULE_PAX_REFCOUNT ""
64193+#endif
64194+
64195+#ifdef CONSTIFY_PLUGIN
64196+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64197+#else
64198+#define MODULE_CONSTIFY_PLUGIN ""
64199+#endif
64200+
64201+#ifdef STACKLEAK_PLUGIN
64202+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64203+#else
64204+#define MODULE_STACKLEAK_PLUGIN ""
64205+#endif
64206+
64207+#ifdef CONFIG_GRKERNSEC
64208+#define MODULE_GRSEC "GRSEC "
64209+#else
64210+#define MODULE_GRSEC ""
64211+#endif
64212+
64213 #define VERMAGIC_STRING \
64214 UTS_RELEASE " " \
64215 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64216 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64217- MODULE_ARCH_VERMAGIC
64218+ MODULE_ARCH_VERMAGIC \
64219+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64220+ MODULE_GRSEC
64221
64222diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64223index dcdfc2b..ec79ab5 100644
64224--- a/include/linux/vmalloc.h
64225+++ b/include/linux/vmalloc.h
64226@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64227 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64228 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64229 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64230+
64231+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64232+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64233+#endif
64234+
64235 /* bits [20..32] reserved for arch specific ioremap internals */
64236
64237 /*
64238@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64239 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64240 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64241 unsigned long start, unsigned long end, gfp_t gfp_mask,
64242- pgprot_t prot, int node, void *caller);
64243+ pgprot_t prot, int node, void *caller) __size_overflow(1);
64244 extern void vfree(const void *addr);
64245
64246 extern void *vmap(struct page **pages, unsigned int count,
64247@@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64248 extern void free_vm_area(struct vm_struct *area);
64249
64250 /* for /dev/kmem */
64251-extern long vread(char *buf, char *addr, unsigned long count);
64252-extern long vwrite(char *buf, char *addr, unsigned long count);
64253+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64254+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64255
64256 /*
64257 * Internals. Dont't use..
64258diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64259index 65efb92..137adbb 100644
64260--- a/include/linux/vmstat.h
64261+++ b/include/linux/vmstat.h
64262@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64263 /*
64264 * Zone based page accounting with per cpu differentials.
64265 */
64266-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64267+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64268
64269 static inline void zone_page_state_add(long x, struct zone *zone,
64270 enum zone_stat_item item)
64271 {
64272- atomic_long_add(x, &zone->vm_stat[item]);
64273- atomic_long_add(x, &vm_stat[item]);
64274+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64275+ atomic_long_add_unchecked(x, &vm_stat[item]);
64276 }
64277
64278 static inline unsigned long global_page_state(enum zone_stat_item item)
64279 {
64280- long x = atomic_long_read(&vm_stat[item]);
64281+ long x = atomic_long_read_unchecked(&vm_stat[item]);
64282 #ifdef CONFIG_SMP
64283 if (x < 0)
64284 x = 0;
64285@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64286 static inline unsigned long zone_page_state(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 #ifdef CONFIG_SMP
64292 if (x < 0)
64293 x = 0;
64294@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64295 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64296 enum zone_stat_item item)
64297 {
64298- long x = atomic_long_read(&zone->vm_stat[item]);
64299+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64300
64301 #ifdef CONFIG_SMP
64302 int cpu;
64303@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64304
64305 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64306 {
64307- atomic_long_inc(&zone->vm_stat[item]);
64308- atomic_long_inc(&vm_stat[item]);
64309+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
64310+ atomic_long_inc_unchecked(&vm_stat[item]);
64311 }
64312
64313 static inline void __inc_zone_page_state(struct page *page,
64314@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64315
64316 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64317 {
64318- atomic_long_dec(&zone->vm_stat[item]);
64319- atomic_long_dec(&vm_stat[item]);
64320+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
64321+ atomic_long_dec_unchecked(&vm_stat[item]);
64322 }
64323
64324 static inline void __dec_zone_page_state(struct page *page,
64325diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64326index e5d1220..ef6e406 100644
64327--- a/include/linux/xattr.h
64328+++ b/include/linux/xattr.h
64329@@ -57,6 +57,11 @@
64330 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64331 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64332
64333+/* User namespace */
64334+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64335+#define XATTR_PAX_FLAGS_SUFFIX "flags"
64336+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64337+
64338 #ifdef __KERNEL__
64339
64340 #include <linux/types.h>
64341diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64342index 944ecdf..a3994fc 100644
64343--- a/include/media/saa7146_vv.h
64344+++ b/include/media/saa7146_vv.h
64345@@ -161,8 +161,8 @@ struct saa7146_ext_vv
64346 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64347
64348 /* the extension can override this */
64349- struct v4l2_ioctl_ops vid_ops;
64350- struct v4l2_ioctl_ops vbi_ops;
64351+ v4l2_ioctl_ops_no_const vid_ops;
64352+ v4l2_ioctl_ops_no_const vbi_ops;
64353 /* pointer to the saa7146 core ops */
64354 const struct v4l2_ioctl_ops *core_ops;
64355
64356diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64357index a056e6e..31023a5 100644
64358--- a/include/media/v4l2-dev.h
64359+++ b/include/media/v4l2-dev.h
64360@@ -73,7 +73,8 @@ struct v4l2_file_operations {
64361 int (*mmap) (struct file *, struct vm_area_struct *);
64362 int (*open) (struct file *);
64363 int (*release) (struct file *);
64364-};
64365+} __do_const;
64366+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64367
64368 /*
64369 * Newer version of video_device, handled by videodev2.c
64370diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64371index d8b76f7..7d5aa18 100644
64372--- a/include/media/v4l2-ioctl.h
64373+++ b/include/media/v4l2-ioctl.h
64374@@ -287,7 +287,7 @@ struct v4l2_ioctl_ops {
64375 long (*vidioc_default) (struct file *file, void *fh,
64376 bool valid_prio, int cmd, void *arg);
64377 };
64378-
64379+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64380
64381 /* v4l debugging and diagnostics */
64382
64383diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64384index 439dadc..1c67e3f 100644
64385--- a/include/net/caif/caif_hsi.h
64386+++ b/include/net/caif/caif_hsi.h
64387@@ -98,7 +98,7 @@ struct cfhsi_drv {
64388 void (*rx_done_cb) (struct cfhsi_drv *drv);
64389 void (*wake_up_cb) (struct cfhsi_drv *drv);
64390 void (*wake_down_cb) (struct cfhsi_drv *drv);
64391-};
64392+} __no_const;
64393
64394 /* Structure implemented by HSI device. */
64395 struct cfhsi_dev {
64396diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64397index 9e5425b..8136ffc 100644
64398--- a/include/net/caif/cfctrl.h
64399+++ b/include/net/caif/cfctrl.h
64400@@ -52,7 +52,7 @@ struct cfctrl_rsp {
64401 void (*radioset_rsp)(void);
64402 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64403 struct cflayer *client_layer);
64404-};
64405+} __no_const;
64406
64407 /* Link Setup Parameters for CAIF-Links. */
64408 struct cfctrl_link_param {
64409@@ -101,8 +101,8 @@ struct cfctrl_request_info {
64410 struct cfctrl {
64411 struct cfsrvl serv;
64412 struct cfctrl_rsp res;
64413- atomic_t req_seq_no;
64414- atomic_t rsp_seq_no;
64415+ atomic_unchecked_t req_seq_no;
64416+ atomic_unchecked_t rsp_seq_no;
64417 struct list_head list;
64418 /* Protects from simultaneous access to first_req list */
64419 spinlock_t info_list_lock;
64420diff --git a/include/net/flow.h b/include/net/flow.h
64421index 6c469db..7743b8e 100644
64422--- a/include/net/flow.h
64423+++ b/include/net/flow.h
64424@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64425
64426 extern void flow_cache_flush(void);
64427 extern void flow_cache_flush_deferred(void);
64428-extern atomic_t flow_cache_genid;
64429+extern atomic_unchecked_t flow_cache_genid;
64430
64431 #endif
64432diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64433index 2040bff..f4c0733 100644
64434--- a/include/net/inetpeer.h
64435+++ b/include/net/inetpeer.h
64436@@ -51,8 +51,8 @@ struct inet_peer {
64437 */
64438 union {
64439 struct {
64440- atomic_t rid; /* Frag reception counter */
64441- atomic_t ip_id_count; /* IP ID for the next packet */
64442+ atomic_unchecked_t rid; /* Frag reception counter */
64443+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64444 __u32 tcp_ts;
64445 __u32 tcp_ts_stamp;
64446 };
64447@@ -118,11 +118,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64448 more++;
64449 inet_peer_refcheck(p);
64450 do {
64451- old = atomic_read(&p->ip_id_count);
64452+ old = atomic_read_unchecked(&p->ip_id_count);
64453 new = old + more;
64454 if (!new)
64455 new = 1;
64456- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64457+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64458 return new;
64459 }
64460
64461diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64462index 78df0866..00e5c9b 100644
64463--- a/include/net/ip_fib.h
64464+++ b/include/net/ip_fib.h
64465@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64466
64467 #define FIB_RES_SADDR(net, res) \
64468 ((FIB_RES_NH(res).nh_saddr_genid == \
64469- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64470+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64471 FIB_RES_NH(res).nh_saddr : \
64472 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64473 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64474diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64475index 95374d1..2300e36 100644
64476--- a/include/net/ip_vs.h
64477+++ b/include/net/ip_vs.h
64478@@ -510,7 +510,7 @@ struct ip_vs_conn {
64479 struct ip_vs_conn *control; /* Master control connection */
64480 atomic_t n_control; /* Number of controlled ones */
64481 struct ip_vs_dest *dest; /* real server */
64482- atomic_t in_pkts; /* incoming packet counter */
64483+ atomic_unchecked_t in_pkts; /* incoming packet counter */
64484
64485 /* packet transmitter for different forwarding methods. If it
64486 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64487@@ -648,7 +648,7 @@ struct ip_vs_dest {
64488 __be16 port; /* port number of the server */
64489 union nf_inet_addr addr; /* IP address of the server */
64490 volatile unsigned int flags; /* dest status flags */
64491- atomic_t conn_flags; /* flags to copy to conn */
64492+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
64493 atomic_t weight; /* server weight */
64494
64495 atomic_t refcnt; /* reference counter */
64496diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64497index 69b610a..fe3962c 100644
64498--- a/include/net/irda/ircomm_core.h
64499+++ b/include/net/irda/ircomm_core.h
64500@@ -51,7 +51,7 @@ typedef struct {
64501 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64502 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64503 struct ircomm_info *);
64504-} call_t;
64505+} __no_const call_t;
64506
64507 struct ircomm_cb {
64508 irda_queue_t queue;
64509diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64510index 59ba38bc..d515662 100644
64511--- a/include/net/irda/ircomm_tty.h
64512+++ b/include/net/irda/ircomm_tty.h
64513@@ -35,6 +35,7 @@
64514 #include <linux/termios.h>
64515 #include <linux/timer.h>
64516 #include <linux/tty.h> /* struct tty_struct */
64517+#include <asm/local.h>
64518
64519 #include <net/irda/irias_object.h>
64520 #include <net/irda/ircomm_core.h>
64521@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64522 unsigned short close_delay;
64523 unsigned short closing_wait; /* time to wait before closing */
64524
64525- int open_count;
64526- int blocked_open; /* # of blocked opens */
64527+ local_t open_count;
64528+ local_t blocked_open; /* # of blocked opens */
64529
64530 /* Protect concurent access to :
64531 * o self->open_count
64532diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64533index cc7c197..9f2da2a 100644
64534--- a/include/net/iucv/af_iucv.h
64535+++ b/include/net/iucv/af_iucv.h
64536@@ -141,7 +141,7 @@ struct iucv_sock {
64537 struct iucv_sock_list {
64538 struct hlist_head head;
64539 rwlock_t lock;
64540- atomic_t autobind_name;
64541+ atomic_unchecked_t autobind_name;
64542 };
64543
64544 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64545diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64546index 6cdfeed..55a0256 100644
64547--- a/include/net/neighbour.h
64548+++ b/include/net/neighbour.h
64549@@ -123,7 +123,7 @@ struct neigh_ops {
64550 void (*error_report)(struct neighbour *, struct sk_buff *);
64551 int (*output)(struct neighbour *, struct sk_buff *);
64552 int (*connected_output)(struct neighbour *, struct sk_buff *);
64553-};
64554+} __do_const;
64555
64556 struct pneigh_entry {
64557 struct pneigh_entry *next;
64558diff --git a/include/net/netlink.h b/include/net/netlink.h
64559index 785f37a..c81dc0c 100644
64560--- a/include/net/netlink.h
64561+++ b/include/net/netlink.h
64562@@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64563 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64564 {
64565 if (mark)
64566- skb_trim(skb, (unsigned char *) mark - skb->data);
64567+ skb_trim(skb, (const unsigned char *) mark - skb->data);
64568 }
64569
64570 /**
64571diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64572index bbd023a..97c6d0d 100644
64573--- a/include/net/netns/ipv4.h
64574+++ b/include/net/netns/ipv4.h
64575@@ -57,8 +57,8 @@ struct netns_ipv4 {
64576 unsigned int sysctl_ping_group_range[2];
64577 long sysctl_tcp_mem[3];
64578
64579- atomic_t rt_genid;
64580- atomic_t dev_addr_genid;
64581+ atomic_unchecked_t rt_genid;
64582+ atomic_unchecked_t dev_addr_genid;
64583
64584 #ifdef CONFIG_IP_MROUTE
64585 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64586diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64587index a2ef814..31a8e3f 100644
64588--- a/include/net/sctp/sctp.h
64589+++ b/include/net/sctp/sctp.h
64590@@ -318,9 +318,9 @@ do { \
64591
64592 #else /* SCTP_DEBUG */
64593
64594-#define SCTP_DEBUG_PRINTK(whatever...)
64595-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64596-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64597+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64598+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64599+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64600 #define SCTP_ENABLE_DEBUG
64601 #define SCTP_DISABLE_DEBUG
64602 #define SCTP_ASSERT(expr, str, func)
64603diff --git a/include/net/sock.h b/include/net/sock.h
64604index 4a45216..7af2578 100644
64605--- a/include/net/sock.h
64606+++ b/include/net/sock.h
64607@@ -303,7 +303,7 @@ struct sock {
64608 #ifdef CONFIG_RPS
64609 __u32 sk_rxhash;
64610 #endif
64611- atomic_t sk_drops;
64612+ atomic_unchecked_t sk_drops;
64613 int sk_rcvbuf;
64614
64615 struct sk_filter __rcu *sk_filter;
64616@@ -1726,7 +1726,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64617 }
64618
64619 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64620- char __user *from, char *to,
64621+ char __user *from, unsigned char *to,
64622 int copy, int offset)
64623 {
64624 if (skb->ip_summed == CHECKSUM_NONE) {
64625diff --git a/include/net/tcp.h b/include/net/tcp.h
64626index e79aa48..9929421 100644
64627--- a/include/net/tcp.h
64628+++ b/include/net/tcp.h
64629@@ -1459,7 +1459,7 @@ struct tcp_seq_afinfo {
64630 char *name;
64631 sa_family_t family;
64632 const struct file_operations *seq_fops;
64633- struct seq_operations seq_ops;
64634+ seq_operations_no_const seq_ops;
64635 };
64636
64637 struct tcp_iter_state {
64638diff --git a/include/net/udp.h b/include/net/udp.h
64639index 065f379..b661b40 100644
64640--- a/include/net/udp.h
64641+++ b/include/net/udp.h
64642@@ -244,7 +244,7 @@ struct udp_seq_afinfo {
64643 sa_family_t family;
64644 struct udp_table *udp_table;
64645 const struct file_operations *seq_fops;
64646- struct seq_operations seq_ops;
64647+ seq_operations_no_const seq_ops;
64648 };
64649
64650 struct udp_iter_state {
64651diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64652index e0a55df..5890bca07 100644
64653--- a/include/net/xfrm.h
64654+++ b/include/net/xfrm.h
64655@@ -505,7 +505,7 @@ struct xfrm_policy {
64656 struct timer_list timer;
64657
64658 struct flow_cache_object flo;
64659- atomic_t genid;
64660+ atomic_unchecked_t genid;
64661 u32 priority;
64662 u32 index;
64663 struct xfrm_mark mark;
64664diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64665index 1a046b1..ee0bef0 100644
64666--- a/include/rdma/iw_cm.h
64667+++ b/include/rdma/iw_cm.h
64668@@ -122,7 +122,7 @@ struct iw_cm_verbs {
64669 int backlog);
64670
64671 int (*destroy_listen)(struct iw_cm_id *cm_id);
64672-};
64673+} __no_const;
64674
64675 /**
64676 * iw_create_cm_id - Create an IW CM identifier.
64677diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64678index 8f9dfba..610ab6c 100644
64679--- a/include/scsi/libfc.h
64680+++ b/include/scsi/libfc.h
64681@@ -756,6 +756,7 @@ struct libfc_function_template {
64682 */
64683 void (*disc_stop_final) (struct fc_lport *);
64684 };
64685+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64686
64687 /**
64688 * struct fc_disc - Discovery context
64689@@ -861,7 +862,7 @@ struct fc_lport {
64690 struct fc_vport *vport;
64691
64692 /* Operational Information */
64693- struct libfc_function_template tt;
64694+ libfc_function_template_no_const tt;
64695 u8 link_up;
64696 u8 qfull;
64697 enum fc_lport_state state;
64698diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64699index ba96988..ecf2eb9 100644
64700--- a/include/scsi/scsi_device.h
64701+++ b/include/scsi/scsi_device.h
64702@@ -163,9 +163,9 @@ struct scsi_device {
64703 unsigned int max_device_blocked; /* what device_blocked counts down from */
64704 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64705
64706- atomic_t iorequest_cnt;
64707- atomic_t iodone_cnt;
64708- atomic_t ioerr_cnt;
64709+ atomic_unchecked_t iorequest_cnt;
64710+ atomic_unchecked_t iodone_cnt;
64711+ atomic_unchecked_t ioerr_cnt;
64712
64713 struct device sdev_gendev,
64714 sdev_dev;
64715diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64716index 719faf1..07b6728 100644
64717--- a/include/scsi/scsi_transport_fc.h
64718+++ b/include/scsi/scsi_transport_fc.h
64719@@ -739,7 +739,8 @@ struct fc_function_template {
64720 unsigned long show_host_system_hostname:1;
64721
64722 unsigned long disable_target_scan:1;
64723-};
64724+} __do_const;
64725+typedef struct fc_function_template __no_const fc_function_template_no_const;
64726
64727
64728 /**
64729diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64730index 030b87c..98a6954 100644
64731--- a/include/sound/ak4xxx-adda.h
64732+++ b/include/sound/ak4xxx-adda.h
64733@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64734 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64735 unsigned char val);
64736 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64737-};
64738+} __no_const;
64739
64740 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64741
64742diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64743index 8c05e47..2b5df97 100644
64744--- a/include/sound/hwdep.h
64745+++ b/include/sound/hwdep.h
64746@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64747 struct snd_hwdep_dsp_status *status);
64748 int (*dsp_load)(struct snd_hwdep *hw,
64749 struct snd_hwdep_dsp_image *image);
64750-};
64751+} __no_const;
64752
64753 struct snd_hwdep {
64754 struct snd_card *card;
64755diff --git a/include/sound/info.h b/include/sound/info.h
64756index 9ca1a49..aba1728 100644
64757--- a/include/sound/info.h
64758+++ b/include/sound/info.h
64759@@ -44,7 +44,7 @@ struct snd_info_entry_text {
64760 struct snd_info_buffer *buffer);
64761 void (*write)(struct snd_info_entry *entry,
64762 struct snd_info_buffer *buffer);
64763-};
64764+} __no_const;
64765
64766 struct snd_info_entry_ops {
64767 int (*open)(struct snd_info_entry *entry,
64768diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64769index 0d11128..814178e 100644
64770--- a/include/sound/pcm.h
64771+++ b/include/sound/pcm.h
64772@@ -81,6 +81,7 @@ struct snd_pcm_ops {
64773 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64774 int (*ack)(struct snd_pcm_substream *substream);
64775 };
64776+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64777
64778 /*
64779 *
64780diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64781index af1b49e..a5d55a5 100644
64782--- a/include/sound/sb16_csp.h
64783+++ b/include/sound/sb16_csp.h
64784@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64785 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64786 int (*csp_stop) (struct snd_sb_csp * p);
64787 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64788-};
64789+} __no_const;
64790
64791 /*
64792 * CSP private data
64793diff --git a/include/sound/soc.h b/include/sound/soc.h
64794index c703871..f7fbbbd 100644
64795--- a/include/sound/soc.h
64796+++ b/include/sound/soc.h
64797@@ -757,7 +757,7 @@ struct snd_soc_platform_driver {
64798 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64799 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64800 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
64801-};
64802+} __do_const;
64803
64804 struct snd_soc_platform {
64805 const char *name;
64806@@ -949,7 +949,7 @@ struct snd_soc_pcm_runtime {
64807 struct snd_soc_dai_link *dai_link;
64808 struct mutex pcm_mutex;
64809 enum snd_soc_pcm_subclass pcm_subclass;
64810- struct snd_pcm_ops ops;
64811+ snd_pcm_ops_no_const ops;
64812
64813 unsigned int dev_registered:1;
64814
64815diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
64816index 0c3c2fb..d9d9990 100644
64817--- a/include/sound/tea575x-tuner.h
64818+++ b/include/sound/tea575x-tuner.h
64819@@ -44,7 +44,7 @@ struct snd_tea575x_ops {
64820
64821 struct snd_tea575x {
64822 struct v4l2_device *v4l2_dev;
64823- struct v4l2_file_operations fops;
64824+ v4l2_file_operations_no_const fops;
64825 struct video_device vd; /* video device */
64826 int radio_nr; /* radio_nr */
64827 bool tea5759; /* 5759 chip is present */
64828diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64829index 4119966..1a4671c 100644
64830--- a/include/sound/ymfpci.h
64831+++ b/include/sound/ymfpci.h
64832@@ -358,7 +358,7 @@ struct snd_ymfpci {
64833 spinlock_t reg_lock;
64834 spinlock_t voice_lock;
64835 wait_queue_head_t interrupt_sleep;
64836- atomic_t interrupt_sleep_count;
64837+ atomic_unchecked_t interrupt_sleep_count;
64838 struct snd_info_entry *proc_entry;
64839 const struct firmware *dsp_microcode;
64840 const struct firmware *controller_microcode;
64841diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64842index dc35d86..4725f45 100644
64843--- a/include/target/target_core_base.h
64844+++ b/include/target/target_core_base.h
64845@@ -440,7 +440,7 @@ struct t10_reservation_ops {
64846 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64847 int (*t10_pr_register)(struct se_cmd *);
64848 int (*t10_pr_clear)(struct se_cmd *);
64849-};
64850+} __no_const;
64851
64852 struct t10_reservation {
64853 /* Reservation effects all target ports */
64854@@ -779,7 +779,7 @@ struct se_device {
64855 spinlock_t stats_lock;
64856 /* Active commands on this virtual SE device */
64857 atomic_t simple_cmds;
64858- atomic_t dev_ordered_id;
64859+ atomic_unchecked_t dev_ordered_id;
64860 atomic_t execute_tasks;
64861 atomic_t dev_ordered_sync;
64862 atomic_t dev_qf_count;
64863diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
64864new file mode 100644
64865index 0000000..2efe49d
64866--- /dev/null
64867+++ b/include/trace/events/fs.h
64868@@ -0,0 +1,53 @@
64869+#undef TRACE_SYSTEM
64870+#define TRACE_SYSTEM fs
64871+
64872+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
64873+#define _TRACE_FS_H
64874+
64875+#include <linux/fs.h>
64876+#include <linux/tracepoint.h>
64877+
64878+TRACE_EVENT(do_sys_open,
64879+
64880+ TP_PROTO(char *filename, int flags, int mode),
64881+
64882+ TP_ARGS(filename, flags, mode),
64883+
64884+ TP_STRUCT__entry(
64885+ __string( filename, filename )
64886+ __field( int, flags )
64887+ __field( int, mode )
64888+ ),
64889+
64890+ TP_fast_assign(
64891+ __assign_str(filename, filename);
64892+ __entry->flags = flags;
64893+ __entry->mode = mode;
64894+ ),
64895+
64896+ TP_printk("\"%s\" %x %o",
64897+ __get_str(filename), __entry->flags, __entry->mode)
64898+);
64899+
64900+TRACE_EVENT(open_exec,
64901+
64902+ TP_PROTO(const char *filename),
64903+
64904+ TP_ARGS(filename),
64905+
64906+ TP_STRUCT__entry(
64907+ __string( filename, filename )
64908+ ),
64909+
64910+ TP_fast_assign(
64911+ __assign_str(filename, filename);
64912+ ),
64913+
64914+ TP_printk("\"%s\"",
64915+ __get_str(filename))
64916+);
64917+
64918+#endif /* _TRACE_FS_H */
64919+
64920+/* This part must be outside protection */
64921+#include <trace/define_trace.h>
64922diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64923index 1c09820..7f5ec79 100644
64924--- a/include/trace/events/irq.h
64925+++ b/include/trace/events/irq.h
64926@@ -36,7 +36,7 @@ struct softirq_action;
64927 */
64928 TRACE_EVENT(irq_handler_entry,
64929
64930- TP_PROTO(int irq, struct irqaction *action),
64931+ TP_PROTO(int irq, const struct irqaction *action),
64932
64933 TP_ARGS(irq, action),
64934
64935@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64936 */
64937 TRACE_EVENT(irq_handler_exit,
64938
64939- TP_PROTO(int irq, struct irqaction *action, int ret),
64940+ TP_PROTO(int irq, const struct irqaction *action, int ret),
64941
64942 TP_ARGS(irq, action, ret),
64943
64944diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64945index f9466fa..f4e2b81 100644
64946--- a/include/video/udlfb.h
64947+++ b/include/video/udlfb.h
64948@@ -53,10 +53,10 @@ struct dlfb_data {
64949 u32 pseudo_palette[256];
64950 int blank_mode; /*one of FB_BLANK_ */
64951 /* blit-only rendering path metrics, exposed through sysfs */
64952- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64953- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64954- atomic_t bytes_sent; /* to usb, after compression including overhead */
64955- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64956+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64957+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64958+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64959+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64960 };
64961
64962 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64963diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64964index 0993a22..32ba2fe 100644
64965--- a/include/video/uvesafb.h
64966+++ b/include/video/uvesafb.h
64967@@ -177,6 +177,7 @@ struct uvesafb_par {
64968 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64969 u8 pmi_setpal; /* PMI for palette changes */
64970 u16 *pmi_base; /* protected mode interface location */
64971+ u8 *pmi_code; /* protected mode code location */
64972 void *pmi_start;
64973 void *pmi_pal;
64974 u8 *vbe_state_orig; /*
64975diff --git a/init/Kconfig b/init/Kconfig
64976index d07dcf9..fa47d0e 100644
64977--- a/init/Kconfig
64978+++ b/init/Kconfig
64979@@ -835,6 +835,7 @@ endif # CGROUPS
64980
64981 config CHECKPOINT_RESTORE
64982 bool "Checkpoint/restore support" if EXPERT
64983+ depends on !GRKERNSEC
64984 default n
64985 help
64986 Enables additional kernel features in a sake of checkpoint/restore.
64987@@ -1014,6 +1015,7 @@ config UIDGID_CONVERTED
64988 # Security modules
64989 depends on SECURITY_TOMOYO = n
64990 depends on SECURITY_APPARMOR = n
64991+ depends on GRKERNSEC = n
64992
64993 config UIDGID_STRICT_TYPE_CHECKS
64994 bool "Require conversions between uid/gids and their internal representation"
64995@@ -1401,7 +1403,7 @@ config SLUB_DEBUG
64996
64997 config COMPAT_BRK
64998 bool "Disable heap randomization"
64999- default y
65000+ default n
65001 help
65002 Randomizing heap placement makes heap exploits harder, but it
65003 also breaks ancient binaries (including anything libc5 based).
65004@@ -1584,7 +1586,7 @@ config INIT_ALL_POSSIBLE
65005 config STOP_MACHINE
65006 bool
65007 default y
65008- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65009+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65010 help
65011 Need stop_machine() primitive.
65012
65013diff --git a/init/do_mounts.c b/init/do_mounts.c
65014index d3f0aee..c9322f5 100644
65015--- a/init/do_mounts.c
65016+++ b/init/do_mounts.c
65017@@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65018 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65019 {
65020 struct super_block *s;
65021- int err = sys_mount(name, "/root", fs, flags, data);
65022+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65023 if (err)
65024 return err;
65025
65026- sys_chdir("/root");
65027+ sys_chdir((const char __force_user *)"/root");
65028 s = current->fs->pwd.dentry->d_sb;
65029 ROOT_DEV = s->s_dev;
65030 printk(KERN_INFO
65031@@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65032 va_start(args, fmt);
65033 vsprintf(buf, fmt, args);
65034 va_end(args);
65035- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65036+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65037 if (fd >= 0) {
65038 sys_ioctl(fd, FDEJECT, 0);
65039 sys_close(fd);
65040 }
65041 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65042- fd = sys_open("/dev/console", O_RDWR, 0);
65043+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65044 if (fd >= 0) {
65045 sys_ioctl(fd, TCGETS, (long)&termios);
65046 termios.c_lflag &= ~ICANON;
65047 sys_ioctl(fd, TCSETSF, (long)&termios);
65048- sys_read(fd, &c, 1);
65049+ sys_read(fd, (char __user *)&c, 1);
65050 termios.c_lflag |= ICANON;
65051 sys_ioctl(fd, TCSETSF, (long)&termios);
65052 sys_close(fd);
65053@@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65054 mount_root();
65055 out:
65056 devtmpfs_mount("dev");
65057- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65058- sys_chroot(".");
65059+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65060+ sys_chroot((const char __force_user *)".");
65061 }
65062diff --git a/init/do_mounts.h b/init/do_mounts.h
65063index f5b978a..69dbfe8 100644
65064--- a/init/do_mounts.h
65065+++ b/init/do_mounts.h
65066@@ -15,15 +15,15 @@ extern int root_mountflags;
65067
65068 static inline int create_dev(char *name, dev_t dev)
65069 {
65070- sys_unlink(name);
65071- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65072+ sys_unlink((char __force_user *)name);
65073+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65074 }
65075
65076 #if BITS_PER_LONG == 32
65077 static inline u32 bstat(char *name)
65078 {
65079 struct stat64 stat;
65080- if (sys_stat64(name, &stat) != 0)
65081+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65082 return 0;
65083 if (!S_ISBLK(stat.st_mode))
65084 return 0;
65085@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65086 static inline u32 bstat(char *name)
65087 {
65088 struct stat stat;
65089- if (sys_newstat(name, &stat) != 0)
65090+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65091 return 0;
65092 if (!S_ISBLK(stat.st_mode))
65093 return 0;
65094diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65095index 135959a2..28a3f43 100644
65096--- a/init/do_mounts_initrd.c
65097+++ b/init/do_mounts_initrd.c
65098@@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65099 create_dev("/dev/root.old", Root_RAM0);
65100 /* mount initrd on rootfs' /root */
65101 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65102- sys_mkdir("/old", 0700);
65103- root_fd = sys_open("/", 0, 0);
65104- old_fd = sys_open("/old", 0, 0);
65105+ sys_mkdir((const char __force_user *)"/old", 0700);
65106+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
65107+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65108 /* move initrd over / and chdir/chroot in initrd root */
65109- sys_chdir("/root");
65110- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65111- sys_chroot(".");
65112+ sys_chdir((const char __force_user *)"/root");
65113+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65114+ sys_chroot((const char __force_user *)".");
65115
65116 /*
65117 * In case that a resume from disk is carried out by linuxrc or one of
65118@@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65119
65120 /* move initrd to rootfs' /old */
65121 sys_fchdir(old_fd);
65122- sys_mount("/", ".", NULL, MS_MOVE, NULL);
65123+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65124 /* switch root and cwd back to / of rootfs */
65125 sys_fchdir(root_fd);
65126- sys_chroot(".");
65127+ sys_chroot((const char __force_user *)".");
65128 sys_close(old_fd);
65129 sys_close(root_fd);
65130
65131 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65132- sys_chdir("/old");
65133+ sys_chdir((const char __force_user *)"/old");
65134 return;
65135 }
65136
65137@@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65138 mount_root();
65139
65140 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65141- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65142+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65143 if (!error)
65144 printk("okay\n");
65145 else {
65146- int fd = sys_open("/dev/root.old", O_RDWR, 0);
65147+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65148 if (error == -ENOENT)
65149 printk("/initrd does not exist. Ignored.\n");
65150 else
65151 printk("failed\n");
65152 printk(KERN_NOTICE "Unmounting old root\n");
65153- sys_umount("/old", MNT_DETACH);
65154+ sys_umount((char __force_user *)"/old", MNT_DETACH);
65155 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65156 if (fd < 0) {
65157 error = fd;
65158@@ -125,11 +125,11 @@ int __init initrd_load(void)
65159 * mounted in the normal path.
65160 */
65161 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65162- sys_unlink("/initrd.image");
65163+ sys_unlink((const char __force_user *)"/initrd.image");
65164 handle_initrd();
65165 return 1;
65166 }
65167 }
65168- sys_unlink("/initrd.image");
65169+ sys_unlink((const char __force_user *)"/initrd.image");
65170 return 0;
65171 }
65172diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65173index 8cb6db5..d729f50 100644
65174--- a/init/do_mounts_md.c
65175+++ b/init/do_mounts_md.c
65176@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65177 partitioned ? "_d" : "", minor,
65178 md_setup_args[ent].device_names);
65179
65180- fd = sys_open(name, 0, 0);
65181+ fd = sys_open((char __force_user *)name, 0, 0);
65182 if (fd < 0) {
65183 printk(KERN_ERR "md: open failed - cannot start "
65184 "array %s\n", name);
65185@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65186 * array without it
65187 */
65188 sys_close(fd);
65189- fd = sys_open(name, 0, 0);
65190+ fd = sys_open((char __force_user *)name, 0, 0);
65191 sys_ioctl(fd, BLKRRPART, 0);
65192 }
65193 sys_close(fd);
65194@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65195
65196 wait_for_device_probe();
65197
65198- fd = sys_open("/dev/md0", 0, 0);
65199+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65200 if (fd >= 0) {
65201 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65202 sys_close(fd);
65203diff --git a/init/init_task.c b/init/init_task.c
65204index 8b2f399..f0797c9 100644
65205--- a/init/init_task.c
65206+++ b/init/init_task.c
65207@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65208 * Initial thread structure. Alignment of this is handled by a special
65209 * linker map entry.
65210 */
65211+#ifdef CONFIG_X86
65212+union thread_union init_thread_union __init_task_data;
65213+#else
65214 union thread_union init_thread_union __init_task_data =
65215 { INIT_THREAD_INFO(init_task) };
65216+#endif
65217diff --git a/init/initramfs.c b/init/initramfs.c
65218index 84c6bf1..8899338 100644
65219--- a/init/initramfs.c
65220+++ b/init/initramfs.c
65221@@ -84,7 +84,7 @@ static void __init free_hash(void)
65222 }
65223 }
65224
65225-static long __init do_utime(char *filename, time_t mtime)
65226+static long __init do_utime(char __force_user *filename, time_t mtime)
65227 {
65228 struct timespec t[2];
65229
65230@@ -119,7 +119,7 @@ static void __init dir_utime(void)
65231 struct dir_entry *de, *tmp;
65232 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65233 list_del(&de->list);
65234- do_utime(de->name, de->mtime);
65235+ do_utime((char __force_user *)de->name, de->mtime);
65236 kfree(de->name);
65237 kfree(de);
65238 }
65239@@ -281,7 +281,7 @@ static int __init maybe_link(void)
65240 if (nlink >= 2) {
65241 char *old = find_link(major, minor, ino, mode, collected);
65242 if (old)
65243- return (sys_link(old, collected) < 0) ? -1 : 1;
65244+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65245 }
65246 return 0;
65247 }
65248@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65249 {
65250 struct stat st;
65251
65252- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65253+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65254 if (S_ISDIR(st.st_mode))
65255- sys_rmdir(path);
65256+ sys_rmdir((char __force_user *)path);
65257 else
65258- sys_unlink(path);
65259+ sys_unlink((char __force_user *)path);
65260 }
65261 }
65262
65263@@ -315,7 +315,7 @@ static int __init do_name(void)
65264 int openflags = O_WRONLY|O_CREAT;
65265 if (ml != 1)
65266 openflags |= O_TRUNC;
65267- wfd = sys_open(collected, openflags, mode);
65268+ wfd = sys_open((char __force_user *)collected, openflags, mode);
65269
65270 if (wfd >= 0) {
65271 sys_fchown(wfd, uid, gid);
65272@@ -327,17 +327,17 @@ static int __init do_name(void)
65273 }
65274 }
65275 } else if (S_ISDIR(mode)) {
65276- sys_mkdir(collected, mode);
65277- sys_chown(collected, uid, gid);
65278- sys_chmod(collected, mode);
65279+ sys_mkdir((char __force_user *)collected, mode);
65280+ sys_chown((char __force_user *)collected, uid, gid);
65281+ sys_chmod((char __force_user *)collected, mode);
65282 dir_add(collected, mtime);
65283 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65284 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65285 if (maybe_link() == 0) {
65286- sys_mknod(collected, mode, rdev);
65287- sys_chown(collected, uid, gid);
65288- sys_chmod(collected, mode);
65289- do_utime(collected, mtime);
65290+ sys_mknod((char __force_user *)collected, mode, rdev);
65291+ sys_chown((char __force_user *)collected, uid, gid);
65292+ sys_chmod((char __force_user *)collected, mode);
65293+ do_utime((char __force_user *)collected, mtime);
65294 }
65295 }
65296 return 0;
65297@@ -346,15 +346,15 @@ static int __init do_name(void)
65298 static int __init do_copy(void)
65299 {
65300 if (count >= body_len) {
65301- sys_write(wfd, victim, body_len);
65302+ sys_write(wfd, (char __force_user *)victim, body_len);
65303 sys_close(wfd);
65304- do_utime(vcollected, mtime);
65305+ do_utime((char __force_user *)vcollected, mtime);
65306 kfree(vcollected);
65307 eat(body_len);
65308 state = SkipIt;
65309 return 0;
65310 } else {
65311- sys_write(wfd, victim, count);
65312+ sys_write(wfd, (char __force_user *)victim, count);
65313 body_len -= count;
65314 eat(count);
65315 return 1;
65316@@ -365,9 +365,9 @@ static int __init do_symlink(void)
65317 {
65318 collected[N_ALIGN(name_len) + body_len] = '\0';
65319 clean_path(collected, 0);
65320- sys_symlink(collected + N_ALIGN(name_len), collected);
65321- sys_lchown(collected, uid, gid);
65322- do_utime(collected, mtime);
65323+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
65324+ sys_lchown((char __force_user *)collected, uid, gid);
65325+ do_utime((char __force_user *)collected, mtime);
65326 state = SkipIt;
65327 next_state = Reset;
65328 return 0;
65329diff --git a/init/main.c b/init/main.c
65330index b5cc0a7..5605c91 100644
65331--- a/init/main.c
65332+++ b/init/main.c
65333@@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
65334 extern void tc_init(void);
65335 #endif
65336
65337+extern void grsecurity_init(void);
65338+
65339 /*
65340 * Debug helper: via this flag we know that we are in 'early bootup code'
65341 * where only the boot processor is running with IRQ disabled. This means
65342@@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
65343
65344 __setup("reset_devices", set_reset_devices);
65345
65346+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65347+extern char pax_enter_kernel_user[];
65348+extern char pax_exit_kernel_user[];
65349+extern pgdval_t clone_pgd_mask;
65350+#endif
65351+
65352+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65353+static int __init setup_pax_nouderef(char *str)
65354+{
65355+#ifdef CONFIG_X86_32
65356+ unsigned int cpu;
65357+ struct desc_struct *gdt;
65358+
65359+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65360+ gdt = get_cpu_gdt_table(cpu);
65361+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65362+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65363+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65364+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65365+ }
65366+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65367+#else
65368+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65369+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65370+ clone_pgd_mask = ~(pgdval_t)0UL;
65371+#endif
65372+
65373+ return 0;
65374+}
65375+early_param("pax_nouderef", setup_pax_nouderef);
65376+#endif
65377+
65378+#ifdef CONFIG_PAX_SOFTMODE
65379+int pax_softmode;
65380+
65381+static int __init setup_pax_softmode(char *str)
65382+{
65383+ get_option(&str, &pax_softmode);
65384+ return 1;
65385+}
65386+__setup("pax_softmode=", setup_pax_softmode);
65387+#endif
65388+
65389 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65390 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65391 static const char *panic_later, *panic_param;
65392@@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65393 {
65394 int count = preempt_count();
65395 int ret;
65396+ const char *msg1 = "", *msg2 = "";
65397
65398 if (initcall_debug)
65399 ret = do_one_initcall_debug(fn);
65400@@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65401 sprintf(msgbuf, "error code %d ", ret);
65402
65403 if (preempt_count() != count) {
65404- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65405+ msg1 = " preemption imbalance";
65406 preempt_count() = count;
65407 }
65408 if (irqs_disabled()) {
65409- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65410+ msg2 = " disabled interrupts";
65411 local_irq_enable();
65412 }
65413- if (msgbuf[0]) {
65414- printk("initcall %pF returned with %s\n", fn, msgbuf);
65415+ if (msgbuf[0] || *msg1 || *msg2) {
65416+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65417 }
65418
65419 return ret;
65420@@ -747,8 +793,14 @@ static void __init do_initcall_level(int level)
65421 level, level,
65422 &repair_env_string);
65423
65424- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
65425+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
65426 do_one_initcall(*fn);
65427+
65428+#ifdef CONFIG_PAX_LATENT_ENTROPY
65429+ transfer_latent_entropy();
65430+#endif
65431+
65432+ }
65433 }
65434
65435 static void __init do_initcalls(void)
65436@@ -782,8 +834,14 @@ static void __init do_pre_smp_initcalls(void)
65437 {
65438 initcall_t *fn;
65439
65440- for (fn = __initcall_start; fn < __initcall0_start; fn++)
65441+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
65442 do_one_initcall(*fn);
65443+
65444+#ifdef CONFIG_PAX_LATENT_ENTROPY
65445+ transfer_latent_entropy();
65446+#endif
65447+
65448+ }
65449 }
65450
65451 static void run_init_process(const char *init_filename)
65452@@ -865,7 +923,7 @@ static int __init kernel_init(void * unused)
65453 do_basic_setup();
65454
65455 /* Open the /dev/console on the rootfs, this should never fail */
65456- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65457+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65458 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65459
65460 (void) sys_dup(0);
65461@@ -878,11 +936,13 @@ static int __init kernel_init(void * unused)
65462 if (!ramdisk_execute_command)
65463 ramdisk_execute_command = "/init";
65464
65465- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65466+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65467 ramdisk_execute_command = NULL;
65468 prepare_namespace();
65469 }
65470
65471+ grsecurity_init();
65472+
65473 /*
65474 * Ok, we have completed the initial bootup, and
65475 * we're essentially up and running. Get rid of the
65476diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65477index 8ce5769..4666884 100644
65478--- a/ipc/mqueue.c
65479+++ b/ipc/mqueue.c
65480@@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65481 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
65482 info->attr.mq_msgsize);
65483
65484+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65485 spin_lock(&mq_lock);
65486 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65487 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65488diff --git a/ipc/msg.c b/ipc/msg.c
65489index 7385de2..a8180e08 100644
65490--- a/ipc/msg.c
65491+++ b/ipc/msg.c
65492@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65493 return security_msg_queue_associate(msq, msgflg);
65494 }
65495
65496+static struct ipc_ops msg_ops = {
65497+ .getnew = newque,
65498+ .associate = msg_security,
65499+ .more_checks = NULL
65500+};
65501+
65502 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65503 {
65504 struct ipc_namespace *ns;
65505- struct ipc_ops msg_ops;
65506 struct ipc_params msg_params;
65507
65508 ns = current->nsproxy->ipc_ns;
65509
65510- msg_ops.getnew = newque;
65511- msg_ops.associate = msg_security;
65512- msg_ops.more_checks = NULL;
65513-
65514 msg_params.key = key;
65515 msg_params.flg = msgflg;
65516
65517diff --git a/ipc/sem.c b/ipc/sem.c
65518index 5215a81..cfc0cac 100644
65519--- a/ipc/sem.c
65520+++ b/ipc/sem.c
65521@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65522 return 0;
65523 }
65524
65525+static struct ipc_ops sem_ops = {
65526+ .getnew = newary,
65527+ .associate = sem_security,
65528+ .more_checks = sem_more_checks
65529+};
65530+
65531 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65532 {
65533 struct ipc_namespace *ns;
65534- struct ipc_ops sem_ops;
65535 struct ipc_params sem_params;
65536
65537 ns = current->nsproxy->ipc_ns;
65538@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65539 if (nsems < 0 || nsems > ns->sc_semmsl)
65540 return -EINVAL;
65541
65542- sem_ops.getnew = newary;
65543- sem_ops.associate = sem_security;
65544- sem_ops.more_checks = sem_more_checks;
65545-
65546 sem_params.key = key;
65547 sem_params.flg = semflg;
65548 sem_params.u.nsems = nsems;
65549diff --git a/ipc/shm.c b/ipc/shm.c
65550index 41c1285..cf6404c 100644
65551--- a/ipc/shm.c
65552+++ b/ipc/shm.c
65553@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65554 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65555 #endif
65556
65557+#ifdef CONFIG_GRKERNSEC
65558+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65559+ const time_t shm_createtime, const uid_t cuid,
65560+ const int shmid);
65561+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65562+ const time_t shm_createtime);
65563+#endif
65564+
65565 void shm_init_ns(struct ipc_namespace *ns)
65566 {
65567 ns->shm_ctlmax = SHMMAX;
65568@@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65569 shp->shm_lprid = 0;
65570 shp->shm_atim = shp->shm_dtim = 0;
65571 shp->shm_ctim = get_seconds();
65572+#ifdef CONFIG_GRKERNSEC
65573+ {
65574+ struct timespec timeval;
65575+ do_posix_clock_monotonic_gettime(&timeval);
65576+
65577+ shp->shm_createtime = timeval.tv_sec;
65578+ }
65579+#endif
65580 shp->shm_segsz = size;
65581 shp->shm_nattch = 0;
65582 shp->shm_file = file;
65583@@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65584 return 0;
65585 }
65586
65587+static struct ipc_ops shm_ops = {
65588+ .getnew = newseg,
65589+ .associate = shm_security,
65590+ .more_checks = shm_more_checks
65591+};
65592+
65593 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65594 {
65595 struct ipc_namespace *ns;
65596- struct ipc_ops shm_ops;
65597 struct ipc_params shm_params;
65598
65599 ns = current->nsproxy->ipc_ns;
65600
65601- shm_ops.getnew = newseg;
65602- shm_ops.associate = shm_security;
65603- shm_ops.more_checks = shm_more_checks;
65604-
65605 shm_params.key = key;
65606 shm_params.flg = shmflg;
65607 shm_params.u.size = size;
65608@@ -1000,6 +1017,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65609 f_mode = FMODE_READ | FMODE_WRITE;
65610 }
65611 if (shmflg & SHM_EXEC) {
65612+
65613+#ifdef CONFIG_PAX_MPROTECT
65614+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
65615+ goto out;
65616+#endif
65617+
65618 prot |= PROT_EXEC;
65619 acc_mode |= S_IXUGO;
65620 }
65621@@ -1023,9 +1046,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65622 if (err)
65623 goto out_unlock;
65624
65625+#ifdef CONFIG_GRKERNSEC
65626+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65627+ shp->shm_perm.cuid, shmid) ||
65628+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65629+ err = -EACCES;
65630+ goto out_unlock;
65631+ }
65632+#endif
65633+
65634 path = shp->shm_file->f_path;
65635 path_get(&path);
65636 shp->shm_nattch++;
65637+#ifdef CONFIG_GRKERNSEC
65638+ shp->shm_lapid = current->pid;
65639+#endif
65640 size = i_size_read(path.dentry->d_inode);
65641 shm_unlock(shp);
65642
65643diff --git a/kernel/acct.c b/kernel/acct.c
65644index 02e6167..54824f7 100644
65645--- a/kernel/acct.c
65646+++ b/kernel/acct.c
65647@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65648 */
65649 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65650 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65651- file->f_op->write(file, (char *)&ac,
65652+ file->f_op->write(file, (char __force_user *)&ac,
65653 sizeof(acct_t), &file->f_pos);
65654 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65655 set_fs(fs);
65656diff --git a/kernel/audit.c b/kernel/audit.c
65657index 1c7f2c6..9ba5359 100644
65658--- a/kernel/audit.c
65659+++ b/kernel/audit.c
65660@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65661 3) suppressed due to audit_rate_limit
65662 4) suppressed due to audit_backlog_limit
65663 */
65664-static atomic_t audit_lost = ATOMIC_INIT(0);
65665+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65666
65667 /* The netlink socket. */
65668 static struct sock *audit_sock;
65669@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65670 unsigned long now;
65671 int print;
65672
65673- atomic_inc(&audit_lost);
65674+ atomic_inc_unchecked(&audit_lost);
65675
65676 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65677
65678@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65679 printk(KERN_WARNING
65680 "audit: audit_lost=%d audit_rate_limit=%d "
65681 "audit_backlog_limit=%d\n",
65682- atomic_read(&audit_lost),
65683+ atomic_read_unchecked(&audit_lost),
65684 audit_rate_limit,
65685 audit_backlog_limit);
65686 audit_panic(message);
65687@@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65688 status_set.pid = audit_pid;
65689 status_set.rate_limit = audit_rate_limit;
65690 status_set.backlog_limit = audit_backlog_limit;
65691- status_set.lost = atomic_read(&audit_lost);
65692+ status_set.lost = atomic_read_unchecked(&audit_lost);
65693 status_set.backlog = skb_queue_len(&audit_skb_queue);
65694 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65695 &status_set, sizeof(status_set));
65696diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65697index 4b96415..d8c16ee 100644
65698--- a/kernel/auditsc.c
65699+++ b/kernel/auditsc.c
65700@@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65701 }
65702
65703 /* global counter which is incremented every time something logs in */
65704-static atomic_t session_id = ATOMIC_INIT(0);
65705+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65706
65707 /**
65708 * audit_set_loginuid - set current task's audit_context loginuid
65709@@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
65710 return -EPERM;
65711 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65712
65713- sessionid = atomic_inc_return(&session_id);
65714+ sessionid = atomic_inc_return_unchecked(&session_id);
65715 if (context && context->in_syscall) {
65716 struct audit_buffer *ab;
65717
65718diff --git a/kernel/capability.c b/kernel/capability.c
65719index 493d972..ea17248 100644
65720--- a/kernel/capability.c
65721+++ b/kernel/capability.c
65722@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65723 * before modification is attempted and the application
65724 * fails.
65725 */
65726+ if (tocopy > ARRAY_SIZE(kdata))
65727+ return -EFAULT;
65728+
65729 if (copy_to_user(dataptr, kdata, tocopy
65730 * sizeof(struct __user_cap_data_struct))) {
65731 return -EFAULT;
65732@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65733 int ret;
65734
65735 rcu_read_lock();
65736- ret = security_capable(__task_cred(t), ns, cap);
65737+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65738+ gr_task_is_capable(t, __task_cred(t), cap);
65739 rcu_read_unlock();
65740
65741- return (ret == 0);
65742+ return ret;
65743 }
65744
65745 /**
65746@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65747 int ret;
65748
65749 rcu_read_lock();
65750- ret = security_capable_noaudit(__task_cred(t), ns, cap);
65751+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65752 rcu_read_unlock();
65753
65754- return (ret == 0);
65755+ return ret;
65756 }
65757
65758 /**
65759@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65760 BUG();
65761 }
65762
65763- if (security_capable(current_cred(), ns, cap) == 0) {
65764+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65765 current->flags |= PF_SUPERPRIV;
65766 return true;
65767 }
65768@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65769 }
65770 EXPORT_SYMBOL(ns_capable);
65771
65772+bool ns_capable_nolog(struct user_namespace *ns, int cap)
65773+{
65774+ if (unlikely(!cap_valid(cap))) {
65775+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65776+ BUG();
65777+ }
65778+
65779+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65780+ current->flags |= PF_SUPERPRIV;
65781+ return true;
65782+ }
65783+ return false;
65784+}
65785+EXPORT_SYMBOL(ns_capable_nolog);
65786+
65787 /**
65788 * capable - Determine if the current task has a superior capability in effect
65789 * @cap: The capability to be tested for
65790@@ -408,6 +427,12 @@ bool capable(int cap)
65791 }
65792 EXPORT_SYMBOL(capable);
65793
65794+bool capable_nolog(int cap)
65795+{
65796+ return ns_capable_nolog(&init_user_ns, cap);
65797+}
65798+EXPORT_SYMBOL(capable_nolog);
65799+
65800 /**
65801 * nsown_capable - Check superior capability to one's own user_ns
65802 * @cap: The capability in question
65803@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
65804
65805 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
65806 }
65807+
65808+bool inode_capable_nolog(const struct inode *inode, int cap)
65809+{
65810+ struct user_namespace *ns = current_user_ns();
65811+
65812+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
65813+}
65814diff --git a/kernel/compat.c b/kernel/compat.c
65815index c28a306..b4d0cf3 100644
65816--- a/kernel/compat.c
65817+++ b/kernel/compat.c
65818@@ -13,6 +13,7 @@
65819
65820 #include <linux/linkage.h>
65821 #include <linux/compat.h>
65822+#include <linux/module.h>
65823 #include <linux/errno.h>
65824 #include <linux/time.h>
65825 #include <linux/signal.h>
65826@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65827 mm_segment_t oldfs;
65828 long ret;
65829
65830- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65831+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65832 oldfs = get_fs();
65833 set_fs(KERNEL_DS);
65834 ret = hrtimer_nanosleep_restart(restart);
65835@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65836 oldfs = get_fs();
65837 set_fs(KERNEL_DS);
65838 ret = hrtimer_nanosleep(&tu,
65839- rmtp ? (struct timespec __user *)&rmt : NULL,
65840+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
65841 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65842 set_fs(oldfs);
65843
65844@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65845 mm_segment_t old_fs = get_fs();
65846
65847 set_fs(KERNEL_DS);
65848- ret = sys_sigpending((old_sigset_t __user *) &s);
65849+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
65850 set_fs(old_fs);
65851 if (ret == 0)
65852 ret = put_user(s, set);
65853@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65854 mm_segment_t old_fs = get_fs();
65855
65856 set_fs(KERNEL_DS);
65857- ret = sys_old_getrlimit(resource, &r);
65858+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65859 set_fs(old_fs);
65860
65861 if (!ret) {
65862@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65863 mm_segment_t old_fs = get_fs();
65864
65865 set_fs(KERNEL_DS);
65866- ret = sys_getrusage(who, (struct rusage __user *) &r);
65867+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65868 set_fs(old_fs);
65869
65870 if (ret)
65871@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65872 set_fs (KERNEL_DS);
65873 ret = sys_wait4(pid,
65874 (stat_addr ?
65875- (unsigned int __user *) &status : NULL),
65876- options, (struct rusage __user *) &r);
65877+ (unsigned int __force_user *) &status : NULL),
65878+ options, (struct rusage __force_user *) &r);
65879 set_fs (old_fs);
65880
65881 if (ret > 0) {
65882@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65883 memset(&info, 0, sizeof(info));
65884
65885 set_fs(KERNEL_DS);
65886- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65887- uru ? (struct rusage __user *)&ru : NULL);
65888+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65889+ uru ? (struct rusage __force_user *)&ru : NULL);
65890 set_fs(old_fs);
65891
65892 if ((ret < 0) || (info.si_signo == 0))
65893@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65894 oldfs = get_fs();
65895 set_fs(KERNEL_DS);
65896 err = sys_timer_settime(timer_id, flags,
65897- (struct itimerspec __user *) &newts,
65898- (struct itimerspec __user *) &oldts);
65899+ (struct itimerspec __force_user *) &newts,
65900+ (struct itimerspec __force_user *) &oldts);
65901 set_fs(oldfs);
65902 if (!err && old && put_compat_itimerspec(old, &oldts))
65903 return -EFAULT;
65904@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65905 oldfs = get_fs();
65906 set_fs(KERNEL_DS);
65907 err = sys_timer_gettime(timer_id,
65908- (struct itimerspec __user *) &ts);
65909+ (struct itimerspec __force_user *) &ts);
65910 set_fs(oldfs);
65911 if (!err && put_compat_itimerspec(setting, &ts))
65912 return -EFAULT;
65913@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65914 oldfs = get_fs();
65915 set_fs(KERNEL_DS);
65916 err = sys_clock_settime(which_clock,
65917- (struct timespec __user *) &ts);
65918+ (struct timespec __force_user *) &ts);
65919 set_fs(oldfs);
65920 return err;
65921 }
65922@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65923 oldfs = get_fs();
65924 set_fs(KERNEL_DS);
65925 err = sys_clock_gettime(which_clock,
65926- (struct timespec __user *) &ts);
65927+ (struct timespec __force_user *) &ts);
65928 set_fs(oldfs);
65929 if (!err && put_compat_timespec(&ts, tp))
65930 return -EFAULT;
65931@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65932
65933 oldfs = get_fs();
65934 set_fs(KERNEL_DS);
65935- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65936+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65937 set_fs(oldfs);
65938
65939 err = compat_put_timex(utp, &txc);
65940@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65941 oldfs = get_fs();
65942 set_fs(KERNEL_DS);
65943 err = sys_clock_getres(which_clock,
65944- (struct timespec __user *) &ts);
65945+ (struct timespec __force_user *) &ts);
65946 set_fs(oldfs);
65947 if (!err && tp && put_compat_timespec(&ts, tp))
65948 return -EFAULT;
65949@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65950 long err;
65951 mm_segment_t oldfs;
65952 struct timespec tu;
65953- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65954+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65955
65956- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65957+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65958 oldfs = get_fs();
65959 set_fs(KERNEL_DS);
65960 err = clock_nanosleep_restart(restart);
65961@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
65962 oldfs = get_fs();
65963 set_fs(KERNEL_DS);
65964 err = sys_clock_nanosleep(which_clock, flags,
65965- (struct timespec __user *) &in,
65966- (struct timespec __user *) &out);
65967+ (struct timespec __force_user *) &in,
65968+ (struct timespec __force_user *) &out);
65969 set_fs(oldfs);
65970
65971 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
65972diff --git a/kernel/configs.c b/kernel/configs.c
65973index 42e8fa0..9e7406b 100644
65974--- a/kernel/configs.c
65975+++ b/kernel/configs.c
65976@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
65977 struct proc_dir_entry *entry;
65978
65979 /* create the current config file */
65980+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
65981+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
65982+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
65983+ &ikconfig_file_ops);
65984+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65985+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
65986+ &ikconfig_file_ops);
65987+#endif
65988+#else
65989 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
65990 &ikconfig_file_ops);
65991+#endif
65992+
65993 if (!entry)
65994 return -ENOMEM;
65995
65996diff --git a/kernel/cred.c b/kernel/cred.c
65997index de728ac..e3c267c 100644
65998--- a/kernel/cred.c
65999+++ b/kernel/cred.c
66000@@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66001 validate_creds(cred);
66002 alter_cred_subscribers(cred, -1);
66003 put_cred(cred);
66004+
66005+#ifdef CONFIG_GRKERNSEC_SETXID
66006+ cred = (struct cred *) tsk->delayed_cred;
66007+ if (cred != NULL) {
66008+ tsk->delayed_cred = NULL;
66009+ validate_creds(cred);
66010+ alter_cred_subscribers(cred, -1);
66011+ put_cred(cred);
66012+ }
66013+#endif
66014 }
66015
66016 /**
66017@@ -469,7 +479,7 @@ error_put:
66018 * Always returns 0 thus allowing this function to be tail-called at the end
66019 * of, say, sys_setgid().
66020 */
66021-int commit_creds(struct cred *new)
66022+static int __commit_creds(struct cred *new)
66023 {
66024 struct task_struct *task = current;
66025 const struct cred *old = task->real_cred;
66026@@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66027
66028 get_cred(new); /* we will require a ref for the subj creds too */
66029
66030+ gr_set_role_label(task, new->uid, new->gid);
66031+
66032 /* dumpability changes */
66033 if (!uid_eq(old->euid, new->euid) ||
66034 !gid_eq(old->egid, new->egid) ||
66035@@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66036 put_cred(old);
66037 return 0;
66038 }
66039+#ifdef CONFIG_GRKERNSEC_SETXID
66040+extern int set_user(struct cred *new);
66041+
66042+void gr_delayed_cred_worker(void)
66043+{
66044+ const struct cred *new = current->delayed_cred;
66045+ struct cred *ncred;
66046+
66047+ current->delayed_cred = NULL;
66048+
66049+ if (current_uid() && new != NULL) {
66050+ // from doing get_cred on it when queueing this
66051+ put_cred(new);
66052+ return;
66053+ } else if (new == NULL)
66054+ return;
66055+
66056+ ncred = prepare_creds();
66057+ if (!ncred)
66058+ goto die;
66059+ // uids
66060+ ncred->uid = new->uid;
66061+ ncred->euid = new->euid;
66062+ ncred->suid = new->suid;
66063+ ncred->fsuid = new->fsuid;
66064+ // gids
66065+ ncred->gid = new->gid;
66066+ ncred->egid = new->egid;
66067+ ncred->sgid = new->sgid;
66068+ ncred->fsgid = new->fsgid;
66069+ // groups
66070+ if (set_groups(ncred, new->group_info) < 0) {
66071+ abort_creds(ncred);
66072+ goto die;
66073+ }
66074+ // caps
66075+ ncred->securebits = new->securebits;
66076+ ncred->cap_inheritable = new->cap_inheritable;
66077+ ncred->cap_permitted = new->cap_permitted;
66078+ ncred->cap_effective = new->cap_effective;
66079+ ncred->cap_bset = new->cap_bset;
66080+
66081+ if (set_user(ncred)) {
66082+ abort_creds(ncred);
66083+ goto die;
66084+ }
66085+
66086+ // from doing get_cred on it when queueing this
66087+ put_cred(new);
66088+
66089+ __commit_creds(ncred);
66090+ return;
66091+die:
66092+ // from doing get_cred on it when queueing this
66093+ put_cred(new);
66094+ do_group_exit(SIGKILL);
66095+}
66096+#endif
66097+
66098+int commit_creds(struct cred *new)
66099+{
66100+#ifdef CONFIG_GRKERNSEC_SETXID
66101+ int ret;
66102+ int schedule_it = 0;
66103+ struct task_struct *t;
66104+
66105+ /* we won't get called with tasklist_lock held for writing
66106+ and interrupts disabled as the cred struct in that case is
66107+ init_cred
66108+ */
66109+ if (grsec_enable_setxid && !current_is_single_threaded() &&
66110+ !current_uid() && new->uid) {
66111+ schedule_it = 1;
66112+ }
66113+ ret = __commit_creds(new);
66114+ if (schedule_it) {
66115+ rcu_read_lock();
66116+ read_lock(&tasklist_lock);
66117+ for (t = next_thread(current); t != current;
66118+ t = next_thread(t)) {
66119+ if (t->delayed_cred == NULL) {
66120+ t->delayed_cred = get_cred(new);
66121+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66122+ set_tsk_need_resched(t);
66123+ }
66124+ }
66125+ read_unlock(&tasklist_lock);
66126+ rcu_read_unlock();
66127+ }
66128+ return ret;
66129+#else
66130+ return __commit_creds(new);
66131+#endif
66132+}
66133+
66134 EXPORT_SYMBOL(commit_creds);
66135
66136 /**
66137diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66138index 0557f24..1a00d9a 100644
66139--- a/kernel/debug/debug_core.c
66140+++ b/kernel/debug/debug_core.c
66141@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66142 */
66143 static atomic_t masters_in_kgdb;
66144 static atomic_t slaves_in_kgdb;
66145-static atomic_t kgdb_break_tasklet_var;
66146+static atomic_unchecked_t kgdb_break_tasklet_var;
66147 atomic_t kgdb_setting_breakpoint;
66148
66149 struct task_struct *kgdb_usethread;
66150@@ -132,7 +132,7 @@ int kgdb_single_step;
66151 static pid_t kgdb_sstep_pid;
66152
66153 /* to keep track of the CPU which is doing the single stepping*/
66154-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66155+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66156
66157 /*
66158 * If you are debugging a problem where roundup (the collection of
66159@@ -540,7 +540,7 @@ return_normal:
66160 * kernel will only try for the value of sstep_tries before
66161 * giving up and continuing on.
66162 */
66163- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66164+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66165 (kgdb_info[cpu].task &&
66166 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66167 atomic_set(&kgdb_active, -1);
66168@@ -634,8 +634,8 @@ cpu_master_loop:
66169 }
66170
66171 kgdb_restore:
66172- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66173- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66174+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66175+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66176 if (kgdb_info[sstep_cpu].task)
66177 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66178 else
66179@@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66180 static void kgdb_tasklet_bpt(unsigned long ing)
66181 {
66182 kgdb_breakpoint();
66183- atomic_set(&kgdb_break_tasklet_var, 0);
66184+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66185 }
66186
66187 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66188
66189 void kgdb_schedule_breakpoint(void)
66190 {
66191- if (atomic_read(&kgdb_break_tasklet_var) ||
66192+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66193 atomic_read(&kgdb_active) != -1 ||
66194 atomic_read(&kgdb_setting_breakpoint))
66195 return;
66196- atomic_inc(&kgdb_break_tasklet_var);
66197+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
66198 tasklet_schedule(&kgdb_tasklet_breakpoint);
66199 }
66200 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66201diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66202index 1f91413..362a0a1 100644
66203--- a/kernel/debug/kdb/kdb_main.c
66204+++ b/kernel/debug/kdb/kdb_main.c
66205@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
66206 list_for_each_entry(mod, kdb_modules, list) {
66207
66208 kdb_printf("%-20s%8u 0x%p ", mod->name,
66209- mod->core_size, (void *)mod);
66210+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
66211 #ifdef CONFIG_MODULE_UNLOAD
66212 kdb_printf("%4ld ", module_refcount(mod));
66213 #endif
66214@@ -1994,7 +1994,7 @@ static int kdb_lsmod(int argc, const char **argv)
66215 kdb_printf(" (Loading)");
66216 else
66217 kdb_printf(" (Live)");
66218- kdb_printf(" 0x%p", mod->module_core);
66219+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66220
66221 #ifdef CONFIG_MODULE_UNLOAD
66222 {
66223diff --git a/kernel/events/core.c b/kernel/events/core.c
66224index d7d71d6..f54b76f 100644
66225--- a/kernel/events/core.c
66226+++ b/kernel/events/core.c
66227@@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66228 return 0;
66229 }
66230
66231-static atomic64_t perf_event_id;
66232+static atomic64_unchecked_t perf_event_id;
66233
66234 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66235 enum event_type_t event_type);
66236@@ -2663,7 +2663,7 @@ static void __perf_event_read(void *info)
66237
66238 static inline u64 perf_event_count(struct perf_event *event)
66239 {
66240- return local64_read(&event->count) + atomic64_read(&event->child_count);
66241+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66242 }
66243
66244 static u64 perf_event_read(struct perf_event *event)
66245@@ -2987,9 +2987,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66246 mutex_lock(&event->child_mutex);
66247 total += perf_event_read(event);
66248 *enabled += event->total_time_enabled +
66249- atomic64_read(&event->child_total_time_enabled);
66250+ atomic64_read_unchecked(&event->child_total_time_enabled);
66251 *running += event->total_time_running +
66252- atomic64_read(&event->child_total_time_running);
66253+ atomic64_read_unchecked(&event->child_total_time_running);
66254
66255 list_for_each_entry(child, &event->child_list, child_list) {
66256 total += perf_event_read(child);
66257@@ -3396,10 +3396,10 @@ void perf_event_update_userpage(struct perf_event *event)
66258 userpg->offset -= local64_read(&event->hw.prev_count);
66259
66260 userpg->time_enabled = enabled +
66261- atomic64_read(&event->child_total_time_enabled);
66262+ atomic64_read_unchecked(&event->child_total_time_enabled);
66263
66264 userpg->time_running = running +
66265- atomic64_read(&event->child_total_time_running);
66266+ atomic64_read_unchecked(&event->child_total_time_running);
66267
66268 arch_perf_update_userpage(userpg, now);
66269
66270@@ -3832,11 +3832,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66271 values[n++] = perf_event_count(event);
66272 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66273 values[n++] = enabled +
66274- atomic64_read(&event->child_total_time_enabled);
66275+ atomic64_read_unchecked(&event->child_total_time_enabled);
66276 }
66277 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
66278 values[n++] = running +
66279- atomic64_read(&event->child_total_time_running);
66280+ atomic64_read_unchecked(&event->child_total_time_running);
66281 }
66282 if (read_format & PERF_FORMAT_ID)
66283 values[n++] = primary_event_id(event);
66284@@ -4514,12 +4514,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66285 * need to add enough zero bytes after the string to handle
66286 * the 64bit alignment we do later.
66287 */
66288- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
66289+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
66290 if (!buf) {
66291 name = strncpy(tmp, "//enomem", sizeof(tmp));
66292 goto got_name;
66293 }
66294- name = d_path(&file->f_path, buf, PATH_MAX);
66295+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
66296 if (IS_ERR(name)) {
66297 name = strncpy(tmp, "//toolong", sizeof(tmp));
66298 goto got_name;
66299@@ -5931,7 +5931,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
66300 event->parent = parent_event;
66301
66302 event->ns = get_pid_ns(current->nsproxy->pid_ns);
66303- event->id = atomic64_inc_return(&perf_event_id);
66304+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
66305
66306 event->state = PERF_EVENT_STATE_INACTIVE;
66307
66308@@ -6493,10 +6493,10 @@ static void sync_child_event(struct perf_event *child_event,
66309 /*
66310 * Add back the child's count to the parent's count:
66311 */
66312- atomic64_add(child_val, &parent_event->child_count);
66313- atomic64_add(child_event->total_time_enabled,
66314+ atomic64_add_unchecked(child_val, &parent_event->child_count);
66315+ atomic64_add_unchecked(child_event->total_time_enabled,
66316 &parent_event->child_total_time_enabled);
66317- atomic64_add(child_event->total_time_running,
66318+ atomic64_add_unchecked(child_event->total_time_running,
66319 &parent_event->child_total_time_running);
66320
66321 /*
66322diff --git a/kernel/exit.c b/kernel/exit.c
66323index 2f59cc3..ce5b167 100644
66324--- a/kernel/exit.c
66325+++ b/kernel/exit.c
66326@@ -59,6 +59,10 @@
66327 #include <asm/pgtable.h>
66328 #include <asm/mmu_context.h>
66329
66330+#ifdef CONFIG_GRKERNSEC
66331+extern rwlock_t grsec_exec_file_lock;
66332+#endif
66333+
66334 static void exit_mm(struct task_struct * tsk);
66335
66336 static void __unhash_process(struct task_struct *p, bool group_dead)
66337@@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
66338 struct task_struct *leader;
66339 int zap_leader;
66340 repeat:
66341+#ifdef CONFIG_NET
66342+ gr_del_task_from_ip_table(p);
66343+#endif
66344+
66345 /* don't need to get the RCU readlock here - the process is dead and
66346 * can't be modifying its own credentials. But shut RCU-lockdep up */
66347 rcu_read_lock();
66348@@ -394,7 +402,7 @@ int allow_signal(int sig)
66349 * know it'll be handled, so that they don't get converted to
66350 * SIGKILL or just silently dropped.
66351 */
66352- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
66353+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
66354 recalc_sigpending();
66355 spin_unlock_irq(&current->sighand->siglock);
66356 return 0;
66357@@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
66358 vsnprintf(current->comm, sizeof(current->comm), name, args);
66359 va_end(args);
66360
66361+#ifdef CONFIG_GRKERNSEC
66362+ write_lock(&grsec_exec_file_lock);
66363+ if (current->exec_file) {
66364+ fput(current->exec_file);
66365+ current->exec_file = NULL;
66366+ }
66367+ write_unlock(&grsec_exec_file_lock);
66368+#endif
66369+
66370+ gr_set_kernel_label(current);
66371+
66372 /*
66373 * If we were started as result of loading a module, close all of the
66374 * user space pages. We don't need them, and if we didn't close them
66375@@ -907,6 +926,8 @@ void do_exit(long code)
66376 struct task_struct *tsk = current;
66377 int group_dead;
66378
66379+ set_fs(USER_DS);
66380+
66381 profile_task_exit(tsk);
66382
66383 WARN_ON(blk_needs_flush_plug(tsk));
66384@@ -923,7 +944,6 @@ void do_exit(long code)
66385 * mm_release()->clear_child_tid() from writing to a user-controlled
66386 * kernel address.
66387 */
66388- set_fs(USER_DS);
66389
66390 ptrace_event(PTRACE_EVENT_EXIT, code);
66391
66392@@ -985,6 +1005,9 @@ void do_exit(long code)
66393 tsk->exit_code = code;
66394 taskstats_exit(tsk, group_dead);
66395
66396+ gr_acl_handle_psacct(tsk, code);
66397+ gr_acl_handle_exit();
66398+
66399 exit_mm(tsk);
66400
66401 if (group_dead)
66402@@ -1101,7 +1124,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66403 * Take down every thread in the group. This is called by fatal signals
66404 * as well as by sys_exit_group (below).
66405 */
66406-void
66407+__noreturn void
66408 do_group_exit(int exit_code)
66409 {
66410 struct signal_struct *sig = current->signal;
66411diff --git a/kernel/fork.c b/kernel/fork.c
66412index f00e319..c212fbc 100644
66413--- a/kernel/fork.c
66414+++ b/kernel/fork.c
66415@@ -321,7 +321,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66416 *stackend = STACK_END_MAGIC; /* for overflow detection */
66417
66418 #ifdef CONFIG_CC_STACKPROTECTOR
66419- tsk->stack_canary = get_random_int();
66420+ tsk->stack_canary = pax_get_random_long();
66421 #endif
66422
66423 /*
66424@@ -345,13 +345,78 @@ out:
66425 }
66426
66427 #ifdef CONFIG_MMU
66428+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
66429+{
66430+ struct vm_area_struct *tmp;
66431+ unsigned long charge;
66432+ struct mempolicy *pol;
66433+ struct file *file;
66434+
66435+ charge = 0;
66436+ if (mpnt->vm_flags & VM_ACCOUNT) {
66437+ unsigned long len;
66438+ len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66439+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66440+ goto fail_nomem;
66441+ charge = len;
66442+ }
66443+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66444+ if (!tmp)
66445+ goto fail_nomem;
66446+ *tmp = *mpnt;
66447+ tmp->vm_mm = mm;
66448+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
66449+ pol = mpol_dup(vma_policy(mpnt));
66450+ if (IS_ERR(pol))
66451+ goto fail_nomem_policy;
66452+ vma_set_policy(tmp, pol);
66453+ if (anon_vma_fork(tmp, mpnt))
66454+ goto fail_nomem_anon_vma_fork;
66455+ tmp->vm_flags &= ~VM_LOCKED;
66456+ tmp->vm_next = tmp->vm_prev = NULL;
66457+ tmp->vm_mirror = NULL;
66458+ file = tmp->vm_file;
66459+ if (file) {
66460+ struct inode *inode = file->f_path.dentry->d_inode;
66461+ struct address_space *mapping = file->f_mapping;
66462+
66463+ get_file(file);
66464+ if (tmp->vm_flags & VM_DENYWRITE)
66465+ atomic_dec(&inode->i_writecount);
66466+ mutex_lock(&mapping->i_mmap_mutex);
66467+ if (tmp->vm_flags & VM_SHARED)
66468+ mapping->i_mmap_writable++;
66469+ flush_dcache_mmap_lock(mapping);
66470+ /* insert tmp into the share list, just after mpnt */
66471+ vma_prio_tree_add(tmp, mpnt);
66472+ flush_dcache_mmap_unlock(mapping);
66473+ mutex_unlock(&mapping->i_mmap_mutex);
66474+ }
66475+
66476+ /*
66477+ * Clear hugetlb-related page reserves for children. This only
66478+ * affects MAP_PRIVATE mappings. Faults generated by the child
66479+ * are not guaranteed to succeed, even if read-only
66480+ */
66481+ if (is_vm_hugetlb_page(tmp))
66482+ reset_vma_resv_huge_pages(tmp);
66483+
66484+ return tmp;
66485+
66486+fail_nomem_anon_vma_fork:
66487+ mpol_put(pol);
66488+fail_nomem_policy:
66489+ kmem_cache_free(vm_area_cachep, tmp);
66490+fail_nomem:
66491+ vm_unacct_memory(charge);
66492+ return NULL;
66493+}
66494+
66495 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66496 {
66497 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66498 struct rb_node **rb_link, *rb_parent;
66499 int retval;
66500- unsigned long charge;
66501- struct mempolicy *pol;
66502
66503 down_write(&oldmm->mmap_sem);
66504 flush_cache_dup_mm(oldmm);
66505@@ -363,8 +428,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66506 mm->locked_vm = 0;
66507 mm->mmap = NULL;
66508 mm->mmap_cache = NULL;
66509- mm->free_area_cache = oldmm->mmap_base;
66510- mm->cached_hole_size = ~0UL;
66511+ mm->free_area_cache = oldmm->free_area_cache;
66512+ mm->cached_hole_size = oldmm->cached_hole_size;
66513 mm->map_count = 0;
66514 cpumask_clear(mm_cpumask(mm));
66515 mm->mm_rb = RB_ROOT;
66516@@ -380,8 +445,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66517
66518 prev = NULL;
66519 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66520- struct file *file;
66521-
66522 if (mpnt->vm_flags & VM_DONTCOPY) {
66523 long pages = vma_pages(mpnt);
66524 mm->total_vm -= pages;
66525@@ -389,54 +452,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66526 -pages);
66527 continue;
66528 }
66529- charge = 0;
66530- if (mpnt->vm_flags & VM_ACCOUNT) {
66531- unsigned long len;
66532- len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66533- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66534- goto fail_nomem;
66535- charge = len;
66536+ tmp = dup_vma(mm, oldmm, mpnt);
66537+ if (!tmp) {
66538+ retval = -ENOMEM;
66539+ goto out;
66540 }
66541- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66542- if (!tmp)
66543- goto fail_nomem;
66544- *tmp = *mpnt;
66545- INIT_LIST_HEAD(&tmp->anon_vma_chain);
66546- pol = mpol_dup(vma_policy(mpnt));
66547- retval = PTR_ERR(pol);
66548- if (IS_ERR(pol))
66549- goto fail_nomem_policy;
66550- vma_set_policy(tmp, pol);
66551- tmp->vm_mm = mm;
66552- if (anon_vma_fork(tmp, mpnt))
66553- goto fail_nomem_anon_vma_fork;
66554- tmp->vm_flags &= ~VM_LOCKED;
66555- tmp->vm_next = tmp->vm_prev = NULL;
66556- file = tmp->vm_file;
66557- if (file) {
66558- struct inode *inode = file->f_path.dentry->d_inode;
66559- struct address_space *mapping = file->f_mapping;
66560-
66561- get_file(file);
66562- if (tmp->vm_flags & VM_DENYWRITE)
66563- atomic_dec(&inode->i_writecount);
66564- mutex_lock(&mapping->i_mmap_mutex);
66565- if (tmp->vm_flags & VM_SHARED)
66566- mapping->i_mmap_writable++;
66567- flush_dcache_mmap_lock(mapping);
66568- /* insert tmp into the share list, just after mpnt */
66569- vma_prio_tree_add(tmp, mpnt);
66570- flush_dcache_mmap_unlock(mapping);
66571- mutex_unlock(&mapping->i_mmap_mutex);
66572- }
66573-
66574- /*
66575- * Clear hugetlb-related page reserves for children. This only
66576- * affects MAP_PRIVATE mappings. Faults generated by the child
66577- * are not guaranteed to succeed, even if read-only
66578- */
66579- if (is_vm_hugetlb_page(tmp))
66580- reset_vma_resv_huge_pages(tmp);
66581
66582 /*
66583 * Link in the new vma and copy the page table entries.
66584@@ -459,9 +479,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66585 if (retval)
66586 goto out;
66587
66588- if (file && uprobe_mmap(tmp))
66589+ if (tmp->vm_file && uprobe_mmap(tmp))
66590 goto out;
66591 }
66592+
66593+#ifdef CONFIG_PAX_SEGMEXEC
66594+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66595+ struct vm_area_struct *mpnt_m;
66596+
66597+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66598+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66599+
66600+ if (!mpnt->vm_mirror)
66601+ continue;
66602+
66603+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66604+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66605+ mpnt->vm_mirror = mpnt_m;
66606+ } else {
66607+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66608+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66609+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66610+ mpnt->vm_mirror->vm_mirror = mpnt;
66611+ }
66612+ }
66613+ BUG_ON(mpnt_m);
66614+ }
66615+#endif
66616+
66617 /* a new mm has just been created */
66618 arch_dup_mmap(oldmm, mm);
66619 retval = 0;
66620@@ -470,14 +515,6 @@ out:
66621 flush_tlb_mm(oldmm);
66622 up_write(&oldmm->mmap_sem);
66623 return retval;
66624-fail_nomem_anon_vma_fork:
66625- mpol_put(pol);
66626-fail_nomem_policy:
66627- kmem_cache_free(vm_area_cachep, tmp);
66628-fail_nomem:
66629- retval = -ENOMEM;
66630- vm_unacct_memory(charge);
66631- goto out;
66632 }
66633
66634 static inline int mm_alloc_pgd(struct mm_struct *mm)
66635@@ -714,8 +751,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66636 return ERR_PTR(err);
66637
66638 mm = get_task_mm(task);
66639- if (mm && mm != current->mm &&
66640- !ptrace_may_access(task, mode)) {
66641+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66642+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66643 mmput(mm);
66644 mm = ERR_PTR(-EACCES);
66645 }
66646@@ -936,13 +973,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66647 spin_unlock(&fs->lock);
66648 return -EAGAIN;
66649 }
66650- fs->users++;
66651+ atomic_inc(&fs->users);
66652 spin_unlock(&fs->lock);
66653 return 0;
66654 }
66655 tsk->fs = copy_fs_struct(fs);
66656 if (!tsk->fs)
66657 return -ENOMEM;
66658+ gr_set_chroot_entries(tsk, &tsk->fs->root);
66659 return 0;
66660 }
66661
66662@@ -1209,6 +1247,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66663 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66664 #endif
66665 retval = -EAGAIN;
66666+
66667+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66668+
66669 if (atomic_read(&p->real_cred->user->processes) >=
66670 task_rlimit(p, RLIMIT_NPROC)) {
66671 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66672@@ -1431,6 +1472,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66673 /* Need tasklist lock for parent etc handling! */
66674 write_lock_irq(&tasklist_lock);
66675
66676+ /* synchronizes with gr_set_acls() */
66677+ gr_copy_label(p);
66678+
66679 /* CLONE_PARENT re-uses the old parent */
66680 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
66681 p->real_parent = current->real_parent;
66682@@ -1541,6 +1585,8 @@ bad_fork_cleanup_count:
66683 bad_fork_free:
66684 free_task(p);
66685 fork_out:
66686+ gr_log_forkfail(retval);
66687+
66688 return ERR_PTR(retval);
66689 }
66690
66691@@ -1641,6 +1687,8 @@ long do_fork(unsigned long clone_flags,
66692 if (clone_flags & CLONE_PARENT_SETTID)
66693 put_user(nr, parent_tidptr);
66694
66695+ gr_handle_brute_check();
66696+
66697 if (clone_flags & CLONE_VFORK) {
66698 p->vfork_done = &vfork;
66699 init_completion(&vfork);
66700@@ -1739,7 +1787,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66701 return 0;
66702
66703 /* don't need lock here; in the worst case we'll do useless copy */
66704- if (fs->users == 1)
66705+ if (atomic_read(&fs->users) == 1)
66706 return 0;
66707
66708 *new_fsp = copy_fs_struct(fs);
66709@@ -1828,7 +1876,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66710 fs = current->fs;
66711 spin_lock(&fs->lock);
66712 current->fs = new_fs;
66713- if (--fs->users)
66714+ gr_set_chroot_entries(current, &current->fs->root);
66715+ if (atomic_dec_return(&fs->users))
66716 new_fs = NULL;
66717 else
66718 new_fs = fs;
66719diff --git a/kernel/futex.c b/kernel/futex.c
66720index e2b0fb9..ced552c 100644
66721--- a/kernel/futex.c
66722+++ b/kernel/futex.c
66723@@ -54,6 +54,7 @@
66724 #include <linux/mount.h>
66725 #include <linux/pagemap.h>
66726 #include <linux/syscalls.h>
66727+#include <linux/ptrace.h>
66728 #include <linux/signal.h>
66729 #include <linux/export.h>
66730 #include <linux/magic.h>
66731@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66732 struct page *page, *page_head;
66733 int err, ro = 0;
66734
66735+#ifdef CONFIG_PAX_SEGMEXEC
66736+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66737+ return -EFAULT;
66738+#endif
66739+
66740 /*
66741 * The futex address must be "naturally" aligned.
66742 */
66743@@ -2231,11 +2237,11 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb,
66744 * @uaddr2: the pi futex we will take prior to returning to user-space
66745 *
66746 * The caller will wait on uaddr and will be requeued by futex_requeue() to
66747- * uaddr2 which must be PI aware. Normal wakeup will wake on uaddr2 and
66748- * complete the acquisition of the rt_mutex prior to returning to userspace.
66749- * This ensures the rt_mutex maintains an owner when it has waiters; without
66750- * one, the pi logic wouldn't know which task to boost/deboost, if there was a
66751- * need to.
66752+ * uaddr2 which must be PI aware and unique from uaddr. Normal wakeup will wake
66753+ * on uaddr2 and complete the acquisition of the rt_mutex prior to returning to
66754+ * userspace. This ensures the rt_mutex maintains an owner when it has waiters;
66755+ * without one, the pi logic would not know which task to boost/deboost, if
66756+ * there was a need to.
66757 *
66758 * We call schedule in futex_wait_queue_me() when we enqueue and return there
66759 * via the following:
66760@@ -2272,6 +2278,9 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
66761 struct futex_q q = futex_q_init;
66762 int res, ret;
66763
66764+ if (uaddr == uaddr2)
66765+ return -EINVAL;
66766+
66767 if (!bitset)
66768 return -EINVAL;
66769
66770@@ -2370,7 +2379,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
66771 * fault, unlock the rt_mutex and return the fault to userspace.
66772 */
66773 if (ret == -EFAULT) {
66774- if (rt_mutex_owner(pi_mutex) == current)
66775+ if (pi_mutex && rt_mutex_owner(pi_mutex) == current)
66776 rt_mutex_unlock(pi_mutex);
66777 } else if (ret == -EINTR) {
66778 /*
66779@@ -2711,6 +2720,7 @@ static int __init futex_init(void)
66780 {
66781 u32 curval;
66782 int i;
66783+ mm_segment_t oldfs;
66784
66785 /*
66786 * This will fail and we want it. Some arch implementations do
66787@@ -2722,8 +2732,11 @@ static int __init futex_init(void)
66788 * implementation, the non-functional ones will return
66789 * -ENOSYS.
66790 */
66791+ oldfs = get_fs();
66792+ set_fs(USER_DS);
66793 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66794 futex_cmpxchg_enabled = 1;
66795+ set_fs(oldfs);
66796
66797 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66798 plist_head_init(&futex_queues[i].chain);
66799diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66800index 9b22d03..6295b62 100644
66801--- a/kernel/gcov/base.c
66802+++ b/kernel/gcov/base.c
66803@@ -102,11 +102,6 @@ void gcov_enable_events(void)
66804 }
66805
66806 #ifdef CONFIG_MODULES
66807-static inline int within(void *addr, void *start, unsigned long size)
66808-{
66809- return ((addr >= start) && (addr < start + size));
66810-}
66811-
66812 /* Update list and generate events when modules are unloaded. */
66813 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66814 void *data)
66815@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66816 prev = NULL;
66817 /* Remove entries located in module from linked list. */
66818 for (info = gcov_info_head; info; info = info->next) {
66819- if (within(info, mod->module_core, mod->core_size)) {
66820+ if (within_module_core_rw((unsigned long)info, mod)) {
66821 if (prev)
66822 prev->next = info->next;
66823 else
66824diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66825index 6db7a5e..25b6648 100644
66826--- a/kernel/hrtimer.c
66827+++ b/kernel/hrtimer.c
66828@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
66829 local_irq_restore(flags);
66830 }
66831
66832-static void run_hrtimer_softirq(struct softirq_action *h)
66833+static void run_hrtimer_softirq(void)
66834 {
66835 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
66836
66837diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66838index 4304919..408c4c0 100644
66839--- a/kernel/jump_label.c
66840+++ b/kernel/jump_label.c
66841@@ -13,6 +13,7 @@
66842 #include <linux/sort.h>
66843 #include <linux/err.h>
66844 #include <linux/static_key.h>
66845+#include <linux/mm.h>
66846
66847 #ifdef HAVE_JUMP_LABEL
66848
66849@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66850
66851 size = (((unsigned long)stop - (unsigned long)start)
66852 / sizeof(struct jump_entry));
66853+ pax_open_kernel();
66854 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66855+ pax_close_kernel();
66856 }
66857
66858 static void jump_label_update(struct static_key *key, int enable);
66859@@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66860 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66861 struct jump_entry *iter;
66862
66863+ pax_open_kernel();
66864 for (iter = iter_start; iter < iter_stop; iter++) {
66865 if (within_module_init(iter->code, mod))
66866 iter->code = 0;
66867 }
66868+ pax_close_kernel();
66869 }
66870
66871 static int
66872diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66873index 2169fee..45c017a 100644
66874--- a/kernel/kallsyms.c
66875+++ b/kernel/kallsyms.c
66876@@ -11,6 +11,9 @@
66877 * Changed the compression method from stem compression to "table lookup"
66878 * compression (see scripts/kallsyms.c for a more complete description)
66879 */
66880+#ifdef CONFIG_GRKERNSEC_HIDESYM
66881+#define __INCLUDED_BY_HIDESYM 1
66882+#endif
66883 #include <linux/kallsyms.h>
66884 #include <linux/module.h>
66885 #include <linux/init.h>
66886@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66887
66888 static inline int is_kernel_inittext(unsigned long addr)
66889 {
66890+ if (system_state != SYSTEM_BOOTING)
66891+ return 0;
66892+
66893 if (addr >= (unsigned long)_sinittext
66894 && addr <= (unsigned long)_einittext)
66895 return 1;
66896 return 0;
66897 }
66898
66899+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66900+#ifdef CONFIG_MODULES
66901+static inline int is_module_text(unsigned long addr)
66902+{
66903+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66904+ return 1;
66905+
66906+ addr = ktla_ktva(addr);
66907+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66908+}
66909+#else
66910+static inline int is_module_text(unsigned long addr)
66911+{
66912+ return 0;
66913+}
66914+#endif
66915+#endif
66916+
66917 static inline int is_kernel_text(unsigned long addr)
66918 {
66919 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66920@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66921
66922 static inline int is_kernel(unsigned long addr)
66923 {
66924+
66925+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66926+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
66927+ return 1;
66928+
66929+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66930+#else
66931 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66932+#endif
66933+
66934 return 1;
66935 return in_gate_area_no_mm(addr);
66936 }
66937
66938 static int is_ksym_addr(unsigned long addr)
66939 {
66940+
66941+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66942+ if (is_module_text(addr))
66943+ return 0;
66944+#endif
66945+
66946 if (all_var)
66947 return is_kernel(addr);
66948
66949@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66950
66951 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66952 {
66953- iter->name[0] = '\0';
66954 iter->nameoff = get_symbol_offset(new_pos);
66955 iter->pos = new_pos;
66956 }
66957@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
66958 {
66959 struct kallsym_iter *iter = m->private;
66960
66961+#ifdef CONFIG_GRKERNSEC_HIDESYM
66962+ if (current_uid())
66963+ return 0;
66964+#endif
66965+
66966 /* Some debugging symbols have no name. Ignore them. */
66967 if (!iter->name[0])
66968 return 0;
66969@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
66970 */
66971 type = iter->exported ? toupper(iter->type) :
66972 tolower(iter->type);
66973+
66974 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
66975 type, iter->name, iter->module_name);
66976 } else
66977@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66978 struct kallsym_iter *iter;
66979 int ret;
66980
66981- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66982+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
66983 if (!iter)
66984 return -ENOMEM;
66985 reset_iter(iter, 0);
66986diff --git a/kernel/kexec.c b/kernel/kexec.c
66987index 4e2e472..cd0c7ae 100644
66988--- a/kernel/kexec.c
66989+++ b/kernel/kexec.c
66990@@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
66991 unsigned long flags)
66992 {
66993 struct compat_kexec_segment in;
66994- struct kexec_segment out, __user *ksegments;
66995+ struct kexec_segment out;
66996+ struct kexec_segment __user *ksegments;
66997 unsigned long i, result;
66998
66999 /* Don't allow clients that don't understand the native
67000diff --git a/kernel/kmod.c b/kernel/kmod.c
67001index ff2c7cb..085d7af 100644
67002--- a/kernel/kmod.c
67003+++ b/kernel/kmod.c
67004@@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67005 kfree(info->argv);
67006 }
67007
67008-static int call_modprobe(char *module_name, int wait)
67009+static int call_modprobe(char *module_name, char *module_param, int wait)
67010 {
67011 static char *envp[] = {
67012 "HOME=/",
67013@@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
67014 NULL
67015 };
67016
67017- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67018+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67019 if (!argv)
67020 goto out;
67021
67022@@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
67023 argv[1] = "-q";
67024 argv[2] = "--";
67025 argv[3] = module_name; /* check free_modprobe_argv() */
67026- argv[4] = NULL;
67027+ argv[4] = module_param;
67028+ argv[5] = NULL;
67029
67030 return call_usermodehelper_fns(modprobe_path, argv, envp,
67031 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67032@@ -112,9 +113,8 @@ out:
67033 * If module auto-loading support is disabled then this function
67034 * becomes a no-operation.
67035 */
67036-int __request_module(bool wait, const char *fmt, ...)
67037+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67038 {
67039- va_list args;
67040 char module_name[MODULE_NAME_LEN];
67041 unsigned int max_modprobes;
67042 int ret;
67043@@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
67044 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67045 static int kmod_loop_msg;
67046
67047- va_start(args, fmt);
67048- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67049- va_end(args);
67050+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67051 if (ret >= MODULE_NAME_LEN)
67052 return -ENAMETOOLONG;
67053
67054@@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
67055 if (ret)
67056 return ret;
67057
67058+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67059+ if (!current_uid()) {
67060+ /* hack to workaround consolekit/udisks stupidity */
67061+ read_lock(&tasklist_lock);
67062+ if (!strcmp(current->comm, "mount") &&
67063+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67064+ read_unlock(&tasklist_lock);
67065+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67066+ return -EPERM;
67067+ }
67068+ read_unlock(&tasklist_lock);
67069+ }
67070+#endif
67071+
67072 /* If modprobe needs a service that is in a module, we get a recursive
67073 * loop. Limit the number of running kmod threads to max_threads/2 or
67074 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67075@@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
67076
67077 trace_module_request(module_name, wait, _RET_IP_);
67078
67079- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67080+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67081
67082 atomic_dec(&kmod_concurrent);
67083 return ret;
67084 }
67085+
67086+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67087+{
67088+ va_list args;
67089+ int ret;
67090+
67091+ va_start(args, fmt);
67092+ ret = ____request_module(wait, module_param, fmt, args);
67093+ va_end(args);
67094+
67095+ return ret;
67096+}
67097+
67098+int __request_module(bool wait, const char *fmt, ...)
67099+{
67100+ va_list args;
67101+ int ret;
67102+
67103+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67104+ if (current_uid()) {
67105+ char module_param[MODULE_NAME_LEN];
67106+
67107+ memset(module_param, 0, sizeof(module_param));
67108+
67109+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67110+
67111+ va_start(args, fmt);
67112+ ret = ____request_module(wait, module_param, fmt, args);
67113+ va_end(args);
67114+
67115+ return ret;
67116+ }
67117+#endif
67118+
67119+ va_start(args, fmt);
67120+ ret = ____request_module(wait, NULL, fmt, args);
67121+ va_end(args);
67122+
67123+ return ret;
67124+}
67125+
67126 EXPORT_SYMBOL(__request_module);
67127 #endif /* CONFIG_MODULES */
67128
67129@@ -266,7 +319,7 @@ static int wait_for_helper(void *data)
67130 *
67131 * Thus the __user pointer cast is valid here.
67132 */
67133- sys_wait4(pid, (int __user *)&ret, 0, NULL);
67134+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67135
67136 /*
67137 * If ret is 0, either ____call_usermodehelper failed and the
67138diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67139index c62b854..cb67968 100644
67140--- a/kernel/kprobes.c
67141+++ b/kernel/kprobes.c
67142@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67143 * kernel image and loaded module images reside. This is required
67144 * so x86_64 can correctly handle the %rip-relative fixups.
67145 */
67146- kip->insns = module_alloc(PAGE_SIZE);
67147+ kip->insns = module_alloc_exec(PAGE_SIZE);
67148 if (!kip->insns) {
67149 kfree(kip);
67150 return NULL;
67151@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67152 */
67153 if (!list_is_singular(&kip->list)) {
67154 list_del(&kip->list);
67155- module_free(NULL, kip->insns);
67156+ module_free_exec(NULL, kip->insns);
67157 kfree(kip);
67158 }
67159 return 1;
67160@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67161 {
67162 int i, err = 0;
67163 unsigned long offset = 0, size = 0;
67164- char *modname, namebuf[128];
67165+ char *modname, namebuf[KSYM_NAME_LEN];
67166 const char *symbol_name;
67167 void *addr;
67168 struct kprobe_blackpoint *kb;
67169@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67170 const char *sym = NULL;
67171 unsigned int i = *(loff_t *) v;
67172 unsigned long offset = 0;
67173- char *modname, namebuf[128];
67174+ char *modname, namebuf[KSYM_NAME_LEN];
67175
67176 head = &kprobe_table[i];
67177 preempt_disable();
67178diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67179index 4e316e1..5501eef 100644
67180--- a/kernel/ksysfs.c
67181+++ b/kernel/ksysfs.c
67182@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67183 {
67184 if (count+1 > UEVENT_HELPER_PATH_LEN)
67185 return -ENOENT;
67186+ if (!capable(CAP_SYS_ADMIN))
67187+ return -EPERM;
67188 memcpy(uevent_helper, buf, count);
67189 uevent_helper[count] = '\0';
67190 if (count && uevent_helper[count-1] == '\n')
67191diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67192index ea9ee45..67ebc8f 100644
67193--- a/kernel/lockdep.c
67194+++ b/kernel/lockdep.c
67195@@ -590,6 +590,10 @@ static int static_obj(void *obj)
67196 end = (unsigned long) &_end,
67197 addr = (unsigned long) obj;
67198
67199+#ifdef CONFIG_PAX_KERNEXEC
67200+ start = ktla_ktva(start);
67201+#endif
67202+
67203 /*
67204 * static variable?
67205 */
67206@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67207 if (!static_obj(lock->key)) {
67208 debug_locks_off();
67209 printk("INFO: trying to register non-static key.\n");
67210+ printk("lock:%pS key:%pS.\n", lock, lock->key);
67211 printk("the code is fine but needs lockdep annotation.\n");
67212 printk("turning off the locking correctness validator.\n");
67213 dump_stack();
67214@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67215 if (!class)
67216 return 0;
67217 }
67218- atomic_inc((atomic_t *)&class->ops);
67219+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67220 if (very_verbose(class)) {
67221 printk("\nacquire class [%p] %s", class->key, class->name);
67222 if (class->name_version > 1)
67223diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67224index 91c32a0..b2c71c5 100644
67225--- a/kernel/lockdep_proc.c
67226+++ b/kernel/lockdep_proc.c
67227@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67228
67229 static void print_name(struct seq_file *m, struct lock_class *class)
67230 {
67231- char str[128];
67232+ char str[KSYM_NAME_LEN];
67233 const char *name = class->name;
67234
67235 if (!name) {
67236diff --git a/kernel/module.c b/kernel/module.c
67237index 4edbd9c..165e780 100644
67238--- a/kernel/module.c
67239+++ b/kernel/module.c
67240@@ -58,6 +58,7 @@
67241 #include <linux/jump_label.h>
67242 #include <linux/pfn.h>
67243 #include <linux/bsearch.h>
67244+#include <linux/grsecurity.h>
67245
67246 #define CREATE_TRACE_POINTS
67247 #include <trace/events/module.h>
67248@@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67249
67250 /* Bounds of module allocation, for speeding __module_address.
67251 * Protected by module_mutex. */
67252-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67253+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67254+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67255
67256 int register_module_notifier(struct notifier_block * nb)
67257 {
67258@@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67259 return true;
67260
67261 list_for_each_entry_rcu(mod, &modules, list) {
67262- struct symsearch arr[] = {
67263+ struct symsearch modarr[] = {
67264 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67265 NOT_GPL_ONLY, false },
67266 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67267@@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67268 #endif
67269 };
67270
67271- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67272+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67273 return true;
67274 }
67275 return false;
67276@@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
67277 static int percpu_modalloc(struct module *mod,
67278 unsigned long size, unsigned long align)
67279 {
67280- if (align > PAGE_SIZE) {
67281+ if (align-1 >= PAGE_SIZE) {
67282 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67283 mod->name, align, PAGE_SIZE);
67284 align = PAGE_SIZE;
67285@@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
67286 static ssize_t show_coresize(struct module_attribute *mattr,
67287 struct module_kobject *mk, char *buffer)
67288 {
67289- return sprintf(buffer, "%u\n", mk->mod->core_size);
67290+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
67291 }
67292
67293 static struct module_attribute modinfo_coresize =
67294@@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
67295 static ssize_t show_initsize(struct module_attribute *mattr,
67296 struct module_kobject *mk, char *buffer)
67297 {
67298- return sprintf(buffer, "%u\n", mk->mod->init_size);
67299+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
67300 }
67301
67302 static struct module_attribute modinfo_initsize =
67303@@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
67304 */
67305 #ifdef CONFIG_SYSFS
67306
67307-#ifdef CONFIG_KALLSYMS
67308+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67309 static inline bool sect_empty(const Elf_Shdr *sect)
67310 {
67311 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
67312@@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
67313
67314 static void unset_module_core_ro_nx(struct module *mod)
67315 {
67316- set_page_attributes(mod->module_core + mod->core_text_size,
67317- mod->module_core + mod->core_size,
67318+ set_page_attributes(mod->module_core_rw,
67319+ mod->module_core_rw + mod->core_size_rw,
67320 set_memory_x);
67321- set_page_attributes(mod->module_core,
67322- mod->module_core + mod->core_ro_size,
67323+ set_page_attributes(mod->module_core_rx,
67324+ mod->module_core_rx + mod->core_size_rx,
67325 set_memory_rw);
67326 }
67327
67328 static void unset_module_init_ro_nx(struct module *mod)
67329 {
67330- set_page_attributes(mod->module_init + mod->init_text_size,
67331- mod->module_init + mod->init_size,
67332+ set_page_attributes(mod->module_init_rw,
67333+ mod->module_init_rw + mod->init_size_rw,
67334 set_memory_x);
67335- set_page_attributes(mod->module_init,
67336- mod->module_init + mod->init_ro_size,
67337+ set_page_attributes(mod->module_init_rx,
67338+ mod->module_init_rx + mod->init_size_rx,
67339 set_memory_rw);
67340 }
67341
67342@@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
67343
67344 mutex_lock(&module_mutex);
67345 list_for_each_entry_rcu(mod, &modules, list) {
67346- if ((mod->module_core) && (mod->core_text_size)) {
67347- set_page_attributes(mod->module_core,
67348- mod->module_core + mod->core_text_size,
67349+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
67350+ set_page_attributes(mod->module_core_rx,
67351+ mod->module_core_rx + mod->core_size_rx,
67352 set_memory_rw);
67353 }
67354- if ((mod->module_init) && (mod->init_text_size)) {
67355- set_page_attributes(mod->module_init,
67356- mod->module_init + mod->init_text_size,
67357+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
67358+ set_page_attributes(mod->module_init_rx,
67359+ mod->module_init_rx + mod->init_size_rx,
67360 set_memory_rw);
67361 }
67362 }
67363@@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
67364
67365 mutex_lock(&module_mutex);
67366 list_for_each_entry_rcu(mod, &modules, list) {
67367- if ((mod->module_core) && (mod->core_text_size)) {
67368- set_page_attributes(mod->module_core,
67369- mod->module_core + mod->core_text_size,
67370+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
67371+ set_page_attributes(mod->module_core_rx,
67372+ mod->module_core_rx + mod->core_size_rx,
67373 set_memory_ro);
67374 }
67375- if ((mod->module_init) && (mod->init_text_size)) {
67376- set_page_attributes(mod->module_init,
67377- mod->module_init + mod->init_text_size,
67378+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
67379+ set_page_attributes(mod->module_init_rx,
67380+ mod->module_init_rx + mod->init_size_rx,
67381 set_memory_ro);
67382 }
67383 }
67384@@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
67385
67386 /* This may be NULL, but that's OK */
67387 unset_module_init_ro_nx(mod);
67388- module_free(mod, mod->module_init);
67389+ module_free(mod, mod->module_init_rw);
67390+ module_free_exec(mod, mod->module_init_rx);
67391 kfree(mod->args);
67392 percpu_modfree(mod);
67393
67394 /* Free lock-classes: */
67395- lockdep_free_key_range(mod->module_core, mod->core_size);
67396+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
67397+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
67398
67399 /* Finally, free the core (containing the module structure) */
67400 unset_module_core_ro_nx(mod);
67401- module_free(mod, mod->module_core);
67402+ module_free_exec(mod, mod->module_core_rx);
67403+ module_free(mod, mod->module_core_rw);
67404
67405 #ifdef CONFIG_MPU
67406 update_protections(current->mm);
67407@@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67408 int ret = 0;
67409 const struct kernel_symbol *ksym;
67410
67411+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67412+ int is_fs_load = 0;
67413+ int register_filesystem_found = 0;
67414+ char *p;
67415+
67416+ p = strstr(mod->args, "grsec_modharden_fs");
67417+ if (p) {
67418+ char *endptr = p + strlen("grsec_modharden_fs");
67419+ /* copy \0 as well */
67420+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67421+ is_fs_load = 1;
67422+ }
67423+#endif
67424+
67425 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67426 const char *name = info->strtab + sym[i].st_name;
67427
67428+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67429+ /* it's a real shame this will never get ripped and copied
67430+ upstream! ;(
67431+ */
67432+ if (is_fs_load && !strcmp(name, "register_filesystem"))
67433+ register_filesystem_found = 1;
67434+#endif
67435+
67436 switch (sym[i].st_shndx) {
67437 case SHN_COMMON:
67438 /* We compiled with -fno-common. These are not
67439@@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67440 ksym = resolve_symbol_wait(mod, info, name);
67441 /* Ok if resolved. */
67442 if (ksym && !IS_ERR(ksym)) {
67443+ pax_open_kernel();
67444 sym[i].st_value = ksym->value;
67445+ pax_close_kernel();
67446 break;
67447 }
67448
67449@@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67450 secbase = (unsigned long)mod_percpu(mod);
67451 else
67452 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67453+ pax_open_kernel();
67454 sym[i].st_value += secbase;
67455+ pax_close_kernel();
67456 break;
67457 }
67458 }
67459
67460+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67461+ if (is_fs_load && !register_filesystem_found) {
67462+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67463+ ret = -EPERM;
67464+ }
67465+#endif
67466+
67467 return ret;
67468 }
67469
67470@@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67471 || s->sh_entsize != ~0UL
67472 || strstarts(sname, ".init"))
67473 continue;
67474- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67475+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67476+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67477+ else
67478+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67479 pr_debug("\t%s\n", sname);
67480 }
67481- switch (m) {
67482- case 0: /* executable */
67483- mod->core_size = debug_align(mod->core_size);
67484- mod->core_text_size = mod->core_size;
67485- break;
67486- case 1: /* RO: text and ro-data */
67487- mod->core_size = debug_align(mod->core_size);
67488- mod->core_ro_size = mod->core_size;
67489- break;
67490- case 3: /* whole core */
67491- mod->core_size = debug_align(mod->core_size);
67492- break;
67493- }
67494 }
67495
67496 pr_debug("Init section allocation order:\n");
67497@@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67498 || s->sh_entsize != ~0UL
67499 || !strstarts(sname, ".init"))
67500 continue;
67501- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67502- | INIT_OFFSET_MASK);
67503+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67504+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67505+ else
67506+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67507+ s->sh_entsize |= INIT_OFFSET_MASK;
67508 pr_debug("\t%s\n", sname);
67509 }
67510- switch (m) {
67511- case 0: /* executable */
67512- mod->init_size = debug_align(mod->init_size);
67513- mod->init_text_size = mod->init_size;
67514- break;
67515- case 1: /* RO: text and ro-data */
67516- mod->init_size = debug_align(mod->init_size);
67517- mod->init_ro_size = mod->init_size;
67518- break;
67519- case 3: /* whole init */
67520- mod->init_size = debug_align(mod->init_size);
67521- break;
67522- }
67523 }
67524 }
67525
67526@@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67527
67528 /* Put symbol section at end of init part of module. */
67529 symsect->sh_flags |= SHF_ALLOC;
67530- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67531+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67532 info->index.sym) | INIT_OFFSET_MASK;
67533 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67534
67535@@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67536 }
67537
67538 /* Append room for core symbols at end of core part. */
67539- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67540- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67541- mod->core_size += strtab_size;
67542+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67543+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67544+ mod->core_size_rx += strtab_size;
67545
67546 /* Put string table section at end of init part of module. */
67547 strsect->sh_flags |= SHF_ALLOC;
67548- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67549+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67550 info->index.str) | INIT_OFFSET_MASK;
67551 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67552 }
67553@@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67554 /* Make sure we get permanent strtab: don't use info->strtab. */
67555 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67556
67557+ pax_open_kernel();
67558+
67559 /* Set types up while we still have access to sections. */
67560 for (i = 0; i < mod->num_symtab; i++)
67561 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67562
67563- mod->core_symtab = dst = mod->module_core + info->symoffs;
67564- mod->core_strtab = s = mod->module_core + info->stroffs;
67565+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67566+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67567 src = mod->symtab;
67568 *dst = *src;
67569 *s++ = 0;
67570@@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67571 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67572 }
67573 mod->core_num_syms = ndst;
67574+
67575+ pax_close_kernel();
67576 }
67577 #else
67578 static inline void layout_symtab(struct module *mod, struct load_info *info)
67579@@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
67580 return size == 0 ? NULL : vmalloc_exec(size);
67581 }
67582
67583-static void *module_alloc_update_bounds(unsigned long size)
67584+static void *module_alloc_update_bounds_rw(unsigned long size)
67585 {
67586 void *ret = module_alloc(size);
67587
67588 if (ret) {
67589 mutex_lock(&module_mutex);
67590 /* Update module bounds. */
67591- if ((unsigned long)ret < module_addr_min)
67592- module_addr_min = (unsigned long)ret;
67593- if ((unsigned long)ret + size > module_addr_max)
67594- module_addr_max = (unsigned long)ret + size;
67595+ if ((unsigned long)ret < module_addr_min_rw)
67596+ module_addr_min_rw = (unsigned long)ret;
67597+ if ((unsigned long)ret + size > module_addr_max_rw)
67598+ module_addr_max_rw = (unsigned long)ret + size;
67599+ mutex_unlock(&module_mutex);
67600+ }
67601+ return ret;
67602+}
67603+
67604+static void *module_alloc_update_bounds_rx(unsigned long size)
67605+{
67606+ void *ret = module_alloc_exec(size);
67607+
67608+ if (ret) {
67609+ mutex_lock(&module_mutex);
67610+ /* Update module bounds. */
67611+ if ((unsigned long)ret < module_addr_min_rx)
67612+ module_addr_min_rx = (unsigned long)ret;
67613+ if ((unsigned long)ret + size > module_addr_max_rx)
67614+ module_addr_max_rx = (unsigned long)ret + size;
67615 mutex_unlock(&module_mutex);
67616 }
67617 return ret;
67618@@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
67619 static int check_modinfo(struct module *mod, struct load_info *info)
67620 {
67621 const char *modmagic = get_modinfo(info, "vermagic");
67622+ const char *license = get_modinfo(info, "license");
67623 int err;
67624
67625+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67626+ if (!license || !license_is_gpl_compatible(license))
67627+ return -ENOEXEC;
67628+#endif
67629+
67630 /* This is allowed: modprobe --force will invalidate it. */
67631 if (!modmagic) {
67632 err = try_to_force_load(mod, "bad vermagic");
67633@@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67634 }
67635
67636 /* Set up license info based on the info section */
67637- set_license(mod, get_modinfo(info, "license"));
67638+ set_license(mod, license);
67639
67640 return 0;
67641 }
67642@@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
67643 void *ptr;
67644
67645 /* Do the allocs. */
67646- ptr = module_alloc_update_bounds(mod->core_size);
67647+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67648 /*
67649 * The pointer to this block is stored in the module structure
67650 * which is inside the block. Just mark it as not being a
67651@@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
67652 if (!ptr)
67653 return -ENOMEM;
67654
67655- memset(ptr, 0, mod->core_size);
67656- mod->module_core = ptr;
67657+ memset(ptr, 0, mod->core_size_rw);
67658+ mod->module_core_rw = ptr;
67659
67660- ptr = module_alloc_update_bounds(mod->init_size);
67661+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67662 /*
67663 * The pointer to this block is stored in the module structure
67664 * which is inside the block. This block doesn't need to be
67665 * scanned as it contains data and code that will be freed
67666 * after the module is initialized.
67667 */
67668- kmemleak_ignore(ptr);
67669- if (!ptr && mod->init_size) {
67670- module_free(mod, mod->module_core);
67671+ kmemleak_not_leak(ptr);
67672+ if (!ptr && mod->init_size_rw) {
67673+ module_free(mod, mod->module_core_rw);
67674 return -ENOMEM;
67675 }
67676- memset(ptr, 0, mod->init_size);
67677- mod->module_init = ptr;
67678+ memset(ptr, 0, mod->init_size_rw);
67679+ mod->module_init_rw = ptr;
67680+
67681+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67682+ kmemleak_not_leak(ptr);
67683+ if (!ptr) {
67684+ module_free(mod, mod->module_init_rw);
67685+ module_free(mod, mod->module_core_rw);
67686+ return -ENOMEM;
67687+ }
67688+
67689+ pax_open_kernel();
67690+ memset(ptr, 0, mod->core_size_rx);
67691+ pax_close_kernel();
67692+ mod->module_core_rx = ptr;
67693+
67694+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67695+ kmemleak_not_leak(ptr);
67696+ if (!ptr && mod->init_size_rx) {
67697+ module_free_exec(mod, mod->module_core_rx);
67698+ module_free(mod, mod->module_init_rw);
67699+ module_free(mod, mod->module_core_rw);
67700+ return -ENOMEM;
67701+ }
67702+
67703+ pax_open_kernel();
67704+ memset(ptr, 0, mod->init_size_rx);
67705+ pax_close_kernel();
67706+ mod->module_init_rx = ptr;
67707
67708 /* Transfer each section which specifies SHF_ALLOC */
67709 pr_debug("final section addresses:\n");
67710@@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
67711 if (!(shdr->sh_flags & SHF_ALLOC))
67712 continue;
67713
67714- if (shdr->sh_entsize & INIT_OFFSET_MASK)
67715- dest = mod->module_init
67716- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67717- else
67718- dest = mod->module_core + shdr->sh_entsize;
67719+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67720+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67721+ dest = mod->module_init_rw
67722+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67723+ else
67724+ dest = mod->module_init_rx
67725+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67726+ } else {
67727+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67728+ dest = mod->module_core_rw + shdr->sh_entsize;
67729+ else
67730+ dest = mod->module_core_rx + shdr->sh_entsize;
67731+ }
67732+
67733+ if (shdr->sh_type != SHT_NOBITS) {
67734+
67735+#ifdef CONFIG_PAX_KERNEXEC
67736+#ifdef CONFIG_X86_64
67737+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67738+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67739+#endif
67740+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67741+ pax_open_kernel();
67742+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67743+ pax_close_kernel();
67744+ } else
67745+#endif
67746
67747- if (shdr->sh_type != SHT_NOBITS)
67748 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67749+ }
67750 /* Update sh_addr to point to copy in image. */
67751- shdr->sh_addr = (unsigned long)dest;
67752+
67753+#ifdef CONFIG_PAX_KERNEXEC
67754+ if (shdr->sh_flags & SHF_EXECINSTR)
67755+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
67756+ else
67757+#endif
67758+
67759+ shdr->sh_addr = (unsigned long)dest;
67760 pr_debug("\t0x%lx %s\n",
67761 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67762 }
67763@@ -2759,12 +2859,12 @@ static void flush_module_icache(const struct module *mod)
67764 * Do it before processing of module parameters, so the module
67765 * can provide parameter accessor functions of its own.
67766 */
67767- if (mod->module_init)
67768- flush_icache_range((unsigned long)mod->module_init,
67769- (unsigned long)mod->module_init
67770- + mod->init_size);
67771- flush_icache_range((unsigned long)mod->module_core,
67772- (unsigned long)mod->module_core + mod->core_size);
67773+ if (mod->module_init_rx)
67774+ flush_icache_range((unsigned long)mod->module_init_rx,
67775+ (unsigned long)mod->module_init_rx
67776+ + mod->init_size_rx);
67777+ flush_icache_range((unsigned long)mod->module_core_rx,
67778+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
67779
67780 set_fs(old_fs);
67781 }
67782@@ -2834,8 +2934,10 @@ out:
67783 static void module_deallocate(struct module *mod, struct load_info *info)
67784 {
67785 percpu_modfree(mod);
67786- module_free(mod, mod->module_init);
67787- module_free(mod, mod->module_core);
67788+ module_free_exec(mod, mod->module_init_rx);
67789+ module_free_exec(mod, mod->module_core_rx);
67790+ module_free(mod, mod->module_init_rw);
67791+ module_free(mod, mod->module_core_rw);
67792 }
67793
67794 int __weak module_finalize(const Elf_Ehdr *hdr,
67795@@ -2848,7 +2950,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
67796 static int post_relocation(struct module *mod, const struct load_info *info)
67797 {
67798 /* Sort exception table now relocations are done. */
67799+ pax_open_kernel();
67800 sort_extable(mod->extable, mod->extable + mod->num_exentries);
67801+ pax_close_kernel();
67802
67803 /* Copy relocated percpu area over. */
67804 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
67805@@ -2899,9 +3003,38 @@ static struct module *load_module(void __user *umod,
67806 if (err)
67807 goto free_unload;
67808
67809+ /* Now copy in args */
67810+ mod->args = strndup_user(uargs, ~0UL >> 1);
67811+ if (IS_ERR(mod->args)) {
67812+ err = PTR_ERR(mod->args);
67813+ goto free_unload;
67814+ }
67815+
67816 /* Set up MODINFO_ATTR fields */
67817 setup_modinfo(mod, &info);
67818
67819+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67820+ {
67821+ char *p, *p2;
67822+
67823+ if (strstr(mod->args, "grsec_modharden_netdev")) {
67824+ 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);
67825+ err = -EPERM;
67826+ goto free_modinfo;
67827+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67828+ p += strlen("grsec_modharden_normal");
67829+ p2 = strstr(p, "_");
67830+ if (p2) {
67831+ *p2 = '\0';
67832+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67833+ *p2 = '_';
67834+ }
67835+ err = -EPERM;
67836+ goto free_modinfo;
67837+ }
67838+ }
67839+#endif
67840+
67841 /* Fix up syms, so that st_value is a pointer to location. */
67842 err = simplify_symbols(mod, &info);
67843 if (err < 0)
67844@@ -2917,13 +3050,6 @@ static struct module *load_module(void __user *umod,
67845
67846 flush_module_icache(mod);
67847
67848- /* Now copy in args */
67849- mod->args = strndup_user(uargs, ~0UL >> 1);
67850- if (IS_ERR(mod->args)) {
67851- err = PTR_ERR(mod->args);
67852- goto free_arch_cleanup;
67853- }
67854-
67855 /* Mark state as coming so strong_try_module_get() ignores us. */
67856 mod->state = MODULE_STATE_COMING;
67857
67858@@ -2981,11 +3107,10 @@ static struct module *load_module(void __user *umod,
67859 unlock:
67860 mutex_unlock(&module_mutex);
67861 synchronize_sched();
67862- kfree(mod->args);
67863- free_arch_cleanup:
67864 module_arch_cleanup(mod);
67865 free_modinfo:
67866 free_modinfo(mod);
67867+ kfree(mod->args);
67868 free_unload:
67869 module_unload_free(mod);
67870 free_module:
67871@@ -3026,16 +3151,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67872 MODULE_STATE_COMING, mod);
67873
67874 /* Set RO and NX regions for core */
67875- set_section_ro_nx(mod->module_core,
67876- mod->core_text_size,
67877- mod->core_ro_size,
67878- mod->core_size);
67879+ set_section_ro_nx(mod->module_core_rx,
67880+ mod->core_size_rx,
67881+ mod->core_size_rx,
67882+ mod->core_size_rx);
67883
67884 /* Set RO and NX regions for init */
67885- set_section_ro_nx(mod->module_init,
67886- mod->init_text_size,
67887- mod->init_ro_size,
67888- mod->init_size);
67889+ set_section_ro_nx(mod->module_init_rx,
67890+ mod->init_size_rx,
67891+ mod->init_size_rx,
67892+ mod->init_size_rx);
67893
67894 do_mod_ctors(mod);
67895 /* Start the module */
67896@@ -3081,11 +3206,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67897 mod->strtab = mod->core_strtab;
67898 #endif
67899 unset_module_init_ro_nx(mod);
67900- module_free(mod, mod->module_init);
67901- mod->module_init = NULL;
67902- mod->init_size = 0;
67903- mod->init_ro_size = 0;
67904- mod->init_text_size = 0;
67905+ module_free(mod, mod->module_init_rw);
67906+ module_free_exec(mod, mod->module_init_rx);
67907+ mod->module_init_rw = NULL;
67908+ mod->module_init_rx = NULL;
67909+ mod->init_size_rw = 0;
67910+ mod->init_size_rx = 0;
67911 mutex_unlock(&module_mutex);
67912
67913 return 0;
67914@@ -3116,10 +3242,16 @@ static const char *get_ksymbol(struct module *mod,
67915 unsigned long nextval;
67916
67917 /* At worse, next value is at end of module */
67918- if (within_module_init(addr, mod))
67919- nextval = (unsigned long)mod->module_init+mod->init_text_size;
67920+ if (within_module_init_rx(addr, mod))
67921+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67922+ else if (within_module_init_rw(addr, mod))
67923+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67924+ else if (within_module_core_rx(addr, mod))
67925+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67926+ else if (within_module_core_rw(addr, mod))
67927+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67928 else
67929- nextval = (unsigned long)mod->module_core+mod->core_text_size;
67930+ return NULL;
67931
67932 /* Scan for closest preceding symbol, and next symbol. (ELF
67933 starts real symbols at 1). */
67934@@ -3354,7 +3486,7 @@ static int m_show(struct seq_file *m, void *p)
67935 char buf[8];
67936
67937 seq_printf(m, "%s %u",
67938- mod->name, mod->init_size + mod->core_size);
67939+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67940 print_unload_info(m, mod);
67941
67942 /* Informative for users. */
67943@@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
67944 mod->state == MODULE_STATE_COMING ? "Loading":
67945 "Live");
67946 /* Used by oprofile and other similar tools. */
67947- seq_printf(m, " 0x%pK", mod->module_core);
67948+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67949
67950 /* Taints info */
67951 if (mod->taints)
67952@@ -3399,7 +3531,17 @@ static const struct file_operations proc_modules_operations = {
67953
67954 static int __init proc_modules_init(void)
67955 {
67956+#ifndef CONFIG_GRKERNSEC_HIDESYM
67957+#ifdef CONFIG_GRKERNSEC_PROC_USER
67958+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67959+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67960+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67961+#else
67962 proc_create("modules", 0, NULL, &proc_modules_operations);
67963+#endif
67964+#else
67965+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67966+#endif
67967 return 0;
67968 }
67969 module_init(proc_modules_init);
67970@@ -3458,12 +3600,12 @@ struct module *__module_address(unsigned long addr)
67971 {
67972 struct module *mod;
67973
67974- if (addr < module_addr_min || addr > module_addr_max)
67975+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67976+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
67977 return NULL;
67978
67979 list_for_each_entry_rcu(mod, &modules, list)
67980- if (within_module_core(addr, mod)
67981- || within_module_init(addr, mod))
67982+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
67983 return mod;
67984 return NULL;
67985 }
67986@@ -3497,11 +3639,20 @@ bool is_module_text_address(unsigned long addr)
67987 */
67988 struct module *__module_text_address(unsigned long addr)
67989 {
67990- struct module *mod = __module_address(addr);
67991+ struct module *mod;
67992+
67993+#ifdef CONFIG_X86_32
67994+ addr = ktla_ktva(addr);
67995+#endif
67996+
67997+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67998+ return NULL;
67999+
68000+ mod = __module_address(addr);
68001+
68002 if (mod) {
68003 /* Make sure it's within the text section. */
68004- if (!within(addr, mod->module_init, mod->init_text_size)
68005- && !within(addr, mod->module_core, mod->core_text_size))
68006+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68007 mod = NULL;
68008 }
68009 return mod;
68010diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68011index 7e3443f..b2a1e6b 100644
68012--- a/kernel/mutex-debug.c
68013+++ b/kernel/mutex-debug.c
68014@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68015 }
68016
68017 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68018- struct thread_info *ti)
68019+ struct task_struct *task)
68020 {
68021 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68022
68023 /* Mark the current thread as blocked on the lock: */
68024- ti->task->blocked_on = waiter;
68025+ task->blocked_on = waiter;
68026 }
68027
68028 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68029- struct thread_info *ti)
68030+ struct task_struct *task)
68031 {
68032 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68033- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68034- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68035- ti->task->blocked_on = NULL;
68036+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
68037+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68038+ task->blocked_on = NULL;
68039
68040 list_del_init(&waiter->list);
68041 waiter->task = NULL;
68042diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68043index 0799fd3..d06ae3b 100644
68044--- a/kernel/mutex-debug.h
68045+++ b/kernel/mutex-debug.h
68046@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68047 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68048 extern void debug_mutex_add_waiter(struct mutex *lock,
68049 struct mutex_waiter *waiter,
68050- struct thread_info *ti);
68051+ struct task_struct *task);
68052 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68053- struct thread_info *ti);
68054+ struct task_struct *task);
68055 extern void debug_mutex_unlock(struct mutex *lock);
68056 extern void debug_mutex_init(struct mutex *lock, const char *name,
68057 struct lock_class_key *key);
68058diff --git a/kernel/mutex.c b/kernel/mutex.c
68059index a307cc9..27fd2e9 100644
68060--- a/kernel/mutex.c
68061+++ b/kernel/mutex.c
68062@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68063 spin_lock_mutex(&lock->wait_lock, flags);
68064
68065 debug_mutex_lock_common(lock, &waiter);
68066- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68067+ debug_mutex_add_waiter(lock, &waiter, task);
68068
68069 /* add waiting tasks to the end of the waitqueue (FIFO): */
68070 list_add_tail(&waiter.list, &lock->wait_list);
68071@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68072 * TASK_UNINTERRUPTIBLE case.)
68073 */
68074 if (unlikely(signal_pending_state(state, task))) {
68075- mutex_remove_waiter(lock, &waiter,
68076- task_thread_info(task));
68077+ mutex_remove_waiter(lock, &waiter, task);
68078 mutex_release(&lock->dep_map, 1, ip);
68079 spin_unlock_mutex(&lock->wait_lock, flags);
68080
68081@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68082 done:
68083 lock_acquired(&lock->dep_map, ip);
68084 /* got the lock - rejoice! */
68085- mutex_remove_waiter(lock, &waiter, current_thread_info());
68086+ mutex_remove_waiter(lock, &waiter, task);
68087 mutex_set_owner(lock);
68088
68089 /* set it to 0 if there are no waiters left: */
68090diff --git a/kernel/panic.c b/kernel/panic.c
68091index d2a5f4e..5edc1d9 100644
68092--- a/kernel/panic.c
68093+++ b/kernel/panic.c
68094@@ -75,6 +75,14 @@ void panic(const char *fmt, ...)
68095 int state = 0;
68096
68097 /*
68098+ * Disable local interrupts. This will prevent panic_smp_self_stop
68099+ * from deadlocking the first cpu that invokes the panic, since
68100+ * there is nothing to prevent an interrupt handler (that runs
68101+ * after the panic_lock is acquired) from invoking panic again.
68102+ */
68103+ local_irq_disable();
68104+
68105+ /*
68106 * It's possible to come here directly from a panic-assertion and
68107 * not have preempt disabled. Some functions called from here want
68108 * preempt to be disabled. No point enabling it later though...
68109@@ -402,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68110 const char *board;
68111
68112 printk(KERN_WARNING "------------[ cut here ]------------\n");
68113- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68114+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68115 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68116 if (board)
68117 printk(KERN_WARNING "Hardware name: %s\n", board);
68118@@ -457,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68119 */
68120 void __stack_chk_fail(void)
68121 {
68122- panic("stack-protector: Kernel stack is corrupted in: %p\n",
68123+ dump_stack();
68124+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68125 __builtin_return_address(0));
68126 }
68127 EXPORT_SYMBOL(__stack_chk_fail);
68128diff --git a/kernel/pid.c b/kernel/pid.c
68129index e86b291a..e8b0fb5 100644
68130--- a/kernel/pid.c
68131+++ b/kernel/pid.c
68132@@ -33,6 +33,7 @@
68133 #include <linux/rculist.h>
68134 #include <linux/bootmem.h>
68135 #include <linux/hash.h>
68136+#include <linux/security.h>
68137 #include <linux/pid_namespace.h>
68138 #include <linux/init_task.h>
68139 #include <linux/syscalls.h>
68140@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68141
68142 int pid_max = PID_MAX_DEFAULT;
68143
68144-#define RESERVED_PIDS 300
68145+#define RESERVED_PIDS 500
68146
68147 int pid_max_min = RESERVED_PIDS + 1;
68148 int pid_max_max = PID_MAX_LIMIT;
68149@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68150 */
68151 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68152 {
68153+ struct task_struct *task;
68154+
68155 rcu_lockdep_assert(rcu_read_lock_held(),
68156 "find_task_by_pid_ns() needs rcu_read_lock()"
68157 " protection");
68158- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68159+
68160+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68161+
68162+ if (gr_pid_is_chrooted(task))
68163+ return NULL;
68164+
68165+ return task;
68166 }
68167
68168 struct task_struct *find_task_by_vpid(pid_t vnr)
68169@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68170 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68171 }
68172
68173+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68174+{
68175+ rcu_lockdep_assert(rcu_read_lock_held(),
68176+ "find_task_by_pid_ns() needs rcu_read_lock()"
68177+ " protection");
68178+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68179+}
68180+
68181 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68182 {
68183 struct pid *pid;
68184diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68185index 125cb67..a4d1c30 100644
68186--- a/kernel/posix-cpu-timers.c
68187+++ b/kernel/posix-cpu-timers.c
68188@@ -6,6 +6,7 @@
68189 #include <linux/posix-timers.h>
68190 #include <linux/errno.h>
68191 #include <linux/math64.h>
68192+#include <linux/security.h>
68193 #include <asm/uaccess.h>
68194 #include <linux/kernel_stat.h>
68195 #include <trace/events/timer.h>
68196@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68197
68198 static __init int init_posix_cpu_timers(void)
68199 {
68200- struct k_clock process = {
68201+ static struct k_clock process = {
68202 .clock_getres = process_cpu_clock_getres,
68203 .clock_get = process_cpu_clock_get,
68204 .timer_create = process_cpu_timer_create,
68205 .nsleep = process_cpu_nsleep,
68206 .nsleep_restart = process_cpu_nsleep_restart,
68207 };
68208- struct k_clock thread = {
68209+ static struct k_clock thread = {
68210 .clock_getres = thread_cpu_clock_getres,
68211 .clock_get = thread_cpu_clock_get,
68212 .timer_create = thread_cpu_timer_create,
68213diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68214index 69185ae..cc2847a 100644
68215--- a/kernel/posix-timers.c
68216+++ b/kernel/posix-timers.c
68217@@ -43,6 +43,7 @@
68218 #include <linux/idr.h>
68219 #include <linux/posix-clock.h>
68220 #include <linux/posix-timers.h>
68221+#include <linux/grsecurity.h>
68222 #include <linux/syscalls.h>
68223 #include <linux/wait.h>
68224 #include <linux/workqueue.h>
68225@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68226 * which we beg off on and pass to do_sys_settimeofday().
68227 */
68228
68229-static struct k_clock posix_clocks[MAX_CLOCKS];
68230+static struct k_clock *posix_clocks[MAX_CLOCKS];
68231
68232 /*
68233 * These ones are defined below.
68234@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68235 */
68236 static __init int init_posix_timers(void)
68237 {
68238- struct k_clock clock_realtime = {
68239+ static struct k_clock clock_realtime = {
68240 .clock_getres = hrtimer_get_res,
68241 .clock_get = posix_clock_realtime_get,
68242 .clock_set = posix_clock_realtime_set,
68243@@ -239,7 +240,7 @@ 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 = {
68248+ static struct k_clock clock_monotonic = {
68249 .clock_getres = hrtimer_get_res,
68250 .clock_get = posix_ktime_get_ts,
68251 .nsleep = common_nsleep,
68252@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68253 .timer_get = common_timer_get,
68254 .timer_del = common_timer_del,
68255 };
68256- struct k_clock clock_monotonic_raw = {
68257+ static struct k_clock clock_monotonic_raw = {
68258 .clock_getres = hrtimer_get_res,
68259 .clock_get = posix_get_monotonic_raw,
68260 };
68261- struct k_clock clock_realtime_coarse = {
68262+ static struct k_clock clock_realtime_coarse = {
68263 .clock_getres = posix_get_coarse_res,
68264 .clock_get = posix_get_realtime_coarse,
68265 };
68266- struct k_clock clock_monotonic_coarse = {
68267+ static struct k_clock clock_monotonic_coarse = {
68268 .clock_getres = posix_get_coarse_res,
68269 .clock_get = posix_get_monotonic_coarse,
68270 };
68271- struct k_clock clock_boottime = {
68272+ static struct k_clock clock_boottime = {
68273 .clock_getres = hrtimer_get_res,
68274 .clock_get = posix_get_boottime,
68275 .nsleep = common_nsleep,
68276@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
68277 return;
68278 }
68279
68280- posix_clocks[clock_id] = *new_clock;
68281+ posix_clocks[clock_id] = new_clock;
68282 }
68283 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
68284
68285@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
68286 return (id & CLOCKFD_MASK) == CLOCKFD ?
68287 &clock_posix_dynamic : &clock_posix_cpu;
68288
68289- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
68290+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
68291 return NULL;
68292- return &posix_clocks[id];
68293+ return posix_clocks[id];
68294 }
68295
68296 static int common_timer_create(struct k_itimer *new_timer)
68297@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
68298 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
68299 return -EFAULT;
68300
68301+ /* only the CLOCK_REALTIME clock can be set, all other clocks
68302+ have their clock_set fptr set to a nosettime dummy function
68303+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
68304+ call common_clock_set, which calls do_sys_settimeofday, which
68305+ we hook
68306+ */
68307+
68308 return kc->clock_set(which_clock, &new_tp);
68309 }
68310
68311diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
68312index d523593..68197a4 100644
68313--- a/kernel/power/poweroff.c
68314+++ b/kernel/power/poweroff.c
68315@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
68316 .enable_mask = SYSRQ_ENABLE_BOOT,
68317 };
68318
68319-static int pm_sysrq_init(void)
68320+static int __init pm_sysrq_init(void)
68321 {
68322 register_sysrq_key('o', &sysrq_poweroff_op);
68323 return 0;
68324diff --git a/kernel/power/process.c b/kernel/power/process.c
68325index 19db29f..33b52b6 100644
68326--- a/kernel/power/process.c
68327+++ b/kernel/power/process.c
68328@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
68329 u64 elapsed_csecs64;
68330 unsigned int elapsed_csecs;
68331 bool wakeup = false;
68332+ bool timedout = false;
68333
68334 do_gettimeofday(&start);
68335
68336@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
68337
68338 while (true) {
68339 todo = 0;
68340+ if (time_after(jiffies, end_time))
68341+ timedout = true;
68342 read_lock(&tasklist_lock);
68343 do_each_thread(g, p) {
68344 if (p == current || !freeze_task(p))
68345@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
68346 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
68347 * transition can't race with task state testing here.
68348 */
68349- if (!task_is_stopped_or_traced(p) &&
68350- !freezer_should_skip(p))
68351+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
68352 todo++;
68353+ if (timedout) {
68354+ printk(KERN_ERR "Task refusing to freeze:\n");
68355+ sched_show_task(p);
68356+ }
68357+ }
68358 } while_each_thread(g, p);
68359 read_unlock(&tasklist_lock);
68360
68361@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
68362 todo += wq_busy;
68363 }
68364
68365- if (!todo || time_after(jiffies, end_time))
68366+ if (!todo || timedout)
68367 break;
68368
68369 if (pm_wakeup_pending()) {
68370diff --git a/kernel/printk.c b/kernel/printk.c
68371index ac4bc9e..1d2db99 100644
68372--- a/kernel/printk.c
68373+++ b/kernel/printk.c
68374@@ -781,6 +781,11 @@ static int check_syslog_permissions(int type, bool from_file)
68375 if (from_file && type != SYSLOG_ACTION_OPEN)
68376 return 0;
68377
68378+#ifdef CONFIG_GRKERNSEC_DMESG
68379+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
68380+ return -EPERM;
68381+#endif
68382+
68383 if (syslog_action_restricted(type)) {
68384 if (capable(CAP_SYSLOG))
68385 return 0;
68386diff --git a/kernel/profile.c b/kernel/profile.c
68387index 76b8e77..a2930e8 100644
68388--- a/kernel/profile.c
68389+++ b/kernel/profile.c
68390@@ -39,7 +39,7 @@ struct profile_hit {
68391 /* Oprofile timer tick hook */
68392 static int (*timer_hook)(struct pt_regs *) __read_mostly;
68393
68394-static atomic_t *prof_buffer;
68395+static atomic_unchecked_t *prof_buffer;
68396 static unsigned long prof_len, prof_shift;
68397
68398 int prof_on __read_mostly;
68399@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
68400 hits[i].pc = 0;
68401 continue;
68402 }
68403- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68404+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68405 hits[i].hits = hits[i].pc = 0;
68406 }
68407 }
68408@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68409 * Add the current hit(s) and flush the write-queue out
68410 * to the global buffer:
68411 */
68412- atomic_add(nr_hits, &prof_buffer[pc]);
68413+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
68414 for (i = 0; i < NR_PROFILE_HIT; ++i) {
68415- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68416+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68417 hits[i].pc = hits[i].hits = 0;
68418 }
68419 out:
68420@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68421 {
68422 unsigned long pc;
68423 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68424- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68425+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68426 }
68427 #endif /* !CONFIG_SMP */
68428
68429@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68430 return -EFAULT;
68431 buf++; p++; count--; read++;
68432 }
68433- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68434+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68435 if (copy_to_user(buf, (void *)pnt, count))
68436 return -EFAULT;
68437 read += count;
68438@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68439 }
68440 #endif
68441 profile_discard_flip_buffers();
68442- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68443+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68444 return count;
68445 }
68446
68447diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68448index a232bb5..2a65ef9 100644
68449--- a/kernel/ptrace.c
68450+++ b/kernel/ptrace.c
68451@@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68452
68453 if (seize)
68454 flags |= PT_SEIZED;
68455- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68456+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68457 flags |= PT_PTRACE_CAP;
68458 task->ptrace = flags;
68459
68460@@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68461 break;
68462 return -EIO;
68463 }
68464- if (copy_to_user(dst, buf, retval))
68465+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68466 return -EFAULT;
68467 copied += retval;
68468 src += retval;
68469@@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
68470 bool seized = child->ptrace & PT_SEIZED;
68471 int ret = -EIO;
68472 siginfo_t siginfo, *si;
68473- void __user *datavp = (void __user *) data;
68474+ void __user *datavp = (__force void __user *) data;
68475 unsigned long __user *datalp = datavp;
68476 unsigned long flags;
68477
68478@@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68479 goto out;
68480 }
68481
68482+ if (gr_handle_ptrace(child, request)) {
68483+ ret = -EPERM;
68484+ goto out_put_task_struct;
68485+ }
68486+
68487 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68488 ret = ptrace_attach(child, request, addr, data);
68489 /*
68490 * Some architectures need to do book-keeping after
68491 * a ptrace attach.
68492 */
68493- if (!ret)
68494+ if (!ret) {
68495 arch_ptrace_attach(child);
68496+ gr_audit_ptrace(child);
68497+ }
68498 goto out_put_task_struct;
68499 }
68500
68501@@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68502 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68503 if (copied != sizeof(tmp))
68504 return -EIO;
68505- return put_user(tmp, (unsigned long __user *)data);
68506+ return put_user(tmp, (__force unsigned long __user *)data);
68507 }
68508
68509 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68510@@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68511 goto out;
68512 }
68513
68514+ if (gr_handle_ptrace(child, request)) {
68515+ ret = -EPERM;
68516+ goto out_put_task_struct;
68517+ }
68518+
68519 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68520 ret = ptrace_attach(child, request, addr, data);
68521 /*
68522 * Some architectures need to do book-keeping after
68523 * a ptrace attach.
68524 */
68525- if (!ret)
68526+ if (!ret) {
68527 arch_ptrace_attach(child);
68528+ gr_audit_ptrace(child);
68529+ }
68530 goto out_put_task_struct;
68531 }
68532
68533diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68534index 37a5444..eec170a 100644
68535--- a/kernel/rcutiny.c
68536+++ b/kernel/rcutiny.c
68537@@ -46,7 +46,7 @@
68538 struct rcu_ctrlblk;
68539 static void invoke_rcu_callbacks(void);
68540 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68541-static void rcu_process_callbacks(struct softirq_action *unused);
68542+static void rcu_process_callbacks(void);
68543 static void __call_rcu(struct rcu_head *head,
68544 void (*func)(struct rcu_head *rcu),
68545 struct rcu_ctrlblk *rcp);
68546@@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68547 rcu_is_callbacks_kthread()));
68548 }
68549
68550-static void rcu_process_callbacks(struct softirq_action *unused)
68551+static void rcu_process_callbacks(void)
68552 {
68553 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68554 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68555diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68556index fc31a2d..be2ec04 100644
68557--- a/kernel/rcutiny_plugin.h
68558+++ b/kernel/rcutiny_plugin.h
68559@@ -939,7 +939,7 @@ static int rcu_kthread(void *arg)
68560 have_rcu_kthread_work = morework;
68561 local_irq_restore(flags);
68562 if (work)
68563- rcu_process_callbacks(NULL);
68564+ rcu_process_callbacks();
68565 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68566 }
68567
68568diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68569index e66b34a..4b8b626 100644
68570--- a/kernel/rcutorture.c
68571+++ b/kernel/rcutorture.c
68572@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68573 { 0 };
68574 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68575 { 0 };
68576-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68577-static atomic_t n_rcu_torture_alloc;
68578-static atomic_t n_rcu_torture_alloc_fail;
68579-static atomic_t n_rcu_torture_free;
68580-static atomic_t n_rcu_torture_mberror;
68581-static atomic_t n_rcu_torture_error;
68582+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68583+static atomic_unchecked_t n_rcu_torture_alloc;
68584+static atomic_unchecked_t n_rcu_torture_alloc_fail;
68585+static atomic_unchecked_t n_rcu_torture_free;
68586+static atomic_unchecked_t n_rcu_torture_mberror;
68587+static atomic_unchecked_t n_rcu_torture_error;
68588 static long n_rcu_torture_barrier_error;
68589 static long n_rcu_torture_boost_ktrerror;
68590 static long n_rcu_torture_boost_rterror;
68591@@ -265,11 +265,11 @@ rcu_torture_alloc(void)
68592
68593 spin_lock_bh(&rcu_torture_lock);
68594 if (list_empty(&rcu_torture_freelist)) {
68595- atomic_inc(&n_rcu_torture_alloc_fail);
68596+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68597 spin_unlock_bh(&rcu_torture_lock);
68598 return NULL;
68599 }
68600- atomic_inc(&n_rcu_torture_alloc);
68601+ atomic_inc_unchecked(&n_rcu_torture_alloc);
68602 p = rcu_torture_freelist.next;
68603 list_del_init(p);
68604 spin_unlock_bh(&rcu_torture_lock);
68605@@ -282,7 +282,7 @@ rcu_torture_alloc(void)
68606 static void
68607 rcu_torture_free(struct rcu_torture *p)
68608 {
68609- atomic_inc(&n_rcu_torture_free);
68610+ atomic_inc_unchecked(&n_rcu_torture_free);
68611 spin_lock_bh(&rcu_torture_lock);
68612 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68613 spin_unlock_bh(&rcu_torture_lock);
68614@@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *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 rcu_torture_free(rp);
68623@@ -451,7 +451,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68624 i = 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 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68630 rp->rtort_mbtest = 0;
68631 list_del(&rp->rtort_free);
68632@@ -983,7 +983,7 @@ rcu_torture_writer(void *arg)
68633 i = old_rp->rtort_pipe_count;
68634 if (i > RCU_TORTURE_PIPE_LEN)
68635 i = RCU_TORTURE_PIPE_LEN;
68636- atomic_inc(&rcu_torture_wcount[i]);
68637+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68638 old_rp->rtort_pipe_count++;
68639 cur_ops->deferred_free(old_rp);
68640 }
68641@@ -1064,7 +1064,7 @@ static void rcu_torture_timer(unsigned long unused)
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 spin_lock(&rand_lock);
68648 cur_ops->read_delay(&rand);
68649 n_rcu_torture_timers++;
68650@@ -1128,7 +1128,7 @@ rcu_torture_reader(void *arg)
68651 }
68652 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68653 if (p->rtort_mbtest == 0)
68654- atomic_inc(&n_rcu_torture_mberror);
68655+ atomic_inc_unchecked(&n_rcu_torture_mberror);
68656 cur_ops->read_delay(&rand);
68657 preempt_disable();
68658 pipe_count = p->rtort_pipe_count;
68659@@ -1191,10 +1191,10 @@ rcu_torture_printk(char *page)
68660 rcu_torture_current,
68661 rcu_torture_current_version,
68662 list_empty(&rcu_torture_freelist),
68663- atomic_read(&n_rcu_torture_alloc),
68664- atomic_read(&n_rcu_torture_alloc_fail),
68665- atomic_read(&n_rcu_torture_free),
68666- atomic_read(&n_rcu_torture_mberror),
68667+ atomic_read_unchecked(&n_rcu_torture_alloc),
68668+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68669+ atomic_read_unchecked(&n_rcu_torture_free),
68670+ atomic_read_unchecked(&n_rcu_torture_mberror),
68671 n_rcu_torture_boost_ktrerror,
68672 n_rcu_torture_boost_rterror,
68673 n_rcu_torture_boost_failure,
68674@@ -1208,14 +1208,14 @@ rcu_torture_printk(char *page)
68675 n_barrier_attempts,
68676 n_rcu_torture_barrier_error);
68677 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68678- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68679+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68680 n_rcu_torture_barrier_error != 0 ||
68681 n_rcu_torture_boost_ktrerror != 0 ||
68682 n_rcu_torture_boost_rterror != 0 ||
68683 n_rcu_torture_boost_failure != 0 ||
68684 i > 1) {
68685 cnt += sprintf(&page[cnt], "!!! ");
68686- atomic_inc(&n_rcu_torture_error);
68687+ atomic_inc_unchecked(&n_rcu_torture_error);
68688 WARN_ON_ONCE(1);
68689 }
68690 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68691@@ -1229,7 +1229,7 @@ rcu_torture_printk(char *page)
68692 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68693 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68694 cnt += sprintf(&page[cnt], " %d",
68695- atomic_read(&rcu_torture_wcount[i]));
68696+ atomic_read_unchecked(&rcu_torture_wcount[i]));
68697 }
68698 cnt += sprintf(&page[cnt], "\n");
68699 if (cur_ops->stats)
68700@@ -1888,7 +1888,7 @@ rcu_torture_cleanup(void)
68701
68702 if (cur_ops->cleanup)
68703 cur_ops->cleanup();
68704- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68705+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68706 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68707 else if (n_online_successes != n_online_attempts ||
68708 n_offline_successes != n_offline_attempts)
68709@@ -1958,18 +1958,18 @@ rcu_torture_init(void)
68710
68711 rcu_torture_current = NULL;
68712 rcu_torture_current_version = 0;
68713- atomic_set(&n_rcu_torture_alloc, 0);
68714- atomic_set(&n_rcu_torture_alloc_fail, 0);
68715- atomic_set(&n_rcu_torture_free, 0);
68716- atomic_set(&n_rcu_torture_mberror, 0);
68717- atomic_set(&n_rcu_torture_error, 0);
68718+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68719+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68720+ atomic_set_unchecked(&n_rcu_torture_free, 0);
68721+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68722+ atomic_set_unchecked(&n_rcu_torture_error, 0);
68723 n_rcu_torture_barrier_error = 0;
68724 n_rcu_torture_boost_ktrerror = 0;
68725 n_rcu_torture_boost_rterror = 0;
68726 n_rcu_torture_boost_failure = 0;
68727 n_rcu_torture_boosts = 0;
68728 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68729- atomic_set(&rcu_torture_wcount[i], 0);
68730+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68731 for_each_possible_cpu(cpu) {
68732 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68733 per_cpu(rcu_torture_count, cpu)[i] = 0;
68734diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68735index 4b97bba..b92c9d2 100644
68736--- a/kernel/rcutree.c
68737+++ b/kernel/rcutree.c
68738@@ -366,9 +366,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68739 rcu_prepare_for_idle(smp_processor_id());
68740 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68741 smp_mb__before_atomic_inc(); /* See above. */
68742- atomic_inc(&rdtp->dynticks);
68743+ atomic_inc_unchecked(&rdtp->dynticks);
68744 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68745- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68746+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68747
68748 /*
68749 * The idle task is not permitted to enter the idle loop while
68750@@ -457,10 +457,10 @@ void rcu_irq_exit(void)
68751 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68752 {
68753 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68754- atomic_inc(&rdtp->dynticks);
68755+ atomic_inc_unchecked(&rdtp->dynticks);
68756 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68757 smp_mb__after_atomic_inc(); /* See above. */
68758- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68759+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68760 rcu_cleanup_after_idle(smp_processor_id());
68761 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68762 if (!is_idle_task(current)) {
68763@@ -554,14 +554,14 @@ void rcu_nmi_enter(void)
68764 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68765
68766 if (rdtp->dynticks_nmi_nesting == 0 &&
68767- (atomic_read(&rdtp->dynticks) & 0x1))
68768+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68769 return;
68770 rdtp->dynticks_nmi_nesting++;
68771 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68772- atomic_inc(&rdtp->dynticks);
68773+ atomic_inc_unchecked(&rdtp->dynticks);
68774 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68775 smp_mb__after_atomic_inc(); /* See above. */
68776- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68777+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68778 }
68779
68780 /**
68781@@ -580,9 +580,9 @@ void rcu_nmi_exit(void)
68782 return;
68783 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68784 smp_mb__before_atomic_inc(); /* See above. */
68785- atomic_inc(&rdtp->dynticks);
68786+ atomic_inc_unchecked(&rdtp->dynticks);
68787 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68788- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68789+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68790 }
68791
68792 #ifdef CONFIG_PROVE_RCU
68793@@ -598,7 +598,7 @@ int rcu_is_cpu_idle(void)
68794 int ret;
68795
68796 preempt_disable();
68797- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68798+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68799 preempt_enable();
68800 return ret;
68801 }
68802@@ -668,7 +668,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68803 */
68804 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68805 {
68806- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68807+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68808 return (rdp->dynticks_snap & 0x1) == 0;
68809 }
68810
68811@@ -683,7 +683,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68812 unsigned int curr;
68813 unsigned int snap;
68814
68815- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68816+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68817 snap = (unsigned int)rdp->dynticks_snap;
68818
68819 /*
68820@@ -713,10 +713,10 @@ static int jiffies_till_stall_check(void)
68821 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
68822 */
68823 if (till_stall_check < 3) {
68824- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
68825+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
68826 till_stall_check = 3;
68827 } else if (till_stall_check > 300) {
68828- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
68829+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
68830 till_stall_check = 300;
68831 }
68832 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
68833@@ -1824,7 +1824,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68834 /*
68835 * Do RCU core processing for the current CPU.
68836 */
68837-static void rcu_process_callbacks(struct softirq_action *unused)
68838+static void rcu_process_callbacks(void)
68839 {
68840 trace_rcu_utilization("Start RCU core");
68841 __rcu_process_callbacks(&rcu_sched_state,
68842@@ -2042,8 +2042,8 @@ void synchronize_rcu_bh(void)
68843 }
68844 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
68845
68846-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68847-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68848+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68849+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68850
68851 static int synchronize_sched_expedited_cpu_stop(void *data)
68852 {
68853@@ -2104,7 +2104,7 @@ void synchronize_sched_expedited(void)
68854 int firstsnap, s, snap, trycount = 0;
68855
68856 /* Note that atomic_inc_return() implies full memory barrier. */
68857- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68858+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68859 get_online_cpus();
68860 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
68861
68862@@ -2126,7 +2126,7 @@ void synchronize_sched_expedited(void)
68863 }
68864
68865 /* Check to see if someone else did our work for us. */
68866- s = atomic_read(&sync_sched_expedited_done);
68867+ s = atomic_read_unchecked(&sync_sched_expedited_done);
68868 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68869 smp_mb(); /* ensure test happens before caller kfree */
68870 return;
68871@@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
68872 * grace period works for us.
68873 */
68874 get_online_cpus();
68875- snap = atomic_read(&sync_sched_expedited_started);
68876+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
68877 smp_mb(); /* ensure read is before try_stop_cpus(). */
68878 }
68879
68880@@ -2152,12 +2152,12 @@ void synchronize_sched_expedited(void)
68881 * than we did beat us to the punch.
68882 */
68883 do {
68884- s = atomic_read(&sync_sched_expedited_done);
68885+ s = atomic_read_unchecked(&sync_sched_expedited_done);
68886 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68887 smp_mb(); /* ensure test happens before caller kfree */
68888 break;
68889 }
68890- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68891+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68892
68893 put_online_cpus();
68894 }
68895@@ -2421,7 +2421,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
68896 rdp->qlen = 0;
68897 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
68898 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
68899- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
68900+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
68901 rdp->cpu = cpu;
68902 rdp->rsp = rsp;
68903 raw_spin_unlock_irqrestore(&rnp->lock, flags);
68904@@ -2449,8 +2449,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
68905 rdp->n_force_qs_snap = rsp->n_force_qs;
68906 rdp->blimit = blimit;
68907 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
68908- atomic_set(&rdp->dynticks->dynticks,
68909- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
68910+ atomic_set_unchecked(&rdp->dynticks->dynticks,
68911+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
68912 rcu_prepare_for_idle_init(cpu);
68913 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
68914
68915diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68916index 19b61ac..5c60a94 100644
68917--- a/kernel/rcutree.h
68918+++ b/kernel/rcutree.h
68919@@ -83,7 +83,7 @@ struct rcu_dynticks {
68920 long long dynticks_nesting; /* Track irq/process nesting level. */
68921 /* Process level is worth LLONG_MAX/2. */
68922 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68923- atomic_t dynticks; /* Even value for idle, else odd. */
68924+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
68925 #ifdef CONFIG_RCU_FAST_NO_HZ
68926 int dyntick_drain; /* Prepare-for-idle state variable. */
68927 unsigned long dyntick_holdoff;
68928diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68929index 3e48994..d94f03a 100644
68930--- a/kernel/rcutree_plugin.h
68931+++ b/kernel/rcutree_plugin.h
68932@@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
68933
68934 /* Clean up and exit. */
68935 smp_mb(); /* ensure expedited GP seen before counter increment. */
68936- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68937+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68938 unlock_mb_ret:
68939 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68940 mb_ret:
68941diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68942index d4bc16d..c234a5c 100644
68943--- a/kernel/rcutree_trace.c
68944+++ b/kernel/rcutree_trace.c
68945@@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68946 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68947 rdp->qs_pending);
68948 seq_printf(m, " dt=%d/%llx/%d df=%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);
68954@@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68955 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68956 rdp->qs_pending);
68957 seq_printf(m, ",%d,%llx,%d,%lu",
68958- atomic_read(&rdp->dynticks->dynticks),
68959+ atomic_read_unchecked(&rdp->dynticks->dynticks),
68960 rdp->dynticks->dynticks_nesting,
68961 rdp->dynticks->dynticks_nmi_nesting,
68962 rdp->dynticks_fqs);
68963diff --git a/kernel/resource.c b/kernel/resource.c
68964index e1d2b8e..24820bb 100644
68965--- a/kernel/resource.c
68966+++ b/kernel/resource.c
68967@@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68968
68969 static int __init ioresources_init(void)
68970 {
68971+#ifdef CONFIG_GRKERNSEC_PROC_ADD
68972+#ifdef CONFIG_GRKERNSEC_PROC_USER
68973+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68974+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68975+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68976+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68977+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68978+#endif
68979+#else
68980 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68981 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68982+#endif
68983 return 0;
68984 }
68985 __initcall(ioresources_init);
68986diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68987index 98ec494..4241d6d 100644
68988--- a/kernel/rtmutex-tester.c
68989+++ b/kernel/rtmutex-tester.c
68990@@ -20,7 +20,7 @@
68991 #define MAX_RT_TEST_MUTEXES 8
68992
68993 static spinlock_t rttest_lock;
68994-static atomic_t rttest_event;
68995+static atomic_unchecked_t rttest_event;
68996
68997 struct test_thread_data {
68998 int opcode;
68999@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69000
69001 case RTTEST_LOCKCONT:
69002 td->mutexes[td->opdata] = 1;
69003- td->event = atomic_add_return(1, &rttest_event);
69004+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69005 return 0;
69006
69007 case RTTEST_RESET:
69008@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69009 return 0;
69010
69011 case RTTEST_RESETEVENT:
69012- atomic_set(&rttest_event, 0);
69013+ atomic_set_unchecked(&rttest_event, 0);
69014 return 0;
69015
69016 default:
69017@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69018 return ret;
69019
69020 td->mutexes[id] = 1;
69021- td->event = atomic_add_return(1, &rttest_event);
69022+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69023 rt_mutex_lock(&mutexes[id]);
69024- td->event = atomic_add_return(1, &rttest_event);
69025+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69026 td->mutexes[id] = 4;
69027 return 0;
69028
69029@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69030 return ret;
69031
69032 td->mutexes[id] = 1;
69033- td->event = atomic_add_return(1, &rttest_event);
69034+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69035 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69036- td->event = atomic_add_return(1, &rttest_event);
69037+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69038 td->mutexes[id] = ret ? 0 : 4;
69039 return ret ? -EINTR : 0;
69040
69041@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69042 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69043 return ret;
69044
69045- td->event = atomic_add_return(1, &rttest_event);
69046+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69047 rt_mutex_unlock(&mutexes[id]);
69048- td->event = atomic_add_return(1, &rttest_event);
69049+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69050 td->mutexes[id] = 0;
69051 return 0;
69052
69053@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69054 break;
69055
69056 td->mutexes[dat] = 2;
69057- td->event = atomic_add_return(1, &rttest_event);
69058+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69059 break;
69060
69061 default:
69062@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69063 return;
69064
69065 td->mutexes[dat] = 3;
69066- td->event = atomic_add_return(1, &rttest_event);
69067+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69068 break;
69069
69070 case RTTEST_LOCKNOWAIT:
69071@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69072 return;
69073
69074 td->mutexes[dat] = 1;
69075- td->event = atomic_add_return(1, &rttest_event);
69076+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69077 return;
69078
69079 default:
69080diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69081index 0984a21..939f183 100644
69082--- a/kernel/sched/auto_group.c
69083+++ b/kernel/sched/auto_group.c
69084@@ -11,7 +11,7 @@
69085
69086 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69087 static struct autogroup autogroup_default;
69088-static atomic_t autogroup_seq_nr;
69089+static atomic_unchecked_t autogroup_seq_nr;
69090
69091 void __init autogroup_init(struct task_struct *init_task)
69092 {
69093@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69094
69095 kref_init(&ag->kref);
69096 init_rwsem(&ag->lock);
69097- ag->id = atomic_inc_return(&autogroup_seq_nr);
69098+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69099 ag->tg = tg;
69100 #ifdef CONFIG_RT_GROUP_SCHED
69101 /*
69102diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69103index 468bdd4..b941572 100644
69104--- a/kernel/sched/core.c
69105+++ b/kernel/sched/core.c
69106@@ -4097,6 +4097,8 @@ int can_nice(const struct task_struct *p, const int nice)
69107 /* convert nice value [19,-20] to rlimit style value [1,40] */
69108 int nice_rlim = 20 - nice;
69109
69110+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69111+
69112 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69113 capable(CAP_SYS_NICE));
69114 }
69115@@ -4130,7 +4132,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69116 if (nice > 19)
69117 nice = 19;
69118
69119- if (increment < 0 && !can_nice(current, nice))
69120+ if (increment < 0 && (!can_nice(current, nice) ||
69121+ gr_handle_chroot_nice()))
69122 return -EPERM;
69123
69124 retval = security_task_setnice(current, nice);
69125@@ -4284,6 +4287,7 @@ recheck:
69126 unsigned long rlim_rtprio =
69127 task_rlimit(p, RLIMIT_RTPRIO);
69128
69129+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69130 /* can't set/change the rt policy */
69131 if (policy != p->policy && !rlim_rtprio)
69132 return -EPERM;
69133diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69134index c099cc6..06aec4f 100644
69135--- a/kernel/sched/fair.c
69136+++ b/kernel/sched/fair.c
69137@@ -4846,7 +4846,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69138 * run_rebalance_domains is triggered when needed from the scheduler tick.
69139 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69140 */
69141-static void run_rebalance_domains(struct softirq_action *h)
69142+static void run_rebalance_domains(void)
69143 {
69144 int this_cpu = smp_processor_id();
69145 struct rq *this_rq = cpu_rq(this_cpu);
69146diff --git a/kernel/signal.c b/kernel/signal.c
69147index 6771027..763e51e 100644
69148--- a/kernel/signal.c
69149+++ b/kernel/signal.c
69150@@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69151
69152 int print_fatal_signals __read_mostly;
69153
69154-static void __user *sig_handler(struct task_struct *t, int sig)
69155+static __sighandler_t sig_handler(struct task_struct *t, int sig)
69156 {
69157 return t->sighand->action[sig - 1].sa.sa_handler;
69158 }
69159
69160-static int sig_handler_ignored(void __user *handler, int sig)
69161+static int sig_handler_ignored(__sighandler_t handler, int sig)
69162 {
69163 /* Is it explicitly or implicitly ignored? */
69164 return handler == SIG_IGN ||
69165@@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69166
69167 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69168 {
69169- void __user *handler;
69170+ __sighandler_t handler;
69171
69172 handler = sig_handler(t, sig);
69173
69174@@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69175 atomic_inc(&user->sigpending);
69176 rcu_read_unlock();
69177
69178+ if (!override_rlimit)
69179+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69180+
69181 if (override_rlimit ||
69182 atomic_read(&user->sigpending) <=
69183 task_rlimit(t, RLIMIT_SIGPENDING)) {
69184@@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69185
69186 int unhandled_signal(struct task_struct *tsk, int sig)
69187 {
69188- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69189+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69190 if (is_global_init(tsk))
69191 return 1;
69192 if (handler != SIG_IGN && handler != SIG_DFL)
69193@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69194 }
69195 }
69196
69197+ /* allow glibc communication via tgkill to other threads in our
69198+ thread group */
69199+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69200+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69201+ && gr_handle_signal(t, sig))
69202+ return -EPERM;
69203+
69204 return security_task_kill(t, info, sig, 0);
69205 }
69206
69207@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69208 return send_signal(sig, info, p, 1);
69209 }
69210
69211-static int
69212+int
69213 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69214 {
69215 return send_signal(sig, info, t, 0);
69216@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69217 unsigned long int flags;
69218 int ret, blocked, ignored;
69219 struct k_sigaction *action;
69220+ int is_unhandled = 0;
69221
69222 spin_lock_irqsave(&t->sighand->siglock, flags);
69223 action = &t->sighand->action[sig-1];
69224@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69225 }
69226 if (action->sa.sa_handler == SIG_DFL)
69227 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69228+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69229+ is_unhandled = 1;
69230 ret = specific_send_sig_info(sig, info, t);
69231 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69232
69233+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
69234+ normal operation */
69235+ if (is_unhandled) {
69236+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
69237+ gr_handle_crash(t, sig);
69238+ }
69239+
69240 return ret;
69241 }
69242
69243@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69244 ret = check_kill_permission(sig, info, p);
69245 rcu_read_unlock();
69246
69247- if (!ret && sig)
69248+ if (!ret && sig) {
69249 ret = do_send_sig_info(sig, info, p, true);
69250+ if (!ret)
69251+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
69252+ }
69253
69254 return ret;
69255 }
69256@@ -2858,7 +2881,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
69257 int error = -ESRCH;
69258
69259 rcu_read_lock();
69260- p = find_task_by_vpid(pid);
69261+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69262+ /* allow glibc communication via tgkill to other threads in our
69263+ thread group */
69264+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
69265+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
69266+ p = find_task_by_vpid_unrestricted(pid);
69267+ else
69268+#endif
69269+ p = find_task_by_vpid(pid);
69270 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
69271 error = check_kill_permission(sig, info, p);
69272 /*
69273diff --git a/kernel/smp.c b/kernel/smp.c
69274index d0ae5b2..b87c5a8 100644
69275--- a/kernel/smp.c
69276+++ b/kernel/smp.c
69277@@ -582,22 +582,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
69278 }
69279 EXPORT_SYMBOL(smp_call_function);
69280
69281-void ipi_call_lock(void)
69282+void ipi_call_lock(void) __acquires(call_function.lock)
69283 {
69284 raw_spin_lock(&call_function.lock);
69285 }
69286
69287-void ipi_call_unlock(void)
69288+void ipi_call_unlock(void) __releases(call_function.lock)
69289 {
69290 raw_spin_unlock(&call_function.lock);
69291 }
69292
69293-void ipi_call_lock_irq(void)
69294+void ipi_call_lock_irq(void) __acquires(call_function.lock)
69295 {
69296 raw_spin_lock_irq(&call_function.lock);
69297 }
69298
69299-void ipi_call_unlock_irq(void)
69300+void ipi_call_unlock_irq(void) __releases(call_function.lock)
69301 {
69302 raw_spin_unlock_irq(&call_function.lock);
69303 }
69304diff --git a/kernel/softirq.c b/kernel/softirq.c
69305index 671f959..91c51cb 100644
69306--- a/kernel/softirq.c
69307+++ b/kernel/softirq.c
69308@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
69309
69310 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
69311
69312-char *softirq_to_name[NR_SOFTIRQS] = {
69313+const char * const softirq_to_name[NR_SOFTIRQS] = {
69314 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
69315 "TASKLET", "SCHED", "HRTIMER", "RCU"
69316 };
69317@@ -235,7 +235,7 @@ restart:
69318 kstat_incr_softirqs_this_cpu(vec_nr);
69319
69320 trace_softirq_entry(vec_nr);
69321- h->action(h);
69322+ h->action();
69323 trace_softirq_exit(vec_nr);
69324 if (unlikely(prev_count != preempt_count())) {
69325 printk(KERN_ERR "huh, entered softirq %u %s %p"
69326@@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
69327 or_softirq_pending(1UL << nr);
69328 }
69329
69330-void open_softirq(int nr, void (*action)(struct softirq_action *))
69331+void open_softirq(int nr, void (*action)(void))
69332 {
69333- softirq_vec[nr].action = action;
69334+ pax_open_kernel();
69335+ *(void **)&softirq_vec[nr].action = action;
69336+ pax_close_kernel();
69337 }
69338
69339 /*
69340@@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
69341
69342 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
69343
69344-static void tasklet_action(struct softirq_action *a)
69345+static void tasklet_action(void)
69346 {
69347 struct tasklet_struct *list;
69348
69349@@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
69350 }
69351 }
69352
69353-static void tasklet_hi_action(struct softirq_action *a)
69354+static void tasklet_hi_action(void)
69355 {
69356 struct tasklet_struct *list;
69357
69358diff --git a/kernel/srcu.c b/kernel/srcu.c
69359index 2095be3..9a5b89d 100644
69360--- a/kernel/srcu.c
69361+++ b/kernel/srcu.c
69362@@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
69363 preempt_disable();
69364 idx = rcu_dereference_index_check(sp->completed,
69365 rcu_read_lock_sched_held()) & 0x1;
69366- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69367+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69368 smp_mb(); /* B */ /* Avoid leaking the critical section. */
69369- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69370+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69371 preempt_enable();
69372 return idx;
69373 }
69374@@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
69375 {
69376 preempt_disable();
69377 smp_mb(); /* C */ /* Avoid leaking the critical section. */
69378- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69379+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69380 preempt_enable();
69381 }
69382 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
69383diff --git a/kernel/sys.c b/kernel/sys.c
69384index 2d39a84..f778b49 100644
69385--- a/kernel/sys.c
69386+++ b/kernel/sys.c
69387@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
69388 error = -EACCES;
69389 goto out;
69390 }
69391+
69392+ if (gr_handle_chroot_setpriority(p, niceval)) {
69393+ error = -EACCES;
69394+ goto out;
69395+ }
69396+
69397 no_nice = security_task_setnice(p, niceval);
69398 if (no_nice) {
69399 error = no_nice;
69400@@ -594,6 +600,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
69401 goto error;
69402 }
69403
69404+ if (gr_check_group_change(new->gid, new->egid, -1))
69405+ goto error;
69406+
69407 if (rgid != (gid_t) -1 ||
69408 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
69409 new->sgid = new->egid;
69410@@ -629,6 +638,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
69411 old = current_cred();
69412
69413 retval = -EPERM;
69414+
69415+ if (gr_check_group_change(kgid, kgid, kgid))
69416+ goto error;
69417+
69418 if (nsown_capable(CAP_SETGID))
69419 new->gid = new->egid = new->sgid = new->fsgid = kgid;
69420 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
69421@@ -646,7 +659,7 @@ error:
69422 /*
69423 * change the user struct in a credentials set to match the new UID
69424 */
69425-static int set_user(struct cred *new)
69426+int set_user(struct cred *new)
69427 {
69428 struct user_struct *new_user;
69429
69430@@ -726,6 +739,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69431 goto error;
69432 }
69433
69434+ if (gr_check_user_change(new->uid, new->euid, -1))
69435+ goto error;
69436+
69437 if (!uid_eq(new->uid, old->uid)) {
69438 retval = set_user(new);
69439 if (retval < 0)
69440@@ -776,6 +792,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69441 old = current_cred();
69442
69443 retval = -EPERM;
69444+
69445+ if (gr_check_crash_uid(kuid))
69446+ goto error;
69447+ if (gr_check_user_change(kuid, kuid, kuid))
69448+ goto error;
69449+
69450 if (nsown_capable(CAP_SETUID)) {
69451 new->suid = new->uid = kuid;
69452 if (!uid_eq(kuid, old->uid)) {
69453@@ -845,6 +867,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69454 goto error;
69455 }
69456
69457+ if (gr_check_user_change(kruid, keuid, -1))
69458+ goto error;
69459+
69460 if (ruid != (uid_t) -1) {
69461 new->uid = kruid;
69462 if (!uid_eq(kruid, old->uid)) {
69463@@ -927,6 +952,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69464 goto error;
69465 }
69466
69467+ if (gr_check_group_change(krgid, kegid, -1))
69468+ goto error;
69469+
69470 if (rgid != (gid_t) -1)
69471 new->gid = krgid;
69472 if (egid != (gid_t) -1)
69473@@ -980,6 +1008,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69474 if (!uid_valid(kuid))
69475 return old_fsuid;
69476
69477+ if (gr_check_user_change(-1, -1, kuid))
69478+ goto error;
69479+
69480 new = prepare_creds();
69481 if (!new)
69482 return old_fsuid;
69483@@ -994,6 +1025,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69484 }
69485 }
69486
69487+error:
69488 abort_creds(new);
69489 return old_fsuid;
69490
69491@@ -1026,12 +1058,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69492 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
69493 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
69494 nsown_capable(CAP_SETGID)) {
69495+ if (gr_check_group_change(-1, -1, kgid))
69496+ goto error;
69497+
69498 if (!gid_eq(kgid, old->fsgid)) {
69499 new->fsgid = kgid;
69500 goto change_okay;
69501 }
69502 }
69503
69504+error:
69505 abort_creds(new);
69506 return old_fsgid;
69507
69508@@ -1283,7 +1319,10 @@ static int override_release(char __user *release, int len)
69509 }
69510 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69511 snprintf(buf, len, "2.6.%u%s", v, rest);
69512- ret = copy_to_user(release, buf, len);
69513+ if (len > sizeof(buf))
69514+ ret = -EFAULT;
69515+ else
69516+ ret = copy_to_user(release, buf, len);
69517 }
69518 return ret;
69519 }
69520@@ -1337,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69521 return -EFAULT;
69522
69523 down_read(&uts_sem);
69524- error = __copy_to_user(&name->sysname, &utsname()->sysname,
69525+ error = __copy_to_user(name->sysname, &utsname()->sysname,
69526 __OLD_UTS_LEN);
69527 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69528- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69529+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
69530 __OLD_UTS_LEN);
69531 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69532- error |= __copy_to_user(&name->release, &utsname()->release,
69533+ error |= __copy_to_user(name->release, &utsname()->release,
69534 __OLD_UTS_LEN);
69535 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69536- error |= __copy_to_user(&name->version, &utsname()->version,
69537+ error |= __copy_to_user(name->version, &utsname()->version,
69538 __OLD_UTS_LEN);
69539 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69540- error |= __copy_to_user(&name->machine, &utsname()->machine,
69541+ error |= __copy_to_user(name->machine, &utsname()->machine,
69542 __OLD_UTS_LEN);
69543 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69544 up_read(&uts_sem);
69545@@ -2024,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69546 error = get_dumpable(me->mm);
69547 break;
69548 case PR_SET_DUMPABLE:
69549- if (arg2 < 0 || arg2 > 1) {
69550+ if (arg2 > 1) {
69551 error = -EINVAL;
69552 break;
69553 }
69554diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69555index 4ab1187..33f4f2b 100644
69556--- a/kernel/sysctl.c
69557+++ b/kernel/sysctl.c
69558@@ -91,7 +91,6 @@
69559
69560
69561 #if defined(CONFIG_SYSCTL)
69562-
69563 /* External variables not in a header file. */
69564 extern int sysctl_overcommit_memory;
69565 extern int sysctl_overcommit_ratio;
69566@@ -169,10 +168,13 @@ static int proc_taint(struct ctl_table *table, int write,
69567 void __user *buffer, size_t *lenp, loff_t *ppos);
69568 #endif
69569
69570-#ifdef CONFIG_PRINTK
69571 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69572 void __user *buffer, size_t *lenp, loff_t *ppos);
69573-#endif
69574+
69575+static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69576+ void __user *buffer, size_t *lenp, loff_t *ppos);
69577+static int proc_dostring_coredump(struct ctl_table *table, int write,
69578+ void __user *buffer, size_t *lenp, loff_t *ppos);
69579
69580 #ifdef CONFIG_MAGIC_SYSRQ
69581 /* Note: sysrq code uses it's own private copy */
69582@@ -196,6 +198,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69583
69584 #endif
69585
69586+extern struct ctl_table grsecurity_table[];
69587+
69588 static struct ctl_table kern_table[];
69589 static struct ctl_table vm_table[];
69590 static struct ctl_table fs_table[];
69591@@ -210,6 +214,20 @@ extern struct ctl_table epoll_table[];
69592 int sysctl_legacy_va_layout;
69593 #endif
69594
69595+#ifdef CONFIG_PAX_SOFTMODE
69596+static ctl_table pax_table[] = {
69597+ {
69598+ .procname = "softmode",
69599+ .data = &pax_softmode,
69600+ .maxlen = sizeof(unsigned int),
69601+ .mode = 0600,
69602+ .proc_handler = &proc_dointvec,
69603+ },
69604+
69605+ { }
69606+};
69607+#endif
69608+
69609 /* The default sysctl tables: */
69610
69611 static struct ctl_table sysctl_base_table[] = {
69612@@ -256,6 +274,22 @@ static int max_extfrag_threshold = 1000;
69613 #endif
69614
69615 static struct ctl_table kern_table[] = {
69616+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69617+ {
69618+ .procname = "grsecurity",
69619+ .mode = 0500,
69620+ .child = grsecurity_table,
69621+ },
69622+#endif
69623+
69624+#ifdef CONFIG_PAX_SOFTMODE
69625+ {
69626+ .procname = "pax",
69627+ .mode = 0500,
69628+ .child = pax_table,
69629+ },
69630+#endif
69631+
69632 {
69633 .procname = "sched_child_runs_first",
69634 .data = &sysctl_sched_child_runs_first,
69635@@ -410,7 +444,7 @@ static struct ctl_table kern_table[] = {
69636 .data = core_pattern,
69637 .maxlen = CORENAME_MAX_SIZE,
69638 .mode = 0644,
69639- .proc_handler = proc_dostring,
69640+ .proc_handler = proc_dostring_coredump,
69641 },
69642 {
69643 .procname = "core_pipe_limit",
69644@@ -540,7 +574,7 @@ static struct ctl_table kern_table[] = {
69645 .data = &modprobe_path,
69646 .maxlen = KMOD_PATH_LEN,
69647 .mode = 0644,
69648- .proc_handler = proc_dostring,
69649+ .proc_handler = proc_dostring_modpriv,
69650 },
69651 {
69652 .procname = "modules_disabled",
69653@@ -707,16 +741,20 @@ static struct ctl_table kern_table[] = {
69654 .extra1 = &zero,
69655 .extra2 = &one,
69656 },
69657+#endif
69658 {
69659 .procname = "kptr_restrict",
69660 .data = &kptr_restrict,
69661 .maxlen = sizeof(int),
69662 .mode = 0644,
69663 .proc_handler = proc_dointvec_minmax_sysadmin,
69664+#ifdef CONFIG_GRKERNSEC_HIDESYM
69665+ .extra1 = &two,
69666+#else
69667 .extra1 = &zero,
69668+#endif
69669 .extra2 = &two,
69670 },
69671-#endif
69672 {
69673 .procname = "ngroups_max",
69674 .data = &ngroups_max,
69675@@ -1215,6 +1253,13 @@ static struct ctl_table vm_table[] = {
69676 .proc_handler = proc_dointvec_minmax,
69677 .extra1 = &zero,
69678 },
69679+ {
69680+ .procname = "heap_stack_gap",
69681+ .data = &sysctl_heap_stack_gap,
69682+ .maxlen = sizeof(sysctl_heap_stack_gap),
69683+ .mode = 0644,
69684+ .proc_handler = proc_doulongvec_minmax,
69685+ },
69686 #else
69687 {
69688 .procname = "nr_trim_pages",
69689@@ -1498,7 +1543,7 @@ static struct ctl_table fs_table[] = {
69690 .data = &suid_dumpable,
69691 .maxlen = sizeof(int),
69692 .mode = 0644,
69693- .proc_handler = proc_dointvec_minmax,
69694+ .proc_handler = proc_dointvec_minmax_coredump,
69695 .extra1 = &zero,
69696 .extra2 = &two,
69697 },
69698@@ -1645,6 +1690,16 @@ int proc_dostring(struct ctl_table *table, int write,
69699 buffer, lenp, ppos);
69700 }
69701
69702+int proc_dostring_modpriv(struct ctl_table *table, int write,
69703+ void __user *buffer, size_t *lenp, loff_t *ppos)
69704+{
69705+ if (write && !capable(CAP_SYS_MODULE))
69706+ return -EPERM;
69707+
69708+ return _proc_do_string(table->data, table->maxlen, write,
69709+ buffer, lenp, ppos);
69710+}
69711+
69712 static size_t proc_skip_spaces(char **buf)
69713 {
69714 size_t ret;
69715@@ -1750,6 +1805,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69716 len = strlen(tmp);
69717 if (len > *size)
69718 len = *size;
69719+ if (len > sizeof(tmp))
69720+ len = sizeof(tmp);
69721 if (copy_to_user(*buf, tmp, len))
69722 return -EFAULT;
69723 *size -= len;
69724@@ -1942,7 +1999,6 @@ static int proc_taint(struct ctl_table *table, int write,
69725 return err;
69726 }
69727
69728-#ifdef CONFIG_PRINTK
69729 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69730 void __user *buffer, size_t *lenp, loff_t *ppos)
69731 {
69732@@ -1951,7 +2007,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69733
69734 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69735 }
69736-#endif
69737
69738 struct do_proc_dointvec_minmax_conv_param {
69739 int *min;
69740@@ -2009,6 +2064,34 @@ int proc_dointvec_minmax(struct ctl_table *table, int write,
69741 do_proc_dointvec_minmax_conv, &param);
69742 }
69743
69744+static void validate_coredump_safety(void)
69745+{
69746+ if (suid_dumpable == SUID_DUMPABLE_SAFE &&
69747+ core_pattern[0] != '/' && core_pattern[0] != '|') {
69748+ printk(KERN_WARNING "Unsafe core_pattern used with "\
69749+ "suid_dumpable=2. Pipe handler or fully qualified "\
69750+ "core dump path required.\n");
69751+ }
69752+}
69753+
69754+static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69755+ void __user *buffer, size_t *lenp, loff_t *ppos)
69756+{
69757+ int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69758+ if (!error)
69759+ validate_coredump_safety();
69760+ return error;
69761+}
69762+
69763+static int proc_dostring_coredump(struct ctl_table *table, int write,
69764+ void __user *buffer, size_t *lenp, loff_t *ppos)
69765+{
69766+ int error = proc_dostring(table, write, buffer, lenp, ppos);
69767+ if (!error)
69768+ validate_coredump_safety();
69769+ return error;
69770+}
69771+
69772 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
69773 void __user *buffer,
69774 size_t *lenp, loff_t *ppos,
69775@@ -2066,8 +2149,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69776 *i = val;
69777 } else {
69778 val = convdiv * (*i) / convmul;
69779- if (!first)
69780+ if (!first) {
69781 err = proc_put_char(&buffer, &left, '\t');
69782+ if (err)
69783+ break;
69784+ }
69785 err = proc_put_long(&buffer, &left, val, false);
69786 if (err)
69787 break;
69788@@ -2459,6 +2545,12 @@ int proc_dostring(struct ctl_table *table, int write,
69789 return -ENOSYS;
69790 }
69791
69792+int proc_dostring_modpriv(struct ctl_table *table, int write,
69793+ void __user *buffer, size_t *lenp, loff_t *ppos)
69794+{
69795+ return -ENOSYS;
69796+}
69797+
69798 int proc_dointvec(struct ctl_table *table, int write,
69799 void __user *buffer, size_t *lenp, loff_t *ppos)
69800 {
69801@@ -2515,5 +2607,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69802 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69803 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69804 EXPORT_SYMBOL(proc_dostring);
69805+EXPORT_SYMBOL(proc_dostring_modpriv);
69806 EXPORT_SYMBOL(proc_doulongvec_minmax);
69807 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69808diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69809index a650694..aaeeb20 100644
69810--- a/kernel/sysctl_binary.c
69811+++ b/kernel/sysctl_binary.c
69812@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69813 int i;
69814
69815 set_fs(KERNEL_DS);
69816- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69817+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69818 set_fs(old_fs);
69819 if (result < 0)
69820 goto out_kfree;
69821@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69822 }
69823
69824 set_fs(KERNEL_DS);
69825- result = vfs_write(file, buffer, str - buffer, &pos);
69826+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69827 set_fs(old_fs);
69828 if (result < 0)
69829 goto out_kfree;
69830@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69831 int i;
69832
69833 set_fs(KERNEL_DS);
69834- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69835+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69836 set_fs(old_fs);
69837 if (result < 0)
69838 goto out_kfree;
69839@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69840 }
69841
69842 set_fs(KERNEL_DS);
69843- result = vfs_write(file, buffer, str - buffer, &pos);
69844+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69845 set_fs(old_fs);
69846 if (result < 0)
69847 goto out_kfree;
69848@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69849 int i;
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@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69858 __le16 dnaddr;
69859
69860 set_fs(KERNEL_DS);
69861- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69862+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69863 set_fs(old_fs);
69864 if (result < 0)
69865 goto out;
69866@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69867 le16_to_cpu(dnaddr) & 0x3ff);
69868
69869 set_fs(KERNEL_DS);
69870- result = vfs_write(file, buf, len, &pos);
69871+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69872 set_fs(old_fs);
69873 if (result < 0)
69874 goto out;
69875diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69876index e660464..c8b9e67 100644
69877--- a/kernel/taskstats.c
69878+++ b/kernel/taskstats.c
69879@@ -27,9 +27,12 @@
69880 #include <linux/cgroup.h>
69881 #include <linux/fs.h>
69882 #include <linux/file.h>
69883+#include <linux/grsecurity.h>
69884 #include <net/genetlink.h>
69885 #include <linux/atomic.h>
69886
69887+extern int gr_is_taskstats_denied(int pid);
69888+
69889 /*
69890 * Maximum length of a cpumask that can be specified in
69891 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69892@@ -556,6 +559,9 @@ err:
69893
69894 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69895 {
69896+ if (gr_is_taskstats_denied(current->pid))
69897+ return -EACCES;
69898+
69899 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69900 return cmd_attr_register_cpumask(info);
69901 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69902diff --git a/kernel/time.c b/kernel/time.c
69903index ba744cf..267b7c5 100644
69904--- a/kernel/time.c
69905+++ b/kernel/time.c
69906@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69907 return error;
69908
69909 if (tz) {
69910+ /* we log in do_settimeofday called below, so don't log twice
69911+ */
69912+ if (!tv)
69913+ gr_log_timechange();
69914+
69915 sys_tz = *tz;
69916 update_vsyscall_tz();
69917 if (firsttime) {
69918diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69919index aa27d39..34d221c 100644
69920--- a/kernel/time/alarmtimer.c
69921+++ b/kernel/time/alarmtimer.c
69922@@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
69923 struct platform_device *pdev;
69924 int error = 0;
69925 int i;
69926- struct k_clock alarm_clock = {
69927+ static struct k_clock alarm_clock = {
69928 .clock_getres = alarm_clock_getres,
69929 .clock_get = alarm_clock_get,
69930 .timer_create = alarm_timer_create,
69931diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69932index f113755..ec24223 100644
69933--- a/kernel/time/tick-broadcast.c
69934+++ b/kernel/time/tick-broadcast.c
69935@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69936 * then clear the broadcast bit.
69937 */
69938 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69939- int cpu = smp_processor_id();
69940+ cpu = smp_processor_id();
69941
69942 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69943 tick_broadcast_clear_oneshot(cpu);
69944diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69945index 3447cfa..291806b 100644
69946--- a/kernel/time/timekeeping.c
69947+++ b/kernel/time/timekeeping.c
69948@@ -14,6 +14,7 @@
69949 #include <linux/init.h>
69950 #include <linux/mm.h>
69951 #include <linux/sched.h>
69952+#include <linux/grsecurity.h>
69953 #include <linux/syscore_ops.h>
69954 #include <linux/clocksource.h>
69955 #include <linux/jiffies.h>
69956@@ -387,6 +388,8 @@ int do_settimeofday(const struct timespec *tv)
69957 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69958 return -EINVAL;
69959
69960+ gr_log_timechange();
69961+
69962 write_seqlock_irqsave(&timekeeper.lock, flags);
69963
69964 timekeeping_forward_now();
69965diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69966index 3258455..f35227d 100644
69967--- a/kernel/time/timer_list.c
69968+++ b/kernel/time/timer_list.c
69969@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69970
69971 static void print_name_offset(struct seq_file *m, void *sym)
69972 {
69973+#ifdef CONFIG_GRKERNSEC_HIDESYM
69974+ SEQ_printf(m, "<%p>", NULL);
69975+#else
69976 char symname[KSYM_NAME_LEN];
69977
69978 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
69979 SEQ_printf(m, "<%pK>", sym);
69980 else
69981 SEQ_printf(m, "%s", symname);
69982+#endif
69983 }
69984
69985 static void
69986@@ -112,7 +116,11 @@ next_one:
69987 static void
69988 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
69989 {
69990+#ifdef CONFIG_GRKERNSEC_HIDESYM
69991+ SEQ_printf(m, " .base: %p\n", NULL);
69992+#else
69993 SEQ_printf(m, " .base: %pK\n", base);
69994+#endif
69995 SEQ_printf(m, " .index: %d\n",
69996 base->index);
69997 SEQ_printf(m, " .resolution: %Lu nsecs\n",
69998@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
69999 {
70000 struct proc_dir_entry *pe;
70001
70002+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70003+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70004+#else
70005 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70006+#endif
70007 if (!pe)
70008 return -ENOMEM;
70009 return 0;
70010diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70011index 0b537f2..9e71eca 100644
70012--- a/kernel/time/timer_stats.c
70013+++ b/kernel/time/timer_stats.c
70014@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70015 static unsigned long nr_entries;
70016 static struct entry entries[MAX_ENTRIES];
70017
70018-static atomic_t overflow_count;
70019+static atomic_unchecked_t overflow_count;
70020
70021 /*
70022 * The entries are in a hash-table, for fast lookup:
70023@@ -140,7 +140,7 @@ static void reset_entries(void)
70024 nr_entries = 0;
70025 memset(entries, 0, sizeof(entries));
70026 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70027- atomic_set(&overflow_count, 0);
70028+ atomic_set_unchecked(&overflow_count, 0);
70029 }
70030
70031 static struct entry *alloc_entry(void)
70032@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70033 if (likely(entry))
70034 entry->count++;
70035 else
70036- atomic_inc(&overflow_count);
70037+ atomic_inc_unchecked(&overflow_count);
70038
70039 out_unlock:
70040 raw_spin_unlock_irqrestore(lock, flags);
70041@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70042
70043 static void print_name_offset(struct seq_file *m, unsigned long addr)
70044 {
70045+#ifdef CONFIG_GRKERNSEC_HIDESYM
70046+ seq_printf(m, "<%p>", NULL);
70047+#else
70048 char symname[KSYM_NAME_LEN];
70049
70050 if (lookup_symbol_name(addr, symname) < 0)
70051 seq_printf(m, "<%p>", (void *)addr);
70052 else
70053 seq_printf(m, "%s", symname);
70054+#endif
70055 }
70056
70057 static int tstats_show(struct seq_file *m, void *v)
70058@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70059
70060 seq_puts(m, "Timer Stats Version: v0.2\n");
70061 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70062- if (atomic_read(&overflow_count))
70063+ if (atomic_read_unchecked(&overflow_count))
70064 seq_printf(m, "Overflow: %d entries\n",
70065- atomic_read(&overflow_count));
70066+ atomic_read_unchecked(&overflow_count));
70067
70068 for (i = 0; i < nr_entries; i++) {
70069 entry = entries + i;
70070@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70071 {
70072 struct proc_dir_entry *pe;
70073
70074+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70075+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70076+#else
70077 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70078+#endif
70079 if (!pe)
70080 return -ENOMEM;
70081 return 0;
70082diff --git a/kernel/timer.c b/kernel/timer.c
70083index 6ec7e7e..cbc448b 100644
70084--- a/kernel/timer.c
70085+++ b/kernel/timer.c
70086@@ -1362,7 +1362,7 @@ void update_process_times(int user_tick)
70087 /*
70088 * This function runs timers and the timer-tq in bottom half context.
70089 */
70090-static void run_timer_softirq(struct softirq_action *h)
70091+static void run_timer_softirq(void)
70092 {
70093 struct tvec_base *base = __this_cpu_read(tvec_bases);
70094
70095diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70096index c0bd030..62a1927 100644
70097--- a/kernel/trace/blktrace.c
70098+++ b/kernel/trace/blktrace.c
70099@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70100 struct blk_trace *bt = filp->private_data;
70101 char buf[16];
70102
70103- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70104+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70105
70106 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70107 }
70108@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70109 return 1;
70110
70111 bt = buf->chan->private_data;
70112- atomic_inc(&bt->dropped);
70113+ atomic_inc_unchecked(&bt->dropped);
70114 return 0;
70115 }
70116
70117@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70118
70119 bt->dir = dir;
70120 bt->dev = dev;
70121- atomic_set(&bt->dropped, 0);
70122+ atomic_set_unchecked(&bt->dropped, 0);
70123
70124 ret = -EIO;
70125 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70126diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70127index a008663..d363254 100644
70128--- a/kernel/trace/ftrace.c
70129+++ b/kernel/trace/ftrace.c
70130@@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70131 if (unlikely(ftrace_disabled))
70132 return 0;
70133
70134+ ret = ftrace_arch_code_modify_prepare();
70135+ FTRACE_WARN_ON(ret);
70136+ if (ret)
70137+ return 0;
70138+
70139 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70140+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70141 if (ret) {
70142 ftrace_bug(ret, ip);
70143- return 0;
70144 }
70145- return 1;
70146+ return ret ? 0 : 1;
70147 }
70148
70149 /*
70150@@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70151
70152 int
70153 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70154- void *data)
70155+ void *data)
70156 {
70157 struct ftrace_func_probe *entry;
70158 struct ftrace_page *pg;
70159diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70160index a7fa070..403bc8d 100644
70161--- a/kernel/trace/trace.c
70162+++ b/kernel/trace/trace.c
70163@@ -4421,10 +4421,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70164 };
70165 #endif
70166
70167-static struct dentry *d_tracer;
70168-
70169 struct dentry *tracing_init_dentry(void)
70170 {
70171+ static struct dentry *d_tracer;
70172 static int once;
70173
70174 if (d_tracer)
70175@@ -4444,10 +4443,9 @@ struct dentry *tracing_init_dentry(void)
70176 return d_tracer;
70177 }
70178
70179-static struct dentry *d_percpu;
70180-
70181 struct dentry *tracing_dentry_percpu(void)
70182 {
70183+ static struct dentry *d_percpu;
70184 static int once;
70185 struct dentry *d_tracer;
70186
70187diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70188index 29111da..d190fe2 100644
70189--- a/kernel/trace/trace_events.c
70190+++ b/kernel/trace/trace_events.c
70191@@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70192 struct ftrace_module_file_ops {
70193 struct list_head list;
70194 struct module *mod;
70195- struct file_operations id;
70196- struct file_operations enable;
70197- struct file_operations format;
70198- struct file_operations filter;
70199 };
70200
70201 static struct ftrace_module_file_ops *
70202@@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70203
70204 file_ops->mod = mod;
70205
70206- file_ops->id = ftrace_event_id_fops;
70207- file_ops->id.owner = mod;
70208-
70209- file_ops->enable = ftrace_enable_fops;
70210- file_ops->enable.owner = mod;
70211-
70212- file_ops->filter = ftrace_event_filter_fops;
70213- file_ops->filter.owner = mod;
70214-
70215- file_ops->format = ftrace_event_format_fops;
70216- file_ops->format.owner = mod;
70217+ pax_open_kernel();
70218+ *(void **)&mod->trace_id.owner = mod;
70219+ *(void **)&mod->trace_enable.owner = mod;
70220+ *(void **)&mod->trace_filter.owner = mod;
70221+ *(void **)&mod->trace_format.owner = mod;
70222+ pax_close_kernel();
70223
70224 list_add(&file_ops->list, &ftrace_module_file_list);
70225
70226@@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70227
70228 for_each_event(call, start, end) {
70229 __trace_add_event_call(*call, mod,
70230- &file_ops->id, &file_ops->enable,
70231- &file_ops->filter, &file_ops->format);
70232+ &mod->trace_id, &mod->trace_enable,
70233+ &mod->trace_filter, &mod->trace_format);
70234 }
70235 }
70236
70237diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70238index fd3c8aa..5f324a6 100644
70239--- a/kernel/trace/trace_mmiotrace.c
70240+++ b/kernel/trace/trace_mmiotrace.c
70241@@ -24,7 +24,7 @@ struct header_iter {
70242 static struct trace_array *mmio_trace_array;
70243 static bool overrun_detected;
70244 static unsigned long prev_overruns;
70245-static atomic_t dropped_count;
70246+static atomic_unchecked_t dropped_count;
70247
70248 static void mmio_reset_data(struct trace_array *tr)
70249 {
70250@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70251
70252 static unsigned long count_overruns(struct trace_iterator *iter)
70253 {
70254- unsigned long cnt = atomic_xchg(&dropped_count, 0);
70255+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70256 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70257
70258 if (over > prev_overruns)
70259@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70260 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
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);
70268@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70269 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70270 sizeof(*entry), 0, pc);
70271 if (!event) {
70272- atomic_inc(&dropped_count);
70273+ atomic_inc_unchecked(&dropped_count);
70274 return;
70275 }
70276 entry = ring_buffer_event_data(event);
70277diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70278index df611a0..10d8b32 100644
70279--- a/kernel/trace/trace_output.c
70280+++ b/kernel/trace/trace_output.c
70281@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
70282
70283 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70284 if (!IS_ERR(p)) {
70285- p = mangle_path(s->buffer + s->len, p, "\n");
70286+ p = mangle_path(s->buffer + s->len, p, "\n\\");
70287 if (p) {
70288 s->len = p - s->buffer;
70289 return 1;
70290diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70291index d4545f4..a9010a1 100644
70292--- a/kernel/trace/trace_stack.c
70293+++ b/kernel/trace/trace_stack.c
70294@@ -53,7 +53,7 @@ static inline void check_stack(void)
70295 return;
70296
70297 /* we do not handle interrupt stacks yet */
70298- if (!object_is_on_stack(&this_size))
70299+ if (!object_starts_on_stack(&this_size))
70300 return;
70301
70302 local_irq_save(flags);
70303diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70304index ff5bdee..3eaeba6 100644
70305--- a/lib/Kconfig.debug
70306+++ b/lib/Kconfig.debug
70307@@ -1165,6 +1165,7 @@ config LATENCYTOP
70308 depends on DEBUG_KERNEL
70309 depends on STACKTRACE_SUPPORT
70310 depends on PROC_FS
70311+ depends on !GRKERNSEC_HIDESYM
70312 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
70313 select KALLSYMS
70314 select KALLSYMS_ALL
70315diff --git a/lib/bitmap.c b/lib/bitmap.c
70316index 06fdfa1..97c5c7d 100644
70317--- a/lib/bitmap.c
70318+++ b/lib/bitmap.c
70319@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
70320 {
70321 int c, old_c, totaldigits, ndigits, nchunks, nbits;
70322 u32 chunk;
70323- const char __user __force *ubuf = (const char __user __force *)buf;
70324+ const char __user *ubuf = (const char __force_user *)buf;
70325
70326 bitmap_zero(maskp, nmaskbits);
70327
70328@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
70329 {
70330 if (!access_ok(VERIFY_READ, ubuf, ulen))
70331 return -EFAULT;
70332- return __bitmap_parse((const char __force *)ubuf,
70333+ return __bitmap_parse((const char __force_kernel *)ubuf,
70334 ulen, 1, maskp, nmaskbits);
70335
70336 }
70337@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
70338 {
70339 unsigned a, b;
70340 int c, old_c, totaldigits;
70341- const char __user __force *ubuf = (const char __user __force *)buf;
70342+ const char __user *ubuf = (const char __force_user *)buf;
70343 int exp_digit, in_range;
70344
70345 totaldigits = c = 0;
70346@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
70347 {
70348 if (!access_ok(VERIFY_READ, ubuf, ulen))
70349 return -EFAULT;
70350- return __bitmap_parselist((const char __force *)ubuf,
70351+ return __bitmap_parselist((const char __force_kernel *)ubuf,
70352 ulen, 1, maskp, nmaskbits);
70353 }
70354 EXPORT_SYMBOL(bitmap_parselist_user);
70355diff --git a/lib/bug.c b/lib/bug.c
70356index a28c141..2bd3d95 100644
70357--- a/lib/bug.c
70358+++ b/lib/bug.c
70359@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
70360 return BUG_TRAP_TYPE_NONE;
70361
70362 bug = find_bug(bugaddr);
70363+ if (!bug)
70364+ return BUG_TRAP_TYPE_NONE;
70365
70366 file = NULL;
70367 line = 0;
70368diff --git a/lib/debugobjects.c b/lib/debugobjects.c
70369index d11808c..dc2d6f8 100644
70370--- a/lib/debugobjects.c
70371+++ b/lib/debugobjects.c
70372@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
70373 if (limit > 4)
70374 return;
70375
70376- is_on_stack = object_is_on_stack(addr);
70377+ is_on_stack = object_starts_on_stack(addr);
70378 if (is_on_stack == onstack)
70379 return;
70380
70381diff --git a/lib/devres.c b/lib/devres.c
70382index 80b9c76..9e32279 100644
70383--- a/lib/devres.c
70384+++ b/lib/devres.c
70385@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
70386 void devm_iounmap(struct device *dev, void __iomem *addr)
70387 {
70388 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
70389- (void *)addr));
70390+ (void __force *)addr));
70391 iounmap(addr);
70392 }
70393 EXPORT_SYMBOL(devm_iounmap);
70394@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70395 {
70396 ioport_unmap(addr);
70397 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70398- devm_ioport_map_match, (void *)addr));
70399+ devm_ioport_map_match, (void __force *)addr));
70400 }
70401 EXPORT_SYMBOL(devm_ioport_unmap);
70402
70403diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70404index 66ce414..6f0a0dd 100644
70405--- a/lib/dma-debug.c
70406+++ b/lib/dma-debug.c
70407@@ -924,7 +924,7 @@ out:
70408
70409 static void check_for_stack(struct device *dev, void *addr)
70410 {
70411- if (object_is_on_stack(addr))
70412+ if (object_starts_on_stack(addr))
70413 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70414 "stack [addr=%p]\n", addr);
70415 }
70416diff --git a/lib/extable.c b/lib/extable.c
70417index 4cac81e..4d66cfc 100644
70418--- a/lib/extable.c
70419+++ b/lib/extable.c
70420@@ -13,6 +13,7 @@
70421 #include <linux/init.h>
70422 #include <linux/sort.h>
70423 #include <asm/uaccess.h>
70424+#include <asm/pgtable.h>
70425
70426 #ifndef ARCH_HAS_SORT_EXTABLE
70427 /*
70428diff --git a/lib/inflate.c b/lib/inflate.c
70429index 013a761..c28f3fc 100644
70430--- a/lib/inflate.c
70431+++ b/lib/inflate.c
70432@@ -269,7 +269,7 @@ static void free(void *where)
70433 malloc_ptr = free_mem_ptr;
70434 }
70435 #else
70436-#define malloc(a) kmalloc(a, GFP_KERNEL)
70437+#define malloc(a) kmalloc((a), GFP_KERNEL)
70438 #define free(a) kfree(a)
70439 #endif
70440
70441diff --git a/lib/ioremap.c b/lib/ioremap.c
70442index 0c9216c..863bd89 100644
70443--- a/lib/ioremap.c
70444+++ b/lib/ioremap.c
70445@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
70446 unsigned long next;
70447
70448 phys_addr -= addr;
70449- pmd = pmd_alloc(&init_mm, pud, addr);
70450+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
70451 if (!pmd)
70452 return -ENOMEM;
70453 do {
70454@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
70455 unsigned long next;
70456
70457 phys_addr -= addr;
70458- pud = pud_alloc(&init_mm, pgd, addr);
70459+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
70460 if (!pud)
70461 return -ENOMEM;
70462 do {
70463diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70464index bd2bea9..6b3c95e 100644
70465--- a/lib/is_single_threaded.c
70466+++ b/lib/is_single_threaded.c
70467@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70468 struct task_struct *p, *t;
70469 bool ret;
70470
70471+ if (!mm)
70472+ return true;
70473+
70474 if (atomic_read(&task->signal->live) != 1)
70475 return false;
70476
70477diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70478index e796429..6e38f9f 100644
70479--- a/lib/radix-tree.c
70480+++ b/lib/radix-tree.c
70481@@ -92,7 +92,7 @@ struct radix_tree_preload {
70482 int nr;
70483 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
70484 };
70485-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70486+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70487
70488 static inline void *ptr_to_indirect(void *ptr)
70489 {
70490diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70491index c3f36d41..5c5aeb5 100644
70492--- a/lib/vsprintf.c
70493+++ b/lib/vsprintf.c
70494@@ -16,6 +16,9 @@
70495 * - scnprintf and vscnprintf
70496 */
70497
70498+#ifdef CONFIG_GRKERNSEC_HIDESYM
70499+#define __INCLUDED_BY_HIDESYM 1
70500+#endif
70501 #include <stdarg.h>
70502 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
70503 #include <linux/types.h>
70504@@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70505 char sym[KSYM_SYMBOL_LEN];
70506 if (ext == 'B')
70507 sprint_backtrace(sym, value);
70508- else if (ext != 'f' && ext != 's')
70509+ else if (ext != 'f' && ext != 's' && ext != 'a')
70510 sprint_symbol(sym, value);
70511 else
70512 sprint_symbol_no_offset(sym, value);
70513@@ -912,7 +915,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70514 return number(buf, end, *(const netdev_features_t *)addr, spec);
70515 }
70516
70517+#ifdef CONFIG_GRKERNSEC_HIDESYM
70518+int kptr_restrict __read_mostly = 2;
70519+#else
70520 int kptr_restrict __read_mostly;
70521+#endif
70522
70523 /*
70524 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70525@@ -926,6 +933,8 @@ int kptr_restrict __read_mostly;
70526 * - 'S' For symbolic direct pointers with offset
70527 * - 's' For symbolic direct pointers without offset
70528 * - 'B' For backtraced symbolic direct pointers with offset
70529+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70530+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70531 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70532 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70533 * - 'M' For a 6-byte MAC address, it prints the address in the
70534@@ -973,12 +982,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70535
70536 if (!ptr && *fmt != 'K') {
70537 /*
70538- * Print (null) with the same width as a pointer so it makes
70539+ * Print (nil) with the same width as a pointer so it makes
70540 * tabular output look nice.
70541 */
70542 if (spec.field_width == -1)
70543 spec.field_width = default_width;
70544- return string(buf, end, "(null)", spec);
70545+ return string(buf, end, "(nil)", spec);
70546 }
70547
70548 switch (*fmt) {
70549@@ -988,6 +997,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70550 /* Fallthrough */
70551 case 'S':
70552 case 's':
70553+#ifdef CONFIG_GRKERNSEC_HIDESYM
70554+ break;
70555+#else
70556+ return symbol_string(buf, end, ptr, spec, *fmt);
70557+#endif
70558+ case 'A':
70559+ case 'a':
70560 case 'B':
70561 return symbol_string(buf, end, ptr, spec, *fmt);
70562 case 'R':
70563@@ -1025,12 +1041,15 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70564 va_end(va);
70565 return buf;
70566 }
70567+ case 'P':
70568+ break;
70569 case 'K':
70570 /*
70571 * %pK cannot be used in IRQ context because its test
70572 * for CAP_SYSLOG would be meaningless.
70573 */
70574- if (in_irq() || in_serving_softirq() || in_nmi()) {
70575+ if (kptr_restrict && (in_irq() || in_serving_softirq() ||
70576+ in_nmi())) {
70577 if (spec.field_width == -1)
70578 spec.field_width = default_width;
70579 return string(buf, end, "pK-error", spec);
70580@@ -1047,6 +1066,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70581 }
70582 break;
70583 }
70584+
70585+#ifdef CONFIG_GRKERNSEC_HIDESYM
70586+ /* 'P' = approved pointers to copy to userland,
70587+ as in the /proc/kallsyms case, as we make it display nothing
70588+ for non-root users, and the real contents for root users
70589+ Also ignore 'K' pointers, since we force their NULLing for non-root users
70590+ above
70591+ */
70592+ if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
70593+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
70594+ dump_stack();
70595+ ptr = NULL;
70596+ }
70597+#endif
70598+
70599 spec.flags |= SMALL;
70600 if (spec.field_width == -1) {
70601 spec.field_width = default_width;
70602@@ -1758,11 +1792,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70603 typeof(type) value; \
70604 if (sizeof(type) == 8) { \
70605 args = PTR_ALIGN(args, sizeof(u32)); \
70606- *(u32 *)&value = *(u32 *)args; \
70607- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70608+ *(u32 *)&value = *(const u32 *)args; \
70609+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70610 } else { \
70611 args = PTR_ALIGN(args, sizeof(type)); \
70612- value = *(typeof(type) *)args; \
70613+ value = *(const typeof(type) *)args; \
70614 } \
70615 args += sizeof(type); \
70616 value; \
70617@@ -1825,7 +1859,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70618 case FORMAT_TYPE_STR: {
70619 const char *str_arg = args;
70620 args += strlen(str_arg) + 1;
70621- str = string(str, end, (char *)str_arg, spec);
70622+ str = string(str, end, str_arg, spec);
70623 break;
70624 }
70625
70626diff --git a/localversion-grsec b/localversion-grsec
70627new file mode 100644
70628index 0000000..7cd6065
70629--- /dev/null
70630+++ b/localversion-grsec
70631@@ -0,0 +1 @@
70632+-grsec
70633diff --git a/mm/Kconfig b/mm/Kconfig
70634index 82fed4e..979e814 100644
70635--- a/mm/Kconfig
70636+++ b/mm/Kconfig
70637@@ -247,10 +247,10 @@ config KSM
70638 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70639
70640 config DEFAULT_MMAP_MIN_ADDR
70641- int "Low address space to protect from user allocation"
70642+ int "Low address space to protect from user allocation"
70643 depends on MMU
70644- default 4096
70645- help
70646+ default 65536
70647+ help
70648 This is the portion of low virtual memory which should be protected
70649 from userspace allocation. Keeping a user from writing to low pages
70650 can help reduce the impact of kernel NULL pointer bugs.
70651@@ -280,7 +280,7 @@ config MEMORY_FAILURE
70652
70653 config HWPOISON_INJECT
70654 tristate "HWPoison pages injector"
70655- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
70656+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
70657 select PROC_PAGE_MONITOR
70658
70659 config NOMMU_INITIAL_TRIM_EXCESS
70660diff --git a/mm/filemap.c b/mm/filemap.c
70661index a4a5260..6151dc5 100644
70662--- a/mm/filemap.c
70663+++ b/mm/filemap.c
70664@@ -1723,7 +1723,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70665 struct address_space *mapping = file->f_mapping;
70666
70667 if (!mapping->a_ops->readpage)
70668- return -ENOEXEC;
70669+ return -ENODEV;
70670 file_accessed(file);
70671 vma->vm_ops = &generic_file_vm_ops;
70672 vma->vm_flags |= VM_CAN_NONLINEAR;
70673@@ -2064,6 +2064,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70674 *pos = i_size_read(inode);
70675
70676 if (limit != RLIM_INFINITY) {
70677+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70678 if (*pos >= limit) {
70679 send_sig(SIGXFSZ, current, 0);
70680 return -EFBIG;
70681diff --git a/mm/fremap.c b/mm/fremap.c
70682index 9ed4fd4..c42648d 100644
70683--- a/mm/fremap.c
70684+++ b/mm/fremap.c
70685@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70686 retry:
70687 vma = find_vma(mm, start);
70688
70689+#ifdef CONFIG_PAX_SEGMEXEC
70690+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70691+ goto out;
70692+#endif
70693+
70694 /*
70695 * Make sure the vma is shared, that it supports prefaulting,
70696 * and that the remapped range is valid and fully within
70697diff --git a/mm/highmem.c b/mm/highmem.c
70698index 57d82c6..e9e0552 100644
70699--- a/mm/highmem.c
70700+++ b/mm/highmem.c
70701@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70702 * So no dangers, even with speculative execution.
70703 */
70704 page = pte_page(pkmap_page_table[i]);
70705+ pax_open_kernel();
70706 pte_clear(&init_mm, (unsigned long)page_address(page),
70707 &pkmap_page_table[i]);
70708-
70709+ pax_close_kernel();
70710 set_page_address(page, NULL);
70711 need_flush = 1;
70712 }
70713@@ -186,9 +187,11 @@ start:
70714 }
70715 }
70716 vaddr = PKMAP_ADDR(last_pkmap_nr);
70717+
70718+ pax_open_kernel();
70719 set_pte_at(&init_mm, vaddr,
70720 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70721-
70722+ pax_close_kernel();
70723 pkmap_count[last_pkmap_nr] = 1;
70724 set_page_address(page, (void *)vaddr);
70725
70726diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70727index 57c4b93..24b8f59 100644
70728--- a/mm/huge_memory.c
70729+++ b/mm/huge_memory.c
70730@@ -735,7 +735,7 @@ out:
70731 * run pte_offset_map on the pmd, if an huge pmd could
70732 * materialize from under us from a different thread.
70733 */
70734- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70735+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70736 return VM_FAULT_OOM;
70737 /* if an huge pmd materialized from under us just retry later */
70738 if (unlikely(pmd_trans_huge(*pmd)))
70739diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70740index e198831..38d524f 100644
70741--- a/mm/hugetlb.c
70742+++ b/mm/hugetlb.c
70743@@ -2447,6 +2447,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70744 return 1;
70745 }
70746
70747+#ifdef CONFIG_PAX_SEGMEXEC
70748+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70749+{
70750+ struct mm_struct *mm = vma->vm_mm;
70751+ struct vm_area_struct *vma_m;
70752+ unsigned long address_m;
70753+ pte_t *ptep_m;
70754+
70755+ vma_m = pax_find_mirror_vma(vma);
70756+ if (!vma_m)
70757+ return;
70758+
70759+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70760+ address_m = address + SEGMEXEC_TASK_SIZE;
70761+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70762+ get_page(page_m);
70763+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
70764+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70765+}
70766+#endif
70767+
70768 /*
70769 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70770 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70771@@ -2559,6 +2580,11 @@ retry_avoidcopy:
70772 make_huge_pte(vma, new_page, 1));
70773 page_remove_rmap(old_page);
70774 hugepage_add_new_anon_rmap(new_page, vma, address);
70775+
70776+#ifdef CONFIG_PAX_SEGMEXEC
70777+ pax_mirror_huge_pte(vma, address, new_page);
70778+#endif
70779+
70780 /* Make the old page be freed below */
70781 new_page = old_page;
70782 mmu_notifier_invalidate_range_end(mm,
70783@@ -2713,6 +2739,10 @@ retry:
70784 && (vma->vm_flags & VM_SHARED)));
70785 set_huge_pte_at(mm, address, ptep, new_pte);
70786
70787+#ifdef CONFIG_PAX_SEGMEXEC
70788+ pax_mirror_huge_pte(vma, address, page);
70789+#endif
70790+
70791 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70792 /* Optimization, do the COW without a second fault */
70793 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70794@@ -2742,6 +2772,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70795 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70796 struct hstate *h = hstate_vma(vma);
70797
70798+#ifdef CONFIG_PAX_SEGMEXEC
70799+ struct vm_area_struct *vma_m;
70800+#endif
70801+
70802 address &= huge_page_mask(h);
70803
70804 ptep = huge_pte_offset(mm, address);
70805@@ -2755,6 +2789,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70806 VM_FAULT_SET_HINDEX(h - hstates);
70807 }
70808
70809+#ifdef CONFIG_PAX_SEGMEXEC
70810+ vma_m = pax_find_mirror_vma(vma);
70811+ if (vma_m) {
70812+ unsigned long address_m;
70813+
70814+ if (vma->vm_start > vma_m->vm_start) {
70815+ address_m = address;
70816+ address -= SEGMEXEC_TASK_SIZE;
70817+ vma = vma_m;
70818+ h = hstate_vma(vma);
70819+ } else
70820+ address_m = address + SEGMEXEC_TASK_SIZE;
70821+
70822+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70823+ return VM_FAULT_OOM;
70824+ address_m &= HPAGE_MASK;
70825+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70826+ }
70827+#endif
70828+
70829 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70830 if (!ptep)
70831 return VM_FAULT_OOM;
70832diff --git a/mm/internal.h b/mm/internal.h
70833index 2ba87fb..7f451e2 100644
70834--- a/mm/internal.h
70835+++ b/mm/internal.h
70836@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70837 * in mm/page_alloc.c
70838 */
70839 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70840+extern void free_compound_page(struct page *page);
70841 extern void prep_compound_page(struct page *page, unsigned long order);
70842 #ifdef CONFIG_MEMORY_FAILURE
70843 extern bool is_free_buddy_page(struct page *page);
70844diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70845index 45eb621..6ccd8ea 100644
70846--- a/mm/kmemleak.c
70847+++ b/mm/kmemleak.c
70848@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70849
70850 for (i = 0; i < object->trace_len; i++) {
70851 void *ptr = (void *)object->trace[i];
70852- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70853+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70854 }
70855 }
70856
70857diff --git a/mm/maccess.c b/mm/maccess.c
70858index d53adf9..03a24bf 100644
70859--- a/mm/maccess.c
70860+++ b/mm/maccess.c
70861@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70862 set_fs(KERNEL_DS);
70863 pagefault_disable();
70864 ret = __copy_from_user_inatomic(dst,
70865- (__force const void __user *)src, size);
70866+ (const void __force_user *)src, size);
70867 pagefault_enable();
70868 set_fs(old_fs);
70869
70870@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70871
70872 set_fs(KERNEL_DS);
70873 pagefault_disable();
70874- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70875+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70876 pagefault_enable();
70877 set_fs(old_fs);
70878
70879diff --git a/mm/madvise.c b/mm/madvise.c
70880index 14d260f..b2a80fd 100644
70881--- a/mm/madvise.c
70882+++ b/mm/madvise.c
70883@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70884 pgoff_t pgoff;
70885 unsigned long new_flags = vma->vm_flags;
70886
70887+#ifdef CONFIG_PAX_SEGMEXEC
70888+ struct vm_area_struct *vma_m;
70889+#endif
70890+
70891 switch (behavior) {
70892 case MADV_NORMAL:
70893 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70894@@ -119,6 +123,13 @@ success:
70895 /*
70896 * vm_flags is protected by the mmap_sem held in write mode.
70897 */
70898+
70899+#ifdef CONFIG_PAX_SEGMEXEC
70900+ vma_m = pax_find_mirror_vma(vma);
70901+ if (vma_m)
70902+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70903+#endif
70904+
70905 vma->vm_flags = new_flags;
70906
70907 out:
70908@@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70909 struct vm_area_struct ** prev,
70910 unsigned long start, unsigned long end)
70911 {
70912+
70913+#ifdef CONFIG_PAX_SEGMEXEC
70914+ struct vm_area_struct *vma_m;
70915+#endif
70916+
70917 *prev = vma;
70918 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70919 return -EINVAL;
70920@@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70921 zap_page_range(vma, start, end - start, &details);
70922 } else
70923 zap_page_range(vma, start, end - start, NULL);
70924+
70925+#ifdef CONFIG_PAX_SEGMEXEC
70926+ vma_m = pax_find_mirror_vma(vma);
70927+ if (vma_m) {
70928+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70929+ struct zap_details details = {
70930+ .nonlinear_vma = vma_m,
70931+ .last_index = ULONG_MAX,
70932+ };
70933+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70934+ } else
70935+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70936+ }
70937+#endif
70938+
70939 return 0;
70940 }
70941
70942@@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70943 if (end < start)
70944 goto out;
70945
70946+#ifdef CONFIG_PAX_SEGMEXEC
70947+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70948+ if (end > SEGMEXEC_TASK_SIZE)
70949+ goto out;
70950+ } else
70951+#endif
70952+
70953+ if (end > TASK_SIZE)
70954+ goto out;
70955+
70956 error = 0;
70957 if (end == start)
70958 goto out;
70959diff --git a/mm/memory-failure.c b/mm/memory-failure.c
70960index ab1e714..415de01 100644
70961--- a/mm/memory-failure.c
70962+++ b/mm/memory-failure.c
70963@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
70964
70965 int sysctl_memory_failure_recovery __read_mostly = 1;
70966
70967-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70968+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70969
70970 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
70971
70972@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
70973 pfn, t->comm, t->pid);
70974 si.si_signo = SIGBUS;
70975 si.si_errno = 0;
70976- si.si_addr = (void *)addr;
70977+ si.si_addr = (void __user *)addr;
70978 #ifdef __ARCH_SI_TRAPNO
70979 si.si_trapno = trapno;
70980 #endif
70981@@ -1036,7 +1036,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
70982 }
70983
70984 nr_pages = 1 << compound_trans_order(hpage);
70985- atomic_long_add(nr_pages, &mce_bad_pages);
70986+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
70987
70988 /*
70989 * We need/can do nothing about count=0 pages.
70990@@ -1066,7 +1066,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
70991 if (!PageHWPoison(hpage)
70992 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
70993 || (p != hpage && TestSetPageHWPoison(hpage))) {
70994- atomic_long_sub(nr_pages, &mce_bad_pages);
70995+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70996 return 0;
70997 }
70998 set_page_hwpoison_huge_page(hpage);
70999@@ -1124,7 +1124,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71000 }
71001 if (hwpoison_filter(p)) {
71002 if (TestClearPageHWPoison(p))
71003- atomic_long_sub(nr_pages, &mce_bad_pages);
71004+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71005 unlock_page(hpage);
71006 put_page(hpage);
71007 return 0;
71008@@ -1319,7 +1319,7 @@ int unpoison_memory(unsigned long pfn)
71009 return 0;
71010 }
71011 if (TestClearPageHWPoison(p))
71012- atomic_long_sub(nr_pages, &mce_bad_pages);
71013+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71014 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71015 return 0;
71016 }
71017@@ -1333,7 +1333,7 @@ int unpoison_memory(unsigned long pfn)
71018 */
71019 if (TestClearPageHWPoison(page)) {
71020 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71021- atomic_long_sub(nr_pages, &mce_bad_pages);
71022+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71023 freeit = 1;
71024 if (PageHuge(page))
71025 clear_page_hwpoison_huge_page(page);
71026@@ -1446,7 +1446,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71027 }
71028 done:
71029 if (!PageHWPoison(hpage))
71030- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
71031+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
71032 set_page_hwpoison_huge_page(hpage);
71033 dequeue_hwpoisoned_huge_page(hpage);
71034 /* keep elevated page count for bad page */
71035@@ -1577,7 +1577,7 @@ int soft_offline_page(struct page *page, int flags)
71036 return ret;
71037
71038 done:
71039- atomic_long_add(1, &mce_bad_pages);
71040+ atomic_long_add_unchecked(1, &mce_bad_pages);
71041 SetPageHWPoison(page);
71042 /* keep elevated page count for bad page */
71043 return ret;
71044diff --git a/mm/memory.c b/mm/memory.c
71045index 2466d12..08be4f6 100644
71046--- a/mm/memory.c
71047+++ b/mm/memory.c
71048@@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71049 return;
71050
71051 pmd = pmd_offset(pud, start);
71052+
71053+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71054 pud_clear(pud);
71055 pmd_free_tlb(tlb, pmd, start);
71056+#endif
71057+
71058 }
71059
71060 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71061@@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71062 if (end - 1 > ceiling - 1)
71063 return;
71064
71065+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71066 pud = pud_offset(pgd, start);
71067 pgd_clear(pgd);
71068 pud_free_tlb(tlb, pud, start);
71069+#endif
71070+
71071 }
71072
71073 /*
71074@@ -1602,12 +1609,6 @@ no_page_table:
71075 return page;
71076 }
71077
71078-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71079-{
71080- return stack_guard_page_start(vma, addr) ||
71081- stack_guard_page_end(vma, addr+PAGE_SIZE);
71082-}
71083-
71084 /**
71085 * __get_user_pages() - pin user pages in memory
71086 * @tsk: task_struct of target task
71087@@ -1680,10 +1681,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71088 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71089 i = 0;
71090
71091- do {
71092+ while (nr_pages) {
71093 struct vm_area_struct *vma;
71094
71095- vma = find_extend_vma(mm, start);
71096+ vma = find_vma(mm, start);
71097 if (!vma && in_gate_area(mm, start)) {
71098 unsigned long pg = start & PAGE_MASK;
71099 pgd_t *pgd;
71100@@ -1731,7 +1732,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71101 goto next_page;
71102 }
71103
71104- if (!vma ||
71105+ if (!vma || start < vma->vm_start ||
71106 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71107 !(vm_flags & vma->vm_flags))
71108 return i ? : -EFAULT;
71109@@ -1758,11 +1759,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71110 int ret;
71111 unsigned int fault_flags = 0;
71112
71113- /* For mlock, just skip the stack guard page. */
71114- if (foll_flags & FOLL_MLOCK) {
71115- if (stack_guard_page(vma, start))
71116- goto next_page;
71117- }
71118 if (foll_flags & FOLL_WRITE)
71119 fault_flags |= FAULT_FLAG_WRITE;
71120 if (nonblocking)
71121@@ -1836,7 +1832,7 @@ next_page:
71122 start += PAGE_SIZE;
71123 nr_pages--;
71124 } while (nr_pages && start < vma->vm_end);
71125- } while (nr_pages);
71126+ }
71127 return i;
71128 }
71129 EXPORT_SYMBOL(__get_user_pages);
71130@@ -2043,6 +2039,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71131 page_add_file_rmap(page);
71132 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71133
71134+#ifdef CONFIG_PAX_SEGMEXEC
71135+ pax_mirror_file_pte(vma, addr, page, ptl);
71136+#endif
71137+
71138 retval = 0;
71139 pte_unmap_unlock(pte, ptl);
71140 return retval;
71141@@ -2077,10 +2077,22 @@ out:
71142 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71143 struct page *page)
71144 {
71145+
71146+#ifdef CONFIG_PAX_SEGMEXEC
71147+ struct vm_area_struct *vma_m;
71148+#endif
71149+
71150 if (addr < vma->vm_start || addr >= vma->vm_end)
71151 return -EFAULT;
71152 if (!page_count(page))
71153 return -EINVAL;
71154+
71155+#ifdef CONFIG_PAX_SEGMEXEC
71156+ vma_m = pax_find_mirror_vma(vma);
71157+ if (vma_m)
71158+ vma_m->vm_flags |= VM_INSERTPAGE;
71159+#endif
71160+
71161 vma->vm_flags |= VM_INSERTPAGE;
71162 return insert_page(vma, addr, page, vma->vm_page_prot);
71163 }
71164@@ -2166,6 +2178,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71165 unsigned long pfn)
71166 {
71167 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71168+ BUG_ON(vma->vm_mirror);
71169
71170 if (addr < vma->vm_start || addr >= vma->vm_end)
71171 return -EFAULT;
71172@@ -2373,7 +2386,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71173
71174 BUG_ON(pud_huge(*pud));
71175
71176- pmd = pmd_alloc(mm, pud, addr);
71177+ pmd = (mm == &init_mm) ?
71178+ pmd_alloc_kernel(mm, pud, addr) :
71179+ pmd_alloc(mm, pud, addr);
71180 if (!pmd)
71181 return -ENOMEM;
71182 do {
71183@@ -2393,7 +2408,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71184 unsigned long next;
71185 int err;
71186
71187- pud = pud_alloc(mm, pgd, addr);
71188+ pud = (mm == &init_mm) ?
71189+ pud_alloc_kernel(mm, pgd, addr) :
71190+ pud_alloc(mm, pgd, addr);
71191 if (!pud)
71192 return -ENOMEM;
71193 do {
71194@@ -2481,6 +2498,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71195 copy_user_highpage(dst, src, va, vma);
71196 }
71197
71198+#ifdef CONFIG_PAX_SEGMEXEC
71199+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71200+{
71201+ struct mm_struct *mm = vma->vm_mm;
71202+ spinlock_t *ptl;
71203+ pte_t *pte, entry;
71204+
71205+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71206+ entry = *pte;
71207+ if (!pte_present(entry)) {
71208+ if (!pte_none(entry)) {
71209+ BUG_ON(pte_file(entry));
71210+ free_swap_and_cache(pte_to_swp_entry(entry));
71211+ pte_clear_not_present_full(mm, address, pte, 0);
71212+ }
71213+ } else {
71214+ struct page *page;
71215+
71216+ flush_cache_page(vma, address, pte_pfn(entry));
71217+ entry = ptep_clear_flush(vma, address, pte);
71218+ BUG_ON(pte_dirty(entry));
71219+ page = vm_normal_page(vma, address, entry);
71220+ if (page) {
71221+ update_hiwater_rss(mm);
71222+ if (PageAnon(page))
71223+ dec_mm_counter_fast(mm, MM_ANONPAGES);
71224+ else
71225+ dec_mm_counter_fast(mm, MM_FILEPAGES);
71226+ page_remove_rmap(page);
71227+ page_cache_release(page);
71228+ }
71229+ }
71230+ pte_unmap_unlock(pte, ptl);
71231+}
71232+
71233+/* PaX: if vma is mirrored, synchronize the mirror's PTE
71234+ *
71235+ * the ptl of the lower mapped page is held on entry and is not released on exit
71236+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71237+ */
71238+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71239+{
71240+ struct mm_struct *mm = vma->vm_mm;
71241+ unsigned long address_m;
71242+ spinlock_t *ptl_m;
71243+ struct vm_area_struct *vma_m;
71244+ pmd_t *pmd_m;
71245+ pte_t *pte_m, entry_m;
71246+
71247+ BUG_ON(!page_m || !PageAnon(page_m));
71248+
71249+ vma_m = pax_find_mirror_vma(vma);
71250+ if (!vma_m)
71251+ return;
71252+
71253+ BUG_ON(!PageLocked(page_m));
71254+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71255+ address_m = address + SEGMEXEC_TASK_SIZE;
71256+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71257+ pte_m = pte_offset_map(pmd_m, address_m);
71258+ ptl_m = pte_lockptr(mm, pmd_m);
71259+ if (ptl != ptl_m) {
71260+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71261+ if (!pte_none(*pte_m))
71262+ goto out;
71263+ }
71264+
71265+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71266+ page_cache_get(page_m);
71267+ page_add_anon_rmap(page_m, vma_m, address_m);
71268+ inc_mm_counter_fast(mm, MM_ANONPAGES);
71269+ set_pte_at(mm, address_m, pte_m, entry_m);
71270+ update_mmu_cache(vma_m, address_m, entry_m);
71271+out:
71272+ if (ptl != ptl_m)
71273+ spin_unlock(ptl_m);
71274+ pte_unmap(pte_m);
71275+ unlock_page(page_m);
71276+}
71277+
71278+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71279+{
71280+ struct mm_struct *mm = vma->vm_mm;
71281+ unsigned long address_m;
71282+ spinlock_t *ptl_m;
71283+ struct vm_area_struct *vma_m;
71284+ pmd_t *pmd_m;
71285+ pte_t *pte_m, entry_m;
71286+
71287+ BUG_ON(!page_m || PageAnon(page_m));
71288+
71289+ vma_m = pax_find_mirror_vma(vma);
71290+ if (!vma_m)
71291+ return;
71292+
71293+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71294+ address_m = address + SEGMEXEC_TASK_SIZE;
71295+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71296+ pte_m = pte_offset_map(pmd_m, address_m);
71297+ ptl_m = pte_lockptr(mm, pmd_m);
71298+ if (ptl != ptl_m) {
71299+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71300+ if (!pte_none(*pte_m))
71301+ goto out;
71302+ }
71303+
71304+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71305+ page_cache_get(page_m);
71306+ page_add_file_rmap(page_m);
71307+ inc_mm_counter_fast(mm, MM_FILEPAGES);
71308+ set_pte_at(mm, address_m, pte_m, entry_m);
71309+ update_mmu_cache(vma_m, address_m, entry_m);
71310+out:
71311+ if (ptl != ptl_m)
71312+ spin_unlock(ptl_m);
71313+ pte_unmap(pte_m);
71314+}
71315+
71316+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71317+{
71318+ struct mm_struct *mm = vma->vm_mm;
71319+ unsigned long address_m;
71320+ spinlock_t *ptl_m;
71321+ struct vm_area_struct *vma_m;
71322+ pmd_t *pmd_m;
71323+ pte_t *pte_m, entry_m;
71324+
71325+ vma_m = pax_find_mirror_vma(vma);
71326+ if (!vma_m)
71327+ return;
71328+
71329+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71330+ address_m = address + SEGMEXEC_TASK_SIZE;
71331+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71332+ pte_m = pte_offset_map(pmd_m, address_m);
71333+ ptl_m = pte_lockptr(mm, pmd_m);
71334+ if (ptl != ptl_m) {
71335+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71336+ if (!pte_none(*pte_m))
71337+ goto out;
71338+ }
71339+
71340+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71341+ set_pte_at(mm, address_m, pte_m, entry_m);
71342+out:
71343+ if (ptl != ptl_m)
71344+ spin_unlock(ptl_m);
71345+ pte_unmap(pte_m);
71346+}
71347+
71348+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71349+{
71350+ struct page *page_m;
71351+ pte_t entry;
71352+
71353+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71354+ goto out;
71355+
71356+ entry = *pte;
71357+ page_m = vm_normal_page(vma, address, entry);
71358+ if (!page_m)
71359+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71360+ else if (PageAnon(page_m)) {
71361+ if (pax_find_mirror_vma(vma)) {
71362+ pte_unmap_unlock(pte, ptl);
71363+ lock_page(page_m);
71364+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71365+ if (pte_same(entry, *pte))
71366+ pax_mirror_anon_pte(vma, address, page_m, ptl);
71367+ else
71368+ unlock_page(page_m);
71369+ }
71370+ } else
71371+ pax_mirror_file_pte(vma, address, page_m, ptl);
71372+
71373+out:
71374+ pte_unmap_unlock(pte, ptl);
71375+}
71376+#endif
71377+
71378 /*
71379 * This routine handles present pages, when users try to write
71380 * to a shared page. It is done by copying the page to a new address
71381@@ -2692,6 +2889,12 @@ gotten:
71382 */
71383 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71384 if (likely(pte_same(*page_table, orig_pte))) {
71385+
71386+#ifdef CONFIG_PAX_SEGMEXEC
71387+ if (pax_find_mirror_vma(vma))
71388+ BUG_ON(!trylock_page(new_page));
71389+#endif
71390+
71391 if (old_page) {
71392 if (!PageAnon(old_page)) {
71393 dec_mm_counter_fast(mm, MM_FILEPAGES);
71394@@ -2743,6 +2946,10 @@ gotten:
71395 page_remove_rmap(old_page);
71396 }
71397
71398+#ifdef CONFIG_PAX_SEGMEXEC
71399+ pax_mirror_anon_pte(vma, address, new_page, ptl);
71400+#endif
71401+
71402 /* Free the old page.. */
71403 new_page = old_page;
71404 ret |= VM_FAULT_WRITE;
71405@@ -3022,6 +3229,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71406 swap_free(entry);
71407 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71408 try_to_free_swap(page);
71409+
71410+#ifdef CONFIG_PAX_SEGMEXEC
71411+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71412+#endif
71413+
71414 unlock_page(page);
71415 if (swapcache) {
71416 /*
71417@@ -3045,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71418
71419 /* No need to invalidate - it was non-present before */
71420 update_mmu_cache(vma, address, page_table);
71421+
71422+#ifdef CONFIG_PAX_SEGMEXEC
71423+ pax_mirror_anon_pte(vma, address, page, ptl);
71424+#endif
71425+
71426 unlock:
71427 pte_unmap_unlock(page_table, ptl);
71428 out:
71429@@ -3064,40 +3281,6 @@ out_release:
71430 }
71431
71432 /*
71433- * This is like a special single-page "expand_{down|up}wards()",
71434- * except we must first make sure that 'address{-|+}PAGE_SIZE'
71435- * doesn't hit another vma.
71436- */
71437-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71438-{
71439- address &= PAGE_MASK;
71440- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71441- struct vm_area_struct *prev = vma->vm_prev;
71442-
71443- /*
71444- * Is there a mapping abutting this one below?
71445- *
71446- * That's only ok if it's the same stack mapping
71447- * that has gotten split..
71448- */
71449- if (prev && prev->vm_end == address)
71450- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71451-
71452- expand_downwards(vma, address - PAGE_SIZE);
71453- }
71454- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71455- struct vm_area_struct *next = vma->vm_next;
71456-
71457- /* As VM_GROWSDOWN but s/below/above/ */
71458- if (next && next->vm_start == address + PAGE_SIZE)
71459- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71460-
71461- expand_upwards(vma, address + PAGE_SIZE);
71462- }
71463- return 0;
71464-}
71465-
71466-/*
71467 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71468 * but allow concurrent faults), and pte mapped but not yet locked.
71469 * We return with mmap_sem still held, but pte unmapped and unlocked.
71470@@ -3106,27 +3289,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71471 unsigned long address, pte_t *page_table, pmd_t *pmd,
71472 unsigned int flags)
71473 {
71474- struct page *page;
71475+ struct page *page = NULL;
71476 spinlock_t *ptl;
71477 pte_t entry;
71478
71479- pte_unmap(page_table);
71480-
71481- /* Check if we need to add a guard page to the stack */
71482- if (check_stack_guard_page(vma, address) < 0)
71483- return VM_FAULT_SIGBUS;
71484-
71485- /* Use the zero-page for reads */
71486 if (!(flags & FAULT_FLAG_WRITE)) {
71487 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71488 vma->vm_page_prot));
71489- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71490+ ptl = pte_lockptr(mm, pmd);
71491+ spin_lock(ptl);
71492 if (!pte_none(*page_table))
71493 goto unlock;
71494 goto setpte;
71495 }
71496
71497 /* Allocate our own private page. */
71498+ pte_unmap(page_table);
71499+
71500 if (unlikely(anon_vma_prepare(vma)))
71501 goto oom;
71502 page = alloc_zeroed_user_highpage_movable(vma, address);
71503@@ -3145,6 +3324,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71504 if (!pte_none(*page_table))
71505 goto release;
71506
71507+#ifdef CONFIG_PAX_SEGMEXEC
71508+ if (pax_find_mirror_vma(vma))
71509+ BUG_ON(!trylock_page(page));
71510+#endif
71511+
71512 inc_mm_counter_fast(mm, MM_ANONPAGES);
71513 page_add_new_anon_rmap(page, vma, address);
71514 setpte:
71515@@ -3152,6 +3336,12 @@ setpte:
71516
71517 /* No need to invalidate - it was non-present before */
71518 update_mmu_cache(vma, address, page_table);
71519+
71520+#ifdef CONFIG_PAX_SEGMEXEC
71521+ if (page)
71522+ pax_mirror_anon_pte(vma, address, page, ptl);
71523+#endif
71524+
71525 unlock:
71526 pte_unmap_unlock(page_table, ptl);
71527 return 0;
71528@@ -3295,6 +3485,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71529 */
71530 /* Only go through if we didn't race with anybody else... */
71531 if (likely(pte_same(*page_table, orig_pte))) {
71532+
71533+#ifdef CONFIG_PAX_SEGMEXEC
71534+ if (anon && pax_find_mirror_vma(vma))
71535+ BUG_ON(!trylock_page(page));
71536+#endif
71537+
71538 flush_icache_page(vma, page);
71539 entry = mk_pte(page, vma->vm_page_prot);
71540 if (flags & FAULT_FLAG_WRITE)
71541@@ -3314,6 +3510,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71542
71543 /* no need to invalidate: a not-present page won't be cached */
71544 update_mmu_cache(vma, address, page_table);
71545+
71546+#ifdef CONFIG_PAX_SEGMEXEC
71547+ if (anon)
71548+ pax_mirror_anon_pte(vma, address, page, ptl);
71549+ else
71550+ pax_mirror_file_pte(vma, address, page, ptl);
71551+#endif
71552+
71553 } else {
71554 if (cow_page)
71555 mem_cgroup_uncharge_page(cow_page);
71556@@ -3467,6 +3671,12 @@ int handle_pte_fault(struct mm_struct *mm,
71557 if (flags & FAULT_FLAG_WRITE)
71558 flush_tlb_fix_spurious_fault(vma, address);
71559 }
71560+
71561+#ifdef CONFIG_PAX_SEGMEXEC
71562+ pax_mirror_pte(vma, address, pte, pmd, ptl);
71563+ return 0;
71564+#endif
71565+
71566 unlock:
71567 pte_unmap_unlock(pte, ptl);
71568 return 0;
71569@@ -3483,6 +3693,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71570 pmd_t *pmd;
71571 pte_t *pte;
71572
71573+#ifdef CONFIG_PAX_SEGMEXEC
71574+ struct vm_area_struct *vma_m;
71575+#endif
71576+
71577 __set_current_state(TASK_RUNNING);
71578
71579 count_vm_event(PGFAULT);
71580@@ -3494,6 +3708,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71581 if (unlikely(is_vm_hugetlb_page(vma)))
71582 return hugetlb_fault(mm, vma, address, flags);
71583
71584+#ifdef CONFIG_PAX_SEGMEXEC
71585+ vma_m = pax_find_mirror_vma(vma);
71586+ if (vma_m) {
71587+ unsigned long address_m;
71588+ pgd_t *pgd_m;
71589+ pud_t *pud_m;
71590+ pmd_t *pmd_m;
71591+
71592+ if (vma->vm_start > vma_m->vm_start) {
71593+ address_m = address;
71594+ address -= SEGMEXEC_TASK_SIZE;
71595+ vma = vma_m;
71596+ } else
71597+ address_m = address + SEGMEXEC_TASK_SIZE;
71598+
71599+ pgd_m = pgd_offset(mm, address_m);
71600+ pud_m = pud_alloc(mm, pgd_m, address_m);
71601+ if (!pud_m)
71602+ return VM_FAULT_OOM;
71603+ pmd_m = pmd_alloc(mm, pud_m, address_m);
71604+ if (!pmd_m)
71605+ return VM_FAULT_OOM;
71606+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71607+ return VM_FAULT_OOM;
71608+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71609+ }
71610+#endif
71611+
71612 retry:
71613 pgd = pgd_offset(mm, address);
71614 pud = pud_alloc(mm, pgd, address);
71615@@ -3535,7 +3777,7 @@ retry:
71616 * run pte_offset_map on the pmd, if an huge pmd could
71617 * materialize from under us from a different thread.
71618 */
71619- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71620+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71621 return VM_FAULT_OOM;
71622 /* if an huge pmd materialized from under us just retry later */
71623 if (unlikely(pmd_trans_huge(*pmd)))
71624@@ -3572,6 +3814,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71625 spin_unlock(&mm->page_table_lock);
71626 return 0;
71627 }
71628+
71629+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71630+{
71631+ pud_t *new = pud_alloc_one(mm, address);
71632+ if (!new)
71633+ return -ENOMEM;
71634+
71635+ smp_wmb(); /* See comment in __pte_alloc */
71636+
71637+ spin_lock(&mm->page_table_lock);
71638+ if (pgd_present(*pgd)) /* Another has populated it */
71639+ pud_free(mm, new);
71640+ else
71641+ pgd_populate_kernel(mm, pgd, new);
71642+ spin_unlock(&mm->page_table_lock);
71643+ return 0;
71644+}
71645 #endif /* __PAGETABLE_PUD_FOLDED */
71646
71647 #ifndef __PAGETABLE_PMD_FOLDED
71648@@ -3602,6 +3861,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71649 spin_unlock(&mm->page_table_lock);
71650 return 0;
71651 }
71652+
71653+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71654+{
71655+ pmd_t *new = pmd_alloc_one(mm, address);
71656+ if (!new)
71657+ return -ENOMEM;
71658+
71659+ smp_wmb(); /* See comment in __pte_alloc */
71660+
71661+ spin_lock(&mm->page_table_lock);
71662+#ifndef __ARCH_HAS_4LEVEL_HACK
71663+ if (pud_present(*pud)) /* Another has populated it */
71664+ pmd_free(mm, new);
71665+ else
71666+ pud_populate_kernel(mm, pud, new);
71667+#else
71668+ if (pgd_present(*pud)) /* Another has populated it */
71669+ pmd_free(mm, new);
71670+ else
71671+ pgd_populate_kernel(mm, pud, new);
71672+#endif /* __ARCH_HAS_4LEVEL_HACK */
71673+ spin_unlock(&mm->page_table_lock);
71674+ return 0;
71675+}
71676 #endif /* __PAGETABLE_PMD_FOLDED */
71677
71678 int make_pages_present(unsigned long addr, unsigned long end)
71679@@ -3639,7 +3922,7 @@ static int __init gate_vma_init(void)
71680 gate_vma.vm_start = FIXADDR_USER_START;
71681 gate_vma.vm_end = FIXADDR_USER_END;
71682 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71683- gate_vma.vm_page_prot = __P101;
71684+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71685
71686 return 0;
71687 }
71688diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71689index 1d771e4..f9a6808 100644
71690--- a/mm/mempolicy.c
71691+++ b/mm/mempolicy.c
71692@@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71693 unsigned long vmstart;
71694 unsigned long vmend;
71695
71696+#ifdef CONFIG_PAX_SEGMEXEC
71697+ struct vm_area_struct *vma_m;
71698+#endif
71699+
71700 vma = find_vma(mm, start);
71701 if (!vma || vma->vm_start > start)
71702 return -EFAULT;
71703@@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71704 if (err)
71705 goto out;
71706 }
71707+
71708+#ifdef CONFIG_PAX_SEGMEXEC
71709+ vma_m = pax_find_mirror_vma(vma);
71710+ if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
71711+ err = vma_m->vm_ops->set_policy(vma_m, new_pol);
71712+ if (err)
71713+ goto out;
71714+ }
71715+#endif
71716+
71717 }
71718
71719 out:
71720@@ -1125,6 +1139,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71721
71722 if (end < start)
71723 return -EINVAL;
71724+
71725+#ifdef CONFIG_PAX_SEGMEXEC
71726+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71727+ if (end > SEGMEXEC_TASK_SIZE)
71728+ return -EINVAL;
71729+ } else
71730+#endif
71731+
71732+ if (end > TASK_SIZE)
71733+ return -EINVAL;
71734+
71735 if (end == start)
71736 return 0;
71737
71738@@ -1348,8 +1373,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71739 */
71740 tcred = __task_cred(task);
71741 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
71742- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
71743- !capable(CAP_SYS_NICE)) {
71744+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
71745 rcu_read_unlock();
71746 err = -EPERM;
71747 goto out_put;
71748@@ -1380,6 +1404,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71749 goto out;
71750 }
71751
71752+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71753+ if (mm != current->mm &&
71754+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71755+ mmput(mm);
71756+ err = -EPERM;
71757+ goto out;
71758+ }
71759+#endif
71760+
71761 err = do_migrate_pages(mm, old, new,
71762 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
71763
71764diff --git a/mm/mlock.c b/mm/mlock.c
71765index ef726e8..cd7f1ec 100644
71766--- a/mm/mlock.c
71767+++ b/mm/mlock.c
71768@@ -13,6 +13,7 @@
71769 #include <linux/pagemap.h>
71770 #include <linux/mempolicy.h>
71771 #include <linux/syscalls.h>
71772+#include <linux/security.h>
71773 #include <linux/sched.h>
71774 #include <linux/export.h>
71775 #include <linux/rmap.h>
71776@@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
71777 {
71778 unsigned long nstart, end, tmp;
71779 struct vm_area_struct * vma, * prev;
71780- int error;
71781+ int error = 0;
71782
71783 VM_BUG_ON(start & ~PAGE_MASK);
71784 VM_BUG_ON(len != PAGE_ALIGN(len));
71785@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71786 return -EINVAL;
71787 if (end == start)
71788 return 0;
71789+ if (end > TASK_SIZE)
71790+ return -EINVAL;
71791+
71792 vma = find_vma(current->mm, start);
71793 if (!vma || vma->vm_start > start)
71794 return -ENOMEM;
71795@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71796 for (nstart = start ; ; ) {
71797 vm_flags_t newflags;
71798
71799+#ifdef CONFIG_PAX_SEGMEXEC
71800+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71801+ break;
71802+#endif
71803+
71804 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71805
71806 newflags = vma->vm_flags | VM_LOCKED;
71807@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71808 lock_limit >>= PAGE_SHIFT;
71809
71810 /* check against resource limits */
71811+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71812 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71813 error = do_mlock(start, len, 1);
71814 up_write(&current->mm->mmap_sem);
71815@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71816 static int do_mlockall(int flags)
71817 {
71818 struct vm_area_struct * vma, * prev = NULL;
71819- unsigned int def_flags = 0;
71820
71821 if (flags & MCL_FUTURE)
71822- def_flags = VM_LOCKED;
71823- current->mm->def_flags = def_flags;
71824+ current->mm->def_flags |= VM_LOCKED;
71825+ else
71826+ current->mm->def_flags &= ~VM_LOCKED;
71827 if (flags == MCL_FUTURE)
71828 goto out;
71829
71830 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71831 vm_flags_t newflags;
71832
71833+#ifdef CONFIG_PAX_SEGMEXEC
71834+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71835+ break;
71836+#endif
71837+
71838+ BUG_ON(vma->vm_end > TASK_SIZE);
71839 newflags = vma->vm_flags | VM_LOCKED;
71840 if (!(flags & MCL_CURRENT))
71841 newflags &= ~VM_LOCKED;
71842@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71843 lock_limit >>= PAGE_SHIFT;
71844
71845 ret = -ENOMEM;
71846+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71847 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71848 capable(CAP_IPC_LOCK))
71849 ret = do_mlockall(flags);
71850diff --git a/mm/mmap.c b/mm/mmap.c
71851index 3edfcdf..4a27ae9 100644
71852--- a/mm/mmap.c
71853+++ b/mm/mmap.c
71854@@ -47,6 +47,16 @@
71855 #define arch_rebalance_pgtables(addr, len) (addr)
71856 #endif
71857
71858+static inline void verify_mm_writelocked(struct mm_struct *mm)
71859+{
71860+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71861+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71862+ up_read(&mm->mmap_sem);
71863+ BUG();
71864+ }
71865+#endif
71866+}
71867+
71868 static void unmap_region(struct mm_struct *mm,
71869 struct vm_area_struct *vma, struct vm_area_struct *prev,
71870 unsigned long start, unsigned long end);
71871@@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
71872 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71873 *
71874 */
71875-pgprot_t protection_map[16] = {
71876+pgprot_t protection_map[16] __read_only = {
71877 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71878 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71879 };
71880
71881-pgprot_t vm_get_page_prot(unsigned long vm_flags)
71882+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71883 {
71884- return __pgprot(pgprot_val(protection_map[vm_flags &
71885+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71886 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71887 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71888+
71889+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71890+ if (!(__supported_pte_mask & _PAGE_NX) &&
71891+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71892+ (vm_flags & (VM_READ | VM_WRITE)))
71893+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71894+#endif
71895+
71896+ return prot;
71897 }
71898 EXPORT_SYMBOL(vm_get_page_prot);
71899
71900 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71901 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71902 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71903+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71904 /*
71905 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71906 * other variables. It can be updated by several CPUs frequently.
71907@@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71908 struct vm_area_struct *next = vma->vm_next;
71909
71910 might_sleep();
71911+ BUG_ON(vma->vm_mirror);
71912 if (vma->vm_ops && vma->vm_ops->close)
71913 vma->vm_ops->close(vma);
71914 if (vma->vm_file) {
71915@@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71916 * not page aligned -Ram Gupta
71917 */
71918 rlim = rlimit(RLIMIT_DATA);
71919+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71920 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71921 (mm->end_data - mm->start_data) > rlim)
71922 goto out;
71923@@ -708,6 +730,12 @@ static int
71924 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71925 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71926 {
71927+
71928+#ifdef CONFIG_PAX_SEGMEXEC
71929+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71930+ return 0;
71931+#endif
71932+
71933 if (is_mergeable_vma(vma, file, vm_flags) &&
71934 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71935 if (vma->vm_pgoff == vm_pgoff)
71936@@ -727,6 +755,12 @@ static int
71937 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71938 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71939 {
71940+
71941+#ifdef CONFIG_PAX_SEGMEXEC
71942+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71943+ return 0;
71944+#endif
71945+
71946 if (is_mergeable_vma(vma, file, vm_flags) &&
71947 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71948 pgoff_t vm_pglen;
71949@@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71950 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71951 struct vm_area_struct *prev, unsigned long addr,
71952 unsigned long end, unsigned long vm_flags,
71953- struct anon_vma *anon_vma, struct file *file,
71954+ struct anon_vma *anon_vma, struct file *file,
71955 pgoff_t pgoff, struct mempolicy *policy)
71956 {
71957 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71958 struct vm_area_struct *area, *next;
71959 int err;
71960
71961+#ifdef CONFIG_PAX_SEGMEXEC
71962+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
71963+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
71964+
71965+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
71966+#endif
71967+
71968 /*
71969 * We later require that vma->vm_flags == vm_flags,
71970 * so this tests vma->vm_flags & VM_SPECIAL, too.
71971@@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71972 if (next && next->vm_end == end) /* cases 6, 7, 8 */
71973 next = next->vm_next;
71974
71975+#ifdef CONFIG_PAX_SEGMEXEC
71976+ if (prev)
71977+ prev_m = pax_find_mirror_vma(prev);
71978+ if (area)
71979+ area_m = pax_find_mirror_vma(area);
71980+ if (next)
71981+ next_m = pax_find_mirror_vma(next);
71982+#endif
71983+
71984 /*
71985 * Can it merge with the predecessor?
71986 */
71987@@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71988 /* cases 1, 6 */
71989 err = vma_adjust(prev, prev->vm_start,
71990 next->vm_end, prev->vm_pgoff, NULL);
71991- } else /* cases 2, 5, 7 */
71992+
71993+#ifdef CONFIG_PAX_SEGMEXEC
71994+ if (!err && prev_m)
71995+ err = vma_adjust(prev_m, prev_m->vm_start,
71996+ next_m->vm_end, prev_m->vm_pgoff, NULL);
71997+#endif
71998+
71999+ } else { /* cases 2, 5, 7 */
72000 err = vma_adjust(prev, prev->vm_start,
72001 end, prev->vm_pgoff, NULL);
72002+
72003+#ifdef CONFIG_PAX_SEGMEXEC
72004+ if (!err && prev_m)
72005+ err = vma_adjust(prev_m, prev_m->vm_start,
72006+ end_m, prev_m->vm_pgoff, NULL);
72007+#endif
72008+
72009+ }
72010 if (err)
72011 return NULL;
72012 khugepaged_enter_vma_merge(prev);
72013@@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72014 mpol_equal(policy, vma_policy(next)) &&
72015 can_vma_merge_before(next, vm_flags,
72016 anon_vma, file, pgoff+pglen)) {
72017- if (prev && addr < prev->vm_end) /* case 4 */
72018+ if (prev && addr < prev->vm_end) { /* case 4 */
72019 err = vma_adjust(prev, prev->vm_start,
72020 addr, prev->vm_pgoff, NULL);
72021- else /* cases 3, 8 */
72022+
72023+#ifdef CONFIG_PAX_SEGMEXEC
72024+ if (!err && prev_m)
72025+ err = vma_adjust(prev_m, prev_m->vm_start,
72026+ addr_m, prev_m->vm_pgoff, NULL);
72027+#endif
72028+
72029+ } else { /* cases 3, 8 */
72030 err = vma_adjust(area, addr, next->vm_end,
72031 next->vm_pgoff - pglen, NULL);
72032+
72033+#ifdef CONFIG_PAX_SEGMEXEC
72034+ if (!err && area_m)
72035+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
72036+ next_m->vm_pgoff - pglen, NULL);
72037+#endif
72038+
72039+ }
72040 if (err)
72041 return NULL;
72042 khugepaged_enter_vma_merge(area);
72043@@ -940,14 +1020,11 @@ none:
72044 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72045 struct file *file, long pages)
72046 {
72047- const unsigned long stack_flags
72048- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72049-
72050 if (file) {
72051 mm->shared_vm += pages;
72052 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72053 mm->exec_vm += pages;
72054- } else if (flags & stack_flags)
72055+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72056 mm->stack_vm += pages;
72057 if (flags & (VM_RESERVED|VM_IO))
72058 mm->reserved_vm += pages;
72059@@ -985,7 +1062,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72060 * (the exception is when the underlying filesystem is noexec
72061 * mounted, in which case we dont add PROT_EXEC.)
72062 */
72063- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72064+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72065 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72066 prot |= PROT_EXEC;
72067
72068@@ -1011,7 +1088,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72069 /* Obtain the address to map to. we verify (or select) it and ensure
72070 * that it represents a valid section of the address space.
72071 */
72072- addr = get_unmapped_area(file, addr, len, pgoff, flags);
72073+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72074 if (addr & ~PAGE_MASK)
72075 return addr;
72076
72077@@ -1022,6 +1099,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72078 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72079 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72080
72081+#ifdef CONFIG_PAX_MPROTECT
72082+ if (mm->pax_flags & MF_PAX_MPROTECT) {
72083+#ifndef CONFIG_PAX_MPROTECT_COMPAT
72084+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72085+ gr_log_rwxmmap(file);
72086+
72087+#ifdef CONFIG_PAX_EMUPLT
72088+ vm_flags &= ~VM_EXEC;
72089+#else
72090+ return -EPERM;
72091+#endif
72092+
72093+ }
72094+
72095+ if (!(vm_flags & VM_EXEC))
72096+ vm_flags &= ~VM_MAYEXEC;
72097+#else
72098+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72099+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72100+#endif
72101+ else
72102+ vm_flags &= ~VM_MAYWRITE;
72103+ }
72104+#endif
72105+
72106+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72107+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72108+ vm_flags &= ~VM_PAGEEXEC;
72109+#endif
72110+
72111 if (flags & MAP_LOCKED)
72112 if (!can_do_mlock())
72113 return -EPERM;
72114@@ -1033,6 +1140,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72115 locked += mm->locked_vm;
72116 lock_limit = rlimit(RLIMIT_MEMLOCK);
72117 lock_limit >>= PAGE_SHIFT;
72118+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72119 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72120 return -EAGAIN;
72121 }
72122@@ -1099,6 +1207,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72123 }
72124 }
72125
72126+ if (!gr_acl_handle_mmap(file, prot))
72127+ return -EACCES;
72128+
72129 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72130 }
72131
72132@@ -1175,7 +1286,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72133 vm_flags_t vm_flags = vma->vm_flags;
72134
72135 /* If it was private or non-writable, the write bit is already clear */
72136- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72137+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72138 return 0;
72139
72140 /* The backer wishes to know when pages are first written to? */
72141@@ -1224,14 +1335,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72142 unsigned long charged = 0;
72143 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72144
72145+#ifdef CONFIG_PAX_SEGMEXEC
72146+ struct vm_area_struct *vma_m = NULL;
72147+#endif
72148+
72149+ /*
72150+ * mm->mmap_sem is required to protect against another thread
72151+ * changing the mappings in case we sleep.
72152+ */
72153+ verify_mm_writelocked(mm);
72154+
72155 /* Clear old maps */
72156 error = -ENOMEM;
72157-munmap_back:
72158 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72159 if (vma && vma->vm_start < addr + len) {
72160 if (do_munmap(mm, addr, len))
72161 return -ENOMEM;
72162- goto munmap_back;
72163+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72164+ BUG_ON(vma && vma->vm_start < addr + len);
72165 }
72166
72167 /* Check against address space limit. */
72168@@ -1280,6 +1401,16 @@ munmap_back:
72169 goto unacct_error;
72170 }
72171
72172+#ifdef CONFIG_PAX_SEGMEXEC
72173+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72174+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72175+ if (!vma_m) {
72176+ error = -ENOMEM;
72177+ goto free_vma;
72178+ }
72179+ }
72180+#endif
72181+
72182 vma->vm_mm = mm;
72183 vma->vm_start = addr;
72184 vma->vm_end = addr + len;
72185@@ -1304,6 +1435,19 @@ munmap_back:
72186 error = file->f_op->mmap(file, vma);
72187 if (error)
72188 goto unmap_and_free_vma;
72189+
72190+#ifdef CONFIG_PAX_SEGMEXEC
72191+ if (vma_m && (vm_flags & VM_EXECUTABLE))
72192+ added_exe_file_vma(mm);
72193+#endif
72194+
72195+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72196+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72197+ vma->vm_flags |= VM_PAGEEXEC;
72198+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72199+ }
72200+#endif
72201+
72202 if (vm_flags & VM_EXECUTABLE)
72203 added_exe_file_vma(mm);
72204
72205@@ -1341,6 +1485,11 @@ munmap_back:
72206 vma_link(mm, vma, prev, rb_link, rb_parent);
72207 file = vma->vm_file;
72208
72209+#ifdef CONFIG_PAX_SEGMEXEC
72210+ if (vma_m)
72211+ BUG_ON(pax_mirror_vma(vma_m, vma));
72212+#endif
72213+
72214 /* Once vma denies write, undo our temporary denial count */
72215 if (correct_wcount)
72216 atomic_inc(&inode->i_writecount);
72217@@ -1349,6 +1498,7 @@ out:
72218
72219 mm->total_vm += len >> PAGE_SHIFT;
72220 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72221+ track_exec_limit(mm, addr, addr + len, vm_flags);
72222 if (vm_flags & VM_LOCKED) {
72223 if (!mlock_vma_pages_range(vma, addr, addr + len))
72224 mm->locked_vm += (len >> PAGE_SHIFT);
72225@@ -1371,6 +1521,12 @@ unmap_and_free_vma:
72226 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72227 charged = 0;
72228 free_vma:
72229+
72230+#ifdef CONFIG_PAX_SEGMEXEC
72231+ if (vma_m)
72232+ kmem_cache_free(vm_area_cachep, vma_m);
72233+#endif
72234+
72235 kmem_cache_free(vm_area_cachep, vma);
72236 unacct_error:
72237 if (charged)
72238@@ -1378,6 +1534,44 @@ unacct_error:
72239 return error;
72240 }
72241
72242+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72243+{
72244+ if (!vma) {
72245+#ifdef CONFIG_STACK_GROWSUP
72246+ if (addr > sysctl_heap_stack_gap)
72247+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72248+ else
72249+ vma = find_vma(current->mm, 0);
72250+ if (vma && (vma->vm_flags & VM_GROWSUP))
72251+ return false;
72252+#endif
72253+ return true;
72254+ }
72255+
72256+ if (addr + len > vma->vm_start)
72257+ return false;
72258+
72259+ if (vma->vm_flags & VM_GROWSDOWN)
72260+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72261+#ifdef CONFIG_STACK_GROWSUP
72262+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72263+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72264+#endif
72265+
72266+ return true;
72267+}
72268+
72269+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72270+{
72271+ if (vma->vm_start < len)
72272+ return -ENOMEM;
72273+ if (!(vma->vm_flags & VM_GROWSDOWN))
72274+ return vma->vm_start - len;
72275+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
72276+ return vma->vm_start - len - sysctl_heap_stack_gap;
72277+ return -ENOMEM;
72278+}
72279+
72280 /* Get an address range which is currently unmapped.
72281 * For shmat() with addr=0.
72282 *
72283@@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
72284 if (flags & MAP_FIXED)
72285 return addr;
72286
72287+#ifdef CONFIG_PAX_RANDMMAP
72288+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72289+#endif
72290+
72291 if (addr) {
72292 addr = PAGE_ALIGN(addr);
72293- vma = find_vma(mm, addr);
72294- if (TASK_SIZE - len >= addr &&
72295- (!vma || addr + len <= vma->vm_start))
72296- return addr;
72297+ if (TASK_SIZE - len >= addr) {
72298+ vma = find_vma(mm, addr);
72299+ if (check_heap_stack_gap(vma, addr, len))
72300+ return addr;
72301+ }
72302 }
72303 if (len > mm->cached_hole_size) {
72304- start_addr = addr = mm->free_area_cache;
72305+ start_addr = addr = mm->free_area_cache;
72306 } else {
72307- start_addr = addr = TASK_UNMAPPED_BASE;
72308- mm->cached_hole_size = 0;
72309+ start_addr = addr = mm->mmap_base;
72310+ mm->cached_hole_size = 0;
72311 }
72312
72313 full_search:
72314@@ -1426,34 +1625,40 @@ full_search:
72315 * Start a new search - just in case we missed
72316 * some holes.
72317 */
72318- if (start_addr != TASK_UNMAPPED_BASE) {
72319- addr = TASK_UNMAPPED_BASE;
72320- start_addr = addr;
72321+ if (start_addr != mm->mmap_base) {
72322+ start_addr = addr = mm->mmap_base;
72323 mm->cached_hole_size = 0;
72324 goto full_search;
72325 }
72326 return -ENOMEM;
72327 }
72328- if (!vma || addr + len <= vma->vm_start) {
72329- /*
72330- * Remember the place where we stopped the search:
72331- */
72332- mm->free_area_cache = addr + len;
72333- return addr;
72334- }
72335+ if (check_heap_stack_gap(vma, addr, len))
72336+ break;
72337 if (addr + mm->cached_hole_size < vma->vm_start)
72338 mm->cached_hole_size = vma->vm_start - addr;
72339 addr = vma->vm_end;
72340 }
72341+
72342+ /*
72343+ * Remember the place where we stopped the search:
72344+ */
72345+ mm->free_area_cache = addr + len;
72346+ return addr;
72347 }
72348 #endif
72349
72350 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72351 {
72352+
72353+#ifdef CONFIG_PAX_SEGMEXEC
72354+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72355+ return;
72356+#endif
72357+
72358 /*
72359 * Is this a new hole at the lowest possible address?
72360 */
72361- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
72362+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
72363 mm->free_area_cache = addr;
72364 }
72365
72366@@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72367 {
72368 struct vm_area_struct *vma;
72369 struct mm_struct *mm = current->mm;
72370- unsigned long addr = addr0, start_addr;
72371+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
72372
72373 /* requested length too big for entire address space */
72374 if (len > TASK_SIZE)
72375@@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72376 if (flags & MAP_FIXED)
72377 return addr;
72378
72379+#ifdef CONFIG_PAX_RANDMMAP
72380+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72381+#endif
72382+
72383 /* requesting a specific address */
72384 if (addr) {
72385 addr = PAGE_ALIGN(addr);
72386- vma = find_vma(mm, addr);
72387- if (TASK_SIZE - len >= addr &&
72388- (!vma || addr + len <= vma->vm_start))
72389- return addr;
72390+ if (TASK_SIZE - len >= addr) {
72391+ vma = find_vma(mm, addr);
72392+ if (check_heap_stack_gap(vma, addr, len))
72393+ return addr;
72394+ }
72395 }
72396
72397 /* check if free_area_cache is useful for us */
72398@@ -1508,7 +1718,7 @@ try_again:
72399 * return with success:
72400 */
72401 vma = find_vma(mm, addr);
72402- if (!vma || addr+len <= vma->vm_start)
72403+ if (check_heap_stack_gap(vma, addr, len))
72404 /* remember the address as a hint for next time */
72405 return (mm->free_area_cache = addr);
72406
72407@@ -1517,8 +1727,8 @@ try_again:
72408 mm->cached_hole_size = vma->vm_start - addr;
72409
72410 /* try just below the current vma->vm_start */
72411- addr = vma->vm_start-len;
72412- } while (len < vma->vm_start);
72413+ addr = skip_heap_stack_gap(vma, len);
72414+ } while (!IS_ERR_VALUE(addr));
72415
72416 fail:
72417 /*
72418@@ -1541,13 +1751,21 @@ fail:
72419 * can happen with large stack limits and large mmap()
72420 * allocations.
72421 */
72422+ mm->mmap_base = TASK_UNMAPPED_BASE;
72423+
72424+#ifdef CONFIG_PAX_RANDMMAP
72425+ if (mm->pax_flags & MF_PAX_RANDMMAP)
72426+ mm->mmap_base += mm->delta_mmap;
72427+#endif
72428+
72429+ mm->free_area_cache = mm->mmap_base;
72430 mm->cached_hole_size = ~0UL;
72431- mm->free_area_cache = TASK_UNMAPPED_BASE;
72432 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72433 /*
72434 * Restore the topdown base:
72435 */
72436- mm->free_area_cache = mm->mmap_base;
72437+ mm->mmap_base = base;
72438+ mm->free_area_cache = base;
72439 mm->cached_hole_size = ~0UL;
72440
72441 return addr;
72442@@ -1556,6 +1774,12 @@ fail:
72443
72444 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72445 {
72446+
72447+#ifdef CONFIG_PAX_SEGMEXEC
72448+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72449+ return;
72450+#endif
72451+
72452 /*
72453 * Is this a new hole at the highest possible address?
72454 */
72455@@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72456 mm->free_area_cache = addr;
72457
72458 /* dont allow allocations above current base */
72459- if (mm->free_area_cache > mm->mmap_base)
72460+ if (mm->free_area_cache > mm->mmap_base) {
72461 mm->free_area_cache = mm->mmap_base;
72462+ mm->cached_hole_size = ~0UL;
72463+ }
72464 }
72465
72466 unsigned long
72467@@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
72468 return vma;
72469 }
72470
72471+#ifdef CONFIG_PAX_SEGMEXEC
72472+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72473+{
72474+ struct vm_area_struct *vma_m;
72475+
72476+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72477+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72478+ BUG_ON(vma->vm_mirror);
72479+ return NULL;
72480+ }
72481+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72482+ vma_m = vma->vm_mirror;
72483+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72484+ BUG_ON(vma->vm_file != vma_m->vm_file);
72485+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72486+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72487+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72488+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72489+ return vma_m;
72490+}
72491+#endif
72492+
72493 /*
72494 * Verify that the stack growth is acceptable and
72495 * update accounting. This is shared with both the
72496@@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72497 return -ENOMEM;
72498
72499 /* Stack limit test */
72500+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
72501 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72502 return -ENOMEM;
72503
72504@@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72505 locked = mm->locked_vm + grow;
72506 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72507 limit >>= PAGE_SHIFT;
72508+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72509 if (locked > limit && !capable(CAP_IPC_LOCK))
72510 return -ENOMEM;
72511 }
72512@@ -1719,37 +1969,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72513 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72514 * vma is the last one with address > vma->vm_end. Have to extend vma.
72515 */
72516+#ifndef CONFIG_IA64
72517+static
72518+#endif
72519 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72520 {
72521 int error;
72522+ bool locknext;
72523
72524 if (!(vma->vm_flags & VM_GROWSUP))
72525 return -EFAULT;
72526
72527+ /* Also guard against wrapping around to address 0. */
72528+ if (address < PAGE_ALIGN(address+1))
72529+ address = PAGE_ALIGN(address+1);
72530+ else
72531+ return -ENOMEM;
72532+
72533 /*
72534 * We must make sure the anon_vma is allocated
72535 * so that the anon_vma locking is not a noop.
72536 */
72537 if (unlikely(anon_vma_prepare(vma)))
72538 return -ENOMEM;
72539+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72540+ if (locknext && anon_vma_prepare(vma->vm_next))
72541+ return -ENOMEM;
72542 vma_lock_anon_vma(vma);
72543+ if (locknext)
72544+ vma_lock_anon_vma(vma->vm_next);
72545
72546 /*
72547 * vma->vm_start/vm_end cannot change under us because the caller
72548 * is required to hold the mmap_sem in read mode. We need the
72549- * anon_vma lock to serialize against concurrent expand_stacks.
72550- * Also guard against wrapping around to address 0.
72551+ * anon_vma locks to serialize against concurrent expand_stacks
72552+ * and expand_upwards.
72553 */
72554- if (address < PAGE_ALIGN(address+4))
72555- address = PAGE_ALIGN(address+4);
72556- else {
72557- vma_unlock_anon_vma(vma);
72558- return -ENOMEM;
72559- }
72560 error = 0;
72561
72562 /* Somebody else might have raced and expanded it already */
72563- if (address > vma->vm_end) {
72564+ 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)
72565+ error = -ENOMEM;
72566+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72567 unsigned long size, grow;
72568
72569 size = address - vma->vm_start;
72570@@ -1764,6 +2025,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72571 }
72572 }
72573 }
72574+ if (locknext)
72575+ vma_unlock_anon_vma(vma->vm_next);
72576 vma_unlock_anon_vma(vma);
72577 khugepaged_enter_vma_merge(vma);
72578 return error;
72579@@ -1777,6 +2040,8 @@ int expand_downwards(struct vm_area_struct *vma,
72580 unsigned long address)
72581 {
72582 int error;
72583+ bool lockprev = false;
72584+ struct vm_area_struct *prev;
72585
72586 /*
72587 * We must make sure the anon_vma is allocated
72588@@ -1790,6 +2055,15 @@ int expand_downwards(struct vm_area_struct *vma,
72589 if (error)
72590 return error;
72591
72592+ prev = vma->vm_prev;
72593+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72594+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72595+#endif
72596+ if (lockprev && anon_vma_prepare(prev))
72597+ return -ENOMEM;
72598+ if (lockprev)
72599+ vma_lock_anon_vma(prev);
72600+
72601 vma_lock_anon_vma(vma);
72602
72603 /*
72604@@ -1799,9 +2073,17 @@ int expand_downwards(struct vm_area_struct *vma,
72605 */
72606
72607 /* Somebody else might have raced and expanded it already */
72608- if (address < vma->vm_start) {
72609+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72610+ error = -ENOMEM;
72611+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72612 unsigned long size, grow;
72613
72614+#ifdef CONFIG_PAX_SEGMEXEC
72615+ struct vm_area_struct *vma_m;
72616+
72617+ vma_m = pax_find_mirror_vma(vma);
72618+#endif
72619+
72620 size = vma->vm_end - address;
72621 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72622
72623@@ -1811,11 +2093,22 @@ int expand_downwards(struct vm_area_struct *vma,
72624 if (!error) {
72625 vma->vm_start = address;
72626 vma->vm_pgoff -= grow;
72627+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72628+
72629+#ifdef CONFIG_PAX_SEGMEXEC
72630+ if (vma_m) {
72631+ vma_m->vm_start -= grow << PAGE_SHIFT;
72632+ vma_m->vm_pgoff -= grow;
72633+ }
72634+#endif
72635+
72636 perf_event_mmap(vma);
72637 }
72638 }
72639 }
72640 vma_unlock_anon_vma(vma);
72641+ if (lockprev)
72642+ vma_unlock_anon_vma(prev);
72643 khugepaged_enter_vma_merge(vma);
72644 return error;
72645 }
72646@@ -1887,6 +2180,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72647 do {
72648 long nrpages = vma_pages(vma);
72649
72650+#ifdef CONFIG_PAX_SEGMEXEC
72651+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72652+ vma = remove_vma(vma);
72653+ continue;
72654+ }
72655+#endif
72656+
72657 if (vma->vm_flags & VM_ACCOUNT)
72658 nr_accounted += nrpages;
72659 mm->total_vm -= nrpages;
72660@@ -1933,6 +2233,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72661 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72662 vma->vm_prev = NULL;
72663 do {
72664+
72665+#ifdef CONFIG_PAX_SEGMEXEC
72666+ if (vma->vm_mirror) {
72667+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72668+ vma->vm_mirror->vm_mirror = NULL;
72669+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
72670+ vma->vm_mirror = NULL;
72671+ }
72672+#endif
72673+
72674 rb_erase(&vma->vm_rb, &mm->mm_rb);
72675 mm->map_count--;
72676 tail_vma = vma;
72677@@ -1961,14 +2271,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72678 struct vm_area_struct *new;
72679 int err = -ENOMEM;
72680
72681+#ifdef CONFIG_PAX_SEGMEXEC
72682+ struct vm_area_struct *vma_m, *new_m = NULL;
72683+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72684+#endif
72685+
72686 if (is_vm_hugetlb_page(vma) && (addr &
72687 ~(huge_page_mask(hstate_vma(vma)))))
72688 return -EINVAL;
72689
72690+#ifdef CONFIG_PAX_SEGMEXEC
72691+ vma_m = pax_find_mirror_vma(vma);
72692+#endif
72693+
72694 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72695 if (!new)
72696 goto out_err;
72697
72698+#ifdef CONFIG_PAX_SEGMEXEC
72699+ if (vma_m) {
72700+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72701+ if (!new_m) {
72702+ kmem_cache_free(vm_area_cachep, new);
72703+ goto out_err;
72704+ }
72705+ }
72706+#endif
72707+
72708 /* most fields are the same, copy all, and then fixup */
72709 *new = *vma;
72710
72711@@ -1981,6 +2310,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72712 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72713 }
72714
72715+#ifdef CONFIG_PAX_SEGMEXEC
72716+ if (vma_m) {
72717+ *new_m = *vma_m;
72718+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
72719+ new_m->vm_mirror = new;
72720+ new->vm_mirror = new_m;
72721+
72722+ if (new_below)
72723+ new_m->vm_end = addr_m;
72724+ else {
72725+ new_m->vm_start = addr_m;
72726+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72727+ }
72728+ }
72729+#endif
72730+
72731 pol = mpol_dup(vma_policy(vma));
72732 if (IS_ERR(pol)) {
72733 err = PTR_ERR(pol);
72734@@ -2006,6 +2351,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72735 else
72736 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72737
72738+#ifdef CONFIG_PAX_SEGMEXEC
72739+ if (!err && vma_m) {
72740+ if (anon_vma_clone(new_m, vma_m))
72741+ goto out_free_mpol;
72742+
72743+ mpol_get(pol);
72744+ vma_set_policy(new_m, pol);
72745+
72746+ if (new_m->vm_file) {
72747+ get_file(new_m->vm_file);
72748+ if (vma_m->vm_flags & VM_EXECUTABLE)
72749+ added_exe_file_vma(mm);
72750+ }
72751+
72752+ if (new_m->vm_ops && new_m->vm_ops->open)
72753+ new_m->vm_ops->open(new_m);
72754+
72755+ if (new_below)
72756+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72757+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72758+ else
72759+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72760+
72761+ if (err) {
72762+ if (new_m->vm_ops && new_m->vm_ops->close)
72763+ new_m->vm_ops->close(new_m);
72764+ if (new_m->vm_file) {
72765+ if (vma_m->vm_flags & VM_EXECUTABLE)
72766+ removed_exe_file_vma(mm);
72767+ fput(new_m->vm_file);
72768+ }
72769+ mpol_put(pol);
72770+ }
72771+ }
72772+#endif
72773+
72774 /* Success. */
72775 if (!err)
72776 return 0;
72777@@ -2018,10 +2399,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72778 removed_exe_file_vma(mm);
72779 fput(new->vm_file);
72780 }
72781- unlink_anon_vmas(new);
72782 out_free_mpol:
72783 mpol_put(pol);
72784 out_free_vma:
72785+
72786+#ifdef CONFIG_PAX_SEGMEXEC
72787+ if (new_m) {
72788+ unlink_anon_vmas(new_m);
72789+ kmem_cache_free(vm_area_cachep, new_m);
72790+ }
72791+#endif
72792+
72793+ unlink_anon_vmas(new);
72794 kmem_cache_free(vm_area_cachep, new);
72795 out_err:
72796 return err;
72797@@ -2034,6 +2423,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72798 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72799 unsigned long addr, int new_below)
72800 {
72801+
72802+#ifdef CONFIG_PAX_SEGMEXEC
72803+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72804+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72805+ if (mm->map_count >= sysctl_max_map_count-1)
72806+ return -ENOMEM;
72807+ } else
72808+#endif
72809+
72810 if (mm->map_count >= sysctl_max_map_count)
72811 return -ENOMEM;
72812
72813@@ -2045,11 +2443,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72814 * work. This now handles partial unmappings.
72815 * Jeremy Fitzhardinge <jeremy@goop.org>
72816 */
72817+#ifdef CONFIG_PAX_SEGMEXEC
72818 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72819 {
72820+ int ret = __do_munmap(mm, start, len);
72821+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72822+ return ret;
72823+
72824+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72825+}
72826+
72827+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72828+#else
72829+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72830+#endif
72831+{
72832 unsigned long end;
72833 struct vm_area_struct *vma, *prev, *last;
72834
72835+ /*
72836+ * mm->mmap_sem is required to protect against another thread
72837+ * changing the mappings in case we sleep.
72838+ */
72839+ verify_mm_writelocked(mm);
72840+
72841 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72842 return -EINVAL;
72843
72844@@ -2124,6 +2541,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72845 /* Fix up all other VM information */
72846 remove_vma_list(mm, vma);
72847
72848+ track_exec_limit(mm, start, end, 0UL);
72849+
72850 return 0;
72851 }
72852
72853@@ -2132,6 +2551,13 @@ int vm_munmap(unsigned long start, size_t len)
72854 int ret;
72855 struct mm_struct *mm = current->mm;
72856
72857+
72858+#ifdef CONFIG_PAX_SEGMEXEC
72859+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72860+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
72861+ return -EINVAL;
72862+#endif
72863+
72864 down_write(&mm->mmap_sem);
72865 ret = do_munmap(mm, start, len);
72866 up_write(&mm->mmap_sem);
72867@@ -2145,16 +2571,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72868 return vm_munmap(addr, len);
72869 }
72870
72871-static inline void verify_mm_writelocked(struct mm_struct *mm)
72872-{
72873-#ifdef CONFIG_DEBUG_VM
72874- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72875- WARN_ON(1);
72876- up_read(&mm->mmap_sem);
72877- }
72878-#endif
72879-}
72880-
72881 /*
72882 * this is really a simplified "do_mmap". it only handles
72883 * anonymous maps. eventually we may be able to do some
72884@@ -2168,6 +2584,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72885 struct rb_node ** rb_link, * rb_parent;
72886 pgoff_t pgoff = addr >> PAGE_SHIFT;
72887 int error;
72888+ unsigned long charged;
72889
72890 len = PAGE_ALIGN(len);
72891 if (!len)
72892@@ -2175,16 +2592,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72893
72894 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72895
72896+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72897+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72898+ flags &= ~VM_EXEC;
72899+
72900+#ifdef CONFIG_PAX_MPROTECT
72901+ if (mm->pax_flags & MF_PAX_MPROTECT)
72902+ flags &= ~VM_MAYEXEC;
72903+#endif
72904+
72905+ }
72906+#endif
72907+
72908 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72909 if (error & ~PAGE_MASK)
72910 return error;
72911
72912+ charged = len >> PAGE_SHIFT;
72913+
72914 /*
72915 * mlock MCL_FUTURE?
72916 */
72917 if (mm->def_flags & VM_LOCKED) {
72918 unsigned long locked, lock_limit;
72919- locked = len >> PAGE_SHIFT;
72920+ locked = charged;
72921 locked += mm->locked_vm;
72922 lock_limit = rlimit(RLIMIT_MEMLOCK);
72923 lock_limit >>= PAGE_SHIFT;
72924@@ -2201,22 +2632,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72925 /*
72926 * Clear old maps. this also does some error checking for us
72927 */
72928- munmap_back:
72929 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72930 if (vma && vma->vm_start < addr + len) {
72931 if (do_munmap(mm, addr, len))
72932 return -ENOMEM;
72933- goto munmap_back;
72934- }
72935+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72936+ BUG_ON(vma && vma->vm_start < addr + len);
72937+ }
72938
72939 /* Check against address space limits *after* clearing old maps... */
72940- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72941+ if (!may_expand_vm(mm, charged))
72942 return -ENOMEM;
72943
72944 if (mm->map_count > sysctl_max_map_count)
72945 return -ENOMEM;
72946
72947- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
72948+ if (security_vm_enough_memory_mm(mm, charged))
72949 return -ENOMEM;
72950
72951 /* Can we just expand an old private anonymous mapping? */
72952@@ -2230,7 +2661,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72953 */
72954 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72955 if (!vma) {
72956- vm_unacct_memory(len >> PAGE_SHIFT);
72957+ vm_unacct_memory(charged);
72958 return -ENOMEM;
72959 }
72960
72961@@ -2244,11 +2675,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72962 vma_link(mm, vma, prev, rb_link, rb_parent);
72963 out:
72964 perf_event_mmap(vma);
72965- mm->total_vm += len >> PAGE_SHIFT;
72966+ mm->total_vm += charged;
72967 if (flags & VM_LOCKED) {
72968 if (!mlock_vma_pages_range(vma, addr, addr + len))
72969- mm->locked_vm += (len >> PAGE_SHIFT);
72970+ mm->locked_vm += charged;
72971 }
72972+ track_exec_limit(mm, addr, addr + len, flags);
72973 return addr;
72974 }
72975
72976@@ -2306,6 +2738,7 @@ void exit_mmap(struct mm_struct *mm)
72977 while (vma) {
72978 if (vma->vm_flags & VM_ACCOUNT)
72979 nr_accounted += vma_pages(vma);
72980+ vma->vm_mirror = NULL;
72981 vma = remove_vma(vma);
72982 }
72983 vm_unacct_memory(nr_accounted);
72984@@ -2322,6 +2755,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72985 struct vm_area_struct * __vma, * prev;
72986 struct rb_node ** rb_link, * rb_parent;
72987
72988+#ifdef CONFIG_PAX_SEGMEXEC
72989+ struct vm_area_struct *vma_m = NULL;
72990+#endif
72991+
72992+ if (security_mmap_addr(vma->vm_start))
72993+ return -EPERM;
72994+
72995 /*
72996 * The vm_pgoff of a purely anonymous vma should be irrelevant
72997 * until its first write fault, when page's anon_vma and index
72998@@ -2348,7 +2788,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72999 if (vma->vm_file && uprobe_mmap(vma))
73000 return -EINVAL;
73001
73002+#ifdef CONFIG_PAX_SEGMEXEC
73003+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73004+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73005+ if (!vma_m)
73006+ return -ENOMEM;
73007+ }
73008+#endif
73009+
73010 vma_link(mm, vma, prev, rb_link, rb_parent);
73011+
73012+#ifdef CONFIG_PAX_SEGMEXEC
73013+ if (vma_m)
73014+ BUG_ON(pax_mirror_vma(vma_m, vma));
73015+#endif
73016+
73017 return 0;
73018 }
73019
73020@@ -2367,6 +2821,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73021 struct mempolicy *pol;
73022 bool faulted_in_anon_vma = true;
73023
73024+ BUG_ON(vma->vm_mirror);
73025+
73026 /*
73027 * If anonymous vma has not yet been faulted, update new pgoff
73028 * to match new location, to increase its chance of merging.
73029@@ -2438,6 +2894,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73030 return NULL;
73031 }
73032
73033+#ifdef CONFIG_PAX_SEGMEXEC
73034+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73035+{
73036+ struct vm_area_struct *prev_m;
73037+ struct rb_node **rb_link_m, *rb_parent_m;
73038+ struct mempolicy *pol_m;
73039+
73040+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73041+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73042+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73043+ *vma_m = *vma;
73044+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73045+ if (anon_vma_clone(vma_m, vma))
73046+ return -ENOMEM;
73047+ pol_m = vma_policy(vma_m);
73048+ mpol_get(pol_m);
73049+ vma_set_policy(vma_m, pol_m);
73050+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73051+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73052+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73053+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73054+ if (vma_m->vm_file)
73055+ get_file(vma_m->vm_file);
73056+ if (vma_m->vm_ops && vma_m->vm_ops->open)
73057+ vma_m->vm_ops->open(vma_m);
73058+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73059+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73060+ vma_m->vm_mirror = vma;
73061+ vma->vm_mirror = vma_m;
73062+ return 0;
73063+}
73064+#endif
73065+
73066 /*
73067 * Return true if the calling process may expand its vm space by the passed
73068 * number of pages
73069@@ -2449,6 +2938,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73070
73071 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73072
73073+#ifdef CONFIG_PAX_RANDMMAP
73074+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73075+ cur -= mm->brk_gap;
73076+#endif
73077+
73078+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73079 if (cur + npages > lim)
73080 return 0;
73081 return 1;
73082@@ -2519,6 +3014,22 @@ int install_special_mapping(struct mm_struct *mm,
73083 vma->vm_start = addr;
73084 vma->vm_end = addr + len;
73085
73086+#ifdef CONFIG_PAX_MPROTECT
73087+ if (mm->pax_flags & MF_PAX_MPROTECT) {
73088+#ifndef CONFIG_PAX_MPROTECT_COMPAT
73089+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73090+ return -EPERM;
73091+ if (!(vm_flags & VM_EXEC))
73092+ vm_flags &= ~VM_MAYEXEC;
73093+#else
73094+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73095+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73096+#endif
73097+ else
73098+ vm_flags &= ~VM_MAYWRITE;
73099+ }
73100+#endif
73101+
73102 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73103 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73104
73105diff --git a/mm/mprotect.c b/mm/mprotect.c
73106index a409926..8b32e6d 100644
73107--- a/mm/mprotect.c
73108+++ b/mm/mprotect.c
73109@@ -23,10 +23,17 @@
73110 #include <linux/mmu_notifier.h>
73111 #include <linux/migrate.h>
73112 #include <linux/perf_event.h>
73113+
73114+#ifdef CONFIG_PAX_MPROTECT
73115+#include <linux/elf.h>
73116+#include <linux/binfmts.h>
73117+#endif
73118+
73119 #include <asm/uaccess.h>
73120 #include <asm/pgtable.h>
73121 #include <asm/cacheflush.h>
73122 #include <asm/tlbflush.h>
73123+#include <asm/mmu_context.h>
73124
73125 #ifndef pgprot_modify
73126 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73127@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73128 flush_tlb_range(vma, start, end);
73129 }
73130
73131+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73132+/* called while holding the mmap semaphor for writing except stack expansion */
73133+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73134+{
73135+ unsigned long oldlimit, newlimit = 0UL;
73136+
73137+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73138+ return;
73139+
73140+ spin_lock(&mm->page_table_lock);
73141+ oldlimit = mm->context.user_cs_limit;
73142+ if ((prot & VM_EXEC) && oldlimit < end)
73143+ /* USER_CS limit moved up */
73144+ newlimit = end;
73145+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73146+ /* USER_CS limit moved down */
73147+ newlimit = start;
73148+
73149+ if (newlimit) {
73150+ mm->context.user_cs_limit = newlimit;
73151+
73152+#ifdef CONFIG_SMP
73153+ wmb();
73154+ cpus_clear(mm->context.cpu_user_cs_mask);
73155+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73156+#endif
73157+
73158+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73159+ }
73160+ spin_unlock(&mm->page_table_lock);
73161+ if (newlimit == end) {
73162+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
73163+
73164+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
73165+ if (is_vm_hugetlb_page(vma))
73166+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73167+ else
73168+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73169+ }
73170+}
73171+#endif
73172+
73173 int
73174 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73175 unsigned long start, unsigned long end, unsigned long newflags)
73176@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73177 int error;
73178 int dirty_accountable = 0;
73179
73180+#ifdef CONFIG_PAX_SEGMEXEC
73181+ struct vm_area_struct *vma_m = NULL;
73182+ unsigned long start_m, end_m;
73183+
73184+ start_m = start + SEGMEXEC_TASK_SIZE;
73185+ end_m = end + SEGMEXEC_TASK_SIZE;
73186+#endif
73187+
73188 if (newflags == oldflags) {
73189 *pprev = vma;
73190 return 0;
73191 }
73192
73193+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73194+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73195+
73196+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73197+ return -ENOMEM;
73198+
73199+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73200+ return -ENOMEM;
73201+ }
73202+
73203 /*
73204 * If we make a private mapping writable we increase our commit;
73205 * but (without finer accounting) cannot reduce our commit if we
73206@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73207 }
73208 }
73209
73210+#ifdef CONFIG_PAX_SEGMEXEC
73211+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73212+ if (start != vma->vm_start) {
73213+ error = split_vma(mm, vma, start, 1);
73214+ if (error)
73215+ goto fail;
73216+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73217+ *pprev = (*pprev)->vm_next;
73218+ }
73219+
73220+ if (end != vma->vm_end) {
73221+ error = split_vma(mm, vma, end, 0);
73222+ if (error)
73223+ goto fail;
73224+ }
73225+
73226+ if (pax_find_mirror_vma(vma)) {
73227+ error = __do_munmap(mm, start_m, end_m - start_m);
73228+ if (error)
73229+ goto fail;
73230+ } else {
73231+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73232+ if (!vma_m) {
73233+ error = -ENOMEM;
73234+ goto fail;
73235+ }
73236+ vma->vm_flags = newflags;
73237+ error = pax_mirror_vma(vma_m, vma);
73238+ if (error) {
73239+ vma->vm_flags = oldflags;
73240+ goto fail;
73241+ }
73242+ }
73243+ }
73244+#endif
73245+
73246 /*
73247 * First try to merge with previous and/or next vma.
73248 */
73249@@ -204,9 +307,21 @@ success:
73250 * vm_flags and vm_page_prot are protected by the mmap_sem
73251 * held in write mode.
73252 */
73253+
73254+#ifdef CONFIG_PAX_SEGMEXEC
73255+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73256+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73257+#endif
73258+
73259 vma->vm_flags = newflags;
73260+
73261+#ifdef CONFIG_PAX_MPROTECT
73262+ if (mm->binfmt && mm->binfmt->handle_mprotect)
73263+ mm->binfmt->handle_mprotect(vma, newflags);
73264+#endif
73265+
73266 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73267- vm_get_page_prot(newflags));
73268+ vm_get_page_prot(vma->vm_flags));
73269
73270 if (vma_wants_writenotify(vma)) {
73271 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73272@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73273 end = start + len;
73274 if (end <= start)
73275 return -ENOMEM;
73276+
73277+#ifdef CONFIG_PAX_SEGMEXEC
73278+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73279+ if (end > SEGMEXEC_TASK_SIZE)
73280+ return -EINVAL;
73281+ } else
73282+#endif
73283+
73284+ if (end > TASK_SIZE)
73285+ return -EINVAL;
73286+
73287 if (!arch_validate_prot(prot))
73288 return -EINVAL;
73289
73290@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73291 /*
73292 * Does the application expect PROT_READ to imply PROT_EXEC:
73293 */
73294- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73295+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73296 prot |= PROT_EXEC;
73297
73298 vm_flags = calc_vm_prot_bits(prot);
73299@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73300 if (start > vma->vm_start)
73301 prev = vma;
73302
73303+#ifdef CONFIG_PAX_MPROTECT
73304+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73305+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
73306+#endif
73307+
73308 for (nstart = start ; ; ) {
73309 unsigned long newflags;
73310
73311@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73312
73313 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73314 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73315+ if (prot & (PROT_WRITE | PROT_EXEC))
73316+ gr_log_rwxmprotect(vma->vm_file);
73317+
73318+ error = -EACCES;
73319+ goto out;
73320+ }
73321+
73322+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73323 error = -EACCES;
73324 goto out;
73325 }
73326@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73327 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73328 if (error)
73329 goto out;
73330+
73331+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
73332+
73333 nstart = tmp;
73334
73335 if (nstart < prev->vm_end)
73336diff --git a/mm/mremap.c b/mm/mremap.c
73337index 21fed20..6822658 100644
73338--- a/mm/mremap.c
73339+++ b/mm/mremap.c
73340@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
73341 continue;
73342 pte = ptep_get_and_clear(mm, old_addr, old_pte);
73343 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73344+
73345+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73346+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73347+ pte = pte_exprotect(pte);
73348+#endif
73349+
73350 set_pte_at(mm, new_addr, new_pte, pte);
73351 }
73352
73353@@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
73354 if (is_vm_hugetlb_page(vma))
73355 goto Einval;
73356
73357+#ifdef CONFIG_PAX_SEGMEXEC
73358+ if (pax_find_mirror_vma(vma))
73359+ goto Einval;
73360+#endif
73361+
73362 /* We can't remap across vm area boundaries */
73363 if (old_len > vma->vm_end - addr)
73364 goto Efault;
73365@@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
73366 unsigned long ret = -EINVAL;
73367 unsigned long charged = 0;
73368 unsigned long map_flags;
73369+ unsigned long pax_task_size = TASK_SIZE;
73370
73371 if (new_addr & ~PAGE_MASK)
73372 goto out;
73373
73374- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
73375+#ifdef CONFIG_PAX_SEGMEXEC
73376+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
73377+ pax_task_size = SEGMEXEC_TASK_SIZE;
73378+#endif
73379+
73380+ pax_task_size -= PAGE_SIZE;
73381+
73382+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
73383 goto out;
73384
73385 /* Check if the location we're moving into overlaps the
73386 * old location at all, and fail if it does.
73387 */
73388- if ((new_addr <= addr) && (new_addr+new_len) > addr)
73389- goto out;
73390-
73391- if ((addr <= new_addr) && (addr+old_len) > new_addr)
73392+ if (addr + old_len > new_addr && new_addr + new_len > addr)
73393 goto out;
73394
73395 ret = do_munmap(mm, new_addr, new_len);
73396@@ -436,6 +452,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73397 struct vm_area_struct *vma;
73398 unsigned long ret = -EINVAL;
73399 unsigned long charged = 0;
73400+ unsigned long pax_task_size = TASK_SIZE;
73401
73402 down_write(&current->mm->mmap_sem);
73403
73404@@ -456,6 +473,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73405 if (!new_len)
73406 goto out;
73407
73408+#ifdef CONFIG_PAX_SEGMEXEC
73409+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
73410+ pax_task_size = SEGMEXEC_TASK_SIZE;
73411+#endif
73412+
73413+ pax_task_size -= PAGE_SIZE;
73414+
73415+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73416+ old_len > pax_task_size || addr > pax_task_size-old_len)
73417+ goto out;
73418+
73419 if (flags & MREMAP_FIXED) {
73420 if (flags & MREMAP_MAYMOVE)
73421 ret = mremap_to(addr, old_len, new_addr, new_len);
73422@@ -505,6 +533,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73423 addr + new_len);
73424 }
73425 ret = addr;
73426+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73427 goto out;
73428 }
73429 }
73430@@ -528,7 +557,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73431 goto out;
73432 }
73433
73434+ map_flags = vma->vm_flags;
73435 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73436+ if (!(ret & ~PAGE_MASK)) {
73437+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73438+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73439+ }
73440 }
73441 out:
73442 if (ret & ~PAGE_MASK)
73443diff --git a/mm/nommu.c b/mm/nommu.c
73444index d4b0c10..ed421b5 100644
73445--- a/mm/nommu.c
73446+++ b/mm/nommu.c
73447@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73448 int sysctl_overcommit_ratio = 50; /* default is 50% */
73449 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73450 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73451-int heap_stack_gap = 0;
73452
73453 atomic_long_t mmap_pages_allocated;
73454
73455@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73456 EXPORT_SYMBOL(find_vma);
73457
73458 /*
73459- * find a VMA
73460- * - we don't extend stack VMAs under NOMMU conditions
73461- */
73462-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73463-{
73464- return find_vma(mm, addr);
73465-}
73466-
73467-/*
73468 * expand a stack to a given address
73469 * - not supported under NOMMU conditions
73470 */
73471@@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73472
73473 /* most fields are the same, copy all, and then fixup */
73474 *new = *vma;
73475+ INIT_LIST_HEAD(&new->anon_vma_chain);
73476 *region = *vma->vm_region;
73477 new->vm_region = region;
73478
73479diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73480index 4a4f921..eaa5e3a 100644
73481--- a/mm/page_alloc.c
73482+++ b/mm/page_alloc.c
73483@@ -336,7 +336,7 @@ out:
73484 * This usage means that zero-order pages may not be compound.
73485 */
73486
73487-static void free_compound_page(struct page *page)
73488+void free_compound_page(struct page *page)
73489 {
73490 __free_pages_ok(page, compound_order(page));
73491 }
73492@@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73493 int i;
73494 int bad = 0;
73495
73496+#ifdef CONFIG_PAX_MEMORY_SANITIZE
73497+ unsigned long index = 1UL << order;
73498+#endif
73499+
73500 trace_mm_page_free(page, order);
73501 kmemcheck_free_shadow(page, order);
73502
73503@@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73504 debug_check_no_obj_freed(page_address(page),
73505 PAGE_SIZE << order);
73506 }
73507+
73508+#ifdef CONFIG_PAX_MEMORY_SANITIZE
73509+ for (; index; --index)
73510+ sanitize_highpage(page + index - 1);
73511+#endif
73512+
73513 arch_free_page(page, order);
73514 kernel_map_pages(page, 1 << order, 0);
73515
73516@@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73517 arch_alloc_page(page, order);
73518 kernel_map_pages(page, 1 << order, 1);
73519
73520+#ifndef CONFIG_PAX_MEMORY_SANITIZE
73521 if (gfp_flags & __GFP_ZERO)
73522 prep_zero_page(page, order, gfp_flags);
73523+#endif
73524
73525 if (order && (gfp_flags & __GFP_COMP))
73526 prep_compound_page(page, order);
73527@@ -3579,7 +3591,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73528 unsigned long pfn;
73529
73530 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73531+#ifdef CONFIG_X86_32
73532+ /* boot failures in VMware 8 on 32bit vanilla since
73533+ this change */
73534+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73535+#else
73536 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73537+#endif
73538 return 1;
73539 }
73540 return 0;
73541diff --git a/mm/percpu.c b/mm/percpu.c
73542index bb4be74..a43ea85 100644
73543--- a/mm/percpu.c
73544+++ b/mm/percpu.c
73545@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73546 static unsigned int pcpu_high_unit_cpu __read_mostly;
73547
73548 /* the address of the first chunk which starts with the kernel static area */
73549-void *pcpu_base_addr __read_mostly;
73550+void *pcpu_base_addr __read_only;
73551 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73552
73553 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73554diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73555index 926b466..b23df53 100644
73556--- a/mm/process_vm_access.c
73557+++ b/mm/process_vm_access.c
73558@@ -13,6 +13,7 @@
73559 #include <linux/uio.h>
73560 #include <linux/sched.h>
73561 #include <linux/highmem.h>
73562+#include <linux/security.h>
73563 #include <linux/ptrace.h>
73564 #include <linux/slab.h>
73565 #include <linux/syscalls.h>
73566@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73567 size_t iov_l_curr_offset = 0;
73568 ssize_t iov_len;
73569
73570+ return -ENOSYS; // PaX: until properly audited
73571+
73572 /*
73573 * Work out how many pages of struct pages we're going to need
73574 * when eventually calling get_user_pages
73575 */
73576 for (i = 0; i < riovcnt; i++) {
73577 iov_len = rvec[i].iov_len;
73578- if (iov_len > 0) {
73579- nr_pages_iov = ((unsigned long)rvec[i].iov_base
73580- + iov_len)
73581- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73582- / PAGE_SIZE + 1;
73583- nr_pages = max(nr_pages, nr_pages_iov);
73584- }
73585+ if (iov_len <= 0)
73586+ continue;
73587+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73588+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73589+ nr_pages = max(nr_pages, nr_pages_iov);
73590 }
73591
73592 if (nr_pages == 0)
73593@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73594 goto free_proc_pages;
73595 }
73596
73597+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73598+ rc = -EPERM;
73599+ goto put_task_struct;
73600+ }
73601+
73602 mm = mm_access(task, PTRACE_MODE_ATTACH);
73603 if (!mm || IS_ERR(mm)) {
73604 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73605diff --git a/mm/rmap.c b/mm/rmap.c
73606index 0f3b7cd..c5652b6 100644
73607--- a/mm/rmap.c
73608+++ b/mm/rmap.c
73609@@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73610 struct anon_vma *anon_vma = vma->anon_vma;
73611 struct anon_vma_chain *avc;
73612
73613+#ifdef CONFIG_PAX_SEGMEXEC
73614+ struct anon_vma_chain *avc_m = NULL;
73615+#endif
73616+
73617 might_sleep();
73618 if (unlikely(!anon_vma)) {
73619 struct mm_struct *mm = vma->vm_mm;
73620@@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73621 if (!avc)
73622 goto out_enomem;
73623
73624+#ifdef CONFIG_PAX_SEGMEXEC
73625+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73626+ if (!avc_m)
73627+ goto out_enomem_free_avc;
73628+#endif
73629+
73630 anon_vma = find_mergeable_anon_vma(vma);
73631 allocated = NULL;
73632 if (!anon_vma) {
73633@@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73634 /* page_table_lock to protect against threads */
73635 spin_lock(&mm->page_table_lock);
73636 if (likely(!vma->anon_vma)) {
73637+
73638+#ifdef CONFIG_PAX_SEGMEXEC
73639+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73640+
73641+ if (vma_m) {
73642+ BUG_ON(vma_m->anon_vma);
73643+ vma_m->anon_vma = anon_vma;
73644+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
73645+ avc_m = NULL;
73646+ }
73647+#endif
73648+
73649 vma->anon_vma = anon_vma;
73650 anon_vma_chain_link(vma, avc, anon_vma);
73651 allocated = NULL;
73652@@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73653
73654 if (unlikely(allocated))
73655 put_anon_vma(allocated);
73656+
73657+#ifdef CONFIG_PAX_SEGMEXEC
73658+ if (unlikely(avc_m))
73659+ anon_vma_chain_free(avc_m);
73660+#endif
73661+
73662 if (unlikely(avc))
73663 anon_vma_chain_free(avc);
73664 }
73665 return 0;
73666
73667 out_enomem_free_avc:
73668+
73669+#ifdef CONFIG_PAX_SEGMEXEC
73670+ if (avc_m)
73671+ anon_vma_chain_free(avc_m);
73672+#endif
73673+
73674 anon_vma_chain_free(avc);
73675 out_enomem:
73676 return -ENOMEM;
73677@@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
73678 * Attach the anon_vmas from src to dst.
73679 * Returns 0 on success, -ENOMEM on failure.
73680 */
73681-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73682+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73683 {
73684 struct anon_vma_chain *avc, *pavc;
73685 struct anon_vma *root = NULL;
73686@@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73687 * the corresponding VMA in the parent process is attached to.
73688 * Returns 0 on success, non-zero on failure.
73689 */
73690-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73691+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73692 {
73693 struct anon_vma_chain *avc;
73694 struct anon_vma *anon_vma;
73695diff --git a/mm/shmem.c b/mm/shmem.c
73696index bd10636..5c16d49 100644
73697--- a/mm/shmem.c
73698+++ b/mm/shmem.c
73699@@ -31,7 +31,7 @@
73700 #include <linux/export.h>
73701 #include <linux/swap.h>
73702
73703-static struct vfsmount *shm_mnt;
73704+struct vfsmount *shm_mnt;
73705
73706 #ifdef CONFIG_SHMEM
73707 /*
73708@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
73709 #define BOGO_DIRENT_SIZE 20
73710
73711 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73712-#define SHORT_SYMLINK_LEN 128
73713+#define SHORT_SYMLINK_LEN 64
73714
73715 struct shmem_xattr {
73716 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73717@@ -2590,8 +2590,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73718 int err = -ENOMEM;
73719
73720 /* Round up to L1_CACHE_BYTES to resist false sharing */
73721- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73722- L1_CACHE_BYTES), GFP_KERNEL);
73723+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73724 if (!sbinfo)
73725 return -ENOMEM;
73726
73727diff --git a/mm/slab.c b/mm/slab.c
73728index e901a36..ca479fc 100644
73729--- a/mm/slab.c
73730+++ b/mm/slab.c
73731@@ -153,7 +153,7 @@
73732
73733 /* Legal flag mask for kmem_cache_create(). */
73734 #if DEBUG
73735-# define CREATE_MASK (SLAB_RED_ZONE | \
73736+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73737 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73738 SLAB_CACHE_DMA | \
73739 SLAB_STORE_USER | \
73740@@ -161,7 +161,7 @@
73741 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73742 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73743 #else
73744-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73745+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73746 SLAB_CACHE_DMA | \
73747 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73748 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73749@@ -290,7 +290,7 @@ struct kmem_list3 {
73750 * Need this for bootstrapping a per node allocator.
73751 */
73752 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73753-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73754+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73755 #define CACHE_CACHE 0
73756 #define SIZE_AC MAX_NUMNODES
73757 #define SIZE_L3 (2 * MAX_NUMNODES)
73758@@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73759 if ((x)->max_freeable < i) \
73760 (x)->max_freeable = i; \
73761 } while (0)
73762-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73763-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73764-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73765-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73766+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73767+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73768+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73769+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73770 #else
73771 #define STATS_INC_ACTIVE(x) do { } while (0)
73772 #define STATS_DEC_ACTIVE(x) do { } while (0)
73773@@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73774 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73775 */
73776 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73777- const struct slab *slab, void *obj)
73778+ const struct slab *slab, const void *obj)
73779 {
73780 u32 offset = (obj - slab->s_mem);
73781 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73782@@ -563,12 +563,13 @@ EXPORT_SYMBOL(malloc_sizes);
73783 struct cache_names {
73784 char *name;
73785 char *name_dma;
73786+ char *name_usercopy;
73787 };
73788
73789 static struct cache_names __initdata cache_names[] = {
73790-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73791+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
73792 #include <linux/kmalloc_sizes.h>
73793- {NULL,}
73794+ {NULL}
73795 #undef CACHE
73796 };
73797
73798@@ -756,6 +757,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
73799 if (unlikely(gfpflags & GFP_DMA))
73800 return csizep->cs_dmacachep;
73801 #endif
73802+
73803+#ifdef CONFIG_PAX_USERCOPY_SLABS
73804+ if (unlikely(gfpflags & GFP_USERCOPY))
73805+ return csizep->cs_usercopycachep;
73806+#endif
73807+
73808 return csizep->cs_cachep;
73809 }
73810
73811@@ -1588,7 +1595,7 @@ void __init kmem_cache_init(void)
73812 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73813 sizes[INDEX_AC].cs_size,
73814 ARCH_KMALLOC_MINALIGN,
73815- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73816+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73817 NULL);
73818
73819 if (INDEX_AC != INDEX_L3) {
73820@@ -1596,7 +1603,7 @@ void __init kmem_cache_init(void)
73821 kmem_cache_create(names[INDEX_L3].name,
73822 sizes[INDEX_L3].cs_size,
73823 ARCH_KMALLOC_MINALIGN,
73824- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73825+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73826 NULL);
73827 }
73828
73829@@ -1614,7 +1621,7 @@ void __init kmem_cache_init(void)
73830 sizes->cs_cachep = kmem_cache_create(names->name,
73831 sizes->cs_size,
73832 ARCH_KMALLOC_MINALIGN,
73833- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73834+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73835 NULL);
73836 }
73837 #ifdef CONFIG_ZONE_DMA
73838@@ -1626,6 +1633,16 @@ void __init kmem_cache_init(void)
73839 SLAB_PANIC,
73840 NULL);
73841 #endif
73842+
73843+#ifdef CONFIG_PAX_USERCOPY_SLABS
73844+ sizes->cs_usercopycachep = kmem_cache_create(
73845+ names->name_usercopy,
73846+ sizes->cs_size,
73847+ ARCH_KMALLOC_MINALIGN,
73848+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73849+ NULL);
73850+#endif
73851+
73852 sizes++;
73853 names++;
73854 }
73855@@ -4390,10 +4407,10 @@ static int s_show(struct seq_file *m, void *p)
73856 }
73857 /* cpu stats */
73858 {
73859- unsigned long allochit = atomic_read(&cachep->allochit);
73860- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73861- unsigned long freehit = atomic_read(&cachep->freehit);
73862- unsigned long freemiss = atomic_read(&cachep->freemiss);
73863+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73864+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73865+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73866+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73867
73868 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73869 allochit, allocmiss, freehit, freemiss);
73870@@ -4652,13 +4669,68 @@ static int __init slab_proc_init(void)
73871 {
73872 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73873 #ifdef CONFIG_DEBUG_SLAB_LEAK
73874- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73875+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73876 #endif
73877 return 0;
73878 }
73879 module_init(slab_proc_init);
73880 #endif
73881
73882+bool is_usercopy_object(const void *ptr)
73883+{
73884+ struct page *page;
73885+ struct kmem_cache *cachep;
73886+
73887+ if (ZERO_OR_NULL_PTR(ptr))
73888+ return false;
73889+
73890+ if (!virt_addr_valid(ptr))
73891+ return false;
73892+
73893+ page = virt_to_head_page(ptr);
73894+
73895+ if (!PageSlab(page))
73896+ return false;
73897+
73898+ cachep = page_get_cache(page);
73899+ return cachep->flags & SLAB_USERCOPY;
73900+}
73901+
73902+#ifdef CONFIG_PAX_USERCOPY
73903+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
73904+{
73905+ struct page *page;
73906+ struct kmem_cache *cachep;
73907+ struct slab *slabp;
73908+ unsigned int objnr;
73909+ unsigned long offset;
73910+
73911+ if (ZERO_OR_NULL_PTR(ptr))
73912+ return "<null>";
73913+
73914+ if (!virt_addr_valid(ptr))
73915+ return NULL;
73916+
73917+ page = virt_to_head_page(ptr);
73918+
73919+ if (!PageSlab(page))
73920+ return NULL;
73921+
73922+ cachep = page_get_cache(page);
73923+ if (!(cachep->flags & SLAB_USERCOPY))
73924+ return cachep->name;
73925+
73926+ slabp = page_get_slab(page);
73927+ objnr = obj_to_index(cachep, slabp, ptr);
73928+ BUG_ON(objnr >= cachep->num);
73929+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73930+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73931+ return NULL;
73932+
73933+ return cachep->name;
73934+}
73935+#endif
73936+
73937 /**
73938 * ksize - get the actual amount of memory allocated for a given object
73939 * @objp: Pointer to the object
73940diff --git a/mm/slob.c b/mm/slob.c
73941index 8105be4..3c15e57 100644
73942--- a/mm/slob.c
73943+++ b/mm/slob.c
73944@@ -29,7 +29,7 @@
73945 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73946 * alloc_pages() directly, allocating compound pages so the page order
73947 * does not have to be separately tracked, and also stores the exact
73948- * allocation size in page->private so that it can be used to accurately
73949+ * allocation size in slob_page->size so that it can be used to accurately
73950 * provide ksize(). These objects are detected in kfree() because slob_page()
73951 * is false for them.
73952 *
73953@@ -58,6 +58,7 @@
73954 */
73955
73956 #include <linux/kernel.h>
73957+#include <linux/sched.h>
73958 #include <linux/slab.h>
73959 #include <linux/mm.h>
73960 #include <linux/swap.h> /* struct reclaim_state */
73961@@ -102,7 +103,8 @@ struct slob_page {
73962 unsigned long flags; /* mandatory */
73963 atomic_t _count; /* mandatory */
73964 slobidx_t units; /* free units left in page */
73965- unsigned long pad[2];
73966+ unsigned long pad[1];
73967+ unsigned long size; /* size when >=PAGE_SIZE */
73968 slob_t *free; /* first free slob_t in page */
73969 struct list_head list; /* linked list of free pages */
73970 };
73971@@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
73972 */
73973 static inline int is_slob_page(struct slob_page *sp)
73974 {
73975- return PageSlab((struct page *)sp);
73976+ return PageSlab((struct page *)sp) && !sp->size;
73977 }
73978
73979 static inline void set_slob_page(struct slob_page *sp)
73980@@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
73981
73982 static inline struct slob_page *slob_page(const void *addr)
73983 {
73984- return (struct slob_page *)virt_to_page(addr);
73985+ return (struct slob_page *)virt_to_head_page(addr);
73986 }
73987
73988 /*
73989@@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
73990 /*
73991 * Return the size of a slob block.
73992 */
73993-static slobidx_t slob_units(slob_t *s)
73994+static slobidx_t slob_units(const slob_t *s)
73995 {
73996 if (s->units > 0)
73997 return s->units;
73998@@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
73999 /*
74000 * Return the next free slob block pointer after this one.
74001 */
74002-static slob_t *slob_next(slob_t *s)
74003+static slob_t *slob_next(const slob_t *s)
74004 {
74005 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74006 slobidx_t next;
74007@@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
74008 /*
74009 * Returns true if s is the last free block in its page.
74010 */
74011-static int slob_last(slob_t *s)
74012+static int slob_last(const slob_t *s)
74013 {
74014 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74015 }
74016@@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74017 if (!page)
74018 return NULL;
74019
74020+ set_slob_page(page);
74021 return page_address(page);
74022 }
74023
74024@@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74025 if (!b)
74026 return NULL;
74027 sp = slob_page(b);
74028- set_slob_page(sp);
74029
74030 spin_lock_irqsave(&slob_lock, flags);
74031 sp->units = SLOB_UNITS(PAGE_SIZE);
74032 sp->free = b;
74033+ sp->size = 0;
74034 INIT_LIST_HEAD(&sp->list);
74035 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74036 set_slob_page_free(sp, slob_list);
74037@@ -476,10 +479,9 @@ out:
74038 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74039 */
74040
74041-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74042+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74043 {
74044- unsigned int *m;
74045- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74046+ slob_t *m;
74047 void *ret;
74048
74049 gfp &= gfp_allowed_mask;
74050@@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74051
74052 if (!m)
74053 return NULL;
74054- *m = size;
74055+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74056+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74057+ m[0].units = size;
74058+ m[1].units = align;
74059 ret = (void *)m + align;
74060
74061 trace_kmalloc_node(_RET_IP_, ret,
74062@@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74063 gfp |= __GFP_COMP;
74064 ret = slob_new_pages(gfp, order, node);
74065 if (ret) {
74066- struct page *page;
74067- page = virt_to_page(ret);
74068- page->private = size;
74069+ struct slob_page *sp;
74070+ sp = slob_page(ret);
74071+ sp->size = size;
74072 }
74073
74074 trace_kmalloc_node(_RET_IP_, ret,
74075 size, PAGE_SIZE << order, gfp, node);
74076 }
74077
74078- kmemleak_alloc(ret, size, 1, gfp);
74079+ return ret;
74080+}
74081+
74082+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74083+{
74084+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74085+ void *ret = __kmalloc_node_align(size, gfp, node, align);
74086+
74087+ if (!ZERO_OR_NULL_PTR(ret))
74088+ kmemleak_alloc(ret, size, 1, gfp);
74089 return ret;
74090 }
74091 EXPORT_SYMBOL(__kmalloc_node);
74092@@ -533,13 +547,83 @@ void kfree(const void *block)
74093 sp = slob_page(block);
74094 if (is_slob_page(sp)) {
74095 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74096- unsigned int *m = (unsigned int *)(block - align);
74097- slob_free(m, *m + align);
74098- } else
74099+ slob_t *m = (slob_t *)(block - align);
74100+ slob_free(m, m[0].units + align);
74101+ } else {
74102+ clear_slob_page(sp);
74103+ free_slob_page(sp);
74104+ sp->size = 0;
74105 put_page(&sp->page);
74106+ }
74107 }
74108 EXPORT_SYMBOL(kfree);
74109
74110+bool is_usercopy_object(const void *ptr)
74111+{
74112+ return false;
74113+}
74114+
74115+#ifdef CONFIG_PAX_USERCOPY
74116+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74117+{
74118+ struct slob_page *sp;
74119+ const slob_t *free;
74120+ const void *base;
74121+ unsigned long flags;
74122+
74123+ if (ZERO_OR_NULL_PTR(ptr))
74124+ return "<null>";
74125+
74126+ if (!virt_addr_valid(ptr))
74127+ return NULL;
74128+
74129+ sp = slob_page(ptr);
74130+ if (!PageSlab((struct page *)sp))
74131+ return NULL;
74132+
74133+ if (sp->size) {
74134+ base = page_address(&sp->page);
74135+ if (base <= ptr && n <= sp->size - (ptr - base))
74136+ return NULL;
74137+ return "<slob>";
74138+ }
74139+
74140+ /* some tricky double walking to find the chunk */
74141+ spin_lock_irqsave(&slob_lock, flags);
74142+ base = (void *)((unsigned long)ptr & PAGE_MASK);
74143+ free = sp->free;
74144+
74145+ while (!slob_last(free) && (void *)free <= ptr) {
74146+ base = free + slob_units(free);
74147+ free = slob_next(free);
74148+ }
74149+
74150+ while (base < (void *)free) {
74151+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74152+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
74153+ int offset;
74154+
74155+ if (ptr < base + align)
74156+ break;
74157+
74158+ offset = ptr - base - align;
74159+ if (offset >= m) {
74160+ base += size;
74161+ continue;
74162+ }
74163+
74164+ if (n > m - offset)
74165+ break;
74166+
74167+ spin_unlock_irqrestore(&slob_lock, flags);
74168+ return NULL;
74169+ }
74170+
74171+ spin_unlock_irqrestore(&slob_lock, flags);
74172+ return "<slob>";
74173+}
74174+#endif
74175+
74176 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74177 size_t ksize(const void *block)
74178 {
74179@@ -552,10 +636,10 @@ size_t ksize(const void *block)
74180 sp = slob_page(block);
74181 if (is_slob_page(sp)) {
74182 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74183- unsigned int *m = (unsigned int *)(block - align);
74184- return SLOB_UNITS(*m) * SLOB_UNIT;
74185+ slob_t *m = (slob_t *)(block - align);
74186+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74187 } else
74188- return sp->page.private;
74189+ return sp->size;
74190 }
74191 EXPORT_SYMBOL(ksize);
74192
74193@@ -571,8 +655,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74194 {
74195 struct kmem_cache *c;
74196
74197+#ifdef CONFIG_PAX_USERCOPY_SLABS
74198+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
74199+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74200+#else
74201 c = slob_alloc(sizeof(struct kmem_cache),
74202 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74203+#endif
74204
74205 if (c) {
74206 c->name = name;
74207@@ -614,17 +703,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74208
74209 lockdep_trace_alloc(flags);
74210
74211+#ifdef CONFIG_PAX_USERCOPY_SLABS
74212+ b = __kmalloc_node_align(c->size, flags, node, c->align);
74213+#else
74214 if (c->size < PAGE_SIZE) {
74215 b = slob_alloc(c->size, flags, c->align, node);
74216 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74217 SLOB_UNITS(c->size) * SLOB_UNIT,
74218 flags, node);
74219 } else {
74220+ struct slob_page *sp;
74221+
74222 b = slob_new_pages(flags, get_order(c->size), node);
74223+ sp = slob_page(b);
74224+ sp->size = c->size;
74225 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74226 PAGE_SIZE << get_order(c->size),
74227 flags, node);
74228 }
74229+#endif
74230
74231 if (c->ctor)
74232 c->ctor(b);
74233@@ -636,10 +733,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74234
74235 static void __kmem_cache_free(void *b, int size)
74236 {
74237- if (size < PAGE_SIZE)
74238+ struct slob_page *sp = slob_page(b);
74239+
74240+ if (is_slob_page(sp))
74241 slob_free(b, size);
74242- else
74243+ else {
74244+ clear_slob_page(sp);
74245+ free_slob_page(sp);
74246+ sp->size = 0;
74247 slob_free_pages(b, get_order(size));
74248+ }
74249 }
74250
74251 static void kmem_rcu_free(struct rcu_head *head)
74252@@ -652,17 +755,31 @@ static void kmem_rcu_free(struct rcu_head *head)
74253
74254 void kmem_cache_free(struct kmem_cache *c, void *b)
74255 {
74256+ int size = c->size;
74257+
74258+#ifdef CONFIG_PAX_USERCOPY_SLABS
74259+ if (size + c->align < PAGE_SIZE) {
74260+ size += c->align;
74261+ b -= c->align;
74262+ }
74263+#endif
74264+
74265 kmemleak_free_recursive(b, c->flags);
74266 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74267 struct slob_rcu *slob_rcu;
74268- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74269- slob_rcu->size = c->size;
74270+ slob_rcu = b + (size - sizeof(struct slob_rcu));
74271+ slob_rcu->size = size;
74272 call_rcu(&slob_rcu->head, kmem_rcu_free);
74273 } else {
74274- __kmem_cache_free(b, c->size);
74275+ __kmem_cache_free(b, size);
74276 }
74277
74278+#ifdef CONFIG_PAX_USERCOPY_SLABS
74279+ trace_kfree(_RET_IP_, b);
74280+#else
74281 trace_kmem_cache_free(_RET_IP_, b);
74282+#endif
74283+
74284 }
74285 EXPORT_SYMBOL(kmem_cache_free);
74286
74287diff --git a/mm/slub.c b/mm/slub.c
74288index 8c691fa..ff23a85 100644
74289--- a/mm/slub.c
74290+++ b/mm/slub.c
74291@@ -209,7 +209,7 @@ struct track {
74292
74293 enum track_item { TRACK_ALLOC, TRACK_FREE };
74294
74295-#ifdef CONFIG_SYSFS
74296+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74297 static int sysfs_slab_add(struct kmem_cache *);
74298 static int sysfs_slab_alias(struct kmem_cache *, const char *);
74299 static void sysfs_slab_remove(struct kmem_cache *);
74300@@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
74301 if (!t->addr)
74302 return;
74303
74304- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74305+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74306 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74307 #ifdef CONFIG_STACKTRACE
74308 {
74309@@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
74310
74311 page = virt_to_head_page(x);
74312
74313+ BUG_ON(!PageSlab(page));
74314+
74315 slab_free(s, page, x, _RET_IP_);
74316
74317 trace_kmem_cache_free(_RET_IP_, x);
74318@@ -2636,7 +2638,7 @@ static int slub_min_objects;
74319 * Merge control. If this is set then no merging of slab caches will occur.
74320 * (Could be removed. This was introduced to pacify the merge skeptics.)
74321 */
74322-static int slub_nomerge;
74323+static int slub_nomerge = 1;
74324
74325 /*
74326 * Calculate the order of allocation given an slab object size.
74327@@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
74328 else
74329 s->cpu_partial = 30;
74330
74331- s->refcount = 1;
74332+ atomic_set(&s->refcount, 1);
74333 #ifdef CONFIG_NUMA
74334 s->remote_node_defrag_ratio = 1000;
74335 #endif
74336@@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
74337 void kmem_cache_destroy(struct kmem_cache *s)
74338 {
74339 down_write(&slub_lock);
74340- s->refcount--;
74341- if (!s->refcount) {
74342+ if (atomic_dec_and_test(&s->refcount)) {
74343 list_del(&s->list);
74344 up_write(&slub_lock);
74345 if (kmem_cache_close(s)) {
74346@@ -3223,6 +3224,10 @@ static struct kmem_cache *kmem_cache;
74347 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
74348 #endif
74349
74350+#ifdef CONFIG_PAX_USERCOPY_SLABS
74351+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
74352+#endif
74353+
74354 static int __init setup_slub_min_order(char *str)
74355 {
74356 get_option(&str, &slub_min_order);
74357@@ -3337,6 +3342,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
74358 return kmalloc_dma_caches[index];
74359
74360 #endif
74361+
74362+#ifdef CONFIG_PAX_USERCOPY_SLABS
74363+ if (flags & SLAB_USERCOPY)
74364+ return kmalloc_usercopy_caches[index];
74365+
74366+#endif
74367+
74368 return kmalloc_caches[index];
74369 }
74370
74371@@ -3405,6 +3417,56 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
74372 EXPORT_SYMBOL(__kmalloc_node);
74373 #endif
74374
74375+bool is_usercopy_object(const void *ptr)
74376+{
74377+ struct page *page;
74378+ struct kmem_cache *s;
74379+
74380+ if (ZERO_OR_NULL_PTR(ptr))
74381+ return false;
74382+
74383+ if (!virt_addr_valid(ptr))
74384+ return false;
74385+
74386+ page = virt_to_head_page(ptr);
74387+
74388+ if (!PageSlab(page))
74389+ return false;
74390+
74391+ s = page->slab;
74392+ return s->flags & SLAB_USERCOPY;
74393+}
74394+
74395+#ifdef CONFIG_PAX_USERCOPY
74396+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74397+{
74398+ struct page *page;
74399+ struct kmem_cache *s;
74400+ unsigned long offset;
74401+
74402+ if (ZERO_OR_NULL_PTR(ptr))
74403+ return "<null>";
74404+
74405+ if (!virt_addr_valid(ptr))
74406+ return NULL;
74407+
74408+ page = virt_to_head_page(ptr);
74409+
74410+ if (!PageSlab(page))
74411+ return NULL;
74412+
74413+ s = page->slab;
74414+ if (!(s->flags & SLAB_USERCOPY))
74415+ return s->name;
74416+
74417+ offset = (ptr - page_address(page)) % s->size;
74418+ if (offset <= s->objsize && n <= s->objsize - offset)
74419+ return NULL;
74420+
74421+ return s->name;
74422+}
74423+#endif
74424+
74425 size_t ksize(const void *object)
74426 {
74427 struct page *page;
74428@@ -3679,7 +3741,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
74429 int node;
74430
74431 list_add(&s->list, &slab_caches);
74432- s->refcount = -1;
74433+ atomic_set(&s->refcount, -1);
74434
74435 for_each_node_state(node, N_NORMAL_MEMORY) {
74436 struct kmem_cache_node *n = get_node(s, node);
74437@@ -3799,17 +3861,17 @@ void __init kmem_cache_init(void)
74438
74439 /* Caches that are not of the two-to-the-power-of size */
74440 if (KMALLOC_MIN_SIZE <= 32) {
74441- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74442+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74443 caches++;
74444 }
74445
74446 if (KMALLOC_MIN_SIZE <= 64) {
74447- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74448+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74449 caches++;
74450 }
74451
74452 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74453- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74454+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74455 caches++;
74456 }
74457
74458@@ -3851,6 +3913,22 @@ void __init kmem_cache_init(void)
74459 }
74460 }
74461 #endif
74462+
74463+#ifdef CONFIG_PAX_USERCOPY_SLABS
74464+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
74465+ struct kmem_cache *s = kmalloc_caches[i];
74466+
74467+ if (s && s->size) {
74468+ char *name = kasprintf(GFP_NOWAIT,
74469+ "usercopy-kmalloc-%d", s->objsize);
74470+
74471+ BUG_ON(!name);
74472+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
74473+ s->objsize, SLAB_USERCOPY);
74474+ }
74475+ }
74476+#endif
74477+
74478 printk(KERN_INFO
74479 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
74480 " CPUs=%d, Nodes=%d\n",
74481@@ -3877,7 +3955,7 @@ static int slab_unmergeable(struct kmem_cache *s)
74482 /*
74483 * We may have set a slab to be unmergeable during bootstrap.
74484 */
74485- if (s->refcount < 0)
74486+ if (atomic_read(&s->refcount) < 0)
74487 return 1;
74488
74489 return 0;
74490@@ -3936,7 +4014,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74491 down_write(&slub_lock);
74492 s = find_mergeable(size, align, flags, name, ctor);
74493 if (s) {
74494- s->refcount++;
74495+ atomic_inc(&s->refcount);
74496 /*
74497 * Adjust the object sizes so that we clear
74498 * the complete object on kzalloc.
74499@@ -3945,7 +4023,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74500 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74501
74502 if (sysfs_slab_alias(s, name)) {
74503- s->refcount--;
74504+ atomic_dec(&s->refcount);
74505 goto err;
74506 }
74507 up_write(&slub_lock);
74508@@ -4074,7 +4152,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74509 }
74510 #endif
74511
74512-#ifdef CONFIG_SYSFS
74513+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74514 static int count_inuse(struct page *page)
74515 {
74516 return page->inuse;
74517@@ -4461,12 +4539,12 @@ static void resiliency_test(void)
74518 validate_slab_cache(kmalloc_caches[9]);
74519 }
74520 #else
74521-#ifdef CONFIG_SYSFS
74522+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74523 static void resiliency_test(void) {};
74524 #endif
74525 #endif
74526
74527-#ifdef CONFIG_SYSFS
74528+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74529 enum slab_stat_type {
74530 SL_ALL, /* All slabs */
74531 SL_PARTIAL, /* Only partially allocated slabs */
74532@@ -4709,7 +4787,7 @@ SLAB_ATTR_RO(ctor);
74533
74534 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74535 {
74536- return sprintf(buf, "%d\n", s->refcount - 1);
74537+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74538 }
74539 SLAB_ATTR_RO(aliases);
74540
74541@@ -5280,6 +5358,7 @@ static char *create_unique_id(struct kmem_cache *s)
74542 return name;
74543 }
74544
74545+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74546 static int sysfs_slab_add(struct kmem_cache *s)
74547 {
74548 int err;
74549@@ -5342,6 +5421,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74550 kobject_del(&s->kobj);
74551 kobject_put(&s->kobj);
74552 }
74553+#endif
74554
74555 /*
74556 * Need to buffer aliases during bootup until sysfs becomes
74557@@ -5355,6 +5435,7 @@ struct saved_alias {
74558
74559 static struct saved_alias *alias_list;
74560
74561+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74562 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74563 {
74564 struct saved_alias *al;
74565@@ -5377,6 +5458,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74566 alias_list = al;
74567 return 0;
74568 }
74569+#endif
74570
74571 static int __init slab_sysfs_init(void)
74572 {
74573diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
74574index 1b7e22a..3fcd4f3 100644
74575--- a/mm/sparse-vmemmap.c
74576+++ b/mm/sparse-vmemmap.c
74577@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
74578 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74579 if (!p)
74580 return NULL;
74581- pud_populate(&init_mm, pud, p);
74582+ pud_populate_kernel(&init_mm, pud, p);
74583 }
74584 return pud;
74585 }
74586@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
74587 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74588 if (!p)
74589 return NULL;
74590- pgd_populate(&init_mm, pgd, p);
74591+ pgd_populate_kernel(&init_mm, pgd, p);
74592 }
74593 return pgd;
74594 }
74595diff --git a/mm/swap.c b/mm/swap.c
74596index 4e7e2ec..0c57830 100644
74597--- a/mm/swap.c
74598+++ b/mm/swap.c
74599@@ -30,6 +30,7 @@
74600 #include <linux/backing-dev.h>
74601 #include <linux/memcontrol.h>
74602 #include <linux/gfp.h>
74603+#include <linux/hugetlb.h>
74604
74605 #include "internal.h"
74606
74607@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
74608
74609 __page_cache_release(page);
74610 dtor = get_compound_page_dtor(page);
74611+ if (!PageHuge(page))
74612+ BUG_ON(dtor != free_compound_page);
74613 (*dtor)(page);
74614 }
74615
74616diff --git a/mm/swapfile.c b/mm/swapfile.c
74617index 71373d0..11fa7d9 100644
74618--- a/mm/swapfile.c
74619+++ b/mm/swapfile.c
74620@@ -63,7 +63,7 @@ static DEFINE_MUTEX(swapon_mutex);
74621
74622 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74623 /* Activity counter to indicate that a swapon or swapoff has occurred */
74624-static atomic_t proc_poll_event = ATOMIC_INIT(0);
74625+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74626
74627 static inline unsigned char swap_count(unsigned char ent)
74628 {
74629@@ -1663,7 +1663,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74630 }
74631 filp_close(swap_file, NULL);
74632 err = 0;
74633- atomic_inc(&proc_poll_event);
74634+ atomic_inc_unchecked(&proc_poll_event);
74635 wake_up_interruptible(&proc_poll_wait);
74636
74637 out_dput:
74638@@ -1679,8 +1679,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74639
74640 poll_wait(file, &proc_poll_wait, wait);
74641
74642- if (seq->poll_event != atomic_read(&proc_poll_event)) {
74643- seq->poll_event = atomic_read(&proc_poll_event);
74644+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74645+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74646 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74647 }
74648
74649@@ -1778,7 +1778,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74650 return ret;
74651
74652 seq = file->private_data;
74653- seq->poll_event = atomic_read(&proc_poll_event);
74654+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74655 return 0;
74656 }
74657
74658@@ -2120,7 +2120,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74659 (frontswap_map) ? "FS" : "");
74660
74661 mutex_unlock(&swapon_mutex);
74662- atomic_inc(&proc_poll_event);
74663+ atomic_inc_unchecked(&proc_poll_event);
74664 wake_up_interruptible(&proc_poll_wait);
74665
74666 if (S_ISREG(inode->i_mode))
74667diff --git a/mm/util.c b/mm/util.c
74668index 8c7265a..c96d884 100644
74669--- a/mm/util.c
74670+++ b/mm/util.c
74671@@ -285,6 +285,12 @@ done:
74672 void arch_pick_mmap_layout(struct mm_struct *mm)
74673 {
74674 mm->mmap_base = TASK_UNMAPPED_BASE;
74675+
74676+#ifdef CONFIG_PAX_RANDMMAP
74677+ if (mm->pax_flags & MF_PAX_RANDMMAP)
74678+ mm->mmap_base += mm->delta_mmap;
74679+#endif
74680+
74681 mm->get_unmapped_area = arch_get_unmapped_area;
74682 mm->unmap_area = arch_unmap_area;
74683 }
74684diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74685index 2aad499..2e608e8 100644
74686--- a/mm/vmalloc.c
74687+++ b/mm/vmalloc.c
74688@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74689
74690 pte = pte_offset_kernel(pmd, addr);
74691 do {
74692- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74693- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74694+
74695+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74696+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74697+ BUG_ON(!pte_exec(*pte));
74698+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74699+ continue;
74700+ }
74701+#endif
74702+
74703+ {
74704+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74705+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74706+ }
74707 } while (pte++, addr += PAGE_SIZE, addr != end);
74708 }
74709
74710@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74711 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74712 {
74713 pte_t *pte;
74714+ int ret = -ENOMEM;
74715
74716 /*
74717 * nr is a running index into the array which helps higher level
74718@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74719 pte = pte_alloc_kernel(pmd, addr);
74720 if (!pte)
74721 return -ENOMEM;
74722+
74723+ pax_open_kernel();
74724 do {
74725 struct page *page = pages[*nr];
74726
74727- if (WARN_ON(!pte_none(*pte)))
74728- return -EBUSY;
74729- if (WARN_ON(!page))
74730- return -ENOMEM;
74731+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74732+ if (pgprot_val(prot) & _PAGE_NX)
74733+#endif
74734+
74735+ if (WARN_ON(!pte_none(*pte))) {
74736+ ret = -EBUSY;
74737+ goto out;
74738+ }
74739+ if (WARN_ON(!page)) {
74740+ ret = -ENOMEM;
74741+ goto out;
74742+ }
74743 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74744 (*nr)++;
74745 } while (pte++, addr += PAGE_SIZE, addr != end);
74746- return 0;
74747+ ret = 0;
74748+out:
74749+ pax_close_kernel();
74750+ return ret;
74751 }
74752
74753 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74754@@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74755 pmd_t *pmd;
74756 unsigned long next;
74757
74758- pmd = pmd_alloc(&init_mm, pud, addr);
74759+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74760 if (!pmd)
74761 return -ENOMEM;
74762 do {
74763@@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
74764 pud_t *pud;
74765 unsigned long next;
74766
74767- pud = pud_alloc(&init_mm, pgd, addr);
74768+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
74769 if (!pud)
74770 return -ENOMEM;
74771 do {
74772@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74773 * and fall back on vmalloc() if that fails. Others
74774 * just put it in the vmalloc space.
74775 */
74776-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74777+#ifdef CONFIG_MODULES
74778+#ifdef MODULES_VADDR
74779 unsigned long addr = (unsigned long)x;
74780 if (addr >= MODULES_VADDR && addr < MODULES_END)
74781 return 1;
74782 #endif
74783+
74784+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74785+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74786+ return 1;
74787+#endif
74788+
74789+#endif
74790+
74791 return is_vmalloc_addr(x);
74792 }
74793
74794@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74795
74796 if (!pgd_none(*pgd)) {
74797 pud_t *pud = pud_offset(pgd, addr);
74798+#ifdef CONFIG_X86
74799+ if (!pud_large(*pud))
74800+#endif
74801 if (!pud_none(*pud)) {
74802 pmd_t *pmd = pmd_offset(pud, addr);
74803+#ifdef CONFIG_X86
74804+ if (!pmd_large(*pmd))
74805+#endif
74806 if (!pmd_none(*pmd)) {
74807 pte_t *ptep, pte;
74808
74809@@ -332,6 +372,10 @@ static void purge_vmap_area_lazy(void);
74810 static struct vmap_area *alloc_vmap_area(unsigned long size,
74811 unsigned long align,
74812 unsigned long vstart, unsigned long vend,
74813+ int node, gfp_t gfp_mask) __size_overflow(1);
74814+static struct vmap_area *alloc_vmap_area(unsigned long size,
74815+ unsigned long align,
74816+ unsigned long vstart, unsigned long vend,
74817 int node, gfp_t gfp_mask)
74818 {
74819 struct vmap_area *va;
74820@@ -1320,6 +1364,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74821 struct vm_struct *area;
74822
74823 BUG_ON(in_interrupt());
74824+
74825+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74826+ if (flags & VM_KERNEXEC) {
74827+ if (start != VMALLOC_START || end != VMALLOC_END)
74828+ return NULL;
74829+ start = (unsigned long)MODULES_EXEC_VADDR;
74830+ end = (unsigned long)MODULES_EXEC_END;
74831+ }
74832+#endif
74833+
74834 if (flags & VM_IOREMAP) {
74835 int bit = fls(size);
74836
74837@@ -1552,6 +1606,11 @@ void *vmap(struct page **pages, unsigned int count,
74838 if (count > totalram_pages)
74839 return NULL;
74840
74841+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74842+ if (!(pgprot_val(prot) & _PAGE_NX))
74843+ flags |= VM_KERNEXEC;
74844+#endif
74845+
74846 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74847 __builtin_return_address(0));
74848 if (!area)
74849@@ -1653,6 +1712,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74850 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74851 goto fail;
74852
74853+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74854+ if (!(pgprot_val(prot) & _PAGE_NX))
74855+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74856+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74857+ else
74858+#endif
74859+
74860 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74861 start, end, node, gfp_mask, caller);
74862 if (!area)
74863@@ -1826,10 +1892,9 @@ EXPORT_SYMBOL(vzalloc_node);
74864 * For tight control over page level allocator and protection flags
74865 * use __vmalloc() instead.
74866 */
74867-
74868 void *vmalloc_exec(unsigned long size)
74869 {
74870- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74871+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74872 -1, __builtin_return_address(0));
74873 }
74874
74875@@ -2124,6 +2189,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74876 unsigned long uaddr = vma->vm_start;
74877 unsigned long usize = vma->vm_end - vma->vm_start;
74878
74879+ BUG_ON(vma->vm_mirror);
74880+
74881 if ((PAGE_SIZE-1) & (unsigned long)addr)
74882 return -EINVAL;
74883
74884diff --git a/mm/vmstat.c b/mm/vmstat.c
74885index 1bbbbd9..ff35669 100644
74886--- a/mm/vmstat.c
74887+++ b/mm/vmstat.c
74888@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74889 *
74890 * vm_stat contains the global counters
74891 */
74892-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74893+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74894 EXPORT_SYMBOL(vm_stat);
74895
74896 #ifdef CONFIG_SMP
74897@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74898 v = p->vm_stat_diff[i];
74899 p->vm_stat_diff[i] = 0;
74900 local_irq_restore(flags);
74901- atomic_long_add(v, &zone->vm_stat[i]);
74902+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74903 global_diff[i] += v;
74904 #ifdef CONFIG_NUMA
74905 /* 3 seconds idle till flush */
74906@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74907
74908 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74909 if (global_diff[i])
74910- atomic_long_add(global_diff[i], &vm_stat[i]);
74911+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74912 }
74913
74914 #endif
74915@@ -1211,10 +1211,20 @@ static int __init setup_vmstat(void)
74916 start_cpu_timer(cpu);
74917 #endif
74918 #ifdef CONFIG_PROC_FS
74919- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74920- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74921- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74922- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74923+ {
74924+ mode_t gr_mode = S_IRUGO;
74925+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74926+ gr_mode = S_IRUSR;
74927+#endif
74928+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74929+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74930+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74931+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74932+#else
74933+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74934+#endif
74935+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74936+ }
74937 #endif
74938 return 0;
74939 }
74940diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74941index 9096bcb..43ed7bb 100644
74942--- a/net/8021q/vlan.c
74943+++ b/net/8021q/vlan.c
74944@@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74945 err = -EPERM;
74946 if (!capable(CAP_NET_ADMIN))
74947 break;
74948- if ((args.u.name_type >= 0) &&
74949- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74950+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74951 struct vlan_net *vn;
74952
74953 vn = net_generic(net, vlan_net_id);
74954diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74955index 6449bae..8c1f454 100644
74956--- a/net/9p/trans_fd.c
74957+++ b/net/9p/trans_fd.c
74958@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74959 oldfs = get_fs();
74960 set_fs(get_ds());
74961 /* The cast to a user pointer is valid due to the set_fs() */
74962- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
74963+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
74964 set_fs(oldfs);
74965
74966 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
74967diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
74968index 876fbe8..8bbea9f 100644
74969--- a/net/atm/atm_misc.c
74970+++ b/net/atm/atm_misc.c
74971@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
74972 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
74973 return 1;
74974 atm_return(vcc, truesize);
74975- atomic_inc(&vcc->stats->rx_drop);
74976+ atomic_inc_unchecked(&vcc->stats->rx_drop);
74977 return 0;
74978 }
74979 EXPORT_SYMBOL(atm_charge);
74980@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
74981 }
74982 }
74983 atm_return(vcc, guess);
74984- atomic_inc(&vcc->stats->rx_drop);
74985+ atomic_inc_unchecked(&vcc->stats->rx_drop);
74986 return NULL;
74987 }
74988 EXPORT_SYMBOL(atm_alloc_charge);
74989@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
74990
74991 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74992 {
74993-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74994+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74995 __SONET_ITEMS
74996 #undef __HANDLE_ITEM
74997 }
74998@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
74999
75000 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75001 {
75002-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75003+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75004 __SONET_ITEMS
75005 #undef __HANDLE_ITEM
75006 }
75007diff --git a/net/atm/lec.h b/net/atm/lec.h
75008index a86aff9..3a0d6f6 100644
75009--- a/net/atm/lec.h
75010+++ b/net/atm/lec.h
75011@@ -48,7 +48,7 @@ struct lane2_ops {
75012 const u8 *tlvs, u32 sizeoftlvs);
75013 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75014 const u8 *tlvs, u32 sizeoftlvs);
75015-};
75016+} __no_const;
75017
75018 /*
75019 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75020diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75021index 0919a88..a23d54e 100644
75022--- a/net/atm/mpc.h
75023+++ b/net/atm/mpc.h
75024@@ -33,7 +33,7 @@ struct mpoa_client {
75025 struct mpc_parameters parameters; /* parameters for this client */
75026
75027 const struct net_device_ops *old_ops;
75028- struct net_device_ops new_ops;
75029+ net_device_ops_no_const new_ops;
75030 };
75031
75032
75033diff --git a/net/atm/proc.c b/net/atm/proc.c
75034index 0d020de..011c7bb 100644
75035--- a/net/atm/proc.c
75036+++ b/net/atm/proc.c
75037@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75038 const struct k_atm_aal_stats *stats)
75039 {
75040 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75041- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75042- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75043- atomic_read(&stats->rx_drop));
75044+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75045+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75046+ atomic_read_unchecked(&stats->rx_drop));
75047 }
75048
75049 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75050diff --git a/net/atm/resources.c b/net/atm/resources.c
75051index 23f45ce..c748f1a 100644
75052--- a/net/atm/resources.c
75053+++ b/net/atm/resources.c
75054@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75055 static void copy_aal_stats(struct k_atm_aal_stats *from,
75056 struct atm_aal_stats *to)
75057 {
75058-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75059+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75060 __AAL_STAT_ITEMS
75061 #undef __HANDLE_ITEM
75062 }
75063@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75064 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75065 struct atm_aal_stats *to)
75066 {
75067-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75068+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75069 __AAL_STAT_ITEMS
75070 #undef __HANDLE_ITEM
75071 }
75072diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75073index dc53798..dc66333 100644
75074--- a/net/batman-adv/bat_iv_ogm.c
75075+++ b/net/batman-adv/bat_iv_ogm.c
75076@@ -63,7 +63,7 @@ static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
75077
75078 /* randomize initial seqno to avoid collision */
75079 get_random_bytes(&random_seqno, sizeof(random_seqno));
75080- atomic_set(&hard_iface->seqno, random_seqno);
75081+ atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75082
75083 hard_iface->packet_len = BATMAN_OGM_HLEN;
75084 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75085@@ -572,7 +572,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75086
75087 /* change sequence number to network order */
75088 batman_ogm_packet->seqno =
75089- htonl((uint32_t)atomic_read(&hard_iface->seqno));
75090+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75091
75092 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75093 batman_ogm_packet->tt_crc = htons((uint16_t)
75094@@ -592,7 +592,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75095 else
75096 batman_ogm_packet->gw_flags = NO_FLAGS;
75097
75098- atomic_inc(&hard_iface->seqno);
75099+ atomic_inc_unchecked(&hard_iface->seqno);
75100
75101 slide_own_bcast_window(hard_iface);
75102 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
75103@@ -956,7 +956,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
75104 return;
75105
75106 /* could be changed by schedule_own_packet() */
75107- if_incoming_seqno = atomic_read(&if_incoming->seqno);
75108+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75109
75110 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
75111
75112diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75113index dc334fa..766a01a 100644
75114--- a/net/batman-adv/hard-interface.c
75115+++ b/net/batman-adv/hard-interface.c
75116@@ -321,7 +321,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
75117 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75118 dev_add_pack(&hard_iface->batman_adv_ptype);
75119
75120- atomic_set(&hard_iface->frag_seqno, 1);
75121+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75122 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75123 hard_iface->net_dev->name);
75124
75125@@ -444,7 +444,7 @@ static struct hard_iface *hardif_add_interface(struct net_device *net_dev)
75126 * This can't be called via a bat_priv callback because
75127 * we have no bat_priv yet.
75128 */
75129- atomic_set(&hard_iface->seqno, 1);
75130+ atomic_set_unchecked(&hard_iface->seqno, 1);
75131 hard_iface->packet_buff = NULL;
75132
75133 return hard_iface;
75134diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75135index a0ec0e4..7beb587 100644
75136--- a/net/batman-adv/soft-interface.c
75137+++ b/net/batman-adv/soft-interface.c
75138@@ -214,7 +214,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
75139
75140 /* set broadcast sequence number */
75141 bcast_packet->seqno =
75142- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75143+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75144
75145 add_bcast_packet_to_list(bat_priv, skb, 1);
75146
75147@@ -390,7 +390,7 @@ struct net_device *softif_create(const char *name)
75148 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75149
75150 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75151- atomic_set(&bat_priv->bcast_seqno, 1);
75152+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75153 atomic_set(&bat_priv->ttvn, 0);
75154 atomic_set(&bat_priv->tt_local_changes, 0);
75155 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75156diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75157index 61308e8..2e142b2 100644
75158--- a/net/batman-adv/types.h
75159+++ b/net/batman-adv/types.h
75160@@ -38,8 +38,8 @@ struct hard_iface {
75161 int16_t if_num;
75162 char if_status;
75163 struct net_device *net_dev;
75164- atomic_t seqno;
75165- atomic_t frag_seqno;
75166+ atomic_unchecked_t seqno;
75167+ atomic_unchecked_t frag_seqno;
75168 unsigned char *packet_buff;
75169 int packet_len;
75170 struct kobject *hardif_obj;
75171@@ -163,7 +163,7 @@ struct bat_priv {
75172 atomic_t orig_interval; /* uint */
75173 atomic_t hop_penalty; /* uint */
75174 atomic_t log_level; /* uint */
75175- atomic_t bcast_seqno;
75176+ atomic_unchecked_t bcast_seqno;
75177 atomic_t bcast_queue_left;
75178 atomic_t batman_queue_left;
75179 atomic_t ttvn; /* translation table version number */
75180diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75181index 74175c2..32f8901 100644
75182--- a/net/batman-adv/unicast.c
75183+++ b/net/batman-adv/unicast.c
75184@@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
75185 frag1->flags = UNI_FRAG_HEAD | large_tail;
75186 frag2->flags = large_tail;
75187
75188- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75189+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75190 frag1->seqno = htons(seqno - 1);
75191 frag2->seqno = htons(seqno);
75192
75193diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75194index 4554e80..b778671 100644
75195--- a/net/bluetooth/l2cap_core.c
75196+++ b/net/bluetooth/l2cap_core.c
75197@@ -2798,8 +2798,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75198 break;
75199
75200 case L2CAP_CONF_RFC:
75201- if (olen == sizeof(rfc))
75202- memcpy(&rfc, (void *)val, olen);
75203+ if (olen != sizeof(rfc))
75204+ break;
75205+
75206+ memcpy(&rfc, (void *)val, olen);
75207
75208 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
75209 rfc.mode != chan->mode)
75210diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
75211index d1820ff..d414b0e 100644
75212--- a/net/bluetooth/rfcomm/tty.c
75213+++ b/net/bluetooth/rfcomm/tty.c
75214@@ -314,7 +314,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
75215 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
75216
75217 spin_lock_irqsave(&dev->port.lock, flags);
75218- if (dev->port.count > 0) {
75219+ if (atomic_read(&dev->port.count) > 0) {
75220 spin_unlock_irqrestore(&dev->port.lock, flags);
75221 return;
75222 }
75223@@ -669,10 +669,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
75224 return -ENODEV;
75225
75226 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
75227- dev->channel, dev->port.count);
75228+ dev->channel, atomic_read(&dev->port.count));
75229
75230 spin_lock_irqsave(&dev->port.lock, flags);
75231- if (++dev->port.count > 1) {
75232+ if (atomic_inc_return(&dev->port.count) > 1) {
75233 spin_unlock_irqrestore(&dev->port.lock, flags);
75234 return 0;
75235 }
75236@@ -737,10 +737,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
75237 return;
75238
75239 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
75240- dev->port.count);
75241+ atomic_read(&dev->port.count));
75242
75243 spin_lock_irqsave(&dev->port.lock, flags);
75244- if (!--dev->port.count) {
75245+ if (!atomic_dec_return(&dev->port.count)) {
75246 spin_unlock_irqrestore(&dev->port.lock, flags);
75247 if (dev->tty_dev->parent)
75248 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
75249diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
75250index 5fe2ff3..10968b5 100644
75251--- a/net/bridge/netfilter/ebtables.c
75252+++ b/net/bridge/netfilter/ebtables.c
75253@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
75254 tmp.valid_hooks = t->table->valid_hooks;
75255 }
75256 mutex_unlock(&ebt_mutex);
75257- if (copy_to_user(user, &tmp, *len) != 0){
75258+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75259 BUGPRINT("c2u Didn't work\n");
75260 ret = -EFAULT;
75261 break;
75262diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
75263index 047cd0e..461fd28 100644
75264--- a/net/caif/cfctrl.c
75265+++ b/net/caif/cfctrl.c
75266@@ -10,6 +10,7 @@
75267 #include <linux/spinlock.h>
75268 #include <linux/slab.h>
75269 #include <linux/pkt_sched.h>
75270+#include <linux/sched.h>
75271 #include <net/caif/caif_layer.h>
75272 #include <net/caif/cfpkt.h>
75273 #include <net/caif/cfctrl.h>
75274@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
75275 memset(&dev_info, 0, sizeof(dev_info));
75276 dev_info.id = 0xff;
75277 cfsrvl_init(&this->serv, 0, &dev_info, false);
75278- atomic_set(&this->req_seq_no, 1);
75279- atomic_set(&this->rsp_seq_no, 1);
75280+ atomic_set_unchecked(&this->req_seq_no, 1);
75281+ atomic_set_unchecked(&this->rsp_seq_no, 1);
75282 this->serv.layer.receive = cfctrl_recv;
75283 sprintf(this->serv.layer.name, "ctrl");
75284 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75285@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
75286 struct cfctrl_request_info *req)
75287 {
75288 spin_lock_bh(&ctrl->info_list_lock);
75289- atomic_inc(&ctrl->req_seq_no);
75290- req->sequence_no = atomic_read(&ctrl->req_seq_no);
75291+ atomic_inc_unchecked(&ctrl->req_seq_no);
75292+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75293 list_add_tail(&req->list, &ctrl->list);
75294 spin_unlock_bh(&ctrl->info_list_lock);
75295 }
75296@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
75297 if (p != first)
75298 pr_warn("Requests are not received in order\n");
75299
75300- atomic_set(&ctrl->rsp_seq_no,
75301+ atomic_set_unchecked(&ctrl->rsp_seq_no,
75302 p->sequence_no);
75303 list_del(&p->list);
75304 goto out;
75305diff --git a/net/can/gw.c b/net/can/gw.c
75306index b41acf2..3affb3a 100644
75307--- a/net/can/gw.c
75308+++ b/net/can/gw.c
75309@@ -96,7 +96,7 @@ struct cf_mod {
75310 struct {
75311 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
75312 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
75313- } csumfunc;
75314+ } __no_const csumfunc;
75315 };
75316
75317
75318diff --git a/net/compat.c b/net/compat.c
75319index 1b96281..a7e6c91 100644
75320--- a/net/compat.c
75321+++ b/net/compat.c
75322@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
75323 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
75324 __get_user(kmsg->msg_flags, &umsg->msg_flags))
75325 return -EFAULT;
75326- kmsg->msg_name = compat_ptr(tmp1);
75327- kmsg->msg_iov = compat_ptr(tmp2);
75328- kmsg->msg_control = compat_ptr(tmp3);
75329+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
75330+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
75331+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
75332 return 0;
75333 }
75334
75335@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75336
75337 if (kern_msg->msg_namelen) {
75338 if (mode == VERIFY_READ) {
75339- int err = move_addr_to_kernel(kern_msg->msg_name,
75340+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
75341 kern_msg->msg_namelen,
75342 kern_address);
75343 if (err < 0)
75344@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75345 kern_msg->msg_name = NULL;
75346
75347 tot_len = iov_from_user_compat_to_kern(kern_iov,
75348- (struct compat_iovec __user *)kern_msg->msg_iov,
75349+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
75350 kern_msg->msg_iovlen);
75351 if (tot_len >= 0)
75352 kern_msg->msg_iov = kern_iov;
75353@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75354
75355 #define CMSG_COMPAT_FIRSTHDR(msg) \
75356 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
75357- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
75358+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
75359 (struct compat_cmsghdr __user *)NULL)
75360
75361 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
75362 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
75363 (ucmlen) <= (unsigned long) \
75364 ((mhdr)->msg_controllen - \
75365- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
75366+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
75367
75368 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
75369 struct compat_cmsghdr __user *cmsg, int cmsg_len)
75370 {
75371 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
75372- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
75373+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
75374 msg->msg_controllen)
75375 return NULL;
75376 return (struct compat_cmsghdr __user *)ptr;
75377@@ -219,7 +219,7 @@ Efault:
75378
75379 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
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 struct compat_cmsghdr cmhdr;
75384 int cmlen;
75385
75386@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75387
75388 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75389 {
75390- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75391+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75392 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75393 int fdnum = scm->fp->count;
75394 struct file **fp = scm->fp->fp;
75395@@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
75396 return -EFAULT;
75397 old_fs = get_fs();
75398 set_fs(KERNEL_DS);
75399- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75400+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75401 set_fs(old_fs);
75402
75403 return err;
75404@@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75405 len = sizeof(ktime);
75406 old_fs = get_fs();
75407 set_fs(KERNEL_DS);
75408- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75409+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75410 set_fs(old_fs);
75411
75412 if (!err) {
75413@@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75414 case MCAST_JOIN_GROUP:
75415 case MCAST_LEAVE_GROUP:
75416 {
75417- struct compat_group_req __user *gr32 = (void *)optval;
75418+ struct compat_group_req __user *gr32 = (void __user *)optval;
75419 struct group_req __user *kgr =
75420 compat_alloc_user_space(sizeof(struct group_req));
75421 u32 interface;
75422@@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75423 case MCAST_BLOCK_SOURCE:
75424 case MCAST_UNBLOCK_SOURCE:
75425 {
75426- struct compat_group_source_req __user *gsr32 = (void *)optval;
75427+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75428 struct group_source_req __user *kgsr = compat_alloc_user_space(
75429 sizeof(struct group_source_req));
75430 u32 interface;
75431@@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75432 }
75433 case MCAST_MSFILTER:
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 u32 interface, fmode, numsrc;
75439
75440@@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75441 char __user *optval, int __user *optlen,
75442 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75443 {
75444- struct compat_group_filter __user *gf32 = (void *)optval;
75445+ struct compat_group_filter __user *gf32 = (void __user *)optval;
75446 struct group_filter __user *kgf;
75447 int __user *koptlen;
75448 u32 interface, fmode, numsrc;
75449diff --git a/net/core/datagram.c b/net/core/datagram.c
75450index ae6acf6..d5c8f66 100644
75451--- a/net/core/datagram.c
75452+++ b/net/core/datagram.c
75453@@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75454 }
75455
75456 kfree_skb(skb);
75457- atomic_inc(&sk->sk_drops);
75458+ atomic_inc_unchecked(&sk->sk_drops);
75459 sk_mem_reclaim_partial(sk);
75460
75461 return err;
75462diff --git a/net/core/dev.c b/net/core/dev.c
75463index 1cb0d8a..0427dd9 100644
75464--- a/net/core/dev.c
75465+++ b/net/core/dev.c
75466@@ -1135,9 +1135,13 @@ void dev_load(struct net *net, const char *name)
75467 if (no_module && capable(CAP_NET_ADMIN))
75468 no_module = request_module("netdev-%s", name);
75469 if (no_module && capable(CAP_SYS_MODULE)) {
75470+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75471+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
75472+#else
75473 if (!request_module("%s", name))
75474 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
75475 name);
75476+#endif
75477 }
75478 }
75479 EXPORT_SYMBOL(dev_load);
75480@@ -1601,7 +1605,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75481 {
75482 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75483 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
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@@ -1611,7 +1615,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75490 nf_reset(skb);
75491
75492 if (unlikely(!is_skb_forwardable(dev, skb))) {
75493- atomic_long_inc(&dev->rx_dropped);
75494+ atomic_long_inc_unchecked(&dev->rx_dropped);
75495 kfree_skb(skb);
75496 return NET_RX_DROP;
75497 }
75498@@ -2040,7 +2044,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75499
75500 struct dev_gso_cb {
75501 void (*destructor)(struct sk_buff *skb);
75502-};
75503+} __no_const;
75504
75505 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75506
75507@@ -2875,7 +2879,7 @@ enqueue:
75508
75509 local_irq_restore(flags);
75510
75511- atomic_long_inc(&skb->dev->rx_dropped);
75512+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75513 kfree_skb(skb);
75514 return NET_RX_DROP;
75515 }
75516@@ -2947,7 +2951,7 @@ int netif_rx_ni(struct sk_buff *skb)
75517 }
75518 EXPORT_SYMBOL(netif_rx_ni);
75519
75520-static void net_tx_action(struct softirq_action *h)
75521+static void net_tx_action(void)
75522 {
75523 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75524
75525@@ -3234,7 +3238,7 @@ ncls:
75526 if (pt_prev) {
75527 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75528 } else {
75529- atomic_long_inc(&skb->dev->rx_dropped);
75530+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75531 kfree_skb(skb);
75532 /* Jamal, now you will not able to escape explaining
75533 * me how you were going to use this. :-)
75534@@ -3799,7 +3803,7 @@ void netif_napi_del(struct napi_struct *napi)
75535 }
75536 EXPORT_SYMBOL(netif_napi_del);
75537
75538-static void net_rx_action(struct softirq_action *h)
75539+static void net_rx_action(void)
75540 {
75541 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75542 unsigned long time_limit = jiffies + 2;
75543@@ -4269,8 +4273,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
75544 else
75545 seq_printf(seq, "%04x", ntohs(pt->type));
75546
75547+#ifdef CONFIG_GRKERNSEC_HIDESYM
75548+ seq_printf(seq, " %-8s %p\n",
75549+ pt->dev ? pt->dev->name : "", NULL);
75550+#else
75551 seq_printf(seq, " %-8s %pF\n",
75552 pt->dev ? pt->dev->name : "", pt->func);
75553+#endif
75554 }
75555
75556 return 0;
75557@@ -5820,7 +5829,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75558 } else {
75559 netdev_stats_to_stats64(storage, &dev->stats);
75560 }
75561- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75562+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75563 return storage;
75564 }
75565 EXPORT_SYMBOL(dev_get_stats);
75566diff --git a/net/core/flow.c b/net/core/flow.c
75567index e318c7e..168b1d0 100644
75568--- a/net/core/flow.c
75569+++ b/net/core/flow.c
75570@@ -61,7 +61,7 @@ struct flow_cache {
75571 struct timer_list rnd_timer;
75572 };
75573
75574-atomic_t flow_cache_genid = ATOMIC_INIT(0);
75575+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75576 EXPORT_SYMBOL(flow_cache_genid);
75577 static struct flow_cache flow_cache_global;
75578 static struct kmem_cache *flow_cachep __read_mostly;
75579@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75580
75581 static int flow_entry_valid(struct flow_cache_entry *fle)
75582 {
75583- if (atomic_read(&flow_cache_genid) != fle->genid)
75584+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75585 return 0;
75586 if (fle->object && !fle->object->ops->check(fle->object))
75587 return 0;
75588@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75589 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75590 fcp->hash_count++;
75591 }
75592- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75593+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75594 flo = fle->object;
75595 if (!flo)
75596 goto ret_object;
75597@@ -280,7 +280,7 @@ nocache:
75598 }
75599 flo = resolver(net, key, family, dir, flo, ctx);
75600 if (fle) {
75601- fle->genid = atomic_read(&flow_cache_genid);
75602+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
75603 if (!IS_ERR(flo))
75604 fle->object = flo;
75605 else
75606diff --git a/net/core/iovec.c b/net/core/iovec.c
75607index 7e7aeb0..2a998cb 100644
75608--- a/net/core/iovec.c
75609+++ b/net/core/iovec.c
75610@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75611 if (m->msg_namelen) {
75612 if (mode == VERIFY_READ) {
75613 void __user *namep;
75614- namep = (void __user __force *) m->msg_name;
75615+ namep = (void __force_user *) m->msg_name;
75616 err = move_addr_to_kernel(namep, m->msg_namelen,
75617 address);
75618 if (err < 0)
75619@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75620 }
75621
75622 size = m->msg_iovlen * sizeof(struct iovec);
75623- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75624+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75625 return -EFAULT;
75626
75627 m->msg_iov = iov;
75628diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75629index 21318d1..7f105e4 100644
75630--- a/net/core/rtnetlink.c
75631+++ b/net/core/rtnetlink.c
75632@@ -58,7 +58,7 @@ struct rtnl_link {
75633 rtnl_doit_func doit;
75634 rtnl_dumpit_func dumpit;
75635 rtnl_calcit_func calcit;
75636-};
75637+} __no_const;
75638
75639 static DEFINE_MUTEX(rtnl_mutex);
75640
75641diff --git a/net/core/scm.c b/net/core/scm.c
75642index 611c5ef..88f6d6d 100644
75643--- a/net/core/scm.c
75644+++ b/net/core/scm.c
75645@@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
75646 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75647 {
75648 struct cmsghdr __user *cm
75649- = (__force struct cmsghdr __user *)msg->msg_control;
75650+ = (struct cmsghdr __force_user *)msg->msg_control;
75651 struct cmsghdr cmhdr;
75652 int cmlen = CMSG_LEN(len);
75653 int err;
75654@@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75655 err = -EFAULT;
75656 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75657 goto out;
75658- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75659+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75660 goto out;
75661 cmlen = CMSG_SPACE(len);
75662 if (msg->msg_controllen < cmlen)
75663@@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
75664 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75665 {
75666 struct cmsghdr __user *cm
75667- = (__force struct cmsghdr __user*)msg->msg_control;
75668+ = (struct cmsghdr __force_user *)msg->msg_control;
75669
75670 int fdmax = 0;
75671 int fdnum = scm->fp->count;
75672@@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75673 if (fdnum < fdmax)
75674 fdmax = fdnum;
75675
75676- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75677+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75678 i++, cmfptr++)
75679 {
75680 int new_fd;
75681diff --git a/net/core/sock.c b/net/core/sock.c
75682index 9e5b71f..66dec30 100644
75683--- a/net/core/sock.c
75684+++ b/net/core/sock.c
75685@@ -344,7 +344,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75686 struct sk_buff_head *list = &sk->sk_receive_queue;
75687
75688 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75689- atomic_inc(&sk->sk_drops);
75690+ atomic_inc_unchecked(&sk->sk_drops);
75691 trace_sock_rcvqueue_full(sk, skb);
75692 return -ENOMEM;
75693 }
75694@@ -354,7 +354,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75695 return err;
75696
75697 if (!sk_rmem_schedule(sk, skb->truesize)) {
75698- atomic_inc(&sk->sk_drops);
75699+ atomic_inc_unchecked(&sk->sk_drops);
75700 return -ENOBUFS;
75701 }
75702
75703@@ -374,7 +374,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75704 skb_dst_force(skb);
75705
75706 spin_lock_irqsave(&list->lock, flags);
75707- skb->dropcount = atomic_read(&sk->sk_drops);
75708+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75709 __skb_queue_tail(list, skb);
75710 spin_unlock_irqrestore(&list->lock, flags);
75711
75712@@ -394,7 +394,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75713 skb->dev = NULL;
75714
75715 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
75716- atomic_inc(&sk->sk_drops);
75717+ atomic_inc_unchecked(&sk->sk_drops);
75718 goto discard_and_relse;
75719 }
75720 if (nested)
75721@@ -412,7 +412,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75722 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75723 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
75724 bh_unlock_sock(sk);
75725- atomic_inc(&sk->sk_drops);
75726+ atomic_inc_unchecked(&sk->sk_drops);
75727 goto discard_and_relse;
75728 }
75729
75730@@ -976,7 +976,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75731 if (len > sizeof(peercred))
75732 len = sizeof(peercred);
75733 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75734- if (copy_to_user(optval, &peercred, len))
75735+ if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75736 return -EFAULT;
75737 goto lenout;
75738 }
75739@@ -989,7 +989,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75740 return -ENOTCONN;
75741 if (lv < len)
75742 return -EINVAL;
75743- if (copy_to_user(optval, address, len))
75744+ if (len > sizeof(address) || copy_to_user(optval, address, len))
75745 return -EFAULT;
75746 goto lenout;
75747 }
75748@@ -1035,7 +1035,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75749
75750 if (len > lv)
75751 len = lv;
75752- if (copy_to_user(optval, &v, len))
75753+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
75754 return -EFAULT;
75755 lenout:
75756 if (put_user(len, optlen))
75757@@ -2124,7 +2124,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75758 */
75759 smp_wmb();
75760 atomic_set(&sk->sk_refcnt, 1);
75761- atomic_set(&sk->sk_drops, 0);
75762+ atomic_set_unchecked(&sk->sk_drops, 0);
75763 }
75764 EXPORT_SYMBOL(sock_init_data);
75765
75766diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
75767index 5fd1467..8b70900 100644
75768--- a/net/core/sock_diag.c
75769+++ b/net/core/sock_diag.c
75770@@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
75771
75772 int sock_diag_check_cookie(void *sk, __u32 *cookie)
75773 {
75774+#ifndef CONFIG_GRKERNSEC_HIDESYM
75775 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
75776 cookie[1] != INET_DIAG_NOCOOKIE) &&
75777 ((u32)(unsigned long)sk != cookie[0] ||
75778 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
75779 return -ESTALE;
75780 else
75781+#endif
75782 return 0;
75783 }
75784 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
75785
75786 void sock_diag_save_cookie(void *sk, __u32 *cookie)
75787 {
75788+#ifdef CONFIG_GRKERNSEC_HIDESYM
75789+ cookie[0] = 0;
75790+ cookie[1] = 0;
75791+#else
75792 cookie[0] = (u32)(unsigned long)sk;
75793 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75794+#endif
75795 }
75796 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
75797
75798diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75799index a55eecc..dd8428c 100644
75800--- a/net/decnet/sysctl_net_decnet.c
75801+++ b/net/decnet/sysctl_net_decnet.c
75802@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75803
75804 if (len > *lenp) len = *lenp;
75805
75806- if (copy_to_user(buffer, addr, len))
75807+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
75808 return -EFAULT;
75809
75810 *lenp = len;
75811@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75812
75813 if (len > *lenp) len = *lenp;
75814
75815- if (copy_to_user(buffer, devname, len))
75816+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
75817 return -EFAULT;
75818
75819 *lenp = len;
75820diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75821index 3854411..2201a94 100644
75822--- a/net/ipv4/fib_frontend.c
75823+++ b/net/ipv4/fib_frontend.c
75824@@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75825 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75826 fib_sync_up(dev);
75827 #endif
75828- atomic_inc(&net->ipv4.dev_addr_genid);
75829+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75830 rt_cache_flush(dev_net(dev), -1);
75831 break;
75832 case NETDEV_DOWN:
75833 fib_del_ifaddr(ifa, NULL);
75834- atomic_inc(&net->ipv4.dev_addr_genid);
75835+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75836 if (ifa->ifa_dev->ifa_list == NULL) {
75837 /* Last address was deleted from this interface.
75838 * Disable IP.
75839@@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75840 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75841 fib_sync_up(dev);
75842 #endif
75843- atomic_inc(&net->ipv4.dev_addr_genid);
75844+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75845 rt_cache_flush(dev_net(dev), -1);
75846 break;
75847 case NETDEV_DOWN:
75848diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75849index e5b7182..570a90e 100644
75850--- a/net/ipv4/fib_semantics.c
75851+++ b/net/ipv4/fib_semantics.c
75852@@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75853 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75854 nh->nh_gw,
75855 nh->nh_parent->fib_scope);
75856- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75857+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75858
75859 return nh->nh_saddr;
75860 }
75861diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75862index 7880af9..70f92a3 100644
75863--- a/net/ipv4/inet_hashtables.c
75864+++ b/net/ipv4/inet_hashtables.c
75865@@ -18,12 +18,15 @@
75866 #include <linux/sched.h>
75867 #include <linux/slab.h>
75868 #include <linux/wait.h>
75869+#include <linux/security.h>
75870
75871 #include <net/inet_connection_sock.h>
75872 #include <net/inet_hashtables.h>
75873 #include <net/secure_seq.h>
75874 #include <net/ip.h>
75875
75876+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75877+
75878 /*
75879 * Allocate and initialize a new local port bind bucket.
75880 * The bindhash mutex for snum's hash chain must be held here.
75881@@ -530,6 +533,8 @@ ok:
75882 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75883 spin_unlock(&head->lock);
75884
75885+ gr_update_task_in_ip_table(current, inet_sk(sk));
75886+
75887 if (tw) {
75888 inet_twsk_deschedule(tw, death_row);
75889 while (twrefcnt) {
75890diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75891index dfba343..c827d50 100644
75892--- a/net/ipv4/inetpeer.c
75893+++ b/net/ipv4/inetpeer.c
75894@@ -487,8 +487,8 @@ relookup:
75895 if (p) {
75896 p->daddr = *daddr;
75897 atomic_set(&p->refcnt, 1);
75898- atomic_set(&p->rid, 0);
75899- atomic_set(&p->ip_id_count,
75900+ atomic_set_unchecked(&p->rid, 0);
75901+ atomic_set_unchecked(&p->ip_id_count,
75902 (daddr->family == AF_INET) ?
75903 secure_ip_id(daddr->addr.a4) :
75904 secure_ipv6_id(daddr->addr.a6));
75905diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75906index 9dbd3dd..0c59fb2 100644
75907--- a/net/ipv4/ip_fragment.c
75908+++ b/net/ipv4/ip_fragment.c
75909@@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75910 return 0;
75911
75912 start = qp->rid;
75913- end = atomic_inc_return(&peer->rid);
75914+ end = atomic_inc_return_unchecked(&peer->rid);
75915 qp->rid = end;
75916
75917 rc = qp->q.fragments && (end - start) > max;
75918diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75919index 0d11f23..2bb3f64 100644
75920--- a/net/ipv4/ip_sockglue.c
75921+++ b/net/ipv4/ip_sockglue.c
75922@@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75923 len = min_t(unsigned int, len, opt->optlen);
75924 if (put_user(len, optlen))
75925 return -EFAULT;
75926- if (copy_to_user(optval, opt->__data, len))
75927+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75928+ copy_to_user(optval, opt->__data, len))
75929 return -EFAULT;
75930 return 0;
75931 }
75932@@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75933 if (sk->sk_type != SOCK_STREAM)
75934 return -ENOPROTOOPT;
75935
75936- msg.msg_control = optval;
75937+ msg.msg_control = (void __force_kernel *)optval;
75938 msg.msg_controllen = len;
75939 msg.msg_flags = flags;
75940
75941diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75942index 67e8a6b..386764d 100644
75943--- a/net/ipv4/ipconfig.c
75944+++ b/net/ipv4/ipconfig.c
75945@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75946
75947 mm_segment_t oldfs = get_fs();
75948 set_fs(get_ds());
75949- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75950+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75951 set_fs(oldfs);
75952 return res;
75953 }
75954@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
75955
75956 mm_segment_t oldfs = get_fs();
75957 set_fs(get_ds());
75958- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75959+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75960 set_fs(oldfs);
75961 return res;
75962 }
75963@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
75964
75965 mm_segment_t oldfs = get_fs();
75966 set_fs(get_ds());
75967- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
75968+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
75969 set_fs(oldfs);
75970 return res;
75971 }
75972diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
75973index 2c00e8b..45b3bdd 100644
75974--- a/net/ipv4/ping.c
75975+++ b/net/ipv4/ping.c
75976@@ -845,7 +845,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
75977 sk_rmem_alloc_get(sp),
75978 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75979 atomic_read(&sp->sk_refcnt), sp,
75980- atomic_read(&sp->sk_drops), len);
75981+ atomic_read_unchecked(&sp->sk_drops), len);
75982 }
75983
75984 static int ping_seq_show(struct seq_file *seq, void *v)
75985diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
75986index 4032b81..625143c 100644
75987--- a/net/ipv4/raw.c
75988+++ b/net/ipv4/raw.c
75989@@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
75990 int raw_rcv(struct sock *sk, struct sk_buff *skb)
75991 {
75992 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
75993- atomic_inc(&sk->sk_drops);
75994+ atomic_inc_unchecked(&sk->sk_drops);
75995 kfree_skb(skb);
75996 return NET_RX_DROP;
75997 }
75998@@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
75999
76000 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76001 {
76002+ struct icmp_filter filter;
76003+
76004 if (optlen > sizeof(struct icmp_filter))
76005 optlen = sizeof(struct icmp_filter);
76006- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76007+ if (copy_from_user(&filter, optval, optlen))
76008 return -EFAULT;
76009+ raw_sk(sk)->filter = filter;
76010 return 0;
76011 }
76012
76013 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76014 {
76015 int len, ret = -EFAULT;
76016+ struct icmp_filter filter;
76017
76018 if (get_user(len, optlen))
76019 goto out;
76020@@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
76021 if (len > sizeof(struct icmp_filter))
76022 len = sizeof(struct icmp_filter);
76023 ret = -EFAULT;
76024- if (put_user(len, optlen) ||
76025- copy_to_user(optval, &raw_sk(sk)->filter, len))
76026+ filter = raw_sk(sk)->filter;
76027+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
76028 goto out;
76029 ret = 0;
76030 out: return ret;
76031@@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76032 sk_wmem_alloc_get(sp),
76033 sk_rmem_alloc_get(sp),
76034 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76035- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76036+ atomic_read(&sp->sk_refcnt),
76037+#ifdef CONFIG_GRKERNSEC_HIDESYM
76038+ NULL,
76039+#else
76040+ sp,
76041+#endif
76042+ atomic_read_unchecked(&sp->sk_drops));
76043 }
76044
76045 static int raw_seq_show(struct seq_file *seq, void *v)
76046diff --git a/net/ipv4/route.c b/net/ipv4/route.c
76047index 98b30d0..cfa3cf7 100644
76048--- a/net/ipv4/route.c
76049+++ b/net/ipv4/route.c
76050@@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
76051
76052 static inline int rt_genid(struct net *net)
76053 {
76054- return atomic_read(&net->ipv4.rt_genid);
76055+ return atomic_read_unchecked(&net->ipv4.rt_genid);
76056 }
76057
76058 #ifdef CONFIG_PROC_FS
76059@@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
76060 unsigned char shuffle;
76061
76062 get_random_bytes(&shuffle, sizeof(shuffle));
76063- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76064+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76065 inetpeer_invalidate_tree(AF_INET);
76066 }
76067
76068@@ -3011,7 +3011,7 @@ static int rt_fill_info(struct net *net,
76069 error = rt->dst.error;
76070 if (peer) {
76071 inet_peer_refcheck(rt->peer);
76072- id = atomic_read(&peer->ip_id_count) & 0xffff;
76073+ id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
76074 if (peer->tcp_ts_stamp) {
76075 ts = peer->tcp_ts;
76076 tsage = get_seconds() - peer->tcp_ts_stamp;
76077diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
76078index c8d28c4..e40f75a 100644
76079--- a/net/ipv4/tcp_ipv4.c
76080+++ b/net/ipv4/tcp_ipv4.c
76081@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
76082 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76083
76084
76085+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76086+extern int grsec_enable_blackhole;
76087+#endif
76088+
76089 #ifdef CONFIG_TCP_MD5SIG
76090 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
76091 __be32 daddr, __be32 saddr, const struct tcphdr *th);
76092@@ -1656,6 +1660,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
76093 return 0;
76094
76095 reset:
76096+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76097+ if (!grsec_enable_blackhole)
76098+#endif
76099 tcp_v4_send_reset(rsk, skb);
76100 discard:
76101 kfree_skb(skb);
76102@@ -1718,12 +1725,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76103 TCP_SKB_CB(skb)->sacked = 0;
76104
76105 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76106- if (!sk)
76107+ if (!sk) {
76108+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76109+ ret = 1;
76110+#endif
76111 goto no_tcp_socket;
76112-
76113+ }
76114 process:
76115- if (sk->sk_state == TCP_TIME_WAIT)
76116+ if (sk->sk_state == TCP_TIME_WAIT) {
76117+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76118+ ret = 2;
76119+#endif
76120 goto do_time_wait;
76121+ }
76122
76123 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76124 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76125@@ -1774,6 +1788,10 @@ no_tcp_socket:
76126 bad_packet:
76127 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76128 } else {
76129+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76130+ if (!grsec_enable_blackhole || (ret == 1 &&
76131+ (skb->dev->flags & IFF_LOOPBACK)))
76132+#endif
76133 tcp_v4_send_reset(NULL, skb);
76134 }
76135
76136@@ -2386,7 +2404,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
76137 0, /* non standard timer */
76138 0, /* open_requests have no inode */
76139 atomic_read(&sk->sk_refcnt),
76140+#ifdef CONFIG_GRKERNSEC_HIDESYM
76141+ NULL,
76142+#else
76143 req,
76144+#endif
76145 len);
76146 }
76147
76148@@ -2436,7 +2458,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
76149 sock_i_uid(sk),
76150 icsk->icsk_probes_out,
76151 sock_i_ino(sk),
76152- atomic_read(&sk->sk_refcnt), sk,
76153+ atomic_read(&sk->sk_refcnt),
76154+#ifdef CONFIG_GRKERNSEC_HIDESYM
76155+ NULL,
76156+#else
76157+ sk,
76158+#endif
76159 jiffies_to_clock_t(icsk->icsk_rto),
76160 jiffies_to_clock_t(icsk->icsk_ack.ato),
76161 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76162@@ -2464,7 +2491,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
76163 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
76164 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76165 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76166- atomic_read(&tw->tw_refcnt), tw, len);
76167+ atomic_read(&tw->tw_refcnt),
76168+#ifdef CONFIG_GRKERNSEC_HIDESYM
76169+ NULL,
76170+#else
76171+ tw,
76172+#endif
76173+ len);
76174 }
76175
76176 #define TMPSZ 150
76177diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
76178index b85d9fe..4b0eed9 100644
76179--- a/net/ipv4/tcp_minisocks.c
76180+++ b/net/ipv4/tcp_minisocks.c
76181@@ -27,6 +27,10 @@
76182 #include <net/inet_common.h>
76183 #include <net/xfrm.h>
76184
76185+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76186+extern int grsec_enable_blackhole;
76187+#endif
76188+
76189 int sysctl_tcp_syncookies __read_mostly = 1;
76190 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76191
76192@@ -754,6 +758,10 @@ listen_overflow:
76193
76194 embryonic_reset:
76195 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76196+
76197+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76198+ if (!grsec_enable_blackhole)
76199+#endif
76200 if (!(flg & TCP_FLAG_RST))
76201 req->rsk_ops->send_reset(sk, skb);
76202
76203diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
76204index 4526fe6..1a34e43 100644
76205--- a/net/ipv4/tcp_probe.c
76206+++ b/net/ipv4/tcp_probe.c
76207@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
76208 if (cnt + width >= len)
76209 break;
76210
76211- if (copy_to_user(buf + cnt, tbuf, width))
76212+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76213 return -EFAULT;
76214 cnt += width;
76215 }
76216diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
76217index e911e6c..d0a9356 100644
76218--- a/net/ipv4/tcp_timer.c
76219+++ b/net/ipv4/tcp_timer.c
76220@@ -22,6 +22,10 @@
76221 #include <linux/gfp.h>
76222 #include <net/tcp.h>
76223
76224+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76225+extern int grsec_lastack_retries;
76226+#endif
76227+
76228 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76229 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76230 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76231@@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
76232 }
76233 }
76234
76235+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76236+ if ((sk->sk_state == TCP_LAST_ACK) &&
76237+ (grsec_lastack_retries > 0) &&
76238+ (grsec_lastack_retries < retry_until))
76239+ retry_until = grsec_lastack_retries;
76240+#endif
76241+
76242 if (retransmits_timed_out(sk, retry_until,
76243 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76244 /* Has it gone just too far? */
76245diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
76246index eaca736..60488ae 100644
76247--- a/net/ipv4/udp.c
76248+++ b/net/ipv4/udp.c
76249@@ -87,6 +87,7 @@
76250 #include <linux/types.h>
76251 #include <linux/fcntl.h>
76252 #include <linux/module.h>
76253+#include <linux/security.h>
76254 #include <linux/socket.h>
76255 #include <linux/sockios.h>
76256 #include <linux/igmp.h>
76257@@ -110,6 +111,10 @@
76258 #include <linux/static_key.h>
76259 #include "udp_impl.h"
76260
76261+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76262+extern int grsec_enable_blackhole;
76263+#endif
76264+
76265 struct udp_table udp_table __read_mostly;
76266 EXPORT_SYMBOL(udp_table);
76267
76268@@ -568,6 +573,9 @@ found:
76269 return s;
76270 }
76271
76272+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76273+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76274+
76275 /*
76276 * This routine is called by the ICMP module when it gets some
76277 * sort of error condition. If err < 0 then the socket should
76278@@ -859,9 +867,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
76279 dport = usin->sin_port;
76280 if (dport == 0)
76281 return -EINVAL;
76282+
76283+ err = gr_search_udp_sendmsg(sk, usin);
76284+ if (err)
76285+ return err;
76286 } else {
76287 if (sk->sk_state != TCP_ESTABLISHED)
76288 return -EDESTADDRREQ;
76289+
76290+ err = gr_search_udp_sendmsg(sk, NULL);
76291+ if (err)
76292+ return err;
76293+
76294 daddr = inet->inet_daddr;
76295 dport = inet->inet_dport;
76296 /* Open fast path for connected socket.
76297@@ -1103,7 +1120,7 @@ static unsigned int first_packet_length(struct sock *sk)
76298 udp_lib_checksum_complete(skb)) {
76299 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76300 IS_UDPLITE(sk));
76301- atomic_inc(&sk->sk_drops);
76302+ atomic_inc_unchecked(&sk->sk_drops);
76303 __skb_unlink(skb, rcvq);
76304 __skb_queue_tail(&list_kill, skb);
76305 }
76306@@ -1189,6 +1206,10 @@ try_again:
76307 if (!skb)
76308 goto out;
76309
76310+ err = gr_search_udp_recvmsg(sk, skb);
76311+ if (err)
76312+ goto out_free;
76313+
76314 ulen = skb->len - sizeof(struct udphdr);
76315 copied = len;
76316 if (copied > ulen)
76317@@ -1498,7 +1519,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76318
76319 drop:
76320 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76321- atomic_inc(&sk->sk_drops);
76322+ atomic_inc_unchecked(&sk->sk_drops);
76323 kfree_skb(skb);
76324 return -1;
76325 }
76326@@ -1517,7 +1538,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76327 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76328
76329 if (!skb1) {
76330- atomic_inc(&sk->sk_drops);
76331+ atomic_inc_unchecked(&sk->sk_drops);
76332 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76333 IS_UDPLITE(sk));
76334 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76335@@ -1686,6 +1707,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76336 goto csum_error;
76337
76338 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76339+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76340+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76341+#endif
76342 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76343
76344 /*
76345@@ -2104,8 +2128,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
76346 sk_wmem_alloc_get(sp),
76347 sk_rmem_alloc_get(sp),
76348 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76349- atomic_read(&sp->sk_refcnt), sp,
76350- atomic_read(&sp->sk_drops), len);
76351+ atomic_read(&sp->sk_refcnt),
76352+#ifdef CONFIG_GRKERNSEC_HIDESYM
76353+ NULL,
76354+#else
76355+ sp,
76356+#endif
76357+ atomic_read_unchecked(&sp->sk_drops), len);
76358 }
76359
76360 int udp4_seq_show(struct seq_file *seq, void *v)
76361diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
76362index 8f6411c..5767579 100644
76363--- a/net/ipv6/addrconf.c
76364+++ b/net/ipv6/addrconf.c
76365@@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
76366 p.iph.ihl = 5;
76367 p.iph.protocol = IPPROTO_IPV6;
76368 p.iph.ttl = 64;
76369- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76370+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76371
76372 if (ops->ndo_do_ioctl) {
76373 mm_segment_t oldfs = get_fs();
76374diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76375index e6cee52..cf47476 100644
76376--- a/net/ipv6/inet6_connection_sock.c
76377+++ b/net/ipv6/inet6_connection_sock.c
76378@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76379 #ifdef CONFIG_XFRM
76380 {
76381 struct rt6_info *rt = (struct rt6_info *)dst;
76382- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76383+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76384 }
76385 #endif
76386 }
76387@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76388 #ifdef CONFIG_XFRM
76389 if (dst) {
76390 struct rt6_info *rt = (struct rt6_info *)dst;
76391- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76392+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76393 __sk_dst_reset(sk);
76394 dst = NULL;
76395 }
76396diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76397index ba6d13d..6899122 100644
76398--- a/net/ipv6/ipv6_sockglue.c
76399+++ b/net/ipv6/ipv6_sockglue.c
76400@@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76401 if (sk->sk_type != SOCK_STREAM)
76402 return -ENOPROTOOPT;
76403
76404- msg.msg_control = optval;
76405+ msg.msg_control = (void __force_kernel *)optval;
76406 msg.msg_controllen = len;
76407 msg.msg_flags = flags;
76408
76409diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76410index 93d6983..8e54c4d 100644
76411--- a/net/ipv6/raw.c
76412+++ b/net/ipv6/raw.c
76413@@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76414 {
76415 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76416 skb_checksum_complete(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@@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76423 struct raw6_sock *rp = raw6_sk(sk);
76424
76425 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, 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@@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76432
76433 if (inet->hdrincl) {
76434 if (skb_checksum_complete(skb)) {
76435- atomic_inc(&sk->sk_drops);
76436+ atomic_inc_unchecked(&sk->sk_drops);
76437 kfree_skb(skb);
76438 return NET_RX_DROP;
76439 }
76440@@ -602,7 +602,7 @@ out:
76441 return err;
76442 }
76443
76444-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76445+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76446 struct flowi6 *fl6, struct dst_entry **dstp,
76447 unsigned int flags)
76448 {
76449@@ -914,12 +914,15 @@ do_confirm:
76450 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76451 char __user *optval, int optlen)
76452 {
76453+ struct icmp6_filter filter;
76454+
76455 switch (optname) {
76456 case ICMPV6_FILTER:
76457 if (optlen > sizeof(struct icmp6_filter))
76458 optlen = sizeof(struct icmp6_filter);
76459- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76460+ if (copy_from_user(&filter, optval, optlen))
76461 return -EFAULT;
76462+ raw6_sk(sk)->filter = filter;
76463 return 0;
76464 default:
76465 return -ENOPROTOOPT;
76466@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76467 char __user *optval, int __user *optlen)
76468 {
76469 int len;
76470+ struct icmp6_filter filter;
76471
76472 switch (optname) {
76473 case ICMPV6_FILTER:
76474@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76475 len = sizeof(struct icmp6_filter);
76476 if (put_user(len, optlen))
76477 return -EFAULT;
76478- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76479+ filter = raw6_sk(sk)->filter;
76480+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
76481 return -EFAULT;
76482 return 0;
76483 default:
76484@@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76485 0, 0L, 0,
76486 sock_i_uid(sp), 0,
76487 sock_i_ino(sp),
76488- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76489+ atomic_read(&sp->sk_refcnt),
76490+#ifdef CONFIG_GRKERNSEC_HIDESYM
76491+ NULL,
76492+#else
76493+ sp,
76494+#endif
76495+ atomic_read_unchecked(&sp->sk_drops));
76496 }
76497
76498 static int raw6_seq_show(struct seq_file *seq, void *v)
76499diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76500index 9df64a5..39875da 100644
76501--- a/net/ipv6/tcp_ipv6.c
76502+++ b/net/ipv6/tcp_ipv6.c
76503@@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76504 }
76505 #endif
76506
76507+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76508+extern int grsec_enable_blackhole;
76509+#endif
76510+
76511 static void tcp_v6_hash(struct sock *sk)
76512 {
76513 if (sk->sk_state != TCP_CLOSE) {
76514@@ -1544,6 +1548,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76515 return 0;
76516
76517 reset:
76518+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76519+ if (!grsec_enable_blackhole)
76520+#endif
76521 tcp_v6_send_reset(sk, skb);
76522 discard:
76523 if (opt_skb)
76524@@ -1625,12 +1632,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76525 TCP_SKB_CB(skb)->sacked = 0;
76526
76527 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76528- if (!sk)
76529+ if (!sk) {
76530+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76531+ ret = 1;
76532+#endif
76533 goto no_tcp_socket;
76534+ }
76535
76536 process:
76537- if (sk->sk_state == TCP_TIME_WAIT)
76538+ if (sk->sk_state == TCP_TIME_WAIT) {
76539+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76540+ ret = 2;
76541+#endif
76542 goto do_time_wait;
76543+ }
76544
76545 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76546 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76547@@ -1679,6 +1694,10 @@ no_tcp_socket:
76548 bad_packet:
76549 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76550 } else {
76551+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76552+ if (!grsec_enable_blackhole || (ret == 1 &&
76553+ (skb->dev->flags & IFF_LOOPBACK)))
76554+#endif
76555 tcp_v6_send_reset(NULL, skb);
76556 }
76557
76558@@ -1885,7 +1904,13 @@ static void get_openreq6(struct seq_file *seq,
76559 uid,
76560 0, /* non standard timer */
76561 0, /* open_requests have no inode */
76562- 0, req);
76563+ 0,
76564+#ifdef CONFIG_GRKERNSEC_HIDESYM
76565+ NULL
76566+#else
76567+ req
76568+#endif
76569+ );
76570 }
76571
76572 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76573@@ -1935,7 +1960,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76574 sock_i_uid(sp),
76575 icsk->icsk_probes_out,
76576 sock_i_ino(sp),
76577- atomic_read(&sp->sk_refcnt), sp,
76578+ atomic_read(&sp->sk_refcnt),
76579+#ifdef CONFIG_GRKERNSEC_HIDESYM
76580+ NULL,
76581+#else
76582+ sp,
76583+#endif
76584 jiffies_to_clock_t(icsk->icsk_rto),
76585 jiffies_to_clock_t(icsk->icsk_ack.ato),
76586 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76587@@ -1970,7 +2000,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76588 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76589 tw->tw_substate, 0, 0,
76590 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76591- atomic_read(&tw->tw_refcnt), tw);
76592+ atomic_read(&tw->tw_refcnt),
76593+#ifdef CONFIG_GRKERNSEC_HIDESYM
76594+ NULL
76595+#else
76596+ tw
76597+#endif
76598+ );
76599 }
76600
76601 static int tcp6_seq_show(struct seq_file *seq, void *v)
76602diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76603index f05099f..ea613f0 100644
76604--- a/net/ipv6/udp.c
76605+++ b/net/ipv6/udp.c
76606@@ -50,6 +50,10 @@
76607 #include <linux/seq_file.h>
76608 #include "udp_impl.h"
76609
76610+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76611+extern int grsec_enable_blackhole;
76612+#endif
76613+
76614 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76615 {
76616 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76617@@ -615,7 +619,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76618 return rc;
76619 drop:
76620 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76621- atomic_inc(&sk->sk_drops);
76622+ atomic_inc_unchecked(&sk->sk_drops);
76623 kfree_skb(skb);
76624 return -1;
76625 }
76626@@ -673,7 +677,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76627 if (likely(skb1 == NULL))
76628 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76629 if (!skb1) {
76630- atomic_inc(&sk->sk_drops);
76631+ atomic_inc_unchecked(&sk->sk_drops);
76632 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76633 IS_UDPLITE(sk));
76634 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76635@@ -844,6 +848,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76636 goto discard;
76637
76638 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76639+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76640+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76641+#endif
76642 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76643
76644 kfree_skb(skb);
76645@@ -1453,8 +1460,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76646 0, 0L, 0,
76647 sock_i_uid(sp), 0,
76648 sock_i_ino(sp),
76649- atomic_read(&sp->sk_refcnt), sp,
76650- atomic_read(&sp->sk_drops));
76651+ atomic_read(&sp->sk_refcnt),
76652+#ifdef CONFIG_GRKERNSEC_HIDESYM
76653+ NULL,
76654+#else
76655+ sp,
76656+#endif
76657+ atomic_read_unchecked(&sp->sk_drops));
76658 }
76659
76660 int udp6_seq_show(struct seq_file *seq, void *v)
76661diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76662index 6b9d5a0..4dffaf1 100644
76663--- a/net/irda/ircomm/ircomm_tty.c
76664+++ b/net/irda/ircomm/ircomm_tty.c
76665@@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76666 add_wait_queue(&self->open_wait, &wait);
76667
76668 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76669- __FILE__,__LINE__, tty->driver->name, self->open_count );
76670+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76671
76672 /* As far as I can see, we protect open_count - Jean II */
76673 spin_lock_irqsave(&self->spinlock, flags);
76674 if (!tty_hung_up_p(filp)) {
76675 extra_count = 1;
76676- self->open_count--;
76677+ local_dec(&self->open_count);
76678 }
76679 spin_unlock_irqrestore(&self->spinlock, flags);
76680- self->blocked_open++;
76681+ local_inc(&self->blocked_open);
76682
76683 while (1) {
76684 if (tty->termios->c_cflag & CBAUD) {
76685@@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76686 }
76687
76688 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76689- __FILE__,__LINE__, tty->driver->name, self->open_count );
76690+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76691
76692 schedule();
76693 }
76694@@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76695 if (extra_count) {
76696 /* ++ is not atomic, so this should be protected - Jean II */
76697 spin_lock_irqsave(&self->spinlock, flags);
76698- self->open_count++;
76699+ local_inc(&self->open_count);
76700 spin_unlock_irqrestore(&self->spinlock, flags);
76701 }
76702- self->blocked_open--;
76703+ local_dec(&self->blocked_open);
76704
76705 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76706- __FILE__,__LINE__, tty->driver->name, self->open_count);
76707+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76708
76709 if (!retval)
76710 self->flags |= ASYNC_NORMAL_ACTIVE;
76711@@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76712 }
76713 /* ++ is not atomic, so this should be protected - Jean II */
76714 spin_lock_irqsave(&self->spinlock, flags);
76715- self->open_count++;
76716+ local_inc(&self->open_count);
76717
76718 tty->driver_data = self;
76719 self->tty = tty;
76720 spin_unlock_irqrestore(&self->spinlock, flags);
76721
76722 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76723- self->line, self->open_count);
76724+ self->line, local_read(&self->open_count));
76725
76726 /* Not really used by us, but lets do it anyway */
76727 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76728@@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76729 return;
76730 }
76731
76732- if ((tty->count == 1) && (self->open_count != 1)) {
76733+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76734 /*
76735 * Uh, oh. tty->count is 1, which means that the tty
76736 * structure will be freed. state->count should always
76737@@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76738 */
76739 IRDA_DEBUG(0, "%s(), bad serial port count; "
76740 "tty->count is 1, state->count is %d\n", __func__ ,
76741- self->open_count);
76742- self->open_count = 1;
76743+ local_read(&self->open_count));
76744+ local_set(&self->open_count, 1);
76745 }
76746
76747- if (--self->open_count < 0) {
76748+ if (local_dec_return(&self->open_count) < 0) {
76749 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76750- __func__, self->line, self->open_count);
76751- self->open_count = 0;
76752+ __func__, self->line, local_read(&self->open_count));
76753+ local_set(&self->open_count, 0);
76754 }
76755- if (self->open_count) {
76756+ if (local_read(&self->open_count)) {
76757 spin_unlock_irqrestore(&self->spinlock, flags);
76758
76759 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76760@@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76761 tty->closing = 0;
76762 self->tty = NULL;
76763
76764- if (self->blocked_open) {
76765+ if (local_read(&self->blocked_open)) {
76766 if (self->close_delay)
76767 schedule_timeout_interruptible(self->close_delay);
76768 wake_up_interruptible(&self->open_wait);
76769@@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76770 spin_lock_irqsave(&self->spinlock, flags);
76771 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76772 self->tty = NULL;
76773- self->open_count = 0;
76774+ local_set(&self->open_count, 0);
76775 spin_unlock_irqrestore(&self->spinlock, flags);
76776
76777 wake_up_interruptible(&self->open_wait);
76778@@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76779 seq_putc(m, '\n');
76780
76781 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76782- seq_printf(m, "Open count: %d\n", self->open_count);
76783+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76784 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76785 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76786
76787diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76788index cd6f7a9..e63fe89 100644
76789--- a/net/iucv/af_iucv.c
76790+++ b/net/iucv/af_iucv.c
76791@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
76792
76793 write_lock_bh(&iucv_sk_list.lock);
76794
76795- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76796+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76797 while (__iucv_get_sock_by_name(name)) {
76798 sprintf(name, "%08x",
76799- atomic_inc_return(&iucv_sk_list.autobind_name));
76800+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76801 }
76802
76803 write_unlock_bh(&iucv_sk_list.lock);
76804diff --git a/net/key/af_key.c b/net/key/af_key.c
76805index 34e4185..8823368 100644
76806--- a/net/key/af_key.c
76807+++ b/net/key/af_key.c
76808@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76809 static u32 get_acqseq(void)
76810 {
76811 u32 res;
76812- static atomic_t acqseq;
76813+ static atomic_unchecked_t acqseq;
76814
76815 do {
76816- res = atomic_inc_return(&acqseq);
76817+ res = atomic_inc_return_unchecked(&acqseq);
76818 } while (!res);
76819 return res;
76820 }
76821diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
76822index 3f3cd50..d2cf249 100644
76823--- a/net/mac80211/ieee80211_i.h
76824+++ b/net/mac80211/ieee80211_i.h
76825@@ -28,6 +28,7 @@
76826 #include <net/ieee80211_radiotap.h>
76827 #include <net/cfg80211.h>
76828 #include <net/mac80211.h>
76829+#include <asm/local.h>
76830 #include "key.h"
76831 #include "sta_info.h"
76832
76833@@ -863,7 +864,7 @@ struct ieee80211_local {
76834 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
76835 spinlock_t queue_stop_reason_lock;
76836
76837- int open_count;
76838+ local_t open_count;
76839 int monitors, cooked_mntrs;
76840 /* number of interfaces with corresponding FIF_ flags */
76841 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
76842diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
76843index 8664111..1d6a065 100644
76844--- a/net/mac80211/iface.c
76845+++ b/net/mac80211/iface.c
76846@@ -328,7 +328,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76847 break;
76848 }
76849
76850- if (local->open_count == 0) {
76851+ if (local_read(&local->open_count) == 0) {
76852 res = drv_start(local);
76853 if (res)
76854 goto err_del_bss;
76855@@ -371,7 +371,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76856 break;
76857 }
76858
76859- if (local->monitors == 0 && local->open_count == 0) {
76860+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
76861 res = ieee80211_add_virtual_monitor(local);
76862 if (res)
76863 goto err_stop;
76864@@ -468,7 +468,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76865 mutex_unlock(&local->mtx);
76866
76867 if (coming_up)
76868- local->open_count++;
76869+ local_inc(&local->open_count);
76870
76871 if (hw_reconf_flags)
76872 ieee80211_hw_config(local, hw_reconf_flags);
76873@@ -481,7 +481,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76874 err_del_interface:
76875 drv_remove_interface(local, sdata);
76876 err_stop:
76877- if (!local->open_count)
76878+ if (!local_read(&local->open_count))
76879 drv_stop(local);
76880 err_del_bss:
76881 sdata->bss = NULL;
76882@@ -613,7 +613,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76883 }
76884
76885 if (going_down)
76886- local->open_count--;
76887+ local_dec(&local->open_count);
76888
76889 switch (sdata->vif.type) {
76890 case NL80211_IFTYPE_AP_VLAN:
76891@@ -685,7 +685,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76892
76893 ieee80211_recalc_ps(local, -1);
76894
76895- if (local->open_count == 0) {
76896+ if (local_read(&local->open_count) == 0) {
76897 if (local->ops->napi_poll)
76898 napi_disable(&local->napi);
76899 ieee80211_clear_tx_pending(local);
76900@@ -717,7 +717,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76901 }
76902 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
76903
76904- if (local->monitors == local->open_count && local->monitors > 0)
76905+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
76906 ieee80211_add_virtual_monitor(local);
76907 }
76908
76909diff --git a/net/mac80211/main.c b/net/mac80211/main.c
76910index f5548e9..474a15f 100644
76911--- a/net/mac80211/main.c
76912+++ b/net/mac80211/main.c
76913@@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
76914 local->hw.conf.power_level = power;
76915 }
76916
76917- if (changed && local->open_count) {
76918+ if (changed && local_read(&local->open_count)) {
76919 ret = drv_config(local, changed);
76920 /*
76921 * Goal:
76922diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
76923index af1c4e2..24dbbe3 100644
76924--- a/net/mac80211/pm.c
76925+++ b/net/mac80211/pm.c
76926@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76927 struct ieee80211_sub_if_data *sdata;
76928 struct sta_info *sta;
76929
76930- if (!local->open_count)
76931+ if (!local_read(&local->open_count))
76932 goto suspend;
76933
76934 ieee80211_scan_cancel(local);
76935@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76936 cancel_work_sync(&local->dynamic_ps_enable_work);
76937 del_timer_sync(&local->dynamic_ps_timer);
76938
76939- local->wowlan = wowlan && local->open_count;
76940+ local->wowlan = wowlan && local_read(&local->open_count);
76941 if (local->wowlan) {
76942 int err = drv_suspend(local, wowlan);
76943 if (err < 0) {
76944@@ -132,7 +132,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76945 drv_remove_interface(local, sdata);
76946
76947 /* stop hardware - this must stop RX */
76948- if (local->open_count)
76949+ if (local_read(&local->open_count))
76950 ieee80211_stop_device(local);
76951
76952 suspend:
76953diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
76954index 3313c11..bec9f17 100644
76955--- a/net/mac80211/rate.c
76956+++ b/net/mac80211/rate.c
76957@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
76958
76959 ASSERT_RTNL();
76960
76961- if (local->open_count)
76962+ if (local_read(&local->open_count))
76963 return -EBUSY;
76964
76965 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
76966diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
76967index c97a065..ff61928 100644
76968--- a/net/mac80211/rc80211_pid_debugfs.c
76969+++ b/net/mac80211/rc80211_pid_debugfs.c
76970@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
76971
76972 spin_unlock_irqrestore(&events->lock, status);
76973
76974- if (copy_to_user(buf, pb, p))
76975+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
76976 return -EFAULT;
76977
76978 return p;
76979diff --git a/net/mac80211/util.c b/net/mac80211/util.c
76980index 8dd4712..19594fa 100644
76981--- a/net/mac80211/util.c
76982+++ b/net/mac80211/util.c
76983@@ -1216,7 +1216,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
76984 }
76985 #endif
76986 /* everything else happens only if HW was up & running */
76987- if (!local->open_count)
76988+ if (!local_read(&local->open_count))
76989 goto wake_up;
76990
76991 /*
76992diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
76993index 209c1ed..39484dc 100644
76994--- a/net/netfilter/Kconfig
76995+++ b/net/netfilter/Kconfig
76996@@ -851,6 +851,16 @@ config NETFILTER_XT_MATCH_ESP
76997
76998 To compile it as a module, choose M here. If unsure, say N.
76999
77000+config NETFILTER_XT_MATCH_GRADM
77001+ tristate '"gradm" match support'
77002+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77003+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77004+ ---help---
77005+ The gradm match allows to match on grsecurity RBAC being enabled.
77006+ It is useful when iptables rules are applied early on bootup to
77007+ prevent connections to the machine (except from a trusted host)
77008+ while the RBAC system is disabled.
77009+
77010 config NETFILTER_XT_MATCH_HASHLIMIT
77011 tristate '"hashlimit" match support'
77012 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77013diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
77014index 4e7960c..89e48d4 100644
77015--- a/net/netfilter/Makefile
77016+++ b/net/netfilter/Makefile
77017@@ -87,6 +87,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77018 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77019 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
77020 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77021+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77022 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77023 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77024 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77025diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
77026index 1548df9..98ad9b4 100644
77027--- a/net/netfilter/ipvs/ip_vs_conn.c
77028+++ b/net/netfilter/ipvs/ip_vs_conn.c
77029@@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
77030 /* Increase the refcnt counter of the dest */
77031 atomic_inc(&dest->refcnt);
77032
77033- conn_flags = atomic_read(&dest->conn_flags);
77034+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
77035 if (cp->protocol != IPPROTO_UDP)
77036 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77037 flags = cp->flags;
77038@@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
77039 atomic_set(&cp->refcnt, 1);
77040
77041 atomic_set(&cp->n_control, 0);
77042- atomic_set(&cp->in_pkts, 0);
77043+ atomic_set_unchecked(&cp->in_pkts, 0);
77044
77045 atomic_inc(&ipvs->conn_count);
77046 if (flags & IP_VS_CONN_F_NO_CPORT)
77047@@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
77048
77049 /* Don't drop the entry if its number of incoming packets is not
77050 located in [0, 8] */
77051- i = atomic_read(&cp->in_pkts);
77052+ i = atomic_read_unchecked(&cp->in_pkts);
77053 if (i > 8 || i < 0) return 0;
77054
77055 if (!todrop_rate[i]) return 0;
77056diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
77057index a54b018c..07e0120 100644
77058--- a/net/netfilter/ipvs/ip_vs_core.c
77059+++ b/net/netfilter/ipvs/ip_vs_core.c
77060@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
77061 ret = cp->packet_xmit(skb, cp, pd->pp);
77062 /* do not touch skb anymore */
77063
77064- atomic_inc(&cp->in_pkts);
77065+ atomic_inc_unchecked(&cp->in_pkts);
77066 ip_vs_conn_put(cp);
77067 return ret;
77068 }
77069@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
77070 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77071 pkts = sysctl_sync_threshold(ipvs);
77072 else
77073- pkts = atomic_add_return(1, &cp->in_pkts);
77074+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77075
77076 if (ipvs->sync_state & IP_VS_STATE_MASTER)
77077 ip_vs_sync_conn(net, cp, pkts);
77078diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
77079index 84444dd..86adaa0 100644
77080--- a/net/netfilter/ipvs/ip_vs_ctl.c
77081+++ b/net/netfilter/ipvs/ip_vs_ctl.c
77082@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
77083 ip_vs_rs_hash(ipvs, dest);
77084 write_unlock_bh(&ipvs->rs_lock);
77085 }
77086- atomic_set(&dest->conn_flags, conn_flags);
77087+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
77088
77089 /* bind the service */
77090 if (!dest->svc) {
77091@@ -2074,7 +2074,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77092 " %-7s %-6d %-10d %-10d\n",
77093 &dest->addr.in6,
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@@ -2085,7 +2085,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77101 "%-7s %-6d %-10d %-10d\n",
77102 ntohl(dest->addr.ip),
77103 ntohs(dest->port),
77104- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77105+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77106 atomic_read(&dest->weight),
77107 atomic_read(&dest->activeconns),
77108 atomic_read(&dest->inactconns));
77109@@ -2555,7 +2555,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
77110
77111 entry.addr = dest->addr.ip;
77112 entry.port = dest->port;
77113- entry.conn_flags = atomic_read(&dest->conn_flags);
77114+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77115 entry.weight = atomic_read(&dest->weight);
77116 entry.u_threshold = dest->u_threshold;
77117 entry.l_threshold = dest->l_threshold;
77118@@ -3089,7 +3089,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
77119 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
77120 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
77121 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77122- (atomic_read(&dest->conn_flags) &
77123+ (atomic_read_unchecked(&dest->conn_flags) &
77124 IP_VS_CONN_F_FWD_MASK)) ||
77125 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
77126 atomic_read(&dest->weight)) ||
77127diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
77128index effa10c..9058928 100644
77129--- a/net/netfilter/ipvs/ip_vs_sync.c
77130+++ b/net/netfilter/ipvs/ip_vs_sync.c
77131@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
77132 cp = cp->control;
77133 if (cp) {
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 ip_vs_sync_conn(net, cp->control, pkts);
77140@@ -758,7 +758,7 @@ control:
77141 if (!cp)
77142 return;
77143 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77144- pkts = atomic_add_return(1, &cp->in_pkts);
77145+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77146 else
77147 pkts = sysctl_sync_threshold(ipvs);
77148 goto sloop;
77149@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
77150
77151 if (opt)
77152 memcpy(&cp->in_seq, opt, sizeof(*opt));
77153- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77154+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77155 cp->state = state;
77156 cp->old_state = cp->state;
77157 /*
77158diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
77159index 7fd66de..e6fb361 100644
77160--- a/net/netfilter/ipvs/ip_vs_xmit.c
77161+++ b/net/netfilter/ipvs/ip_vs_xmit.c
77162@@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(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
77171@@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
77172 else
77173 rc = NF_ACCEPT;
77174 /* do not touch skb anymore */
77175- atomic_inc(&cp->in_pkts);
77176+ atomic_inc_unchecked(&cp->in_pkts);
77177 goto out;
77178 }
77179
77180diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
77181index ac3af97..c134c21 100644
77182--- a/net/netfilter/nf_conntrack_core.c
77183+++ b/net/netfilter/nf_conntrack_core.c
77184@@ -1530,6 +1530,10 @@ err_proto:
77185 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
77186 #define DYING_NULLS_VAL ((1<<30)+1)
77187
77188+#ifdef CONFIG_GRKERNSEC_HIDESYM
77189+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
77190+#endif
77191+
77192 static int nf_conntrack_init_net(struct net *net)
77193 {
77194 int ret;
77195@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
77196 goto err_stat;
77197 }
77198
77199+#ifdef CONFIG_GRKERNSEC_HIDESYM
77200+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
77201+#else
77202 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
77203+#endif
77204 if (!net->ct.slabname) {
77205 ret = -ENOMEM;
77206 goto err_slabname;
77207diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
77208index 3c3cfc0..7a6ea1a 100644
77209--- a/net/netfilter/nfnetlink_log.c
77210+++ b/net/netfilter/nfnetlink_log.c
77211@@ -70,7 +70,7 @@ struct nfulnl_instance {
77212 };
77213
77214 static DEFINE_SPINLOCK(instances_lock);
77215-static atomic_t global_seq;
77216+static atomic_unchecked_t global_seq;
77217
77218 #define INSTANCE_BUCKETS 16
77219 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77220@@ -517,7 +517,7 @@ __build_packet_message(struct nfulnl_instance *inst,
77221 /* global sequence number */
77222 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
77223 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
77224- htonl(atomic_inc_return(&global_seq))))
77225+ htonl(atomic_inc_return_unchecked(&global_seq))))
77226 goto nla_put_failure;
77227
77228 if (data_len) {
77229diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
77230new file mode 100644
77231index 0000000..6905327
77232--- /dev/null
77233+++ b/net/netfilter/xt_gradm.c
77234@@ -0,0 +1,51 @@
77235+/*
77236+ * gradm match for netfilter
77237